Skip to content

Commit

Permalink
Push bench file
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Mar 26, 2024
1 parent b9fef8b commit c86ce87
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
%builtins range_check add_mod mul_mod
from starkware.cairo.common.cairo_builtins import ModBuiltin, UInt384
from starkware.cairo.common.registers import get_label_location
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.modulo import run_mod_p_circuit_with_large_batch_size

func run_circuit{range_check_ptr, add_mod_ptr: ModBuiltin*, mul_mod_ptr: ModBuiltin*}() {
alloc_locals;

let p = UInt384(d0=1, d1=1, d2=0, d3=0);
let x1 = UInt384(d0=1, d1=0, d2=0, d3=0);
let x2 = UInt384(d0=2, d1=1, d2=0, d3=0);
let x3 = UInt384(d0=2, d1=0, d2=0, d3=0);
let res = UInt384(d0=1, d1=0, d2=0, d3=0);

let (local values_arr: UInt384*) = alloc();
assert values_arr[0] = x1;
assert values_arr[1] = x2;
assert values_arr[2] = x3;
assert values_arr[7] = res;

let (local add_mod_offsets_arr: felt*) = alloc();
assert add_mod_offsets_arr[0] = 0; // x1
assert add_mod_offsets_arr[1] = 12; // x2 - x1
assert add_mod_offsets_arr[2] = 4; // x2
assert add_mod_offsets_arr[3] = 16; // (x2 - x1) * x3
assert add_mod_offsets_arr[4] = 20; // x1 * x3
assert add_mod_offsets_arr[5] = 24; // (x2 - x1) * x3 + x1 * x3

let (local mul_mod_offsets_arr: felt*) = alloc();
assert mul_mod_offsets_arr[0] = 12; // x2 - x1
assert mul_mod_offsets_arr[1] = 8; // x3
assert mul_mod_offsets_arr[2] = 16; // (x2 - x1) * x3
assert mul_mod_offsets_arr[3] = 0; // x1
assert mul_mod_offsets_arr[4] = 8; // x3
assert mul_mod_offsets_arr[5] = 20; // x1 * x3
assert mul_mod_offsets_arr[6] = 8; // x3
assert mul_mod_offsets_arr[7] = 28; // ((x2 - x1) * x3 + x1 * x3) / x3 = x2 mod p
assert mul_mod_offsets_arr[8] = 24; // (x2 - x1) * x3 + x1 * x3

run_mod_p_circuit_with_large_batch_size(
p=p,
values_ptr=values_arr,
add_mod_offsets_ptr=add_mod_offsets_arr,
add_mod_n=2,
mul_mod_offsets_ptr=mul_mod_offsets_arr,
mul_mod_n=3,
);

return ();
}

func run_loop{range_check_ptr, add_mod_ptr: ModBuiltin*, mul_mod_ptr: ModBuiltin*}(n: felt) {
if (n == 0) {
return ();
}
run_circuit();
return run_loop(n - 1);
}

func main{range_check_ptr, add_mod_ptr: ModBuiltin*, mul_mod_ptr: ModBuiltin*}() {
return run_loop(100);
}

0 comments on commit c86ce87

Please sign in to comment.