mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-05-01 15:53:09 +00:00
fixes
This commit is contained in:
parent
534395ee4d
commit
4e736b63b8
@ -29,25 +29,22 @@ add_loop:
|
|||||||
// stack: (a[cur] + b[cur] + carry) // 2^128, a[cur] + b[cur] + carry, i, a_cur_loc, b_cur_loc, retdest
|
// stack: (a[cur] + b[cur] + carry) // 2^128, a[cur] + b[cur] + carry, i, a_cur_loc, b_cur_loc, retdest
|
||||||
SWAP1
|
SWAP1
|
||||||
// stack: a[cur] + b[cur] + carry, (a[cur] + b[cur] + carry) // 2^128, i, a_cur_loc, b_cur_loc, retdest
|
// stack: a[cur] + b[cur] + carry, (a[cur] + b[cur] + carry) // 2^128, i, a_cur_loc, b_cur_loc, retdest
|
||||||
%shl_const(128)
|
%mod_const(0x100000000000000000000000000000000)
|
||||||
%shr_const(128)
|
|
||||||
// stack: c[cur] = (a[cur] + b[cur] + carry) % 2^128, carry_new = (a[cur] + b[cur] + carry) // 2^128, i, a_cur_loc, b_cur_loc, retdest
|
// stack: c[cur] = (a[cur] + b[cur] + carry) % 2^128, carry_new = (a[cur] + b[cur] + carry) // 2^128, i, a_cur_loc, b_cur_loc, retdest
|
||||||
DUP4
|
DUP4
|
||||||
// stack: a_cur_loc, c[cur], carry_new, i, a_cur_loc, b_cur_loc, retdest
|
// stack: a_cur_loc, c[cur], carry_new, i, a_cur_loc, b_cur_loc, retdest
|
||||||
%mstore_kernel_general
|
%mstore_kernel_general
|
||||||
// stack: carry_new, i, a_cur_loc, b_cur_loc, retdest
|
// stack: carry_new, i, a_cur_loc, b_cur_loc, retdest
|
||||||
%stack (c, i, a, b) -> (a, b, c, i)
|
SWAP2
|
||||||
// stack: a_cur_loc, b_cur_loc, carry_new, i, retdest
|
|
||||||
%increment
|
%increment
|
||||||
// stack: a_cur_loc + 1, b_cur_loc, carry_new, i, retdest
|
SWAP2
|
||||||
|
// stack: carry_new, i, a_cur_loc + 1, b_cur_loc, retdest
|
||||||
|
SWAP3
|
||||||
|
%increment
|
||||||
|
SWAP3
|
||||||
|
// stack: carry_new, i, a_cur_loc + 1, b_cur_loc + 1, retdest
|
||||||
SWAP1
|
SWAP1
|
||||||
// stack: b_cur_loc, a_cur_loc + 1, carry_new, i, retdest
|
|
||||||
%increment
|
|
||||||
// stack: b_cur_loc + 1, a_cur_loc + 1, carry_new, i, retdest
|
|
||||||
%stack (b, a, c, i) -> (i, c, a, b)
|
|
||||||
// stack: i, carry_new, a_cur_loc + 1, b_cur_loc + 1, retdest
|
|
||||||
%decrement
|
%decrement
|
||||||
// stack: i - 1, carry_new, a_cur_loc + 1, b_cur_loc + 1, retdest
|
|
||||||
SWAP1
|
SWAP1
|
||||||
// stack: carry_new, i - 1, a_cur_loc + 1, b_cur_loc + 1, retdest
|
// stack: carry_new, i - 1, a_cur_loc + 1, b_cur_loc + 1, retdest
|
||||||
DUP2
|
DUP2
|
||||||
|
|||||||
@ -20,6 +20,8 @@ fn test_data() -> Vec<BigUint> {
|
|||||||
0u128.into(),
|
0u128.into(),
|
||||||
1u128.into(),
|
1u128.into(),
|
||||||
u128::MAX.into(),
|
u128::MAX.into(),
|
||||||
|
|
||||||
|
// Generated by GMP's mpz_rrandomb for bit lengths 5, 10, 100, 255, 256, 257, 500, 511, 512, 513, 1000, and 1500.
|
||||||
21u128.into(),
|
21u128.into(),
|
||||||
908u128.into(),
|
908u128.into(),
|
||||||
1267650597867046177654064545792u128.into(),
|
1267650597867046177654064545792u128.into(),
|
||||||
@ -266,6 +268,7 @@ where
|
|||||||
F: Fn(usize) -> (BigUint, BigUint, U256, Vec<U256>),
|
F: Fn(usize) -> (BigUint, BigUint, U256, Vec<U256>),
|
||||||
{
|
{
|
||||||
let (a, b, length, memory) = prepare_two_bignums_fn(1000);
|
let (a, b, length, memory) = prepare_two_bignums_fn(1000);
|
||||||
|
let len: usize = length.try_into().unwrap();
|
||||||
|
|
||||||
// Determine expected sum.
|
// Determine expected sum.
|
||||||
let sum = a + b;
|
let sum = a + b;
|
||||||
@ -288,7 +291,9 @@ where
|
|||||||
interpreter.run()?;
|
interpreter.run()?;
|
||||||
|
|
||||||
// Determine actual sum.
|
// Determine actual sum.
|
||||||
let new_memory = interpreter.get_kernel_general_memory();
|
let carry_limb = interpreter.stack()[0];
|
||||||
|
let mut new_memory = interpreter.get_kernel_general_memory();
|
||||||
|
new_memory[len] = carry_limb;
|
||||||
let actual_sum: Vec<_> = new_memory[..expected_sum.len()].into();
|
let actual_sum: Vec<_> = new_memory[..expected_sum.len()].into();
|
||||||
|
|
||||||
// Compare.
|
// Compare.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user