@@ -509,12 +509,24 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
509
509
}
510
510
} ,
511
511
ebpf:: MUL32_IMM | ebpf:: DIV32_IMM | ebpf:: MOD32_IMM if !self . executable . get_sbpf_version ( ) . enable_pqr ( ) =>
512
- self . emit_product_quotient_remainder ( OperandSize :: S32 , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL , dst, dst, Some ( insn. imm ) ) ,
512
+ self . emit_product_quotient_remainder (
513
+ OperandSize :: S32 ,
514
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD ,
515
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL ,
516
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL ,
517
+ dst, dst, Some ( insn. imm ) ,
518
+ ) ,
513
519
ebpf:: LD_1B_REG if self . executable . get_sbpf_version ( ) . move_memory_instruction_classes ( ) => {
514
520
self . emit_address_translation ( Some ( dst) , Value :: RegisterPlusConstant64 ( src, insn. off as i64 , true ) , 1 , None ) ;
515
521
} ,
516
522
ebpf:: MUL32_REG | ebpf:: DIV32_REG | ebpf:: MOD32_REG if !self . executable . get_sbpf_version ( ) . enable_pqr ( ) =>
517
- self . emit_product_quotient_remainder ( OperandSize :: S32 , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL , src, dst, None ) ,
523
+ self . emit_product_quotient_remainder (
524
+ OperandSize :: S32 ,
525
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD ,
526
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL ,
527
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL ,
528
+ src, dst, None ,
529
+ ) ,
518
530
ebpf:: LD_2B_REG if self . executable . get_sbpf_version ( ) . move_memory_instruction_classes ( ) => {
519
531
self . emit_address_translation ( Some ( dst) , Value :: RegisterPlusConstant64 ( src, insn. off as i64 , true ) , 2 , None ) ;
520
532
} ,
@@ -594,15 +606,27 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
594
606
}
595
607
ebpf:: SUB64_REG => self . emit_ins ( X86Instruction :: alu ( OperandSize :: S64 , 0x29 , src, dst, 0 , None ) ) ,
596
608
ebpf:: MUL64_IMM | ebpf:: DIV64_IMM | ebpf:: MOD64_IMM if !self . executable . get_sbpf_version ( ) . enable_pqr ( ) =>
597
- self . emit_product_quotient_remainder ( OperandSize :: S64 , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL , dst, dst, Some ( insn. imm ) ) ,
609
+ self . emit_product_quotient_remainder (
610
+ OperandSize :: S64 ,
611
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD ,
612
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL ,
613
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL ,
614
+ dst, dst, Some ( insn. imm ) ,
615
+ ) ,
598
616
ebpf:: ST_1B_IMM if self . executable . get_sbpf_version ( ) . move_memory_instruction_classes ( ) => {
599
617
self . emit_address_translation ( None , Value :: RegisterPlusConstant64 ( dst, insn. off as i64 , true ) , 1 , Some ( Value :: Constant64 ( insn. imm , true ) ) ) ;
600
618
} ,
601
619
ebpf:: ST_2B_IMM if self . executable . get_sbpf_version ( ) . move_memory_instruction_classes ( ) => {
602
620
self . emit_address_translation ( None , Value :: RegisterPlusConstant64 ( dst, insn. off as i64 , true ) , 2 , Some ( Value :: Constant64 ( insn. imm , true ) ) ) ;
603
621
} ,
604
622
ebpf:: MUL64_REG | ebpf:: DIV64_REG | ebpf:: MOD64_REG if !self . executable . get_sbpf_version ( ) . enable_pqr ( ) =>
605
- self . emit_product_quotient_remainder ( OperandSize :: S64 , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL , ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL , src, dst, None ) ,
623
+ self . emit_product_quotient_remainder (
624
+ OperandSize :: S64 ,
625
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MOD ,
626
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) != ebpf:: BPF_MUL ,
627
+ ( insn. opc & ebpf:: BPF_ALU_OP_MASK ) == ebpf:: BPF_MUL ,
628
+ src, dst, None ,
629
+ ) ,
606
630
ebpf:: ST_1B_REG if self . executable . get_sbpf_version ( ) . move_memory_instruction_classes ( ) => {
607
631
self . emit_address_translation ( None , Value :: RegisterPlusConstant64 ( dst, insn. off as i64 , true ) , 1 , Some ( Value :: Register ( src) ) ) ;
608
632
} ,
@@ -651,26 +675,30 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
651
675
ebpf:: UDIV32_IMM | ebpf:: UDIV64_IMM | ebpf:: UREM32_IMM | ebpf:: UREM64_IMM |
652
676
ebpf:: SDIV32_IMM | ebpf:: SDIV64_IMM | ebpf:: SREM32_IMM | ebpf:: SREM64_IMM
653
677
if self . executable . get_sbpf_version ( ) . enable_pqr ( ) => {
678
+ let signed = insn. opc & ( 1 << 7 ) != 0 ;
679
+ let mut imm = insn. imm ;
680
+ if !signed {
681
+ imm &= u32:: MAX as i64 ;
682
+ }
654
683
self . emit_product_quotient_remainder (
655
684
if insn. opc & ( 1 << 4 ) != 0 { OperandSize :: S64 } else { OperandSize :: S32 } ,
656
685
insn. opc & ( 1 << 5 ) != 0 ,
657
686
insn. opc & ( 1 << 6 ) != 0 ,
658
- insn . opc & ( 1 << 7 ) != 0 ,
659
- dst, dst, Some ( insn . imm ) ,
687
+ signed ,
688
+ dst, dst, Some ( imm) ,
660
689
)
661
690
}
662
691
ebpf:: LMUL32_REG | ebpf:: LMUL64_REG | ebpf:: UHMUL64_REG | ebpf:: SHMUL64_REG |
663
692
ebpf:: UDIV32_REG | ebpf:: UDIV64_REG | ebpf:: UREM32_REG | ebpf:: UREM64_REG |
664
693
ebpf:: SDIV32_REG | ebpf:: SDIV64_REG | ebpf:: SREM32_REG | ebpf:: SREM64_REG
665
- if self . executable . get_sbpf_version ( ) . enable_pqr ( ) => {
694
+ if self . executable . get_sbpf_version ( ) . enable_pqr ( ) =>
666
695
self . emit_product_quotient_remainder (
667
696
if insn. opc & ( 1 << 4 ) != 0 { OperandSize :: S64 } else { OperandSize :: S32 } ,
668
697
insn. opc & ( 1 << 5 ) != 0 ,
669
698
insn. opc & ( 1 << 6 ) != 0 ,
670
699
insn. opc & ( 1 << 7 ) != 0 ,
671
700
src, dst, None ,
672
- )
673
- }
701
+ ) ,
674
702
675
703
// BPF_JMP class
676
704
ebpf:: JA => {
@@ -1272,7 +1300,16 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
1272
1300
}
1273
1301
1274
1302
#[ allow( clippy:: too_many_arguments) ]
1275
- fn emit_product_quotient_remainder ( & mut self , size : OperandSize , alt_dst : bool , division : bool , signed : bool , src : u8 , dst : u8 , imm : Option < i64 > ) {
1303
+ fn emit_product_quotient_remainder (
1304
+ & mut self ,
1305
+ size : OperandSize ,
1306
+ alt_dst : bool ,
1307
+ division : bool ,
1308
+ signed : bool ,
1309
+ src : u8 ,
1310
+ dst : u8 ,
1311
+ imm : Option < i64 > ,
1312
+ ) {
1276
1313
// LMUL UHMUL SHMUL UDIV SDIV UREM SREM
1277
1314
// ALU F7/4 F7/4 F7/5 F7/6 F7/7 F7/6 F7/7
1278
1315
// src-in REGISTER_SCRATCH REGISTER_SCRATCH REGISTER_SCRATCH REGISTER_SCRATCH REGISTER_SCRATCH REGISTER_SCRATCH REGISTER_SCRATCH
0 commit comments