Skip to content

Commit 5506da6

Browse files
committed
fix: fixed formatting with cargo fmt
1 parent 70a5a8c commit 5506da6

31 files changed

Lines changed: 956 additions & 407 deletions

bench-native/src/main.rs

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,36 @@ const BLOCK: usize = 4096;
66
fn median(mut v: Vec<f64>) -> f64 {
77
v.sort_by(|a, b| a.partial_cmp(b).unwrap());
88
let n = v.len();
9-
if n == 0 { return 0.0; }
10-
if n % 2 == 1 { v[n / 2] } else { (v[n / 2 - 1] + v[n / 2]) / 2.0 }
9+
if n == 0 {
10+
return 0.0;
11+
}
12+
if n % 2 == 1 {
13+
v[n / 2]
14+
} else {
15+
(v[n / 2 - 1] + v[n / 2]) / 2.0
16+
}
1117
}
1218

1319
fn bench<F: FnMut()>(trials: usize, iters: u64, mut f: F) -> f64 {
14-
for _ in 0..iters.min(64) { f(); }
20+
for _ in 0..iters.min(64) {
21+
f();
22+
}
1523
let mut per_op = Vec::with_capacity(trials);
1624
for _ in 0..trials {
1725
let start = Instant::now();
18-
for _ in 0..iters { f(); }
26+
for _ in 0..iters {
27+
f();
28+
}
1929
per_op.push(start.elapsed().as_nanos() as f64 / iters as f64);
2030
}
2131
median(per_op)
2232
}
2333

2434
fn inline_vs_periodic() {
25-
const NBLOCKS: usize = 256;
26-
const OPS: usize = 200_000;
27-
const VICTIM: usize = 123;
28-
const TAMPER_AT: usize = OPS / 2;
35+
const NBLOCKS: usize = 256;
36+
const OPS: usize = 200_000;
37+
const VICTIM: usize = 123;
38+
const TAMPER_AT: usize = OPS / 2;
2939

3040
let mut data = vec![0u8; NBLOCKS * BLOCK];
3141
for (i, b) in data.iter_mut().enumerate() {
@@ -106,7 +116,9 @@ fn inline_vs_periodic() {
106116
);
107117
}
108118
println!("tradeoff: inline pays per read but serves 0 corrupted bytes; periodic is cheaper");
109-
println!(" per op as the interval grows, but serves corrupted data across the window.");
119+
println!(
120+
" per op as the interval grows, but serves corrupted data across the window."
121+
);
110122
}
111123

112124
fn main() {
@@ -118,22 +130,41 @@ fn main() {
118130
println!("--- BLAKE3 throughput ---");
119131
for &sz in &[64usize, 512, 4096] {
120132
let buf = vec![0xABu8; sz];
121-
let ns = bench(7, 5000, || { let h = blake3::hash(black_box(&buf)); black_box(h); });
133+
let ns = bench(7, 5000, || {
134+
let h = blake3::hash(black_box(&buf));
135+
black_box(h);
136+
});
122137
let gbs = sz as f64 / ns;
123138
println!(" hash {sz:>6} B: {ns:8.1} ns/op ({gbs:5.2} GB/s)");
124139
}
125140
println!();
126141

127142
println!("--- read+verify: whole-file vs one 4 KiB block ---");
128-
println!("{:>10} {:>7} {:>14} {:>12} {:>8}", "size(B)", "blocks", "wholefile(ms)", "block(ms)", "speedup");
143+
println!(
144+
"{:>10} {:>7} {:>14} {:>12} {:>8}",
145+
"size(B)", "blocks", "wholefile(ms)", "block(ms)", "speedup"
146+
);
129147
for &sz in &[4096usize, 16384, 65536, 262144, 1048576, 4194304] {
130148
let buf = vec![0xABu8; sz];
131149
let nblocks = (sz + BLOCK - 1) / BLOCK;
132150
let first = &buf[..BLOCK.min(sz)];
133151
let iters = (8_000_000u64 / sz as u64).max(50);
134-
let wf = bench(7, iters, || { let h = blake3::hash(black_box(&buf)); black_box(h); });
135-
let bl = bench(7, iters.max(4000), || { let h = blake3::hash(black_box(first)); black_box(h); });
136-
println!("{:>10} {:>7} {:>14.6} {:>12.6} {:>7.1}x", sz, nblocks, wf / 1e6, bl / 1e6, wf / bl);
152+
let wf = bench(7, iters, || {
153+
let h = blake3::hash(black_box(&buf));
154+
black_box(h);
155+
});
156+
let bl = bench(7, iters.max(4000), || {
157+
let h = blake3::hash(black_box(first));
158+
black_box(h);
159+
});
160+
println!(
161+
"{:>10} {:>7} {:>14.6} {:>12.6} {:>7.1}x",
162+
sz,
163+
nblocks,
164+
wf / 1e6,
165+
bl / 1e6,
166+
wf / bl
167+
);
137168
}
138169
println!();
139170
println!("speedup = proportional-access effect (platform-independent in shape).");

build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ use std::path::PathBuf;
33

44
fn main() {
55
let target = env::var("TARGET").unwrap_or_default();
6-
6+
77
if !target.starts_with("x86_64") {
88
return;
99
}
1010

1111
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
12-
12+
1313
println!("cargo:rerun-if-changed=src/task/switch.s");
14-
14+
1515
std::process::Command::new("nasm")
1616
.args(&["-f", "elf64", "src/task/switch.s", "-o"])
1717
.arg(&format!("{}/switch.o", out_dir.display()))
1818
.status()
1919
.expect("Failed to assemble switch.s");
20-
20+
2121
println!("cargo:rustc-link-search={}", out_dir.display());
2222
println!("cargo:rustc-link-lib=static=switch");
23-
23+
2424
ar::Builder::new(std::fs::File::create(format!("{}/libswitch.a", out_dir.display())).unwrap())
2525
.append_path(format!("{}/switch.o", out_dir.display()))
2626
.unwrap();

src/arch/aarch64/boot.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@ global_asm!(
66
" mrs x0, mpidr_el1",
77
" and x0, x0, #0xFF",
88
" cbnz x0, halt",
9-
109
// Enable NEON/FP at EL1
1110
// CPACR_EL1 bits [21:20] = 0b11 enables FP/SIMD access
1211
" mrs x0, cpacr_el1",
1312
" orr x0, x0, #(0x3 << 20)",
1413
" msr cpacr_el1, x0",
1514
" isb",
16-
1715
// Set stack pointer
1816
" mov x0, #0x4800",
1917
" lsl x0, x0, #16",
2018
" mov sp, x0",
21-
2219
" bl zero_bss",
2320
" bl kernel_main_arm",
24-
2521
"halt:",
2622
" wfe",
2723
" b halt",

src/arch/aarch64/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#![no_std]
22
#![no_main]
33

4-
mod uart;
54
mod boot;
5+
mod uart;
66

7-
use uart::{uart_puts, uart_put_u64};
7+
use uart::{uart_put_u64, uart_puts};
88

99
#[unsafe(no_mangle)]
1010
pub extern "C" fn kernel_main_arm() -> ! {
1111
uart_puts("\n AXIOM OS v0.3.0-alpha - aarch64\n\n");
1212

1313
let sp: u64;
14-
unsafe { core::arch::asm!("mov {}, sp", out(reg) sp); }
14+
unsafe {
15+
core::arch::asm!("mov {}, sp", out(reg) sp);
16+
}
1517
uart_puts(" SP: ");
1618
uart_put_u64(sp);
1719
uart_puts("\n\n");
@@ -39,7 +41,9 @@ pub extern "C" fn kernel_main_arm() -> ! {
3941
uart_puts("\n Benchmark: OK\n\n");
4042

4143
uart_puts(" ARM64 boot successful. Halting.\n");
42-
loop { unsafe { core::arch::asm!("wfe") }; }
44+
loop {
45+
unsafe { core::arch::asm!("wfe") };
46+
}
4347
}
4448

4549
#[inline(never)]
@@ -66,5 +70,7 @@ fn read_cntvct() -> u64 {
6670
#[panic_handler]
6771
fn panic(_info: &core::panic::PanicInfo) -> ! {
6872
uart::uart_puts("\n KERNEL PANIC\n");
69-
loop { unsafe { core::arch::asm!("wfe") }; }
73+
loop {
74+
unsafe { core::arch::asm!("wfe") };
75+
}
7076
}

src/arch/aarch64/uart.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ pub fn uart_putc(c: u8) {
1212

1313
pub fn uart_puts(s: &str) {
1414
for byte in s.bytes() {
15-
if byte == b'\n' { uart_putc(b'\r'); }
15+
if byte == b'\n' {
16+
uart_putc(b'\r');
17+
}
1618
uart_putc(byte);
1719
}
1820
}

src/ata.rs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use x86_64::instructions::port::Port;
21
use crate::println;
2+
use x86_64::instructions::port::Port;
33

4-
const ATA_DATA: u16 = 0x170;
4+
const ATA_DATA: u16 = 0x170;
55
#[allow(dead_code)]
6-
const ATA_ERROR: u16 = 0x171;
7-
const ATA_SECTOR_CNT: u16 = 0x172;
8-
const ATA_LBA_LO: u16 = 0x173;
9-
const ATA_LBA_MID: u16 = 0x174;
10-
const ATA_LBA_HI: u16 = 0x175;
11-
const ATA_DRIVE_HEAD: u16 = 0x176;
12-
const ATA_STATUS: u16 = 0x177;
13-
const ATA_COMMAND: u16 = 0x177;
6+
const ATA_ERROR: u16 = 0x171;
7+
const ATA_SECTOR_CNT: u16 = 0x172;
8+
const ATA_LBA_LO: u16 = 0x173;
9+
const ATA_LBA_MID: u16 = 0x174;
10+
const ATA_LBA_HI: u16 = 0x175;
11+
const ATA_DRIVE_HEAD: u16 = 0x176;
12+
const ATA_STATUS: u16 = 0x177;
13+
const ATA_COMMAND: u16 = 0x177;
1414

15-
const CMD_READ: u8 = 0x20;
15+
const CMD_READ: u8 = 0x20;
1616
const CMD_WRITE: u8 = 0x30;
1717

1818
#[allow(dead_code)]
@@ -25,8 +25,12 @@ fn wait_ready() -> bool {
2525
let mut status: Port<u8> = unsafe { Port::new(ATA_STATUS) };
2626
for _ in 0..100_000 {
2727
let s = unsafe { status.read() };
28-
if s & STATUS_BSY == 0 && s & STATUS_DRQ != 0 { return true; }
29-
if s & STATUS_ERR != 0 { return false; }
28+
if s & STATUS_BSY == 0 && s & STATUS_DRQ != 0 {
29+
return true;
30+
}
31+
if s & STATUS_ERR != 0 {
32+
return false;
33+
}
3034
}
3135
false
3236
}
@@ -35,7 +39,9 @@ fn wait_ready() -> bool {
3539
fn wait_not_busy() {
3640
let mut status: Port<u8> = unsafe { Port::new(ATA_STATUS) };
3741
for _ in 0..100_000 {
38-
if unsafe { status.read() } & STATUS_BSY == 0 { return; }
42+
if unsafe { status.read() } & STATUS_BSY == 0 {
43+
return;
44+
}
3945
}
4046
}
4147

@@ -57,13 +63,17 @@ pub fn read_sector(lba: u32, buf: &mut [u8; 512]) -> bool {
5763
Port::<u8>::new(ATA_COMMAND).write(CMD_READ);
5864
// Fixed delay - read status 400 times
5965
let mut sp = Port::<u8>::new(ATA_STATUS);
60-
for _ in 0..400usize { sp.read(); }
66+
for _ in 0..400usize {
67+
sp.read();
68+
}
6169
let s = sp.read();
62-
if s & STATUS_ERR != 0 || s & STATUS_DRQ == 0 { return false; }
70+
if s & STATUS_ERR != 0 || s & STATUS_DRQ == 0 {
71+
return false;
72+
}
6373
let mut data: Port<u16> = Port::new(ATA_DATA);
6474
for i in 0..256usize {
6575
let word = data.read();
66-
buf[i * 2] = (word & 0xFF) as u8;
76+
buf[i * 2] = (word & 0xFF) as u8;
6777
buf[i * 2 + 1] = (word >> 8) as u8;
6878
}
6979
true
@@ -79,9 +89,13 @@ pub fn write_sector(lba: u32, buf: &[u8; 512]) -> bool {
7989
Port::<u8>::new(ATA_LBA_HI).write((lba >> 16) as u8);
8090
Port::<u8>::new(ATA_COMMAND).write(CMD_WRITE);
8191
let mut sp = Port::<u8>::new(ATA_STATUS);
82-
for _ in 0..400usize { sp.read(); }
92+
for _ in 0..400usize {
93+
sp.read();
94+
}
8395
let s = sp.read();
84-
if s & STATUS_ERR != 0 || s & STATUS_DRQ == 0 { return false; }
96+
if s & STATUS_ERR != 0 || s & STATUS_DRQ == 0 {
97+
return false;
98+
}
8599
let mut data: Port<u16> = Port::new(ATA_DATA);
86100
for i in 0..256usize {
87101
let word = (buf[i * 2] as u16) | ((buf[i * 2 + 1] as u16) << 8);
@@ -96,7 +110,9 @@ pub fn detect() -> bool {
96110
// Select slave drive (0xB0)
97111
Port::<u8>::new(ATA_DRIVE_HEAD).write(0xA0);
98112
// Read status 4 times to let drive respond
99-
for _ in 0..4 { Port::<u8>::new(ATA_STATUS).read(); }
113+
for _ in 0..4 {
114+
Port::<u8>::new(ATA_STATUS).read();
115+
}
100116
let status = Port::<u8>::new(ATA_STATUS).read();
101117
// 0xFF = floating bus = no drive, 0x00 = also no drive
102118
status != 0xFF && status != 0x00
@@ -107,7 +123,9 @@ pub fn init() -> bool {
107123
unsafe {
108124
// Check secondary channel master (our axiom-disk.img is index=1 = secondary master)
109125
Port::<u8>::new(ATA_DRIVE_HEAD).write(0xA0);
110-
for _ in 0..15usize { Port::<u8>::new(ATA_STATUS).read(); }
126+
for _ in 0..15usize {
127+
Port::<u8>::new(ATA_STATUS).read();
128+
}
111129
let s1 = Port::<u8>::new(ATA_STATUS).read();
112130
let s2 = Port::<u8>::new(ATA_STATUS).read();
113131
let s3 = Port::<u8>::new(ATA_STATUS).read();

src/benchmark.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ pub struct Benchmark {
66

77
impl Benchmark {
88
pub fn new(name: &'static str) -> Self {
9-
Benchmark { name, iterations: 0, total_cycles: 0 }
9+
Benchmark {
10+
name,
11+
iterations: 0,
12+
total_cycles: 0,
13+
}
1014
}
1115

1216
pub fn run<F: FnMut()>(&mut self, iterations: u64, mut f: F) {
@@ -22,9 +26,16 @@ impl Benchmark {
2226
pub fn report(&self) {
2327
let avg = if self.iterations > 0 {
2428
self.total_cycles / self.iterations
25-
} else { 0 };
26-
crate::println!("[bench] {}: {} iterations, {} total cycles, {} avg cycles/op",
27-
self.name, self.iterations, self.total_cycles, avg);
29+
} else {
30+
0
31+
};
32+
crate::println!(
33+
"[bench] {}: {} iterations, {} total cycles, {} avg cycles/op",
34+
self.name,
35+
self.iterations,
36+
self.total_cycles,
37+
avg
38+
);
2839
}
2940
}
3041

0 commit comments

Comments
 (0)