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 {
155155 ) catch unreachable;
156156 for (dep.system_libs.toSliceConst()) |lib| {
157157 const static_bare_name = if (mem.eql(u8, lib, "curses"))
158 ([]const u8)("libncurses.a")
158 @as([]const u8,"libncurses.a")
159159 else
160160 b.fmt("lib{}.a", lib);
161161 const static_lib_name = fs.path.join(
lib/std/array_list.zig+8-8
......@@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" {
344344 try list.append(7);
345345
346346 //remove from middle
347 testing.expectEqual(i32(4), list.orderedRemove(3));
348 testing.expectEqual(i32(5), list.at(3));
349 testing.expectEqual(usize(6), list.len);
347 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
348 testing.expectEqual(@as(i32, 5), list.at(3));
349 testing.expectEqual(@as(usize, 6), list.len);
350350
351351 //remove from end
352 testing.expectEqual(i32(7), list.orderedRemove(5));
353 testing.expectEqual(usize(5), list.len);
352 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
353 testing.expectEqual(@as(usize, 5), list.len);
354354
355355 //remove from front
356 testing.expectEqual(i32(1), list.orderedRemove(0));
357 testing.expectEqual(i32(2), list.at(0));
358 testing.expectEqual(usize(4), list.len);
356 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
357 testing.expectEqual(@as(i32, 2), list.at(0));
358 testing.expectEqual(@as(usize, 4), list.len);
359359}
360360
361361test "std.ArrayList.swapRemove" {
lib/std/ascii.zig+11-11
......@@ -129,26 +129,26 @@ const combinedTable = init: {
129129 comptime var i = 0;
130130 inline while (i < 128) : (i += 1) {
131131 table[i] =
132 u8(alpha[i]) << @enumToInt(tIndex.Alpha) |
133 u8(hex[i]) << @enumToInt(tIndex.Hex) |
134 u8(space[i]) << @enumToInt(tIndex.Space) |
135 u8(digit[i]) << @enumToInt(tIndex.Digit) |
136 u8(lower[i]) << @enumToInt(tIndex.Lower) |
137 u8(upper[i]) << @enumToInt(tIndex.Upper) |
138 u8(punct[i]) << @enumToInt(tIndex.Punct) |
139 u8(graph[i]) << @enumToInt(tIndex.Graph);
132 @as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) |
133 @as(u8, hex[i]) << @enumToInt(tIndex.Hex) |
134 @as(u8, space[i]) << @enumToInt(tIndex.Space) |
135 @as(u8, digit[i]) << @enumToInt(tIndex.Digit) |
136 @as(u8, lower[i]) << @enumToInt(tIndex.Lower) |
137 @as(u8, upper[i]) << @enumToInt(tIndex.Upper) |
138 @as(u8, punct[i]) << @enumToInt(tIndex.Punct) |
139 @as(u8, graph[i]) << @enumToInt(tIndex.Graph);
140140 }
141141 mem.set(u8, table[128..256], 0);
142142 break :init table;
143143};
144144
145145fn 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;
147147}
148148
149149pub fn isAlNum(c: u8) bool {
150 return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) |
151 u8(1) << @enumToInt(tIndex.Digit))) != 0;
150 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
151 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
152152}
153153
154154pub fn isAlpha(c: u8) bool {
lib/std/atomic/queue.zig+2-2
......@@ -214,8 +214,8 @@ test "std.atomic.Queue" {
214214 std.debug.panic(
215215 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
216216 context.get_count,
217 u32(puts_per_thread),
218 u32(put_thread_count),
217 @as(u32, puts_per_thread),
218 @as(u32, put_thread_count),
219219 );
220220 }
221221}
lib/std/atomic/stack.zig+3-3
......@@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type {
1111 root: ?*Node,
1212 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
1616 pub const Self = @This();
1717
......@@ -141,8 +141,8 @@ test "std.atomic.stack" {
141141 std.debug.panic(
142142 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
143143 context.get_count,
144 u32(puts_per_thread),
145 u32(put_thread_count),
144 @as(u32, puts_per_thread),
145 @as(u32, put_thread_count),
146146 );
147147 }
148148}
lib/std/bloom_filter.zig+3-3
......@@ -171,7 +171,7 @@ test "std.BloomFilter" {
171171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
172172 }
173173 testing.expectEqual(BF.Index(0), bf.popCount());
174 testing.expectEqual(f64(0), bf.estimateItems());
174 testing.expectEqual(@as(f64, 0), bf.estimateItems());
175175 // fill in a few items
176176 bf.incrementCell(42);
177177 bf.incrementCell(255);
......@@ -197,7 +197,7 @@ test "std.BloomFilter" {
197197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
198198 }
199199 testing.expectEqual(BF.Index(0), bf.popCount());
200 testing.expectEqual(f64(0), bf.estimateItems());
200 testing.expectEqual(@as(f64, 0), bf.estimateItems());
201201
202202 // Lets add a string
203203 bf.add("foo");
......@@ -219,7 +219,7 @@ test "std.BloomFilter" {
219219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
220220 }
221221 testing.expectEqual(BF.Index(0), bf.popCount());
222 testing.expectEqual(f64(0), bf.estimateItems());
222 testing.expectEqual(@as(f64, 0), bf.estimateItems());
223223
224224 comptime var teststrings = [_][]const u8{
225225 "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
5353pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
5454
5555pub fn sigaddset(set: *sigset_t, signo: u5) void {
56 set.* |= u32(1) << (signo - 1);
56 set.* |= @as(u32, 1) << (signo - 1);
5757}
5858
5959pub 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 {
717717// Child of fork calls this to report an error to the fork parent.
718718// Then the child exits.
719719fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
720 writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};
720 writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {};
721721 os.exit(1);
722722}
723723
lib/std/crypto/aes.zig+10-10
......@@ -6,7 +6,7 @@ const testing = std.testing;
66
77// Apply sbox0 to each byte in w.
88fn 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]);
1010}
1111
1212fn rotw(w: u32) u32 {
......@@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
4848 }
4949
5050 // 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]);
52 s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | 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]);
54 s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 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 = @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 = @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 = @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
5656 s0 ^= xk[k + 0];
5757 s1 ^= xk[k + 1];
......@@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
9999 }
100100
101101 // 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]);
103 s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | 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]);
105 s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 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 = @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 = @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 = @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
107107 s0 ^= xk[k + 0];
108108 s1 ^= xk[k + 1];
......@@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void {
256256 while (i < enc.len) : (i += 1) {
257257 var t = enc[i - 1];
258258 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);
260260 } else if (nk > 6 and i % nk == 4) {
261261 t = subw(t);
262262 }
lib/std/crypto/blake2.zig+8-8
......@@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type {
164164 inline while (j < 10) : (j += 1) {
165165 inline for (rounds) |r| {
166166 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));
168168 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));
170170 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));
172172 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));
174174 }
175175 }
176176
......@@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type {
398398 inline while (j < 12) : (j += 1) {
399399 inline for (rounds) |r| {
400400 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));
402402 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));
404404 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));
406406 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));
408408 }
409409 }
410410
lib/std/crypto/chacha20.zig+4-4
......@@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {
4949 // two-round cycles
5050 inline for (rounds) |r| {
5151 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));
5353 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));
5555 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));
5757 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));
5959 }
6060 }
6161
lib/std/crypto/gimli.zig+4-4
......@@ -34,9 +34,9 @@ pub const State = struct {
3434
3535 pub fn permute(self: *Self) void {
3636 const state = &self.data;
37 var round = u32(24);
37 var round = @as(u32, 24);
3838 while (round > 0) : (round -= 1) {
39 var column = usize(0);
39 var column = @as(usize, 0);
4040 while (column < 4) : (column += 1) {
4141 const x = math.rotl(u32, state[column], 24);
4242 const y = math.rotl(u32, state[4 + column], 9);
......@@ -61,7 +61,7 @@ pub const State = struct {
6161 }
6262
6363 pub fn squeeze(self: *Self, out: []u8) void {
64 var i = usize(0);
64 var i = @as(usize, 0);
6565 while (i + RATE <= out.len) : (i += RATE) {
6666 self.permute();
6767 mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]);
......@@ -79,7 +79,7 @@ test "permute" {
7979 var state = State{
8080 .data = blk: {
8181 var input: [12]u32 = undefined;
82 var i = u32(0);
82 var i = @as(u32, 0);
8383 while (i < 12) : (i += 1) {
8484 input[i] = i * i * i + i *% 0x9e3779b9;
8585 }
lib/std/crypto/md5.zig+4-4
......@@ -126,10 +126,10 @@ pub const Md5 = struct {
126126 while (i < 16) : (i += 1) {
127127 // NOTE: Performing or's separately improves perf by ~10%
128128 s[i] = 0;
129 s[i] |= u32(b[i * 4 + 0]);
130 s[i] |= u32(b[i * 4 + 1]) << 8;
131 s[i] |= u32(b[i * 4 + 2]) << 16;
132 s[i] |= u32(b[i * 4 + 3]) << 24;
129 s[i] |= @as(u32, b[i * 4 + 0]);
130 s[i] |= @as(u32, b[i * 4 + 1]) << 8;
131 s[i] |= @as(u32, b[i * 4 + 2]) << 16;
132 s[i] |= @as(u32, b[i * 4 + 3]) << 24;
133133 }
134134
135135 var v: [4]u32 = [_]u32{
lib/std/crypto/poly1305.zig+6-6
......@@ -87,11 +87,11 @@ pub const Poly1305 = struct {
8787 // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff
8888 fn polyBlock(ctx: *Self) void {
8989 // s = h + c, without carry propagation
90 const s0 = u64(ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
91 const s1 = u64(ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
92 const s2 = u64(ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
93 const s3 = u64(ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
94 const s4 = u64(ctx.h[4]) + ctx.c[4]; // s4 <= 5
90 const s0 = @as(u64, ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
91 const s1 = @as(u64, ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
92 const s2 = @as(u64, ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
93 const s3 = @as(u64, ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
94 const s4 = @as(u64, ctx.h[4]) + ctx.c[4]; // s4 <= 5
9595
9696 // Local all the things!
9797 const r0 = ctx.r[0]; // r0 <= 0fffffff
......@@ -197,7 +197,7 @@ pub const Poly1305 = struct {
197197
198198 // check if we should subtract 2^130-5 by performing the
199199 // corresponding carry propagation.
200 const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004
200 const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004
201201 const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000
202202 const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000
203203 const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000
lib/std/crypto/sha1.zig+15-15
......@@ -146,10 +146,10 @@ pub const Sha1 = struct {
146146 Rp(0, 1, 2, 3, 4, 15),
147147 };
148148 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]));
152 v[r.b] = math.rotl(u32, v[r.b], u32(30));
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], @as(u32, 30));
153153 }
154154
155155 const round0b = comptime [_]RoundParam{
......@@ -160,10 +160,10 @@ pub const Sha1 = struct {
160160 };
161161 inline for (round0b) |r| {
162162 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]));
166 v[r.b] = math.rotl(u32, v[r.b], u32(30));
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], @as(u32, 30));
167167 }
168168
169169 const round1 = comptime [_]RoundParam{
......@@ -190,10 +190,10 @@ pub const Sha1 = struct {
190190 };
191191 inline for (round1) |r| {
192192 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]);
196 v[r.b] = math.rotl(u32, v[r.b], u32(30));
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], @as(u32, 30));
197197 }
198198
199199 const round2 = comptime [_]RoundParam{
......@@ -220,10 +220,10 @@ pub const Sha1 = struct {
220220 };
221221 inline for (round2) |r| {
222222 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]));
226 v[r.b] = math.rotl(u32, v[r.b], u32(30));
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], @as(u32, 30));
227227 }
228228
229229 const round3 = comptime [_]RoundParam{
......@@ -250,10 +250,10 @@ pub const Sha1 = struct {
250250 };
251251 inline for (round3) |r| {
252252 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]);
256 v[r.b] = math.rotl(u32, v[r.b], u32(30));
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], @as(u32, 30));
257257 }
258258
259259 d.s[0] +%= v[0];
lib/std/crypto/sha2.zig+20-18
......@@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type {
180180 var i: usize = 0;
181181 while (i < 16) : (i += 1) {
182182 s[i] = 0;
183 s[i] |= u32(b[i * 4 + 0]) << 24;
184 s[i] |= u32(b[i * 4 + 1]) << 16;
185 s[i] |= u32(b[i * 4 + 2]) << 8;
186 s[i] |= u32(b[i * 4 + 3]) << 0;
183 s[i] |= @as(u32, b[i * 4 + 0]) << 24;
184 s[i] |= @as(u32, b[i * 4 + 1]) << 16;
185 s[i] |= @as(u32, b[i * 4 + 2]) << 8;
186 s[i] |= @as(u32, b[i * 4 + 3]) << 0;
187187 }
188188 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));
190190 }
191191
192192 var v: [8]u32 = [_]u32{
......@@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type {
267267 Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2),
268268 };
269269 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
272272 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]));
275275 }
276276
277277 d.s[0] +%= v[0];
......@@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type {
522522 var i: usize = 0;
523523 while (i < 16) : (i += 1) {
524524 s[i] = 0;
525 s[i] |= u64(b[i * 8 + 0]) << 56;
526 s[i] |= u64(b[i * 8 + 1]) << 48;
527 s[i] |= u64(b[i * 8 + 2]) << 40;
528 s[i] |= u64(b[i * 8 + 3]) << 32;
529 s[i] |= u64(b[i * 8 + 4]) << 24;
530 s[i] |= u64(b[i * 8 + 5]) << 16;
531 s[i] |= u64(b[i * 8 + 6]) << 8;
532 s[i] |= u64(b[i * 8 + 7]) << 0;
525 s[i] |= @as(u64, b[i * 8 + 0]) << 56;
526 s[i] |= @as(u64, b[i * 8 + 1]) << 48;
527 s[i] |= @as(u64, b[i * 8 + 2]) << 40;
528 s[i] |= @as(u64, b[i * 8 + 3]) << 32;
529 s[i] |= @as(u64, b[i * 8 + 4]) << 24;
530 s[i] |= @as(u64, b[i * 8 + 5]) << 16;
531 s[i] |= @as(u64, b[i * 8 + 6]) << 8;
532 s[i] |= @as(u64, b[i * 8 + 7]) << 0;
533533 }
534534 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));
536538 }
537539
538540 var v: [8]u64 = [_]u64{
......@@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type {
629631 Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817),
630632 };
631633 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
634636 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]));
637639 }
638640
639641 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 {
133133 }
134134 x = 0;
135135 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));
137137 y = 0;
138138 inline while (y < 5) : (y += 1) {
139139 s[x + y * 5] ^= t[0];
lib/std/crypto/x25519.zig+10-10
......@@ -256,15 +256,15 @@ const Fe = struct {
256256 var t: [10]i64 = undefined;
257257
258258 t[0] = readIntSliceLittle(u32, s[0..4]);
259 t[1] = u32(readIntSliceLittle(u24, s[4..7])) << 6;
260 t[2] = u32(readIntSliceLittle(u24, s[7..10])) << 5;
261 t[3] = u32(readIntSliceLittle(u24, s[10..13])) << 3;
262 t[4] = u32(readIntSliceLittle(u24, s[13..16])) << 2;
259 t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6;
260 t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5;
261 t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3;
262 t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2;
263263 t[5] = readIntSliceLittle(u32, s[16..20]);
264 t[6] = u32(readIntSliceLittle(u24, s[20..23])) << 7;
265 t[7] = u32(readIntSliceLittle(u24, s[23..26])) << 5;
266 t[8] = u32(readIntSliceLittle(u24, s[26..29])) << 4;
267 t[9] = (u32(readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
264 t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7;
265 t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5;
266 t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4;
267 t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
268268
269269 carry1(h, t[0..]);
270270 }
......@@ -500,7 +500,7 @@ const Fe = struct {
500500 if (i + 1 < 10) {
501501 t[i + 1] += c[i];
502502 }
503 t[i] -= c[i] * (i32(1) << shift);
503 t[i] -= c[i] * (@as(i32, 1) << shift);
504504 }
505505
506506 fn toBytes(s: []u8, h: *const Fe) void {
......@@ -511,7 +511,7 @@ const Fe = struct {
511511 t[i] = h.b[i];
512512 }
513513
514 var q = (19 * t[9] + ((i32(1) << 24))) >> 25;
514 var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25;
515515 {
516516 var i: usize = 0;
517517 while (i < 5) : (i += 1) {
lib/std/debug.zig+13-10
......@@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
10081008 const word = try stream.readIntLittle(u32);
10091009 var bit_i: u5 = 0;
10101010 while (true) : (bit_i += 1) {
1011 if (word & (u32(1) << bit_i) != 0) {
1011 if (word & (@as(u32, 1) << bit_i) != 0) {
10121012 try list.append(word_i * 32 + bit_i);
10131013 }
10141014 if (bit_i == maxInt(u5)) break;
......@@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
15561556
15571557// TODO the noasyncs here are workarounds
15581558fn 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));
15601560}
15611561
15621562// TODO the noasyncs here are workarounds
15631563fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
15641564 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));
15661567 } else if (@sizeOf(usize) == 8) {
15671568 return noasync in_stream.readIntLittle(u64);
15681569 } else {
......@@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
18461847 // special opcodes
18471848 const adjusted_opcode = opcode - opcode_base;
18481849 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);
18501851 prog.line += inc_line;
18511852 prog.address += inc_addr;
18521853 if (try prog.checkLineMatch()) |info| return info;
......@@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
19131914 if (unit_length == 0) {
19141915 return error.MissingDebugInfo;
19151916 }
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
19181919 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
19191920 // TODO support 3 and 5
......@@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
20122013 // special opcodes
20132014 const adjusted_opcode = opcode - opcode_base;
20142015 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);
20162017 prog.line += inc_line;
20172018 prog.address += inc_addr;
20182019 if (try prog.checkLineMatch()) |info| return info;
......@@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {
20932094 var is_64: bool = undefined;
20942095 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
20952096 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
20982099 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
20992100 if (version < 2 or version > 5) return error.InvalidDebugInfo;
......@@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void {
21952196 var is_64: bool = undefined;
21962197 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
21972198 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
22002201 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
22012202 if (version < 2 or version > 5) return error.InvalidDebugInfo;
......@@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {
23122313 } else {
23132314 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
23142315 ptr.* += 4;
2315 return u64(first_32_bits);
2316 // TODO this cast should not be needed
2317 return @as(u64, first_32_bits);
23162318 }
23172319}
23182320
......@@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool)
23292331 return in_stream.readIntLittle(u64);
23302332 } else {
23312333 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);
23332336 }
23342337}
23352338
lib/std/debug/leb128.zig+2-2
......@@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
6262 var shift: usize = 0;
6363
6464 while (true) {
65 const byte = u8(try in_stream.readByte());
65 const byte: u8 = try in_stream.readByte();
6666
6767 if (shift > T.bit_count)
6868 return error.Overflow;
6969
7070 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)) {
7272 if (byte != 0x7f)
7373 return error.Overflow;
7474 }
lib/std/dynamic_library.zig+2-2
......@@ -215,8 +215,8 @@ pub const ElfLib = struct {
215215
216216 var i: usize = 0;
217217 while (i < self.hashtab[1]) : (i += 1) {
218 if (0 == (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;
218 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
219 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
220220 if (0 == self.syms[i].st_shndx) continue;
221221 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
222222 if (maybe_versym) |versym| {
lib/std/elf.zig+12-12
......@@ -441,9 +441,9 @@ pub const Elf = struct {
441441 elf.program_header_offset = try in.readInt(u64, elf.endian);
442442 elf.section_header_offset = try in.readInt(u64, elf.endian);
443443 } else {
444 elf.entry_addr = u64(try in.readInt(u32, elf.endian));
445 elf.program_header_offset = u64(try in.readInt(u32, elf.endian));
446 elf.section_header_offset = u64(try in.readInt(u32, elf.endian));
444 elf.entry_addr = @as(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 = @as(u64, try in.readInt(u32, elf.endian));
447447 }
448448
449449 // skip over flags
......@@ -458,13 +458,13 @@ pub const Elf = struct {
458458 const ph_entry_count = try in.readInt(u16, elf.endian);
459459 const sh_entry_size = try in.readInt(u16, elf.endian);
460460 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
463463 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);
466466 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);
468468 const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count);
469469
470470 const stream_end = try seekable_stream.getEndPos();
......@@ -499,14 +499,14 @@ pub const Elf = struct {
499499 // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ?
500500 elf_section.name = try in.readInt(u32, elf.endian);
501501 elf_section.sh_type = try in.readInt(u32, elf.endian);
502 elf_section.flags = u64(try in.readInt(u32, elf.endian));
503 elf_section.addr = u64(try in.readInt(u32, elf.endian));
504 elf_section.offset = u64(try in.readInt(u32, elf.endian));
505 elf_section.size = u64(try in.readInt(u32, elf.endian));
502 elf_section.flags = @as(u64, try in.readInt(u32, elf.endian));
503 elf_section.addr = @as(u64, try in.readInt(u32, elf.endian));
504 elf_section.offset = @as(u64, try in.readInt(u32, elf.endian));
505 elf_section.size = @as(u64, try in.readInt(u32, elf.endian));
506506 elf_section.link = try in.readInt(u32, elf.endian);
507507 elf_section.info = try in.readInt(u32, elf.endian);
508 elf_section.addr_align = u64(try in.readInt(u32, elf.endian));
509 elf_section.ent_size = 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 = @as(u64, try in.readInt(u32, elf.endian));
510510 }
511511 }
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 {
328328 windows.ERROR.IO_PENDING => unreachable,
329329 windows.ERROR.OPERATION_ABORTED => return error.OperationAborted,
330330 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),
332332 else => |err| return windows.unexpectedError(err),
333333 }
334334 }
335 return usize(bytes_transferred);
335 return @as(usize, bytes_transferred);
336336}
337337
338338/// iovecs must live until preadv frame completes
lib/std/fifo.zig+13-13
......@@ -257,7 +257,7 @@ test "ByteFifo" {
257257 defer fifo.deinit();
258258
259259 try fifo.write("HELLO");
260 testing.expectEqual(usize(5), fifo.readableLength());
260 testing.expectEqual(@as(usize, 5), fifo.readableLength());
261261 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
262262
263263 {
......@@ -265,34 +265,34 @@ test "ByteFifo" {
265265 while (i < 5) : (i += 1) {
266266 try fifo.write([_]u8{try fifo.peekItem(i)});
267267 }
268 testing.expectEqual(usize(10), fifo.readableLength());
268 testing.expectEqual(@as(usize, 10), fifo.readableLength());
269269 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
270270 }
271271
272272 {
273 testing.expectEqual(u8('H'), try fifo.readItem());
274 testing.expectEqual(u8('E'), try fifo.readItem());
275 testing.expectEqual(u8('L'), try fifo.readItem());
276 testing.expectEqual(u8('L'), try fifo.readItem());
277 testing.expectEqual(u8('O'), try fifo.readItem());
273 testing.expectEqual(@as(u8, 'H'), try fifo.readItem());
274 testing.expectEqual(@as(u8, 'E'), try fifo.readItem());
275 testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
276 testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
277 testing.expectEqual(@as(u8, 'O'), try fifo.readItem());
278278 }
279 testing.expectEqual(usize(5), fifo.readableLength());
279 testing.expectEqual(@as(usize, 5), fifo.readableLength());
280280
281281 { // Writes that wrap around
282 testing.expectEqual(usize(11), fifo.writableLength());
283 testing.expectEqual(usize(6), fifo.writableSlice(0).len);
282 testing.expectEqual(@as(usize, 11), fifo.writableLength());
283 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
284284 fifo.writeAssumeCapacity("6<chars<11");
285285 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
286286 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
287287 fifo.discard(11);
288288 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
289289 fifo.discard(4);
290 testing.expectEqual(usize(0), fifo.readableLength());
290 testing.expectEqual(@as(usize, 0), fifo.readableLength());
291291 }
292292
293293 {
294294 const buf = try fifo.writeableWithSize(12);
295 testing.expectEqual(usize(12), buf.len);
295 testing.expectEqual(@as(usize, 12), buf.len);
296296 var i: u8 = 0;
297297 while (i < 10) : (i += 1) {
298298 buf[i] = i + 'a';
......@@ -313,6 +313,6 @@ test "ByteFifo" {
313313 try fifo.print("{}, {}!", "Hello", "World");
314314 var result: [30]u8 = undefined;
315315 testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result));
316 testing.expectEqual(usize(0), fifo.readableLength());
316 testing.expectEqual(@as(usize, 0), fifo.readableLength());
317317 }
318318}
lib/std/fmt.zig+51-51
......@@ -512,7 +512,7 @@ pub fn formatIntValue(
512512 uppercase = false;
513513 } else if (comptime std.mem.eql(u8, fmt, "c")) {
514514 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);
516516 } else {
517517 @compileError("Cannot print integer that is larger than 8 bits as a ascii");
518518 }
......@@ -594,7 +594,7 @@ pub fn formatBuf(
594594 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
595595 const pad_byte: u8 = options.fill;
596596 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]);
598598 }
599599}
600600
......@@ -668,7 +668,7 @@ pub fn formatFloatScientific(
668668 try output(context, float_decimal.digits[0..1]);
669669 try output(context, ".");
670670 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
673673 try output(context, float_decimal.digits[1..num_digits]);
674674 } else {
......@@ -703,7 +703,7 @@ pub fn formatFloatDecimal(
703703 comptime Errors: type,
704704 output: fn (@typeOf(context), []const u8) Errors!void,
705705) Errors!void {
706 var x = f64(value);
706 var x = @as(f64, value);
707707
708708 // Errol doesn't handle these special cases.
709709 if (math.signbit(x)) {
......@@ -921,14 +921,14 @@ fn formatIntSigned(
921921 const uint = @IntType(false, @typeOf(value).bit_count);
922922 if (value < 0) {
923923 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..]);
925925 const new_value = @intCast(uint, -(value + 1)) + 1;
926926 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
927927 } else if (options.width == null or options.width.? == 0) {
928928 return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);
929929 } else {
930930 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..]);
932932 const new_value = @intCast(uint, value);
933933 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
934934 }
......@@ -966,7 +966,7 @@ fn formatIntUnsigned(
966966 const zero_byte: u8 = options.fill;
967967 var leftover_padding = padding - index;
968968 while (true) {
969 try output(context, (*const [1]u8)(&zero_byte)[0..]);
969 try output(context, @as(*const [1]u8, &zero_byte)[0..]);
970970 leftover_padding -= 1;
971971 if (leftover_padding == 0) break;
972972 }
......@@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
10881088fn digitToChar(digit: u8, uppercase: bool) u8 {
10891089 return switch (digit) {
10901090 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),
10921092 else => unreachable,
10931093 };
10941094}
......@@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
11341134test "bufPrintInt" {
11351135 var buffer: [100]u8 = undefined;
11361136 const buf = buffer[0..];
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678"));
1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e"));
1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, FormatOptions{}), "-BC614E"));
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678"));
1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, 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"));
1145 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1146 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
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, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 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"));
1149 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, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
11501150}
11511151
11521152fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
......@@ -1208,8 +1208,8 @@ test "int.specifier" {
12081208}
12091209
12101210test "int.padded" {
1211 try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1));
1212 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", u8(1));
1211 try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));
1212 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));
12131213}
12141214
12151215test "buffer" {
......@@ -1287,8 +1287,8 @@ test "filesize" {
12871287 // TODO https://github.com/ziglang/zig/issues/3289
12881288 return error.SkipZigTest;
12891289 }
1290 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024));
1291 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\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", @as(usize, 63 * 1024 * 1024));
12921292}
12931293
12941294test "struct" {
......@@ -1327,8 +1327,8 @@ test "float.scientific" {
13271327 }
13281328 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));
13291329 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));
1330 try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10));
1331 try testFmt("f64: 9.99996e-40", "f64: {e}", f64(9.999960e-40));
1330 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
1331 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
13321332}
13331333
13341334test "float.scientific.precision" {
......@@ -1336,12 +1336,12 @@ test "float.scientific.precision" {
13361336 // TODO https://github.com/ziglang/zig/issues/3289
13371337 return error.SkipZigTest;
13381338 }
1339 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42));
1340 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563))));
1341 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", f64(@bitCast(f32, u32(1006632960))));
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}", @as(f64, @bitCast(f32, @as(u32, 814313563))));
1341 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));
13421342 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
13431343 // 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))));
13451345}
13461346
13471347test "float.special" {
......@@ -1364,21 +1364,21 @@ test "float.decimal" {
13641364 // TODO https://github.com/ziglang/zig/issues/3289
13651365 return error.SkipZigTest;
13661366 }
1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29));
1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
13681368 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));
13691369 try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));
13701370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
13711371 // -11.12339... is rounded back up to -11.1234
13721372 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));
13731373 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));
1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235));
1375 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0));
1376 try testFmt("f64: 6", "f64: {d:.0}", f64(5.700));
1377 try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999));
1378 try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0));
1379 try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003));
1380 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45));
1381 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(9.999960e-40));
1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
1375 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
1376 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
1377 try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));
1378 try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));
1379 try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));
1380 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));
1381 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));
13821382}
13831383
13841384test "float.libc.sanity" {
......@@ -1386,22 +1386,22 @@ test "float.libc.sanity" {
13861386 // TODO https://github.com/ziglang/zig/issues/3289
13871387 return error.SkipZigTest;
13881388 }
1389 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781))));
1390 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389))));
1391 try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278))));
1392 try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133))));
1393 try testFmt("f64: 10.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1092616192))));
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}", @as(f64, @bitCast(f32, @as(u32, 925353389))));
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}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));
1393 try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));
13941394
13951395 // libc differences
13961396 //
13971397 // This is 0.015625 exactly according to gdb. We thus round down,
13981398 // however glibc rounds up for some reason. This occurs for all
13991399 // 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))));
14011401 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
14021402 // also rounds to 630 so I'm inclined to believe libc is not
14031403 // 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))));
14051405}
14061406
14071407test "custom" {
......@@ -1677,17 +1677,17 @@ test "formatType max_depth" {
16771677}
16781678
16791679test "positional" {
1680 try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2));
1681 try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2));
1682 try testFmt("0 0", "{0} {0}", usize(0));
1683 try testFmt("0 1", "{} {1}", usize(0), usize(1));
1684 try testFmt("1 0 0 1", "{1} {} {0} {}", usize(0), usize(1));
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} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1682 try testFmt("0 0", "{0} {0}", @as(usize, 0));
1683 try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));
1684 try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));
16851685}
16861686
16871687test "positional with specifier" {
1688 try testFmt("10.0", "{0d:.1}", f64(9.999));
1688 try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
16891689}
16901690
16911691test "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));
16931693}
lib/std/fmt/errol.zig+2-2
......@@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void {
296296/// @buf: The output buffer.
297297/// &return: The exponent.
298298fn errolInt(val: f64, buffer: []u8) FloatDecimal {
299 const pow19 = u128(1e19);
299 const pow19 = @as(u128, 1e19);
300300
301301 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
302302
......@@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 {
670670 const bits = @bitCast(u64, from);
671671 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);
674674}
675675
676676/// 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 {
5959
6060 // d += s
6161 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);
6363 d.d0 = @truncate(u32, w);
6464
6565 w >>= 32;
66 w += u64(d.d1) + u64(s.d1);
66 w += @as(u64, d.d1) + @as(u64, s.d1);
6767 d.d1 = @truncate(u32, w);
6868
6969 w >>= 32;
70 w += u64(d.d2) + u64(s.d2);
70 w += @as(u64, d.d2) + @as(u64, s.d2);
7171 d.d2 = @truncate(u32, w);
7272 }
7373
7474 // d -= s
7575 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);
7777 d.d0 = @truncate(u32, w);
7878
7979 w >>= 32;
80 w += u64(d.d1) -% u64(s.d1);
80 w += @as(u64, d.d1) -% @as(u64, s.d1);
8181 d.d1 = @truncate(u32, w);
8282
8383 w >>= 32;
84 w += u64(d.d2) -% u64(s.d2);
84 w += @as(u64, d.d2) -% @as(u64, s.d2);
8585 d.d2 = @truncate(u32, w);
8686 }
8787};
......@@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {
160160 break :blk if (n.negative) f64_minus_zero else f64_plus_zero;
161161 } else if (s.d2 != 0) {
162162 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;
164164 break :blk if (n.negative) rr | (1 << 63) else rr;
165165 } else {
166166 break :blk 0;
lib/std/fs/file.zig+3-3
......@@ -272,9 +272,9 @@ pub const File = struct {
272272 return Stat{
273273 .size = @bitCast(u64, st.size),
274274 .mode = st.mode,
275 .atime = 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,
277 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
275 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
276 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
277 .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
278278 };
279279 }
280280
lib/std/hash/auto_hash.zig+7-7
......@@ -306,7 +306,7 @@ test "hash struct deep" {
306306test "testHash optional" {
307307 const a: ?u32 = 123;
308308 const b: ?u32 = null;
309 testing.expectEqual(testHash(a), testHash(u32(123)));
309 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
310310 testing.expect(testHash(a) != testHash(b));
311311 testing.expectEqual(testHash(b), 0);
312312}
......@@ -315,9 +315,9 @@ test "testHash array" {
315315 const a = [_]u32{ 1, 2, 3 };
316316 const h = testHash(a);
317317 var hasher = Wyhash.init(0);
318 autoHash(&hasher, u32(1));
319 autoHash(&hasher, u32(2));
320 autoHash(&hasher, u32(3));
318 autoHash(&hasher, @as(u32, 1));
319 autoHash(&hasher, @as(u32, 2));
320 autoHash(&hasher, @as(u32, 3));
321321 testing.expectEqual(h, hasher.final());
322322}
323323
......@@ -330,9 +330,9 @@ test "testHash struct" {
330330 const f = Foo{};
331331 const h = testHash(f);
332332 var hasher = Wyhash.init(0);
333 autoHash(&hasher, u32(1));
334 autoHash(&hasher, u32(2));
335 autoHash(&hasher, u32(3));
333 autoHash(&hasher, @as(u32, 1));
334 autoHash(&hasher, @as(u32, 2));
335 autoHash(&hasher, @as(u32, 3));
336336 testing.expectEqual(h, hasher.final());
337337}
338338
lib/std/hash/cityhash.zig+4-4
......@@ -214,7 +214,7 @@ pub const CityHash64 = struct {
214214 }
215215
216216 fn hashLen0To16(str: []const u8) u64 {
217 const len: u64 = u64(str.len);
217 const len: u64 = @as(u64, str.len);
218218 if (len >= 8) {
219219 const mul: u64 = k2 +% len *% 2;
220220 const a: u64 = fetch64(str.ptr) +% k2;
......@@ -240,7 +240,7 @@ pub const CityHash64 = struct {
240240 }
241241
242242 fn hashLen17To32(str: []const u8) u64 {
243 const len: u64 = u64(str.len);
243 const len: u64 = @as(u64, str.len);
244244 const mul: u64 = k2 +% len *% 2;
245245 const a: u64 = fetch64(str.ptr) *% k1;
246246 const b: u64 = fetch64(str.ptr + 8);
......@@ -251,7 +251,7 @@ pub const CityHash64 = struct {
251251 }
252252
253253 fn hashLen33To64(str: []const u8) u64 {
254 const len: u64 = u64(str.len);
254 const len: u64 = @as(u64, str.len);
255255 const mul: u64 = k2 +% len *% 2;
256256 const a: u64 = fetch64(str.ptr) *% k2;
257257 const b: u64 = fetch64(str.ptr + 8);
......@@ -305,7 +305,7 @@ pub const CityHash64 = struct {
305305 return hashLen33To64(str);
306306 }
307307
308 var len: u64 = u64(str.len);
308 var len: u64 = @as(u64, str.len);
309309
310310 var x: u64 = fetch64(str.ptr + str.len - 40);
311311 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 {
6565 const p = input[i .. i + 8];
6666
6767 // Unrolling this way gives ~50Mb/s increase
68 self.crc ^= (u32(p[0]) << 0);
69 self.crc ^= (u32(p[1]) << 8);
70 self.crc ^= (u32(p[2]) << 16);
71 self.crc ^= (u32(p[3]) << 24);
68 self.crc ^= (@as(u32, p[0]) << 0);
69 self.crc ^= (@as(u32, p[1]) << 8);
70 self.crc ^= (@as(u32, p[2]) << 16);
71 self.crc ^= (@as(u32, p[3]) << 24);
7272
7373 self.crc =
7474 lookup_tables[0][p[7]] ^
lib/std/hash/murmur.zig+1-1
......@@ -98,7 +98,7 @@ pub const Murmur2_64 = struct {
9898
9999 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
100100 const m: u64 = 0xc6a4a7935bd1e995;
101 const len = u64(str.len);
101 const len = @as(u64, str.len);
102102 var h1: u64 = seed ^ (len *% m);
103103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104104 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
102102 }
103103
104104 const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3;
105 return (u128(b2) << 64) | b1;
105 return (@as(u128, b2) << 64) | b1;
106106 }
107107
108108 fn round(self: *Self, b: []const u8) void {
......@@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
121121
122122 fn sipRound(d: *Self) void {
123123 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));
125125 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));
127127 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));
129129 d.v3 ^= d.v2;
130130 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));
132132 d.v3 ^= d.v0;
133133 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));
135135 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));
137137 }
138138
139139 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
402402 }
403403
404404 fn keyToIndex(hm: Self, key: K) usize {
405 return hm.constrainIndex(usize(hash(key)));
405 return hm.constrainIndex(@as(usize, hash(key)));
406406 }
407407
408408 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
896896 const large_align = u29(mem.page_size << 2);
897897
898898 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
901901 var slice = try allocator.alignedAlloc(u8, large_align, 500);
902902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
lib/std/http/headers.zig+5-5
......@@ -399,7 +399,7 @@ test "Headers.iterator" {
399399 }
400400 count += 1;
401401 }
402 testing.expectEqual(i32(2), count);
402 testing.expectEqual(@as(i32, 2), count);
403403}
404404
405405test "Headers.contains" {
......@@ -420,10 +420,10 @@ test "Headers.delete" {
420420 try h.append("cookie", "somevalue", null);
421421
422422 testing.expectEqual(false, h.delete("not-present"));
423 testing.expectEqual(usize(3), h.count());
423 testing.expectEqual(@as(usize, 3), h.count());
424424
425425 testing.expectEqual(true, h.delete("foo"));
426 testing.expectEqual(usize(2), h.count());
426 testing.expectEqual(@as(usize, 2), h.count());
427427 {
428428 const e = h.at(0);
429429 testing.expectEqualSlices(u8, "baz", e.name);
......@@ -448,7 +448,7 @@ test "Headers.orderedRemove" {
448448 try h.append("cookie", "somevalue", null);
449449
450450 h.orderedRemove(0);
451 testing.expectEqual(usize(2), h.count());
451 testing.expectEqual(@as(usize, 2), h.count());
452452 {
453453 const e = h.at(0);
454454 testing.expectEqualSlices(u8, "baz", e.name);
......@@ -471,7 +471,7 @@ test "Headers.swapRemove" {
471471 try h.append("cookie", "somevalue", null);
472472
473473 h.swapRemove(0);
474 testing.expectEqual(usize(2), h.count());
474 testing.expectEqual(@as(usize, 2), h.count());
475475 {
476476 const e = h.at(0);
477477 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 {
353353 const Buf = @IntType(false, buf_bit_count);
354354 const BufShift = math.Log2Int(Buf);
355355
356 out_bits.* = usize(0);
356 out_bits.* = @as(usize, 0);
357357 if (U == u0 or bits == 0) return 0;
358358 var out_buffer = Buf(0);
359359
......@@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
434434 var self = @fieldParentPtr(Self, "stream", self_stream);
435435
436436 var out_bits: usize = undefined;
437 var out_bits_total = usize(0);
437 var out_bits_total = @as(usize, 0);
438438 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
439439 if (self.bit_count > 0) {
440440 for (buffer) |*b, i| {
lib/std/io/out_stream.zig+2-2
......@@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type {
4040 }
4141
4242 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..];
4444 return self.writeFn(self, slice);
4545 }
4646
4747 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..];
4949 var i: usize = 0;
5050 while (i < n) : (i += 1) {
5151 try self.writeFn(self, slice);
lib/std/io/test.zig+20-20
......@@ -228,8 +228,8 @@ test "BitOutStream" {
228228
229229 try bit_stream_be.writeBits(u2(1), 1);
230230 try bit_stream_be.writeBits(u5(2), 2);
231 try bit_stream_be.writeBits(u128(3), 3);
232 try bit_stream_be.writeBits(u8(4), 4);
231 try bit_stream_be.writeBits(@as(u128, 3), 3);
232 try bit_stream_be.writeBits(@as(u8, 4), 4);
233233 try bit_stream_be.writeBits(u9(5), 5);
234234 try bit_stream_be.writeBits(u1(1), 1);
235235
......@@ -242,33 +242,33 @@ test "BitOutStream" {
242242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
243243
244244 mem_out_be.pos = 0;
245 try bit_stream_be.writeBits(u32(0b110011010000101), 16);
245 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
246246 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
250250 var mem_out_le = io.SliceOutStream.init(mem_le[0..]);
251251 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);
254 try bit_stream_le.writeBits(u5(2), 2);
255 try bit_stream_le.writeBits(u128(3), 3);
256 try bit_stream_le.writeBits(u8(4), 4);
257 try bit_stream_le.writeBits(u9(5), 5);
258 try bit_stream_le.writeBits(u1(1), 1);
253 try bit_stream_le.writeBits(@as(u2, 1), 1);
254 try bit_stream_le.writeBits(@as(u5, 2), 2);
255 try bit_stream_le.writeBits(@as(u128, 3), 3);
256 try bit_stream_le.writeBits(@as(u8, 4), 4);
257 try bit_stream_le.writeBits(@as(u9, 5), 5);
258 try bit_stream_le.writeBits(@as(u1, 1), 1);
259259
260260 expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
261261
262262 mem_out_le.pos = 0;
263 try bit_stream_le.writeBits(u15(0b110011010000101), 15);
263 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
264264 try bit_stream_le.flushBits();
265265 expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
266266
267267 mem_out_le.pos = 0;
268 try bit_stream_le.writeBits(u32(0b1100110100001011), 16);
268 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
269269 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);
272272}
273273
274274test "BitStreams with File Stream" {
......@@ -282,12 +282,12 @@ test "BitStreams with File Stream" {
282282 const OutError = File.WriteError;
283283 var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream);
284284
285 try bit_stream.writeBits(u2(1), 1);
286 try bit_stream.writeBits(u5(2), 2);
287 try bit_stream.writeBits(u128(3), 3);
288 try bit_stream.writeBits(u8(4), 4);
289 try bit_stream.writeBits(u9(5), 5);
290 try bit_stream.writeBits(u1(1), 1);
285 try bit_stream.writeBits(@as(u2, 1), 1);
286 try bit_stream.writeBits(@as(u5, 2), 2);
287 try bit_stream.writeBits(@as(u128, 3), 3);
288 try bit_stream.writeBits(@as(u8, 4), 4);
289 try bit_stream.writeBits(@as(u9, 5), 5);
290 try bit_stream.writeBits(@as(u1, 1), 1);
291291 try bit_stream.flushBits();
292292 }
293293 {
......@@ -603,7 +603,7 @@ test "c out stream" {
603603 }
604604
605605 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));
607607}
608608
609609test "File seek ops" {
lib/std/json.zig+2-2
......@@ -1343,7 +1343,7 @@ test "write json then parse it" {
13431343 try jw.emitBool(true);
13441344
13451345 try jw.objectField("int");
1346 try jw.emitNumber(i32(1234));
1346 try jw.emitNumber(@as(i32, 1234));
13471347
13481348 try jw.objectField("array");
13491349 try jw.beginArray();
......@@ -1352,7 +1352,7 @@ test "write json then parse it" {
13521352 try jw.emitNull();
13531353
13541354 try jw.arrayElem();
1355 try jw.emitNumber(f64(12.34));
1355 try jw.emitNumber(@as(f64, 12.34));
13561356
13571357 try jw.endArray();
13581358
lib/std/math.zig+68-68
......@@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079;
4444pub const sqrt1_2 = 0.707106781186547524400844362104849039;
4545
4646// From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128)
47pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001));
48pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000));
49pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
50pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000));
47pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001));
48pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000));
49pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
50pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000));
5151pub const f128_toint = 1.0 / f128_epsilon;
5252
5353// float.h details
......@@ -69,28 +69,28 @@ pub const f16_max = 65504;
6969pub const f16_epsilon = 0.0009765625; // 2**-10
7070pub const f16_toint = 1.0 / f16_epsilon;
7171
72pub const nan_u16 = u16(0x7C01);
72pub const nan_u16 = @as(u16, 0x7C01);
7373pub const nan_f16 = @bitCast(f16, nan_u16);
7474
75pub const inf_u16 = u16(0x7C00);
75pub const inf_u16 = @as(u16, 0x7C00);
7676pub const inf_f16 = @bitCast(f16, inf_u16);
7777
78pub const nan_u32 = u32(0x7F800001);
78pub const nan_u32 = @as(u32, 0x7F800001);
7979pub const nan_f32 = @bitCast(f32, nan_u32);
8080
81pub const inf_u32 = u32(0x7F800000);
81pub const inf_u32 = @as(u32, 0x7F800000);
8282pub 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;
8585pub const nan_f64 = @bitCast(f64, nan_u64);
8686
87pub const inf_u64 = u64(0x7FF << 52);
87pub const inf_u64 = @as(u64, 0x7FF << 52);
8888pub const inf_f64 = @bitCast(f64, inf_u64);
8989
90pub const nan_u128 = u128(0x7fff0000000000000000000000000001);
90pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
9191pub const nan_f128 = @bitCast(f128, nan_u128);
9292
93pub const inf_u128 = u128(0x7fff0000000000000000000000000000);
93pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000);
9494pub const inf_f128 = @bitCast(f128, inf_u128);
9595
9696pub const nan = @import("math/nan.zig").nan;
......@@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type {
248248 },
249249 else => {},
250250 }
251 return @typeOf(A(0) + B(0));
251 return @typeOf(@as(A, 0) + @as(B, 0));
252252}
253253
254254/// 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)) {
273273}
274274
275275test "math.min" {
276 testing.expect(min(i32(-1), i32(2)) == -1);
276 testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
277277 {
278278 var a: u16 = 999;
279279 var b: u32 = 10;
......@@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
309309}
310310
311311test "math.max" {
312 testing.expect(max(i32(-1), i32(2)) == 2);
312 testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
313313}
314314
315315pub 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 {
352352}
353353
354354test "math.shl" {
355 testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000);
356 testing.expect(shl(u8, 0b11111111, usize(8)) == 0);
357 testing.expect(shl(u8, 0b11111111, usize(9)) == 0);
358 testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111);
355 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
356 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
357 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
358 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
359359 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
360360 testing.expect(shl(u8, 0b11111111, 8) == 0);
361361 testing.expect(shl(u8, 0b11111111, 9) == 0);
......@@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
380380}
381381
382382test "math.shr" {
383 testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111);
384 testing.expect(shr(u8, 0b11111111, usize(8)) == 0);
385 testing.expect(shr(u8, 0b11111111, usize(9)) == 0);
386 testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100);
383 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
384 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
385 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
386 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
387387 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
388388 testing.expect(shr(u8, 0b11111111, 8) == 0);
389389 testing.expect(shr(u8, 0b11111111, 9) == 0);
......@@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
402402}
403403
404404test "math.rotr" {
405 testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001);
406 testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000);
407 testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001);
408 testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000);
409 testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);
405 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
406 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
407 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
408 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
409 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
410410}
411411
412412/// Rotates left. Only unsigned values can be rotated.
......@@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
421421}
422422
423423test "math.rotl" {
424 testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001);
425 testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010);
426 testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001);
427 testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000);
428 testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);
424 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
425 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
426 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
427 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
428 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
429429}
430430
431431pub fn Log2Int(comptime T: type) type {
......@@ -532,8 +532,8 @@ test "math.absInt" {
532532 comptime testAbsInt();
533533}
534534fn testAbsInt() void {
535 testing.expect((absInt(i32(-10)) catch unreachable) == 10);
536 testing.expect((absInt(i32(10)) catch unreachable) == 10);
535 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
536 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
537537}
538538
539539pub const absFloat = fabs;
......@@ -679,14 +679,14 @@ pub fn absCast(x: var) t: {
679679}
680680
681681test "math.absCast" {
682 testing.expect(absCast(i32(-999)) == 999);
683 testing.expect(@typeOf(absCast(i32(-999))) == u32);
682 testing.expect(absCast(@as(i32, -999)) == 999);
683 testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);
684684
685 testing.expect(absCast(i32(999)) == 999);
686 testing.expect(@typeOf(absCast(i32(999))) == u32);
685 testing.expect(absCast(@as(i32, 999)) == 999);
686 testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);
687687
688 testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));
689 testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);
688 testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
689 testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);
690690
691691 testing.expect(absCast(-999) == 999);
692692}
......@@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
705705}
706706
707707test "math.negateCast" {
708 testing.expect((negateCast(u32(999)) catch unreachable) == -999);
709 testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
708 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
709 testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
710710
711 testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
712 testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
711 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(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)));
715715}
716716
717717/// 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) {
729729}
730730
731731test "math.cast" {
732 testing.expectError(error.Overflow, cast(u8, u32(300)));
733 testing.expectError(error.Overflow, cast(i8, i32(-200)));
732 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
733 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
734734 testing.expectError(error.Overflow, cast(u8, i8(-1)));
735735 testing.expectError(error.Overflow, cast(u64, i8(-1)));
736736
737 testing.expect((try cast(u8, u32(255))) == u8(255));
738 testing.expect(@typeOf(try cast(u8, u32(255))) == u8);
737 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
738 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
739739}
740740
741741pub const AlignCastError = error{UnalignedMemory};
......@@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" {
812812}
813813
814814fn testCeilPowerOfTwoPromote() void {
815 testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1));
816 testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2));
817 testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63));
818 testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64));
819 testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65));
820 testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7));
821 testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8));
822 testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9));
823 testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9));
815 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
816 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
817 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
818 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
819 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
820 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
821 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
822 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
823 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
824824}
825825
826826test "math.ceilPowerOfTwo" {
......@@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" {
829829}
830830
831831fn testCeilPowerOfTwo() !void {
832 testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1));
833 testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2));
834 testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63));
835 testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64));
836 testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65));
837 testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7));
838 testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8));
839 testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9));
832 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
833 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
834 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
835 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
836 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
837 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
838 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
839 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
840840 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
841841}
842842
......@@ -944,7 +944,7 @@ test "max value type" {
944944
945945pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
946946 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
947 return ResultInt(a) * ResultInt(b);
947 return @as(ResultInt, a) * @as(ResultInt, b);
948948}
949949
950950test "math.mulWide" {
lib/std/math/acos.zig+2-2
......@@ -149,8 +149,8 @@ fn acos64(x: f64) f64 {
149149}
150150
151151test "math.acos" {
152 expect(acos(f32(0.0)) == acos32(0.0));
153 expect(acos(f64(0.0)) == acos64(0.0));
152 expect(acos(@as(f32, 0.0)) == acos32(0.0));
153 expect(acos(@as(f64, 0.0)) == acos64(0.0));
154154}
155155
156156test "math.acos32" {
lib/std/math/acosh.zig+2-2
......@@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 {
6161}
6262
6363test "math.acosh" {
64 expect(acosh(f32(1.5)) == acosh32(1.5));
65 expect(acosh(f64(1.5)) == acosh64(1.5));
64 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
65 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
6666}
6767
6868test "math.acosh32" {
lib/std/math/asin.zig+2-2
......@@ -142,8 +142,8 @@ fn asin64(x: f64) f64 {
142142}
143143
144144test "math.asin" {
145 expect(asin(f32(0.0)) == asin32(0.0));
146 expect(asin(f64(0.0)) == asin64(0.0));
145 expect(asin(@as(f32, 0.0)) == asin32(0.0));
146 expect(asin(@as(f64, 0.0)) == asin64(0.0));
147147}
148148
149149test "math.asin32" {
lib/std/math/asinh.zig+2-2
......@@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 {
8989}
9090
9191test "math.asinh" {
92 expect(asinh(f32(0.0)) == asinh32(0.0));
93 expect(asinh(f64(0.0)) == asinh64(0.0));
92 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
93 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
9494}
9595
9696test "math.asinh32" {
lib/std/math/atan.zig+2-2
......@@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 {
212212}
213213
214214test "math.atan" {
215 expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));
216 expect(atan(f64(0.2)) == atan64(0.2));
215 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
216 expect(atan(@as(f64, 0.2)) == atan64(0.2));
217217}
218218
219219test "math.atan32" {
lib/std/math/atanh.zig+2-2
......@@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 {
8484}
8585
8686test "math.atanh" {
87 expect(atanh(f32(0.0)) == atanh_32(0.0));
88 expect(atanh(f64(0.0)) == atanh_64(0.0));
87 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
88 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
8989}
9090
9191test "math.atanh_32" {
lib/std/math/big/int.zig+1-1
......@@ -261,7 +261,7 @@ pub const Int = struct {
261261 /// the minus sign. This is used for determining the number of characters needed to print the
262262 /// value. It is inexact and may exceed the given value by ~1-2 bytes.
263263 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();
265265 return (bit_count / math.log2(base)) + 1;
266266 }
267267
lib/std/math/cbrt.zig+5-5
......@@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 {
5454 // first step newton to 16 bits
5555 var t: f64 = @bitCast(f32, u);
5656 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
5959 // second step newton to 47 bits
6060 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
6363 return @floatCast(f32, t);
6464}
......@@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 {
9797 }
9898
9999 u &= 1 << 63;
100 u |= u64(hx) << 32;
100 u |= @as(u64, hx) << 32;
101101 var t = @bitCast(f64, u);
102102
103103 // cbrt to 23 bits
......@@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 {
120120}
121121
122122test "math.cbrt" {
123 expect(cbrt(f32(0.0)) == cbrt32(0.0));
124 expect(cbrt(f64(0.0)) == cbrt64(0.0));
123 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
124 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
125125}
126126
127127test "math.cbrt32" {
lib/std/math/ceil.zig+3-3
......@@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 {
3737 if (e >= 23) {
3838 return x;
3939 } else if (e >= 0) {
40 m = u32(0x007FFFFF) >> @intCast(u5, e);
40 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
4141 if (u & m == 0) {
4242 return x;
4343 }
......@@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 {
8787}
8888
8989test "math.ceil" {
90 expect(ceil(f32(0.0)) == ceil32(0.0));
91 expect(ceil(f64(0.0)) == ceil64(0.0));
90 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
91 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
9292}
9393
9494test "math.ceil32" {
lib/std/math/complex/ldexp.zig+1-1
......@@ -59,7 +59,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
5959 expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
6060
6161 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);
6363}
6464
6565fn 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) {
5252 // y = nan special case is handled fine below
5353
5454 // double-precision avoids overflow with correct rounding.
55 const dx = f64(x);
56 const dy = f64(y);
55 const dx = @as(f64, x);
56 const dy = @as(f64, y);
5757
5858 if (dx >= 0) {
5959 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) {
7676 return Complex(f64).new(x, r);
7777 }
7878
79 const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx);
79 const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);
8080 const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y);
8181 return Complex(f64).new(xx, math.copysign(f64, 0, r));
8282 }
lib/std/math/copysign.zig+3-3
......@@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 {
2424 const uy = @bitCast(u16, y);
2525
2626 const h1 = ux & (maxInt(u16) / 2);
27 const h2 = uy & (u16(1) << 15);
27 const h2 = uy & (@as(u16, 1) << 15);
2828 return @bitCast(f16, h1 | h2);
2929}
3030
......@@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 {
3333 const uy = @bitCast(u32, y);
3434
3535 const h1 = ux & (maxInt(u32) / 2);
36 const h2 = uy & (u32(1) << 31);
36 const h2 = uy & (@as(u32, 1) << 31);
3737 return @bitCast(f32, h1 | h2);
3838}
3939
......@@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 {
4242 const uy = @bitCast(u64, y);
4343
4444 const h1 = ux & (maxInt(u64) / 2);
45 const h2 = uy & (u64(1) << 63);
45 const h2 = uy & (@as(u64, 1) << 63);
4646 return @bitCast(f64, h1 | h2);
4747}
4848
lib/std/math/cos.zig+2-2
......@@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T {
8383}
8484
8585test "math.cos" {
86 expect(cos(f32(0.0)) == cos_(f32, 0.0));
87 expect(cos(f64(0.0)) == cos_(f64, 0.0));
86 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
87 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
8888}
8989
9090test "math.cos32" {
lib/std/math/cosh.zig+2-2
......@@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 {
8888}
8989
9090test "math.cosh" {
91 expect(cosh(f32(1.5)) == cosh32(1.5));
92 expect(cosh(f64(1.5)) == cosh64(1.5));
91 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
92 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
9393}
9494
9595test "math.cosh32" {
lib/std/math/exp.zig+2-2
......@@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 {
183183}
184184
185185test "math.exp" {
186 assert(exp(f32(0.0)) == exp32(0.0));
187 assert(exp(f64(0.0)) == exp64(0.0));
186 assert(exp(@as(f32, 0.0)) == exp32(0.0));
187 assert(exp(@as(f64, 0.0)) == exp64(0.0));
188188}
189189
190190test "math.exp32" {
lib/std/math/exp2.zig+3-3
......@@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 {
8585 const k = i_0 / tblsiz;
8686 // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the
8787 // 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);
8989 i_0 &= tblsiz - 1;
9090 uf -= redux;
9191
......@@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 {
421421}
422422
423423test "math.exp2" {
424 expect(exp2(f32(0.8923)) == exp2_32(0.8923));
425 expect(exp2(f64(0.8923)) == exp2_64(0.8923));
424 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
425 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
426426}
427427
428428test "math.exp2_32" {
lib/std/math/expm1.zig+2-2
......@@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 {
287287}
288288
289289test "math.exp1m" {
290 expect(expm1(f32(0.0)) == expm1_32(0.0));
291 expect(expm1(f64(0.0)) == expm1_64(0.0));
290 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
291 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
292292}
293293
294294test "math.expm1_32" {
lib/std/math/expo2.zig+1-1
......@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {
3030 const kln2 = 0x1.62066151ADD8BP+10;
3131
3232 const u = (0x3FF + k / 2) << 20;
33 const scale = @bitCast(f64, u64(u) << 32);
33 const scale = @bitCast(f64, @as(u64, u) << 32);
3434 return math.exp(x - kln2) * scale * scale;
3535}
lib/std/math/fabs.zig+4-4
......@@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 {
5050}
5151
5252test "math.fabs" {
53 expect(fabs(f16(1.0)) == fabs16(1.0));
54 expect(fabs(f32(1.0)) == fabs32(1.0));
55 expect(fabs(f64(1.0)) == fabs64(1.0));
56 expect(fabs(f128(1.0)) == fabs128(1.0));
53 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
54 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
55 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
56 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
5757}
5858
5959test "math.fabs16" {
lib/std/math/floor.zig+5-5
......@@ -40,7 +40,7 @@ fn floor16(x: f16) f16 {
4040 }
4141
4242 if (e >= 0) {
43 m = u16(1023) >> @intCast(u4, e);
43 m = @as(u16, 1023) >> @intCast(u4, e);
4444 if (u & m == 0) {
4545 return x;
4646 }
......@@ -74,7 +74,7 @@ fn floor32(x: f32) f32 {
7474 }
7575
7676 if (e >= 0) {
77 m = u32(0x007FFFFF) >> @intCast(u5, e);
77 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
7878 if (u & m == 0) {
7979 return x;
8080 }
......@@ -123,9 +123,9 @@ fn floor64(x: f64) f64 {
123123}
124124
125125test "math.floor" {
126 expect(floor(f16(1.3)) == floor16(1.3));
127 expect(floor(f32(1.3)) == floor32(1.3));
128 expect(floor(f64(1.3)) == floor64(1.3));
126 expect(floor(@as(f16, 1.3)) == floor16(1.3));
127 expect(floor(@as(f32, 1.3)) == floor32(1.3));
128 expect(floor(@as(f64, 1.3)) == floor64(1.3));
129129}
130130
131131test "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 {
1818}
1919
2020fn fma32(x: f32, y: f32, z: f32) f32 {
21 const xy = f64(x) * y;
21 const xy = @as(f64, x) * y;
2222 const xy_z = xy + z;
2323 const u = @bitCast(u64, xy_z);
2424 const e = (u >> 52) & 0x7FF;
lib/std/math/frexp.zig+2-2
......@@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result {
108108}
109109
110110test "math.frexp" {
111 const a = frexp(f32(1.3));
111 const a = frexp(@as(f32, 1.3));
112112 const b = frexp32(1.3);
113113 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));
116116 const d = frexp64(1.3);
117117 expect(c.significand == d.significand and c.exponent == d.exponent);
118118}
lib/std/math/hypot.zig+1-1
......@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {
5656 yy *= 0x1.0p-90;
5757 }
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));
6060}
6161
6262fn 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 {
2626}
2727
2828// NOTE: Should these be exposed publicly?
29const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1);
29const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1);
3030const fp_ilogb0 = fp_ilogbnan;
3131
3232fn ilogb32(x: f32) i32 {
......@@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 {
101101}
102102
103103test "math.ilogb" {
104 expect(ilogb(f32(0.2)) == ilogb32(0.2));
105 expect(ilogb(f64(0.2)) == ilogb64(0.2));
104 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
105 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
106106}
107107
108108test "math.ilogb32" {
lib/std/math/isfinite.zig+6-6
......@@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool {
2626}
2727
2828test "math.isFinite" {
29 expect(isFinite(f16(0.0)));
30 expect(isFinite(f16(-0.0)));
31 expect(isFinite(f32(0.0)));
32 expect(isFinite(f32(-0.0)));
33 expect(isFinite(f64(0.0)));
34 expect(isFinite(f64(-0.0)));
29 expect(isFinite(@as(f16, 0.0)));
30 expect(isFinite(@as(f16, -0.0)));
31 expect(isFinite(@as(f32, 0.0)));
32 expect(isFinite(@as(f32, -0.0)));
33 expect(isFinite(@as(f64, 0.0)));
34 expect(isFinite(@as(f64, -0.0)));
3535 expect(!isFinite(math.inf(f16)));
3636 expect(!isFinite(-math.inf(f16)));
3737 expect(!isFinite(math.inf(f32)));
lib/std/math/isinf.zig+24-24
......@@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool {
7474}
7575
7676test "math.isInf" {
77 expect(!isInf(f16(0.0)));
78 expect(!isInf(f16(-0.0)));
79 expect(!isInf(f32(0.0)));
80 expect(!isInf(f32(-0.0)));
81 expect(!isInf(f64(0.0)));
82 expect(!isInf(f64(-0.0)));
83 expect(!isInf(f128(0.0)));
84 expect(!isInf(f128(-0.0)));
77 expect(!isInf(@as(f16, 0.0)));
78 expect(!isInf(@as(f16, -0.0)));
79 expect(!isInf(@as(f32, 0.0)));
80 expect(!isInf(@as(f32, -0.0)));
81 expect(!isInf(@as(f64, 0.0)));
82 expect(!isInf(@as(f64, -0.0)));
83 expect(!isInf(@as(f128, 0.0)));
84 expect(!isInf(@as(f128, -0.0)));
8585 expect(isInf(math.inf(f16)));
8686 expect(isInf(-math.inf(f16)));
8787 expect(isInf(math.inf(f32)));
......@@ -93,14 +93,14 @@ test "math.isInf" {
9393}
9494
9595test "math.isPositiveInf" {
96 expect(!isPositiveInf(f16(0.0)));
97 expect(!isPositiveInf(f16(-0.0)));
98 expect(!isPositiveInf(f32(0.0)));
99 expect(!isPositiveInf(f32(-0.0)));
100 expect(!isPositiveInf(f64(0.0)));
101 expect(!isPositiveInf(f64(-0.0)));
102 expect(!isPositiveInf(f128(0.0)));
103 expect(!isPositiveInf(f128(-0.0)));
96 expect(!isPositiveInf(@as(f16, 0.0)));
97 expect(!isPositiveInf(@as(f16, -0.0)));
98 expect(!isPositiveInf(@as(f32, 0.0)));
99 expect(!isPositiveInf(@as(f32, -0.0)));
100 expect(!isPositiveInf(@as(f64, 0.0)));
101 expect(!isPositiveInf(@as(f64, -0.0)));
102 expect(!isPositiveInf(@as(f128, 0.0)));
103 expect(!isPositiveInf(@as(f128, -0.0)));
104104 expect(isPositiveInf(math.inf(f16)));
105105 expect(!isPositiveInf(-math.inf(f16)));
106106 expect(isPositiveInf(math.inf(f32)));
......@@ -112,14 +112,14 @@ test "math.isPositiveInf" {
112112}
113113
114114test "math.isNegativeInf" {
115 expect(!isNegativeInf(f16(0.0)));
116 expect(!isNegativeInf(f16(-0.0)));
117 expect(!isNegativeInf(f32(0.0)));
118 expect(!isNegativeInf(f32(-0.0)));
119 expect(!isNegativeInf(f64(0.0)));
120 expect(!isNegativeInf(f64(-0.0)));
121 expect(!isNegativeInf(f128(0.0)));
122 expect(!isNegativeInf(f128(-0.0)));
115 expect(!isNegativeInf(@as(f16, 0.0)));
116 expect(!isNegativeInf(@as(f16, -0.0)));
117 expect(!isNegativeInf(@as(f32, 0.0)));
118 expect(!isNegativeInf(@as(f32, -0.0)));
119 expect(!isNegativeInf(@as(f64, 0.0)));
120 expect(!isNegativeInf(@as(f64, -0.0)));
121 expect(!isNegativeInf(@as(f128, 0.0)));
122 expect(!isNegativeInf(@as(f128, -0.0)));
123123 expect(!isNegativeInf(math.inf(f16)));
124124 expect(isNegativeInf(-math.inf(f16)));
125125 expect(!isNegativeInf(math.inf(f32)));
lib/std/math/isnan.zig+4-4
......@@ -20,8 +20,8 @@ test "math.isNan" {
2020 expect(isNan(math.nan(f32)));
2121 expect(isNan(math.nan(f64)));
2222 expect(isNan(math.nan(f128)));
23 expect(!isNan(f16(1.0)));
24 expect(!isNan(f32(1.0)));
25 expect(!isNan(f64(1.0)));
26 expect(!isNan(f128(1.0)));
23 expect(!isNan(@as(f16, 1.0)));
24 expect(!isNan(@as(f32, 1.0)));
25 expect(!isNan(@as(f64, 1.0)));
26 expect(!isNan(@as(f128, 1.0)));
2727}
lib/std/math/isnormal.zig+6-6
......@@ -29,10 +29,10 @@ test "math.isNormal" {
2929 expect(!isNormal(math.nan(f16)));
3030 expect(!isNormal(math.nan(f32)));
3131 expect(!isNormal(math.nan(f64)));
32 expect(!isNormal(f16(0)));
33 expect(!isNormal(f32(0)));
34 expect(!isNormal(f64(0)));
35 expect(isNormal(f16(1.0)));
36 expect(isNormal(f32(1.0)));
37 expect(isNormal(f64(1.0)));
32 expect(!isNormal(@as(f16, 0)));
33 expect(!isNormal(@as(f32, 0)));
34 expect(!isNormal(@as(f64, 0)));
35 expect(isNormal(@as(f16, 1.0)));
36 expect(isNormal(@as(f32, 1.0)));
37 expect(isNormal(@as(f64, 1.0)));
3838}
lib/std/math/ln.zig+5-5
......@@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) {
3131 };
3232 },
3333 TypeId.ComptimeInt => {
34 return @typeOf(1)(math.floor(ln_64(f64(x))));
34 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
3535 },
3636 TypeId.Int => {
37 return T(math.floor(ln_64(f64(x))));
37 return T(math.floor(ln_64(@as(f64, x))));
3838 },
3939 else => @compileError("ln not implemented for " ++ @typeName(T)),
4040 }
......@@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 {
132132 hx += 0x3FF00000 - 0x3FE6A09E;
133133 k += @intCast(i32, hx >> 20) - 0x3FF;
134134 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
135 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
135 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
136136 x = @bitCast(f64, ix);
137137
138138 const f = x - 1.0;
......@@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 {
149149}
150150
151151test "math.ln" {
152 expect(ln(f32(0.2)) == ln_32(0.2));
153 expect(ln(f64(0.2)) == ln_64(0.2));
152 expect(ln(@as(f32, 0.2)) == ln_32(0.2));
153 expect(ln(@as(f64, 0.2)) == ln_64(0.2));
154154}
155155
156156test "math.ln32" {
lib/std/math/log.zig+5-5
......@@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
2323 const float_base = math.lossyCast(f64, base);
2424 switch (@typeId(T)) {
2525 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));
2727 },
2828 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)));
3030 },
3131 builtin.TypeId.Int => {
3232 // TODO implement integer log without using float math
......@@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
3535
3636 builtin.TypeId.Float => {
3737 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)),
3939 f64 => return math.ln(x) / math.ln(float_base),
4040 else => @compileError("log not implemented for " ++ @typeName(T)),
4141 }
......@@ -67,6 +67,6 @@ test "math.log float_special" {
6767 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
6868 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
6969
70 expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));
71 expect(log(f64, 10, 213.23019799993) == math.log10(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(@as(f64, 213.23019799993)));
7272}
lib/std/math/log10.zig+4-4
......@@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
3232 };
3333 },
3434 TypeId.ComptimeInt => {
35 return @typeOf(1)(math.floor(log10_64(f64(x))));
35 return @typeOf(1)(math.floor(log10_64(@as(f64, x))));
3636 },
3737 TypeId.Int => {
3838 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
......@@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 {
143143 hx += 0x3FF00000 - 0x3FE6A09E;
144144 k += @intCast(i32, hx >> 20) - 0x3FF;
145145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
146 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
146 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
147147 x = @bitCast(f64, ix);
148148
149149 const f = x - 1.0;
......@@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 {
158158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
159159 var hi = f - hfsq;
160160 var hii = @bitCast(u64, hi);
161 hii &= u64(maxInt(u64)) << 32;
161 hii &= @as(u64, maxInt(u64)) << 32;
162162 hi = @bitCast(f64, hii);
163163 const lo = f - hi - hfsq + s * (hfsq + R);
164164
......@@ -178,7 +178,7 @@ pub fn log10_64(x_: f64) f64 {
178178
179179test "math.log10" {
180180 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));
182182}
183183
184184test "math.log10_32" {
lib/std/math/log1p.zig+3-3
......@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {
166166
167167 // u into [sqrt(2)/2, sqrt(2)]
168168 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;
169 const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF);
169 const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);
170170 f = @bitCast(f64, iq) - 1;
171171 }
172172
......@@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 {
183183}
184184
185185test "math.log1p" {
186 expect(log1p(f32(0.0)) == log1p_32(0.0));
187 expect(log1p(f64(0.0)) == log1p_64(0.0));
186 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
187 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
188188}
189189
190190test "math.log1p_32" {
lib/std/math/log2.zig+4-4
......@@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 {
143143 hx += 0x3FF00000 - 0x3FE6A09E;
144144 k += @intCast(i32, hx >> 20) - 0x3FF;
145145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
146 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
146 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
147147 x = @bitCast(f64, ix);
148148
149149 const f = x - 1.0;
......@@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 {
158158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
159159 var hi = f - hfsq;
160160 var hii = @bitCast(u64, hi);
161 hii &= u64(maxInt(u64)) << 32;
161 hii &= @as(u64, maxInt(u64)) << 32;
162162 hi = @bitCast(f64, hii);
163163 const lo = f - hi - hfsq + s * (hfsq + R);
164164
......@@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 {
175175}
176176
177177test "math.log2" {
178 expect(log2(f32(0.2)) == log2_32(0.2));
179 expect(log2(f64(0.2)) == log2_64(0.2));
178 expect(log2(@as(f32, 0.2)) == log2_32(0.2));
179 expect(log2(@as(f64, 0.2)) == log2_64(0.2));
180180}
181181
182182test "math.log2_32" {
lib/std/math/modf.zig+4-4
......@@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result {
6565 return result;
6666 }
6767
68 const mask = u32(0x007FFFFF) >> @intCast(u5, e);
68 const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
6969 if (u & mask == 0) {
7070 result.ipart = x;
7171 result.fpart = @bitCast(f32, us);
......@@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result {
109109 return result;
110110 }
111111
112 const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e);
112 const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e);
113113 if (u & mask == 0) {
114114 result.ipart = x;
115115 result.fpart = @bitCast(f64, us);
......@@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result {
123123}
124124
125125test "math.modf" {
126 const a = modf(f32(1.0));
126 const a = modf(@as(f32, 1.0));
127127 const b = modf32(1.0);
128128 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
129129 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));
132132 const d = modf64(1.0);
133133 expect(a.ipart == b.ipart and a.fpart == b.fpart);
134134}
lib/std/math/round.zig+2-2
......@@ -91,8 +91,8 @@ fn round64(x_: f64) f64 {
9191}
9292
9393test "math.round" {
94 expect(round(f32(1.3)) == round32(1.3));
95 expect(round(f64(1.3)) == round64(1.3));
94 expect(round(@as(f32, 1.3)) == round32(1.3));
95 expect(round(@as(f64, 1.3)) == round64(1.3));
9696}
9797
9898test "math.round32" {
lib/std/math/scalbn.zig+2-2
......@@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 {
7979}
8080
8181test "math.scalbn" {
82 expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));
83 expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));
82 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
83 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
8484}
8585
8686test "math.scalbn32" {
lib/std/math/signbit.zig+3-3
......@@ -29,9 +29,9 @@ fn signbit64(x: f64) bool {
2929}
3030
3131test "math.signbit" {
32 expect(signbit(f16(4.0)) == signbit16(4.0));
33 expect(signbit(f32(4.0)) == signbit32(4.0));
34 expect(signbit(f64(4.0)) == signbit64(4.0));
32 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
33 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
34 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
3535}
3636
3737test "math.signbit16" {
lib/std/math/sin.zig+3-3
......@@ -88,9 +88,9 @@ test "math.sin" {
8888 // TODO https://github.com/ziglang/zig/issues/3289
8989 return error.SkipZigTest;
9090 }
91 expect(sin(f32(0.0)) == sin_(f32, 0.0));
92 expect(sin(f64(0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(f64(2))) == math.sin(f64(2)));
91 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
92 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
9494}
9595
9696test "math.sin32" {
lib/std/math/sinh.zig+2-2
......@@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 {
9393}
9494
9595test "math.sinh" {
96 expect(sinh(f32(1.5)) == sinh32(1.5));
97 expect(sinh(f64(1.5)) == sinh64(1.5));
96 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
97 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
9898}
9999
100100test "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
3232}
3333
3434test "math.sqrt" {
35 expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
36 expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
37 expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
35 expect(sqrt(@as(f16, 0.0)) == @sqrt(f16, 0.0));
36 expect(sqrt(@as(f32, 0.0)) == @sqrt(f32, 0.0));
37 expect(sqrt(@as(f64, 0.0)) == @sqrt(f64, 0.0));
3838}
3939
4040test "math.sqrt16" {
lib/std/math/tan.zig+2-2
......@@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T {
7575}
7676
7777test "math.tan" {
78 expect(tan(f32(0.0)) == tan_(f32, 0.0));
79 expect(tan(f64(0.0)) == tan_(f64, 0.0));
78 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
79 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
8080}
8181
8282test "math.tan32" {
lib/std/math/tanh.zig+2-2
......@@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 {
119119}
120120
121121test "math.tanh" {
122 expect(tanh(f32(1.5)) == tanh32(1.5));
123 expect(tanh(f64(1.5)) == tanh64(1.5));
122 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
123 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
124124}
125125
126126test "math.tanh32" {
lib/std/math/trunc.zig+4-4
......@@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 {
3636 e = 1;
3737 }
3838
39 m = u32(maxInt(u32)) >> @intCast(u5, e);
39 m = @as(u32, maxInt(u32)) >> @intCast(u5, e);
4040 if (u & m == 0) {
4141 return x;
4242 } else {
......@@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 {
5757 e = 1;
5858 }
5959
60 m = u64(maxInt(u64)) >> @intCast(u6, e);
60 m = @as(u64, maxInt(u64)) >> @intCast(u6, e);
6161 if (u & m == 0) {
6262 return x;
6363 } else {
......@@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 {
6767}
6868
6969test "math.trunc" {
70 expect(trunc(f32(1.3)) == trunc32(1.3));
71 expect(trunc(f64(1.3)) == trunc64(1.3));
70 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
71 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
7272}
7373
7474test "math.trunc32" {
lib/std/mem.zig+10-10
......@@ -118,7 +118,7 @@ pub const Allocator = struct {
118118 } else @alignOf(T);
119119
120120 if (n == 0) {
121 return ([*]align(a) T)(undefined)[0..0];
121 return @as([*]align(a) T, undefined)[0..0];
122122 }
123123
124124 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
......@@ -170,7 +170,7 @@ pub const Allocator = struct {
170170 }
171171 if (new_n == 0) {
172172 self.free(old_mem);
173 return ([*]align(new_alignment) T)(undefined)[0..0];
173 return @as([*]align(new_alignment) T, undefined)[0..0];
174174 }
175175
176176 const old_byte_slice = @sliceToBytes(old_mem);
......@@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.
523523 builtin.Endian.Little => {
524524 const ShiftType = math.Log2Int(ReturnType);
525525 for (bytes) |b, index| {
526 result = result | (ReturnType(b) << @intCast(ShiftType, index * 8));
526 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));
527527 }
528528 },
529529 }
......@@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type {
13321332 if (comptime !trait.isSingleItemPtr(P))
13331333 @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)));
13361336 const alignment = comptime meta.alignment(P);
13371337
13381338 if (alignment == 0) {
......@@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {
13531353}
13541354
13551355test "asBytes" {
1356 const deadbeef = u32(0xDEADBEEF);
1356 const deadbeef = @as(u32, 0xDEADBEEF);
13571357 const deadbeef_bytes = switch (builtin.endian) {
13581358 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
13591359 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
......@@ -1361,7 +1361,7 @@ test "asBytes" {
13611361
13621362 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
13631363
1364 var codeface = u32(0xC0DEFACE);
1364 var codeface = @as(u32, 0xC0DEFACE);
13651365 for (asBytes(&codeface).*) |*b|
13661366 b.* = 0;
13671367 testing.expect(codeface == 0);
......@@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
13921392}
13931393
13941394test "toBytes" {
1395 var my_bytes = toBytes(u32(0x12345678));
1395 var my_bytes = toBytes(@as(u32, 0x12345678));
13961396 switch (builtin.endian) {
13971397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
13981398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
......@@ -1406,7 +1406,7 @@ test "toBytes" {
14061406}
14071407
14081408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
1409 const size = usize(@sizeOf(T));
1409 const size = @as(usize, @sizeOf(T));
14101410
14111411 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) {
14121412 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
......@@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ
14241424}
14251425
14261426test "bytesAsValue" {
1427 const deadbeef = u32(0xDEADBEEF);
1427 const deadbeef = @as(u32, 0xDEADBEEF);
14281428 const deadbeef_bytes = switch (builtin.endian) {
14291429 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
14301430 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
......@@ -1472,7 +1472,7 @@ test "bytesToValue" {
14721472 };
14731473
14741474 const deadbeef = bytesToValue(u32, deadbeef_bytes);
1475 testing.expect(deadbeef == u32(0xDEADBEEF));
1475 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
14761476}
14771477
14781478fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
lib/std/meta.zig+1-1
......@@ -505,7 +505,7 @@ test "std.meta.eql" {
505505 const EU = struct {
506506 fn tst(err: bool) !u8 {
507507 if (err) return error.Error;
508 return u8(5);
508 return @as(u8, 5);
509509 }
510510 };
511511
lib/std/meta/trait.zig+2-2
......@@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool {
327327}
328328
329329test "std.meta.trait.isConstPtr" {
330 var t = u8(0);
331 const c = u8(0);
330 var t = @as(u8, 0);
331 const c = @as(u8, 0);
332332 testing.expect(isConstPtr(*const @typeOf(t)));
333333 testing.expect(isConstPtr(@typeOf(&c)));
334334 testing.expect(!isConstPtr(*@typeOf(t)));
lib/std/net.zig+7-7
......@@ -611,7 +611,7 @@ fn linuxLookupName(
611611 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
612612 mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
613613 }
614 if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
614 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
615615 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
616616 prefixlen = prefixMatch(sa6.addr, da6.addr);
617617 } else |_| {}
......@@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
710710 // address. However the definition of the source prefix length is
711711 // not clear and thus this limiting is not yet implemented.
712712 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) {}
714714 return i;
715715}
716716
......@@ -1194,23 +1194,23 @@ fn dnsParse(
11941194 if (r.len < 12) return error.InvalidDnsPacket;
11951195 if ((r[3] & 15) != 0) return;
11961196 var p = r.ptr + 12;
1197 var qdcount = r[4] * usize(256) + r[5];
1198 var ancount = r[6] * usize(256) + r[7];
1197 var qdcount = r[4] * @as(usize, 256) + r[5];
1198 var ancount = r[6] * @as(usize, 256) + r[7];
11991199 if (qdcount + ancount > 64) return error.InvalidDnsPacket;
12001200 while (qdcount != 0) {
12011201 qdcount -= 1;
12021202 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
12031203 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
12041204 return error.InvalidDnsPacket;
1205 p += usize(5) + @boolToInt(p[0] != 0);
1205 p += @as(usize, 5) + @boolToInt(p[0] != 0);
12061206 }
12071207 while (ancount != 0) {
12081208 ancount -= 1;
12091209 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
12101210 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
12111211 return error.InvalidDnsPacket;
1212 p += usize(1) + @boolToInt(p[0] != 0);
1213 const len = p[8] * usize(256) + p[9];
1212 p += @as(usize, 1) + @boolToInt(p[0] != 0);
1213 const len = p[8] * @as(usize, 256) + p[9];
12141214 if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket;
12151215 try callback(ctx, p[1], p[10 .. 10 + len], r);
12161216 p += 10 + len;
lib/std/os.zig+5-5
......@@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
472472
473473 var index: usize = 0;
474474 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));
476476 const rc = system.write(fd, bytes.ptr + index, amt_to_write);
477477 switch (errno(rc)) {
478478 0 => {
......@@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool {
15261526 }
15271527 if (builtin.os == .linux) {
15281528 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;
15301530 }
15311531 unreachable;
15321532}
......@@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
15471547 }
15481548
15491549 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)];
15511551 const name_wide = @bytesToSlice(u16, name_bytes);
15521552 return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
15531553 mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
......@@ -2897,7 +2897,7 @@ pub fn res_mkquery(
28972897 // Construct query template - ID will be filled later
28982898 var q: [280]u8 = undefined;
28992899 @memset(&q, 0, n);
2900 q[2] = u8(op) * 8 + 1;
2900 q[2] = @as(u8, op) * 8 + 1;
29012901 q[5] = 1;
29022902 mem.copy(u8, q[13..], name);
29032903 var i: usize = 13;
......@@ -3143,7 +3143,7 @@ pub fn dn_expand(
31433143 // loop invariants: p<end, dest<dend
31443144 if ((p[0] & 0xc0) != 0) {
31453145 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];
31473147 if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr);
31483148 if (j >= msg.len) return error.InvalidDnsPacket;
31493149 p = msg.ptr + j;
lib/std/os/bits/dragonfly.zig+1-1
......@@ -315,7 +315,7 @@ pub const dirent = extern struct {
315315 d_name: [256]u8,
316316
317317 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);
319319 }
320320};
321321
lib/std/os/bits/linux.zig+5-5
......@@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400;
559559pub const EPOLLERR = 0x008;
560560pub const EPOLLHUP = 0x010;
561561pub const EPOLLRDHUP = 0x2000;
562pub const EPOLLEXCLUSIVE = (u32(1) << 28);
563pub const EPOLLWAKEUP = (u32(1) << 29);
564pub const EPOLLONESHOT = (u32(1) << 30);
565pub const EPOLLET = (u32(1) << 31);
562pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28);
563pub const EPOLLWAKEUP = (@as(u32, 1) << 29);
564pub const EPOLLONESHOT = (@as(u32, 1) << 30);
565pub const EPOLLET = (@as(u32, 1) << 31);
566566
567567pub const CLOCK_REALTIME = 0;
568568pub const CLOCK_MONOTONIC = 1;
......@@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool {
950950}
951951
952952pub fn CAP_TO_MASK(cap: u8) u32 {
953 return u32(1) << u5(cap & 31);
953 return @as(u32, 1) << u5(cap & 31);
954954}
955955
956956pub fn CAP_TO_INDEX(cap: u8) u8 {
lib/std/os/linux.zig+94-94
......@@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 {
4646
4747pub fn dup2(old: i32, new: i32) usize {
4848 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)));
5050 } else {
5151 if (old == new) {
5252 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);
5454 if (@bitCast(isize, rc) < 0) return rc;
5555 }
5656 return @intCast(usize, old);
5757 } 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);
5959 }
6060 }
6161}
6262
6363pub 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);
6565}
6666
6767// TODO https://github.com/ziglang/zig/issues/265
......@@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
102102
103103// TODO https://github.com/ziglang/zig/issues/265
104104pub 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);
106106}
107107
108108pub 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 {
120120pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
121121 return syscall3(
122122 SYS_getdents,
123 @bitCast(usize, isize(fd)),
123 @bitCast(usize, @as(isize, fd)),
124124 @ptrToInt(dirp),
125125 std.math.min(len, maxInt(c_int)),
126126 );
......@@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
129129pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
130130 return syscall3(
131131 SYS_getdents64,
132 @bitCast(usize, isize(fd)),
132 @bitCast(usize, @as(isize, fd)),
133133 @ptrToInt(dirp),
134134 std.math.min(len, maxInt(c_int)),
135135 );
......@@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize {
140140}
141141
142142pub 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);
144144}
145145
146146pub 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)));
148148}
149149
150150// 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
152152 if (@hasDecl(@This(), "SYS_readlink")) {
153153 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
154154 } 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);
156156 }
157157}
158158
159159// TODO https://github.com/ziglang/zig/issues/265
160160pub 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);
162162}
163163
164164// TODO https://github.com/ziglang/zig/issues/265
......@@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
166166 if (@hasDecl(@This(), "SYS_mkdir")) {
167167 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
168168 } 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);
170170 }
171171}
172172
173173// TODO https://github.com/ziglang/zig/issues/265
174174pub 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);
176176}
177177
178178// 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
194194 if (@hasDecl(@This(), "SYS_mmap2")) {
195195 // Make sure the offset is also specified in multiples of page size
196196 if ((offset & (MMAP2_UNIT - 1)) != 0)
197 return @bitCast(usize, isize(-EINVAL));
197 return @bitCast(usize, @as(isize, -EINVAL));
198198
199199 return syscall6(
200200 SYS_mmap2,
......@@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
202202 length,
203203 prot,
204204 flags,
205 @bitCast(usize, isize(fd)),
205 @bitCast(usize, @as(isize, fd)),
206206 @truncate(usize, offset / MMAP2_UNIT),
207207 );
208208 } else {
......@@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
212212 length,
213213 prot,
214214 flags,
215 @bitCast(usize, isize(fd)),
215 @bitCast(usize, @as(isize, fd)),
216216 offset,
217217 );
218218 }
......@@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
249249}
250250
251251pub 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);
253253}
254254
255255pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
256256 return syscall5(
257257 SYS_preadv,
258 @bitCast(usize, isize(fd)),
258 @bitCast(usize, @as(isize, fd)),
259259 @ptrToInt(iov),
260260 count,
261261 @truncate(usize, offset),
......@@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
266266pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
267267 return syscall6(
268268 SYS_preadv2,
269 @bitCast(usize, isize(fd)),
269 @bitCast(usize, @as(isize, fd)),
270270 @ptrToInt(iov),
271271 count,
272272 @truncate(usize, offset),
......@@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k
276276}
277277
278278pub 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);
280280}
281281
282282pub 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);
284284}
285285
286286pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
287287 return syscall5(
288288 SYS_pwritev,
289 @bitCast(usize, isize(fd)),
289 @bitCast(usize, @as(isize, fd)),
290290 @ptrToInt(iov),
291291 count,
292292 @truncate(usize, offset),
......@@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us
297297pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
298298 return syscall6(
299299 SYS_pwritev2,
300 @bitCast(usize, isize(fd)),
300 @bitCast(usize, @as(isize, fd)),
301301 @ptrToInt(iov),
302302 count,
303303 @truncate(usize, offset),
......@@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize {
311311 if (@hasDecl(@This(), "SYS_rmdir")) {
312312 return syscall1(SYS_rmdir, @ptrToInt(path));
313313 } 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);
315315 }
316316}
317317
......@@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
320320 if (@hasDecl(@This(), "SYS_symlink")) {
321321 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
322322 } 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));
324324 }
325325}
326326
327327// TODO https://github.com/ziglang/zig/issues/265
328328pub 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));
330330}
331331
332332// TODO https://github.com/ziglang/zig/issues/265
333333pub 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);
335335}
336336
337337// TODO https://github.com/ziglang/zig/issues/265
......@@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize {
339339 if (@hasDecl(@This(), "SYS_access")) {
340340 return syscall2(SYS_access, @ptrToInt(path), mode);
341341 } 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);
343343 }
344344}
345345
346346// TODO https://github.com/ziglang/zig/issues/265
347347pub 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);
349349}
350350
351351pub fn pipe(fd: *[2]i32) usize {
......@@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {
363363}
364364
365365pub 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);
367367}
368368
369369pub 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);
371371}
372372
373373// TODO https://github.com/ziglang/zig/issues/265
......@@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {
375375 if (@hasDecl(@This(), "SYS_rename")) {
376376 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
377377 } 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));
379379 } 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);
381381 }
382382}
383383
......@@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
385385 if (@hasDecl(@This(), "SYS_renameat")) {
386386 return syscall4(
387387 SYS_renameat,
388 @bitCast(usize, isize(oldfd)),
388 @bitCast(usize, @as(isize, oldfd)),
389389 @ptrToInt(old),
390 @bitCast(usize, isize(newfd)),
390 @bitCast(usize, @as(isize, newfd)),
391391 @ptrToInt(new),
392392 );
393393 } else {
394394 return syscall5(
395395 SYS_renameat2,
396 @bitCast(usize, isize(oldfd)),
396 @bitCast(usize, @as(isize, oldfd)),
397397 @ptrToInt(old),
398 @bitCast(usize, isize(newfd)),
398 @bitCast(usize, @as(isize, newfd)),
399399 @ptrToInt(new),
400400 0,
401401 );
......@@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
406406pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize {
407407 return syscall5(
408408 SYS_renameat2,
409 @bitCast(usize, isize(oldfd)),
409 @bitCast(usize, @as(isize, oldfd)),
410410 @ptrToInt(oldpath),
411 @bitCast(usize, isize(newfd)),
411 @bitCast(usize, @as(isize, newfd)),
412412 @ptrToInt(newpath),
413413 flags,
414414 );
......@@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
421421 } else {
422422 return syscall4(
423423 SYS_openat,
424 @bitCast(usize, isize(AT_FDCWD)),
424 @bitCast(usize, @as(isize, AT_FDCWD)),
425425 @ptrToInt(path),
426426 flags,
427427 perm,
......@@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {
437437// TODO https://github.com/ziglang/zig/issues/265
438438pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize {
439439 // 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);
441441}
442442
443443/// See also `clone` (from the arch-specific include)
......@@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
451451}
452452
453453pub fn close(fd: i32) usize {
454 return syscall1(SYS_close, @bitCast(usize, isize(fd)));
454 return syscall1(SYS_close, @bitCast(usize, @as(isize, fd)));
455455}
456456
457457/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
458458pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
459459 return syscall5(
460460 SYS__llseek,
461 @bitCast(usize, isize(fd)),
461 @bitCast(usize, @as(isize, fd)),
462462 @truncate(usize, offset >> 32),
463463 @truncate(usize, offset),
464464 @ptrToInt(result),
......@@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
468468
469469/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
470470pub 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);
472472}
473473
474474pub fn exit(status: i32) noreturn {
475 _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
475 _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status)));
476476 unreachable;
477477}
478478
479479pub 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)));
481481 unreachable;
482482}
483483
......@@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
486486}
487487
488488pub 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)));
490490}
491491
492492// TODO https://github.com/ziglang/zig/issues/265
......@@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize {
494494 if (@hasDecl(@This(), "SYS_unlink")) {
495495 return syscall1(SYS_unlink, @ptrToInt(path));
496496 } 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);
498498 }
499499}
500500
501501// TODO https://github.com/ziglang/zig/issues/265
502502pub 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);
504504}
505505
506506pub 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);
508508}
509509
510510var 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 {
519519 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
520520 const rc = f(clk_id, tp);
521521 switch (rc) {
522 0, @bitCast(usize, isize(-EINVAL)) => return rc,
522 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
523523 else => {},
524524 }
525525 }
526526 }
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));
528528}
529529
530530extern 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 {
537537 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
538538 return f(clk, ts);
539539 }
540 return @bitCast(usize, isize(-ENOSYS));
540 return @bitCast(usize, @as(isize, -ENOSYS));
541541}
542542
543543pub 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));
545545}
546546
547547pub 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));
549549}
550550
551551pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
......@@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize {
594594
595595pub fn getuid() u32 {
596596 if (@hasDecl(@This(), "SYS_getuid32")) {
597 return u32(syscall0(SYS_getuid32));
597 return @as(u32, syscall0(SYS_getuid32));
598598 } else {
599 return u32(syscall0(SYS_getuid));
599 return @as(u32, syscall0(SYS_getuid));
600600 }
601601}
602602
603603pub fn getgid() u32 {
604604 if (@hasDecl(@This(), "SYS_getgid32")) {
605 return u32(syscall0(SYS_getgid32));
605 return @as(u32, syscall0(SYS_getgid32));
606606 } else {
607 return u32(syscall0(SYS_getgid));
607 return @as(u32, syscall0(SYS_getgid));
608608 }
609609}
610610
611611pub fn geteuid() u32 {
612612 if (@hasDecl(@This(), "SYS_geteuid32")) {
613 return u32(syscall0(SYS_geteuid32));
613 return @as(u32, syscall0(SYS_geteuid32));
614614 } else {
615 return u32(syscall0(SYS_geteuid));
615 return @as(u32, syscall0(SYS_geteuid));
616616 }
617617}
618618
619619pub fn getegid() u32 {
620620 if (@hasDecl(@This(), "SYS_getegid32")) {
621 return u32(syscall0(SYS_getegid32));
621 return @as(u32, syscall0(SYS_getegid32));
622622 } else {
623 return u32(syscall0(SYS_getegid));
623 return @as(u32, syscall0(SYS_getegid));
624624 }
625625}
626626
......@@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
743743}
744744
745745pub 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));
747747}
748748
749749pub 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));
751751}
752752
753753pub 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 {
755755}
756756
757757pub 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));
759759}
760760
761761pub 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));
763763}
764764
765765pub 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);
767767}
768768
769769pub 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
781781 // batch-send all messages up to the current message
782782 if (next_unsent < i) {
783783 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);
785785 if (getErrno(r) != 0) return next_unsent;
786786 if (r < batch_size) return next_unsent + r;
787787 }
......@@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
797797 }
798798 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
799799 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);
801801 if (getErrno(r) != 0) return r;
802802 return next_unsent + r;
803803 }
804804 return kvlen;
805805 }
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);
807807}
808808
809809pub 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);
811811}
812812
813813pub 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);
815815}
816816
817817pub 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));
819819}
820820
821821pub 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)));
823823}
824824
825825pub 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));
827827}
828828
829829pub 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);
831831}
832832
833833pub 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));
835835}
836836
837837pub 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 {
843843}
844844
845845pub 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);
847847}
848848
849849pub fn fstat(fd: i32, stat_buf: *Stat) usize {
850850 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));
852852 } 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));
854854 }
855855}
856856
......@@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
875875// TODO https://github.com/ziglang/zig/issues/265
876876pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
877877 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);
879879 } 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);
881881 }
882882}
883883
......@@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
885885 if (@hasDecl(@This(), "SYS_statx")) {
886886 return syscall5(
887887 SYS_statx,
888 @bitCast(usize, isize(dirfd)),
888 @bitCast(usize, @as(isize, dirfd)),
889889 @ptrToInt(path),
890890 flags,
891891 mask,
892892 @ptrToInt(statx_buf),
893893 );
894894 }
895 return @bitCast(usize, isize(-ENOSYS));
895 return @bitCast(usize, @as(isize, -ENOSYS));
896896}
897897
898898// TODO https://github.com/ziglang/zig/issues/265
......@@ -959,7 +959,7 @@ pub fn sched_yield() usize {
959959}
960960
961961pub 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));
963963 if (@bitCast(isize, rc) < 0) return rc;
964964 if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
965965 return 0;
......@@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize {
974974}
975975
976976pub 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));
978978}
979979
980980pub 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
984984pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {
985985 return syscall6(
986986 SYS_epoll_pwait,
987 @bitCast(usize, isize(epoll_fd)),
987 @bitCast(usize, @as(isize, epoll_fd)),
988988 @ptrToInt(events),
989989 @intCast(usize, maxevents),
990 @bitCast(usize, isize(timeout)),
990 @bitCast(usize, @as(isize, timeout)),
991991 @ptrToInt(sigmask),
992992 @sizeOf(sigset_t),
993993 );
......@@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
998998}
999999
10001000pub 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);
10021002}
10031003
10041004pub const itimerspec = extern struct {
......@@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct {
10071007};
10081008
10091009pub 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));
10111011}
10121012
10131013pub 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));
10151015}
10161016
10171017pub fn unshare(flags: usize) usize {
......@@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
10961096}
10971097
10981098pub 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);
11001100}
11011101
11021102pub 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);
11041104}
11051105
11061106test "" {
lib/std/os/linux/arm-eabi.zig+2-2
......@@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize {
100100pub nakedcc fn restore() void {
101101 return asm volatile ("svc #0"
102102 :
103 : [number] "{r7}" (usize(SYS_sigreturn))
103 : [number] "{r7}" (@as(usize, SYS_sigreturn))
104104 : "memory"
105105 );
106106}
......@@ -108,7 +108,7 @@ pub nakedcc fn restore() void {
108108pub nakedcc fn restore_rt() void {
109109 return asm volatile ("svc #0"
110110 :
111 : [number] "{r7}" (usize(SYS_rt_sigreturn))
111 : [number] "{r7}" (@as(usize, SYS_rt_sigreturn))
112112 : "memory"
113113 );
114114}
lib/std/os/linux/arm64.zig+1-1
......@@ -93,7 +93,7 @@ pub const restore = restore_rt;
9393pub nakedcc fn restore_rt() void {
9494 return asm volatile ("svc #0"
9595 :
96 : [number] "{x8}" (usize(SYS_rt_sigreturn))
96 : [number] "{x8}" (@as(usize, SYS_rt_sigreturn))
9797 : "memory", "cc"
9898 );
9999}
lib/std/os/linux/mipsel.zig+3-3
......@@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
2626 \\ sw $3, 4($4)
2727 \\ 2:
2828 : [ret] "={$2}" (-> usize)
29 : [number] "{$2}" (usize(SYS_pipe))
29 : [number] "{$2}" (@as(usize, SYS_pipe))
3030 : "memory", "cc", "$7"
3131 );
3232}
......@@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
147147pub nakedcc fn restore() void {
148148 return asm volatile ("syscall"
149149 :
150 : [number] "{$2}" (usize(SYS_sigreturn))
150 : [number] "{$2}" (@as(usize, SYS_sigreturn))
151151 : "memory", "cc", "$7"
152152 );
153153}
......@@ -155,7 +155,7 @@ pub nakedcc fn restore() void {
155155pub nakedcc fn restore_rt() void {
156156 return asm volatile ("syscall"
157157 :
158 : [number] "{$2}" (usize(SYS_rt_sigreturn))
158 : [number] "{$2}" (@as(usize, SYS_rt_sigreturn))
159159 : "memory", "cc", "$7"
160160 );
161161}
lib/std/os/linux/riscv64.zig+1-1
......@@ -92,7 +92,7 @@ pub const restore = restore_rt;
9292pub nakedcc fn restore_rt() void {
9393 return asm volatile ("ecall"
9494 :
95 : [number] "{x17}" (usize(SYS_rt_sigreturn))
95 : [number] "{x17}" (@as(usize, SYS_rt_sigreturn))
9696 : "memory"
9797 );
9898}
lib/std/os/linux/vdso.zig+2-2
......@@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6262
6363 var i: usize = 0;
6464 while (i < hashtab[1]) : (i += 1) {
65 if (0 == (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;
65 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
6767 if (0 == syms[i].st_shndx) continue;
6868 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;
6969 if (maybe_versym) |versym| {
lib/std/os/linux/x86_64.zig+1-1
......@@ -93,7 +93,7 @@ pub const restore = restore_rt;
9393pub nakedcc fn restore_rt() void {
9494 return asm volatile ("syscall"
9595 :
96 : [number] "{rax}" (usize(SYS_rt_sigreturn))
96 : [number] "{rax}" (@as(usize, SYS_rt_sigreturn))
9797 : "rcx", "r11", "memory"
9898 );
9999}
lib/std/os/test.zig+1-1
......@@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {
172172
173173 var counter = data.?;
174174 // Count how many libraries are loaded
175 counter.* += usize(1);
175 counter.* += @as(usize, 1);
176176
177177 // The image should contain at least a PT_LOAD segment
178178 if (info.dlpi_phnum < 1) return -1;
lib/std/os/windows.zig+1-1
......@@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 {
801801}
802802
803803pub 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);
805805 return fromSysTime(hns);
806806}
807807
lib/std/os/zen.zig+2-2
......@@ -138,7 +138,7 @@ pub const Syscall = enum(usize) {
138138////////////////////
139139
140140pub fn exit(status: i32) noreturn {
141 _ = syscall1(Syscall.exit, @bitCast(usize, isize(status)));
141 _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status)));
142142 unreachable;
143143}
144144
......@@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
167167}
168168
169169pub fn createThread(function: fn () void) u16 {
170 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
170 return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function)));
171171}
172172
173173/////////////////////////
lib/std/packed_int_array.zig+9-9
......@@ -331,7 +331,7 @@ test "PackedIntArray" {
331331 var data = PackedArray(undefined);
332332
333333 //write values, counting up
334 var i = usize(0);
334 var i = @as(usize, 0);
335335 var count = I(0);
336336 while (i < data.len()) : (i += 1) {
337337 data.set(i, count);
......@@ -352,7 +352,7 @@ test "PackedIntArray" {
352352test "PackedIntArray init" {
353353 const PackedArray = PackedIntArray(u3, 8);
354354 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);
356356 while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i);
357357}
358358
......@@ -375,7 +375,7 @@ test "PackedIntSlice" {
375375 var data = P.init(&buffer, int_count);
376376
377377 //write values, counting up
378 var i = usize(0);
378 var i = @as(usize, 0);
379379 var count = I(0);
380380 while (i < data.len()) : (i += 1) {
381381 data.set(i, count);
......@@ -406,7 +406,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
406406
407407 const limit = (1 << bits);
408408
409 var i = usize(0);
409 var i = @as(usize, 0);
410410 while (i < packed_array.len()) : (i += 1) {
411411 packed_array.set(i, @intCast(Int, i % limit));
412412 }
......@@ -466,7 +466,7 @@ test "PackedIntSlice accumulating bit offsets" {
466466 var packed_array = PackedArray(undefined);
467467
468468 var packed_slice = packed_array.slice(0, packed_array.len());
469 var i = usize(0);
469 var i = @as(usize, 0);
470470 while (i < packed_array.len() - 1) : (i += 1) {
471471 packed_slice = packed_slice.slice(1, packed_slice.len());
472472 }
......@@ -476,7 +476,7 @@ test "PackedIntSlice accumulating bit offsets" {
476476 var packed_array = PackedArray(undefined);
477477
478478 var packed_slice = packed_array.slice(0, packed_array.len());
479 var i = usize(0);
479 var i = @as(usize, 0);
480480 while (i < packed_array.len() - 1) : (i += 1) {
481481 packed_slice = packed_slice.slice(1, packed_slice.len());
482482 }
......@@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" {
493493 var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9);
494494 const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3);
495495
496 var i = usize(0);
496 var i = @as(usize, 0);
497497 while (i < packed_slice_cast_2.len()) : (i += 1) {
498498 const val = switch (builtin.endian) {
499499 .Big => 0b01,
......@@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" {
541541 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542542 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543543
544 var i = usize(0);
544 var i = @as(usize, 0);
545545 while (i < packed_array_be.len()) : (i += 1) {
546546 testing.expect(packed_array_be.get(i) == i);
547547 }
......@@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" {
579579 testing.expect(packed_array_be.bytes[3] == 0b00000001);
580580 testing.expect(packed_array_be.bytes[4] == 0b00000000);
581581
582 var i = usize(0);
582 var i = @as(usize, 0);
583583 while (i < packed_array_be.len()) : (i += 1) {
584584 testing.expect(packed_array_be.get(i) == i);
585585 }
lib/std/pdb.zig+1-1
......@@ -532,7 +532,7 @@ const Msf = struct {
532532 const stream_sizes = try allocator.alloc(u32, stream_count);
533533 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.
536536 // These streams are not used, but still participate in the file
537537 // and must be taken into account when resolving stream indices.
538538 const Nil = 0xFFFFFFFF;
lib/std/priority_queue.zig+30-30
......@@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" {
236236 try queue.add(23);
237237 try queue.add(25);
238238 try queue.add(13);
239 expectEqual(u32(7), queue.remove());
240 expectEqual(u32(12), queue.remove());
241 expectEqual(u32(13), queue.remove());
242 expectEqual(u32(23), queue.remove());
243 expectEqual(u32(25), queue.remove());
244 expectEqual(u32(54), queue.remove());
239 expectEqual(@as(u32, 7), queue.remove());
240 expectEqual(@as(u32, 12), queue.remove());
241 expectEqual(@as(u32, 13), queue.remove());
242 expectEqual(@as(u32, 23), queue.remove());
243 expectEqual(@as(u32, 25), queue.remove());
244 expectEqual(@as(u32, 54), queue.remove());
245245}
246246
247247test "std.PriorityQueue: add and remove same min heap" {
......@@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" {
254254 try queue.add(2);
255255 try queue.add(1);
256256 try queue.add(1);
257 expectEqual(u32(1), queue.remove());
258 expectEqual(u32(1), queue.remove());
259 expectEqual(u32(1), queue.remove());
260 expectEqual(u32(1), queue.remove());
261 expectEqual(u32(2), queue.remove());
262 expectEqual(u32(2), queue.remove());
257 expectEqual(@as(u32, 1), queue.remove());
258 expectEqual(@as(u32, 1), queue.remove());
259 expectEqual(@as(u32, 1), queue.remove());
260 expectEqual(@as(u32, 1), queue.remove());
261 expectEqual(@as(u32, 2), queue.remove());
262 expectEqual(@as(u32, 2), queue.remove());
263263}
264264
265265test "std.PriorityQueue: removeOrNull on empty" {
......@@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" {
276276 try queue.add(9);
277277 try queue.add(3);
278278 try queue.add(2);
279 expectEqual(u32(2), queue.remove());
280 expectEqual(u32(3), queue.remove());
281 expectEqual(u32(9), queue.remove());
279 expectEqual(@as(u32, 2), queue.remove());
280 expectEqual(@as(u32, 3), queue.remove());
281 expectEqual(@as(u32, 9), queue.remove());
282282}
283283
284284test "std.PriorityQueue: peek" {
......@@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" {
289289 try queue.add(9);
290290 try queue.add(3);
291291 try queue.add(2);
292 expectEqual(u32(2), queue.peek().?);
293 expectEqual(u32(2), queue.peek().?);
292 expectEqual(@as(u32, 2), queue.peek().?);
293 expectEqual(@as(u32, 2), queue.peek().?);
294294}
295295
296296test "std.PriorityQueue: sift up with odd indices" {
......@@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" {
341341 try queue.add(23);
342342 try queue.add(25);
343343 try queue.add(13);
344 expectEqual(u32(54), queue.remove());
345 expectEqual(u32(25), queue.remove());
346 expectEqual(u32(23), queue.remove());
347 expectEqual(u32(13), queue.remove());
348 expectEqual(u32(12), queue.remove());
349 expectEqual(u32(7), queue.remove());
344 expectEqual(@as(u32, 54), queue.remove());
345 expectEqual(@as(u32, 25), queue.remove());
346 expectEqual(@as(u32, 23), queue.remove());
347 expectEqual(@as(u32, 13), queue.remove());
348 expectEqual(@as(u32, 12), queue.remove());
349 expectEqual(@as(u32, 7), queue.remove());
350350}
351351
352352test "std.PriorityQueue: add and remove same max heap" {
......@@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" {
359359 try queue.add(2);
360360 try queue.add(1);
361361 try queue.add(1);
362 expectEqual(u32(2), queue.remove());
363 expectEqual(u32(2), queue.remove());
364 expectEqual(u32(1), queue.remove());
365 expectEqual(u32(1), queue.remove());
366 expectEqual(u32(1), queue.remove());
367 expectEqual(u32(1), queue.remove());
362 expectEqual(@as(u32, 2), queue.remove());
363 expectEqual(@as(u32, 2), queue.remove());
364 expectEqual(@as(u32, 1), queue.remove());
365 expectEqual(@as(u32, 1), queue.remove());
366 expectEqual(@as(u32, 1), queue.remove());
367 expectEqual(@as(u32, 1), queue.remove());
368368}
369369
370370test "std.PriorityQueue: iterator" {
......@@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" {
386386 _ = map.remove(e);
387387 }
388388
389 expectEqual(usize(0), map.count());
389 expectEqual(@as(usize, 0), map.count());
390390}
lib/std/rand.zig+4-4
......@@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct {
633633 const r = s0 +% s1;
634634
635635 s1 ^= s0;
636 self.s[0] = math.rotl(u64, s0, u8(55)) ^ s1 ^ (s1 << 14);
637 self.s[1] = math.rotl(u64, s1, u8(36));
636 self.s[0] = math.rotl(u64, s0, @as(u8, 55)) ^ s1 ^ (s1 << 14);
637 self.s[1] = math.rotl(u64, s1, @as(u8, 36));
638638
639639 return r;
640640 }
......@@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct {
652652 inline for (table) |entry| {
653653 var b: usize = 0;
654654 while (b < 64) : (b += 1) {
655 if ((entry & (u64(1) << @intCast(u6, b))) != 0) {
655 if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) {
656656 s0 ^= self.s[0];
657657 s1 ^= self.s[1];
658658 }
......@@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void {
10901090 testRangeBias(r, start, end, false);
10911091}
10921092fn 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));
10941094 var values_buffer = [_]bool{false} ** 0x100;
10951095 const values = values_buffer[0..count];
10961096 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 {
1717 // We manually construct a float from parts as we can avoid an extra random lookup here by
1818 // using the unused exponent for the lookup table entry.
1919 const bits = random.scalar(u64);
20 const i = usize(bits & 0xff);
20 const i = @as(usize, bits & 0xff);
2121
2222 const u = blk: {
2323 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
162162 /// Grows or shrinks capacity to match usage.
163163 pub fn setCapacity(self: *Self, new_capacity: usize) !void {
164164 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))) {
166166 return self.shrinkCapacity(new_capacity);
167167 }
168168 }
......@@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
231231
232232 fn shelfSize(shelf_index: ShelfIndex) usize {
233233 if (prealloc_item_count == 0) {
234 return usize(1) << shelf_index;
234 return @as(usize, 1) << shelf_index;
235235 }
236 return usize(1) << (shelf_index + (prealloc_exp + 1));
236 return @as(usize, 1) << (shelf_index + (prealloc_exp + 1));
237237 }
238238
239239 fn shelfIndex(list_index: usize) ShelfIndex {
......@@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
245245
246246 fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize {
247247 if (prealloc_item_count == 0) {
248 return (list_index + 1) - (usize(1) << shelf_index);
248 return (list_index + 1) - (@as(usize, 1) << shelf_index);
249249 }
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));
251251 }
252252
253253 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
813813// where have some idea as to how many unique values there are and where the next value might be
814814fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
815815 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
818818 var index = range.start + skip;
819819 while (lessThan(items[index - 1], value)) : (index += skip) {
......@@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh
827827
828828fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
829829 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
832832 var index = range.end - skip;
833833 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
841841
842842fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
843843 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
846846 var index = range.start + skip;
847847 while (!lessThan(value, items[index - 1])) : (index += skip) {
......@@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha
855855
856856fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
857857 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
860860 var index = range.end - skip;
861861 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 {
6262 r += 1;
6363 n -= 1;
6464 }
65 return c_int(l[0]) - c_int(r[0]);
65 return @as(c_int, l[0]) - @as(c_int, r[0]);
6666}
6767
6868extern fn strerror(errnum: c_int) [*]const u8 {
......@@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
540540 // scale result up
541541 if (ex > 0) {
542542 ux -%= 1 << digits;
543 ux |= uint(@bitCast(u32, ex)) << digits;
543 ux |= @as(uint, @bitCast(u32, ex)) << digits;
544544 } else {
545545 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));
546546 }
......@@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 {
687687
688688export fn sqrtf(x: f32) f32 {
689689 const tiny: f32 = 1.0e-30;
690 const sign: i32 = @bitCast(i32, u32(0x80000000));
690 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));
691691 var ix: i32 = @bitCast(i32, x);
692692
693693 if ((ix & 0x7F800000) == 0x7F800000) {
lib/std/special/compiler_rt.zig+17-17
......@@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 {
672672 // special cases
673673 if (d == 0) return 0; // ?!
674674 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)));
676676 // 0 <= sr <= n_uword_bits - 1 or sr large
677677 if (sr > n_uword_bits - 1) {
678678 // d > r
......@@ -1414,10 +1414,10 @@ test "test_divsi3" {
14141414 [_]i32{ -2, 1, -2 },
14151415 [_]i32{ -2, -1, 2 },
14161416
1417 [_]i32{ @bitCast(i32, u32(0x80000000)), 1, @bitCast(i32, u32(0x80000000)) },
1418 [_]i32{ @bitCast(i32, u32(0x80000000)), -1, @bitCast(i32, u32(0x80000000)) },
1419 [_]i32{ @bitCast(i32, u32(0x80000000)), -2, 0x40000000 },
1420 [_]i32{ @bitCast(i32, u32(0x80000000)), 2, @bitCast(i32, u32(0xC0000000)) },
1417 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) },
1418 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) },
1419 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 },
1420 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) },
14211421 };
14221422
14231423 for (cases) |case| {
......@@ -1443,8 +1443,8 @@ test "test_divmodsi4" {
14431443 [_]i32{ 19, 5, 3, 4 },
14441444 [_]i32{ 19, -5, -3, 4 },
14451445
1446 [_]i32{ @bitCast(i32, u32(0x80000000)), 8, @bitCast(i32, u32(0xf0000000)), 0 },
1447 [_]i32{ @bitCast(i32, u32(0x80000007)), 8, @bitCast(i32, u32(0xf0000001)), -1 },
1446 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 },
1447 [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 },
14481448 };
14491449
14501450 for (cases) |case| {
......@@ -1467,10 +1467,10 @@ test "test_divdi3" {
14671467 [_]i64{ -2, 1, -2 },
14681468 [_]i64{ -2, -1, 2 },
14691469
1470 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)) },
1471 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)) },
1472 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -2, 0x4000000000000000 },
1473 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0xC000000000000000)) },
1470 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
1471 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
1472 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 },
1473 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) },
14741474 };
14751475
14761476 for (cases) |case| {
......@@ -1492,12 +1492,12 @@ test "test_moddi3" {
14921492 [_]i64{ -5, 3, -2 },
14931493 [_]i64{ -5, -3, -2 },
14941494
1495 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 1, 0 },
1496 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -1, 0 },
1497 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 2, 0 },
1498 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -2, 0 },
1499 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 3, -2 },
1500 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -3, -2 },
1495 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 },
1496 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 },
1497 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 },
1498 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 },
1499 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 },
1500 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 },
15011501 };
15021502
15031503 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 {
1919}
2020
2121pub 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));
2323 return addXf3(f32, a, neg_b);
2424}
2525
2626pub 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));
2828 return addXf3(f64, a, neg_b);
2929}
3030
3131pub 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));
3333 return addXf3(f128, a, neg_b);
3434}
3535
3636// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
3737fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
3838 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));
4040 const significandBits = std.math.floatMantissaBits(T);
41 const implicitBit = Z(1) << significandBits;
41 const implicitBit = @as(Z, 1) << significandBits;
4242
4343 const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
4444 significand.* <<= @intCast(S, shift);
......@@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
4848// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
4949fn addXf3(comptime T: type, a: T, b: T) T {
5050 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
5353 const typeWidth = T.bit_count;
5454 const significandBits = std.math.floatMantissaBits(T);
5555 const exponentBits = std.math.floatExponentBits(T);
5656
57 const signBit = (Z(1) << (significandBits + exponentBits));
57 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
5858 const maxExponent = ((1 << exponentBits) - 1);
5959 const exponentBias = (maxExponent >> 1);
6060
61 const implicitBit = (Z(1) << significandBits);
61 const implicitBit = (@as(Z, 1) << significandBits);
6262 const quietBit = implicitBit >> 1;
6363 const significandMask = implicitBit - 1;
6464
......@@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T {
7878 const infRep = @bitCast(Z, std.math.inf(T));
7979
8080 // Detect if a or b is zero, infinity, or NaN.
81 if (aAbs -% Z(1) >= infRep - Z(1) or
82 bAbs -% Z(1) >= infRep - Z(1))
81 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
82 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
8383 {
8484 // NaN + anything = qNaN
8585 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);
......@@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
148148 const @"align" = @intCast(Z, aExponent - bExponent);
149149 if (@"align" != 0) {
150150 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;
152152 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
153153 } else {
154154 bSignificand = 1; // sticky; b is known to be non-zero.
......@@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
157157 if (subtraction) {
158158 aSignificand -= bSignificand;
159159 // 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
162162 // If partial cancellation occured, we need to left-shift the result
163163 // and adjust the exponent:
......@@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
185185 // Result is denormal before rounding; the exponent is zero and we
186186 // need to shift the significand.
187187 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;
189189 aSignificand = aSignificand >> @intCast(S, shift | sticky);
190190 aExponent = 0;
191191 }
lib/std/special/compiler_rt/addXf3_test.zig+4-4
......@@ -3,8 +3,8 @@
33// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c
44// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c
55
6const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64);
7const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64);
6const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
7const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
88
99const __addtf3 = @import("addXf3.zig").__addtf3;
1010
......@@ -34,7 +34,7 @@ test "addtf3" {
3434 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3535
3636 // 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
3939 // inf + inf = inf
4040 test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
......@@ -75,7 +75,7 @@ test "subtf3" {
7575 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7676
7777 // 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
8080 // inf - any = inf
8181 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;
1313const typeWidth = rep_t.bit_count;
1414const significandBits = std.math.floatMantissaBits(fp_t);
1515const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (rep_t(1) << (significandBits + exponentBits));
16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
1717const absMask = signBit - 1;
18const implicitBit = rep_t(1) << significandBits;
18const implicitBit = @as(rep_t, 1) << significandBits;
1919const significandMask = implicitBit - 1;
2020const exponentMask = absMask ^ significandMask;
2121const infRep = @bitCast(rep_t, std.math.inf(fp_t));
2222
2323// TODO https://github.com/ziglang/zig/issues/641
2424// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = c_int(-1);
26const LE_EQUAL = c_int(0);
27const LE_GREATER = c_int(1);
28const LE_UNORDERED = c_int(1);
25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);
2929
3030pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {
3131 @setRuntimeSafety(is_test);
......@@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {
6565
6666// TODO https://github.com/ziglang/zig/issues/641
6767// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = c_int(-1);
69const GE_EQUAL = c_int(0);
70const GE_GREATER = c_int(1);
71const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
7373pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {
7474 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/comparesf2.zig+10-10
......@@ -13,19 +13,19 @@ const srep_t = i32;
1313const typeWidth = rep_t.bit_count;
1414const significandBits = std.math.floatMantissaBits(fp_t);
1515const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (rep_t(1) << (significandBits + exponentBits));
16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
1717const absMask = signBit - 1;
18const implicitBit = rep_t(1) << significandBits;
18const implicitBit = @as(rep_t, 1) << significandBits;
1919const significandMask = implicitBit - 1;
2020const exponentMask = absMask ^ significandMask;
2121const infRep = @bitCast(rep_t, std.math.inf(fp_t));
2222
2323// TODO https://github.com/ziglang/zig/issues/641
2424// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = c_int(-1);
26const LE_EQUAL = c_int(0);
27const LE_GREATER = c_int(1);
28const LE_UNORDERED = c_int(1);
25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);
2929
3030pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {
3131 @setRuntimeSafety(is_test);
......@@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {
6565
6666// TODO https://github.com/ziglang/zig/issues/641
6767// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = c_int(-1);
69const GE_EQUAL = c_int(0);
70const GE_GREATER = c_int(1);
71const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
7373pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {
7474 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/comparetf2.zig+10-10
......@@ -1,9 +1,9 @@
11// TODO https://github.com/ziglang/zig/issues/641
22// and then make the return types of some of these functions the enum instead of c_int
3const LE_LESS = c_int(-1);
4const LE_EQUAL = c_int(0);
5const LE_GREATER = c_int(1);
6const LE_UNORDERED = c_int(1);
3const LE_LESS = @as(c_int, -1);
4const LE_EQUAL = @as(c_int, 0);
5const LE_GREATER = @as(c_int, 1);
6const LE_UNORDERED = @as(c_int, 1);
77
88const rep_t = u128;
99const srep_t = i128;
......@@ -11,9 +11,9 @@ const srep_t = i128;
1111const typeWidth = rep_t.bit_count;
1212const significandBits = 112;
1313const exponentBits = (typeWidth - significandBits - 1);
14const signBit = (rep_t(1) << (significandBits + exponentBits));
14const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
1515const absMask = signBit - 1;
16const implicitBit = rep_t(1) << significandBits;
16const implicitBit = @as(rep_t, 1) << significandBits;
1717const significandMask = implicitBit - 1;
1818const exponentMask = absMask ^ significandMask;
1919const infRep = exponentMask;
......@@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int {
6060
6161// TODO https://github.com/ziglang/zig/issues/641
6262// and then make the return types of some of these functions the enum instead of c_int
63const GE_LESS = c_int(-1);
64const GE_EQUAL = c_int(0);
65const GE_GREATER = c_int(1);
66const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
63const GE_LESS = @as(c_int, -1);
64const GE_EQUAL = @as(c_int, 0);
65const GE_GREATER = @as(c_int, 1);
66const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
6767
6868pub extern fn __getf2(a: f128, b: f128) c_int {
6969 @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 {
1414 const significandBits = std.math.floatMantissaBits(f64);
1515 const exponentBits = std.math.floatExponentBits(f64);
1616
17 const signBit = (Z(1) << (significandBits + exponentBits));
17 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1818 const maxExponent = ((1 << exponentBits) - 1);
1919 const exponentBias = (maxExponent >> 1);
2020
21 const implicitBit = (Z(1) << significandBits);
21 const implicitBit = (@as(Z, 1) << significandBits);
2222 const quietBit = implicitBit >> 1;
2323 const significandMask = implicitBit - 1;
2424
......@@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
9191 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
9292 // is accurate to about 3.5 binary digits.
9393 const q31b: u32 = @truncate(u32, bSignificand >> 21);
94 var recip32 = u32(0x7504f333) -% q31b;
94 var recip32 = @as(u32, 0x7504f333) -% q31b;
9595
9696 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
9797 //
......@@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
101101 // with each iteration, so after three iterations, we have about 28 binary
102102 // digits of accuracy.
103103 var correction32: u32 = undefined;
104 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);
105 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);
106 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);
107 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);
108 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);
109 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);
104 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
105 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
106 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
107 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
108 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
109 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
110110
111111 // recip32 might have overflowed to exactly zero in the preceding
112112 // 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 {
119119 const q63blo: u32 = @truncate(u32, bSignificand << 11);
120120 var correction: u64 = undefined;
121121 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;
123123 const cHi = @truncate(u32, correction >> 32);
124124 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
127127 // We already adjusted the 32-bit estimate, now we need to adjust the final
128128 // 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 {
195195 // Clear the implicit bit
196196 var absResult = quotient & significandMask;
197197 // Insert the exponent
198 absResult |= @bitCast(Z, SignedZ(writtenExponent)) << significandBits;
198 absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits;
199199 // Round
200200 absResult +%= round;
201201 // Insert the sign and return
......@@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
208208 switch (Z) {
209209 u32 => {
210210 // 32x32 --> 64 bit multiply
211 const product = u64(a) * u64(b);
211 const product = @as(u64, a) * @as(u64, b);
212212 hi.* = @truncate(u32, product >> 32);
213213 lo.* = @truncate(u32, product);
214214 },
......@@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
237237 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
238238 },
239239 u128 => {
240 const Word_LoMask = u64(0x00000000ffffffff);
241 const Word_HiMask = u64(0xffffffff00000000);
242 const Word_FullMask = u64(0xffffffffffffffff);
240 const Word_LoMask = @as(u64, 0x00000000ffffffff);
241 const Word_HiMask = @as(u64, 0xffffffff00000000);
242 const Word_FullMask = @as(u64, 0xffffffffffffffff);
243243 const S = struct {
244244 fn Word_1(x: u128) u64 {
245245 return @truncate(u32, x >> 96);
......@@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
275275 const product43: u64 = S.Word_4(a) * S.Word_3(b);
276276 const product44: u64 = S.Word_4(a) * S.Word_4(b);
277277
278 const sum0: u128 = u128(product44);
279 const sum1: u128 = u128(product34) +%
280 u128(product43);
281 const sum2: u128 = u128(product24) +%
282 u128(product33) +%
283 u128(product42);
284 const sum3: u128 = u128(product14) +%
285 u128(product23) +%
286 u128(product32) +%
287 u128(product41);
288 const sum4: u128 = u128(product13) +%
289 u128(product22) +%
290 u128(product31);
291 const sum5: u128 = u128(product12) +%
292 u128(product21);
293 const sum6: u128 = u128(product11);
278 const sum0: u128 = @as(u128, product44);
279 const sum1: u128 = @as(u128, product34) +%
280 @as(u128, product43);
281 const sum2: u128 = @as(u128, product24) +%
282 @as(u128, product33) +%
283 @as(u128, product42);
284 const sum3: u128 = @as(u128, product14) +%
285 @as(u128, product23) +%
286 @as(u128, product32) +%
287 @as(u128, product41);
288 const sum4: u128 = @as(u128, product13) +%
289 @as(u128, product22) +%
290 @as(u128, product31);
291 const sum5: u128 = @as(u128, product12) +%
292 @as(u128, product21);
293 const sum6: u128 = @as(u128, product11);
294294
295295 const r0: u128 = (sum0 & Word_FullMask) +%
296296 ((sum1 & Word_LoMask) << 32);
......@@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
316316 @setRuntimeSafety(builtin.is_test);
317317 const Z = @IntType(false, T.bit_count);
318318 const significandBits = std.math.floatMantissaBits(T);
319 const implicitBit = Z(1) << significandBits;
319 const implicitBit = @as(Z, 1) << significandBits;
320320
321321 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
322322 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 {
1313 const significandBits = std.math.floatMantissaBits(f32);
1414 const exponentBits = std.math.floatExponentBits(f32);
1515
16 const signBit = (Z(1) << (significandBits + exponentBits));
16 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1717 const maxExponent = ((1 << exponentBits) - 1);
1818 const exponentBias = (maxExponent >> 1);
1919
20 const implicitBit = (Z(1) << significandBits);
20 const implicitBit = (@as(Z, 1) << significandBits);
2121 const quietBit = implicitBit >> 1;
2222 const significandMask = implicitBit - 1;
2323
......@@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
9090 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
9191 // is accurate to about 3.5 binary digits.
9292 const q31b = bSignificand << 8;
93 var reciprocal = u32(0x7504f333) -% q31b;
93 var reciprocal = @as(u32, 0x7504f333) -% q31b;
9494
9595 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
9696 //
......@@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
100100 // with each iteration, so after three iterations, we have about 28 binary
101101 // digits of accuracy.
102102 var correction: u32 = undefined;
103 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);
104 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);
105 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);
106 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);
107 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);
108 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);
103 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
104 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
105 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
106 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
107 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
108 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
109109
110110 // Exhaustive testing shows that the error in reciprocal after three steps
111111 // 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 {
127127 // is the error in the reciprocal of b scaled by the maximum
128128 // possible value of a. As a consequence of this error bound,
129129 // 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
132132 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
133133 // 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 {
189189 @setRuntimeSafety(builtin.is_test);
190190 const Z = @IntType(false, T.bit_count);
191191 const significandBits = std.math.floatMantissaBits(T);
192 const implicitBit = Z(1) << significandBits;
192 const implicitBit = @as(Z, 1) << significandBits;
193193
194194 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
195195 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/divti3_test.zig+4-4
......@@ -14,8 +14,8 @@ test "divti3" {
1414 test__divti3(-2, 1, -2);
1515 test__divti3(-2, -1, 2);
1616
17 test__divti3(@bitCast(i128, u128(0x8 << 124)), 1, @bitCast(i128, u128(0x8 << 124)));
18 test__divti3(@bitCast(i128, u128(0x8 << 124)), -1, @bitCast(i128, u128(0x8 << 124)));
19 test__divti3(@bitCast(i128, u128(0x8 << 124)), -2, @bitCast(i128, u128(0x4 << 124)));
20 test__divti3(@bitCast(i128, u128(0x8 << 124)), 2, @bitCast(i128, u128(0xc << 124)));
17 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
18 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
19 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
20 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
2121}
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
4949 const dstInfExp = (1 << dstExpBits) - 1;
5050 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
5454 // Break a into a sign and representation of the absolute value
5555 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
6161 // a is a normal number.
6262 // Extend to the destination type by shifting the significand and
6363 // 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);
6565 absResult += (dstExpBias - srcExpBias) << dstSigBits;
6666 } else if (aAbs >= srcInfinity) {
6767 // a is NaN or infinity.
......@@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
6969 // bit (if needed) and right-aligning the rest of the trailing NaN
7070 // payload field.
7171 absResult = dstInfExp << dstSigBits;
72 absResult |= dst_rep_t(aAbs & srcQNaN) << (dstSigBits - srcSigBits);
73 absResult |= dst_rep_t(aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
72 absResult |= @as(dst_rep_t, aAbs & srcQNaN) << (dstSigBits - srcSigBits);
73 absResult |= @as(dst_rep_t, aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
7474 } else if (aAbs != 0) {
7575 // a is denormal.
7676 // renormalize the significand and clear the leading bit, then insert
7777 // the correct adjusted exponent in the destination type.
7878 const scale: u32 = @clz(src_rep_t, aAbs) -
79 @clz(src_rep_t, src_rep_t(srcMinNormal));
80 absResult = dst_rep_t(aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
79 @clz(src_rep_t, @as(src_rep_t, srcMinNormal));
80 absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
8181 absResult ^= dstMinNormal;
8282 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
8383 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
8787 }
8888
8989 // 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);
9191 return @bitCast(dst_t, result);
9292}
9393
lib/std/special/compiler_rt/extendXfYf2_test.zig+4-4
......@@ -134,11 +134,11 @@ test "extendsftf2" {
134134}
135135
136136fn makeQNaN64() f64 {
137 return @bitCast(f64, u64(0x7ff8000000000000));
137 return @bitCast(f64, @as(u64, 0x7ff8000000000000));
138138}
139139
140140fn makeInf64() f64 {
141 return @bitCast(f64, u64(0x7ff0000000000000));
141 return @bitCast(f64, @as(u64, 0x7ff0000000000000));
142142}
143143
144144fn makeNaN64(rand: u64) f64 {
......@@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 {
146146}
147147
148148fn makeQNaN32() f32 {
149 return @bitCast(f32, u32(0x7fc00000));
149 return @bitCast(f32, @as(u32, 0x7fc00000));
150150}
151151
152152fn makeNaN32(rand: u32) f32 {
......@@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 {
154154}
155155
156156fn makeInf32() f32 {
157 return @bitCast(f32, u32(0x7f800000));
157 return @bitCast(f32, @as(u32, 0x7f800000));
158158}
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixdfdi(a: f64, expected: i64) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixdfsi(a: f64, expected: i32) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixdfti_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixdfti(a: f64, expected: i128) void {
88 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));
1010 testing.expect(x == expected);
1111}
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 {
2525
2626 const typeWidth = rep_t.bit_count;
2727 const exponentBits = (typeWidth - significandBits - 1);
28 const signBit = (rep_t(1) << (significandBits + exponentBits));
28 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
2929 const maxExponent = ((1 << exponentBits) - 1);
3030 const exponentBias = (maxExponent >> 1);
3131
32 const implicitBit = (rep_t(1) << significandBits);
32 const implicitBit = (@as(rep_t, 1) << significandBits);
3333 const significandMask = (implicitBit - 1);
3434
3535 // 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 {
5151
5252 // If the value is too large for the integer type, saturate.
5353 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));
5555 }
5656
5757 // 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" {
8181test "fixint.i32" {
8282 test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
8383 test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
84 test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32));
85 test__fixint(f64, i32, f64(math.minInt(i32)) + 1, math.minInt(i32) + 1);
84 test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
85 test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
8686 test__fixint(f64, i32, -2.0, -2);
8787 test__fixint(f64, i32, -1.9, -1);
8888 test__fixint(f64, i32, -1.1, -1);
......@@ -96,8 +96,8 @@ test "fixint.i32" {
9696 test__fixint(f64, i32, 0.1, 0);
9797 test__fixint(f64, i32, 0.9, 0);
9898 test__fixint(f64, i32, 1.0, 1);
99 test__fixint(f64, i32, f64(math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
100 test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32));
99 test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
100 test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
101101 test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
102102 test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
103103}
......@@ -105,9 +105,9 @@ test "fixint.i32" {
105105test "fixint.i64" {
106106 test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
107107 test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
108 test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64));
109 test__fixint(f64, i64, f64(math.minInt(i64)) + 1, math.minInt(i64));
110 test__fixint(f64, i64, f64(math.minInt(i64) / 2), math.minInt(i64) / 2);
108 test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
109 test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
110 test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
111111 test__fixint(f64, i64, -2.0, -2);
112112 test__fixint(f64, i64, -1.9, -1);
113113 test__fixint(f64, i64, -1.1, -1);
......@@ -121,8 +121,8 @@ test "fixint.i64" {
121121 test__fixint(f64, i64, 0.1, 0);
122122 test__fixint(f64, i64, 0.9, 0);
123123 test__fixint(f64, i64, 1.0, 1);
124 test__fixint(f64, i64, f64(math.maxInt(i64)) - 1, math.maxInt(i64));
125 test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64));
124 test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
125 test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
126126 test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
127127 test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
128128}
......@@ -130,8 +130,8 @@ test "fixint.i64" {
130130test "fixint.i128" {
131131 test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
132132 test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
133 test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128));
134 test__fixint(f64, i128, f64(math.minInt(i128)) + 1, math.minInt(i128));
133 test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
134 test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
135135 test__fixint(f64, i128, -2.0, -2);
136136 test__fixint(f64, i128, -1.9, -1);
137137 test__fixint(f64, i128, -1.1, -1);
......@@ -145,8 +145,8 @@ test "fixint.i128" {
145145 test__fixint(f64, i128, 0.1, 0);
146146 test__fixint(f64, i128, 0.9, 0);
147147 test__fixint(f64, i128, 1.0, 1);
148 test__fixint(f64, i128, f64(math.maxInt(i128)) - 1, math.maxInt(i128));
149 test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128));
148 test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
149 test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
150150 test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
151151 test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
152152}
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixsfdi(a: f32, expected: i64) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixsfsi(a: f32, expected: i32) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixsfti_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixsfti(a: f32, expected: i128) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixtfdi(a: f128, expected: i64) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixtfsi(a: f128, expected: i32) void {
88 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));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixtfti_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixtfti(a: f128, expected: i128) void {
88 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));
1010 testing.expect(x == expected);
1111}
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
1919 };
2020 const typeWidth = rep_t.bit_count;
2121 const exponentBits = (typeWidth - significandBits - 1);
22 const signBit = (rep_t(1) << (significandBits + exponentBits));
22 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
2323 const maxExponent = ((1 << exponentBits) - 1);
2424 const exponentBias = (maxExponent >> 1);
2525
26 const implicitBit = (rep_t(1) << significandBits);
26 const implicitBit = (@as(rep_t, 1) << significandBits);
2727 const significandMask = (implicitBit - 1);
2828
2929 // 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
3131 const absMask = signBit - 1;
3232 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);
3535 const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias;
3636 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
3939 if (sign == -1 or exponent < 0) return 0;
4040
4141 // 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
4444 // If 0 <= exponent < significandBits, right shift to get the result.
4545 // 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 {
66 testing.expect(x == expected);
77}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
1111test "fixunstfsi" {
1212 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 {
66 testing.expect(x == expected);
77}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
1111test "fixunstfti" {
1212 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 {
66 @setRuntimeSafety(builtin.is_test);
77
88 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
1111 if (a == 0) {
12 return T(0.0);
12 return @as(T, 0.0);
1313 }
1414
1515 const significandBits = std.math.floatMantissaBits(T);
1616 const exponentBits = std.math.floatExponentBits(T);
1717 const exponentBias = ((1 << exponentBits - 1) - 1);
1818
19 const implicitBit = Z(1) << significandBits;
20 const signBit = Z(1 << Z.bit_count - 1);
19 const implicitBit = @as(Z, 1) << significandBits;
20 const signBit = @as(Z, 1 << Z.bit_count - 1);
2121
2222 const sign = a >> 31;
2323 // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31).
2424 const abs_a = (a ^ sign) -% sign;
2525 // 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
2828 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 {
4747 a += 1; // round - this step may add a significant bit
4848 a >>= 2; // dump Q and R
4949 // 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) {
5151 a >>= 1;
5252 e += 1;
5353 }
lib/std/special/compiler_rt/floattisf.zig+1-1
......@@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 {
4848 a += 1; // round - this step may add a significant bit
4949 a >>= 2; // dump Q and R
5050 // 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) {
5252 a >>= 1;
5353 e += 1;
5454 }
lib/std/special/compiler_rt/floattitf.zig+1-1
......@@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 {
4747 a += 1; // round - this step may add a significant bit
4848 a >>= 2; // dump Q and R
4949 // 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) {
5151 a >>= 1;
5252 e += 1;
5353 }
lib/std/special/compiler_rt/floatunsidf.zig+3-3
......@@ -2,7 +2,7 @@ const builtin = @import("builtin");
22const std = @import("std");
33const maxInt = std.math.maxInt;
44
5const implicitBit = u64(1) << 52;
5const implicitBit = @as(u64, 1) << 52;
66
77pub extern fn __floatunsidf(arg: u32) f64 {
88 @setRuntimeSafety(builtin.is_test);
......@@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 {
1010 if (arg == 0) return 0.0;
1111
1212 // 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);
1414 // Shift a into the significand field and clear the implicit bit
1515 const shift = @intCast(u6, 52 - exp);
16 const mant = u64(arg) << shift ^ implicitBit;
16 const mant = @as(u64, arg) << shift ^ implicitBit;
1717
1818 return @bitCast(f64, mant | (exp + 1023) << 52);
1919}
lib/std/special/compiler_rt/floatuntidf.zig+2-2
......@@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
3232 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
3333 const shift_amt_u7 = @intCast(u7, shift_amt);
3434 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);
3636 },
3737 }
3838 // finish
......@@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
4040 a += 1; // round - this step may add a significant bit
4141 a >>= 2; // dump Q and R
4242 // 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) {
4444 a >>= 1;
4545 e += 1;
4646 }
lib/std/special/compiler_rt/floatuntisf.zig+2-2
......@@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
3232 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
3333 const shift_amt_u7 = @intCast(u7, shift_amt);
3434 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);
3636 },
3737 }
3838 // finish
......@@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
4040 a += 1; // round - this step may add a significant bit
4141 a >>= 2; // dump Q and R
4242 // 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) {
4444 a >>= 1;
4545 e += 1;
4646 }
lib/std/special/compiler_rt/floatuntitf.zig+2-2
......@@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
3232 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
3333 const shift_amt_u7 = @intCast(u7, shift_amt);
3434 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);
3636 },
3737 }
3838 // finish
......@@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
4040 a += 1; // round - this step may add a significant bit
4141 a >>= 2; // dump Q and R
4242 // 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) {
4444 a >>= 1;
4545 e += 1;
4646 }
lib/std/special/compiler_rt/mulXf3.zig+25-25
......@@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
2424 const significandBits = std.math.floatMantissaBits(T);
2525 const exponentBits = std.math.floatExponentBits(T);
2626
27 const signBit = (Z(1) << (significandBits + exponentBits));
27 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
2828 const maxExponent = ((1 << exponentBits) - 1);
2929 const exponentBias = (maxExponent >> 1);
3030
31 const implicitBit = (Z(1) << significandBits);
31 const implicitBit = (@as(Z, 1) << significandBits);
3232 const quietBit = implicitBit >> 1;
3333 const significandMask = implicitBit - 1;
3434
......@@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
122122 // a zero of the appropriate sign. Mathematically there is no need to
123123 // handle this case separately, but we make it a special case to
124124 // 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));
126126 if (shift >= typeWidth) return @bitCast(T, productSign);
127127
128128 // 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 {
131131 } else {
132132 // Result is normal before rounding; insert the exponent.
133133 productHi &= significandMask;
134 productHi |= Z(@bitCast(u32, productExponent)) << significandBits;
134 productHi |= @as(Z, @bitCast(u32, productExponent)) << significandBits;
135135 }
136136
137137 // Insert the sign of the result:
......@@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
150150 switch (Z) {
151151 u32 => {
152152 // 32x32 --> 64 bit multiply
153 const product = u64(a) * u64(b);
153 const product = @as(u64, a) * @as(u64, b);
154154 hi.* = @truncate(u32, product >> 32);
155155 lo.* = @truncate(u32, product);
156156 },
......@@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
179179 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
180180 },
181181 u128 => {
182 const Word_LoMask = u64(0x00000000ffffffff);
183 const Word_HiMask = u64(0xffffffff00000000);
184 const Word_FullMask = u64(0xffffffffffffffff);
182 const Word_LoMask = @as(u64, 0x00000000ffffffff);
183 const Word_HiMask = @as(u64, 0xffffffff00000000);
184 const Word_FullMask = @as(u64, 0xffffffffffffffff);
185185 const S = struct {
186186 fn Word_1(x: u128) u64 {
187187 return @truncate(u32, x >> 96);
......@@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
217217 const product43: u64 = S.Word_4(a) * S.Word_3(b);
218218 const product44: u64 = S.Word_4(a) * S.Word_4(b);
219219
220 const sum0: u128 = u128(product44);
221 const sum1: u128 = u128(product34) +%
222 u128(product43);
223 const sum2: u128 = u128(product24) +%
224 u128(product33) +%
225 u128(product42);
226 const sum3: u128 = u128(product14) +%
227 u128(product23) +%
228 u128(product32) +%
229 u128(product41);
230 const sum4: u128 = u128(product13) +%
231 u128(product22) +%
232 u128(product31);
233 const sum5: u128 = u128(product12) +%
234 u128(product21);
235 const sum6: u128 = u128(product11);
220 const sum0: u128 = @as(u128, product44);
221 const sum1: u128 = @as(u128, product34) +%
222 @as(u128, product43);
223 const sum2: u128 = @as(u128, product24) +%
224 @as(u128, product33) +%
225 @as(u128, product42);
226 const sum3: u128 = @as(u128, product14) +%
227 @as(u128, product23) +%
228 @as(u128, product32) +%
229 @as(u128, product41);
230 const sum4: u128 = @as(u128, product13) +%
231 @as(u128, product22) +%
232 @as(u128, product31);
233 const sum5: u128 = @as(u128, product12) +%
234 @as(u128, product21);
235 const sum6: u128 = @as(u128, product11);
236236
237237 const r0: u128 = (sum0 & Word_FullMask) +%
238238 ((sum1 & Word_LoMask) << 32);
......@@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
258258 @setRuntimeSafety(builtin.is_test);
259259 const Z = @IntType(false, T.bit_count);
260260 const significandBits = std.math.floatMantissaBits(T);
261 const implicitBit = Z(1) << significandBits;
261 const implicitBit = @as(Z, 1) << significandBits;
262262
263263 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
264264 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/mulXf3_test.zig+9-9
......@@ -2,8 +2,8 @@
22//
33// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c
44
5const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64);
6const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64);
5const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
6const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
77
88const __multf3 = @import("mulXf3.zig").__multf3;
99
......@@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
3939}
4040
4141fn makeNaN128(rand: u64) f128 {
42 const int_result = u128(0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
42 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
4343 const float_result = @bitCast(f128, int_result);
4444 return float_result;
4545}
......@@ -55,15 +55,15 @@ test "multf3" {
5555
5656 // any * any
5757 test__multf3(
58 @bitCast(f128, u128(0x40042eab345678439abcdefea5678234)),
59 @bitCast(f128, u128(0x3ffeedcb34a235253948765432134675)),
58 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
59 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
6060 0x400423e7f9e3c9fc,
6161 0xd906c2c2a85777c4,
6262 );
6363
6464 test__multf3(
65 @bitCast(f128, u128(0x3fcd353e45674d89abacc3a2ebf3ff50)),
66 @bitCast(f128, u128(0x3ff6ed8764648369535adf4be3214568)),
65 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
66 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
6767 0x3fc52a163c6223fc,
6868 0xc94c4bf0430768b4,
6969 );
......@@ -76,8 +76,8 @@ test "multf3" {
7676 );
7777
7878 test__multf3(
79 @bitCast(f128, u128(0x3f154356473c82a9fabf2d22ace345df)),
80 @bitCast(f128, u128(0x3e38eda98765476743ab21da23d45679)),
79 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
80 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
8181 0x3d4f37c1a3137cae,
8282 0xfc6807048bc2836a,
8383 );
lib/std/special/compiler_rt/muldi3.zig+1-1
......@@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
2121 @setRuntimeSafety(builtin.is_test);
2222
2323 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
2626 var r: dwords = undefined;
2727 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;
66pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 {
77 @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)));
1010 const max = ~min;
1111
1212 overflow.* = 0;
lib/std/special/compiler_rt/mulodi4_test.zig+24-24
......@@ -52,34 +52,34 @@ test "mulodi4" {
5252
5353 test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
5454 test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
55 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, u64(0x8000000000000001)), 0);
56 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 0);
55 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
56 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
5757 test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
5858 test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
5959 test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
6060 test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
61 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, u64(0x8000000000000001)), 1);
62 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 1);
61 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(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);
65 test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);
66 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)), 1);
67 test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);
68 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 0, 0, 0);
69 test__mulodi4(0, @bitCast(i64, u64(0x8000000000000000)), 0, 0);
70 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)), 0);
71 test__mulodi4(1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 0);
72 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0x8000000000000000)), 1);
73 test__mulodi4(2, @bitCast(i64, u64(0x8000000000000000)), @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, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
66 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
67 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
68 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
69 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
70 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
71 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
72 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(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);
76 test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 1);
77 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
78 test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
79 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 0, 0, 0);
80 test__mulodi4(0, @bitCast(i64, u64(0x8000000000000001)), 0, 0);
81 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 1, @bitCast(i64, u64(0x8000000000000001)), 0);
82 test__mulodi4(1, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 0);
83 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 2, @bitCast(i64, u64(0x8000000000000000)), 1);
84 test__mulodi4(2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000000)), 1);
75 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
76 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
77 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
78 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
79 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
80 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
81 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
82 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
83 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
84 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
8585}
lib/std/special/compiler_rt/muloti4.zig+1-1
......@@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig");
44pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {
55 @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)));
88 const max = ~min;
99 overflow.* = 0;
1010
lib/std/special/compiler_rt/muloti4_test.zig+31-31
......@@ -39,38 +39,38 @@ test "muloti4" {
3939 test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
4040 test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
4141
42 test__muloti4(@bitCast(i128, u128(0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, u128(0x000000000000000000B504F333F9DE5B)), @bitCast(i128, u128(0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
43 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
44 test__muloti4(-2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
42 test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
43 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(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);
47 test__muloti4(-1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
48 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
49 test__muloti4(0, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
50 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
51 test__muloti4(1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
52 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
53 test__muloti4(2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
46 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
47 test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
48 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
49 test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
50 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
51 test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
52 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(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);
56 test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
57 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
58 test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
59 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0, 0);
60 test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0);
61 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0);
62 test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 0);
63 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
64 test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @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, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
57 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
58 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
59 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
60 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
61 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
62 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
63 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(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);
67 test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
68 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
69 test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
70 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0, 0);
71 test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0);
72 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
73 test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
74 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
75 test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
66 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
67 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
68 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
69 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
70 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
71 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
72 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
73 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
74 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
75 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
7676}
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 {
2121
2222fn __mulddi3(a: u64, b: u64) i128 {
2323 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;
2525 var r: twords = undefined;
2626 r.s.low = (a & lower_mask) *% (b & lower_mask);
2727 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 {
1515 const significandBits = std.math.floatMantissaBits(T);
1616 const exponentBits = std.math.floatExponentBits(T);
1717
18 const signBit = (Z(1) << (significandBits + exponentBits));
18 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1919
2020 return @bitCast(T, @bitCast(Z, a) ^ signBit);
2121}
lib/std/special/compiler_rt/popcountdi2_test.zig+3-3
......@@ -20,8 +20,8 @@ test "popcountdi2" {
2020 test__popcountdi2(0);
2121 test__popcountdi2(1);
2222 test__popcountdi2(2);
23 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFD)));
24 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFE)));
25 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFF)));
23 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
24 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
25 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
2626 // TODO some fuzz testing
2727}
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
6969 // destination format. We can convert by simply right-shifting with
7070 // rounding and adjusting the exponent.
7171 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
7474 const roundBits: src_rep_t = aAbs & roundMask;
7575 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 {
152152
153153test "trunctfsf2" {
154154 // qnan
155 test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000);
155 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
156156 // nan
157 test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);
157 test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);
158158 // inf
159 test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000);
159 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000);
160160 // zero
161161 test__trunctfsf2(0.0, 0x0);
162162
......@@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
187187
188188test "trunctfdf2" {
189189 // qnan
190 test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000);
190 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
191191 // nan
192 test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);
192 test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);
193193 // inf
194 test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000);
194 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);
195195 // zero
196196 test__trunctfdf2(0.0, 0x0);
197197
......@@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
224224
225225test "truncdfsf2" {
226226 // nan & qnan
227 test__truncdfsf2(@bitCast(f64, u64(0x7ff8000000000000)), 0x7fc00000);
228 test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000001)), 0x7fc00000);
227 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000);
228 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000);
229229 // inf
230 test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000000)), 0x7f800000);
231 test__truncdfsf2(@bitCast(f64, u64(0xfff0000000000000)), 0xff800000);
230 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000);
231 test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000);
232232
233233 test__truncdfsf2(0.0, 0x0);
234234 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:
7676 // K K
7777 // ---
7878 // 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])));
8080 // 0 <= sr <= SingleInt.bit_count - 2 or sr large
8181 if (sr > SingleInt.bit_count - 2) {
8282 if (maybe_rem) |rem| {
......@@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
114114 // K X
115115 // ---
116116 // 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]));
118118 // 2 <= sr <= DoubleInt.bit_count - 1
119119 // q.all = a << (DoubleInt.bit_count - sr);
120120 // r.all = a >> sr;
......@@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
140140 // K X
141141 // ---
142142 // 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])));
144144 // 0 <= sr <= SingleInt.bit_count - 1 or sr large
145145 if (sr > SingleInt.bit_count - 1) {
146146 if (maybe_rem) |rem| {
lib/std/target.zig+1-1
......@@ -581,7 +581,7 @@ pub const Target = union(enum) {
581581 };
582582
583583 pub fn getExternalExecutor(self: Target) Executor {
584 if (@TagType(Target)(self) == .Native) return .native;
584 if (@as(@TagType(Target),self) == .Native) return .native;
585585
586586 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
587587 if (self.getOs() == builtin.os) {
lib/std/thread.zig+1-1
......@@ -344,7 +344,7 @@ pub const Thread = struct {
344344 pub fn cpuCount() CpuCountError!usize {
345345 if (builtin.os == .linux) {
346346 const cpu_set = try os.sched_getaffinity(0);
347 return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
347 return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
348348 }
349349 if (builtin.os == .windows) {
350350 var system_info: windows.SYSTEM_INFO = undefined;
lib/std/time.zig+4-4
......@@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 {
3838 const hns_per_ms = (ns_per_s / 100) / ms_per_s;
3939 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;
4242 return @divFloor(ft64, hns_per_ms) - -epoch_adj;
4343 }
4444 if (builtin.os == .wasi and !builtin.link_libc) {
......@@ -142,10 +142,10 @@ pub const Timer = struct {
142142 // seccomp is going to block us it will at least do so consistently
143143 var ts: os.timespec = undefined;
144144 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
147147 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);
149149 }
150150
151151 return self;
......@@ -185,7 +185,7 @@ pub const Timer = struct {
185185 }
186186 var ts: os.timespec = undefined;
187187 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);
189189 }
190190};
191191
lib/std/unicode.zig+5-5
......@@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error
6868/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
6969pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 {
7070 return switch (bytes.len) {
71 1 => u32(bytes[0]),
71 1 => @as(u32, bytes[0]),
7272 2 => utf8Decode2(bytes),
7373 3 => utf8Decode3(bytes),
7474 4 => utf8Decode4(bytes),
......@@ -226,7 +226,7 @@ pub const Utf8Iterator = struct {
226226 const slice = it.nextCodepointSlice() orelse return null;
227227
228228 switch (slice.len) {
229 1 => return u32(slice[0]),
229 1 => return @as(u32, slice[0]),
230230 2 => return utf8Decode2(slice) catch unreachable,
231231 3 => return utf8Decode3(slice) catch unreachable,
232232 4 => return utf8Decode4(slice) catch unreachable,
......@@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct {
250250 assert(it.i <= it.bytes.len);
251251 if (it.i == it.bytes.len) return null;
252252 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) {
254254 // surrogate pair
255255 it.i += 2;
256256 if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf;
257257 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;
259259 it.i += 2;
260260 return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff));
261 } else if (c0 & ~u32(0x03ff) == 0xdc00) {
261 } else if (c0 & ~@as(u32, 0x03ff) == 0xdc00) {
262262 return error.UnexpectedSecondSurrogateHalf;
263263 } else {
264264 it.i += 2;
lib/std/valgrind.zig+1-1
......@@ -76,7 +76,7 @@ pub const ClientRequest = extern enum {
7676 InnerThreads = 6402,
7777};
7878pub 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);
8080}
8181pub fn IsTool(base: [2]u8, code: usize) bool {
8282 return ToolBase(base) == (code & 0xffff0000);
lib/std/zig/parse_string_literal.zig+1-1
......@@ -19,7 +19,7 @@ pub fn parseStringLiteral(
1919 bytes: []const u8,
2020 bad_index: *usize, // populated if error.InvalidCharacter is returned
2121) 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);
2323 assert(bytes[bytes.len - 1] == '"');
2424
2525 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" {
3737 \\test "" {
3838 \\ const result = while (returnError()) |value| {
3939 \\ break value;
40 \\ } else |err| i32(2);
40 \\ } else |err| @as(i32, 2);
4141 \\ expect(result == 2);
4242 \\}
4343 \\
lib/std/zig/render.zig+3-3
......@@ -410,8 +410,8 @@ fn renderExpression(
410410 switch (prefix_op_node.op) {
411411 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
412412 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {
413 Token.Id.AsteriskAsterisk => usize(1),
414 else => usize(0),
413 Token.Id.AsteriskAsterisk => @as(usize, 1),
414 else => @as(usize, 0),
415415 };
416416 try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // *
417417 if (ptr_info.allowzero_token) |allowzero_token| {
......@@ -2097,7 +2097,7 @@ fn renderTokenOffset(
20972097
20982098 while (true) {
20992099 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);
21012101 try stream.writeByteNTimes('\n', newline_count);
21022102 try stream.writeByteNTimes(' ', indent);
21032103 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 {
350350 };
351351 } else {
352352 // 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);
354354 return Tokenizer{
355355 .buffer = buffer,
356356 .index = src_start,
test/compare_output.zig+25-25
......@@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
122122 \\
123123 \\pub fn main() void {
124124 \\ 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;
126126 \\}
127127 , "Hello, world!\n 12 12 a\n");
128128
......@@ -166,54 +166,54 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
166166 \\ _ = c.printf(c"\n");
167167 \\
168168 \\ _ = c.printf(c"0.0: %.013a\n",
169 \\ f64(0.0));
169 \\ @as(f64, 0.0));
170170 \\ _ = c.printf(c"0e0: %.013a\n",
171 \\ f64(0e0));
171 \\ @as(f64, 0e0));
172172 \\ _ = c.printf(c"0.0e0: %.013a\n",
173 \\ f64(0.0e0));
173 \\ @as(f64, 0.0e0));
174174 \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
175 \\ f64(000000000000000000000000000000000000000000000000000000000.0e0));
175 \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0));
176176 \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
177 \\ f64(0.000000000000000000000000000000000000000000000000000000000e0));
177 \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0));
178178 \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
179 \\ f64(0.0e000000000000000000000000000000000000000000000000000000000));
179 \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000));
180180 \\ _ = c.printf(c"1.0: %.013a\n",
181 \\ f64(1.0));
181 \\ @as(f64, 1.0));
182182 \\ _ = c.printf(c"10.0: %.013a\n",
183 \\ f64(10.0));
183 \\ @as(f64, 10.0));
184184 \\ _ = c.printf(c"10.5: %.013a\n",
185 \\ f64(10.5));
185 \\ @as(f64, 10.5));
186186 \\ _ = c.printf(c"10.5e5: %.013a\n",
187 \\ f64(10.5e5));
187 \\ @as(f64, 10.5e5));
188188 \\ _ = c.printf(c"10.5e+5: %.013a\n",
189 \\ f64(10.5e+5));
189 \\ @as(f64, 10.5e+5));
190190 \\ _ = c.printf(c"50.0e-2: %.013a\n",
191 \\ f64(50.0e-2));
191 \\ @as(f64, 50.0e-2));
192192 \\ _ = c.printf(c"50e-2: %.013a\n",
193 \\ f64(50e-2));
193 \\ @as(f64, 50e-2));
194194 \\
195195 \\ _ = c.printf(c"\n");
196196 \\
197197 \\ _ = c.printf(c"0x1.0: %.013a\n",
198 \\ f64(0x1.0));
198 \\ @as(f64, 0x1.0));
199199 \\ _ = c.printf(c"0x10.0: %.013a\n",
200 \\ f64(0x10.0));
200 \\ @as(f64, 0x10.0));
201201 \\ _ = c.printf(c"0x100.0: %.013a\n",
202 \\ f64(0x100.0));
202 \\ @as(f64, 0x100.0));
203203 \\ _ = c.printf(c"0x103.0: %.013a\n",
204 \\ f64(0x103.0));
204 \\ @as(f64, 0x103.0));
205205 \\ _ = c.printf(c"0x103.7: %.013a\n",
206 \\ f64(0x103.7));
206 \\ @as(f64, 0x103.7));
207207 \\ _ = c.printf(c"0x103.70: %.013a\n",
208 \\ f64(0x103.70));
208 \\ @as(f64, 0x103.70));
209209 \\ _ = c.printf(c"0x103.70p4: %.013a\n",
210 \\ f64(0x103.70p4));
210 \\ @as(f64, 0x103.70p4));
211211 \\ _ = c.printf(c"0x103.70p5: %.013a\n",
212 \\ f64(0x103.70p5));
212 \\ @as(f64, 0x103.70p5));
213213 \\ _ = c.printf(c"0x103.70p+5: %.013a\n",
214 \\ f64(0x103.70p+5));
214 \\ @as(f64, 0x103.70p+5));
215215 \\ _ = c.printf(c"0x103.70p-5: %.013a\n",
216 \\ f64(0x103.70p-5));
216 \\ @as(f64, 0x103.70p-5));
217217 \\
218218 \\ return 0;
219219 \\}
......@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
323323 \\ const x: f64 = small;
324324 \\ const y = @floatToInt(i32, x);
325325 \\ 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));
327327 \\ return 0;
328328 \\}
329329 , "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 {
186186 cases.add(
187187 "shift amount has to be an integer type",
188188 \\export fn entry() void {
189 \\ const x = 1 << &u8(10);
189 \\ const x = 1 << &@as(u8, 10);
190190 \\}
191191 ,
192192 "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 {
196196 cases.add(
197197 "bit shifting only works on integer types",
198198 \\export fn entry() void {
199 \\ const x = &u8(1) << 10;
199 \\ const x = &@as(u8, 1) << 10;
200200 \\}
201201 ,
202202 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",
......@@ -241,7 +241,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
241241 \\ var x: []align(true) i32 = undefined;
242242 \\}
243243 \\export fn entry2() void {
244 \\ var x: *align(f64(12.34)) i32 = undefined;
244 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
245245 \\}
246246 ,
247247 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
......@@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12971297 cases.add(
12981298 "@truncate undefined value",
12991299 \\export fn entry() void {
1300 \\ var z = @truncate(u8, u16(undefined));
1300 \\ var z = @truncate(u8, @as(u16, undefined));
13011301 \\}
13021302 ,
13031303 "tmp.zig:2:30: error: use of undefined value here causes undefined behavior",
......@@ -1686,7 +1686,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16861686 cases.add(
16871687 "non float passed to @floatToInt",
16881688 \\export fn entry() void {
1689 \\ const x = @floatToInt(i32, i32(54));
1689 \\ const x = @floatToInt(i32, @as(i32, 54));
16901690 \\}
16911691 ,
16921692 "tmp.zig:2:35: error: expected float type, found 'i32'",
......@@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21972197 cases.add(
21982198 "error when evaluating return type",
21992199 \\const Foo = struct {
2200 \\ map: i32(i32),
2200 \\ map: @as(i32, i32),
22012201 \\
22022202 \\ fn init() Foo {
22032203 \\ return undefined;
......@@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23382338 cases.add(
23392339 "var not allowed in structs",
23402340 \\export fn entry() void {
2341 \\ var s = (struct{v: var}){.v=i32(10)};
2341 \\ var s = (struct{v: var}){.v=@as(i32, 10)};
23422342 \\}
23432343 ,
23442344 "tmp.zig:2:23: error: invalid token: 'var'",
......@@ -2657,7 +2657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26572657 cases.add(
26582658 "cast negative integer literal to usize",
26592659 \\export fn entry() void {
2660 \\ const x = usize(-10);
2660 \\ const x = @as(usize, -10);
26612661 \\}
26622662 ,
26632663 "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 {
33843384 \\ const x : i32 = if (b) h: { break :h 1; };
33853385 \\}
33863386 \\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); };
33883388 \\}
33893389 \\export fn entry() void { f(true); g(true); }
33903390 ,
......@@ -3520,7 +3520,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35203520 cases.add(
35213521 "cast unreachable",
35223522 \\fn f() i32 {
3523 \\ return i32(return 1);
3523 \\ return @as(i32, return 1);
35243524 \\}
35253525 \\export fn entry() void { _ = f(); }
35263526 ,
......@@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35953595 \\ switch (n) {
35963596 \\ Number.One => 1,
35973597 \\ Number.Two => 2,
3598 \\ Number.Three => i32(3),
3598 \\ Number.Three => @as(i32, 3),
35993599 \\ }
36003600 \\}
36013601 \\
......@@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36163616 \\ switch (n) {
36173617 \\ Number.One => 1,
36183618 \\ Number.Two => 2,
3619 \\ Number.Three => i32(3),
3619 \\ Number.Three => @as(i32, 3),
36203620 \\ Number.Four => 4,
36213621 \\ Number.Two => 2,
36223622 \\ }
......@@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36403640 \\ switch (n) {
36413641 \\ Number.One => 1,
36423642 \\ Number.Two => 2,
3643 \\ Number.Three => i32(3),
3643 \\ Number.Three => @as(i32, 3),
36443644 \\ Number.Four => 4,
36453645 \\ Number.Two => 2,
36463646 \\ else => 10,
......@@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36853685 "switch expression - duplicate or overlapping integer value",
36863686 \\fn foo(x: u8) u8 {
36873687 \\ return switch (x) {
3688 \\ 0 ... 100 => u8(0),
3688 \\ 0 ... 100 => @as(u8, 0),
36893689 \\ 101 ... 200 => 1,
36903690 \\ 201, 203 ... 207 => 2,
36913691 \\ 206 ... 255 => 3,
......@@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37223722 cases.add(
37233723 "array concatenation with wrong type",
37243724 \\const src = "aoeu";
3725 \\const derp = usize(1234);
3725 \\const derp = @as(usize, 1234);
37263726 \\const a = derp ++ "foo";
37273727 \\
37283728 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
......@@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38873887 "division by zero",
38883888 \\const lit_int_x = 1 / 0;
38893889 \\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);
38913891 \\const float_x = f32(1.0) / f32(0.0);
38923892 \\
38933893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
......@@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
45904590 \\var bytes: [ext()]u8 = undefined;
45914591 \\export fn f() void {
45924592 \\ for (bytes) |*b, i| {
4593 \\ b.* = u8(i);
4593 \\ b.* = @as(u8, i);
45944594 \\ }
45954595 \\}
45964596 ,
......@@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48744874 \\}
48754875 \\
48764876 \\fn foo() i32 {
4877 \\ return add(i32(1234));
4877 \\ return add(@as(i32, 1234));
48784878 \\}
48794879 \\
48804880 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
......@@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48864886 cases.add(
48874887 "pass integer literal to var args",
48884888 \\fn add(args: ...) i32 {
4889 \\ var sum = i32(0);
4889 \\ var sum = @as(i32, 0);
48904890 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
48914891 \\ sum += args[i];
48924892 \\ }}
......@@ -5581,7 +5581,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55815581 cases.add(
55825582 "explicit cast float literal to integer when there is a fraction component",
55835583 \\export fn entry() i32 {
5584 \\ return i32(12.34);
5584 \\ return @as(i32, 12.34);
55855585 \\}
55865586 ,
55875587 "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 {
55995599 cases.add(
56005600 "@shlExact shifts out 1 bits",
56015601 \\comptime {
5602 \\ const x = @shlExact(u8(0b01010101), 2);
5602 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
56035603 \\}
56045604 ,
56055605 "tmp.zig:2:15: error: operation caused overflow",
......@@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56085608 cases.add(
56095609 "@shrExact shifts out 1 bits",
56105610 \\comptime {
5611 \\ const x = @shrExact(u8(0b10101010), 2);
5611 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
56125612 \\}
56135613 ,
56145614 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
......@@ -5699,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56995699 cases.add(
57005700 "@alignCast expects pointer or slice",
57015701 \\export fn entry() void {
5702 \\ @alignCast(4, u32(3));
5702 \\ @alignCast(4, @as(u32, 3));
57035703 \\}
57045704 ,
57055705 "tmp.zig:2:22: error: expected pointer or slice, found 'u32'",
......@@ -5744,7 +5744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57445744 \\const Derp = @OpaqueType();
57455745 \\extern fn bar(d: *Derp) void;
57465746 \\export fn foo() void {
5747 \\ var x = u8(1);
5747 \\ var x = @as(u8, 1);
57485748 \\ bar(@ptrCast(*c_void, &x));
57495749 \\}
57505750 ,
......@@ -5800,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58005800 "wrong types given to atomic order args in cmpxchg",
58015801 \\export fn entry() void {
58025802 \\ 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))) {}
58045804 \\}
58055805 ,
58065806 "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
......@@ -5810,7 +5810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58105810 "wrong types given to @export",
58115811 \\extern fn entry() void { }
58125812 \\comptime {
5813 \\ @export("entry", entry, u32(1234));
5813 \\ @export("entry", entry, @as(u32, 1234));
58145814 \\}
58155815 ,
58165816 "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
test/stage1/behavior.zig+5-5
......@@ -1,7 +1,7 @@
11comptime {
2 _ = @import("behavior/align.zig");
2 //_ = @import("behavior/align.zig");
33 _ = @import("behavior/alignof.zig");
4 _ = @import("behavior/array.zig");
4 //_ = @import("behavior/array.zig");
55 _ = @import("behavior/asm.zig");
66 _ = @import("behavior/async_fn.zig");
77 _ = @import("behavior/atomics.zig");
......@@ -50,7 +50,7 @@ comptime {
5050 _ = @import("behavior/bugs/920.zig");
5151 _ = @import("behavior/byteswap.zig");
5252 _ = @import("behavior/byval_arg_var.zig");
53 _ = @import("behavior/cast.zig");
53 //_ = @import("behavior/cast.zig");
5454 _ = @import("behavior/const_slice_child.zig");
5555 _ = @import("behavior/defer.zig");
5656 _ = @import("behavior/enum.zig");
......@@ -59,7 +59,7 @@ comptime {
5959 _ = @import("behavior/eval.zig");
6060 _ = @import("behavior/field_parent_ptr.zig");
6161 _ = @import("behavior/floatop.zig");
62 _ = @import("behavior/fn.zig");
62 //_ = @import("behavior/fn.zig");
6363 _ = @import("behavior/fn_in_struct_in_comptime.zig");
6464 _ = @import("behavior/fn_delegation.zig");
6565 _ = @import("behavior/for.zig");
......@@ -73,7 +73,7 @@ comptime {
7373 _ = @import("behavior/ir_block_deps.zig");
7474 _ = @import("behavior/math.zig");
7575 _ = @import("behavior/merge_error_sets.zig");
76 _ = @import("behavior/misc.zig");
76 //_ = @import("behavior/misc.zig");
7777 _ = @import("behavior/muladd.zig");
7878 _ = @import("behavior/namespace_depends_on_compile_var.zig");
7979 _ = @import("behavior/new_stack_call.zig");
test/stage1/behavior/align.zig+2-2
......@@ -7,7 +7,7 @@ var foo: u8 align(4) = 100;
77test "global variable alignment" {
88 expect(@typeOf(&foo).alignment == 4);
99 expect(@typeOf(&foo) == *align(4) u8);
10 const slice = (*[1]u8)(&foo)[0..];
10 const slice = @as(*[1]u8, &foo)[0..];
1111 expect(@typeOf(slice) == []align(4) u8);
1212}
1313
......@@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
6161test "implicitly decreasing slice alignment" {
6262 const a: u32 align(4) = 3;
6363 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);
6565}
6666fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
6767 return a[0] + b[0];
test/stage1/behavior/array.zig+2-2
......@@ -12,7 +12,7 @@ test "arrays" {
1212 }
1313
1414 i = 0;
15 var accumulator = u32(0);
15 var accumulator = @as(u32, 0);
1616 while (i < 5) {
1717 accumulator += array[i];
1818
......@@ -149,7 +149,7 @@ test "implicit cast single-item pointer" {
149149
150150fn testImplicitCastSingleItemPtr() void {
151151 var byte: u8 = 100;
152 const slice = (*[1]u8)(&byte)[0..];
152 const slice = @as(*[1]u8, &byte)[0..];
153153 slice[0] += 1;
154154 expect(byte == 101);
155155}
test/stage1/behavior/asm.zig+8-8
......@@ -45,42 +45,42 @@ test "alternative constraints" {
4545test "sized integer/float in asm input" {
4646 asm volatile (""
4747 :
48 : [_] "m" (usize(3))
48 : [_] "m" (@as(usize, 3))
4949 : ""
5050 );
5151 asm volatile (""
5252 :
53 : [_] "m" (i15(-3))
53 : [_] "m" (@as(i15, -3))
5454 : ""
5555 );
5656 asm volatile (""
5757 :
58 : [_] "m" (u3(3))
58 : [_] "m" (@as(u3, 3))
5959 : ""
6060 );
6161 asm volatile (""
6262 :
63 : [_] "m" (i3(3))
63 : [_] "m" (@as(i3, 3))
6464 : ""
6565 );
6666 asm volatile (""
6767 :
68 : [_] "m" (u121(3))
68 : [_] "m" (@as(u121, 3))
6969 : ""
7070 );
7171 asm volatile (""
7272 :
73 : [_] "m" (i121(3))
73 : [_] "m" (@as(i121, 3))
7474 : ""
7575 );
7676 asm volatile (""
7777 :
78 : [_] "m" (f32(3.17))
78 : [_] "m" (@as(f32, 3.17))
7979 : ""
8080 );
8181 asm volatile (""
8282 :
83 : [_] "m" (f64(3.17))
83 : [_] "m" (@as(f64, 3.17))
8484 : ""
8585 );
8686}
test/stage1/behavior/async_fn.zig+5-5
......@@ -191,7 +191,7 @@ async fn testSuspendBlock() void {
191191
192192 // Test to make sure that @frame() works as advertised (issue #1296)
193193 // var our_handle: anyframe = @frame();
194 expect(a_promise == anyframe(@frame()));
194 expect(a_promise == @as(anyframe, @frame()));
195195
196196 global_result = true;
197197}
......@@ -543,7 +543,7 @@ test "pass string literal to async function" {
543543 fn hello(msg: []const u8) void {
544544 frame = @frame();
545545 suspend;
546 expectEqual(([]const u8)("hello"), msg);
546 expectEqual(@as([]const u8, "hello"), msg);
547547 ok = true;
548548 }
549549 };
......@@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" {
10481048 return await @asyncCall(frame, {}, amain, x - 1);
10491049 }
10501050 };
1051 _ = async S.amain(u32(1));
1051 _ = async S.amain(@as(u32, 1));
10521052 resume S.global_frame;
10531053 expect(S.global_ok);
10541054}
......@@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" {
10801080 };
10811081 };
10821082 var res: S.Foo = undefined;
1083 var frame: @typeOf(async S.amain(u32(1))) = undefined;
1084 _ = @asyncCall(&frame, &res, S.amain, u32(1));
1083 var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined;
1084 _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1));
10851085 resume S.global_frame;
10861086 expect(S.global_ok);
10871087 expect(res.x == 1);
test/stage1/behavior/atomics.zig+3-3
......@@ -98,12 +98,12 @@ test "cmpxchg with ignored result" {
9898
9999 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
100100
101 expectEqual(i32(5678), x);
101 expectEqual(@as(i32, 5678), x);
102102}
103103
104var a_global_variable = u32(1234);
104var a_global_variable = @as(u32, 1234);
105105
106106test "cmpxchg on a global variable" {
107107 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
108 expectEqual(u32(42), a_global_variable);
108 expectEqual(@as(u32, 42), a_global_variable);
109109}
test/stage1/behavior/bitreverse.zig+14-14
......@@ -46,24 +46,24 @@ fn testBitReverse() void {
4646 expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
4848 // using comptime_ints, signed, positive
49 expect(@bitReverse(u8, u8(0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));
51 expect(@bitReverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));
52 expect(@bitReverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));
53 expect(@bitReverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));
54 expect(@bitReverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));
55 expect(@bitReverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));
56 expect(@bitReverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));
57 expect(@bitReverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));
58 expect(@bitReverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));
49 expect(@bitReverse(u8, @as(u8, 0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
51 expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
52 expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
53 expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
54 expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
55 expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
56 expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
57 expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
58 expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
5959
6060 // using signed, negative. Compare to runtime ints returned from llvm.
6161 var neg8: i8 = -18;
62 expect(@bitReverse(i8, i8(-18)) == @bitReverse(i8, neg8));
62 expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
6363 var neg16: i16 = -32694;
64 expect(@bitReverse(i16, i16(-32694)) == @bitReverse(i16, neg16));
64 expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
6565 var neg24: i24 = -6773785;
66 expect(@bitReverse(i24, i24(-6773785)) == @bitReverse(i24, neg24));
66 expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
6767 var neg32: i32 = -16773785;
68 expect(@bitReverse(i32, i32(-16773785)) == @bitReverse(i32, neg32));
68 expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
6969}
test/stage1/behavior/bool.zig+4-4
......@@ -8,14 +8,14 @@ test "bool literals" {
88test "cast bool to int" {
99 const t = true;
1010 const f = false;
11 expect(@boolToInt(t) == u32(1));
12 expect(@boolToInt(f) == u32(0));
11 expect(@boolToInt(t) == @as(u32, 1));
12 expect(@boolToInt(f) == @as(u32, 0));
1313 nonConstCastBoolToInt(t, f);
1414}
1515
1616fn nonConstCastBoolToInt(t: bool, f: bool) void {
17 expect(@boolToInt(t) == u32(1));
18 expect(@boolToInt(f) == u32(0));
17 expect(@boolToInt(t) == @as(u32, 1));
18 expect(@boolToInt(f) == @as(u32, 0));
1919}
2020
2121test "bool cmp" {
test/stage1/behavior/bugs/1322.zig+2-2
......@@ -13,7 +13,7 @@ const C = struct {};
1313
1414test "tagged union with all void fields but a meaningful tag" {
1515 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);
1717 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);
1919}
test/stage1/behavior/bugs/1421.zig+1-1
......@@ -10,5 +10,5 @@ const S = struct {
1010
1111test "functions with return type required to be comptime are generic" {
1212 const ti = S.method();
13 expect(builtin.TypeId(ti) == builtin.TypeId.Struct);
13 expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct);
1414}
test/stage1/behavior/bugs/2114.zig+4-4
......@@ -12,8 +12,8 @@ test "fixed" {
1212}
1313
1414fn testClz() void {
15 expect(ctz(u128(0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1)) == u128(0x80000000000000000000000000000000));
17 expect(ctz(u128(0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1))) == 127);
15 expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
17 expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
1919}
test/stage1/behavior/bugs/3046.zig+1-1
......@@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined;
1313
1414test "fixed" {
1515 some_struct = SomeStruct{
16 .field = couldFail() catch |_| i32(0),
16 .field = couldFail() catch |_| @as(i32, 0),
1717 };
1818 expect(some_struct.field == 1);
1919}
test/stage1/behavior/byteswap.zig+12-12
......@@ -11,24 +11,24 @@ test "@byteSwap integers" {
1111 t(u24, 0x123456, 0x563412);
1212 t(u32, 0x12345678, 0x78563412);
1313 t(u40, 0x123456789a, 0x9a78563412);
14 t(i48, 0x123456789abc, @bitCast(i48, u48(0xbc9a78563412)));
14 t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
1515 t(u56, 0x123456789abcde, 0xdebc9a78563412);
1616 t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
1717 t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
1818
19 t(u0, u0(0), 0);
20 t(i8, i8(-50), -50);
21 t(i16, @bitCast(i16, u16(0x1234)), @bitCast(i16, u16(0x3412)));
22 t(i24, @bitCast(i24, u24(0x123456)), @bitCast(i24, u24(0x563412)));
23 t(i32, @bitCast(i32, u32(0x12345678)), @bitCast(i32, u32(0x78563412)));
24 t(u40, @bitCast(i40, u40(0x123456789a)), u40(0x9a78563412));
25 t(i48, @bitCast(i48, u48(0x123456789abc)), @bitCast(i48, u48(0xbc9a78563412)));
26 t(i56, @bitCast(i56, u56(0x123456789abcde)), @bitCast(i56, u56(0xdebc9a78563412)));
27 t(i64, @bitCast(i64, u64(0x123456789abcdef1)), @bitCast(i64, u64(0xf1debc9a78563412)));
19 t(u0, @as(u0, 0), 0);
20 t(i8, @as(i8, -50), -50);
21 t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
22 t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
23 t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
24 t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
25 t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
26 t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
27 t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
2828 t(
2929 i128,
30 @bitCast(i128, u128(0x123456789abcdef11121314151617181)),
31 @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)),
30 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
31 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
3232 );
3333 }
3434 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;
44const maxInt = std.math.maxInt;
55
66test "int to ptr cast" {
7 const x = usize(13);
7 const x = @as(usize, 13);
88 const y = @intToPtr(*u8, x);
99 const z = @ptrToInt(y);
1010 expect(z == 13);
......@@ -90,7 +90,7 @@ const A = struct {
9090 a: i32,
9191};
9292fn castToOptionalTypeError(z: i32) void {
93 const x = i32(1);
93 const x = @as(i32, 1);
9494 const y: anyerror!?i32 = x;
9595 expect((try y).? == 1);
9696
......@@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" {
134134}
135135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
136136 if (c) {
137 return if (b) null else usize(0);
137 return if (b) null else @as(usize, 0);
138138 }
139139
140 return usize(3);
140 return @as(usize, 3);
141141}
142142
143143test "peer type resolution: [0]u8 and []const u8" {
......@@ -256,7 +256,7 @@ test "@floatToInt" {
256256}
257257
258258fn testFloatToInts() void {
259 const x = i32(1e4);
259 const x = @as(i32, 1e4);
260260 expect(x == 10000);
261261 const y = @floatToInt(i32, f32(1e4));
262262 expect(y == 10000);
......@@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
442442}
443443
444444test "*usize to *void" {
445 var i = usize(0);
445 var i = @as(usize, 0);
446446 var v = @ptrCast(*void, &i);
447447 v.* = {};
448448}
test/stage1/behavior/defer.zig+1-1
......@@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void {
5252}
5353
5454test "defer and labeled break" {
55 var i = usize(0);
55 var i = @as(usize, 0);
5656
5757 blk: {
5858 defer i += 1;
test/stage1/behavior/enum.zig+2-2
......@@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
788788 expect(1234 == switch (x) {
789789 MultipleChoice.A => 1,
790790 MultipleChoice.B => 2,
791 MultipleChoice.C => u32(1234),
791 MultipleChoice.C => @as(u32, 1234),
792792 MultipleChoice.D => 4,
793793 });
794794}
......@@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
816816 MultipleChoice2.A => 1,
817817 MultipleChoice2.B => 2,
818818 MultipleChoice2.C => 3,
819 MultipleChoice2.D => u32(1234),
819 MultipleChoice2.D => @as(u32, 1234),
820820 MultipleChoice2.Unspecified1 => 5,
821821 MultipleChoice2.Unspecified2 => 6,
822822 MultipleChoice2.Unspecified3 => 7,
test/stage1/behavior/error.zig+2-2
......@@ -51,7 +51,7 @@ test "error binary operator" {
5151 expect(b == 10);
5252}
5353fn errBinaryOperatorG(x: bool) anyerror!isize {
54 return if (x) error.ItBroke else isize(10);
54 return if (x) error.ItBroke else @as(isize, 10);
5555}
5656
5757test "unwrap simple value from error" {
......@@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" {
295295test "widen cast integer payload of error union function call" {
296296 const S = struct {
297297 fn errorable() !u64 {
298 var x = u64(try number());
298 var x = @as(u64, try number());
299299 return x;
300300 }
301301
test/stage1/behavior/eval.zig+18-18
......@@ -405,19 +405,19 @@ test "float literal at compile time not lossy" {
405405}
406406
407407test "f32 at compile time is lossy" {
408 expect(f32(1 << 24) + 1 == 1 << 24);
408 expect(@as(f32, 1 << 24) + 1 == 1 << 24);
409409}
410410
411411test "f64 at compile time is lossy" {
412 expect(f64(1 << 53) + 1 == 1 << 53);
412 expect(@as(f64, 1 << 53) + 1 == 1 << 53);
413413}
414414
415415test "f128 at compile time is lossy" {
416 expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
416 expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
417417}
418418
419419comptime {
420 expect(f128(1 << 113) == 10384593717069655257060992658440192);
420 expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
421421}
422422
423423pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
......@@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" {
434434}
435435
436436test "comptime slice of undefined pointer of length 0" {
437 const slice1 = ([*]i32)(undefined)[0..0];
437 const slice1 = @as([*]i32, undefined)[0..0];
438438 expect(slice1.len == 0);
439 const slice2 = ([*]i32)(undefined)[100..100];
439 const slice2 = @as([*]i32, undefined)[100..100];
440440 expect(slice2.len == 0);
441441}
442442
......@@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void {
444444 comptime var i: usize = 0;
445445 inline while (i < 4) : (i += 1) {
446446 s[i] = 0;
447 s[i] |= u32(b[i * 4 + 0]) << 24;
448 s[i] |= u32(b[i * 4 + 1]) << 16;
449 s[i] |= u32(b[i * 4 + 2]) << 8;
450 s[i] |= u32(b[i * 4 + 3]) << 0;
447 s[i] |= @as(u32, b[i * 4 + 0]) << 24;
448 s[i] |= @as(u32, b[i * 4 + 1]) << 16;
449 s[i] |= @as(u32, b[i * 4 + 2]) << 8;
450 s[i] |= @as(u32, b[i * 4 + 3]) << 0;
451451 }
452452}
453453
......@@ -557,14 +557,14 @@ test "array concat of slices gives slice" {
557557
558558test "comptime shlWithOverflow" {
559559 const ct_shifted: u64 = comptime amt: {
560 var amt = u64(0);
561 _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);
560 var amt = @as(u64, 0);
561 _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt);
562562 break :amt amt;
563563 };
564564
565565 const rt_shifted: u64 = amt: {
566 var amt = u64(0);
567 _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);
566 var amt = @as(u64, 0);
567 _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt);
568568 break :amt amt;
569569 };
570570
......@@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void {
670670}
671671
672672test "variable inside inline loop that has different types on different iterations" {
673 testVarInsideInlineLoop(true, u32(42));
673 testVarInsideInlineLoop(true, @as(u32, 42));
674674}
675675
676676fn testVarInsideInlineLoop(args: ...) void {
......@@ -757,11 +757,11 @@ test "comptime bitwise operators" {
757757 expect(-3 | -1 == -1);
758758 expect(3 ^ -1 == -4);
759759 expect(-3 ^ -1 == 2);
760 expect(~i8(-1) == 0);
761 expect(~i128(-1) == 0);
760 expect(~@as(i8, -1) == 0);
761 expect(~@as(i128, -1) == 0);
762762 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
763763 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
764 expect(~u128(0) == 0xffffffffffffffffffffffffffffffff);
764 expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
765765 }
766766}
767767
test/stage1/behavior/floatop.zig+2-2
......@@ -117,11 +117,11 @@ test "@ln" {
117117fn testLn() void {
118118 {
119119 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)));
121121 }
122122 {
123123 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)));
125125 }
126126}
127127
test/stage1/behavior/fn.zig+2-2
......@@ -29,7 +29,7 @@ test "mutable local variables" {
2929 var zero: i32 = 0;
3030 expect(zero == 0);
3131
32 var i = i32(0);
32 var i = @as(i32, 0);
3333 while (i != 3) {
3434 i += 1;
3535 }
......@@ -43,7 +43,7 @@ test "separate block scopes" {
4343 }
4444
4545 const c = x: {
46 const no_conflict = i32(10);
46 const no_conflict = @as(i32, 10);
4747 break :x no_conflict;
4848 };
4949 expect(c == 10);
test/stage1/behavior/if.zig+2-2
......@@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 {
3232 } else if (c == 1) {
3333 return 1;
3434 } else {
35 return u8(2);
35 return @as(u8, 2);
3636 }
3737}
3838
......@@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" {
5858 var c = true;
5959 if (c) {
6060 answer = if (true) blk: {
61 break :blk i32(42);
61 break :blk @as(i32, 42);
6262 };
6363 }
6464 expect(answer == 42);
test/stage1/behavior/import.zig+2-2
......@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;
33const a_namespace = @import("import/a_namespace.zig");
44
55test "call fn via namespace lookup" {
6 expectEqual(i32(1234), a_namespace.foo());
6 expectEqual(@as(i32, 1234), a_namespace.foo());
77}
88
99test "importing the same thing gives the same import" {
......@@ -14,5 +14,5 @@ test "import in non-toplevel scope" {
1414 const S = struct {
1515 usingnamespace @import("import/a_namespace.zig");
1616 };
17 expectEqual(i32(1234), S.foo());
17 expectEqual(@as(i32, 1234), S.foo());
1818}
test/stage1/behavior/math.zig+12-12
......@@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void {
186186 assertFalse(90 >> 1 >> 2 != 90 >> 3);
187187 assertFalse(100 - 1 + 1000 != 1099);
188188 assertFalse(5 * 4 / 2 % 3 != 1);
189 assertFalse(i32(i32(5)) != 5);
189 assertFalse(@as(i32, @as(i32, 5)) != 5);
190190 assertFalse(!!false);
191 assertFalse(i32(7) != --(i32(7)));
191 assertFalse(@as(i32, 7) != --(@as(i32, 7)));
192192}
193193fn assertFalse(b: bool) void {
194194 expect(!b);
......@@ -256,10 +256,10 @@ const DivResult = struct {
256256
257257test "binary not" {
258258 expect(comptime x: {
259 break :x ~u16(0b1010101010101010) == 0b0101010101010101;
259 break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;
260260 });
261261 expect(comptime x: {
262 break :x ~u64(2147483647) == 18446744071562067968;
262 break :x ~@as(u64, 2147483647) == 18446744071562067968;
263263 });
264264 testBinaryNot(0b1010101010101010);
265265}
......@@ -472,7 +472,7 @@ test "comptime_int multiplication" {
472472
473473test "comptime_int shifting" {
474474 comptime {
475 expect((u128(1) << 127) == 0x80000000000000000000000000000000);
475 expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
476476 }
477477}
478478
......@@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" {
480480 comptime {
481481 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
482482
483 expect(u32(a & 0xffffffff) == 0xaaaaaaab);
483 expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
484484 a >>= 32;
485 expect(u32(a & 0xffffffff) == 0xeeeeeeef);
485 expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
486486 a >>= 32;
487 expect(u32(a & 0xffffffff) == 0xa0000001);
487 expect(@as(u32, a & 0xffffffff) == 0xa0000001);
488488 a >>= 32;
489 expect(u32(a & 0xffffffff) == 0xefffffff);
489 expect(@as(u32, a & 0xffffffff) == 0xefffffff);
490490 a >>= 32;
491491
492492 expect(a == 0);
......@@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void {
552552
553553test "comptime float rem int" {
554554 comptime {
555 var x = f32(1) % 2;
555 var x = @as(f32, 1) % 2;
556556 expect(x == 1.0);
557557 }
558558}
......@@ -568,8 +568,8 @@ test "remainder division" {
568568}
569569
570570fn remdiv(comptime T: type) void {
571 expect(T(1) == T(1) % T(2));
572 expect(T(1) == T(7) % T(3));
571 expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
572 expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
573573}
574574
575575test "@sqrt" {
test/stage1/behavior/misc.zig+3-3
......@@ -268,7 +268,7 @@ fn outer() i64 {
268268}
269269
270270test "pointer dereferencing" {
271 var x = i32(3);
271 var x = @as(i32, 3);
272272 const y = &x;
273273
274274 y.* += 1;
......@@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type {
500500}
501501
502502test "double implicit cast in same expression" {
503 var x = i32(u16(nine()));
503 var x = @as(i32, @as(u16, nine()));
504504 expect(x == 9);
505505}
506506fn nine() u8 {
......@@ -761,7 +761,7 @@ test "nested optional field in struct" {
761761
762762fn maybe(x: bool) anyerror!?u32 {
763763 return switch (x) {
764 true => u32(42),
764 true => @as(u32, 42),
765765 else => null,
766766 };
767767}
test/stage1/behavior/popcount.zig+1-1
......@@ -35,7 +35,7 @@ fn testPopCount() void {
3535 expect(@popCount(i8, x) == 2);
3636 }
3737 comptime {
38 expect(@popCount(u8, @bitCast(u8, i8(-120))) == 2);
38 expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
3939 }
4040 comptime {
4141 expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
test/stage1/behavior/pub_enum.zig+1-1
......@@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void {
99}
1010
1111test "cast with imported symbol" {
12 expect(other.size_t(42) == 42);
12 expect(@as(other.size_t, 42) == 42);
1313}
test/stage1/behavior/shuffle.zig+13-13
......@@ -7,39 +7,39 @@ test "@shuffle" {
77 fn doTheTest() void {
88 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
99 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) };
1111 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
1414 // Implicit cast from array (of mask)
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~i32(2), 3, ~i32(3) });
16 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 }));
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
1717
1818 // Undefined
1919 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
2020 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
2323 // Upcasting of b
2424 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 };
2626 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
2929 // Upcasting of a
3030 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) };
3232 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
3535 // bool
3636 // Disabled because of #3317
3737 if (@import("builtin").arch != .mipsel) {
3838 var x2: @Vector(4, bool) = [4]bool{ false, true, false, true };
3939 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 };
4141 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 }));
4343 }
4444
4545 // TODO re-enable when LLVM codegen is fixed
......@@ -47,9 +47,9 @@ test "@shuffle" {
4747 if (false) {
4848 var x2: @Vector(3, bool) = [3]bool{ false, true, false };
4949 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 };
5151 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 }));
5353 }
5454 }
5555 };
test/stage1/behavior/slicetobytes.zig+1-1
......@@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" {
1010 const S = struct {
1111 fn doTheTest() void {
1212 var foo: Foo = undefined;
13 var slice = @sliceToBytes(((*[1]Foo)(&foo))[0..1]);
13 var slice = @sliceToBytes(@as(*[1]Foo, &foo)[0..1]);
1414 slice[0] = 0x13;
1515 switch (builtin.endian) {
1616 builtin.Endian.Big => {
test/stage1/behavior/struct.zig+8-8
......@@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" {
388388 expect(s2.y == @intCast(u4, x2));
389389}
390390
391var x1 = u4(1);
392var x2 = u8(2);
391var x1 = @as(u4, 1);
392var x2 = @as(u8, 2);
393393
394394const Nibbles = packed struct {
395395 x: u4,
......@@ -545,9 +545,9 @@ test "packed struct with fp fields" {
545545 s.data[1] = 2.0;
546546 s.data[2] = 3.0;
547547 s.frob();
548 expectEqual(f32(6.0), s.data[0]);
549 expectEqual(f32(11.0), s.data[1]);
550 expectEqual(f32(20.0), s.data[2]);
548 expectEqual(@as(f32, 6.0), s.data[0]);
549 expectEqual(@as(f32, 11.0), s.data[1]);
550 expectEqual(@as(f32, 20.0), s.data[2]);
551551}
552552
553553test "use within struct scope" {
......@@ -558,7 +558,7 @@ test "use within struct scope" {
558558 }
559559 };
560560 };
561 expectEqual(i32(42), S.inner());
561 expectEqual(@as(i32, 42), S.inner());
562562}
563563
564564test "default struct initialization fields" {
......@@ -583,7 +583,7 @@ test "extern fn returns struct by value" {
583583 const S = struct {
584584 fn entry() void {
585585 var x = makeBar(10);
586 expectEqual(i32(10), x.handle);
586 expectEqual(@as(i32, 10), x.handle);
587587 }
588588
589589 const ExternBar = extern struct {
......@@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {
614614
615615 const ArrayList = struct {
616616 fn toSlice(self: *ArrayList) []*Foo {
617 return ([*]*Foo)(undefined)[0..0];
617 return @as([*]*Foo, undefined)[0..0];
618618 }
619619 };
620620
test/stage1/behavior/switch.zig+4-4
......@@ -68,7 +68,7 @@ test "switch statement" {
6868}
6969fn nonConstSwitch(foo: SwitchStatmentFoo) void {
7070 const val = switch (foo) {
71 SwitchStatmentFoo.A => i32(1),
71 SwitchStatmentFoo.A => @as(i32, 1),
7272 SwitchStatmentFoo.B => 2,
7373 SwitchStatmentFoo.C => 3,
7474 SwitchStatmentFoo.D => 4,
......@@ -127,7 +127,7 @@ test "switch with multiple expressions" {
127127 const x = switch (returnsFive()) {
128128 1, 2, 3 => 1,
129129 4, 5, 6 => 2,
130 else => i32(3),
130 else => @as(i32, 3),
131131 };
132132 expect(x == 2);
133133}
......@@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void {
186186
187187fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
188188 return switch (x) {
189 0 => u2(3),
189 0 => @as(u2, 3),
190190 1 => 2,
191191 2 => 1,
192192 3 => 0,
......@@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
195195
196196fn testSwitchHandleAllCasesRange(x: u8) u8 {
197197 return switch (x) {
198 0...100 => u8(0),
198 0...100 => @as(u8, 0),
199199 101...200 => 1,
200200 201, 203 => 2,
201201 202 => 4,
test/stage1/behavior/try.zig+3-3
......@@ -8,7 +8,7 @@ test "try on error union" {
88fn tryOnErrorUnionImpl() void {
99 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
1010 error.ItBroke, error.NoMem => 1,
11 error.CrappedOut => i32(2),
11 error.CrappedOut => @as(i32, 2),
1212 else => unreachable,
1313 };
1414 expect(x == 11);
......@@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 {
1919}
2020
2121test "try without vars" {
22 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);
22 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
2323 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);
2626 expect(result2 == 1);
2727}
2828
test/stage1/behavior/type_info.zig+23-23
......@@ -13,7 +13,7 @@ test "type info: tag type, void info" {
1313fn testBasic() void {
1414 expect(@TagType(TypeInfo) == TypeId);
1515 const void_info = @typeInfo(void);
16 expect(TypeId(void_info) == TypeId.Void);
16 expect(@as(TypeId, void_info) == TypeId.Void);
1717 expect(void_info.Void == {});
1818}
1919
......@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {
2424
2525fn testIntFloat() void {
2626 const u8_info = @typeInfo(u8);
27 expect(TypeId(u8_info) == TypeId.Int);
27 expect(@as(TypeId, u8_info) == TypeId.Int);
2828 expect(!u8_info.Int.is_signed);
2929 expect(u8_info.Int.bits == 8);
3030
3131 const f64_info = @typeInfo(f64);
32 expect(TypeId(f64_info) == TypeId.Float);
32 expect(@as(TypeId, f64_info) == TypeId.Float);
3333 expect(f64_info.Float.bits == 64);
3434}
3535
......@@ -40,7 +40,7 @@ test "type info: pointer type info" {
4040
4141fn testPointer() void {
4242 const u32_ptr_info = @typeInfo(*u32);
43 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
43 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);
4444 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
4545 expect(u32_ptr_info.Pointer.is_const == false);
4646 expect(u32_ptr_info.Pointer.is_volatile == false);
......@@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" {
5555
5656fn testUnknownLenPtr() void {
5757 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);
5959 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
6060 expect(u32_ptr_info.Pointer.is_const == true);
6161 expect(u32_ptr_info.Pointer.is_volatile == true);
......@@ -70,7 +70,7 @@ test "type info: C pointer type info" {
7070
7171fn testCPtr() void {
7272 const ptr_info = @typeInfo([*c]align(4) const i8);
73 expect(TypeId(ptr_info) == TypeId.Pointer);
73 expect(@as(TypeId,ptr_info) == TypeId.Pointer);
7474 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);
7575 expect(ptr_info.Pointer.is_const);
7676 expect(!ptr_info.Pointer.is_volatile);
......@@ -85,7 +85,7 @@ test "type info: slice type info" {
8585
8686fn testSlice() void {
8787 const u32_slice_info = @typeInfo([]u32);
88 expect(TypeId(u32_slice_info) == TypeId.Pointer);
88 expect(@as(TypeId, u32_slice_info) == TypeId.Pointer);
8989 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
9090 expect(u32_slice_info.Pointer.is_const == false);
9191 expect(u32_slice_info.Pointer.is_volatile == false);
......@@ -100,7 +100,7 @@ test "type info: array type info" {
100100
101101fn testArray() void {
102102 const arr_info = @typeInfo([42]bool);
103 expect(TypeId(arr_info) == TypeId.Array);
103 expect(@as(TypeId, arr_info) == TypeId.Array);
104104 expect(arr_info.Array.len == 42);
105105 expect(arr_info.Array.child == bool);
106106}
......@@ -112,7 +112,7 @@ test "type info: optional type info" {
112112
113113fn testOptional() void {
114114 const null_info = @typeInfo(?void);
115 expect(TypeId(null_info) == TypeId.Optional);
115 expect(@as(TypeId, null_info) == TypeId.Optional);
116116 expect(null_info.Optional.child == void);
117117}
118118
......@@ -129,18 +129,18 @@ fn testErrorSet() void {
129129 };
130130
131131 const error_set_info = @typeInfo(TestErrorSet);
132 expect(TypeId(error_set_info) == TypeId.ErrorSet);
132 expect(@as(TypeId, error_set_info) == TypeId.ErrorSet);
133133 expect(error_set_info.ErrorSet.?.len == 3);
134134 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
135135 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));
136136
137137 const error_union_info = @typeInfo(TestErrorSet!usize);
138 expect(TypeId(error_union_info) == TypeId.ErrorUnion);
138 expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion);
139139 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
140140 expect(error_union_info.ErrorUnion.payload == usize);
141141
142142 const global_info = @typeInfo(anyerror);
143 expect(TypeId(global_info) == TypeId.ErrorSet);
143 expect(@as(TypeId, global_info) == TypeId.ErrorSet);
144144 expect(global_info.ErrorSet == null);
145145}
146146
......@@ -158,7 +158,7 @@ fn testEnum() void {
158158 };
159159
160160 const os_info = @typeInfo(Os);
161 expect(TypeId(os_info) == TypeId.Enum);
161 expect(@as(TypeId, os_info) == TypeId.Enum);
162162 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
163163 expect(os_info.Enum.fields.len == 4);
164164 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
......@@ -174,7 +174,7 @@ test "type info: union info" {
174174
175175fn testUnion() void {
176176 const typeinfo_info = @typeInfo(TypeInfo);
177 expect(TypeId(typeinfo_info) == TypeId.Union);
177 expect(@as(TypeId, typeinfo_info) == TypeId.Union);
178178 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
179179 expect(typeinfo_info.Union.tag_type.? == TypeId);
180180 expect(typeinfo_info.Union.fields.len == 26);
......@@ -189,7 +189,7 @@ fn testUnion() void {
189189 };
190190
191191 const notag_union_info = @typeInfo(TestNoTagUnion);
192 expect(TypeId(notag_union_info) == TypeId.Union);
192 expect(@as(TypeId, notag_union_info) == TypeId.Union);
193193 expect(notag_union_info.Union.tag_type == null);
194194 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);
195195 expect(notag_union_info.Union.fields.len == 2);
......@@ -214,7 +214,7 @@ test "type info: struct info" {
214214
215215fn testStruct() void {
216216 const struct_info = @typeInfo(TestStruct);
217 expect(TypeId(struct_info) == TypeId.Struct);
217 expect(@as(TypeId, struct_info) == TypeId.Struct);
218218 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
219219 expect(struct_info.Struct.fields.len == 3);
220220 expect(struct_info.Struct.fields[1].offset == null);
......@@ -244,7 +244,7 @@ test "type info: function type info" {
244244
245245fn testFunction() void {
246246 const fn_info = @typeInfo(@typeOf(foo));
247 expect(TypeId(fn_info) == TypeId.Fn);
247 expect(@as(TypeId, fn_info) == TypeId.Fn);
248248 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
249249 expect(fn_info.Fn.is_generic);
250250 expect(fn_info.Fn.args.len == 2);
......@@ -253,7 +253,7 @@ fn testFunction() void {
253253
254254 const test_instance: TestStruct = undefined;
255255 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);
257257 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
258258}
259259
......@@ -275,7 +275,7 @@ test "type info: vectors" {
275275
276276fn testVector() void {
277277 const vec_info = @typeInfo(@Vector(4, i32));
278 expect(TypeId(vec_info) == TypeId.Vector);
278 expect(@as(TypeId, vec_info) == TypeId.Vector);
279279 expect(vec_info.Vector.len == 4);
280280 expect(vec_info.Vector.child == i32);
281281}
......@@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" {
288288fn testAnyFrame() void {
289289 {
290290 const anyframe_info = @typeInfo(anyframe->i32);
291 expect(TypeId(anyframe_info) == .AnyFrame);
291 expect(@as(TypeId,anyframe_info) == .AnyFrame);
292292 expect(anyframe_info.AnyFrame.child.? == i32);
293293 }
294294
295295 {
296296 const anyframe_info = @typeInfo(anyframe);
297 expect(TypeId(anyframe_info) == .AnyFrame);
297 expect(@as(TypeId,anyframe_info) == .AnyFrame);
298298 expect(anyframe_info.AnyFrame.child == null);
299299 }
300300}
......@@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" {
334334 if (std.mem.eql(u8, decl.name, "bar1")) {
335335 expect(decl.data.Fn.lib_name == null);
336336 } 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.?);
338338 }
339339 }
340340 }
......@@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" {
342342
343343test "data field is a compile-time value" {
344344 const S = struct {
345 const Bar = isize(-1);
345 const Bar = @as(isize, -1);
346346 };
347347 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
348348}
test/stage1/behavior/union.zig+12-12
......@@ -14,7 +14,7 @@ const Agg = struct {
1414const v1 = Value{ .Int = 1234 };
1515const v2 = Value{ .Array = [_]u8{3} ** 9 };
1616
17const err = (anyerror!Agg)(Agg{
17const err = @as(anyerror!Agg, Agg{
1818 .val1 = v1,
1919 .val2 = v2,
2020});
......@@ -110,11 +110,11 @@ fn doTest() void {
110110}
111111
112112fn bar(value: Payload) i32 {
113 expect(Letter(value) == Letter.A);
113 expect(@as(Letter,value) == Letter.A);
114114 return switch (value) {
115115 Payload.A => |x| return x - 1244,
116 Payload.B => |x| if (x == 12.34) i32(20) else 21,
117 Payload.C => |x| if (x) i32(30) else 31,
116 Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,
117 Payload.C => |x| if (x) @as(i32, 30) else 31,
118118 };
119119}
120120
......@@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) {
127127test "simple union(enum(u32))" {
128128 var x = MultipleChoice.C;
129129 expect(x == MultipleChoice.C);
130 expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
130 expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60);
131131}
132132
133133const MultipleChoice2 = union(enum(u32)) {
......@@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" {
149149}
150150
151151fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
152 expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60);
153153 expect(1123 == switch (x) {
154154 MultipleChoice2.A => 1,
155155 MultipleChoice2.B => 2,
156 MultipleChoice2.C => |v| i32(1000) + v,
156 MultipleChoice2.C => |v| @as(i32, 1000) + v,
157157 MultipleChoice2.D => 4,
158158 MultipleChoice2.Unspecified1 => 5,
159159 MultipleChoice2.Unspecified2 => 6,
......@@ -208,12 +208,12 @@ test "cast union to tag type of union" {
208208}
209209
210210fn testCastUnionToTagType(x: TheUnion) void {
211 expect(TheTag(x) == TheTag.B);
211 expect(@as(TheTag,x) == TheTag.B);
212212}
213213
214214test "cast tag type of union to union" {
215215 var x: Value2 = Letter2.B;
216 expect(Letter2(x) == Letter2.B);
216 expect(@as(Letter2, x) == Letter2.B);
217217}
218218const Letter2 = enum {
219219 A,
......@@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) {
297297
298298fn testTaggedUnionInit(x: var) bool {
299299 const y = TaggedUnionWithAVoid{ .A = x };
300 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
300 return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;
301301}
302302
303303pub const UnionEnumNoPayloads = union(enum) {
......@@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" {
326326 var e = Expr{ .Literal = Literal{ .Bool = true } };
327327 const Tag = @TagType(Expr);
328328 comptime expect(@TagType(Tag) == u0);
329 var t = Tag(e);
329 var t = @as(Tag, e);
330330 expect(t == Expr.Literal);
331331}
332332
......@@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci
346346
347347 var e = Expr{ .Literal = Literal{ .Bool = true } };
348348 comptime expect(@TagType(Tag) == comptime_int);
349 var t = Tag(e);
349 var t = @as(Tag, e);
350350 expect(t == Expr.Literal);
351351 expect(@enumToInt(t) == 33);
352352 comptime expect(@enumToInt(t) == 33);
test/stage1/behavior/var_args.zig+5-5
......@@ -1,7 +1,7 @@
11const expect = @import("std").testing.expect;
22
33fn add(args: ...) i32 {
4 var sum = i32(0);
4 var sum = @as(i32, 0);
55 {
66 comptime var i: usize = 0;
77 inline while (i < args.len) : (i += 1) {
......@@ -12,8 +12,8 @@ fn add(args: ...) i32 {
1212}
1313
1414test "add arbitrary args" {
15 expect(add(i32(1), i32(2), i32(3), i32(4)) == 10);
16 expect(add(i32(1234)) == 1234);
15 expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
16 expect(add(@as(i32, 1234)) == 1234);
1717 expect(add() == 0);
1818}
1919
......@@ -26,8 +26,8 @@ test "send void arg to var args" {
2626}
2727
2828test "pass args directly" {
29 expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);
30 expect(addSomeStuff(i32(1234)) == 1234);
29 expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
30 expect(addSomeStuff(@as(i32, 1234)) == 1234);
3131 expect(addSomeStuff() == 0);
3232}
3333
test/stage1/behavior/vector.zig+25-25
......@@ -20,11 +20,11 @@ test "vector wrap operators" {
2020 fn doTheTest() void {
2121 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
2222 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 }));
24 expect(mem.eql(i32, ([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 }));
23 expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
2626 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 }));
2828 }
2929 };
3030 S.doTheTest();
......@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
3636 fn doTheTest() void {
3737 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
3838 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 }));
40 expect(mem.eql(bool, ([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 }));
42 expect(mem.eql(bool, ([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 }));
44 expect(mem.eql(bool, ([4]bool)(v >= x), [4]bool{ true, false, true, true }));
39 expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));
4545 }
4646 };
4747 S.doTheTest();
......@@ -53,10 +53,10 @@ test "vector int operators" {
5353 fn doTheTest() void {
5454 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
5555 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 }));
57 expect(mem.eql(i32, ([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 }));
59 expect(mem.eql(i32, ([4]i32)(-v), [4]i32{ -10, -20, -30, -40 }));
56 expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));
6060 }
6161 };
6262 S.doTheTest();
......@@ -68,10 +68,10 @@ test "vector float operators" {
6868 fn doTheTest() void {
6969 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
7070 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 }));
72 expect(mem.eql(f32, ([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 }));
74 expect(mem.eql(f32, ([4]f32)(-x), [4]f32{ -1, -2, -3, -4 }));
71 expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));
7575 }
7676 };
7777 S.doTheTest();
......@@ -83,9 +83,9 @@ test "vector bit operators" {
8383 fn doTheTest() void {
8484 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
8585 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 }));
87 expect(mem.eql(u8, ([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 }));
86 expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
8989 }
9090 };
9191 S.doTheTest();
......@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120120 {
121121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122122 var x: [4]u3 = v;
123 expect(mem.eql(u3, x, ([4]u3)(v)));
123 expect(mem.eql(u3, x, @as([4]u3, v)));
124124 }
125125 {
126126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127127 var x: [4]u2 = v;
128 expect(mem.eql(u2, x, ([4]u2)(v)));
128 expect(mem.eql(u2, x, @as([4]u2, v)));
129129 }
130130 {
131131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132132 var x: [4]u1 = v;
133 expect(mem.eql(u1, x, ([4]u1)(v)));
133 expect(mem.eql(u1, x, @as([4]u1, v)));
134134 }
135135 {
136136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137137 var x: [4]bool = v;
138 expect(mem.eql(bool, x, ([4]bool)(v)));
138 expect(mem.eql(bool, x, @as([4]bool, v)));
139139 }
140140 }
141141 };
test/stage1/behavior/void.zig+1-1
......@@ -26,7 +26,7 @@ test "iterate over a void slice" {
2626}
2727
2828fn times(n: usize) []const void {
29 return ([*]void)(undefined)[0..n];
29 return @as([*]void, undefined)[0..n];
3030}
3131
3232test "void optional" {
test/stage1/behavior/while.zig+8-8
......@@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" {
137137 const result = while (returnNull()) |value| {
138138 break value;
139139 } else
140 i32(2);
140 @as(i32, 2);
141141 expect(result == 2);
142142}
143143
......@@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" {
145145 const result = while (returnOptional(10)) |value| {
146146 break value;
147147 } else
148 i32(2);
148 @as(i32, 2);
149149 expect(result == 10);
150150}
151151
......@@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" {
153153 const result = while (returnError()) |value| {
154154 break value;
155155 } else |err|
156 i32(2);
156 @as(i32, 2);
157157 expect(result == 2);
158158}
159159
......@@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" {
161161 const result = while (returnSuccess(10)) |value| {
162162 break value;
163163 } else |err|
164 i32(2);
164 @as(i32, 2);
165165 expect(result == 10);
166166}
167167
168168test "while on bool with else result follow else prong" {
169169 const result = while (returnFalse()) {
170 break i32(10);
170 break @as(i32, 10);
171171 } else
172 i32(2);
172 @as(i32, 2);
173173 expect(result == 2);
174174}
175175
176176test "while on bool with else result follow break prong" {
177177 const result = while (returnTrue()) {
178 break i32(10);
178 break @as(i32, 10);
179179 } else
180 i32(2);
180 @as(i32, 2);
181181 expect(result == 10);
182182}
183183
test/tests.zig+2-2
......@@ -411,7 +411,7 @@ pub fn addPkgTests(
411411 const ArchTag = @TagType(builtin.Arch);
412412 if (test_target.disable_native and
413413 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))
415415 {
416416 continue;
417417 }
......@@ -429,7 +429,7 @@ pub fn addPkgTests(
429429 "bare";
430430
431431 const triple_prefix = if (test_target.target == .Native)
432 ([]const u8)("native")
432 @as([]const u8,"native")
433433 else
434434 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 {
2828 ,
2929 \\pub fn foo() void {
3030 \\ var a: c_int = undefined;
31 \\ var b: u8 = u8(123);
31 \\ var b: u8 = @as(u8, 123);
3232 \\ const c: c_int = undefined;
33 \\ const d: c_uint = c_uint(440);
33 \\ const d: c_uint = @as(c_uint, 440);
3434 \\}
3535 );
3636
......@@ -561,7 +561,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
561561 cases.add("u integer suffix after hex literal",
562562 \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
563563 ,
564 \\pub const SDL_INIT_VIDEO = c_uint(32);
564 \\pub const SDL_INIT_VIDEO = @as(c_uint, 32);
565565 );
566566
567567 cases.add("l integer suffix after hex literal",
......@@ -676,7 +676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
676676 \\pub export fn log2(_arg_a: c_uint) c_int {
677677 \\ var a = _arg_a;
678678 \\ var i: c_int = 0;
679 \\ while (a > c_uint(0)) {
679 \\ while (a > @as(c_uint, 0)) {
680680 \\ a >>= @import("std").math.Log2Int(c_uint)(1);
681681 \\ }
682682 \\ return i;
......@@ -848,7 +848,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
848848 \\pub export fn log2(_arg_a: u32) c_int {
849849 \\ var a = _arg_a;
850850 \\ var i: c_int = 0;
851 \\ while (a > c_uint(0)) {
851 \\ while (a > @as(c_uint, 0)) {
852852 \\ a >>= u5(1);
853853 \\ }
854854 \\ return i;
......@@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
937937 \\}
938938 ,
939939 \\pub export fn float_to_int(a: f32) c_int {
940 \\ return c_int(a);
940 \\ return @as(c_int, a);
941941 \\}
942942 );
943943
......@@ -1103,35 +1103,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11031103 \\}
11041104 ,
11051105 \\pub export fn foo() void {
1106 \\ var a: c_uint = c_uint(0);
1106 \\ var a: c_uint = @as(c_uint, 0);
11071107 \\ a +%= (x: {
11081108 \\ const _ref = &a;
1109 \\ _ref.* = (_ref.* +% c_uint(1));
1109 \\ _ref.* = (_ref.* +% @as(c_uint, 1));
11101110 \\ break :x _ref.*;
11111111 \\ });
11121112 \\ a -%= (x: {
11131113 \\ const _ref = &a;
1114 \\ _ref.* = (_ref.* -% c_uint(1));
1114 \\ _ref.* = (_ref.* -% @as(c_uint, 1));
11151115 \\ break :x _ref.*;
11161116 \\ });
11171117 \\ a *%= (x: {
11181118 \\ const _ref = &a;
1119 \\ _ref.* = (_ref.* *% c_uint(1));
1119 \\ _ref.* = (_ref.* *% @as(c_uint, 1));
11201120 \\ break :x _ref.*;
11211121 \\ });
11221122 \\ a &= (x: {
11231123 \\ const _ref = &a;
1124 \\ _ref.* = (_ref.* & c_uint(1));
1124 \\ _ref.* = (_ref.* & @as(c_uint, 1));
11251125 \\ break :x _ref.*;
11261126 \\ });
11271127 \\ a |= (x: {
11281128 \\ const _ref = &a;
1129 \\ _ref.* = (_ref.* | c_uint(1));
1129 \\ _ref.* = (_ref.* | @as(c_uint, 1));
11301130 \\ break :x _ref.*;
11311131 \\ });
11321132 \\ a ^= (x: {
11331133 \\ const _ref = &a;
1134 \\ _ref.* = (_ref.* ^ c_uint(1));
1134 \\ _ref.* = (_ref.* ^ @as(c_uint, 1));
11351135 \\ break :x _ref.*;
11361136 \\ });
11371137 \\ a >>= @import("std").math.Log2Int(c_uint)((x: {
......@@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11741174 ,
11751175 \\pub export fn foo() void {
11761176 \\ var i: c_int = 0;
1177 \\ var u: c_uint = c_uint(0);
1177 \\ var u: c_uint = @as(c_uint, 0);
11781178 \\ i += 1;
11791179 \\ i -= 1;
11801180 \\ u +%= 1;
......@@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12221222 ,
12231223 \\pub export fn foo() void {
12241224 \\ var i: c_int = 0;
1225 \\ var u: c_uint = c_uint(0);
1225 \\ var u: c_uint = @as(c_uint, 0);
12261226 \\ i += 1;
12271227 \\ i -= 1;
12281228 \\ u +%= 1;
......@@ -1646,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16461646 cases.addC(
16471647 "u integer suffix after 0 (zero) in macro definition",
16481648 "#define ZERO 0U",
1649 "pub const ZERO = c_uint(0);",
1649 "pub const ZERO = @as(c_uint, 0);",
16501650 );
16511651
16521652 cases.addC(
......@@ -1688,7 +1688,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16881688 cases.addC(
16891689 "bitwise not on u-suffixed 0 (zero) in macro definition",
16901690 "#define NOT_ZERO (~0U)",
1691 "pub const NOT_ZERO = ~c_uint(0);",
1691 "pub const NOT_ZERO = ~@as(c_uint, 0);",
16921692 );
16931693
16941694 cases.addC("implicit casts",
......@@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17331733 \\ fn_int(1094861636);
17341734 \\ fn_f32(@intToFloat(f32, 3));
17351735 \\ fn_f64(@intToFloat(f64, 3));
1736 \\ fn_char(u8('3'));
1737 \\ fn_char(u8('\x01'));
1738 \\ fn_char(u8(0));
1736 \\ fn_char(@as(u8, '3'));
1737 \\ fn_char(@as(u8, '\x01'));
1738 \\ fn_char(@as(u8, 0));
17391739 \\ fn_f32(3.000000);
17401740 \\ fn_f64(3.000000);
17411741 \\ fn_bool(true);
......@@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17981798 \\
17991799 ,
18001800 \\pub export fn escapes() [*c]const u8 {
1801 \\ var a: u8 = u8('\'');
1802 \\ var b: u8 = u8('\\');
1803 \\ var c: u8 = u8('\x07');
1804 \\ var d: u8 = u8('\x08');
1805 \\ var e: u8 = u8('\x0c');
1806 \\ var f: u8 = u8('\n');
1807 \\ var g: u8 = u8('\r');
1808 \\ var h: u8 = u8('\t');
1809 \\ var i: u8 = u8('\x0b');
1810 \\ var j: u8 = u8('\x00');
1811 \\ var k: u8 = u8('\"');
1801 \\ var a: u8 = @as(u8, '\'');
1802 \\ var b: u8 = @as(u8, '\\');
1803 \\ var c: u8 = @as(u8, '\x07');
1804 \\ var d: u8 = @as(u8, '\x08');
1805 \\ var e: u8 = @as(u8, '\x0c');
1806 \\ var f: u8 = @as(u8, '\n');
1807 \\ var g: u8 = @as(u8, '\r');
1808 \\ var h: u8 = @as(u8, '\t');
1809 \\ var i: u8 = @as(u8, '\x0b');
1810 \\ var j: u8 = @as(u8, '\x00');
1811 \\ var k: u8 = @as(u8, '\"');
18121812 \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
18131813 \\}
18141814 \\