authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-06 23:25:57-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-08 15:57:24-05:00
loge0db54e89d6f4e9f56800ddb1017e30be1b7d58a
tree5a5a88dcebf349bf92da9ba2be9e8de63dc3ab81
parent2a6fbbd8fba30b8d24aa966606372f595c102d55
signaturelock-open Commit is signed but in an unrecognized format.

update the codebase to use `@as`


206 files changed, 1287 insertions(+), 1282 deletions(-)

build.zig+1-1
...@@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
155 ) catch unreachable;155 ) catch unreachable;
156 for (dep.system_libs.toSliceConst()) |lib| {156 for (dep.system_libs.toSliceConst()) |lib| {
157 const static_bare_name = if (mem.eql(u8, lib, "curses"))157 const static_bare_name = if (mem.eql(u8, lib, "curses"))
158 ([]const u8)("libncurses.a")158 @as([]const u8,"libncurses.a")
159 else159 else
160 b.fmt("lib{}.a", lib);160 b.fmt("lib{}.a", lib);
161 const static_lib_name = fs.path.join(161 const static_lib_name = fs.path.join(
lib/std/array_list.zig+8-8
...@@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" {...@@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" {
344 try list.append(7);344 try list.append(7);
345345
346 //remove from middle346 //remove from middle
347 testing.expectEqual(i32(4), list.orderedRemove(3));347 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
348 testing.expectEqual(i32(5), list.at(3));348 testing.expectEqual(@as(i32, 5), list.at(3));
349 testing.expectEqual(usize(6), list.len);349 testing.expectEqual(@as(usize, 6), list.len);
350350
351 //remove from end351 //remove from end
352 testing.expectEqual(i32(7), list.orderedRemove(5));352 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
353 testing.expectEqual(usize(5), list.len);353 testing.expectEqual(@as(usize, 5), list.len);
354354
355 //remove from front355 //remove from front
356 testing.expectEqual(i32(1), list.orderedRemove(0));356 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
357 testing.expectEqual(i32(2), list.at(0));357 testing.expectEqual(@as(i32, 2), list.at(0));
358 testing.expectEqual(usize(4), list.len);358 testing.expectEqual(@as(usize, 4), list.len);
359}359}
360360
361test "std.ArrayList.swapRemove" {361test "std.ArrayList.swapRemove" {
lib/std/ascii.zig+11-11
...@@ -129,26 +129,26 @@ const combinedTable = init: {...@@ -129,26 +129,26 @@ const combinedTable = init: {
129 comptime var i = 0;129 comptime var i = 0;
130 inline while (i < 128) : (i += 1) {130 inline while (i < 128) : (i += 1) {
131 table[i] =131 table[i] =
132 u8(alpha[i]) << @enumToInt(tIndex.Alpha) |132 @as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) |
133 u8(hex[i]) << @enumToInt(tIndex.Hex) |133 @as(u8, hex[i]) << @enumToInt(tIndex.Hex) |
134 u8(space[i]) << @enumToInt(tIndex.Space) |134 @as(u8, space[i]) << @enumToInt(tIndex.Space) |
135 u8(digit[i]) << @enumToInt(tIndex.Digit) |135 @as(u8, digit[i]) << @enumToInt(tIndex.Digit) |
136 u8(lower[i]) << @enumToInt(tIndex.Lower) |136 @as(u8, lower[i]) << @enumToInt(tIndex.Lower) |
137 u8(upper[i]) << @enumToInt(tIndex.Upper) |137 @as(u8, upper[i]) << @enumToInt(tIndex.Upper) |
138 u8(punct[i]) << @enumToInt(tIndex.Punct) |138 @as(u8, punct[i]) << @enumToInt(tIndex.Punct) |
139 u8(graph[i]) << @enumToInt(tIndex.Graph);139 @as(u8, graph[i]) << @enumToInt(tIndex.Graph);
140 }140 }
141 mem.set(u8, table[128..256], 0);141 mem.set(u8, table[128..256], 0);
142 break :init table;142 break :init table;
143};143};
144144
145fn inTable(c: u8, t: tIndex) bool {145fn inTable(c: u8, t: tIndex) bool {
146 return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0;146 return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
147}147}
148148
149pub fn isAlNum(c: u8) bool {149pub fn isAlNum(c: u8) bool {
150 return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) |150 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
151 u8(1) << @enumToInt(tIndex.Digit))) != 0;151 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
152}152}
153153
154pub fn isAlpha(c: u8) bool {154pub fn isAlpha(c: u8) bool {
lib/std/atomic/queue.zig+2-2
...@@ -214,8 +214,8 @@ test "std.atomic.Queue" {...@@ -214,8 +214,8 @@ test "std.atomic.Queue" {
214 std.debug.panic(214 std.debug.panic(
215 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",215 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
216 context.get_count,216 context.get_count,
217 u32(puts_per_thread),217 @as(u32, puts_per_thread),
218 u32(put_thread_count),218 @as(u32, put_thread_count),
219 );219 );
220 }220 }
221}221}
lib/std/atomic/stack.zig+3-3
...@@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type {...@@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type {
11 root: ?*Node,11 root: ?*Node,
12 lock: @typeOf(lock_init),12 lock: @typeOf(lock_init),
1313
14 const lock_init = if (builtin.single_threaded) {} else u8(0);14 const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);
1515
16 pub const Self = @This();16 pub const Self = @This();
1717
...@@ -141,8 +141,8 @@ test "std.atomic.stack" {...@@ -141,8 +141,8 @@ test "std.atomic.stack" {
141 std.debug.panic(141 std.debug.panic(
142 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",142 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
143 context.get_count,143 context.get_count,
144 u32(puts_per_thread),144 @as(u32, puts_per_thread),
145 u32(put_thread_count),145 @as(u32, put_thread_count),
146 );146 );
147 }147 }
148}148}
lib/std/bloom_filter.zig+3-3
...@@ -171,7 +171,7 @@ test "std.BloomFilter" {...@@ -171,7 +171,7 @@ test "std.BloomFilter" {
171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
172 }172 }
173 testing.expectEqual(BF.Index(0), bf.popCount());173 testing.expectEqual(BF.Index(0), bf.popCount());
174 testing.expectEqual(f64(0), bf.estimateItems());174 testing.expectEqual(@as(f64, 0), bf.estimateItems());
175 // fill in a few items175 // fill in a few items
176 bf.incrementCell(42);176 bf.incrementCell(42);
177 bf.incrementCell(255);177 bf.incrementCell(255);
...@@ -197,7 +197,7 @@ test "std.BloomFilter" {...@@ -197,7 +197,7 @@ test "std.BloomFilter" {
197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
198 }198 }
199 testing.expectEqual(BF.Index(0), bf.popCount());199 testing.expectEqual(BF.Index(0), bf.popCount());
200 testing.expectEqual(f64(0), bf.estimateItems());200 testing.expectEqual(@as(f64, 0), bf.estimateItems());
201201
202 // Lets add a string202 // Lets add a string
203 bf.add("foo");203 bf.add("foo");
...@@ -219,7 +219,7 @@ test "std.BloomFilter" {...@@ -219,7 +219,7 @@ test "std.BloomFilter" {
219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
220 }220 }
221 testing.expectEqual(BF.Index(0), bf.popCount());221 testing.expectEqual(BF.Index(0), bf.popCount());
222 testing.expectEqual(f64(0), bf.estimateItems());222 testing.expectEqual(@as(f64, 0), bf.estimateItems());
223223
224 comptime var teststrings = [_][]const u8{224 comptime var teststrings = [_][]const u8{
225 "foo",225 "foo",
lib/std/c/darwin.zig+1-1
...@@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo...@@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo
53pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;53pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
5454
55pub fn sigaddset(set: *sigset_t, signo: u5) void {55pub fn sigaddset(set: *sigset_t, signo: u5) void {
56 set.* |= u32(1) << (signo - 1);56 set.* |= @as(u32, 1) << (signo - 1);
57}57}
5858
59pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;59pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
lib/std/child_process.zig+1-1
...@@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void {...@@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void {
717// Child of fork calls this to report an error to the fork parent.717// Child of fork calls this to report an error to the fork parent.
718// Then the child exits.718// Then the child exits.
719fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {719fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
720 writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};720 writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {};
721 os.exit(1);721 os.exit(1);
722}722}
723723
lib/std/crypto/aes.zig+10-10
...@@ -6,7 +6,7 @@ const testing = std.testing;...@@ -6,7 +6,7 @@ const testing = std.testing;
66
7// Apply sbox0 to each byte in w.7// Apply sbox0 to each byte in w.
8fn subw(w: u32) u32 {8fn subw(w: u32) u32 {
9 return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]);9 return @as(u32, sbox0[w >> 24]) << 24 | @as(u32, sbox0[w >> 16 & 0xff]) << 16 | @as(u32, sbox0[w >> 8 & 0xff]) << 8 | @as(u32, sbox0[w & 0xff]);
10}10}
1111
12fn rotw(w: u32) u32 {12fn rotw(w: u32) u32 {
...@@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {...@@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
48 }48 }
4949
50 // Last round uses s-box directly and XORs to produce output.50 // Last round uses s-box directly and XORs to produce output.
51 s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]);51 s0 = @as(u32, sbox0[t0 >> 24]) << 24 | @as(u32, sbox0[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t3 & 0xff]);
52 s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | u32(sbox0[t0 & 0xff]);52 s1 = @as(u32, sbox0[t1 >> 24]) << 24 | @as(u32, sbox0[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t0 & 0xff]);
53 s2 = u32(sbox0[t2 >> 24]) << 24 | u32(sbox0[t3 >> 16 & 0xff]) << 16 | u32(sbox0[t0 >> 8 & 0xff]) << 8 | u32(sbox0[t1 & 0xff]);53 s2 = @as(u32, sbox0[t2 >> 24]) << 24 | @as(u32, sbox0[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t1 & 0xff]);
54 s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 0xff]);54 s3 = @as(u32, sbox0[t3 >> 24]) << 24 | @as(u32, sbox0[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t2 & 0xff]);
5555
56 s0 ^= xk[k + 0];56 s0 ^= xk[k + 0];
57 s1 ^= xk[k + 1];57 s1 ^= xk[k + 1];
...@@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {...@@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
99 }99 }
100100
101 // Last round uses s-box directly and XORs to produce output.101 // Last round uses s-box directly and XORs to produce output.
102 s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]);102 s0 = @as(u32, sbox1[t0 >> 24]) << 24 | @as(u32, sbox1[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t1 & 0xff]);
103 s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | u32(sbox1[t2 & 0xff]);103 s1 = @as(u32, sbox1[t1 >> 24]) << 24 | @as(u32, sbox1[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t2 & 0xff]);
104 s2 = u32(sbox1[t2 >> 24]) << 24 | u32(sbox1[t1 >> 16 & 0xff]) << 16 | u32(sbox1[t0 >> 8 & 0xff]) << 8 | u32(sbox1[t3 & 0xff]);104 s2 = @as(u32, sbox1[t2 >> 24]) << 24 | @as(u32, sbox1[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t3 & 0xff]);
105 s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 0xff]);105 s3 = @as(u32, sbox1[t3 >> 24]) << 24 | @as(u32, sbox1[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t0 & 0xff]);
106106
107 s0 ^= xk[k + 0];107 s0 ^= xk[k + 0];
108 s1 ^= xk[k + 1];108 s1 ^= xk[k + 1];
...@@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void {...@@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void {
256 while (i < enc.len) : (i += 1) {256 while (i < enc.len) : (i += 1) {
257 var t = enc[i - 1];257 var t = enc[i - 1];
258 if (i % nk == 0) {258 if (i % nk == 0) {
259 t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24);259 t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24);
260 } else if (nk > 6 and i % nk == 4) {260 } else if (nk > 6 and i % nk == 4) {
261 t = subw(t);261 t = subw(t);
262 }262 }
lib/std/crypto/blake2.zig+8-8
...@@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type {...@@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type {
164 inline while (j < 10) : (j += 1) {164 inline while (j < 10) : (j += 1) {
165 inline for (rounds) |r| {165 inline for (rounds) |r| {
166 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];166 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
167 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16));167 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16));
168 v[r.c] = v[r.c] +% v[r.d];168 v[r.c] = v[r.c] +% v[r.d];
169 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12));169 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12));
170 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];170 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
171 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8));171 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8));
172 v[r.c] = v[r.c] +% v[r.d];172 v[r.c] = v[r.c] +% v[r.d];
173 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7));173 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7));
174 }174 }
175 }175 }
176176
...@@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type {...@@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type {
398 inline while (j < 12) : (j += 1) {398 inline while (j < 12) : (j += 1) {
399 inline for (rounds) |r| {399 inline for (rounds) |r| {
400 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];400 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
401 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32));401 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32));
402 v[r.c] = v[r.c] +% v[r.d];402 v[r.c] = v[r.c] +% v[r.d];
403 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24));403 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24));
404 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];404 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
405 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16));405 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16));
406 v[r.c] = v[r.c] +% v[r.d];406 v[r.c] = v[r.c] +% v[r.d];
407 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63));407 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63));
408 }408 }
409 }409 }
410410
lib/std/crypto/chacha20.zig+4-4
...@@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {...@@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {
49 // two-round cycles49 // two-round cycles
50 inline for (rounds) |r| {50 inline for (rounds) |r| {
51 x[r.a] +%= x[r.b];51 x[r.a] +%= x[r.b];
52 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(16));52 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 16));
53 x[r.c] +%= x[r.d];53 x[r.c] +%= x[r.d];
54 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(12));54 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 12));
55 x[r.a] +%= x[r.b];55 x[r.a] +%= x[r.b];
56 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(8));56 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 8));
57 x[r.c] +%= x[r.d];57 x[r.c] +%= x[r.d];
58 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(7));58 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 7));
59 }59 }
60 }60 }
6161
lib/std/crypto/gimli.zig+4-4
...@@ -34,9 +34,9 @@ pub const State = struct {...@@ -34,9 +34,9 @@ pub const State = struct {
3434
35 pub fn permute(self: *Self) void {35 pub fn permute(self: *Self) void {
36 const state = &self.data;36 const state = &self.data;
37 var round = u32(24);37 var round = @as(u32, 24);
38 while (round > 0) : (round -= 1) {38 while (round > 0) : (round -= 1) {
39 var column = usize(0);39 var column = @as(usize, 0);
40 while (column < 4) : (column += 1) {40 while (column < 4) : (column += 1) {
41 const x = math.rotl(u32, state[column], 24);41 const x = math.rotl(u32, state[column], 24);
42 const y = math.rotl(u32, state[4 + column], 9);42 const y = math.rotl(u32, state[4 + column], 9);
...@@ -61,7 +61,7 @@ pub const State = struct {...@@ -61,7 +61,7 @@ pub const State = struct {
61 }61 }
6262
63 pub fn squeeze(self: *Self, out: []u8) void {63 pub fn squeeze(self: *Self, out: []u8) void {
64 var i = usize(0);64 var i = @as(usize, 0);
65 while (i + RATE <= out.len) : (i += RATE) {65 while (i + RATE <= out.len) : (i += RATE) {
66 self.permute();66 self.permute();
67 mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]);67 mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]);
...@@ -79,7 +79,7 @@ test "permute" {...@@ -79,7 +79,7 @@ test "permute" {
79 var state = State{79 var state = State{
80 .data = blk: {80 .data = blk: {
81 var input: [12]u32 = undefined;81 var input: [12]u32 = undefined;
82 var i = u32(0);82 var i = @as(u32, 0);
83 while (i < 12) : (i += 1) {83 while (i < 12) : (i += 1) {
84 input[i] = i * i * i + i *% 0x9e3779b9;84 input[i] = i * i * i + i *% 0x9e3779b9;
85 }85 }
lib/std/crypto/md5.zig+4-4
...@@ -126,10 +126,10 @@ pub const Md5 = struct {...@@ -126,10 +126,10 @@ pub const Md5 = struct {
126 while (i < 16) : (i += 1) {126 while (i < 16) : (i += 1) {
127 // NOTE: Performing or's separately improves perf by ~10%127 // NOTE: Performing or's separately improves perf by ~10%
128 s[i] = 0;128 s[i] = 0;
129 s[i] |= u32(b[i * 4 + 0]);129 s[i] |= @as(u32, b[i * 4 + 0]);
130 s[i] |= u32(b[i * 4 + 1]) << 8;130 s[i] |= @as(u32, b[i * 4 + 1]) << 8;
131 s[i] |= u32(b[i * 4 + 2]) << 16;131 s[i] |= @as(u32, b[i * 4 + 2]) << 16;
132 s[i] |= u32(b[i * 4 + 3]) << 24;132 s[i] |= @as(u32, b[i * 4 + 3]) << 24;
133 }133 }
134134
135 var v: [4]u32 = [_]u32{135 var v: [4]u32 = [_]u32{
lib/std/crypto/poly1305.zig+6-6
...@@ -87,11 +87,11 @@ pub const Poly1305 = struct {...@@ -87,11 +87,11 @@ pub const Poly1305 = struct {
87 // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff87 // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff
88 fn polyBlock(ctx: *Self) void {88 fn polyBlock(ctx: *Self) void {
89 // s = h + c, without carry propagation89 // s = h + c, without carry propagation
90 const s0 = u64(ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe90 const s0 = @as(u64, ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
91 const s1 = u64(ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe91 const s1 = @as(u64, ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
92 const s2 = u64(ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe92 const s2 = @as(u64, ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
93 const s3 = u64(ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe93 const s3 = @as(u64, ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
94 const s4 = u64(ctx.h[4]) + ctx.c[4]; // s4 <= 594 const s4 = @as(u64, ctx.h[4]) + ctx.c[4]; // s4 <= 5
9595
96 // Local all the things!96 // Local all the things!
97 const r0 = ctx.r[0]; // r0 <= 0fffffff97 const r0 = ctx.r[0]; // r0 <= 0fffffff
...@@ -197,7 +197,7 @@ pub const Poly1305 = struct {...@@ -197,7 +197,7 @@ pub const Poly1305 = struct {
197197
198 // check if we should subtract 2^130-5 by performing the198 // check if we should subtract 2^130-5 by performing the
199 // corresponding carry propagation.199 // corresponding carry propagation.
200 const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004200 const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004
201 const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000201 const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000
202 const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000202 const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000
203 const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000203 const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000
lib/std/crypto/sha1.zig+15-15
...@@ -146,10 +146,10 @@ pub const Sha1 = struct {...@@ -146,10 +146,10 @@ pub const Sha1 = struct {
146 Rp(0, 1, 2, 3, 4, 15),146 Rp(0, 1, 2, 3, 4, 15),
147 };147 };
148 inline for (round0a) |r| {148 inline for (round0a) |r| {
149 s[r.i] = (u32(b[r.i * 4 + 0]) << 24) | (u32(b[r.i * 4 + 1]) << 16) | (u32(b[r.i * 4 + 2]) << 8) | (u32(b[r.i * 4 + 3]) << 0);149 s[r.i] = (@as(u32, b[r.i * 4 + 0]) << 24) | (@as(u32, b[r.i * 4 + 1]) << 16) | (@as(u32, b[r.i * 4 + 2]) << 8) | (@as(u32, b[r.i * 4 + 3]) << 0);
150150
151 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));151 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));
152 v[r.b] = math.rotl(u32, v[r.b], u32(30));152 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
153 }153 }
154154
155 const round0b = comptime [_]RoundParam{155 const round0b = comptime [_]RoundParam{
...@@ -160,10 +160,10 @@ pub const Sha1 = struct {...@@ -160,10 +160,10 @@ pub const Sha1 = struct {
160 };160 };
161 inline for (round0b) |r| {161 inline for (round0b) |r| {
162 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];162 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
163 s[r.i & 0xf] = math.rotl(u32, t, u32(1));163 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
164164
165 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));165 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d]));
166 v[r.b] = math.rotl(u32, v[r.b], u32(30));166 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
167 }167 }
168168
169 const round1 = comptime [_]RoundParam{169 const round1 = comptime [_]RoundParam{
...@@ -190,10 +190,10 @@ pub const Sha1 = struct {...@@ -190,10 +190,10 @@ pub const Sha1 = struct {
190 };190 };
191 inline for (round1) |r| {191 inline for (round1) |r| {
192 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];192 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
193 s[r.i & 0xf] = math.rotl(u32, t, u32(1));193 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
194194
195 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]);195 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]);
196 v[r.b] = math.rotl(u32, v[r.b], u32(30));196 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
197 }197 }
198198
199 const round2 = comptime [_]RoundParam{199 const round2 = comptime [_]RoundParam{
...@@ -220,10 +220,10 @@ pub const Sha1 = struct {...@@ -220,10 +220,10 @@ pub const Sha1 = struct {
220 };220 };
221 inline for (round2) |r| {221 inline for (round2) |r| {
222 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];222 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
223 s[r.i & 0xf] = math.rotl(u32, t, u32(1));223 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
224224
225 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d]));225 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d]));
226 v[r.b] = math.rotl(u32, v[r.b], u32(30));226 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
227 }227 }
228228
229 const round3 = comptime [_]RoundParam{229 const round3 = comptime [_]RoundParam{
...@@ -250,10 +250,10 @@ pub const Sha1 = struct {...@@ -250,10 +250,10 @@ pub const Sha1 = struct {
250 };250 };
251 inline for (round3) |r| {251 inline for (round3) |r| {
252 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];252 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
253 s[r.i & 0xf] = math.rotl(u32, t, u32(1));253 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
254254
255 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]);255 v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]);
256 v[r.b] = math.rotl(u32, v[r.b], u32(30));256 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
257 }257 }
258258
259 d.s[0] +%= v[0];259 d.s[0] +%= v[0];
lib/std/crypto/sha2.zig+20-18
...@@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type {
180 var i: usize = 0;180 var i: usize = 0;
181 while (i < 16) : (i += 1) {181 while (i < 16) : (i += 1) {
182 s[i] = 0;182 s[i] = 0;
183 s[i] |= u32(b[i * 4 + 0]) << 24;183 s[i] |= @as(u32, b[i * 4 + 0]) << 24;
184 s[i] |= u32(b[i * 4 + 1]) << 16;184 s[i] |= @as(u32, b[i * 4 + 1]) << 16;
185 s[i] |= u32(b[i * 4 + 2]) << 8;185 s[i] |= @as(u32, b[i * 4 + 2]) << 8;
186 s[i] |= u32(b[i * 4 + 3]) << 0;186 s[i] |= @as(u32, b[i * 4 + 3]) << 0;
187 }187 }
188 while (i < 64) : (i += 1) {188 while (i < 64) : (i += 1) {
189 s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10));189 s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], @as(u32, 7)) ^ math.rotr(u32, s[i - 15], @as(u32, 18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], @as(u32, 17)) ^ math.rotr(u32, s[i - 2], @as(u32, 19)) ^ (s[i - 2] >> 10));
190 }190 }
191191
192 var v: [8]u32 = [_]u32{192 var v: [8]u32 = [_]u32{
...@@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type {
267 Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2),267 Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2),
268 };268 };
269 inline for (round0) |r| {269 inline for (round0) |r| {
270 v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], u32(6)) ^ math.rotr(u32, v[r.e], u32(11)) ^ math.rotr(u32, v[r.e], u32(25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i];270 v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], @as(u32, 6)) ^ math.rotr(u32, v[r.e], @as(u32, 11)) ^ math.rotr(u32, v[r.e], @as(u32, 25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i];
271271
272 v[r.d] = v[r.d] +% v[r.h];272 v[r.d] = v[r.d] +% v[r.h];
273273
274 v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], u32(2)) ^ math.rotr(u32, v[r.a], u32(13)) ^ math.rotr(u32, v[r.a], u32(22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));274 v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], @as(u32, 2)) ^ math.rotr(u32, v[r.a], @as(u32, 13)) ^ math.rotr(u32, v[r.a], @as(u32, 22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));
275 }275 }
276276
277 d.s[0] +%= v[0];277 d.s[0] +%= v[0];
...@@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type {
522 var i: usize = 0;522 var i: usize = 0;
523 while (i < 16) : (i += 1) {523 while (i < 16) : (i += 1) {
524 s[i] = 0;524 s[i] = 0;
525 s[i] |= u64(b[i * 8 + 0]) << 56;525 s[i] |= @as(u64, b[i * 8 + 0]) << 56;
526 s[i] |= u64(b[i * 8 + 1]) << 48;526 s[i] |= @as(u64, b[i * 8 + 1]) << 48;
527 s[i] |= u64(b[i * 8 + 2]) << 40;527 s[i] |= @as(u64, b[i * 8 + 2]) << 40;
528 s[i] |= u64(b[i * 8 + 3]) << 32;528 s[i] |= @as(u64, b[i * 8 + 3]) << 32;
529 s[i] |= u64(b[i * 8 + 4]) << 24;529 s[i] |= @as(u64, b[i * 8 + 4]) << 24;
530 s[i] |= u64(b[i * 8 + 5]) << 16;530 s[i] |= @as(u64, b[i * 8 + 5]) << 16;
531 s[i] |= u64(b[i * 8 + 6]) << 8;531 s[i] |= @as(u64, b[i * 8 + 6]) << 8;
532 s[i] |= u64(b[i * 8 + 7]) << 0;532 s[i] |= @as(u64, b[i * 8 + 7]) << 0;
533 }533 }
534 while (i < 80) : (i += 1) {534 while (i < 80) : (i += 1) {
535 s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6));535 s[i] = s[i - 16] +% s[i - 7] +%
536 (math.rotr(u64, s[i - 15], @as(u64, 1)) ^ math.rotr(u64, s[i - 15], @as(u64, 8)) ^ (s[i - 15] >> 7)) +%
537 (math.rotr(u64, s[i - 2], @as(u64, 19)) ^ math.rotr(u64, s[i - 2], @as(u64, 61)) ^ (s[i - 2] >> 6));
536 }538 }
537539
538 var v: [8]u64 = [_]u64{540 var v: [8]u64 = [_]u64{
...@@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type {
629 Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817),631 Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817),
630 };632 };
631 inline for (round0) |r| {633 inline for (round0) |r| {
632 v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], u64(14)) ^ math.rotr(u64, v[r.e], u64(18)) ^ math.rotr(u64, v[r.e], u64(41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i];634 v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], @as(u64, 14)) ^ math.rotr(u64, v[r.e], @as(u64, 18)) ^ math.rotr(u64, v[r.e], @as(u64, 41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i];
633635
634 v[r.d] = v[r.d] +% v[r.h];636 v[r.d] = v[r.d] +% v[r.h];
635637
636 v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], u64(28)) ^ math.rotr(u64, v[r.a], u64(34)) ^ math.rotr(u64, v[r.a], u64(39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));638 v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], @as(u64, 28)) ^ math.rotr(u64, v[r.a], @as(u64, 34)) ^ math.rotr(u64, v[r.a], @as(u64, 39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c]));
637 }639 }
638640
639 d.s[0] +%= v[0];641 d.s[0] +%= v[0];
lib/std/crypto/sha3.zig+1-1
...@@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {...@@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
133 }133 }
134 x = 0;134 x = 0;
135 inline while (x < 5) : (x += 1) {135 inline while (x < 5) : (x += 1) {
136 t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], usize(1));136 t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], @as(usize, 1));
137 y = 0;137 y = 0;
138 inline while (y < 5) : (y += 1) {138 inline while (y < 5) : (y += 1) {
139 s[x + y * 5] ^= t[0];139 s[x + y * 5] ^= t[0];
lib/std/crypto/x25519.zig+10-10
...@@ -256,15 +256,15 @@ const Fe = struct {...@@ -256,15 +256,15 @@ const Fe = struct {
256 var t: [10]i64 = undefined;256 var t: [10]i64 = undefined;
257257
258 t[0] = readIntSliceLittle(u32, s[0..4]);258 t[0] = readIntSliceLittle(u32, s[0..4]);
259 t[1] = u32(readIntSliceLittle(u24, s[4..7])) << 6;259 t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6;
260 t[2] = u32(readIntSliceLittle(u24, s[7..10])) << 5;260 t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5;
261 t[3] = u32(readIntSliceLittle(u24, s[10..13])) << 3;261 t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3;
262 t[4] = u32(readIntSliceLittle(u24, s[13..16])) << 2;262 t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2;
263 t[5] = readIntSliceLittle(u32, s[16..20]);263 t[5] = readIntSliceLittle(u32, s[16..20]);
264 t[6] = u32(readIntSliceLittle(u24, s[20..23])) << 7;264 t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7;
265 t[7] = u32(readIntSliceLittle(u24, s[23..26])) << 5;265 t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5;
266 t[8] = u32(readIntSliceLittle(u24, s[26..29])) << 4;266 t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4;
267 t[9] = (u32(readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;267 t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
268268
269 carry1(h, t[0..]);269 carry1(h, t[0..]);
270 }270 }
...@@ -500,7 +500,7 @@ const Fe = struct {...@@ -500,7 +500,7 @@ const Fe = struct {
500 if (i + 1 < 10) {500 if (i + 1 < 10) {
501 t[i + 1] += c[i];501 t[i + 1] += c[i];
502 }502 }
503 t[i] -= c[i] * (i32(1) << shift);503 t[i] -= c[i] * (@as(i32, 1) << shift);
504 }504 }
505505
506 fn toBytes(s: []u8, h: *const Fe) void {506 fn toBytes(s: []u8, h: *const Fe) void {
...@@ -511,7 +511,7 @@ const Fe = struct {...@@ -511,7 +511,7 @@ const Fe = struct {
511 t[i] = h.b[i];511 t[i] = h.b[i];
512 }512 }
513513
514 var q = (19 * t[9] + ((i32(1) << 24))) >> 25;514 var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25;
515 {515 {
516 var i: usize = 0;516 var i: usize = 0;
517 while (i < 5) : (i += 1) {517 while (i < 5) : (i += 1) {
lib/std/debug.zig+13-10
...@@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {...@@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
1008 const word = try stream.readIntLittle(u32);1008 const word = try stream.readIntLittle(u32);
1009 var bit_i: u5 = 0;1009 var bit_i: u5 = 0;
1010 while (true) : (bit_i += 1) {1010 while (true) : (bit_i += 1) {
1011 if (word & (u32(1) << bit_i) != 0) {1011 if (word & (@as(u32, 1) << bit_i) != 0) {
1012 try list.append(word_i * 32 + bit_i);1012 try list.append(word_i * 32 + bit_i);
1013 }1013 }
1014 if (bit_i == maxInt(u5)) break;1014 if (bit_i == maxInt(u5)) break;
...@@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo...@@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
15561556
1557// TODO the noasyncs here are workarounds1557// TODO the noasyncs here are workarounds
1558fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 {1558fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 {
1559 return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32));1559 return if (is_64) try noasync in_stream.readIntLittle(u64) else @as(u64, try noasync in_stream.readIntLittle(u32));
1560}1560}
15611561
1562// TODO the noasyncs here are workarounds1562// TODO the noasyncs here are workarounds
1563fn parseFormValueTargetAddrSize(in_stream: var) !u64 {1563fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
1564 if (@sizeOf(usize) == 4) {1564 if (@sizeOf(usize) == 4) {
1565 return u64(try noasync in_stream.readIntLittle(u32));1565 // TODO this cast should not be needed
1566 return @as(u64, try noasync in_stream.readIntLittle(u32));
1566 } else if (@sizeOf(usize) == 8) {1567 } else if (@sizeOf(usize) == 8) {
1567 return noasync in_stream.readIntLittle(u64);1568 return noasync in_stream.readIntLittle(u64);
1568 } else {1569 } else {
...@@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u...@@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
1846 // special opcodes1847 // special opcodes
1847 const adjusted_opcode = opcode - opcode_base;1848 const adjusted_opcode = opcode - opcode_base;
1848 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);1849 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
1849 const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);1850 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
1850 prog.line += inc_line;1851 prog.line += inc_line;
1851 prog.address += inc_addr;1852 prog.address += inc_addr;
1852 if (try prog.checkLineMatch()) |info| return info;1853 if (try prog.checkLineMatch()) |info| return info;
...@@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr...@@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
1913 if (unit_length == 0) {1914 if (unit_length == 0) {
1914 return error.MissingDebugInfo;1915 return error.MissingDebugInfo;
1915 }1916 }
1916 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));1917 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
19171918
1918 const version = try di.dwarf_in_stream.readInt(u16, di.endian);1919 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
1919 // TODO support 3 and 51920 // TODO support 3 and 5
...@@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr...@@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
2012 // special opcodes2013 // special opcodes
2013 const adjusted_opcode = opcode - opcode_base;2014 const adjusted_opcode = opcode - opcode_base;
2014 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);2015 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
2015 const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);2016 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
2016 prog.line += inc_line;2017 prog.line += inc_line;
2017 prog.address += inc_addr;2018 prog.address += inc_addr;
2018 if (try prog.checkLineMatch()) |info| return info;2019 if (try prog.checkLineMatch()) |info| return info;
...@@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {...@@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {
2093 var is_64: bool = undefined;2094 var is_64: bool = undefined;
2094 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);2095 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
2095 if (unit_length == 0) return;2096 if (unit_length == 0) return;
2096 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));2097 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
20972098
2098 const version = try di.dwarf_in_stream.readInt(u16, di.endian);2099 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
2099 if (version < 2 or version > 5) return error.InvalidDebugInfo;2100 if (version < 2 or version > 5) return error.InvalidDebugInfo;
...@@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void {...@@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void {
2195 var is_64: bool = undefined;2196 var is_64: bool = undefined;
2196 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);2197 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
2197 if (unit_length == 0) return;2198 if (unit_length == 0) return;
2198 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));2199 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
21992200
2200 const version = try di.dwarf_in_stream.readInt(u16, di.endian);2201 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
2201 if (version < 2 or version > 5) return error.InvalidDebugInfo;2202 if (version < 2 or version > 5) return error.InvalidDebugInfo;
...@@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {...@@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {
2312 } else {2313 } else {
2313 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;2314 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
2314 ptr.* += 4;2315 ptr.* += 4;
2315 return u64(first_32_bits);2316 // TODO this cast should not be needed
2317 return @as(u64, first_32_bits);
2316 }2318 }
2317}2319}
23182320
...@@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool)...@@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool)
2329 return in_stream.readIntLittle(u64);2331 return in_stream.readIntLittle(u64);
2330 } else {2332 } else {
2331 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;2333 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
2332 return u64(first_32_bits);2334 // TODO this cast should not be needed
2335 return @as(u64, first_32_bits);
2333 }2336 }
2334}2337}
23352338
lib/std/debug/leb128.zig+2-2
...@@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {...@@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
62 var shift: usize = 0;62 var shift: usize = 0;
6363
64 while (true) {64 while (true) {
65 const byte = u8(try in_stream.readByte());65 const byte: u8 = try in_stream.readByte();
6666
67 if (shift > T.bit_count)67 if (shift > T.bit_count)
68 return error.Overflow;68 return error.Overflow;
6969
70 var operand: UT = undefined;70 var operand: UT = undefined;
71 if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) {71 if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
72 if (byte != 0x7f)72 if (byte != 0x7f)
73 return error.Overflow;73 return error.Overflow;
74 }74 }
lib/std/dynamic_library.zig+2-2
...@@ -215,8 +215,8 @@ pub const ElfLib = struct {...@@ -215,8 +215,8 @@ pub const ElfLib = struct {
215215
216 var i: usize = 0;216 var i: usize = 0;
217 while (i < self.hashtab[1]) : (i += 1) {217 while (i < self.hashtab[1]) : (i += 1) {
218 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;218 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
219 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;219 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
220 if (0 == self.syms[i].st_shndx) continue;220 if (0 == self.syms[i].st_shndx) continue;
221 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;221 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
222 if (maybe_versym) |versym| {222 if (maybe_versym) |versym| {
lib/std/elf.zig+12-12
...@@ -441,9 +441,9 @@ pub const Elf = struct {...@@ -441,9 +441,9 @@ pub const Elf = struct {
441 elf.program_header_offset = try in.readInt(u64, elf.endian);441 elf.program_header_offset = try in.readInt(u64, elf.endian);
442 elf.section_header_offset = try in.readInt(u64, elf.endian);442 elf.section_header_offset = try in.readInt(u64, elf.endian);
443 } else {443 } else {
444 elf.entry_addr = u64(try in.readInt(u32, elf.endian));444 elf.entry_addr = @as(u64, try in.readInt(u32, elf.endian));
445 elf.program_header_offset = u64(try in.readInt(u32, elf.endian));445 elf.program_header_offset = @as(u64, try in.readInt(u32, elf.endian));
446 elf.section_header_offset = u64(try in.readInt(u32, elf.endian));446 elf.section_header_offset = @as(u64, try in.readInt(u32, elf.endian));
447 }447 }
448448
449 // skip over flags449 // skip over flags
...@@ -458,13 +458,13 @@ pub const Elf = struct {...@@ -458,13 +458,13 @@ pub const Elf = struct {
458 const ph_entry_count = try in.readInt(u16, elf.endian);458 const ph_entry_count = try in.readInt(u16, elf.endian);
459 const sh_entry_size = try in.readInt(u16, elf.endian);459 const sh_entry_size = try in.readInt(u16, elf.endian);
460 const sh_entry_count = try in.readInt(u16, elf.endian);460 const sh_entry_count = try in.readInt(u16, elf.endian);
461 elf.string_section_index = usize(try in.readInt(u16, elf.endian));461 elf.string_section_index = @as(usize, try in.readInt(u16, elf.endian));
462462
463 if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat;463 if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat;
464464
465 const sh_byte_count = u64(sh_entry_size) * u64(sh_entry_count);465 const sh_byte_count = @as(u64, sh_entry_size) * @as(u64, sh_entry_count);
466 const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count);466 const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count);
467 const ph_byte_count = u64(ph_entry_size) * u64(ph_entry_count);467 const ph_byte_count = @as(u64, ph_entry_size) * @as(u64, ph_entry_count);
468 const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count);468 const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count);
469469
470 const stream_end = try seekable_stream.getEndPos();470 const stream_end = try seekable_stream.getEndPos();
...@@ -499,14 +499,14 @@ pub const Elf = struct {...@@ -499,14 +499,14 @@ pub const Elf = struct {
499 // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ?499 // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ?
500 elf_section.name = try in.readInt(u32, elf.endian);500 elf_section.name = try in.readInt(u32, elf.endian);
501 elf_section.sh_type = try in.readInt(u32, elf.endian);501 elf_section.sh_type = try in.readInt(u32, elf.endian);
502 elf_section.flags = u64(try in.readInt(u32, elf.endian));502 elf_section.flags = @as(u64, try in.readInt(u32, elf.endian));
503 elf_section.addr = u64(try in.readInt(u32, elf.endian));503 elf_section.addr = @as(u64, try in.readInt(u32, elf.endian));
504 elf_section.offset = u64(try in.readInt(u32, elf.endian));504 elf_section.offset = @as(u64, try in.readInt(u32, elf.endian));
505 elf_section.size = u64(try in.readInt(u32, elf.endian));505 elf_section.size = @as(u64, try in.readInt(u32, elf.endian));
506 elf_section.link = try in.readInt(u32, elf.endian);506 elf_section.link = try in.readInt(u32, elf.endian);
507 elf_section.info = try in.readInt(u32, elf.endian);507 elf_section.info = try in.readInt(u32, elf.endian);
508 elf_section.addr_align = u64(try in.readInt(u32, elf.endian));508 elf_section.addr_align = @as(u64, try in.readInt(u32, elf.endian));
509 elf_section.ent_size = u64(try in.readInt(u32, elf.endian));509 elf_section.ent_size = @as(u64, try in.readInt(u32, elf.endian));
510 }510 }
511 }511 }
512512
lib/std/event/fs.zig+2-2
...@@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize {...@@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize {
328 windows.ERROR.IO_PENDING => unreachable,328 windows.ERROR.IO_PENDING => unreachable,
329 windows.ERROR.OPERATION_ABORTED => return error.OperationAborted,329 windows.ERROR.OPERATION_ABORTED => return error.OperationAborted,
330 windows.ERROR.BROKEN_PIPE => return error.BrokenPipe,330 windows.ERROR.BROKEN_PIPE => return error.BrokenPipe,
331 windows.ERROR.HANDLE_EOF => return usize(bytes_transferred),331 windows.ERROR.HANDLE_EOF => return @as(usize, bytes_transferred),
332 else => |err| return windows.unexpectedError(err),332 else => |err| return windows.unexpectedError(err),
333 }333 }
334 }334 }
335 return usize(bytes_transferred);335 return @as(usize, bytes_transferred);
336}336}
337337
338/// iovecs must live until preadv frame completes338/// iovecs must live until preadv frame completes
lib/std/fifo.zig+13-13
...@@ -257,7 +257,7 @@ test "ByteFifo" {...@@ -257,7 +257,7 @@ test "ByteFifo" {
257 defer fifo.deinit();257 defer fifo.deinit();
258258
259 try fifo.write("HELLO");259 try fifo.write("HELLO");
260 testing.expectEqual(usize(5), fifo.readableLength());260 testing.expectEqual(@as(usize, 5), fifo.readableLength());
261 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));261 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
262262
263 {263 {
...@@ -265,34 +265,34 @@ test "ByteFifo" {...@@ -265,34 +265,34 @@ test "ByteFifo" {
265 while (i < 5) : (i += 1) {265 while (i < 5) : (i += 1) {
266 try fifo.write([_]u8{try fifo.peekItem(i)});266 try fifo.write([_]u8{try fifo.peekItem(i)});
267 }267 }
268 testing.expectEqual(usize(10), fifo.readableLength());268 testing.expectEqual(@as(usize, 10), fifo.readableLength());
269 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));269 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
270 }270 }
271271
272 {272 {
273 testing.expectEqual(u8('H'), try fifo.readItem());273 testing.expectEqual(@as(u8, 'H'), try fifo.readItem());
274 testing.expectEqual(u8('E'), try fifo.readItem());274 testing.expectEqual(@as(u8, 'E'), try fifo.readItem());
275 testing.expectEqual(u8('L'), try fifo.readItem());275 testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
276 testing.expectEqual(u8('L'), try fifo.readItem());276 testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
277 testing.expectEqual(u8('O'), try fifo.readItem());277 testing.expectEqual(@as(u8, 'O'), try fifo.readItem());
278 }278 }
279 testing.expectEqual(usize(5), fifo.readableLength());279 testing.expectEqual(@as(usize, 5), fifo.readableLength());
280280
281 { // Writes that wrap around281 { // Writes that wrap around
282 testing.expectEqual(usize(11), fifo.writableLength());282 testing.expectEqual(@as(usize, 11), fifo.writableLength());
283 testing.expectEqual(usize(6), fifo.writableSlice(0).len);283 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
284 fifo.writeAssumeCapacity("6<chars<11");284 fifo.writeAssumeCapacity("6<chars<11");
285 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));285 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
286 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));286 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
287 fifo.discard(11);287 fifo.discard(11);
288 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));288 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
289 fifo.discard(4);289 fifo.discard(4);
290 testing.expectEqual(usize(0), fifo.readableLength());290 testing.expectEqual(@as(usize, 0), fifo.readableLength());
291 }291 }
292292
293 {293 {
294 const buf = try fifo.writeableWithSize(12);294 const buf = try fifo.writeableWithSize(12);
295 testing.expectEqual(usize(12), buf.len);295 testing.expectEqual(@as(usize, 12), buf.len);
296 var i: u8 = 0;296 var i: u8 = 0;
297 while (i < 10) : (i += 1) {297 while (i < 10) : (i += 1) {
298 buf[i] = i + 'a';298 buf[i] = i + 'a';
...@@ -313,6 +313,6 @@ test "ByteFifo" {...@@ -313,6 +313,6 @@ test "ByteFifo" {
313 try fifo.print("{}, {}!", "Hello", "World");313 try fifo.print("{}, {}!", "Hello", "World");
314 var result: [30]u8 = undefined;314 var result: [30]u8 = undefined;
315 testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result));315 testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result));
316 testing.expectEqual(usize(0), fifo.readableLength());316 testing.expectEqual(@as(usize, 0), fifo.readableLength());
317 }317 }
318}318}
lib/std/fmt.zig+51-51
...@@ -512,7 +512,7 @@ pub fn formatIntValue(...@@ -512,7 +512,7 @@ pub fn formatIntValue(
512 uppercase = false;512 uppercase = false;
513 } else if (comptime std.mem.eql(u8, fmt, "c")) {513 } else if (comptime std.mem.eql(u8, fmt, "c")) {
514 if (@typeOf(int_value).bit_count <= 8) {514 if (@typeOf(int_value).bit_count <= 8) {
515 return formatAsciiChar(u8(int_value), options, context, Errors, output);515 return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
516 } else {516 } else {
517 @compileError("Cannot print integer that is larger than 8 bits as a ascii");517 @compileError("Cannot print integer that is larger than 8 bits as a ascii");
518 }518 }
...@@ -594,7 +594,7 @@ pub fn formatBuf(...@@ -594,7 +594,7 @@ pub fn formatBuf(
594 var leftover_padding = if (width > buf.len) (width - buf.len) else return;594 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
595 const pad_byte: u8 = options.fill;595 const pad_byte: u8 = options.fill;
596 while (leftover_padding > 0) : (leftover_padding -= 1) {596 while (leftover_padding > 0) : (leftover_padding -= 1) {
597 try output(context, (*const [1]u8)(&pad_byte)[0..1]);597 try output(context, @as(*const [1]u8, &pad_byte)[0..1]);
598 }598 }
599}599}
600600
...@@ -668,7 +668,7 @@ pub fn formatFloatScientific(...@@ -668,7 +668,7 @@ pub fn formatFloatScientific(
668 try output(context, float_decimal.digits[0..1]);668 try output(context, float_decimal.digits[0..1]);
669 try output(context, ".");669 try output(context, ".");
670 if (float_decimal.digits.len > 1) {670 if (float_decimal.digits.len > 1) {
671 const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len;671 const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
672672
673 try output(context, float_decimal.digits[1..num_digits]);673 try output(context, float_decimal.digits[1..num_digits]);
674 } else {674 } else {
...@@ -703,7 +703,7 @@ pub fn formatFloatDecimal(...@@ -703,7 +703,7 @@ pub fn formatFloatDecimal(
703 comptime Errors: type,703 comptime Errors: type,
704 output: fn (@typeOf(context), []const u8) Errors!void,704 output: fn (@typeOf(context), []const u8) Errors!void,
705) Errors!void {705) Errors!void {
706 var x = f64(value);706 var x = @as(f64, value);
707707
708 // Errol doesn't handle these special cases.708 // Errol doesn't handle these special cases.
709 if (math.signbit(x)) {709 if (math.signbit(x)) {
...@@ -921,14 +921,14 @@ fn formatIntSigned(...@@ -921,14 +921,14 @@ fn formatIntSigned(
921 const uint = @IntType(false, @typeOf(value).bit_count);921 const uint = @IntType(false, @typeOf(value).bit_count);
922 if (value < 0) {922 if (value < 0) {
923 const minus_sign: u8 = '-';923 const minus_sign: u8 = '-';
924 try output(context, (*const [1]u8)(&minus_sign)[0..]);924 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
925 const new_value = @intCast(uint, -(value + 1)) + 1;925 const new_value = @intCast(uint, -(value + 1)) + 1;
926 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);926 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
927 } else if (options.width == null or options.width.? == 0) {927 } else if (options.width == null or options.width.? == 0) {
928 return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);928 return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);
929 } else {929 } else {
930 const plus_sign: u8 = '+';930 const plus_sign: u8 = '+';
931 try output(context, (*const [1]u8)(&plus_sign)[0..]);931 try output(context, @as(*const [1]u8, &plus_sign)[0..]);
932 const new_value = @intCast(uint, value);932 const new_value = @intCast(uint, value);
933 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);933 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
934 }934 }
...@@ -966,7 +966,7 @@ fn formatIntUnsigned(...@@ -966,7 +966,7 @@ fn formatIntUnsigned(
966 const zero_byte: u8 = options.fill;966 const zero_byte: u8 = options.fill;
967 var leftover_padding = padding - index;967 var leftover_padding = padding - index;
968 while (true) {968 while (true) {
969 try output(context, (*const [1]u8)(&zero_byte)[0..]);969 try output(context, @as(*const [1]u8, &zero_byte)[0..]);
970 leftover_padding -= 1;970 leftover_padding -= 1;
971 if (leftover_padding == 0) break;971 if (leftover_padding == 0) break;
972 }972 }
...@@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {...@@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
1088fn digitToChar(digit: u8, uppercase: bool) u8 {1088fn digitToChar(digit: u8, uppercase: bool) u8 {
1089 return switch (digit) {1089 return switch (digit) {
1090 0...9 => digit + '0',1090 0...9 => digit + '0',
1091 10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),1091 10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10),
1092 else => unreachable,1092 else => unreachable,
1093 };1093 };
1094}1094}
...@@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {...@@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
1134test "bufPrintInt" {1134test "bufPrintInt" {
1135 var buffer: [100]u8 = undefined;1135 var buffer: [100]u8 = undefined;
1136 const buf = buffer[0..];1136 const buf = buffer[0..];
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678"));1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678"));
1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e"));1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e"));
1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, FormatOptions{}), "-BC614E"));1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E"));
11411141
1142 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, FormatOptions{}), "12345678"));1142 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678"));
11431143
1144 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, FormatOptions{ .width = 6 }), " 666"));1144 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666"));
1145 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));1145 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1146 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));1146 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
11471147
1148 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, FormatOptions{ .width = 3 }), "+42"));1148 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42"));
1149 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, FormatOptions{ .width = 3 }), "-42"));1149 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
1150}1150}
11511151
1152fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {1152fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
...@@ -1208,8 +1208,8 @@ test "int.specifier" {...@@ -1208,8 +1208,8 @@ test "int.specifier" {
1208}1208}
12091209
1210test "int.padded" {1210test "int.padded" {
1211 try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1));1211 try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));
1212 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", u8(1));1212 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));
1213}1213}
12141214
1215test "buffer" {1215test "buffer" {
...@@ -1287,8 +1287,8 @@ test "filesize" {...@@ -1287,8 +1287,8 @@ test "filesize" {
1287 // TODO https://github.com/ziglang/zig/issues/32891287 // TODO https://github.com/ziglang/zig/issues/3289
1288 return error.SkipZigTest;1288 return error.SkipZigTest;
1289 }1289 }
1290 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024));1290 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024));
1291 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", usize(63 * 1024 * 1024));1291 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024));
1292}1292}
12931293
1294test "struct" {1294test "struct" {
...@@ -1327,8 +1327,8 @@ test "float.scientific" {...@@ -1327,8 +1327,8 @@ test "float.scientific" {
1327 }1327 }
1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));
1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));
1330 try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10));1330 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
1331 try testFmt("f64: 9.99996e-40", "f64: {e}", f64(9.999960e-40));1331 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
1332}1332}
13331333
1334test "float.scientific.precision" {1334test "float.scientific.precision" {
...@@ -1336,12 +1336,12 @@ test "float.scientific.precision" {...@@ -1336,12 +1336,12 @@ test "float.scientific.precision" {
1336 // TODO https://github.com/ziglang/zig/issues/32891336 // TODO https://github.com/ziglang/zig/issues/3289
1337 return error.SkipZigTest;1337 return error.SkipZigTest;
1338 }1338 }
1339 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42));1339 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42));
1340 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563))));1340 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563))));
1341 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", f64(@bitCast(f32, u32(1006632960))));1341 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));
1342 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.1342 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
1343 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.1343 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
1344 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", f64(@bitCast(f32, u32(1203982400))));1344 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400))));
1345}1345}
13461346
1347test "float.special" {1347test "float.special" {
...@@ -1364,21 +1364,21 @@ test "float.decimal" {...@@ -1364,21 +1364,21 @@ test "float.decimal" {
1364 // TODO https://github.com/ziglang/zig/issues/32891364 // TODO https://github.com/ziglang/zig/issues/3289
1365 return error.SkipZigTest;1365 return error.SkipZigTest;
1366 }1366 }
1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29));1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
1368 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));1368 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));
1369 try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));1369 try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));
1370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).1370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
1371 // -11.12339... is rounded back up to -11.12341371 // -11.12339... is rounded back up to -11.1234
1372 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));1372 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));
1373 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));1373 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));
1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235));1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
1375 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0));1375 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
1376 try testFmt("f64: 6", "f64: {d:.0}", f64(5.700));1376 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
1377 try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999));1377 try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));
1378 try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0));1378 try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));
1379 try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003));1379 try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));
1380 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45));1380 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));
1381 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(9.999960e-40));1381 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));
1382}1382}
13831383
1384test "float.libc.sanity" {1384test "float.libc.sanity" {
...@@ -1386,22 +1386,22 @@ test "float.libc.sanity" {...@@ -1386,22 +1386,22 @@ test "float.libc.sanity" {
1386 // TODO https://github.com/ziglang/zig/issues/32891386 // TODO https://github.com/ziglang/zig/issues/3289
1387 return error.SkipZigTest;1387 return error.SkipZigTest;
1388 }1388 }
1389 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781))));1389 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781))));
1390 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389))));1390 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389))));
1391 try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278))));1391 try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278))));
1392 try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133))));1392 try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));
1393 try testFmt("f64: 10.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1092616192))));1393 try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));
13941394
1395 // libc differences1395 // libc differences
1396 //1396 //
1397 // This is 0.015625 exactly according to gdb. We thus round down,1397 // This is 0.015625 exactly according to gdb. We thus round down,
1398 // however glibc rounds up for some reason. This occurs for all1398 // however glibc rounds up for some reason. This occurs for all
1399 // floats of the form x.yyyy25 on a precision point.1399 // floats of the form x.yyyy25 on a precision point.
1400 try testFmt("f64: 0.01563", "f64: {d:.5}", f64(@bitCast(f32, u32(1015021568))));1400 try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568))));
1401 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu31401 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
1402 // also rounds to 630 so I'm inclined to believe libc is not1402 // also rounds to 630 so I'm inclined to believe libc is not
1403 // optimal here.1403 // optimal here.
1404 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1518338049))));1404 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049))));
1405}1405}
14061406
1407test "custom" {1407test "custom" {
...@@ -1677,17 +1677,17 @@ test "formatType max_depth" {...@@ -1677,17 +1677,17 @@ test "formatType max_depth" {
1677}1677}
16781678
1679test "positional" {1679test "positional" {
1680 try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2));1680 try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1681 try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2));1681 try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1682 try testFmt("0 0", "{0} {0}", usize(0));1682 try testFmt("0 0", "{0} {0}", @as(usize, 0));
1683 try testFmt("0 1", "{} {1}", usize(0), usize(1));1683 try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));
1684 try testFmt("1 0 0 1", "{1} {} {0} {}", usize(0), usize(1));1684 try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));
1685}1685}
16861686
1687test "positional with specifier" {1687test "positional with specifier" {
1688 try testFmt("10.0", "{0d:.1}", f64(9.999));1688 try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
1689}1689}
16901690
1691test "positional/alignment/width/precision" {1691test "positional/alignment/width/precision" {
1692 try testFmt("10.0", "{0d: >3.1}", f64(9.999));1692 try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));
1693}1693}
lib/std/fmt/errol.zig+2-2
...@@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void {...@@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void {
296/// @buf: The output buffer.296/// @buf: The output buffer.
297/// &return: The exponent.297/// &return: The exponent.
298fn errolInt(val: f64, buffer: []u8) FloatDecimal {298fn errolInt(val: f64, buffer: []u8) FloatDecimal {
299 const pow19 = u128(1e19);299 const pow19 = @as(u128, 1e19);
300300
301 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));301 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
302302
...@@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 {...@@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 {
670 const bits = @bitCast(u64, from);670 const bits = @bitCast(u64, from);
671 assert((bits & ((1 << 52) - 1)) == 0);671 assert((bits & ((1 << 52) - 1)) == 0);
672672
673 return u128(1) << @truncate(u7, (bits >> 52) -% 1023);673 return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023);
674}674}
675675
676/// Given two different integers with the same length in terms of the number676/// Given two different integers with the same length in terms of the number
lib/std/fmt/parse_float.zig+7-7
...@@ -59,29 +59,29 @@ const Z96 = struct {...@@ -59,29 +59,29 @@ const Z96 = struct {
5959
60 // d += s60 // d += s
61 inline fn add(d: *Z96, s: Z96) void {61 inline fn add(d: *Z96, s: Z96) void {
62 var w = u64(d.d0) + u64(s.d0);62 var w = @as(u64, d.d0) + @as(u64, s.d0);
63 d.d0 = @truncate(u32, w);63 d.d0 = @truncate(u32, w);
6464
65 w >>= 32;65 w >>= 32;
66 w += u64(d.d1) + u64(s.d1);66 w += @as(u64, d.d1) + @as(u64, s.d1);
67 d.d1 = @truncate(u32, w);67 d.d1 = @truncate(u32, w);
6868
69 w >>= 32;69 w >>= 32;
70 w += u64(d.d2) + u64(s.d2);70 w += @as(u64, d.d2) + @as(u64, s.d2);
71 d.d2 = @truncate(u32, w);71 d.d2 = @truncate(u32, w);
72 }72 }
7373
74 // d -= s74 // d -= s
75 inline fn sub(d: *Z96, s: Z96) void {75 inline fn sub(d: *Z96, s: Z96) void {
76 var w = u64(d.d0) -% u64(s.d0);76 var w = @as(u64, d.d0) -% @as(u64, s.d0);
77 d.d0 = @truncate(u32, w);77 d.d0 = @truncate(u32, w);
7878
79 w >>= 32;79 w >>= 32;
80 w += u64(d.d1) -% u64(s.d1);80 w += @as(u64, d.d1) -% @as(u64, s.d1);
81 d.d1 = @truncate(u32, w);81 d.d1 = @truncate(u32, w);
8282
83 w >>= 32;83 w >>= 32;
84 w += u64(d.d2) -% u64(s.d2);84 w += @as(u64, d.d2) -% @as(u64, s.d2);
85 d.d2 = @truncate(u32, w);85 d.d2 = @truncate(u32, w);
86 }86 }
87};87};
...@@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {...@@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {
160 break :blk if (n.negative) f64_minus_zero else f64_plus_zero;160 break :blk if (n.negative) f64_minus_zero else f64_plus_zero;
161 } else if (s.d2 != 0) {161 } else if (s.d2 != 0) {
162 const binexs2 = @intCast(u64, binary_exponent) << 52;162 const binexs2 = @intCast(u64, binary_exponent) << 52;
163 const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2;163 const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2;
164 break :blk if (n.negative) rr | (1 << 63) else rr;164 break :blk if (n.negative) rr | (1 << 63) else rr;
165 } else {165 } else {
166 break :blk 0;166 break :blk 0;
lib/std/fs/file.zig+3-3
...@@ -272,9 +272,9 @@ pub const File = struct {...@@ -272,9 +272,9 @@ pub const File = struct {
272 return Stat{272 return Stat{
273 .size = @bitCast(u64, st.size),273 .size = @bitCast(u64, st.size),
274 .mode = st.mode,274 .mode = st.mode,
275 .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,275 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
276 .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,276 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
277 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,277 .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
278 };278 };
279 }279 }
280280
lib/std/hash/auto_hash.zig+7-7
...@@ -306,7 +306,7 @@ test "hash struct deep" {...@@ -306,7 +306,7 @@ test "hash struct deep" {
306test "testHash optional" {306test "testHash optional" {
307 const a: ?u32 = 123;307 const a: ?u32 = 123;
308 const b: ?u32 = null;308 const b: ?u32 = null;
309 testing.expectEqual(testHash(a), testHash(u32(123)));309 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
310 testing.expect(testHash(a) != testHash(b));310 testing.expect(testHash(a) != testHash(b));
311 testing.expectEqual(testHash(b), 0);311 testing.expectEqual(testHash(b), 0);
312}312}
...@@ -315,9 +315,9 @@ test "testHash array" {...@@ -315,9 +315,9 @@ test "testHash array" {
315 const a = [_]u32{ 1, 2, 3 };315 const a = [_]u32{ 1, 2, 3 };
316 const h = testHash(a);316 const h = testHash(a);
317 var hasher = Wyhash.init(0);317 var hasher = Wyhash.init(0);
318 autoHash(&hasher, u32(1));318 autoHash(&hasher, @as(u32, 1));
319 autoHash(&hasher, u32(2));319 autoHash(&hasher, @as(u32, 2));
320 autoHash(&hasher, u32(3));320 autoHash(&hasher, @as(u32, 3));
321 testing.expectEqual(h, hasher.final());321 testing.expectEqual(h, hasher.final());
322}322}
323323
...@@ -330,9 +330,9 @@ test "testHash struct" {...@@ -330,9 +330,9 @@ test "testHash struct" {
330 const f = Foo{};330 const f = Foo{};
331 const h = testHash(f);331 const h = testHash(f);
332 var hasher = Wyhash.init(0);332 var hasher = Wyhash.init(0);
333 autoHash(&hasher, u32(1));333 autoHash(&hasher, @as(u32, 1));
334 autoHash(&hasher, u32(2));334 autoHash(&hasher, @as(u32, 2));
335 autoHash(&hasher, u32(3));335 autoHash(&hasher, @as(u32, 3));
336 testing.expectEqual(h, hasher.final());336 testing.expectEqual(h, hasher.final());
337}337}
338338
lib/std/hash/cityhash.zig+4-4
...@@ -214,7 +214,7 @@ pub const CityHash64 = struct {...@@ -214,7 +214,7 @@ pub const CityHash64 = struct {
214 }214 }
215215
216 fn hashLen0To16(str: []const u8) u64 {216 fn hashLen0To16(str: []const u8) u64 {
217 const len: u64 = u64(str.len);217 const len: u64 = @as(u64, str.len);
218 if (len >= 8) {218 if (len >= 8) {
219 const mul: u64 = k2 +% len *% 2;219 const mul: u64 = k2 +% len *% 2;
220 const a: u64 = fetch64(str.ptr) +% k2;220 const a: u64 = fetch64(str.ptr) +% k2;
...@@ -240,7 +240,7 @@ pub const CityHash64 = struct {...@@ -240,7 +240,7 @@ pub const CityHash64 = struct {
240 }240 }
241241
242 fn hashLen17To32(str: []const u8) u64 {242 fn hashLen17To32(str: []const u8) u64 {
243 const len: u64 = u64(str.len);243 const len: u64 = @as(u64, str.len);
244 const mul: u64 = k2 +% len *% 2;244 const mul: u64 = k2 +% len *% 2;
245 const a: u64 = fetch64(str.ptr) *% k1;245 const a: u64 = fetch64(str.ptr) *% k1;
246 const b: u64 = fetch64(str.ptr + 8);246 const b: u64 = fetch64(str.ptr + 8);
...@@ -251,7 +251,7 @@ pub const CityHash64 = struct {...@@ -251,7 +251,7 @@ pub const CityHash64 = struct {
251 }251 }
252252
253 fn hashLen33To64(str: []const u8) u64 {253 fn hashLen33To64(str: []const u8) u64 {
254 const len: u64 = u64(str.len);254 const len: u64 = @as(u64, str.len);
255 const mul: u64 = k2 +% len *% 2;255 const mul: u64 = k2 +% len *% 2;
256 const a: u64 = fetch64(str.ptr) *% k2;256 const a: u64 = fetch64(str.ptr) *% k2;
257 const b: u64 = fetch64(str.ptr + 8);257 const b: u64 = fetch64(str.ptr + 8);
...@@ -305,7 +305,7 @@ pub const CityHash64 = struct {...@@ -305,7 +305,7 @@ pub const CityHash64 = struct {
305 return hashLen33To64(str);305 return hashLen33To64(str);
306 }306 }
307307
308 var len: u64 = u64(str.len);308 var len: u64 = @as(u64, str.len);
309309
310 var x: u64 = fetch64(str.ptr + str.len - 40);310 var x: u64 = fetch64(str.ptr + str.len - 40);
311 var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56);311 var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56);
lib/std/hash/crc.zig+4-4
...@@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type {...@@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
65 const p = input[i .. i + 8];65 const p = input[i .. i + 8];
6666
67 // Unrolling this way gives ~50Mb/s increase67 // Unrolling this way gives ~50Mb/s increase
68 self.crc ^= (u32(p[0]) << 0);68 self.crc ^= (@as(u32, p[0]) << 0);
69 self.crc ^= (u32(p[1]) << 8);69 self.crc ^= (@as(u32, p[1]) << 8);
70 self.crc ^= (u32(p[2]) << 16);70 self.crc ^= (@as(u32, p[2]) << 16);
71 self.crc ^= (u32(p[3]) << 24);71 self.crc ^= (@as(u32, p[3]) << 24);
7272
73 self.crc =73 self.crc =
74 lookup_tables[0][p[7]] ^74 lookup_tables[0][p[7]] ^
lib/std/hash/murmur.zig+1-1
...@@ -98,7 +98,7 @@ pub const Murmur2_64 = struct {...@@ -98,7 +98,7 @@ pub const Murmur2_64 = struct {
9898
99 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {99 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
100 const m: u64 = 0xc6a4a7935bd1e995;100 const m: u64 = 0xc6a4a7935bd1e995;
101 const len = u64(str.len);101 const len = @as(u64, str.len);
102 var h1: u64 = seed ^ (len *% m);102 var h1: u64 = seed ^ (len *% m);
103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104 var k1: u64 = v;104 var k1: u64 = v;
lib/std/hash/siphash.zig+7-7
...@@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round...@@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
102 }102 }
103103
104 const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3;104 const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3;
105 return (u128(b2) << 64) | b1;105 return (@as(u128, b2) << 64) | b1;
106 }106 }
107107
108 fn round(self: *Self, b: []const u8) void {108 fn round(self: *Self, b: []const u8) void {
...@@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round...@@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
121121
122 fn sipRound(d: *Self) void {122 fn sipRound(d: *Self) void {
123 d.v0 +%= d.v1;123 d.v0 +%= d.v1;
124 d.v1 = math.rotl(u64, d.v1, u64(13));124 d.v1 = math.rotl(u64, d.v1, @as(u64, 13));
125 d.v1 ^= d.v0;125 d.v1 ^= d.v0;
126 d.v0 = math.rotl(u64, d.v0, u64(32));126 d.v0 = math.rotl(u64, d.v0, @as(u64, 32));
127 d.v2 +%= d.v3;127 d.v2 +%= d.v3;
128 d.v3 = math.rotl(u64, d.v3, u64(16));128 d.v3 = math.rotl(u64, d.v3, @as(u64, 16));
129 d.v3 ^= d.v2;129 d.v3 ^= d.v2;
130 d.v0 +%= d.v3;130 d.v0 +%= d.v3;
131 d.v3 = math.rotl(u64, d.v3, u64(21));131 d.v3 = math.rotl(u64, d.v3, @as(u64, 21));
132 d.v3 ^= d.v0;132 d.v3 ^= d.v0;
133 d.v2 +%= d.v1;133 d.v2 +%= d.v1;
134 d.v1 = math.rotl(u64, d.v1, u64(17));134 d.v1 = math.rotl(u64, d.v1, @as(u64, 17));
135 d.v1 ^= d.v2;135 d.v1 ^= d.v2;
136 d.v2 = math.rotl(u64, d.v2, u64(32));136 d.v2 = math.rotl(u64, d.v2, @as(u64, 32));
137 }137 }
138138
139 pub fn hash(key: []const u8, input: []const u8) T {139 pub fn hash(key: []const u8, input: []const u8) T {
lib/std/hash_map.zig+1-1
...@@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
402 }402 }
403403
404 fn keyToIndex(hm: Self, key: K) usize {404 fn keyToIndex(hm: Self, key: K) usize {
405 return hm.constrainIndex(usize(hash(key)));405 return hm.constrainIndex(@as(usize, hash(key)));
406 }406 }
407407
408 fn constrainIndex(hm: Self, i: usize) usize {408 fn constrainIndex(hm: Self, i: usize) usize {
lib/std/heap.zig+1-1
...@@ -896,7 +896,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo...@@ -896,7 +896,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
896 const large_align = u29(mem.page_size << 2);896 const large_align = u29(mem.page_size << 2);
897897
898 var align_mask: usize = undefined;898 var align_mask: usize = undefined;
899 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask);899 _ = @shlWithOverflow(usize, ~@as(usize, 0), USizeShift(@ctz(u29, large_align)), &align_mask);
900900
901 var slice = try allocator.alignedAlloc(u8, large_align, 500);901 var slice = try allocator.alignedAlloc(u8, large_align, 500);
902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
lib/std/http/headers.zig+5-5
...@@ -399,7 +399,7 @@ test "Headers.iterator" {...@@ -399,7 +399,7 @@ test "Headers.iterator" {
399 }399 }
400 count += 1;400 count += 1;
401 }401 }
402 testing.expectEqual(i32(2), count);402 testing.expectEqual(@as(i32, 2), count);
403}403}
404404
405test "Headers.contains" {405test "Headers.contains" {
...@@ -420,10 +420,10 @@ test "Headers.delete" {...@@ -420,10 +420,10 @@ test "Headers.delete" {
420 try h.append("cookie", "somevalue", null);420 try h.append("cookie", "somevalue", null);
421421
422 testing.expectEqual(false, h.delete("not-present"));422 testing.expectEqual(false, h.delete("not-present"));
423 testing.expectEqual(usize(3), h.count());423 testing.expectEqual(@as(usize, 3), h.count());
424424
425 testing.expectEqual(true, h.delete("foo"));425 testing.expectEqual(true, h.delete("foo"));
426 testing.expectEqual(usize(2), h.count());426 testing.expectEqual(@as(usize, 2), h.count());
427 {427 {
428 const e = h.at(0);428 const e = h.at(0);
429 testing.expectEqualSlices(u8, "baz", e.name);429 testing.expectEqualSlices(u8, "baz", e.name);
...@@ -448,7 +448,7 @@ test "Headers.orderedRemove" {...@@ -448,7 +448,7 @@ test "Headers.orderedRemove" {
448 try h.append("cookie", "somevalue", null);448 try h.append("cookie", "somevalue", null);
449449
450 h.orderedRemove(0);450 h.orderedRemove(0);
451 testing.expectEqual(usize(2), h.count());451 testing.expectEqual(@as(usize, 2), h.count());
452 {452 {
453 const e = h.at(0);453 const e = h.at(0);
454 testing.expectEqualSlices(u8, "baz", e.name);454 testing.expectEqualSlices(u8, "baz", e.name);
...@@ -471,7 +471,7 @@ test "Headers.swapRemove" {...@@ -471,7 +471,7 @@ test "Headers.swapRemove" {
471 try h.append("cookie", "somevalue", null);471 try h.append("cookie", "somevalue", null);
472472
473 h.swapRemove(0);473 h.swapRemove(0);
474 testing.expectEqual(usize(2), h.count());474 testing.expectEqual(@as(usize, 2), h.count());
475 {475 {
476 const e = h.at(0);476 const e = h.at(0);
477 testing.expectEqualSlices(u8, "cookie", e.name);477 testing.expectEqualSlices(u8, "cookie", e.name);
lib/std/io.zig+2-2
...@@ -353,7 +353,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -353,7 +353,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
353 const Buf = @IntType(false, buf_bit_count);353 const Buf = @IntType(false, buf_bit_count);
354 const BufShift = math.Log2Int(Buf);354 const BufShift = math.Log2Int(Buf);
355355
356 out_bits.* = usize(0);356 out_bits.* = @as(usize, 0);
357 if (U == u0 or bits == 0) return 0;357 if (U == u0 or bits == 0) return 0;
358 var out_buffer = Buf(0);358 var out_buffer = Buf(0);
359359
...@@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
434 var self = @fieldParentPtr(Self, "stream", self_stream);434 var self = @fieldParentPtr(Self, "stream", self_stream);
435435
436 var out_bits: usize = undefined;436 var out_bits: usize = undefined;
437 var out_bits_total = usize(0);437 var out_bits_total = @as(usize, 0);
438 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced438 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
439 if (self.bit_count > 0) {439 if (self.bit_count > 0) {
440 for (buffer) |*b, i| {440 for (buffer) |*b, i| {
lib/std/io/out_stream.zig+2-2
...@@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type {
40 }40 }
4141
42 pub fn writeByte(self: *Self, byte: u8) Error!void {42 pub fn writeByte(self: *Self, byte: u8) Error!void {
43 const slice = (*const [1]u8)(&byte)[0..];43 const slice = @as(*const [1]u8, &byte)[0..];
44 return self.writeFn(self, slice);44 return self.writeFn(self, slice);
45 }45 }
4646
47 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {47 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {
48 const slice = (*const [1]u8)(&byte)[0..];48 const slice = @as(*const [1]u8, &byte)[0..];
49 var i: usize = 0;49 var i: usize = 0;
50 while (i < n) : (i += 1) {50 while (i < n) : (i += 1) {
51 try self.writeFn(self, slice);51 try self.writeFn(self, slice);
lib/std/io/test.zig+20-20
...@@ -228,8 +228,8 @@ test "BitOutStream" {...@@ -228,8 +228,8 @@ test "BitOutStream" {
228228
229 try bit_stream_be.writeBits(u2(1), 1);229 try bit_stream_be.writeBits(u2(1), 1);
230 try bit_stream_be.writeBits(u5(2), 2);230 try bit_stream_be.writeBits(u5(2), 2);
231 try bit_stream_be.writeBits(u128(3), 3);231 try bit_stream_be.writeBits(@as(u128, 3), 3);
232 try bit_stream_be.writeBits(u8(4), 4);232 try bit_stream_be.writeBits(@as(u8, 4), 4);
233 try bit_stream_be.writeBits(u9(5), 5);233 try bit_stream_be.writeBits(u9(5), 5);
234 try bit_stream_be.writeBits(u1(1), 1);234 try bit_stream_be.writeBits(u1(1), 1);
235235
...@@ -242,33 +242,33 @@ test "BitOutStream" {...@@ -242,33 +242,33 @@ test "BitOutStream" {
242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
243243
244 mem_out_be.pos = 0;244 mem_out_be.pos = 0;
245 try bit_stream_be.writeBits(u32(0b110011010000101), 16);245 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
246 expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);246 expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
247247
248 try bit_stream_be.writeBits(u0(0), 0);248 try bit_stream_be.writeBits(@as(u0, 0), 0);
249249
250 var mem_out_le = io.SliceOutStream.init(mem_le[0..]);250 var mem_out_le = io.SliceOutStream.init(mem_le[0..]);
251 var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream);251 var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream);
252252
253 try bit_stream_le.writeBits(u2(1), 1);253 try bit_stream_le.writeBits(@as(u2, 1), 1);
254 try bit_stream_le.writeBits(u5(2), 2);254 try bit_stream_le.writeBits(@as(u5, 2), 2);
255 try bit_stream_le.writeBits(u128(3), 3);255 try bit_stream_le.writeBits(@as(u128, 3), 3);
256 try bit_stream_le.writeBits(u8(4), 4);256 try bit_stream_le.writeBits(@as(u8, 4), 4);
257 try bit_stream_le.writeBits(u9(5), 5);257 try bit_stream_le.writeBits(@as(u9, 5), 5);
258 try bit_stream_le.writeBits(u1(1), 1);258 try bit_stream_le.writeBits(@as(u1, 1), 1);
259259
260 expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);260 expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
261261
262 mem_out_le.pos = 0;262 mem_out_le.pos = 0;
263 try bit_stream_le.writeBits(u15(0b110011010000101), 15);263 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
264 try bit_stream_le.flushBits();264 try bit_stream_le.flushBits();
265 expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);265 expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
266266
267 mem_out_le.pos = 0;267 mem_out_le.pos = 0;
268 try bit_stream_le.writeBits(u32(0b1100110100001011), 16);268 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
269 expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);269 expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
270270
271 try bit_stream_le.writeBits(u0(0), 0);271 try bit_stream_le.writeBits(@as(u0, 0), 0);
272}272}
273273
274test "BitStreams with File Stream" {274test "BitStreams with File Stream" {
...@@ -282,12 +282,12 @@ test "BitStreams with File Stream" {...@@ -282,12 +282,12 @@ test "BitStreams with File Stream" {
282 const OutError = File.WriteError;282 const OutError = File.WriteError;
283 var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream);283 var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream);
284284
285 try bit_stream.writeBits(u2(1), 1);285 try bit_stream.writeBits(@as(u2, 1), 1);
286 try bit_stream.writeBits(u5(2), 2);286 try bit_stream.writeBits(@as(u5, 2), 2);
287 try bit_stream.writeBits(u128(3), 3);287 try bit_stream.writeBits(@as(u128, 3), 3);
288 try bit_stream.writeBits(u8(4), 4);288 try bit_stream.writeBits(@as(u8, 4), 4);
289 try bit_stream.writeBits(u9(5), 5);289 try bit_stream.writeBits(@as(u9, 5), 5);
290 try bit_stream.writeBits(u1(1), 1);290 try bit_stream.writeBits(@as(u1, 1), 1);
291 try bit_stream.flushBits();291 try bit_stream.flushBits();
292 }292 }
293 {293 {
...@@ -603,7 +603,7 @@ test "c out stream" {...@@ -603,7 +603,7 @@ test "c out stream" {
603 }603 }
604604
605 const out_stream = &io.COutStream.init(out_file).stream;605 const out_stream = &io.COutStream.init(out_file).stream;
606 try out_stream.print("hi: {}\n", i32(123));606 try out_stream.print("hi: {}\n", @as(i32, 123));
607}607}
608608
609test "File seek ops" {609test "File seek ops" {
lib/std/json.zig+2-2
...@@ -1343,7 +1343,7 @@ test "write json then parse it" {...@@ -1343,7 +1343,7 @@ test "write json then parse it" {
1343 try jw.emitBool(true);1343 try jw.emitBool(true);
13441344
1345 try jw.objectField("int");1345 try jw.objectField("int");
1346 try jw.emitNumber(i32(1234));1346 try jw.emitNumber(@as(i32, 1234));
13471347
1348 try jw.objectField("array");1348 try jw.objectField("array");
1349 try jw.beginArray();1349 try jw.beginArray();
...@@ -1352,7 +1352,7 @@ test "write json then parse it" {...@@ -1352,7 +1352,7 @@ test "write json then parse it" {
1352 try jw.emitNull();1352 try jw.emitNull();
13531353
1354 try jw.arrayElem();1354 try jw.arrayElem();
1355 try jw.emitNumber(f64(12.34));1355 try jw.emitNumber(@as(f64, 12.34));
13561356
1357 try jw.endArray();1357 try jw.endArray();
13581358
lib/std/math.zig+68-68
...@@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079;...@@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079;
44pub const sqrt1_2 = 0.707106781186547524400844362104849039;44pub const sqrt1_2 = 0.707106781186547524400844362104849039;
4545
46// From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128)46// From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128)
47pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001));47pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001));
48pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000));48pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000));
49pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));49pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
50pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000));50pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000));
51pub const f128_toint = 1.0 / f128_epsilon;51pub const f128_toint = 1.0 / f128_epsilon;
5252
53// float.h details53// float.h details
...@@ -69,28 +69,28 @@ pub const f16_max = 65504;...@@ -69,28 +69,28 @@ pub const f16_max = 65504;
69pub const f16_epsilon = 0.0009765625; // 2**-1069pub const f16_epsilon = 0.0009765625; // 2**-10
70pub const f16_toint = 1.0 / f16_epsilon;70pub const f16_toint = 1.0 / f16_epsilon;
7171
72pub const nan_u16 = u16(0x7C01);72pub const nan_u16 = @as(u16, 0x7C01);
73pub const nan_f16 = @bitCast(f16, nan_u16);73pub const nan_f16 = @bitCast(f16, nan_u16);
7474
75pub const inf_u16 = u16(0x7C00);75pub const inf_u16 = @as(u16, 0x7C00);
76pub const inf_f16 = @bitCast(f16, inf_u16);76pub const inf_f16 = @bitCast(f16, inf_u16);
7777
78pub const nan_u32 = u32(0x7F800001);78pub const nan_u32 = @as(u32, 0x7F800001);
79pub const nan_f32 = @bitCast(f32, nan_u32);79pub const nan_f32 = @bitCast(f32, nan_u32);
8080
81pub const inf_u32 = u32(0x7F800000);81pub const inf_u32 = @as(u32, 0x7F800000);
82pub const inf_f32 = @bitCast(f32, inf_u32);82pub const inf_f32 = @bitCast(f32, inf_u32);
8383
84pub const nan_u64 = u64(0x7FF << 52) | 1;84pub const nan_u64 = @as(u64, 0x7FF << 52) | 1;
85pub const nan_f64 = @bitCast(f64, nan_u64);85pub const nan_f64 = @bitCast(f64, nan_u64);
8686
87pub const inf_u64 = u64(0x7FF << 52);87pub const inf_u64 = @as(u64, 0x7FF << 52);
88pub const inf_f64 = @bitCast(f64, inf_u64);88pub const inf_f64 = @bitCast(f64, inf_u64);
8989
90pub const nan_u128 = u128(0x7fff0000000000000000000000000001);90pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
91pub const nan_f128 = @bitCast(f128, nan_u128);91pub const nan_f128 = @bitCast(f128, nan_u128);
9292
93pub const inf_u128 = u128(0x7fff0000000000000000000000000000);93pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000);
94pub const inf_f128 = @bitCast(f128, inf_u128);94pub const inf_f128 = @bitCast(f128, inf_u128);
9595
96pub const nan = @import("math/nan.zig").nan;96pub const nan = @import("math/nan.zig").nan;
...@@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type {...@@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type {
248 },248 },
249 else => {},249 else => {},
250 }250 }
251 return @typeOf(A(0) + B(0));251 return @typeOf(@as(A, 0) + @as(B, 0));
252}252}
253253
254/// Returns the smaller number. When one of the parameter's type's full range fits in the other,254/// Returns the smaller number. When one of the parameter's type's full range fits in the other,
...@@ -273,7 +273,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) {...@@ -273,7 +273,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) {
273}273}
274274
275test "math.min" {275test "math.min" {
276 testing.expect(min(i32(-1), i32(2)) == -1);276 testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
277 {277 {
278 var a: u16 = 999;278 var a: u16 = 999;
279 var b: u32 = 10;279 var b: u32 = 10;
...@@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {...@@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
309}309}
310310
311test "math.max" {311test "math.max" {
312 testing.expect(max(i32(-1), i32(2)) == 2);312 testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
313}313}
314314
315pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {315pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
...@@ -352,10 +352,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {...@@ -352,10 +352,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {
352}352}
353353
354test "math.shl" {354test "math.shl" {
355 testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000);355 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
356 testing.expect(shl(u8, 0b11111111, usize(8)) == 0);356 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
357 testing.expect(shl(u8, 0b11111111, usize(9)) == 0);357 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
358 testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111);358 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
359 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);359 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
360 testing.expect(shl(u8, 0b11111111, 8) == 0);360 testing.expect(shl(u8, 0b11111111, 8) == 0);
361 testing.expect(shl(u8, 0b11111111, 9) == 0);361 testing.expect(shl(u8, 0b11111111, 9) == 0);
...@@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {...@@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
380}380}
381381
382test "math.shr" {382test "math.shr" {
383 testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111);383 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
384 testing.expect(shr(u8, 0b11111111, usize(8)) == 0);384 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
385 testing.expect(shr(u8, 0b11111111, usize(9)) == 0);385 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
386 testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100);386 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
387 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);387 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
388 testing.expect(shr(u8, 0b11111111, 8) == 0);388 testing.expect(shr(u8, 0b11111111, 8) == 0);
389 testing.expect(shr(u8, 0b11111111, 9) == 0);389 testing.expect(shr(u8, 0b11111111, 9) == 0);
...@@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {...@@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
402}402}
403403
404test "math.rotr" {404test "math.rotr" {
405 testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001);405 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
406 testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000);406 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
407 testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001);407 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
408 testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000);408 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
409 testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);409 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
410}410}
411411
412/// Rotates left. Only unsigned values can be rotated.412/// Rotates left. Only unsigned values can be rotated.
...@@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {...@@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
421}421}
422422
423test "math.rotl" {423test "math.rotl" {
424 testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001);424 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
425 testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010);425 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
426 testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001);426 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
427 testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000);427 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
428 testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);428 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
429}429}
430430
431pub fn Log2Int(comptime T: type) type {431pub fn Log2Int(comptime T: type) type {
...@@ -532,8 +532,8 @@ test "math.absInt" {...@@ -532,8 +532,8 @@ test "math.absInt" {
532 comptime testAbsInt();532 comptime testAbsInt();
533}533}
534fn testAbsInt() void {534fn testAbsInt() void {
535 testing.expect((absInt(i32(-10)) catch unreachable) == 10);535 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
536 testing.expect((absInt(i32(10)) catch unreachable) == 10);536 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
537}537}
538538
539pub const absFloat = fabs;539pub const absFloat = fabs;
...@@ -679,14 +679,14 @@ pub fn absCast(x: var) t: {...@@ -679,14 +679,14 @@ pub fn absCast(x: var) t: {
679}679}
680680
681test "math.absCast" {681test "math.absCast" {
682 testing.expect(absCast(i32(-999)) == 999);682 testing.expect(absCast(@as(i32, -999)) == 999);
683 testing.expect(@typeOf(absCast(i32(-999))) == u32);683 testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);
684684
685 testing.expect(absCast(i32(999)) == 999);685 testing.expect(absCast(@as(i32, 999)) == 999);
686 testing.expect(@typeOf(absCast(i32(999))) == u32);686 testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);
687687
688 testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));688 testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
689 testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);689 testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);
690690
691 testing.expect(absCast(-999) == 999);691 testing.expect(absCast(-999) == 999);
692}692}
...@@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {...@@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
705}705}
706706
707test "math.negateCast" {707test "math.negateCast" {
708 testing.expect((negateCast(u32(999)) catch unreachable) == -999);708 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
709 testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);709 testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
710710
711 testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));711 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
712 testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);712 testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
713713
714 testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10)));714 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
715}715}
716716
717/// Cast an integer to a different integer type. If the value doesn't fit,717/// Cast an integer to a different integer type. If the value doesn't fit,
...@@ -729,13 +729,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {...@@ -729,13 +729,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
729}729}
730730
731test "math.cast" {731test "math.cast" {
732 testing.expectError(error.Overflow, cast(u8, u32(300)));732 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
733 testing.expectError(error.Overflow, cast(i8, i32(-200)));733 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
734 testing.expectError(error.Overflow, cast(u8, i8(-1)));734 testing.expectError(error.Overflow, cast(u8, i8(-1)));
735 testing.expectError(error.Overflow, cast(u64, i8(-1)));735 testing.expectError(error.Overflow, cast(u64, i8(-1)));
736736
737 testing.expect((try cast(u8, u32(255))) == u8(255));737 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
738 testing.expect(@typeOf(try cast(u8, u32(255))) == u8);738 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
739}739}
740740
741pub const AlignCastError = error{UnalignedMemory};741pub const AlignCastError = error{UnalignedMemory};
...@@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" {...@@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" {
812}812}
813813
814fn testCeilPowerOfTwoPromote() void {814fn testCeilPowerOfTwoPromote() void {
815 testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1));815 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
816 testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2));816 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
817 testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63));817 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
818 testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64));818 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
819 testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65));819 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
820 testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7));820 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
821 testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8));821 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
822 testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9));822 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
823 testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9));823 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
824}824}
825825
826test "math.ceilPowerOfTwo" {826test "math.ceilPowerOfTwo" {
...@@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" {...@@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" {
829}829}
830830
831fn testCeilPowerOfTwo() !void {831fn testCeilPowerOfTwo() !void {
832 testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1));832 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
833 testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2));833 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
834 testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63));834 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
835 testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64));835 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
836 testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65));836 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
837 testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7));837 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
838 testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8));838 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
839 testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9));839 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
840 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));840 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
841}841}
842842
...@@ -944,7 +944,7 @@ test "max value type" {...@@ -944,7 +944,7 @@ test "max value type" {
944944
945pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {945pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
946 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);946 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
947 return ResultInt(a) * ResultInt(b);947 return @as(ResultInt, a) * @as(ResultInt, b);
948}948}
949949
950test "math.mulWide" {950test "math.mulWide" {
lib/std/math/acos.zig+2-2
...@@ -149,8 +149,8 @@ fn acos64(x: f64) f64 {...@@ -149,8 +149,8 @@ fn acos64(x: f64) f64 {
149}149}
150150
151test "math.acos" {151test "math.acos" {
152 expect(acos(f32(0.0)) == acos32(0.0));152 expect(acos(@as(f32, 0.0)) == acos32(0.0));
153 expect(acos(f64(0.0)) == acos64(0.0));153 expect(acos(@as(f64, 0.0)) == acos64(0.0));
154}154}
155155
156test "math.acos32" {156test "math.acos32" {
lib/std/math/acosh.zig+2-2
...@@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 {...@@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 {
61}61}
6262
63test "math.acosh" {63test "math.acosh" {
64 expect(acosh(f32(1.5)) == acosh32(1.5));64 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
65 expect(acosh(f64(1.5)) == acosh64(1.5));65 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
66}66}
6767
68test "math.acosh32" {68test "math.acosh32" {
lib/std/math/asin.zig+2-2
...@@ -142,8 +142,8 @@ fn asin64(x: f64) f64 {...@@ -142,8 +142,8 @@ fn asin64(x: f64) f64 {
142}142}
143143
144test "math.asin" {144test "math.asin" {
145 expect(asin(f32(0.0)) == asin32(0.0));145 expect(asin(@as(f32, 0.0)) == asin32(0.0));
146 expect(asin(f64(0.0)) == asin64(0.0));146 expect(asin(@as(f64, 0.0)) == asin64(0.0));
147}147}
148148
149test "math.asin32" {149test "math.asin32" {
lib/std/math/asinh.zig+2-2
...@@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 {...@@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 {
89}89}
9090
91test "math.asinh" {91test "math.asinh" {
92 expect(asinh(f32(0.0)) == asinh32(0.0));92 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
93 expect(asinh(f64(0.0)) == asinh64(0.0));93 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
94}94}
9595
96test "math.asinh32" {96test "math.asinh32" {
lib/std/math/atan.zig+2-2
...@@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 {...@@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 {
212}212}
213213
214test "math.atan" {214test "math.atan" {
215 expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));215 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
216 expect(atan(f64(0.2)) == atan64(0.2));216 expect(atan(@as(f64, 0.2)) == atan64(0.2));
217}217}
218218
219test "math.atan32" {219test "math.atan32" {
lib/std/math/atanh.zig+2-2
...@@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 {...@@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 {
84}84}
8585
86test "math.atanh" {86test "math.atanh" {
87 expect(atanh(f32(0.0)) == atanh_32(0.0));87 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
88 expect(atanh(f64(0.0)) == atanh_64(0.0));88 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
89}89}
9090
91test "math.atanh_32" {91test "math.atanh_32" {
lib/std/math/big/int.zig+1-1
...@@ -261,7 +261,7 @@ pub const Int = struct {...@@ -261,7 +261,7 @@ pub const Int = struct {
261 /// the minus sign. This is used for determining the number of characters needed to print the261 /// the minus sign. This is used for determining the number of characters needed to print the
262 /// value. It is inexact and may exceed the given value by ~1-2 bytes.262 /// value. It is inexact and may exceed the given value by ~1-2 bytes.
263 pub fn sizeInBase(self: Int, base: usize) usize {263 pub fn sizeInBase(self: Int, base: usize) usize {
264 const bit_count = usize(@boolToInt(!self.isPositive())) + self.bitCountAbs();264 const bit_count = @as(usize, @boolToInt(!self.isPositive())) + self.bitCountAbs();
265 return (bit_count / math.log2(base)) + 1;265 return (bit_count / math.log2(base)) + 1;
266 }266 }
267267
lib/std/math/cbrt.zig+5-5
...@@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 {...@@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 {
54 // first step newton to 16 bits54 // first step newton to 16 bits
55 var t: f64 = @bitCast(f32, u);55 var t: f64 = @bitCast(f32, u);
56 var r: f64 = t * t * t;56 var r: f64 = t * t * t;
57 t = t * (f64(x) + x + r) / (x + r + r);57 t = t * (@as(f64, x) + x + r) / (x + r + r);
5858
59 // second step newton to 47 bits59 // second step newton to 47 bits
60 r = t * t * t;60 r = t * t * t;
61 t = t * (f64(x) + x + r) / (x + r + r);61 t = t * (@as(f64, x) + x + r) / (x + r + r);
6262
63 return @floatCast(f32, t);63 return @floatCast(f32, t);
64}64}
...@@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 {...@@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 {
97 }97 }
9898
99 u &= 1 << 63;99 u &= 1 << 63;
100 u |= u64(hx) << 32;100 u |= @as(u64, hx) << 32;
101 var t = @bitCast(f64, u);101 var t = @bitCast(f64, u);
102102
103 // cbrt to 23 bits103 // cbrt to 23 bits
...@@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 {...@@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 {
120}120}
121121
122test "math.cbrt" {122test "math.cbrt" {
123 expect(cbrt(f32(0.0)) == cbrt32(0.0));123 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
124 expect(cbrt(f64(0.0)) == cbrt64(0.0));124 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
125}125}
126126
127test "math.cbrt32" {127test "math.cbrt32" {
lib/std/math/ceil.zig+3-3
...@@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 {...@@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 {
37 if (e >= 23) {37 if (e >= 23) {
38 return x;38 return x;
39 } else if (e >= 0) {39 } else if (e >= 0) {
40 m = u32(0x007FFFFF) >> @intCast(u5, e);40 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
41 if (u & m == 0) {41 if (u & m == 0) {
42 return x;42 return x;
43 }43 }
...@@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 {...@@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 {
87}87}
8888
89test "math.ceil" {89test "math.ceil" {
90 expect(ceil(f32(0.0)) == ceil32(0.0));90 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
91 expect(ceil(f64(0.0)) == ceil64(0.0));91 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
92}92}
9393
94test "math.ceil32" {94test "math.ceil32" {
lib/std/math/complex/ldexp.zig+1-1
...@@ -59,7 +59,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {...@@ -59,7 +59,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
59 expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;59 expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
6060
61 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);61 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
62 return @bitCast(f64, (u64(high_word) << 32) | lx);62 return @bitCast(f64, (@as(u64, high_word) << 32) | lx);
63}63}
6464
65fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {65fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
lib/std/math/complex/sqrt.zig+2-2
...@@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {...@@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {
52 // y = nan special case is handled fine below52 // y = nan special case is handled fine below
5353
54 // double-precision avoids overflow with correct rounding.54 // double-precision avoids overflow with correct rounding.
55 const dx = f64(x);55 const dx = @as(f64, x);
56 const dy = f64(y);56 const dy = @as(f64, y);
5757
58 if (dx >= 0) {58 if (dx >= 0) {
59 const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);59 const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
lib/std/math/complex/tanh.zig+1-1
...@@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {...@@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
76 return Complex(f64).new(x, r);76 return Complex(f64).new(x, r);
77 }77 }
7878
79 const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx);79 const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);
80 const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y);80 const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y);
81 return Complex(f64).new(xx, math.copysign(f64, 0, r));81 return Complex(f64).new(xx, math.copysign(f64, 0, r));
82 }82 }
lib/std/math/copysign.zig+3-3
...@@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 {...@@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 {
24 const uy = @bitCast(u16, y);24 const uy = @bitCast(u16, y);
2525
26 const h1 = ux & (maxInt(u16) / 2);26 const h1 = ux & (maxInt(u16) / 2);
27 const h2 = uy & (u16(1) << 15);27 const h2 = uy & (@as(u16, 1) << 15);
28 return @bitCast(f16, h1 | h2);28 return @bitCast(f16, h1 | h2);
29}29}
3030
...@@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 {...@@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 {
33 const uy = @bitCast(u32, y);33 const uy = @bitCast(u32, y);
3434
35 const h1 = ux & (maxInt(u32) / 2);35 const h1 = ux & (maxInt(u32) / 2);
36 const h2 = uy & (u32(1) << 31);36 const h2 = uy & (@as(u32, 1) << 31);
37 return @bitCast(f32, h1 | h2);37 return @bitCast(f32, h1 | h2);
38}38}
3939
...@@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 {...@@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 {
42 const uy = @bitCast(u64, y);42 const uy = @bitCast(u64, y);
4343
44 const h1 = ux & (maxInt(u64) / 2);44 const h1 = ux & (maxInt(u64) / 2);
45 const h2 = uy & (u64(1) << 63);45 const h2 = uy & (@as(u64, 1) << 63);
46 return @bitCast(f64, h1 | h2);46 return @bitCast(f64, h1 | h2);
47}47}
4848
lib/std/math/cos.zig+2-2
...@@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T {...@@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T {
83}83}
8484
85test "math.cos" {85test "math.cos" {
86 expect(cos(f32(0.0)) == cos_(f32, 0.0));86 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
87 expect(cos(f64(0.0)) == cos_(f64, 0.0));87 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
88}88}
8989
90test "math.cos32" {90test "math.cos32" {
lib/std/math/cosh.zig+2-2
...@@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 {...@@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 {
88}88}
8989
90test "math.cosh" {90test "math.cosh" {
91 expect(cosh(f32(1.5)) == cosh32(1.5));91 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
92 expect(cosh(f64(1.5)) == cosh64(1.5));92 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
93}93}
9494
95test "math.cosh32" {95test "math.cosh32" {
lib/std/math/exp.zig+2-2
...@@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 {...@@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 {
183}183}
184184
185test "math.exp" {185test "math.exp" {
186 assert(exp(f32(0.0)) == exp32(0.0));186 assert(exp(@as(f32, 0.0)) == exp32(0.0));
187 assert(exp(f64(0.0)) == exp64(0.0));187 assert(exp(@as(f64, 0.0)) == exp64(0.0));
188}188}
189189
190test "math.exp32" {190test "math.exp32" {
lib/std/math/exp2.zig+3-3
...@@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 {...@@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 {
85 const k = i_0 / tblsiz;85 const k = i_0 / tblsiz;
86 // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the86 // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the
87 // intended result but should confirm how GCC/Clang handle this to ensure.87 // intended result but should confirm how GCC/Clang handle this to ensure.
88 const uk = @bitCast(f64, u64(0x3FF + k) << 52);88 const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52);
89 i_0 &= tblsiz - 1;89 i_0 &= tblsiz - 1;
90 uf -= redux;90 uf -= redux;
9191
...@@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 {...@@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 {
421}421}
422422
423test "math.exp2" {423test "math.exp2" {
424 expect(exp2(f32(0.8923)) == exp2_32(0.8923));424 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
425 expect(exp2(f64(0.8923)) == exp2_64(0.8923));425 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
426}426}
427427
428test "math.exp2_32" {428test "math.exp2_32" {
lib/std/math/expm1.zig+2-2
...@@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 {...@@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 {
287}287}
288288
289test "math.exp1m" {289test "math.exp1m" {
290 expect(expm1(f32(0.0)) == expm1_32(0.0));290 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
291 expect(expm1(f64(0.0)) == expm1_64(0.0));291 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
292}292}
293293
294test "math.expm1_32" {294test "math.expm1_32" {
lib/std/math/expo2.zig+1-1
...@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {...@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {
30 const kln2 = 0x1.62066151ADD8BP+10;30 const kln2 = 0x1.62066151ADD8BP+10;
3131
32 const u = (0x3FF + k / 2) << 20;32 const u = (0x3FF + k / 2) << 20;
33 const scale = @bitCast(f64, u64(u) << 32);33 const scale = @bitCast(f64, @as(u64, u) << 32);
34 return math.exp(x - kln2) * scale * scale;34 return math.exp(x - kln2) * scale * scale;
35}35}
lib/std/math/fabs.zig+4-4
...@@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 {...@@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 {
50}50}
5151
52test "math.fabs" {52test "math.fabs" {
53 expect(fabs(f16(1.0)) == fabs16(1.0));53 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
54 expect(fabs(f32(1.0)) == fabs32(1.0));54 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
55 expect(fabs(f64(1.0)) == fabs64(1.0));55 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
56 expect(fabs(f128(1.0)) == fabs128(1.0));56 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
57}57}
5858
59test "math.fabs16" {59test "math.fabs16" {
lib/std/math/floor.zig+5-5
...@@ -40,7 +40,7 @@ fn floor16(x: f16) f16 {...@@ -40,7 +40,7 @@ fn floor16(x: f16) f16 {
40 }40 }
4141
42 if (e >= 0) {42 if (e >= 0) {
43 m = u16(1023) >> @intCast(u4, e);43 m = @as(u16, 1023) >> @intCast(u4, e);
44 if (u & m == 0) {44 if (u & m == 0) {
45 return x;45 return x;
46 }46 }
...@@ -74,7 +74,7 @@ fn floor32(x: f32) f32 {...@@ -74,7 +74,7 @@ fn floor32(x: f32) f32 {
74 }74 }
7575
76 if (e >= 0) {76 if (e >= 0) {
77 m = u32(0x007FFFFF) >> @intCast(u5, e);77 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
78 if (u & m == 0) {78 if (u & m == 0) {
79 return x;79 return x;
80 }80 }
...@@ -123,9 +123,9 @@ fn floor64(x: f64) f64 {...@@ -123,9 +123,9 @@ fn floor64(x: f64) f64 {
123}123}
124124
125test "math.floor" {125test "math.floor" {
126 expect(floor(f16(1.3)) == floor16(1.3));126 expect(floor(@as(f16, 1.3)) == floor16(1.3));
127 expect(floor(f32(1.3)) == floor32(1.3));127 expect(floor(@as(f32, 1.3)) == floor32(1.3));
128 expect(floor(f64(1.3)) == floor64(1.3));128 expect(floor(@as(f64, 1.3)) == floor64(1.3));
129}129}
130130
131test "math.floor16" {131test "math.floor16" {
lib/std/math/fma.zig+1-1
...@@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T {...@@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T {
18}18}
1919
20fn fma32(x: f32, y: f32, z: f32) f32 {20fn fma32(x: f32, y: f32, z: f32) f32 {
21 const xy = f64(x) * y;21 const xy = @as(f64, x) * y;
22 const xy_z = xy + z;22 const xy_z = xy + z;
23 const u = @bitCast(u64, xy_z);23 const u = @bitCast(u64, xy_z);
24 const e = (u >> 52) & 0x7FF;24 const e = (u >> 52) & 0x7FF;
lib/std/math/frexp.zig+2-2
...@@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result {...@@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result {
108}108}
109109
110test "math.frexp" {110test "math.frexp" {
111 const a = frexp(f32(1.3));111 const a = frexp(@as(f32, 1.3));
112 const b = frexp32(1.3);112 const b = frexp32(1.3);
113 expect(a.significand == b.significand and a.exponent == b.exponent);113 expect(a.significand == b.significand and a.exponent == b.exponent);
114114
115 const c = frexp(f64(1.3));115 const c = frexp(@as(f64, 1.3));
116 const d = frexp64(1.3);116 const d = frexp64(1.3);
117 expect(c.significand == d.significand and c.exponent == d.exponent);117 expect(c.significand == d.significand and c.exponent == d.exponent);
118}118}
lib/std/math/hypot.zig+1-1
...@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {...@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {
56 yy *= 0x1.0p-90;56 yy *= 0x1.0p-90;
57 }57 }
5858
59 return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y));59 return z * math.sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y));
60}60}
6161
62fn sq(hi: *f64, lo: *f64, x: f64) void {62fn sq(hi: *f64, lo: *f64, x: f64) void {
lib/std/math/ilogb.zig+3-3
...@@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 {...@@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 {
26}26}
2727
28// NOTE: Should these be exposed publicly?28// NOTE: Should these be exposed publicly?
29const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1);29const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1);
30const fp_ilogb0 = fp_ilogbnan;30const fp_ilogb0 = fp_ilogbnan;
3131
32fn ilogb32(x: f32) i32 {32fn ilogb32(x: f32) i32 {
...@@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 {...@@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 {
101}101}
102102
103test "math.ilogb" {103test "math.ilogb" {
104 expect(ilogb(f32(0.2)) == ilogb32(0.2));104 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
105 expect(ilogb(f64(0.2)) == ilogb64(0.2));105 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
106}106}
107107
108test "math.ilogb32" {108test "math.ilogb32" {
lib/std/math/isfinite.zig+6-6
...@@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool {...@@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool {
26}26}
2727
28test "math.isFinite" {28test "math.isFinite" {
29 expect(isFinite(f16(0.0)));29 expect(isFinite(@as(f16, 0.0)));
30 expect(isFinite(f16(-0.0)));30 expect(isFinite(@as(f16, -0.0)));
31 expect(isFinite(f32(0.0)));31 expect(isFinite(@as(f32, 0.0)));
32 expect(isFinite(f32(-0.0)));32 expect(isFinite(@as(f32, -0.0)));
33 expect(isFinite(f64(0.0)));33 expect(isFinite(@as(f64, 0.0)));
34 expect(isFinite(f64(-0.0)));34 expect(isFinite(@as(f64, -0.0)));
35 expect(!isFinite(math.inf(f16)));35 expect(!isFinite(math.inf(f16)));
36 expect(!isFinite(-math.inf(f16)));36 expect(!isFinite(-math.inf(f16)));
37 expect(!isFinite(math.inf(f32)));37 expect(!isFinite(math.inf(f32)));
lib/std/math/isinf.zig+24-24
...@@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool {...@@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool {
74}74}
7575
76test "math.isInf" {76test "math.isInf" {
77 expect(!isInf(f16(0.0)));77 expect(!isInf(@as(f16, 0.0)));
78 expect(!isInf(f16(-0.0)));78 expect(!isInf(@as(f16, -0.0)));
79 expect(!isInf(f32(0.0)));79 expect(!isInf(@as(f32, 0.0)));
80 expect(!isInf(f32(-0.0)));80 expect(!isInf(@as(f32, -0.0)));
81 expect(!isInf(f64(0.0)));81 expect(!isInf(@as(f64, 0.0)));
82 expect(!isInf(f64(-0.0)));82 expect(!isInf(@as(f64, -0.0)));
83 expect(!isInf(f128(0.0)));83 expect(!isInf(@as(f128, 0.0)));
84 expect(!isInf(f128(-0.0)));84 expect(!isInf(@as(f128, -0.0)));
85 expect(isInf(math.inf(f16)));85 expect(isInf(math.inf(f16)));
86 expect(isInf(-math.inf(f16)));86 expect(isInf(-math.inf(f16)));
87 expect(isInf(math.inf(f32)));87 expect(isInf(math.inf(f32)));
...@@ -93,14 +93,14 @@ test "math.isInf" {...@@ -93,14 +93,14 @@ test "math.isInf" {
93}93}
9494
95test "math.isPositiveInf" {95test "math.isPositiveInf" {
96 expect(!isPositiveInf(f16(0.0)));96 expect(!isPositiveInf(@as(f16, 0.0)));
97 expect(!isPositiveInf(f16(-0.0)));97 expect(!isPositiveInf(@as(f16, -0.0)));
98 expect(!isPositiveInf(f32(0.0)));98 expect(!isPositiveInf(@as(f32, 0.0)));
99 expect(!isPositiveInf(f32(-0.0)));99 expect(!isPositiveInf(@as(f32, -0.0)));
100 expect(!isPositiveInf(f64(0.0)));100 expect(!isPositiveInf(@as(f64, 0.0)));
101 expect(!isPositiveInf(f64(-0.0)));101 expect(!isPositiveInf(@as(f64, -0.0)));
102 expect(!isPositiveInf(f128(0.0)));102 expect(!isPositiveInf(@as(f128, 0.0)));
103 expect(!isPositiveInf(f128(-0.0)));103 expect(!isPositiveInf(@as(f128, -0.0)));
104 expect(isPositiveInf(math.inf(f16)));104 expect(isPositiveInf(math.inf(f16)));
105 expect(!isPositiveInf(-math.inf(f16)));105 expect(!isPositiveInf(-math.inf(f16)));
106 expect(isPositiveInf(math.inf(f32)));106 expect(isPositiveInf(math.inf(f32)));
...@@ -112,14 +112,14 @@ test "math.isPositiveInf" {...@@ -112,14 +112,14 @@ test "math.isPositiveInf" {
112}112}
113113
114test "math.isNegativeInf" {114test "math.isNegativeInf" {
115 expect(!isNegativeInf(f16(0.0)));115 expect(!isNegativeInf(@as(f16, 0.0)));
116 expect(!isNegativeInf(f16(-0.0)));116 expect(!isNegativeInf(@as(f16, -0.0)));
117 expect(!isNegativeInf(f32(0.0)));117 expect(!isNegativeInf(@as(f32, 0.0)));
118 expect(!isNegativeInf(f32(-0.0)));118 expect(!isNegativeInf(@as(f32, -0.0)));
119 expect(!isNegativeInf(f64(0.0)));119 expect(!isNegativeInf(@as(f64, 0.0)));
120 expect(!isNegativeInf(f64(-0.0)));120 expect(!isNegativeInf(@as(f64, -0.0)));
121 expect(!isNegativeInf(f128(0.0)));121 expect(!isNegativeInf(@as(f128, 0.0)));
122 expect(!isNegativeInf(f128(-0.0)));122 expect(!isNegativeInf(@as(f128, -0.0)));
123 expect(!isNegativeInf(math.inf(f16)));123 expect(!isNegativeInf(math.inf(f16)));
124 expect(isNegativeInf(-math.inf(f16)));124 expect(isNegativeInf(-math.inf(f16)));
125 expect(!isNegativeInf(math.inf(f32)));125 expect(!isNegativeInf(math.inf(f32)));
lib/std/math/isnan.zig+4-4
...@@ -20,8 +20,8 @@ test "math.isNan" {...@@ -20,8 +20,8 @@ test "math.isNan" {
20 expect(isNan(math.nan(f32)));20 expect(isNan(math.nan(f32)));
21 expect(isNan(math.nan(f64)));21 expect(isNan(math.nan(f64)));
22 expect(isNan(math.nan(f128)));22 expect(isNan(math.nan(f128)));
23 expect(!isNan(f16(1.0)));23 expect(!isNan(@as(f16, 1.0)));
24 expect(!isNan(f32(1.0)));24 expect(!isNan(@as(f32, 1.0)));
25 expect(!isNan(f64(1.0)));25 expect(!isNan(@as(f64, 1.0)));
26 expect(!isNan(f128(1.0)));26 expect(!isNan(@as(f128, 1.0)));
27}27}
lib/std/math/isnormal.zig+6-6
...@@ -29,10 +29,10 @@ test "math.isNormal" {...@@ -29,10 +29,10 @@ test "math.isNormal" {
29 expect(!isNormal(math.nan(f16)));29 expect(!isNormal(math.nan(f16)));
30 expect(!isNormal(math.nan(f32)));30 expect(!isNormal(math.nan(f32)));
31 expect(!isNormal(math.nan(f64)));31 expect(!isNormal(math.nan(f64)));
32 expect(!isNormal(f16(0)));32 expect(!isNormal(@as(f16, 0)));
33 expect(!isNormal(f32(0)));33 expect(!isNormal(@as(f32, 0)));
34 expect(!isNormal(f64(0)));34 expect(!isNormal(@as(f64, 0)));
35 expect(isNormal(f16(1.0)));35 expect(isNormal(@as(f16, 1.0)));
36 expect(isNormal(f32(1.0)));36 expect(isNormal(@as(f32, 1.0)));
37 expect(isNormal(f64(1.0)));37 expect(isNormal(@as(f64, 1.0)));
38}38}
lib/std/math/ln.zig+5-5
...@@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) {...@@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) {
31 };31 };
32 },32 },
33 TypeId.ComptimeInt => {33 TypeId.ComptimeInt => {
34 return @typeOf(1)(math.floor(ln_64(f64(x))));34 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
35 },35 },
36 TypeId.Int => {36 TypeId.Int => {
37 return T(math.floor(ln_64(f64(x))));37 return T(math.floor(ln_64(@as(f64, x))));
38 },38 },
39 else => @compileError("ln not implemented for " ++ @typeName(T)),39 else => @compileError("ln not implemented for " ++ @typeName(T)),
40 }40 }
...@@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 {...@@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 {
132 hx += 0x3FF00000 - 0x3FE6A09E;132 hx += 0x3FF00000 - 0x3FE6A09E;
133 k += @intCast(i32, hx >> 20) - 0x3FF;133 k += @intCast(i32, hx >> 20) - 0x3FF;
134 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;134 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
135 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);135 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
136 x = @bitCast(f64, ix);136 x = @bitCast(f64, ix);
137137
138 const f = x - 1.0;138 const f = x - 1.0;
...@@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 {...@@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 {
149}149}
150150
151test "math.ln" {151test "math.ln" {
152 expect(ln(f32(0.2)) == ln_32(0.2));152 expect(ln(@as(f32, 0.2)) == ln_32(0.2));
153 expect(ln(f64(0.2)) == ln_64(0.2));153 expect(ln(@as(f64, 0.2)) == ln_64(0.2));
154}154}
155155
156test "math.ln32" {156test "math.ln32" {
lib/std/math/log.zig+5-5
...@@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
23 const float_base = math.lossyCast(f64, base);23 const float_base = math.lossyCast(f64, base);
24 switch (@typeId(T)) {24 switch (@typeId(T)) {
25 TypeId.ComptimeFloat => {25 TypeId.ComptimeFloat => {
26 return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base));26 return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
27 },27 },
28 TypeId.ComptimeInt => {28 TypeId.ComptimeInt => {
29 return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base)));29 return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
30 },30 },
31 builtin.TypeId.Int => {31 builtin.TypeId.Int => {
32 // TODO implement integer log without using float math32 // TODO implement integer log without using float math
...@@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
3535
36 builtin.TypeId.Float => {36 builtin.TypeId.Float => {
37 switch (T) {37 switch (T) {
38 f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)),38 f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),
39 f64 => return math.ln(x) / math.ln(float_base),39 f64 => return math.ln(x) / math.ln(float_base),
40 else => @compileError("log not implemented for " ++ @typeName(T)),40 else => @compileError("log not implemented for " ++ @typeName(T)),
41 }41 }
...@@ -67,6 +67,6 @@ test "math.log float_special" {...@@ -67,6 +67,6 @@ test "math.log float_special" {
67 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));67 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
68 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));68 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
6969
70 expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));70 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
71 expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));71 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
72}72}
lib/std/math/log10.zig+4-4
...@@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {...@@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
32 };32 };
33 },33 },
34 TypeId.ComptimeInt => {34 TypeId.ComptimeInt => {
35 return @typeOf(1)(math.floor(log10_64(f64(x))));35 return @typeOf(1)(math.floor(log10_64(@as(f64, x))));
36 },36 },
37 TypeId.Int => {37 TypeId.Int => {
38 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));38 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
...@@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 {
143 hx += 0x3FF00000 - 0x3FE6A09E;143 hx += 0x3FF00000 - 0x3FE6A09E;
144 k += @intCast(i32, hx >> 20) - 0x3FF;144 k += @intCast(i32, hx >> 20) - 0x3FF;
145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
146 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);146 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
147 x = @bitCast(f64, ix);147 x = @bitCast(f64, ix);
148148
149 const f = x - 1.0;149 const f = x - 1.0;
...@@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 {
158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
159 var hi = f - hfsq;159 var hi = f - hfsq;
160 var hii = @bitCast(u64, hi);160 var hii = @bitCast(u64, hi);
161 hii &= u64(maxInt(u64)) << 32;161 hii &= @as(u64, maxInt(u64)) << 32;
162 hi = @bitCast(f64, hii);162 hi = @bitCast(f64, hii);
163 const lo = f - hi - hfsq + s * (hfsq + R);163 const lo = f - hi - hfsq + s * (hfsq + R);
164164
...@@ -178,7 +178,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -178,7 +178,7 @@ pub fn log10_64(x_: f64) f64 {
178178
179test "math.log10" {179test "math.log10" {
180 testing.expect(log10(f32(0.2)) == log10_32(0.2));180 testing.expect(log10(f32(0.2)) == log10_32(0.2));
181 testing.expect(log10(f64(0.2)) == log10_64(0.2));181 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
182}182}
183183
184test "math.log10_32" {184test "math.log10_32" {
lib/std/math/log1p.zig+3-3
...@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {...@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {
166166
167 // u into [sqrt(2)/2, sqrt(2)]167 // u into [sqrt(2)/2, sqrt(2)]
168 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;168 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;
169 const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF);169 const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);
170 f = @bitCast(f64, iq) - 1;170 f = @bitCast(f64, iq) - 1;
171 }171 }
172172
...@@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 {...@@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 {
183}183}
184184
185test "math.log1p" {185test "math.log1p" {
186 expect(log1p(f32(0.0)) == log1p_32(0.0));186 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
187 expect(log1p(f64(0.0)) == log1p_64(0.0));187 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
188}188}
189189
190test "math.log1p_32" {190test "math.log1p_32" {
lib/std/math/log2.zig+4-4
...@@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 {...@@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 {
143 hx += 0x3FF00000 - 0x3FE6A09E;143 hx += 0x3FF00000 - 0x3FE6A09E;
144 k += @intCast(i32, hx >> 20) - 0x3FF;144 k += @intCast(i32, hx >> 20) - 0x3FF;
145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
146 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);146 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
147 x = @bitCast(f64, ix);147 x = @bitCast(f64, ix);
148148
149 const f = x - 1.0;149 const f = x - 1.0;
...@@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 {...@@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 {
158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
159 var hi = f - hfsq;159 var hi = f - hfsq;
160 var hii = @bitCast(u64, hi);160 var hii = @bitCast(u64, hi);
161 hii &= u64(maxInt(u64)) << 32;161 hii &= @as(u64, maxInt(u64)) << 32;
162 hi = @bitCast(f64, hii);162 hi = @bitCast(f64, hii);
163 const lo = f - hi - hfsq + s * (hfsq + R);163 const lo = f - hi - hfsq + s * (hfsq + R);
164164
...@@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 {...@@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 {
175}175}
176176
177test "math.log2" {177test "math.log2" {
178 expect(log2(f32(0.2)) == log2_32(0.2));178 expect(log2(@as(f32, 0.2)) == log2_32(0.2));
179 expect(log2(f64(0.2)) == log2_64(0.2));179 expect(log2(@as(f64, 0.2)) == log2_64(0.2));
180}180}
181181
182test "math.log2_32" {182test "math.log2_32" {
lib/std/math/modf.zig+4-4
...@@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result {...@@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result {
65 return result;65 return result;
66 }66 }
6767
68 const mask = u32(0x007FFFFF) >> @intCast(u5, e);68 const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
69 if (u & mask == 0) {69 if (u & mask == 0) {
70 result.ipart = x;70 result.ipart = x;
71 result.fpart = @bitCast(f32, us);71 result.fpart = @bitCast(f32, us);
...@@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result {...@@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result {
109 return result;109 return result;
110 }110 }
111111
112 const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e);112 const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e);
113 if (u & mask == 0) {113 if (u & mask == 0) {
114 result.ipart = x;114 result.ipart = x;
115 result.fpart = @bitCast(f64, us);115 result.fpart = @bitCast(f64, us);
...@@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result {...@@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result {
123}123}
124124
125test "math.modf" {125test "math.modf" {
126 const a = modf(f32(1.0));126 const a = modf(@as(f32, 1.0));
127 const b = modf32(1.0);127 const b = modf32(1.0);
128 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.128 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
129 expect(a.ipart == b.ipart and a.fpart == b.fpart);129 expect(a.ipart == b.ipart and a.fpart == b.fpart);
130130
131 const c = modf(f64(1.0));131 const c = modf(@as(f64, 1.0));
132 const d = modf64(1.0);132 const d = modf64(1.0);
133 expect(a.ipart == b.ipart and a.fpart == b.fpart);133 expect(a.ipart == b.ipart and a.fpart == b.fpart);
134}134}
lib/std/math/round.zig+2-2
...@@ -91,8 +91,8 @@ fn round64(x_: f64) f64 {...@@ -91,8 +91,8 @@ fn round64(x_: f64) f64 {
91}91}
9292
93test "math.round" {93test "math.round" {
94 expect(round(f32(1.3)) == round32(1.3));94 expect(round(@as(f32, 1.3)) == round32(1.3));
95 expect(round(f64(1.3)) == round64(1.3));95 expect(round(@as(f64, 1.3)) == round64(1.3));
96}96}
9797
98test "math.round32" {98test "math.round32" {
lib/std/math/scalbn.zig+2-2
...@@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 {...@@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 {
79}79}
8080
81test "math.scalbn" {81test "math.scalbn" {
82 expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));82 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
83 expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));83 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
84}84}
8585
86test "math.scalbn32" {86test "math.scalbn32" {
lib/std/math/signbit.zig+3-3
...@@ -29,9 +29,9 @@ fn signbit64(x: f64) bool {...@@ -29,9 +29,9 @@ fn signbit64(x: f64) bool {
29}29}
3030
31test "math.signbit" {31test "math.signbit" {
32 expect(signbit(f16(4.0)) == signbit16(4.0));32 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
33 expect(signbit(f32(4.0)) == signbit32(4.0));33 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
34 expect(signbit(f64(4.0)) == signbit64(4.0));34 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
35}35}
3636
37test "math.signbit16" {37test "math.signbit16" {
lib/std/math/sin.zig+3-3
...@@ -88,9 +88,9 @@ test "math.sin" {...@@ -88,9 +88,9 @@ test "math.sin" {
88 // TODO https://github.com/ziglang/zig/issues/328988 // TODO https://github.com/ziglang/zig/issues/3289
89 return error.SkipZigTest;89 return error.SkipZigTest;
90 }90 }
91 expect(sin(f32(0.0)) == sin_(f32, 0.0));91 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
92 expect(sin(f64(0.0)) == sin_(f64, 0.0));92 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(f64(2))) == math.sin(f64(2)));93 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
94}94}
9595
96test "math.sin32" {96test "math.sin32" {
lib/std/math/sinh.zig+2-2
...@@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 {...@@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 {
93}93}
9494
95test "math.sinh" {95test "math.sinh" {
96 expect(sinh(f32(1.5)) == sinh32(1.5));96 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
97 expect(sinh(f64(1.5)) == sinh64(1.5));97 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
98}98}
9999
100test "math.sinh32" {100test "math.sinh32" {
lib/std/math/sqrt.zig+3-3
...@@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ...@@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
32}32}
3333
34test "math.sqrt" {34test "math.sqrt" {
35 expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0));35 expect(sqrt(@as(f16, 0.0)) == @sqrt(f16, 0.0));
36 expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0));36 expect(sqrt(@as(f32, 0.0)) == @sqrt(f32, 0.0));
37 expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0));37 expect(sqrt(@as(f64, 0.0)) == @sqrt(f64, 0.0));
38}38}
3939
40test "math.sqrt16" {40test "math.sqrt16" {
lib/std/math/tan.zig+2-2
...@@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T {...@@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T {
75}75}
7676
77test "math.tan" {77test "math.tan" {
78 expect(tan(f32(0.0)) == tan_(f32, 0.0));78 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
79 expect(tan(f64(0.0)) == tan_(f64, 0.0));79 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
80}80}
8181
82test "math.tan32" {82test "math.tan32" {
lib/std/math/tanh.zig+2-2
...@@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 {...@@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 {
119}119}
120120
121test "math.tanh" {121test "math.tanh" {
122 expect(tanh(f32(1.5)) == tanh32(1.5));122 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
123 expect(tanh(f64(1.5)) == tanh64(1.5));123 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
124}124}
125125
126test "math.tanh32" {126test "math.tanh32" {
lib/std/math/trunc.zig+4-4
...@@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 {...@@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 {
36 e = 1;36 e = 1;
37 }37 }
3838
39 m = u32(maxInt(u32)) >> @intCast(u5, e);39 m = @as(u32, maxInt(u32)) >> @intCast(u5, e);
40 if (u & m == 0) {40 if (u & m == 0) {
41 return x;41 return x;
42 } else {42 } else {
...@@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 {...@@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 {
57 e = 1;57 e = 1;
58 }58 }
5959
60 m = u64(maxInt(u64)) >> @intCast(u6, e);60 m = @as(u64, maxInt(u64)) >> @intCast(u6, e);
61 if (u & m == 0) {61 if (u & m == 0) {
62 return x;62 return x;
63 } else {63 } else {
...@@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 {...@@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 {
67}67}
6868
69test "math.trunc" {69test "math.trunc" {
70 expect(trunc(f32(1.3)) == trunc32(1.3));70 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
71 expect(trunc(f64(1.3)) == trunc64(1.3));71 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
72}72}
7373
74test "math.trunc32" {74test "math.trunc32" {
lib/std/mem.zig+10-10
...@@ -118,7 +118,7 @@ pub const Allocator = struct {...@@ -118,7 +118,7 @@ pub const Allocator = struct {
118 } else @alignOf(T);118 } else @alignOf(T);
119119
120 if (n == 0) {120 if (n == 0) {
121 return ([*]align(a) T)(undefined)[0..0];121 return @as([*]align(a) T, undefined)[0..0];
122 }122 }
123123
124 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;124 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
...@@ -170,7 +170,7 @@ pub const Allocator = struct {...@@ -170,7 +170,7 @@ pub const Allocator = struct {
170 }170 }
171 if (new_n == 0) {171 if (new_n == 0) {
172 self.free(old_mem);172 self.free(old_mem);
173 return ([*]align(new_alignment) T)(undefined)[0..0];173 return @as([*]align(new_alignment) T, undefined)[0..0];
174 }174 }
175175
176 const old_byte_slice = @sliceToBytes(old_mem);176 const old_byte_slice = @sliceToBytes(old_mem);
...@@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin....@@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.
523 builtin.Endian.Little => {523 builtin.Endian.Little => {
524 const ShiftType = math.Log2Int(ReturnType);524 const ShiftType = math.Log2Int(ReturnType);
525 for (bytes) |b, index| {525 for (bytes) |b, index| {
526 result = result | (ReturnType(b) << @intCast(ShiftType, index * 8));526 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));
527 }527 }
528 },528 },
529 }529 }
...@@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type {...@@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type {
1332 if (comptime !trait.isSingleItemPtr(P))1332 if (comptime !trait.isSingleItemPtr(P))
1333 @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P));1333 @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P));
13341334
1335 const size = usize(@sizeOf(meta.Child(P)));1335 const size = @as(usize, @sizeOf(meta.Child(P)));
1336 const alignment = comptime meta.alignment(P);1336 const alignment = comptime meta.alignment(P);
13371337
1338 if (alignment == 0) {1338 if (alignment == 0) {
...@@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {...@@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {
1353}1353}
13541354
1355test "asBytes" {1355test "asBytes" {
1356 const deadbeef = u32(0xDEADBEEF);1356 const deadbeef = @as(u32, 0xDEADBEEF);
1357 const deadbeef_bytes = switch (builtin.endian) {1357 const deadbeef_bytes = switch (builtin.endian) {
1358 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",1358 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
1359 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1359 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
...@@ -1361,7 +1361,7 @@ test "asBytes" {...@@ -1361,7 +1361,7 @@ test "asBytes" {
13611361
1362 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));1362 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
13631363
1364 var codeface = u32(0xC0DEFACE);1364 var codeface = @as(u32, 0xC0DEFACE);
1365 for (asBytes(&codeface).*) |*b|1365 for (asBytes(&codeface).*) |*b|
1366 b.* = 0;1366 b.* = 0;
1367 testing.expect(codeface == 0);1367 testing.expect(codeface == 0);
...@@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {...@@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
1392}1392}
13931393
1394test "toBytes" {1394test "toBytes" {
1395 var my_bytes = toBytes(u32(0x12345678));1395 var my_bytes = toBytes(@as(u32, 0x12345678));
1396 switch (builtin.endian) {1396 switch (builtin.endian) {
1397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),1397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
1398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),1398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
...@@ -1406,7 +1406,7 @@ test "toBytes" {...@@ -1406,7 +1406,7 @@ test "toBytes" {
1406}1406}
14071407
1408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {1408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
1409 const size = usize(@sizeOf(T));1409 const size = @as(usize, @sizeOf(T));
14101410
1411 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) {1411 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) {
1412 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));1412 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
...@@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ...@@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ
1424}1424}
14251425
1426test "bytesAsValue" {1426test "bytesAsValue" {
1427 const deadbeef = u32(0xDEADBEEF);1427 const deadbeef = @as(u32, 0xDEADBEEF);
1428 const deadbeef_bytes = switch (builtin.endian) {1428 const deadbeef_bytes = switch (builtin.endian) {
1429 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",1429 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
1430 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1430 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
...@@ -1472,7 +1472,7 @@ test "bytesToValue" {...@@ -1472,7 +1472,7 @@ test "bytesToValue" {
1472 };1472 };
14731473
1474 const deadbeef = bytesToValue(u32, deadbeef_bytes);1474 const deadbeef = bytesToValue(u32, deadbeef_bytes);
1475 testing.expect(deadbeef == u32(0xDEADBEEF));1475 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
1476}1476}
14771477
1478fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {1478fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
lib/std/meta.zig+1-1
...@@ -505,7 +505,7 @@ test "std.meta.eql" {...@@ -505,7 +505,7 @@ test "std.meta.eql" {
505 const EU = struct {505 const EU = struct {
506 fn tst(err: bool) !u8 {506 fn tst(err: bool) !u8 {
507 if (err) return error.Error;507 if (err) return error.Error;
508 return u8(5);508 return @as(u8, 5);
509 }509 }
510 };510 };
511511
lib/std/meta/trait.zig+2-2
...@@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool {...@@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool {
327}327}
328328
329test "std.meta.trait.isConstPtr" {329test "std.meta.trait.isConstPtr" {
330 var t = u8(0);330 var t = @as(u8, 0);
331 const c = u8(0);331 const c = @as(u8, 0);
332 testing.expect(isConstPtr(*const @typeOf(t)));332 testing.expect(isConstPtr(*const @typeOf(t)));
333 testing.expect(isConstPtr(@typeOf(&c)));333 testing.expect(isConstPtr(@typeOf(&c)));
334 testing.expect(!isConstPtr(*@typeOf(t)));334 testing.expect(!isConstPtr(*@typeOf(t)));
lib/std/net.zig+7-7
...@@ -611,7 +611,7 @@ fn linuxLookupName(...@@ -611,7 +611,7 @@ fn linuxLookupName(
611 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.611 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
612 mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);612 mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
613 }613 }
614 if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;614 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
615 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;615 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
616 prefixlen = prefixMatch(sa6.addr, da6.addr);616 prefixlen = prefixMatch(sa6.addr, da6.addr);
617 } else |_| {}617 } else |_| {}
...@@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {...@@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
710 // address. However the definition of the source prefix length is710 // address. However the definition of the source prefix length is
711 // not clear and thus this limiting is not yet implemented.711 // not clear and thus this limiting is not yet implemented.
712 var i: u8 = 0;712 var i: u8 = 0;
713 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}713 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
714 return i;714 return i;
715}715}
716716
...@@ -1194,23 +1194,23 @@ fn dnsParse(...@@ -1194,23 +1194,23 @@ fn dnsParse(
1194 if (r.len < 12) return error.InvalidDnsPacket;1194 if (r.len < 12) return error.InvalidDnsPacket;
1195 if ((r[3] & 15) != 0) return;1195 if ((r[3] & 15) != 0) return;
1196 var p = r.ptr + 12;1196 var p = r.ptr + 12;
1197 var qdcount = r[4] * usize(256) + r[5];1197 var qdcount = r[4] * @as(usize, 256) + r[5];
1198 var ancount = r[6] * usize(256) + r[7];1198 var ancount = r[6] * @as(usize, 256) + r[7];
1199 if (qdcount + ancount > 64) return error.InvalidDnsPacket;1199 if (qdcount + ancount > 64) return error.InvalidDnsPacket;
1200 while (qdcount != 0) {1200 while (qdcount != 0) {
1201 qdcount -= 1;1201 qdcount -= 1;
1202 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;1202 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
1203 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)1203 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
1204 return error.InvalidDnsPacket;1204 return error.InvalidDnsPacket;
1205 p += usize(5) + @boolToInt(p[0] != 0);1205 p += @as(usize, 5) + @boolToInt(p[0] != 0);
1206 }1206 }
1207 while (ancount != 0) {1207 while (ancount != 0) {
1208 ancount -= 1;1208 ancount -= 1;
1209 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;1209 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
1210 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)1210 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
1211 return error.InvalidDnsPacket;1211 return error.InvalidDnsPacket;
1212 p += usize(1) + @boolToInt(p[0] != 0);1212 p += @as(usize, 1) + @boolToInt(p[0] != 0);
1213 const len = p[8] * usize(256) + p[9];1213 const len = p[8] * @as(usize, 256) + p[9];
1214 if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket;1214 if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket;
1215 try callback(ctx, p[1], p[10 .. 10 + len], r);1215 try callback(ctx, p[1], p[10 .. 10 + len], r);
1216 p += 10 + len;1216 p += 10 + len;
lib/std/os.zig+5-5
...@@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {...@@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
472472
473 var index: usize = 0;473 var index: usize = 0;
474 while (index < bytes.len) {474 while (index < bytes.len) {
475 const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len));475 const amt_to_write = math.min(bytes.len - index, @as(usize, max_bytes_len));
476 const rc = system.write(fd, bytes.ptr + index, amt_to_write);476 const rc = system.write(fd, bytes.ptr + index, amt_to_write);
477 switch (errno(rc)) {477 switch (errno(rc)) {
478 0 => {478 0 => {
...@@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool {...@@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool {
1526 }1526 }
1527 if (builtin.os == .linux) {1527 if (builtin.os == .linux) {
1528 var wsz: linux.winsize = undefined;1528 var wsz: linux.winsize = undefined;
1529 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;1529 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
1530 }1530 }
1531 unreachable;1531 unreachable;
1532}1532}
...@@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool {...@@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
1547 }1547 }
15481548
1549 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);1549 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
1550 const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];1550 const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];
1551 const name_wide = @bytesToSlice(u16, name_bytes);1551 const name_wide = @bytesToSlice(u16, name_bytes);
1552 return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or1552 return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
1553 mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;1553 mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
...@@ -2897,7 +2897,7 @@ pub fn res_mkquery(...@@ -2897,7 +2897,7 @@ pub fn res_mkquery(
2897 // Construct query template - ID will be filled later2897 // Construct query template - ID will be filled later
2898 var q: [280]u8 = undefined;2898 var q: [280]u8 = undefined;
2899 @memset(&q, 0, n);2899 @memset(&q, 0, n);
2900 q[2] = u8(op) * 8 + 1;2900 q[2] = @as(u8, op) * 8 + 1;
2901 q[5] = 1;2901 q[5] = 1;
2902 mem.copy(u8, q[13..], name);2902 mem.copy(u8, q[13..], name);
2903 var i: usize = 13;2903 var i: usize = 13;
...@@ -3143,7 +3143,7 @@ pub fn dn_expand(...@@ -3143,7 +3143,7 @@ pub fn dn_expand(
3143 // loop invariants: p<end, dest<dend3143 // loop invariants: p<end, dest<dend
3144 if ((p[0] & 0xc0) != 0) {3144 if ((p[0] & 0xc0) != 0) {
3145 if (p + 1 == end) return error.InvalidDnsPacket;3145 if (p + 1 == end) return error.InvalidDnsPacket;
3146 var j = ((p[0] & usize(0x3f)) << 8) | p[1];3146 var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
3147 if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr);3147 if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr);
3148 if (j >= msg.len) return error.InvalidDnsPacket;3148 if (j >= msg.len) return error.InvalidDnsPacket;
3149 p = msg.ptr + j;3149 p = msg.ptr + j;
lib/std/os/bits/dragonfly.zig+1-1
...@@ -315,7 +315,7 @@ pub const dirent = extern struct {...@@ -315,7 +315,7 @@ pub const dirent = extern struct {
315 d_name: [256]u8,315 d_name: [256]u8,
316316
317 pub fn reclen(self: dirent) u16 {317 pub fn reclen(self: dirent) u16 {
318 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7);318 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
319 }319 }
320};320};
321321
lib/std/os/bits/linux.zig+5-5
...@@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400;...@@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400;
559pub const EPOLLERR = 0x008;559pub const EPOLLERR = 0x008;
560pub const EPOLLHUP = 0x010;560pub const EPOLLHUP = 0x010;
561pub const EPOLLRDHUP = 0x2000;561pub const EPOLLRDHUP = 0x2000;
562pub const EPOLLEXCLUSIVE = (u32(1) << 28);562pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28);
563pub const EPOLLWAKEUP = (u32(1) << 29);563pub const EPOLLWAKEUP = (@as(u32, 1) << 29);
564pub const EPOLLONESHOT = (u32(1) << 30);564pub const EPOLLONESHOT = (@as(u32, 1) << 30);
565pub const EPOLLET = (u32(1) << 31);565pub const EPOLLET = (@as(u32, 1) << 31);
566566
567pub const CLOCK_REALTIME = 0;567pub const CLOCK_REALTIME = 0;
568pub const CLOCK_MONOTONIC = 1;568pub const CLOCK_MONOTONIC = 1;
...@@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool {...@@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool {
950}950}
951951
952pub fn CAP_TO_MASK(cap: u8) u32 {952pub fn CAP_TO_MASK(cap: u8) u32 {
953 return u32(1) << u5(cap & 31);953 return @as(u32, 1) << u5(cap & 31);
954}954}
955955
956pub fn CAP_TO_INDEX(cap: u8) u8 {956pub fn CAP_TO_INDEX(cap: u8) u8 {
lib/std/os/linux.zig+94-94
...@@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 {...@@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 {
4646
47pub fn dup2(old: i32, new: i32) usize {47pub fn dup2(old: i32, new: i32) usize {
48 if (@hasDecl(@This(), "SYS_dup2")) {48 if (@hasDecl(@This(), "SYS_dup2")) {
49 return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)));49 return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));
50 } else {50 } else {
51 if (old == new) {51 if (old == new) {
52 if (std.debug.runtime_safety) {52 if (std.debug.runtime_safety) {
53 const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD);53 const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD);
54 if (@bitCast(isize, rc) < 0) return rc;54 if (@bitCast(isize, rc) < 0) return rc;
55 }55 }
56 return @intCast(usize, old);56 return @intCast(usize, old);
57 } else {57 } else {
58 return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0);58 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);
59 }59 }
60 }60 }
61}61}
6262
63pub fn dup3(old: i32, new: i32, flags: u32) usize {63pub fn dup3(old: i32, new: i32, flags: u32) usize {
64 return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags);64 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
65}65}
6666
67// TODO https://github.com/ziglang/zig/issues/26567// TODO https://github.com/ziglang/zig/issues/265
...@@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {...@@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
102102
103// TODO https://github.com/ziglang/zig/issues/265103// TODO https://github.com/ziglang/zig/issues/265
104pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize {104pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize {
105 return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags);105 return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
106}106}
107107
108pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {108pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {
...@@ -120,7 +120,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {...@@ -120,7 +120,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
120pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {120pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
121 return syscall3(121 return syscall3(
122 SYS_getdents,122 SYS_getdents,
123 @bitCast(usize, isize(fd)),123 @bitCast(usize, @as(isize, fd)),
124 @ptrToInt(dirp),124 @ptrToInt(dirp),
125 std.math.min(len, maxInt(c_int)),125 std.math.min(len, maxInt(c_int)),
126 );126 );
...@@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {...@@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
129pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {129pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
130 return syscall3(130 return syscall3(
131 SYS_getdents64,131 SYS_getdents64,
132 @bitCast(usize, isize(fd)),132 @bitCast(usize, @as(isize, fd)),
133 @ptrToInt(dirp),133 @ptrToInt(dirp),
134 std.math.min(len, maxInt(c_int)),134 std.math.min(len, maxInt(c_int)),
135 );135 );
...@@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize {...@@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize {
140}140}
141141
142pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize {142pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize {
143 return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask);143 return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
144}144}
145145
146pub fn inotify_rm_watch(fd: i32, wd: i32) usize {146pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
147 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd)));147 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
148}148}
149149
150// TODO https://github.com/ziglang/zig/issues/265150// TODO https://github.com/ziglang/zig/issues/265
...@@ -152,13 +152,13 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz...@@ -152,13 +152,13 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz
152 if (@hasDecl(@This(), "SYS_readlink")) {152 if (@hasDecl(@This(), "SYS_readlink")) {
153 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);153 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
154 } else {154 } else {
155 return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);155 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
156 }156 }
157}157}
158158
159// TODO https://github.com/ziglang/zig/issues/265159// TODO https://github.com/ziglang/zig/issues/265
160pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {160pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
161 return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);161 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
162}162}
163163
164// TODO https://github.com/ziglang/zig/issues/265164// TODO https://github.com/ziglang/zig/issues/265
...@@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {...@@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
166 if (@hasDecl(@This(), "SYS_mkdir")) {166 if (@hasDecl(@This(), "SYS_mkdir")) {
167 return syscall2(SYS_mkdir, @ptrToInt(path), mode);167 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
168 } else {168 } else {
169 return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode);169 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
170 }170 }
171}171}
172172
173// TODO https://github.com/ziglang/zig/issues/265173// TODO https://github.com/ziglang/zig/issues/265
174pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize {174pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize {
175 return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode);175 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
176}176}
177177
178// TODO https://github.com/ziglang/zig/issues/265178// TODO https://github.com/ziglang/zig/issues/265
...@@ -194,7 +194,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -194,7 +194,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
194 if (@hasDecl(@This(), "SYS_mmap2")) {194 if (@hasDecl(@This(), "SYS_mmap2")) {
195 // Make sure the offset is also specified in multiples of page size195 // Make sure the offset is also specified in multiples of page size
196 if ((offset & (MMAP2_UNIT - 1)) != 0)196 if ((offset & (MMAP2_UNIT - 1)) != 0)
197 return @bitCast(usize, isize(-EINVAL));197 return @bitCast(usize, @as(isize, -EINVAL));
198198
199 return syscall6(199 return syscall6(
200 SYS_mmap2,200 SYS_mmap2,
...@@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
202 length,202 length,
203 prot,203 prot,
204 flags,204 flags,
205 @bitCast(usize, isize(fd)),205 @bitCast(usize, @as(isize, fd)),
206 @truncate(usize, offset / MMAP2_UNIT),206 @truncate(usize, offset / MMAP2_UNIT),
207 );207 );
208 } else {208 } else {
...@@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
212 length,212 length,
213 prot,213 prot,
214 flags,214 flags,
215 @bitCast(usize, isize(fd)),215 @bitCast(usize, @as(isize, fd)),
216 offset,216 offset,
217 );217 );
218 }218 }
...@@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {...@@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
249}249}
250250
251pub fn read(fd: i32, buf: [*]u8, count: usize) usize {251pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
252 return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);252 return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
253}253}
254254
255pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {255pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
256 return syscall5(256 return syscall5(
257 SYS_preadv,257 SYS_preadv,
258 @bitCast(usize, isize(fd)),258 @bitCast(usize, @as(isize, fd)),
259 @ptrToInt(iov),259 @ptrToInt(iov),
260 count,260 count,
261 @truncate(usize, offset),261 @truncate(usize, offset),
...@@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {...@@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
266pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {266pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
267 return syscall6(267 return syscall6(
268 SYS_preadv2,268 SYS_preadv2,
269 @bitCast(usize, isize(fd)),269 @bitCast(usize, @as(isize, fd)),
270 @ptrToInt(iov),270 @ptrToInt(iov),
271 count,271 count,
272 @truncate(usize, offset),272 @truncate(usize, offset),
...@@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k...@@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k
276}276}
277277
278pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {278pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
279 return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);279 return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
280}280}
281281
282pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {282pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
283 return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);283 return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
284}284}
285285
286pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {286pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
287 return syscall5(287 return syscall5(
288 SYS_pwritev,288 SYS_pwritev,
289 @bitCast(usize, isize(fd)),289 @bitCast(usize, @as(isize, fd)),
290 @ptrToInt(iov),290 @ptrToInt(iov),
291 count,291 count,
292 @truncate(usize, offset),292 @truncate(usize, offset),
...@@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us...@@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us
297pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {297pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
298 return syscall6(298 return syscall6(
299 SYS_pwritev2,299 SYS_pwritev2,
300 @bitCast(usize, isize(fd)),300 @bitCast(usize, @as(isize, fd)),
301 @ptrToInt(iov),301 @ptrToInt(iov),
302 count,302 count,
303 @truncate(usize, offset),303 @truncate(usize, offset),
...@@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize {...@@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize {
311 if (@hasDecl(@This(), "SYS_rmdir")) {311 if (@hasDecl(@This(), "SYS_rmdir")) {
312 return syscall1(SYS_rmdir, @ptrToInt(path));312 return syscall1(SYS_rmdir, @ptrToInt(path));
313 } else {313 } else {
314 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);314 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
315 }315 }
316}316}
317317
...@@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {...@@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
320 if (@hasDecl(@This(), "SYS_symlink")) {320 if (@hasDecl(@This(), "SYS_symlink")) {
321 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));321 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
322 } else {322 } else {
323 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));323 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
324 }324 }
325}325}
326326
327// TODO https://github.com/ziglang/zig/issues/265327// TODO https://github.com/ziglang/zig/issues/265
328pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize {328pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize {
329 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath));329 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
330}330}
331331
332// TODO https://github.com/ziglang/zig/issues/265332// TODO https://github.com/ziglang/zig/issues/265
333pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {333pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
334 return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);334 return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
335}335}
336336
337// TODO https://github.com/ziglang/zig/issues/265337// TODO https://github.com/ziglang/zig/issues/265
...@@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize {...@@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize {
339 if (@hasDecl(@This(), "SYS_access")) {339 if (@hasDecl(@This(), "SYS_access")) {
340 return syscall2(SYS_access, @ptrToInt(path), mode);340 return syscall2(SYS_access, @ptrToInt(path), mode);
341 } else {341 } else {
342 return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0);342 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
343 }343 }
344}344}
345345
346// TODO https://github.com/ziglang/zig/issues/265346// TODO https://github.com/ziglang/zig/issues/265
347pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {347pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
348 return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags);348 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
349}349}
350350
351pub fn pipe(fd: *[2]i32) usize {351pub fn pipe(fd: *[2]i32) usize {
...@@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {...@@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {
363}363}
364364
365pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {365pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
366 return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);366 return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
367}367}
368368
369pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {369pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
370 return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);370 return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
371}371}
372372
373// TODO https://github.com/ziglang/zig/issues/265373// TODO https://github.com/ziglang/zig/issues/265
...@@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {...@@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {
375 if (@hasDecl(@This(), "SYS_rename")) {375 if (@hasDecl(@This(), "SYS_rename")) {
376 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));376 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
377 } else if (@hasDecl(@This(), "SYS_renameat")) {377 } else if (@hasDecl(@This(), "SYS_renameat")) {
378 return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));378 return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
379 } else {379 } else {
380 return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0);380 return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
381 }381 }
382}382}
383383
...@@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
385 if (@hasDecl(@This(), "SYS_renameat")) {385 if (@hasDecl(@This(), "SYS_renameat")) {
386 return syscall4(386 return syscall4(
387 SYS_renameat,387 SYS_renameat,
388 @bitCast(usize, isize(oldfd)),388 @bitCast(usize, @as(isize, oldfd)),
389 @ptrToInt(old),389 @ptrToInt(old),
390 @bitCast(usize, isize(newfd)),390 @bitCast(usize, @as(isize, newfd)),
391 @ptrToInt(new),391 @ptrToInt(new),
392 );392 );
393 } else {393 } else {
394 return syscall5(394 return syscall5(
395 SYS_renameat2,395 SYS_renameat2,
396 @bitCast(usize, isize(oldfd)),396 @bitCast(usize, @as(isize, oldfd)),
397 @ptrToInt(old),397 @ptrToInt(old),
398 @bitCast(usize, isize(newfd)),398 @bitCast(usize, @as(isize, newfd)),
399 @ptrToInt(new),399 @ptrToInt(new),
400 0,400 0,
401 );401 );
...@@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
406pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize {406pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize {
407 return syscall5(407 return syscall5(
408 SYS_renameat2,408 SYS_renameat2,
409 @bitCast(usize, isize(oldfd)),409 @bitCast(usize, @as(isize, oldfd)),
410 @ptrToInt(oldpath),410 @ptrToInt(oldpath),
411 @bitCast(usize, isize(newfd)),411 @bitCast(usize, @as(isize, newfd)),
412 @ptrToInt(newpath),412 @ptrToInt(newpath),
413 flags,413 flags,
414 );414 );
...@@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {...@@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
421 } else {421 } else {
422 return syscall4(422 return syscall4(
423 SYS_openat,423 SYS_openat,
424 @bitCast(usize, isize(AT_FDCWD)),424 @bitCast(usize, @as(isize, AT_FDCWD)),
425 @ptrToInt(path),425 @ptrToInt(path),
426 flags,426 flags,
427 perm,427 perm,
...@@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {...@@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {
437// TODO https://github.com/ziglang/zig/issues/265437// TODO https://github.com/ziglang/zig/issues/265
438pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize {438pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize {
439 // dirfd could be negative, for example AT_FDCWD is -100439 // dirfd could be negative, for example AT_FDCWD is -100
440 return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode);440 return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
441}441}
442442
443/// See also `clone` (from the arch-specific include)443/// See also `clone` (from the arch-specific include)
...@@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {...@@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
451}451}
452452
453pub fn close(fd: i32) usize {453pub fn close(fd: i32) usize {
454 return syscall1(SYS_close, @bitCast(usize, isize(fd)));454 return syscall1(SYS_close, @bitCast(usize, @as(isize, fd)));
455}455}
456456
457/// Can only be called on 32 bit systems. For 64 bit see `lseek`.457/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
458pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {458pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
459 return syscall5(459 return syscall5(
460 SYS__llseek,460 SYS__llseek,
461 @bitCast(usize, isize(fd)),461 @bitCast(usize, @as(isize, fd)),
462 @truncate(usize, offset >> 32),462 @truncate(usize, offset >> 32),
463 @truncate(usize, offset),463 @truncate(usize, offset),
464 @ptrToInt(result),464 @ptrToInt(result),
...@@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {...@@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
468468
469/// Can only be called on 64 bit systems. For 32 bit see `llseek`.469/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
470pub fn lseek(fd: i32, offset: i64, whence: usize) usize {470pub fn lseek(fd: i32, offset: i64, whence: usize) usize {
471 return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence);471 return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);
472}472}
473473
474pub fn exit(status: i32) noreturn {474pub fn exit(status: i32) noreturn {
475 _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));475 _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status)));
476 unreachable;476 unreachable;
477}477}
478478
479pub fn exit_group(status: i32) noreturn {479pub fn exit_group(status: i32) noreturn {
480 _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status)));480 _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status)));
481 unreachable;481 unreachable;
482}482}
483483
...@@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {...@@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
486}486}
487487
488pub fn kill(pid: i32, sig: i32) usize {488pub fn kill(pid: i32, sig: i32) usize {
489 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));489 return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
490}490}
491491
492// TODO https://github.com/ziglang/zig/issues/265492// TODO https://github.com/ziglang/zig/issues/265
...@@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize {...@@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize {
494 if (@hasDecl(@This(), "SYS_unlink")) {494 if (@hasDecl(@This(), "SYS_unlink")) {
495 return syscall1(SYS_unlink, @ptrToInt(path));495 return syscall1(SYS_unlink, @ptrToInt(path));
496 } else {496 } else {
497 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0);497 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
498 }498 }
499}499}
500500
501// TODO https://github.com/ziglang/zig/issues/265501// TODO https://github.com/ziglang/zig/issues/265
502pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize {502pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize {
503 return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags);503 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
504}504}
505505
506pub fn waitpid(pid: i32, status: *u32, flags: u32) usize {506pub fn waitpid(pid: i32, status: *u32, flags: u32) usize {
507 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0);507 return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
508}508}
509509
510var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);510var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);
...@@ -519,12 +519,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {...@@ -519,12 +519,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
519 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);519 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
520 const rc = f(clk_id, tp);520 const rc = f(clk_id, tp);
521 switch (rc) {521 switch (rc) {
522 0, @bitCast(usize, isize(-EINVAL)) => return rc,522 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
523 else => {},523 else => {},
524 }524 }
525 }525 }
526 }526 }
527 return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));527 return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
528}528}
529529
530extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {530extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {
...@@ -537,15 +537,15 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {...@@ -537,15 +537,15 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {
537 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);537 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
538 return f(clk, ts);538 return f(clk, ts);
539 }539 }
540 return @bitCast(usize, isize(-ENOSYS));540 return @bitCast(usize, @as(isize, -ENOSYS));
541}541}
542542
543pub fn clock_getres(clk_id: i32, tp: *timespec) usize {543pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
544 return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));544 return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
545}545}
546546
547pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {547pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
548 return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));548 return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
549}549}
550550
551pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {551pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
...@@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize {...@@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize {
594594
595pub fn getuid() u32 {595pub fn getuid() u32 {
596 if (@hasDecl(@This(), "SYS_getuid32")) {596 if (@hasDecl(@This(), "SYS_getuid32")) {
597 return u32(syscall0(SYS_getuid32));597 return @as(u32, syscall0(SYS_getuid32));
598 } else {598 } else {
599 return u32(syscall0(SYS_getuid));599 return @as(u32, syscall0(SYS_getuid));
600 }600 }
601}601}
602602
603pub fn getgid() u32 {603pub fn getgid() u32 {
604 if (@hasDecl(@This(), "SYS_getgid32")) {604 if (@hasDecl(@This(), "SYS_getgid32")) {
605 return u32(syscall0(SYS_getgid32));605 return @as(u32, syscall0(SYS_getgid32));
606 } else {606 } else {
607 return u32(syscall0(SYS_getgid));607 return @as(u32, syscall0(SYS_getgid));
608 }608 }
609}609}
610610
611pub fn geteuid() u32 {611pub fn geteuid() u32 {
612 if (@hasDecl(@This(), "SYS_geteuid32")) {612 if (@hasDecl(@This(), "SYS_geteuid32")) {
613 return u32(syscall0(SYS_geteuid32));613 return @as(u32, syscall0(SYS_geteuid32));
614 } else {614 } else {
615 return u32(syscall0(SYS_geteuid));615 return @as(u32, syscall0(SYS_geteuid));
616 }616 }
617}617}
618618
619pub fn getegid() u32 {619pub fn getegid() u32 {
620 if (@hasDecl(@This(), "SYS_getegid32")) {620 if (@hasDecl(@This(), "SYS_getegid32")) {
621 return u32(syscall0(SYS_getegid32));621 return @as(u32, syscall0(SYS_getegid32));
622 } else {622 } else {
623 return u32(syscall0(SYS_getegid));623 return @as(u32, syscall0(SYS_getegid));
624 }624 }
625}625}
626626
...@@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {...@@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
743}743}
744744
745pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {745pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
746 return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));746 return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
747}747}
748748
749pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {749pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
750 return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));750 return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
751}751}
752752
753pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {753pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
...@@ -755,15 +755,15 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {...@@ -755,15 +755,15 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
755}755}
756756
757pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {757pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
758 return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));758 return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
759}759}
760760
761pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {761pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
762 return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));762 return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
763}763}
764764
765pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {765pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
766 return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags);766 return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
767}767}
768768
769pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {769pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {
...@@ -781,7 +781,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -781,7 +781,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
781 // batch-send all messages up to the current message781 // batch-send all messages up to the current message
782 if (next_unsent < i) {782 if (next_unsent < i) {
783 const batch_size = i - next_unsent;783 const batch_size = i - next_unsent;
784 const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);784 const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
785 if (getErrno(r) != 0) return next_unsent;785 if (getErrno(r) != 0) return next_unsent;
786 if (r < batch_size) return next_unsent + r;786 if (r < batch_size) return next_unsent + r;
787 }787 }
...@@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
797 }797 }
798 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)798 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
799 const batch_size = kvlen - next_unsent;799 const batch_size = kvlen - next_unsent;
800 const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);800 const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
801 if (getErrno(r) != 0) return r;801 if (getErrno(r) != 0) return r;
802 return next_unsent + r;802 return next_unsent + r;
803 }803 }
804 return kvlen;804 return kvlen;
805 }805 }
806 return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags);806 return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags);
807}807}
808808
809pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {809pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
810 return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len);810 return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
811}811}
812812
813pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {813pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
814 return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags);814 return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
815}815}
816816
817pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {817pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
818 return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));818 return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
819}819}
820820
821pub fn shutdown(fd: i32, how: i32) usize {821pub fn shutdown(fd: i32, how: i32) usize {
822 return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how)));822 return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
823}823}
824824
825pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {825pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
826 return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len));826 return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
827}827}
828828
829pub fn listen(fd: i32, backlog: u32) usize {829pub fn listen(fd: i32, backlog: u32) usize {
830 return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog);830 return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog);
831}831}
832832
833pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {833pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
834 return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));834 return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
835}835}
836836
837pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {837pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
...@@ -843,14 +843,14 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {...@@ -843,14 +843,14 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
843}843}
844844
845pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {845pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {
846 return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags);846 return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
847}847}
848848
849pub fn fstat(fd: i32, stat_buf: *Stat) usize {849pub fn fstat(fd: i32, stat_buf: *Stat) usize {
850 if (@hasDecl(@This(), "SYS_fstat64")) {850 if (@hasDecl(@This(), "SYS_fstat64")) {
851 return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));851 return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
852 } else {852 } else {
853 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));853 return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
854 }854 }
855}855}
856856
...@@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {...@@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
875// TODO https://github.com/ziglang/zig/issues/265875// TODO https://github.com/ziglang/zig/issues/265
876pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {876pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
877 if (@hasDecl(@This(), "SYS_fstatat64")) {877 if (@hasDecl(@This(), "SYS_fstatat64")) {
878 return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);878 return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
879 } else {879 } else {
880 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);880 return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
881 }881 }
882}882}
883883
...@@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S...@@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
885 if (@hasDecl(@This(), "SYS_statx")) {885 if (@hasDecl(@This(), "SYS_statx")) {
886 return syscall5(886 return syscall5(
887 SYS_statx,887 SYS_statx,
888 @bitCast(usize, isize(dirfd)),888 @bitCast(usize, @as(isize, dirfd)),
889 @ptrToInt(path),889 @ptrToInt(path),
890 flags,890 flags,
891 mask,891 mask,
892 @ptrToInt(statx_buf),892 @ptrToInt(statx_buf),
893 );893 );
894 }894 }
895 return @bitCast(usize, isize(-ENOSYS));895 return @bitCast(usize, @as(isize, -ENOSYS));
896}896}
897897
898// TODO https://github.com/ziglang/zig/issues/265898// TODO https://github.com/ziglang/zig/issues/265
...@@ -959,7 +959,7 @@ pub fn sched_yield() usize {...@@ -959,7 +959,7 @@ pub fn sched_yield() usize {
959}959}
960960
961pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize {961pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize {
962 const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set));962 const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set));
963 if (@bitCast(isize, rc) < 0) return rc;963 if (@bitCast(isize, rc) < 0) return rc;
964 if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);964 if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
965 return 0;965 return 0;
...@@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize {...@@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize {
974}974}
975975
976pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {976pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
977 return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev));977 return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev));
978}978}
979979
980pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {980pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
...@@ -984,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout...@@ -984,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout
984pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {984pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {
985 return syscall6(985 return syscall6(
986 SYS_epoll_pwait,986 SYS_epoll_pwait,
987 @bitCast(usize, isize(epoll_fd)),987 @bitCast(usize, @as(isize, epoll_fd)),
988 @ptrToInt(events),988 @ptrToInt(events),
989 @intCast(usize, maxevents),989 @intCast(usize, maxevents),
990 @bitCast(usize, isize(timeout)),990 @bitCast(usize, @as(isize, timeout)),
991 @ptrToInt(sigmask),991 @ptrToInt(sigmask),
992 @sizeOf(sigset_t),992 @sizeOf(sigset_t),
993 );993 );
...@@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize {...@@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
998}998}
999999
1000pub fn timerfd_create(clockid: i32, flags: u32) usize {1000pub fn timerfd_create(clockid: i32, flags: u32) usize {
1001 return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags);1001 return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
1002}1002}
10031003
1004pub const itimerspec = extern struct {1004pub const itimerspec = extern struct {
...@@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct {...@@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct {
1007};1007};
10081008
1009pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {1009pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1010 return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value));1010 return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value));
1011}1011}
10121012
1013pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {1013pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1014 return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));1014 return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
1015}1015}
10161016
1017pub fn unshare(flags: usize) usize {1017pub fn unshare(flags: usize) usize {
...@@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {...@@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
1096}1096}
10971097
1098pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {1098pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
1099 return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);1099 return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
1100}1100}
11011101
1102pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {1102pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {
1103 return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args);1103 return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
1104}1104}
11051105
1106test "" {1106test "" {
lib/std/os/linux/arm-eabi.zig+2-2
...@@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize {...@@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize {
100pub nakedcc fn restore() void {100pub nakedcc fn restore() void {
101 return asm volatile ("svc #0"101 return asm volatile ("svc #0"
102 :102 :
103 : [number] "{r7}" (usize(SYS_sigreturn))103 : [number] "{r7}" (@as(usize, SYS_sigreturn))
104 : "memory"104 : "memory"
105 );105 );
106}106}
...@@ -108,7 +108,7 @@ pub nakedcc fn restore() void {...@@ -108,7 +108,7 @@ pub nakedcc fn restore() void {
108pub nakedcc fn restore_rt() void {108pub nakedcc fn restore_rt() void {
109 return asm volatile ("svc #0"109 return asm volatile ("svc #0"
110 :110 :
111 : [number] "{r7}" (usize(SYS_rt_sigreturn))111 : [number] "{r7}" (@as(usize, SYS_rt_sigreturn))
112 : "memory"112 : "memory"
113 );113 );
114}114}
lib/std/os/linux/arm64.zig+1-1
...@@ -93,7 +93,7 @@ pub const restore = restore_rt;...@@ -93,7 +93,7 @@ pub const restore = restore_rt;
93pub nakedcc fn restore_rt() void {93pub nakedcc fn restore_rt() void {
94 return asm volatile ("svc #0"94 return asm volatile ("svc #0"
95 :95 :
96 : [number] "{x8}" (usize(SYS_rt_sigreturn))96 : [number] "{x8}" (@as(usize, SYS_rt_sigreturn))
97 : "memory", "cc"97 : "memory", "cc"
98 );98 );
99}99}
lib/std/os/linux/mipsel.zig+3-3
...@@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize {...@@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
26 \\ sw $3, 4($4)26 \\ sw $3, 4($4)
27 \\ 2:27 \\ 2:
28 : [ret] "={$2}" (-> usize)28 : [ret] "={$2}" (-> usize)
29 : [number] "{$2}" (usize(SYS_pipe))29 : [number] "{$2}" (@as(usize, SYS_pipe))
30 : "memory", "cc", "$7"30 : "memory", "cc", "$7"
31 );31 );
32}32}
...@@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a...@@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
147pub nakedcc fn restore() void {147pub nakedcc fn restore() void {
148 return asm volatile ("syscall"148 return asm volatile ("syscall"
149 :149 :
150 : [number] "{$2}" (usize(SYS_sigreturn))150 : [number] "{$2}" (@as(usize, SYS_sigreturn))
151 : "memory", "cc", "$7"151 : "memory", "cc", "$7"
152 );152 );
153}153}
...@@ -155,7 +155,7 @@ pub nakedcc fn restore() void {...@@ -155,7 +155,7 @@ pub nakedcc fn restore() void {
155pub nakedcc fn restore_rt() void {155pub nakedcc fn restore_rt() void {
156 return asm volatile ("syscall"156 return asm volatile ("syscall"
157 :157 :
158 : [number] "{$2}" (usize(SYS_rt_sigreturn))158 : [number] "{$2}" (@as(usize, SYS_rt_sigreturn))
159 : "memory", "cc", "$7"159 : "memory", "cc", "$7"
160 );160 );
161}161}
lib/std/os/linux/riscv64.zig+1-1
...@@ -92,7 +92,7 @@ pub const restore = restore_rt;...@@ -92,7 +92,7 @@ pub const restore = restore_rt;
92pub nakedcc fn restore_rt() void {92pub nakedcc fn restore_rt() void {
93 return asm volatile ("ecall"93 return asm volatile ("ecall"
94 :94 :
95 : [number] "{x17}" (usize(SYS_rt_sigreturn))95 : [number] "{x17}" (@as(usize, SYS_rt_sigreturn))
96 : "memory"96 : "memory"
97 );97 );
98}98}
lib/std/os/linux/vdso.zig+2-2
...@@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6262
63 var i: usize = 0;63 var i: usize = 0;
64 while (i < hashtab[1]) : (i += 1) {64 while (i < hashtab[1]) : (i += 1) {
65 if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;65 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;66 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
67 if (0 == syms[i].st_shndx) continue;67 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;68 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;
69 if (maybe_versym) |versym| {69 if (maybe_versym) |versym| {
lib/std/os/linux/x86_64.zig+1-1
...@@ -93,7 +93,7 @@ pub const restore = restore_rt;...@@ -93,7 +93,7 @@ pub const restore = restore_rt;
93pub nakedcc fn restore_rt() void {93pub nakedcc fn restore_rt() void {
94 return asm volatile ("syscall"94 return asm volatile ("syscall"
95 :95 :
96 : [number] "{rax}" (usize(SYS_rt_sigreturn))96 : [number] "{rax}" (@as(usize, SYS_rt_sigreturn))
97 : "rcx", "r11", "memory"97 : "rcx", "r11", "memory"
98 );98 );
99}99}
lib/std/os/test.zig+1-1
...@@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {...@@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {
172172
173 var counter = data.?;173 var counter = data.?;
174 // Count how many libraries are loaded174 // Count how many libraries are loaded
175 counter.* += usize(1);175 counter.* += @as(usize, 1);
176176
177 // The image should contain at least a PT_LOAD segment177 // The image should contain at least a PT_LOAD segment
178 if (info.dlpi_phnum < 1) return -1;178 if (info.dlpi_phnum < 1) return -1;
lib/std/os/windows.zig+1-1
...@@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 {...@@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 {
801}801}
802802
803pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 {803pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 {
804 const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime);804 const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime);
805 return fromSysTime(hns);805 return fromSysTime(hns);
806}806}
807807
lib/std/os/zen.zig+2-2
...@@ -138,7 +138,7 @@ pub const Syscall = enum(usize) {...@@ -138,7 +138,7 @@ pub const Syscall = enum(usize) {
138////////////////////138////////////////////
139139
140pub fn exit(status: i32) noreturn {140pub fn exit(status: i32) noreturn {
141 _ = syscall1(Syscall.exit, @bitCast(usize, isize(status)));141 _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status)));
142 unreachable;142 unreachable;
143}143}
144144
...@@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {...@@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
167}167}
168168
169pub fn createThread(function: fn () void) u16 {169pub fn createThread(function: fn () void) u16 {
170 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));170 return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function)));
171}171}
172172
173/////////////////////////173/////////////////////////
lib/std/packed_int_array.zig+9-9
...@@ -331,7 +331,7 @@ test "PackedIntArray" {...@@ -331,7 +331,7 @@ test "PackedIntArray" {
331 var data = PackedArray(undefined);331 var data = PackedArray(undefined);
332332
333 //write values, counting up333 //write values, counting up
334 var i = usize(0);334 var i = @as(usize, 0);
335 var count = I(0);335 var count = I(0);
336 while (i < data.len()) : (i += 1) {336 while (i < data.len()) : (i += 1) {
337 data.set(i, count);337 data.set(i, count);
...@@ -352,7 +352,7 @@ test "PackedIntArray" {...@@ -352,7 +352,7 @@ test "PackedIntArray" {
352test "PackedIntArray init" {352test "PackedIntArray init" {
353 const PackedArray = PackedIntArray(u3, 8);353 const PackedArray = PackedIntArray(u3, 8);
354 var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });354 var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
355 var i = usize(0);355 var i = @as(usize, 0);
356 while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i);356 while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i);
357}357}
358358
...@@ -375,7 +375,7 @@ test "PackedIntSlice" {...@@ -375,7 +375,7 @@ test "PackedIntSlice" {
375 var data = P.init(&buffer, int_count);375 var data = P.init(&buffer, int_count);
376376
377 //write values, counting up377 //write values, counting up
378 var i = usize(0);378 var i = @as(usize, 0);
379 var count = I(0);379 var count = I(0);
380 while (i < data.len()) : (i += 1) {380 while (i < data.len()) : (i += 1) {
381 data.set(i, count);381 data.set(i, count);
...@@ -406,7 +406,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {...@@ -406,7 +406,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
406406
407 const limit = (1 << bits);407 const limit = (1 << bits);
408408
409 var i = usize(0);409 var i = @as(usize, 0);
410 while (i < packed_array.len()) : (i += 1) {410 while (i < packed_array.len()) : (i += 1) {
411 packed_array.set(i, @intCast(Int, i % limit));411 packed_array.set(i, @intCast(Int, i % limit));
412 }412 }
...@@ -466,7 +466,7 @@ test "PackedIntSlice accumulating bit offsets" {...@@ -466,7 +466,7 @@ test "PackedIntSlice accumulating bit offsets" {
466 var packed_array = PackedArray(undefined);466 var packed_array = PackedArray(undefined);
467467
468 var packed_slice = packed_array.slice(0, packed_array.len());468 var packed_slice = packed_array.slice(0, packed_array.len());
469 var i = usize(0);469 var i = @as(usize, 0);
470 while (i < packed_array.len() - 1) : (i += 1) {470 while (i < packed_array.len() - 1) : (i += 1) {
471 packed_slice = packed_slice.slice(1, packed_slice.len());471 packed_slice = packed_slice.slice(1, packed_slice.len());
472 }472 }
...@@ -476,7 +476,7 @@ test "PackedIntSlice accumulating bit offsets" {...@@ -476,7 +476,7 @@ test "PackedIntSlice accumulating bit offsets" {
476 var packed_array = PackedArray(undefined);476 var packed_array = PackedArray(undefined);
477477
478 var packed_slice = packed_array.slice(0, packed_array.len());478 var packed_slice = packed_array.slice(0, packed_array.len());
479 var i = usize(0);479 var i = @as(usize, 0);
480 while (i < packed_array.len() - 1) : (i += 1) {480 while (i < packed_array.len() - 1) : (i += 1) {
481 packed_slice = packed_slice.slice(1, packed_slice.len());481 packed_slice = packed_slice.slice(1, packed_slice.len());
482 }482 }
...@@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" {
493 var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9);493 var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9);
494 const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3);494 const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3);
495495
496 var i = usize(0);496 var i = @as(usize, 0);
497 while (i < packed_slice_cast_2.len()) : (i += 1) {497 while (i < packed_slice_cast_2.len()) : (i += 1) {
498 const val = switch (builtin.endian) {498 const val = switch (builtin.endian) {
499 .Big => 0b01,499 .Big => 0b01,
...@@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" {...@@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" {
541 testing.expect(packed_array_be.bytes[0] == 0b00000001);541 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542 testing.expect(packed_array_be.bytes[1] == 0b00100011);542 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543543
544 var i = usize(0);544 var i = @as(usize, 0);
545 while (i < packed_array_be.len()) : (i += 1) {545 while (i < packed_array_be.len()) : (i += 1) {
546 testing.expect(packed_array_be.get(i) == i);546 testing.expect(packed_array_be.get(i) == i);
547 }547 }
...@@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" {...@@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" {
579 testing.expect(packed_array_be.bytes[3] == 0b00000001);579 testing.expect(packed_array_be.bytes[3] == 0b00000001);
580 testing.expect(packed_array_be.bytes[4] == 0b00000000);580 testing.expect(packed_array_be.bytes[4] == 0b00000000);
581581
582 var i = usize(0);582 var i = @as(usize, 0);
583 while (i < packed_array_be.len()) : (i += 1) {583 while (i < packed_array_be.len()) : (i += 1) {
584 testing.expect(packed_array_be.get(i) == i);584 testing.expect(packed_array_be.get(i) == i);
585 }585 }
lib/std/pdb.zig+1-1
...@@ -532,7 +532,7 @@ const Msf = struct {...@@ -532,7 +532,7 @@ const Msf = struct {
532 const stream_sizes = try allocator.alloc(u32, stream_count);532 const stream_sizes = try allocator.alloc(u32, stream_count);
533 defer allocator.free(stream_sizes);533 defer allocator.free(stream_sizes);
534534
535 // Microsoft's implementation uses u32(-1) for inexistant streams.535 // Microsoft's implementation uses @as(u32, -1) for inexistant streams.
536 // These streams are not used, but still participate in the file536 // These streams are not used, but still participate in the file
537 // and must be taken into account when resolving stream indices.537 // and must be taken into account when resolving stream indices.
538 const Nil = 0xFFFFFFFF;538 const Nil = 0xFFFFFFFF;
lib/std/priority_queue.zig+30-30
...@@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" {...@@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" {
236 try queue.add(23);236 try queue.add(23);
237 try queue.add(25);237 try queue.add(25);
238 try queue.add(13);238 try queue.add(13);
239 expectEqual(u32(7), queue.remove());239 expectEqual(@as(u32, 7), queue.remove());
240 expectEqual(u32(12), queue.remove());240 expectEqual(@as(u32, 12), queue.remove());
241 expectEqual(u32(13), queue.remove());241 expectEqual(@as(u32, 13), queue.remove());
242 expectEqual(u32(23), queue.remove());242 expectEqual(@as(u32, 23), queue.remove());
243 expectEqual(u32(25), queue.remove());243 expectEqual(@as(u32, 25), queue.remove());
244 expectEqual(u32(54), queue.remove());244 expectEqual(@as(u32, 54), queue.remove());
245}245}
246246
247test "std.PriorityQueue: add and remove same min heap" {247test "std.PriorityQueue: add and remove same min heap" {
...@@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" {...@@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" {
254 try queue.add(2);254 try queue.add(2);
255 try queue.add(1);255 try queue.add(1);
256 try queue.add(1);256 try queue.add(1);
257 expectEqual(u32(1), queue.remove());257 expectEqual(@as(u32, 1), queue.remove());
258 expectEqual(u32(1), queue.remove());258 expectEqual(@as(u32, 1), queue.remove());
259 expectEqual(u32(1), queue.remove());259 expectEqual(@as(u32, 1), queue.remove());
260 expectEqual(u32(1), queue.remove());260 expectEqual(@as(u32, 1), queue.remove());
261 expectEqual(u32(2), queue.remove());261 expectEqual(@as(u32, 2), queue.remove());
262 expectEqual(u32(2), queue.remove());262 expectEqual(@as(u32, 2), queue.remove());
263}263}
264264
265test "std.PriorityQueue: removeOrNull on empty" {265test "std.PriorityQueue: removeOrNull on empty" {
...@@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" {...@@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" {
276 try queue.add(9);276 try queue.add(9);
277 try queue.add(3);277 try queue.add(3);
278 try queue.add(2);278 try queue.add(2);
279 expectEqual(u32(2), queue.remove());279 expectEqual(@as(u32, 2), queue.remove());
280 expectEqual(u32(3), queue.remove());280 expectEqual(@as(u32, 3), queue.remove());
281 expectEqual(u32(9), queue.remove());281 expectEqual(@as(u32, 9), queue.remove());
282}282}
283283
284test "std.PriorityQueue: peek" {284test "std.PriorityQueue: peek" {
...@@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" {...@@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" {
289 try queue.add(9);289 try queue.add(9);
290 try queue.add(3);290 try queue.add(3);
291 try queue.add(2);291 try queue.add(2);
292 expectEqual(u32(2), queue.peek().?);292 expectEqual(@as(u32, 2), queue.peek().?);
293 expectEqual(u32(2), queue.peek().?);293 expectEqual(@as(u32, 2), queue.peek().?);
294}294}
295295
296test "std.PriorityQueue: sift up with odd indices" {296test "std.PriorityQueue: sift up with odd indices" {
...@@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" {...@@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" {
341 try queue.add(23);341 try queue.add(23);
342 try queue.add(25);342 try queue.add(25);
343 try queue.add(13);343 try queue.add(13);
344 expectEqual(u32(54), queue.remove());344 expectEqual(@as(u32, 54), queue.remove());
345 expectEqual(u32(25), queue.remove());345 expectEqual(@as(u32, 25), queue.remove());
346 expectEqual(u32(23), queue.remove());346 expectEqual(@as(u32, 23), queue.remove());
347 expectEqual(u32(13), queue.remove());347 expectEqual(@as(u32, 13), queue.remove());
348 expectEqual(u32(12), queue.remove());348 expectEqual(@as(u32, 12), queue.remove());
349 expectEqual(u32(7), queue.remove());349 expectEqual(@as(u32, 7), queue.remove());
350}350}
351351
352test "std.PriorityQueue: add and remove same max heap" {352test "std.PriorityQueue: add and remove same max heap" {
...@@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" {...@@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" {
359 try queue.add(2);359 try queue.add(2);
360 try queue.add(1);360 try queue.add(1);
361 try queue.add(1);361 try queue.add(1);
362 expectEqual(u32(2), queue.remove());362 expectEqual(@as(u32, 2), queue.remove());
363 expectEqual(u32(2), queue.remove());363 expectEqual(@as(u32, 2), queue.remove());
364 expectEqual(u32(1), queue.remove());364 expectEqual(@as(u32, 1), queue.remove());
365 expectEqual(u32(1), queue.remove());365 expectEqual(@as(u32, 1), queue.remove());
366 expectEqual(u32(1), queue.remove());366 expectEqual(@as(u32, 1), queue.remove());
367 expectEqual(u32(1), queue.remove());367 expectEqual(@as(u32, 1), queue.remove());
368}368}
369369
370test "std.PriorityQueue: iterator" {370test "std.PriorityQueue: iterator" {
...@@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" {...@@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" {
386 _ = map.remove(e);386 _ = map.remove(e);
387 }387 }
388388
389 expectEqual(usize(0), map.count());389 expectEqual(@as(usize, 0), map.count());
390}390}
lib/std/rand.zig+4-4
...@@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct {...@@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct {
633 const r = s0 +% s1;633 const r = s0 +% s1;
634634
635 s1 ^= s0;635 s1 ^= s0;
636 self.s[0] = math.rotl(u64, s0, u8(55)) ^ s1 ^ (s1 << 14);636 self.s[0] = math.rotl(u64, s0, @as(u8, 55)) ^ s1 ^ (s1 << 14);
637 self.s[1] = math.rotl(u64, s1, u8(36));637 self.s[1] = math.rotl(u64, s1, @as(u8, 36));
638638
639 return r;639 return r;
640 }640 }
...@@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct {...@@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct {
652 inline for (table) |entry| {652 inline for (table) |entry| {
653 var b: usize = 0;653 var b: usize = 0;
654 while (b < 64) : (b += 1) {654 while (b < 64) : (b += 1) {
655 if ((entry & (u64(1) << @intCast(u6, b))) != 0) {655 if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) {
656 s0 ^= self.s[0];656 s0 ^= self.s[0];
657 s1 ^= self.s[1];657 s1 ^= self.s[1];
658 }658 }
...@@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void {...@@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void {
1090 testRangeBias(r, start, end, false);1090 testRangeBias(r, start, end, false);
1091}1091}
1092fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {1092fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
1093 const count = @intCast(usize, i32(end) - i32(start));1093 const count = @intCast(usize, @as(i32, end) - @as(i32, start));
1094 var values_buffer = [_]bool{false} ** 0x100;1094 var values_buffer = [_]bool{false} ** 0x100;
1095 const values = values_buffer[0..count];1095 const values = values_buffer[0..count];
1096 var i: usize = 0;1096 var i: usize = 0;
lib/std/rand/ziggurat.zig+1-1
...@@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 {...@@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 {
17 // We manually construct a float from parts as we can avoid an extra random lookup here by17 // We manually construct a float from parts as we can avoid an extra random lookup here by
18 // using the unused exponent for the lookup table entry.18 // using the unused exponent for the lookup table entry.
19 const bits = random.scalar(u64);19 const bits = random.scalar(u64);
20 const i = usize(bits & 0xff);20 const i = @as(usize, bits & 0xff);
2121
22 const u = blk: {22 const u = blk: {
23 if (tables.is_symmetric) {23 if (tables.is_symmetric) {
lib/std/segmented_list.zig+5-5
...@@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
162 /// Grows or shrinks capacity to match usage.162 /// Grows or shrinks capacity to match usage.
163 pub fn setCapacity(self: *Self, new_capacity: usize) !void {163 pub fn setCapacity(self: *Self, new_capacity: usize) !void {
164 if (prealloc_item_count != 0) {164 if (prealloc_item_count != 0) {
165 if (new_capacity <= usize(1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) {165 if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) {
166 return self.shrinkCapacity(new_capacity);166 return self.shrinkCapacity(new_capacity);
167 }167 }
168 }168 }
...@@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
231231
232 fn shelfSize(shelf_index: ShelfIndex) usize {232 fn shelfSize(shelf_index: ShelfIndex) usize {
233 if (prealloc_item_count == 0) {233 if (prealloc_item_count == 0) {
234 return usize(1) << shelf_index;234 return @as(usize, 1) << shelf_index;
235 }235 }
236 return usize(1) << (shelf_index + (prealloc_exp + 1));236 return @as(usize, 1) << (shelf_index + (prealloc_exp + 1));
237 }237 }
238238
239 fn shelfIndex(list_index: usize) ShelfIndex {239 fn shelfIndex(list_index: usize) ShelfIndex {
...@@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
245245
246 fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize {246 fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize {
247 if (prealloc_item_count == 0) {247 if (prealloc_item_count == 0) {
248 return (list_index + 1) - (usize(1) << shelf_index);248 return (list_index + 1) - (@as(usize, 1) << shelf_index);
249 }249 }
250 return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index));250 return list_index + prealloc_item_count - (@as(usize, 1) << ((prealloc_exp + 1) + shelf_index));
251 }251 }
252252
253 fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void {253 fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void {
lib/std/sort.zig+4-4
...@@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s...@@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s
813// where have some idea as to how many unique values there are and where the next value might be813// where have some idea as to how many unique values there are and where the next value might be
814fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {814fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
815 if (range.length() == 0) return range.start;815 if (range.length() == 0) return range.start;
816 const skip = math.max(range.length() / unique, usize(1));816 const skip = math.max(range.length() / unique, @as(usize, 1));
817817
818 var index = range.start + skip;818 var index = range.start + skip;
819 while (lessThan(items[index - 1], value)) : (index += skip) {819 while (lessThan(items[index - 1], value)) : (index += skip) {
...@@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh...@@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh
827827
828fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {828fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
829 if (range.length() == 0) return range.start;829 if (range.length() == 0) return range.start;
830 const skip = math.max(range.length() / unique, usize(1));830 const skip = math.max(range.length() / unique, @as(usize, 1));
831831
832 var index = range.end - skip;832 var index = range.end - skip;
833 while (index > range.start and !lessThan(items[index - 1], value)) : (index -= skip) {833 while (index > range.start and !lessThan(items[index - 1], value)) : (index -= skip) {
...@@ -841,7 +841,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessT...@@ -841,7 +841,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessT
841841
842fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {842fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
843 if (range.length() == 0) return range.start;843 if (range.length() == 0) return range.start;
844 const skip = math.max(range.length() / unique, usize(1));844 const skip = math.max(range.length() / unique, @as(usize, 1));
845845
846 var index = range.start + skip;846 var index = range.start + skip;
847 while (!lessThan(value, items[index - 1])) : (index += skip) {847 while (!lessThan(value, items[index - 1])) : (index += skip) {
...@@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha...@@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha
855855
856fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {856fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
857 if (range.length() == 0) return range.start;857 if (range.length() == 0) return range.start;
858 const skip = math.max(range.length() / unique, usize(1));858 const skip = math.max(range.length() / unique, @as(usize, 1));
859859
860 var index = range.end - skip;860 var index = range.end - skip;
861 while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) {861 while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) {
lib/std/special/c.zig+3-3
...@@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int {...@@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int {
62 r += 1;62 r += 1;
63 n -= 1;63 n -= 1;
64 }64 }
65 return c_int(l[0]) - c_int(r[0]);65 return @as(c_int, l[0]) - @as(c_int, r[0]);
66}66}
6767
68extern fn strerror(errnum: c_int) [*]const u8 {68extern fn strerror(errnum: c_int) [*]const u8 {
...@@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
540 // scale result up540 // scale result up
541 if (ex > 0) {541 if (ex > 0) {
542 ux -%= 1 << digits;542 ux -%= 1 << digits;
543 ux |= uint(@bitCast(u32, ex)) << digits;543 ux |= @as(uint, @bitCast(u32, ex)) << digits;
544 } else {544 } else {
545 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));545 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));
546 }546 }
...@@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 {...@@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 {
687687
688export fn sqrtf(x: f32) f32 {688export fn sqrtf(x: f32) f32 {
689 const tiny: f32 = 1.0e-30;689 const tiny: f32 = 1.0e-30;
690 const sign: i32 = @bitCast(i32, u32(0x80000000));690 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));
691 var ix: i32 = @bitCast(i32, x);691 var ix: i32 = @bitCast(i32, x);
692692
693 if ((ix & 0x7F800000) == 0x7F800000) {693 if ((ix & 0x7F800000) == 0x7F800000) {
lib/std/special/compiler_rt.zig+17-17
...@@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 {...@@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 {
672 // special cases672 // special cases
673 if (d == 0) return 0; // ?!673 if (d == 0) return 0; // ?!
674 if (n == 0) return 0;674 if (n == 0) return 0;
675 var sr = @bitCast(c_uint, c_int(@clz(u32, d)) - c_int(@clz(u32, n)));675 var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n)));
676 // 0 <= sr <= n_uword_bits - 1 or sr large676 // 0 <= sr <= n_uword_bits - 1 or sr large
677 if (sr > n_uword_bits - 1) {677 if (sr > n_uword_bits - 1) {
678 // d > r678 // d > r
...@@ -1414,10 +1414,10 @@ test "test_divsi3" {...@@ -1414,10 +1414,10 @@ test "test_divsi3" {
1414 [_]i32{ -2, 1, -2 },1414 [_]i32{ -2, 1, -2 },
1415 [_]i32{ -2, -1, 2 },1415 [_]i32{ -2, -1, 2 },
14161416
1417 [_]i32{ @bitCast(i32, u32(0x80000000)), 1, @bitCast(i32, u32(0x80000000)) },1417 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) },
1418 [_]i32{ @bitCast(i32, u32(0x80000000)), -1, @bitCast(i32, u32(0x80000000)) },1418 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) },
1419 [_]i32{ @bitCast(i32, u32(0x80000000)), -2, 0x40000000 },1419 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 },
1420 [_]i32{ @bitCast(i32, u32(0x80000000)), 2, @bitCast(i32, u32(0xC0000000)) },1420 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) },
1421 };1421 };
14221422
1423 for (cases) |case| {1423 for (cases) |case| {
...@@ -1443,8 +1443,8 @@ test "test_divmodsi4" {...@@ -1443,8 +1443,8 @@ test "test_divmodsi4" {
1443 [_]i32{ 19, 5, 3, 4 },1443 [_]i32{ 19, 5, 3, 4 },
1444 [_]i32{ 19, -5, -3, 4 },1444 [_]i32{ 19, -5, -3, 4 },
14451445
1446 [_]i32{ @bitCast(i32, u32(0x80000000)), 8, @bitCast(i32, u32(0xf0000000)), 0 },1446 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 },
1447 [_]i32{ @bitCast(i32, u32(0x80000007)), 8, @bitCast(i32, u32(0xf0000001)), -1 },1447 [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 },
1448 };1448 };
14491449
1450 for (cases) |case| {1450 for (cases) |case| {
...@@ -1467,10 +1467,10 @@ test "test_divdi3" {...@@ -1467,10 +1467,10 @@ test "test_divdi3" {
1467 [_]i64{ -2, 1, -2 },1467 [_]i64{ -2, 1, -2 },
1468 [_]i64{ -2, -1, 2 },1468 [_]i64{ -2, -1, 2 },
14691469
1470 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)) },1470 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
1471 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)) },1471 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
1472 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -2, 0x4000000000000000 },1472 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 },
1473 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0xC000000000000000)) },1473 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) },
1474 };1474 };
14751475
1476 for (cases) |case| {1476 for (cases) |case| {
...@@ -1492,12 +1492,12 @@ test "test_moddi3" {...@@ -1492,12 +1492,12 @@ test "test_moddi3" {
1492 [_]i64{ -5, 3, -2 },1492 [_]i64{ -5, 3, -2 },
1493 [_]i64{ -5, -3, -2 },1493 [_]i64{ -5, -3, -2 },
14941494
1495 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 1, 0 },1495 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 },
1496 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -1, 0 },1496 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 },
1497 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 2, 0 },1497 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 },
1498 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -2, 0 },1498 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 },
1499 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 3, -2 },1499 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 },
1500 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -3, -2 },1500 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 },
1501 };1501 };
15021502
1503 for (cases) |case| {1503 for (cases) |case| {
lib/std/special/compiler_rt/addXf3.zig+13-13
...@@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 {...@@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 {
19}19}
2020
21pub extern fn __subsf3(a: f32, b: f32) f32 {21pub extern fn __subsf3(a: f32, b: f32) f32 {
22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (u32(1) << 31));22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));
23 return addXf3(f32, a, neg_b);23 return addXf3(f32, a, neg_b);
24}24}
2525
26pub extern fn __subdf3(a: f64, b: f64) f64 {26pub extern fn __subdf3(a: f64, b: f64) f64 {
27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (u64(1) << 63));27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63));
28 return addXf3(f64, a, neg_b);28 return addXf3(f64, a, neg_b);
29}29}
3030
31pub extern fn __subtf3(a: f128, b: f128) f128 {31pub extern fn __subtf3(a: f128, b: f128) f128 {
32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127));32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127));
33 return addXf3(f128, a, neg_b);33 return addXf3(f128, a, neg_b);
34}34}
3535
36// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/215436// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
37fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {37fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
38 const Z = @IntType(false, T.bit_count);38 const Z = @IntType(false, T.bit_count);
39 const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1));39 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
40 const significandBits = std.math.floatMantissaBits(T);40 const significandBits = std.math.floatMantissaBits(T);
41 const implicitBit = Z(1) << significandBits;41 const implicitBit = @as(Z, 1) << significandBits;
4242
43 const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);43 const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
44 significand.* <<= @intCast(S, shift);44 significand.* <<= @intCast(S, shift);
...@@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {...@@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
48// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/215448// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
49fn addXf3(comptime T: type, a: T, b: T) T {49fn addXf3(comptime T: type, a: T, b: T) T {
50 const Z = @IntType(false, T.bit_count);50 const Z = @IntType(false, T.bit_count);
51 const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1));51 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
5252
53 const typeWidth = T.bit_count;53 const typeWidth = T.bit_count;
54 const significandBits = std.math.floatMantissaBits(T);54 const significandBits = std.math.floatMantissaBits(T);
55 const exponentBits = std.math.floatExponentBits(T);55 const exponentBits = std.math.floatExponentBits(T);
5656
57 const signBit = (Z(1) << (significandBits + exponentBits));57 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
58 const maxExponent = ((1 << exponentBits) - 1);58 const maxExponent = ((1 << exponentBits) - 1);
59 const exponentBias = (maxExponent >> 1);59 const exponentBias = (maxExponent >> 1);
6060
61 const implicitBit = (Z(1) << significandBits);61 const implicitBit = (@as(Z, 1) << significandBits);
62 const quietBit = implicitBit >> 1;62 const quietBit = implicitBit >> 1;
63 const significandMask = implicitBit - 1;63 const significandMask = implicitBit - 1;
6464
...@@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T {...@@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T {
78 const infRep = @bitCast(Z, std.math.inf(T));78 const infRep = @bitCast(Z, std.math.inf(T));
7979
80 // Detect if a or b is zero, infinity, or NaN.80 // Detect if a or b is zero, infinity, or NaN.
81 if (aAbs -% Z(1) >= infRep - Z(1) or81 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
82 bAbs -% Z(1) >= infRep - Z(1))82 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
83 {83 {
84 // NaN + anything = qNaN84 // NaN + anything = qNaN
85 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);85 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);
...@@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {...@@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
148 const @"align" = @intCast(Z, aExponent - bExponent);148 const @"align" = @intCast(Z, aExponent - bExponent);
149 if (@"align" != 0) {149 if (@"align" != 0) {
150 if (@"align" < typeWidth) {150 if (@"align" < typeWidth) {
151 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0;151 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0;
152 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;152 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
153 } else {153 } else {
154 bSignificand = 1; // sticky; b is known to be non-zero.154 bSignificand = 1; // sticky; b is known to be non-zero.
...@@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {...@@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
157 if (subtraction) {157 if (subtraction) {
158 aSignificand -= bSignificand;158 aSignificand -= bSignificand;
159 // If a == -b, return +zero.159 // If a == -b, return +zero.
160 if (aSignificand == 0) return @bitCast(T, Z(0));160 if (aSignificand == 0) return @bitCast(T, @as(Z, 0));
161161
162 // If partial cancellation occured, we need to left-shift the result162 // If partial cancellation occured, we need to left-shift the result
163 // and adjust the exponent:163 // and adjust the exponent:
...@@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {...@@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
185 // Result is denormal before rounding; the exponent is zero and we185 // Result is denormal before rounding; the exponent is zero and we
186 // need to shift the significand.186 // need to shift the significand.
187 const shift = @intCast(Z, 1 - aExponent);187 const shift = @intCast(Z, 1 - aExponent);
188 const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0;188 const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) @as(Z, 1) else 0;
189 aSignificand = aSignificand >> @intCast(S, shift | sticky);189 aSignificand = aSignificand >> @intCast(S, shift | sticky);
190 aExponent = 0;190 aExponent = 0;
191 }191 }
lib/std/special/compiler_rt/addXf3_test.zig+4-4
...@@ -3,8 +3,8 @@...@@ -3,8 +3,8 @@
3// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c3// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c
4// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c4// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c
55
6const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64);6const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
7const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64);7const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
88
9const __addtf3 = @import("addXf3.zig").__addtf3;9const __addtf3 = @import("addXf3.zig").__addtf3;
1010
...@@ -34,7 +34,7 @@ test "addtf3" {...@@ -34,7 +34,7 @@ test "addtf3" {
34 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);34 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3535
36 // NaN + any = NaN36 // NaN + any = NaN
37 test__addtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);37 test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3838
39 // inf + inf = inf39 // inf + inf = inf
40 test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);40 test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
...@@ -75,7 +75,7 @@ test "subtf3" {...@@ -75,7 +75,7 @@ test "subtf3" {
75 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);75 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7676
77 // NaN + any = NaN77 // NaN + any = NaN
78 test__subtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);78 test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7979
80 // inf - any = inf80 // inf - any = inf
81 test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);81 test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
lib/std/special/compiler_rt/comparedf2.zig+10-10
...@@ -13,19 +13,19 @@ const srep_t = i64;...@@ -13,19 +13,19 @@ const srep_t = i64;
13const typeWidth = rep_t.bit_count;13const typeWidth = rep_t.bit_count;
14const significandBits = std.math.floatMantissaBits(fp_t);14const significandBits = std.math.floatMantissaBits(fp_t);
15const exponentBits = std.math.floatExponentBits(fp_t);15const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (rep_t(1) << (significandBits + exponentBits));16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
17const absMask = signBit - 1;17const absMask = signBit - 1;
18const implicitBit = rep_t(1) << significandBits;18const implicitBit = @as(rep_t, 1) << significandBits;
19const significandMask = implicitBit - 1;19const significandMask = implicitBit - 1;
20const exponentMask = absMask ^ significandMask;20const exponentMask = absMask ^ significandMask;
21const infRep = @bitCast(rep_t, std.math.inf(fp_t));21const infRep = @bitCast(rep_t, std.math.inf(fp_t));
2222
23// TODO https://github.com/ziglang/zig/issues/64123// TODO https://github.com/ziglang/zig/issues/641
24// and then make the return types of some of these functions the enum instead of c_int24// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = c_int(-1);25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = c_int(0);26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = c_int(1);27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = c_int(1);28const LE_UNORDERED = @as(c_int, 1);
2929
30pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {30pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {
31 @setRuntimeSafety(is_test);31 @setRuntimeSafety(is_test);
...@@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {...@@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {
6565
66// TODO https://github.com/ziglang/zig/issues/64166// TODO https://github.com/ziglang/zig/issues/641
67// and then make the return types of some of these functions the enum instead of c_int67// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = c_int(-1);68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = c_int(0);69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = c_int(1);70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
73pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {73pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {
74 @setRuntimeSafety(is_test);74 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/comparesf2.zig+10-10
...@@ -13,19 +13,19 @@ const srep_t = i32;...@@ -13,19 +13,19 @@ const srep_t = i32;
13const typeWidth = rep_t.bit_count;13const typeWidth = rep_t.bit_count;
14const significandBits = std.math.floatMantissaBits(fp_t);14const significandBits = std.math.floatMantissaBits(fp_t);
15const exponentBits = std.math.floatExponentBits(fp_t);15const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (rep_t(1) << (significandBits + exponentBits));16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
17const absMask = signBit - 1;17const absMask = signBit - 1;
18const implicitBit = rep_t(1) << significandBits;18const implicitBit = @as(rep_t, 1) << significandBits;
19const significandMask = implicitBit - 1;19const significandMask = implicitBit - 1;
20const exponentMask = absMask ^ significandMask;20const exponentMask = absMask ^ significandMask;
21const infRep = @bitCast(rep_t, std.math.inf(fp_t));21const infRep = @bitCast(rep_t, std.math.inf(fp_t));
2222
23// TODO https://github.com/ziglang/zig/issues/64123// TODO https://github.com/ziglang/zig/issues/641
24// and then make the return types of some of these functions the enum instead of c_int24// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = c_int(-1);25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = c_int(0);26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = c_int(1);27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = c_int(1);28const LE_UNORDERED = @as(c_int, 1);
2929
30pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {30pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {
31 @setRuntimeSafety(is_test);31 @setRuntimeSafety(is_test);
...@@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {...@@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {
6565
66// TODO https://github.com/ziglang/zig/issues/64166// TODO https://github.com/ziglang/zig/issues/641
67// and then make the return types of some of these functions the enum instead of c_int67// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = c_int(-1);68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = c_int(0);69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = c_int(1);70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
73pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {73pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {
74 @setRuntimeSafety(is_test);74 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/comparetf2.zig+10-10
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1// TODO https://github.com/ziglang/zig/issues/6411// TODO https://github.com/ziglang/zig/issues/641
2// and then make the return types of some of these functions the enum instead of c_int2// and then make the return types of some of these functions the enum instead of c_int
3const LE_LESS = c_int(-1);3const LE_LESS = @as(c_int, -1);
4const LE_EQUAL = c_int(0);4const LE_EQUAL = @as(c_int, 0);
5const LE_GREATER = c_int(1);5const LE_GREATER = @as(c_int, 1);
6const LE_UNORDERED = c_int(1);6const LE_UNORDERED = @as(c_int, 1);
77
8const rep_t = u128;8const rep_t = u128;
9const srep_t = i128;9const srep_t = i128;
...@@ -11,9 +11,9 @@ const srep_t = i128;...@@ -11,9 +11,9 @@ const srep_t = i128;
11const typeWidth = rep_t.bit_count;11const typeWidth = rep_t.bit_count;
12const significandBits = 112;12const significandBits = 112;
13const exponentBits = (typeWidth - significandBits - 1);13const exponentBits = (typeWidth - significandBits - 1);
14const signBit = (rep_t(1) << (significandBits + exponentBits));14const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
15const absMask = signBit - 1;15const absMask = signBit - 1;
16const implicitBit = rep_t(1) << significandBits;16const implicitBit = @as(rep_t, 1) << significandBits;
17const significandMask = implicitBit - 1;17const significandMask = implicitBit - 1;
18const exponentMask = absMask ^ significandMask;18const exponentMask = absMask ^ significandMask;
19const infRep = exponentMask;19const infRep = exponentMask;
...@@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int {...@@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int {
6060
61// TODO https://github.com/ziglang/zig/issues/64161// TODO https://github.com/ziglang/zig/issues/641
62// and then make the return types of some of these functions the enum instead of c_int62// and then make the return types of some of these functions the enum instead of c_int
63const GE_LESS = c_int(-1);63const GE_LESS = @as(c_int, -1);
64const GE_EQUAL = c_int(0);64const GE_EQUAL = @as(c_int, 0);
65const GE_GREATER = c_int(1);65const GE_GREATER = @as(c_int, 1);
66const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED66const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
6767
68pub extern fn __getf2(a: f128, b: f128) c_int {68pub extern fn __getf2(a: f128, b: f128) c_int {
69 @setRuntimeSafety(is_test);69 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/divdf3.zig+33-33
...@@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {...@@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
14 const significandBits = std.math.floatMantissaBits(f64);14 const significandBits = std.math.floatMantissaBits(f64);
15 const exponentBits = std.math.floatExponentBits(f64);15 const exponentBits = std.math.floatExponentBits(f64);
1616
17 const signBit = (Z(1) << (significandBits + exponentBits));17 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
18 const maxExponent = ((1 << exponentBits) - 1);18 const maxExponent = ((1 << exponentBits) - 1);
19 const exponentBias = (maxExponent >> 1);19 const exponentBias = (maxExponent >> 1);
2020
21 const implicitBit = (Z(1) << significandBits);21 const implicitBit = (@as(Z, 1) << significandBits);
22 const quietBit = implicitBit >> 1;22 const quietBit = implicitBit >> 1;
23 const significandMask = implicitBit - 1;23 const significandMask = implicitBit - 1;
2424
...@@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {...@@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
91 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This91 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
92 // is accurate to about 3.5 binary digits.92 // is accurate to about 3.5 binary digits.
93 const q31b: u32 = @truncate(u32, bSignificand >> 21);93 const q31b: u32 = @truncate(u32, bSignificand >> 21);
94 var recip32 = u32(0x7504f333) -% q31b;94 var recip32 = @as(u32, 0x7504f333) -% q31b;
9595
96 // Now refine the reciprocal estimate using a Newton-Raphson iteration:96 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
97 //97 //
...@@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {...@@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
101 // with each iteration, so after three iterations, we have about 28 binary101 // with each iteration, so after three iterations, we have about 28 binary
102 // digits of accuracy.102 // digits of accuracy.
103 var correction32: u32 = undefined;103 var correction32: u32 = undefined;
104 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);104 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
105 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);105 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
106 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);106 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
107 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);107 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
108 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);108 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
109 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);109 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
110110
111 // recip32 might have overflowed to exactly zero in the preceding111 // recip32 might have overflowed to exactly zero in the preceding
112 // computation if the high word of b is exactly 1.0. This would sabotage112 // computation if the high word of b is exactly 1.0. This would sabotage
...@@ -119,10 +119,10 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {...@@ -119,10 +119,10 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
119 const q63blo: u32 = @truncate(u32, bSignificand << 11);119 const q63blo: u32 = @truncate(u32, bSignificand << 11);
120 var correction: u64 = undefined;120 var correction: u64 = undefined;
121 var reciprocal: u64 = undefined;121 var reciprocal: u64 = undefined;
122 correction = ~(u64(recip32) *% q31b +% (u64(recip32) *% q63blo >> 32)) +% 1;122 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
123 const cHi = @truncate(u32, correction >> 32);123 const cHi = @truncate(u32, correction >> 32);
124 const cLo = @truncate(u32, correction);124 const cLo = @truncate(u32, correction);
125 reciprocal = u64(recip32) *% cHi +% (u64(recip32) *% cLo >> 32);125 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
126126
127 // We already adjusted the 32-bit estimate, now we need to adjust the final127 // We already adjusted the 32-bit estimate, now we need to adjust the final
128 // 64-bit reciprocal estimate downward to ensure that it is strictly smaller128 // 64-bit reciprocal estimate downward to ensure that it is strictly smaller
...@@ -195,7 +195,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {...@@ -195,7 +195,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
195 // Clear the implicit bit195 // Clear the implicit bit
196 var absResult = quotient & significandMask;196 var absResult = quotient & significandMask;
197 // Insert the exponent197 // Insert the exponent
198 absResult |= @bitCast(Z, SignedZ(writtenExponent)) << significandBits;198 absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits;
199 // Round199 // Round
200 absResult +%= round;200 absResult +%= round;
201 // Insert the sign and return201 // Insert the sign and return
...@@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
208 switch (Z) {208 switch (Z) {
209 u32 => {209 u32 => {
210 // 32x32 --> 64 bit multiply210 // 32x32 --> 64 bit multiply
211 const product = u64(a) * u64(b);211 const product = @as(u64, a) * @as(u64, b);
212 hi.* = @truncate(u32, product >> 32);212 hi.* = @truncate(u32, product >> 32);
213 lo.* = @truncate(u32, product);213 lo.* = @truncate(u32, product);
214 },214 },
...@@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
237 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;237 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
238 },238 },
239 u128 => {239 u128 => {
240 const Word_LoMask = u64(0x00000000ffffffff);240 const Word_LoMask = @as(u64, 0x00000000ffffffff);
241 const Word_HiMask = u64(0xffffffff00000000);241 const Word_HiMask = @as(u64, 0xffffffff00000000);
242 const Word_FullMask = u64(0xffffffffffffffff);242 const Word_FullMask = @as(u64, 0xffffffffffffffff);
243 const S = struct {243 const S = struct {
244 fn Word_1(x: u128) u64 {244 fn Word_1(x: u128) u64 {
245 return @truncate(u32, x >> 96);245 return @truncate(u32, x >> 96);
...@@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
275 const product43: u64 = S.Word_4(a) * S.Word_3(b);275 const product43: u64 = S.Word_4(a) * S.Word_3(b);
276 const product44: u64 = S.Word_4(a) * S.Word_4(b);276 const product44: u64 = S.Word_4(a) * S.Word_4(b);
277277
278 const sum0: u128 = u128(product44);278 const sum0: u128 = @as(u128, product44);
279 const sum1: u128 = u128(product34) +%279 const sum1: u128 = @as(u128, product34) +%
280 u128(product43);280 @as(u128, product43);
281 const sum2: u128 = u128(product24) +%281 const sum2: u128 = @as(u128, product24) +%
282 u128(product33) +%282 @as(u128, product33) +%
283 u128(product42);283 @as(u128, product42);
284 const sum3: u128 = u128(product14) +%284 const sum3: u128 = @as(u128, product14) +%
285 u128(product23) +%285 @as(u128, product23) +%
286 u128(product32) +%286 @as(u128, product32) +%
287 u128(product41);287 @as(u128, product41);
288 const sum4: u128 = u128(product13) +%288 const sum4: u128 = @as(u128, product13) +%
289 u128(product22) +%289 @as(u128, product22) +%
290 u128(product31);290 @as(u128, product31);
291 const sum5: u128 = u128(product12) +%291 const sum5: u128 = @as(u128, product12) +%
292 u128(product21);292 @as(u128, product21);
293 const sum6: u128 = u128(product11);293 const sum6: u128 = @as(u128, product11);
294294
295 const r0: u128 = (sum0 & Word_FullMask) +%295 const r0: u128 = (sum0 & Word_FullMask) +%
296 ((sum1 & Word_LoMask) << 32);296 ((sum1 & Word_LoMask) << 32);
...@@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {...@@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
316 @setRuntimeSafety(builtin.is_test);316 @setRuntimeSafety(builtin.is_test);
317 const Z = @IntType(false, T.bit_count);317 const Z = @IntType(false, T.bit_count);
318 const significandBits = std.math.floatMantissaBits(T);318 const significandBits = std.math.floatMantissaBits(T);
319 const implicitBit = Z(1) << significandBits;319 const implicitBit = @as(Z, 1) << significandBits;
320320
321 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);321 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
322 significand.* <<= @intCast(std.math.Log2Int(Z), shift);322 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/divsf3.zig+11-11
...@@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {...@@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
13 const significandBits = std.math.floatMantissaBits(f32);13 const significandBits = std.math.floatMantissaBits(f32);
14 const exponentBits = std.math.floatExponentBits(f32);14 const exponentBits = std.math.floatExponentBits(f32);
1515
16 const signBit = (Z(1) << (significandBits + exponentBits));16 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
17 const maxExponent = ((1 << exponentBits) - 1);17 const maxExponent = ((1 << exponentBits) - 1);
18 const exponentBias = (maxExponent >> 1);18 const exponentBias = (maxExponent >> 1);
1919
20 const implicitBit = (Z(1) << significandBits);20 const implicitBit = (@as(Z, 1) << significandBits);
21 const quietBit = implicitBit >> 1;21 const quietBit = implicitBit >> 1;
22 const significandMask = implicitBit - 1;22 const significandMask = implicitBit - 1;
2323
...@@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {...@@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
90 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This90 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
91 // is accurate to about 3.5 binary digits.91 // is accurate to about 3.5 binary digits.
92 const q31b = bSignificand << 8;92 const q31b = bSignificand << 8;
93 var reciprocal = u32(0x7504f333) -% q31b;93 var reciprocal = @as(u32, 0x7504f333) -% q31b;
9494
95 // Now refine the reciprocal estimate using a Newton-Raphson iteration:95 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
96 //96 //
...@@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {...@@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
100 // with each iteration, so after three iterations, we have about 28 binary100 // with each iteration, so after three iterations, we have about 28 binary
101 // digits of accuracy.101 // digits of accuracy.
102 var correction: u32 = undefined;102 var correction: u32 = undefined;
103 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);103 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
104 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);104 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
105 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);105 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
106 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);106 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
107 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);107 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
108 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);108 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
109109
110 // Exhaustive testing shows that the error in reciprocal after three steps110 // Exhaustive testing shows that the error in reciprocal after three steps
111 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our111 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
...@@ -127,7 +127,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {...@@ -127,7 +127,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
127 // is the error in the reciprocal of b scaled by the maximum127 // is the error in the reciprocal of b scaled by the maximum
128 // possible value of a. As a consequence of this error bound,128 // possible value of a. As a consequence of this error bound,
129 // either q or nextafter(q) is the correctly rounded129 // either q or nextafter(q) is the correctly rounded
130 var quotient: Z = @truncate(u32, u64(reciprocal) *% (aSignificand << 1) >> 32);130 var quotient: Z = @truncate(u32, @as(u64, reciprocal) *% (aSignificand << 1) >> 32);
131131
132 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).132 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
133 // In either case, we are going to compute a residual of the form133 // In either case, we are going to compute a residual of the form
...@@ -189,7 +189,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {...@@ -189,7 +189,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
189 @setRuntimeSafety(builtin.is_test);189 @setRuntimeSafety(builtin.is_test);
190 const Z = @IntType(false, T.bit_count);190 const Z = @IntType(false, T.bit_count);
191 const significandBits = std.math.floatMantissaBits(T);191 const significandBits = std.math.floatMantissaBits(T);
192 const implicitBit = Z(1) << significandBits;192 const implicitBit = @as(Z, 1) << significandBits;
193193
194 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);194 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
195 significand.* <<= @intCast(std.math.Log2Int(Z), shift);195 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/divti3_test.zig+4-4
...@@ -14,8 +14,8 @@ test "divti3" {...@@ -14,8 +14,8 @@ test "divti3" {
14 test__divti3(-2, 1, -2);14 test__divti3(-2, 1, -2);
15 test__divti3(-2, -1, 2);15 test__divti3(-2, -1, 2);
1616
17 test__divti3(@bitCast(i128, u128(0x8 << 124)), 1, @bitCast(i128, u128(0x8 << 124)));17 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
18 test__divti3(@bitCast(i128, u128(0x8 << 124)), -1, @bitCast(i128, u128(0x8 << 124)));18 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
19 test__divti3(@bitCast(i128, u128(0x8 << 124)), -2, @bitCast(i128, u128(0x4 << 124)));19 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
20 test__divti3(@bitCast(i128, u128(0x8 << 124)), 2, @bitCast(i128, u128(0xc << 124)));20 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
21}21}
lib/std/special/compiler_rt/extendXfYf2.zig+7-7
...@@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t...@@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
49 const dstInfExp = (1 << dstExpBits) - 1;49 const dstInfExp = (1 << dstExpBits) - 1;
50 const dstExpBias = dstInfExp >> 1;50 const dstExpBias = dstInfExp >> 1;
5151
52 const dstMinNormal: dst_rep_t = dst_rep_t(1) << dstSigBits;52 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;
5353
54 // Break a into a sign and representation of the absolute value54 // Break a into a sign and representation of the absolute value
55 const aRep: src_rep_t = @bitCast(src_rep_t, a);55 const aRep: src_rep_t = @bitCast(src_rep_t, a);
...@@ -61,7 +61,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t...@@ -61,7 +61,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
61 // a is a normal number.61 // a is a normal number.
62 // Extend to the destination type by shifting the significand and62 // Extend to the destination type by shifting the significand and
63 // exponent into the proper position and rebiasing the exponent.63 // exponent into the proper position and rebiasing the exponent.
64 absResult = dst_rep_t(aAbs) << (dstSigBits - srcSigBits);64 absResult = @as(dst_rep_t, aAbs) << (dstSigBits - srcSigBits);
65 absResult += (dstExpBias - srcExpBias) << dstSigBits;65 absResult += (dstExpBias - srcExpBias) << dstSigBits;
66 } else if (aAbs >= srcInfinity) {66 } else if (aAbs >= srcInfinity) {
67 // a is NaN or infinity.67 // a is NaN or infinity.
...@@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t...@@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
69 // bit (if needed) and right-aligning the rest of the trailing NaN69 // bit (if needed) and right-aligning the rest of the trailing NaN
70 // payload field.70 // payload field.
71 absResult = dstInfExp << dstSigBits;71 absResult = dstInfExp << dstSigBits;
72 absResult |= dst_rep_t(aAbs & srcQNaN) << (dstSigBits - srcSigBits);72 absResult |= @as(dst_rep_t, aAbs & srcQNaN) << (dstSigBits - srcSigBits);
73 absResult |= dst_rep_t(aAbs & srcNaNCode) << (dstSigBits - srcSigBits);73 absResult |= @as(dst_rep_t, aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
74 } else if (aAbs != 0) {74 } else if (aAbs != 0) {
75 // a is denormal.75 // a is denormal.
76 // renormalize the significand and clear the leading bit, then insert76 // renormalize the significand and clear the leading bit, then insert
77 // the correct adjusted exponent in the destination type.77 // the correct adjusted exponent in the destination type.
78 const scale: u32 = @clz(src_rep_t, aAbs) -78 const scale: u32 = @clz(src_rep_t, aAbs) -
79 @clz(src_rep_t, src_rep_t(srcMinNormal));79 @clz(src_rep_t, @as(src_rep_t, srcMinNormal));
80 absResult = dst_rep_t(aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);80 absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
81 absResult ^= dstMinNormal;81 absResult ^= dstMinNormal;
82 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;82 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
83 absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits;83 absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits;
...@@ -87,7 +87,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t...@@ -87,7 +87,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
87 }87 }
8888
89 // Apply the signbit to (dst_t)abs(a).89 // Apply the signbit to (dst_t)abs(a).
90 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | dst_rep_t(sign) << (dstBits - srcBits);90 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);
91 return @bitCast(dst_t, result);91 return @bitCast(dst_t, result);
92}92}
9393
lib/std/special/compiler_rt/extendXfYf2_test.zig+4-4
...@@ -134,11 +134,11 @@ test "extendsftf2" {...@@ -134,11 +134,11 @@ test "extendsftf2" {
134}134}
135135
136fn makeQNaN64() f64 {136fn makeQNaN64() f64 {
137 return @bitCast(f64, u64(0x7ff8000000000000));137 return @bitCast(f64, @as(u64, 0x7ff8000000000000));
138}138}
139139
140fn makeInf64() f64 {140fn makeInf64() f64 {
141 return @bitCast(f64, u64(0x7ff0000000000000));141 return @bitCast(f64, @as(u64, 0x7ff0000000000000));
142}142}
143143
144fn makeNaN64(rand: u64) f64 {144fn makeNaN64(rand: u64) f64 {
...@@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 {...@@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 {
146}146}
147147
148fn makeQNaN32() f32 {148fn makeQNaN32() f32 {
149 return @bitCast(f32, u32(0x7fc00000));149 return @bitCast(f32, @as(u32, 0x7fc00000));
150}150}
151151
152fn makeNaN32(rand: u32) f32 {152fn makeNaN32(rand: u32) f32 {
...@@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 {...@@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 {
154}154}
155155
156fn makeInf32() f32 {156fn makeInf32() f32 {
157 return @bitCast(f32, u32(0x7f800000));157 return @bitCast(f32, @as(u32, 0x7f800000));
158}158}
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixdfdi(a: f64, expected: i64) void {7fn test__fixdfdi(a: f64, expected: i64) void {
8 const x = __fixdfdi(a);8 const x = __fixdfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixdfsi(a: f64, expected: i32) void {7fn test__fixdfsi(a: f64, expected: i32) void {
8 const x = __fixdfsi(a);8 const x = __fixdfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixdfti_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixdfti(a: f64, expected: i128) void {7fn test__fixdfti(a: f64, expected: i128) void {
8 const x = __fixdfti(a);8 const x = __fixdfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixint.zig+3-3
...@@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {...@@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
2525
26 const typeWidth = rep_t.bit_count;26 const typeWidth = rep_t.bit_count;
27 const exponentBits = (typeWidth - significandBits - 1);27 const exponentBits = (typeWidth - significandBits - 1);
28 const signBit = (rep_t(1) << (significandBits + exponentBits));28 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
29 const maxExponent = ((1 << exponentBits) - 1);29 const maxExponent = ((1 << exponentBits) - 1);
30 const exponentBias = (maxExponent >> 1);30 const exponentBias = (maxExponent >> 1);
3131
32 const implicitBit = (rep_t(1) << significandBits);32 const implicitBit = (@as(rep_t, 1) << significandBits);
33 const significandMask = (implicitBit - 1);33 const significandMask = (implicitBit - 1);
3434
35 // Break a into sign, exponent, significand35 // Break a into sign, exponent, significand
...@@ -51,7 +51,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {...@@ -51,7 +51,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
5151
52 // If the value is too large for the integer type, saturate.52 // If the value is too large for the integer type, saturate.
53 if (@intCast(usize, exponent) >= fixint_t.bit_count) {53 if (@intCast(usize, exponent) >= fixint_t.bit_count) {
54 return if (negative) fixint_t(minInt(fixint_t)) else fixint_t(maxInt(fixint_t));54 return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t));
55 }55 }
5656
57 // If 0 <= exponent < significandBits, right shift else left shift57 // If 0 <= exponent < significandBits, right shift else left shift
lib/std/special/compiler_rt/fixint_test.zig+13-13
...@@ -81,8 +81,8 @@ test "fixint.i3" {...@@ -81,8 +81,8 @@ test "fixint.i3" {
81test "fixint.i32" {81test "fixint.i32" {
82 test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));82 test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
83 test__fixint(f64, i32, -math.f64_max, math.minInt(i32));83 test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
84 test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32));84 test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
85 test__fixint(f64, i32, f64(math.minInt(i32)) + 1, math.minInt(i32) + 1);85 test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
86 test__fixint(f64, i32, -2.0, -2);86 test__fixint(f64, i32, -2.0, -2);
87 test__fixint(f64, i32, -1.9, -1);87 test__fixint(f64, i32, -1.9, -1);
88 test__fixint(f64, i32, -1.1, -1);88 test__fixint(f64, i32, -1.1, -1);
...@@ -96,8 +96,8 @@ test "fixint.i32" {...@@ -96,8 +96,8 @@ test "fixint.i32" {
96 test__fixint(f64, i32, 0.1, 0);96 test__fixint(f64, i32, 0.1, 0);
97 test__fixint(f64, i32, 0.9, 0);97 test__fixint(f64, i32, 0.9, 0);
98 test__fixint(f64, i32, 1.0, 1);98 test__fixint(f64, i32, 1.0, 1);
99 test__fixint(f64, i32, f64(math.maxInt(i32)) - 1, math.maxInt(i32) - 1);99 test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
100 test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32));100 test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
101 test__fixint(f64, i32, math.f64_max, math.maxInt(i32));101 test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
102 test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));102 test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
103}103}
...@@ -105,9 +105,9 @@ test "fixint.i32" {...@@ -105,9 +105,9 @@ test "fixint.i32" {
105test "fixint.i64" {105test "fixint.i64" {
106 test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));106 test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
107 test__fixint(f64, i64, -math.f64_max, math.minInt(i64));107 test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
108 test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64));108 test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
109 test__fixint(f64, i64, f64(math.minInt(i64)) + 1, math.minInt(i64));109 test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
110 test__fixint(f64, i64, f64(math.minInt(i64) / 2), math.minInt(i64) / 2);110 test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
111 test__fixint(f64, i64, -2.0, -2);111 test__fixint(f64, i64, -2.0, -2);
112 test__fixint(f64, i64, -1.9, -1);112 test__fixint(f64, i64, -1.9, -1);
113 test__fixint(f64, i64, -1.1, -1);113 test__fixint(f64, i64, -1.1, -1);
...@@ -121,8 +121,8 @@ test "fixint.i64" {...@@ -121,8 +121,8 @@ test "fixint.i64" {
121 test__fixint(f64, i64, 0.1, 0);121 test__fixint(f64, i64, 0.1, 0);
122 test__fixint(f64, i64, 0.9, 0);122 test__fixint(f64, i64, 0.9, 0);
123 test__fixint(f64, i64, 1.0, 1);123 test__fixint(f64, i64, 1.0, 1);
124 test__fixint(f64, i64, f64(math.maxInt(i64)) - 1, math.maxInt(i64));124 test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
125 test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64));125 test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
126 test__fixint(f64, i64, math.f64_max, math.maxInt(i64));126 test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
127 test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));127 test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
128}128}
...@@ -130,8 +130,8 @@ test "fixint.i64" {...@@ -130,8 +130,8 @@ test "fixint.i64" {
130test "fixint.i128" {130test "fixint.i128" {
131 test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));131 test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
132 test__fixint(f64, i128, -math.f64_max, math.minInt(i128));132 test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
133 test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128));133 test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
134 test__fixint(f64, i128, f64(math.minInt(i128)) + 1, math.minInt(i128));134 test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
135 test__fixint(f64, i128, -2.0, -2);135 test__fixint(f64, i128, -2.0, -2);
136 test__fixint(f64, i128, -1.9, -1);136 test__fixint(f64, i128, -1.9, -1);
137 test__fixint(f64, i128, -1.1, -1);137 test__fixint(f64, i128, -1.1, -1);
...@@ -145,8 +145,8 @@ test "fixint.i128" {...@@ -145,8 +145,8 @@ test "fixint.i128" {
145 test__fixint(f64, i128, 0.1, 0);145 test__fixint(f64, i128, 0.1, 0);
146 test__fixint(f64, i128, 0.9, 0);146 test__fixint(f64, i128, 0.9, 0);
147 test__fixint(f64, i128, 1.0, 1);147 test__fixint(f64, i128, 1.0, 1);
148 test__fixint(f64, i128, f64(math.maxInt(i128)) - 1, math.maxInt(i128));148 test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
149 test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128));149 test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
150 test__fixint(f64, i128, math.f64_max, math.maxInt(i128));150 test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
151 test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));151 test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
152}152}
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixsfdi(a: f32, expected: i64) void {7fn test__fixsfdi(a: f32, expected: i64) void {
8 const x = __fixsfdi(a);8 const x = __fixsfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixsfsi(a: f32, expected: i32) void {7fn test__fixsfsi(a: f32, expected: i32) void {
8 const x = __fixsfsi(a);8 const x = __fixsfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixsfti_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixsfti(a: f32, expected: i128) void {7fn test__fixsfti(a: f32, expected: i128) void {
8 const x = __fixsfti(a);8 const x = __fixsfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixtfdi(a: f128, expected: i64) void {7fn test__fixtfdi(a: f128, expected: i64) void {
8 const x = __fixtfdi(a);8 const x = __fixtfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixtfsi(a: f128, expected: i32) void {7fn test__fixtfsi(a: f128, expected: i32) void {
8 const x = __fixtfsi(a);8 const x = __fixtfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixtfti_test.zig+1-1
...@@ -6,7 +6,7 @@ const warn = std.debug.warn;...@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
7fn test__fixtfti(a: f128, expected: i128) void {7fn test__fixtfti(a: f128, expected: i128) void {
8 const x = __fixtfti(a);8 const x = __fixtfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected));9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected));
10 testing.expect(x == expected);10 testing.expect(x == expected);
11}11}
1212
lib/std/special/compiler_rt/fixuint.zig+4-4
...@@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t...@@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
19 };19 };
20 const typeWidth = rep_t.bit_count;20 const typeWidth = rep_t.bit_count;
21 const exponentBits = (typeWidth - significandBits - 1);21 const exponentBits = (typeWidth - significandBits - 1);
22 const signBit = (rep_t(1) << (significandBits + exponentBits));22 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
23 const maxExponent = ((1 << exponentBits) - 1);23 const maxExponent = ((1 << exponentBits) - 1);
24 const exponentBias = (maxExponent >> 1);24 const exponentBias = (maxExponent >> 1);
2525
26 const implicitBit = (rep_t(1) << significandBits);26 const implicitBit = (@as(rep_t, 1) << significandBits);
27 const significandMask = (implicitBit - 1);27 const significandMask = (implicitBit - 1);
2828
29 // Break a into sign, exponent, significand29 // Break a into sign, exponent, significand
...@@ -31,7 +31,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t...@@ -31,7 +31,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
31 const absMask = signBit - 1;31 const absMask = signBit - 1;
32 const aAbs: rep_t = aRep & absMask;32 const aAbs: rep_t = aRep & absMask;
3333
34 const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1);34 const sign = if ((aRep & signBit) != 0) @as(i32, -1) else @as(i32, 1);
35 const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias;35 const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias;
36 const significand: rep_t = (aAbs & significandMask) | implicitBit;36 const significand: rep_t = (aAbs & significandMask) | implicitBit;
3737
...@@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t...@@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
39 if (sign == -1 or exponent < 0) return 0;39 if (sign == -1 or exponent < 0) return 0;
4040
41 // If the value is too large for the integer type, saturate.41 // If the value is too large for the integer type, saturate.
42 if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);42 if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0);
4343
44 // If 0 <= exponent < significandBits, right shift to get the result.44 // If 0 <= exponent < significandBits, right shift to get the result.
45 // Otherwise, shift left.45 // Otherwise, shift left.
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1
...@@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void {...@@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void {
6 testing.expect(x == expected);6 testing.expect(x == expected);
7}7}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
11test "fixunstfsi" {11test "fixunstfsi" {
12 test__fixunstfsi(inf128, 0xffffffff);12 test__fixunstfsi(inf128, 0xffffffff);
lib/std/special/compiler_rt/fixunstfti_test.zig+1-1
...@@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void {...@@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void {
6 testing.expect(x == expected);6 testing.expect(x == expected);
7}7}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
11test "fixunstfti" {11test "fixunstfti" {
12 test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);12 test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
lib/std/special/compiler_rt/floatsiXf.zig+5-5
...@@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T {...@@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T {
6 @setRuntimeSafety(builtin.is_test);6 @setRuntimeSafety(builtin.is_test);
77
8 const Z = @IntType(false, T.bit_count);8 const Z = @IntType(false, T.bit_count);
9 const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1));9 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
1010
11 if (a == 0) {11 if (a == 0) {
12 return T(0.0);12 return @as(T, 0.0);
13 }13 }
1414
15 const significandBits = std.math.floatMantissaBits(T);15 const significandBits = std.math.floatMantissaBits(T);
16 const exponentBits = std.math.floatExponentBits(T);16 const exponentBits = std.math.floatExponentBits(T);
17 const exponentBias = ((1 << exponentBits - 1) - 1);17 const exponentBias = ((1 << exponentBits - 1) - 1);
1818
19 const implicitBit = Z(1) << significandBits;19 const implicitBit = @as(Z, 1) << significandBits;
20 const signBit = Z(1 << Z.bit_count - 1);20 const signBit = @as(Z, 1 << Z.bit_count - 1);
2121
22 const sign = a >> 31;22 const sign = a >> 31;
23 // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31).23 // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31).
24 const abs_a = (a ^ sign) -% sign;24 const abs_a = (a ^ sign) -% sign;
25 // The exponent is the width of abs(a)25 // The exponent is the width of abs(a)
26 const exp = Z(31 - @clz(i32, abs_a));26 const exp = @as(Z, 31 - @clz(i32, abs_a));
2727
28 const sign_bit = if (sign < 0) signBit else 0;28 const sign_bit = if (sign < 0) signBit else 0;
2929
lib/std/special/compiler_rt/floattidf.zig+1-1
...@@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 {...@@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 {
47 a += 1; // round - this step may add a significant bit47 a += 1; // round - this step may add a significant bit
48 a >>= 2; // dump Q and R48 a >>= 2; // dump Q and R
49 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits49 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
50 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {50 if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) {
51 a >>= 1;51 a >>= 1;
52 e += 1;52 e += 1;
53 }53 }
lib/std/special/compiler_rt/floattisf.zig+1-1
...@@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 {...@@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 {
48 a += 1; // round - this step may add a significant bit48 a += 1; // round - this step may add a significant bit
49 a >>= 2; // dump Q and R49 a >>= 2; // dump Q and R
50 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits50 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
51 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {51 if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) {
52 a >>= 1;52 a >>= 1;
53 e += 1;53 e += 1;
54 }54 }
lib/std/special/compiler_rt/floattitf.zig+1-1
...@@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 {...@@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 {
47 a += 1; // round - this step may add a significant bit47 a += 1; // round - this step may add a significant bit
48 a >>= 2; // dump Q and R48 a >>= 2; // dump Q and R
49 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits49 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
50 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {50 if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) {
51 a >>= 1;51 a >>= 1;
52 e += 1;52 e += 1;
53 }53 }
lib/std/special/compiler_rt/floatunsidf.zig+3-3
...@@ -2,7 +2,7 @@ const builtin = @import("builtin");...@@ -2,7 +2,7 @@ const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
44
5const implicitBit = u64(1) << 52;5const implicitBit = @as(u64, 1) << 52;
66
7pub extern fn __floatunsidf(arg: u32) f64 {7pub extern fn __floatunsidf(arg: u32) f64 {
8 @setRuntimeSafety(builtin.is_test);8 @setRuntimeSafety(builtin.is_test);
...@@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 {...@@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 {
10 if (arg == 0) return 0.0;10 if (arg == 0) return 0.0;
1111
12 // The exponent is the width of abs(a)12 // The exponent is the width of abs(a)
13 const exp = u64(31) - @clz(u32, arg);13 const exp = @as(u64, 31) - @clz(u32, arg);
14 // Shift a into the significand field and clear the implicit bit14 // Shift a into the significand field and clear the implicit bit
15 const shift = @intCast(u6, 52 - exp);15 const shift = @intCast(u6, 52 - exp);
16 const mant = u64(arg) << shift ^ implicitBit;16 const mant = @as(u64, arg) << shift ^ implicitBit;
1717
18 return @bitCast(f64, mant | (exp + 1023) << 52);18 return @bitCast(f64, mant | (exp + 1023) << 52);
19}19}
lib/std/special/compiler_rt/floatuntidf.zig+2-2
...@@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {...@@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
32 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;32 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
33 const shift_amt_u7 = @intCast(u7, shift_amt);33 const shift_amt_u7 = @intCast(u7, shift_amt);
34 a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) |34 a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) |
35 @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);35 @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0);
36 },36 },
37 }37 }
38 // finish38 // finish
...@@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {...@@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
40 a += 1; // round - this step may add a significant bit40 a += 1; // round - this step may add a significant bit
41 a >>= 2; // dump Q and R41 a >>= 2; // dump Q and R
42 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits42 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
43 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {43 if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) {
44 a >>= 1;44 a >>= 1;
45 e += 1;45 e += 1;
46 }46 }
lib/std/special/compiler_rt/floatuntisf.zig+2-2
...@@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {...@@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
32 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;32 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
33 const shift_amt_u7 = @intCast(u7, shift_amt);33 const shift_amt_u7 = @intCast(u7, shift_amt);
34 a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) |34 a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) |
35 @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);35 @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0);
36 },36 },
37 }37 }
38 // finish38 // finish
...@@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {...@@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
40 a += 1; // round - this step may add a significant bit40 a += 1; // round - this step may add a significant bit
41 a >>= 2; // dump Q and R41 a >>= 2; // dump Q and R
42 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits42 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
43 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {43 if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) {
44 a >>= 1;44 a >>= 1;
45 e += 1;45 e += 1;
46 }46 }
lib/std/special/compiler_rt/floatuntitf.zig+2-2
...@@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {...@@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
32 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;32 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
33 const shift_amt_u7 = @intCast(u7, shift_amt);33 const shift_amt_u7 = @intCast(u7, shift_amt);
34 a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) |34 a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) |
35 @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);35 @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0);
36 },36 },
37 }37 }
38 // finish38 // finish
...@@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {...@@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
40 a += 1; // round - this step may add a significant bit40 a += 1; // round - this step may add a significant bit
41 a >>= 2; // dump Q and R41 a >>= 2; // dump Q and R
42 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits42 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
43 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {43 if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) {
44 a >>= 1;44 a >>= 1;
45 e += 1;45 e += 1;
46 }46 }
lib/std/special/compiler_rt/mulXf3.zig+25-25
...@@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T {...@@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
24 const significandBits = std.math.floatMantissaBits(T);24 const significandBits = std.math.floatMantissaBits(T);
25 const exponentBits = std.math.floatExponentBits(T);25 const exponentBits = std.math.floatExponentBits(T);
2626
27 const signBit = (Z(1) << (significandBits + exponentBits));27 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
28 const maxExponent = ((1 << exponentBits) - 1);28 const maxExponent = ((1 << exponentBits) - 1);
29 const exponentBias = (maxExponent >> 1);29 const exponentBias = (maxExponent >> 1);
3030
31 const implicitBit = (Z(1) << significandBits);31 const implicitBit = (@as(Z, 1) << significandBits);
32 const quietBit = implicitBit >> 1;32 const quietBit = implicitBit >> 1;
33 const significandMask = implicitBit - 1;33 const significandMask = implicitBit - 1;
3434
...@@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T {...@@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
122 // a zero of the appropriate sign. Mathematically there is no need to122 // a zero of the appropriate sign. Mathematically there is no need to
123 // handle this case separately, but we make it a special case to123 // handle this case separately, but we make it a special case to
124 // simplify the shift logic.124 // simplify the shift logic.
125 const shift: u32 = @truncate(u32, Z(1) -% @bitCast(u32, productExponent));125 const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent));
126 if (shift >= typeWidth) return @bitCast(T, productSign);126 if (shift >= typeWidth) return @bitCast(T, productSign);
127127
128 // Otherwise, shift the significand of the result so that the round128 // Otherwise, shift the significand of the result so that the round
...@@ -131,7 +131,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T {...@@ -131,7 +131,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
131 } else {131 } else {
132 // Result is normal before rounding; insert the exponent.132 // Result is normal before rounding; insert the exponent.
133 productHi &= significandMask;133 productHi &= significandMask;
134 productHi |= Z(@bitCast(u32, productExponent)) << significandBits;134 productHi |= @as(Z, @bitCast(u32, productExponent)) << significandBits;
135 }135 }
136136
137 // Insert the sign of the result:137 // Insert the sign of the result:
...@@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
150 switch (Z) {150 switch (Z) {
151 u32 => {151 u32 => {
152 // 32x32 --> 64 bit multiply152 // 32x32 --> 64 bit multiply
153 const product = u64(a) * u64(b);153 const product = @as(u64, a) * @as(u64, b);
154 hi.* = @truncate(u32, product >> 32);154 hi.* = @truncate(u32, product >> 32);
155 lo.* = @truncate(u32, product);155 lo.* = @truncate(u32, product);
156 },156 },
...@@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
179 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;179 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
180 },180 },
181 u128 => {181 u128 => {
182 const Word_LoMask = u64(0x00000000ffffffff);182 const Word_LoMask = @as(u64, 0x00000000ffffffff);
183 const Word_HiMask = u64(0xffffffff00000000);183 const Word_HiMask = @as(u64, 0xffffffff00000000);
184 const Word_FullMask = u64(0xffffffffffffffff);184 const Word_FullMask = @as(u64, 0xffffffffffffffff);
185 const S = struct {185 const S = struct {
186 fn Word_1(x: u128) u64 {186 fn Word_1(x: u128) u64 {
187 return @truncate(u32, x >> 96);187 return @truncate(u32, x >> 96);
...@@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
217 const product43: u64 = S.Word_4(a) * S.Word_3(b);217 const product43: u64 = S.Word_4(a) * S.Word_3(b);
218 const product44: u64 = S.Word_4(a) * S.Word_4(b);218 const product44: u64 = S.Word_4(a) * S.Word_4(b);
219219
220 const sum0: u128 = u128(product44);220 const sum0: u128 = @as(u128, product44);
221 const sum1: u128 = u128(product34) +%221 const sum1: u128 = @as(u128, product34) +%
222 u128(product43);222 @as(u128, product43);
223 const sum2: u128 = u128(product24) +%223 const sum2: u128 = @as(u128, product24) +%
224 u128(product33) +%224 @as(u128, product33) +%
225 u128(product42);225 @as(u128, product42);
226 const sum3: u128 = u128(product14) +%226 const sum3: u128 = @as(u128, product14) +%
227 u128(product23) +%227 @as(u128, product23) +%
228 u128(product32) +%228 @as(u128, product32) +%
229 u128(product41);229 @as(u128, product41);
230 const sum4: u128 = u128(product13) +%230 const sum4: u128 = @as(u128, product13) +%
231 u128(product22) +%231 @as(u128, product22) +%
232 u128(product31);232 @as(u128, product31);
233 const sum5: u128 = u128(product12) +%233 const sum5: u128 = @as(u128, product12) +%
234 u128(product21);234 @as(u128, product21);
235 const sum6: u128 = u128(product11);235 const sum6: u128 = @as(u128, product11);
236236
237 const r0: u128 = (sum0 & Word_FullMask) +%237 const r0: u128 = (sum0 & Word_FullMask) +%
238 ((sum1 & Word_LoMask) << 32);238 ((sum1 & Word_LoMask) << 32);
...@@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {...@@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
258 @setRuntimeSafety(builtin.is_test);258 @setRuntimeSafety(builtin.is_test);
259 const Z = @IntType(false, T.bit_count);259 const Z = @IntType(false, T.bit_count);
260 const significandBits = std.math.floatMantissaBits(T);260 const significandBits = std.math.floatMantissaBits(T);
261 const implicitBit = Z(1) << significandBits;261 const implicitBit = @as(Z, 1) << significandBits;
262262
263 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);263 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
264 significand.* <<= @intCast(std.math.Log2Int(Z), shift);264 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/mulXf3_test.zig+9-9
...@@ -2,8 +2,8 @@...@@ -2,8 +2,8 @@
2//2//
3// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c3// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c
44
5const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64);5const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
6const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64);6const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
77
8const __multf3 = @import("mulXf3.zig").__multf3;8const __multf3 = @import("mulXf3.zig").__multf3;
99
...@@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {...@@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
39}39}
4040
41fn makeNaN128(rand: u64) f128 {41fn makeNaN128(rand: u64) f128 {
42 const int_result = u128(0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;42 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
43 const float_result = @bitCast(f128, int_result);43 const float_result = @bitCast(f128, int_result);
44 return float_result;44 return float_result;
45}45}
...@@ -55,15 +55,15 @@ test "multf3" {...@@ -55,15 +55,15 @@ test "multf3" {
5555
56 // any * any56 // any * any
57 test__multf3(57 test__multf3(
58 @bitCast(f128, u128(0x40042eab345678439abcdefea5678234)),58 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
59 @bitCast(f128, u128(0x3ffeedcb34a235253948765432134675)),59 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
60 0x400423e7f9e3c9fc,60 0x400423e7f9e3c9fc,
61 0xd906c2c2a85777c4,61 0xd906c2c2a85777c4,
62 );62 );
6363
64 test__multf3(64 test__multf3(
65 @bitCast(f128, u128(0x3fcd353e45674d89abacc3a2ebf3ff50)),65 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
66 @bitCast(f128, u128(0x3ff6ed8764648369535adf4be3214568)),66 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
67 0x3fc52a163c6223fc,67 0x3fc52a163c6223fc,
68 0xc94c4bf0430768b4,68 0xc94c4bf0430768b4,
69 );69 );
...@@ -76,8 +76,8 @@ test "multf3" {...@@ -76,8 +76,8 @@ test "multf3" {
76 );76 );
7777
78 test__multf3(78 test__multf3(
79 @bitCast(f128, u128(0x3f154356473c82a9fabf2d22ace345df)),79 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
80 @bitCast(f128, u128(0x3e38eda98765476743ab21da23d45679)),80 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
81 0x3d4f37c1a3137cae,81 0x3d4f37c1a3137cae,
82 0xfc6807048bc2836a,82 0xfc6807048bc2836a,
83 );83 );
lib/std/special/compiler_rt/muldi3.zig+1-1
...@@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 {...@@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
21 @setRuntimeSafety(builtin.is_test);21 @setRuntimeSafety(builtin.is_test);
2222
23 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;23 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
24 const lower_mask = (~u32(0)) >> bits_in_word_2;24 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
2525
26 var r: dwords = undefined;26 var r: dwords = undefined;
27 r.s.low = (a & lower_mask) *% (b & lower_mask);27 r.s.low = (a & lower_mask) *% (b & lower_mask);
lib/std/special/compiler_rt/mulodi4.zig+1-1
...@@ -6,7 +6,7 @@ const minInt = std.math.minInt;...@@ -6,7 +6,7 @@ const minInt = std.math.minInt;
6pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 {6pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 {
7 @setRuntimeSafety(builtin.is_test);7 @setRuntimeSafety(builtin.is_test);
88
9 const min = @bitCast(i64, u64(1 << (i64.bit_count - 1)));9 const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1)));
10 const max = ~min;10 const max = ~min;
1111
12 overflow.* = 0;12 overflow.* = 0;
lib/std/special/compiler_rt/mulodi4_test.zig+24-24
...@@ -52,34 +52,34 @@ test "mulodi4" {...@@ -52,34 +52,34 @@ test "mulodi4" {
5252
53 test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);53 test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
54 test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);54 test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
55 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, u64(0x8000000000000001)), 0);55 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
56 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 0);56 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
57 test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);57 test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
58 test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);58 test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
59 test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);59 test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
60 test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);60 test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
61 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, u64(0x8000000000000001)), 1);61 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
62 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 1);62 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
6363
64 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -2, @bitCast(i64, u64(0x8000000000000000)), 1);64 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
65 test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);65 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
66 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)), 1);66 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
67 test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);67 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
68 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 0, 0, 0);68 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
69 test__mulodi4(0, @bitCast(i64, u64(0x8000000000000000)), 0, 0);69 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
70 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)), 0);70 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
71 test__mulodi4(1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 0);71 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
72 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0x8000000000000000)), 1);72 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
73 test__mulodi4(2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);73 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
7474
75 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -2, @bitCast(i64, u64(0x8000000000000001)), 1);75 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
76 test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 1);76 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
77 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);77 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
78 test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);78 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
79 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 0, 0, 0);79 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
80 test__mulodi4(0, @bitCast(i64, u64(0x8000000000000001)), 0, 0);80 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
81 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 1, @bitCast(i64, u64(0x8000000000000001)), 0);81 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
82 test__mulodi4(1, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 0);82 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
83 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 2, @bitCast(i64, u64(0x8000000000000000)), 1);83 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
84 test__mulodi4(2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000000)), 1);84 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
85}85}
lib/std/special/compiler_rt/muloti4.zig+1-1
...@@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig");...@@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig");
4pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {4pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
66
7 const min = @bitCast(i128, u128(1 << (i128.bit_count - 1)));7 const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1)));
8 const max = ~min;8 const max = ~min;
9 overflow.* = 0;9 overflow.* = 0;
1010
lib/std/special/compiler_rt/muloti4_test.zig+31-31
...@@ -39,38 +39,38 @@ test "muloti4" {...@@ -39,38 +39,38 @@ test "muloti4" {
39 test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);39 test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
40 test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);40 test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
4141
42 test__muloti4(@bitCast(i128, u128(0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, u128(0x000000000000000000B504F333F9DE5B)), @bitCast(i128, u128(0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);42 test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
43 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);43 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
44 test__muloti4(-2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);44 test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
4545
46 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);46 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
47 test__muloti4(-1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);47 test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
48 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);48 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
49 test__muloti4(0, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);49 test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
50 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);50 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
51 test__muloti4(1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);51 test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
52 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);52 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
53 test__muloti4(2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);53 test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
5454
55 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);55 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
56 test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);56 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
57 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);57 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
58 test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);58 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
59 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0, 0);59 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
60 test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0);60 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
61 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0);61 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
62 test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 0);62 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
63 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);63 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
64 test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);64 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
6565
66 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);66 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
67 test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);67 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
68 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);68 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
69 test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);69 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
70 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0, 0);70 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
71 test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0);71 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
72 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);72 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
73 test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);73 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
74 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);74 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
75 test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);75 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
76}76}
lib/std/special/compiler_rt/multi3.zig+1-1
...@@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 {...@@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 {
2121
22fn __mulddi3(a: u64, b: u64) i128 {22fn __mulddi3(a: u64, b: u64) i128 {
23 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;23 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;
24 const lower_mask = ~u64(0) >> bits_in_dword_2;24 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;
25 var r: twords = undefined;25 var r: twords = undefined;
26 r.s.low = (a & lower_mask) *% (b & lower_mask);26 r.s.low = (a & lower_mask) *% (b & lower_mask);
27 var t: u64 = r.s.low >> bits_in_dword_2;27 var t: u64 = r.s.low >> bits_in_dword_2;
lib/std/special/compiler_rt/negXf2.zig+1-1
...@@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T {...@@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T {
15 const significandBits = std.math.floatMantissaBits(T);15 const significandBits = std.math.floatMantissaBits(T);
16 const exponentBits = std.math.floatExponentBits(T);16 const exponentBits = std.math.floatExponentBits(T);
1717
18 const signBit = (Z(1) << (significandBits + exponentBits));18 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1919
20 return @bitCast(T, @bitCast(Z, a) ^ signBit);20 return @bitCast(T, @bitCast(Z, a) ^ signBit);
21}21}
lib/std/special/compiler_rt/popcountdi2_test.zig+3-3
...@@ -20,8 +20,8 @@ test "popcountdi2" {...@@ -20,8 +20,8 @@ test "popcountdi2" {
20 test__popcountdi2(0);20 test__popcountdi2(0);
21 test__popcountdi2(1);21 test__popcountdi2(1);
22 test__popcountdi2(2);22 test__popcountdi2(2);
23 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFD)));23 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
24 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFE)));24 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
25 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFF)));25 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
26 // TODO some fuzz testing26 // TODO some fuzz testing
27}27}
lib/std/special/compiler_rt/truncXfYf2.zig+1-1
...@@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t...@@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
69 // destination format. We can convert by simply right-shifting with69 // destination format. We can convert by simply right-shifting with
70 // rounding and adjusting the exponent.70 // rounding and adjusting the exponent.
71 absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits));71 absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits));
72 absResult -%= dst_rep_t(srcExpBias - dstExpBias) << dstSigBits;72 absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits;
7373
74 const roundBits: src_rep_t = aAbs & roundMask;74 const roundBits: src_rep_t = aAbs & roundMask;
75 if (roundBits > halfway) {75 if (roundBits > halfway) {
lib/std/special/compiler_rt/truncXfYf2_test.zig+10-10
...@@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {...@@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
152152
153test "trunctfsf2" {153test "trunctfsf2" {
154 // qnan154 // qnan
155 test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000);155 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
156 // nan156 // nan
157 test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);157 test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);
158 // inf158 // inf
159 test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000);159 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000);
160 // zero160 // zero
161 test__trunctfsf2(0.0, 0x0);161 test__trunctfsf2(0.0, 0x0);
162162
...@@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {...@@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
187187
188test "trunctfdf2" {188test "trunctfdf2" {
189 // qnan189 // qnan
190 test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000);190 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
191 // nan191 // nan
192 test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);192 test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);
193 // inf193 // inf
194 test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000);194 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);
195 // zero195 // zero
196 test__trunctfdf2(0.0, 0x0);196 test__trunctfdf2(0.0, 0x0);
197197
...@@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {...@@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
224224
225test "truncdfsf2" {225test "truncdfsf2" {
226 // nan & qnan226 // nan & qnan
227 test__truncdfsf2(@bitCast(f64, u64(0x7ff8000000000000)), 0x7fc00000);227 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000);
228 test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000001)), 0x7fc00000);228 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000);
229 // inf229 // inf
230 test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000000)), 0x7f800000);230 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000);
231 test__truncdfsf2(@bitCast(f64, u64(0xfff0000000000000)), 0xff800000);231 test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000);
232232
233 test__truncdfsf2(0.0, 0x0);233 test__truncdfsf2(0.0, 0x0);
234 test__truncdfsf2(1.0, 0x3f800000);234 test__truncdfsf2(1.0, 0x3f800000);
lib/std/special/compiler_rt/udivmod.zig+3-3
...@@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
76 // K K76 // K K
77 // ---77 // ---
78 // K 078 // K 0
79 sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high])));79 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
80 // 0 <= sr <= SingleInt.bit_count - 2 or sr large80 // 0 <= sr <= SingleInt.bit_count - 2 or sr large
81 if (sr > SingleInt.bit_count - 2) {81 if (sr > SingleInt.bit_count - 2) {
82 if (maybe_rem) |rem| {82 if (maybe_rem) |rem| {
...@@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
114 // K X114 // K X
115 // ---115 // ---
116 // 0 K116 // 0 K
117 sr = 1 + SingleInt.bit_count + c_uint(@clz(SingleInt, d[low])) - c_uint(@clz(SingleInt, n[high]));117 sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
118 // 2 <= sr <= DoubleInt.bit_count - 1118 // 2 <= sr <= DoubleInt.bit_count - 1
119 // q.all = a << (DoubleInt.bit_count - sr);119 // q.all = a << (DoubleInt.bit_count - sr);
120 // r.all = a >> sr;120 // r.all = a >> sr;
...@@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
140 // K X140 // K X
141 // ---141 // ---
142 // K K142 // K K
143 sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high])));143 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
144 // 0 <= sr <= SingleInt.bit_count - 1 or sr large144 // 0 <= sr <= SingleInt.bit_count - 1 or sr large
145 if (sr > SingleInt.bit_count - 1) {145 if (sr > SingleInt.bit_count - 1) {
146 if (maybe_rem) |rem| {146 if (maybe_rem) |rem| {
lib/std/target.zig+1-1
...@@ -581,7 +581,7 @@ pub const Target = union(enum) {...@@ -581,7 +581,7 @@ pub const Target = union(enum) {
581 };581 };
582582
583 pub fn getExternalExecutor(self: Target) Executor {583 pub fn getExternalExecutor(self: Target) Executor {
584 if (@TagType(Target)(self) == .Native) return .native;584 if (@as(@TagType(Target),self) == .Native) return .native;
585585
586 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.586 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
587 if (self.getOs() == builtin.os) {587 if (self.getOs() == builtin.os) {
lib/std/thread.zig+1-1
...@@ -344,7 +344,7 @@ pub const Thread = struct {...@@ -344,7 +344,7 @@ pub const Thread = struct {
344 pub fn cpuCount() CpuCountError!usize {344 pub fn cpuCount() CpuCountError!usize {
345 if (builtin.os == .linux) {345 if (builtin.os == .linux) {
346 const cpu_set = try os.sched_getaffinity(0);346 const cpu_set = try os.sched_getaffinity(0);
347 return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast347 return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
348 }348 }
349 if (builtin.os == .windows) {349 if (builtin.os == .windows) {
350 var system_info: windows.SYSTEM_INFO = undefined;350 var system_info: windows.SYSTEM_INFO = undefined;
lib/std/time.zig+4-4
...@@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 {...@@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 {
38 const hns_per_ms = (ns_per_s / 100) / ms_per_s;38 const hns_per_ms = (ns_per_s / 100) / ms_per_s;
39 const epoch_adj = epoch.windows * ms_per_s;39 const epoch_adj = epoch.windows * ms_per_s;
4040
41 const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;41 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
42 return @divFloor(ft64, hns_per_ms) - -epoch_adj;42 return @divFloor(ft64, hns_per_ms) - -epoch_adj;
43 }43 }
44 if (builtin.os == .wasi and !builtin.link_libc) {44 if (builtin.os == .wasi and !builtin.link_libc) {
...@@ -142,10 +142,10 @@ pub const Timer = struct {...@@ -142,10 +142,10 @@ pub const Timer = struct {
142 // seccomp is going to block us it will at least do so consistently142 // seccomp is going to block us it will at least do so consistently
143 var ts: os.timespec = undefined;143 var ts: os.timespec = undefined;
144 os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported;144 os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported;
145 self.resolution = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);145 self.resolution = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec);
146146
147 os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported;147 os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported;
148 self.start_time = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);148 self.start_time = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec);
149 }149 }
150150
151 return self;151 return self;
...@@ -185,7 +185,7 @@ pub const Timer = struct {...@@ -185,7 +185,7 @@ pub const Timer = struct {
185 }185 }
186 var ts: os.timespec = undefined;186 var ts: os.timespec = undefined;
187 os.clock_gettime(monotonic_clock_id, &ts) catch unreachable;187 os.clock_gettime(monotonic_clock_id, &ts) catch unreachable;
188 return @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);188 return @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec);
189 }189 }
190};190};
191191
lib/std/unicode.zig+5-5
...@@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error...@@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error
68/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.68/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
69pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 {69pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 {
70 return switch (bytes.len) {70 return switch (bytes.len) {
71 1 => u32(bytes[0]),71 1 => @as(u32, bytes[0]),
72 2 => utf8Decode2(bytes),72 2 => utf8Decode2(bytes),
73 3 => utf8Decode3(bytes),73 3 => utf8Decode3(bytes),
74 4 => utf8Decode4(bytes),74 4 => utf8Decode4(bytes),
...@@ -226,7 +226,7 @@ pub const Utf8Iterator = struct {...@@ -226,7 +226,7 @@ pub const Utf8Iterator = struct {
226 const slice = it.nextCodepointSlice() orelse return null;226 const slice = it.nextCodepointSlice() orelse return null;
227227
228 switch (slice.len) {228 switch (slice.len) {
229 1 => return u32(slice[0]),229 1 => return @as(u32, slice[0]),
230 2 => return utf8Decode2(slice) catch unreachable,230 2 => return utf8Decode2(slice) catch unreachable,
231 3 => return utf8Decode3(slice) catch unreachable,231 3 => return utf8Decode3(slice) catch unreachable,
232 4 => return utf8Decode4(slice) catch unreachable,232 4 => return utf8Decode4(slice) catch unreachable,
...@@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct {...@@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct {
250 assert(it.i <= it.bytes.len);250 assert(it.i <= it.bytes.len);
251 if (it.i == it.bytes.len) return null;251 if (it.i == it.bytes.len) return null;
252 const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]);252 const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]);
253 if (c0 & ~u32(0x03ff) == 0xd800) {253 if (c0 & ~@as(u32, 0x03ff) == 0xd800) {
254 // surrogate pair254 // surrogate pair
255 it.i += 2;255 it.i += 2;
256 if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf;256 if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf;
257 const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]);257 const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]);
258 if (c1 & ~u32(0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf;258 if (c1 & ~@as(u32, 0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf;
259 it.i += 2;259 it.i += 2;
260 return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff));260 return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff));
261 } else if (c0 & ~u32(0x03ff) == 0xdc00) {261 } else if (c0 & ~@as(u32, 0x03ff) == 0xdc00) {
262 return error.UnexpectedSecondSurrogateHalf;262 return error.UnexpectedSecondSurrogateHalf;
263 } else {263 } else {
264 it.i += 2;264 it.i += 2;
lib/std/valgrind.zig+1-1
...@@ -76,7 +76,7 @@ pub const ClientRequest = extern enum {...@@ -76,7 +76,7 @@ pub const ClientRequest = extern enum {
76 InnerThreads = 6402,76 InnerThreads = 6402,
77};77};
78pub fn ToolBase(base: [2]u8) u32 {78pub fn ToolBase(base: [2]u8) u32 {
79 return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16);79 return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16);
80}80}
81pub fn IsTool(base: [2]u8, code: usize) bool {81pub fn IsTool(base: [2]u8, code: usize) bool {
82 return ToolBase(base) == (code & 0xffff0000);82 return ToolBase(base) == (code & 0xffff0000);
lib/std/zig/parse_string_literal.zig+1-1
...@@ -19,7 +19,7 @@ pub fn parseStringLiteral(...@@ -19,7 +19,7 @@ pub fn parseStringLiteral(
19 bytes: []const u8,19 bytes: []const u8,
20 bad_index: *usize, // populated if error.InvalidCharacter is returned20 bad_index: *usize, // populated if error.InvalidCharacter is returned
21) ParseStringLiteralError![]u8 {21) ParseStringLiteralError![]u8 {
22 const first_index = if (bytes[0] == 'c') usize(2) else usize(1);22 const first_index = if (bytes[0] == 'c') @as(usize, 2) else @as(usize, 1);
23 assert(bytes[bytes.len - 1] == '"');23 assert(bytes[bytes.len - 1] == '"');
2424
25 var list = std.ArrayList(u8).init(allocator);25 var list = std.ArrayList(u8).init(allocator);
lib/std/zig/parser_test.zig+1-1
...@@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" {...@@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" {
37 \\test "" {37 \\test "" {
38 \\ const result = while (returnError()) |value| {38 \\ const result = while (returnError()) |value| {
39 \\ break value;39 \\ break value;
40 \\ } else |err| i32(2);40 \\ } else |err| @as(i32, 2);
41 \\ expect(result == 2);41 \\ expect(result == 2);
42 \\}42 \\}
43 \\43 \\
lib/std/zig/render.zig+3-3
...@@ -410,8 +410,8 @@ fn renderExpression(...@@ -410,8 +410,8 @@ fn renderExpression(
410 switch (prefix_op_node.op) {410 switch (prefix_op_node.op) {
411 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {411 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
412 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {412 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {
413 Token.Id.AsteriskAsterisk => usize(1),413 Token.Id.AsteriskAsterisk => @as(usize, 1),
414 else => usize(0),414 else => @as(usize, 0),
415 };415 };
416 try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // *416 try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // *
417 if (ptr_info.allowzero_token) |allowzero_token| {417 if (ptr_info.allowzero_token) |allowzero_token| {
...@@ -2097,7 +2097,7 @@ fn renderTokenOffset(...@@ -2097,7 +2097,7 @@ fn renderTokenOffset(
20972097
2098 while (true) {2098 while (true) {
2099 assert(loc.line != 0);2099 assert(loc.line != 0);
2100 const newline_count = if (loc.line == 1) u8(1) else u8(2);2100 const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2);
2101 try stream.writeByteNTimes('\n', newline_count);2101 try stream.writeByteNTimes('\n', newline_count);
2102 try stream.writeByteNTimes(' ', indent);2102 try stream.writeByteNTimes(' ', indent);
2103 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));2103 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
lib/std/zig/tokenizer.zig+1-1
...@@ -350,7 +350,7 @@ pub const Tokenizer = struct {...@@ -350,7 +350,7 @@ pub const Tokenizer = struct {
350 };350 };
351 } else {351 } else {
352 // Skip the UTF-8 BOM if present352 // Skip the UTF-8 BOM if present
353 const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0);353 const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else @as(usize, 0);
354 return Tokenizer{354 return Tokenizer{
355 .buffer = buffer,355 .buffer = buffer,
356 .index = src_start,356 .index = src_start,
test/compare_output.zig+25-25
...@@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
122 \\122 \\
123 \\pub fn main() void {123 \\pub fn main() void {
124 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;124 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
125 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;125 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable;
126 \\}126 \\}
127 , "Hello, world!\n 12 12 a\n");127 , "Hello, world!\n 12 12 a\n");
128128
...@@ -166,54 +166,54 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -166,54 +166,54 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
166 \\ _ = c.printf(c"\n");166 \\ _ = c.printf(c"\n");
167 \\167 \\
168 \\ _ = c.printf(c"0.0: %.013a\n",168 \\ _ = c.printf(c"0.0: %.013a\n",
169 \\ f64(0.0));169 \\ @as(f64, 0.0));
170 \\ _ = c.printf(c"0e0: %.013a\n",170 \\ _ = c.printf(c"0e0: %.013a\n",
171 \\ f64(0e0));171 \\ @as(f64, 0e0));
172 \\ _ = c.printf(c"0.0e0: %.013a\n",172 \\ _ = c.printf(c"0.0e0: %.013a\n",
173 \\ f64(0.0e0));173 \\ @as(f64, 0.0e0));
174 \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",174 \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
175 \\ f64(000000000000000000000000000000000000000000000000000000000.0e0));175 \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0));
176 \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",176 \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
177 \\ f64(0.000000000000000000000000000000000000000000000000000000000e0));177 \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0));
178 \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",178 \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
179 \\ f64(0.0e000000000000000000000000000000000000000000000000000000000));179 \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000));
180 \\ _ = c.printf(c"1.0: %.013a\n",180 \\ _ = c.printf(c"1.0: %.013a\n",
181 \\ f64(1.0));181 \\ @as(f64, 1.0));
182 \\ _ = c.printf(c"10.0: %.013a\n",182 \\ _ = c.printf(c"10.0: %.013a\n",
183 \\ f64(10.0));183 \\ @as(f64, 10.0));
184 \\ _ = c.printf(c"10.5: %.013a\n",184 \\ _ = c.printf(c"10.5: %.013a\n",
185 \\ f64(10.5));185 \\ @as(f64, 10.5));
186 \\ _ = c.printf(c"10.5e5: %.013a\n",186 \\ _ = c.printf(c"10.5e5: %.013a\n",
187 \\ f64(10.5e5));187 \\ @as(f64, 10.5e5));
188 \\ _ = c.printf(c"10.5e+5: %.013a\n",188 \\ _ = c.printf(c"10.5e+5: %.013a\n",
189 \\ f64(10.5e+5));189 \\ @as(f64, 10.5e+5));
190 \\ _ = c.printf(c"50.0e-2: %.013a\n",190 \\ _ = c.printf(c"50.0e-2: %.013a\n",
191 \\ f64(50.0e-2));191 \\ @as(f64, 50.0e-2));
192 \\ _ = c.printf(c"50e-2: %.013a\n",192 \\ _ = c.printf(c"50e-2: %.013a\n",
193 \\ f64(50e-2));193 \\ @as(f64, 50e-2));
194 \\194 \\
195 \\ _ = c.printf(c"\n");195 \\ _ = c.printf(c"\n");
196 \\196 \\
197 \\ _ = c.printf(c"0x1.0: %.013a\n",197 \\ _ = c.printf(c"0x1.0: %.013a\n",
198 \\ f64(0x1.0));198 \\ @as(f64, 0x1.0));
199 \\ _ = c.printf(c"0x10.0: %.013a\n",199 \\ _ = c.printf(c"0x10.0: %.013a\n",
200 \\ f64(0x10.0));200 \\ @as(f64, 0x10.0));
201 \\ _ = c.printf(c"0x100.0: %.013a\n",201 \\ _ = c.printf(c"0x100.0: %.013a\n",
202 \\ f64(0x100.0));202 \\ @as(f64, 0x100.0));
203 \\ _ = c.printf(c"0x103.0: %.013a\n",203 \\ _ = c.printf(c"0x103.0: %.013a\n",
204 \\ f64(0x103.0));204 \\ @as(f64, 0x103.0));
205 \\ _ = c.printf(c"0x103.7: %.013a\n",205 \\ _ = c.printf(c"0x103.7: %.013a\n",
206 \\ f64(0x103.7));206 \\ @as(f64, 0x103.7));
207 \\ _ = c.printf(c"0x103.70: %.013a\n",207 \\ _ = c.printf(c"0x103.70: %.013a\n",
208 \\ f64(0x103.70));208 \\ @as(f64, 0x103.70));
209 \\ _ = c.printf(c"0x103.70p4: %.013a\n",209 \\ _ = c.printf(c"0x103.70p4: %.013a\n",
210 \\ f64(0x103.70p4));210 \\ @as(f64, 0x103.70p4));
211 \\ _ = c.printf(c"0x103.70p5: %.013a\n",211 \\ _ = c.printf(c"0x103.70p5: %.013a\n",
212 \\ f64(0x103.70p5));212 \\ @as(f64, 0x103.70p5));
213 \\ _ = c.printf(c"0x103.70p+5: %.013a\n",213 \\ _ = c.printf(c"0x103.70p+5: %.013a\n",
214 \\ f64(0x103.70p+5));214 \\ @as(f64, 0x103.70p+5));
215 \\ _ = c.printf(c"0x103.70p-5: %.013a\n",215 \\ _ = c.printf(c"0x103.70p-5: %.013a\n",
216 \\ f64(0x103.70p-5));216 \\ @as(f64, 0x103.70p-5));
217 \\217 \\
218 \\ return 0;218 \\ return 0;
219 \\}219 \\}
...@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
323 \\ const x: f64 = small;323 \\ const x: f64 = small;
324 \\ const y = @floatToInt(i32, x);324 \\ const y = @floatToInt(i32, x);
325 \\ const z = @intToFloat(f64, y);325 \\ const z = @intToFloat(f64, y);
326 \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4));326 \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));
327 \\ return 0;327 \\ return 0;
328 \\}328 \\}
329 , "3.25\n3\n3.00\n-0.40\n");329 , "3.25\n3\n3.00\n-0.40\n");
test/compile_errors.zig+26-26
...@@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
186 cases.add(186 cases.add(
187 "shift amount has to be an integer type",187 "shift amount has to be an integer type",
188 \\export fn entry() void {188 \\export fn entry() void {
189 \\ const x = 1 << &u8(10);189 \\ const x = 1 << &@as(u8, 10);
190 \\}190 \\}
191 ,191 ,
192 "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'",192 "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'",
...@@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
196 cases.add(196 cases.add(
197 "bit shifting only works on integer types",197 "bit shifting only works on integer types",
198 \\export fn entry() void {198 \\export fn entry() void {
199 \\ const x = &u8(1) << 10;199 \\ const x = &@as(u8, 1) << 10;
200 \\}200 \\}
201 ,201 ,
202 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",202 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",
...@@ -241,7 +241,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -241,7 +241,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
241 \\ var x: []align(true) i32 = undefined;241 \\ var x: []align(true) i32 = undefined;
242 \\}242 \\}
243 \\export fn entry2() void {243 \\export fn entry2() void {
244 \\ var x: *align(f64(12.34)) i32 = undefined;244 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
245 \\}245 \\}
246 ,246 ,
247 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",247 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
...@@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1297 cases.add(1297 cases.add(
1298 "@truncate undefined value",1298 "@truncate undefined value",
1299 \\export fn entry() void {1299 \\export fn entry() void {
1300 \\ var z = @truncate(u8, u16(undefined));1300 \\ var z = @truncate(u8, @as(u16, undefined));
1301 \\}1301 \\}
1302 ,1302 ,
1303 "tmp.zig:2:30: error: use of undefined value here causes undefined behavior",1303 "tmp.zig:2:30: error: use of undefined value here causes undefined behavior",
...@@ -1686,7 +1686,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1686,7 +1686,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1686 cases.add(1686 cases.add(
1687 "non float passed to @floatToInt",1687 "non float passed to @floatToInt",
1688 \\export fn entry() void {1688 \\export fn entry() void {
1689 \\ const x = @floatToInt(i32, i32(54));1689 \\ const x = @floatToInt(i32, @as(i32, 54));
1690 \\}1690 \\}
1691 ,1691 ,
1692 "tmp.zig:2:35: error: expected float type, found 'i32'",1692 "tmp.zig:2:35: error: expected float type, found 'i32'",
...@@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2197 cases.add(2197 cases.add(
2198 "error when evaluating return type",2198 "error when evaluating return type",
2199 \\const Foo = struct {2199 \\const Foo = struct {
2200 \\ map: i32(i32),2200 \\ map: @as(i32, i32),
2201 \\2201 \\
2202 \\ fn init() Foo {2202 \\ fn init() Foo {
2203 \\ return undefined;2203 \\ return undefined;
...@@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2338 cases.add(2338 cases.add(
2339 "var not allowed in structs",2339 "var not allowed in structs",
2340 \\export fn entry() void {2340 \\export fn entry() void {
2341 \\ var s = (struct{v: var}){.v=i32(10)};2341 \\ var s = (struct{v: var}){.v=@as(i32, 10)};
2342 \\}2342 \\}
2343 ,2343 ,
2344 "tmp.zig:2:23: error: invalid token: 'var'",2344 "tmp.zig:2:23: error: invalid token: 'var'",
...@@ -2657,7 +2657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2657,7 +2657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2657 cases.add(2657 cases.add(
2658 "cast negative integer literal to usize",2658 "cast negative integer literal to usize",
2659 \\export fn entry() void {2659 \\export fn entry() void {
2660 \\ const x = usize(-10);2660 \\ const x = @as(usize, -10);
2661 \\}2661 \\}
2662 ,2662 ,
2663 "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'",2663 "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'",
...@@ -3384,7 +3384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3384,7 +3384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3384 \\ const x : i32 = if (b) h: { break :h 1; };3384 \\ const x : i32 = if (b) h: { break :h 1; };
3385 \\}3385 \\}
3386 \\fn g(b: bool) void {3386 \\fn g(b: bool) void {
3387 \\ const y = if (b) h: { break :h i32(1); };3387 \\ const y = if (b) h: { break :h @as(i32, 1); };
3388 \\}3388 \\}
3389 \\export fn entry() void { f(true); g(true); }3389 \\export fn entry() void { f(true); g(true); }
3390 ,3390 ,
...@@ -3520,7 +3520,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3520,7 +3520,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3520 cases.add(3520 cases.add(
3521 "cast unreachable",3521 "cast unreachable",
3522 \\fn f() i32 {3522 \\fn f() i32 {
3523 \\ return i32(return 1);3523 \\ return @as(i32, return 1);
3524 \\}3524 \\}
3525 \\export fn entry() void { _ = f(); }3525 \\export fn entry() void { _ = f(); }
3526 ,3526 ,
...@@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3595 \\ switch (n) {3595 \\ switch (n) {
3596 \\ Number.One => 1,3596 \\ Number.One => 1,
3597 \\ Number.Two => 2,3597 \\ Number.Two => 2,
3598 \\ Number.Three => i32(3),3598 \\ Number.Three => @as(i32, 3),
3599 \\ }3599 \\ }
3600 \\}3600 \\}
3601 \\3601 \\
...@@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3616 \\ switch (n) {3616 \\ switch (n) {
3617 \\ Number.One => 1,3617 \\ Number.One => 1,
3618 \\ Number.Two => 2,3618 \\ Number.Two => 2,
3619 \\ Number.Three => i32(3),3619 \\ Number.Three => @as(i32, 3),
3620 \\ Number.Four => 4,3620 \\ Number.Four => 4,
3621 \\ Number.Two => 2,3621 \\ Number.Two => 2,
3622 \\ }3622 \\ }
...@@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3640 \\ switch (n) {3640 \\ switch (n) {
3641 \\ Number.One => 1,3641 \\ Number.One => 1,
3642 \\ Number.Two => 2,3642 \\ Number.Two => 2,
3643 \\ Number.Three => i32(3),3643 \\ Number.Three => @as(i32, 3),
3644 \\ Number.Four => 4,3644 \\ Number.Four => 4,
3645 \\ Number.Two => 2,3645 \\ Number.Two => 2,
3646 \\ else => 10,3646 \\ else => 10,
...@@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3685 "switch expression - duplicate or overlapping integer value",3685 "switch expression - duplicate or overlapping integer value",
3686 \\fn foo(x: u8) u8 {3686 \\fn foo(x: u8) u8 {
3687 \\ return switch (x) {3687 \\ return switch (x) {
3688 \\ 0 ... 100 => u8(0),3688 \\ 0 ... 100 => @as(u8, 0),
3689 \\ 101 ... 200 => 1,3689 \\ 101 ... 200 => 1,
3690 \\ 201, 203 ... 207 => 2,3690 \\ 201, 203 ... 207 => 2,
3691 \\ 206 ... 255 => 3,3691 \\ 206 ... 255 => 3,
...@@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3722 cases.add(3722 cases.add(
3723 "array concatenation with wrong type",3723 "array concatenation with wrong type",
3724 \\const src = "aoeu";3724 \\const src = "aoeu";
3725 \\const derp = usize(1234);3725 \\const derp = @as(usize, 1234);
3726 \\const a = derp ++ "foo";3726 \\const a = derp ++ "foo";
3727 \\3727 \\
3728 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }3728 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
...@@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3887 "division by zero",3887 "division by zero",
3888 \\const lit_int_x = 1 / 0;3888 \\const lit_int_x = 1 / 0;
3889 \\const lit_float_x = 1.0 / 0.0;3889 \\const lit_float_x = 1.0 / 0.0;
3890 \\const int_x = u32(1) / u32(0);3890 \\const int_x = @as(u32, 1) / @as(u32, 0);
3891 \\const float_x = f32(1.0) / f32(0.0);3891 \\const float_x = f32(1.0) / f32(0.0);
3892 \\3892 \\
3893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }3893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
...@@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4590 \\var bytes: [ext()]u8 = undefined;4590 \\var bytes: [ext()]u8 = undefined;
4591 \\export fn f() void {4591 \\export fn f() void {
4592 \\ for (bytes) |*b, i| {4592 \\ for (bytes) |*b, i| {
4593 \\ b.* = u8(i);4593 \\ b.* = @as(u8, i);
4594 \\ }4594 \\ }
4595 \\}4595 \\}
4596 ,4596 ,
...@@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4874 \\}4874 \\}
4875 \\4875 \\
4876 \\fn foo() i32 {4876 \\fn foo() i32 {
4877 \\ return add(i32(1234));4877 \\ return add(@as(i32, 1234));
4878 \\}4878 \\}
4879 \\4879 \\
4880 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }4880 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
...@@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4886 cases.add(4886 cases.add(
4887 "pass integer literal to var args",4887 "pass integer literal to var args",
4888 \\fn add(args: ...) i32 {4888 \\fn add(args: ...) i32 {
4889 \\ var sum = i32(0);4889 \\ var sum = @as(i32, 0);
4890 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {4890 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
4891 \\ sum += args[i];4891 \\ sum += args[i];
4892 \\ }}4892 \\ }}
...@@ -5581,7 +5581,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5581,7 +5581,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5581 cases.add(5581 cases.add(
5582 "explicit cast float literal to integer when there is a fraction component",5582 "explicit cast float literal to integer when there is a fraction component",
5583 \\export fn entry() i32 {5583 \\export fn entry() i32 {
5584 \\ return i32(12.34);5584 \\ return @as(i32, 12.34);
5585 \\}5585 \\}
5586 ,5586 ,
5587 "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",5587 "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
...@@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5599 cases.add(5599 cases.add(
5600 "@shlExact shifts out 1 bits",5600 "@shlExact shifts out 1 bits",
5601 \\comptime {5601 \\comptime {
5602 \\ const x = @shlExact(u8(0b01010101), 2);5602 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
5603 \\}5603 \\}
5604 ,5604 ,
5605 "tmp.zig:2:15: error: operation caused overflow",5605 "tmp.zig:2:15: error: operation caused overflow",
...@@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5608 cases.add(5608 cases.add(
5609 "@shrExact shifts out 1 bits",5609 "@shrExact shifts out 1 bits",
5610 \\comptime {5610 \\comptime {
5611 \\ const x = @shrExact(u8(0b10101010), 2);5611 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
5612 \\}5612 \\}
5613 ,5613 ,
5614 "tmp.zig:2:15: error: exact shift shifted out 1 bits",5614 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
...@@ -5699,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5699,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5699 cases.add(5699 cases.add(
5700 "@alignCast expects pointer or slice",5700 "@alignCast expects pointer or slice",
5701 \\export fn entry() void {5701 \\export fn entry() void {
5702 \\ @alignCast(4, u32(3));5702 \\ @alignCast(4, @as(u32, 3));
5703 \\}5703 \\}
5704 ,5704 ,
5705 "tmp.zig:2:22: error: expected pointer or slice, found 'u32'",5705 "tmp.zig:2:22: error: expected pointer or slice, found 'u32'",
...@@ -5744,7 +5744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5744,7 +5744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5744 \\const Derp = @OpaqueType();5744 \\const Derp = @OpaqueType();
5745 \\extern fn bar(d: *Derp) void;5745 \\extern fn bar(d: *Derp) void;
5746 \\export fn foo() void {5746 \\export fn foo() void {
5747 \\ var x = u8(1);5747 \\ var x = @as(u8, 1);
5748 \\ bar(@ptrCast(*c_void, &x));5748 \\ bar(@ptrCast(*c_void, &x));
5749 \\}5749 \\}
5750 ,5750 ,
...@@ -5800,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5800,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5800 "wrong types given to atomic order args in cmpxchg",5800 "wrong types given to atomic order args in cmpxchg",
5801 \\export fn entry() void {5801 \\export fn entry() void {
5802 \\ var x: i32 = 1234;5802 \\ var x: i32 = 1234;
5803 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {}5803 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
5804 \\}5804 \\}
5805 ,5805 ,
5806 "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'",5806 "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
...@@ -5810,7 +5810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5810,7 +5810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5810 "wrong types given to @export",5810 "wrong types given to @export",
5811 \\extern fn entry() void { }5811 \\extern fn entry() void { }
5812 \\comptime {5812 \\comptime {
5813 \\ @export("entry", entry, u32(1234));5813 \\ @export("entry", entry, @as(u32, 1234));
5814 \\}5814 \\}
5815 ,5815 ,
5816 "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",5816 "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
test/stage1/behavior.zig+5-5
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1comptime {1comptime {
2 _ = @import("behavior/align.zig");2 //_ = @import("behavior/align.zig");
3 _ = @import("behavior/alignof.zig");3 _ = @import("behavior/alignof.zig");
4 _ = @import("behavior/array.zig");4 //_ = @import("behavior/array.zig");
5 _ = @import("behavior/asm.zig");5 _ = @import("behavior/asm.zig");
6 _ = @import("behavior/async_fn.zig");6 _ = @import("behavior/async_fn.zig");
7 _ = @import("behavior/atomics.zig");7 _ = @import("behavior/atomics.zig");
...@@ -50,7 +50,7 @@ comptime {...@@ -50,7 +50,7 @@ comptime {
50 _ = @import("behavior/bugs/920.zig");50 _ = @import("behavior/bugs/920.zig");
51 _ = @import("behavior/byteswap.zig");51 _ = @import("behavior/byteswap.zig");
52 _ = @import("behavior/byval_arg_var.zig");52 _ = @import("behavior/byval_arg_var.zig");
53 _ = @import("behavior/cast.zig");53 //_ = @import("behavior/cast.zig");
54 _ = @import("behavior/const_slice_child.zig");54 _ = @import("behavior/const_slice_child.zig");
55 _ = @import("behavior/defer.zig");55 _ = @import("behavior/defer.zig");
56 _ = @import("behavior/enum.zig");56 _ = @import("behavior/enum.zig");
...@@ -59,7 +59,7 @@ comptime {...@@ -59,7 +59,7 @@ comptime {
59 _ = @import("behavior/eval.zig");59 _ = @import("behavior/eval.zig");
60 _ = @import("behavior/field_parent_ptr.zig");60 _ = @import("behavior/field_parent_ptr.zig");
61 _ = @import("behavior/floatop.zig");61 _ = @import("behavior/floatop.zig");
62 _ = @import("behavior/fn.zig");62 //_ = @import("behavior/fn.zig");
63 _ = @import("behavior/fn_in_struct_in_comptime.zig");63 _ = @import("behavior/fn_in_struct_in_comptime.zig");
64 _ = @import("behavior/fn_delegation.zig");64 _ = @import("behavior/fn_delegation.zig");
65 _ = @import("behavior/for.zig");65 _ = @import("behavior/for.zig");
...@@ -73,7 +73,7 @@ comptime {...@@ -73,7 +73,7 @@ comptime {
73 _ = @import("behavior/ir_block_deps.zig");73 _ = @import("behavior/ir_block_deps.zig");
74 _ = @import("behavior/math.zig");74 _ = @import("behavior/math.zig");
75 _ = @import("behavior/merge_error_sets.zig");75 _ = @import("behavior/merge_error_sets.zig");
76 _ = @import("behavior/misc.zig");76 //_ = @import("behavior/misc.zig");
77 _ = @import("behavior/muladd.zig");77 _ = @import("behavior/muladd.zig");
78 _ = @import("behavior/namespace_depends_on_compile_var.zig");78 _ = @import("behavior/namespace_depends_on_compile_var.zig");
79 _ = @import("behavior/new_stack_call.zig");79 _ = @import("behavior/new_stack_call.zig");
test/stage1/behavior/align.zig+2-2
...@@ -7,7 +7,7 @@ var foo: u8 align(4) = 100;...@@ -7,7 +7,7 @@ var foo: u8 align(4) = 100;
7test "global variable alignment" {7test "global variable alignment" {
8 expect(@typeOf(&foo).alignment == 4);8 expect(@typeOf(&foo).alignment == 4);
9 expect(@typeOf(&foo) == *align(4) u8);9 expect(@typeOf(&foo) == *align(4) u8);
10 const slice = (*[1]u8)(&foo)[0..];10 const slice = @as(*[1]u8, &foo)[0..];
11 expect(@typeOf(slice) == []align(4) u8);11 expect(@typeOf(slice) == []align(4) u8);
12}12}
1313
...@@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {...@@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
61test "implicitly decreasing slice alignment" {61test "implicitly decreasing slice alignment" {
62 const a: u32 align(4) = 3;62 const a: u32 align(4) = 3;
63 const b: u32 align(8) = 4;63 const b: u32 align(8) = 4;
64 expect(addUnalignedSlice((*const [1]u32)(&a)[0..], (*const [1]u32)(&b)[0..]) == 7);64 expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
65}65}
66fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {66fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
67 return a[0] + b[0];67 return a[0] + b[0];
test/stage1/behavior/array.zig+2-2
...@@ -12,7 +12,7 @@ test "arrays" {...@@ -12,7 +12,7 @@ test "arrays" {
12 }12 }
1313
14 i = 0;14 i = 0;
15 var accumulator = u32(0);15 var accumulator = @as(u32, 0);
16 while (i < 5) {16 while (i < 5) {
17 accumulator += array[i];17 accumulator += array[i];
1818
...@@ -149,7 +149,7 @@ test "implicit cast single-item pointer" {...@@ -149,7 +149,7 @@ test "implicit cast single-item pointer" {
149149
150fn testImplicitCastSingleItemPtr() void {150fn testImplicitCastSingleItemPtr() void {
151 var byte: u8 = 100;151 var byte: u8 = 100;
152 const slice = (*[1]u8)(&byte)[0..];152 const slice = @as(*[1]u8, &byte)[0..];
153 slice[0] += 1;153 slice[0] += 1;
154 expect(byte == 101);154 expect(byte == 101);
155}155}
test/stage1/behavior/asm.zig+8-8
...@@ -45,42 +45,42 @@ test "alternative constraints" {...@@ -45,42 +45,42 @@ test "alternative constraints" {
45test "sized integer/float in asm input" {45test "sized integer/float in asm input" {
46 asm volatile (""46 asm volatile (""
47 :47 :
48 : [_] "m" (usize(3))48 : [_] "m" (@as(usize, 3))
49 : ""49 : ""
50 );50 );
51 asm volatile (""51 asm volatile (""
52 :52 :
53 : [_] "m" (i15(-3))53 : [_] "m" (@as(i15, -3))
54 : ""54 : ""
55 );55 );
56 asm volatile (""56 asm volatile (""
57 :57 :
58 : [_] "m" (u3(3))58 : [_] "m" (@as(u3, 3))
59 : ""59 : ""
60 );60 );
61 asm volatile (""61 asm volatile (""
62 :62 :
63 : [_] "m" (i3(3))63 : [_] "m" (@as(i3, 3))
64 : ""64 : ""
65 );65 );
66 asm volatile (""66 asm volatile (""
67 :67 :
68 : [_] "m" (u121(3))68 : [_] "m" (@as(u121, 3))
69 : ""69 : ""
70 );70 );
71 asm volatile (""71 asm volatile (""
72 :72 :
73 : [_] "m" (i121(3))73 : [_] "m" (@as(i121, 3))
74 : ""74 : ""
75 );75 );
76 asm volatile (""76 asm volatile (""
77 :77 :
78 : [_] "m" (f32(3.17))78 : [_] "m" (@as(f32, 3.17))
79 : ""79 : ""
80 );80 );
81 asm volatile (""81 asm volatile (""
82 :82 :
83 : [_] "m" (f64(3.17))83 : [_] "m" (@as(f64, 3.17))
84 : ""84 : ""
85 );85 );
86}86}
test/stage1/behavior/async_fn.zig+5-5
...@@ -191,7 +191,7 @@ async fn testSuspendBlock() void {...@@ -191,7 +191,7 @@ async fn testSuspendBlock() void {
191191
192 // Test to make sure that @frame() works as advertised (issue #1296)192 // Test to make sure that @frame() works as advertised (issue #1296)
193 // var our_handle: anyframe = @frame();193 // var our_handle: anyframe = @frame();
194 expect(a_promise == anyframe(@frame()));194 expect(a_promise == @as(anyframe, @frame()));
195195
196 global_result = true;196 global_result = true;
197}197}
...@@ -543,7 +543,7 @@ test "pass string literal to async function" {...@@ -543,7 +543,7 @@ test "pass string literal to async function" {
543 fn hello(msg: []const u8) void {543 fn hello(msg: []const u8) void {
544 frame = @frame();544 frame = @frame();
545 suspend;545 suspend;
546 expectEqual(([]const u8)("hello"), msg);546 expectEqual(@as([]const u8, "hello"), msg);
547 ok = true;547 ok = true;
548 }548 }
549 };549 };
...@@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" {...@@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" {
1048 return await @asyncCall(frame, {}, amain, x - 1);1048 return await @asyncCall(frame, {}, amain, x - 1);
1049 }1049 }
1050 };1050 };
1051 _ = async S.amain(u32(1));1051 _ = async S.amain(@as(u32, 1));
1052 resume S.global_frame;1052 resume S.global_frame;
1053 expect(S.global_ok);1053 expect(S.global_ok);
1054}1054}
...@@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" {...@@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" {
1080 };1080 };
1081 };1081 };
1082 var res: S.Foo = undefined;1082 var res: S.Foo = undefined;
1083 var frame: @typeOf(async S.amain(u32(1))) = undefined;1083 var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined;
1084 _ = @asyncCall(&frame, &res, S.amain, u32(1));1084 _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1));
1085 resume S.global_frame;1085 resume S.global_frame;
1086 expect(S.global_ok);1086 expect(S.global_ok);
1087 expect(res.x == 1);1087 expect(res.x == 1);
test/stage1/behavior/atomics.zig+3-3
...@@ -98,12 +98,12 @@ test "cmpxchg with ignored result" {...@@ -98,12 +98,12 @@ test "cmpxchg with ignored result" {
9898
99 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);99 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
100100
101 expectEqual(i32(5678), x);101 expectEqual(@as(i32, 5678), x);
102}102}
103103
104var a_global_variable = u32(1234);104var a_global_variable = @as(u32, 1234);
105105
106test "cmpxchg on a global variable" {106test "cmpxchg on a global variable" {
107 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);107 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
108 expectEqual(u32(42), a_global_variable);108 expectEqual(@as(u32, 42), a_global_variable);
109}109}
test/stage1/behavior/bitreverse.zig+14-14
...@@ -46,24 +46,24 @@ fn testBitReverse() void {...@@ -46,24 +46,24 @@ fn testBitReverse() void {
46 expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);46 expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
48 // using comptime_ints, signed, positive48 // using comptime_ints, signed, positive
49 expect(@bitReverse(u8, u8(0)) == 0);49 expect(@bitReverse(u8, @as(u8, 0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));50 expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
51 expect(@bitReverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));51 expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
52 expect(@bitReverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));52 expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
53 expect(@bitReverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));53 expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
54 expect(@bitReverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));54 expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
55 expect(@bitReverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));55 expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
56 expect(@bitReverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));56 expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
57 expect(@bitReverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));57 expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
58 expect(@bitReverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));58 expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
5959
60 // using signed, negative. Compare to runtime ints returned from llvm.60 // using signed, negative. Compare to runtime ints returned from llvm.
61 var neg8: i8 = -18;61 var neg8: i8 = -18;
62 expect(@bitReverse(i8, i8(-18)) == @bitReverse(i8, neg8));62 expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
63 var neg16: i16 = -32694;63 var neg16: i16 = -32694;
64 expect(@bitReverse(i16, i16(-32694)) == @bitReverse(i16, neg16));64 expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
65 var neg24: i24 = -6773785;65 var neg24: i24 = -6773785;
66 expect(@bitReverse(i24, i24(-6773785)) == @bitReverse(i24, neg24));66 expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
67 var neg32: i32 = -16773785;67 var neg32: i32 = -16773785;
68 expect(@bitReverse(i32, i32(-16773785)) == @bitReverse(i32, neg32));68 expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
69}69}
test/stage1/behavior/bool.zig+4-4
...@@ -8,14 +8,14 @@ test "bool literals" {...@@ -8,14 +8,14 @@ test "bool literals" {
8test "cast bool to int" {8test "cast bool to int" {
9 const t = true;9 const t = true;
10 const f = false;10 const f = false;
11 expect(@boolToInt(t) == u32(1));11 expect(@boolToInt(t) == @as(u32, 1));
12 expect(@boolToInt(f) == u32(0));12 expect(@boolToInt(f) == @as(u32, 0));
13 nonConstCastBoolToInt(t, f);13 nonConstCastBoolToInt(t, f);
14}14}
1515
16fn nonConstCastBoolToInt(t: bool, f: bool) void {16fn nonConstCastBoolToInt(t: bool, f: bool) void {
17 expect(@boolToInt(t) == u32(1));17 expect(@boolToInt(t) == @as(u32, 1));
18 expect(@boolToInt(f) == u32(0));18 expect(@boolToInt(f) == @as(u32, 0));
19}19}
2020
21test "bool cmp" {21test "bool cmp" {
test/stage1/behavior/bugs/1322.zig+2-2
...@@ -13,7 +13,7 @@ const C = struct {};...@@ -13,7 +13,7 @@ const C = struct {};
1313
14test "tagged union with all void fields but a meaningful tag" {14test "tagged union with all void fields but a meaningful tag" {
15 var a: A = A{ .b = B{ .c = C{} } };15 var a: A = A{ .b = B{ .c = C{} } };
16 std.testing.expect(@TagType(B)(a.b) == @TagType(B).c);16 std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c);
17 a = A{ .b = B.None };17 a = A{ .b = B.None };
18 std.testing.expect(@TagType(B)(a.b) == @TagType(B).None);18 std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None);
19}19}
test/stage1/behavior/bugs/1421.zig+1-1
...@@ -10,5 +10,5 @@ const S = struct {...@@ -10,5 +10,5 @@ const S = struct {
1010
11test "functions with return type required to be comptime are generic" {11test "functions with return type required to be comptime are generic" {
12 const ti = S.method();12 const ti = S.method();
13 expect(builtin.TypeId(ti) == builtin.TypeId.Struct);13 expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct);
14}14}
test/stage1/behavior/bugs/2114.zig+4-4
...@@ -12,8 +12,8 @@ test "fixed" {...@@ -12,8 +12,8 @@ test "fixed" {
12}12}
1313
14fn testClz() void {14fn testClz() void {
15 expect(ctz(u128(0x40000000000000000000000000000000)) == 126);15 expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1)) == u128(0x80000000000000000000000000000000));16 expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
17 expect(ctz(u128(0x80000000000000000000000000000000)) == 127);17 expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1))) == 127);18 expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
19}19}
test/stage1/behavior/bugs/3046.zig+1-1
...@@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined;...@@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined;
1313
14test "fixed" {14test "fixed" {
15 some_struct = SomeStruct{15 some_struct = SomeStruct{
16 .field = couldFail() catch |_| i32(0),16 .field = couldFail() catch |_| @as(i32, 0),
17 };17 };
18 expect(some_struct.field == 1);18 expect(some_struct.field == 1);
19}19}
test/stage1/behavior/byteswap.zig+12-12
...@@ -11,24 +11,24 @@ test "@byteSwap integers" {...@@ -11,24 +11,24 @@ test "@byteSwap integers" {
11 t(u24, 0x123456, 0x563412);11 t(u24, 0x123456, 0x563412);
12 t(u32, 0x12345678, 0x78563412);12 t(u32, 0x12345678, 0x78563412);
13 t(u40, 0x123456789a, 0x9a78563412);13 t(u40, 0x123456789a, 0x9a78563412);
14 t(i48, 0x123456789abc, @bitCast(i48, u48(0xbc9a78563412)));14 t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
15 t(u56, 0x123456789abcde, 0xdebc9a78563412);15 t(u56, 0x123456789abcde, 0xdebc9a78563412);
16 t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);16 t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
17 t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);17 t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
1818
19 t(u0, u0(0), 0);19 t(u0, @as(u0, 0), 0);
20 t(i8, i8(-50), -50);20 t(i8, @as(i8, -50), -50);
21 t(i16, @bitCast(i16, u16(0x1234)), @bitCast(i16, u16(0x3412)));21 t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
22 t(i24, @bitCast(i24, u24(0x123456)), @bitCast(i24, u24(0x563412)));22 t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
23 t(i32, @bitCast(i32, u32(0x12345678)), @bitCast(i32, u32(0x78563412)));23 t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
24 t(u40, @bitCast(i40, u40(0x123456789a)), u40(0x9a78563412));24 t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
25 t(i48, @bitCast(i48, u48(0x123456789abc)), @bitCast(i48, u48(0xbc9a78563412)));25 t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
26 t(i56, @bitCast(i56, u56(0x123456789abcde)), @bitCast(i56, u56(0xdebc9a78563412)));26 t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
27 t(i64, @bitCast(i64, u64(0x123456789abcdef1)), @bitCast(i64, u64(0xf1debc9a78563412)));27 t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
28 t(28 t(
29 i128,29 i128,
30 @bitCast(i128, u128(0x123456789abcdef11121314151617181)),30 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
31 @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)),31 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
32 );32 );
33 }33 }
34 fn t(comptime I: type, input: I, expected_output: I) void {34 fn t(comptime I: type, input: I, expected_output: I) void {
test/stage1/behavior/cast.zig+6-6
...@@ -4,7 +4,7 @@ const mem = std.mem;...@@ -4,7 +4,7 @@ const mem = std.mem;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6test "int to ptr cast" {6test "int to ptr cast" {
7 const x = usize(13);7 const x = @as(usize, 13);
8 const y = @intToPtr(*u8, x);8 const y = @intToPtr(*u8, x);
9 const z = @ptrToInt(y);9 const z = @ptrToInt(y);
10 expect(z == 13);10 expect(z == 13);
...@@ -90,7 +90,7 @@ const A = struct {...@@ -90,7 +90,7 @@ const A = struct {
90 a: i32,90 a: i32,
91};91};
92fn castToOptionalTypeError(z: i32) void {92fn castToOptionalTypeError(z: i32) void {
93 const x = i32(1);93 const x = @as(i32, 1);
94 const y: anyerror!?i32 = x;94 const y: anyerror!?i32 = x;
95 expect((try y).? == 1);95 expect((try y).? == 1);
9696
...@@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" {...@@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" {
134}134}
135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
136 if (c) {136 if (c) {
137 return if (b) null else usize(0);137 return if (b) null else @as(usize, 0);
138 }138 }
139139
140 return usize(3);140 return @as(usize, 3);
141}141}
142142
143test "peer type resolution: [0]u8 and []const u8" {143test "peer type resolution: [0]u8 and []const u8" {
...@@ -256,7 +256,7 @@ test "@floatToInt" {...@@ -256,7 +256,7 @@ test "@floatToInt" {
256}256}
257257
258fn testFloatToInts() void {258fn testFloatToInts() void {
259 const x = i32(1e4);259 const x = @as(i32, 1e4);
260 expect(x == 10000);260 expect(x == 10000);
261 const y = @floatToInt(i32, f32(1e4));261 const y = @floatToInt(i32, f32(1e4));
262 expect(y == 10000);262 expect(y == 10000);
...@@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {...@@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
442}442}
443443
444test "*usize to *void" {444test "*usize to *void" {
445 var i = usize(0);445 var i = @as(usize, 0);
446 var v = @ptrCast(*void, &i);446 var v = @ptrCast(*void, &i);
447 v.* = {};447 v.* = {};
448}448}
test/stage1/behavior/defer.zig+1-1
...@@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void {...@@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void {
52}52}
5353
54test "defer and labeled break" {54test "defer and labeled break" {
55 var i = usize(0);55 var i = @as(usize, 0);
5656
57 blk: {57 blk: {
58 defer i += 1;58 defer i += 1;
test/stage1/behavior/enum.zig+2-2
...@@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {...@@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
788 expect(1234 == switch (x) {788 expect(1234 == switch (x) {
789 MultipleChoice.A => 1,789 MultipleChoice.A => 1,
790 MultipleChoice.B => 2,790 MultipleChoice.B => 2,
791 MultipleChoice.C => u32(1234),791 MultipleChoice.C => @as(u32, 1234),
792 MultipleChoice.D => 4,792 MultipleChoice.D => 4,
793 });793 });
794}794}
...@@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {...@@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
816 MultipleChoice2.A => 1,816 MultipleChoice2.A => 1,
817 MultipleChoice2.B => 2,817 MultipleChoice2.B => 2,
818 MultipleChoice2.C => 3,818 MultipleChoice2.C => 3,
819 MultipleChoice2.D => u32(1234),819 MultipleChoice2.D => @as(u32, 1234),
820 MultipleChoice2.Unspecified1 => 5,820 MultipleChoice2.Unspecified1 => 5,
821 MultipleChoice2.Unspecified2 => 6,821 MultipleChoice2.Unspecified2 => 6,
822 MultipleChoice2.Unspecified3 => 7,822 MultipleChoice2.Unspecified3 => 7,
test/stage1/behavior/error.zig+2-2
...@@ -51,7 +51,7 @@ test "error binary operator" {...@@ -51,7 +51,7 @@ test "error binary operator" {
51 expect(b == 10);51 expect(b == 10);
52}52}
53fn errBinaryOperatorG(x: bool) anyerror!isize {53fn errBinaryOperatorG(x: bool) anyerror!isize {
54 return if (x) error.ItBroke else isize(10);54 return if (x) error.ItBroke else @as(isize, 10);
55}55}
5656
57test "unwrap simple value from error" {57test "unwrap simple value from error" {
...@@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" {...@@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" {
295test "widen cast integer payload of error union function call" {295test "widen cast integer payload of error union function call" {
296 const S = struct {296 const S = struct {
297 fn errorable() !u64 {297 fn errorable() !u64 {
298 var x = u64(try number());298 var x = @as(u64, try number());
299 return x;299 return x;
300 }300 }
301301
test/stage1/behavior/eval.zig+18-18
...@@ -405,19 +405,19 @@ test "float literal at compile time not lossy" {...@@ -405,19 +405,19 @@ test "float literal at compile time not lossy" {
405}405}
406406
407test "f32 at compile time is lossy" {407test "f32 at compile time is lossy" {
408 expect(f32(1 << 24) + 1 == 1 << 24);408 expect(@as(f32, 1 << 24) + 1 == 1 << 24);
409}409}
410410
411test "f64 at compile time is lossy" {411test "f64 at compile time is lossy" {
412 expect(f64(1 << 53) + 1 == 1 << 53);412 expect(@as(f64, 1 << 53) + 1 == 1 << 53);
413}413}
414414
415test "f128 at compile time is lossy" {415test "f128 at compile time is lossy" {
416 expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);416 expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
417}417}
418418
419comptime {419comptime {
420 expect(f128(1 << 113) == 10384593717069655257060992658440192);420 expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
421}421}
422422
423pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {423pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
...@@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" {...@@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" {
434}434}
435435
436test "comptime slice of undefined pointer of length 0" {436test "comptime slice of undefined pointer of length 0" {
437 const slice1 = ([*]i32)(undefined)[0..0];437 const slice1 = @as([*]i32, undefined)[0..0];
438 expect(slice1.len == 0);438 expect(slice1.len == 0);
439 const slice2 = ([*]i32)(undefined)[100..100];439 const slice2 = @as([*]i32, undefined)[100..100];
440 expect(slice2.len == 0);440 expect(slice2.len == 0);
441}441}
442442
...@@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void {...@@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void {
444 comptime var i: usize = 0;444 comptime var i: usize = 0;
445 inline while (i < 4) : (i += 1) {445 inline while (i < 4) : (i += 1) {
446 s[i] = 0;446 s[i] = 0;
447 s[i] |= u32(b[i * 4 + 0]) << 24;447 s[i] |= @as(u32, b[i * 4 + 0]) << 24;
448 s[i] |= u32(b[i * 4 + 1]) << 16;448 s[i] |= @as(u32, b[i * 4 + 1]) << 16;
449 s[i] |= u32(b[i * 4 + 2]) << 8;449 s[i] |= @as(u32, b[i * 4 + 2]) << 8;
450 s[i] |= u32(b[i * 4 + 3]) << 0;450 s[i] |= @as(u32, b[i * 4 + 3]) << 0;
451 }451 }
452}452}
453453
...@@ -557,14 +557,14 @@ test "array concat of slices gives slice" {...@@ -557,14 +557,14 @@ test "array concat of slices gives slice" {
557557
558test "comptime shlWithOverflow" {558test "comptime shlWithOverflow" {
559 const ct_shifted: u64 = comptime amt: {559 const ct_shifted: u64 = comptime amt: {
560 var amt = u64(0);560 var amt = @as(u64, 0);
561 _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);561 _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt);
562 break :amt amt;562 break :amt amt;
563 };563 };
564564
565 const rt_shifted: u64 = amt: {565 const rt_shifted: u64 = amt: {
566 var amt = u64(0);566 var amt = @as(u64, 0);
567 _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);567 _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt);
568 break :amt amt;568 break :amt amt;
569 };569 };
570570
...@@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void {...@@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void {
670}670}
671671
672test "variable inside inline loop that has different types on different iterations" {672test "variable inside inline loop that has different types on different iterations" {
673 testVarInsideInlineLoop(true, u32(42));673 testVarInsideInlineLoop(true, @as(u32, 42));
674}674}
675675
676fn testVarInsideInlineLoop(args: ...) void {676fn testVarInsideInlineLoop(args: ...) void {
...@@ -757,11 +757,11 @@ test "comptime bitwise operators" {...@@ -757,11 +757,11 @@ test "comptime bitwise operators" {
757 expect(-3 | -1 == -1);757 expect(-3 | -1 == -1);
758 expect(3 ^ -1 == -4);758 expect(3 ^ -1 == -4);
759 expect(-3 ^ -1 == 2);759 expect(-3 ^ -1 == 2);
760 expect(~i8(-1) == 0);760 expect(~@as(i8, -1) == 0);
761 expect(~i128(-1) == 0);761 expect(~@as(i128, -1) == 0);
762 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);762 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
763 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);763 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
764 expect(~u128(0) == 0xffffffffffffffffffffffffffffffff);764 expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
765 }765 }
766}766}
767767
test/stage1/behavior/floatop.zig+2-2
...@@ -117,11 +117,11 @@ test "@ln" {...@@ -117,11 +117,11 @@ test "@ln" {
117fn testLn() void {117fn testLn() void {
118 {118 {
119 var a: f32 = e;119 var a: f32 = e;
120 expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, u32(0x3f7fffff)));120 expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, @as(u32, 0x3f7fffff)));
121 }121 }
122 {122 {
123 var a: f64 = e;123 var a: f64 = e;
124 expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, u64(0x3ff0000000000000)));124 expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
125 }125 }
126}126}
127127
test/stage1/behavior/fn.zig+2-2
...@@ -29,7 +29,7 @@ test "mutable local variables" {...@@ -29,7 +29,7 @@ test "mutable local variables" {
29 var zero: i32 = 0;29 var zero: i32 = 0;
30 expect(zero == 0);30 expect(zero == 0);
3131
32 var i = i32(0);32 var i = @as(i32, 0);
33 while (i != 3) {33 while (i != 3) {
34 i += 1;34 i += 1;
35 }35 }
...@@ -43,7 +43,7 @@ test "separate block scopes" {...@@ -43,7 +43,7 @@ test "separate block scopes" {
43 }43 }
4444
45 const c = x: {45 const c = x: {
46 const no_conflict = i32(10);46 const no_conflict = @as(i32, 10);
47 break :x no_conflict;47 break :x no_conflict;
48 };48 };
49 expect(c == 10);49 expect(c == 10);
test/stage1/behavior/if.zig+2-2
...@@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 {...@@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 {
32 } else if (c == 1) {32 } else if (c == 1) {
33 return 1;33 return 1;
34 } else {34 } else {
35 return u8(2);35 return @as(u8, 2);
36 }36 }
37}37}
3838
...@@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" {...@@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" {
58 var c = true;58 var c = true;
59 if (c) {59 if (c) {
60 answer = if (true) blk: {60 answer = if (true) blk: {
61 break :blk i32(42);61 break :blk @as(i32, 42);
62 };62 };
63 }63 }
64 expect(answer == 42);64 expect(answer == 42);
test/stage1/behavior/import.zig+2-2
...@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;...@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;
3const a_namespace = @import("import/a_namespace.zig");3const a_namespace = @import("import/a_namespace.zig");
44
5test "call fn via namespace lookup" {5test "call fn via namespace lookup" {
6 expectEqual(i32(1234), a_namespace.foo());6 expectEqual(@as(i32, 1234), a_namespace.foo());
7}7}
88
9test "importing the same thing gives the same import" {9test "importing the same thing gives the same import" {
...@@ -14,5 +14,5 @@ test "import in non-toplevel scope" {...@@ -14,5 +14,5 @@ test "import in non-toplevel scope" {
14 const S = struct {14 const S = struct {
15 usingnamespace @import("import/a_namespace.zig");15 usingnamespace @import("import/a_namespace.zig");
16 };16 };
17 expectEqual(i32(1234), S.foo());17 expectEqual(@as(i32, 1234), S.foo());
18}18}
test/stage1/behavior/math.zig+12-12
...@@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void {...@@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void {
186 assertFalse(90 >> 1 >> 2 != 90 >> 3);186 assertFalse(90 >> 1 >> 2 != 90 >> 3);
187 assertFalse(100 - 1 + 1000 != 1099);187 assertFalse(100 - 1 + 1000 != 1099);
188 assertFalse(5 * 4 / 2 % 3 != 1);188 assertFalse(5 * 4 / 2 % 3 != 1);
189 assertFalse(i32(i32(5)) != 5);189 assertFalse(@as(i32, @as(i32, 5)) != 5);
190 assertFalse(!!false);190 assertFalse(!!false);
191 assertFalse(i32(7) != --(i32(7)));191 assertFalse(@as(i32, 7) != --(@as(i32, 7)));
192}192}
193fn assertFalse(b: bool) void {193fn assertFalse(b: bool) void {
194 expect(!b);194 expect(!b);
...@@ -256,10 +256,10 @@ const DivResult = struct {...@@ -256,10 +256,10 @@ const DivResult = struct {
256256
257test "binary not" {257test "binary not" {
258 expect(comptime x: {258 expect(comptime x: {
259 break :x ~u16(0b1010101010101010) == 0b0101010101010101;259 break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;
260 });260 });
261 expect(comptime x: {261 expect(comptime x: {
262 break :x ~u64(2147483647) == 18446744071562067968;262 break :x ~@as(u64, 2147483647) == 18446744071562067968;
263 });263 });
264 testBinaryNot(0b1010101010101010);264 testBinaryNot(0b1010101010101010);
265}265}
...@@ -472,7 +472,7 @@ test "comptime_int multiplication" {...@@ -472,7 +472,7 @@ test "comptime_int multiplication" {
472472
473test "comptime_int shifting" {473test "comptime_int shifting" {
474 comptime {474 comptime {
475 expect((u128(1) << 127) == 0x80000000000000000000000000000000);475 expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
476 }476 }
477}477}
478478
...@@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" {...@@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" {
480 comptime {480 comptime {
481 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;481 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
482482
483 expect(u32(a & 0xffffffff) == 0xaaaaaaab);483 expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
484 a >>= 32;484 a >>= 32;
485 expect(u32(a & 0xffffffff) == 0xeeeeeeef);485 expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
486 a >>= 32;486 a >>= 32;
487 expect(u32(a & 0xffffffff) == 0xa0000001);487 expect(@as(u32, a & 0xffffffff) == 0xa0000001);
488 a >>= 32;488 a >>= 32;
489 expect(u32(a & 0xffffffff) == 0xefffffff);489 expect(@as(u32, a & 0xffffffff) == 0xefffffff);
490 a >>= 32;490 a >>= 32;
491491
492 expect(a == 0);492 expect(a == 0);
...@@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void {...@@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void {
552552
553test "comptime float rem int" {553test "comptime float rem int" {
554 comptime {554 comptime {
555 var x = f32(1) % 2;555 var x = @as(f32, 1) % 2;
556 expect(x == 1.0);556 expect(x == 1.0);
557 }557 }
558}558}
...@@ -568,8 +568,8 @@ test "remainder division" {...@@ -568,8 +568,8 @@ test "remainder division" {
568}568}
569569
570fn remdiv(comptime T: type) void {570fn remdiv(comptime T: type) void {
571 expect(T(1) == T(1) % T(2));571 expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
572 expect(T(1) == T(7) % T(3));572 expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
573}573}
574574
575test "@sqrt" {575test "@sqrt" {
test/stage1/behavior/misc.zig+3-3
...@@ -268,7 +268,7 @@ fn outer() i64 {...@@ -268,7 +268,7 @@ fn outer() i64 {
268}268}
269269
270test "pointer dereferencing" {270test "pointer dereferencing" {
271 var x = i32(3);271 var x = @as(i32, 3);
272 const y = &x;272 const y = &x;
273273
274 y.* += 1;274 y.* += 1;
...@@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type {...@@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type {
500}500}
501501
502test "double implicit cast in same expression" {502test "double implicit cast in same expression" {
503 var x = i32(u16(nine()));503 var x = @as(i32, @as(u16, nine()));
504 expect(x == 9);504 expect(x == 9);
505}505}
506fn nine() u8 {506fn nine() u8 {
...@@ -761,7 +761,7 @@ test "nested optional field in struct" {...@@ -761,7 +761,7 @@ test "nested optional field in struct" {
761761
762fn maybe(x: bool) anyerror!?u32 {762fn maybe(x: bool) anyerror!?u32 {
763 return switch (x) {763 return switch (x) {
764 true => u32(42),764 true => @as(u32, 42),
765 else => null,765 else => null,
766 };766 };
767}767}
test/stage1/behavior/popcount.zig+1-1
...@@ -35,7 +35,7 @@ fn testPopCount() void {...@@ -35,7 +35,7 @@ fn testPopCount() void {
35 expect(@popCount(i8, x) == 2);35 expect(@popCount(i8, x) == 2);
36 }36 }
37 comptime {37 comptime {
38 expect(@popCount(u8, @bitCast(u8, i8(-120))) == 2);38 expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
39 }39 }
40 comptime {40 comptime {
41 expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);41 expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
test/stage1/behavior/pub_enum.zig+1-1
...@@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void {...@@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void {
9}9}
1010
11test "cast with imported symbol" {11test "cast with imported symbol" {
12 expect(other.size_t(42) == 42);12 expect(@as(other.size_t, 42) == 42);
13}13}
test/stage1/behavior/shuffle.zig+13-13
...@@ -7,39 +7,39 @@ test "@shuffle" {...@@ -7,39 +7,39 @@ test "@shuffle" {
7 fn doTheTest() void {7 fn doTheTest() void {
8 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };8 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
9 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };9 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
10 const mask: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 3, ~i32(3) };10 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
11 var res = @shuffle(i32, v, x, mask);11 var res = @shuffle(i32, v, x, mask);
12 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 }));12 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
1313
14 // Implicit cast from array (of mask)14 // Implicit cast from array (of mask)
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~i32(2), 3, ~i32(3) });15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 }));16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
1717
18 // Undefined18 // Undefined
19 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };19 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
20 res = @shuffle(i32, v, undefined, mask2);20 res = @shuffle(i32, v, undefined, mask2);
21 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 40, -2, 30, 2147483647 }));21 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 }));
2222
23 // Upcasting of b23 // Upcasting of b
24 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };24 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
25 const mask3: @Vector(4, i32) = [4]i32{ ~i32(0), 2, ~i32(0), 3 };25 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
26 res = @shuffle(i32, x, v2, mask3);26 res = @shuffle(i32, x, v2, mask3);
27 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 2147483647, 4 }));27 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 }));
2828
29 // Upcasting of a29 // Upcasting of a
30 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };30 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 1, ~i32(3) };31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
32 res = @shuffle(i32, v3, x, mask4);32 res = @shuffle(i32, v3, x, mask4);
33 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, -2, 4 }));33 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 }));
3434
35 // bool35 // bool
36 // Disabled because of #331736 // Disabled because of #3317
37 if (@import("builtin").arch != .mipsel) {37 if (@import("builtin").arch != .mipsel) {
38 var x2: @Vector(4, bool) = [4]bool{ false, true, false, true };38 var x2: @Vector(4, bool) = [4]bool{ false, true, false, true };
39 var v4: @Vector(2, bool) = [2]bool{ true, false };39 var v4: @Vector(2, bool) = [2]bool{ true, false };
40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 };40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
41 var res2 = @shuffle(bool, x2, v4, mask5);41 var res2 = @shuffle(bool, x2, v4, mask5);
42 expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false }));42 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
43 }43 }
4444
45 // TODO re-enable when LLVM codegen is fixed45 // TODO re-enable when LLVM codegen is fixed
...@@ -47,9 +47,9 @@ test "@shuffle" {...@@ -47,9 +47,9 @@ test "@shuffle" {
47 if (false) {47 if (false) {
48 var x2: @Vector(3, bool) = [3]bool{ false, true, false };48 var x2: @Vector(3, bool) = [3]bool{ false, true, false };
49 var v4: @Vector(2, bool) = [2]bool{ true, false };49 var v4: @Vector(2, bool) = [2]bool{ true, false };
50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 };50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
51 var res2 = @shuffle(bool, x2, v4, mask5);51 var res2 = @shuffle(bool, x2, v4, mask5);
52 expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false }));52 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
53 }53 }
54 }54 }
55 };55 };
test/stage1/behavior/slicetobytes.zig+1-1
...@@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" {...@@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" {
10 const S = struct {10 const S = struct {
11 fn doTheTest() void {11 fn doTheTest() void {
12 var foo: Foo = undefined;12 var foo: Foo = undefined;
13 var slice = @sliceToBytes(((*[1]Foo)(&foo))[0..1]);13 var slice = @sliceToBytes(@as(*[1]Foo, &foo)[0..1]);
14 slice[0] = 0x13;14 slice[0] = 0x13;
15 switch (builtin.endian) {15 switch (builtin.endian) {
16 builtin.Endian.Big => {16 builtin.Endian.Big => {
test/stage1/behavior/struct.zig+8-8
...@@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" {...@@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" {
388 expect(s2.y == @intCast(u4, x2));388 expect(s2.y == @intCast(u4, x2));
389}389}
390390
391var x1 = u4(1);391var x1 = @as(u4, 1);
392var x2 = u8(2);392var x2 = @as(u8, 2);
393393
394const Nibbles = packed struct {394const Nibbles = packed struct {
395 x: u4,395 x: u4,
...@@ -545,9 +545,9 @@ test "packed struct with fp fields" {...@@ -545,9 +545,9 @@ test "packed struct with fp fields" {
545 s.data[1] = 2.0;545 s.data[1] = 2.0;
546 s.data[2] = 3.0;546 s.data[2] = 3.0;
547 s.frob();547 s.frob();
548 expectEqual(f32(6.0), s.data[0]);548 expectEqual(@as(f32, 6.0), s.data[0]);
549 expectEqual(f32(11.0), s.data[1]);549 expectEqual(@as(f32, 11.0), s.data[1]);
550 expectEqual(f32(20.0), s.data[2]);550 expectEqual(@as(f32, 20.0), s.data[2]);
551}551}
552552
553test "use within struct scope" {553test "use within struct scope" {
...@@ -558,7 +558,7 @@ test "use within struct scope" {...@@ -558,7 +558,7 @@ test "use within struct scope" {
558 }558 }
559 };559 };
560 };560 };
561 expectEqual(i32(42), S.inner());561 expectEqual(@as(i32, 42), S.inner());
562}562}
563563
564test "default struct initialization fields" {564test "default struct initialization fields" {
...@@ -583,7 +583,7 @@ test "extern fn returns struct by value" {...@@ -583,7 +583,7 @@ test "extern fn returns struct by value" {
583 const S = struct {583 const S = struct {
584 fn entry() void {584 fn entry() void {
585 var x = makeBar(10);585 var x = makeBar(10);
586 expectEqual(i32(10), x.handle);586 expectEqual(@as(i32, 10), x.handle);
587 }587 }
588588
589 const ExternBar = extern struct {589 const ExternBar = extern struct {
...@@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {...@@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {
614614
615 const ArrayList = struct {615 const ArrayList = struct {
616 fn toSlice(self: *ArrayList) []*Foo {616 fn toSlice(self: *ArrayList) []*Foo {
617 return ([*]*Foo)(undefined)[0..0];617 return @as([*]*Foo, undefined)[0..0];
618 }618 }
619 };619 };
620620
test/stage1/behavior/switch.zig+4-4
...@@ -68,7 +68,7 @@ test "switch statement" {...@@ -68,7 +68,7 @@ test "switch statement" {
68}68}
69fn nonConstSwitch(foo: SwitchStatmentFoo) void {69fn nonConstSwitch(foo: SwitchStatmentFoo) void {
70 const val = switch (foo) {70 const val = switch (foo) {
71 SwitchStatmentFoo.A => i32(1),71 SwitchStatmentFoo.A => @as(i32, 1),
72 SwitchStatmentFoo.B => 2,72 SwitchStatmentFoo.B => 2,
73 SwitchStatmentFoo.C => 3,73 SwitchStatmentFoo.C => 3,
74 SwitchStatmentFoo.D => 4,74 SwitchStatmentFoo.D => 4,
...@@ -127,7 +127,7 @@ test "switch with multiple expressions" {...@@ -127,7 +127,7 @@ test "switch with multiple expressions" {
127 const x = switch (returnsFive()) {127 const x = switch (returnsFive()) {
128 1, 2, 3 => 1,128 1, 2, 3 => 1,
129 4, 5, 6 => 2,129 4, 5, 6 => 2,
130 else => i32(3),130 else => @as(i32, 3),
131 };131 };
132 expect(x == 2);132 expect(x == 2);
133}133}
...@@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void {...@@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void {
186186
187fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {187fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
188 return switch (x) {188 return switch (x) {
189 0 => u2(3),189 0 => @as(u2, 3),
190 1 => 2,190 1 => 2,
191 2 => 1,191 2 => 1,
192 3 => 0,192 3 => 0,
...@@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {...@@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
195195
196fn testSwitchHandleAllCasesRange(x: u8) u8 {196fn testSwitchHandleAllCasesRange(x: u8) u8 {
197 return switch (x) {197 return switch (x) {
198 0...100 => u8(0),198 0...100 => @as(u8, 0),
199 101...200 => 1,199 101...200 => 1,
200 201, 203 => 2,200 201, 203 => 2,
201 202 => 4,201 202 => 4,
test/stage1/behavior/try.zig+3-3
...@@ -8,7 +8,7 @@ test "try on error union" {...@@ -8,7 +8,7 @@ test "try on error union" {
8fn tryOnErrorUnionImpl() void {8fn tryOnErrorUnionImpl() void {
9 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {9 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
10 error.ItBroke, error.NoMem => 1,10 error.ItBroke, error.NoMem => 1,
11 error.CrappedOut => i32(2),11 error.CrappedOut => @as(i32, 2),
12 else => unreachable,12 else => unreachable,
13 };13 };
14 expect(x == 11);14 expect(x == 11);
...@@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 {...@@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 {
19}19}
2020
21test "try without vars" {21test "try without vars" {
22 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);22 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
23 expect(result1 == 2);23 expect(result1 == 2);
2424
25 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);25 const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2);
26 expect(result2 == 1);26 expect(result2 == 1);
27}27}
2828
test/stage1/behavior/type_info.zig+23-23
...@@ -13,7 +13,7 @@ test "type info: tag type, void info" {...@@ -13,7 +13,7 @@ test "type info: tag type, void info" {
13fn testBasic() void {13fn testBasic() void {
14 expect(@TagType(TypeInfo) == TypeId);14 expect(@TagType(TypeInfo) == TypeId);
15 const void_info = @typeInfo(void);15 const void_info = @typeInfo(void);
16 expect(TypeId(void_info) == TypeId.Void);16 expect(@as(TypeId, void_info) == TypeId.Void);
17 expect(void_info.Void == {});17 expect(void_info.Void == {});
18}18}
1919
...@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {...@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {
2424
25fn testIntFloat() void {25fn testIntFloat() void {
26 const u8_info = @typeInfo(u8);26 const u8_info = @typeInfo(u8);
27 expect(TypeId(u8_info) == TypeId.Int);27 expect(@as(TypeId, u8_info) == TypeId.Int);
28 expect(!u8_info.Int.is_signed);28 expect(!u8_info.Int.is_signed);
29 expect(u8_info.Int.bits == 8);29 expect(u8_info.Int.bits == 8);
3030
31 const f64_info = @typeInfo(f64);31 const f64_info = @typeInfo(f64);
32 expect(TypeId(f64_info) == TypeId.Float);32 expect(@as(TypeId, f64_info) == TypeId.Float);
33 expect(f64_info.Float.bits == 64);33 expect(f64_info.Float.bits == 64);
34}34}
3535
...@@ -40,7 +40,7 @@ test "type info: pointer type info" {...@@ -40,7 +40,7 @@ test "type info: pointer type info" {
4040
41fn testPointer() void {41fn testPointer() void {
42 const u32_ptr_info = @typeInfo(*u32);42 const u32_ptr_info = @typeInfo(*u32);
43 expect(TypeId(u32_ptr_info) == TypeId.Pointer);43 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);
44 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);44 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
45 expect(u32_ptr_info.Pointer.is_const == false);45 expect(u32_ptr_info.Pointer.is_const == false);
46 expect(u32_ptr_info.Pointer.is_volatile == false);46 expect(u32_ptr_info.Pointer.is_volatile == false);
...@@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" {...@@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" {
5555
56fn testUnknownLenPtr() void {56fn testUnknownLenPtr() void {
57 const u32_ptr_info = @typeInfo([*]const volatile f64);57 const u32_ptr_info = @typeInfo([*]const volatile f64);
58 expect(TypeId(u32_ptr_info) == TypeId.Pointer);58 expect(@as(TypeId,u32_ptr_info) == TypeId.Pointer);
59 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);59 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
60 expect(u32_ptr_info.Pointer.is_const == true);60 expect(u32_ptr_info.Pointer.is_const == true);
61 expect(u32_ptr_info.Pointer.is_volatile == true);61 expect(u32_ptr_info.Pointer.is_volatile == true);
...@@ -70,7 +70,7 @@ test "type info: C pointer type info" {...@@ -70,7 +70,7 @@ test "type info: C pointer type info" {
7070
71fn testCPtr() void {71fn testCPtr() void {
72 const ptr_info = @typeInfo([*c]align(4) const i8);72 const ptr_info = @typeInfo([*c]align(4) const i8);
73 expect(TypeId(ptr_info) == TypeId.Pointer);73 expect(@as(TypeId,ptr_info) == TypeId.Pointer);
74 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);74 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);
75 expect(ptr_info.Pointer.is_const);75 expect(ptr_info.Pointer.is_const);
76 expect(!ptr_info.Pointer.is_volatile);76 expect(!ptr_info.Pointer.is_volatile);
...@@ -85,7 +85,7 @@ test "type info: slice type info" {...@@ -85,7 +85,7 @@ test "type info: slice type info" {
8585
86fn testSlice() void {86fn testSlice() void {
87 const u32_slice_info = @typeInfo([]u32);87 const u32_slice_info = @typeInfo([]u32);
88 expect(TypeId(u32_slice_info) == TypeId.Pointer);88 expect(@as(TypeId, u32_slice_info) == TypeId.Pointer);
89 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);89 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
90 expect(u32_slice_info.Pointer.is_const == false);90 expect(u32_slice_info.Pointer.is_const == false);
91 expect(u32_slice_info.Pointer.is_volatile == false);91 expect(u32_slice_info.Pointer.is_volatile == false);
...@@ -100,7 +100,7 @@ test "type info: array type info" {...@@ -100,7 +100,7 @@ test "type info: array type info" {
100100
101fn testArray() void {101fn testArray() void {
102 const arr_info = @typeInfo([42]bool);102 const arr_info = @typeInfo([42]bool);
103 expect(TypeId(arr_info) == TypeId.Array);103 expect(@as(TypeId, arr_info) == TypeId.Array);
104 expect(arr_info.Array.len == 42);104 expect(arr_info.Array.len == 42);
105 expect(arr_info.Array.child == bool);105 expect(arr_info.Array.child == bool);
106}106}
...@@ -112,7 +112,7 @@ test "type info: optional type info" {...@@ -112,7 +112,7 @@ test "type info: optional type info" {
112112
113fn testOptional() void {113fn testOptional() void {
114 const null_info = @typeInfo(?void);114 const null_info = @typeInfo(?void);
115 expect(TypeId(null_info) == TypeId.Optional);115 expect(@as(TypeId, null_info) == TypeId.Optional);
116 expect(null_info.Optional.child == void);116 expect(null_info.Optional.child == void);
117}117}
118118
...@@ -129,18 +129,18 @@ fn testErrorSet() void {...@@ -129,18 +129,18 @@ fn testErrorSet() void {
129 };129 };
130130
131 const error_set_info = @typeInfo(TestErrorSet);131 const error_set_info = @typeInfo(TestErrorSet);
132 expect(TypeId(error_set_info) == TypeId.ErrorSet);132 expect(@as(TypeId, error_set_info) == TypeId.ErrorSet);
133 expect(error_set_info.ErrorSet.?.len == 3);133 expect(error_set_info.ErrorSet.?.len == 3);
134 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));134 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
135 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));135 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));
136136
137 const error_union_info = @typeInfo(TestErrorSet!usize);137 const error_union_info = @typeInfo(TestErrorSet!usize);
138 expect(TypeId(error_union_info) == TypeId.ErrorUnion);138 expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion);
139 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);139 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
140 expect(error_union_info.ErrorUnion.payload == usize);140 expect(error_union_info.ErrorUnion.payload == usize);
141141
142 const global_info = @typeInfo(anyerror);142 const global_info = @typeInfo(anyerror);
143 expect(TypeId(global_info) == TypeId.ErrorSet);143 expect(@as(TypeId, global_info) == TypeId.ErrorSet);
144 expect(global_info.ErrorSet == null);144 expect(global_info.ErrorSet == null);
145}145}
146146
...@@ -158,7 +158,7 @@ fn testEnum() void {...@@ -158,7 +158,7 @@ fn testEnum() void {
158 };158 };
159159
160 const os_info = @typeInfo(Os);160 const os_info = @typeInfo(Os);
161 expect(TypeId(os_info) == TypeId.Enum);161 expect(@as(TypeId, os_info) == TypeId.Enum);
162 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);162 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
163 expect(os_info.Enum.fields.len == 4);163 expect(os_info.Enum.fields.len == 4);
164 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));164 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
...@@ -174,7 +174,7 @@ test "type info: union info" {...@@ -174,7 +174,7 @@ test "type info: union info" {
174174
175fn testUnion() void {175fn testUnion() void {
176 const typeinfo_info = @typeInfo(TypeInfo);176 const typeinfo_info = @typeInfo(TypeInfo);
177 expect(TypeId(typeinfo_info) == TypeId.Union);177 expect(@as(TypeId, typeinfo_info) == TypeId.Union);
178 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);178 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
179 expect(typeinfo_info.Union.tag_type.? == TypeId);179 expect(typeinfo_info.Union.tag_type.? == TypeId);
180 expect(typeinfo_info.Union.fields.len == 26);180 expect(typeinfo_info.Union.fields.len == 26);
...@@ -189,7 +189,7 @@ fn testUnion() void {...@@ -189,7 +189,7 @@ fn testUnion() void {
189 };189 };
190190
191 const notag_union_info = @typeInfo(TestNoTagUnion);191 const notag_union_info = @typeInfo(TestNoTagUnion);
192 expect(TypeId(notag_union_info) == TypeId.Union);192 expect(@as(TypeId, notag_union_info) == TypeId.Union);
193 expect(notag_union_info.Union.tag_type == null);193 expect(notag_union_info.Union.tag_type == null);
194 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);194 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);
195 expect(notag_union_info.Union.fields.len == 2);195 expect(notag_union_info.Union.fields.len == 2);
...@@ -214,7 +214,7 @@ test "type info: struct info" {...@@ -214,7 +214,7 @@ test "type info: struct info" {
214214
215fn testStruct() void {215fn testStruct() void {
216 const struct_info = @typeInfo(TestStruct);216 const struct_info = @typeInfo(TestStruct);
217 expect(TypeId(struct_info) == TypeId.Struct);217 expect(@as(TypeId, struct_info) == TypeId.Struct);
218 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);218 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
219 expect(struct_info.Struct.fields.len == 3);219 expect(struct_info.Struct.fields.len == 3);
220 expect(struct_info.Struct.fields[1].offset == null);220 expect(struct_info.Struct.fields[1].offset == null);
...@@ -244,7 +244,7 @@ test "type info: function type info" {...@@ -244,7 +244,7 @@ test "type info: function type info" {
244244
245fn testFunction() void {245fn testFunction() void {
246 const fn_info = @typeInfo(@typeOf(foo));246 const fn_info = @typeInfo(@typeOf(foo));
247 expect(TypeId(fn_info) == TypeId.Fn);247 expect(@as(TypeId, fn_info) == TypeId.Fn);
248 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);248 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
249 expect(fn_info.Fn.is_generic);249 expect(fn_info.Fn.is_generic);
250 expect(fn_info.Fn.args.len == 2);250 expect(fn_info.Fn.args.len == 2);
...@@ -253,7 +253,7 @@ fn testFunction() void {...@@ -253,7 +253,7 @@ fn testFunction() void {
253253
254 const test_instance: TestStruct = undefined;254 const test_instance: TestStruct = undefined;
255 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));255 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
256 expect(TypeId(bound_fn_info) == TypeId.BoundFn);256 expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn);
257 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);257 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
258}258}
259259
...@@ -275,7 +275,7 @@ test "type info: vectors" {...@@ -275,7 +275,7 @@ test "type info: vectors" {
275275
276fn testVector() void {276fn testVector() void {
277 const vec_info = @typeInfo(@Vector(4, i32));277 const vec_info = @typeInfo(@Vector(4, i32));
278 expect(TypeId(vec_info) == TypeId.Vector);278 expect(@as(TypeId, vec_info) == TypeId.Vector);
279 expect(vec_info.Vector.len == 4);279 expect(vec_info.Vector.len == 4);
280 expect(vec_info.Vector.child == i32);280 expect(vec_info.Vector.child == i32);
281}281}
...@@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" {...@@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" {
288fn testAnyFrame() void {288fn testAnyFrame() void {
289 {289 {
290 const anyframe_info = @typeInfo(anyframe->i32);290 const anyframe_info = @typeInfo(anyframe->i32);
291 expect(TypeId(anyframe_info) == .AnyFrame);291 expect(@as(TypeId,anyframe_info) == .AnyFrame);
292 expect(anyframe_info.AnyFrame.child.? == i32);292 expect(anyframe_info.AnyFrame.child.? == i32);
293 }293 }
294294
295 {295 {
296 const anyframe_info = @typeInfo(anyframe);296 const anyframe_info = @typeInfo(anyframe);
297 expect(TypeId(anyframe_info) == .AnyFrame);297 expect(@as(TypeId,anyframe_info) == .AnyFrame);
298 expect(anyframe_info.AnyFrame.child == null);298 expect(anyframe_info.AnyFrame.child == null);
299 }299 }
300}300}
...@@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" {...@@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" {
334 if (std.mem.eql(u8, decl.name, "bar1")) {334 if (std.mem.eql(u8, decl.name, "bar1")) {
335 expect(decl.data.Fn.lib_name == null);335 expect(decl.data.Fn.lib_name == null);
336 } else {336 } else {
337 std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?);337 std.testing.expectEqual(@as([]const u8,"cool"), decl.data.Fn.lib_name.?);
338 }338 }
339 }339 }
340 }340 }
...@@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" {...@@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" {
342342
343test "data field is a compile-time value" {343test "data field is a compile-time value" {
344 const S = struct {344 const S = struct {
345 const Bar = isize(-1);345 const Bar = @as(isize, -1);
346 };346 };
347 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);347 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
348}348}
test/stage1/behavior/union.zig+12-12
...@@ -14,7 +14,7 @@ const Agg = struct {...@@ -14,7 +14,7 @@ const Agg = struct {
14const v1 = Value{ .Int = 1234 };14const v1 = Value{ .Int = 1234 };
15const v2 = Value{ .Array = [_]u8{3} ** 9 };15const v2 = Value{ .Array = [_]u8{3} ** 9 };
1616
17const err = (anyerror!Agg)(Agg{17const err = @as(anyerror!Agg, Agg{
18 .val1 = v1,18 .val1 = v1,
19 .val2 = v2,19 .val2 = v2,
20});20});
...@@ -110,11 +110,11 @@ fn doTest() void {...@@ -110,11 +110,11 @@ fn doTest() void {
110}110}
111111
112fn bar(value: Payload) i32 {112fn bar(value: Payload) i32 {
113 expect(Letter(value) == Letter.A);113 expect(@as(Letter,value) == Letter.A);
114 return switch (value) {114 return switch (value) {
115 Payload.A => |x| return x - 1244,115 Payload.A => |x| return x - 1244,
116 Payload.B => |x| if (x == 12.34) i32(20) else 21,116 Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,
117 Payload.C => |x| if (x) i32(30) else 31,117 Payload.C => |x| if (x) @as(i32, 30) else 31,
118 };118 };
119}119}
120120
...@@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) {...@@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) {
127test "simple union(enum(u32))" {127test "simple union(enum(u32))" {
128 var x = MultipleChoice.C;128 var x = MultipleChoice.C;
129 expect(x == MultipleChoice.C);129 expect(x == MultipleChoice.C);
130 expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60);130 expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60);
131}131}
132132
133const MultipleChoice2 = union(enum(u32)) {133const MultipleChoice2 = union(enum(u32)) {
...@@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" {...@@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" {
149}149}
150150
151fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {151fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
152 expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);152 expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60);
153 expect(1123 == switch (x) {153 expect(1123 == switch (x) {
154 MultipleChoice2.A => 1,154 MultipleChoice2.A => 1,
155 MultipleChoice2.B => 2,155 MultipleChoice2.B => 2,
156 MultipleChoice2.C => |v| i32(1000) + v,156 MultipleChoice2.C => |v| @as(i32, 1000) + v,
157 MultipleChoice2.D => 4,157 MultipleChoice2.D => 4,
158 MultipleChoice2.Unspecified1 => 5,158 MultipleChoice2.Unspecified1 => 5,
159 MultipleChoice2.Unspecified2 => 6,159 MultipleChoice2.Unspecified2 => 6,
...@@ -208,12 +208,12 @@ test "cast union to tag type of union" {...@@ -208,12 +208,12 @@ test "cast union to tag type of union" {
208}208}
209209
210fn testCastUnionToTagType(x: TheUnion) void {210fn testCastUnionToTagType(x: TheUnion) void {
211 expect(TheTag(x) == TheTag.B);211 expect(@as(TheTag,x) == TheTag.B);
212}212}
213213
214test "cast tag type of union to union" {214test "cast tag type of union to union" {
215 var x: Value2 = Letter2.B;215 var x: Value2 = Letter2.B;
216 expect(Letter2(x) == Letter2.B);216 expect(@as(Letter2, x) == Letter2.B);
217}217}
218const Letter2 = enum {218const Letter2 = enum {
219 A,219 A,
...@@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) {...@@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) {
297297
298fn testTaggedUnionInit(x: var) bool {298fn testTaggedUnionInit(x: var) bool {
299 const y = TaggedUnionWithAVoid{ .A = x };299 const y = TaggedUnionWithAVoid{ .A = x };
300 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;300 return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;
301}301}
302302
303pub const UnionEnumNoPayloads = union(enum) {303pub const UnionEnumNoPayloads = union(enum) {
...@@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" {...@@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" {
326 var e = Expr{ .Literal = Literal{ .Bool = true } };326 var e = Expr{ .Literal = Literal{ .Bool = true } };
327 const Tag = @TagType(Expr);327 const Tag = @TagType(Expr);
328 comptime expect(@TagType(Tag) == u0);328 comptime expect(@TagType(Tag) == u0);
329 var t = Tag(e);329 var t = @as(Tag, e);
330 expect(t == Expr.Literal);330 expect(t == Expr.Literal);
331}331}
332332
...@@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci...@@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci
346346
347 var e = Expr{ .Literal = Literal{ .Bool = true } };347 var e = Expr{ .Literal = Literal{ .Bool = true } };
348 comptime expect(@TagType(Tag) == comptime_int);348 comptime expect(@TagType(Tag) == comptime_int);
349 var t = Tag(e);349 var t = @as(Tag, e);
350 expect(t == Expr.Literal);350 expect(t == Expr.Literal);
351 expect(@enumToInt(t) == 33);351 expect(@enumToInt(t) == 33);
352 comptime expect(@enumToInt(t) == 33);352 comptime expect(@enumToInt(t) == 33);
test/stage1/behavior/var_args.zig+5-5
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3fn add(args: ...) i32 {3fn add(args: ...) i32 {
4 var sum = i32(0);4 var sum = @as(i32, 0);
5 {5 {
6 comptime var i: usize = 0;6 comptime var i: usize = 0;
7 inline while (i < args.len) : (i += 1) {7 inline while (i < args.len) : (i += 1) {
...@@ -12,8 +12,8 @@ fn add(args: ...) i32 {...@@ -12,8 +12,8 @@ fn add(args: ...) i32 {
12}12}
1313
14test "add arbitrary args" {14test "add arbitrary args" {
15 expect(add(i32(1), i32(2), i32(3), i32(4)) == 10);15 expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
16 expect(add(i32(1234)) == 1234);16 expect(add(@as(i32, 1234)) == 1234);
17 expect(add() == 0);17 expect(add() == 0);
18}18}
1919
...@@ -26,8 +26,8 @@ test "send void arg to var args" {...@@ -26,8 +26,8 @@ test "send void arg to var args" {
26}26}
2727
28test "pass args directly" {28test "pass args directly" {
29 expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);29 expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
30 expect(addSomeStuff(i32(1234)) == 1234);30 expect(addSomeStuff(@as(i32, 1234)) == 1234);
31 expect(addSomeStuff() == 0);31 expect(addSomeStuff() == 0);
32}32}
3333
test/stage1/behavior/vector.zig+25-25
...@@ -20,11 +20,11 @@ test "vector wrap operators" {...@@ -20,11 +20,11 @@ test "vector wrap operators" {
20 fn doTheTest() void {20 fn doTheTest() void {
21 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };21 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
22 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };22 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
23 expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));23 expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));24 expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 2147483647, 2, 90, 160 }));25 expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
26 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };26 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
27 expect(mem.eql(i32, ([4]i32)(-%z), [4]i32{ -1, -2, -3, -2147483648 }));27 expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 }));
28 }28 }
29 };29 };
30 S.doTheTest();30 S.doTheTest();
...@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {...@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
36 fn doTheTest() void {36 fn doTheTest() void {
37 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };37 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
38 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };38 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
39 expect(mem.eql(bool, ([4]bool)(v == x), [4]bool{ false, false, true, false }));39 expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, ([4]bool)(v != x), [4]bool{ true, true, false, true }));40 expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, ([4]bool)(v < x), [4]bool{ false, true, false, false }));41 expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, ([4]bool)(v > x), [4]bool{ true, false, false, true }));42 expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, ([4]bool)(v <= x), [4]bool{ false, true, true, false }));43 expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, ([4]bool)(v >= x), [4]bool{ true, false, true, true }));44 expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));
45 }45 }
46 };46 };
47 S.doTheTest();47 S.doTheTest();
...@@ -53,10 +53,10 @@ test "vector int operators" {...@@ -53,10 +53,10 @@ test "vector int operators" {
53 fn doTheTest() void {53 fn doTheTest() void {
54 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };54 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
55 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };55 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
56 expect(mem.eql(i32, ([4]i32)(v + x), [4]i32{ 11, 22, 33, 44 }));56 expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, ([4]i32)(v - x), [4]i32{ 9, 18, 27, 36 }));57 expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, ([4]i32)(v * x), [4]i32{ 10, 40, 90, 160 }));58 expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, ([4]i32)(-v), [4]i32{ -10, -20, -30, -40 }));59 expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));
60 }60 }
61 };61 };
62 S.doTheTest();62 S.doTheTest();
...@@ -68,10 +68,10 @@ test "vector float operators" {...@@ -68,10 +68,10 @@ test "vector float operators" {
68 fn doTheTest() void {68 fn doTheTest() void {
69 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };69 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
70 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };70 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
71 expect(mem.eql(f32, ([4]f32)(v + x), [4]f32{ 11, 22, 33, 44 }));71 expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, ([4]f32)(v - x), [4]f32{ 9, 18, 27, 36 }));72 expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, ([4]f32)(v * x), [4]f32{ 10, 40, 90, 160 }));73 expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, ([4]f32)(-x), [4]f32{ -1, -2, -3, -4 }));74 expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));
75 }75 }
76 };76 };
77 S.doTheTest();77 S.doTheTest();
...@@ -83,9 +83,9 @@ test "vector bit operators" {...@@ -83,9 +83,9 @@ test "vector bit operators" {
83 fn doTheTest() void {83 fn doTheTest() void {
84 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };84 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
85 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };85 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
86 expect(mem.eql(u8, ([4]u8)(v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));86 expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, ([4]u8)(v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));87 expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, ([4]u8)(v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));88 expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
89 }89 }
90 };90 };
91 S.doTheTest();91 S.doTheTest();
...@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {...@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120 {120 {
121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122 var x: [4]u3 = v;122 var x: [4]u3 = v;
123 expect(mem.eql(u3, x, ([4]u3)(v)));123 expect(mem.eql(u3, x, @as([4]u3, v)));
124 }124 }
125 {125 {
126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127 var x: [4]u2 = v;127 var x: [4]u2 = v;
128 expect(mem.eql(u2, x, ([4]u2)(v)));128 expect(mem.eql(u2, x, @as([4]u2, v)));
129 }129 }
130 {130 {
131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132 var x: [4]u1 = v;132 var x: [4]u1 = v;
133 expect(mem.eql(u1, x, ([4]u1)(v)));133 expect(mem.eql(u1, x, @as([4]u1, v)));
134 }134 }
135 {135 {
136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137 var x: [4]bool = v;137 var x: [4]bool = v;
138 expect(mem.eql(bool, x, ([4]bool)(v)));138 expect(mem.eql(bool, x, @as([4]bool, v)));
139 }139 }
140 }140 }
141 };141 };
test/stage1/behavior/void.zig+1-1
...@@ -26,7 +26,7 @@ test "iterate over a void slice" {...@@ -26,7 +26,7 @@ test "iterate over a void slice" {
26}26}
2727
28fn times(n: usize) []const void {28fn times(n: usize) []const void {
29 return ([*]void)(undefined)[0..n];29 return @as([*]void, undefined)[0..n];
30}30}
3131
32test "void optional" {32test "void optional" {
test/stage1/behavior/while.zig+8-8
...@@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" {...@@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" {
137 const result = while (returnNull()) |value| {137 const result = while (returnNull()) |value| {
138 break value;138 break value;
139 } else139 } else
140 i32(2);140 @as(i32, 2);
141 expect(result == 2);141 expect(result == 2);
142}142}
143143
...@@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" {...@@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" {
145 const result = while (returnOptional(10)) |value| {145 const result = while (returnOptional(10)) |value| {
146 break value;146 break value;
147 } else147 } else
148 i32(2);148 @as(i32, 2);
149 expect(result == 10);149 expect(result == 10);
150}150}
151151
...@@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" {...@@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" {
153 const result = while (returnError()) |value| {153 const result = while (returnError()) |value| {
154 break value;154 break value;
155 } else |err|155 } else |err|
156 i32(2);156 @as(i32, 2);
157 expect(result == 2);157 expect(result == 2);
158}158}
159159
...@@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" {...@@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" {
161 const result = while (returnSuccess(10)) |value| {161 const result = while (returnSuccess(10)) |value| {
162 break value;162 break value;
163 } else |err|163 } else |err|
164 i32(2);164 @as(i32, 2);
165 expect(result == 10);165 expect(result == 10);
166}166}
167167
168test "while on bool with else result follow else prong" {168test "while on bool with else result follow else prong" {
169 const result = while (returnFalse()) {169 const result = while (returnFalse()) {
170 break i32(10);170 break @as(i32, 10);
171 } else171 } else
172 i32(2);172 @as(i32, 2);
173 expect(result == 2);173 expect(result == 2);
174}174}
175175
176test "while on bool with else result follow break prong" {176test "while on bool with else result follow break prong" {
177 const result = while (returnTrue()) {177 const result = while (returnTrue()) {
178 break i32(10);178 break @as(i32, 10);
179 } else179 } else
180 i32(2);180 @as(i32, 2);
181 expect(result == 10);181 expect(result == 10);
182}182}
183183
test/tests.zig+2-2
...@@ -411,7 +411,7 @@ pub fn addPkgTests(...@@ -411,7 +411,7 @@ pub fn addPkgTests(
411 const ArchTag = @TagType(builtin.Arch);411 const ArchTag = @TagType(builtin.Arch);
412 if (test_target.disable_native and412 if (test_target.disable_native and
413 test_target.target.getOs() == builtin.os and413 test_target.target.getOs() == builtin.os and
414 ArchTag(test_target.target.getArch()) == ArchTag(builtin.arch))414 @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch))
415 {415 {
416 continue;416 continue;
417 }417 }
...@@ -429,7 +429,7 @@ pub fn addPkgTests(...@@ -429,7 +429,7 @@ pub fn addPkgTests(
429 "bare";429 "bare";
430430
431 const triple_prefix = if (test_target.target == .Native)431 const triple_prefix = if (test_target.target == .Native)
432 ([]const u8)("native")432 @as([]const u8,"native")
433 else433 else
434 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;434 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
435435
test/translate_c.zig+31-31
...@@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28 ,28 ,
29 \\pub fn foo() void {29 \\pub fn foo() void {
30 \\ var a: c_int = undefined;30 \\ var a: c_int = undefined;
31 \\ var b: u8 = u8(123);31 \\ var b: u8 = @as(u8, 123);
32 \\ const c: c_int = undefined;32 \\ const c: c_int = undefined;
33 \\ const d: c_uint = c_uint(440);33 \\ const d: c_uint = @as(c_uint, 440);
34 \\}34 \\}
35 );35 );
3636
...@@ -561,7 +561,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -561,7 +561,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
561 cases.add("u integer suffix after hex literal",561 cases.add("u integer suffix after hex literal",
562 \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */562 \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
563 ,563 ,
564 \\pub const SDL_INIT_VIDEO = c_uint(32);564 \\pub const SDL_INIT_VIDEO = @as(c_uint, 32);
565 );565 );
566566
567 cases.add("l integer suffix after hex literal",567 cases.add("l integer suffix after hex literal",
...@@ -676,7 +676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -676,7 +676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
676 \\pub export fn log2(_arg_a: c_uint) c_int {676 \\pub export fn log2(_arg_a: c_uint) c_int {
677 \\ var a = _arg_a;677 \\ var a = _arg_a;
678 \\ var i: c_int = 0;678 \\ var i: c_int = 0;
679 \\ while (a > c_uint(0)) {679 \\ while (a > @as(c_uint, 0)) {
680 \\ a >>= @import("std").math.Log2Int(c_uint)(1);680 \\ a >>= @import("std").math.Log2Int(c_uint)(1);
681 \\ }681 \\ }
682 \\ return i;682 \\ return i;
...@@ -848,7 +848,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -848,7 +848,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
848 \\pub export fn log2(_arg_a: u32) c_int {848 \\pub export fn log2(_arg_a: u32) c_int {
849 \\ var a = _arg_a;849 \\ var a = _arg_a;
850 \\ var i: c_int = 0;850 \\ var i: c_int = 0;
851 \\ while (a > c_uint(0)) {851 \\ while (a > @as(c_uint, 0)) {
852 \\ a >>= u5(1);852 \\ a >>= u5(1);
853 \\ }853 \\ }
854 \\ return i;854 \\ return i;
...@@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
937 \\}937 \\}
938 ,938 ,
939 \\pub export fn float_to_int(a: f32) c_int {939 \\pub export fn float_to_int(a: f32) c_int {
940 \\ return c_int(a);940 \\ return @as(c_int, a);
941 \\}941 \\}
942 );942 );
943943
...@@ -1103,35 +1103,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1103,35 +1103,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1103 \\}1103 \\}
1104 ,1104 ,
1105 \\pub export fn foo() void {1105 \\pub export fn foo() void {
1106 \\ var a: c_uint = c_uint(0);1106 \\ var a: c_uint = @as(c_uint, 0);
1107 \\ a +%= (x: {1107 \\ a +%= (x: {
1108 \\ const _ref = &a;1108 \\ const _ref = &a;
1109 \\ _ref.* = (_ref.* +% c_uint(1));1109 \\ _ref.* = (_ref.* +% @as(c_uint, 1));
1110 \\ break :x _ref.*;1110 \\ break :x _ref.*;
1111 \\ });1111 \\ });
1112 \\ a -%= (x: {1112 \\ a -%= (x: {
1113 \\ const _ref = &a;1113 \\ const _ref = &a;
1114 \\ _ref.* = (_ref.* -% c_uint(1));1114 \\ _ref.* = (_ref.* -% @as(c_uint, 1));
1115 \\ break :x _ref.*;1115 \\ break :x _ref.*;
1116 \\ });1116 \\ });
1117 \\ a *%= (x: {1117 \\ a *%= (x: {
1118 \\ const _ref = &a;1118 \\ const _ref = &a;
1119 \\ _ref.* = (_ref.* *% c_uint(1));1119 \\ _ref.* = (_ref.* *% @as(c_uint, 1));
1120 \\ break :x _ref.*;1120 \\ break :x _ref.*;
1121 \\ });1121 \\ });
1122 \\ a &= (x: {1122 \\ a &= (x: {
1123 \\ const _ref = &a;1123 \\ const _ref = &a;
1124 \\ _ref.* = (_ref.* & c_uint(1));1124 \\ _ref.* = (_ref.* & @as(c_uint, 1));
1125 \\ break :x _ref.*;1125 \\ break :x _ref.*;
1126 \\ });1126 \\ });
1127 \\ a |= (x: {1127 \\ a |= (x: {
1128 \\ const _ref = &a;1128 \\ const _ref = &a;
1129 \\ _ref.* = (_ref.* | c_uint(1));1129 \\ _ref.* = (_ref.* | @as(c_uint, 1));
1130 \\ break :x _ref.*;1130 \\ break :x _ref.*;
1131 \\ });1131 \\ });
1132 \\ a ^= (x: {1132 \\ a ^= (x: {
1133 \\ const _ref = &a;1133 \\ const _ref = &a;
1134 \\ _ref.* = (_ref.* ^ c_uint(1));1134 \\ _ref.* = (_ref.* ^ @as(c_uint, 1));
1135 \\ break :x _ref.*;1135 \\ break :x _ref.*;
1136 \\ });1136 \\ });
1137 \\ a >>= @import("std").math.Log2Int(c_uint)((x: {1137 \\ a >>= @import("std").math.Log2Int(c_uint)((x: {
...@@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1174 ,1174 ,
1175 \\pub export fn foo() void {1175 \\pub export fn foo() void {
1176 \\ var i: c_int = 0;1176 \\ var i: c_int = 0;
1177 \\ var u: c_uint = c_uint(0);1177 \\ var u: c_uint = @as(c_uint, 0);
1178 \\ i += 1;1178 \\ i += 1;
1179 \\ i -= 1;1179 \\ i -= 1;
1180 \\ u +%= 1;1180 \\ u +%= 1;
...@@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1222 ,1222 ,
1223 \\pub export fn foo() void {1223 \\pub export fn foo() void {
1224 \\ var i: c_int = 0;1224 \\ var i: c_int = 0;
1225 \\ var u: c_uint = c_uint(0);1225 \\ var u: c_uint = @as(c_uint, 0);
1226 \\ i += 1;1226 \\ i += 1;
1227 \\ i -= 1;1227 \\ i -= 1;
1228 \\ u +%= 1;1228 \\ u +%= 1;
...@@ -1646,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1646,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1646 cases.addC(1646 cases.addC(
1647 "u integer suffix after 0 (zero) in macro definition",1647 "u integer suffix after 0 (zero) in macro definition",
1648 "#define ZERO 0U",1648 "#define ZERO 0U",
1649 "pub const ZERO = c_uint(0);",1649 "pub const ZERO = @as(c_uint, 0);",
1650 );1650 );
16511651
1652 cases.addC(1652 cases.addC(
...@@ -1688,7 +1688,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1688,7 +1688,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1688 cases.addC(1688 cases.addC(
1689 "bitwise not on u-suffixed 0 (zero) in macro definition",1689 "bitwise not on u-suffixed 0 (zero) in macro definition",
1690 "#define NOT_ZERO (~0U)",1690 "#define NOT_ZERO (~0U)",
1691 "pub const NOT_ZERO = ~c_uint(0);",1691 "pub const NOT_ZERO = ~@as(c_uint, 0);",
1692 );1692 );
16931693
1694 cases.addC("implicit casts",1694 cases.addC("implicit casts",
...@@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1733 \\ fn_int(1094861636);1733 \\ fn_int(1094861636);
1734 \\ fn_f32(@intToFloat(f32, 3));1734 \\ fn_f32(@intToFloat(f32, 3));
1735 \\ fn_f64(@intToFloat(f64, 3));1735 \\ fn_f64(@intToFloat(f64, 3));
1736 \\ fn_char(u8('3'));1736 \\ fn_char(@as(u8, '3'));
1737 \\ fn_char(u8('\x01'));1737 \\ fn_char(@as(u8, '\x01'));
1738 \\ fn_char(u8(0));1738 \\ fn_char(@as(u8, 0));
1739 \\ fn_f32(3.000000);1739 \\ fn_f32(3.000000);
1740 \\ fn_f64(3.000000);1740 \\ fn_f64(3.000000);
1741 \\ fn_bool(true);1741 \\ fn_bool(true);
...@@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1798 \\1798 \\
1799 ,1799 ,
1800 \\pub export fn escapes() [*c]const u8 {1800 \\pub export fn escapes() [*c]const u8 {
1801 \\ var a: u8 = u8('\'');1801 \\ var a: u8 = @as(u8, '\'');
1802 \\ var b: u8 = u8('\\');1802 \\ var b: u8 = @as(u8, '\\');
1803 \\ var c: u8 = u8('\x07');1803 \\ var c: u8 = @as(u8, '\x07');
1804 \\ var d: u8 = u8('\x08');1804 \\ var d: u8 = @as(u8, '\x08');
1805 \\ var e: u8 = u8('\x0c');1805 \\ var e: u8 = @as(u8, '\x0c');
1806 \\ var f: u8 = u8('\n');1806 \\ var f: u8 = @as(u8, '\n');
1807 \\ var g: u8 = u8('\r');1807 \\ var g: u8 = @as(u8, '\r');
1808 \\ var h: u8 = u8('\t');1808 \\ var h: u8 = @as(u8, '\t');
1809 \\ var i: u8 = u8('\x0b');1809 \\ var i: u8 = @as(u8, '\x0b');
1810 \\ var j: u8 = u8('\x00');1810 \\ var j: u8 = @as(u8, '\x00');
1811 \\ var k: u8 = u8('\"');1811 \\ var k: u8 = @as(u8, '\"');
1812 \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";1812 \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
1813 \\}1813 \\}
1814 \\1814 \\