diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2020-12-06 00:49:48 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-06 00:49:48 +0000 |
| commit | f0683c910231513db9adab83f7c2fca9dd8d2613 (patch) | |
| tree | 2539634b5b71caf5148d8927c9298ba20bad5246 /core/sys | |
| parent | 54fbdabc380905a925ab5e922749fa2b1ccb2621 (diff) | |
| parent | ca4657fd31b9efc7ab52f7e1b6f4145d5ed28fb7 (diff) | |
Merge branch 'master' into parser-experiments
Diffstat (limited to 'core/sys')
| -rw-r--r-- | core/sys/cpu/cpu.odin | 35 | ||||
| -rw-r--r-- | core/sys/cpu/cpu_x86.odin | 67 | ||||
| -rw-r--r-- | core/sys/unix/pthread_darwin.odin | 18 | ||||
| -rw-r--r-- | core/sys/unix/pthread_freebsd.odin | 18 | ||||
| -rw-r--r-- | core/sys/unix/pthread_linux.odin | 18 | ||||
| -rw-r--r-- | core/sys/win32/kernel32.odin | 4 |
6 files changed, 131 insertions, 29 deletions
diff --git a/core/sys/cpu/cpu.odin b/core/sys/cpu/cpu.odin new file mode 100644 index 000000000..b6f770aed --- /dev/null +++ b/core/sys/cpu/cpu.odin @@ -0,0 +1,35 @@ +package sys_cpu + +#assert(ODIN_USE_LLVM_API); + +Cache_Line_Pad :: struct {_: [_cache_line_size]byte}; + +initialized: bool; + +x86: struct { + _: Cache_Line_Pad, + has_aes: bool, // AES hardware implementation (AES NI) + has_adx: bool, // Multi-precision add-carry instruction extensions + has_avx: bool, // Advanced vector extension + has_avx2: bool, // Advanced vector extension 2 + has_bmi1: bool, // Bit manipulation instruction set 1 + has_bmi2: bool, // Bit manipulation instruction set 2 + has_erms: bool, // Enhanced REP for MOVSB and STOSB + has_fma: bool, // Fused-multiply-add instructions + has_os_xsave: bool, // OS supports XSAVE/XRESTOR for saving/restoring XMM registers. + has_pclmulqdq: bool, // PCLMULQDQ instruction - most often used for AES-GCM + has_popcnt: bool, // Hamming weight instruction POPCNT. + has_rdrand: bool, // RDRAND instruction (on-chip random number generator) + has_rdseed: bool, // RDSEED instruction (on-chip random number generator) + has_sse2: bool, // Streaming SIMD extension 2 (always available on amd64) + has_sse3: bool, // Streaming SIMD extension 3 + has_ssse3: bool, // Supplemental streaming SIMD extension 3 + has_sse41: bool, // Streaming SIMD extension 4 and 4.1 + has_sse42: bool, // Streaming SIMD extension 4 and 4.2 + _: Cache_Line_Pad, +}; + + +init :: proc() { + _init(); +} diff --git a/core/sys/cpu/cpu_x86.odin b/core/sys/cpu/cpu_x86.odin new file mode 100644 index 000000000..8f3560a87 --- /dev/null +++ b/core/sys/cpu/cpu_x86.odin @@ -0,0 +1,67 @@ +//+build 386, amd64 +package sys_cpu + +_cache_line_size :: 64; + +cpuid :: proc(ax, cx: u32) -> (eax, ebc, ecx, edx: u32) { + return expand_to_tuple(asm(u32, u32) -> struct{eax, ebc, ecx, edx: u32} { + "cpuid", + "={ax},={bx},={cx},={dx},{ax},{cx}", + }(ax, cx)); +} + +xgetbv :: proc() -> (eax, edx: u32) { + return expand_to_tuple(asm(u32) -> struct{eax, edx: u32} { + "xgetbv", + "={ax},={dx},{cx}", + }(0)); +} + +_init :: proc() { + is_set :: proc(hwc: u32, value: u32) -> bool { + return hwc&value != 0; + } + + initialized = true; + + max_id, _, _, _ := cpuid(0, 0); + + if max_id < 1 { + return; + } + + _, _, ecx1, edx1 := cpuid(1, 0); + + x86.has_sse2 = is_set(26, edx1); + + x86.has_sse3 = is_set(0, ecx1); + x86.has_pclmulqdq = is_set(1, ecx1); + x86.has_ssse3 = is_set(9, ecx1); + x86.has_fma = is_set(12, ecx1); + x86.has_sse41 = is_set(19, ecx1); + x86.has_sse42 = is_set(20, ecx1); + x86.has_popcnt = is_set(23, ecx1); + x86.has_aes = is_set(25, ecx1); + x86.has_os_xsave = is_set(27, ecx1); + x86.has_rdrand = is_set(30, ecx1); + + os_supports_avx := false; + if x86.has_os_xsave { + eax, _ := xgetbv(); + os_supports_avx = is_set(1, eax) && is_set(2, eax); + } + + x86.has_avx = is_set(28, ecx1) && os_supports_avx; + + if max_id < 7 { + return; + } + + _, ebx7, _, _ := cpuid(7, 0); + x86.has_bmi1 = is_set(3, ebx7); + x86.has_avx2 = is_set(5, ebx7) && os_supports_avx; + x86.has_bmi2 = is_set(8, ebx7); + x86.has_erms = is_set(9, ebx7); + x86.has_rdseed = is_set(18, ebx7); + x86.has_adx = is_set(19, ebx7); +} diff --git a/core/sys/unix/pthread_darwin.odin b/core/sys/unix/pthread_darwin.odin index 7f7f59189..8460c4852 100644 --- a/core/sys/unix/pthread_darwin.odin +++ b/core/sys/unix/pthread_darwin.odin @@ -14,44 +14,44 @@ PTHREAD_ONCE_SIZE :: 8; PTHREAD_RWLOCK_SIZE :: 192; PTHREAD_RWLOCKATTR_SIZE :: 16; -pthread_t :: opaque u64; +pthread_t :: #opaque u64; -pthread_attr_t :: opaque struct #align 16 { +pthread_attr_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_ATTR_SIZE] c.char, }; -pthread_cond_t :: opaque struct #align 16 { +pthread_cond_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_COND_SIZE] c.char, }; -pthread_condattr_t :: opaque struct #align 16 { +pthread_condattr_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_CONDATTR_SIZE] c.char, }; -pthread_mutex_t :: opaque struct #align 16 { +pthread_mutex_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_MUTEX_SIZE] c.char, }; -pthread_mutexattr_t :: opaque struct #align 16 { +pthread_mutexattr_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_MUTEXATTR_SIZE] c.char, }; -pthread_once_t :: opaque struct #align 16 { +pthread_once_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_ONCE_SIZE] c.char, }; -pthread_rwlock_t :: opaque struct #align 16 { +pthread_rwlock_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_RWLOCK_SIZE] c.char, }; -pthread_rwlockattr_t :: opaque struct #align 16 { +pthread_rwlockattr_t :: #opaque struct #align 16 { sig: c.long, _: [PTHREAD_RWLOCKATTR_SIZE] c.char, }; diff --git a/core/sys/unix/pthread_freebsd.odin b/core/sys/unix/pthread_freebsd.odin index 77b922686..cbd7e99f1 100644 --- a/core/sys/unix/pthread_freebsd.odin +++ b/core/sys/unix/pthread_freebsd.odin @@ -26,32 +26,32 @@ when size_of(int) == 8 { PTHREAD_BARRIER_T_SIZE :: 20; } -pthread_cond_t :: opaque struct #align 16 { +pthread_cond_t :: #opaque struct #align 16 { _: [PTHREAD_COND_T_SIZE] c.char, }; -pthread_mutex_t :: opaque struct #align 16 { +pthread_mutex_t :: #opaque struct #align 16 { _: [PTHREAD_MUTEX_T_SIZE] c.char, }; -pthread_rwlock_t :: opaque struct #align 16 { +pthread_rwlock_t :: #opaque struct #align 16 { _: [PTHREAD_RWLOCK_T_SIZE] c.char, }; -pthread_barrier_t :: opaque struct #align 16 { +pthread_barrier_t :: #opaque struct #align 16 { _: [PTHREAD_BARRIER_T_SIZE] c.char, }; -pthread_attr_t :: opaque struct #align 16 { +pthread_attr_t :: #opaque struct #align 16 { _: [PTHREAD_ATTR_T_SIZE] c.char, }; -pthread_condattr_t :: opaque struct #align 16 { +pthread_condattr_t :: #opaque struct #align 16 { _: [PTHREAD_CONDATTR_T_SIZE] c.char, }; -pthread_mutexattr_t :: opaque struct #align 16 { +pthread_mutexattr_t :: #opaque struct #align 16 { _: [PTHREAD_MUTEXATTR_T_SIZE] c.char, }; -pthread_rwlockattr_t :: opaque struct #align 16 { +pthread_rwlockattr_t :: #opaque struct #align 16 { _: [PTHREAD_RWLOCKATTR_T_SIZE] c.char, }; -pthread_barrierattr_t :: opaque struct #align 16 { +pthread_barrierattr_t :: #opaque struct #align 16 { _: [PTHREAD_BARRIERATTR_T_SIZE] c.char, }; diff --git a/core/sys/unix/pthread_linux.odin b/core/sys/unix/pthread_linux.odin index 5edd1ef5a..76a0719fb 100644 --- a/core/sys/unix/pthread_linux.odin +++ b/core/sys/unix/pthread_linux.odin @@ -33,32 +33,32 @@ when size_of(int) == 8 { PTHREAD_BARRIER_T_SIZE :: 20; } -pthread_cond_t :: opaque struct #align 16 { +pthread_cond_t :: #opaque struct #align 16 { _: [PTHREAD_COND_T_SIZE] c.char, }; -pthread_mutex_t :: opaque struct #align 16 { +pthread_mutex_t :: #opaque struct #align 16 { _: [PTHREAD_MUTEX_T_SIZE] c.char, }; -pthread_rwlock_t :: opaque struct #align 16 { +pthread_rwlock_t :: #opaque struct #align 16 { _: [PTHREAD_RWLOCK_T_SIZE] c.char, }; -pthread_barrier_t :: opaque struct #align 16 { +pthread_barrier_t :: #opaque struct #align 16 { _: [PTHREAD_BARRIER_T_SIZE] c.char, }; -pthread_attr_t :: opaque struct #align 16 { +pthread_attr_t :: #opaque struct #align 16 { _: [PTHREAD_ATTR_T_SIZE] c.char, }; -pthread_condattr_t :: opaque struct #align 16 { +pthread_condattr_t :: #opaque struct #align 16 { _: [PTHREAD_CONDATTR_T_SIZE] c.char, }; -pthread_mutexattr_t :: opaque struct #align 16 { +pthread_mutexattr_t :: #opaque struct #align 16 { _: [PTHREAD_MUTEXATTR_T_SIZE] c.char, }; -pthread_rwlockattr_t :: opaque struct #align 16 { +pthread_rwlockattr_t :: #opaque struct #align 16 { _: [PTHREAD_RWLOCKATTR_T_SIZE] c.char, }; -pthread_barrierattr_t :: opaque struct #align 16 { +pthread_barrierattr_t :: #opaque struct #align 16 { _: [PTHREAD_BARRIERATTR_T_SIZE] c.char, }; diff --git a/core/sys/win32/kernel32.odin b/core/sys/win32/kernel32.odin index d5cefad94..ba3898730 100644 --- a/core/sys/win32/kernel32.odin +++ b/core/sys/win32/kernel32.odin @@ -8,12 +8,12 @@ foreign kernel32 { @(link_name="CreateProcessA") create_process_a :: proc(application_name, command_line: cstring, process_attributes, thread_attributes: ^Security_Attributes, inherit_handle: Bool, creation_flags: u32, environment: rawptr, - current_direcotry: cstring, startup_info: ^Startup_Info, + current_directory: cstring, startup_info: ^Startup_Info, process_information: ^Process_Information) -> Bool ---; @(link_name="CreateProcessW") create_process_w :: proc(application_name, command_line: Wstring, process_attributes, thread_attributes: ^Security_Attributes, inherit_handle: Bool, creation_flags: u32, environment: rawptr, - current_direcotry: Wstring, startup_info: ^Startup_Info, + current_directory: Wstring, startup_info: ^Startup_Info, process_information: ^Process_Information) -> Bool ---; @(link_name="GetExitCodeProcess") get_exit_code_process :: proc(process: Handle, exit: ^u32) -> Bool ---; @(link_name="ExitProcess") exit_process :: proc(exit_code: u32) ---; |