#x86 #cpuid #libcore #parser #os

no-std bin+lib raw-cpuid

A library to parse the x86 CPUID instruction, written in rust with no external dependencies. The implementation closely resembles the Intel CPUID manual description. The library does only depend on libcore.

47 releases (stable)

11.0.1 May 3, 2023
10.7.0 Feb 27, 2023
10.6.0 Sep 12, 2022
10.3.0 Mar 19, 2022
0.0.2 Mar 24, 2015

#6 in Hardware support

Download history 198922/week @ 2024-01-03 210940/week @ 2024-01-10 246238/week @ 2024-01-17 236388/week @ 2024-01-24 237679/week @ 2024-01-31 255531/week @ 2024-02-07 250330/week @ 2024-02-14 277482/week @ 2024-02-21 295614/week @ 2024-02-28 288883/week @ 2024-03-06 305454/week @ 2024-03-13 315639/week @ 2024-03-20 306638/week @ 2024-03-27 338343/week @ 2024-04-03 338541/week @ 2024-04-10 267021/week @ 2024-04-17

1,308,570 downloads per month
Used in 953 crates (52 directly)

MIT license

505KB
9K SLoC

cpuid Crates.io Standard checks

A library to parse the x86 CPUID instruction, written in rust with no external dependencies. The implementation closely resembles the Intel CPUID manual description. The library works in no_std environments. Some additional cargo features require std (e.g., pretty printing, serialization).

  • For Intel platforms: The code should be in sync with the March 2018 revision of the Intel Architectures SDM.
  • For AMD platforms it should be in sync with the AMD64 systems manual no. 24594, Revision 3.32 (March 2021).

Library usage

use raw_cpuid::CpuId;
let cpuid = CpuId::new();

if let Some(vf) = cpuid.get_vendor_info() {
    assert!(vf.as_str() == "GenuineIntel" || vf.as_str() == "AuthenticAMD");
}

let has_sse = cpuid.get_feature_info().map_or(false, |finfo| finfo.has_sse());
if has_sse {
    println!("CPU supports SSE!");
}

if let Some(cparams) = cpuid.get_cache_parameters() {
    for cache in cparams {
        let size = cache.associativity() * cache.physical_line_partitions() * cache.coherency_line_size() * cache.sets();
        println!("L{}-Cache size is {}", cache.level(), size);
    }
} else {
    println!("No cache parameter information available")
}

cpuid binary

raw-cpuid ships with a cpuid binary that can be installed to inspect the output of the CPUID instruction on a host system.

To install, use:

cargo install raw-cpuid --features cli

The cli feature is currently required to build the binary version due to cargo limitations.

Documentation

Dependencies

~0.1–10MB
~71K SLoC