mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-14 02:25:49 +00:00
[core:sys/info] Remove , ok
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@(private) _features: CPU_Features
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user