mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-22 06:15:20 +00:00
Remove u128 and i128
This commit is contained in:
@@ -35,8 +35,8 @@ Calling_Convention :: enum {
|
||||
|
||||
Type_Info_Enum_Value :: union {
|
||||
rune,
|
||||
i8, i16, i32, i64, i128, int,
|
||||
u8, u16, u32, u64, u128, uint, uintptr,
|
||||
i8, i16, i32, i64, int,
|
||||
u8, u16, u32, u64, uint, uintptr,
|
||||
f32, f64,
|
||||
};
|
||||
|
||||
@@ -180,7 +180,7 @@ DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
|
||||
__INITIAL_MAP_CAP :: 16;
|
||||
|
||||
__Map_Key :: struct {
|
||||
hash: u128,
|
||||
hash: u64,
|
||||
str: string,
|
||||
}
|
||||
|
||||
@@ -426,21 +426,20 @@ __get_map_key :: proc "contextless" (key: $K) -> __Map_Key {
|
||||
switch _ in ti.variant {
|
||||
case Type_Info_Integer:
|
||||
switch 8*size_of(key) {
|
||||
case 8: map_key.hash = u128(( ^u8)(&key)^);
|
||||
case 16: map_key.hash = u128(( ^u16)(&key)^);
|
||||
case 32: map_key.hash = u128(( ^u32)(&key)^);
|
||||
case 64: map_key.hash = u128(( ^u64)(&key)^);
|
||||
case 128: map_key.hash = u128((^u128)(&key)^);
|
||||
case 8: map_key.hash = u64(( ^u8)(&key)^);
|
||||
case 16: map_key.hash = u64(( ^u16)(&key)^);
|
||||
case 32: map_key.hash = u64(( ^u32)(&key)^);
|
||||
case 64: map_key.hash = u64(( ^u64)(&key)^);
|
||||
case: panic("Unhandled integer size");
|
||||
}
|
||||
case Type_Info_Rune:
|
||||
map_key.hash = u128((cast(^rune)&key)^);
|
||||
map_key.hash = u64((cast(^rune)&key)^);
|
||||
case Type_Info_Pointer:
|
||||
map_key.hash = u128(uintptr((^rawptr)(&key)^));
|
||||
map_key.hash = u64(uintptr((^rawptr)(&key)^));
|
||||
case Type_Info_Float:
|
||||
switch 8*size_of(key) {
|
||||
case 32: map_key.hash = u128((^u32)(&key)^);
|
||||
case 64: map_key.hash = u128((^u64)(&key)^);
|
||||
case 32: map_key.hash = u64((^u32)(&key)^);
|
||||
case 64: map_key.hash = u64((^u64)(&key)^);
|
||||
case: panic("Unhandled float size");
|
||||
}
|
||||
case Type_Info_String:
|
||||
@@ -928,17 +927,17 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
||||
|
||||
// Map stuff
|
||||
|
||||
__default_hash :: proc(data: []byte) -> u128 {
|
||||
fnv128a :: proc(data: []byte) -> u128 {
|
||||
h: u128 = 0x6c62272e07bb014262b821756295c58d;
|
||||
__default_hash :: proc(data: []byte) -> u64 {
|
||||
fnv64a :: proc(data: []byte) -> u64 {
|
||||
h: u64 = 0xcbf29ce484222325;
|
||||
for b in data {
|
||||
h = (h ~ u128(b)) * 0x1000000000000000000013b;
|
||||
h = (h ~ u64(b)) * 0x100000001b3;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
return fnv128a(data);
|
||||
return fnv64a(data);
|
||||
}
|
||||
__default_hash_string :: proc(s: string) -> u128 do return __default_hash(cast([]byte)s);
|
||||
__default_hash_string :: proc(s: string) -> u64 do return __default_hash(cast([]byte)s);
|
||||
|
||||
__dynamic_map_reserve :: proc(using header: __Map_Header, cap: int, loc := #caller_location) {
|
||||
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap, loc);
|
||||
@@ -1048,7 +1047,7 @@ __dynamic_map_hash_equal :: proc(h: __Map_Header, a, b: __Map_Key) -> bool {
|
||||
__dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_Result {
|
||||
fr := __Map_Find_Result{-1, -1, -1};
|
||||
if len(m.hashes) > 0 {
|
||||
fr.hash_index = int(key.hash % u128(len(m.hashes)));
|
||||
fr.hash_index = int(key.hash % u64(len(m.hashes)));
|
||||
fr.entry_index = m.hashes[fr.hash_index];
|
||||
for fr.entry_index >= 0 {
|
||||
entry := __dynamic_map_get_entry(h, fr.entry_index);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#shared_global_scope
|
||||
|
||||
/*
|
||||
@(link_name="__multi3")
|
||||
__multi3 :: proc "c" (a, b: u128) -> u128 {
|
||||
bits_in_dword_2 :: size_of(i64) * 4;
|
||||
@@ -108,3 +109,4 @@ __u128_quo_mod :: proc "c" (a, b: u128, rem: ^u128) -> (quo: u128) {
|
||||
if rem != nil do rem^ = r;
|
||||
return q;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -2,55 +2,46 @@ U8_MIN :: u8(0);
|
||||
U16_MIN :: u16(0);
|
||||
U32_MIN :: u32(0);
|
||||
U64_MIN :: u64(0);
|
||||
U128_MIN :: u128(0);
|
||||
|
||||
U8_MAX :: ~u8(0);
|
||||
U16_MAX :: ~u16(0);
|
||||
U32_MAX :: ~u32(0);
|
||||
U64_MAX :: ~u64(0);
|
||||
U128_MAX :: ~u128(0);
|
||||
|
||||
I8_MIN :: i8( ~u8(0) >> 1);
|
||||
I16_MIN :: i16( ~u16(0) >> 1);
|
||||
I32_MIN :: i32( ~u32(0) >> 1);
|
||||
I64_MIN :: i64( ~u64(0) >> 1);
|
||||
I128_MIN :: i128(~u128(0) >> 1);
|
||||
|
||||
I8_MAX :: -I8_MIN - 1;
|
||||
I16_MAX :: -I16_MIN - 1;
|
||||
I32_MAX :: -I32_MIN - 1;
|
||||
I64_MAX :: -I64_MIN - 1;
|
||||
I128_MAX :: -I128_MIN - 1;
|
||||
|
||||
foreign __llvm_core {
|
||||
@(link_name="llvm.ctpop.i8") __llvm_ctpop8 :: proc(u8) -> u8 ---;
|
||||
@(link_name="llvm.ctpop.i16") __llvm_ctpop16 :: proc(u16) -> u16 ---;
|
||||
@(link_name="llvm.ctpop.i32") __llvm_ctpop32 :: proc(u32) -> u32 ---;
|
||||
@(link_name="llvm.ctpop.i64") __llvm_ctpop64 :: proc(u64) -> u64 ---;
|
||||
@(link_name="llvm.ctpop.i128") __llvm_ctpop128 :: proc(u128) -> u128 ---;
|
||||
|
||||
@(link_name="llvm.ctlz.i8") __llvm_ctlz8 :: proc(u8, bool) -> u8 ---;
|
||||
@(link_name="llvm.ctlz.i16") __llvm_ctlz16 :: proc(u16, bool) -> u16 ---;
|
||||
@(link_name="llvm.ctlz.i32") __llvm_ctlz32 :: proc(u32, bool) -> u32 ---;
|
||||
@(link_name="llvm.ctlz.i64") __llvm_ctlz64 :: proc(u64, bool) -> u64 ---;
|
||||
@(link_name="llvm.ctlz.i128") __llvm_ctlz128 :: proc(u128, bool) -> u128 ---;
|
||||
|
||||
@(link_name="llvm.cttz.i8") __llvm_cttz8 :: proc(u8, bool) -> u8 ---;
|
||||
@(link_name="llvm.cttz.i16") __llvm_cttz16 :: proc(u16, bool) -> u16 ---;
|
||||
@(link_name="llvm.cttz.i32") __llvm_cttz32 :: proc(u32, bool) -> u32 ---;
|
||||
@(link_name="llvm.cttz.i64") __llvm_cttz64 :: proc(u64, bool) -> u64 ---;
|
||||
@(link_name="llvm.cttz.i128") __llvm_cttz128 :: proc(u128, bool) -> u128 ---;
|
||||
|
||||
@(link_name="llvm.bitreverse.i8") __llvm_bitreverse8 :: proc(u8) -> u8 ---;
|
||||
@(link_name="llvm.bitreverse.i16") __llvm_bitreverse16 :: proc(u16) -> u16 ---;
|
||||
@(link_name="llvm.bitreverse.i32") __llvm_bitreverse32 :: proc(u32) -> u32 ---;
|
||||
@(link_name="llvm.bitreverse.i64") __llvm_bitreverse64 :: proc(u64) -> u64 ---;
|
||||
@(link_name="llvm.bitreverse.i128") __llvm_bitreverse128 :: proc(u128) -> u128 ---;
|
||||
|
||||
@(link_name="llvm.bswap.i16") byte_swap16 :: proc(u16) -> u16 ---;
|
||||
@(link_name="llvm.bswap.i32") byte_swap32 :: proc(u32) -> u32 ---;
|
||||
@(link_name="llvm.bswap.i64") byte_swap64 :: proc(u64) -> u64 ---;
|
||||
@(link_name="llvm.bswap.i128") byte_swap128 :: proc(u128) -> u128 ---;
|
||||
}
|
||||
|
||||
byte_swap_uint :: proc(i: uint) -> uint {
|
||||
@@ -61,72 +52,62 @@ byte_swap_uint :: proc(i: uint) -> uint {
|
||||
}
|
||||
}
|
||||
|
||||
byte_swap :: proc[byte_swap16, byte_swap32, byte_swap64, byte_swap128, byte_swap_uint];
|
||||
byte_swap :: proc[byte_swap16, byte_swap32, byte_swap64, byte_swap_uint];
|
||||
|
||||
count_ones8 :: proc(i: u8) -> u8 { return __llvm_ctpop8(i); }
|
||||
count_ones16 :: proc(i: u16) -> u16 { return __llvm_ctpop16(i); }
|
||||
count_ones32 :: proc(i: u32) -> u32 { return __llvm_ctpop32(i); }
|
||||
count_ones64 :: proc(i: u64) -> u64 { return __llvm_ctpop64(i); }
|
||||
count_ones128 :: proc(i: u128) -> u128 { return __llvm_ctpop128(i); }
|
||||
|
||||
count_zeros8 :: proc(i: u8) -> u8 { return 8 - count_ones8(i); }
|
||||
count_zeros16 :: proc(i: u16) -> u16 { return 16 - count_ones16(i); }
|
||||
count_zeros32 :: proc(i: u32) -> u32 { return 32 - count_ones32(i); }
|
||||
count_zeros64 :: proc(i: u64) -> u64 { return 64 - count_ones64(i); }
|
||||
count_zeros128 :: proc(i: u128) -> u128 { return 128 - count_ones128(i); }
|
||||
|
||||
|
||||
rotate_left8 :: proc(i: u8, s: uint) -> u8 { return (i << s)|(i >> (8*size_of(u8) - s)); }
|
||||
rotate_left16 :: proc(i: u16, s: uint) -> u16 { return (i << s)|(i >> (8*size_of(u16) - s)); }
|
||||
rotate_left32 :: proc(i: u32, s: uint) -> u32 { return (i << s)|(i >> (8*size_of(u32) - s)); }
|
||||
rotate_left64 :: proc(i: u64, s: uint) -> u64 { return (i << s)|(i >> (8*size_of(u64) - s)); }
|
||||
rotate_left128 :: proc(i: u128, s: uint) -> u128 { return (i << s)|(i >> (8*size_of(u128) - s)); }
|
||||
|
||||
|
||||
rotate_right8 :: proc(i: u8, s: uint) -> u8 { return (i >> s)|(i << (8*size_of(u8) - s)); }
|
||||
rotate_right16 :: proc(i: u16, s: uint) -> u16 { return (i >> s)|(i << (8*size_of(u16) - s)); }
|
||||
rotate_right32 :: proc(i: u32, s: uint) -> u32 { return (i >> s)|(i << (8*size_of(u32) - s)); }
|
||||
rotate_right64 :: proc(i: u64, s: uint) -> u64 { return (i >> s)|(i << (8*size_of(u64) - s)); }
|
||||
rotate_right128 :: proc(i: u128, s: uint) -> u128 { return (i >> s)|(i << (8*size_of(u128) - s)); }
|
||||
|
||||
leading_zeros8 :: proc(i: u8) -> u8 { return __llvm_ctlz8(i, false); }
|
||||
leading_zeros16 :: proc(i: u16) -> u16 { return __llvm_ctlz16(i, false); }
|
||||
leading_zeros32 :: proc(i: u32) -> u32 { return __llvm_ctlz32(i, false); }
|
||||
leading_zeros64 :: proc(i: u64) -> u64 { return __llvm_ctlz64(i, false); }
|
||||
leading_zeros128 :: proc(i: u128) -> u128 { return __llvm_ctlz128(i, false); }
|
||||
|
||||
trailing_zeros8 :: proc(i: u8) -> u8 { return __llvm_cttz8(i, false); }
|
||||
trailing_zeros16 :: proc(i: u16) -> u16 { return __llvm_cttz16(i, false); }
|
||||
trailing_zeros32 :: proc(i: u32) -> u32 { return __llvm_cttz32(i, false); }
|
||||
trailing_zeros64 :: proc(i: u64) -> u64 { return __llvm_cttz64(i, false); }
|
||||
trailing_zeros128 :: proc(i: u128) -> u128 { return __llvm_cttz128(i, false); }
|
||||
|
||||
|
||||
reverse_bits8 :: proc(i: u8) -> u8 { return __llvm_bitreverse8(i); }
|
||||
reverse_bits16 :: proc(i: u16) -> u16 { return __llvm_bitreverse16(i); }
|
||||
reverse_bits32 :: proc(i: u32) -> u32 { return __llvm_bitreverse32(i); }
|
||||
reverse_bits64 :: proc(i: u64) -> u64 { return __llvm_bitreverse64(i); }
|
||||
reverse_bits128 :: proc(i: u128) -> u128 { return __llvm_bitreverse128(i); }
|
||||
|
||||
from_be_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
from_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_u128 :: proc(i: u128) -> u128 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
from_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
|
||||
from_le_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
from_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_u128 :: proc(i: u128) -> u128 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
from_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
|
||||
to_be_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
to_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_u128 :: proc(i: u128) -> u128 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
to_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||
|
||||
|
||||
@@ -134,7 +115,6 @@ to_le_u8 :: proc(i: u8) -> u8 { return i; }
|
||||
to_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_u128 :: proc(i: u128) -> u128 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
to_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
|
||||
|
||||
@@ -146,8 +126,6 @@ overflowing_add_u32 :: proc(lhs, rhs: u32) -> (u32, bool) { foreign __llvm_co
|
||||
overflowing_add_i32 :: proc(lhs, rhs: i32) -> (i32, bool) { foreign __llvm_core @(link_name="llvm.sadd.with.overflow.i32") op :: proc(i32, i32) -> (i32, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_add_u64 :: proc(lhs, rhs: u64) -> (u64, bool) { foreign __llvm_core @(link_name="llvm.uadd.with.overflow.i64") op :: proc(u64, u64) -> (u64, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_add_i64 :: proc(lhs, rhs: i64) -> (i64, bool) { foreign __llvm_core @(link_name="llvm.sadd.with.overflow.i64") op :: proc(i64, i64) -> (i64, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_add_u128 :: proc(lhs, rhs: u128) -> (u128, bool) { foreign __llvm_core @(link_name="llvm.uadd.with.overflow.i128") op :: proc(u128, u128) -> (u128, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_add_i128 :: proc(lhs, rhs: i128) -> (i128, bool) { foreign __llvm_core @(link_name="llvm.sadd.with.overflow.i128") op :: proc(i128, i128) -> (i128, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_add_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
x, ok := overflowing_add_u32(u32(lhs), u32(rhs));
|
||||
@@ -172,7 +150,6 @@ overflowing_add :: proc[
|
||||
overflowing_add_u16, overflowing_add_i16,
|
||||
overflowing_add_u32, overflowing_add_i32,
|
||||
overflowing_add_u64, overflowing_add_i64,
|
||||
overflowing_add_u128, overflowing_add_i128,
|
||||
overflowing_add_uint, overflowing_add_int,
|
||||
];
|
||||
|
||||
@@ -184,8 +161,6 @@ overflowing_sub_u32 :: proc(lhs, rhs: u32) -> (u32, bool) { foreign __llvm_co
|
||||
overflowing_sub_i32 :: proc(lhs, rhs: i32) -> (i32, bool) { foreign __llvm_core @(link_name="llvm.ssub.with.overflow.i32") op :: proc(i32, i32) -> (i32, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_sub_u64 :: proc(lhs, rhs: u64) -> (u64, bool) { foreign __llvm_core @(link_name="llvm.usub.with.overflow.i64") op :: proc(u64, u64) -> (u64, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_sub_i64 :: proc(lhs, rhs: i64) -> (i64, bool) { foreign __llvm_core @(link_name="llvm.ssub.with.overflow.i64") op :: proc(i64, i64) -> (i64, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_sub_u128 :: proc(lhs, rhs: u128) -> (u128, bool) { foreign __llvm_core @(link_name="llvm.usub.with.overflow.i128") op :: proc(u128, u128) -> (u128, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_sub_i128 :: proc(lhs, rhs: i128) -> (i128, bool) { foreign __llvm_core @(link_name="llvm.ssub.with.overflow.i128") op :: proc(i128, i128) -> (i128, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_sub_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
x, ok := overflowing_sub_u32(u32(lhs), u32(rhs));
|
||||
@@ -210,7 +185,6 @@ overflowing_sub :: proc[
|
||||
overflowing_sub_u16, overflowing_sub_i16,
|
||||
overflowing_sub_u32, overflowing_sub_i32,
|
||||
overflowing_sub_u64, overflowing_sub_i64,
|
||||
overflowing_sub_u128, overflowing_sub_i128,
|
||||
overflowing_sub_uint, overflowing_sub_int,
|
||||
];
|
||||
|
||||
@@ -223,8 +197,6 @@ overflowing_mul_u32 :: proc(lhs, rhs: u32) -> (u32, bool) { foreign __llvm_co
|
||||
overflowing_mul_i32 :: proc(lhs, rhs: i32) -> (i32, bool) { foreign __llvm_core @(link_name="llvm.smul.with.overflow.i32") op :: proc(i32, i32) -> (i32, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_mul_u64 :: proc(lhs, rhs: u64) -> (u64, bool) { foreign __llvm_core @(link_name="llvm.umul.with.overflow.i64") op :: proc(u64, u64) -> (u64, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_mul_i64 :: proc(lhs, rhs: i64) -> (i64, bool) { foreign __llvm_core @(link_name="llvm.smul.with.overflow.i64") op :: proc(i64, i64) -> (i64, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_mul_u128 :: proc(lhs, rhs: u128) -> (u128, bool) { foreign __llvm_core @(link_name="llvm.umul.with.overflow.i128") op :: proc(u128, u128) -> (u128, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_mul_i128 :: proc(lhs, rhs: i128) -> (i128, bool) { foreign __llvm_core @(link_name="llvm.smul.with.overflow.i128") op :: proc(i128, i128) -> (i128, bool) ---; return op(lhs, rhs); }
|
||||
overflowing_mul_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
x, ok := overflowing_mul_u32(u32(lhs), u32(rhs));
|
||||
@@ -249,7 +221,6 @@ overflowing_mul :: proc[
|
||||
overflowing_mul_u16, overflowing_mul_i16,
|
||||
overflowing_mul_u32, overflowing_mul_i32,
|
||||
overflowing_mul_u64, overflowing_mul_i64,
|
||||
overflowing_mul_u128, overflowing_mul_i128,
|
||||
overflowing_mul_uint, overflowing_mul_int,
|
||||
];
|
||||
|
||||
@@ -261,8 +232,6 @@ is_power_of_two_u32 :: proc(i: u32) -> bool { return i > 0 && (i & (i-1)) == 0
|
||||
is_power_of_two_i32 :: proc(i: i32) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_u64 :: proc(i: u64) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_i64 :: proc(i: i64) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_u128 :: proc(i: u128) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_i128 :: proc(i: i128) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_uint :: proc(i: uint) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
is_power_of_two_int :: proc(i: int) -> bool { return i > 0 && (i & (i-1)) == 0; }
|
||||
|
||||
@@ -271,6 +240,5 @@ is_power_of_two :: proc[
|
||||
is_power_of_two_u16, is_power_of_two_i16,
|
||||
is_power_of_two_u32, is_power_of_two_i32,
|
||||
is_power_of_two_u64, is_power_of_two_i64,
|
||||
is_power_of_two_u128, is_power_of_two_i128,
|
||||
is_power_of_two_uint, is_power_of_two_int,
|
||||
]
|
||||
|
||||
@@ -65,14 +65,9 @@ write_rune :: proc(buf: ^String_Buffer, r: rune) {
|
||||
write_bytes(buf, b[..n]);
|
||||
}
|
||||
|
||||
write_i128 :: proc(buf: ^String_Buffer, i: i128, base: int) {
|
||||
b: [129]byte;
|
||||
s := strconv.append_bits(b[..], u128(i), base, true, 128, strconv.digits, 0);
|
||||
write_string(buf, s);
|
||||
}
|
||||
write_i64 :: proc(buf: ^String_Buffer, i: i64, base: int) {
|
||||
b: [129]byte;
|
||||
s := strconv.append_bits(b[..], u128(i), base, true, 64, strconv.digits, 0);
|
||||
s := strconv.append_bits(b[..], u64(i), base, true, 64, strconv.digits, 0);
|
||||
write_string(buf, s);
|
||||
}
|
||||
|
||||
@@ -418,8 +413,8 @@ fmt_write_padding :: proc(fi: ^Fmt_Info, width: int) {
|
||||
}
|
||||
}
|
||||
|
||||
_fmt_int :: proc(fi: ^Fmt_Info, u: u128, base: int, is_signed: bool, bit_size: int, digits: string) {
|
||||
_, neg := strconv.is_integer_negative(u128(u), is_signed, bit_size);
|
||||
_fmt_int :: proc(fi: ^Fmt_Info, u: u64, base: int, is_signed: bool, bit_size: int, digits: string) {
|
||||
_, neg := strconv.is_integer_negative(u, is_signed, bit_size);
|
||||
|
||||
BUF_SIZE :: 256;
|
||||
if fi.width_set || fi.prec_set {
|
||||
@@ -462,14 +457,13 @@ _fmt_int :: proc(fi: ^Fmt_Info, u: u128, base: int, is_signed: bool, bit_size: i
|
||||
if fi.hash && !fi.zero do flags |= strconv.Int_Flag.Prefix;
|
||||
if fi.plus do flags |= strconv.Int_Flag.Plus;
|
||||
if fi.space do flags |= strconv.Int_Flag.Space;
|
||||
s := strconv.append_bits(buf[start..], u128(u), base, is_signed, bit_size, digits, flags);
|
||||
s := strconv.append_bits(buf[start..], u, base, is_signed, bit_size, digits, flags);
|
||||
|
||||
if fi.hash && fi.zero {
|
||||
c: byte;
|
||||
c: byte = 0;
|
||||
switch base {
|
||||
case 2: c = 'b';
|
||||
case 8: c = 'o';
|
||||
// case 10: c = 'd';
|
||||
case 12: c = 'z';
|
||||
case 16: c = 'x';
|
||||
}
|
||||
@@ -494,11 +488,11 @@ fmt_rune :: proc(fi: ^Fmt_Info, r: rune, verb: rune) {
|
||||
case 'c', 'r', 'v':
|
||||
write_rune(fi.buf, r);
|
||||
case:
|
||||
fmt_int(fi, u128(r), false, 32, verb);
|
||||
fmt_int(fi, u64(r), false, 32, verb);
|
||||
}
|
||||
}
|
||||
|
||||
fmt_int :: proc(fi: ^Fmt_Info, u: u128, is_signed: bool, bit_size: int, verb: rune) {
|
||||
fmt_int :: proc(fi: ^Fmt_Info, u: u64, is_signed: bool, bit_size: int, verb: rune) {
|
||||
switch verb {
|
||||
case 'v': _fmt_int(fi, u, 10, is_signed, bit_size, __DIGITS_LOWER);
|
||||
case 'b': _fmt_int(fi, u, 2, is_signed, bit_size, __DIGITS_LOWER);
|
||||
@@ -597,7 +591,7 @@ fmt_string :: proc(fi: ^Fmt_Info, s: string, verb: rune) {
|
||||
if i > 0 && space do write_byte(fi.buf, ' ');
|
||||
char_set := __DIGITS_UPPER;
|
||||
if verb == 'x' do char_set = __DIGITS_LOWER;
|
||||
_fmt_int(fi, u128(s[i]), 16, false, 8, char_set);
|
||||
_fmt_int(fi, u64(s[i]), 16, false, 8, char_set);
|
||||
}
|
||||
|
||||
case:
|
||||
@@ -613,7 +607,7 @@ fmt_pointer :: proc(fi: ^Fmt_Info, p: rawptr, verb: rune) {
|
||||
fmt_bad_verb(fi, verb);
|
||||
return;
|
||||
}
|
||||
u := u128(uintptr(p));
|
||||
u := u64(uintptr(p));
|
||||
if !fi.hash || verb == 'v' {
|
||||
write_string(fi.buf, "0x");
|
||||
}
|
||||
@@ -652,13 +646,11 @@ enum_value_to_string :: proc(v: any) -> (string, bool) {
|
||||
case i16: return get_str(v, e);
|
||||
case i32: return get_str(v, e);
|
||||
case i64: return get_str(v, e);
|
||||
case i128: return get_str(v, e);
|
||||
case int: return get_str(v, e);
|
||||
case u8: return get_str(v, e);
|
||||
case u16: return get_str(v, e);
|
||||
case u32: return get_str(v, e);
|
||||
case u64: return get_str(v, e);
|
||||
case u128: return get_str(v, e);
|
||||
case uint: return get_str(v, e);
|
||||
case uintptr: return get_str(v, e);
|
||||
|
||||
@@ -817,6 +809,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
|
||||
m := (^raw.Map)(v.data);
|
||||
if m != nil {
|
||||
assert(info.generated_struct != nil);
|
||||
entries := &m.entries;
|
||||
gs := type_info_base(info.generated_struct).variant.(Type_Info_Struct);
|
||||
ed := type_info_base(gs.types[1]).variant.(Type_Info_Dynamic_Array);
|
||||
@@ -893,8 +886,6 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
case i32: tag = i64(i);
|
||||
case u64: tag = i64(i);
|
||||
case i64: tag = i64(i);
|
||||
case u128: tag = i64(i);
|
||||
case i128: tag = i64(i);
|
||||
case: panic("Invalid union tag type");
|
||||
}
|
||||
|
||||
@@ -937,10 +928,6 @@ fmt_complex :: proc(fi: ^Fmt_Info, c: complex128, bits: int, verb: rune) {
|
||||
}
|
||||
}
|
||||
|
||||
_u128_to_lo_hi :: proc(a: u128) -> (lo, hi: u64) do return u64(a), u64(a>>64);
|
||||
_i128_to_lo_hi :: proc(a: u128) -> (lo: u64 hi: i64) do return u64(a), i64(a>>64);
|
||||
|
||||
|
||||
fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
|
||||
if arg == nil {
|
||||
write_string(fi.buf, "<nil>");
|
||||
@@ -971,21 +958,19 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
|
||||
case complex64: fmt_complex(fi, complex128(a), 64, verb);
|
||||
case complex128: fmt_complex(fi, a, 128, verb);
|
||||
|
||||
case int: fmt_int(fi, u128(a), true, 8*size_of(int), verb);
|
||||
case i8: fmt_int(fi, u128(a), true, 8, verb);
|
||||
case i16: fmt_int(fi, u128(a), true, 16, verb);
|
||||
case i32: fmt_int(fi, u128(a), true, 32, verb);
|
||||
case i64: fmt_int(fi, u128(a), true, 64, verb);
|
||||
case i128: fmt_int(fi, u128(a), true, 128, verb);
|
||||
case int: fmt_int(fi, u64(a), true, 8*size_of(int), verb);
|
||||
case i8: fmt_int(fi, u64(a), true, 8, verb);
|
||||
case i16: fmt_int(fi, u64(a), true, 16, verb);
|
||||
case i32: fmt_int(fi, u64(a), true, 32, verb);
|
||||
case i64: fmt_int(fi, u64(a), true, 64, verb);
|
||||
|
||||
case uintptr: fmt_int(fi, u128(a), false, 8*size_of(uintptr), verb);
|
||||
case uintptr: fmt_int(fi, u64(a), false, 8*size_of(uintptr), verb);
|
||||
|
||||
case uint: fmt_int(fi, u128(a), false, 8*size_of(uint), verb);
|
||||
case u8: fmt_int(fi, u128(a), false, 8, verb);
|
||||
case u16: fmt_int(fi, u128(a), false, 16, verb);
|
||||
case u32: fmt_int(fi, u128(a), false, 32, verb);
|
||||
case u64: fmt_int(fi, u128(a), false, 64, verb);
|
||||
case u128: fmt_int(fi, u128(a), false, 128, verb);
|
||||
case uint: fmt_int(fi, u64(a), false, 8*size_of(uint), verb);
|
||||
case u8: fmt_int(fi, u64(a), false, 8, verb);
|
||||
case u16: fmt_int(fi, u64(a), false, 16, verb);
|
||||
case u32: fmt_int(fi, u64(a), false, 32, verb);
|
||||
case u64: fmt_int(fi, u64(a), false, 64, verb);
|
||||
|
||||
case string: fmt_string(fi, a, verb);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ _digit_value :: proc(r: rune) -> int {
|
||||
return v;
|
||||
}
|
||||
|
||||
parse_i128 :: proc(s: string) -> i128 {
|
||||
parse_i64 :: proc(s: string) -> i64 {
|
||||
neg := false;
|
||||
if len(s) > 1 {
|
||||
switch s[0] {
|
||||
@@ -41,7 +41,7 @@ parse_i128 :: proc(s: string) -> i128 {
|
||||
}
|
||||
|
||||
|
||||
base: i128 = 10;
|
||||
base: i64 = 10;
|
||||
if len(s) > 2 && s[0] == '0' {
|
||||
switch s[1] {
|
||||
case 'b': base = 2; s = s[2..];
|
||||
@@ -53,13 +53,13 @@ parse_i128 :: proc(s: string) -> i128 {
|
||||
}
|
||||
|
||||
|
||||
value: i128;
|
||||
value: i64;
|
||||
for r in s {
|
||||
if r == '_' {
|
||||
continue;
|
||||
}
|
||||
|
||||
v := i128(_digit_value(r));
|
||||
v := i64(_digit_value(r));
|
||||
if v >= base {
|
||||
break;
|
||||
}
|
||||
@@ -71,14 +71,14 @@ parse_i128 :: proc(s: string) -> i128 {
|
||||
return value;
|
||||
}
|
||||
|
||||
parse_u128 :: proc(s: string) -> u128 {
|
||||
parse_u64 :: proc(s: string) -> u64 {
|
||||
neg := false;
|
||||
if len(s) > 1 && s[0] == '+' {
|
||||
s = s[1..];
|
||||
}
|
||||
|
||||
|
||||
base := u128(10);
|
||||
base := u64(10);
|
||||
if len(s) > 2 && s[0] == '0' {
|
||||
switch s[1] {
|
||||
case 'b': base = 2; s = s[2..];
|
||||
@@ -90,13 +90,13 @@ parse_u128 :: proc(s: string) -> u128 {
|
||||
}
|
||||
|
||||
|
||||
value: u128;
|
||||
value: u64;
|
||||
for r in s {
|
||||
if r == '_' do continue;
|
||||
v := u128(_digit_value(r));
|
||||
v := u64(_digit_value(r));
|
||||
if v >= base do break;
|
||||
value *= base;
|
||||
value += u128(v);
|
||||
value += u64(v);
|
||||
}
|
||||
|
||||
if neg do return -value;
|
||||
@@ -105,10 +105,10 @@ parse_u128 :: proc(s: string) -> u128 {
|
||||
|
||||
|
||||
parse_int :: proc(s: string) -> int {
|
||||
return int(parse_i128(s));
|
||||
return int(parse_i64(s));
|
||||
}
|
||||
parse_uint :: proc(s: string, base: int) -> uint {
|
||||
return uint(parse_u128(s));
|
||||
return uint(parse_u64(s));
|
||||
}
|
||||
|
||||
parse_f32 :: proc(s: string) -> f32 {
|
||||
@@ -193,10 +193,10 @@ append_bool :: proc(buf: []byte, b: bool) -> string {
|
||||
}
|
||||
|
||||
append_uint :: proc(buf: []byte, u: u64, base: int) -> string {
|
||||
return append_bits(buf, u128(u), base, false, 8*size_of(uint), digits, 0);
|
||||
return append_bits(buf, u64(u), base, false, 8*size_of(uint), digits, 0);
|
||||
}
|
||||
append_int :: proc(buf: []byte, i: i64, base: int) -> string {
|
||||
return append_bits(buf, u128(i), base, true, 8*size_of(int), digits, 0);
|
||||
return append_bits(buf, u64(i), base, true, 8*size_of(int), digits, 0);
|
||||
}
|
||||
itoa :: proc(buf: []byte, i: int) -> string do return append_int(buf, i64(i), 10);
|
||||
|
||||
@@ -427,30 +427,26 @@ MAX_BASE :: 32;
|
||||
digits := "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
|
||||
is_integer_negative :: proc(u: u128, is_signed: bool, bit_size: int) -> (unsigned: u128, neg: bool) {
|
||||
is_integer_negative :: proc(u: u64, is_signed: bool, bit_size: int) -> (unsigned: u64, neg: bool) {
|
||||
neg := false;
|
||||
if is_signed {
|
||||
switch bit_size {
|
||||
case 8:
|
||||
i := i8(u);
|
||||
neg = i < 0;
|
||||
u = u128(abs(i));
|
||||
u = u64(abs(i));
|
||||
case 16:
|
||||
i := i16(u);
|
||||
neg = i < 0;
|
||||
u = u128(abs(i));
|
||||
u = u64(abs(i));
|
||||
case 32:
|
||||
i := i32(u);
|
||||
neg = i < 0;
|
||||
u = u128(abs(i));
|
||||
u = u64(abs(i));
|
||||
case 64:
|
||||
i := i64(u);
|
||||
neg = i < 0;
|
||||
u = u128(abs(i));
|
||||
case 128:
|
||||
i := i128(u);
|
||||
neg = i < 0;
|
||||
u = u128(abs(i));
|
||||
u = u64(abs(i));
|
||||
case:
|
||||
panic("is_integer_negative: Unknown integer size");
|
||||
}
|
||||
@@ -458,7 +454,7 @@ is_integer_negative :: proc(u: u128, is_signed: bool, bit_size: int) -> (unsigne
|
||||
return u, neg;
|
||||
}
|
||||
|
||||
append_bits :: proc(buf: []byte, u: u128, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flag) -> string {
|
||||
append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flag) -> string {
|
||||
if base < 2 || base > MAX_BASE {
|
||||
panic("strconv: illegal base passed to append_bits");
|
||||
}
|
||||
@@ -467,12 +463,12 @@ append_bits :: proc(buf: []byte, u: u128, base: int, is_signed: bool, bit_size:
|
||||
a: [129]byte;
|
||||
i := len(a);
|
||||
u, neg = is_integer_negative(u, is_signed, bit_size);
|
||||
b := u128(base);
|
||||
b := u64(base);
|
||||
for u >= b {
|
||||
i-=1; a[i] = digits[uint(u % b)];
|
||||
i-=1; a[i] = digits[u % b];
|
||||
u /= b;
|
||||
}
|
||||
i-=1; a[i] = digits[uint(u % b)];
|
||||
i-=1; a[i] = digits[u % b];
|
||||
|
||||
if flags&Int_Flag.Prefix != 0 {
|
||||
ok := true;
|
||||
|
||||
@@ -793,7 +793,7 @@ bool is_polymorphic_type_assignable(Checker *c, Type *poly, Type *source, bool c
|
||||
if (e->Constant.value.kind != ExactValue_Integer) {
|
||||
return false;
|
||||
}
|
||||
i64 count = i128_to_i64(e->Constant.value.value_integer);
|
||||
i64 count = e->Constant.value.value_integer;
|
||||
if (count != source->Array.count) {
|
||||
return false;
|
||||
}
|
||||
@@ -1211,37 +1211,39 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
|
||||
return true;
|
||||
}
|
||||
|
||||
i128 i = v.value_integer;
|
||||
u128 u = *cast(u128 *)&i;
|
||||
i64 i = v.value_integer;
|
||||
u64 u = *cast(u64 *)&i;
|
||||
i64 s = 8*type_size_of(c->allocator, type);
|
||||
u128 umax = U128_NEG_ONE;
|
||||
if (s < 128) {
|
||||
umax = u128_sub(u128_shl(U128_ONE, cast(u32)s), U128_ONE);
|
||||
u64 umax = ~cast(u64)0ull;
|
||||
if (s < 64) {
|
||||
umax = (1ull << cast(u64)s) - 1ull;
|
||||
} else {
|
||||
// IMPORTANT TODO(bill): I NEED A PROPER BIG NUMBER LIBRARY THAT CAN SUPPORT 128 bit floats
|
||||
s = 128;
|
||||
s = 64;
|
||||
}
|
||||
i128 imax = i128_shl(I128_ONE, cast(u32)s-1);
|
||||
i64 imin = -1ll << (s-1ll);
|
||||
i64 imax = (1ll << (s-1ll))-1ll;
|
||||
|
||||
switch (type->Basic.kind) {
|
||||
case Basic_rune:
|
||||
case Basic_i8:
|
||||
case Basic_i16:
|
||||
case Basic_i32:
|
||||
case Basic_i64:
|
||||
case Basic_i128:
|
||||
case Basic_int:
|
||||
return i128_le(i128_neg(imax), i) && i128_le(i, i128_sub(imax, I128_ONE));
|
||||
return imin <= i && i <= imax;
|
||||
|
||||
case Basic_u8:
|
||||
case Basic_u16:
|
||||
case Basic_u32:
|
||||
case Basic_u64:
|
||||
case Basic_u128:
|
||||
case Basic_uint:
|
||||
case Basic_uintptr:
|
||||
return !(u128_lt(u, U128_ZERO) || u128_gt(u, umax));
|
||||
return !(u < 0ull || u > umax);
|
||||
|
||||
case Basic_u64:
|
||||
return 0ull <= i;
|
||||
|
||||
case Basic_i64:
|
||||
return true;
|
||||
case Basic_UntypedInteger:
|
||||
return true;
|
||||
|
||||
@@ -1317,11 +1319,11 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
|
||||
} else {
|
||||
char buf[127] = {};
|
||||
String str = {};
|
||||
i128 i = o->value.value_integer;
|
||||
i64 i = o->value.value_integer;
|
||||
if (is_type_unsigned(o->type)) {
|
||||
str = u128_to_string(*cast(u128 *)&i, buf, gb_size_of(buf));
|
||||
str = u64_to_string(*cast(u64 *)&i, buf, gb_size_of(buf));
|
||||
} else {
|
||||
str = i128_to_string(i, buf, gb_size_of(buf));
|
||||
str = i64_to_string(i, buf, gb_size_of(buf));
|
||||
}
|
||||
error(o->expr, "'%s = %.*s' overflows '%s'", a, LIT(str), b);
|
||||
}
|
||||
@@ -1569,7 +1571,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) {
|
||||
return;
|
||||
}
|
||||
|
||||
i64 amount = i128_to_i64(y_val.value_integer);
|
||||
i64 amount = y_val.value_integer;
|
||||
if (amount > 128) {
|
||||
gbString err_str = expr_to_string(y->expr);
|
||||
error(node, "Shift amount too large: '%s'", err_str);
|
||||
@@ -1604,7 +1606,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) {
|
||||
}
|
||||
}
|
||||
|
||||
if (y->mode == Addressing_Constant && i128_lt(y->value.value_integer, I128_ZERO)) {
|
||||
if (y->mode == Addressing_Constant && y->value.value_integer < 0) {
|
||||
gbString err_str = expr_to_string(y->expr);
|
||||
error(node, "Shift amount cannot be negative: '%s'", err_str);
|
||||
gb_string_free(err_str);
|
||||
@@ -1656,7 +1658,7 @@ Operand check_ptr_addition(Checker *c, TokenKind op, Operand *ptr, Operand *offs
|
||||
|
||||
if (ptr->mode == Addressing_Constant && offset->mode == Addressing_Constant) {
|
||||
i64 ptr_val = ptr->value.value_pointer;
|
||||
i64 offset_val = i128_to_i64(exact_value_to_integer(offset->value).value_integer);
|
||||
i64 offset_val = exact_value_to_integer(offset->value).value_integer;
|
||||
i64 new_ptr_val = ptr_val;
|
||||
if (op == Token_Add) {
|
||||
new_ptr_val += elem_size*offset_val;
|
||||
@@ -2010,7 +2012,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
|
||||
bool fail = false;
|
||||
switch (y->value.kind) {
|
||||
case ExactValue_Integer:
|
||||
if (i128_eq(y->value.value_integer, I128_ZERO)) {
|
||||
if (y->value.value_integer == 0 ) {
|
||||
fail = true;
|
||||
}
|
||||
break;
|
||||
@@ -2148,7 +2150,7 @@ void convert_untyped_error(Checker *c, Operand *operand, Type *target_type) {
|
||||
char *extra_text = "";
|
||||
|
||||
if (operand->mode == Addressing_Constant) {
|
||||
if (i128_eq(operand->value.value_integer, I128_ZERO)) {
|
||||
if (operand->value.value_integer == 0) {
|
||||
if (make_string_c(expr_str) != "nil") { // HACK NOTE(bill): Just in case
|
||||
// NOTE(bill): Doesn't matter what the type is as it's still zero in the union
|
||||
extra_text = " - Did you want 'nil'?";
|
||||
@@ -2396,7 +2398,7 @@ bool check_index_value(Checker *c, bool open_range, AstNode *index_value, i64 ma
|
||||
|
||||
if (operand.mode == Addressing_Constant &&
|
||||
(c->context.stmt_state_flags & StmtStateFlag_no_bounds_check) == 0) {
|
||||
i64 i = i128_to_i64(exact_value_to_integer(operand.value).value_integer);
|
||||
i64 i = exact_value_to_integer(operand.value).value_integer;
|
||||
if (i < 0) {
|
||||
gbString expr_str = expr_to_string(operand.expr);
|
||||
error(operand.expr, "Index '%s' cannot be a negative value", expr_str);
|
||||
@@ -2605,7 +2607,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
|
||||
operand->expr = node;
|
||||
return nullptr;
|
||||
}
|
||||
i64 index = i128_to_i64(o.value.value_integer);
|
||||
i64 index = o.value.value_integer;
|
||||
if (index < 0) {
|
||||
error(o.expr, "Index %lld cannot be a negative value", index);
|
||||
operand->mode = Addressing_Invalid;
|
||||
@@ -3307,7 +3309,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
i64 max_count = type->Array.count;
|
||||
Type *elem_type = type->Array.elem;
|
||||
|
||||
i128 max_count128 = i128_from_i64(max_count);
|
||||
i64 arg_count = 0;
|
||||
for_array(i, ce->args) {
|
||||
if (i == 0) {
|
||||
@@ -3325,12 +3326,12 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
return false;
|
||||
}
|
||||
|
||||
if (op.value.value_integer < I128_ZERO) {
|
||||
if (op.value.value_integer < 0) {
|
||||
error(op.expr, "Negative 'swizzle' index");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (max_count128 <= op.value.value_integer) {
|
||||
if (max_count <= op.value.value_integer) {
|
||||
error(op.expr, "'swizzle' index exceeds length");
|
||||
return false;
|
||||
}
|
||||
@@ -3717,7 +3718,7 @@ break;
|
||||
if (operand->mode == Addressing_Constant) {
|
||||
switch (operand->value.kind) {
|
||||
case ExactValue_Integer:
|
||||
operand->value.value_integer = i128_abs(operand->value.value_integer);
|
||||
operand->value.value_integer = gb_abs(operand->value.value_integer);
|
||||
break;
|
||||
case ExactValue_Float:
|
||||
operand->value.value_float = gb_abs(operand->value.value_float);
|
||||
|
||||
@@ -260,16 +260,16 @@ Type *check_assignment_variable(Checker *c, Operand *lhs, Operand *rhs) {
|
||||
if (rhs->mode == Addressing_Constant) {
|
||||
ExactValue v = exact_value_to_integer(rhs->value);
|
||||
if (v.kind == ExactValue_Integer) {
|
||||
i128 i = v.value_integer;
|
||||
u128 u = *cast(u128 *)&i;
|
||||
u128 umax = U128_NEG_ONE;
|
||||
if (lhs_bits < 128) {
|
||||
umax = u128_sub(u128_shl(U128_ONE, cast(u32)lhs_bits), U128_ONE);
|
||||
i64 i = v.value_integer;
|
||||
u64 u = *cast(u64 *)&i;
|
||||
u64 umax = ~cast(u64)0ull;
|
||||
if (lhs_bits < 64) {
|
||||
umax = (1ull << cast(u64)lhs_bits) - 1ull;
|
||||
}
|
||||
i128 imax = i128_shl(I128_ONE, cast(u32)lhs_bits-1);
|
||||
i64 imax = 1ll << (cast(i64)lhs_bits-1ll);
|
||||
|
||||
bool ok = false;
|
||||
ok = !(u128_lt(u, U128_ZERO) || u128_gt(u, umax));
|
||||
ok = !(u < 0 || u > umax);
|
||||
|
||||
if (ok) {
|
||||
return rhs->type;
|
||||
|
||||
@@ -271,7 +271,7 @@ bool check_custom_align(Checker *c, AstNode *node, i64 *align_) {
|
||||
Type *type = base_type(o.type);
|
||||
if (is_type_untyped(type) || is_type_integer(type)) {
|
||||
if (o.value.kind == ExactValue_Integer) {
|
||||
i64 align = i128_to_i64(o.value.value_integer);
|
||||
i64 align = o.value.value_integer;
|
||||
if (align < 1 || !gb_is_power_of_two(align)) {
|
||||
error(node, "#align must be a power of 2, got %lld", align);
|
||||
return false;
|
||||
@@ -847,9 +847,9 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, AstNode *node) {
|
||||
error(value, "Bit field bit size must be a constant integer");
|
||||
continue;
|
||||
}
|
||||
i64 bits = i128_to_i64(v.value_integer);
|
||||
if (bits < 0 || bits > 128) {
|
||||
error(value, "Bit field's bit size must be within the range 1..<128, got %lld", cast(long long)bits);
|
||||
i64 bits = v.value_integer;
|
||||
if (bits < 0 || bits > 64) {
|
||||
error(value, "Bit field's bit size must be within the range 1..<64, got %lld", cast(long long)bits);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1767,7 +1767,7 @@ i64 check_array_count(Checker *c, Operand *o, AstNode *e) {
|
||||
Type *type = base_type(o->type);
|
||||
if (is_type_untyped(type) || is_type_integer(type)) {
|
||||
if (o->value.kind == ExactValue_Integer) {
|
||||
i64 count = i128_to_i64(o->value.value_integer);
|
||||
i64 count = o->value.value_integer;
|
||||
if (count >= 0) {
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -913,7 +913,6 @@ void init_universal_scope(void) {
|
||||
t_u8_ptr = make_type_pointer(a, t_u8);
|
||||
t_int_ptr = make_type_pointer(a, t_int);
|
||||
t_i64_ptr = make_type_pointer(a, t_i64);
|
||||
t_i128_ptr = make_type_pointer(a, t_i128);
|
||||
t_f64_ptr = make_type_pointer(a, t_f64);
|
||||
t_u8_slice = make_type_slice(a, t_u8);
|
||||
t_string_slice = make_type_slice(a, t_string);
|
||||
|
||||
102
src/common.cpp
102
src/common.cpp
@@ -95,23 +95,113 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
|
||||
#include "unicode.cpp"
|
||||
#include "string.cpp"
|
||||
#include "array.cpp"
|
||||
#include "integer128.cpp"
|
||||
// #include "integer128.cpp"
|
||||
#include "murmurhash3.cpp"
|
||||
|
||||
#define for_array(index_, array_) for (isize index_ = 0; index_ < (array_).count; index_++)
|
||||
|
||||
|
||||
u128 fnv128a(void const *data, isize len) {
|
||||
u128 o = u128_lo_hi(0x13bull, 0x1000000ull);
|
||||
u128 h = u128_lo_hi(0x62b821756295c58dull, 0x6c62272e07bb0142ull);
|
||||
u64 fnv64a(void const *data, isize len) {
|
||||
u8 const *bytes = cast(u8 const *)data;
|
||||
u64 h = 0xcbf29ce484222325ull;
|
||||
for (isize i = 0; i < len; i++) {
|
||||
h.lo ^= bytes[i];
|
||||
h = h * o;
|
||||
u64 b = cast(u64)bytes[i];
|
||||
h = (h ^ b) * 0x100000001b3ull;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
u64 u64_digit_value(Rune r) {
|
||||
if ('0' <= r && r <= '9') {
|
||||
return r - '0';
|
||||
} else if ('a' <= r && r <= 'f') {
|
||||
return r - 'a' + 10;
|
||||
} else if ('A' <= r && r <= 'F') {
|
||||
return r - 'A' + 10;
|
||||
}
|
||||
return 16; // NOTE(bill): Larger than highest possible
|
||||
}
|
||||
|
||||
|
||||
u64 u64_from_string(String string) {
|
||||
u64 base = 10;
|
||||
bool has_prefix = false;
|
||||
if (string.len > 2 && string[0] == '0') {
|
||||
switch (string[1]) {
|
||||
case 'b': base = 2; has_prefix = true; break;
|
||||
case 'o': base = 8; has_prefix = true; break;
|
||||
case 'd': base = 10; has_prefix = true; break;
|
||||
case 'z': base = 12; has_prefix = true; break;
|
||||
case 'x': base = 16; has_prefix = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
u8 *text = string.text;
|
||||
isize len = string.len;
|
||||
if (has_prefix) {
|
||||
text += 2;
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
u64 result = 0ull;
|
||||
for (isize i = 0; i < len; i++) {
|
||||
Rune r = cast(Rune)text[i];
|
||||
if (r == '_') {
|
||||
continue;
|
||||
}
|
||||
u64 v = u64_digit_value(r);
|
||||
if (v >= base) {
|
||||
break;
|
||||
}
|
||||
result *= base;
|
||||
result += v;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String u64_to_string(u64 v, char *out_buf, isize out_buf_len) {
|
||||
char buf[200] = {0};
|
||||
isize i = gb_size_of(buf);
|
||||
|
||||
u64 b = 10;
|
||||
while (v >= b) {
|
||||
buf[--i] = gb__num_to_char_table[v%b];
|
||||
v /= b;
|
||||
}
|
||||
buf[--i] = gb__num_to_char_table[v%b];
|
||||
|
||||
isize len = gb_min(gb_size_of(buf)-i, out_buf_len);
|
||||
gb_memcopy(out_buf, &buf[i], len);
|
||||
return make_string(cast(u8 *)out_buf, len);
|
||||
}
|
||||
String i64_to_string(i64 a, char *out_buf, isize out_buf_len) {
|
||||
char buf[200] = {0};
|
||||
isize i = gb_size_of(buf);
|
||||
bool negative = false;
|
||||
if (a < 0) {
|
||||
negative = true;
|
||||
a = -a;
|
||||
}
|
||||
|
||||
u64 v = cast(u64)a;
|
||||
u64 b = 10;
|
||||
while (v >= b) {
|
||||
buf[--i] = gb__num_to_char_table[v%b];
|
||||
v /= b;
|
||||
}
|
||||
buf[--i] = gb__num_to_char_table[v%b];
|
||||
|
||||
if (negative) {
|
||||
buf[--i] = '-';
|
||||
}
|
||||
|
||||
isize len = gb_min(gb_size_of(buf)-i, out_buf_len);
|
||||
gb_memcopy(out_buf, &buf[i], len);
|
||||
return make_string(cast(u8 *)out_buf, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "map.cpp"
|
||||
|
||||
@@ -33,7 +33,7 @@ struct ExactValue {
|
||||
union {
|
||||
bool value_bool;
|
||||
String value_string;
|
||||
i128 value_integer; // NOTE(bill): This must be an integer and not a pointer
|
||||
i64 value_integer; // NOTE(bill): This must be an integer and not a pointer
|
||||
f64 value_float;
|
||||
i64 value_pointer;
|
||||
Complex128 value_complex;
|
||||
@@ -70,19 +70,14 @@ ExactValue exact_value_string(String string) {
|
||||
}
|
||||
|
||||
ExactValue exact_value_i64(i64 i) {
|
||||
ExactValue result = {ExactValue_Integer};
|
||||
result.value_integer = i128_from_i64(i);
|
||||
return result;
|
||||
}
|
||||
|
||||
ExactValue exact_value_i128(i128 i) {
|
||||
ExactValue result = {ExactValue_Integer};
|
||||
result.value_integer = i;
|
||||
return result;
|
||||
}
|
||||
ExactValue exact_value_u128(u128 i) {
|
||||
|
||||
ExactValue exact_value_u64(u64 i) {
|
||||
ExactValue result = {ExactValue_Integer};
|
||||
result.value_integer = u128_to_i128(i);
|
||||
result.value_integer = i64(i);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -119,7 +114,8 @@ ExactValue exact_value_procedure(AstNode *node) {
|
||||
|
||||
|
||||
ExactValue exact_value_integer_from_string(String string) {
|
||||
return exact_value_u128(u128_from_string(string));
|
||||
u64 u = u64_from_string(string);
|
||||
return exact_value_u64(u);
|
||||
}
|
||||
|
||||
f64 float_from_string(String string) {
|
||||
@@ -273,10 +269,10 @@ ExactValue exact_value_to_integer(ExactValue v) {
|
||||
case ExactValue_Integer:
|
||||
return v;
|
||||
case ExactValue_Float: {
|
||||
i128 i = i128_from_f64(v.value_float);
|
||||
f64 f = i128_to_f64(i);
|
||||
i64 i = cast(i64)v.value_float;
|
||||
f64 f = cast(f64)i;
|
||||
if (f == v.value_float) {
|
||||
return exact_value_i128(i);
|
||||
return exact_value_i64(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -291,7 +287,7 @@ ExactValue exact_value_to_integer(ExactValue v) {
|
||||
ExactValue exact_value_to_float(ExactValue v) {
|
||||
switch (v.kind) {
|
||||
case ExactValue_Integer:
|
||||
return exact_value_float(i128_to_f64(v.value_integer));
|
||||
return exact_value_float(cast(f64)v.value_integer);
|
||||
case ExactValue_Float:
|
||||
return v;
|
||||
}
|
||||
@@ -302,7 +298,7 @@ ExactValue exact_value_to_float(ExactValue v) {
|
||||
ExactValue exact_value_to_complex(ExactValue v) {
|
||||
switch (v.kind) {
|
||||
case ExactValue_Integer:
|
||||
return exact_value_complex(i128_to_f64(v.value_integer), 0);
|
||||
return exact_value_complex(cast(f64)v.value_integer, 0);
|
||||
case ExactValue_Float:
|
||||
return exact_value_complex(v.value_float, 0);
|
||||
case ExactValue_Complex:
|
||||
@@ -388,7 +384,7 @@ ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision)
|
||||
}
|
||||
|
||||
case Token_Xor: {
|
||||
i128 i = I128_ZERO;
|
||||
i64 i = 0;
|
||||
switch (v.kind) {
|
||||
case ExactValue_Invalid:
|
||||
return v;
|
||||
@@ -402,12 +398,11 @@ ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision)
|
||||
// NOTE(bill): unsigned integers will be negative and will need to be
|
||||
// limited to the types precision
|
||||
// IMPORTANT NOTE(bill): Max precision is 64 bits as that's how integers are stored
|
||||
if (0 < precision && precision < 128) {
|
||||
i = i & ~(I128_NEG_ONE << precision);
|
||||
if (0 < precision && precision < 64) {
|
||||
i = i & ~(-1ll << precision);
|
||||
}
|
||||
|
||||
return exact_value_i128(i);
|
||||
break;
|
||||
return exact_value_i64(i);
|
||||
}
|
||||
|
||||
case Token_Not: {
|
||||
@@ -472,10 +467,10 @@ void match_exact_values(ExactValue *x, ExactValue *y) {
|
||||
return;
|
||||
case ExactValue_Float:
|
||||
// TODO(bill): Is this good enough?
|
||||
*x = exact_value_float(i128_to_f64(x->value_integer));
|
||||
*x = exact_value_float(cast(f64)x->value_integer);
|
||||
return;
|
||||
case ExactValue_Complex:
|
||||
*x = exact_value_complex(i128_to_f64(x->value_integer), 0);
|
||||
*x = exact_value_complex(cast(f64)x->value_integer, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -513,27 +508,27 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y)
|
||||
break;
|
||||
|
||||
case ExactValue_Integer: {
|
||||
i128 a = x.value_integer;
|
||||
i128 b = y.value_integer;
|
||||
i128 c = I128_ZERO;
|
||||
i64 a = x.value_integer;
|
||||
i64 b = y.value_integer;
|
||||
i64 c = 0ll;
|
||||
switch (op) {
|
||||
case Token_Add: c = a + b; break;
|
||||
case Token_Sub: c = a - b; break;
|
||||
case Token_Mul: c = a * b; break;
|
||||
case Token_Quo: return exact_value_float(fmod(i128_to_f64(a), i128_to_f64(b)));
|
||||
case Token_Quo: return exact_value_float(fmod(cast(f64)a, cast(f64)b));
|
||||
case Token_QuoEq: c = a / b; break; // NOTE(bill): Integer division
|
||||
case Token_Mod: c = a % b; break;
|
||||
case Token_ModMod: c = ((a % b) + b) % b; break;
|
||||
case Token_And: c = a & b; break;
|
||||
case Token_Or: c = a | b; break;
|
||||
case Token_Xor: c = a ^ b; break;
|
||||
case Token_AndNot: c = i128_and_not(a, b); break;
|
||||
case Token_Shl: c = a << cast(u32)i128_to_u64(b); break;
|
||||
case Token_Shr: c = a >> cast(u32)i128_to_u64(b); break;
|
||||
case Token_AndNot: c = a & (~b); break;
|
||||
case Token_Shl: c = a << b; break;
|
||||
case Token_Shr: c = a >> b; break;
|
||||
default: goto error;
|
||||
}
|
||||
|
||||
return exact_value_i128(c);
|
||||
return exact_value_i64(c);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -628,8 +623,8 @@ bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) {
|
||||
break;
|
||||
|
||||
case ExactValue_Integer: {
|
||||
i128 a = x.value_integer;
|
||||
i128 b = y.value_integer;
|
||||
i64 a = x.value_integer;
|
||||
i64 b = y.value_integer;
|
||||
switch (op) {
|
||||
case Token_CmpEq: return a == b;
|
||||
case Token_NotEq: return a != b;
|
||||
|
||||
31
src/ir.cpp
31
src/ir.cpp
@@ -1808,7 +1808,7 @@ irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val_ptr, Type *map_ty
|
||||
}
|
||||
|
||||
irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
|
||||
Type *hash_type = t_u128;
|
||||
Type *hash_type = t_u64;
|
||||
irValue *v = ir_add_local_generated(proc, t_map_key);
|
||||
Type *t = base_type(ir_type(key));
|
||||
key = ir_emit_conv(proc, key, key_type);
|
||||
@@ -1834,8 +1834,8 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
|
||||
if (str->kind == irValue_Constant) {
|
||||
ExactValue ev = str->Constant.value;
|
||||
GB_ASSERT(ev.kind == ExactValue_String);
|
||||
u128 hs = fnv128a(ev.value_string.text, ev.value_string.len);
|
||||
hashed_str = ir_value_constant(proc->module->allocator, t_u128, exact_value_u128(hs));
|
||||
u64 hs = fnv64a(ev.value_string.text, ev.value_string.len);
|
||||
hashed_str = ir_value_constant(proc->module->allocator, t_u64, exact_value_u64(hs));
|
||||
} else {
|
||||
irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 1);
|
||||
args[0] = str;
|
||||
@@ -1936,7 +1936,6 @@ irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) {
|
||||
case 2: int_type = t_u16; break;
|
||||
case 4: int_type = t_u32; break;
|
||||
case 8: int_type = t_u64; break;
|
||||
case 16: int_type = t_u128; break;
|
||||
}
|
||||
GB_ASSERT(int_type != nullptr);
|
||||
|
||||
@@ -2051,7 +2050,6 @@ irValue *ir_addr_load(irProcedure *proc, irAddr addr) {
|
||||
case 2: int_type = t_u16; break;
|
||||
case 4: int_type = t_u32; break;
|
||||
case 8: int_type = t_u64; break;
|
||||
case 16: int_type = t_u128; break;
|
||||
}
|
||||
GB_ASSERT(int_type != nullptr);
|
||||
|
||||
@@ -2355,23 +2353,6 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
|
||||
return ir_emit_arith(proc, Token_Mod, b, m, type);
|
||||
}
|
||||
|
||||
if (is_type_i128_or_u128(type)) {
|
||||
// IMPORTANT NOTE(bill): LLVM is goddamn buggy!
|
||||
bool is_unsigned = is_type_unsigned(type);
|
||||
char *name = nullptr;
|
||||
if (op == Token_Quo) {
|
||||
name = cast(char *)(is_unsigned ? "__udivti3" : "__divti3");
|
||||
} else if (op == Token_Mod) {
|
||||
name = cast(char *)(is_unsigned ? "__umodti3" : "__modti3");
|
||||
}
|
||||
if (name != nullptr) {
|
||||
irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 2);
|
||||
args[0] = left;
|
||||
args[1] = right;
|
||||
return ir_emit_global_call(proc, name, args, 2);
|
||||
}
|
||||
}
|
||||
|
||||
return ir_emit(proc, ir_instr_binary_op(proc, op, left, right, type));
|
||||
}
|
||||
|
||||
@@ -4587,7 +4568,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
GB_ASSERT(is_type_integer(tv.type));
|
||||
GB_ASSERT(tv.value.kind == ExactValue_Integer);
|
||||
|
||||
i32 src_index = cast(i32)i128_to_i64(tv.value.value_integer);
|
||||
i32 src_index = cast(i32)tv.value.value_integer;
|
||||
i32 dst_index = i-1;
|
||||
|
||||
irValue *src_elem = ir_emit_array_epi(proc, src, src_index);
|
||||
@@ -5484,7 +5465,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
Type *selector_type = base_type(type_of_expr(proc->module->info, se->selector));
|
||||
GB_ASSERT_MSG(is_type_integer(selector_type), "%s", type_to_string(selector_type));
|
||||
ExactValue val = type_and_value_of_expr(proc->module->info, sel).value;
|
||||
i64 index = i128_to_i64(val.value_integer);
|
||||
i64 index = val.value_integer;
|
||||
|
||||
Selection sel = lookup_field_from_index(proc->module->allocator, type, index);
|
||||
GB_ASSERT(sel.entity != nullptr);
|
||||
@@ -7900,8 +7881,6 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
case Basic_u32:
|
||||
case Basic_i64:
|
||||
case Basic_u64:
|
||||
case Basic_i128:
|
||||
case Basic_u128:
|
||||
case Basic_int:
|
||||
case Basic_uint:
|
||||
case Basic_uintptr: {
|
||||
|
||||
@@ -54,9 +54,9 @@ void ir_write_string(irFileBuffer *f, char const *s) {
|
||||
void ir_write_byte(irFileBuffer *f, u8 c) {
|
||||
ir_file_buffer_write(f, &c, 1);
|
||||
}
|
||||
void ir_write_i128(irFileBuffer *f, i128 i) {
|
||||
void ir_write_i64(irFileBuffer *f, i64 i) {
|
||||
char buf[200] = {};
|
||||
String str = i128_to_string(i, buf, gb_size_of(buf)-1);
|
||||
String str = i64_to_string(i, buf, gb_size_of(buf)-1);
|
||||
ir_write_string(f, str);
|
||||
}
|
||||
|
||||
@@ -280,8 +280,6 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t, bool in_struct) {
|
||||
case Basic_u32: ir_write_string(f, "i32"); return;
|
||||
case Basic_i64: ir_write_string(f, "i64"); return;
|
||||
case Basic_u64: ir_write_string(f, "i64"); return;
|
||||
case Basic_i128: ir_write_string(f, "i128"); return;
|
||||
case Basic_u128: ir_write_string(f, "i128"); return;
|
||||
|
||||
case Basic_rune: ir_write_string(f, "i32"); return;
|
||||
|
||||
@@ -525,19 +523,19 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
|
||||
}
|
||||
case ExactValue_Integer: {
|
||||
if (is_type_pointer(type)) {
|
||||
if (i128_eq(value.value_integer, I128_ZERO)) {
|
||||
if (value.value_integer == 0) {
|
||||
ir_write_string(f, "null");
|
||||
} else {
|
||||
ir_write_string(f, "inttoptr (");
|
||||
ir_print_type(f, m, t_int);
|
||||
ir_write_byte(f, ' ');
|
||||
ir_write_i128(f, value.value_integer);
|
||||
ir_write_i64(f, value.value_integer);
|
||||
ir_write_string(f, " to ");
|
||||
ir_print_type(f, m, t_rawptr);
|
||||
ir_write_string(f, ")");
|
||||
}
|
||||
} else {
|
||||
ir_write_i128(f, value.value_integer);
|
||||
ir_write_i64(f, value.value_integer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ bool parse_build_flags(Array<String> args) {
|
||||
if (ok) switch (bf.kind) {
|
||||
case BuildFlag_OptimizationLevel:
|
||||
GB_ASSERT(value.kind == ExactValue_Integer);
|
||||
build_context.optimization_level = cast(i32)i128_to_i64(value.value_integer);
|
||||
build_context.optimization_level = cast(i32)value.value_integer;
|
||||
break;
|
||||
case BuildFlag_ShowTimings:
|
||||
GB_ASSERT(value.kind == ExactValue_Invalid);
|
||||
@@ -369,7 +369,7 @@ bool parse_build_flags(Array<String> args) {
|
||||
break;
|
||||
case BuildFlag_ThreadCount: {
|
||||
GB_ASSERT(value.kind == ExactValue_Integer);
|
||||
isize count = cast(isize)i128_to_i64(value.value_integer);
|
||||
isize count = cast(isize)value.value_integer;
|
||||
if (count <= 0) {
|
||||
gb_printf_err("%.*s expected a positive non-zero number, got %.*s", LIT(name), LIT(param));
|
||||
build_context.thread_count = 0;
|
||||
|
||||
@@ -212,14 +212,14 @@ void MurmurHash3_x86_128(void const *key, isize len, u32 seed, void *out) {
|
||||
((u32 *)out)[3] = h4;
|
||||
}
|
||||
|
||||
gb_inline u128 MurmurHash3_128(void const *key, isize len, u32 seed) {
|
||||
u128 res;
|
||||
#if defined(GB_ARCH_64_BIT)
|
||||
MurmurHash3_x64_128(key, len, seed, &res);
|
||||
#else
|
||||
MurmurHash3_x86_128(key, len, seed, &res);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
// gb_inline u128 MurmurHash3_128(void const *key, isize len, u32 seed) {
|
||||
// u128 res;
|
||||
// #if defined(GB_ARCH_64_BIT)
|
||||
// MurmurHash3_x64_128(key, len, seed, &res);
|
||||
// #else
|
||||
// MurmurHash3_x86_128(key, len, seed, &res);
|
||||
// #endif
|
||||
// return res;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ enum BasicKind {
|
||||
Basic_u32,
|
||||
Basic_i64,
|
||||
Basic_u64,
|
||||
Basic_i128,
|
||||
Basic_u128,
|
||||
|
||||
Basic_rune,
|
||||
|
||||
@@ -249,8 +247,6 @@ gb_global Type basic_types[] = {
|
||||
{Type_Basic, {Basic_u32, BasicFlag_Integer | BasicFlag_Unsigned, 4, STR_LIT("u32")}},
|
||||
{Type_Basic, {Basic_i64, BasicFlag_Integer, 8, STR_LIT("i64")}},
|
||||
{Type_Basic, {Basic_u64, BasicFlag_Integer | BasicFlag_Unsigned, 8, STR_LIT("u64")}},
|
||||
{Type_Basic, {Basic_i128, BasicFlag_Integer, 16, STR_LIT("i128")}},
|
||||
{Type_Basic, {Basic_u128, BasicFlag_Integer | BasicFlag_Unsigned, 16, STR_LIT("u128")}},
|
||||
|
||||
{Type_Basic, {Basic_rune, BasicFlag_Integer | BasicFlag_Rune, 4, STR_LIT("rune")}},
|
||||
|
||||
@@ -296,8 +292,6 @@ gb_global Type *t_i32 = &basic_types[Basic_i32];
|
||||
gb_global Type *t_u32 = &basic_types[Basic_u32];
|
||||
gb_global Type *t_i64 = &basic_types[Basic_i64];
|
||||
gb_global Type *t_u64 = &basic_types[Basic_u64];
|
||||
gb_global Type *t_i128 = &basic_types[Basic_i128];
|
||||
gb_global Type *t_u128 = &basic_types[Basic_u128];
|
||||
|
||||
gb_global Type *t_rune = &basic_types[Basic_rune];
|
||||
|
||||
@@ -331,7 +325,6 @@ gb_global Type *t_untyped_undef = &basic_types[Basic_UntypedUndef];
|
||||
gb_global Type *t_u8_ptr = nullptr;
|
||||
gb_global Type *t_int_ptr = nullptr;
|
||||
gb_global Type *t_i64_ptr = nullptr;
|
||||
gb_global Type *t_i128_ptr = nullptr;
|
||||
gb_global Type *t_f64_ptr = nullptr;
|
||||
gb_global Type *t_u8_slice = nullptr;
|
||||
gb_global Type *t_string_slice = nullptr;
|
||||
@@ -756,12 +749,6 @@ bool is_type_uintptr(Type *t) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool is_type_i128_or_u128(Type *t) {
|
||||
if (t->kind == Type_Basic) {
|
||||
return (t->Basic.kind == Basic_i128) || (t->Basic.kind == Basic_u128);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool is_type_rawptr(Type *t) {
|
||||
if (t->kind == Type_Basic) {
|
||||
return t->Basic.kind == Basic_rawptr;
|
||||
@@ -1264,7 +1251,6 @@ Type *default_bit_field_value_type(Type *type) {
|
||||
case 16: return t_u16;
|
||||
case 32: return t_u32;
|
||||
case 64: return t_u64;
|
||||
case 128: return t_u128;
|
||||
default: GB_PANIC("Too big of a bit size!"); break;
|
||||
}
|
||||
}
|
||||
@@ -1385,7 +1371,6 @@ Type *union_tag_type(gbAllocator a, Type *u) {
|
||||
case 2: return t_u16;
|
||||
case 4: return t_u32;
|
||||
case 8: return t_u64;
|
||||
case 16: return t_u128;
|
||||
}
|
||||
GB_PANIC("Invalid union_tag_size");
|
||||
return t_uint;
|
||||
|
||||
Reference in New Issue
Block a user