From af43e6851bdbf5a2c484fbf145ca7a1a12a22dd1 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 23 Feb 2026 23:55:36 +0100 Subject: [PATCH] [core:sys/info] Remove `, ok` --- core/crypto/_aes/hw_intel/api.odin | 4 +--- core/crypto/_chacha20/simd128/chacha20_simd128.odin | 4 +--- core/crypto/_chacha20/simd256/chacha20_simd256.odin | 4 +--- core/crypto/sha2/sha2_impl_hw_intel.odin | 4 +--- core/sys/info/cpu_arm.odin | 1 - core/sys/info/cpu_darwin_arm64.odin | 4 ++-- core/sys/info/cpu_intel.odin | 8 ++------ core/sys/info/cpu_linux_arm.odin | 6 ++---- core/sys/info/cpu_linux_riscv64.odin | 6 ++---- core/sys/info/cpu_other.odin | 4 ++-- core/sys/info/cpu_riscv64.odin | 3 +-- core/sys/info/cpu_wasm.odin | 4 ++-- core/sys/info/doc.odin | 11 +++++------ core/sys/info/sysinfo.odin | 13 ++++++------- 14 files changed, 28 insertions(+), 48 deletions(-) diff --git a/core/crypto/_aes/hw_intel/api.odin b/core/crypto/_aes/hw_intel/api.odin index e2da09f12..ce769fc10 100644 --- a/core/crypto/_aes/hw_intel/api.odin +++ b/core/crypto/_aes/hw_intel/api.odin @@ -6,8 +6,6 @@ import "core:sys/info" // is_supported returns true iff hardware accelerated AES // is supported. is_supported :: proc "contextless" () -> bool { - features := info.cpu_features() or_return - // Note: Everything with AES-NI and PCLMULQDQ has support for // the required SSE extxtensions. req_features :: info.CPU_Features{ @@ -17,7 +15,7 @@ is_supported :: proc "contextless" () -> bool { .aes, .pclmulqdq, } - return features >= req_features + return info.cpu_features() >= req_features } // Context is a keyed AES (ECB) instance. diff --git a/core/crypto/_chacha20/simd128/chacha20_simd128.odin b/core/crypto/_chacha20/simd128/chacha20_simd128.odin index e477954d2..9da0a54ea 100644 --- a/core/crypto/_chacha20/simd128/chacha20_simd128.odin +++ b/core/crypto/_chacha20/simd128/chacha20_simd128.odin @@ -227,9 +227,7 @@ is_performant :: proc "contextless" () -> bool { req_features :: info.CPU_Features{.V} } - features := info.cpu_features() or_return - - return features >= req_features + return info.cpu_features() >= req_features } else when ODIN_ARCH == .wasm64p32 || ODIN_ARCH == .wasm32 { return intrinsics.has_target_feature("simd128") } else { diff --git a/core/crypto/_chacha20/simd256/chacha20_simd256.odin b/core/crypto/_chacha20/simd256/chacha20_simd256.odin index ebc294590..407fbac56 100644 --- a/core/crypto/_chacha20/simd256/chacha20_simd256.odin +++ b/core/crypto/_chacha20/simd256/chacha20_simd256.odin @@ -39,11 +39,9 @@ _VEC_TWO: simd.u64x4 : {2, 0, 2, 0} // is_performant returns true iff the target and current host both support // "enough" SIMD to make this implementation performant. is_performant :: proc "contextless" () -> bool { - features := info.cpu_features() or_return - req_features :: info.CPU_Features{.avx, .avx2} - return features >= req_features + return info.cpu_features() >= req_features } @(private = "file") diff --git a/core/crypto/sha2/sha2_impl_hw_intel.odin b/core/crypto/sha2/sha2_impl_hw_intel.odin index 594edf0dc..83ef58a12 100644 --- a/core/crypto/sha2/sha2_impl_hw_intel.odin +++ b/core/crypto/sha2/sha2_impl_hw_intel.odin @@ -52,15 +52,13 @@ K_15 :: simd.u64x2{0xa4506ceb90befffa, 0xc67178f2bef9a3f7} // is_hardware_accelerated_256 returns true iff hardware accelerated // SHA-224/SHA-256 is supported. is_hardware_accelerated_256 :: proc "contextless" () -> bool { - features := info.cpu_features() or_return - req_features :: info.CPU_Features{ .sse2, .ssse3, .sse41, .sha, } - return features >= req_features + return info.cpu_features() >= req_features } @(private, enable_target_feature="sse2,ssse3,sse4.1,sha") diff --git a/core/sys/info/cpu_arm.odin b/core/sys/info/cpu_arm.odin index c254432e3..439007e24 100644 --- a/core/sys/info/cpu_arm.odin +++ b/core/sys/info/cpu_arm.odin @@ -43,7 +43,6 @@ CPU_Features :: distinct bit_set[CPU_Feature; u64] // Retrieving CPU features on ARM is even more expensive than on Intel, so we're doing this lookup only once, before `main()` @(private) _features: CPU_Features -@(private) _features_ok: bool @(private) _name_buf: [256]u8 diff --git a/core/sys/info/cpu_darwin_arm64.odin b/core/sys/info/cpu_darwin_arm64.odin index 45f1d4082..7f4c7dda2 100644 --- a/core/sys/info/cpu_darwin_arm64.odin +++ b/core/sys/info/cpu_darwin_arm64.odin @@ -3,8 +3,8 @@ package sysinfo import "core:sys/unix" @(private) -_cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { - return _features, true +_cpu_features :: proc "contextless" () -> (features: CPU_Features) { + return _features } @(init, private) diff --git a/core/sys/info/cpu_intel.odin b/core/sys/info/cpu_intel.odin index 01cee1b3e..0a75e2475 100644 --- a/core/sys/info/cpu_intel.odin +++ b/core/sys/info/cpu_intel.odin @@ -53,7 +53,6 @@ CPU_Features :: distinct bit_set[CPU_Feature; u64] // `cpuid` is a barrier so we try not performing this query this more than necessary. // `atomic_load_explicit` is also a barrier, so we're doing this lookup only once, before `main()` @(private) _features: CPU_Features -@(private) _features_ok: bool @(init, private) _init_cpu_features :: proc "contextless" () { @@ -69,7 +68,6 @@ _init_cpu_features :: proc "contextless" () { max_id, _, _, _ := cpuid(0, 0) if max_id < 1 { _features = {} - _features_ok = false return } @@ -87,8 +85,6 @@ _init_cpu_features :: proc "contextless" () { try_set(&_features, .os_xsave, 27, ecx1) try_set(&_features, .rdrand, 30, ecx1) - _features_ok = true - when ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD { // xgetbv is an illegal instruction under FreeBSD 13, OpenBSD 7.1 and NetBSD 10 // return before probing further @@ -156,8 +152,8 @@ _init_cpu_features :: proc "contextless" () { } @(private) -_cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { - return _features, _features_ok +_cpu_features :: proc "contextless" () -> (features: CPU_Features) { + return _features } // `cpuid` is a barrier so we try not performing this query this more than necessary. diff --git a/core/sys/info/cpu_linux_arm.odin b/core/sys/info/cpu_linux_arm.odin index cfdcbaf75..492b51c8b 100644 --- a/core/sys/info/cpu_linux_arm.odin +++ b/core/sys/info/cpu_linux_arm.odin @@ -8,8 +8,8 @@ import "core:strconv" import "core:strings" @(private) -_cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { - return _features, _features_ok +_cpu_features :: proc "contextless" () -> (features: CPU_Features) { + return _features } @(init, private) @@ -32,8 +32,6 @@ _init_cpu_features :: proc "contextless" () { if key != "Features" { continue } - _features_ok = true - for feature in strings.split_by_byte_iterator(&value, ' ') { switch feature { case "asimd", "neon": _features += { .asimd } diff --git a/core/sys/info/cpu_linux_riscv64.odin b/core/sys/info/cpu_linux_riscv64.odin index 612456ff0..519c6b315 100644 --- a/core/sys/info/cpu_linux_riscv64.odin +++ b/core/sys/info/cpu_linux_riscv64.odin @@ -71,8 +71,6 @@ _init_cpu_features :: proc "contextless" () { } } - _features_ok = true - // hwprobe for other features. { pairs := []linux.RISCV_HWProbe{ @@ -109,8 +107,8 @@ _init_cpu_features :: proc "contextless" () { } @(private) -_cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { - return _features, _features_ok +_cpu_features :: proc "contextless" () -> (features: CPU_Features) { + return _features } @(private) diff --git a/core/sys/info/cpu_other.odin b/core/sys/info/cpu_other.odin index 6b7f78e19..cb190a3c4 100644 --- a/core/sys/info/cpu_other.odin +++ b/core/sys/info/cpu_other.odin @@ -8,7 +8,7 @@ _cpu_core_count :: proc "contextless" () -> (physical: int, logical: int, ok: bo when ODIN_ARCH == .arm32 || ODIN_ARCH == .arm64 { @(private) - _cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { - return {}, false + _cpu_features :: proc "contextless" () -> (features: CPU_Features) { + return {} } } \ No newline at end of file diff --git a/core/sys/info/cpu_riscv64.odin b/core/sys/info/cpu_riscv64.odin index f67f15ebd..9303e6e79 100644 --- a/core/sys/info/cpu_riscv64.odin +++ b/core/sys/info/cpu_riscv64.odin @@ -98,5 +98,4 @@ CPU_Features :: distinct bit_set[CPU_Feature; u64] // Looking up CPU features is expensive on RISCV, and `atomic_load_explicit` // is also a barrier, so we're doing this lookup only once, before `main()` -@(private) _features: CPU_Features -@(private) _features_ok: bool \ No newline at end of file +@(private) _features: CPU_Features \ No newline at end of file diff --git a/core/sys/info/cpu_wasm.odin b/core/sys/info/cpu_wasm.odin index 9fc99b98c..f33f7cbb4 100644 --- a/core/sys/info/cpu_wasm.odin +++ b/core/sys/info/cpu_wasm.odin @@ -10,8 +10,8 @@ CPU_Feature :: enum u64 {} CPU_Features :: distinct bit_set[CPU_Feature; u64] @(private) -_cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { - return {}, false +_cpu_features :: proc "contextless" () -> (features: CPU_Features) { + return {} } @(private) diff --git a/core/sys/info/doc.odin b/core/sys/info/doc.odin index b93fcc694..b881bef86 100644 --- a/core/sys/info/doc.odin +++ b/core/sys/info/doc.odin @@ -7,7 +7,9 @@ and CPU information. On Windows, GPUs will also be enumerated using the registry. CPU feature flags can be tested against `cpu_features`, where applicable, e.g. -`if .aes in info.cpu_features.? { ... }` +```odin +if .aes in info.cpu_features() { ... } +``` Example: package main @@ -24,11 +26,8 @@ Example: fmt.printfln("OS: %v", version.os) fmt.printfln("Kernel: %v", version.kernel) } - fmt.printfln("CPU: %v", si.cpu_name()) - - if features, features_ok := si.cpu_features(); features_ok { - fmt.printfln(" %v", features) - } + fmt.printfln("CPU: %v", si.cpu_name()) + fmt.printfln(" %v", si.cpu_features()) if physical, logical, cores_ok := si.cpu_core_count(); cores_ok { fmt.printfln("CPU cores: %vc/%vt", physical, logical) } diff --git a/core/sys/info/sysinfo.odin b/core/sys/info/sysinfo.odin index fa4847158..ad120b264 100644 --- a/core/sys/info/sysinfo.odin +++ b/core/sys/info/sysinfo.odin @@ -24,22 +24,21 @@ cpu_core_count :: proc "contextless" () -> (physical: int, logical: int, ok: boo } /* -Retrieves CPU features where available +Returns CPU features where available -The results are cached +The results are looked up before `main` enters and cached Returns: -- features: An architecture-specific `bit_set` -- ok: `true` when we could retrieve the CPU features, `false` otherwise +- features: An architecture-specific `bit_set`, empty if we couldn't retrieve them */ -cpu_features :: proc "contextless" () -> (features: CPU_Features, ok: bool) { +cpu_features :: proc "contextless" () -> (features: CPU_Features) { return _cpu_features() } /* -Retrieves the CPU's name +Returns the CPU's name -The results are cached +The results are looked up before `main` enters and cached Returns: - name: A `string` containing the CPU model name, empty if the lookup failed