mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-16 16:01:26 -07:00
Merge remote-tracking branch 'offical/master'
This commit is contained in:
@@ -356,7 +356,7 @@ int_count_lsb :: proc(a: ^Int, allocator := context.allocator) -> (count: int, e
|
||||
}
|
||||
|
||||
platform_count_lsb :: #force_inline proc(a: $T) -> (count: int)
|
||||
where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) {
|
||||
where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T) {
|
||||
return int(intrinsics.count_trailing_zeros(a)) if a > 0 else 0
|
||||
}
|
||||
|
||||
|
||||
@@ -546,7 +546,7 @@ internal_int_shl1 :: proc(dest, src: ^Int, allocator := context.allocator) -> (e
|
||||
Like `internal_int_mul_digit` but with an integer as the small input.
|
||||
*/
|
||||
internal_int_mul_integer :: proc(dest, a: ^Int, b: $T, allocator := context.allocator) -> (err: Error)
|
||||
where intrinsics.type_is_integer(T) && T != DIGIT {
|
||||
where intrinsics.type_is_integer(T), T != DIGIT {
|
||||
context.allocator = allocator
|
||||
|
||||
t := &Int{}
|
||||
@@ -2806,7 +2806,7 @@ internal_int_count_lsb :: proc(a: ^Int) -> (count: int, err: Error) {
|
||||
}
|
||||
|
||||
internal_platform_count_lsb :: #force_inline proc(a: $T) -> (count: int)
|
||||
where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) {
|
||||
where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T) {
|
||||
return int(intrinsics.count_trailing_zeros(a)) if a > 0 else 0
|
||||
}
|
||||
|
||||
|
||||
@@ -469,7 +469,7 @@ internal_int_pack_count :: proc(a: ^Int, $T: typeid, nails := 0) -> (size_needed
|
||||
Assumes `a` not to be `nil` and to have been initialized.
|
||||
*/
|
||||
internal_int_pack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_First) -> (written: int, err: Error)
|
||||
where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) && size_of(T) <= 16 {
|
||||
where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T), size_of(T) <= 16 {
|
||||
|
||||
assert(nails >= 0 && nails < (size_of(T) * 8))
|
||||
|
||||
@@ -505,7 +505,7 @@ internal_int_pack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_Fir
|
||||
|
||||
|
||||
internal_int_unpack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_First, allocator := context.allocator) -> (err: Error)
|
||||
where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) && size_of(T) <= 16 {
|
||||
where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T), size_of(T) <= 16 {
|
||||
assert(nails >= 0 && nails < (size_of(T) * 8))
|
||||
context.allocator = allocator
|
||||
|
||||
|
||||
@@ -701,3 +701,39 @@ enumerated_array :: proc(ptr: ^$T) -> []intrinsics.type_elem_type(T)
|
||||
where intrinsics.type_is_enumerated_array(T) {
|
||||
return ([^]intrinsics.type_elem_type(T))(ptr)[:len(T)]
|
||||
}
|
||||
|
||||
// Turn a `[]E` into `bit_set[E]`
|
||||
// e.g.:
|
||||
// bs := slice.enum_slice_to_bitset(my_flag_slice, rl.ConfigFlags)
|
||||
@(require_results)
|
||||
enum_slice_to_bitset :: proc(enums: []$E, $T: typeid/bit_set[E]) -> (bits: T) where intrinsics.type_is_enum(E), intrinsics.type_bit_set_elem_type(T) == E {
|
||||
for v in enums {
|
||||
bits |= {v}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Turn a `bit_set[E]` into a `[]E`
|
||||
// e.g.:
|
||||
// sl := slice.bitset_to_enum_slice(flag_buf[:], bs)
|
||||
@(require_results)
|
||||
bitset_to_enum_slice_with_buffer :: proc(buf: []$E, bs: $T) -> (slice: []E) where intrinsics.type_is_enum(E), intrinsics.type_bit_set_elem_type(T) == E {
|
||||
count := 0
|
||||
for v in bs {
|
||||
buf[count] = v
|
||||
count += 1
|
||||
}
|
||||
return buf[:count]
|
||||
}
|
||||
|
||||
// Turn a `bit_set[E]` into a `[]E`, allocates
|
||||
// e.g.:
|
||||
// sl := slice.bitset_to_enum_slice(bs)
|
||||
@(require_results)
|
||||
bitset_to_enum_slice_with_make :: proc(bs: $T, $E: typeid, allocator := context.allocator) -> (slice: []E) where intrinsics.type_is_enum(E), intrinsics.type_bit_set_elem_type(T) == E {
|
||||
ones := intrinsics.count_ones(transmute(E)bs)
|
||||
buf := make([]E, int(ones), allocator)
|
||||
return bitset_to_enum_slice(buf, bs)
|
||||
}
|
||||
|
||||
bitset_to_enum_slice :: proc{bitset_to_enum_slice_with_make, bitset_to_enum_slice_with_buffer}
|
||||
+15
-15
@@ -26,7 +26,7 @@ where
|
||||
@(private)
|
||||
syscall2 :: #force_inline proc "contextless" (nr: uintptr,p1: $T1, p2: $T2) -> int
|
||||
where
|
||||
size_of(p1) <= size_of(uintptr) &&
|
||||
size_of(p1) <= size_of(uintptr),
|
||||
size_of(p2) <= size_of(uintptr)
|
||||
{
|
||||
return cast(int) intrinsics.syscall(nr,
|
||||
@@ -36,8 +36,8 @@ where
|
||||
@(private)
|
||||
syscall3 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3) -> int
|
||||
where
|
||||
size_of(p1) <= size_of(uintptr) &&
|
||||
size_of(p2) <= size_of(uintptr) &&
|
||||
size_of(p1) <= size_of(uintptr),
|
||||
size_of(p2) <= size_of(uintptr),
|
||||
size_of(p3) <= size_of(uintptr)
|
||||
{
|
||||
return cast(int) intrinsics.syscall(nr,
|
||||
@@ -49,9 +49,9 @@ where
|
||||
@(private)
|
||||
syscall4 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3, p4: $T4) -> int
|
||||
where
|
||||
size_of(p1) <= size_of(uintptr) &&
|
||||
size_of(p2) <= size_of(uintptr) &&
|
||||
size_of(p3) <= size_of(uintptr) &&
|
||||
size_of(p1) <= size_of(uintptr),
|
||||
size_of(p2) <= size_of(uintptr),
|
||||
size_of(p3) <= size_of(uintptr),
|
||||
size_of(p4) <= size_of(uintptr)
|
||||
{
|
||||
return cast(int) intrinsics.syscall(nr,
|
||||
@@ -64,10 +64,10 @@ where
|
||||
@(private)
|
||||
syscall5 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3, p4: $T4, p5: $T5) -> int
|
||||
where
|
||||
size_of(p1) <= size_of(uintptr) &&
|
||||
size_of(p2) <= size_of(uintptr) &&
|
||||
size_of(p3) <= size_of(uintptr) &&
|
||||
size_of(p4) <= size_of(uintptr) &&
|
||||
size_of(p1) <= size_of(uintptr),
|
||||
size_of(p2) <= size_of(uintptr),
|
||||
size_of(p3) <= size_of(uintptr),
|
||||
size_of(p4) <= size_of(uintptr),
|
||||
size_of(p5) <= size_of(uintptr)
|
||||
{
|
||||
return cast(int) intrinsics.syscall(nr,
|
||||
@@ -81,11 +81,11 @@ where
|
||||
@(private)
|
||||
syscall6 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3, p4: $T4, p5: $T5, p6: $T6) -> int
|
||||
where
|
||||
size_of(p1) <= size_of(uintptr) &&
|
||||
size_of(p2) <= size_of(uintptr) &&
|
||||
size_of(p3) <= size_of(uintptr) &&
|
||||
size_of(p4) <= size_of(uintptr) &&
|
||||
size_of(p5) <= size_of(uintptr) &&
|
||||
size_of(p1) <= size_of(uintptr),
|
||||
size_of(p2) <= size_of(uintptr),
|
||||
size_of(p3) <= size_of(uintptr),
|
||||
size_of(p4) <= size_of(uintptr),
|
||||
size_of(p5) <= size_of(uintptr),
|
||||
size_of(p6) <= size_of(uintptr)
|
||||
{
|
||||
return cast(int) intrinsics.syscall(nr,
|
||||
|
||||
Reference in New Issue
Block a user