authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-16 10:53:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-16 10:53:15-04:00
loge9a03cccf375f11aa4e0a8a3515e499c88d05cde
tree6e6cd2117a7d25684a09a24be9f30ab684b650cc
parent363f4facea7fac2d6cfeab9d1d276ecd8e8e4df0

all integer sizes are available as primitives

* fix wrong implicit cast for `@IntType` bit_count parameter. * fix incorrect docs for `@IntType` bit_count parameter. closes #1242 closes #745 closes #1240

17 files changed, 74 insertions(+), 104 deletions(-)

doc/langref.html.in+6-6
...@@ -2310,11 +2310,11 @@ test "while loop continue expression" {...@@ -2310,11 +2310,11 @@ test "while loop continue expression" {
2310}2310}
23112311
2312test "while loop continue expression, more complicated" {2312test "while loop continue expression, more complicated" {
2313 var i1: usize = 1;2313 var i: usize = 1;
2314 var j1: usize = 1;2314 var j: usize = 1;
2315 while (i1 * j1 < 2000) : ({ i1 *= 2; j1 *= 3; }) {2315 while (i * j < 2000) : ({ i *= 2; j *= 3; }) {
2316 const my_ij1 = i1 * j1;2316 const my_ij = i * j;
2317 assert(my_ij1 < 2000);2317 assert(my_ij < 2000);
2318 }2318 }
2319}2319}
2320 {#code_end#}2320 {#code_end#}
...@@ -5424,7 +5424,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }...@@ -5424,7 +5424,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
5424 {#header_close#}5424 {#header_close#}
54255425
5426 {#header_open|@IntType#}5426 {#header_open|@IntType#}
5427 <pre><code class="zig">@IntType(comptime is_signed: bool, comptime bit_count: u8) type</code></pre>5427 <pre><code class="zig">@IntType(comptime is_signed: bool, comptime bit_count: u32) type</code></pre>
5428 <p>5428 <p>
5429 This function returns an integer type with the given signness and bit count.5429 This function returns an integer type with the given signness and bit count.
5430 </p>5430 </p>
src/all_types.hpp-4
...@@ -1587,7 +1587,6 @@ struct CodeGen {...@@ -1587,7 +1587,6 @@ struct CodeGen {
15871587
1588 struct {1588 struct {
1589 TypeTableEntry *entry_bool;1589 TypeTableEntry *entry_bool;
1590 TypeTableEntry *entry_int[2][12]; // [signed,unsigned][2,3,4,5,6,7,8,16,29,32,64,128]
1591 TypeTableEntry *entry_c_int[CIntTypeCount];1590 TypeTableEntry *entry_c_int[CIntTypeCount];
1592 TypeTableEntry *entry_c_longdouble;1591 TypeTableEntry *entry_c_longdouble;
1593 TypeTableEntry *entry_c_void;1592 TypeTableEntry *entry_c_void;
...@@ -1596,12 +1595,9 @@ struct CodeGen {...@@ -1596,12 +1595,9 @@ struct CodeGen {
1596 TypeTableEntry *entry_u32;1595 TypeTableEntry *entry_u32;
1597 TypeTableEntry *entry_u29;1596 TypeTableEntry *entry_u29;
1598 TypeTableEntry *entry_u64;1597 TypeTableEntry *entry_u64;
1599 TypeTableEntry *entry_u128;
1600 TypeTableEntry *entry_i8;1598 TypeTableEntry *entry_i8;
1601 TypeTableEntry *entry_i16;
1602 TypeTableEntry *entry_i32;1599 TypeTableEntry *entry_i32;
1603 TypeTableEntry *entry_i64;1600 TypeTableEntry *entry_i64;
1604 TypeTableEntry *entry_i128;
1605 TypeTableEntry *entry_isize;1601 TypeTableEntry *entry_isize;
1606 TypeTableEntry *entry_usize;1602 TypeTableEntry *entry_usize;
1607 TypeTableEntry *entry_f16;1603 TypeTableEntry *entry_f16;
src/analyze.cpp+31-42
...@@ -3227,9 +3227,8 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {...@@ -3227,9 +3227,8 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
3227 }3227 }
32283228
3229 {3229 {
3230 auto entry = g->primitive_type_table.maybe_get(tld->name);3230 TypeTableEntry *type = get_primitive_type(g, tld->name);
3231 if (entry) {3231 if (type != nullptr) {
3232 TypeTableEntry *type = entry->value;
3233 add_node_error(g, tld->source_node,3232 add_node_error(g, tld->source_node,
3234 buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name)));3233 buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name)));
3235 }3234 }
...@@ -3474,9 +3473,8 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent...@@ -3474,9 +3473,8 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent
3474 add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));3473 add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
3475 variable_entry->value->type = g->builtin_types.entry_invalid;3474 variable_entry->value->type = g->builtin_types.entry_invalid;
3476 } else {3475 } else {
3477 auto primitive_table_entry = g->primitive_type_table.maybe_get(name);3476 TypeTableEntry *type = get_primitive_type(g, name);
3478 if (primitive_table_entry) {3477 if (type != nullptr) {
3479 TypeTableEntry *type = primitive_table_entry->value;
3480 add_node_error(g, source_node,3478 add_node_error(g, source_node,
3481 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));3479 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
3482 variable_entry->value->type = g->builtin_types.entry_invalid;3480 variable_entry->value->type = g->builtin_types.entry_invalid;
...@@ -4307,43 +4305,7 @@ void semantic_analyze(CodeGen *g) {...@@ -4307,43 +4305,7 @@ void semantic_analyze(CodeGen *g) {
4307 }4305 }
4308}4306}
43094307
4310TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
4311 size_t index;
4312 if (size_in_bits == 2) {
4313 index = 0;
4314 } else if (size_in_bits == 3) {
4315 index = 1;
4316 } else if (size_in_bits == 4) {
4317 index = 2;
4318 } else if (size_in_bits == 5) {
4319 index = 3;
4320 } else if (size_in_bits == 6) {
4321 index = 4;
4322 } else if (size_in_bits == 7) {
4323 index = 5;
4324 } else if (size_in_bits == 8) {
4325 index = 6;
4326 } else if (size_in_bits == 16) {
4327 index = 7;
4328 } else if (size_in_bits == 29) {
4329 index = 8;
4330 } else if (size_in_bits == 32) {
4331 index = 9;
4332 } else if (size_in_bits == 64) {
4333 index = 10;
4334 } else if (size_in_bits == 128) {
4335 index = 11;
4336 } else {
4337 return nullptr;
4338 }
4339 return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];
4340}
4341
4342TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {4308TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
4343 TypeTableEntry **common_entry = get_int_type_ptr(g, is_signed, size_in_bits);
4344 if (common_entry)
4345 return *common_entry;
4346
4347 TypeId type_id = {};4309 TypeId type_id = {};
4348 type_id.id = TypeTableEntryIdInt;4310 type_id.id = TypeTableEntryIdInt;
4349 type_id.data.integer.is_signed = is_signed;4311 type_id.data.integer.is_signed = is_signed;
...@@ -4953,6 +4915,8 @@ bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type) {...@@ -4953,6 +4915,8 @@ bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type) {
4953 while (scope) {4915 while (scope) {
4954 if (scope->id == ScopeIdVarDecl) {4916 if (scope->id == ScopeIdVarDecl) {
4955 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;4917 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;
4918 if (type_is_invalid(var_scope->var->value->type))
4919 return false;
4956 if (can_mutate_comptime_var_state(var_scope->var->value))4920 if (can_mutate_comptime_var_state(var_scope->var->value))
4957 return false;4921 return false;
4958 } else if (scope->id == ScopeIdFnDef) {4922 } else if (scope->id == ScopeIdFnDef) {
...@@ -6310,3 +6274,28 @@ bool type_can_fail(TypeTableEntry *type_entry) {...@@ -6310,3 +6274,28 @@ bool type_can_fail(TypeTableEntry *type_entry) {
6310bool fn_type_can_fail(FnTypeId *fn_type_id) {6274bool fn_type_can_fail(FnTypeId *fn_type_id) {
6311 return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync;6275 return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync;
6312}6276}
6277
6278TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name) {
6279 if (buf_len(name) >= 2) {
6280 uint8_t first_c = buf_ptr(name)[0];
6281 if (first_c == 'i' || first_c == 'u') {
6282 for (size_t i = 1; i < buf_len(name); i += 1) {
6283 uint8_t c = buf_ptr(name)[i];
6284 if (c < '0' || c > '9') {
6285 goto not_integer;
6286 }
6287 }
6288 bool is_signed = (first_c == 'i');
6289 uint32_t bit_count = atoi(buf_ptr(name) + 1);
6290 return get_int_type(g, is_signed, bit_count);
6291 }
6292 }
6293
6294not_integer:
6295
6296 auto primitive_table_entry = g->primitive_type_table.maybe_get(name);
6297 if (primitive_table_entry != nullptr) {
6298 return primitive_table_entry->value;
6299 }
6300 return nullptr;
6301}
src/analyze.hpp+2-1
...@@ -19,7 +19,6 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type...@@ -19,7 +19,6 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
19 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);19 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
20uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);20uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
21uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);21uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);
22TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits);
23TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);22TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
24TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);23TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
25TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);24TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
...@@ -204,4 +203,6 @@ bool type_can_fail(TypeTableEntry *type_entry);...@@ -204,4 +203,6 @@ bool type_can_fail(TypeTableEntry *type_entry);
204bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type);203bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type);
205AstNode *type_decl_node(TypeTableEntry *type_entry);204AstNode *type_decl_node(TypeTableEntry *type_entry);
206205
206TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name);
207
207#endif208#endif
src/codegen.cpp-13
...@@ -6161,16 +6161,6 @@ static void define_builtin_types(CodeGen *g) {...@@ -6161,16 +6161,6 @@ static void define_builtin_types(CodeGen *g) {
6161 g->builtin_types.entry_arg_tuple = entry;6161 g->builtin_types.entry_arg_tuple = entry;
6162 }6162 }
61636163
6164 for (size_t int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
6165 uint8_t size_in_bits = int_sizes_in_bits[int_size_i];
6166 for (size_t is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
6167 bool is_signed = is_signed_list[is_sign_i];
6168 TypeTableEntry *entry = make_int_type(g, is_signed, size_in_bits);
6169 g->primitive_type_table.put(&entry->name, entry);
6170 get_int_type_ptr(g, is_signed, size_in_bits)[0] = entry;
6171 }
6172 }
6173
6174 for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) {6164 for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) {
6175 const CIntTypeInfo *info = &c_int_type_infos[i];6165 const CIntTypeInfo *info = &c_int_type_infos[i];
6176 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);6166 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);
...@@ -6286,12 +6276,9 @@ static void define_builtin_types(CodeGen *g) {...@@ -6286,12 +6276,9 @@ static void define_builtin_types(CodeGen *g) {
6286 g->builtin_types.entry_u29 = get_int_type(g, false, 29);6276 g->builtin_types.entry_u29 = get_int_type(g, false, 29);
6287 g->builtin_types.entry_u32 = get_int_type(g, false, 32);6277 g->builtin_types.entry_u32 = get_int_type(g, false, 32);
6288 g->builtin_types.entry_u64 = get_int_type(g, false, 64);6278 g->builtin_types.entry_u64 = get_int_type(g, false, 64);
6289 g->builtin_types.entry_u128 = get_int_type(g, false, 128);
6290 g->builtin_types.entry_i8 = get_int_type(g, true, 8);6279 g->builtin_types.entry_i8 = get_int_type(g, true, 8);
6291 g->builtin_types.entry_i16 = get_int_type(g, true, 16);
6292 g->builtin_types.entry_i32 = get_int_type(g, true, 32);6280 g->builtin_types.entry_i32 = get_int_type(g, true, 32);
6293 g->builtin_types.entry_i64 = get_int_type(g, true, 64);6281 g->builtin_types.entry_i64 = get_int_type(g, true, 64);
6294 g->builtin_types.entry_i128 = get_int_type(g, true, 128);
62956282
6296 {6283 {
6297 g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void");6284 g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void");
src/ir.cpp+12-9
...@@ -3217,9 +3217,8 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco...@@ -3217,9 +3217,8 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
3217 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));3217 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
3218 variable_entry->value->type = codegen->builtin_types.entry_invalid;3218 variable_entry->value->type = codegen->builtin_types.entry_invalid;
3219 } else {3219 } else {
3220 auto primitive_table_entry = codegen->primitive_type_table.maybe_get(name);3220 TypeTableEntry *type = get_primitive_type(codegen, name);
3221 if (primitive_table_entry) {3221 if (type != nullptr) {
3222 TypeTableEntry *type = primitive_table_entry->value;
3223 add_node_error(codegen, node,3222 add_node_error(codegen, node,
3224 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));3223 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
3225 variable_entry->value->type = codegen->builtin_types.entry_invalid;3224 variable_entry->value->type = codegen->builtin_types.entry_invalid;
...@@ -3661,9 +3660,9 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3661,9 +3660,9 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3661 return &const_instruction->base;3660 return &const_instruction->base;
3662 }3661 }
36633662
3664 auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name);3663 TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name);
3665 if (primitive_table_entry) {3664 if (primitive_type != nullptr) {
3666 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value);3665 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);
3667 if (lval == LValPtr) {3666 if (lval == LValPtr) {
3668 return ir_build_ref(irb, scope, node, value, false, false);3667 return ir_build_ref(irb, scope, node, value, false, false);
3669 } else {3668 } else {
...@@ -10691,11 +10690,11 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out...@@ -10691,11 +10690,11 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out
10691 return true;10690 return true;
10692}10691}
1069310692
10694static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {10693static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *int_type, uint64_t *out) {
10695 if (type_is_invalid(value->value.type))10694 if (type_is_invalid(value->value.type))
10696 return false;10695 return false;
1069710696
10698 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize);10697 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);
10699 if (type_is_invalid(casted_value->value.type))10698 if (type_is_invalid(casted_value->value.type))
10700 return false;10699 return false;
1070110700
...@@ -10707,6 +10706,10 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out...@@ -10707,6 +10706,10 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
10707 return true;10706 return true;
10708}10707}
1070910708
10709static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {
10710 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);
10711}
10712
10710static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {10713static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
10711 if (type_is_invalid(value->value.type))10714 if (type_is_invalid(value->value.type))
10712 return false;10715 return false;
...@@ -18025,7 +18028,7 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc...@@ -18025,7 +18028,7 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
1802518028
18026 IrInstruction *bit_count_value = instruction->bit_count->other;18029 IrInstruction *bit_count_value = instruction->bit_count->other;
18027 uint64_t bit_count;18030 uint64_t bit_count;
18028 if (!ir_resolve_usize(ira, bit_count_value, &bit_count))18031 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u32, &bit_count))
18029 return ira->codegen->builtin_types.entry_invalid;18032 return ira->codegen->builtin_types.entry_invalid;
1803018033
18031 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);18034 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
src/translate_c.cpp+1-1
...@@ -427,7 +427,7 @@ static AstNode *get_global(Context *c, Buf *name) {...@@ -427,7 +427,7 @@ static AstNode *get_global(Context *c, Buf *name) {
427 if (entry)427 if (entry)
428 return entry->value;428 return entry->value;
429 }429 }
430 if (c->codegen->primitive_type_table.maybe_get(name) != nullptr) {430 if (get_primitive_type(c->codegen, name) != nullptr) {
431 return trans_create_node_symbol(c, name);431 return trans_create_node_symbol(c, name);
432 }432 }
433 return nullptr;433 return nullptr;
std/buffer.zig-2
...@@ -5,8 +5,6 @@ const Allocator = mem.Allocator;...@@ -5,8 +5,6 @@ const Allocator = mem.Allocator;
5const assert = debug.assert;5const assert = debug.assert;
6const ArrayList = std.ArrayList;6const ArrayList = std.ArrayList;
77
8const fmt = std.fmt;
9
10/// A buffer that allocates memory and maintains a null byte at the end.8/// A buffer that allocates memory and maintains a null byte at the end.
11pub const Buffer = struct {9pub const Buffer = struct {
12 list: ArrayList(u8),10 list: ArrayList(u8),
std/crypto/sha1.zig-2
...@@ -4,8 +4,6 @@ const endian = @import("../endian.zig");...@@ -4,8 +4,6 @@ const endian = @import("../endian.zig");
4const debug = @import("../debug/index.zig");4const debug = @import("../debug/index.zig");
5const builtin = @import("builtin");5const builtin = @import("builtin");
66
7pub const u160 = @IntType(false, 160);
8
9const RoundParam = struct {7const RoundParam = struct {
10 a: usize,8 a: usize,
11 b: usize,9 b: usize,
std/json.zig-3
...@@ -6,9 +6,6 @@ const std = @import("index.zig");...@@ -6,9 +6,6 @@ const std = @import("index.zig");
6const debug = std.debug;6const debug = std.debug;
7const mem = std.mem;7const mem = std.mem;
88
9const u1 = @IntType(false, 1);
10const u256 = @IntType(false, 256);
11
12// A single token slice into the parent string.9// A single token slice into the parent string.
13//10//
14// Use `token.slice()` on the input at the current position to get the current slice.11// Use `token.slice()` on the input at the current position to get the current slice.
std/math/big/int.zig-1
...@@ -996,7 +996,6 @@ pub const Int = struct {...@@ -996,7 +996,6 @@ pub const Int = struct {
996// They will still run on larger than this and should pass, but the multi-limb code-paths996// They will still run on larger than this and should pass, but the multi-limb code-paths
997// may be untested in some cases.997// may be untested in some cases.
998998
999const u256 = @IntType(false, 256);
1000const al = debug.global_allocator;999const al = debug.global_allocator;
10011000
1002test "big.int comptime_int set" {1001test "big.int comptime_int set" {
std/math/exp2.zig+12-12
...@@ -75,18 +75,18 @@ fn exp2_32(x: f32) f32 {...@@ -75,18 +75,18 @@ fn exp2_32(x: f32) f32 {
75 }75 }
7676
77 var uf = x + redux;77 var uf = x + redux;
78 var i0 = @bitCast(u32, uf);78 var i_0 = @bitCast(u32, uf);
79 i0 += tblsiz / 2;79 i_0 += tblsiz / 2;
8080
81 const k = i0 / tblsiz;81 const k = i_0 / tblsiz;
82 // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the82 // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the
83 // intended result but should confirm how GCC/Clang handle this to ensure.83 // intended result but should confirm how GCC/Clang handle this to ensure.
84 const uk = @bitCast(f64, u64(0x3FF + k) << 52);84 const uk = @bitCast(f64, u64(0x3FF + k) << 52);
85 i0 &= tblsiz - 1;85 i_0 &= tblsiz - 1;
86 uf -= redux;86 uf -= redux;
8787
88 const z: f64 = x - uf;88 const z: f64 = x - uf;
89 var r: f64 = exp2ft[i0];89 var r: f64 = exp2ft[i_0];
90 const t: f64 = r * z;90 const t: f64 = r * z;
91 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);91 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
92 return @floatCast(f32, r * uk);92 return @floatCast(f32, r * uk);
...@@ -401,18 +401,18 @@ fn exp2_64(x: f64) f64 {...@@ -401,18 +401,18 @@ fn exp2_64(x: f64) f64 {
401 // reduce x401 // reduce x
402 var uf = x + redux;402 var uf = x + redux;
403 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here403 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here
404 var i0 = @truncate(u32, @bitCast(u64, uf));404 var i_0 = @truncate(u32, @bitCast(u64, uf));
405 i0 += tblsiz / 2;405 i_0 += tblsiz / 2;
406406
407 const k: u32 = i0 / tblsiz * tblsiz;407 const k: u32 = i_0 / tblsiz * tblsiz;
408 const ik = @bitCast(i32, k / tblsiz);408 const ik = @bitCast(i32, k / tblsiz);
409 i0 %= tblsiz;409 i_0 %= tblsiz;
410 uf -= redux;410 uf -= redux;
411411
412 // r = exp2(y) = exp2t[i0] * p(z - eps[i])412 // r = exp2(y) = exp2t[i_0] * p(z - eps[i])
413 var z = x - uf;413 var z = x - uf;
414 const t = exp2dt[2 * i0];414 const t = exp2dt[2 * i_0];
415 z -= exp2dt[2 * i0 + 1];415 z -= exp2dt[2 * i_0 + 1];
416 const r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));416 const r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
417417
418 return math.scalbn(r, ik);418 return math.scalbn(r, ik);
std/math/index.zig+1-1
...@@ -354,7 +354,7 @@ test "math.rotl" {...@@ -354,7 +354,7 @@ test "math.rotl" {
354354
355pub fn Log2Int(comptime T: type) type {355pub fn Log2Int(comptime T: type) type {
356 // comptime ceil log2356 // comptime ceil log2
357 comptime var count: usize = 0;357 comptime var count = 0;
358 comptime var s = T.bit_count - 1;358 comptime var s = T.bit_count - 1;
359 inline while (s != 0) : (s >>= 1) {359 inline while (s != 0) : (s >>= 1) {
360 count += 1;360 count += 1;
std/os/time.zig-1
...@@ -25,7 +25,6 @@ pub fn sleep(seconds: usize, nanoseconds: usize) void {...@@ -25,7 +25,6 @@ pub fn sleep(seconds: usize, nanoseconds: usize) void {
25 }25 }
26}26}
2727
28const u63 = @IntType(false, 63);
29pub fn posixSleep(seconds: u63, nanoseconds: u63) void {28pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
30 var req = posix.timespec{29 var req = posix.timespec{
31 .tv_sec = seconds,30 .tv_sec = seconds,
test/cases/misc.zig-5
...@@ -58,11 +58,6 @@ test "floating point primitive bit counts" {...@@ -58,11 +58,6 @@ test "floating point primitive bit counts" {
58 assert(f64.bit_count == 64);58 assert(f64.bit_count == 64);
59}59}
6060
61const u1 = @IntType(false, 1);
62const u63 = @IntType(false, 63);
63const i1 = @IntType(true, 1);
64const i63 = @IntType(true, 63);
65
66test "@minValue and @maxValue" {61test "@minValue and @maxValue" {
67 assert(@maxValue(u1) == 1);62 assert(@maxValue(u1) == 1);
68 assert(@maxValue(u8) == 255);63 assert(@maxValue(u8) == 255);
test/cases/struct.zig-1
...@@ -240,7 +240,6 @@ fn getC(data: *const BitField1) u2 {...@@ -240,7 +240,6 @@ fn getC(data: *const BitField1) u2 {
240 return data.c;240 return data.c;
241}241}
242242
243const u24 = @IntType(false, 24);
244const Foo24Bits = packed struct {243const Foo24Bits = packed struct {
245 field: u24,244 field: u24,
246};245};
test/compile_errors.zig+9
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "optional pointer to void in extern struct",
6 \\comptime {
7 \\ _ = @IntType(false, @maxValue(u32) + 1);
8 \\}
9 ,
10 ".tmp_source.zig:2:40: error: integer value 4294967296 cannot be implicitly casted to type 'u32'",
11 );
12
4 cases.add(13 cases.add(
5 "optional pointer to void in extern struct",14 "optional pointer to void in extern struct",
6 \\const Foo = extern struct {15 \\const Foo = extern struct {