Skip to content

Commit

Permalink
Fix some tests (#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoalt authored Nov 29, 2024
1 parent 2832ff1 commit 89969ad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion riscv/src/large_field/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl Runtime {
"std::machines::large_field::arith::Arith",
None,
"arith",
vec![],
vec!["MIN_DEGREE", "MAIN_MAX_DEGREE"],
[
format!(
"instr affine_256 link ~> {};",
Expand Down
4 changes: 2 additions & 2 deletions riscv/src/small_field/code_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn preamble(field: KnownField, runtime: &Runtime, with_bootloader: bool) -> Stri
// Jump to the address in register XL and store the return program counter in register WL.
instr jump_dyn XL, WL
link ~> (tmp1_h, tmp1_l) = regs.mload(0, XL, STEP)
link ~> regs.mstore(0, WL, STEP, tmp2_h, tmp2_l)
link ~> regs.mstore(0, WL, STEP + 3, tmp2_h, tmp2_l)
// pc is capped at 24 bits, so for this instruction
// we restrict the higher limbs to 1 byte
link => byte.check(tmp1_h)
Expand Down Expand Up @@ -568,7 +568,7 @@ fn preamble(field: KnownField, runtime: &Runtime, with_bootloader: bool) -> Stri
// Stores 1 in register WL if val(XL) == val(YL), otherwise stores 0.
instr is_not_equal XL, YL, WL
link ~> (tmp1_h, tmp1_l) = regs.mload(0, XL, STEP)
link ~> (tmp2_h, tmp2_l) = regs.mload(0, YL, STEP)
link ~> (tmp2_h, tmp2_l) = regs.mload(0, YL, STEP + 1)
link ~> (tmp3_h, tmp3_l) = add_sub.sub(tmp1_h, tmp1_l, tmp2_h, tmp2_l)
link ~> regs.mstore(0, WL, STEP + 2, 0, 1 - XXIsZero)
{
Expand Down
4 changes: 2 additions & 2 deletions riscv/src/small_field/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ impl Runtime {
[
r#"instr shl XL, YL, ZH, ZL, WL
link ~> (tmp1_h, tmp1_l) = regs.mload(0, XL, STEP)
link ~> (tmp2_h, tmp2_l) = regs.mload(0, YL, STEP)
link ~> (tmp2_h, tmp2_l) = regs.mload(0, YL, STEP + 1)
link ~> (tmp3_h, tmp3_l) = add_sub.add(tmp2_h, tmp2_l, ZH, ZL)
link ~> (tmp4_l, tmp4_h) = shift.shl(tmp1_l, tmp1_h, tmp3_l)
link ~> regs.mstore(0, WL, STEP + 3, tmp4_h, tmp4_l);
"#,
r#"instr shr XL, YL, ZH, ZL, WL
link ~> (tmp1_h, tmp1_l) = regs.mload(0, XL, STEP)
link ~> (tmp2_h, tmp2_l) = regs.mload(0, YL, STEP)
link ~> (tmp2_h, tmp2_l) = regs.mload(0, YL, STEP + 1)
link ~> (tmp3_h, tmp3_l) = add_sub.add(tmp2_h, tmp2_l, ZH, ZL)
link ~> (tmp4_l, tmp4_h) = shift.shr(tmp1_l, tmp1_h, tmp3_l)
link ~> regs.mstore(0, WL, STEP + 3, tmp4_h, tmp4_l);
Expand Down
24 changes: 12 additions & 12 deletions riscv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ pub fn verify_riscv_asm_string<T: FieldElement, S: serde::Serialize + Send + Syn
pipeline = pipeline.add_data_vec(data);
}

// Compute the witness once for all tests that follow.
pipeline.compute_witness().unwrap();

test_mock_backend(pipeline.clone());

// verify with PILCOM
if T::known_field().unwrap() == KnownField::GoldilocksField {
let pipeline_gl: Pipeline<GoldilocksField> =
unsafe { std::mem::transmute(pipeline.clone()) };
run_pilcom_with_backend_variant(pipeline_gl, BackendVariant::Composite).unwrap();
}

// Test with the fast RISCV executor.
// TODO remove the guard once the executor is implemented for BB
if T::known_field().unwrap() == KnownField::GoldilocksField {
Expand All @@ -56,6 +44,18 @@ pub fn verify_riscv_asm_string<T: FieldElement, S: serde::Serialize + Send + Syn
);
}

// Compute the witness once for all tests that follow.
pipeline.compute_witness().unwrap();

test_mock_backend(pipeline.clone());

// verify with PILCOM
if T::known_field().unwrap() == KnownField::GoldilocksField {
let pipeline_gl: Pipeline<GoldilocksField> =
unsafe { std::mem::transmute(pipeline.clone()) };
run_pilcom_with_backend_variant(pipeline_gl, BackendVariant::Composite).unwrap();
}

test_plonky3_pipeline::<T>(pipeline.clone());

// verify executor generated witness
Expand Down
8 changes: 4 additions & 4 deletions riscv/tests/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ fn features_with_options<T: FieldElement>(options: CompilerOptions) {
&from_elf,
&[expected.into()],
None,
true,
false,
);

// "add_two"
Expand All @@ -513,7 +513,7 @@ fn features_with_options<T: FieldElement>(options: CompilerOptions) {
&from_elf,
&[expected.into()],
None,
true,
false,
);

// "add_two" and "add_three"
Expand All @@ -531,7 +531,7 @@ fn features_with_options<T: FieldElement>(options: CompilerOptions) {
&from_elf,
&[expected.into()],
None,
true,
false,
);
}

Expand Down Expand Up @@ -615,12 +615,12 @@ fn many_chunks_memory() {
}

fn verify_riscv_crate(case: &str, inputs: &[u64], executor_witgen: bool) {
verify_riscv_crate_bb(case, inputs.iter().map(|&x| x.into()).collect());
verify_riscv_crate_gl(
case,
inputs.iter().map(|&x| x.into()).collect(),
executor_witgen,
);
verify_riscv_crate_bb(case, inputs.iter().map(|&x| x.into()).collect());
}

fn verify_riscv_crate_bb(case: &str, inputs: Vec<BabyBearField>) {
Expand Down

0 comments on commit 89969ad

Please sign in to comment.