Skip to content

Commit fd3a3f2

Browse files
committed
hoist the and out of the inline assembly
1 parent d94dcff commit fd3a3f2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

coresimd/x86/cpuid.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,23 @@ pub fn has_cpuid() -> bool {
113113
# xor with the original eflags sets the bits that
114114
# have been modified:
115115
xor $0, $1
116-
# There is a race between popfd (A) and pushfd (B)
117-
# where other bits beyond 21st may have been modified due to
118-
# interrupts, a debugger stepping through the asm, etc.
119-
#
120-
# Therefore, explicitly check whether the 21st bit
121-
# was modified or not:
122-
and $0, 0x200000
123116
"#
124117
: "=r"(result), "=r"(_temp)
125118
:
126119
: "cc", "memory"
127120
: "intel");
128-
// If result == 0, the 21st bit was not modified and cpuid is
129-
// not available. If cpuid is available, the bit was modified and
130-
// result != 0.
131-
result != 0
121+
// There is a race between popfd (A) and pushfd (B)
122+
// where other bits beyond 21st may have been modified due to
123+
// interrupts, a debugger stepping through the asm, etc.
124+
//
125+
// Therefore, explicitly check whether the 21st bit
126+
// was modified or not.
127+
//
128+
// If the result is zero, the cpuid bit was not modified.
129+
// If the result is 0x200000 (non-zero), then the cpuid
130+
// was correctly modified and the CPU supports the cpuid
131+
// instruction:
132+
(result & 0x200000) != 0
132133
}
133134
}
134135
}

0 commit comments

Comments
 (0)