Skip to content

Commit 524e841

Browse files
committed
Removes redundant load of target_pc in REGISTER_SCRATCH
1 parent eec30c5 commit 524e841

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
@@ -723,7 +723,6 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
723723
// BPF_JMP class
724724
ebpf::JA => {
725725
self.emit_validate_and_profile_instruction_count(Some(target_pc));
726-
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, target_pc as i64));
727726
let jump_offset = self.relative_to_target_pc(target_pc, 5);
728727
self.emit_ins(X86Instruction::jump_immediate(jump_offset));
729728
},
@@ -1225,7 +1224,6 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
12251224
} else { // Arithmetic
12261225
self.emit_ins(X86Instruction::cmp(OperandSize::S64, first_operand, second_operand, None));
12271226
}
1228-
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, target_pc as i64));
12291227
let jump_offset = self.relative_to_target_pc(target_pc, 6);
12301228
self.emit_ins(X86Instruction::conditional_jump_immediate(op, jump_offset));
12311229
self.emit_undo_profile_instruction_count(target_pc);
@@ -1235,18 +1233,19 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
12351233
fn emit_conditional_branch_imm(&mut self, op: u8, bitwise: bool, immediate: i64, second_operand: X86Register, target_pc: usize) {
12361234
self.emit_validate_and_profile_instruction_count(Some(target_pc));
12371235
if self.should_sanitize_constant(immediate) {
1236+
self.emit_ins(X86Instruction::mov_mmx(OperandSize::S64, REGISTER_SCRATCH, MM0));
12381237
self.emit_sanitized_load_immediate(REGISTER_SCRATCH, immediate);
12391238
if bitwise { // Logical
12401239
self.emit_ins(X86Instruction::test(OperandSize::S64, REGISTER_SCRATCH, second_operand, None));
12411240
} else { // Arithmetic
12421241
self.emit_ins(X86Instruction::cmp(OperandSize::S64, REGISTER_SCRATCH, second_operand, None));
12431242
}
1243+
self.emit_ins(X86Instruction::mov_mmx(OperandSize::S64, MM0, REGISTER_SCRATCH));
12441244
} else if bitwise { // Logical
12451245
self.emit_ins(X86Instruction::test_immediate(OperandSize::S64, second_operand, immediate, None));
12461246
} else { // Arithmetic
12471247
self.emit_ins(X86Instruction::cmp_immediate(OperandSize::S64, second_operand, immediate, None));
12481248
}
1249-
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, target_pc as i64));
12501249
let jump_offset = self.relative_to_target_pc(target_pc, 6);
12511250
self.emit_ins(X86Instruction::conditional_jump_immediate(op, jump_offset));
12521251
self.emit_undo_profile_instruction_count(target_pc);

0 commit comments

Comments
 (0)