RustCrypto / utils

Utility crates used in RustCrypto
450 stars 130 forks source link

cpufeatures: PCLMULQDQ does not require OSXSAVE #1129

Closed ericlagergren closed 2 weeks ago

ericlagergren commented 3 weeks ago

For example, this is fails on an M1 running under Rosetta (macOS Sequoia 15.0):

fn main() {
    cpufeatures::new!(has_pclmulqdq, "pclmulqdq");
    assert!(has_pclmulqdq::get());
}

macOS (under Rosetta) does not support OSXSAVE or AVX, so has_pclmulqdq returns false. But PCLMULQDQ does not require AVX, only SSE2 + CLMUL.

Indeed, Go does not require OSXSAVE for PCLMULQDQ

See also: https://github.com/golang/go/issues/41022

newpavlov commented 2 weeks ago

PCLMULQDQ works with XMM registers and I thought that XSAVE support (with 0b10 bits) is needed for properly saving and restoring XMM registers, e.g. during context switches.

Looking at is_x86_feature_detected's source code, it looks like it does not have a similar XSAVE check for XMM registers, so I guess we can drop it as well.