@@ -3139,35 +3139,38 @@ impl MachInstEmit for Inst {
31393139 stack_bytes_to_pop,
31403140 ..
31413141 } => {
3142- let key = match key {
3143- APIKey :: A => 0b0 ,
3144- APIKey :: B => 0b1 ,
3142+ if stack_bytes_to_pop != 0 {
3143+ // The requirement that `stack_bytes_to_pop` fit in an
3144+ // `Imm12` isn't fundamental, but lifting it is left for
3145+ // future PRs.
3146+ let imm12 = Imm12 :: maybe_from_u64 ( u64:: from ( stack_bytes_to_pop) )
3147+ . expect ( "stack bytes to pop must fit in Imm12" ) ;
3148+ Inst :: AluRRImm12 {
3149+ alu_op : ALUOp :: Add ,
3150+ size : OperandSize :: Size64 ,
3151+ rd : writable_stack_reg ( ) ,
3152+ rn : stack_reg ( ) ,
3153+ imm12,
3154+ }
3155+ . emit ( & [ ] , sink, emit_info, state) ;
3156+ }
3157+
3158+ let ( op2, is_hint) = match key {
3159+ APIKey :: AZ => ( 0b100 , true ) ,
3160+ APIKey :: ASP => ( 0b101 , is_hint) ,
3161+ APIKey :: BZ => ( 0b110 , true ) ,
3162+ APIKey :: BSP => ( 0b111 , is_hint) ,
31453163 } ;
31463164
31473165 if is_hint {
3148- sink. put4 ( 0xd50323bf | key << 6 ) ; // autiasp / autibsp
3166+ sink. put4 ( key. enc_auti_hint ( ) ) ;
31493167 Inst :: Ret {
31503168 rets : vec ! [ ] ,
3151- stack_bytes_to_pop,
3169+ stack_bytes_to_pop : 0 ,
31523170 }
31533171 . emit ( & [ ] , sink, emit_info, state) ;
31543172 } else {
3155- if stack_bytes_to_pop != 0 {
3156- // The requirement that `stack_bytes_to_pop` fit in an
3157- // `Imm12` isn't fundamental, but lifting it is left for
3158- // future PRs.
3159- let imm12 = Imm12 :: maybe_from_u64 ( u64:: from ( stack_bytes_to_pop) )
3160- . expect ( "stack bytes to pop must fit in Imm12" ) ;
3161- Inst :: AluRRImm12 {
3162- alu_op : ALUOp :: Add ,
3163- size : OperandSize :: Size64 ,
3164- rd : writable_stack_reg ( ) ,
3165- rn : stack_reg ( ) ,
3166- imm12,
3167- }
3168- . emit ( & [ ] , sink, emit_info, state) ;
3169- }
3170- sink. put4 ( 0xd65f0bff | key << 10 ) ; // retaa / retab
3173+ sink. put4 ( 0xd65f0bff | ( op2 << 9 ) ) ; // reta{key}
31713174 }
31723175 }
31733176 & Inst :: Call { ref info } => {
@@ -3208,15 +3211,7 @@ impl MachInstEmit for Inst {
32083211 ref callee,
32093212 ref info,
32103213 } => {
3211- emit_return_call_common_sequence (
3212- & mut allocs,
3213- sink,
3214- emit_info,
3215- state,
3216- info. new_stack_arg_size ,
3217- info. old_stack_arg_size ,
3218- & info. uses ,
3219- ) ;
3214+ emit_return_call_common_sequence ( & mut allocs, sink, emit_info, state, info) ;
32203215
32213216 // Note: this is not `Inst::Jump { .. }.emit(..)` because we
32223217 // have different metadata in this case: we don't have a label
@@ -3233,15 +3228,7 @@ impl MachInstEmit for Inst {
32333228 & Inst :: ReturnCallInd { callee, ref info } => {
32343229 let callee = allocs. next ( callee) ;
32353230
3236- emit_return_call_common_sequence (
3237- & mut allocs,
3238- sink,
3239- emit_info,
3240- state,
3241- info. new_stack_arg_size ,
3242- info. old_stack_arg_size ,
3243- & info. uses ,
3244- ) ;
3231+ emit_return_call_common_sequence ( & mut allocs, sink, emit_info, state, info) ;
32453232
32463233 Inst :: IndirectBr {
32473234 rn : callee,
@@ -3556,13 +3543,15 @@ impl MachInstEmit for Inst {
35563543 add. emit ( & [ ] , sink, emit_info, state) ;
35573544 }
35583545 }
3559- & Inst :: Pacisp { key } => {
3560- let key = match key {
3561- APIKey :: A => 0b0 ,
3562- APIKey :: B => 0b1 ,
3546+ & Inst :: Paci { key } => {
3547+ let ( crm, op2) = match key {
3548+ APIKey :: AZ => ( 0b0011 , 0b000 ) ,
3549+ APIKey :: ASP => ( 0b0011 , 0b001 ) ,
3550+ APIKey :: BZ => ( 0b0011 , 0b010 ) ,
3551+ APIKey :: BSP => ( 0b0011 , 0b011 ) ,
35633552 } ;
35643553
3565- sink. put4 ( 0xd503233f | key << 6 ) ;
3554+ sink. put4 ( 0xd503211f | ( crm << 8 ) | ( op2 << 5 ) ) ;
35663555 }
35673556 & Inst :: Xpaclri => sink. put4 ( 0xd50320ff ) ,
35683557 & Inst :: Bti { targets } => {
@@ -3768,18 +3757,16 @@ fn emit_return_call_common_sequence(
37683757 sink : & mut MachBuffer < Inst > ,
37693758 emit_info : & EmitInfo ,
37703759 state : & mut EmitState ,
3771- new_stack_arg_size : u32 ,
3772- old_stack_arg_size : u32 ,
3773- uses : & CallArgList ,
3760+ info : & ReturnCallInfo ,
37743761) {
3775- for u in uses {
3762+ for u in info . uses . iter ( ) {
37763763 let _ = allocs. next ( u. vreg ) ;
37773764 }
37783765
37793766 // We are emitting a dynamic number of instructions and might need an
37803767 // island. We emit four instructions regardless of how many stack arguments
37813768 // we have, and then two instructions per word of stack argument space.
3782- let new_stack_words = new_stack_arg_size / 8 ;
3769+ let new_stack_words = info . new_stack_arg_size / 8 ;
37833770 let insts = 4 + 2 * new_stack_words;
37843771 let size_of_inst = 4 ;
37853772 let space_needed = insts * size_of_inst;
@@ -3820,7 +3807,7 @@ fn emit_return_call_common_sequence(
38203807 // actual jump happens outside this helper function.
38213808
38223809 assert_eq ! (
3823- new_stack_arg_size % 8 ,
3810+ info . new_stack_arg_size % 8 ,
38243811 0 ,
38253812 "size of new stack arguments must be 8-byte aligned"
38263813 ) ;
@@ -3830,7 +3817,8 @@ fn emit_return_call_common_sequence(
38303817 // arguments as well as accounting for the two words we pushed onto the
38313818 // stack upon entry to this function (the return address and old frame
38323819 // pointer).
3833- let fp_to_callee_sp = i64:: from ( old_stack_arg_size) - i64:: from ( new_stack_arg_size) + 16 ;
3820+ let fp_to_callee_sp =
3821+ i64:: from ( info. old_stack_arg_size ) - i64:: from ( info. new_stack_arg_size ) + 16 ;
38343822
38353823 let tmp1 = regs:: writable_spilltmp_reg ( ) ;
38363824 let tmp2 = regs:: writable_tmp2_reg ( ) ;
@@ -3910,10 +3898,14 @@ fn emit_return_call_common_sequence(
39103898 }
39113899 . emit ( & [ ] , sink, emit_info, state) ;
39123900
3913- state. virtual_sp_offset -= i64:: from ( new_stack_arg_size) ;
3901+ state. virtual_sp_offset -= i64:: from ( info . new_stack_arg_size ) ;
39143902 trace ! (
39153903 "return_call[_ind] adjusts virtual sp offset by {} -> {}" ,
3916- new_stack_arg_size,
3904+ info . new_stack_arg_size,
39173905 state. virtual_sp_offset
39183906 ) ;
3907+
3908+ if let Some ( key) = info. key {
3909+ sink. put4 ( key. enc_auti_hint ( ) ) ;
3910+ }
39193911}
0 commit comments