Skip to content

Commit

Permalink
Update to fuel-vm 0.32 (including wideint gas profiling) (FuelLabs#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentosal authored May 18, 2023
1 parent 722e59d commit 1ab29d9
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 20 deletions.
38 changes: 24 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fuel-core-tests = { version = "0.0.0", path = "./tests" }
fuel-core-xtask = { version = "0.0.0", path = "./xtask" }

# Fuel dependencies
fuel-vm-private = { version = "0.31.1", package = "fuel-vm" }
fuel-vm-private = { version = "0.32", package = "fuel-vm" }

# Common dependencies
anyhow = "1.0"
Expand Down
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = "0.0.0"
clap = { workspace = true, features = ["derive"] }
criterion = { version = "0.4", features = ["html_reports"] }
ctrlc = "3.2.3"
ethnum = "1.3"
fuel-core = { path = "../crates/fuel-core", default-features = false }
fuel-core-storage = { path = "./../crates/storage" }
fuel-core-types = { path = "./../crates/types", features = ["test-helpers"] }
Expand Down
227 changes: 227 additions & 0 deletions benches/benches/set/alu.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
use super::run_group_ref;

use criterion::Criterion;
use ethnum::U256;
use fuel_core_benches::*;
use fuel_core_types::fuel_asm::*;

use fuel_core_types::fuel_asm::wideint::{
CompareArgs,
CompareMode,
DivArgs,
MathArgs,
MathOp,
MulArgs,
};

/// Allocates a byte array from heap and initializes it. Then points `reg` to it.
fn aloc_bytearray<const S: usize>(reg: u8, v: [u8; S]) -> Vec<Instruction> {
let mut ops = vec![op::movi(reg, S as u32), op::aloc(reg)];
for (i, b) in v.iter().enumerate() {
if *b != 0 {
ops.push(op::movi(reg, *b as u32));
ops.push(op::sb(RegId::HP, reg, i as u16));
}
}
ops.push(op::move_(reg, RegId::HP));
ops
}

fn make_u128(reg: u8, v: u128) -> Vec<Instruction> {
aloc_bytearray(reg, v.to_be_bytes())
}

fn make_u256(reg: u8, v: U256) -> Vec<Instruction> {
aloc_bytearray(reg, v.to_be_bytes())
}

pub fn run(c: &mut Criterion) {
run_group_ref(
&mut c.benchmark_group("add"),
Expand Down Expand Up @@ -235,4 +266,200 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::xori(0x10, 0x11, 27))
.with_prepare_script(vec![op::movi(0x11, 100000)]),
);

// Wideint operations: 128 bit
let mut wideint_prepare = Vec::new();
wideint_prepare.extend(make_u128(0x10, 0));
wideint_prepare.extend(make_u128(0x11, u128::MAX));
wideint_prepare.extend(make_u128(0x12, u128::MAX / 2 + 1));
wideint_prepare.extend(make_u128(0x13, u128::MAX - 158)); // prime
wideint_prepare.extend(make_u128(0x14, u64::MAX.into()));

run_group_ref(
&mut c.benchmark_group("wdcm"),
"wdcm",
VmBench::new(op::wdcm_args(
0x10,
0x12,
0x13,
CompareArgs {
mode: CompareMode::LTE,
indirect_rhs: true,
},
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wdop"),
"wdop",
VmBench::new(op::wdop_args(
0x10,
0x13,
0x12,
MathArgs {
op: MathOp::SUB,
indirect_rhs: true,
},
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wdml"),
"wdml",
VmBench::new(op::wdml_args(
0x10,
0x14,
0x14,
MulArgs {
indirect_lhs: true,
indirect_rhs: true,
},
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wddv"),
"wddv",
VmBench::new(op::wddv_args(
0x10,
0x12,
0x13,
DivArgs { indirect_rhs: true },
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wddv"),
"wddv",
VmBench::new(op::wddv_args(
0x10,
0x12,
0x13,
DivArgs { indirect_rhs: true },
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wdmd"),
"wdmd",
VmBench::new(op::wdmd(0x10, 0x12, 0x13, 0x13))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wdam"),
"wdam",
VmBench::new(op::wdam(0x10, 0x12, 0x13, 0x13))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wdmm"),
"wdmm",
VmBench::new(op::wdmm(0x10, 0x12, 0x13, 0x13))
.with_prepare_script(wideint_prepare.clone()),
);

// Wideint operations: 256 bit
let mut wideint_prepare = Vec::new();
wideint_prepare.extend(make_u256(0x10, U256::ZERO));
wideint_prepare.extend(make_u256(0x11, U256::MAX));
wideint_prepare.extend(make_u256(0x12, U256::MAX / 2 + 1));
wideint_prepare.extend(make_u256(0x13, U256::MAX - 188)); // prime
wideint_prepare.extend(make_u256(0x14, u128::MAX.into()));

run_group_ref(
&mut c.benchmark_group("wqcm"),
"wqcm",
VmBench::new(op::wqcm_args(
0x10,
0x12,
0x13,
CompareArgs {
mode: CompareMode::LTE,
indirect_rhs: true,
},
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqop"),
"wqop",
VmBench::new(op::wqop_args(
0x10,
0x13,
0x12,
MathArgs {
op: MathOp::SUB,
indirect_rhs: true,
},
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqml"),
"wqml",
VmBench::new(op::wqml_args(
0x10,
0x14,
0x14,
MulArgs {
indirect_lhs: true,
indirect_rhs: true,
},
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqdv"),
"wqdv",
VmBench::new(op::wqdv_args(
0x10,
0x12,
0x13,
DivArgs { indirect_rhs: true },
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqdv"),
"wqdv",
VmBench::new(op::wqdv_args(
0x10,
0x12,
0x13,
DivArgs { indirect_rhs: true },
))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqmd"),
"wqmd",
VmBench::new(op::wqmd(0x10, 0x12, 0x13, 0x13))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqam"),
"wqam",
VmBench::new(op::wqam(0x10, 0x12, 0x13, 0x13))
.with_prepare_script(wideint_prepare.clone()),
);

run_group_ref(
&mut c.benchmark_group("wqmm"),
"wqmm",
VmBench::new(op::wdmm(0x10, 0x12, 0x13, 0x13))
.with_prepare_script(wideint_prepare.clone()),
);
}
Loading

0 comments on commit 1ab29d9

Please sign in to comment.