Skip to content

Commit 4a34649

Browse files
committed
fix tests
1 parent df95cef commit 4a34649

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

extensions/circuit/src/adapters/jaaf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ use openvm_womir_transpiler::JaafOpcode;
3131
use serde::{Deserialize, Serialize};
3232
use struct_reflection::{StructReflection, StructReflectionHelper};
3333

34-
use crate::{AdapterRuntimeContextWom, FrameBridge, FrameBus, FrameState, VmAdapterChipWom};
34+
use crate::{
35+
adapters::compose, AdapterRuntimeContextWom, FrameBridge, FrameBus, FrameState,
36+
VmAdapterChipWom,
37+
};
3538

3639
use super::{abstract_compose, RV32_REGISTER_NUM_LIMBS};
3740

integration/src/instruction_builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ pub fn call_indirect<F: PrimeField32>(
216216
) -> Instruction<F> {
217217
Instruction::new(
218218
JaafOpcode::CALL_INDIRECT.global_opcode(),
219-
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * save_pc), // a: rd1 (save PC here)
220-
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * save_fp), // b: rd2 (save FP here)
221-
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * to_pc_reg), // c: rs1 (PC source)
219+
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * save_pc),
220+
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * save_fp),
221+
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * to_pc_reg),
222222
F::ZERO, // d: immediate (not used)
223-
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * to_fp_reg), // e: rs2 (FP source)
223+
F::from_canonical_usize(riscv::RV32_REGISTER_NUM_LIMBS * to_fp_reg),
224224
F::ONE, // f: enabled
225225
F::ZERO, // g: imm sign
226226
)

integration/src/main.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ mod tests {
583583
halt(), // This should be skipped
584584
halt(), // This should be skipped too
585585
// PC = 24 (byte offset, so instruction at index 6)
586-
reveal(11, 0), // Reveal x11 (should be 0, the old FP)
586+
// TODO: replace by 11 once reveal uses fp.
587+
reveal(2 + 11, 0), // Reveal x11 (should be 0, the old FP)
587588
halt(),
588589
];
589590

@@ -611,14 +612,15 @@ mod tests {
611612
fn test_call_instruction() -> Result<(), Box<dyn std::error::Error>> {
612613
// Test CALL: save PC and FP, then jump
613614
let instructions = vec![
614-
wom::addi::<F>(9, 0, 15), // x9 = 15 (new FP)
615+
wom::addi::<F>(9, 0, 16), // x9 = 15 (new FP)
615616
wom::call::<F>(10, 11, 20, 9), // Call to PC=20, FP=x9, save PC to x10, FP to x11
616617
wom::addi::<F>(8, 0, 123), // x8 = 123 (after return) - this should NOT execute
617618
reveal(8, 0), // Reveal x8 - this should NOT execute
618619
halt(), // Padding
619620
// PC = 20 (function start)
620-
reveal(10, 0), // Reveal x10 (should be 8, the return address)
621-
halt(), // End the test here, don't return
621+
// TODO: change reveal to just 10 once it uses fp.
622+
reveal(4 + 10, 0), // Reveal x10 (should be 8, the return address)
623+
halt(), // End the test here, don't return
622624
];
623625

624626
run_vm_test("CALL instruction", instructions, 8, None)
@@ -630,14 +632,14 @@ mod tests {
630632
let instructions = vec![
631633
wom::addi::<F>(12, 0, 28), // x12 = 28 (target PC)
632634
wom::addi::<F>(9, 0, 20), // x9 = 20 (new FP)
633-
wom::addi::<F>(11, 0, 999), // x9 = 20 (new FP)
635+
wom::addi::<F>(11, 0, 999), // x11 = 999
634636
wom::call_indirect::<F>(10, 11, 12, 9), // Call to PC=x12, FP=x9, save PC to x10, FP to x11
635637
wom::addi::<F>(8, 0, 456), // x8 = 456 (after return) - this should NOT execute
636638
reveal(8, 0), // Reveal x8 - this should NOT execute
637639
halt(), // Padding
638640
// PC = 28 (function start, where x12 points)
639-
reveal(11, 0), // Reveal x11 (should be 0, the saved FP)
640-
halt(), // End the test here, don't return
641+
reveal(5 + 11, 0), // Reveal x11 (should be 0, the saved FP)
642+
halt(), // End the test here, don't return
641643
];
642644

643645
run_vm_test("CALL_INDIRECT instruction", instructions, 0, None)
@@ -787,7 +789,7 @@ mod tests {
787789
];
788790

789791
// We expect 4 because the register allocator starts at 4 as convention.
790-
run_vm_test("ALLOCATE_FRAME instruction", instructions, 4, None)
792+
run_vm_test("ALLOCATE_FRAME instruction", instructions, 8, None)
791793
}
792794

793795
#[test]
@@ -818,13 +820,13 @@ mod tests {
818820
// This test verifies that copy_into_frame actually writes the value
819821
let instructions = vec![
820822
wom::addi::<F>(8, 0, 123), // PC=0: x8 = 123 (value to store)
821-
wom::allocate_frame_imm::<F>(9, 128), // PC=4: Allocate 128 bytes, pointer in x9. x9=1
823+
wom::allocate_frame_imm::<F>(9, 128), // PC=4: Allocate 128 bytes, pointer in x9. x9=2
822824
// by convention on the first allocation.
823825
wom::addi::<F>(10, 0, 0), // PC=8: x10 = 0 (destination register)
824826
wom::copy_into_frame::<F>(10, 8, 9), // PC=12: Copy x8 to [x9[x10]]
825827
// TODO: `reveal` uses the loadstore chip which does not use fp. Change back to 10 once
826828
// it does.
827-
reveal(1 + 10, 0), // PC=16: Reveal x10 (should be 123, the value from x8)
829+
reveal(2 + 10, 0), // PC=16: Reveal x10 (should be 123, the value from x8)
828830
halt(), // PC=20: End
829831
];
830832

@@ -1149,7 +1151,7 @@ mod tests {
11491151
// Read first value into r8
11501152
wom::pre_read_u32::<F>(),
11511153
wom::read_u32::<F>(8),
1152-
wom::allocate_frame_imm::<F>(9, 64), // Allocate frame, pointer in 99
1154+
wom::allocate_frame_imm::<F>(9, 64), // Allocate frame, pointer in r9
11531155
wom::copy_into_frame::<F>(2, 8, 9), // Copy r8 to frame[2]
11541156
// Jump to new frame
11551157
wom::jaaf::<F>(24, 9), // Jump to PC=24, activate frame at r9
@@ -1160,11 +1162,11 @@ mod tests {
11601162
wom::read_u32::<F>(3),
11611163
// Xor the two read values
11621164
wom::xor::<F>(4, 2, 3),
1163-
// TODO: register 5 below is the absolute value for local register 4 used above,
1165+
// TODO: register 6 below is the absolute value for local register 4 used above,
11641166
// due to the `loadstore` chip not being fp relative yet.
1165-
// The allocated frame is 4 (first allocation). Registers are 4-aligned,
1166-
// so in order to access local reg 4 we need (fp / 4 + local reg) = 4/4+1.
1167-
reveal(5, 0),
1167+
// The allocated frame is 8 (first allocation). Registers are 4-aligned,
1168+
// so in order to access local reg 4 we need (fp / 4 + local reg) = 8/4+1.
1169+
reveal(6, 0),
11681170
halt(),
11691171
];
11701172

0 commit comments

Comments
 (0)