Skip to content

Commit

Permalink
Merge pull request #505 from FourteenBrush/patch-1
Browse files Browse the repository at this point in the history
Sync builtins with compiler
  • Loading branch information
DanielGavin authored Sep 21, 2024
2 parents b272226 + 25b3f7b commit b29789b
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 9 deletions.
43 changes: 42 additions & 1 deletion builtin/builtin.odin
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Odin_Arch_Type :: enum int {
}

@builtin
ODIN_ARCH: Odin_Arch_Type
ODIN_ARCH: Odin_Arch_Type

Odin_Build_Mode_Type :: enum int {
Executable,
Expand All @@ -88,6 +88,14 @@ Odin_Build_Mode_Type :: enum int {
@builtin
ODIN_BUILD_MODE: Odin_Build_Mode_Type

Odin_Error_Pos_Style_Type :: enum int {
Default = 0,
Unix = 1,
}

@builtin
ODIN_ERROR_POS_STYLE: Odin_Error_Pos_Style_Type

Odin_Endian_Type :: enum int {
Unknown,
Little,
Expand Down Expand Up @@ -127,3 +135,36 @@ ODIN_OPTIMIZATION_MODE: Odin_Optimization_Mode

@builtin
ODIN_DEBUG: bool

@builtin
ODIN_WINDOWS_SUBSYSTEM: string

@builtin
ODIN_VENDOR: string

@builtin
ODIN_VERSION: string

@builtin
ODIN_ROOT: string

@builtin
ODIN_DISABLE_ASSERT: bool

@builtin
ODIN_DEFAULT_TO_NIL_ALLOCATOR: bool

@builtin
ODIN_DEFAULT_TO_PANIC_ALLOCATOR: bool

@builtin
ODIN_NO_CRT: bool

@builtin
ODIN_NO_ENTRY_POINT: bool

@builtin
ODIN_NO_RTTI: bool

@builtin
ODIN_COMPILE_TIMESTAMP: int
74 changes: 66 additions & 8 deletions builtin/intrinsics.odin
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package ols_builtin
// Package-Related
is_package_imported :: proc(package_name: string) -> bool ---

// Matrix Related Procedures
transpose :: proc(m: $T/matrix[$R, $C]$E) -> matrix[C, R]E ---
outer_product :: proc(a: $A/[$X]$E, b: $B/[$Y]E) -> matrix[X, Y]E ---
hadamard_product :: proc(a, b: $T/matrix[$R, $C]$E) -> T ---
matrix_flatten :: proc(m: $T/matrix[$R, $C]$E) -> [R*C]E ---

// Types
soa_struct :: proc($N: int, $T: typeid) -> type / #soa[N]T

Expand Down Expand Up @@ -34,6 +40,9 @@ overflow_add :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
overflow_sub :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
overflow_mul :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---

saturating_add :: proc(lhs, rhs: $T) -> T ---
saturating_sub :: proc(lhs, rhs: $T) -> T ---

sqrt :: proc(x: $T) -> T ---

fused_mul_add :: proc(a, b, c: $T) -> T ---
Expand Down Expand Up @@ -71,7 +80,8 @@ expect :: proc(val, expected_val: T) -> T ---

// Linux and Darwin Only
syscall :: proc(id: uintptr, args: ..uintptr) -> uintptr ---

// FreeBSD, NetBSD, et cetera
syscall_bsd :: proc(id: uintptr, args: ..uintptr) -> (uintptr, bool) ---

// Atomics
Atomic_Memory_Order :: enum {
Expand Down Expand Up @@ -219,8 +229,21 @@ type_is_matrix :: proc($T: typeid) -> bool ---

type_has_nil :: proc($T: typeid) -> bool ---

type_is_matrix_row_major :: proc($T: typeid) -> bool ---
type_is_matrix_column_major :: proc($T: typeid) -> bool ---

type_is_specialization_of :: proc($T, $S: typeid) -> bool ---

type_is_variant_of :: proc($U, $V: typeid) -> bool ---
type_union_tag_type :: proc($T: typeid) -> typeid ---
type_union_tag_offset :: proc($T: typeid) -> uintptr ---
type_union_base_tag_value :: proc($T: typeid) -> int ---
type_union_variant_count :: proc($T: typeid) -> int ---
type_variant_type_of :: proc($T: typeid, $index: int) -> typeid ---
type_variant_index_of :: proc($U, $V: typeid) -> int ---

type_bit_set_elem_type :: proc($T: typeid) -> typeid ---
type_bit_set_underlying_type :: proc($T: typeid) -> typeid ---

type_has_field :: proc($T: typeid, $name: string) -> bool ---
type_field_type :: proc($T: typeid, $name: string) -> typeid ---
Expand All @@ -232,6 +255,7 @@ type_proc_parameter_type :: proc($T: typeid, index: int) -> typeid ---
type_proc_return_type :: proc($T: typeid, index: int) -> typeid ---

type_struct_field_count :: proc($T: typeid) -> int ---
type_struct_has_implicit_padding :: proc($T: typeid) -> bool ---

type_polymorphic_record_parameter_count :: proc($T: typeid) -> typeid ---
type_polymorphic_record_parameter_value :: proc(
Expand All @@ -257,14 +281,27 @@ type_hasher_proc :: proc(
hasher: proc "contextless" (data: rawptr, seed: uintptr) -> uintptr
) ---

type_map_info :: proc($T: typeid/map[$K]$V) -> ^runtime.Map_Info ---
type_map_cell_info :: proc($T: typeid) -> ^runtime.Map_Cell_Info ---

type_convert_variants_to_pointers :: proc($T: typeid) -> typeid ---
type_merge :: proc($U, $V: typeid) -> typeid ---

type_has_shared_fields :: proc($U, $V: typeid) -> bool ---

constant_utf16_cstring :: proc($literal: string) -> [^]u16 ---

constant_log2 :: proc($v: $T) -> T ---

// SIMD related
simd_add :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_sub :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_mul :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_div :: proc(a, b: #simd[N]T) -> #simd[N]T ---

simd_saturating_add :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_saturating_sub :: proc(a, b: #simd[N]T) -> #simd[N]T ---

// Keeps Odin's Behaviour
// (x << y) if y <= mask else 0
simd_shl :: proc(a: #simd[N]T, b: #simd[N]Unsigned_Integer) -> #simd[N]T ---
Expand All @@ -284,10 +321,10 @@ simd_shr_masked :: proc(
simd_add_sat :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_sub_sat :: proc(a, b: #simd[N]T) -> #simd[N]T ---

simd_and :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_or :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_xor :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_and_not :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_and :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_or :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_xor :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_bit_and_not :: proc(a, b: #simd[N]T) -> #simd[N]T ---

simd_neg :: proc(a: #simd[N]T) -> #simd[N]T ---

Expand Down Expand Up @@ -320,6 +357,18 @@ simd_reduce_and :: proc(a: #simd[N]T) -> T ---
simd_reduce_or :: proc(a: #simd[N]T) -> T ---
simd_reduce_xor :: proc(a: #simd[N]T) -> T ---

simd_reduce_any :: proc(a: #simd[N]T) -> T ---
simd_reduce_all :: proc(a: #simd[N]T) -> T ---

simd_gather :: proc(ptr: #simd[N]rawptr, val: #simd[N]T, mask: #simd[N]U) -> #simd[N]T ---
simd_scatter :: proc(ptr: #simd[N]rawptr, val: #simd[N]T, mask: #simd[N]U) ---

simd_masked_load :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) -> #simd[N]T ---
simd_masked_store :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) ---

simd_masked_expand_load :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) -> #simd[N]T ---
simd_masked_compress_store :: proc(ptr: rawptr, val: #simd[N]T, mask: #simd[N]U) ---

simd_shuffle :: proc(
a, b: #simd[N]T,
indices: ..int,
Expand All @@ -339,11 +388,20 @@ simd_nearest :: proc(a: #simd[N]any_float) -> #simd[N]any_float ---
simd_to_bits :: proc(v: #simd[N]T) -> #simd[N]Integer ---

// equivalent a swizzle with descending indices, e.g. reserve(a, 3, 2, 1, 0)
simd_reverse :: proc(a: #simd[N]T) -> #simd[N]T ---
simd_lanes_reverse :: proc(a: #simd[N]T) -> #simd[N]T ---

simd_lanes_rotate_left :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
simd_lanes_rotate_right :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---

simd_rotate_left :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
simd_rotate_right :: proc(a: #simd[N]T, $offset: int) -> #simd[N]T ---
// Checks if the current target supports the given target features.
//
// Takes a constant comma-seperated string (eg: "sha512,sse4.1"), or a procedure type which has either
// `@(require_target_feature)` or `@(enable_target_feature)` as its input and returns a boolean indicating
// if all listed features are supported.
has_target_feature :: proc($test: $T) -> bool ---

// Returns the value of the procedure where `x` must be a call expression
procedure_of :: proc(x: $T) -> T ---

// WASM targets only
wasm_memory_grow :: proc(index, delta: uintptr) -> int ---
Expand Down

0 comments on commit b29789b

Please sign in to comment.