diff options
| author | gingerBill <bill@gingerbill.org> | 2019-05-28 20:57:02 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-05-28 20:57:02 +0100 |
| commit | b894e2b3788307546e330bd43304e5ff785dac51 (patch) | |
| tree | 4d354bbb2be385626035f3bada3c4fda363b0ced /src | |
| parent | c40acd008e92f8385ac1535adcbb4d7a46ce0a0e (diff) | |
Fix bit set size with 128-bit integers
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_type.cpp | 3 | ||||
| -rw-r--r-- | src/types.cpp | 29 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 1ab975b07..ca0fab260 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -948,7 +948,8 @@ void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *no ast_node(bs, BitSetType, node); GB_ASSERT(type->kind == Type_BitSet); - i64 const MAX_BITS = 64; + i64 const DEFAULT_BITS = cast(i64)(8*build_context.word_size); + i64 const MAX_BITS = 128; Ast *base = unparen_expr(bs->elem); if (is_ast_range(base)) { diff --git a/src/types.cpp b/src/types.cpp index 0c4c11175..875519f2d 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1238,11 +1238,12 @@ Type *bit_set_to_int(Type *t) { i64 sz = type_size_of(t); switch (sz) { - case 0: return t_u8; - case 1: return t_u8; - case 2: return t_u16; - case 4: return t_u32; - case 8: return t_u64; + case 0: return t_u8; + case 1: return t_u8; + case 2: return t_u16; + case 4: return t_u32; + case 8: return t_u64; + case 16: return t_u128; } GB_PANIC("Unknown bit_set size"); return nullptr; @@ -2414,10 +2415,11 @@ i64 type_align_of_internal(Type *t, TypePath *path) { return type_align_of(t->BitSet.underlying); } i64 bits = t->BitSet.upper - t->BitSet.lower + 1; - if (bits <= 8) return 1; - if (bits <= 16) return 2; - if (bits <= 32) return 4; - if (bits <= 64) return 8; + if (bits <= 8) return 1; + if (bits <= 16) return 2; + if (bits <= 32) return 4; + if (bits <= 64) return 8; + if (bits <= 128) return 16; return 8; // NOTE(bill): Could be an invalid range so limit it for now } @@ -2665,10 +2667,11 @@ i64 type_size_of_internal(Type *t, TypePath *path) { return type_size_of(t->BitSet.underlying); } i64 bits = t->BitSet.upper - t->BitSet.lower + 1; - if (bits <= 8) return 1; - if (bits <= 16) return 2; - if (bits <= 32) return 4; - if (bits <= 64) return 8; + if (bits <= 8) return 1; + if (bits <= 16) return 2; + if (bits <= 32) return 4; + if (bits <= 64) return 8; + if (bits <= 128) return 16; return 8; // NOTE(bill): Could be an invalid range so limit it for now } |