Compare commits

...

6 commits

Author SHA1 Message Date
7825dddfbf message for Jesse 2025-05-23 11:46:25 -06:00
ce16be8cff finish 001 2025-05-23 11:40:55 -06:00
9faf43aeeb create platform module with arch extension checking 2025-05-23 11:40:29 -06:00
ea13e93591 start 001 2025-05-23 10:07:43 -06:00
32d74754f4 . 2025-05-23 10:07:10 -06:00
f33421009a . 2025-05-23 10:06:40 -06:00
5 changed files with 131 additions and 10 deletions

8
INBOX
View file

@ -8,3 +8,11 @@
module instead. There's enough overlap that I
think it makes sense. Let me know what you think,
thanks!
05.23.25 Judah
I went ahead and created the platform module and
added arch-specific extension checking. Sadly
these happen at runtime because we're manually
checking isa extension flags. It's probably worth
it to add a 'SIMD' constant that we set for
targets that will almost always support SIMD
instructions; unsure for now.

4
TODO
View file

@ -3,7 +3,6 @@
[Judah]
[Jesse]
001 [arch] create module to determine simd support
011 [math] add more Vec math procedures
034 [math] Rect '#type,distinct Vec(4, T)' type + rectcut
002 [math] use simd for Mat4 operations
@ -19,7 +18,7 @@
009 [encoding] jai-friendly binary serialization support - blocked by 007
012 [map] create a simple arena-backed hash map implementation 'Map(K, V)', should be able to hash a key of any type (must include: get, set, remove, for_expansion) - possibly blocked by 032
013 [bindings] create build/binding utilitites module (since we do this a lot)
014 [platform] create module for OS/platform-specific procedures (read file, write file, etc.)
014 [platform] add support for read file, write file, etc.
015 [meta] create metaprogramming utilitites module (AST rewriting, code generation/introspection, etc.)
016 [x] default to arena-based allocators everywhere (a la brevis/serenum)
017 [x] re-implement dynamic arrays (should mirror procedures on 'Static_Array')
@ -77,3 +76,4 @@
042 [x] use absolute imports internally (ie. #import "jc/math"), update symlink/install process in README
000 [math] add easing procedures
004 [thirdparty/luajit] create bindings
001 [platform] create module for OS/platform-specific things

View file

@ -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
View 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
View file

@ -0,0 +1,7 @@
#module_parameters(RUN_TESTS := false);
#load "arch.jai";
#if RUN_TESTS {
test :: #import "jc/test";
}