@@ -1297,17 +1297,20 @@ pub(crate) struct PatchableAddToReg {
1297
1297
region : PatchRegion ,
1298
1298
1299
1299
// The destination register for the add instruction.
1300
- reg : Reg ,
1300
+ reg : Writable < Reg > ,
1301
1301
1302
1302
// The temporary register used to hold the immediate value.
1303
- tmp : Reg ,
1303
+ tmp : Writable < Reg > ,
1304
1304
}
1305
1305
1306
1306
impl PatchableAddToReg {
1307
- /// Create a new [`PatchableAddToReg`] by capturing a region in the output buffer where the
1308
- /// add-with-immediate sequence occurs. The [`MachBuffer`] will have and add-with-immediate instruction
1309
- /// sequence present in that region, though it will add `0` until the `::finalize` method is called.
1310
- pub ( crate ) fn new ( reg : Reg , tmp : Reg , buf : & mut MachBuffer < Inst > ) -> Self {
1307
+ /// Create a new [`PatchableAddToReg`] by capturing a region in the output
1308
+ /// buffer containing an instruction sequence that loads an immediate into a
1309
+ /// register `tmp`, then adds it to a register `reg`. The [`MachBuffer`]
1310
+ /// will have that instruction sequence written to the region, though the
1311
+ /// immediate loaded into `tmp` will be `0` until the `::finalize` method is
1312
+ /// called.
1313
+ pub ( crate ) fn new ( reg : Writable < Reg > , tmp : Writable < Reg > , buf : & mut MachBuffer < Inst > ) -> Self {
1311
1314
let insns = Self :: add_immediate_instruction_sequence ( reg, tmp, 0 ) ;
1312
1315
let open = buf. start_patchable ( ) ;
1313
1316
buf. put_data ( & insns) ;
@@ -1316,7 +1319,11 @@ impl PatchableAddToReg {
1316
1319
Self { region, reg, tmp }
1317
1320
}
1318
1321
1319
- fn add_immediate_instruction_sequence ( reg : Reg , tmp : Reg , imm : i32 ) -> [ u8 ; 12 ] {
1322
+ fn add_immediate_instruction_sequence (
1323
+ reg : Writable < Reg > ,
1324
+ tmp : Writable < Reg > ,
1325
+ imm : i32 ,
1326
+ ) -> [ u8 ; 12 ] {
1320
1327
let imm_hi = imm as u64 & 0xffff_0000 ;
1321
1328
let imm_hi = MoveWideConst :: maybe_from_u64 ( imm_hi) . unwrap ( ) ;
1322
1329
@@ -1325,18 +1332,15 @@ impl PatchableAddToReg {
1325
1332
1326
1333
let size = OperandSize :: S64 . into ( ) ;
1327
1334
1328
- let tmp = writable ! ( tmp) ;
1329
1335
let tmp = tmp. map ( Into :: into) ;
1336
+ let rd = reg. map ( Into :: into) ;
1330
1337
1331
1338
// This is "movz to bits 16-31 of 64 bit reg tmp and zero the rest"
1332
1339
let mov_insn = enc_move_wide ( inst:: MoveWideOp :: MovZ , tmp, imm_hi, size) ;
1333
1340
1334
1341
// This is "movk to bits 0-15 of 64 bit reg tmp"
1335
1342
let movk_insn = enc_movk ( tmp, imm_lo, size) ;
1336
1343
1337
- let rd = writable ! ( reg) ;
1338
- let rd = rd. map ( Into :: into) ;
1339
-
1340
1344
// This is "add tmp to rd". The opcodes are somewhat buried in the
1341
1345
// instruction encoder so we just repeat them here.
1342
1346
let add_bits_31_21: u32 = 0b00001011_000 | ( size. sf_bit ( ) << 10 ) ;
0 commit comments