Skip to content

Commit

Permalink
Use memcpy and memset from musl for performance benefit (#277)
Browse files Browse the repository at this point in the history
Base: commit 37e18b7bf307fa4a8c745feebfcba54a0ba74f30
- src/string/memcpy.c
- src/string/memset.c

This was compiled into assembly with:

 clang-14 -target riscv32 -march=rv32im -O3 -S memcpy.c -nostdlib -fno-builtin -funroll-loops

and labels manually updated to not conflict

License is MIT, see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT and indicated in the .s files

Signed-off-by: Carsten Munk <carsten@zippie.com>

Signed-off-by: Carsten Munk <carsten@zippie.com>
Co-authored-by: Carsten Munk <carsten@zippie.com>
Co-authored-by: Frank Laub <flaub@risc0.com>
  • Loading branch information
3 people committed Sep 15, 2022
1 parent 145a64f commit d471cc6
Show file tree
Hide file tree
Showing 4 changed files with 786 additions and 2 deletions.
2 changes: 1 addition & 1 deletion risc0/zkvm/sdk/rust/guest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rust_library(
name = "guest",
srcs = glob(["src/**/*.rs"]),
crate_name = "risc0_zkvm_guest",
data = ["README.md"],
data = ["README.md", "src/memset.s", "src/memcpy.s"],
deps = [
"//risc0/zkp/rust:zkp_guest",
"//risc0/zkvm/sdk/rust:zkvm_guest",
Expand Down
7 changes: 6 additions & 1 deletion risc0/zkvm/sdk/rust/guest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ pub mod sha;
#[cfg(feature = "pure-prove")]
pub mod sha_insecure;

use core::{arch::asm, mem, ptr};
use core::{arch::asm, arch::global_asm, mem, ptr};

#[cfg(target_arch = "riscv32")]
global_asm!(include_str!("memset.s"));
#[cfg(target_arch = "riscv32")]
global_asm!(include_str!("memcpy.s"));

extern "C" {
fn _fault() -> !;
Expand Down

0 comments on commit d471cc6

Please sign in to comment.