diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-16 16:32:24 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-16 16:37:58 -0400 |
| commit | 80983ca1ca5cdcbd5ce7db017c1987d75cc8184b (patch) | |
| tree | 9a7e19e081e2dc575b9b363c28145f60b18cc32f /src/analyze.cpp | |
| parent | 1fdb24827fb51351d5e31103069619668fae31c4 (diff) | |
| download | zig-80983ca1ca5cdcbd5ce7db017c1987d75cc8184b.tar.gz zig-80983ca1ca5cdcbd5ce7db017c1987d75cc8184b.zip | |
fixups to the previous commit
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index f4e81ec042..57244aba6a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -213,6 +213,15 @@ static ZigType *new_container_type_entry(CodeGen *g, ZigTypeId id, AstNode *sour return entry; } +static uint8_t bits_needed_for_unsigned(uint64_t x) { + if (x == 0) { + return 0; + } + uint8_t base = log2_u64(x); + uint64_t upper = (((uint64_t)1) << base) - 1; + return (upper >= x) ? base : (base + 1); +} + AstNode *type_decl_node(ZigType *type_entry) { switch (type_entry->id) { case ZigTypeIdInvalid: @@ -326,33 +335,10 @@ static bool is_slice(ZigType *type) { return type->id == ZigTypeIdStruct && type->data.structure.is_slice; } -static uint8_t bits_needed_for_unsigned(uint64_t x) { - if (x == 0) { - return 0; - } - uint8_t base = log2_u64(x); - uint64_t upper = (((uint64_t)1) << base) - 1; - return (upper >= x) ? base : (base + 1); -} - -static uint8_t bits_needed_for_popcount_unsigned(uint64_t x) { - uint8_t count = 0; - for (uint64_t s = x;s != 0;s >>= 1) - count++; - - return count; -} - ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) { return get_int_type(g, false, bits_needed_for_unsigned(x)); } -// This is not the same as above, because while shift by bit width is UB, @clz, @popCount, and @ctz -// can return bit width -ZigType *get_smallest_popcount_unsigned_int_type(CodeGen *g, uint64_t x) { - return get_int_type(g, false, bits_needed_for_popcount_unsigned(x)); -} - ZigType *get_promise_type(CodeGen *g, ZigType *result_type) { if (result_type != nullptr && result_type->promise_parent != nullptr) { return result_type->promise_parent; |
