Skip to content

Commit 1f29bd3

Browse files
committed
Impr: r0 loops to minimize instructions
1 parent eef90a0 commit 1f29bd3

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

riscv-rt/src/lib.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
413413
if _mp_hook(hartid) {
414414
__pre_init();
415415

416-
// Initialize RAM (32-bit version)
416+
// Initialize RAM
417417
// 1. Copy over .data from flash to RAM
418418
// 2. Zero out .bss
419419
core::arch::asm!(
@@ -423,29 +423,28 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
423423
la {end},_edata
424424
la {input},_sidata
425425
426+
bgeu {start},{end},2f
426427
1:
427-
addi {a},{start},4
428-
bgeu {a},{end},1f
429-
lw {b},0({input})
430-
sw {b},0({start})
431-
addi {start},{start},4
428+
lw {a},0({input})
432429
addi {input},{input},4
433-
j 1b
430+
sw {a},0({start})
431+
addi {start},{start},4
432+
bltu {start},{end},1b
433+
434+
2:
435+
li {a},0
434436
435-
1:
436437
// Zero out .bss
437438
la {start},_sbss
438439
la {end},_ebss
439440
441+
bgeu {start},{end},3f
440442
2:
441-
addi {a},{start},4
442-
bgeu {a},{end},2f
443443
sw zero,0({start})
444444
addi {start},{start},4
445-
j 2b
446-
447-
2:
445+
bltu {start},{end},2b
448446
447+
3:
449448
li {start},0
450449
li {end},0
451450
li {input},0
@@ -454,7 +453,6 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
454453
end = out(reg) _,
455454
input = out(reg) _,
456455
a = out(reg) _,
457-
b = out(reg) _,
458456
);
459457

460458
compiler_fence(Ordering::SeqCst);

0 commit comments

Comments
 (0)