Skip to content

Commit 42350be

Browse files
committed
Some comments and minor refactors.
1 parent 3daa6bf commit 42350be

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

redox-core/src/cpu.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ impl Cpu {
449449
let quotient: u32;
450450
let modulo: u32;
451451

452+
// This allows us to compute the quotient and modulo at once, avoiding doing two
453+
// separate operations here.
452454
unsafe {
453455
asm!(
454456
"xor edx, edx", // Clear the EDX register before attempting to load a new value into it.
@@ -718,24 +720,22 @@ impl Cpu {
718720

719721
let value = self.registers.read_reg_u32(source_reg, privilege);
720722

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+
}
735735
} else {
736-
value
737-
};
738-
};
736+
final_value = value & ((1 << index) - 1)
737+
}
738+
}
739739

740740
self.set_flag_state(CpuFlag::SF, utils::is_bit_set(final_value, 31));
741741
self.set_flag_state(CpuFlag::ZF, final_value == 0);

0 commit comments

Comments
 (0)