@@ -449,6 +449,8 @@ impl Cpu {
449
449
let quotient: u32 ;
450
450
let modulo: u32 ;
451
451
452
+ // This allows us to compute the quotient and modulo at once, avoiding doing two
453
+ // separate operations here.
452
454
unsafe {
453
455
asm ! (
454
456
"xor edx, edx" , // Clear the EDX register before attempting to load a new value into it.
@@ -718,24 +720,22 @@ impl Cpu {
718
720
719
721
let value = self . registers . read_reg_u32 ( source_reg, privilege) ;
720
722
721
- let final_value: u32 ;
722
- if is_x86_feature_detected ! ( "bmi2" ) {
723
- // We can use the inbuilt assembly instruction here for added performance gains.
724
- unsafe {
725
- asm ! (
726
- "bzhi {0:e}, {1:e}, {2:e}" ,
727
- out( reg) final_value,
728
- in( reg) value,
729
- in( reg) index,
730
- ) ;
731
- }
732
- } else {
733
- final_value = if index > 0 {
734
- value & ( ( 1 << index) - 1 )
723
+ let mut final_value: u32 = 0 ;
724
+ if index > 0 {
725
+ if is_x86_feature_detected ! ( "bmi2" ) {
726
+ // We can use the inbuilt assembly instruction here for added performance gains.
727
+ unsafe {
728
+ asm ! (
729
+ "bzhi {0:e}, {1:e}, {2:e}" ,
730
+ out( reg) final_value,
731
+ in( reg) value,
732
+ in( reg) index,
733
+ ) ;
734
+ }
735
735
} else {
736
- value
737
- } ;
738
- } ;
736
+ final_value = value & ( ( 1 << index ) - 1 )
737
+ }
738
+ }
739
739
740
740
self . set_flag_state ( CpuFlag :: SF , utils:: is_bit_set ( final_value, 31 ) ) ;
741
741
self . set_flag_state ( CpuFlag :: ZF , final_value == 0 ) ;
0 commit comments