Skip to content

Commit 46facd1

Browse files
committed
Removes redundant load of target_pc in REGISTER_SCRATCH
1 parent 2a474e2 commit 46facd1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/jit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
720720
// BPF_JMP class
721721
ebpf::JA => {
722722
self.emit_validate_and_profile_instruction_count(Some(target_pc));
723-
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, target_pc as i64));
724723
let jump_offset = self.relative_to_target_pc(target_pc, 5);
725724
self.emit_ins(X86Instruction::jump_immediate(jump_offset));
726725
},
@@ -1222,7 +1221,6 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
12221221
} else { // Arithmetic
12231222
self.emit_ins(X86Instruction::cmp(OperandSize::S64, first_operand, second_operand, None));
12241223
}
1225-
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, target_pc as i64));
12261224
let jump_offset = self.relative_to_target_pc(target_pc, 6);
12271225
self.emit_ins(X86Instruction::conditional_jump_immediate(op, jump_offset));
12281226
self.emit_undo_profile_instruction_count(target_pc);
@@ -1232,18 +1230,19 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
12321230
fn emit_conditional_branch_imm(&mut self, op: u8, bitwise: bool, immediate: i64, second_operand: X86Register, target_pc: usize) {
12331231
self.emit_validate_and_profile_instruction_count(Some(target_pc));
12341232
if self.should_sanitize_constant(immediate) {
1233+
self.emit_ins(X86Instruction::mov_mmx(OperandSize::S64, REGISTER_SCRATCH, MM0));
12351234
self.emit_sanitized_load_immediate(REGISTER_SCRATCH, immediate);
12361235
if bitwise { // Logical
12371236
self.emit_ins(X86Instruction::test(OperandSize::S64, REGISTER_SCRATCH, second_operand, None));
12381237
} else { // Arithmetic
12391238
self.emit_ins(X86Instruction::cmp(OperandSize::S64, REGISTER_SCRATCH, second_operand, None));
12401239
}
1240+
self.emit_ins(X86Instruction::mov_mmx(OperandSize::S64, MM0, REGISTER_SCRATCH));
12411241
} else if bitwise { // Logical
12421242
self.emit_ins(X86Instruction::test_immediate(OperandSize::S64, second_operand, immediate, None));
12431243
} else { // Arithmetic
12441244
self.emit_ins(X86Instruction::cmp_immediate(OperandSize::S64, second_operand, immediate, None));
12451245
}
1246-
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, target_pc as i64));
12471246
let jump_offset = self.relative_to_target_pc(target_pc, 6);
12481247
self.emit_ins(X86Instruction::conditional_jump_immediate(op, jump_offset));
12491248
self.emit_undo_profile_instruction_count(target_pc);

0 commit comments

Comments
 (0)