athenavm / athena

Athena monorepo
https://www.athenavm.org/
Apache License 2.0
6 stars 0 forks source link

Switch to RV32E toolchain #1

Closed lrettig closed 4 weeks ago

lrettig commented 1 month ago

We'd like to use the RV32E toolchain (which uses only 16 registers) for a couple of reasons. One is to save registers for internal use, which may make the wrapper/harness code that's used to run Athena programs in ZK simpler. Another is for possible performance gains when running on hardware with 16 registers such as amd64 (although preliminary results on this are mixed).

Note that LLVM mainlined support for RV32E but this support is still considered experimental:

https://github.com/llvm/llvm-project/blob/ae1596a31a6fac2f4daafe1e256d4a5cf3742617/llvm/docs/RISCVUsage.rst?plain=1#L52-L57

https://github.com/llvm/llvm-project/blob/ae1596a31a6fac2f4daafe1e256d4a5cf3742617/llvm/docs/RISCVUsage.rst?plain=1#L220-L221

Another issue here is lack of stdlib support in Rust. Right now we're using https://github.com/succinctlabs/rust which, just like risczero, includes partial stdlib support. This uses RV32IM (the riscv32im-succinct-zkvm-elf Rust target, to be exact).

lrettig commented 4 weeks ago

Making good progress on this. Was able to compile a toolchain, see https://github.com/athenavm/rustc-rv32e-toolchain. Still getting some errors about missing atomics (and updating the target settings doesn't seem to help), but found a temporary workaround. To do:

lrettig commented 4 weeks ago

I put the RV32E stuff behind a feature flag. The VM should work fine with both. But having full support for both would mean two sets of compiled examples, two sets of compiled tests, support for building and downloading two different toolchains, etc. - I didn't go so far as to enable all of that. Can revisit in future.