create platform module with arch extension checking
This commit is contained in:
parent
ea13e93591
commit
9faf43aeeb
3 changed files with 121 additions and 8 deletions
|
|
@ -5,15 +5,16 @@
|
|||
// @note(judah): we use relative imports here because that'll
|
||||
// print cleaner file locations.
|
||||
|
||||
#import,file "./array/module.jai"(true);
|
||||
#import,file "./encoding/module.jai"(true);
|
||||
#import,file "./hash/module.jai"(true);
|
||||
#import,file "./memory/module.jai"(true);
|
||||
#import,file "./meta/module.jai"(true);
|
||||
#import,file "./array/module.jai"(RUN_TESTS = true);
|
||||
#import,file "./encoding/module.jai"(RUN_TESTS = true);
|
||||
#import,file "./hash/module.jai"(RUN_TESTS = true);
|
||||
#import,file "./memory/module.jai"(RUN_TESTS = true);
|
||||
#import,file "./meta/module.jai"(RUN_TESTS = true);
|
||||
#import,file "./platform/module.jai"(RUN_TESTS = true);
|
||||
|
||||
rmath :: #import,file "./math/module.jai"(.radians, true);
|
||||
dmath :: #import,file "./math/module.jai"(.degrees, true);
|
||||
tmath :: #import,file "./math/module.jai"(.turns, true);
|
||||
rmath :: #import,file "./math/module.jai"(.radians, RUN_TESTS = true);
|
||||
dmath :: #import,file "./math/module.jai"(.degrees, RUN_TESTS = true);
|
||||
tmath :: #import,file "./math/module.jai"(.turns, RUN_TESTS = true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
105
platform/arch.jai
Normal file
105
platform/arch.jai
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
// All of the architecture-specific extensions we care to look for.
|
||||
// Note: Checking for impossible extensions will always turn into a no-op (ex. NEON support on x64).
|
||||
ISA_Extension :: enum {
|
||||
// x64
|
||||
sse2;
|
||||
sse3;
|
||||
sse41;
|
||||
sse42;
|
||||
ssse3;
|
||||
|
||||
avx;
|
||||
avx2;
|
||||
avx512cd;
|
||||
avx512f;
|
||||
avx512vnni;
|
||||
|
||||
// arm64
|
||||
neon;
|
||||
|
||||
// riscv
|
||||
rv64ip;
|
||||
}
|
||||
|
||||
// Returns true if the extension is supported by the current architecture.
|
||||
arch_supports :: inline ($ext: ISA_Extension) -> bool {
|
||||
lazy_init_cpu_info();
|
||||
return arch_has_extension(ext);
|
||||
}
|
||||
|
||||
// Returns true if any of the extensions are supported by the current architecture.
|
||||
arch_supports_any :: inline ($extensions: ..ISA_Extension) -> bool {
|
||||
lazy_init_cpu_info();
|
||||
|
||||
res: bool;
|
||||
#insert -> string {
|
||||
b: basic.String_Builder;
|
||||
for extensions {
|
||||
basic.print_to_builder(*b, "res ||= arch_has_extension(.%);\n", it);
|
||||
}
|
||||
return basic.builder_to_string(*b);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Returns true if all of the extensions are supported by the current architecture.
|
||||
arch_supports_all :: inline ($extensions: ..ISA_Extension) -> bool {
|
||||
lazy_init_cpu_info();
|
||||
|
||||
res: bool;
|
||||
#insert -> string {
|
||||
b: basic.String_Builder;
|
||||
for extensions {
|
||||
basic.print_to_builder(*b, "res &&= arch_has_extension(.%);\n", it);
|
||||
}
|
||||
return basic.builder_to_string(*b);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#scope_file;
|
||||
|
||||
// @note(judah): this assumes lazy_init_cpu_info was already called
|
||||
arch_has_extension :: inline ($ext: ISA_Extension) -> bool {
|
||||
#if CPU == {
|
||||
case .X64; #if ext == {
|
||||
case .sse2; return x64.check_feature(info.feature_leaves, .SSE2);
|
||||
case .sse3; return x64.check_feature(info.feature_leaves, .SSE3);
|
||||
case .sse41; return x64.check_feature(info.feature_leaves, .SSE4_1);
|
||||
case .sse42; return x64.check_feature(info.feature_leaves, .SSE4_2);
|
||||
case .ssse3; return x64.check_feature(info.feature_leaves, .SSSE3);
|
||||
case .avx; return x64.check_feature(info.feature_leaves, .AVX);
|
||||
case .avx2; return x64.check_feature(info.feature_leaves, .AVX2);
|
||||
case .avx512cd; return x64.check_feature(info.feature_leaves, .AVX512CD);
|
||||
case .avx512f; return x64.check_feature(info.feature_leaves, .AVX512F);
|
||||
case .avx512vnni; return x64.check_feature(info.feature_leaves, .AVX512_VNNI);
|
||||
}
|
||||
case .ARM64; #if ext == {
|
||||
case .neon;
|
||||
return true; // @note(judah): it's safe to assume neon support if we're on arm (for now)
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
info_initialized := false;
|
||||
|
||||
lazy_init_cpu_info :: () #expand {
|
||||
if info_initialized return;
|
||||
info_initialized = true;
|
||||
|
||||
#if CPU == .X64 {
|
||||
info = x64.get_cpu_info();
|
||||
}
|
||||
}
|
||||
|
||||
#if CPU == {
|
||||
case .X64;
|
||||
info: x64.Cpu_X86;
|
||||
x64 :: #import "Machine_X64"; // @future
|
||||
}
|
||||
|
||||
|
||||
basic :: #import "Basic"; // @future
|
||||
7
platform/module.jai
Normal file
7
platform/module.jai
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#module_parameters(RUN_TESTS := false);
|
||||
|
||||
#load "arch.jai";
|
||||
|
||||
#if RUN_TESTS {
|
||||
test :: #import "jc/test";
|
||||
}
|
||||
Loading…
Reference in a new issue