Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM support #2576

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ members = [
"isa-utils",
"airgen",
"riscv-executor",
"riscv-syscalls",
"syscalls",
"schemas",
"backend-utils",
"executor-utils",
"wasm",
]

exclude = ["riscv-runtime"]
Expand Down Expand Up @@ -67,7 +68,7 @@ powdr-pipeline = { path = "./pipeline", version = "0.1.4" }
powdr-plonky3 = { path = "./plonky3", version = "0.1.4" }
powdr-riscv = { path = "./riscv", version = "0.1.4" }
powdr-riscv-executor = { path = "./riscv-executor", version = "0.1.4" }
powdr-riscv-syscalls = { path = "./riscv-syscalls", version = "0.1.4" }
powdr-syscalls = { path = "./syscalls", version = "0.1.4" }
powdr-schemas = { path = "./schemas", version = "0.1.4" }

[profile.pr-tests]
Expand Down
12 changes: 9 additions & 3 deletions riscv-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ homepage = "https://powdr.org"
repository = "https://github.com/powdr-labs/powdr"

[dependencies]
serde = { version = "1.0", default-features = false, features = ["alloc", "derive", "rc"] }
serde_cbor = { version = "0.11.2", default-features = false, features = ["alloc"] }
powdr-riscv-syscalls = { path = "../riscv-syscalls", version = "0.1.4" }
serde = { version = "1.0", default-features = false, features = [
"alloc",
"derive",
"rc",
] }
serde_cbor = { version = "0.11.2", default-features = false, features = [
"alloc",
] }
powdr-syscalls = { path = "../syscalls", version = "0.1.4" }
getrandom = { version = "0.2", features = ["custom"], optional = true }
spin = "0.9"

Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/arith.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::arch::asm;

use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

use crate::ecall;

Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/ec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::arch::asm;

use crate::arith::{bes_to_u32, u32x16_to_be};
use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

/// Add two k256 ec points. Coordinates are big-endian u8 arrays.
pub fn add_u8_be(ax: [u8; 32], ay: [u8; 32], bx: [u8; 32], by: [u8; 32]) -> [u8; 64] {
Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::arch::asm;
use core::fmt;

use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

#[macro_export]
macro_rules! print {
Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/goldilocks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::{arch::asm, mem::MaybeUninit};
use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

pub const PRIME: u64 = 0xffffffff00000001;

Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::convert::TryInto;
use core::mem::MaybeUninit;

use crate::goldilocks::{Goldilocks, OpaqueGoldilocks};
use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

pub fn native_hash(data: &mut [u64; 12]) -> &[u64; 4] {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::slice;

extern crate alloc;

use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

use alloc::vec;
use alloc::vec::Vec;
Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod no_std_support;
mod std_support;

use core::arch::{asm, global_asm};
use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

#[no_mangle]
pub fn halt() -> ! {
Expand Down
2 changes: 1 addition & 1 deletion riscv-runtime/src/std_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use core::{alloc::Layout, arch::asm, slice};

use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

use crate::io::write_slice;

Expand Down
2 changes: 1 addition & 1 deletion riscv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ powdr-parser.workspace = true
powdr-parser-util.workspace = true
powdr-pipeline.workspace = true
powdr-riscv-executor.workspace = true
powdr-riscv-syscalls.workspace = true
powdr-syscalls.workspace = true

gimli = "0.31"
goblin = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion riscv/src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use goblin::elf::{
};
use itertools::{Either, Itertools};
use powdr_isa_utils::SingleDataValue;
use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;
use raki::{
decode::Decode,
instruction::{Extensions, Instruction as Ins, OpcodeKind as Op},
Expand Down
2 changes: 1 addition & 1 deletion riscv/src/large_field/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

use itertools::Itertools;

Expand Down
2 changes: 1 addition & 1 deletion riscv/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use powdr_ast::parsed::asm::{FunctionStatement, MachineStatement, SymbolPath};

use powdr_parser::ParserContext;
use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

lazy_static::lazy_static! {
static ref INSTRUCTION_DECLARATION_PARSER: powdr_parser::powdr::InstructionDeclarationParser
Expand Down
2 changes: 1 addition & 1 deletion riscv/src/small_field/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use powdr_riscv_syscalls::Syscall;
use powdr_syscalls::Syscall;

use itertools::Itertools;

Expand Down
6 changes: 3 additions & 3 deletions riscv/tests/riscv_data/plonky3_verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
powdr-riscv-syscalls = { path = "../../../../riscv-syscalls" }
powdr-riscv-runtime = { path = "../../../../riscv-runtime", features = ["std"]}
powdr-plonky3 = { path = "../../../../plonky3", features = ["powdr-accel"]}
powdr-syscalls = { path = "../../../../syscalls" }
powdr-riscv-runtime = { path = "../../../../riscv-runtime", features = ["std"] }
powdr-plonky3 = { path = "../../../../plonky3", features = ["powdr-accel"] }

[workspace]
4 changes: 2 additions & 2 deletions riscv/tests/riscv_data/std_hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
powdr-riscv-syscalls = { path = "../../../../riscv-syscalls" }
powdr-riscv-runtime = { path = "../../../../riscv-runtime", features = ["std"]}
powdr-syscalls = { path = "../../../../syscalls" }
powdr-riscv-runtime = { path = "../../../../riscv-runtime", features = ["std"] }

[workspace]
4 changes: 2 additions & 2 deletions riscv-syscalls/Cargo.toml → syscalls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "powdr-riscv-syscalls"
description = "powdr RISC-V syscalls"
name = "powdr-syscalls"
description = "powdr syscalls"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
40 changes: 23 additions & 17 deletions riscv-syscalls/src/lib.rs → syscalls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]

macro_rules! syscalls {
($(($num:expr, $identifier:ident, $name:expr)),* $(,)?) => {
($(($num:expr, $identifier:ident, $name:expr, $input_count:expr, $output_count:expr)),* $(,)?) => {
/// We use repr(u8) to make sure the enum discriminant will fit into the
/// 12 bits of the immediate field of the `addi` instruction,
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
Expand All @@ -11,11 +11,17 @@ macro_rules! syscalls {
}

impl Syscall {
pub fn name(&self) -> &'static str {
pub const fn name(&self) -> &'static str {
match self {
$(Syscall::$identifier => $name),*
}
}

pub const fn arity(&self) -> (u32, u32) {
match self {
$(Syscall::$identifier => ($input_count, $output_count)),*
}
}
}

impl core::fmt::Display for Syscall {
Expand Down Expand Up @@ -56,19 +62,19 @@ macro_rules! syscalls {

// Generate `Syscall` enum with supported syscalls and their numbers.
syscalls!(
(1, Input, "input"),
(2, Output, "output"),
(3, PoseidonGL, "poseidon_gl"),
(4, Affine256, "affine_256"),
(5, EcAdd, "ec_add"),
(6, EcDouble, "ec_double"),
(7, KeccakF, "keccakf"),
(8, Mod256, "mod_256"),
(9, Halt, "halt"),
(10, Poseidon2GL, "poseidon2_gl"),
(11, NativeHash, "native_hash"),
(12, CommitPublic, "commit_public"),
(13, InvertGL, "invert_gl"),
(14, SplitGLVec, "split_gl_vec"),
(15, MergeGL, "merge_gl"),
(1, Input, "input", 2, 1),
(2, Output, "output", 2, 0),
(3, PoseidonGL, "poseidon_gl", 1, 0),
(4, Affine256, "affine_256", 4, 0),
(5, EcAdd, "ec_add", 3, 0),
(6, EcDouble, "ec_double", 2, 0),
(7, KeccakF, "keccakf", 2, 0),
(8, Mod256, "mod_256", 3, 0),
(9, Halt, "halt", 0, 0),
(10, Poseidon2GL, "poseidon2_gl", 2, 0),
(11, NativeHash, "native_hash", 1, 0),
(12, CommitPublic, "commit_public", 2, 0),
(13, InvertGL, "invert_gl", 2, 2),
(14, SplitGLVec, "split_gl_vec", 2, 0),
(15, MergeGL, "merge_gl", 3, 0),
);
17 changes: 17 additions & 0 deletions wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "powdr_wasm"
description = "powdr WebAssembly frontend"
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
powdr-syscalls.workspace = true

wasmparser = "0.227"
log = "0.4.17"

[lints]
workspace = true
Loading
Loading