@@ -904,7 +904,8 @@ if_else_block(
904904 Stream2 = State2 # state .stream ,
905905 % % Emit unconditional branch to skip the else block (will be replaced)
906906 ElseJumpOffset = StreamModule :offset (Stream2 ),
907- ElseJumpInstr = jit_riscv32_asm :j (0 ),
907+ % % Use all-1s placeholder for flash compatibility (can only flip 1->0)
908+ ElseJumpInstr = <<16#FFFF :16 >>,
908909 Stream3 = StreamModule :append (Stream2 , ElseJumpInstr ),
909910 % % Else block starts here.
910911 OffsetAfter = StreamModule :offset (Stream3 ),
@@ -924,6 +925,9 @@ if_else_block(
924925 % % Patch the unconditional branch to jump to the end
925926 FinalJumpOffset = OffsetFinal - ElseJumpOffset ,
926927 NewElseJumpInstr = jit_riscv32_asm :j (FinalJumpOffset ),
928+ % % Assert that replacement is 2 bytes (c.j range: -2048..2046)
929+ % % If this fails, the if/else blocks are too large
930+ 2 = byte_size (NewElseJumpInstr ),
927931 Stream6 = StreamModule :replace (Stream5 , ElseJumpOffset , NewElseJumpInstr ),
928932 merge_used_regs (State3 # state {stream = Stream6 }, State2 # state .used_regs ).
929933
0 commit comments