Skip to content

euphoric-hardware/baremetal-rust-riscv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

riscv-rust-baremetal

Rust example that compiles to baremetal riscv. Supports HTIF to communicate with host and perform proxy syscalls.

Quick start

Edit the configuration at .cargo/config.toml.

rustup target add riscv64gc-unknown-none-elf
cargo build

To run a specific benchmark (Requires Spike):

cargo run --bin bin-name

You can also run cargo with specific configuration with the --config flag. Example:

rustup target add riscv32imac-unknown-none-elf
cargo --config 'build.target="riscv32imac-unknown-none-elf"' \
    --config 'target.riscv32imac-unknown-none-elf.linker="riscv32-unknown-elf-ld"' \
    r --bin median --release

TODO

Ideas

Benchmarks

  • Port benchmarks from riscv tests

  • Cycles should be similar?

  • Not sure if cycles are accurate, might need more testing / investigating.

  • Figured out why mcycle is worst: no vector instructions

  • Tower: The the original riscv-tests uses linked list. Linked list normally sucks, but maybe in embedded programming it is good. Still need to decide how to port

  • memcpy: clone (memcpy) uses 5x more mcycle, maybe look at rust documentation. C version unrolls the loop

  • radix sort: https://crates.io/crates/rdx/0.0.7

Conclusion

Hard to recreate some of the tests without using unsafe and pointers, but then we would just be writing C. Maybe we should still do that.

Borrow checker is pretty good. Safety gaurantees are nice too. For example, global static is unsafe by default, so the programmer knows that they need sync or redesign (for porting riscv-tests, I make the caller track data for now instead of global statics).

Results

Benchmark Rust mcycle C mcycle Godbolt
median 6449 4654 https://godbolt.org/z/8rdThb57a
sort 215018 x
qsort 231015 123208
qsort (with no bounds checking) 184037
rsort TODO 171156
towers TODO
vvadd 4835 2411 https://godbolt.org/z/e1jcPajGW
memcpy 9540 5515 https://godbolt.org/z/Wz3T6oP96
multiply 7590 26811 https://godbolt.org/z/6fjjqP6rq
multiply (with --unroll-loops) 20986 https://godbolt.org/z/6fjjqP6rq

Resources

HTIF implementations:

Rust:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published