diff --git a/docs/book/src/reference/compiler_intrinsics.md b/docs/book/src/reference/compiler_intrinsics.md index a8126bec0c4..80de9d623c3 100644 --- a/docs/book/src/reference/compiler_intrinsics.md +++ b/docs/book/src/reference/compiler_intrinsics.md @@ -319,11 +319,9 @@ __not(op: T) -> T ___ ```sway -__jmpb_ssp(offset: u64) +__jmp_mem() ``` -**Description:** Jumps to `$ssp - offset`. When the offset is the growth -of `$ssp` after an `ldc` call, this transfers control to the newly loaded -contract. +**Description:** Jumps to `MEM[$hp]`. -**Constraints:** offset must have type `u64`. +**Constraints:** None. diff --git a/sway-ast/src/intrinsics.rs b/sway-ast/src/intrinsics.rs index f2ca2817a63..f7bef855e45 100644 --- a/sway-ast/src/intrinsics.rs +++ b/sway-ast/src/intrinsics.rs @@ -35,7 +35,7 @@ pub enum Intrinsic { PtrSub, Smo, Not, - JmpbSsp, + JmpMem, } impl fmt::Display for Intrinsic { @@ -74,7 +74,7 @@ impl fmt::Display for Intrinsic { Intrinsic::PtrSub => "ptr_sub", Intrinsic::Smo => "smo", Intrinsic::Not => "not", - Intrinsic::JmpbSsp => "jmpb_ssp", + Intrinsic::JmpMem => "jmp_mem", }; write!(f, "{s}") } @@ -117,7 +117,7 @@ impl Intrinsic { "__ptr_sub" => PtrSub, "__smo" => Smo, "__not" => Not, - "__jmpb_ssp" => JmpbSsp, + "__jmp_mem" => JmpMem, _ => return None, }) } diff --git a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs index 13b699a3d92..004f09ef271 100644 --- a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs +++ b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs @@ -305,7 +305,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { arg2, arg3, } => self.compile_wide_modular_op(instr_val, op, result, arg1, arg2, arg3), - FuelVmInstruction::JmpbSsp(offset) => self.compile_jmpb_ssp(instr_val, offset), + FuelVmInstruction::JmpMem => self.compile_jmp_mem(instr_val), }, InstOp::GetElemPtr { base, @@ -1452,45 +1452,44 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { Ok(()) } - fn compile_jmpb_ssp(&mut self, instr_val: &Value, offset: &Value) -> Result<(), CompileError> { + fn compile_jmp_mem(&mut self, instr_val: &Value) -> Result<(), CompileError> { let owning_span = self.md_mgr.val_to_span(self.context, *instr_val); - let offset_reg = self.value_to_register(offset)?; - let is_offset_reg = self.reg_seqr.next(); - let prev_ssp_reg = self.reg_seqr.next(); + let target_reg = self.reg_seqr.next(); + let is_target_reg = self.reg_seqr.next(); let by4_reg = self.reg_seqr.next(); self.cur_bytecode.push(Op { owning_span: owning_span.clone(), - opcode: Either::Left(VirtualOp::SUB( - prev_ssp_reg.clone(), - VirtualRegister::Constant(ConstantRegister::StackStartPointer), - offset_reg, + opcode: Either::Left(VirtualOp::LW( + target_reg.clone(), + VirtualRegister::Constant(ConstantRegister::HeapPointer), + VirtualImmediate12::new(0, Span::dummy()).unwrap(), )), - comment: "jmpb_ssp: Compute $ssp - offset".into(), + comment: "jmp_mem: Load MEM[$hp]".into(), }); self.cur_bytecode.push(Op { owning_span: owning_span.clone(), opcode: Either::Left(VirtualOp::SUB( - is_offset_reg.clone(), - prev_ssp_reg, + is_target_reg.clone(), + target_reg, VirtualRegister::Constant(ConstantRegister::InstructionStart), )), - comment: "jmpb_ssp: Subtract $is since $jmp adds it back.".into(), + comment: "jmp_mem: Subtract $is since Jmp adds it back.".into(), }); self.cur_bytecode.push(Op { owning_span: owning_span.clone(), opcode: Either::Left(VirtualOp::DIVI( by4_reg.clone(), - is_offset_reg.clone(), + is_target_reg.clone(), VirtualImmediate12::new(4, Span::dummy()).unwrap(), )), - comment: "jmpb_ssp: Divide by 4 since Jmp multiplies by 4.".into(), + comment: "jmp_mem: Divide by 4 since Jmp multiplies by 4.".into(), }); self.cur_bytecode.push(Op { owning_span, opcode: Either::Left(VirtualOp::JMP(by4_reg)), - comment: "jmpb_ssp: Jump to computed value".into(), + comment: "jmp_mem: Jump to computed value".into(), }); Ok(()) diff --git a/sway-core/src/asm_generation/fuel/functions.rs b/sway-core/src/asm_generation/fuel/functions.rs index 9fa415850f1..08b34efd87b 100644 --- a/sway-core/src/asm_generation/fuel/functions.rs +++ b/sway-core/src/asm_generation/fuel/functions.rs @@ -305,7 +305,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { // Free our stack allocated locals. This is unneeded for entries since they will have // actually returned to the calling context via a VM RET. - self.drop_locals(function); + self.drop_locals(); // Restore $reta. self.cur_bytecode.push(Op::register_move( @@ -946,7 +946,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { .push((locals_size_bytes, locals_base_reg, max_num_extra_args)); } - fn drop_locals(&mut self, _function: Function) { + pub(super) fn drop_locals(&mut self) { let (locals_size_bytes, max_num_extra_args) = (self.locals_size_bytes(), self.max_num_extra_args()); if locals_size_bytes > compiler_constants::TWENTY_FOUR_BITS { diff --git a/sway-core/src/ir_generation/const_eval.rs b/sway-core/src/ir_generation/const_eval.rs index 3a08ce171c5..d0f08a8e8d0 100644 --- a/sway-core/src/ir_generation/const_eval.rs +++ b/sway-core/src/ir_generation/const_eval.rs @@ -1111,7 +1111,7 @@ fn const_eval_intrinsic( | Intrinsic::StateStoreQuad | Intrinsic::Log | Intrinsic::Revert - | Intrinsic::JmpbSsp + | Intrinsic::JmpMem | Intrinsic::Smo => Err(ConstEvalError::CannotBeEvaluatedToConst { span: intrinsic.span.clone(), }), diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index e4aa6af1dfe..bd7249b6c63 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -1095,16 +1095,12 @@ impl<'eng> FnCompiler<'eng> { .add_metadatum(context, span_md_idx); Ok(TerminatorValue::new(val, context)) } - Intrinsic::JmpbSsp => { - let offset_val = return_on_termination_or_extract!( - self.compile_expression_to_value(context, md_mgr, &arguments[0])? - ); - + Intrinsic::JmpMem => { let span_md_idx = md_mgr.span_to_md(context, &span); let val = self .current_block .append(context) - .jmpb_ssp(offset_val) + .jmp_mem() .add_metadatum(context, span_md_idx); Ok(TerminatorValue::new(val, context)) } diff --git a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs index e042ee746fa..46296ef9927 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs @@ -83,8 +83,8 @@ impl ty::TyIntrinsicFunctionKind { } Intrinsic::Smo => type_check_smo(handler, ctx, kind, arguments, type_arguments, span), Intrinsic::Not => type_check_not(handler, ctx, kind, arguments, type_arguments, span), - Intrinsic::JmpbSsp => { - type_check_jmpb_ssp(handler, ctx, kind, arguments, type_arguments, span) + Intrinsic::JmpMem => { + type_check_jmp_mem(handler, ctx, kind, arguments, type_arguments, span) } } } @@ -1173,12 +1173,11 @@ fn type_check_revert( )) } -/// Signature: `__jmpb_ssp(offset: u64) -> !` -/// Description: Jumps to `$ssp - offset`. -/// Constraints: offset has type `u64`. -fn type_check_jmpb_ssp( +/// Signature: `__jmp_mem() -> !` +/// Description: Jumps to `MEM[$hp]`. +fn type_check_jmp_mem( handler: &Handler, - mut ctx: TypeCheckContext, + ctx: TypeCheckContext, kind: sway_ast::Intrinsic, arguments: Vec, type_arguments: Vec, @@ -1187,7 +1186,7 @@ fn type_check_jmpb_ssp( let type_engine = ctx.engines.te(); let engines = ctx.engines(); - if arguments.len() != 1 { + if !arguments.is_empty() { return Err(handler.emit_err(CompileError::IntrinsicIncorrectNumArgs { name: kind.to_string(), expected: 0, @@ -1203,18 +1202,10 @@ fn type_check_jmpb_ssp( })); } - // Type check the argument which is the jmpb_ssp offset - let mut ctx = ctx.by_ref().with_type_annotation(type_engine.insert( - engines, - TypeInfo::UnsignedInteger(IntegerBits::SixtyFour), - None, - )); - let offset = ty::TyExpression::type_check(handler, ctx.by_ref(), arguments[0].clone())?; - Ok(( ty::TyIntrinsicFunctionKind { kind, - arguments: vec![offset], + arguments: vec![], type_arguments: vec![], span, }, diff --git a/sway-core/src/semantic_analysis/cei_pattern_analysis.rs b/sway-core/src/semantic_analysis/cei_pattern_analysis.rs index 459fc922a3e..61e6fb5fc5e 100644 --- a/sway-core/src/semantic_analysis/cei_pattern_analysis.rs +++ b/sway-core/src/semantic_analysis/cei_pattern_analysis.rs @@ -608,7 +608,7 @@ fn effects_of_intrinsic(intr: &sway_ast::Intrinsic) -> HashSet { StateClear | StateStoreWord | StateStoreQuad => HashSet::from([Effect::StorageWrite]), StateLoadWord | StateLoadQuad => HashSet::from([Effect::StorageRead]), Smo => HashSet::from([Effect::OutputMessage]), - Revert | JmpbSsp | IsReferenceType | IsStrArray | SizeOfType | SizeOfVal | SizeOfStr + Revert | JmpMem | IsReferenceType | IsStrArray | SizeOfType | SizeOfVal | SizeOfStr | AssertIsStrArray | ToStrArray | Eq | Gt | Lt | Gtf | AddrOf | Log | Add | Sub | Mul | Div | And | Or | Xor | Mod | Rsh | Lsh | PtrAdd | PtrSub | Not => HashSet::new(), } diff --git a/sway-ir/src/analysis/memory_utils.rs b/sway-ir/src/analysis/memory_utils.rs index d75ac184984..dfc8829bf95 100644 --- a/sway-ir/src/analysis/memory_utils.rs +++ b/sway-ir/src/analysis/memory_utils.rs @@ -201,7 +201,7 @@ pub fn get_loaded_ptr_values(context: &Context, val: Value) -> Vec { InstOp::Store { dst_val_ptr: _, .. } => vec![], InstOp::FuelVm(FuelVmInstruction::Gtf { .. }) | InstOp::FuelVm(FuelVmInstruction::ReadRegister(_)) - | InstOp::FuelVm(FuelVmInstruction::Revert(_) | FuelVmInstruction::JmpbSsp(_)) => vec![], + | InstOp::FuelVm(FuelVmInstruction::Revert(_) | FuelVmInstruction::JmpMem) => vec![], InstOp::FuelVm(FuelVmInstruction::WideUnaryOp { arg, .. }) => vec![*arg], InstOp::FuelVm(FuelVmInstruction::WideBinaryOp { arg1, arg2, .. }) | InstOp::FuelVm(FuelVmInstruction::WideCmpOp { arg1, arg2, .. }) => { @@ -252,7 +252,7 @@ pub fn get_stored_ptr_values(context: &Context, val: Value) -> Vec { | FuelVmInstruction::Log { .. } | FuelVmInstruction::ReadRegister(_) | FuelVmInstruction::Revert(_) - | FuelVmInstruction::JmpbSsp(_) + | FuelVmInstruction::JmpMem | FuelVmInstruction::Smo { .. } | FuelVmInstruction::StateClear { .. } => vec![], FuelVmInstruction::StateLoadQuadWord { load_val, .. } => vec![*load_val], diff --git a/sway-ir/src/block.rs b/sway-ir/src/block.rs index 2417bbe56ee..a92b60a5c45 100644 --- a/sway-ir/src/block.rs +++ b/sway-ir/src/block.rs @@ -369,9 +369,7 @@ impl Block { i, Instruction { op: InstOp::Ret(..) - | InstOp::FuelVm( - FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpbSsp(..) - ), + | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpMem), .. } ) diff --git a/sway-ir/src/instruction.rs b/sway-ir/src/instruction.rs index 208e2490346..de9b316b858 100644 --- a/sway-ir/src/instruction.rs +++ b/sway-ir/src/instruction.rs @@ -194,7 +194,7 @@ pub enum FuelVmInstruction { arg1: Value, arg2: Value, }, - JmpbSsp(Value), + JmpMem, } /// Comparison operations. @@ -299,7 +299,7 @@ impl InstOp { // These are all terminators which don't return, essentially. No type. InstOp::Branch(_) | InstOp::ConditionalBranch { .. } - | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpbSsp(..)) + | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpMem) | InstOp::Ret(..) => None, // No-op is also no-type. @@ -408,7 +408,8 @@ impl InstOp { log_val, log_id, .. } => vec![*log_val, *log_id], FuelVmInstruction::ReadRegister(_) => vec![], - FuelVmInstruction::Revert(v) | FuelVmInstruction::JmpbSsp(v) => vec![*v], + FuelVmInstruction::Revert(v) => vec![*v], + FuelVmInstruction::JmpMem => vec![], FuelVmInstruction::Smo { recipient, message, @@ -545,7 +546,7 @@ impl InstOp { } FuelVmInstruction::ReadRegister { .. } => (), FuelVmInstruction::Revert(revert_val) => replace(revert_val), - FuelVmInstruction::JmpbSsp(contr_id) => replace(contr_id), + FuelVmInstruction::JmpMem => (), FuelVmInstruction::Smo { recipient, message, @@ -631,7 +632,7 @@ impl InstOp { | InstOp::FuelVm(FuelVmInstruction::StateLoadQuadWord { .. }) | InstOp::FuelVm(FuelVmInstruction::StateStoreQuadWord { .. }) | InstOp::FuelVm(FuelVmInstruction::StateStoreWord { .. }) - | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpbSsp(..)) + | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpMem) | InstOp::MemCopyBytes { .. } | InstOp::MemCopyVal { .. } | InstOp::Store { .. } @@ -666,7 +667,7 @@ impl InstOp { InstOp::Branch(_) | InstOp::ConditionalBranch { .. } | InstOp::Ret(..) - | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpbSsp(..)) + | InstOp::FuelVm(FuelVmInstruction::Revert(..) | FuelVmInstruction::JmpMem) ) } } @@ -1074,11 +1075,11 @@ impl<'a, 'eng> InstructionInserter<'a, 'eng> { revert_val } - pub fn jmpb_ssp(self, offset: Value) -> Value { + pub fn jmp_mem(self) -> Value { let ldc_exec = Value::new_instruction( self.context, self.block, - InstOp::FuelVm(FuelVmInstruction::JmpbSsp(offset)), + InstOp::FuelVm(FuelVmInstruction::JmpMem), ); self.context.blocks[self.block.0] .instructions diff --git a/sway-ir/src/optimize/fn_dedup.rs b/sway-ir/src/optimize/fn_dedup.rs index 25c0085a0c5..35608886944 100644 --- a/sway-ir/src/optimize/fn_dedup.rs +++ b/sway-ir/src/optimize/fn_dedup.rs @@ -154,7 +154,7 @@ fn hash_fn(context: &Context, function: Function, eq_class: &mut EqClass) -> u64 crate::FuelVmInstruction::Log { log_ty, .. } => log_ty.hash(state), crate::FuelVmInstruction::ReadRegister(reg) => reg.hash(state), crate::FuelVmInstruction::Revert(_) - | crate::FuelVmInstruction::JmpbSsp(_) + | crate::FuelVmInstruction::JmpMem | crate::FuelVmInstruction::Smo { .. } | crate::FuelVmInstruction::StateClear { .. } | crate::FuelVmInstruction::StateLoadQuadWord { .. } diff --git a/sway-ir/src/optimize/inline.rs b/sway-ir/src/optimize/inline.rs index 50402b62d50..29c97517a3a 100644 --- a/sway-ir/src/optimize/inline.rs +++ b/sway-ir/src/optimize/inline.rs @@ -535,9 +535,7 @@ fn inline_instruction( new_block.append(context).read_register(reg) } FuelVmInstruction::Revert(val) => new_block.append(context).revert(map_value(val)), - FuelVmInstruction::JmpbSsp(offset) => { - new_block.append(context).jmpb_ssp(map_value(offset)) - } + FuelVmInstruction::JmpMem => new_block.append(context).jmp_mem(), FuelVmInstruction::Smo { recipient, message, diff --git a/sway-ir/src/parser.rs b/sway-ir/src/parser.rs index 526898f559f..703c3ca2aa5 100644 --- a/sway-ir/src/parser.rs +++ b/sway-ir/src/parser.rs @@ -203,7 +203,7 @@ mod ir_builder { / op_read_register() / op_ret() / op_revert() - / op_jmpb_ssp() + / op_jmp_mem() / op_smo() / op_state_load_quad_word() / op_state_load_word() @@ -363,9 +363,9 @@ mod ir_builder { IrAstOperation::Revert(vn) } - rule op_jmpb_ssp() -> IrAstOperation - = "jmpb_ssp" _ vn:id() { - IrAstOperation::JmpbSsp(vn) + rule op_jmp_mem() -> IrAstOperation + = "jmp_mem" _ { + IrAstOperation::JmpMem } rule op_smo() -> IrAstOperation @@ -728,7 +728,7 @@ mod ir_builder { ReadRegister(String), Ret(IrAstTy, String), Revert(String), - JmpbSsp(String), + JmpMem, Smo(String, String, String, String), StateClear(String, String), StateLoadQuadWord(String, String, String), @@ -1351,9 +1351,9 @@ mod ir_builder { .append(context) .revert(*val_map.get(&ret_val_name).unwrap()) .add_metadatum(context, opt_metadata), - IrAstOperation::JmpbSsp(offset_name) => block + IrAstOperation::JmpMem => block .append(context) - .jmpb_ssp(*val_map.get(&offset_name).unwrap()) + .jmp_mem() .add_metadatum(context, opt_metadata), IrAstOperation::Smo(recipient, message, message_size, coins) => block .append(context) diff --git a/sway-ir/src/printer.rs b/sway-ir/src/printer.rs index 48a4b75f089..285b22dd6e7 100644 --- a/sway-ir/src/printer.rs +++ b/sway-ir/src/printer.rs @@ -656,12 +656,10 @@ fn instruction_to_doc<'a>( Doc::text(format!("revert {}", namer.name(context, v),)) .append(md_namer.md_idx_to_doc(context, metadata)), )), - FuelVmInstruction::JmpbSsp(offset) => { - maybe_constant_to_doc(context, md_namer, namer, offset).append(Doc::line( - Doc::text(format!("jmpb_ssp {}", namer.name(context, offset),)) - .append(md_namer.md_idx_to_doc(context, metadata)), - )) - } + FuelVmInstruction::JmpMem => Doc::line( + Doc::text("jmp_mem".to_string()) + .append(md_namer.md_idx_to_doc(context, metadata)), + ), FuelVmInstruction::Smo { recipient, message, diff --git a/sway-ir/src/value.rs b/sway-ir/src/value.rs index 63f5be75f48..3f87325da22 100644 --- a/sway-ir/src/value.rs +++ b/sway-ir/src/value.rs @@ -122,7 +122,7 @@ impl Value { InstOp::Branch(_) | InstOp::ConditionalBranch { .. } | InstOp::Ret(_, _) - | InstOp::FuelVm(FuelVmInstruction::Revert(_) | FuelVmInstruction::JmpbSsp(_)) + | InstOp::FuelVm(FuelVmInstruction::Revert(_) | FuelVmInstruction::JmpMem) ), ValueDatum::Argument(..) | ValueDatum::Configurable(..) | ValueDatum::Constant(..) => { false diff --git a/sway-ir/src/verify.rs b/sway-ir/src/verify.rs index 30942dddda1..7c8e08384c3 100644 --- a/sway-ir/src/verify.rs +++ b/sway-ir/src/verify.rs @@ -230,7 +230,7 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { log_id, } => self.verify_log(log_val, log_ty, log_id)?, FuelVmInstruction::ReadRegister(_) => (), - FuelVmInstruction::JmpbSsp(_) => (), + FuelVmInstruction::JmpMem => (), FuelVmInstruction::Revert(val) => self.verify_revert(val)?, FuelVmInstruction::Smo { recipient, diff --git a/test/src/ir_generation/mod.rs b/test/src/ir_generation/mod.rs index 815ef8a7aa2..b1e83fa5a1b 100644 --- a/test/src/ir_generation/mod.rs +++ b/test/src/ir_generation/mod.rs @@ -367,6 +367,7 @@ pub(super) async fn run( let _ = pass_mgr.run(&mut ir, &group); let ir_output = sway_ir::printer::to_string(&ir); + println!("{}", ir_output); match checker.explain(&ir_output, filecheck::NO_VARIABLES) { diff --git a/test/src/ir_generation/tests/jmp_mem.sw b/test/src/ir_generation/tests/jmp_mem.sw new file mode 100644 index 00000000000..24267ed4301 --- /dev/null +++ b/test/src/ir_generation/tests/jmp_mem.sw @@ -0,0 +1,55 @@ +// target-fuelvm + +contract; + +pub struct ContractId { + /// The underlying raw `b256` data of the contract id. + pub value: b256, +} + +abi MyContract { + fn test_function(code_id: ContractId); +} + +impl MyContract for Contract { + fn test_function(code_id_p: ContractId) { + asm(code_id, word, length, ssp_saved) { + lw code_id fp i74; + // Load the entire contract with LDC + csiz length code_id; + // Save the old ssp + move ssp_saved ssp; + ldc code_id zero length; + // Store the old ssp to MEM[$hp] so that we can jump to it. + // allocate a word the stack + addi word zero i64; + aloc word; + sw hp ssp_saved i0; + } + __jmp_mem() + } +} + +// ::check-ir:: + +// check: pub entry fn test_function<72a09f5b> + +// ::check-ir-optimized:: +// pass: o1 + +// check: pub entry fn test_function +// not: local +// check: csiz length code_id +// check: ldc code_id zero length, +// check: jmp_mem + +// ::check-asm:: + +// regex: REG=.r\d+\b + +// check: csiz $(len=$REG) $REG +// check: ldc $REG $$zero $len +// check: lw $(target=$REG) $$hp i0 ; jmp_mem: Load MEM[$$hp] +// check: sub $(jmp_target_4=$REG) $target $$is ; jmp_mem: Subtract $$is since Jmp adds it back +// check: divi $(jmp_target=$REG) $jmp_target_4 i4 ; jmp_mem: Divide by 4 since Jmp multiplies by 4 +// check: jmp $jmp_target ; jmp_mem: Jump to computed value diff --git a/test/src/ir_generation/tests/jmpb_ssp.sw b/test/src/ir_generation/tests/jmpb_ssp.sw deleted file mode 100644 index 55969c622b2..00000000000 --- a/test/src/ir_generation/tests/jmpb_ssp.sw +++ /dev/null @@ -1,62 +0,0 @@ -// target-fuelvm - -contract; - -pub struct ContractId { - /// The underlying raw `b256` data of the contract id. - pub value: b256, -} - -abi MyContract { - fn test_function(code_id: ContractId); -} - -impl MyContract for Contract { - fn test_function(code_id_p: ContractId) { - let length = asm(code_id, length, word, ssp_saved) { - // Allocate 32 bytes on the heap (we can't use the stack) - addi word zero i32; - aloc word; - - lw code_id fp i74; - - // Log the ContractID for debugging - logd zero zero code_id word; - - // Load the entire contract with LDC - csiz length code_id; - // Save the old ssp - move ssp_saved ssp; - ldc code_id zero length; - // return the ssp difference, to feed __jmpb_ssp. - // This need not always be equal to `length` as `ldc` pads the `length`. - sub length ssp ssp_saved; - length: u64 - }; - __jmpb_ssp(length) - } -} - -// ::check-ir:: - -// check: pub entry fn test_function<72a09f5b> - -// ::check-ir-optimized:: -// pass: o1 - -// check: pub entry fn test_function -// not: local -// check: csiz length code_id, !7 -// check: ldc code_id zero length, -// check: jmpb_ssp - -// ::check-asm:: - -// regex: REG=.r\d+\b - -// check: csiz $(len=$REG) $REG -// check: ldc $REG $$zero $len -// check: sub $(old_ssp=$REG) $$ssp $REG ; jmpb_ssp: Compute $$ssp - offset -// sub $(jmp_target_4=$REG) $old_ssp $$is ; jmpb_ssp: Subtract $$is since $$jmp adds it back -// divi $(jmp_target=$REG) $jmp_target_4 i4 ; jmpb_ssp: Divide by 4 since Jmp multiplies by 4 -// jmp $jmp_target ; jmpb_ssp: Jump to computed value