@@ -28,10 +28,19 @@ pub struct CpuidResult {
28
28
/// Returns the result of the `cpuid` instruction for a given `leaf` (`EAX`)
29
29
/// and `sub_leaf` (`ECX`).
30
30
///
31
- /// The highest-supported leaf value is returned by the first tuple argument of
32
- /// [`__get_cpuid_max(0)`](fn.__get_cpuid_max.html). For leaves containing
33
- /// sub-leaves, the second tuple argument returns the highest-supported
34
- /// sub-leaf value.
31
+ /// There are 2 types of information leafs - basic leafs (with `leaf < 0x8000000`)
32
+ /// and extended leafs (with `leaf >= 0x80000000`). The highest supported basic and
33
+ /// extended leafs can be obtained by calling CPUID with `0` and `0x80000000`,
34
+ /// respectively, and reading the value in the `EAX` register. If the leaf supports
35
+ /// more than one sub-leafs, then the procedure of obtaining the highest supported
36
+ /// sub-leaf, as well as the behavior if a invalid sub-leaf value is passed, depends
37
+ /// on the specific leaf.
38
+ ///
39
+ /// If the `leaf` value is higher than the maximum supported basic or extended leaf
40
+ /// for the processor, this returns the information for the highest supported basic
41
+ /// information leaf (with the passed `sub_leaf` value). If the `leaf` value is less
42
+ /// than or equal to the highest basic or extended leaf value, but the leaf is not
43
+ /// supported on the processor, all zeros are returned.
35
44
///
36
45
/// The [CPUID Wikipedia page][wiki_cpuid] contains how to query which
37
46
/// information using the `EAX` and `ECX` registers, and the interpretation of
@@ -49,7 +58,7 @@ pub struct CpuidResult {
49
58
#[ inline]
50
59
#[ cfg_attr( test, assert_instr( cpuid) ) ]
51
60
#[ stable( feature = "simd_x86" , since = "1.27.0" ) ]
52
- pub unsafe fn __cpuid_count ( leaf : u32 , sub_leaf : u32 ) -> CpuidResult {
61
+ pub fn __cpuid_count ( leaf : u32 , sub_leaf : u32 ) -> CpuidResult {
53
62
let eax;
54
63
let ebx;
55
64
let ecx;
@@ -58,7 +67,7 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
58
67
// LLVM sometimes reserves `ebx` for its internal use, we so we need to use
59
68
// a scratch register for it instead.
60
69
#[ cfg( target_arch = "x86" ) ]
61
- {
70
+ unsafe {
62
71
asm ! (
63
72
"mov {0}, ebx" ,
64
73
"cpuid" ,
@@ -71,7 +80,7 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
71
80
) ;
72
81
}
73
82
#[ cfg( target_arch = "x86_64" ) ]
74
- {
83
+ unsafe {
75
84
asm ! (
76
85
"mov {0:r}, rbx" ,
77
86
"cpuid" ,
@@ -86,27 +95,26 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
86
95
CpuidResult { eax, ebx, ecx, edx }
87
96
}
88
97
98
+ /// Calls CPUID with the provided `leaf` value, with `sub_leaf` set to 0.
89
99
/// See [`__cpuid_count`](fn.__cpuid_count.html).
90
100
#[ inline]
91
101
#[ cfg_attr( test, assert_instr( cpuid) ) ]
92
102
#[ stable( feature = "simd_x86" , since = "1.27.0" ) ]
93
- pub unsafe fn __cpuid ( leaf : u32 ) -> CpuidResult {
103
+ pub fn __cpuid ( leaf : u32 ) -> CpuidResult {
94
104
__cpuid_count ( leaf, 0 )
95
105
}
96
106
97
- /// Returns the highest-supported `leaf` (` EAX`) and sub-leaf (`ECX`) `cpuid`
98
- /// values .
107
+ /// Returns the EAX and EBX register after calling CPUID with the provided `leaf`,
108
+ /// with `sub_leaf` set to 0 .
99
109
///
100
- /// If `cpuid` is supported, and `leaf` is zero, then the first tuple argument
101
- /// contains the highest `leaf` value that `cpuid` supports. For `leaf`s
102
- /// containing sub-leafs, the second tuple argument contains the
103
- /// highest-supported sub-leaf value.
110
+ /// If `leaf` if 0 or `0x80000000`, the first tuple argument contains the maximum
111
+ /// supported basic or extended leaf, respectively.
104
112
///
105
113
/// See also [`__cpuid`](fn.__cpuid.html) and
106
114
/// [`__cpuid_count`](fn.__cpuid_count.html).
107
115
#[ inline]
108
116
#[ stable( feature = "simd_x86" , since = "1.27.0" ) ]
109
- pub unsafe fn __get_cpuid_max ( leaf : u32 ) -> ( u32 , u32 ) {
117
+ pub fn __get_cpuid_max ( leaf : u32 ) -> ( u32 , u32 ) {
110
118
let CpuidResult { eax, ebx, .. } = __cpuid ( leaf) ;
111
119
( eax, ebx)
112
120
}
0 commit comments