From b894e2b3788307546e330bd43304e5ff785dac51 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 28 May 2019 20:57:02 +0100 Subject: [PATCH] Fix bit set size with 128-bit integers --- src/check_type.cpp | 3 ++- 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 }