@@ -583,7 +583,8 @@ mod tests {
583
583
halt( ) , // This should be skipped
584
584
halt( ) , // This should be skipped too
585
585
// 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)
587
588
halt( ) ,
588
589
] ;
589
590
@@ -611,14 +612,15 @@ mod tests {
611
612
fn test_call_instruction ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
612
613
// Test CALL: save PC and FP, then jump
613
614
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)
615
616
wom:: call:: <F >( 10 , 11 , 20 , 9 ) , // Call to PC=20, FP=x9, save PC to x10, FP to x11
616
617
wom:: addi:: <F >( 8 , 0 , 123 ) , // x8 = 123 (after return) - this should NOT execute
617
618
reveal( 8 , 0 ) , // Reveal x8 - this should NOT execute
618
619
halt( ) , // Padding
619
620
// 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
622
624
] ;
623
625
624
626
run_vm_test ( "CALL instruction" , instructions, 8 , None )
@@ -630,14 +632,14 @@ mod tests {
630
632
let instructions = vec ! [
631
633
wom:: addi:: <F >( 12 , 0 , 28 ) , // x12 = 28 (target PC)
632
634
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
634
636
wom:: call_indirect:: <F >( 10 , 11 , 12 , 9 ) , // Call to PC=x12, FP=x9, save PC to x10, FP to x11
635
637
wom:: addi:: <F >( 8 , 0 , 456 ) , // x8 = 456 (after return) - this should NOT execute
636
638
reveal( 8 , 0 ) , // Reveal x8 - this should NOT execute
637
639
halt( ) , // Padding
638
640
// 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
641
643
] ;
642
644
643
645
run_vm_test ( "CALL_INDIRECT instruction" , instructions, 0 , None )
@@ -787,7 +789,7 @@ mod tests {
787
789
] ;
788
790
789
791
// 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 )
791
793
}
792
794
793
795
#[ test]
@@ -818,13 +820,13 @@ mod tests {
818
820
// This test verifies that copy_into_frame actually writes the value
819
821
let instructions = vec ! [
820
822
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
822
824
// by convention on the first allocation.
823
825
wom:: addi:: <F >( 10 , 0 , 0 ) , // PC=8: x10 = 0 (destination register)
824
826
wom:: copy_into_frame:: <F >( 10 , 8 , 9 ) , // PC=12: Copy x8 to [x9[x10]]
825
827
// TODO: `reveal` uses the loadstore chip which does not use fp. Change back to 10 once
826
828
// 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)
828
830
halt( ) , // PC=20: End
829
831
] ;
830
832
@@ -1149,7 +1151,7 @@ mod tests {
1149
1151
// Read first value into r8
1150
1152
wom:: pre_read_u32:: <F >( ) ,
1151
1153
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
1153
1155
wom:: copy_into_frame:: <F >( 2 , 8 , 9 ) , // Copy r8 to frame[2]
1154
1156
// Jump to new frame
1155
1157
wom:: jaaf:: <F >( 24 , 9 ) , // Jump to PC=24, activate frame at r9
@@ -1160,11 +1162,11 @@ mod tests {
1160
1162
wom:: read_u32:: <F >( 3 ) ,
1161
1163
// Xor the two read values
1162
1164
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,
1164
1166
// 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 ) ,
1168
1170
halt( ) ,
1169
1171
] ;
1170
1172
0 commit comments