From ad0160d8aacdbd8feffd3d781e94705c213c078d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 27 Dec 2024 16:19:03 -0300 Subject: [PATCH 01/72] Adds CI step to check if stylus_benchmark can be built --- .github/workflows/arbitrator-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index dd58a30571..f53312731a 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -165,6 +165,9 @@ jobs: - name: Run rust tests run: cargo test -p arbutil -p prover -p jit -p stylus --release --manifest-path arbitrator/prover/Cargo.toml + - name: Check stylus_bechmark + run: cargo check --manifest-path arbitrator/tools/stylus_benchmark/Cargo.toml + - name: Rustfmt run: cargo fmt -p arbutil -p prover -p jit -p stylus --manifest-path arbitrator/Cargo.toml -- --check From 962d0b651ef74ea215e85287a2d5e004558e7d77 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 27 Dec 2024 16:23:19 -0300 Subject: [PATCH 02/72] Renames exec_program to launch_program_thread --- arbitrator/jit/src/program.rs | 4 ++-- arbitrator/tools/stylus_benchmark/src/benchmark.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arbitrator/jit/src/program.rs b/arbitrator/jit/src/program.rs index d80b3771c6..abb498cf55 100644 --- a/arbitrator/jit/src/program.rs +++ b/arbitrator/jit/src/program.rs @@ -139,10 +139,10 @@ pub fn new_program( ))); }; - exec_program(exec, module, calldata, config, evm_data, gas) + launch_program_thread(exec, module, calldata, config, evm_data, gas) } -pub fn exec_program( +pub fn launch_program_thread( exec: &mut WasmEnv, module: Arc<[u8]>, calldata: Vec, diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 43f7b7553a..3cc2aabb7d 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -45,7 +45,7 @@ fn run(compiled_module: Vec) -> (Duration, Ink) { let exec = &mut WasmEnv::default(); - let module = jit::program::exec_program( + let module = jit::program::launch_program_thread( exec, compiled_module.into(), calldata, From 8d0c6cbf169244322119493e2b417a8ecb660e38 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Mon, 6 Jan 2025 11:01:37 -0300 Subject: [PATCH 03/72] stylus_benchmark: Prints available scenarios in help --- arbitrator/tools/stylus_benchmark/Cargo.lock | 35 +++---------------- arbitrator/tools/stylus_benchmark/Cargo.toml | 2 -- arbitrator/tools/stylus_benchmark/src/main.rs | 9 +++-- .../tools/stylus_benchmark/src/scenario.rs | 10 +++--- 4 files changed, 13 insertions(+), 43 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/Cargo.lock b/arbitrator/tools/stylus_benchmark/Cargo.lock index fe3ff5e908..f1b9fb4996 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.lock +++ b/arbitrator/tools/stylus_benchmark/Cargo.lock @@ -1663,12 +1663,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustversion" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" - [[package]] name = "ryu" version = "1.0.18" @@ -1701,9 +1695,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -1721,9 +1715,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -1909,25 +1903,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "strum" -version = "0.26.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" - -[[package]] -name = "strum_macros" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" -dependencies = [ - "heck 0.5.0", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.87", -] - [[package]] name = "stylus" version = "0.1.0" @@ -1964,8 +1939,6 @@ dependencies = [ "eyre", "jit", "prover", - "strum", - "strum_macros", "stylus", "wasmer", "wasmer-compiler-cranelift", diff --git a/arbitrator/tools/stylus_benchmark/Cargo.toml b/arbitrator/tools/stylus_benchmark/Cargo.toml index e193fc0ca8..4f9ed74d46 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.toml +++ b/arbitrator/tools/stylus_benchmark/Cargo.toml @@ -12,5 +12,3 @@ arbutil = { path = "../../arbutil/" } prover = { path = "../../prover/", default-features = false, features = ["native"] } stylus = { path = "../../stylus/", default-features = false } clap = { version = "4.4.8", features = ["derive"] } -strum = "0.26" -strum_macros = "0.26" diff --git a/arbitrator/tools/stylus_benchmark/src/main.rs b/arbitrator/tools/stylus_benchmark/src/main.rs index 4b8971ecab..c2d55ef06c 100644 --- a/arbitrator/tools/stylus_benchmark/src/main.rs +++ b/arbitrator/tools/stylus_benchmark/src/main.rs @@ -4,10 +4,9 @@ mod benchmark; mod scenario; -use clap::Parser; +use clap::{Parser, ValueEnum}; use scenario::Scenario; use std::path::PathBuf; -use strum::IntoEnumIterator; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -20,7 +19,7 @@ struct Args { } fn handle_scenario(scenario: Scenario, output_wat_dir_path: Option) -> eyre::Result<()> { - println!("Benchmarking {}", scenario); + println!("Benchmarking {:?}", scenario); let wat = scenario::generate_wat(scenario, output_wat_dir_path); benchmark::benchmark(wat) } @@ -32,8 +31,8 @@ fn main() -> eyre::Result<()> { Some(scenario) => handle_scenario(scenario, args.output_wat_dir_path), None => { println!("No scenario specified, benchmarking all scenarios\n"); - for scenario in Scenario::iter() { - let benchmark_result = handle_scenario(scenario, args.output_wat_dir_path.clone()); + for scenario in Scenario::value_variants() { + let benchmark_result = handle_scenario(*scenario, args.output_wat_dir_path.clone()); if let Err(err) = benchmark_result { return Err(err); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 348678ed69..cfd2d59aa4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,13 +4,13 @@ use std::fs::File; use std::io::Write; use std::path::PathBuf; -use strum_macros::{Display, EnumIter, EnumString}; +use clap::ValueEnum; +use std::fmt; -#[derive(Copy, Clone, PartialEq, Eq, Debug, EnumString, Display, EnumIter)] +#[derive(ValueEnum, Copy, Clone, PartialEq, Eq, Debug)] +#[clap(rename_all = "PascalCase")] pub enum Scenario { - #[strum(serialize = "add_i32")] AddI32, - #[strum(serialize = "xor_i32")] XorI32, } @@ -119,7 +119,7 @@ pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> // print wat to file if needed if let Some(output_wat_dir_path) = output_wat_dir_path { let mut output_wat_path = output_wat_dir_path; - output_wat_path.push(format!("{}.wat", scenario)); + output_wat_path.push(format!("{:?}.wat", scenario)); let mut file = File::create(output_wat_path).unwrap(); file.write_all(&wat).unwrap(); } From ed480a006c1926d6cdc44d9273fb13a79134c57e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Mon, 6 Jan 2025 16:34:54 -0300 Subject: [PATCH 04/72] Prints ink per nano second instead of micro second --- arbitrator/tools/stylus_benchmark/src/benchmark.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 3cc2aabb7d..84a9b40af8 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -94,11 +94,11 @@ pub fn benchmark(wat: Vec) -> eyre::Result<()> { durations = durations[l..r].to_vec(); let avg_duration = durations.iter().sum::() / (r - l) as u32; - let avg_ink_spent_per_micro_second = ink_spent.0 / avg_duration.as_micros() as u64; + let avg_ink_spent_per_nano_second = ink_spent.0 / avg_duration.as_nanos() as u64; println!("After discarding top and bottom runs: "); println!( - "avg_duration: {:?}, avg_ink_spent_per_micro_second: {:?}", - avg_duration, avg_ink_spent_per_micro_second + "avg_duration: {:?}, avg_ink_spent_per_nano_second: {:?}", + avg_duration, avg_ink_spent_per_nano_second ); Ok(()) From c6f0ec841c24a6e2a5bd4f1bc9998b2103573c0d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Mon, 6 Jan 2025 16:53:45 -0300 Subject: [PATCH 05/72] CallIndirect benchmark --- .../tools/stylus_benchmark/src/scenario.rs | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index cfd2d59aa4..4b63494191 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,17 +1,17 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use clap::ValueEnum; use std::fs::File; use std::io::Write; use std::path::PathBuf; -use clap::ValueEnum; -use std::fmt; #[derive(ValueEnum, Copy, Clone, PartialEq, Eq, Debug)] #[clap(rename_all = "PascalCase")] pub enum Scenario { AddI32, XorI32, + CallIndirect, } // Programs to be benchmarked have a loop in which several similar operations are executed. @@ -19,7 +19,7 @@ pub enum Scenario { // but not too large to avoid a big program size. // Keeping a small program size is important to better use CPU cache, trying to keep the code in the cache. -fn write_wat_beginning(wat: &mut Vec) { +fn write_common_wat_beginning(wat: &mut Vec) { wat.write_all(b"(module\n").unwrap(); wat.write_all(b" (import \"debug\" \"start_benchmark\" (func $start_benchmark))\n") .unwrap(); @@ -29,12 +29,17 @@ fn write_wat_beginning(wat: &mut Vec) { .unwrap(); wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") .unwrap(); +} + +fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); wat.write_all(b" call $start_benchmark\n").unwrap(); wat.write_all(b" (loop $loop\n").unwrap(); + wat.write_all(b" call $start_benchmark\n") + .unwrap(); } fn write_wat_end( @@ -73,13 +78,19 @@ fn write_wat_end( wat.write_all(b")").unwrap(); } -fn wat(write_wat_ops: fn(&mut Vec, usize)) -> Vec { +fn wat( + write_specific_wat_beginning: fn(&mut Vec), + write_wat_ops: fn(&mut Vec, usize), +) -> Vec { let number_of_loop_iterations = 200_000; let number_of_ops_per_loop_iteration = 2000; let mut wat = Vec::new(); - write_wat_beginning(&mut wat); + write_common_wat_beginning(&mut wat); + write_specific_wat_beginning(&mut wat); + + write_exported_func_beginning(&mut wat); write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); @@ -110,10 +121,33 @@ fn write_xor_i32_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: us wat.write_all(b" drop\n").unwrap(); } +fn write_call_indirect_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (type $nop_func_type (func))\n") + .unwrap(); + wat.write_all(b" (func $nop nop)\n").unwrap(); + wat.write_all(b" (table 1 funcref)\n").unwrap(); + wat.write_all(b" (elem (i32.const 0) $nop)\n") + .unwrap(); +} + +fn write_call_indirect_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" call_indirect (type $nop_func_type)\n") + .unwrap(); + } +} + +fn noop_write_specific_wat_beginning(_: &mut Vec) {} + pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> Vec { let wat = match scenario { - Scenario::AddI32 => wat(write_add_i32_wat_ops), - Scenario::XorI32 => wat(write_xor_i32_wat_ops), + Scenario::AddI32 => wat(noop_write_specific_wat_beginning, write_add_i32_wat_ops), + Scenario::XorI32 => wat(noop_write_specific_wat_beginning, write_xor_i32_wat_ops), + Scenario::CallIndirect => wat( + write_call_indirect_wat_beginning, + write_call_indirect_wat_ops, + ), }; // print wat to file if needed From 6f71e92865bb239f3e3c2a09fc9362bdc96ea128 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 09:41:23 -0300 Subject: [PATCH 06/72] ScenarioWatGenerator trait --- arbitrator/tools/stylus_benchmark/src/main.rs | 1 + .../tools/stylus_benchmark/src/scenario.rs | 89 +++++++------------ .../stylus_benchmark/src/scenarios/add_i32.rs | 15 ++++ .../src/scenarios/call_indirect.rs | 21 +++++ .../stylus_benchmark/src/scenarios/mod.rs | 6 ++ .../stylus_benchmark/src/scenarios/xor_i32.rs | 15 ++++ 6 files changed, 91 insertions(+), 56 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs diff --git a/arbitrator/tools/stylus_benchmark/src/main.rs b/arbitrator/tools/stylus_benchmark/src/main.rs index c2d55ef06c..297acc1867 100644 --- a/arbitrator/tools/stylus_benchmark/src/main.rs +++ b/arbitrator/tools/stylus_benchmark/src/main.rs @@ -3,6 +3,7 @@ mod benchmark; mod scenario; +mod scenarios; use clap::{Parser, ValueEnum}; use scenario::Scenario; diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 4b63494191..a06d380784 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,6 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use crate::scenarios::{add_i32, call_indirect, xor_i32}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -14,6 +15,35 @@ pub enum Scenario { CallIndirect, } +trait ScenarioWatGenerator { + fn write_specific_wat_beginning(&self, wat: &mut Vec); + fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize); +} + +impl ScenarioWatGenerator for Scenario { + fn write_specific_wat_beginning(&self, wat: &mut Vec) { + match self { + Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), + Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), + Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), + } + } + + fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + match self { + Scenario::AddI32 => { + add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); + } + Scenario::XorI32 => { + xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); + } + Scenario::CallIndirect => { + call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration); + } + } + } +} + // Programs to be benchmarked have a loop in which several similar operations are executed. // The number of operations per loop is chosen to be large enough so the overhead related to the loop is negligible, // but not too large to avoid a big program size. @@ -78,21 +108,18 @@ fn write_wat_end( wat.write_all(b")").unwrap(); } -fn wat( - write_specific_wat_beginning: fn(&mut Vec), - write_wat_ops: fn(&mut Vec, usize), -) -> Vec { +pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> Vec { let number_of_loop_iterations = 200_000; let number_of_ops_per_loop_iteration = 2000; let mut wat = Vec::new(); write_common_wat_beginning(&mut wat); - write_specific_wat_beginning(&mut wat); + scenario.write_specific_wat_beginning(&mut wat); write_exported_func_beginning(&mut wat); - write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); + scenario.write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); write_wat_end( &mut wat, @@ -100,56 +127,6 @@ fn wat( number_of_ops_per_loop_iteration, ); - wat.to_vec() -} - -fn write_add_i32_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.add\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} - -fn write_xor_i32_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 12312313\n").unwrap(); - wat.write_all(b" i32.xor\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} - -fn write_call_indirect_wat_beginning(wat: &mut Vec) { - wat.write_all(b" (type $nop_func_type (func))\n") - .unwrap(); - wat.write_all(b" (func $nop nop)\n").unwrap(); - wat.write_all(b" (table 1 funcref)\n").unwrap(); - wat.write_all(b" (elem (i32.const 0) $nop)\n") - .unwrap(); -} - -fn write_call_indirect_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { - for _ in 0..number_of_loop_iterations { - wat.write_all(b" i32.const 0\n").unwrap(); - wat.write_all(b" call_indirect (type $nop_func_type)\n") - .unwrap(); - } -} - -fn noop_write_specific_wat_beginning(_: &mut Vec) {} - -pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> Vec { - let wat = match scenario { - Scenario::AddI32 => wat(noop_write_specific_wat_beginning, write_add_i32_wat_ops), - Scenario::XorI32 => wat(noop_write_specific_wat_beginning, write_xor_i32_wat_ops), - Scenario::CallIndirect => wat( - write_call_indirect_wat_beginning, - write_call_indirect_wat_ops, - ), - }; - // print wat to file if needed if let Some(output_wat_dir_path) = output_wat_dir_path { let mut output_wat_path = output_wat_dir_path; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs new file mode 100644 index 0000000000..dc259357aa --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.add\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs new file mode 100644 index 0000000000..b104720c44 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs @@ -0,0 +1,21 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (type $nop_func_type (func))\n") + .unwrap(); + wat.write_all(b" (func $nop nop)\n").unwrap(); + wat.write_all(b" (table 1 funcref)\n").unwrap(); + wat.write_all(b" (elem (i32.const 0) $nop)\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" call_indirect (type $nop_func_type)\n") + .unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs new file mode 100644 index 0000000000..05cffcd8a3 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -0,0 +1,6 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +pub mod add_i32; +pub mod xor_i32; +pub mod call_indirect; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs new file mode 100644 index 0000000000..bd38fa8b34 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 12312313\n").unwrap(); + wat.write_all(b" i32.xor\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} From d6a92ad8d3a86c7ab7b418a3716120870f77b76e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 09:50:37 -0300 Subject: [PATCH 07/72] If scenario --- .../tools/stylus_benchmark/src/scenario.rs | 15 +++++++-------- .../stylus_benchmark/src/scenarios/if_op.rs | 17 +++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index a06d380784..24e6dfb7f7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{add_i32, call_indirect, xor_i32}; +use crate::scenarios::{add_i32, call_indirect, if_op, xor_i32}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -13,6 +13,7 @@ pub enum Scenario { AddI32, XorI32, CallIndirect, + If, } trait ScenarioWatGenerator { @@ -26,20 +27,18 @@ impl ScenarioWatGenerator for Scenario { Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), + Scenario::If => if_op::write_specific_wat_beginning(wat), } } fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { - Scenario::AddI32 => { - add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); - } - Scenario::XorI32 => { - xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration); - } + Scenario::AddI32 => add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::XorI32 => xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { - call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration); + call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } + Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs new file mode 100644 index 0000000000..71559f78ea --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs @@ -0,0 +1,17 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" (if\n").unwrap(); + wat.write_all(b" (then\n").unwrap(); + wat.write_all(b" nop\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 05cffcd8a3..e4db532417 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,3 +4,4 @@ pub mod add_i32; pub mod xor_i32; pub mod call_indirect; +pub mod if_op; From 84839efdc480bc4dd2c03711d0da61b56ba9e190 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 09:57:57 -0300 Subject: [PATCH 08/72] Fix: removes start_benchmark inside loop --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 24e6dfb7f7..e32a222d64 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -67,8 +67,6 @@ fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" call $start_benchmark\n").unwrap(); wat.write_all(b" (loop $loop\n").unwrap(); - wat.write_all(b" call $start_benchmark\n") - .unwrap(); } fn write_wat_end( From 5ea72c06903582048cebf057bde43b6d5dcdd8ce Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:07:51 -0300 Subject: [PATCH 09/72] GlobalGet --- .../tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/global_get.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e32a222d64..537f14b2ef 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{add_i32, call_indirect, if_op, xor_i32}; +use crate::scenarios::{add_i32, call_indirect, global_get, if_op, xor_i32}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -13,6 +13,7 @@ pub enum Scenario { AddI32, XorI32, CallIndirect, + GlobalGet, If, } @@ -27,6 +28,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), + Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), } } @@ -38,6 +40,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } + Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs new file mode 100644 index 0000000000..f053ad8782 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (global $var i32 (i32.const 10))\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" global.get $var\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e4db532417..c2ad9b7937 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,4 +4,5 @@ pub mod add_i32; pub mod xor_i32; pub mod call_indirect; +pub mod global_get; pub mod if_op; From 8c10174f1fc10d29b2ce7cff0c7549b87f7c6b46 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:11:04 -0300 Subject: [PATCH 10/72] add_i32 -> i32_add, xor_i32 -> i32_xor --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 14 +++++++------- .../src/scenarios/{add_i32.rs => i32_add.rs} | 0 .../src/scenarios/{xor_i32.rs => i32_xor.rs} | 0 .../tools/stylus_benchmark/src/scenarios/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename arbitrator/tools/stylus_benchmark/src/scenarios/{add_i32.rs => i32_add.rs} (100%) rename arbitrator/tools/stylus_benchmark/src/scenarios/{xor_i32.rs => i32_xor.rs} (100%) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 537f14b2ef..9fa15b4199 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{add_i32, call_indirect, global_get, if_op, xor_i32}; +use crate::scenarios::{call_indirect, global_get, i32_add, i32_xor, if_op}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -10,8 +10,8 @@ use std::path::PathBuf; #[derive(ValueEnum, Copy, Clone, PartialEq, Eq, Debug)] #[clap(rename_all = "PascalCase")] pub enum Scenario { - AddI32, - XorI32, + I32Add, + I32Xor, CallIndirect, GlobalGet, If, @@ -25,8 +25,8 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::AddI32 => add_i32::write_specific_wat_beginning(wat), - Scenario::XorI32 => xor_i32::write_specific_wat_beginning(wat), + Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -35,8 +35,8 @@ impl ScenarioWatGenerator for Scenario { fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { - Scenario::AddI32 => add_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::XorI32 => xor_i32::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs similarity index 100% rename from arbitrator/tools/stylus_benchmark/src/scenarios/add_i32.rs rename to arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs similarity index 100% rename from arbitrator/tools/stylus_benchmark/src/scenarios/xor_i32.rs rename to arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index c2ad9b7937..dd0fe57b04 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,8 +1,8 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -pub mod add_i32; -pub mod xor_i32; +pub mod i32_add; +pub mod i32_xor; pub mod call_indirect; pub mod global_get; pub mod if_op; From b47fc570165ff1cbfd077add2d015f538f243caf Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:18:15 -0300 Subject: [PATCH 11/72] GlobalSet --- .../tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/global_set.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9fa15b4199..db91f5cb17 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call_indirect, global_get, i32_add, i32_xor, if_op}; +use crate::scenarios::{call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -14,6 +14,7 @@ pub enum Scenario { I32Xor, CallIndirect, GlobalGet, + GlobalSet, If, } @@ -29,6 +30,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), + Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), } } @@ -41,6 +43,7 @@ impl ScenarioWatGenerator for Scenario { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs new file mode 100644 index 0000000000..1e648d7a85 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (global $var (mut i32) (i32.const 0))\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" i32.const 10\n").unwrap(); + wat.write_all(b" global.set $var\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index dd0fe57b04..60a6368214 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -5,4 +5,5 @@ pub mod i32_add; pub mod i32_xor; pub mod call_indirect; pub mod global_get; +pub mod global_set; pub mod if_op; From 78efd18b687ca278d159914e2adb3bc3f6f5444a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:44:18 -0300 Subject: [PATCH 12/72] Call --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 13 ++++++++----- .../tools/stylus_benchmark/src/scenarios/call.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/call.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index db91f5cb17..58f549bf7b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; +use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -12,6 +12,7 @@ use std::path::PathBuf; pub enum Scenario { I32Add, I32Xor, + Call, CallIndirect, GlobalGet, GlobalSet, @@ -26,24 +27,26 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), - Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), + Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), + Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), } } fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { - Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) } Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs new file mode 100644 index 0000000000..6160001510 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(wat: &mut Vec) { + wat.write_all(b" (func $nop nop)\n").unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" call $nop\n") + .unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 60a6368214..8ac1dc6444 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,6 +3,7 @@ pub mod i32_add; pub mod i32_xor; +pub mod call; pub mod call_indirect; pub mod global_get; pub mod global_set; From 7f2456245ce1cace901734560d2b22dc15717f1d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 10:53:40 -0300 Subject: [PATCH 13/72] Select --- .../tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + .../stylus_benchmark/src/scenarios/select.rs | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/select.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 58f549bf7b..f8e6dd5857 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op}; +use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op, select}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -17,6 +17,7 @@ pub enum Scenario { GlobalGet, GlobalSet, If, + Select, } trait ScenarioWatGenerator { @@ -34,6 +35,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), + Scenario::Select => select::write_specific_wat_beginning(wat), } } @@ -48,6 +50,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8ac1dc6444..3f556a6072 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -8,3 +8,4 @@ pub mod call_indirect; pub mod global_get; pub mod global_set; pub mod if_op; +pub mod select; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs new file mode 100644 index 0000000000..a1487e47d0 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 10\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 20\n").unwrap(); + wat.write_all(b" i32.const 0\n").unwrap(); + wat.write_all(b" select\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} From 4f797c124dca8f673a388dd007f35f5aac9b8ed9 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 11:03:43 -0300 Subject: [PATCH 14/72] I32Eqz --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_eqz.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index f8e6dd5857..9cff07bbcc 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_xor, if_op, select}; +use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_eqz, i32_xor, if_op, select}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -11,6 +11,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32Eqz, I32Xor, Call, CallIndirect, @@ -33,6 +34,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -48,6 +50,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs new file mode 100644 index 0000000000..15752cc800 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.eqz\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 3f556a6072..e2f41c4264 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_eqz; pub mod i32_xor; pub mod call; pub mod call_indirect; From fb4fcf0fabaebb004923ac6c081390251051d558 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 11:05:23 -0300 Subject: [PATCH 15/72] I32Eq --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 ++++++- .../stylus_benchmark/src/scenarios/i32_eq.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9cff07bbcc..3100f6fb1b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,7 +1,9 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use crate::scenarios::{call, call_indirect, global_get, global_set, i32_add, i32_eqz, i32_xor, if_op, select}; +use crate::scenarios::{ + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_xor, if_op, select, +}; use clap::ValueEnum; use std::fs::File; use std::io::Write; @@ -11,6 +13,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32Eq, I32Eqz, I32Xor, Call, @@ -34,6 +37,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -50,6 +54,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs new file mode 100644 index 0000000000..8918f1b2e8 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.eq\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e2f41c4264..decf8aba3a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_eq; pub mod i32_eqz; pub mod i32_xor; pub mod call; From 7bc887bdb05b8471710f00b5e29a4c4c79a49de4 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 11:08:00 -0300 Subject: [PATCH 16/72] I32Ne --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 6 +++++- .../stylus_benchmark/src/scenarios/i32_ne.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3100f6fb1b..996899c566 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ne, i32_xor, if_op, + select, }; use clap::ValueEnum; use std::fs::File; @@ -15,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32Ne, I32Xor, Call, CallIndirect, @@ -39,6 +41,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -56,6 +59,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs new file mode 100644 index 0000000000..139743938c --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.ne\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index decf8aba3a..6bc6f1f19b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_ne; pub mod i32_xor; pub mod call; pub mod call_indirect; From 6e0758e0fe3425b54d3c1d44e33b0896454d8b70 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:10:48 -0300 Subject: [PATCH 17/72] i32_lt_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_lt_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 996899c566..31b700bc03 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ne, i32_xor, if_op, - select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_ne, + i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32LtS, I32Ne, I32Xor, Call, @@ -41,6 +42,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -59,6 +61,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs new file mode 100644 index 0000000000..2adcbcfc4a --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.lt_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 6bc6f1f19b..6d49ab92c0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_lt_s; pub mod i32_ne; pub mod i32_xor; pub mod call; From c6e2b0f31192579ad4d514ef2bff15cae64d143c Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:12:58 -0300 Subject: [PATCH 18/72] i32_lt_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_lt_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 31b700bc03..ce04db71e1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_ne, - i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_lt_u, + i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32LtU, I32LtS, I32Ne, I32Xor, @@ -42,6 +43,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), @@ -61,6 +63,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs new file mode 100644 index 0000000000..59ba86f600 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.lt_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 6d49ab92c0..5c6586d944 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; pub mod i32_xor; From 5f2b8c8dc511efdd44160220ee0ee5b9b9e752ab Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:16:42 -0300 Subject: [PATCH 19/72] stylus_benchmark: i32_gt_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_gt_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index ce04db71e1..edad346def 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_lt_s, i32_lt_u, - i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_lt_s, + i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32GtS, I32LtU, I32LtS, I32Ne, @@ -43,6 +44,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), @@ -63,6 +65,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs new file mode 100644 index 0000000000..59a5c59afc --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.gt_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 5c6586d944..d0b532be4a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_gt_s; pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; From 45468070a6d723ed7b92abf87951a9a24fac8c57 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:19:46 -0300 Subject: [PATCH 20/72] stylus_benchmark: i32_gt_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_gt_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index edad346def..03650d2e7b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_lt_s, - i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, + i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32GtU, I32GtS, I32LtU, I32LtS, @@ -44,6 +45,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), @@ -65,6 +67,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs new file mode 100644 index 0000000000..ae057bc1e6 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.gt_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index d0b532be4a..d21321cfe5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_gt_u; pub mod i32_gt_s; pub mod i32_lt_u; pub mod i32_lt_s; From f802dbe3185da08992768d7374d67a1a6dade079 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:28:26 -0300 Subject: [PATCH 21/72] stylus_benchmark: i32_le_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_le_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 03650d2e7b..958d91a855 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, - i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -18,6 +18,7 @@ pub enum Scenario { I32Eqz, I32GtU, I32GtS, + I32LeS, I32LtU, I32LtS, I32Ne, @@ -47,6 +48,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), + Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), @@ -69,6 +71,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs new file mode 100644 index 0000000000..8e8621a18c --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.le_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index d21321cfe5..303bc81c46 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -6,6 +6,7 @@ pub mod i32_eq; pub mod i32_eqz; pub mod i32_gt_u; pub mod i32_gt_s; +pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; From b7448068e7ac6b36a252989c71009e2347211dab Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:29:55 -0300 Subject: [PATCH 22/72] stylus_benchmark: i32_le_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_le_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 958d91a855..055ca639cb 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, - i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + i32_le_u, i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -18,6 +18,7 @@ pub enum Scenario { I32Eqz, I32GtU, I32GtS, + I32LeU, I32LeS, I32LtU, I32LtS, @@ -48,6 +49,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), + Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), @@ -71,6 +73,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs new file mode 100644 index 0000000000..abf69ca27d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.le_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 303bc81c46..b730155eb0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -6,6 +6,7 @@ pub mod i32_eq; pub mod i32_eqz; pub mod i32_gt_u; pub mod i32_gt_s; +pub mod i32_le_u; pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; From ec72c2a862d7ba63b814c4cf824b8e4a57a37caa Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:31:46 -0300 Subject: [PATCH 23/72] stylus_benchmark: i32.ge_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_ge_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 055ca639cb..e569b11995 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_gt_s, i32_gt_u, - i32_le_u, i32_le_s, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_gt_s, + i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ pub enum Scenario { I32Add, I32Eq, I32Eqz, + I32GeS, I32GtU, I32GtS, I32LeU, @@ -47,6 +48,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), @@ -71,6 +73,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs new file mode 100644 index 0000000000..f2b4cd1b5d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.ge_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index b730155eb0..5591d6535c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_ge_s; pub mod i32_gt_u; pub mod i32_gt_s; pub mod i32_le_u; From 6c0ed575f6e12c0f6ab0b5b6957c619de653d57e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 14:34:25 -0300 Subject: [PATCH 24/72] stylus_benchmark: i32.ge_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_ge_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e569b11995..ce094ce295 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_gt_s, - i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, + i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -17,6 +17,7 @@ pub enum Scenario { I32Eq, I32Eqz, I32GeS, + I32GeU, I32GtU, I32GtS, I32LeU, @@ -49,6 +50,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), + Scenario::I32GeU => i32_ge_u::write_specific_wat_beginning(wat), Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), @@ -74,6 +76,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GeU => i32_ge_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs new file mode 100644 index 0000000000..524fc106d0 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 0\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.ge_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 5591d6535c..a5d813a2bf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_eq; pub mod i32_eqz; +pub mod i32_ge_u; pub mod i32_ge_s; pub mod i32_gt_u; pub mod i32_gt_s; From 0e440c5da9971baf84399ed4f2bb1e23c91bdd34 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 16:12:02 -0300 Subject: [PATCH 25/72] stylus_benchmark: i32.clz --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 8 ++++++-- .../stylus_benchmark/src/scenarios/i32_clz.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index ce094ce295..5cce4f6961 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, - i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_eq, i32_eqz, i32_ge_s, + i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, + select, }; use clap::ValueEnum; use std::fs::File; @@ -14,6 +15,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32Clz, I32Eq, I32Eqz, I32GeS, @@ -47,6 +49,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -73,6 +76,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs new file mode 100644 index 0000000000..398908e09d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.clz\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index a5d813a2bf..c193ef4bb6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_clz; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; From 4ab50eb7153779920144657bc64809c4fb0d578e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 7 Jan 2025 16:15:25 -0300 Subject: [PATCH 26/72] stylus_benchmark: i32.ctz --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 ++++++--- .../stylus_benchmark/src/scenarios/i32_ctz.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 5cce4f6961..feaf4663b3 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_eq, i32_eqz, i32_ge_s, - i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, i32_xor, if_op, - select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, + i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, + i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -16,6 +16,7 @@ use std::path::PathBuf; pub enum Scenario { I32Add, I32Clz, + I32Ctz, I32Eq, I32Eqz, I32GeS, @@ -50,6 +51,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), + Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -77,6 +79,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs new file mode 100644 index 0000000000..822b5a899d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.ctz\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index c193ef4bb6..94ac00ead6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,6 +3,7 @@ pub mod i32_add; pub mod i32_clz; +pub mod i32_ctz; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; From 2f95a47fbae4d4b82f017cb4afa587b64d9c9b2f Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:04:25 -0300 Subject: [PATCH 27/72] stylus_benchmark: i32.popcnt --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_popcnt.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index feaf4663b3..449ccb869f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, - i32_xor, if_op, select, + i32_popcnt, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -28,6 +28,7 @@ pub enum Scenario { I32LtU, I32LtS, I32Ne, + I32Popcnt, I32Xor, Call, CallIndirect, @@ -63,6 +64,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), + Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -91,6 +93,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs new file mode 100644 index 0000000000..294a3a7b93 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1231\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.popcnt\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 94ac00ead6..aece3c7233 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -15,6 +15,7 @@ pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; +pub mod i32_popcnt; pub mod i32_xor; pub mod call; pub mod call_indirect; From badbb5b7193934505914ba1ca92e1b59ea9d86bb Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:07:01 -0300 Subject: [PATCH 28/72] stylus_benchmark: i32.sub --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_sub.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 449ccb869f..9faaff4568 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, - i32_popcnt, i32_xor, if_op, select, + i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -29,6 +29,7 @@ pub enum Scenario { I32LtS, I32Ne, I32Popcnt, + I32Sub, I32Xor, Call, CallIndirect, @@ -65,6 +66,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), + Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -94,6 +96,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs new file mode 100644 index 0000000000..54c0e1f0e5 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 10000000\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.sub\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index aece3c7233..562950a14e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -16,6 +16,7 @@ pub mod i32_lt_u; pub mod i32_lt_s; pub mod i32_ne; pub mod i32_popcnt; +pub mod i32_sub; pub mod i32_xor; pub mod call; pub mod call_indirect; From 92f8756b85adf898ca1adb28165bd3a5427f25f0 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:09:18 -0300 Subject: [PATCH 29/72] stylus_benchmark: i32.mul --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_mul.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9faaff4568..8ef1745215 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,8 +3,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, - i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_ne, - i32_popcnt, i32_sub, i32_xor, if_op, select, + i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, + i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -27,6 +27,7 @@ pub enum Scenario { I32LeS, I32LtU, I32LtS, + I32Mul, I32Ne, I32Popcnt, I32Sub, @@ -64,6 +65,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), + Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), @@ -94,6 +96,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs new file mode 100644 index 0000000000..0e156920a2 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.mul\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 562950a14e..e5542be2e4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -14,6 +14,7 @@ pub mod i32_le_u; pub mod i32_le_s; pub mod i32_lt_u; pub mod i32_lt_s; +pub mod i32_mul; pub mod i32_ne; pub mod i32_popcnt; pub mod i32_sub; From 535a2f544547201d213c200c19d28278aacffda0 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:15:28 -0300 Subject: [PATCH 30/72] stylus_benchmark: i32.div_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 ++++++--- .../stylus_benchmark/src/scenarios/i32_div_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 8ef1745215..017579f9b1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_eq, i32_eqz, - i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, - i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_eq, + i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, + i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -17,6 +17,7 @@ pub enum Scenario { I32Add, I32Clz, I32Ctz, + I32DivS, I32Eq, I32Eqz, I32GeS, @@ -55,6 +56,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), + Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -86,6 +88,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs new file mode 100644 index 0000000000..b9404408f1 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.div_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e5542be2e4..85273d0e31 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_clz; pub mod i32_ctz; +pub mod i32_div_s; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; From c602d733b3b6278fea22ac18d2d2a347311c787a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:17:16 -0300 Subject: [PATCH 31/72] stylus_benchmark: i32.div_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 ++++++--- .../stylus_benchmark/src/scenarios/i32_div_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 017579f9b1..cf055339d2 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_eq, - i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, - i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, + i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, + i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -18,6 +18,7 @@ pub enum Scenario { I32Clz, I32Ctz, I32DivS, + I32DivU, I32Eq, I32Eqz, I32GeS, @@ -57,6 +58,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), + Scenario::I32DivU => i32_div_u::write_specific_wat_beginning(wat), Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), @@ -89,6 +91,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32DivU => i32_div_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs new file mode 100644 index 0000000000..4183dcd82f --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.div_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 85273d0e31..891c7e3e45 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,6 +4,7 @@ pub mod i32_add; pub mod i32_clz; pub mod i32_ctz; +pub mod i32_div_u; pub mod i32_div_s; pub mod i32_eq; pub mod i32_eqz; From 5088d6ed2139a5f24776a7ea28358f832b72c195 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:19:26 -0300 Subject: [PATCH 32/72] stylus_benchmark: i32.rem_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_rem_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index cf055339d2..caf284a63a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, - i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_sub, i32_xor, if_op, select, + i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -32,6 +32,7 @@ pub enum Scenario { I32Mul, I32Ne, I32Popcnt, + I32RemS, I32Sub, I32Xor, Call, @@ -72,6 +73,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), + Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -105,6 +107,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs new file mode 100644 index 0000000000..f9cd4f5fda --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rem_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 891c7e3e45..0e49692bc2 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -4,8 +4,8 @@ pub mod i32_add; pub mod i32_clz; pub mod i32_ctz; -pub mod i32_div_u; pub mod i32_div_s; +pub mod i32_div_u; pub mod i32_eq; pub mod i32_eqz; pub mod i32_ge_u; @@ -19,6 +19,7 @@ pub mod i32_lt_s; pub mod i32_mul; pub mod i32_ne; pub mod i32_popcnt; +pub mod i32_rem_s; pub mod i32_sub; pub mod i32_xor; pub mod call; From a06b8543516865a3aa3edd90efced7653df1f17e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:22:14 -0300 Subject: [PATCH 33/72] stylus_benchmark: i32.rem_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_rem_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index caf284a63a..4fc93ee01b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, - i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_sub, i32_xor, if_op, select, + i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -33,6 +33,7 @@ pub enum Scenario { I32Ne, I32Popcnt, I32RemS, + I32RemU, I32Sub, I32Xor, Call, @@ -74,6 +75,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), + Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -108,6 +110,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs new file mode 100644 index 0000000000..1fc645ae94 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rem_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 0e49692bc2..b79e9ac771 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -20,6 +20,7 @@ pub mod i32_mul; pub mod i32_ne; pub mod i32_popcnt; pub mod i32_rem_s; +pub mod i32_rem_u; pub mod i32_sub; pub mod i32_xor; pub mod call; From 926482319b9efd2aebefff8982ede7a795c570a1 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:23:53 -0300 Subject: [PATCH 34/72] stylus_benchmark: i32.and --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 10 +++++++--- .../stylus_benchmark/src/scenarios/i32_and.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 4fc93ee01b..be632f047e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,10 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_clz, i32_ctz, i32_div_s, i32_div_u, - i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, - i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, + i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, + select, }; use clap::ValueEnum; use std::fs::File; @@ -15,6 +16,7 @@ use std::path::PathBuf; #[clap(rename_all = "PascalCase")] pub enum Scenario { I32Add, + I32And, I32Clz, I32Ctz, I32DivS, @@ -57,6 +59,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), + Scenario::I32And => i32_and::write_specific_wat_beginning(wat), Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), @@ -92,6 +95,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32And => i32_and::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs new file mode 100644 index 0000000000..1ffc094058 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 11111\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1111111\n").unwrap(); + wat.write_all(b" i32.and\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index b79e9ac771..c4ceeabf06 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod i32_add; +pub mod i32_and; pub mod i32_clz; pub mod i32_ctz; pub mod i32_div_s; From eeb1aafa7cf549ebcdb60eb847865f40bc1ae4f9 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:25:44 -0300 Subject: [PATCH 35/72] stylus_benchmark: i32.or --- .../tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_or.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 17 +++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index be632f047e..902a67bf0e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,8 +4,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, i32_xor, if_op, - select, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, + i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -33,6 +33,7 @@ pub enum Scenario { I32LtS, I32Mul, I32Ne, + I32Or, I32Popcnt, I32RemS, I32RemU, @@ -76,6 +77,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), + Scenario::I32Or => i32_or::write_specific_wat_beginning(wat), Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), @@ -112,6 +114,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Or => i32_or::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs new file mode 100644 index 0000000000..7bf3343e56 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 23132213\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 12344\n").unwrap(); + wat.write_all(b" i32.or\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index c4ceeabf06..a28a8a9e77 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,6 +1,10 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +pub mod call; +pub mod call_indirect; +pub mod global_get; +pub mod global_set; pub mod i32_add; pub mod i32_and; pub mod i32_clz; @@ -9,24 +13,21 @@ pub mod i32_div_s; pub mod i32_div_u; pub mod i32_eq; pub mod i32_eqz; -pub mod i32_ge_u; pub mod i32_ge_s; -pub mod i32_gt_u; +pub mod i32_ge_u; pub mod i32_gt_s; -pub mod i32_le_u; +pub mod i32_gt_u; pub mod i32_le_s; -pub mod i32_lt_u; +pub mod i32_le_u; pub mod i32_lt_s; +pub mod i32_lt_u; pub mod i32_mul; pub mod i32_ne; +pub mod i32_or; pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_sub; pub mod i32_xor; -pub mod call; -pub mod call_indirect; -pub mod global_get; -pub mod global_set; pub mod if_op; pub mod select; From 929ad0710e1f489c1848ef2af0994111bbb6032b Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:30:40 -0300 Subject: [PATCH 36/72] stylus_benchmark: i32.shl --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_shl.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 902a67bf0e..d85442beda 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,8 +4,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_sub, - i32_xor, if_op, select, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, + i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -37,6 +37,7 @@ pub enum Scenario { I32Popcnt, I32RemS, I32RemU, + I32Shl, I32Sub, I32Xor, Call, @@ -81,6 +82,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), + Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -118,6 +120,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs new file mode 100644 index 0000000000..b15f446e99 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 1212323\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.shl\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index a28a8a9e77..8395286699 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -27,6 +27,7 @@ pub mod i32_or; pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; +pub mod i32_shl; pub mod i32_sub; pub mod i32_xor; pub mod if_op; From 559f08312980517620bc8ab591c2421b02f3c618 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:43:33 -0300 Subject: [PATCH 37/72] stylus_benchmark: i32.shr_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_shr_s.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index d85442beda..76aa40d4d8 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, - i32_sub, i32_xor, if_op, select, + i32_shr_s, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -38,6 +38,7 @@ pub enum Scenario { I32RemS, I32RemU, I32Shl, + I32ShrS, I32Sub, I32Xor, Call, @@ -83,6 +84,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), + Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -121,6 +123,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs new file mode 100644 index 0000000000..1ac8afa24d --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.shr_s\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8395286699..168d70870b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -28,6 +28,7 @@ pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_shl; +pub mod i32_shr_s; pub mod i32_sub; pub mod i32_xor; pub mod if_op; From f43c579899e19afd3228c158a4d4f41b496b095b Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:44:53 -0300 Subject: [PATCH 38/72] stylus_benchmark: i32.shr_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_shr_u.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 76aa40d4d8..f1db0efe4f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, - i32_shr_s, i32_sub, i32_xor, if_op, select, + i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -39,6 +39,7 @@ pub enum Scenario { I32RemU, I32Shl, I32ShrS, + I32ShrU, I32Sub, I32Xor, Call, @@ -85,6 +86,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), + Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), @@ -124,6 +126,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs new file mode 100644 index 0000000000..5539710521 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.shr_u\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 168d70870b..8d3f402a11 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -29,6 +29,7 @@ pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_shl; pub mod i32_shr_s; +pub mod i32_shr_u; pub mod i32_sub; pub mod i32_xor; pub mod if_op; From 6f9a9f3d978cb1050dcc0e69581ad7a4daab1535 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:46:29 -0300 Subject: [PATCH 39/72] stylus_benchmark: i32.rotl --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 7 +++++-- .../stylus_benchmark/src/scenarios/i32_rotl.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index f1db0efe4f..126d10c099 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,8 +4,8 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_shl, - i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, + i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, + i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -37,6 +37,7 @@ pub enum Scenario { I32Popcnt, I32RemS, I32RemU, + I32Rotl, I32Shl, I32ShrS, I32ShrU, @@ -84,6 +85,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), + Scenario::I32Rotl => i32_rotl::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), @@ -124,6 +126,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Rotl => i32_rotl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs new file mode 100644 index 0000000000..de2edc73f1 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rotl\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8d3f402a11..8ffb9ca0cf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -27,6 +27,7 @@ pub mod i32_or; pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; +pub mod i32_rotl; pub mod i32_shl; pub mod i32_shr_s; pub mod i32_shr_u; From 05c4288ac38d36edd58148acad5abacd5f62b80a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:49:13 -0300 Subject: [PATCH 40/72] stylus_benchmark: i32.rotr --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_rotr.rs | 15 +++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 126d10c099..3083a181a8 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, - i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, + i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -38,6 +38,7 @@ pub enum Scenario { I32RemS, I32RemU, I32Rotl, + I32Rotr, I32Shl, I32ShrS, I32ShrU, @@ -86,6 +87,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), Scenario::I32Rotl => i32_rotl::write_specific_wat_beginning(wat), + Scenario::I32Rotr => i32_rotr::write_specific_wat_beginning(wat), Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), @@ -127,6 +129,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Rotl => i32_rotl::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Rotr => i32_rotr::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs new file mode 100644 index 0000000000..c2ab4e666e --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs @@ -0,0 +1,15 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + wat.write_all(b" i32.const 123123\n").unwrap(); + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.rotr\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8ffb9ca0cf..4ab9d7175f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -28,6 +28,7 @@ pub mod i32_popcnt; pub mod i32_rem_s; pub mod i32_rem_u; pub mod i32_rotl; +pub mod i32_rotr; pub mod i32_shl; pub mod i32_shr_s; pub mod i32_shr_u; From 7bfc31ae709b1c19ca35a764353fdc740d87d962 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 10:56:00 -0300 Subject: [PATCH 41/72] stylus_benchmark: i32.wrap_i64 --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 5 ++++- .../stylus_benchmark/src/scenarios/i32_wrap_i64.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3083a181a8..9d8061faa4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -5,7 +5,7 @@ use crate::scenarios::{ call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, - i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_xor, if_op, select, + i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_wrap_i64, i32_xor, if_op, select, }; use clap::ValueEnum; use std::fs::File; @@ -43,6 +43,7 @@ pub enum Scenario { I32ShrS, I32ShrU, I32Sub, + I32WrapI64, I32Xor, Call, CallIndirect, @@ -92,6 +93,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), + Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), @@ -134,6 +136,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32WrapI64 => i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs new file mode 100644 index 0000000000..2634615447 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_wat_beginning(_: &mut Vec) {} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" i64.const 123123\n").unwrap(); + wat.write_all(b" i32.wrap_i64\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 4ab9d7175f..7088335107 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -33,6 +33,7 @@ pub mod i32_shl; pub mod i32_shr_s; pub mod i32_shr_u; pub mod i32_sub; +pub mod i32_wrap_i64; pub mod i32_xor; pub mod if_op; pub mod select; From b0a8e387ca50cb7618de505fde751148914bb5d0 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 15:45:21 -0300 Subject: [PATCH 42/72] instruction_with_2_args_1_return --- .../tools/stylus_benchmark/src/scenario.rs | 260 ++++++++++++++---- .../stylus_benchmark/src/scenarios/i32_add.rs | 15 - .../stylus_benchmark/src/scenarios/i32_and.rs | 15 - .../src/scenarios/i32_div_s.rs | 15 - .../src/scenarios/i32_div_u.rs | 15 - .../stylus_benchmark/src/scenarios/i32_eq.rs | 15 - .../src/scenarios/i32_ge_s.rs | 15 - .../src/scenarios/i32_ge_u.rs | 15 - .../src/scenarios/i32_gt_s.rs | 15 - .../src/scenarios/i32_gt_u.rs | 15 - .../src/scenarios/i32_le_s.rs | 15 - .../src/scenarios/i32_le_u.rs | 15 - .../src/scenarios/i32_lt_s.rs | 15 - .../src/scenarios/i32_lt_u.rs | 15 - .../stylus_benchmark/src/scenarios/i32_mul.rs | 15 - .../stylus_benchmark/src/scenarios/i32_ne.rs | 15 - .../stylus_benchmark/src/scenarios/i32_or.rs | 15 - .../src/scenarios/i32_rem_s.rs | 15 - .../src/scenarios/i32_rem_u.rs | 15 - .../src/scenarios/i32_rotl.rs | 15 - .../src/scenarios/i32_rotr.rs | 15 - .../stylus_benchmark/src/scenarios/i32_shl.rs | 15 - .../src/scenarios/i32_shr_s.rs | 15 - .../src/scenarios/i32_shr_u.rs | 15 - .../stylus_benchmark/src/scenarios/i32_sub.rs | 15 - .../stylus_benchmark/src/scenarios/i32_xor.rs | 15 - .../instruction_with_2_args_1_return.rs | 13 + .../stylus_benchmark/src/scenarios/mod.rs | 26 +- 28 files changed, 219 insertions(+), 455 deletions(-) delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 9d8061faa4..c70a5ba9e4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,10 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_add, i32_and, i32_clz, i32_ctz, i32_div_s, - i32_div_u, i32_eq, i32_eqz, i32_ge_s, i32_ge_u, i32_gt_s, i32_gt_u, i32_le_s, i32_le_u, - i32_lt_s, i32_lt_u, i32_mul, i32_ne, i32_or, i32_popcnt, i32_rem_s, i32_rem_u, i32_rotl, - i32_rotr, i32_shl, i32_shr_s, i32_shr_u, i32_sub, i32_wrap_i64, i32_xor, if_op, select, + call, call_indirect, global_get, global_set, i32_eqz, i32_popcnt, i32_wrap_i64, if_op, i32_ctz, i32_clz, + instruction_with_2_args_1_return, select, }; use clap::ValueEnum; use std::fs::File; @@ -65,36 +63,36 @@ impl ScenarioWatGenerator for Scenario { Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), - Scenario::I32Add => i32_add::write_specific_wat_beginning(wat), - Scenario::I32And => i32_and::write_specific_wat_beginning(wat), + Scenario::I32Add => {} + Scenario::I32And => {} Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), - Scenario::I32DivS => i32_div_s::write_specific_wat_beginning(wat), - Scenario::I32DivU => i32_div_u::write_specific_wat_beginning(wat), - Scenario::I32Eq => i32_eq::write_specific_wat_beginning(wat), + Scenario::I32DivS => {} + Scenario::I32DivU => {} + Scenario::I32Eq => {} Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), - Scenario::I32GeS => i32_ge_s::write_specific_wat_beginning(wat), - Scenario::I32GeU => i32_ge_u::write_specific_wat_beginning(wat), - Scenario::I32GtU => i32_gt_u::write_specific_wat_beginning(wat), - Scenario::I32GtS => i32_gt_s::write_specific_wat_beginning(wat), - Scenario::I32LeU => i32_le_u::write_specific_wat_beginning(wat), - Scenario::I32LeS => i32_le_s::write_specific_wat_beginning(wat), - Scenario::I32LtU => i32_lt_u::write_specific_wat_beginning(wat), - Scenario::I32LtS => i32_lt_s::write_specific_wat_beginning(wat), - Scenario::I32Mul => i32_mul::write_specific_wat_beginning(wat), - Scenario::I32Ne => i32_ne::write_specific_wat_beginning(wat), - Scenario::I32Or => i32_or::write_specific_wat_beginning(wat), + Scenario::I32GeS => {} + Scenario::I32GeU => {} + Scenario::I32GtU => {} + Scenario::I32GtS => {} + Scenario::I32LeU => {} + Scenario::I32LeS => {} + Scenario::I32LtU => {} + Scenario::I32LtS => {} + Scenario::I32Mul => {} + Scenario::I32Ne => {} + Scenario::I32Or => {} Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), - Scenario::I32RemS => i32_rem_s::write_specific_wat_beginning(wat), - Scenario::I32RemU => i32_rem_u::write_specific_wat_beginning(wat), - Scenario::I32Rotl => i32_rotl::write_specific_wat_beginning(wat), - Scenario::I32Rotr => i32_rotr::write_specific_wat_beginning(wat), - Scenario::I32Shl => i32_shl::write_specific_wat_beginning(wat), - Scenario::I32ShrS => i32_shr_s::write_specific_wat_beginning(wat), - Scenario::I32ShrU => i32_shr_u::write_specific_wat_beginning(wat), - Scenario::I32Sub => i32_sub::write_specific_wat_beginning(wat), + Scenario::I32RemS => {} + Scenario::I32RemU => {} + Scenario::I32Rotl => {} + Scenario::I32Rotr => {} + Scenario::I32Shl => {} + Scenario::I32ShrS => {} + Scenario::I32ShrU => {} + Scenario::I32Sub => {} Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), - Scenario::I32Xor => i32_xor::write_specific_wat_beginning(wat), + Scenario::I32Xor => {} Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::Select => select::write_specific_wat_beginning(wat), } @@ -108,36 +106,188 @@ impl ScenarioWatGenerator for Scenario { } Scenario::GlobalGet => global_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::GlobalSet => global_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Add => i32_add::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32And => i32_and::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Add => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.add", + 0, + 1, + ), + Scenario::I32And => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.and", + 0, + 1, + ), Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32DivS => i32_div_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32DivU => i32_div_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Eq => i32_eq::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.div_s", + 1, + 1, + ), + Scenario::I32DivU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.div_u", + 1, + 1, + ), + Scenario::I32Eq => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.eq", + 0, + 1, + ), Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GeS => i32_ge_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GeU => i32_ge_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GtU => i32_gt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32GtS => i32_gt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LeU => i32_le_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LeS => i32_le_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LtU => i32_lt_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32LtS => i32_lt_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Mul => i32_mul::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Ne => i32_ne::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Or => i32_or::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ge_s", + 0, + 1, + ), + Scenario::I32GeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ge_u", + 0, + 1, + ), + Scenario::I32GtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.gt_u", + 0, + 1, + ), + Scenario::I32GtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.gt_s", + 0, + 1, + ), + Scenario::I32LeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.le_u", + 0, + 1, + ), + Scenario::I32LeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.le_s", + 0, + 1, + ), + Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.lt_u", + 0, + 1, + ), + Scenario::I32LtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.lt_s", + 0, + 1, + ), + Scenario::I32Mul => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.mul", + 0, + 1, + ), + Scenario::I32Ne => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ne", + 0, + 1, + ), + Scenario::I32Or => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.or", + 0, + 1, + ), Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32RemS => i32_rem_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32RemU => i32_rem_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Rotl => i32_rotl::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Rotr => i32_rotr::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Shl => i32_shl::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32ShrS => i32_shr_s::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32ShrU => i32_shr_u::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Sub => i32_sub::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32WrapI64 => i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Xor => i32_xor::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rem_s", + 1, + 1, + ), + Scenario::I32RemU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rem_u", + 1, + 1, + ), + Scenario::I32Rotl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rotl", + 11231, + 1, + ), + Scenario::I32Rotr => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.rotr", + 11231, + 1, + ), + Scenario::I32Shl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.shl", + 11231, + 1, + ), + Scenario::I32ShrS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.shr_s", + 11231, + 1, + ), + Scenario::I32ShrU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.shr_u", + 11231, + 1, + ), + Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.sub", + 11231, + 1, + ), + Scenario::I32WrapI64 => { + i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration) + } + Scenario::I32Xor => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.xor", + 11231, + 13242, + ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs deleted file mode 100644 index dc259357aa..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_add.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.add\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs deleted file mode 100644 index 1ffc094058..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_and.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 11111\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1111111\n").unwrap(); - wat.write_all(b" i32.and\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs deleted file mode 100644 index b9404408f1..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.div_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs deleted file mode 100644 index 4183dcd82f..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_div_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.div_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs deleted file mode 100644 index 8918f1b2e8..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eq.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.eq\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs deleted file mode 100644 index f2b4cd1b5d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.ge_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs deleted file mode 100644 index 524fc106d0..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ge_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.ge_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs deleted file mode 100644 index 59a5c59afc..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.gt_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs deleted file mode 100644 index ae057bc1e6..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_gt_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.gt_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs deleted file mode 100644 index 8e8621a18c..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.le_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs deleted file mode 100644 index abf69ca27d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_le_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.le_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs deleted file mode 100644 index 2adcbcfc4a..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.lt_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs deleted file mode 100644 index 59ba86f600..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_lt_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.lt_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs deleted file mode 100644 index 0e156920a2..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_mul.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.mul\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs deleted file mode 100644 index 139743938c..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ne.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.ne\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs deleted file mode 100644 index 7bf3343e56..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_or.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 23132213\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 12344\n").unwrap(); - wat.write_all(b" i32.or\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs deleted file mode 100644 index f9cd4f5fda..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rem_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs deleted file mode 100644 index 1fc645ae94..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rem_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rem_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs deleted file mode 100644 index de2edc73f1..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotl.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rotl\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs deleted file mode 100644 index c2ab4e666e..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_rotr.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.rotr\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs deleted file mode 100644 index b15f446e99..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shl.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1212323\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.shl\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs deleted file mode 100644 index 1ac8afa24d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_s.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.shr_s\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs deleted file mode 100644 index 5539710521..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_shr_u.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 123123\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.shr_u\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs deleted file mode 100644 index 54c0e1f0e5..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_sub.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 10000000\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 1\n").unwrap(); - wat.write_all(b" i32.sub\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs deleted file mode 100644 index bd38fa8b34..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_xor.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 12312313\n").unwrap(); - wat.write_all(b" i32.xor\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs new file mode 100644 index 0000000000..610bf33c8a --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -0,0 +1,13 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, first_arg: usize, second_arg: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" i32.const {}\n", first_arg).as_bytes()).unwrap(); + wat.write_all(format!(" i32.const {}\n", second_arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 7088335107..f217ca80ea 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -5,35 +5,11 @@ pub mod call; pub mod call_indirect; pub mod global_get; pub mod global_set; -pub mod i32_add; -pub mod i32_and; pub mod i32_clz; pub mod i32_ctz; -pub mod i32_div_s; -pub mod i32_div_u; -pub mod i32_eq; pub mod i32_eqz; -pub mod i32_ge_s; -pub mod i32_ge_u; -pub mod i32_gt_s; -pub mod i32_gt_u; -pub mod i32_le_s; -pub mod i32_le_u; -pub mod i32_lt_s; -pub mod i32_lt_u; -pub mod i32_mul; -pub mod i32_ne; -pub mod i32_or; pub mod i32_popcnt; -pub mod i32_rem_s; -pub mod i32_rem_u; -pub mod i32_rotl; -pub mod i32_rotr; -pub mod i32_shl; -pub mod i32_shr_s; -pub mod i32_shr_u; -pub mod i32_sub; pub mod i32_wrap_i64; -pub mod i32_xor; pub mod if_op; +pub mod instruction_with_2_args_1_return; pub mod select; From b122e7088539c97a92322c9ab5b8c73813e68e11 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 16:46:50 -0300 Subject: [PATCH 43/72] instruction_with_1_arg_1_return --- .../tools/stylus_benchmark/src/scenario.rs | 40 ++++++++++++++----- .../stylus_benchmark/src/scenarios/i32_ctz.rs | 14 ------- .../stylus_benchmark/src/scenarios/i32_eqz.rs | 14 ------- .../src/scenarios/i32_popcnt.rs | 14 ------- ....rs => instruction_with_1_arg_1_return.rs} | 10 ++--- .../stylus_benchmark/src/scenarios/mod.rs | 5 +-- 6 files changed, 35 insertions(+), 62 deletions(-) delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs rename arbitrator/tools/stylus_benchmark/src/scenarios/{i32_clz.rs => instruction_with_1_arg_1_return.rs} (50%) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index c70a5ba9e4..20db7496fe 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,8 +2,8 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_eqz, i32_popcnt, i32_wrap_i64, if_op, i32_ctz, i32_clz, - instruction_with_2_args_1_return, select, + call, call_indirect, global_get, global_set, i32_wrap_i64, if_op, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, select, }; use clap::ValueEnum; use std::fs::File; @@ -65,12 +65,12 @@ impl ScenarioWatGenerator for Scenario { Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), Scenario::I32Add => {} Scenario::I32And => {} - Scenario::I32Clz => i32_clz::write_specific_wat_beginning(wat), - Scenario::I32Ctz => i32_ctz::write_specific_wat_beginning(wat), + Scenario::I32Clz => {} + Scenario::I32Ctz => {} Scenario::I32DivS => {} Scenario::I32DivU => {} Scenario::I32Eq => {} - Scenario::I32Eqz => i32_eqz::write_specific_wat_beginning(wat), + Scenario::I32Eqz => {} Scenario::I32GeS => {} Scenario::I32GeU => {} Scenario::I32GtU => {} @@ -82,7 +82,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Mul => {} Scenario::I32Ne => {} Scenario::I32Or => {} - Scenario::I32Popcnt => i32_popcnt::write_specific_wat_beginning(wat), + Scenario::I32Popcnt => {} Scenario::I32RemS => {} Scenario::I32RemU => {} Scenario::I32Rotl => {} @@ -120,8 +120,18 @@ impl ScenarioWatGenerator for Scenario { 0, 1, ), - Scenario::I32Clz => i32_clz::write_wat_ops(wat, number_of_ops_per_loop_iteration), - Scenario::I32Ctz => i32_ctz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Clz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.clz", + 1231, + ), + Scenario::I32Ctz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.ctz", + 1231, + ), Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -143,7 +153,12 @@ impl ScenarioWatGenerator for Scenario { 0, 1, ), - Scenario::I32Eqz => i32_eqz::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Eqz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.eqz", + 1231, + ), Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -221,7 +236,12 @@ impl ScenarioWatGenerator for Scenario { 0, 1, ), - Scenario::I32Popcnt => i32_popcnt::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::I32Popcnt => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + "i32.popcnt", + 1231, + ), Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs deleted file mode 100644 index 822b5a899d..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_ctz.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.ctz\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs deleted file mode 100644 index 15752cc800..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_eqz.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 0\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.eqz\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs deleted file mode 100644 index 294a3a7b93..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_popcnt.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.popcnt\n").unwrap(); - } - wat.write_all(b" drop\n").unwrap(); -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs similarity index 50% rename from arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs rename to arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 398908e09d..fd2d749a39 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_clz.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -3,12 +3,10 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 1231\n").unwrap(); +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, arg: usize) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.clz\n").unwrap(); + wat.write_all(format!(" i32.const {}\n", arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(b" drop\n").unwrap(); } - wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index f217ca80ea..29a2953018 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -5,11 +5,8 @@ pub mod call; pub mod call_indirect; pub mod global_get; pub mod global_set; -pub mod i32_clz; -pub mod i32_ctz; -pub mod i32_eqz; -pub mod i32_popcnt; pub mod i32_wrap_i64; pub mod if_op; pub mod instruction_with_2_args_1_return; +pub mod instruction_with_1_arg_1_return; pub mod select; From fbecd0fac8edcb49cdb719b7eb72c3b6adf68f9e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 17:09:19 -0300 Subject: [PATCH 44/72] Adds DataType to intruction_with_1_arg_1_return --- arbitrator/tools/stylus_benchmark/Cargo.lock | 27 +++++++++++++++++++ arbitrator/tools/stylus_benchmark/Cargo.toml | 2 ++ .../tools/stylus_benchmark/src/scenario.rs | 14 ++++++---- .../src/scenarios/data_type.rs | 12 +++++++++ .../instruction_with_1_arg_1_return.rs | 7 ++--- .../stylus_benchmark/src/scenarios/mod.rs | 3 ++- 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs diff --git a/arbitrator/tools/stylus_benchmark/Cargo.lock b/arbitrator/tools/stylus_benchmark/Cargo.lock index f1b9fb4996..1168b45a2a 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.lock +++ b/arbitrator/tools/stylus_benchmark/Cargo.lock @@ -1663,6 +1663,12 @@ dependencies = [ "semver", ] +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + [[package]] name = "ryu" version = "1.0.18" @@ -1903,6 +1909,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.87", +] + [[package]] name = "stylus" version = "0.1.0" @@ -1939,6 +1964,8 @@ dependencies = [ "eyre", "jit", "prover", + "strum", + "strum_macros", "stylus", "wasmer", "wasmer-compiler-cranelift", diff --git a/arbitrator/tools/stylus_benchmark/Cargo.toml b/arbitrator/tools/stylus_benchmark/Cargo.toml index 4f9ed74d46..e193fc0ca8 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.toml +++ b/arbitrator/tools/stylus_benchmark/Cargo.toml @@ -12,3 +12,5 @@ arbutil = { path = "../../arbutil/" } prover = { path = "../../prover/", default-features = false, features = ["native"] } stylus = { path = "../../stylus/", default-features = false } clap = { version = "4.4.8", features = ["derive"] } +strum = "0.26" +strum_macros = "0.26" diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 20db7496fe..a6ed2ff05f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, global_get, global_set, i32_wrap_i64, if_op, + call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, select, }; use clap::ValueEnum; @@ -123,13 +123,15 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Clz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.clz", + DataType::I32, + "clz", 1231, ), Scenario::I32Ctz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ctz", + DataType::I32, + "ctz", 1231, ), Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( @@ -156,7 +158,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Eqz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.eqz", + DataType::I32, + "eqz", 1231, ), Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( @@ -239,7 +242,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Popcnt => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.popcnt", + DataType::I32, + "popcnt", 1231, ), Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs new file mode 100644 index 0000000000..a3bd2228c7 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -0,0 +1,12 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use strum_macros::{Display, EnumString}; +use strum; + +#[derive(Debug, Display, EnumString)] +#[strum(serialize_all = "lowercase")] +pub enum DataType { + I32, + I64 +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index fd2d749a39..9e59adf41a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -2,11 +2,12 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; +use crate::scenarios::data_type::DataType; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, arg: usize) { +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str, arg: usize) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" i32.const {}\n", arg).as_bytes()).unwrap(); - wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()).unwrap(); wat.write_all(b" drop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 29a2953018..7dd8bf31cf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,10 +3,11 @@ pub mod call; pub mod call_indirect; +pub mod data_type; pub mod global_get; pub mod global_set; pub mod i32_wrap_i64; pub mod if_op; -pub mod instruction_with_2_args_1_return; pub mod instruction_with_1_arg_1_return; +pub mod instruction_with_2_args_1_return; pub mod select; From 134c64acec261b22912c19d0ffd842a9ec5efb3a Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Wed, 8 Jan 2025 17:19:35 -0300 Subject: [PATCH 45/72] Adds DataType to intruction_with_2_args_1_return --- .../tools/stylus_benchmark/src/scenario.rs | 75 ++++++++++++------- .../instruction_with_2_args_1_return.rs | 19 ++++- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index a6ed2ff05f..c7b7bb953d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -109,14 +109,16 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Add => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.add", + DataType::I32, + "add", 0, 1, ), Scenario::I32And => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.and", + DataType::I32, + "and", 0, 1, ), @@ -137,21 +139,24 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.div_s", + DataType::I32, + "div_s", 1, 1, ), Scenario::I32DivU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.div_u", + DataType::I32, + "div_u", 1, 1, ), Scenario::I32Eq => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.eq", + DataType::I32, + "eq", 0, 1, ), @@ -165,77 +170,88 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ge_s", + DataType::I32, + "ge_s", 0, 1, ), Scenario::I32GeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ge_u", + DataType::I32, + "ge_u", 0, 1, ), Scenario::I32GtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.gt_u", + DataType::I32, + "gt_u", 0, 1, ), Scenario::I32GtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.gt_s", + DataType::I32, + "gt_s", 0, 1, ), Scenario::I32LeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.le_u", + DataType::I32, + "le_u", 0, 1, ), Scenario::I32LeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.le_s", + DataType::I32, + "le_s", 0, 1, ), Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.lt_u", + DataType::I32, + "lt_u", 0, 1, ), Scenario::I32LtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.lt_s", + DataType::I32, + "lt_s", 0, 1, ), Scenario::I32Mul => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.mul", + DataType::I32, + "mul", 0, 1, ), Scenario::I32Ne => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.ne", + DataType::I32, + "ne", 0, 1, ), Scenario::I32Or => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.or", + DataType::I32, + "or", 0, 1, ), @@ -249,56 +265,64 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rem_s", + DataType::I32, + "rem_s", 1, 1, ), Scenario::I32RemU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rem_u", + DataType::I32, + "rem_u", 1, 1, ), Scenario::I32Rotl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rotl", + DataType::I32, + "rotl", 11231, 1, ), Scenario::I32Rotr => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.rotr", + DataType::I32, + "rotr", 11231, 1, ), Scenario::I32Shl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.shl", + DataType::I32, + "shl", 11231, 1, ), Scenario::I32ShrS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.shr_s", + DataType::I32, + "shr_s", 11231, 1, ), Scenario::I32ShrU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.shr_u", + DataType::I32, + "shr_u", 11231, 1, ), Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.sub", + DataType::I32, + "sub", 11231, 1, ), @@ -308,7 +332,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Xor => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, - "i32.xor", + DataType::I32, + "xor", 11231, 13242, ), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index 610bf33c8a..7e8b893a5c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -2,12 +2,23 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; +use crate::scenarios::data_type::DataType; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, instruction: &str, first_arg: usize, second_arg: usize) { +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, + instruction: &str, + first_arg: usize, + second_arg: usize, +) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" i32.const {}\n", first_arg).as_bytes()).unwrap(); - wat.write_all(format!(" i32.const {}\n", second_arg).as_bytes()).unwrap(); - wat.write_all(format!(" {}\n", instruction).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, first_arg).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, second_arg).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + .unwrap(); wat.write_all(b" drop\n").unwrap(); } } From f19ddc5da3cc8efac83d4484a1605f87b16eff4e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:31:33 -0300 Subject: [PATCH 46/72] stylus_benchmark: generate random values --- arbitrator/tools/stylus_benchmark/Cargo.lock | 1 + arbitrator/tools/stylus_benchmark/Cargo.toml | 1 + .../tools/stylus_benchmark/src/scenario.rs | 54 ------------------- .../src/scenarios/data_type.rs | 16 +++++- .../instruction_with_1_arg_1_return.rs | 6 +-- .../instruction_with_2_args_1_return.rs | 8 ++- 6 files changed, 23 insertions(+), 63 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/Cargo.lock b/arbitrator/tools/stylus_benchmark/Cargo.lock index 1168b45a2a..44a838fd15 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.lock +++ b/arbitrator/tools/stylus_benchmark/Cargo.lock @@ -1964,6 +1964,7 @@ dependencies = [ "eyre", "jit", "prover", + "rand", "strum", "strum_macros", "stylus", diff --git a/arbitrator/tools/stylus_benchmark/Cargo.toml b/arbitrator/tools/stylus_benchmark/Cargo.toml index e193fc0ca8..20d169e3e5 100644 --- a/arbitrator/tools/stylus_benchmark/Cargo.toml +++ b/arbitrator/tools/stylus_benchmark/Cargo.toml @@ -14,3 +14,4 @@ stylus = { path = "../../stylus/", default-features = false } clap = { version = "4.4.8", features = ["derive"] } strum = "0.26" strum_macros = "0.26" +rand = "0.8.5" diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index c7b7bb953d..3f7837a1cf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -111,220 +111,168 @@ impl ScenarioWatGenerator for Scenario { number_of_ops_per_loop_iteration, DataType::I32, "add", - 0, - 1, ), Scenario::I32And => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "and", - 0, - 1, ), Scenario::I32Clz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "clz", - 1231, ), Scenario::I32Ctz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ctz", - 1231, ), Scenario::I32DivS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "div_s", - 1, - 1, ), Scenario::I32DivU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "div_u", - 1, - 1, ), Scenario::I32Eq => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "eq", - 0, - 1, ), Scenario::I32Eqz => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "eqz", - 1231, ), Scenario::I32GeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ge_s", - 0, - 1, ), Scenario::I32GeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ge_u", - 0, - 1, ), Scenario::I32GtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "gt_u", - 0, - 1, ), Scenario::I32GtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "gt_s", - 0, - 1, ), Scenario::I32LeU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "le_u", - 0, - 1, ), Scenario::I32LeS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "le_s", - 0, - 1, ), Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "lt_u", - 0, - 1, ), Scenario::I32LtS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "lt_s", - 0, - 1, ), Scenario::I32Mul => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "mul", - 0, - 1, ), Scenario::I32Ne => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "ne", - 0, - 1, ), Scenario::I32Or => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "or", - 0, - 1, ), Scenario::I32Popcnt => instruction_with_1_arg_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "popcnt", - 1231, ), Scenario::I32RemS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rem_s", - 1, - 1, ), Scenario::I32RemU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rem_u", - 1, - 1, ), Scenario::I32Rotl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rotl", - 11231, - 1, ), Scenario::I32Rotr => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "rotr", - 11231, - 1, ), Scenario::I32Shl => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "shl", - 11231, - 1, ), Scenario::I32ShrS => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "shr_s", - 11231, - 1, ), Scenario::I32ShrU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "shr_u", - 11231, - 1, ), Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, DataType::I32, "sub", - 11231, - 1, ), Scenario::I32WrapI64 => { i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration) @@ -334,8 +282,6 @@ impl ScenarioWatGenerator for Scenario { number_of_ops_per_loop_iteration, DataType::I32, "xor", - 11231, - 13242, ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index a3bd2228c7..dda7ad80b7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -1,8 +1,8 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use rand::Rng; use strum_macros::{Display, EnumString}; -use strum; #[derive(Debug, Display, EnumString)] #[strum(serialize_all = "lowercase")] @@ -10,3 +10,17 @@ pub enum DataType { I32, I64 } + +pub trait Rand { + fn gen(&self) -> usize; +} + +impl Rand for DataType { + fn gen(&self) -> usize { + let mut rng = rand::thread_rng(); + match self { + DataType::I32 => rng.gen::().try_into().unwrap(), + DataType::I64 => rng.gen::().try_into().unwrap(), + } + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 9e59adf41a..44421bb756 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -2,11 +2,11 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; -use crate::scenarios::data_type::DataType; +use crate::scenarios::data_type::{DataType, Rand}; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str, arg: usize) { +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", data_type, arg).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()).unwrap(); wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()).unwrap(); wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index 7e8b893a5c..470b994caa 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -2,20 +2,18 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; -use crate::scenarios::data_type::DataType; +use crate::scenarios::data_type::{DataType, Rand}; pub fn write_wat_ops( wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str, - first_arg: usize, - second_arg: usize, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", data_type, first_arg).as_bytes()) + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) .unwrap(); - wat.write_all(format!(" {}.const {}\n", data_type, second_arg).as_bytes()) + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) .unwrap(); wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) .unwrap(); From 9413683b1fff455ac50181015a70f2d0b2013db3 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:45:03 -0300 Subject: [PATCH 47/72] stylus_benchmark: local.get --- .../tools/stylus_benchmark/src/scenario.rs | 53 ++++++++++++++++++- .../src/scenarios/local_get.rs | 17 ++++++ .../stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3f7837a1cf..3723e4ae17 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, select, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, select, }; use clap::ValueEnum; use std::fs::File; @@ -48,11 +48,13 @@ pub enum Scenario { GlobalGet, GlobalSet, If, + LocalGet, Select, } trait ScenarioWatGenerator { fn write_specific_wat_beginning(&self, wat: &mut Vec); + fn write_specific_exported_func_beginning(&self, wat: &mut Vec); fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize); } @@ -94,10 +96,53 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), Scenario::I32Xor => {} Scenario::If => if_op::write_specific_wat_beginning(wat), + Scenario::LocalGet => {}, Scenario::Select => select::write_specific_wat_beginning(wat), } } + fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { + match self { + Scenario::Call => {} + Scenario::CallIndirect => {} + Scenario::GlobalGet => {} + Scenario::GlobalSet => {} + Scenario::I32Add => {} + Scenario::I32And => {} + Scenario::I32Clz => {} + Scenario::I32Ctz => {} + Scenario::I32DivS => {} + Scenario::I32DivU => {} + Scenario::I32Eq => {} + Scenario::I32Eqz => {} + Scenario::I32GeS => {} + Scenario::I32GeU => {} + Scenario::I32GtU => {} + Scenario::I32GtS => {} + Scenario::I32LeU => {} + Scenario::I32LeS => {} + Scenario::I32LtU => {} + Scenario::I32LtS => {} + Scenario::I32Mul => {} + Scenario::I32Ne => {} + Scenario::I32Or => {} + Scenario::I32Popcnt => {} + Scenario::I32RemS => {} + Scenario::I32RemU => {} + Scenario::I32Rotl => {} + Scenario::I32Rotr => {} + Scenario::I32Shl => {} + Scenario::I32ShrS => {} + Scenario::I32ShrU => {} + Scenario::I32Sub => {} + Scenario::I32WrapI64 => {} + Scenario::I32Xor => {} + Scenario::If => {} + Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), + Scenario::Select => {} + } + } + fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), @@ -284,6 +329,7 @@ impl ScenarioWatGenerator for Scenario { "xor", ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } @@ -309,9 +355,10 @@ fn write_common_wat_beginning(wat: &mut Vec) { fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); +} +fn write_loop_beginning(wat: &mut Vec) { wat.write_all(b" call $start_benchmark\n").unwrap(); - wat.write_all(b" (loop $loop\n").unwrap(); } @@ -361,6 +408,8 @@ pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option) -> scenario.write_specific_wat_beginning(&mut wat); write_exported_func_beginning(&mut wat); + scenario.write_specific_exported_func_beginning(&mut wat); + write_loop_beginning(&mut wat); scenario.write_wat_ops(&mut wat, number_of_ops_per_loop_iteration); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs new file mode 100644 index 0000000000..edd304c007 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs @@ -0,0 +1,17 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_exported_func_beginning(wat: &mut Vec) { + wat.write_all(b" (local $var i32)\n").unwrap(); + wat.write_all(b" (local.set $var (i32.const 10))\n") + .unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" local.get $var\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 7dd8bf31cf..335de00ed6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -10,4 +10,5 @@ pub mod i32_wrap_i64; pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; +pub mod local_get; pub mod select; From a0aeffe1963c57049c3058dd2c5065a52b75e99b Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:48:52 -0300 Subject: [PATCH 48/72] stylus_benchmark: local.set --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 9 +++++++-- .../stylus_benchmark/src/scenarios/local_set.rs | 14 ++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 3723e4ae17..e6a6212d0f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,8 @@ use crate::scenarios::{ call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, select, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, + select, }; use clap::ValueEnum; use std::fs::File; @@ -49,6 +50,7 @@ pub enum Scenario { GlobalSet, If, LocalGet, + LocalSet, Select, } @@ -96,7 +98,8 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), Scenario::I32Xor => {} Scenario::If => if_op::write_specific_wat_beginning(wat), - Scenario::LocalGet => {}, + Scenario::LocalGet => {} + Scenario::LocalSet => {} Scenario::Select => select::write_specific_wat_beginning(wat), } } @@ -139,6 +142,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Xor => {} Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), + Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), Scenario::Select => {} } } @@ -330,6 +334,7 @@ impl ScenarioWatGenerator for Scenario { ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::LocalSet => local_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs new file mode 100644 index 0000000000..6b0261a819 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -0,0 +1,14 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_exported_func_beginning(wat: &mut Vec) { + wat.write_all(b" (local $var i32)\n").unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + for _ in 0..number_of_loop_iterations { + wat.write_all(b" (local.set $var (i32.const 1073741823))\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 335de00ed6..4564799eb1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -11,4 +11,5 @@ pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; pub mod local_get; +pub mod local_set; pub mod select; From bedf6d8e5e1d80a89a0b616691d985a787f3809c Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 10:59:52 -0300 Subject: [PATCH 49/72] stylus_benchmark: local.tee --- .../tools/stylus_benchmark/src/scenario.rs | 6 +++++- .../stylus_benchmark/src/scenarios/local_tee.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e6a6212d0f..bf8d5d875e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, - select, + local_tee, select, }; use clap::ValueEnum; use std::fs::File; @@ -51,6 +51,7 @@ pub enum Scenario { If, LocalGet, LocalSet, + LocalTee, Select, } @@ -100,6 +101,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::If => if_op::write_specific_wat_beginning(wat), Scenario::LocalGet => {} Scenario::LocalSet => {} + Scenario::LocalTee => {} Scenario::Select => select::write_specific_wat_beginning(wat), } } @@ -143,6 +145,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), + Scenario::LocalTee => local_tee::write_specific_exported_func_beginning(wat), Scenario::Select => {} } } @@ -335,6 +338,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalSet => local_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::LocalTee => local_tee::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Select => select::write_wat_ops(wat, number_of_ops_per_loop_iteration), } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs new file mode 100644 index 0000000000..6369a1331f --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_specific_exported_func_beginning(wat: &mut Vec) { + wat.write_all(b" (local $var i32)\n").unwrap(); +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { + wat.write_all(b" (i32.const 1073741823)\n").unwrap(); + for _ in 0..number_of_loop_iterations { + wat.write_all(b" local.tee $var\n").unwrap(); + } + wat.write_all(b" drop\n").unwrap(); +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 4564799eb1..dbdf9d0257 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -12,4 +12,5 @@ pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; pub mod local_get; pub mod local_set; +pub mod local_tee; pub mod select; From 86a6b25fe7c34f8189d45bcf93430ce214c02247 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 14:24:04 -0300 Subject: [PATCH 50/72] Removes unused fn --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 6 +++--- .../tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs | 2 -- arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs | 2 -- arbitrator/tools/stylus_benchmark/src/scenarios/select.rs | 2 -- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index bf8d5d875e..427f8a8604 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -96,13 +96,13 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => {} Scenario::I32ShrU => {} Scenario::I32Sub => {} - Scenario::I32WrapI64 => i32_wrap_i64::write_specific_wat_beginning(wat), + Scenario::I32WrapI64 => {}, Scenario::I32Xor => {} - Scenario::If => if_op::write_specific_wat_beginning(wat), + Scenario::If => {}, Scenario::LocalGet => {} Scenario::LocalSet => {} Scenario::LocalTee => {} - Scenario::Select => select::write_specific_wat_beginning(wat), + Scenario::Select => {}, } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs index 2634615447..59352016aa 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs @@ -3,8 +3,6 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { for _ in 0..number_of_ops_per_loop_iteration { wat.write_all(b" i64.const 123123\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs index 71559f78ea..59199d6cde 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs @@ -3,8 +3,6 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { for _ in 0..number_of_ops_per_loop_iteration { wat.write_all(b" i32.const 0\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs index a1487e47d0..f35e3420d6 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -3,8 +3,6 @@ use std::io::Write; -pub fn write_specific_wat_beginning(_: &mut Vec) {} - pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { wat.write_all(b" i32.const 10\n").unwrap(); for _ in 0..number_of_ops_per_loop_iteration { From d4189586de75f3a981fe9c7a20424dfad0a0fd88 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 15:41:11 -0300 Subject: [PATCH 51/72] convert mod instead of i32_wrap_i64 mod --- .../tools/stylus_benchmark/src/scenario.rs | 18 +++++++++++------- .../stylus_benchmark/src/scenarios/convert.rs | 19 +++++++++++++++++++ .../src/scenarios/i32_wrap_i64.rs | 12 ------------ .../stylus_benchmark/src/scenarios/mod.rs | 2 +- 4 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs delete mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 427f8a8604..6b1919385a 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, data_type::DataType, global_get, global_set, i32_wrap_i64, if_op, + call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, local_tee, select, }; @@ -96,13 +96,13 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32ShrS => {} Scenario::I32ShrU => {} Scenario::I32Sub => {} - Scenario::I32WrapI64 => {}, + Scenario::I32WrapI64 => {} Scenario::I32Xor => {} - Scenario::If => {}, + Scenario::If => {} Scenario::LocalGet => {} Scenario::LocalSet => {} Scenario::LocalTee => {} - Scenario::Select => {}, + Scenario::Select => {} } } @@ -326,9 +326,13 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "sub", ), - Scenario::I32WrapI64 => { - i32_wrap_i64::write_wat_ops(wat, number_of_ops_per_loop_iteration) - } + Scenario::I32WrapI64 => convert::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + DataType::I32, + "wrap_i64", + ), Scenario::I32Xor => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs new file mode 100644 index 0000000000..07ccf43aee --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -0,0 +1,19 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; + +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + source_data_type: DataType, + dest_data_type: DataType, + instruction: &str, +) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" {}.const {}\n", source_data_type, dest_data_type.gen()).as_bytes()).unwrap(); + wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()).unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs deleted file mode 100644 index 59352016aa..0000000000 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/i32_wrap_i64.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2021-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use std::io::Write; - -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i64.const 123123\n").unwrap(); - wat.write_all(b" i32.wrap_i64\n").unwrap(); - wat.write_all(b" drop\n").unwrap(); - } -} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index dbdf9d0257..8998f991f7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,10 +3,10 @@ pub mod call; pub mod call_indirect; +pub mod convert; pub mod data_type; pub mod global_get; pub mod global_set; -pub mod i32_wrap_i64; pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; From 71c2ec865a037f32fcda235aa9e88da604cf3b68 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 16:28:21 -0300 Subject: [PATCH 52/72] stylus_benchmark: i64.extend_i32_s --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 10 ++++++++++ .../tools/stylus_benchmark/src/scenarios/convert.rs | 2 +- .../tools/stylus_benchmark/src/scenarios/data_type.rs | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 6b1919385a..bd5c72d5c4 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -44,6 +44,7 @@ pub enum Scenario { I32Sub, I32WrapI64, I32Xor, + I64ExtendI32S, Call, CallIndirect, GlobalGet, @@ -98,6 +99,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => {} Scenario::LocalSet => {} @@ -142,6 +144,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), @@ -339,6 +342,13 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "xor", ), + Scenario::I64ExtendI32S => convert::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I32, + DataType::I64, + "extend_i32_s", + ), Scenario::If => if_op::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalGet => local_get::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::LocalSet => local_set::write_wat_ops(wat, number_of_ops_per_loop_iteration), diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs index 07ccf43aee..573bdd3858 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -12,7 +12,7 @@ pub fn write_wat_ops( instruction: &str, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", source_data_type, dest_data_type.gen()).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", source_data_type, DataType::I32.gen()).as_bytes()).unwrap(); wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()).unwrap(); wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index dda7ad80b7..6425dd852c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -19,8 +19,8 @@ impl Rand for DataType { fn gen(&self) -> usize { let mut rng = rand::thread_rng(); match self { - DataType::I32 => rng.gen::().try_into().unwrap(), - DataType::I64 => rng.gen::().try_into().unwrap(), + DataType::I32 => (rng.gen::() >> 1).try_into().unwrap(), + DataType::I64 => (rng.gen::() >> 1).try_into().unwrap(), } } } From 67ff06307a044abe478c8e843785f076ffe16c53 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 16:29:25 -0300 Subject: [PATCH 53/72] stylus_benchmark: i64.extend_i32_u --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index bd5c72d5c4..c8d06faa43 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -44,6 +44,7 @@ pub enum Scenario { I32Sub, I32WrapI64, I32Xor, + I64ExtendI32U, I64ExtendI32S, Call, CallIndirect, @@ -99,6 +100,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => {} @@ -144,6 +146,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), @@ -342,6 +345,13 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "xor", ), + Scenario::I64ExtendI32U => convert::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I32, + DataType::I64, + "extend_i32_u", + ), Scenario::I64ExtendI32S => convert::write_wat_ops( wat, number_of_ops_per_loop_iteration, From bd5969283abe6984df02cdbb981ab9a75359dd2e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 18:55:58 -0300 Subject: [PATCH 54/72] stylus_benchmark: i32.load --- .../tools/stylus_benchmark/src/scenario.rs | 16 +++++++++++++-- .../stylus_benchmark/src/scenarios/load.rs | 20 +++++++++++++++++++ .../stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/load.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index c8d06faa43..08da65a4c9 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -3,7 +3,7 @@ use crate::scenarios::{ call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, local_get, local_set, + instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, local_tee, select, }; use clap::ValueEnum; @@ -28,6 +28,7 @@ pub enum Scenario { I32GtS, I32LeU, I32LeS, + I32Load, I32LtU, I32LtS, I32Mul, @@ -84,6 +85,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32GtS => {} Scenario::I32LeU => {} Scenario::I32LeS => {} + Scenario::I32Load => {} Scenario::I32LtU => {} Scenario::I32LtS => {} Scenario::I32Mul => {} @@ -130,6 +132,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32GtS => {} Scenario::I32LeU => {} Scenario::I32LeS => {} + Scenario::I32Load => {} Scenario::I32LtU => {} Scenario::I32LtS => {} Scenario::I32Mul => {} @@ -248,6 +251,12 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "le_s", ), + Scenario::I32Load => load::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I32, + "load", + ), Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -379,7 +388,10 @@ fn write_common_wat_beginning(wat: &mut Vec) { .unwrap(); wat.write_all(b" (import \"debug\" \"end_benchmark\" (func $end_benchmark))\n") .unwrap(); - wat.write_all(b" (memory (export \"memory\") 0 0)\n") + wat.write_all(b" (import \"vm_hooks\" \"pay_for_memory_grow\" (func (param i32)))\n") + .unwrap(); + wat.write_all(b" (memory $memory 1)\n").unwrap(); + wat.write_all(b" (export \"memory\" (memory $memory))\n") .unwrap(); wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") .unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs new file mode 100644 index 0000000000..3de0211ce3 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -0,0 +1,20 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use crate::scenarios::data_type::DataType; +use std::io::Write; + +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, + instruction: &str, +) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + .unwrap(); + wat.write_all(b" drop\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8998f991f7..be9cc3d228 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -14,3 +14,4 @@ pub mod local_get; pub mod local_set; pub mod local_tee; pub mod select; +pub mod load; From 43ab5321d56cdbaaf7654d96e055c6cc55b144b7 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 19:01:38 -0300 Subject: [PATCH 55/72] stylus_benchmark: i32.store --- .../tools/stylus_benchmark/src/scenario.rs | 17 +++++++++------- .../stylus_benchmark/src/scenarios/load.rs | 3 +-- .../stylus_benchmark/src/scenarios/mod.rs | 3 ++- .../stylus_benchmark/src/scenarios/store.rs | 20 +++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/store.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 08da65a4c9..75b3432ef0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -4,7 +4,7 @@ use crate::scenarios::{ call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, - local_tee, select, + local_tee, select, store, }; use clap::ValueEnum; use std::fs::File; @@ -42,6 +42,7 @@ pub enum Scenario { I32Shl, I32ShrS, I32ShrU, + I32Store, I32Sub, I32WrapI64, I32Xor, @@ -99,6 +100,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Shl => {} Scenario::I32ShrS => {} Scenario::I32ShrU => {} + Scenario::I32Store => {} Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} @@ -146,6 +148,7 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Shl => {} Scenario::I32ShrS => {} Scenario::I32ShrU => {} + Scenario::I32Store => {} Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} @@ -251,12 +254,9 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "le_s", ), - Scenario::I32Load => load::write_wat_ops( - wat, - number_of_ops_per_loop_iteration, - DataType::I32, - "load", - ), + Scenario::I32Load => { + load::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I32) + } Scenario::I32LtU => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, @@ -335,6 +335,9 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "shr_u", ), + Scenario::I32Store => { + store::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I32) + } Scenario::I32Sub => instruction_with_2_args_1_return::write_wat_ops( wat, number_of_ops_per_loop_iteration, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs index 3de0211ce3..90ec890719 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -8,12 +8,11 @@ pub fn write_wat_ops( wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, - instruction: &str, ) { for _ in 0..number_of_ops_per_loop_iteration { wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) .unwrap(); - wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + wat.write_all(format!(" {}.load\n", data_type).as_bytes()) .unwrap(); wat.write_all(b" drop\n").unwrap(); } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index be9cc3d228..70ddbf40ad 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -10,8 +10,9 @@ pub mod global_set; pub mod if_op; pub mod instruction_with_1_arg_1_return; pub mod instruction_with_2_args_1_return; +pub mod load; pub mod local_get; pub mod local_set; pub mod local_tee; pub mod select; -pub mod load; +pub mod store; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs new file mode 100644 index 0000000000..89f6a59157 --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs @@ -0,0 +1,20 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; + +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, +) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.store\n", data_type).as_bytes()) + .unwrap(); + } +} From 309e79c3375b719d193f8e38df3c0464a5864492 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 19:17:13 -0300 Subject: [PATCH 56/72] stylus_benchmark: I64 ops --- .../tools/stylus_benchmark/src/scenario.rs | 273 ++++++++++++++++++ 1 file changed, 273 insertions(+) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 75b3432ef0..39588d75db 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -46,6 +46,37 @@ pub enum Scenario { I32Sub, I32WrapI64, I32Xor, + I64Add, + I64And, + I64Clz, + I64Ctz, + I64DivS, + I64DivU, + I64Eq, + I64Eqz, + I64GeS, + I64GeU, + I64GtU, + I64GtS, + I64LeU, + I64LeS, + I64Load, + I64LtU, + I64LtS, + I64Mul, + I64Ne, + I64Or, + I64Popcnt, + I64RemS, + I64RemU, + I64Rotl, + I64Rotr, + I64Shl, + I64ShrS, + I64ShrU, + I64Store, + I64Sub, + I64Xor, I64ExtendI32U, I64ExtendI32S, Call, @@ -104,6 +135,37 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64Add => {} + Scenario::I64And => {} + Scenario::I64Clz => {} + Scenario::I64Ctz => {} + Scenario::I64DivS => {} + Scenario::I64DivU => {} + Scenario::I64Eq => {} + Scenario::I64Eqz => {} + Scenario::I64GeS => {} + Scenario::I64GeU => {} + Scenario::I64GtU => {} + Scenario::I64GtS => {} + Scenario::I64LeU => {} + Scenario::I64LeS => {} + Scenario::I64Load => {} + Scenario::I64LtU => {} + Scenario::I64LtS => {} + Scenario::I64Mul => {} + Scenario::I64Ne => {} + Scenario::I64Or => {} + Scenario::I64Popcnt => {} + Scenario::I64RemS => {} + Scenario::I64RemU => {} + Scenario::I64Rotl => {} + Scenario::I64Rotr => {} + Scenario::I64Shl => {} + Scenario::I64ShrS => {} + Scenario::I64ShrU => {} + Scenario::I64Store => {} + Scenario::I64Sub => {} + Scenario::I64Xor => {} Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} @@ -152,6 +214,37 @@ impl ScenarioWatGenerator for Scenario { Scenario::I32Sub => {} Scenario::I32WrapI64 => {} Scenario::I32Xor => {} + Scenario::I64Add => {} + Scenario::I64And => {} + Scenario::I64Clz => {} + Scenario::I64Ctz => {} + Scenario::I64DivS => {} + Scenario::I64DivU => {} + Scenario::I64Eq => {} + Scenario::I64Eqz => {} + Scenario::I64GeS => {} + Scenario::I64GeU => {} + Scenario::I64GtU => {} + Scenario::I64GtS => {} + Scenario::I64LeU => {} + Scenario::I64LeS => {} + Scenario::I64Load => {} + Scenario::I64LtU => {} + Scenario::I64LtS => {} + Scenario::I64Mul => {} + Scenario::I64Ne => {} + Scenario::I64Or => {} + Scenario::I64Popcnt => {} + Scenario::I64RemS => {} + Scenario::I64RemU => {} + Scenario::I64Rotl => {} + Scenario::I64Rotr => {} + Scenario::I64Shl => {} + Scenario::I64ShrS => {} + Scenario::I64ShrU => {} + Scenario::I64Store => {} + Scenario::I64Sub => {} + Scenario::I64Xor => {} Scenario::I64ExtendI32U => {} Scenario::I64ExtendI32S => {} Scenario::If => {} @@ -357,6 +450,186 @@ impl ScenarioWatGenerator for Scenario { DataType::I32, "xor", ), + Scenario::I64Add => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "add", + ), + Scenario::I64And => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "and", + ), + Scenario::I64Clz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "clz", + ), + Scenario::I64Ctz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ctz", + ), + Scenario::I64DivS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "div_s", + ), + Scenario::I64DivU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "div_u", + ), + Scenario::I64Eq => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "eq", + ), + Scenario::I64Eqz => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "eqz", + ), + Scenario::I64GeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ge_s", + ), + Scenario::I64GeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ge_u", + ), + Scenario::I64GtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "gt_u", + ), + Scenario::I64GtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "gt_s", + ), + Scenario::I64LeU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "le_u", + ), + Scenario::I64LeS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "le_s", + ), + Scenario::I64Load => { + load::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I64) + } + Scenario::I64LtU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "lt_u", + ), + Scenario::I64LtS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "lt_s", + ), + Scenario::I64Mul => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "mul", + ), + Scenario::I64Ne => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "ne", + ), + Scenario::I64Or => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "or", + ), + Scenario::I64Popcnt => instruction_with_1_arg_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "popcnt", + ), + Scenario::I64RemS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rem_s", + ), + Scenario::I64RemU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rem_u", + ), + Scenario::I64Rotl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rotl", + ), + Scenario::I64Rotr => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "rotr", + ), + Scenario::I64Shl => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "shl", + ), + Scenario::I64ShrS => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "shr_s", + ), + Scenario::I64ShrU => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "shr_u", + ), + Scenario::I64Store => { + store::write_wat_ops(wat, number_of_ops_per_loop_iteration, DataType::I64) + } + Scenario::I64Sub => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "sub", + ), + Scenario::I64Xor => instruction_with_2_args_1_return::write_wat_ops( + wat, + number_of_ops_per_loop_iteration, + DataType::I64, + "xor", + ), Scenario::I64ExtendI32U => convert::write_wat_ops( wat, number_of_ops_per_loop_iteration, From 20c7d4a2840f728f87abe1cba537254719e0c627 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 9 Jan 2025 19:21:17 -0300 Subject: [PATCH 57/72] Uses local instead of global for ops_counter --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 39588d75db..e10e500ec0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -669,13 +669,14 @@ fn write_common_wat_beginning(wat: &mut Vec) { wat.write_all(b" (memory $memory 1)\n").unwrap(); wat.write_all(b" (export \"memory\" (memory $memory))\n") .unwrap(); - wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") - .unwrap(); } fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); + wat.write_all(b" (local $ops_counter i32)\n") + .unwrap(); + wat.write_all(b" (local.set $ops_counter (i32.const 0))\n").unwrap(); } fn write_loop_beginning(wat: &mut Vec) { @@ -691,7 +692,7 @@ fn write_wat_end( let number_of_ops = number_of_loop_iterations * number_of_ops_per_loop_iteration; // update ops_counter - wat.write_all(b" global.get $ops_counter\n") + wat.write_all(b" local.get $ops_counter\n") .unwrap(); wat.write_all( format!( @@ -702,12 +703,10 @@ fn write_wat_end( ) .unwrap(); wat.write_all(b" i32.add\n").unwrap(); - wat.write_all(b" global.set $ops_counter\n") + wat.write_all(b" local.tee $ops_counter\n") .unwrap(); // check if we need to continue looping - wat.write_all(b" global.get $ops_counter\n") - .unwrap(); wat.write_all(format!(" i32.const {}\n", number_of_ops).as_bytes()) .unwrap(); wat.write_all(b" i32.lt_s\n").unwrap(); From 02f9249d17130857c3d018ce9ef78ca6f3ce3468 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 09:29:12 -0300 Subject: [PATCH 58/72] stylus_benchmark: br --- .../tools/stylus_benchmark/src/scenario.rs | 9 +++++++-- .../tools/stylus_benchmark/src/scenarios/br.rs | 16 ++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/br.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index e10e500ec0..b695a33635 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, + br, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, local_tee, select, store, }; @@ -79,6 +79,7 @@ pub enum Scenario { I64Xor, I64ExtendI32U, I64ExtendI32S, + Br, Call, CallIndirect, GlobalGet, @@ -99,6 +100,7 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { + Scenario::Br => {}, Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), @@ -178,6 +180,7 @@ impl ScenarioWatGenerator for Scenario { fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { match self { + Scenario::Br => {}, Scenario::Call => {} Scenario::CallIndirect => {} Scenario::GlobalGet => {} @@ -257,6 +260,7 @@ impl ScenarioWatGenerator for Scenario { fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { + Scenario::Br => br::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) @@ -676,7 +680,8 @@ fn write_exported_func_beginning(wat: &mut Vec) { .unwrap(); wat.write_all(b" (local $ops_counter i32)\n") .unwrap(); - wat.write_all(b" (local.set $ops_counter (i32.const 0))\n").unwrap(); + wat.write_all(b" (local.set $ops_counter (i32.const 0))\n") + .unwrap(); } fn write_loop_beginning(wat: &mut Vec) { diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs new file mode 100644 index 0000000000..1356c048ea --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -0,0 +1,16 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" (block\n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" br 2\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 70ddbf40ad..8f2146bec7 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,6 +1,7 @@ // Copyright 2021-2024, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +pub mod br; pub mod call; pub mod call_indirect; pub mod convert; From 7298af4c8795a558f6ea349a0e2610a7bdf932a9 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 09:34:17 -0300 Subject: [PATCH 59/72] stylus_benchmark: br_if --- .../tools/stylus_benchmark/src/scenario.rs | 10 +++++++--- .../tools/stylus_benchmark/src/scenarios/br.rs | 2 +- .../stylus_benchmark/src/scenarios/br_if.rs | 17 +++++++++++++++++ .../tools/stylus_benchmark/src/scenarios/mod.rs | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index b695a33635..790cd65396 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - br, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, + br, br_if, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, local_tee, select, store, }; @@ -80,6 +80,7 @@ pub enum Scenario { I64ExtendI32U, I64ExtendI32S, Br, + BrIf, Call, CallIndirect, GlobalGet, @@ -100,7 +101,8 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {}, + Scenario::Br => {} + Scenario::BrIf => {} Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), @@ -180,7 +182,8 @@ impl ScenarioWatGenerator for Scenario { fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {}, + Scenario::Br => {} + Scenario::BrIf => {} Scenario::Call => {} Scenario::CallIndirect => {} Scenario::GlobalGet => {} @@ -261,6 +264,7 @@ impl ScenarioWatGenerator for Scenario { fn write_wat_ops(&self, wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { match self { Scenario::Br => br::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::BrIf => br_if::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs index 1356c048ea..a79b5173ce 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -8,7 +8,7 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block\n").unwrap(); wat.write_all(b" (block \n").unwrap(); wat.write_all(b" (block \n").unwrap(); - wat.write_all(b" br 2\n").unwrap(); + wat.write_all(b" br 2\n").unwrap(); // it will jump to the end of the last block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs new file mode 100644 index 0000000000..01f7620afe --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -0,0 +1,17 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + wat.write_all(b" (block\n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" (block \n").unwrap(); + wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the last block + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + wat.write_all(b" )\n").unwrap(); + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 8f2146bec7..e1452151e5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -2,6 +2,7 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod br; +pub mod br_if; pub mod call; pub mod call_indirect; pub mod convert; From 8ec1f561b26829072b55be1194ed46fb4de15c7e Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 09:58:58 -0300 Subject: [PATCH 60/72] stylus_benchmark: br_table --- .../tools/stylus_benchmark/src/scenario.rs | 10 ++++-- .../src/scenarios/br_table.rs | 32 +++++++++++++++++++ .../stylus_benchmark/src/scenarios/mod.rs | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 790cd65396..159581441d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -2,9 +2,9 @@ // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ - br, br_if, call, call_indirect, convert, data_type::DataType, global_get, global_set, if_op, - instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, local_set, - local_tee, select, store, + br, br_if, br_table, call, call_indirect, convert, data_type::DataType, global_get, global_set, + if_op, instruction_with_1_arg_1_return, instruction_with_2_args_1_return, load, local_get, + local_set, local_tee, select, store, }; use clap::ValueEnum; use std::fs::File; @@ -81,6 +81,7 @@ pub enum Scenario { I64ExtendI32S, Br, BrIf, + BrTable, Call, CallIndirect, GlobalGet, @@ -103,6 +104,7 @@ impl ScenarioWatGenerator for Scenario { match self { Scenario::Br => {} Scenario::BrIf => {} + Scenario::BrTable => {} Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), @@ -184,6 +186,7 @@ impl ScenarioWatGenerator for Scenario { match self { Scenario::Br => {} Scenario::BrIf => {} + Scenario::BrTable => {} Scenario::Call => {} Scenario::CallIndirect => {} Scenario::GlobalGet => {} @@ -265,6 +268,7 @@ impl ScenarioWatGenerator for Scenario { match self { Scenario::Br => br::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::BrIf => br_if::write_wat_ops(wat, number_of_ops_per_loop_iteration), + Scenario::BrTable => br_table::write_wat_ops(wat, number_of_ops_per_loop_iteration, 5), Scenario::Call => call::write_wat_ops(wat, number_of_ops_per_loop_iteration), Scenario::CallIndirect => { call_indirect::write_wat_ops(wat, number_of_ops_per_loop_iteration) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs new file mode 100644 index 0000000000..b4b0db8e4b --- /dev/null +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -0,0 +1,32 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +use std::io::Write; + +fn rm_identation(s: &mut String) { + for _ in 0..4 { + s.pop(); + } +} + +pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, table_size: usize) { + for _ in 0..number_of_ops_per_loop_iteration { + let mut identation = String::from(" "); + for _ in 0..table_size { + wat.write_all(format!("{}(block\n", identation).as_bytes()).unwrap(); + identation.push_str(" "); + } + wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()).unwrap(); // it will jump to the end of the last block + + let mut br_table = String::from("br_table"); + for i in 0..table_size { + br_table.push_str(&format!(" {}", i)); + } + wat.write_all(format!("{}{}\n", identation, br_table).as_bytes()).unwrap(); + + for _ in 0..table_size { + rm_identation(&mut identation); + wat.write_all(format!("{})\n", identation).as_bytes()).unwrap(); + } + } +} diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index e1452151e5..1f02b63aaf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -3,6 +3,7 @@ pub mod br; pub mod br_if; +pub mod br_table; pub mod call; pub mod call_indirect; pub mod convert; From 751d62316a0fe09ff15cc0150b13c16ce94c51fd Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:02:05 -0300 Subject: [PATCH 61/72] Updates date in copyright --- arbitrator/tools/stylus_benchmark/src/benchmark.rs | 2 +- arbitrator/tools/stylus_benchmark/src/main.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenario.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/call.rs | 2 +- .../tools/stylus_benchmark/src/scenarios/call_indirect.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs | 2 +- .../src/scenarios/instruction_with_1_arg_1_return.rs | 2 +- .../src/scenarios/instruction_with_2_args_1_return.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/load.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/select.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/store.rs | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 84a9b40af8..40ea15ad0b 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use arbutil::evm::{api::Ink, EvmData}; diff --git a/arbitrator/tools/stylus_benchmark/src/main.rs b/arbitrator/tools/stylus_benchmark/src/main.rs index 297acc1867..db5ff2e5c1 100644 --- a/arbitrator/tools/stylus_benchmark/src/main.rs +++ b/arbitrator/tools/stylus_benchmark/src/main.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE mod benchmark; diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 159581441d..1bccb170f3 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::{ diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs index a79b5173ce..a9ddd1f109 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs index 01f7620afe..485baef01e 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index b4b0db8e4b..f257772a19 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs index 6160001510..acb66fb391 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs index b104720c44..6dbe6cbe6f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call_indirect.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs index 573bdd3858..ddcd24eaff 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::data_type::{DataType, Rand}; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 6425dd852c..10895be62c 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use rand::Rng; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs index f053ad8782..f2fa065bc5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_get.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs index 1e648d7a85..4781a9b276 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/global_set.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs index 59199d6cde..1c076a6700 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/if_op.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 44421bb756..5545bd9cac 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index 470b994caa..a6c2275ed1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs index 90ec890719..5abc52a1ce 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::data_type::DataType; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs index edd304c007..bd89fe6925 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_get.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs index 6b0261a819..7697e8d16d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs index 6369a1331f..c442433bcf 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs index 1f02b63aaf..6cf7d499ce 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE pub mod br; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs index f35e3420d6..5ad3a996ee 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use std::io::Write; diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs index 89f6a59157..0157235e5b 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs @@ -1,4 +1,4 @@ -// Copyright 2021-2024, Offchain Labs, Inc. +// Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE use crate::scenarios::data_type::{DataType, Rand}; From 4fe605be63c3a0e22ea55d7de80ee571ca0de72c Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:23:28 -0300 Subject: [PATCH 62/72] Fix load --- arbitrator/tools/stylus_benchmark/src/scenarios/load.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs index 5abc52a1ce..50094bf19d 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/load.rs @@ -10,7 +10,7 @@ pub fn write_wat_ops( data_type: DataType, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + wat.write_all(format!(" i32.const 0\n").as_bytes()) .unwrap(); wat.write_all(format!(" {}.load\n", data_type).as_bytes()) .unwrap(); From 2cae13b028bdc9d7af5db8ae3ce9d078a8b6dd7f Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:26:40 -0300 Subject: [PATCH 63/72] Fix store --- arbitrator/tools/stylus_benchmark/src/scenarios/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs index 0157235e5b..78b3067870 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/store.rs @@ -10,7 +10,7 @@ pub fn write_wat_ops( data_type: DataType, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const 0\n", data_type).as_bytes()) + wat.write_all(format!(" i32.const 0\n").as_bytes()) .unwrap(); wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) .unwrap(); From d6f01fffd5810173efe48cafa49651c9002f18ef Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 10:33:03 -0300 Subject: [PATCH 64/72] Fix fmt --- .../stylus_benchmark/src/scenarios/br_if.rs | 3 ++- .../stylus_benchmark/src/scenarios/br_table.rs | 18 +++++++++++++----- .../stylus_benchmark/src/scenarios/call.rs | 3 +-- .../stylus_benchmark/src/scenarios/convert.rs | 13 +++++++++++-- .../src/scenarios/data_type.rs | 2 +- .../instruction_with_1_arg_1_return.rs | 15 +++++++++++---- .../instruction_with_2_args_1_return.rs | 2 +- .../src/scenarios/local_set.rs | 3 ++- .../src/scenarios/local_tee.rs | 3 ++- 9 files changed, 44 insertions(+), 18 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs index 485baef01e..be178a57be 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -8,7 +8,8 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block\n").unwrap(); wat.write_all(b" (block \n").unwrap(); wat.write_all(b" (block \n").unwrap(); - wat.write_all(b" i32.const 1\n").unwrap(); + wat.write_all(b" i32.const 1\n") + .unwrap(); wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the last block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index f257772a19..02dee3501f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -9,24 +9,32 @@ fn rm_identation(s: &mut String) { } } -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, table_size: usize) { +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + table_size: usize, +) { for _ in 0..number_of_ops_per_loop_iteration { let mut identation = String::from(" "); for _ in 0..table_size { - wat.write_all(format!("{}(block\n", identation).as_bytes()).unwrap(); + wat.write_all(format!("{}(block\n", identation).as_bytes()) + .unwrap(); identation.push_str(" "); } - wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()).unwrap(); // it will jump to the end of the last block + wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()) + .unwrap(); // it will jump to the end of the last block let mut br_table = String::from("br_table"); for i in 0..table_size { br_table.push_str(&format!(" {}", i)); } - wat.write_all(format!("{}{}\n", identation, br_table).as_bytes()).unwrap(); + wat.write_all(format!("{}{}\n", identation, br_table).as_bytes()) + .unwrap(); for _ in 0..table_size { rm_identation(&mut identation); - wat.write_all(format!("{})\n", identation).as_bytes()).unwrap(); + wat.write_all(format!("{})\n", identation).as_bytes()) + .unwrap(); } } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs index acb66fb391..8a79ba79f0 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/call.rs @@ -9,7 +9,6 @@ pub fn write_specific_wat_beginning(wat: &mut Vec) { pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { for _ in 0..number_of_loop_iterations { - wat.write_all(b" call $nop\n") - .unwrap(); + wat.write_all(b" call $nop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs index ddcd24eaff..63b8829c44 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/convert.rs @@ -12,8 +12,17 @@ pub fn write_wat_ops( instruction: &str, ) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", source_data_type, DataType::I32.gen()).as_bytes()).unwrap(); - wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()).unwrap(); + wat.write_all( + format!( + " {}.const {}\n", + source_data_type, + DataType::I32.gen() + ) + .as_bytes(), + ) + .unwrap(); + wat.write_all(format!(" {}.{}\n", dest_data_type, instruction).as_bytes()) + .unwrap(); wat.write_all(b" drop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 10895be62c..94d52ee20f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -8,7 +8,7 @@ use strum_macros::{Display, EnumString}; #[strum(serialize_all = "lowercase")] pub enum DataType { I32, - I64 + I64, } pub trait Rand { diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs index 5545bd9cac..06c13c541f 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_1_arg_1_return.rs @@ -1,13 +1,20 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use std::io::Write; use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; -pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize, data_type: DataType, instruction: &str) { +pub fn write_wat_ops( + wat: &mut Vec, + number_of_ops_per_loop_iteration: usize, + data_type: DataType, + instruction: &str, +) { for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()).unwrap(); - wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()).unwrap(); + wat.write_all(format!(" {}.const {}\n", data_type, data_type.gen()).as_bytes()) + .unwrap(); + wat.write_all(format!(" {}.{}\n", data_type, instruction).as_bytes()) + .unwrap(); wat.write_all(b" drop\n").unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs index a6c2275ed1..dd4f20c542 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/instruction_with_2_args_1_return.rs @@ -1,8 +1,8 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE -use std::io::Write; use crate::scenarios::data_type::{DataType, Rand}; +use std::io::Write; pub fn write_wat_ops( wat: &mut Vec, diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs index 7697e8d16d..f686a6d598 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -9,6 +9,7 @@ pub fn write_specific_exported_func_beginning(wat: &mut Vec) { pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { for _ in 0..number_of_loop_iterations { - wat.write_all(b" (local.set $var (i32.const 1073741823))\n").unwrap(); + wat.write_all(b" (local.set $var (i32.const 1073741823))\n") + .unwrap(); } } diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs index c442433bcf..ed81647cd5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_tee.rs @@ -8,7 +8,8 @@ pub fn write_specific_exported_func_beginning(wat: &mut Vec) { } pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { - wat.write_all(b" (i32.const 1073741823)\n").unwrap(); + wat.write_all(b" (i32.const 1073741823)\n") + .unwrap(); for _ in 0..number_of_loop_iterations { wat.write_all(b" local.tee $var\n").unwrap(); } From d328ed433560a2a4a490c9842c421dbefa1278ca Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 11:00:44 -0300 Subject: [PATCH 65/72] ops_counter as global again --- arbitrator/tools/stylus_benchmark/src/scenario.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index 1bccb170f3..b05190f288 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -681,15 +681,13 @@ fn write_common_wat_beginning(wat: &mut Vec) { wat.write_all(b" (memory $memory 1)\n").unwrap(); wat.write_all(b" (export \"memory\" (memory $memory))\n") .unwrap(); + wat.write_all(b" (global $ops_counter (mut i32) (i32.const 0))\n") + .unwrap(); } fn write_exported_func_beginning(wat: &mut Vec) { wat.write_all(b" (func (export \"user_entrypoint\") (param i32) (result i32)\n") .unwrap(); - wat.write_all(b" (local $ops_counter i32)\n") - .unwrap(); - wat.write_all(b" (local.set $ops_counter (i32.const 0))\n") - .unwrap(); } fn write_loop_beginning(wat: &mut Vec) { @@ -705,7 +703,7 @@ fn write_wat_end( let number_of_ops = number_of_loop_iterations * number_of_ops_per_loop_iteration; // update ops_counter - wat.write_all(b" local.get $ops_counter\n") + wat.write_all(b" global.get $ops_counter\n") .unwrap(); wat.write_all( format!( @@ -716,10 +714,12 @@ fn write_wat_end( ) .unwrap(); wat.write_all(b" i32.add\n").unwrap(); - wat.write_all(b" local.tee $ops_counter\n") + wat.write_all(b" global.set $ops_counter\n") .unwrap(); // check if we need to continue looping + wat.write_all(b" global.get $ops_counter\n") + .unwrap(); wat.write_all(format!(" i32.const {}\n", number_of_ops).as_bytes()) .unwrap(); wat.write_all(b" i32.lt_s\n").unwrap(); From 3cd6b0ac0b90b4110370cb7fc23f153329e79c22 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:07:52 -0300 Subject: [PATCH 66/72] Update comments related to branch instructions --- arbitrator/tools/stylus_benchmark/src/scenarios/br.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs | 2 +- arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs index a9ddd1f109..84f3dfbac1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br.rs @@ -8,7 +8,7 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block\n").unwrap(); wat.write_all(b" (block \n").unwrap(); wat.write_all(b" (block \n").unwrap(); - wat.write_all(b" br 2\n").unwrap(); // it will jump to the end of the last block + wat.write_all(b" br 2\n").unwrap(); // it will jump to the end of the first block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs index be178a57be..fe7509b646 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_if.rs @@ -10,7 +10,7 @@ pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) wat.write_all(b" (block \n").unwrap(); wat.write_all(b" i32.const 1\n") .unwrap(); - wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the last block + wat.write_all(b" br_if 2\n").unwrap(); // it will jump to the end of the first block wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); wat.write_all(b" )\n").unwrap(); diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index 02dee3501f..3fc5503b08 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -21,8 +21,9 @@ pub fn write_wat_ops( .unwrap(); identation.push_str(" "); } + // it will jump to the end of the first block wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()) - .unwrap(); // it will jump to the end of the last block + .unwrap(); let mut br_table = String::from("br_table"); for i in 0..table_size { From 8d259101a4319883b57f2f240ff2b52845b56ec6 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:16:33 -0300 Subject: [PATCH 67/72] Fix br_table --- arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs index 3fc5503b08..e3a0e00815 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/br_table.rs @@ -22,7 +22,7 @@ pub fn write_wat_ops( identation.push_str(" "); } // it will jump to the end of the first block - wat.write_all(format!("{}i32.const {}\n", identation, table_size).as_bytes()) + wat.write_all(format!("{}i32.const {}\n", identation, table_size - 1).as_bytes()) .unwrap(); let mut br_table = String::from("br_table"); From fe323f6a041ff38c5190936cdda9c7dcb9badf2d Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:20:08 -0300 Subject: [PATCH 68/72] Fixes data_type.gen --- arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 94d52ee20f..262250cc17 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -19,8 +19,9 @@ impl Rand for DataType { fn gen(&self) -> usize { let mut rng = rand::thread_rng(); match self { - DataType::I32 => (rng.gen::() >> 1).try_into().unwrap(), - DataType::I64 => (rng.gen::() >> 1).try_into().unwrap(), + // makes sure that the generated number fits a signed integer + DataType::I32 => (rng.gen::() / 2 - 1).try_into().unwrap(), + DataType::I64 => (rng.gen::() / 2 - 1).try_into().unwrap(), } } } From aef94dcb59670ee6cafeea55de420aec455a1070 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:33:04 -0300 Subject: [PATCH 69/72] Generates number in local.set --- .../tools/stylus_benchmark/src/scenarios/local_set.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs index f686a6d598..6333a84c06 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/local_set.rs @@ -1,6 +1,7 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use crate::scenarios::data_type::{DataType, Rand}; use std::io::Write; pub fn write_specific_exported_func_beginning(wat: &mut Vec) { @@ -9,7 +10,13 @@ pub fn write_specific_exported_func_beginning(wat: &mut Vec) { pub fn write_wat_ops(wat: &mut Vec, number_of_loop_iterations: usize) { for _ in 0..number_of_loop_iterations { - wat.write_all(b" (local.set $var (i32.const 1073741823))\n") - .unwrap(); + wat.write_all( + format!( + " (local.set $var (i32.const {}))\n", + DataType::I32.gen() + ) + .as_bytes(), + ) + .unwrap(); } } From fb1e838cea17b5426c37f21192755f34bdf6c975 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 13:37:23 -0300 Subject: [PATCH 70/72] Fixes select --- .../tools/stylus_benchmark/src/scenarios/select.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs index 5ad3a996ee..7b744625a1 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/select.rs @@ -1,14 +1,17 @@ // Copyright 2021-2025, Offchain Labs, Inc. // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE +use crate::scenarios::data_type::{DataType, Rand}; use std::io::Write; pub fn write_wat_ops(wat: &mut Vec, number_of_ops_per_loop_iteration: usize) { - wat.write_all(b" i32.const 10\n").unwrap(); for _ in 0..number_of_ops_per_loop_iteration { - wat.write_all(b" i32.const 20\n").unwrap(); + wat.write_all(format!(" i32.const {}\n", DataType::I32.gen()).as_bytes()) + .unwrap(); + wat.write_all(format!(" i32.const {}\n", DataType::I32.gen()).as_bytes()) + .unwrap(); wat.write_all(b" i32.const 0\n").unwrap(); wat.write_all(b" select\n").unwrap(); + wat.write_all(b" drop\n").unwrap(); } - wat.write_all(b" drop\n").unwrap(); } From 34ef4c28bbe79207866a64c96ffe853a56016ffc Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 20:04:40 -0300 Subject: [PATCH 71/72] Uses catch all in match --- .../tools/stylus_benchmark/src/scenario.rs | 149 +----------------- 1 file changed, 2 insertions(+), 147 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenario.rs b/arbitrator/tools/stylus_benchmark/src/scenario.rs index b05190f288..8856080d05 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenario.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenario.rs @@ -102,165 +102,20 @@ trait ScenarioWatGenerator { impl ScenarioWatGenerator for Scenario { fn write_specific_wat_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {} - Scenario::BrIf => {} - Scenario::BrTable => {} Scenario::Call => call::write_specific_wat_beginning(wat), Scenario::CallIndirect => call_indirect::write_specific_wat_beginning(wat), Scenario::GlobalGet => global_get::write_specific_wat_beginning(wat), Scenario::GlobalSet => global_set::write_specific_wat_beginning(wat), - Scenario::I32Add => {} - Scenario::I32And => {} - Scenario::I32Clz => {} - Scenario::I32Ctz => {} - Scenario::I32DivS => {} - Scenario::I32DivU => {} - Scenario::I32Eq => {} - Scenario::I32Eqz => {} - Scenario::I32GeS => {} - Scenario::I32GeU => {} - Scenario::I32GtU => {} - Scenario::I32GtS => {} - Scenario::I32LeU => {} - Scenario::I32LeS => {} - Scenario::I32Load => {} - Scenario::I32LtU => {} - Scenario::I32LtS => {} - Scenario::I32Mul => {} - Scenario::I32Ne => {} - Scenario::I32Or => {} - Scenario::I32Popcnt => {} - Scenario::I32RemS => {} - Scenario::I32RemU => {} - Scenario::I32Rotl => {} - Scenario::I32Rotr => {} - Scenario::I32Shl => {} - Scenario::I32ShrS => {} - Scenario::I32ShrU => {} - Scenario::I32Store => {} - Scenario::I32Sub => {} - Scenario::I32WrapI64 => {} - Scenario::I32Xor => {} - Scenario::I64Add => {} - Scenario::I64And => {} - Scenario::I64Clz => {} - Scenario::I64Ctz => {} - Scenario::I64DivS => {} - Scenario::I64DivU => {} - Scenario::I64Eq => {} - Scenario::I64Eqz => {} - Scenario::I64GeS => {} - Scenario::I64GeU => {} - Scenario::I64GtU => {} - Scenario::I64GtS => {} - Scenario::I64LeU => {} - Scenario::I64LeS => {} - Scenario::I64Load => {} - Scenario::I64LtU => {} - Scenario::I64LtS => {} - Scenario::I64Mul => {} - Scenario::I64Ne => {} - Scenario::I64Or => {} - Scenario::I64Popcnt => {} - Scenario::I64RemS => {} - Scenario::I64RemU => {} - Scenario::I64Rotl => {} - Scenario::I64Rotr => {} - Scenario::I64Shl => {} - Scenario::I64ShrS => {} - Scenario::I64ShrU => {} - Scenario::I64Store => {} - Scenario::I64Sub => {} - Scenario::I64Xor => {} - Scenario::I64ExtendI32U => {} - Scenario::I64ExtendI32S => {} - Scenario::If => {} - Scenario::LocalGet => {} - Scenario::LocalSet => {} - Scenario::LocalTee => {} - Scenario::Select => {} + _ => {} } } fn write_specific_exported_func_beginning(&self, wat: &mut Vec) { match self { - Scenario::Br => {} - Scenario::BrIf => {} - Scenario::BrTable => {} - Scenario::Call => {} - Scenario::CallIndirect => {} - Scenario::GlobalGet => {} - Scenario::GlobalSet => {} - Scenario::I32Add => {} - Scenario::I32And => {} - Scenario::I32Clz => {} - Scenario::I32Ctz => {} - Scenario::I32DivS => {} - Scenario::I32DivU => {} - Scenario::I32Eq => {} - Scenario::I32Eqz => {} - Scenario::I32GeS => {} - Scenario::I32GeU => {} - Scenario::I32GtU => {} - Scenario::I32GtS => {} - Scenario::I32LeU => {} - Scenario::I32LeS => {} - Scenario::I32Load => {} - Scenario::I32LtU => {} - Scenario::I32LtS => {} - Scenario::I32Mul => {} - Scenario::I32Ne => {} - Scenario::I32Or => {} - Scenario::I32Popcnt => {} - Scenario::I32RemS => {} - Scenario::I32RemU => {} - Scenario::I32Rotl => {} - Scenario::I32Rotr => {} - Scenario::I32Shl => {} - Scenario::I32ShrS => {} - Scenario::I32ShrU => {} - Scenario::I32Store => {} - Scenario::I32Sub => {} - Scenario::I32WrapI64 => {} - Scenario::I32Xor => {} - Scenario::I64Add => {} - Scenario::I64And => {} - Scenario::I64Clz => {} - Scenario::I64Ctz => {} - Scenario::I64DivS => {} - Scenario::I64DivU => {} - Scenario::I64Eq => {} - Scenario::I64Eqz => {} - Scenario::I64GeS => {} - Scenario::I64GeU => {} - Scenario::I64GtU => {} - Scenario::I64GtS => {} - Scenario::I64LeU => {} - Scenario::I64LeS => {} - Scenario::I64Load => {} - Scenario::I64LtU => {} - Scenario::I64LtS => {} - Scenario::I64Mul => {} - Scenario::I64Ne => {} - Scenario::I64Or => {} - Scenario::I64Popcnt => {} - Scenario::I64RemS => {} - Scenario::I64RemU => {} - Scenario::I64Rotl => {} - Scenario::I64Rotr => {} - Scenario::I64Shl => {} - Scenario::I64ShrS => {} - Scenario::I64ShrU => {} - Scenario::I64Store => {} - Scenario::I64Sub => {} - Scenario::I64Xor => {} - Scenario::I64ExtendI32U => {} - Scenario::I64ExtendI32S => {} - Scenario::If => {} Scenario::LocalGet => local_get::write_specific_exported_func_beginning(wat), Scenario::LocalSet => local_set::write_specific_exported_func_beginning(wat), Scenario::LocalTee => local_tee::write_specific_exported_func_beginning(wat), - Scenario::Select => {} + _ => {} } } From 35ae6f32bb1e55a65ad40983be61ca15898f5746 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 10 Jan 2025 20:32:51 -0300 Subject: [PATCH 72/72] Fixes data_type.gen --- arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs index 262250cc17..f7af36fdd5 100644 --- a/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs +++ b/arbitrator/tools/stylus_benchmark/src/scenarios/data_type.rs @@ -19,9 +19,8 @@ impl Rand for DataType { fn gen(&self) -> usize { let mut rng = rand::thread_rng(); match self { - // makes sure that the generated number fits a signed integer - DataType::I32 => (rng.gen::() / 2 - 1).try_into().unwrap(), - DataType::I64 => (rng.gen::() / 2 - 1).try_into().unwrap(), + DataType::I32 => rng.gen_range(0..i32::MAX).try_into().unwrap(), + DataType::I64 => rng.gen_range(0..i64::MAX).try_into().unwrap(), } } }