diff --git a/_run_all_tests.jai b/_run_all_tests.jai index 10dbeb4..3d1179b 100644 --- a/_run_all_tests.jai +++ b/_run_all_tests.jai @@ -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); } diff --git a/platform/arch.jai b/platform/arch.jai new file mode 100644 index 0000000..35ea510 --- /dev/null +++ b/platform/arch.jai @@ -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 diff --git a/platform/module.jai b/platform/module.jai new file mode 100644 index 0000000..a390cb0 --- /dev/null +++ b/platform/module.jai @@ -0,0 +1,7 @@ +#module_parameters(RUN_TESTS := false); + +#load "arch.jai"; + +#if RUN_TESTS { + test :: #import "jc/test"; +}