Remove u128 and i128

This commit is contained in:
gingerBill
2018-01-13 22:26:37 +00:00
parent 37790c13a0
commit 6b3c4cc379
16 changed files with 249 additions and 252 deletions
+18 -19
View File
@@ -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);
+2
View File
@@ -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;
}
*/
+1 -33
View File
@@ -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,
]
+21 -36
View File
@@ -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);
+22 -26
View File
@@ -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;