| author | |
| committer | |
| log | e0db54e89d6f4e9f56800ddb1017e30be1b7d58a |
| tree | 5a5a88dcebf349bf92da9ba2be9e8de63dc3ab81 |
| parent | 2a6fbbd8fba30b8d24aa966606372f595c102d55 |
| signature |
206 files changed, 1287 insertions(+), 1282 deletions(-)
build.zig+1-1| ... | ... | @@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { |
| 155 | 155 | ) catch unreachable; |
| 156 | 156 | for (dep.system_libs.toSliceConst()) |lib| { |
| 157 | 157 | const static_bare_name = if (mem.eql(u8, lib, "curses")) |
| 158 | ([]const u8)("libncurses.a") | |
| 158 | @as([]const u8,"libncurses.a") | |
| 159 | 159 | else |
| 160 | 160 | b.fmt("lib{}.a", lib); |
| 161 | 161 | const static_lib_name = fs.path.join( |
lib/std/array_list.zig+8-8| ... | ... | @@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" { |
| 344 | 344 | try list.append(7); |
| 345 | 345 | |
| 346 | 346 | //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); | |
| 350 | 350 | |
| 351 | 351 | //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); | |
| 354 | 354 | |
| 355 | 355 | //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); | |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | test "std.ArrayList.swapRemove" { |
lib/std/ascii.zig+11-11| ... | ... | @@ -129,26 +129,26 @@ const combinedTable = init: { |
| 129 | 129 | comptime var i = 0; |
| 130 | 130 | inline while (i < 128) : (i += 1) { |
| 131 | 131 | 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); | |
| 140 | 140 | } |
| 141 | 141 | mem.set(u8, table[128..256], 0); |
| 142 | 142 | break :init table; |
| 143 | 143 | }; |
| 144 | 144 | |
| 145 | 145 | fn inTable(c: u8, t: tIndex) bool { |
| 146 | return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0; | |
| 146 | return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0; | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | pub 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; | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | pub fn isAlpha(c: u8) bool { |
lib/std/atomic/queue.zig+2-2| ... | ... | @@ -214,8 +214,8 @@ test "std.atomic.Queue" { |
| 214 | 214 | std.debug.panic( |
| 215 | 215 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", |
| 216 | 216 | 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), | |
| 219 | 219 | ); |
| 220 | 220 | } |
| 221 | 221 | } |
lib/std/atomic/stack.zig+3-3| ... | ... | @@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type { |
| 11 | 11 | root: ?*Node, |
| 12 | 12 | lock: @typeOf(lock_init), |
| 13 | 13 | |
| 14 | const lock_init = if (builtin.single_threaded) {} else u8(0); | |
| 14 | const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); | |
| 15 | 15 | |
| 16 | 16 | pub const Self = @This(); |
| 17 | 17 | |
| ... | ... | @@ -141,8 +141,8 @@ test "std.atomic.stack" { |
| 141 | 141 | std.debug.panic( |
| 142 | 142 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", |
| 143 | 143 | 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), | |
| 146 | 146 | ); |
| 147 | 147 | } |
| 148 | 148 | } |
lib/std/bloom_filter.zig+3-3| ... | ... | @@ -171,7 +171,7 @@ test "std.BloomFilter" { |
| 171 | 171 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); |
| 172 | 172 | } |
| 173 | 173 | testing.expectEqual(BF.Index(0), bf.popCount()); |
| 174 | testing.expectEqual(f64(0), bf.estimateItems()); | |
| 174 | testing.expectEqual(@as(f64, 0), bf.estimateItems()); | |
| 175 | 175 | // fill in a few items |
| 176 | 176 | bf.incrementCell(42); |
| 177 | 177 | bf.incrementCell(255); |
| ... | ... | @@ -197,7 +197,7 @@ test "std.BloomFilter" { |
| 197 | 197 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); |
| 198 | 198 | } |
| 199 | 199 | testing.expectEqual(BF.Index(0), bf.popCount()); |
| 200 | testing.expectEqual(f64(0), bf.estimateItems()); | |
| 200 | testing.expectEqual(@as(f64, 0), bf.estimateItems()); | |
| 201 | 201 | |
| 202 | 202 | // Lets add a string |
| 203 | 203 | bf.add("foo"); |
| ... | ... | @@ -219,7 +219,7 @@ test "std.BloomFilter" { |
| 219 | 219 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); |
| 220 | 220 | } |
| 221 | 221 | testing.expectEqual(BF.Index(0), bf.popCount()); |
| 222 | testing.expectEqual(f64(0), bf.estimateItems()); | |
| 222 | testing.expectEqual(@as(f64, 0), bf.estimateItems()); | |
| 223 | 223 | |
| 224 | 224 | comptime var teststrings = [_][]const u8{ |
| 225 | 225 | "foo", |
lib/std/c/darwin.zig+1-1| ... | ... | @@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo |
| 53 | 53 | pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; |
| 54 | 54 | |
| 55 | 55 | pub fn sigaddset(set: *sigset_t, signo: u5) void { |
| 56 | set.* |= u32(1) << (signo - 1); | |
| 56 | set.* |= @as(u32, 1) << (signo - 1); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
lib/std/child_process.zig+1-1| ... | ... | @@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void { |
| 717 | 717 | // Child of fork calls this to report an error to the fork parent. |
| 718 | 718 | // Then the child exits. |
| 719 | 719 | fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { |
| 720 | writeIntFd(fd, ErrInt(@errorToInt(err))) catch {}; | |
| 720 | writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {}; | |
| 721 | 721 | os.exit(1); |
| 722 | 722 | } |
| 723 | 723 |
lib/std/crypto/aes.zig+10-10| ... | ... | @@ -6,7 +6,7 @@ const testing = std.testing; |
| 6 | 6 | |
| 7 | 7 | // Apply sbox0 to each byte in w. |
| 8 | 8 | fn subw(w: u32) u32 { |
| 9 | return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]); | |
| 9 | return @as(u32, sbox0[w >> 24]) << 24 | @as(u32, sbox0[w >> 16 & 0xff]) << 16 | @as(u32, sbox0[w >> 8 & 0xff]) << 8 | @as(u32, sbox0[w & 0xff]); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | fn rotw(w: u32) u32 { |
| ... | ... | @@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Last round uses s-box directly and XORs to produce output. |
| 51 | s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]); | |
| 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]); | |
| 55 | 55 | |
| 56 | 56 | s0 ^= xk[k + 0]; |
| 57 | 57 | s1 ^= xk[k + 1]; |
| ... | ... | @@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Last round uses s-box directly and XORs to produce output. |
| 102 | s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]); | |
| 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]); | |
| 106 | 106 | |
| 107 | 107 | s0 ^= xk[k + 0]; |
| 108 | 108 | s1 ^= xk[k + 1]; |
| ... | ... | @@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void { |
| 256 | 256 | while (i < enc.len) : (i += 1) { |
| 257 | 257 | var t = enc[i - 1]; |
| 258 | 258 | if (i % nk == 0) { |
| 259 | t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24); | |
| 259 | t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24); | |
| 260 | 260 | } else if (nk > 6 and i % nk == 4) { |
| 261 | 261 | t = subw(t); |
| 262 | 262 | } |
lib/std/crypto/blake2.zig+8-8| ... | ... | @@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type { |
| 164 | 164 | inline while (j < 10) : (j += 1) { |
| 165 | 165 | inline for (rounds) |r| { |
| 166 | 166 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; |
| 167 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16)); | |
| 167 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16)); | |
| 168 | 168 | v[r.c] = v[r.c] +% v[r.d]; |
| 169 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12)); | |
| 169 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12)); | |
| 170 | 170 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; |
| 171 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8)); | |
| 171 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8)); | |
| 172 | 172 | v[r.c] = v[r.c] +% v[r.d]; |
| 173 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7)); | |
| 173 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7)); | |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| ... | ... | @@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type { |
| 398 | 398 | inline while (j < 12) : (j += 1) { |
| 399 | 399 | inline for (rounds) |r| { |
| 400 | 400 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; |
| 401 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32)); | |
| 401 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32)); | |
| 402 | 402 | v[r.c] = v[r.c] +% v[r.d]; |
| 403 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24)); | |
| 403 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24)); | |
| 404 | 404 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; |
| 405 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16)); | |
| 405 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16)); | |
| 406 | 406 | v[r.c] = v[r.c] +% v[r.d]; |
| 407 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63)); | |
| 407 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63)); | |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 |
lib/std/crypto/chacha20.zig+4-4| ... | ... | @@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void { |
| 49 | 49 | // two-round cycles |
| 50 | 50 | inline for (rounds) |r| { |
| 51 | 51 | x[r.a] +%= x[r.b]; |
| 52 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(16)); | |
| 52 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 16)); | |
| 53 | 53 | x[r.c] +%= x[r.d]; |
| 54 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(12)); | |
| 54 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 12)); | |
| 55 | 55 | x[r.a] +%= x[r.b]; |
| 56 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(8)); | |
| 56 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 8)); | |
| 57 | 57 | x[r.c] +%= x[r.d]; |
| 58 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(7)); | |
| 58 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 7)); | |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 |
lib/std/crypto/gimli.zig+4-4| ... | ... | @@ -34,9 +34,9 @@ pub const State = struct { |
| 34 | 34 | |
| 35 | 35 | pub fn permute(self: *Self) void { |
| 36 | 36 | const state = &self.data; |
| 37 | var round = u32(24); | |
| 37 | var round = @as(u32, 24); | |
| 38 | 38 | while (round > 0) : (round -= 1) { |
| 39 | var column = usize(0); | |
| 39 | var column = @as(usize, 0); | |
| 40 | 40 | while (column < 4) : (column += 1) { |
| 41 | 41 | const x = math.rotl(u32, state[column], 24); |
| 42 | 42 | const y = math.rotl(u32, state[4 + column], 9); |
| ... | ... | @@ -61,7 +61,7 @@ pub const State = struct { |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | pub fn squeeze(self: *Self, out: []u8) void { |
| 64 | var i = usize(0); | |
| 64 | var i = @as(usize, 0); | |
| 65 | 65 | while (i + RATE <= out.len) : (i += RATE) { |
| 66 | 66 | self.permute(); |
| 67 | 67 | mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]); |
| ... | ... | @@ -79,7 +79,7 @@ test "permute" { |
| 79 | 79 | var state = State{ |
| 80 | 80 | .data = blk: { |
| 81 | 81 | var input: [12]u32 = undefined; |
| 82 | var i = u32(0); | |
| 82 | var i = @as(u32, 0); | |
| 83 | 83 | while (i < 12) : (i += 1) { |
| 84 | 84 | input[i] = i * i * i + i *% 0x9e3779b9; |
| 85 | 85 | } |
lib/std/crypto/md5.zig+4-4| ... | ... | @@ -126,10 +126,10 @@ pub const Md5 = struct { |
| 126 | 126 | while (i < 16) : (i += 1) { |
| 127 | 127 | // NOTE: Performing or's separately improves perf by ~10% |
| 128 | 128 | 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; | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | var v: [4]u32 = [_]u32{ |
lib/std/crypto/poly1305.zig+6-6| ... | ... | @@ -87,11 +87,11 @@ pub const Poly1305 = struct { |
| 87 | 87 | // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff |
| 88 | 88 | fn polyBlock(ctx: *Self) void { |
| 89 | 89 | // 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 | |
| 95 | 95 | |
| 96 | 96 | // Local all the things! |
| 97 | 97 | const r0 = ctx.r[0]; // r0 <= 0fffffff |
| ... | ... | @@ -197,7 +197,7 @@ pub const Poly1305 = struct { |
| 197 | 197 | |
| 198 | 198 | // check if we should subtract 2^130-5 by performing the |
| 199 | 199 | // corresponding carry propagation. |
| 200 | const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004 | |
| 200 | const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004 | |
| 201 | 201 | const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000 |
| 202 | 202 | const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000 |
| 203 | 203 | const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000 |
lib/std/crypto/sha1.zig+15-15| ... | ... | @@ -146,10 +146,10 @@ pub const Sha1 = struct { |
| 146 | 146 | Rp(0, 1, 2, 3, 4, 15), |
| 147 | 147 | }; |
| 148 | 148 | inline for (round0a) |r| { |
| 149 | s[r.i] = (u32(b[r.i * 4 + 0]) << 24) | (u32(b[r.i * 4 + 1]) << 16) | (u32(b[r.i * 4 + 2]) << 8) | (u32(b[r.i * 4 + 3]) << 0); | |
| 149 | s[r.i] = (@as(u32, b[r.i * 4 + 0]) << 24) | (@as(u32, b[r.i * 4 + 1]) << 16) | (@as(u32, b[r.i * 4 + 2]) << 8) | (@as(u32, b[r.i * 4 + 3]) << 0); | |
| 150 | 150 | |
| 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)); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | const round0b = comptime [_]RoundParam{ |
| ... | ... | @@ -160,10 +160,10 @@ pub const Sha1 = struct { |
| 160 | 160 | }; |
| 161 | 161 | inline for (round0b) |r| { |
| 162 | 162 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 163 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | |
| 163 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); | |
| 164 | 164 | |
| 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)); | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | const round1 = comptime [_]RoundParam{ |
| ... | ... | @@ -190,10 +190,10 @@ pub const Sha1 = struct { |
| 190 | 190 | }; |
| 191 | 191 | inline for (round1) |r| { |
| 192 | 192 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 193 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | |
| 193 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); | |
| 194 | 194 | |
| 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)); | |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | const round2 = comptime [_]RoundParam{ |
| ... | ... | @@ -220,10 +220,10 @@ pub const Sha1 = struct { |
| 220 | 220 | }; |
| 221 | 221 | inline for (round2) |r| { |
| 222 | 222 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 223 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | |
| 223 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); | |
| 224 | 224 | |
| 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)); | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | const round3 = comptime [_]RoundParam{ |
| ... | ... | @@ -250,10 +250,10 @@ pub const Sha1 = struct { |
| 250 | 250 | }; |
| 251 | 251 | inline for (round3) |r| { |
| 252 | 252 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 253 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | |
| 253 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); | |
| 254 | 254 | |
| 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)); | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | d.s[0] +%= v[0]; |
lib/std/crypto/sha2.zig+20-18| ... | ... | @@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type { |
| 180 | 180 | var i: usize = 0; |
| 181 | 181 | while (i < 16) : (i += 1) { |
| 182 | 182 | 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; | |
| 187 | 187 | } |
| 188 | 188 | while (i < 64) : (i += 1) { |
| 189 | s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10)); | |
| 189 | s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], @as(u32, 7)) ^ math.rotr(u32, s[i - 15], @as(u32, 18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], @as(u32, 17)) ^ math.rotr(u32, s[i - 2], @as(u32, 19)) ^ (s[i - 2] >> 10)); | |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | var v: [8]u32 = [_]u32{ |
| ... | ... | @@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type { |
| 267 | 267 | Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2), |
| 268 | 268 | }; |
| 269 | 269 | inline for (round0) |r| { |
| 270 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], u32(6)) ^ math.rotr(u32, v[r.e], u32(11)) ^ math.rotr(u32, v[r.e], u32(25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; | |
| 270 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], @as(u32, 6)) ^ math.rotr(u32, v[r.e], @as(u32, 11)) ^ math.rotr(u32, v[r.e], @as(u32, 25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; | |
| 271 | 271 | |
| 272 | 272 | v[r.d] = v[r.d] +% v[r.h]; |
| 273 | 273 | |
| 274 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], u32(2)) ^ math.rotr(u32, v[r.a], u32(13)) ^ math.rotr(u32, v[r.a], u32(22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); | |
| 274 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], @as(u32, 2)) ^ math.rotr(u32, v[r.a], @as(u32, 13)) ^ math.rotr(u32, v[r.a], @as(u32, 22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | d.s[0] +%= v[0]; |
| ... | ... | @@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type { |
| 522 | 522 | var i: usize = 0; |
| 523 | 523 | while (i < 16) : (i += 1) { |
| 524 | 524 | 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; | |
| 533 | 533 | } |
| 534 | 534 | while (i < 80) : (i += 1) { |
| 535 | s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6)); | |
| 535 | s[i] = s[i - 16] +% s[i - 7] +% | |
| 536 | (math.rotr(u64, s[i - 15], @as(u64, 1)) ^ math.rotr(u64, s[i - 15], @as(u64, 8)) ^ (s[i - 15] >> 7)) +% | |
| 537 | (math.rotr(u64, s[i - 2], @as(u64, 19)) ^ math.rotr(u64, s[i - 2], @as(u64, 61)) ^ (s[i - 2] >> 6)); | |
| 536 | 538 | } |
| 537 | 539 | |
| 538 | 540 | var v: [8]u64 = [_]u64{ |
| ... | ... | @@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type { |
| 629 | 631 | Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817), |
| 630 | 632 | }; |
| 631 | 633 | inline for (round0) |r| { |
| 632 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], u64(14)) ^ math.rotr(u64, v[r.e], u64(18)) ^ math.rotr(u64, v[r.e], u64(41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; | |
| 634 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], @as(u64, 14)) ^ math.rotr(u64, v[r.e], @as(u64, 18)) ^ math.rotr(u64, v[r.e], @as(u64, 41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; | |
| 633 | 635 | |
| 634 | 636 | v[r.d] = v[r.d] +% v[r.h]; |
| 635 | 637 | |
| 636 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], u64(28)) ^ math.rotr(u64, v[r.a], u64(34)) ^ math.rotr(u64, v[r.a], u64(39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); | |
| 638 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], @as(u64, 28)) ^ math.rotr(u64, v[r.a], @as(u64, 34)) ^ math.rotr(u64, v[r.a], @as(u64, 39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); | |
| 637 | 639 | } |
| 638 | 640 | |
| 639 | 641 | d.s[0] +%= v[0]; |
lib/std/crypto/sha3.zig+1-1| ... | ... | @@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void { |
| 133 | 133 | } |
| 134 | 134 | x = 0; |
| 135 | 135 | inline while (x < 5) : (x += 1) { |
| 136 | t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], usize(1)); | |
| 136 | t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], @as(usize, 1)); | |
| 137 | 137 | y = 0; |
| 138 | 138 | inline while (y < 5) : (y += 1) { |
| 139 | 139 | s[x + y * 5] ^= t[0]; |
lib/std/crypto/x25519.zig+10-10| ... | ... | @@ -256,15 +256,15 @@ const Fe = struct { |
| 256 | 256 | var t: [10]i64 = undefined; |
| 257 | 257 | |
| 258 | 258 | 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; | |
| 263 | 263 | 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; | |
| 268 | 268 | |
| 269 | 269 | carry1(h, t[0..]); |
| 270 | 270 | } |
| ... | ... | @@ -500,7 +500,7 @@ const Fe = struct { |
| 500 | 500 | if (i + 1 < 10) { |
| 501 | 501 | t[i + 1] += c[i]; |
| 502 | 502 | } |
| 503 | t[i] -= c[i] * (i32(1) << shift); | |
| 503 | t[i] -= c[i] * (@as(i32, 1) << shift); | |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | fn toBytes(s: []u8, h: *const Fe) void { |
| ... | ... | @@ -511,7 +511,7 @@ const Fe = struct { |
| 511 | 511 | t[i] = h.b[i]; |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | var q = (19 * t[9] + ((i32(1) << 24))) >> 25; | |
| 514 | var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25; | |
| 515 | 515 | { |
| 516 | 516 | var i: usize = 0; |
| 517 | 517 | while (i < 5) : (i += 1) { |
lib/std/debug.zig+13-10| ... | ... | @@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { |
| 1008 | 1008 | const word = try stream.readIntLittle(u32); |
| 1009 | 1009 | var bit_i: u5 = 0; |
| 1010 | 1010 | while (true) : (bit_i += 1) { |
| 1011 | if (word & (u32(1) << bit_i) != 0) { | |
| 1011 | if (word & (@as(u32, 1) << bit_i) != 0) { | |
| 1012 | 1012 | try list.append(word_i * 32 + bit_i); |
| 1013 | 1013 | } |
| 1014 | 1014 | if (bit_i == maxInt(u5)) break; |
| ... | ... | @@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo |
| 1556 | 1556 | |
| 1557 | 1557 | // TODO the noasyncs here are workarounds |
| 1558 | 1558 | fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 { |
| 1559 | return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32)); | |
| 1559 | return if (is_64) try noasync in_stream.readIntLittle(u64) else @as(u64, try noasync in_stream.readIntLittle(u32)); | |
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | // TODO the noasyncs here are workarounds |
| 1563 | 1563 | fn parseFormValueTargetAddrSize(in_stream: var) !u64 { |
| 1564 | 1564 | if (@sizeOf(usize) == 4) { |
| 1565 | return u64(try noasync in_stream.readIntLittle(u32)); | |
| 1565 | // TODO this cast should not be needed | |
| 1566 | return @as(u64, try noasync in_stream.readIntLittle(u32)); | |
| 1566 | 1567 | } else if (@sizeOf(usize) == 8) { |
| 1567 | 1568 | return noasync in_stream.readIntLittle(u64); |
| 1568 | 1569 | } else { |
| ... | ... | @@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u |
| 1846 | 1847 | // special opcodes |
| 1847 | 1848 | const adjusted_opcode = opcode - opcode_base; |
| 1848 | 1849 | const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); |
| 1849 | const inc_line = i32(line_base) + i32(adjusted_opcode % line_range); | |
| 1850 | const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range); | |
| 1850 | 1851 | prog.line += inc_line; |
| 1851 | 1852 | prog.address += inc_addr; |
| 1852 | 1853 | if (try prog.checkLineMatch()) |info| return info; |
| ... | ... | @@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr |
| 1913 | 1914 | if (unit_length == 0) { |
| 1914 | 1915 | return error.MissingDebugInfo; |
| 1915 | 1916 | } |
| 1916 | const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); | |
| 1917 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); | |
| 1917 | 1918 | |
| 1918 | 1919 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); |
| 1919 | 1920 | // TODO support 3 and 5 |
| ... | ... | @@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr |
| 2012 | 2013 | // special opcodes |
| 2013 | 2014 | const adjusted_opcode = opcode - opcode_base; |
| 2014 | 2015 | const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); |
| 2015 | const inc_line = i32(line_base) + i32(adjusted_opcode % line_range); | |
| 2016 | const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range); | |
| 2016 | 2017 | prog.line += inc_line; |
| 2017 | 2018 | prog.address += inc_addr; |
| 2018 | 2019 | if (try prog.checkLineMatch()) |info| return info; |
| ... | ... | @@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void { |
| 2093 | 2094 | var is_64: bool = undefined; |
| 2094 | 2095 | const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); |
| 2095 | 2096 | if (unit_length == 0) return; |
| 2096 | const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); | |
| 2097 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); | |
| 2097 | 2098 | |
| 2098 | 2099 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); |
| 2099 | 2100 | if (version < 2 or version > 5) return error.InvalidDebugInfo; |
| ... | ... | @@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void { |
| 2195 | 2196 | var is_64: bool = undefined; |
| 2196 | 2197 | const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); |
| 2197 | 2198 | if (unit_length == 0) return; |
| 2198 | const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); | |
| 2199 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); | |
| 2199 | 2200 | |
| 2200 | 2201 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); |
| 2201 | 2202 | if (version < 2 or version > 5) return error.InvalidDebugInfo; |
| ... | ... | @@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 { |
| 2312 | 2313 | } else { |
| 2313 | 2314 | if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; |
| 2314 | 2315 | ptr.* += 4; |
| 2315 | return u64(first_32_bits); | |
| 2316 | // TODO this cast should not be needed | |
| 2317 | return @as(u64, first_32_bits); | |
| 2316 | 2318 | } |
| 2317 | 2319 | } |
| 2318 | 2320 | |
| ... | ... | @@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) |
| 2329 | 2331 | return in_stream.readIntLittle(u64); |
| 2330 | 2332 | } else { |
| 2331 | 2333 | if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; |
| 2332 | return u64(first_32_bits); | |
| 2334 | // TODO this cast should not be needed | |
| 2335 | return @as(u64, first_32_bits); | |
| 2333 | 2336 | } |
| 2334 | 2337 | } |
| 2335 | 2338 |
lib/std/debug/leb128.zig+2-2| ... | ... | @@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T { |
| 62 | 62 | var shift: usize = 0; |
| 63 | 63 | |
| 64 | 64 | while (true) { |
| 65 | const byte = u8(try in_stream.readByte()); | |
| 65 | const byte: u8 = try in_stream.readByte(); | |
| 66 | 66 | |
| 67 | 67 | if (shift > T.bit_count) |
| 68 | 68 | return error.Overflow; |
| 69 | 69 | |
| 70 | 70 | var operand: UT = undefined; |
| 71 | if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) { | |
| 71 | if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) { | |
| 72 | 72 | if (byte != 0x7f) |
| 73 | 73 | return error.Overflow; |
| 74 | 74 | } |
lib/std/dynamic_library.zig+2-2| ... | ... | @@ -215,8 +215,8 @@ pub const ElfLib = struct { |
| 215 | 215 | |
| 216 | 216 | var i: usize = 0; |
| 217 | 217 | 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; | |
| 220 | 220 | if (0 == self.syms[i].st_shndx) continue; |
| 221 | 221 | if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue; |
| 222 | 222 | if (maybe_versym) |versym| { |
lib/std/elf.zig+12-12| ... | ... | @@ -441,9 +441,9 @@ pub const Elf = struct { |
| 441 | 441 | elf.program_header_offset = try in.readInt(u64, elf.endian); |
| 442 | 442 | elf.section_header_offset = try in.readInt(u64, elf.endian); |
| 443 | 443 | } 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)); | |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | // skip over flags |
| ... | ... | @@ -458,13 +458,13 @@ pub const Elf = struct { |
| 458 | 458 | const ph_entry_count = try in.readInt(u16, elf.endian); |
| 459 | 459 | const sh_entry_size = try in.readInt(u16, elf.endian); |
| 460 | 460 | const sh_entry_count = try in.readInt(u16, elf.endian); |
| 461 | elf.string_section_index = usize(try in.readInt(u16, elf.endian)); | |
| 461 | elf.string_section_index = @as(usize, try in.readInt(u16, elf.endian)); | |
| 462 | 462 | |
| 463 | 463 | if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat; |
| 464 | 464 | |
| 465 | const sh_byte_count = u64(sh_entry_size) * u64(sh_entry_count); | |
| 465 | const sh_byte_count = @as(u64, sh_entry_size) * @as(u64, sh_entry_count); | |
| 466 | 466 | const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count); |
| 467 | const ph_byte_count = u64(ph_entry_size) * u64(ph_entry_count); | |
| 467 | const ph_byte_count = @as(u64, ph_entry_size) * @as(u64, ph_entry_count); | |
| 468 | 468 | const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count); |
| 469 | 469 | |
| 470 | 470 | const stream_end = try seekable_stream.getEndPos(); |
| ... | ... | @@ -499,14 +499,14 @@ pub const Elf = struct { |
| 499 | 499 | // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ? |
| 500 | 500 | elf_section.name = try in.readInt(u32, elf.endian); |
| 501 | 501 | 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)); | |
| 506 | 506 | elf_section.link = try in.readInt(u32, elf.endian); |
| 507 | 507 | 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)); | |
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 |
lib/std/event/fs.zig+2-2| ... | ... | @@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize { |
| 328 | 328 | windows.ERROR.IO_PENDING => unreachable, |
| 329 | 329 | windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, |
| 330 | 330 | windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, |
| 331 | windows.ERROR.HANDLE_EOF => return usize(bytes_transferred), | |
| 331 | windows.ERROR.HANDLE_EOF => return @as(usize, bytes_transferred), | |
| 332 | 332 | else => |err| return windows.unexpectedError(err), |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | return usize(bytes_transferred); | |
| 335 | return @as(usize, bytes_transferred); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /// iovecs must live until preadv frame completes |
lib/std/fifo.zig+13-13| ... | ... | @@ -257,7 +257,7 @@ test "ByteFifo" { |
| 257 | 257 | defer fifo.deinit(); |
| 258 | 258 | |
| 259 | 259 | try fifo.write("HELLO"); |
| 260 | testing.expectEqual(usize(5), fifo.readableLength()); | |
| 260 | testing.expectEqual(@as(usize, 5), fifo.readableLength()); | |
| 261 | 261 | testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0)); |
| 262 | 262 | |
| 263 | 263 | { |
| ... | ... | @@ -265,34 +265,34 @@ test "ByteFifo" { |
| 265 | 265 | while (i < 5) : (i += 1) { |
| 266 | 266 | try fifo.write([_]u8{try fifo.peekItem(i)}); |
| 267 | 267 | } |
| 268 | testing.expectEqual(usize(10), fifo.readableLength()); | |
| 268 | testing.expectEqual(@as(usize, 10), fifo.readableLength()); | |
| 269 | 269 | testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | { |
| 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()); | |
| 278 | 278 | } |
| 279 | testing.expectEqual(usize(5), fifo.readableLength()); | |
| 279 | testing.expectEqual(@as(usize, 5), fifo.readableLength()); | |
| 280 | 280 | |
| 281 | 281 | { // 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); | |
| 284 | 284 | fifo.writeAssumeCapacity("6<chars<11"); |
| 285 | 285 | testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0)); |
| 286 | 286 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11)); |
| 287 | 287 | fifo.discard(11); |
| 288 | 288 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0)); |
| 289 | 289 | fifo.discard(4); |
| 290 | testing.expectEqual(usize(0), fifo.readableLength()); | |
| 290 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | { |
| 294 | 294 | const buf = try fifo.writeableWithSize(12); |
| 295 | testing.expectEqual(usize(12), buf.len); | |
| 295 | testing.expectEqual(@as(usize, 12), buf.len); | |
| 296 | 296 | var i: u8 = 0; |
| 297 | 297 | while (i < 10) : (i += 1) { |
| 298 | 298 | buf[i] = i + 'a'; |
| ... | ... | @@ -313,6 +313,6 @@ test "ByteFifo" { |
| 313 | 313 | try fifo.print("{}, {}!", "Hello", "World"); |
| 314 | 314 | var result: [30]u8 = undefined; |
| 315 | 315 | testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result)); |
| 316 | testing.expectEqual(usize(0), fifo.readableLength()); | |
| 316 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 317 | 317 | } |
| 318 | 318 | } |
lib/std/fmt.zig+51-51| ... | ... | @@ -512,7 +512,7 @@ pub fn formatIntValue( |
| 512 | 512 | uppercase = false; |
| 513 | 513 | } else if (comptime std.mem.eql(u8, fmt, "c")) { |
| 514 | 514 | if (@typeOf(int_value).bit_count <= 8) { |
| 515 | return formatAsciiChar(u8(int_value), options, context, Errors, output); | |
| 515 | return formatAsciiChar(@as(u8, int_value), options, context, Errors, output); | |
| 516 | 516 | } else { |
| 517 | 517 | @compileError("Cannot print integer that is larger than 8 bits as a ascii"); |
| 518 | 518 | } |
| ... | ... | @@ -594,7 +594,7 @@ pub fn formatBuf( |
| 594 | 594 | var leftover_padding = if (width > buf.len) (width - buf.len) else return; |
| 595 | 595 | const pad_byte: u8 = options.fill; |
| 596 | 596 | while (leftover_padding > 0) : (leftover_padding -= 1) { |
| 597 | try output(context, (*const [1]u8)(&pad_byte)[0..1]); | |
| 597 | try output(context, @as(*const [1]u8, &pad_byte)[0..1]); | |
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | |
| ... | ... | @@ -668,7 +668,7 @@ pub fn formatFloatScientific( |
| 668 | 668 | try output(context, float_decimal.digits[0..1]); |
| 669 | 669 | try output(context, "."); |
| 670 | 670 | if (float_decimal.digits.len > 1) { |
| 671 | const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len; | |
| 671 | const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; | |
| 672 | 672 | |
| 673 | 673 | try output(context, float_decimal.digits[1..num_digits]); |
| 674 | 674 | } else { |
| ... | ... | @@ -703,7 +703,7 @@ pub fn formatFloatDecimal( |
| 703 | 703 | comptime Errors: type, |
| 704 | 704 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 705 | 705 | ) Errors!void { |
| 706 | var x = f64(value); | |
| 706 | var x = @as(f64, value); | |
| 707 | 707 | |
| 708 | 708 | // Errol doesn't handle these special cases. |
| 709 | 709 | if (math.signbit(x)) { |
| ... | ... | @@ -921,14 +921,14 @@ fn formatIntSigned( |
| 921 | 921 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 922 | 922 | if (value < 0) { |
| 923 | 923 | const minus_sign: u8 = '-'; |
| 924 | try output(context, (*const [1]u8)(&minus_sign)[0..]); | |
| 924 | try output(context, @as(*const [1]u8, &minus_sign)[0..]); | |
| 925 | 925 | const new_value = @intCast(uint, -(value + 1)) + 1; |
| 926 | 926 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); |
| 927 | 927 | } else if (options.width == null or options.width.? == 0) { |
| 928 | 928 | return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output); |
| 929 | 929 | } else { |
| 930 | 930 | const plus_sign: u8 = '+'; |
| 931 | try output(context, (*const [1]u8)(&plus_sign)[0..]); | |
| 931 | try output(context, @as(*const [1]u8, &plus_sign)[0..]); | |
| 932 | 932 | const new_value = @intCast(uint, value); |
| 933 | 933 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); |
| 934 | 934 | } |
| ... | ... | @@ -966,7 +966,7 @@ fn formatIntUnsigned( |
| 966 | 966 | const zero_byte: u8 = options.fill; |
| 967 | 967 | var leftover_padding = padding - index; |
| 968 | 968 | while (true) { |
| 969 | try output(context, (*const [1]u8)(&zero_byte)[0..]); | |
| 969 | try output(context, @as(*const [1]u8, &zero_byte)[0..]); | |
| 970 | 970 | leftover_padding -= 1; |
| 971 | 971 | if (leftover_padding == 0) break; |
| 972 | 972 | } |
| ... | ... | @@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { |
| 1088 | 1088 | fn digitToChar(digit: u8, uppercase: bool) u8 { |
| 1089 | 1089 | return switch (digit) { |
| 1090 | 1090 | 0...9 => digit + '0', |
| 1091 | 10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10), | |
| 1091 | 10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10), | |
| 1092 | 1092 | else => unreachable, |
| 1093 | 1093 | }; |
| 1094 | 1094 | } |
| ... | ... | @@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { |
| 1134 | 1134 | test "bufPrintInt" { |
| 1135 | 1135 | var buffer: [100]u8 = undefined; |
| 1136 | 1136 | 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")); | |
| 1141 | 1141 | |
| 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")); | |
| 1143 | 1143 | |
| 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")); | |
| 1147 | 1147 | |
| 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")); | |
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 { |
| ... | ... | @@ -1208,8 +1208,8 @@ test "int.specifier" { |
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | test "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)); | |
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | test "buffer" { |
| ... | ... | @@ -1287,8 +1287,8 @@ test "filesize" { |
| 1287 | 1287 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1288 | 1288 | return error.SkipZigTest; |
| 1289 | 1289 | } |
| 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)); | |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | test "struct" { |
| ... | ... | @@ -1327,8 +1327,8 @@ test "float.scientific" { |
| 1327 | 1327 | } |
| 1328 | 1328 | try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34)); |
| 1329 | 1329 | 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)); | |
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | test "float.scientific.precision" { |
| ... | ... | @@ -1336,12 +1336,12 @@ test "float.scientific.precision" { |
| 1336 | 1336 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1337 | 1337 | return error.SkipZigTest; |
| 1338 | 1338 | } |
| 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)))); | |
| 1342 | 1342 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. |
| 1343 | 1343 | // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. |
| 1344 | try testFmt("f64: 1.00001e+05", "f64: {e:.5}", f64(@bitCast(f32, u32(1203982400)))); | |
| 1344 | try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400)))); | |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | 1347 | test "float.special" { |
| ... | ... | @@ -1364,21 +1364,21 @@ test "float.decimal" { |
| 1364 | 1364 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1365 | 1365 | return error.SkipZigTest; |
| 1366 | 1366 | } |
| 1367 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29)); | |
| 1367 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29)); | |
| 1368 | 1368 | try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234)); |
| 1369 | 1369 | try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567)); |
| 1370 | 1370 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). |
| 1371 | 1371 | // -11.12339... is rounded back up to -11.1234 |
| 1372 | 1372 | try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234)); |
| 1373 | 1373 | 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)); | |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | 1384 | test "float.libc.sanity" { |
| ... | ... | @@ -1386,22 +1386,22 @@ test "float.libc.sanity" { |
| 1386 | 1386 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1387 | 1387 | return error.SkipZigTest; |
| 1388 | 1388 | } |
| 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)))); | |
| 1394 | 1394 | |
| 1395 | 1395 | // libc differences |
| 1396 | 1396 | // |
| 1397 | 1397 | // This is 0.015625 exactly according to gdb. We thus round down, |
| 1398 | 1398 | // however glibc rounds up for some reason. This occurs for all |
| 1399 | 1399 | // floats of the form x.yyyy25 on a precision point. |
| 1400 | try testFmt("f64: 0.01563", "f64: {d:.5}", f64(@bitCast(f32, u32(1015021568)))); | |
| 1400 | try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568)))); | |
| 1401 | 1401 | // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 |
| 1402 | 1402 | // also rounds to 630 so I'm inclined to believe libc is not |
| 1403 | 1403 | // optimal here. |
| 1404 | try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1518338049)))); | |
| 1404 | try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049)))); | |
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | test "custom" { |
| ... | ... | @@ -1677,17 +1677,17 @@ test "formatType max_depth" { |
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | 1679 | test "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)); | |
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | 1687 | test "positional with specifier" { |
| 1688 | try testFmt("10.0", "{0d:.1}", f64(9.999)); | |
| 1688 | try testFmt("10.0", "{0d:.1}", @as(f64, 9.999)); | |
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | test "positional/alignment/width/precision" { |
| 1692 | try testFmt("10.0", "{0d: >3.1}", f64(9.999)); | |
| 1692 | try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999)); | |
| 1693 | 1693 | } |
lib/std/fmt/errol.zig+2-2| ... | ... | @@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void { |
| 296 | 296 | /// @buf: The output buffer. |
| 297 | 297 | /// &return: The exponent. |
| 298 | 298 | fn errolInt(val: f64, buffer: []u8) FloatDecimal { |
| 299 | const pow19 = u128(1e19); | |
| 299 | const pow19 = @as(u128, 1e19); | |
| 300 | 300 | |
| 301 | 301 | assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); |
| 302 | 302 | |
| ... | ... | @@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 { |
| 670 | 670 | const bits = @bitCast(u64, from); |
| 671 | 671 | assert((bits & ((1 << 52) - 1)) == 0); |
| 672 | 672 | |
| 673 | return u128(1) << @truncate(u7, (bits >> 52) -% 1023); | |
| 673 | return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023); | |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /// Given two different integers with the same length in terms of the number |
lib/std/fmt/parse_float.zig+7-7| ... | ... | @@ -59,29 +59,29 @@ const Z96 = struct { |
| 59 | 59 | |
| 60 | 60 | // d += s |
| 61 | 61 | inline fn add(d: *Z96, s: Z96) void { |
| 62 | var w = u64(d.d0) + u64(s.d0); | |
| 62 | var w = @as(u64, d.d0) + @as(u64, s.d0); | |
| 63 | 63 | d.d0 = @truncate(u32, w); |
| 64 | 64 | |
| 65 | 65 | w >>= 32; |
| 66 | w += u64(d.d1) + u64(s.d1); | |
| 66 | w += @as(u64, d.d1) + @as(u64, s.d1); | |
| 67 | 67 | d.d1 = @truncate(u32, w); |
| 68 | 68 | |
| 69 | 69 | w >>= 32; |
| 70 | w += u64(d.d2) + u64(s.d2); | |
| 70 | w += @as(u64, d.d2) + @as(u64, s.d2); | |
| 71 | 71 | d.d2 = @truncate(u32, w); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // d -= s |
| 75 | 75 | inline fn sub(d: *Z96, s: Z96) void { |
| 76 | var w = u64(d.d0) -% u64(s.d0); | |
| 76 | var w = @as(u64, d.d0) -% @as(u64, s.d0); | |
| 77 | 77 | d.d0 = @truncate(u32, w); |
| 78 | 78 | |
| 79 | 79 | w >>= 32; |
| 80 | w += u64(d.d1) -% u64(s.d1); | |
| 80 | w += @as(u64, d.d1) -% @as(u64, s.d1); | |
| 81 | 81 | d.d1 = @truncate(u32, w); |
| 82 | 82 | |
| 83 | 83 | w >>= 32; |
| 84 | w += u64(d.d2) -% u64(s.d2); | |
| 84 | w += @as(u64, d.d2) -% @as(u64, s.d2); | |
| 85 | 85 | d.d2 = @truncate(u32, w); |
| 86 | 86 | } |
| 87 | 87 | }; |
| ... | ... | @@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T { |
| 160 | 160 | break :blk if (n.negative) f64_minus_zero else f64_plus_zero; |
| 161 | 161 | } else if (s.d2 != 0) { |
| 162 | 162 | const binexs2 = @intCast(u64, binary_exponent) << 52; |
| 163 | const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2; | |
| 163 | const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2; | |
| 164 | 164 | break :blk if (n.negative) rr | (1 << 63) else rr; |
| 165 | 165 | } else { |
| 166 | 166 | break :blk 0; |
lib/std/fs/file.zig+3-3| ... | ... | @@ -272,9 +272,9 @@ pub const File = struct { |
| 272 | 272 | return Stat{ |
| 273 | 273 | .size = @bitCast(u64, st.size), |
| 274 | 274 | .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, | |
| 278 | 278 | }; |
| 279 | 279 | } |
| 280 | 280 |
lib/std/hash/auto_hash.zig+7-7| ... | ... | @@ -306,7 +306,7 @@ test "hash struct deep" { |
| 306 | 306 | test "testHash optional" { |
| 307 | 307 | const a: ?u32 = 123; |
| 308 | 308 | const b: ?u32 = null; |
| 309 | testing.expectEqual(testHash(a), testHash(u32(123))); | |
| 309 | testing.expectEqual(testHash(a), testHash(@as(u32, 123))); | |
| 310 | 310 | testing.expect(testHash(a) != testHash(b)); |
| 311 | 311 | testing.expectEqual(testHash(b), 0); |
| 312 | 312 | } |
| ... | ... | @@ -315,9 +315,9 @@ test "testHash array" { |
| 315 | 315 | const a = [_]u32{ 1, 2, 3 }; |
| 316 | 316 | const h = testHash(a); |
| 317 | 317 | 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)); | |
| 321 | 321 | testing.expectEqual(h, hasher.final()); |
| 322 | 322 | } |
| 323 | 323 | |
| ... | ... | @@ -330,9 +330,9 @@ test "testHash struct" { |
| 330 | 330 | const f = Foo{}; |
| 331 | 331 | const h = testHash(f); |
| 332 | 332 | 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)); | |
| 336 | 336 | testing.expectEqual(h, hasher.final()); |
| 337 | 337 | } |
| 338 | 338 |
lib/std/hash/cityhash.zig+4-4| ... | ... | @@ -214,7 +214,7 @@ pub const CityHash64 = struct { |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | fn hashLen0To16(str: []const u8) u64 { |
| 217 | const len: u64 = u64(str.len); | |
| 217 | const len: u64 = @as(u64, str.len); | |
| 218 | 218 | if (len >= 8) { |
| 219 | 219 | const mul: u64 = k2 +% len *% 2; |
| 220 | 220 | const a: u64 = fetch64(str.ptr) +% k2; |
| ... | ... | @@ -240,7 +240,7 @@ pub const CityHash64 = struct { |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | fn hashLen17To32(str: []const u8) u64 { |
| 243 | const len: u64 = u64(str.len); | |
| 243 | const len: u64 = @as(u64, str.len); | |
| 244 | 244 | const mul: u64 = k2 +% len *% 2; |
| 245 | 245 | const a: u64 = fetch64(str.ptr) *% k1; |
| 246 | 246 | const b: u64 = fetch64(str.ptr + 8); |
| ... | ... | @@ -251,7 +251,7 @@ pub const CityHash64 = struct { |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | fn hashLen33To64(str: []const u8) u64 { |
| 254 | const len: u64 = u64(str.len); | |
| 254 | const len: u64 = @as(u64, str.len); | |
| 255 | 255 | const mul: u64 = k2 +% len *% 2; |
| 256 | 256 | const a: u64 = fetch64(str.ptr) *% k2; |
| 257 | 257 | const b: u64 = fetch64(str.ptr + 8); |
| ... | ... | @@ -305,7 +305,7 @@ pub const CityHash64 = struct { |
| 305 | 305 | return hashLen33To64(str); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | var len: u64 = u64(str.len); | |
| 308 | var len: u64 = @as(u64, str.len); | |
| 309 | 309 | |
| 310 | 310 | var x: u64 = fetch64(str.ptr + str.len - 40); |
| 311 | 311 | var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56); |
lib/std/hash/crc.zig+4-4| ... | ... | @@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type { |
| 65 | 65 | const p = input[i .. i + 8]; |
| 66 | 66 | |
| 67 | 67 | // 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); | |
| 72 | 72 | |
| 73 | 73 | self.crc = |
| 74 | 74 | lookup_tables[0][p[7]] ^ |
lib/std/hash/murmur.zig+1-1| ... | ... | @@ -98,7 +98,7 @@ pub const Murmur2_64 = struct { |
| 98 | 98 | |
| 99 | 99 | pub fn hashWithSeed(str: []const u8, seed: u64) u64 { |
| 100 | 100 | const m: u64 = 0xc6a4a7935bd1e995; |
| 101 | const len = u64(str.len); | |
| 101 | const len = @as(u64, str.len); | |
| 102 | 102 | var h1: u64 = seed ^ (len *% m); |
| 103 | 103 | for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { |
| 104 | 104 | var k1: u64 = v; |
lib/std/hash/siphash.zig+7-7| ... | ... | @@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3; |
| 105 | return (u128(b2) << 64) | b1; | |
| 105 | return (@as(u128, b2) << 64) | b1; | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | fn round(self: *Self, b: []const u8) void { |
| ... | ... | @@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 121 | 121 | |
| 122 | 122 | fn sipRound(d: *Self) void { |
| 123 | 123 | d.v0 +%= d.v1; |
| 124 | d.v1 = math.rotl(u64, d.v1, u64(13)); | |
| 124 | d.v1 = math.rotl(u64, d.v1, @as(u64, 13)); | |
| 125 | 125 | d.v1 ^= d.v0; |
| 126 | d.v0 = math.rotl(u64, d.v0, u64(32)); | |
| 126 | d.v0 = math.rotl(u64, d.v0, @as(u64, 32)); | |
| 127 | 127 | d.v2 +%= d.v3; |
| 128 | d.v3 = math.rotl(u64, d.v3, u64(16)); | |
| 128 | d.v3 = math.rotl(u64, d.v3, @as(u64, 16)); | |
| 129 | 129 | d.v3 ^= d.v2; |
| 130 | 130 | d.v0 +%= d.v3; |
| 131 | d.v3 = math.rotl(u64, d.v3, u64(21)); | |
| 131 | d.v3 = math.rotl(u64, d.v3, @as(u64, 21)); | |
| 132 | 132 | d.v3 ^= d.v0; |
| 133 | 133 | d.v2 +%= d.v1; |
| 134 | d.v1 = math.rotl(u64, d.v1, u64(17)); | |
| 134 | d.v1 = math.rotl(u64, d.v1, @as(u64, 17)); | |
| 135 | 135 | d.v1 ^= d.v2; |
| 136 | d.v2 = math.rotl(u64, d.v2, u64(32)); | |
| 136 | d.v2 = math.rotl(u64, d.v2, @as(u64, 32)); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | pub fn hash(key: []const u8, input: []const u8) T { |
lib/std/hash_map.zig+1-1| ... | ... | @@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | fn keyToIndex(hm: Self, key: K) usize { |
| 405 | return hm.constrainIndex(usize(hash(key))); | |
| 405 | return hm.constrainIndex(@as(usize, hash(key))); | |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | fn constrainIndex(hm: Self, i: usize) usize { |
lib/std/heap.zig+1-1| ... | ... | @@ -896,7 +896,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo |
| 896 | 896 | const large_align = u29(mem.page_size << 2); |
| 897 | 897 | |
| 898 | 898 | var align_mask: usize = undefined; |
| 899 | _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask); | |
| 899 | _ = @shlWithOverflow(usize, ~@as(usize, 0), USizeShift(@ctz(u29, large_align)), &align_mask); | |
| 900 | 900 | |
| 901 | 901 | var slice = try allocator.alignedAlloc(u8, large_align, 500); |
| 902 | 902 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
lib/std/http/headers.zig+5-5| ... | ... | @@ -399,7 +399,7 @@ test "Headers.iterator" { |
| 399 | 399 | } |
| 400 | 400 | count += 1; |
| 401 | 401 | } |
| 402 | testing.expectEqual(i32(2), count); | |
| 402 | testing.expectEqual(@as(i32, 2), count); | |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | test "Headers.contains" { |
| ... | ... | @@ -420,10 +420,10 @@ test "Headers.delete" { |
| 420 | 420 | try h.append("cookie", "somevalue", null); |
| 421 | 421 | |
| 422 | 422 | testing.expectEqual(false, h.delete("not-present")); |
| 423 | testing.expectEqual(usize(3), h.count()); | |
| 423 | testing.expectEqual(@as(usize, 3), h.count()); | |
| 424 | 424 | |
| 425 | 425 | testing.expectEqual(true, h.delete("foo")); |
| 426 | testing.expectEqual(usize(2), h.count()); | |
| 426 | testing.expectEqual(@as(usize, 2), h.count()); | |
| 427 | 427 | { |
| 428 | 428 | const e = h.at(0); |
| 429 | 429 | testing.expectEqualSlices(u8, "baz", e.name); |
| ... | ... | @@ -448,7 +448,7 @@ test "Headers.orderedRemove" { |
| 448 | 448 | try h.append("cookie", "somevalue", null); |
| 449 | 449 | |
| 450 | 450 | h.orderedRemove(0); |
| 451 | testing.expectEqual(usize(2), h.count()); | |
| 451 | testing.expectEqual(@as(usize, 2), h.count()); | |
| 452 | 452 | { |
| 453 | 453 | const e = h.at(0); |
| 454 | 454 | testing.expectEqualSlices(u8, "baz", e.name); |
| ... | ... | @@ -471,7 +471,7 @@ test "Headers.swapRemove" { |
| 471 | 471 | try h.append("cookie", "somevalue", null); |
| 472 | 472 | |
| 473 | 473 | h.swapRemove(0); |
| 474 | testing.expectEqual(usize(2), h.count()); | |
| 474 | testing.expectEqual(@as(usize, 2), h.count()); | |
| 475 | 475 | { |
| 476 | 476 | const e = h.at(0); |
| 477 | 477 | testing.expectEqualSlices(u8, "cookie", e.name); |
lib/std/io.zig+2-2| ... | ... | @@ -353,7 +353,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 353 | 353 | const Buf = @IntType(false, buf_bit_count); |
| 354 | 354 | const BufShift = math.Log2Int(Buf); |
| 355 | 355 | |
| 356 | out_bits.* = usize(0); | |
| 356 | out_bits.* = @as(usize, 0); | |
| 357 | 357 | if (U == u0 or bits == 0) return 0; |
| 358 | 358 | var out_buffer = Buf(0); |
| 359 | 359 | |
| ... | ... | @@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 434 | 434 | var self = @fieldParentPtr(Self, "stream", self_stream); |
| 435 | 435 | |
| 436 | 436 | var out_bits: usize = undefined; |
| 437 | var out_bits_total = usize(0); | |
| 437 | var out_bits_total = @as(usize, 0); | |
| 438 | 438 | //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced |
| 439 | 439 | if (self.bit_count > 0) { |
| 440 | 440 | for (buffer) |*b, i| { |
lib/std/io/out_stream.zig+2-2| ... | ... | @@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type { |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | pub fn writeByte(self: *Self, byte: u8) Error!void { |
| 43 | const slice = (*const [1]u8)(&byte)[0..]; | |
| 43 | const slice = @as(*const [1]u8, &byte)[0..]; | |
| 44 | 44 | return self.writeFn(self, slice); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void { |
| 48 | const slice = (*const [1]u8)(&byte)[0..]; | |
| 48 | const slice = @as(*const [1]u8, &byte)[0..]; | |
| 49 | 49 | var i: usize = 0; |
| 50 | 50 | while (i < n) : (i += 1) { |
| 51 | 51 | try self.writeFn(self, slice); |
lib/std/io/test.zig+20-20| ... | ... | @@ -228,8 +228,8 @@ test "BitOutStream" { |
| 228 | 228 | |
| 229 | 229 | try bit_stream_be.writeBits(u2(1), 1); |
| 230 | 230 | 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); | |
| 233 | 233 | try bit_stream_be.writeBits(u9(5), 5); |
| 234 | 234 | try bit_stream_be.writeBits(u1(1), 1); |
| 235 | 235 | |
| ... | ... | @@ -242,33 +242,33 @@ test "BitOutStream" { |
| 242 | 242 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); |
| 243 | 243 | |
| 244 | 244 | mem_out_be.pos = 0; |
| 245 | try bit_stream_be.writeBits(u32(0b110011010000101), 16); | |
| 245 | try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16); | |
| 246 | 246 | expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); |
| 247 | 247 | |
| 248 | try bit_stream_be.writeBits(u0(0), 0); | |
| 248 | try bit_stream_be.writeBits(@as(u0, 0), 0); | |
| 249 | 249 | |
| 250 | 250 | var mem_out_le = io.SliceOutStream.init(mem_le[0..]); |
| 251 | 251 | var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream); |
| 252 | 252 | |
| 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); | |
| 259 | 259 | |
| 260 | 260 | expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); |
| 261 | 261 | |
| 262 | 262 | mem_out_le.pos = 0; |
| 263 | try bit_stream_le.writeBits(u15(0b110011010000101), 15); | |
| 263 | try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15); | |
| 264 | 264 | try bit_stream_le.flushBits(); |
| 265 | 265 | expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); |
| 266 | 266 | |
| 267 | 267 | mem_out_le.pos = 0; |
| 268 | try bit_stream_le.writeBits(u32(0b1100110100001011), 16); | |
| 268 | try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16); | |
| 269 | 269 | expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); |
| 270 | 270 | |
| 271 | try bit_stream_le.writeBits(u0(0), 0); | |
| 271 | try bit_stream_le.writeBits(@as(u0, 0), 0); | |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | test "BitStreams with File Stream" { |
| ... | ... | @@ -282,12 +282,12 @@ test "BitStreams with File Stream" { |
| 282 | 282 | const OutError = File.WriteError; |
| 283 | 283 | var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); |
| 284 | 284 | |
| 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); | |
| 291 | 291 | try bit_stream.flushBits(); |
| 292 | 292 | } |
| 293 | 293 | { |
| ... | ... | @@ -603,7 +603,7 @@ test "c out stream" { |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | const out_stream = &io.COutStream.init(out_file).stream; |
| 606 | try out_stream.print("hi: {}\n", i32(123)); | |
| 606 | try out_stream.print("hi: {}\n", @as(i32, 123)); | |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | test "File seek ops" { |
lib/std/json.zig+2-2| ... | ... | @@ -1343,7 +1343,7 @@ test "write json then parse it" { |
| 1343 | 1343 | try jw.emitBool(true); |
| 1344 | 1344 | |
| 1345 | 1345 | try jw.objectField("int"); |
| 1346 | try jw.emitNumber(i32(1234)); | |
| 1346 | try jw.emitNumber(@as(i32, 1234)); | |
| 1347 | 1347 | |
| 1348 | 1348 | try jw.objectField("array"); |
| 1349 | 1349 | try jw.beginArray(); |
| ... | ... | @@ -1352,7 +1352,7 @@ test "write json then parse it" { |
| 1352 | 1352 | try jw.emitNull(); |
| 1353 | 1353 | |
| 1354 | 1354 | try jw.arrayElem(); |
| 1355 | try jw.emitNumber(f64(12.34)); | |
| 1355 | try jw.emitNumber(@as(f64, 12.34)); | |
| 1356 | 1356 | |
| 1357 | 1357 | try jw.endArray(); |
| 1358 | 1358 |
lib/std/math.zig+68-68| ... | ... | @@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079; |
| 44 | 44 | pub const sqrt1_2 = 0.707106781186547524400844362104849039; |
| 45 | 45 | |
| 46 | 46 | // From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128) |
| 47 | pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001)); | |
| 48 | pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000)); | |
| 49 | pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); | |
| 50 | pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000)); | |
| 47 | pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001)); | |
| 48 | pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000)); | |
| 49 | pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); | |
| 50 | pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000)); | |
| 51 | 51 | pub const f128_toint = 1.0 / f128_epsilon; |
| 52 | 52 | |
| 53 | 53 | // float.h details |
| ... | ... | @@ -69,28 +69,28 @@ pub const f16_max = 65504; |
| 69 | 69 | pub const f16_epsilon = 0.0009765625; // 2**-10 |
| 70 | 70 | pub const f16_toint = 1.0 / f16_epsilon; |
| 71 | 71 | |
| 72 | pub const nan_u16 = u16(0x7C01); | |
| 72 | pub const nan_u16 = @as(u16, 0x7C01); | |
| 73 | 73 | pub const nan_f16 = @bitCast(f16, nan_u16); |
| 74 | 74 | |
| 75 | pub const inf_u16 = u16(0x7C00); | |
| 75 | pub const inf_u16 = @as(u16, 0x7C00); | |
| 76 | 76 | pub const inf_f16 = @bitCast(f16, inf_u16); |
| 77 | 77 | |
| 78 | pub const nan_u32 = u32(0x7F800001); | |
| 78 | pub const nan_u32 = @as(u32, 0x7F800001); | |
| 79 | 79 | pub const nan_f32 = @bitCast(f32, nan_u32); |
| 80 | 80 | |
| 81 | pub const inf_u32 = u32(0x7F800000); | |
| 81 | pub const inf_u32 = @as(u32, 0x7F800000); | |
| 82 | 82 | pub const inf_f32 = @bitCast(f32, inf_u32); |
| 83 | 83 | |
| 84 | pub const nan_u64 = u64(0x7FF << 52) | 1; | |
| 84 | pub const nan_u64 = @as(u64, 0x7FF << 52) | 1; | |
| 85 | 85 | pub const nan_f64 = @bitCast(f64, nan_u64); |
| 86 | 86 | |
| 87 | pub const inf_u64 = u64(0x7FF << 52); | |
| 87 | pub const inf_u64 = @as(u64, 0x7FF << 52); | |
| 88 | 88 | pub const inf_f64 = @bitCast(f64, inf_u64); |
| 89 | 89 | |
| 90 | pub const nan_u128 = u128(0x7fff0000000000000000000000000001); | |
| 90 | pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001); | |
| 91 | 91 | pub const nan_f128 = @bitCast(f128, nan_u128); |
| 92 | 92 | |
| 93 | pub const inf_u128 = u128(0x7fff0000000000000000000000000000); | |
| 93 | pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000); | |
| 94 | 94 | pub const inf_f128 = @bitCast(f128, inf_u128); |
| 95 | 95 | |
| 96 | 96 | pub const nan = @import("math/nan.zig").nan; |
| ... | ... | @@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type { |
| 248 | 248 | }, |
| 249 | 249 | else => {}, |
| 250 | 250 | } |
| 251 | return @typeOf(A(0) + B(0)); | |
| 251 | return @typeOf(@as(A, 0) + @as(B, 0)); | |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /// Returns the smaller number. When one of the parameter's type's full range fits in the other, |
| ... | ... | @@ -273,7 +273,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | test "math.min" { |
| 276 | testing.expect(min(i32(-1), i32(2)) == -1); | |
| 276 | testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1); | |
| 277 | 277 | { |
| 278 | 278 | var a: u16 = 999; |
| 279 | 279 | var b: u32 = 10; |
| ... | ... | @@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) { |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | test "math.max" { |
| 312 | testing.expect(max(i32(-1), i32(2)) == 2); | |
| 312 | testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2); | |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) { |
| ... | ... | @@ -352,10 +352,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | test "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); | |
| 359 | 359 | testing.expect(shl(u8, 0b11111111, 3) == 0b11111000); |
| 360 | 360 | testing.expect(shl(u8, 0b11111111, 8) == 0); |
| 361 | 361 | testing.expect(shl(u8, 0b11111111, 9) == 0); |
| ... | ... | @@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T { |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | test "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); | |
| 387 | 387 | testing.expect(shr(u8, 0b11111111, 3) == 0b00011111); |
| 388 | 388 | testing.expect(shr(u8, 0b11111111, 8) == 0); |
| 389 | 389 | testing.expect(shr(u8, 0b11111111, 9) == 0); |
| ... | ... | @@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T { |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | test "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); | |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /// Rotates left. Only unsigned values can be rotated. |
| ... | ... | @@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T { |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | test "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); | |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | pub fn Log2Int(comptime T: type) type { |
| ... | ... | @@ -532,8 +532,8 @@ test "math.absInt" { |
| 532 | 532 | comptime testAbsInt(); |
| 533 | 533 | } |
| 534 | 534 | fn 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); | |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | pub const absFloat = fabs; |
| ... | ... | @@ -679,14 +679,14 @@ pub fn absCast(x: var) t: { |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | test "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); | |
| 684 | 684 | |
| 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); | |
| 687 | 687 | |
| 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); | |
| 690 | 690 | |
| 691 | 691 | testing.expect(absCast(-999) == 999); |
| 692 | 692 | } |
| ... | ... | @@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | test "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); | |
| 710 | 710 | |
| 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); | |
| 713 | 713 | |
| 714 | testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10))); | |
| 714 | testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10))); | |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| ... | ... | @@ -729,13 +729,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | test "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))); | |
| 734 | 734 | testing.expectError(error.Overflow, cast(u8, i8(-1))); |
| 735 | 735 | testing.expectError(error.Overflow, cast(u64, i8(-1))); |
| 736 | 736 | |
| 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); | |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | pub const AlignCastError = error{UnalignedMemory}; |
| ... | ... | @@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" { |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | fn 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)); | |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | test "math.ceilPowerOfTwo" { |
| ... | ... | @@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" { |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | fn 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)); | |
| 840 | 840 | testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9)); |
| 841 | 841 | } |
| 842 | 842 | |
| ... | ... | @@ -944,7 +944,7 @@ test "max value type" { |
| 944 | 944 | |
| 945 | 945 | pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) { |
| 946 | 946 | const ResultInt = @IntType(T.is_signed, T.bit_count * 2); |
| 947 | return ResultInt(a) * ResultInt(b); | |
| 947 | return @as(ResultInt, a) * @as(ResultInt, b); | |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | test "math.mulWide" { |
lib/std/math/acos.zig+2-2| ... | ... | @@ -149,8 +149,8 @@ fn acos64(x: f64) f64 { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "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)); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | test "math.acos32" { |
lib/std/math/acosh.zig+2-2| ... | ... | @@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 { |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | test "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)); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "math.acosh32" { |
lib/std/math/asin.zig+2-2| ... | ... | @@ -142,8 +142,8 @@ fn asin64(x: f64) f64 { |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "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)); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | test "math.asin32" { |
lib/std/math/asinh.zig+2-2| ... | ... | @@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "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)); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.asinh32" { |
lib/std/math/atan.zig+2-2| ... | ... | @@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 { |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | test "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)); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "math.atan32" { |
lib/std/math/atanh.zig+2-2| ... | ... | @@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 { |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "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)); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "math.atanh_32" { |
lib/std/math/big/int.zig+1-1| ... | ... | @@ -261,7 +261,7 @@ pub const Int = struct { |
| 261 | 261 | /// the minus sign. This is used for determining the number of characters needed to print the |
| 262 | 262 | /// value. It is inexact and may exceed the given value by ~1-2 bytes. |
| 263 | 263 | pub fn sizeInBase(self: Int, base: usize) usize { |
| 264 | const bit_count = usize(@boolToInt(!self.isPositive())) + self.bitCountAbs(); | |
| 264 | const bit_count = @as(usize, @boolToInt(!self.isPositive())) + self.bitCountAbs(); | |
| 265 | 265 | return (bit_count / math.log2(base)) + 1; |
| 266 | 266 | } |
| 267 | 267 |
lib/std/math/cbrt.zig+5-5| ... | ... | @@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 { |
| 54 | 54 | // first step newton to 16 bits |
| 55 | 55 | var t: f64 = @bitCast(f32, u); |
| 56 | 56 | var r: f64 = t * t * t; |
| 57 | t = t * (f64(x) + x + r) / (x + r + r); | |
| 57 | t = t * (@as(f64, x) + x + r) / (x + r + r); | |
| 58 | 58 | |
| 59 | 59 | // second step newton to 47 bits |
| 60 | 60 | r = t * t * t; |
| 61 | t = t * (f64(x) + x + r) / (x + r + r); | |
| 61 | t = t * (@as(f64, x) + x + r) / (x + r + r); | |
| 62 | 62 | |
| 63 | 63 | return @floatCast(f32, t); |
| 64 | 64 | } |
| ... | ... | @@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 { |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | u &= 1 << 63; |
| 100 | u |= u64(hx) << 32; | |
| 100 | u |= @as(u64, hx) << 32; | |
| 101 | 101 | var t = @bitCast(f64, u); |
| 102 | 102 | |
| 103 | 103 | // cbrt to 23 bits |
| ... | ... | @@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 { |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "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)); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | test "math.cbrt32" { |
lib/std/math/ceil.zig+3-3| ... | ... | @@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 { |
| 37 | 37 | if (e >= 23) { |
| 38 | 38 | return x; |
| 39 | 39 | } else if (e >= 0) { |
| 40 | m = u32(0x007FFFFF) >> @intCast(u5, e); | |
| 40 | m = @as(u32, 0x007FFFFF) >> @intCast(u5, e); | |
| 41 | 41 | if (u & m == 0) { |
| 42 | 42 | return x; |
| 43 | 43 | } |
| ... | ... | @@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 { |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "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)); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | test "math.ceil32" { |
lib/std/math/complex/ldexp.zig+1-1| ... | ... | @@ -59,7 +59,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 { |
| 59 | 59 | expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k; |
| 60 | 60 | |
| 61 | 61 | const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20); |
| 62 | return @bitCast(f64, (u64(high_word) << 32) | lx); | |
| 62 | return @bitCast(f64, (@as(u64, high_word) << 32) | lx); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) { |
lib/std/math/complex/sqrt.zig+2-2| ... | ... | @@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) { |
| 52 | 52 | // y = nan special case is handled fine below |
| 53 | 53 | |
| 54 | 54 | // 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); | |
| 57 | 57 | |
| 58 | 58 | if (dx >= 0) { |
| 59 | 59 | const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5); |
lib/std/math/complex/tanh.zig+1-1| ... | ... | @@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) { |
| 76 | 76 | return Complex(f64).new(x, r); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx); | |
| 79 | const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx); | |
| 80 | 80 | const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y); |
| 81 | 81 | return Complex(f64).new(xx, math.copysign(f64, 0, r)); |
| 82 | 82 | } |
lib/std/math/copysign.zig+3-3| ... | ... | @@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 { |
| 24 | 24 | const uy = @bitCast(u16, y); |
| 25 | 25 | |
| 26 | 26 | const h1 = ux & (maxInt(u16) / 2); |
| 27 | const h2 = uy & (u16(1) << 15); | |
| 27 | const h2 = uy & (@as(u16, 1) << 15); | |
| 28 | 28 | return @bitCast(f16, h1 | h2); |
| 29 | 29 | } |
| 30 | 30 | |
| ... | ... | @@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 { |
| 33 | 33 | const uy = @bitCast(u32, y); |
| 34 | 34 | |
| 35 | 35 | const h1 = ux & (maxInt(u32) / 2); |
| 36 | const h2 = uy & (u32(1) << 31); | |
| 36 | const h2 = uy & (@as(u32, 1) << 31); | |
| 37 | 37 | return @bitCast(f32, h1 | h2); |
| 38 | 38 | } |
| 39 | 39 | |
| ... | ... | @@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 { |
| 42 | 42 | const uy = @bitCast(u64, y); |
| 43 | 43 | |
| 44 | 44 | const h1 = ux & (maxInt(u64) / 2); |
| 45 | const h2 = uy & (u64(1) << 63); | |
| 45 | const h2 = uy & (@as(u64, 1) << 63); | |
| 46 | 46 | return @bitCast(f64, h1 | h2); |
| 47 | 47 | } |
| 48 | 48 |
lib/std/math/cos.zig+2-2| ... | ... | @@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T { |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "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)); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "math.cos32" { |
lib/std/math/cosh.zig+2-2| ... | ... | @@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 { |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "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)); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "math.cosh32" { |
lib/std/math/exp.zig+2-2| ... | ... | @@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 { |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "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)); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | test "math.exp32" { |
lib/std/math/exp2.zig+3-3| ... | ... | @@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 { |
| 85 | 85 | const k = i_0 / tblsiz; |
| 86 | 86 | // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the |
| 87 | 87 | // intended result but should confirm how GCC/Clang handle this to ensure. |
| 88 | const uk = @bitCast(f64, u64(0x3FF + k) << 52); | |
| 88 | const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52); | |
| 89 | 89 | i_0 &= tblsiz - 1; |
| 90 | 90 | uf -= redux; |
| 91 | 91 | |
| ... | ... | @@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 { |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | test "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)); | |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | test "math.exp2_32" { |
lib/std/math/expm1.zig+2-2| ... | ... | @@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 { |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | test "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)); | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | test "math.expm1_32" { |
lib/std/math/expo2.zig+1-1| ... | ... | @@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 { |
| 30 | 30 | const kln2 = 0x1.62066151ADD8BP+10; |
| 31 | 31 | |
| 32 | 32 | const u = (0x3FF + k / 2) << 20; |
| 33 | const scale = @bitCast(f64, u64(u) << 32); | |
| 33 | const scale = @bitCast(f64, @as(u64, u) << 32); | |
| 34 | 34 | return math.exp(x - kln2) * scale * scale; |
| 35 | 35 | } |
lib/std/math/fabs.zig+4-4| ... | ... | @@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 { |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | test "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)); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | test "math.fabs16" { |
lib/std/math/floor.zig+5-5| ... | ... | @@ -40,7 +40,7 @@ fn floor16(x: f16) f16 { |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | if (e >= 0) { |
| 43 | m = u16(1023) >> @intCast(u4, e); | |
| 43 | m = @as(u16, 1023) >> @intCast(u4, e); | |
| 44 | 44 | if (u & m == 0) { |
| 45 | 45 | return x; |
| 46 | 46 | } |
| ... | ... | @@ -74,7 +74,7 @@ fn floor32(x: f32) f32 { |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | if (e >= 0) { |
| 77 | m = u32(0x007FFFFF) >> @intCast(u5, e); | |
| 77 | m = @as(u32, 0x007FFFFF) >> @intCast(u5, e); | |
| 78 | 78 | if (u & m == 0) { |
| 79 | 79 | return x; |
| 80 | 80 | } |
| ... | ... | @@ -123,9 +123,9 @@ fn floor64(x: f64) f64 { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "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)); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "math.floor16" { |
lib/std/math/fma.zig+1-1| ... | ... | @@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T { |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | fn fma32(x: f32, y: f32, z: f32) f32 { |
| 21 | const xy = f64(x) * y; | |
| 21 | const xy = @as(f64, x) * y; | |
| 22 | 22 | const xy_z = xy + z; |
| 23 | 23 | const u = @bitCast(u64, xy_z); |
| 24 | 24 | const e = (u >> 52) & 0x7FF; |
lib/std/math/frexp.zig+2-2| ... | ... | @@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result { |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | test "math.frexp" { |
| 111 | const a = frexp(f32(1.3)); | |
| 111 | const a = frexp(@as(f32, 1.3)); | |
| 112 | 112 | const b = frexp32(1.3); |
| 113 | 113 | expect(a.significand == b.significand and a.exponent == b.exponent); |
| 114 | 114 | |
| 115 | const c = frexp(f64(1.3)); | |
| 115 | const c = frexp(@as(f64, 1.3)); | |
| 116 | 116 | const d = frexp64(1.3); |
| 117 | 117 | expect(c.significand == d.significand and c.exponent == d.exponent); |
| 118 | 118 | } |
lib/std/math/hypot.zig+1-1| ... | ... | @@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 { |
| 56 | 56 | yy *= 0x1.0p-90; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y)); | |
| 59 | return z * math.sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y)); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | fn sq(hi: *f64, lo: *f64, x: f64) void { |
lib/std/math/ilogb.zig+3-3| ... | ... | @@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // NOTE: Should these be exposed publicly? |
| 29 | const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1); | |
| 29 | const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1); | |
| 30 | 30 | const fp_ilogb0 = fp_ilogbnan; |
| 31 | 31 | |
| 32 | 32 | fn ilogb32(x: f32) i32 { |
| ... | ... | @@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 { |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | test "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)); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | test "math.ilogb32" { |
lib/std/math/isfinite.zig+6-6| ... | ... | @@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "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))); | |
| 35 | 35 | expect(!isFinite(math.inf(f16))); |
| 36 | 36 | expect(!isFinite(-math.inf(f16))); |
| 37 | 37 | expect(!isFinite(math.inf(f32))); |
lib/std/math/isinf.zig+24-24| ... | ... | @@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool { |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | test "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))); | |
| 85 | 85 | expect(isInf(math.inf(f16))); |
| 86 | 86 | expect(isInf(-math.inf(f16))); |
| 87 | 87 | expect(isInf(math.inf(f32))); |
| ... | ... | @@ -93,14 +93,14 @@ test "math.isInf" { |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "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))); | |
| 104 | 104 | expect(isPositiveInf(math.inf(f16))); |
| 105 | 105 | expect(!isPositiveInf(-math.inf(f16))); |
| 106 | 106 | expect(isPositiveInf(math.inf(f32))); |
| ... | ... | @@ -112,14 +112,14 @@ test "math.isPositiveInf" { |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | test "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))); | |
| 123 | 123 | expect(!isNegativeInf(math.inf(f16))); |
| 124 | 124 | expect(isNegativeInf(-math.inf(f16))); |
| 125 | 125 | expect(!isNegativeInf(math.inf(f32))); |
lib/std/math/isnan.zig+4-4| ... | ... | @@ -20,8 +20,8 @@ test "math.isNan" { |
| 20 | 20 | expect(isNan(math.nan(f32))); |
| 21 | 21 | expect(isNan(math.nan(f64))); |
| 22 | 22 | 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))); | |
| 27 | 27 | } |
lib/std/math/isnormal.zig+6-6| ... | ... | @@ -29,10 +29,10 @@ test "math.isNormal" { |
| 29 | 29 | expect(!isNormal(math.nan(f16))); |
| 30 | 30 | expect(!isNormal(math.nan(f32))); |
| 31 | 31 | 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))); | |
| 38 | 38 | } |
lib/std/math/ln.zig+5-5| ... | ... | @@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) { |
| 31 | 31 | }; |
| 32 | 32 | }, |
| 33 | 33 | TypeId.ComptimeInt => { |
| 34 | return @typeOf(1)(math.floor(ln_64(f64(x)))); | |
| 34 | return @typeOf(1)(math.floor(ln_64(@as(f64, x)))); | |
| 35 | 35 | }, |
| 36 | 36 | TypeId.Int => { |
| 37 | return T(math.floor(ln_64(f64(x)))); | |
| 37 | return T(math.floor(ln_64(@as(f64, x)))); | |
| 38 | 38 | }, |
| 39 | 39 | else => @compileError("ln not implemented for " ++ @typeName(T)), |
| 40 | 40 | } |
| ... | ... | @@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 { |
| 132 | 132 | hx += 0x3FF00000 - 0x3FE6A09E; |
| 133 | 133 | k += @intCast(i32, hx >> 20) - 0x3FF; |
| 134 | 134 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 135 | ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); | |
| 135 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); | |
| 136 | 136 | x = @bitCast(f64, ix); |
| 137 | 137 | |
| 138 | 138 | const f = x - 1.0; |
| ... | ... | @@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "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)); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | test "math.ln32" { |
lib/std/math/log.zig+5-5| ... | ... | @@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T { |
| 23 | 23 | const float_base = math.lossyCast(f64, base); |
| 24 | 24 | switch (@typeId(T)) { |
| 25 | 25 | TypeId.ComptimeFloat => { |
| 26 | return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base)); | |
| 26 | return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base)); | |
| 27 | 27 | }, |
| 28 | 28 | TypeId.ComptimeInt => { |
| 29 | return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base))); | |
| 29 | return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); | |
| 30 | 30 | }, |
| 31 | 31 | builtin.TypeId.Int => { |
| 32 | 32 | // TODO implement integer log without using float math |
| ... | ... | @@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T { |
| 35 | 35 | |
| 36 | 36 | builtin.TypeId.Float => { |
| 37 | 37 | switch (T) { |
| 38 | f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)), | |
| 38 | f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)), | |
| 39 | 39 | f64 => return math.ln(x) / math.ln(float_base), |
| 40 | 40 | else => @compileError("log not implemented for " ++ @typeName(T)), |
| 41 | 41 | } |
| ... | ... | @@ -67,6 +67,6 @@ test "math.log float_special" { |
| 67 | 67 | expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974))); |
| 68 | 68 | expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974))); |
| 69 | 69 | |
| 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))); | |
| 72 | 72 | } |
lib/std/math/log10.zig+4-4| ... | ... | @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { |
| 32 | 32 | }; |
| 33 | 33 | }, |
| 34 | 34 | TypeId.ComptimeInt => { |
| 35 | return @typeOf(1)(math.floor(log10_64(f64(x)))); | |
| 35 | return @typeOf(1)(math.floor(log10_64(@as(f64, x)))); | |
| 36 | 36 | }, |
| 37 | 37 | TypeId.Int => { |
| 38 | 38 | return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); |
| ... | ... | @@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 { |
| 143 | 143 | hx += 0x3FF00000 - 0x3FE6A09E; |
| 144 | 144 | k += @intCast(i32, hx >> 20) - 0x3FF; |
| 145 | 145 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 146 | ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); | |
| 146 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); | |
| 147 | 147 | x = @bitCast(f64, ix); |
| 148 | 148 | |
| 149 | 149 | const f = x - 1.0; |
| ... | ... | @@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 { |
| 158 | 158 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 159 | 159 | var hi = f - hfsq; |
| 160 | 160 | var hii = @bitCast(u64, hi); |
| 161 | hii &= u64(maxInt(u64)) << 32; | |
| 161 | hii &= @as(u64, maxInt(u64)) << 32; | |
| 162 | 162 | hi = @bitCast(f64, hii); |
| 163 | 163 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 164 | 164 | |
| ... | ... | @@ -178,7 +178,7 @@ pub fn log10_64(x_: f64) f64 { |
| 178 | 178 | |
| 179 | 179 | test "math.log10" { |
| 180 | 180 | testing.expect(log10(f32(0.2)) == log10_32(0.2)); |
| 181 | testing.expect(log10(f64(0.2)) == log10_64(0.2)); | |
| 181 | testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2)); | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | test "math.log10_32" { |
lib/std/math/log1p.zig+3-3| ... | ... | @@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 { |
| 166 | 166 | |
| 167 | 167 | // u into [sqrt(2)/2, sqrt(2)] |
| 168 | 168 | iu = (iu & 0x000FFFFF) + 0x3FE6A09E; |
| 169 | const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF); | |
| 169 | const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF); | |
| 170 | 170 | f = @bitCast(f64, iq) - 1; |
| 171 | 171 | } |
| 172 | 172 | |
| ... | ... | @@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 { |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "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)); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | test "math.log1p_32" { |
lib/std/math/log2.zig+4-4| ... | ... | @@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 { |
| 143 | 143 | hx += 0x3FF00000 - 0x3FE6A09E; |
| 144 | 144 | k += @intCast(i32, hx >> 20) - 0x3FF; |
| 145 | 145 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 146 | ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); | |
| 146 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); | |
| 147 | 147 | x = @bitCast(f64, ix); |
| 148 | 148 | |
| 149 | 149 | const f = x - 1.0; |
| ... | ... | @@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 { |
| 158 | 158 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 159 | 159 | var hi = f - hfsq; |
| 160 | 160 | var hii = @bitCast(u64, hi); |
| 161 | hii &= u64(maxInt(u64)) << 32; | |
| 161 | hii &= @as(u64, maxInt(u64)) << 32; | |
| 162 | 162 | hi = @bitCast(f64, hii); |
| 163 | 163 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 164 | 164 | |
| ... | ... | @@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 { |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "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)); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | test "math.log2_32" { |
lib/std/math/modf.zig+4-4| ... | ... | @@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result { |
| 65 | 65 | return result; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | const mask = u32(0x007FFFFF) >> @intCast(u5, e); | |
| 68 | const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e); | |
| 69 | 69 | if (u & mask == 0) { |
| 70 | 70 | result.ipart = x; |
| 71 | 71 | result.fpart = @bitCast(f32, us); |
| ... | ... | @@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result { |
| 109 | 109 | return result; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e); | |
| 112 | const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e); | |
| 113 | 113 | if (u & mask == 0) { |
| 114 | 114 | result.ipart = x; |
| 115 | 115 | result.fpart = @bitCast(f64, us); |
| ... | ... | @@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "math.modf" { |
| 126 | const a = modf(f32(1.0)); | |
| 126 | const a = modf(@as(f32, 1.0)); | |
| 127 | 127 | const b = modf32(1.0); |
| 128 | 128 | // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still. |
| 129 | 129 | expect(a.ipart == b.ipart and a.fpart == b.fpart); |
| 130 | 130 | |
| 131 | const c = modf(f64(1.0)); | |
| 131 | const c = modf(@as(f64, 1.0)); | |
| 132 | 132 | const d = modf64(1.0); |
| 133 | 133 | expect(a.ipart == b.ipart and a.fpart == b.fpart); |
| 134 | 134 | } |
lib/std/math/round.zig+2-2| ... | ... | @@ -91,8 +91,8 @@ fn round64(x_: f64) f64 { |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | test "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)); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "math.round32" { |
lib/std/math/scalbn.zig+2-2| ... | ... | @@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 { |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | test "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)); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "math.scalbn32" { |
lib/std/math/signbit.zig+3-3| ... | ... | @@ -29,9 +29,9 @@ fn signbit64(x: f64) bool { |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | test "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)); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | test "math.signbit16" { |
lib/std/math/sin.zig+3-3| ... | ... | @@ -88,9 +88,9 @@ test "math.sin" { |
| 88 | 88 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 89 | 89 | return error.SkipZigTest; |
| 90 | 90 | } |
| 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))); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.sin32" { |
lib/std/math/sinh.zig+2-2| ... | ... | @@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 { |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "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)); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "math.sinh32" { |
lib/std/math/sqrt.zig+3-3| ... | ... | @@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "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)); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "math.sqrt16" { |
lib/std/math/tan.zig+2-2| ... | ... | @@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T { |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | test "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)); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | test "math.tan32" { |
lib/std/math/tanh.zig+2-2| ... | ... | @@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 { |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | test "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)); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | test "math.tanh32" { |
lib/std/math/trunc.zig+4-4| ... | ... | @@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 { |
| 36 | 36 | e = 1; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | m = u32(maxInt(u32)) >> @intCast(u5, e); | |
| 39 | m = @as(u32, maxInt(u32)) >> @intCast(u5, e); | |
| 40 | 40 | if (u & m == 0) { |
| 41 | 41 | return x; |
| 42 | 42 | } else { |
| ... | ... | @@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 { |
| 57 | 57 | e = 1; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | m = u64(maxInt(u64)) >> @intCast(u6, e); | |
| 60 | m = @as(u64, maxInt(u64)) >> @intCast(u6, e); | |
| 61 | 61 | if (u & m == 0) { |
| 62 | 62 | return x; |
| 63 | 63 | } else { |
| ... | ... | @@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 { |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | test "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)); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | test "math.trunc32" { |
lib/std/mem.zig+10-10| ... | ... | @@ -118,7 +118,7 @@ pub const Allocator = struct { |
| 118 | 118 | } else @alignOf(T); |
| 119 | 119 | |
| 120 | 120 | if (n == 0) { |
| 121 | return ([*]align(a) T)(undefined)[0..0]; | |
| 121 | return @as([*]align(a) T, undefined)[0..0]; | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory; |
| ... | ... | @@ -170,7 +170,7 @@ pub const Allocator = struct { |
| 170 | 170 | } |
| 171 | 171 | if (new_n == 0) { |
| 172 | 172 | self.free(old_mem); |
| 173 | return ([*]align(new_alignment) T)(undefined)[0..0]; | |
| 173 | return @as([*]align(new_alignment) T, undefined)[0..0]; | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | const old_byte_slice = @sliceToBytes(old_mem); |
| ... | ... | @@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin. |
| 523 | 523 | builtin.Endian.Little => { |
| 524 | 524 | const ShiftType = math.Log2Int(ReturnType); |
| 525 | 525 | for (bytes) |b, index| { |
| 526 | result = result | (ReturnType(b) << @intCast(ShiftType, index * 8)); | |
| 526 | result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8)); | |
| 527 | 527 | } |
| 528 | 528 | }, |
| 529 | 529 | } |
| ... | ... | @@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type { |
| 1332 | 1332 | if (comptime !trait.isSingleItemPtr(P)) |
| 1333 | 1333 | @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P)); |
| 1334 | 1334 | |
| 1335 | const size = usize(@sizeOf(meta.Child(P))); | |
| 1335 | const size = @as(usize, @sizeOf(meta.Child(P))); | |
| 1336 | 1336 | const alignment = comptime meta.alignment(P); |
| 1337 | 1337 | |
| 1338 | 1338 | if (alignment == 0) { |
| ... | ... | @@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { |
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | test "asBytes" { |
| 1356 | const deadbeef = u32(0xDEADBEEF); | |
| 1356 | const deadbeef = @as(u32, 0xDEADBEEF); | |
| 1357 | 1357 | const deadbeef_bytes = switch (builtin.endian) { |
| 1358 | 1358 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", |
| 1359 | 1359 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", |
| ... | ... | @@ -1361,7 +1361,7 @@ test "asBytes" { |
| 1361 | 1361 | |
| 1362 | 1362 | testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); |
| 1363 | 1363 | |
| 1364 | var codeface = u32(0xC0DEFACE); | |
| 1364 | var codeface = @as(u32, 0xC0DEFACE); | |
| 1365 | 1365 | for (asBytes(&codeface).*) |*b| |
| 1366 | 1366 | b.* = 0; |
| 1367 | 1367 | testing.expect(codeface == 0); |
| ... | ... | @@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | test "toBytes" { |
| 1395 | var my_bytes = toBytes(u32(0x12345678)); | |
| 1395 | var my_bytes = toBytes(@as(u32, 0x12345678)); | |
| 1396 | 1396 | switch (builtin.endian) { |
| 1397 | 1397 | builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")), |
| 1398 | 1398 | builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")), |
| ... | ... | @@ -1406,7 +1406,7 @@ test "toBytes" { |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { |
| 1409 | const size = usize(@sizeOf(T)); | |
| 1409 | const size = @as(usize, @sizeOf(T)); | |
| 1410 | 1410 | |
| 1411 | 1411 | if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) { |
| 1412 | 1412 | @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B)); |
| ... | ... | @@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ |
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | test "bytesAsValue" { |
| 1427 | const deadbeef = u32(0xDEADBEEF); | |
| 1427 | const deadbeef = @as(u32, 0xDEADBEEF); | |
| 1428 | 1428 | const deadbeef_bytes = switch (builtin.endian) { |
| 1429 | 1429 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", |
| 1430 | 1430 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", |
| ... | ... | @@ -1472,7 +1472,7 @@ test "bytesToValue" { |
| 1472 | 1472 | }; |
| 1473 | 1473 | |
| 1474 | 1474 | const deadbeef = bytesToValue(u32, deadbeef_bytes); |
| 1475 | testing.expect(deadbeef == u32(0xDEADBEEF)); | |
| 1475 | testing.expect(deadbeef == @as(u32, 0xDEADBEEF)); | |
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { |
lib/std/meta.zig+1-1| ... | ... | @@ -505,7 +505,7 @@ test "std.meta.eql" { |
| 505 | 505 | const EU = struct { |
| 506 | 506 | fn tst(err: bool) !u8 { |
| 507 | 507 | if (err) return error.Error; |
| 508 | return u8(5); | |
| 508 | return @as(u8, 5); | |
| 509 | 509 | } |
| 510 | 510 | }; |
| 511 | 511 |
lib/std/meta/trait.zig+2-2| ... | ... | @@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool { |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | test "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); | |
| 332 | 332 | testing.expect(isConstPtr(*const @typeOf(t))); |
| 333 | 333 | testing.expect(isConstPtr(@typeOf(&c))); |
| 334 | 334 | testing.expect(!isConstPtr(*@typeOf(t))); |
lib/std/net.zig+7-7| ... | ... | @@ -611,7 +611,7 @@ fn linuxLookupName( |
| 611 | 611 | // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary. |
| 612 | 612 | mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr); |
| 613 | 613 | } |
| 614 | if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; | |
| 614 | if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; | |
| 615 | 615 | if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL; |
| 616 | 616 | prefixlen = prefixMatch(sa6.addr, da6.addr); |
| 617 | 617 | } else |_| {} |
| ... | ... | @@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 { |
| 710 | 710 | // address. However the definition of the source prefix length is |
| 711 | 711 | // not clear and thus this limiting is not yet implemented. |
| 712 | 712 | var i: u8 = 0; |
| 713 | while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {} | |
| 713 | while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {} | |
| 714 | 714 | return i; |
| 715 | 715 | } |
| 716 | 716 | |
| ... | ... | @@ -1194,23 +1194,23 @@ fn dnsParse( |
| 1194 | 1194 | if (r.len < 12) return error.InvalidDnsPacket; |
| 1195 | 1195 | if ((r[3] & 15) != 0) return; |
| 1196 | 1196 | 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]; | |
| 1199 | 1199 | if (qdcount + ancount > 64) return error.InvalidDnsPacket; |
| 1200 | 1200 | while (qdcount != 0) { |
| 1201 | 1201 | qdcount -= 1; |
| 1202 | 1202 | while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; |
| 1203 | 1203 | if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) |
| 1204 | 1204 | return error.InvalidDnsPacket; |
| 1205 | p += usize(5) + @boolToInt(p[0] != 0); | |
| 1205 | p += @as(usize, 5) + @boolToInt(p[0] != 0); | |
| 1206 | 1206 | } |
| 1207 | 1207 | while (ancount != 0) { |
| 1208 | 1208 | ancount -= 1; |
| 1209 | 1209 | while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; |
| 1210 | 1210 | if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) |
| 1211 | 1211 | 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]; | |
| 1214 | 1214 | if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket; |
| 1215 | 1215 | try callback(ctx, p[1], p[10 .. 10 + len], r); |
| 1216 | 1216 | p += 10 + len; |
lib/std/os.zig+5-5| ... | ... | @@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { |
| 472 | 472 | |
| 473 | 473 | var index: usize = 0; |
| 474 | 474 | while (index < bytes.len) { |
| 475 | const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len)); | |
| 475 | const amt_to_write = math.min(bytes.len - index, @as(usize, max_bytes_len)); | |
| 476 | 476 | const rc = system.write(fd, bytes.ptr + index, amt_to_write); |
| 477 | 477 | switch (errno(rc)) { |
| 478 | 478 | 0 => { |
| ... | ... | @@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool { |
| 1526 | 1526 | } |
| 1527 | 1527 | if (builtin.os == .linux) { |
| 1528 | 1528 | var wsz: linux.winsize = undefined; |
| 1529 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 1529 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 1530 | 1530 | } |
| 1531 | 1531 | unreachable; |
| 1532 | 1532 | } |
| ... | ... | @@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool { |
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | 1549 | const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]); |
| 1550 | const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)]; | |
| 1550 | const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)]; | |
| 1551 | 1551 | const name_wide = @bytesToSlice(u16, name_bytes); |
| 1552 | 1552 | return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or |
| 1553 | 1553 | mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null; |
| ... | ... | @@ -2897,7 +2897,7 @@ pub fn res_mkquery( |
| 2897 | 2897 | // Construct query template - ID will be filled later |
| 2898 | 2898 | var q: [280]u8 = undefined; |
| 2899 | 2899 | @memset(&q, 0, n); |
| 2900 | q[2] = u8(op) * 8 + 1; | |
| 2900 | q[2] = @as(u8, op) * 8 + 1; | |
| 2901 | 2901 | q[5] = 1; |
| 2902 | 2902 | mem.copy(u8, q[13..], name); |
| 2903 | 2903 | var i: usize = 13; |
| ... | ... | @@ -3143,7 +3143,7 @@ pub fn dn_expand( |
| 3143 | 3143 | // loop invariants: p<end, dest<dend |
| 3144 | 3144 | if ((p[0] & 0xc0) != 0) { |
| 3145 | 3145 | if (p + 1 == end) return error.InvalidDnsPacket; |
| 3146 | var j = ((p[0] & usize(0x3f)) << 8) | p[1]; | |
| 3146 | var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1]; | |
| 3147 | 3147 | if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr); |
| 3148 | 3148 | if (j >= msg.len) return error.InvalidDnsPacket; |
| 3149 | 3149 | p = msg.ptr + j; |
lib/std/os/bits/dragonfly.zig+1-1| ... | ... | @@ -315,7 +315,7 @@ pub const dirent = extern struct { |
| 315 | 315 | d_name: [256]u8, |
| 316 | 316 | |
| 317 | 317 | pub fn reclen(self: dirent) u16 { |
| 318 | return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7); | |
| 318 | return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7); | |
| 319 | 319 | } |
| 320 | 320 | }; |
| 321 | 321 |
lib/std/os/bits/linux.zig+5-5| ... | ... | @@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400; |
| 559 | 559 | pub const EPOLLERR = 0x008; |
| 560 | 560 | pub const EPOLLHUP = 0x010; |
| 561 | 561 | pub const EPOLLRDHUP = 0x2000; |
| 562 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); | |
| 563 | pub const EPOLLWAKEUP = (u32(1) << 29); | |
| 564 | pub const EPOLLONESHOT = (u32(1) << 30); | |
| 565 | pub const EPOLLET = (u32(1) << 31); | |
| 562 | pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28); | |
| 563 | pub const EPOLLWAKEUP = (@as(u32, 1) << 29); | |
| 564 | pub const EPOLLONESHOT = (@as(u32, 1) << 30); | |
| 565 | pub const EPOLLET = (@as(u32, 1) << 31); | |
| 566 | 566 | |
| 567 | 567 | pub const CLOCK_REALTIME = 0; |
| 568 | 568 | pub const CLOCK_MONOTONIC = 1; |
| ... | ... | @@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool { |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | pub fn CAP_TO_MASK(cap: u8) u32 { |
| 953 | return u32(1) << u5(cap & 31); | |
| 953 | return @as(u32, 1) << u5(cap & 31); | |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | pub fn CAP_TO_INDEX(cap: u8) u8 { |
lib/std/os/linux.zig+94-94| ... | ... | @@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 { |
| 46 | 46 | |
| 47 | 47 | pub fn dup2(old: i32, new: i32) usize { |
| 48 | 48 | if (@hasDecl(@This(), "SYS_dup2")) { |
| 49 | return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new))); | |
| 49 | return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new))); | |
| 50 | 50 | } else { |
| 51 | 51 | if (old == new) { |
| 52 | 52 | if (std.debug.runtime_safety) { |
| 53 | const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD); | |
| 53 | const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD); | |
| 54 | 54 | if (@bitCast(isize, rc) < 0) return rc; |
| 55 | 55 | } |
| 56 | 56 | return @intCast(usize, old); |
| 57 | 57 | } else { |
| 58 | return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0); | |
| 58 | return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0); | |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | pub fn dup3(old: i32, new: i32, flags: u32) usize { |
| 64 | return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags); | |
| 64 | return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize { |
| 102 | 102 | |
| 103 | 103 | // TODO https://github.com/ziglang/zig/issues/265 |
| 104 | 104 | pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize { |
| 105 | return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags); | |
| 105 | return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize { |
| ... | ... | @@ -120,7 +120,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 120 | 120 | pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { |
| 121 | 121 | return syscall3( |
| 122 | 122 | SYS_getdents, |
| 123 | @bitCast(usize, isize(fd)), | |
| 123 | @bitCast(usize, @as(isize, fd)), | |
| 124 | 124 | @ptrToInt(dirp), |
| 125 | 125 | std.math.min(len, maxInt(c_int)), |
| 126 | 126 | ); |
| ... | ... | @@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { |
| 129 | 129 | pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { |
| 130 | 130 | return syscall3( |
| 131 | 131 | SYS_getdents64, |
| 132 | @bitCast(usize, isize(fd)), | |
| 132 | @bitCast(usize, @as(isize, fd)), | |
| 133 | 133 | @ptrToInt(dirp), |
| 134 | 134 | std.math.min(len, maxInt(c_int)), |
| 135 | 135 | ); |
| ... | ... | @@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize { |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize { |
| 143 | return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask); | |
| 143 | return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | pub fn inotify_rm_watch(fd: i32, wd: i32) usize { |
| 147 | return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd))); | |
| 147 | return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd))); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -152,13 +152,13 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz |
| 152 | 152 | if (@hasDecl(@This(), "SYS_readlink")) { |
| 153 | 153 | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 154 | 154 | } else { |
| 155 | return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 155 | return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // TODO https://github.com/ziglang/zig/issues/265 |
| 160 | 160 | pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 161 | return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 161 | return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize { |
| 166 | 166 | if (@hasDecl(@This(), "SYS_mkdir")) { |
| 167 | 167 | return syscall2(SYS_mkdir, @ptrToInt(path), mode); |
| 168 | 168 | } else { |
| 169 | return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode); | |
| 169 | return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode); | |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // TODO https://github.com/ziglang/zig/issues/265 |
| 174 | 174 | pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { |
| 175 | return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); | |
| 175 | return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -194,7 +194,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 194 | 194 | if (@hasDecl(@This(), "SYS_mmap2")) { |
| 195 | 195 | // Make sure the offset is also specified in multiples of page size |
| 196 | 196 | if ((offset & (MMAP2_UNIT - 1)) != 0) |
| 197 | return @bitCast(usize, isize(-EINVAL)); | |
| 197 | return @bitCast(usize, @as(isize, -EINVAL)); | |
| 198 | 198 | |
| 199 | 199 | return syscall6( |
| 200 | 200 | SYS_mmap2, |
| ... | ... | @@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 202 | 202 | length, |
| 203 | 203 | prot, |
| 204 | 204 | flags, |
| 205 | @bitCast(usize, isize(fd)), | |
| 205 | @bitCast(usize, @as(isize, fd)), | |
| 206 | 206 | @truncate(usize, offset / MMAP2_UNIT), |
| 207 | 207 | ); |
| 208 | 208 | } else { |
| ... | ... | @@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 212 | 212 | length, |
| 213 | 213 | prot, |
| 214 | 214 | flags, |
| 215 | @bitCast(usize, isize(fd)), | |
| 215 | @bitCast(usize, @as(isize, fd)), | |
| 216 | 216 | offset, |
| 217 | 217 | ); |
| 218 | 218 | } |
| ... | ... | @@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { |
| 252 | return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); | |
| 252 | return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 256 | 256 | return syscall5( |
| 257 | 257 | SYS_preadv, |
| 258 | @bitCast(usize, isize(fd)), | |
| 258 | @bitCast(usize, @as(isize, fd)), | |
| 259 | 259 | @ptrToInt(iov), |
| 260 | 260 | count, |
| 261 | 261 | @truncate(usize, offset), |
| ... | ... | @@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 266 | 266 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { |
| 267 | 267 | return syscall6( |
| 268 | 268 | SYS_preadv2, |
| 269 | @bitCast(usize, isize(fd)), | |
| 269 | @bitCast(usize, @as(isize, fd)), | |
| 270 | 270 | @ptrToInt(iov), |
| 271 | 271 | count, |
| 272 | 272 | @truncate(usize, offset), |
| ... | ... | @@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { |
| 279 | return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); | |
| 279 | return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { |
| 283 | return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); | |
| 283 | return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { |
| 287 | 287 | return syscall5( |
| 288 | 288 | SYS_pwritev, |
| 289 | @bitCast(usize, isize(fd)), | |
| 289 | @bitCast(usize, @as(isize, fd)), | |
| 290 | 290 | @ptrToInt(iov), |
| 291 | 291 | count, |
| 292 | 292 | @truncate(usize, offset), |
| ... | ... | @@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 297 | 297 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { |
| 298 | 298 | return syscall6( |
| 299 | 299 | SYS_pwritev2, |
| 300 | @bitCast(usize, isize(fd)), | |
| 300 | @bitCast(usize, @as(isize, fd)), | |
| 301 | 301 | @ptrToInt(iov), |
| 302 | 302 | count, |
| 303 | 303 | @truncate(usize, offset), |
| ... | ... | @@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize { |
| 311 | 311 | if (@hasDecl(@This(), "SYS_rmdir")) { |
| 312 | 312 | return syscall1(SYS_rmdir, @ptrToInt(path)); |
| 313 | 313 | } else { |
| 314 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); | |
| 314 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); | |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| ... | ... | @@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { |
| 320 | 320 | if (@hasDecl(@This(), "SYS_symlink")) { |
| 321 | 321 | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); |
| 322 | 322 | } else { |
| 323 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); | |
| 323 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); | |
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // TODO https://github.com/ziglang/zig/issues/265 |
| 328 | 328 | pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { |
| 329 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath)); | |
| 329 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath)); | |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // TODO https://github.com/ziglang/zig/issues/265 |
| 333 | 333 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { |
| 334 | return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); | |
| 334 | return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize { |
| 339 | 339 | if (@hasDecl(@This(), "SYS_access")) { |
| 340 | 340 | return syscall2(SYS_access, @ptrToInt(path), mode); |
| 341 | 341 | } else { |
| 342 | return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0); | |
| 342 | return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0); | |
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // TODO https://github.com/ziglang/zig/issues/265 |
| 347 | 347 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize { |
| 348 | return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags); | |
| 348 | return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags); | |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | pub fn pipe(fd: *[2]i32) usize { |
| ... | ... | @@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize { |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { |
| 366 | return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); | |
| 366 | return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); | |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 370 | return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); | |
| 370 | return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); | |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize { |
| 375 | 375 | if (@hasDecl(@This(), "SYS_rename")) { |
| 376 | 376 | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); |
| 377 | 377 | } else if (@hasDecl(@This(), "SYS_renameat")) { |
| 378 | return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); | |
| 378 | return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); | |
| 379 | 379 | } else { |
| 380 | return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0); | |
| 380 | return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0); | |
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
| ... | ... | @@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 385 | 385 | if (@hasDecl(@This(), "SYS_renameat")) { |
| 386 | 386 | return syscall4( |
| 387 | 387 | SYS_renameat, |
| 388 | @bitCast(usize, isize(oldfd)), | |
| 388 | @bitCast(usize, @as(isize, oldfd)), | |
| 389 | 389 | @ptrToInt(old), |
| 390 | @bitCast(usize, isize(newfd)), | |
| 390 | @bitCast(usize, @as(isize, newfd)), | |
| 391 | 391 | @ptrToInt(new), |
| 392 | 392 | ); |
| 393 | 393 | } else { |
| 394 | 394 | return syscall5( |
| 395 | 395 | SYS_renameat2, |
| 396 | @bitCast(usize, isize(oldfd)), | |
| 396 | @bitCast(usize, @as(isize, oldfd)), | |
| 397 | 397 | @ptrToInt(old), |
| 398 | @bitCast(usize, isize(newfd)), | |
| 398 | @bitCast(usize, @as(isize, newfd)), | |
| 399 | 399 | @ptrToInt(new), |
| 400 | 400 | 0, |
| 401 | 401 | ); |
| ... | ... | @@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 406 | 406 | pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { |
| 407 | 407 | return syscall5( |
| 408 | 408 | SYS_renameat2, |
| 409 | @bitCast(usize, isize(oldfd)), | |
| 409 | @bitCast(usize, @as(isize, oldfd)), | |
| 410 | 410 | @ptrToInt(oldpath), |
| 411 | @bitCast(usize, isize(newfd)), | |
| 411 | @bitCast(usize, @as(isize, newfd)), | |
| 412 | 412 | @ptrToInt(newpath), |
| 413 | 413 | flags, |
| 414 | 414 | ); |
| ... | ... | @@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { |
| 421 | 421 | } else { |
| 422 | 422 | return syscall4( |
| 423 | 423 | SYS_openat, |
| 424 | @bitCast(usize, isize(AT_FDCWD)), | |
| 424 | @bitCast(usize, @as(isize, AT_FDCWD)), | |
| 425 | 425 | @ptrToInt(path), |
| 426 | 426 | flags, |
| 427 | 427 | perm, |
| ... | ... | @@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize { |
| 437 | 437 | // TODO https://github.com/ziglang/zig/issues/265 |
| 438 | 438 | pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { |
| 439 | 439 | // dirfd could be negative, for example AT_FDCWD is -100 |
| 440 | return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode); | |
| 440 | return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode); | |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /// See also `clone` (from the arch-specific include) |
| ... | ... | @@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize { |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | pub fn close(fd: i32) usize { |
| 454 | return syscall1(SYS_close, @bitCast(usize, isize(fd))); | |
| 454 | return syscall1(SYS_close, @bitCast(usize, @as(isize, fd))); | |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /// Can only be called on 32 bit systems. For 64 bit see `lseek`. |
| 458 | 458 | pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { |
| 459 | 459 | return syscall5( |
| 460 | 460 | SYS__llseek, |
| 461 | @bitCast(usize, isize(fd)), | |
| 461 | @bitCast(usize, @as(isize, fd)), | |
| 462 | 462 | @truncate(usize, offset >> 32), |
| 463 | 463 | @truncate(usize, offset), |
| 464 | 464 | @ptrToInt(result), |
| ... | ... | @@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { |
| 468 | 468 | |
| 469 | 469 | /// Can only be called on 64 bit systems. For 32 bit see `llseek`. |
| 470 | 470 | pub fn lseek(fd: i32, offset: i64, whence: usize) usize { |
| 471 | return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence); | |
| 471 | return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence); | |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | pub fn exit(status: i32) noreturn { |
| 475 | _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); | |
| 475 | _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status))); | |
| 476 | 476 | unreachable; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | pub fn exit_group(status: i32) noreturn { |
| 480 | _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status))); | |
| 480 | _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status))); | |
| 481 | 481 | unreachable; |
| 482 | 482 | } |
| 483 | 483 | |
| ... | ... | @@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | pub fn kill(pid: i32, sig: i32) usize { |
| 489 | return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig))); | |
| 489 | return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); | |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize { |
| 494 | 494 | if (@hasDecl(@This(), "SYS_unlink")) { |
| 495 | 495 | return syscall1(SYS_unlink, @ptrToInt(path)); |
| 496 | 496 | } else { |
| 497 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0); | |
| 497 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0); | |
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // TODO https://github.com/ziglang/zig/issues/265 |
| 502 | 502 | pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { |
| 503 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags); | |
| 503 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); | |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | pub fn waitpid(pid: i32, status: *u32, flags: u32) usize { |
| 507 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0); | |
| 507 | return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); | |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); |
| ... | ... | @@ -519,12 +519,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { |
| 519 | 519 | const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); |
| 520 | 520 | const rc = f(clk_id, tp); |
| 521 | 521 | switch (rc) { |
| 522 | 0, @bitCast(usize, isize(-EINVAL)) => return rc, | |
| 522 | 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc, | |
| 523 | 523 | else => {}, |
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | |
| 527 | return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { |
| ... | ... | @@ -537,15 +537,15 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { |
| 537 | 537 | const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); |
| 538 | 538 | return f(clk, ts); |
| 539 | 539 | } |
| 540 | return @bitCast(usize, isize(-ENOSYS)); | |
| 540 | return @bitCast(usize, @as(isize, -ENOSYS)); | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { |
| 544 | return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | |
| 544 | return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { |
| 548 | return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | |
| 548 | return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { |
| ... | ... | @@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize { |
| 594 | 594 | |
| 595 | 595 | pub fn getuid() u32 { |
| 596 | 596 | if (@hasDecl(@This(), "SYS_getuid32")) { |
| 597 | return u32(syscall0(SYS_getuid32)); | |
| 597 | return @as(u32, syscall0(SYS_getuid32)); | |
| 598 | 598 | } else { |
| 599 | return u32(syscall0(SYS_getuid)); | |
| 599 | return @as(u32, syscall0(SYS_getuid)); | |
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | pub fn getgid() u32 { |
| 604 | 604 | if (@hasDecl(@This(), "SYS_getgid32")) { |
| 605 | return u32(syscall0(SYS_getgid32)); | |
| 605 | return @as(u32, syscall0(SYS_getgid32)); | |
| 606 | 606 | } else { |
| 607 | return u32(syscall0(SYS_getgid)); | |
| 607 | return @as(u32, syscall0(SYS_getgid)); | |
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | pub fn geteuid() u32 { |
| 612 | 612 | if (@hasDecl(@This(), "SYS_geteuid32")) { |
| 613 | return u32(syscall0(SYS_geteuid32)); | |
| 613 | return @as(u32, syscall0(SYS_geteuid32)); | |
| 614 | 614 | } else { |
| 615 | return u32(syscall0(SYS_geteuid)); | |
| 615 | return @as(u32, syscall0(SYS_geteuid)); | |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | pub fn getegid() u32 { |
| 620 | 620 | if (@hasDecl(@This(), "SYS_getegid32")) { |
| 621 | return u32(syscall0(SYS_getegid32)); | |
| 621 | return @as(u32, syscall0(SYS_getegid32)); | |
| 622 | 622 | } else { |
| 623 | return u32(syscall0(SYS_getegid)); | |
| 623 | return @as(u32, syscall0(SYS_getegid)); | |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
| ... | ... | @@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 746 | return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 746 | return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 750 | return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 750 | return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { |
| ... | ... | @@ -755,15 +755,15 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { |
| 758 | return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); | |
| 758 | return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); | |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { |
| 762 | return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); | |
| 762 | return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); | |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { |
| 766 | return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); | |
| 766 | return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); | |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { |
| ... | ... | @@ -781,7 +781,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 781 | 781 | // batch-send all messages up to the current message |
| 782 | 782 | if (next_unsent < i) { |
| 783 | 783 | const batch_size = i - next_unsent; |
| 784 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 784 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 785 | 785 | if (getErrno(r) != 0) return next_unsent; |
| 786 | 786 | if (r < batch_size) return next_unsent + r; |
| 787 | 787 | } |
| ... | ... | @@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 797 | 797 | } |
| 798 | 798 | if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR) |
| 799 | 799 | const batch_size = kvlen - next_unsent; |
| 800 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 800 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 801 | 801 | if (getErrno(r) != 0) return r; |
| 802 | 802 | return next_unsent + r; |
| 803 | 803 | } |
| 804 | 804 | return kvlen; |
| 805 | 805 | } |
| 806 | return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags); | |
| 806 | return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags); | |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { |
| 810 | return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len); | |
| 810 | return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); | |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { |
| 814 | return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); | |
| 814 | return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); | |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { |
| 818 | return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | |
| 818 | return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | pub fn shutdown(fd: i32, how: i32) usize { |
| 822 | return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how))); | |
| 822 | return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); | |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { |
| 826 | return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len)); | |
| 826 | return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); | |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | pub fn listen(fd: i32, backlog: u32) usize { |
| 830 | return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog); | |
| 830 | return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog); | |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { |
| 834 | return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); | |
| 834 | return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); | |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { |
| ... | ... | @@ -843,14 +843,14 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize { |
| 846 | return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags); | |
| 846 | return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); | |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { |
| 850 | 850 | if (@hasDecl(@This(), "SYS_fstat64")) { |
| 851 | return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); | |
| 851 | return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); | |
| 852 | 852 | } else { |
| 853 | return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); | |
| 853 | return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); | |
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | |
| ... | ... | @@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 875 | 875 | // TODO https://github.com/ziglang/zig/issues/265 |
| 876 | 876 | pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { |
| 877 | 877 | if (@hasDecl(@This(), "SYS_fstatat64")) { |
| 878 | return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 878 | return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 879 | 879 | } else { |
| 880 | return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 880 | return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 881 | 881 | } |
| 882 | 882 | } |
| 883 | 883 | |
| ... | ... | @@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S |
| 885 | 885 | if (@hasDecl(@This(), "SYS_statx")) { |
| 886 | 886 | return syscall5( |
| 887 | 887 | SYS_statx, |
| 888 | @bitCast(usize, isize(dirfd)), | |
| 888 | @bitCast(usize, @as(isize, dirfd)), | |
| 889 | 889 | @ptrToInt(path), |
| 890 | 890 | flags, |
| 891 | 891 | mask, |
| 892 | 892 | @ptrToInt(statx_buf), |
| 893 | 893 | ); |
| 894 | 894 | } |
| 895 | return @bitCast(usize, isize(-ENOSYS)); | |
| 895 | return @bitCast(usize, @as(isize, -ENOSYS)); | |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -959,7 +959,7 @@ pub fn sched_yield() usize { |
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize { |
| 962 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set)); | |
| 962 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); | |
| 963 | 963 | if (@bitCast(isize, rc) < 0) return rc; |
| 964 | 964 | if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); |
| 965 | 965 | return 0; |
| ... | ... | @@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize { |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { |
| 977 | return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev)); | |
| 977 | return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev)); | |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { |
| ... | ... | @@ -984,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout |
| 984 | 984 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { |
| 985 | 985 | return syscall6( |
| 986 | 986 | SYS_epoll_pwait, |
| 987 | @bitCast(usize, isize(epoll_fd)), | |
| 987 | @bitCast(usize, @as(isize, epoll_fd)), | |
| 988 | 988 | @ptrToInt(events), |
| 989 | 989 | @intCast(usize, maxevents), |
| 990 | @bitCast(usize, isize(timeout)), | |
| 990 | @bitCast(usize, @as(isize, timeout)), | |
| 991 | 991 | @ptrToInt(sigmask), |
| 992 | 992 | @sizeOf(sigset_t), |
| 993 | 993 | ); |
| ... | ... | @@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize { |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 1001 | return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags); | |
| 1001 | return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags); | |
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | pub const itimerspec = extern struct { |
| ... | ... | @@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct { |
| 1007 | 1007 | }; |
| 1008 | 1008 | |
| 1009 | 1009 | pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { |
| 1010 | return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value)); | |
| 1010 | return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value)); | |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { |
| 1014 | return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | |
| 1014 | return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | pub fn unshare(flags: usize) usize { |
| ... | ... | @@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { |
| 1099 | return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); | |
| 1099 | return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); | |
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | 1102 | pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize { |
| 1103 | return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args); | |
| 1103 | return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args); | |
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | test "" { |
lib/std/os/linux/arm-eabi.zig+2-2| ... | ... | @@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize { |
| 100 | 100 | pub nakedcc fn restore() void { |
| 101 | 101 | return asm volatile ("svc #0" |
| 102 | 102 | : |
| 103 | : [number] "{r7}" (usize(SYS_sigreturn)) | |
| 103 | : [number] "{r7}" (@as(usize, SYS_sigreturn)) | |
| 104 | 104 | : "memory" |
| 105 | 105 | ); |
| 106 | 106 | } |
| ... | ... | @@ -108,7 +108,7 @@ pub nakedcc fn restore() void { |
| 108 | 108 | pub nakedcc fn restore_rt() void { |
| 109 | 109 | return asm volatile ("svc #0" |
| 110 | 110 | : |
| 111 | : [number] "{r7}" (usize(SYS_rt_sigreturn)) | |
| 111 | : [number] "{r7}" (@as(usize, SYS_rt_sigreturn)) | |
| 112 | 112 | : "memory" |
| 113 | 113 | ); |
| 114 | 114 | } |
lib/std/os/linux/arm64.zig+1-1| ... | ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; |
| 93 | 93 | pub nakedcc fn restore_rt() void { |
| 94 | 94 | return asm volatile ("svc #0" |
| 95 | 95 | : |
| 96 | : [number] "{x8}" (usize(SYS_rt_sigreturn)) | |
| 96 | : [number] "{x8}" (@as(usize, SYS_rt_sigreturn)) | |
| 97 | 97 | : "memory", "cc" |
| 98 | 98 | ); |
| 99 | 99 | } |
lib/std/os/linux/mipsel.zig+3-3| ... | ... | @@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize { |
| 26 | 26 | \\ sw $3, 4($4) |
| 27 | 27 | \\ 2: |
| 28 | 28 | : [ret] "={$2}" (-> usize) |
| 29 | : [number] "{$2}" (usize(SYS_pipe)) | |
| 29 | : [number] "{$2}" (@as(usize, SYS_pipe)) | |
| 30 | 30 | : "memory", "cc", "$7" |
| 31 | 31 | ); |
| 32 | 32 | } |
| ... | ... | @@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a |
| 147 | 147 | pub nakedcc fn restore() void { |
| 148 | 148 | return asm volatile ("syscall" |
| 149 | 149 | : |
| 150 | : [number] "{$2}" (usize(SYS_sigreturn)) | |
| 150 | : [number] "{$2}" (@as(usize, SYS_sigreturn)) | |
| 151 | 151 | : "memory", "cc", "$7" |
| 152 | 152 | ); |
| 153 | 153 | } |
| ... | ... | @@ -155,7 +155,7 @@ pub nakedcc fn restore() void { |
| 155 | 155 | pub nakedcc fn restore_rt() void { |
| 156 | 156 | return asm volatile ("syscall" |
| 157 | 157 | : |
| 158 | : [number] "{$2}" (usize(SYS_rt_sigreturn)) | |
| 158 | : [number] "{$2}" (@as(usize, SYS_rt_sigreturn)) | |
| 159 | 159 | : "memory", "cc", "$7" |
| 160 | 160 | ); |
| 161 | 161 | } |
lib/std/os/linux/riscv64.zig+1-1| ... | ... | @@ -92,7 +92,7 @@ pub const restore = restore_rt; |
| 92 | 92 | pub nakedcc fn restore_rt() void { |
| 93 | 93 | return asm volatile ("ecall" |
| 94 | 94 | : |
| 95 | : [number] "{x17}" (usize(SYS_rt_sigreturn)) | |
| 95 | : [number] "{x17}" (@as(usize, SYS_rt_sigreturn)) | |
| 96 | 96 | : "memory" |
| 97 | 97 | ); |
| 98 | 98 | } |
lib/std/os/linux/vdso.zig+2-2| ... | ... | @@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 62 | 62 | |
| 63 | 63 | var i: usize = 0; |
| 64 | 64 | 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; | |
| 67 | 67 | if (0 == syms[i].st_shndx) continue; |
| 68 | 68 | if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue; |
| 69 | 69 | if (maybe_versym) |versym| { |
lib/std/os/linux/x86_64.zig+1-1| ... | ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; |
| 93 | 93 | pub nakedcc fn restore_rt() void { |
| 94 | 94 | return asm volatile ("syscall" |
| 95 | 95 | : |
| 96 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) | |
| 96 | : [number] "{rax}" (@as(usize, SYS_rt_sigreturn)) | |
| 97 | 97 | : "rcx", "r11", "memory" |
| 98 | 98 | ); |
| 99 | 99 | } |
lib/std/os/test.zig+1-1| ... | ... | @@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 { |
| 172 | 172 | |
| 173 | 173 | var counter = data.?; |
| 174 | 174 | // Count how many libraries are loaded |
| 175 | counter.* += usize(1); | |
| 175 | counter.* += @as(usize, 1); | |
| 176 | 176 | |
| 177 | 177 | // The image should contain at least a PT_LOAD segment |
| 178 | 178 | if (info.dlpi_phnum < 1) return -1; |
lib/std/os/windows.zig+1-1| ... | ... | @@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 { |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 { |
| 804 | const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime); | |
| 804 | const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime); | |
| 805 | 805 | return fromSysTime(hns); |
| 806 | 806 | } |
| 807 | 807 |
lib/std/os/zen.zig+2-2| ... | ... | @@ -138,7 +138,7 @@ pub const Syscall = enum(usize) { |
| 138 | 138 | //////////////////// |
| 139 | 139 | |
| 140 | 140 | pub fn exit(status: i32) noreturn { |
| 141 | _ = syscall1(Syscall.exit, @bitCast(usize, isize(status))); | |
| 141 | _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status))); | |
| 142 | 142 | unreachable; |
| 143 | 143 | } |
| 144 | 144 | |
| ... | ... | @@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | pub fn createThread(function: fn () void) u16 { |
| 170 | return u16(syscall1(Syscall.createThread, @ptrToInt(function))); | |
| 170 | return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function))); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | ///////////////////////// |
lib/std/packed_int_array.zig+9-9| ... | ... | @@ -331,7 +331,7 @@ test "PackedIntArray" { |
| 331 | 331 | var data = PackedArray(undefined); |
| 332 | 332 | |
| 333 | 333 | //write values, counting up |
| 334 | var i = usize(0); | |
| 334 | var i = @as(usize, 0); | |
| 335 | 335 | var count = I(0); |
| 336 | 336 | while (i < data.len()) : (i += 1) { |
| 337 | 337 | data.set(i, count); |
| ... | ... | @@ -352,7 +352,7 @@ test "PackedIntArray" { |
| 352 | 352 | test "PackedIntArray init" { |
| 353 | 353 | const PackedArray = PackedIntArray(u3, 8); |
| 354 | 354 | var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 }); |
| 355 | var i = usize(0); | |
| 355 | var i = @as(usize, 0); | |
| 356 | 356 | while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i); |
| 357 | 357 | } |
| 358 | 358 | |
| ... | ... | @@ -375,7 +375,7 @@ test "PackedIntSlice" { |
| 375 | 375 | var data = P.init(&buffer, int_count); |
| 376 | 376 | |
| 377 | 377 | //write values, counting up |
| 378 | var i = usize(0); | |
| 378 | var i = @as(usize, 0); | |
| 379 | 379 | var count = I(0); |
| 380 | 380 | while (i < data.len()) : (i += 1) { |
| 381 | 381 | data.set(i, count); |
| ... | ... | @@ -406,7 +406,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" { |
| 406 | 406 | |
| 407 | 407 | const limit = (1 << bits); |
| 408 | 408 | |
| 409 | var i = usize(0); | |
| 409 | var i = @as(usize, 0); | |
| 410 | 410 | while (i < packed_array.len()) : (i += 1) { |
| 411 | 411 | packed_array.set(i, @intCast(Int, i % limit)); |
| 412 | 412 | } |
| ... | ... | @@ -466,7 +466,7 @@ test "PackedIntSlice accumulating bit offsets" { |
| 466 | 466 | var packed_array = PackedArray(undefined); |
| 467 | 467 | |
| 468 | 468 | var packed_slice = packed_array.slice(0, packed_array.len()); |
| 469 | var i = usize(0); | |
| 469 | var i = @as(usize, 0); | |
| 470 | 470 | while (i < packed_array.len() - 1) : (i += 1) { |
| 471 | 471 | packed_slice = packed_slice.slice(1, packed_slice.len()); |
| 472 | 472 | } |
| ... | ... | @@ -476,7 +476,7 @@ test "PackedIntSlice accumulating bit offsets" { |
| 476 | 476 | var packed_array = PackedArray(undefined); |
| 477 | 477 | |
| 478 | 478 | var packed_slice = packed_array.slice(0, packed_array.len()); |
| 479 | var i = usize(0); | |
| 479 | var i = @as(usize, 0); | |
| 480 | 480 | while (i < packed_array.len() - 1) : (i += 1) { |
| 481 | 481 | packed_slice = packed_slice.slice(1, packed_slice.len()); |
| 482 | 482 | } |
| ... | ... | @@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 493 | 493 | var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9); |
| 494 | 494 | const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3); |
| 495 | 495 | |
| 496 | var i = usize(0); | |
| 496 | var i = @as(usize, 0); | |
| 497 | 497 | while (i < packed_slice_cast_2.len()) : (i += 1) { |
| 498 | 498 | const val = switch (builtin.endian) { |
| 499 | 499 | .Big => 0b01, |
| ... | ... | @@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 541 | 541 | testing.expect(packed_array_be.bytes[0] == 0b00000001); |
| 542 | 542 | testing.expect(packed_array_be.bytes[1] == 0b00100011); |
| 543 | 543 | |
| 544 | var i = usize(0); | |
| 544 | var i = @as(usize, 0); | |
| 545 | 545 | while (i < packed_array_be.len()) : (i += 1) { |
| 546 | 546 | testing.expect(packed_array_be.get(i) == i); |
| 547 | 547 | } |
| ... | ... | @@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 579 | 579 | testing.expect(packed_array_be.bytes[3] == 0b00000001); |
| 580 | 580 | testing.expect(packed_array_be.bytes[4] == 0b00000000); |
| 581 | 581 | |
| 582 | var i = usize(0); | |
| 582 | var i = @as(usize, 0); | |
| 583 | 583 | while (i < packed_array_be.len()) : (i += 1) { |
| 584 | 584 | testing.expect(packed_array_be.get(i) == i); |
| 585 | 585 | } |
lib/std/pdb.zig+1-1| ... | ... | @@ -532,7 +532,7 @@ const Msf = struct { |
| 532 | 532 | const stream_sizes = try allocator.alloc(u32, stream_count); |
| 533 | 533 | defer allocator.free(stream_sizes); |
| 534 | 534 | |
| 535 | // Microsoft's implementation uses u32(-1) for inexistant streams. | |
| 535 | // Microsoft's implementation uses @as(u32, -1) for inexistant streams. | |
| 536 | 536 | // These streams are not used, but still participate in the file |
| 537 | 537 | // and must be taken into account when resolving stream indices. |
| 538 | 538 | const Nil = 0xFFFFFFFF; |
lib/std/priority_queue.zig+30-30| ... | ... | @@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" { |
| 236 | 236 | try queue.add(23); |
| 237 | 237 | try queue.add(25); |
| 238 | 238 | 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()); | |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | test "std.PriorityQueue: add and remove same min heap" { |
| ... | ... | @@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" { |
| 254 | 254 | try queue.add(2); |
| 255 | 255 | try queue.add(1); |
| 256 | 256 | 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()); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | test "std.PriorityQueue: removeOrNull on empty" { |
| ... | ... | @@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" { |
| 276 | 276 | try queue.add(9); |
| 277 | 277 | try queue.add(3); |
| 278 | 278 | 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()); | |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | test "std.PriorityQueue: peek" { |
| ... | ... | @@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" { |
| 289 | 289 | try queue.add(9); |
| 290 | 290 | try queue.add(3); |
| 291 | 291 | 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().?); | |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | test "std.PriorityQueue: sift up with odd indices" { |
| ... | ... | @@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" { |
| 341 | 341 | try queue.add(23); |
| 342 | 342 | try queue.add(25); |
| 343 | 343 | 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()); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | test "std.PriorityQueue: add and remove same max heap" { |
| ... | ... | @@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" { |
| 359 | 359 | try queue.add(2); |
| 360 | 360 | try queue.add(1); |
| 361 | 361 | 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()); | |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | test "std.PriorityQueue: iterator" { |
| ... | ... | @@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" { |
| 386 | 386 | _ = map.remove(e); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | expectEqual(usize(0), map.count()); | |
| 389 | expectEqual(@as(usize, 0), map.count()); | |
| 390 | 390 | } |
lib/std/rand.zig+4-4| ... | ... | @@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct { |
| 633 | 633 | const r = s0 +% s1; |
| 634 | 634 | |
| 635 | 635 | 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)); | |
| 638 | 638 | |
| 639 | 639 | return r; |
| 640 | 640 | } |
| ... | ... | @@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct { |
| 652 | 652 | inline for (table) |entry| { |
| 653 | 653 | var b: usize = 0; |
| 654 | 654 | while (b < 64) : (b += 1) { |
| 655 | if ((entry & (u64(1) << @intCast(u6, b))) != 0) { | |
| 655 | if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) { | |
| 656 | 656 | s0 ^= self.s[0]; |
| 657 | 657 | s1 ^= self.s[1]; |
| 658 | 658 | } |
| ... | ... | @@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void { |
| 1090 | 1090 | testRangeBias(r, start, end, false); |
| 1091 | 1091 | } |
| 1092 | 1092 | fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void { |
| 1093 | const count = @intCast(usize, i32(end) - i32(start)); | |
| 1093 | const count = @intCast(usize, @as(i32, end) - @as(i32, start)); | |
| 1094 | 1094 | var values_buffer = [_]bool{false} ** 0x100; |
| 1095 | 1095 | const values = values_buffer[0..count]; |
| 1096 | 1096 | var i: usize = 0; |
lib/std/rand/ziggurat.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 { |
| 17 | 17 | // We manually construct a float from parts as we can avoid an extra random lookup here by |
| 18 | 18 | // using the unused exponent for the lookup table entry. |
| 19 | 19 | const bits = random.scalar(u64); |
| 20 | const i = usize(bits & 0xff); | |
| 20 | const i = @as(usize, bits & 0xff); | |
| 21 | 21 | |
| 22 | 22 | const u = blk: { |
| 23 | 23 | if (tables.is_symmetric) { |
lib/std/segmented_list.zig+5-5| ... | ... | @@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 162 | 162 | /// Grows or shrinks capacity to match usage. |
| 163 | 163 | pub fn setCapacity(self: *Self, new_capacity: usize) !void { |
| 164 | 164 | if (prealloc_item_count != 0) { |
| 165 | if (new_capacity <= usize(1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) { | |
| 165 | if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) { | |
| 166 | 166 | return self.shrinkCapacity(new_capacity); |
| 167 | 167 | } |
| 168 | 168 | } |
| ... | ... | @@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 231 | 231 | |
| 232 | 232 | fn shelfSize(shelf_index: ShelfIndex) usize { |
| 233 | 233 | if (prealloc_item_count == 0) { |
| 234 | return usize(1) << shelf_index; | |
| 234 | return @as(usize, 1) << shelf_index; | |
| 235 | 235 | } |
| 236 | return usize(1) << (shelf_index + (prealloc_exp + 1)); | |
| 236 | return @as(usize, 1) << (shelf_index + (prealloc_exp + 1)); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | fn shelfIndex(list_index: usize) ShelfIndex { |
| ... | ... | @@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 245 | 245 | |
| 246 | 246 | fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize { |
| 247 | 247 | if (prealloc_item_count == 0) { |
| 248 | return (list_index + 1) - (usize(1) << shelf_index); | |
| 248 | return (list_index + 1) - (@as(usize, 1) << shelf_index); | |
| 249 | 249 | } |
| 250 | return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index)); | |
| 250 | return list_index + prealloc_item_count - (@as(usize, 1) << ((prealloc_exp + 1) + shelf_index)); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void { |
lib/std/sort.zig+4-4| ... | ... | @@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s |
| 813 | 813 | // where have some idea as to how many unique values there are and where the next value might be |
| 814 | 814 | fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 815 | 815 | if (range.length() == 0) return range.start; |
| 816 | const skip = math.max(range.length() / unique, usize(1)); | |
| 816 | const skip = math.max(range.length() / unique, @as(usize, 1)); | |
| 817 | 817 | |
| 818 | 818 | var index = range.start + skip; |
| 819 | 819 | while (lessThan(items[index - 1], value)) : (index += skip) { |
| ... | ... | @@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh |
| 827 | 827 | |
| 828 | 828 | fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 829 | 829 | if (range.length() == 0) return range.start; |
| 830 | const skip = math.max(range.length() / unique, usize(1)); | |
| 830 | const skip = math.max(range.length() / unique, @as(usize, 1)); | |
| 831 | 831 | |
| 832 | 832 | var index = range.end - skip; |
| 833 | 833 | while (index > range.start and !lessThan(items[index - 1], value)) : (index -= skip) { |
| ... | ... | @@ -841,7 +841,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessT |
| 841 | 841 | |
| 842 | 842 | fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 843 | 843 | if (range.length() == 0) return range.start; |
| 844 | const skip = math.max(range.length() / unique, usize(1)); | |
| 844 | const skip = math.max(range.length() / unique, @as(usize, 1)); | |
| 845 | 845 | |
| 846 | 846 | var index = range.start + skip; |
| 847 | 847 | while (!lessThan(value, items[index - 1])) : (index += skip) { |
| ... | ... | @@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha |
| 855 | 855 | |
| 856 | 856 | fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 857 | 857 | if (range.length() == 0) return range.start; |
| 858 | const skip = math.max(range.length() / unique, usize(1)); | |
| 858 | const skip = math.max(range.length() / unique, @as(usize, 1)); | |
| 859 | 859 | |
| 860 | 860 | var index = range.end - skip; |
| 861 | 861 | while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) { |
lib/std/special/c.zig+3-3| ... | ... | @@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int { |
| 62 | 62 | r += 1; |
| 63 | 63 | n -= 1; |
| 64 | 64 | } |
| 65 | return c_int(l[0]) - c_int(r[0]); | |
| 65 | return @as(c_int, l[0]) - @as(c_int, r[0]); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | extern fn strerror(errnum: c_int) [*]const u8 { |
| ... | ... | @@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 540 | 540 | // scale result up |
| 541 | 541 | if (ex > 0) { |
| 542 | 542 | ux -%= 1 << digits; |
| 543 | ux |= uint(@bitCast(u32, ex)) << digits; | |
| 543 | ux |= @as(uint, @bitCast(u32, ex)) << digits; | |
| 544 | 544 | } else { |
| 545 | 545 | ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1)); |
| 546 | 546 | } |
| ... | ... | @@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 { |
| 687 | 687 | |
| 688 | 688 | export fn sqrtf(x: f32) f32 { |
| 689 | 689 | const tiny: f32 = 1.0e-30; |
| 690 | const sign: i32 = @bitCast(i32, u32(0x80000000)); | |
| 690 | const sign: i32 = @bitCast(i32, @as(u32, 0x80000000)); | |
| 691 | 691 | var ix: i32 = @bitCast(i32, x); |
| 692 | 692 | |
| 693 | 693 | if ((ix & 0x7F800000) == 0x7F800000) { |
lib/std/special/compiler_rt.zig+17-17| ... | ... | @@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 { |
| 672 | 672 | // special cases |
| 673 | 673 | if (d == 0) return 0; // ?! |
| 674 | 674 | if (n == 0) return 0; |
| 675 | var sr = @bitCast(c_uint, c_int(@clz(u32, d)) - c_int(@clz(u32, n))); | |
| 675 | var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n))); | |
| 676 | 676 | // 0 <= sr <= n_uword_bits - 1 or sr large |
| 677 | 677 | if (sr > n_uword_bits - 1) { |
| 678 | 678 | // d > r |
| ... | ... | @@ -1414,10 +1414,10 @@ test "test_divsi3" { |
| 1414 | 1414 | [_]i32{ -2, 1, -2 }, |
| 1415 | 1415 | [_]i32{ -2, -1, 2 }, |
| 1416 | 1416 | |
| 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)) }, | |
| 1421 | 1421 | }; |
| 1422 | 1422 | |
| 1423 | 1423 | for (cases) |case| { |
| ... | ... | @@ -1443,8 +1443,8 @@ test "test_divmodsi4" { |
| 1443 | 1443 | [_]i32{ 19, 5, 3, 4 }, |
| 1444 | 1444 | [_]i32{ 19, -5, -3, 4 }, |
| 1445 | 1445 | |
| 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 }, | |
| 1448 | 1448 | }; |
| 1449 | 1449 | |
| 1450 | 1450 | for (cases) |case| { |
| ... | ... | @@ -1467,10 +1467,10 @@ test "test_divdi3" { |
| 1467 | 1467 | [_]i64{ -2, 1, -2 }, |
| 1468 | 1468 | [_]i64{ -2, -1, 2 }, |
| 1469 | 1469 | |
| 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)) }, | |
| 1474 | 1474 | }; |
| 1475 | 1475 | |
| 1476 | 1476 | for (cases) |case| { |
| ... | ... | @@ -1492,12 +1492,12 @@ test "test_moddi3" { |
| 1492 | 1492 | [_]i64{ -5, 3, -2 }, |
| 1493 | 1493 | [_]i64{ -5, -3, -2 }, |
| 1494 | 1494 | |
| 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 }, | |
| 1501 | 1501 | }; |
| 1502 | 1502 | |
| 1503 | 1503 | for (cases) |case| { |
lib/std/special/compiler_rt/addXf3.zig+13-13| ... | ... | @@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | pub extern fn __subsf3(a: f32, b: f32) f32 { |
| 22 | const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (u32(1) << 31)); | |
| 22 | const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31)); | |
| 23 | 23 | return addXf3(f32, a, neg_b); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | pub extern fn __subdf3(a: f64, b: f64) f64 { |
| 27 | const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (u64(1) << 63)); | |
| 27 | const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63)); | |
| 28 | 28 | return addXf3(f64, a, neg_b); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | pub extern fn __subtf3(a: f128, b: f128) f128 { |
| 32 | const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127)); | |
| 32 | const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127)); | |
| 33 | 33 | return addXf3(f128, a, neg_b); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 |
| 37 | 37 | fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 38 | 38 | const Z = @IntType(false, T.bit_count); |
| 39 | const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); | |
| 39 | const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); | |
| 40 | 40 | const significandBits = std.math.floatMantissaBits(T); |
| 41 | const implicitBit = Z(1) << significandBits; | |
| 41 | const implicitBit = @as(Z, 1) << significandBits; | |
| 42 | 42 | |
| 43 | 43 | const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit); |
| 44 | 44 | significand.* <<= @intCast(S, shift); |
| ... | ... | @@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 48 | 48 | // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 |
| 49 | 49 | fn addXf3(comptime T: type, a: T, b: T) T { |
| 50 | 50 | const Z = @IntType(false, T.bit_count); |
| 51 | const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); | |
| 51 | const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); | |
| 52 | 52 | |
| 53 | 53 | const typeWidth = T.bit_count; |
| 54 | 54 | const significandBits = std.math.floatMantissaBits(T); |
| 55 | 55 | const exponentBits = std.math.floatExponentBits(T); |
| 56 | 56 | |
| 57 | const signBit = (Z(1) << (significandBits + exponentBits)); | |
| 57 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); | |
| 58 | 58 | const maxExponent = ((1 << exponentBits) - 1); |
| 59 | 59 | const exponentBias = (maxExponent >> 1); |
| 60 | 60 | |
| 61 | const implicitBit = (Z(1) << significandBits); | |
| 61 | const implicitBit = (@as(Z, 1) << significandBits); | |
| 62 | 62 | const quietBit = implicitBit >> 1; |
| 63 | 63 | const significandMask = implicitBit - 1; |
| 64 | 64 | |
| ... | ... | @@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 78 | 78 | const infRep = @bitCast(Z, std.math.inf(T)); |
| 79 | 79 | |
| 80 | 80 | // 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)) | |
| 83 | 83 | { |
| 84 | 84 | // NaN + anything = qNaN |
| 85 | 85 | if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit); |
| ... | ... | @@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 148 | 148 | const @"align" = @intCast(Z, aExponent - bExponent); |
| 149 | 149 | if (@"align" != 0) { |
| 150 | 150 | if (@"align" < typeWidth) { |
| 151 | const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0; | |
| 151 | const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0; | |
| 152 | 152 | bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky; |
| 153 | 153 | } else { |
| 154 | 154 | bSignificand = 1; // sticky; b is known to be non-zero. |
| ... | ... | @@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 157 | 157 | if (subtraction) { |
| 158 | 158 | aSignificand -= bSignificand; |
| 159 | 159 | // If a == -b, return +zero. |
| 160 | if (aSignificand == 0) return @bitCast(T, Z(0)); | |
| 160 | if (aSignificand == 0) return @bitCast(T, @as(Z, 0)); | |
| 161 | 161 | |
| 162 | 162 | // If partial cancellation occured, we need to left-shift the result |
| 163 | 163 | // and adjust the exponent: |
| ... | ... | @@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 185 | 185 | // Result is denormal before rounding; the exponent is zero and we |
| 186 | 186 | // need to shift the significand. |
| 187 | 187 | const shift = @intCast(Z, 1 - aExponent); |
| 188 | const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0; | |
| 188 | const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) @as(Z, 1) else 0; | |
| 189 | 189 | aSignificand = aSignificand >> @intCast(S, shift | sticky); |
| 190 | 190 | aExponent = 0; |
| 191 | 191 | } |
lib/std/special/compiler_rt/addXf3_test.zig+4-4| ... | ... | @@ -3,8 +3,8 @@ |
| 3 | 3 | // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c |
| 4 | 4 | // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c |
| 5 | 5 | |
| 6 | const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64); | |
| 7 | const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64); | |
| 6 | const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64); | |
| 7 | const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); | |
| 8 | 8 | |
| 9 | 9 | const __addtf3 = @import("addXf3.zig").__addtf3; |
| 10 | 10 | |
| ... | ... | @@ -34,7 +34,7 @@ test "addtf3" { |
| 34 | 34 | test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); |
| 35 | 35 | |
| 36 | 36 | // 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); | |
| 38 | 38 | |
| 39 | 39 | // inf + inf = inf |
| 40 | 40 | test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0); |
| ... | ... | @@ -75,7 +75,7 @@ test "subtf3" { |
| 75 | 75 | test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); |
| 76 | 76 | |
| 77 | 77 | // 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); | |
| 79 | 79 | |
| 80 | 80 | // inf - any = inf |
| 81 | 81 | test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); |
lib/std/special/compiler_rt/comparedf2.zig+10-10| ... | ... | @@ -13,19 +13,19 @@ const srep_t = i64; |
| 13 | 13 | const typeWidth = rep_t.bit_count; |
| 14 | 14 | const significandBits = std.math.floatMantissaBits(fp_t); |
| 15 | 15 | const exponentBits = std.math.floatExponentBits(fp_t); |
| 16 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | |
| 16 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 17 | 17 | const absMask = signBit - 1; |
| 18 | const implicitBit = rep_t(1) << significandBits; | |
| 18 | const implicitBit = @as(rep_t, 1) << significandBits; | |
| 19 | 19 | const significandMask = implicitBit - 1; |
| 20 | 20 | const exponentMask = absMask ^ significandMask; |
| 21 | 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); |
| 22 | 22 | |
| 23 | 23 | // TODO https://github.com/ziglang/zig/issues/641 |
| 24 | 24 | // and then make the return types of some of these functions the enum instead of c_int |
| 25 | const LE_LESS = c_int(-1); | |
| 26 | const LE_EQUAL = c_int(0); | |
| 27 | const LE_GREATER = c_int(1); | |
| 28 | const LE_UNORDERED = c_int(1); | |
| 25 | const LE_LESS = @as(c_int, -1); | |
| 26 | const LE_EQUAL = @as(c_int, 0); | |
| 27 | const LE_GREATER = @as(c_int, 1); | |
| 28 | const LE_UNORDERED = @as(c_int, 1); | |
| 29 | 29 | |
| 30 | 30 | pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { |
| 31 | 31 | @setRuntimeSafety(is_test); |
| ... | ... | @@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { |
| 65 | 65 | |
| 66 | 66 | // TODO https://github.com/ziglang/zig/issues/641 |
| 67 | 67 | // and then make the return types of some of these functions the enum instead of c_int |
| 68 | const GE_LESS = c_int(-1); | |
| 69 | const GE_EQUAL = c_int(0); | |
| 70 | const GE_GREATER = c_int(1); | |
| 71 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | |
| 68 | const GE_LESS = @as(c_int, -1); | |
| 69 | const GE_EQUAL = @as(c_int, 0); | |
| 70 | const GE_GREATER = @as(c_int, 1); | |
| 71 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED | |
| 72 | 72 | |
| 73 | 73 | pub extern fn __gedf2(a: fp_t, b: fp_t) c_int { |
| 74 | 74 | @setRuntimeSafety(is_test); |
lib/std/special/compiler_rt/comparesf2.zig+10-10| ... | ... | @@ -13,19 +13,19 @@ const srep_t = i32; |
| 13 | 13 | const typeWidth = rep_t.bit_count; |
| 14 | 14 | const significandBits = std.math.floatMantissaBits(fp_t); |
| 15 | 15 | const exponentBits = std.math.floatExponentBits(fp_t); |
| 16 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | |
| 16 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 17 | 17 | const absMask = signBit - 1; |
| 18 | const implicitBit = rep_t(1) << significandBits; | |
| 18 | const implicitBit = @as(rep_t, 1) << significandBits; | |
| 19 | 19 | const significandMask = implicitBit - 1; |
| 20 | 20 | const exponentMask = absMask ^ significandMask; |
| 21 | 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); |
| 22 | 22 | |
| 23 | 23 | // TODO https://github.com/ziglang/zig/issues/641 |
| 24 | 24 | // and then make the return types of some of these functions the enum instead of c_int |
| 25 | const LE_LESS = c_int(-1); | |
| 26 | const LE_EQUAL = c_int(0); | |
| 27 | const LE_GREATER = c_int(1); | |
| 28 | const LE_UNORDERED = c_int(1); | |
| 25 | const LE_LESS = @as(c_int, -1); | |
| 26 | const LE_EQUAL = @as(c_int, 0); | |
| 27 | const LE_GREATER = @as(c_int, 1); | |
| 28 | const LE_UNORDERED = @as(c_int, 1); | |
| 29 | 29 | |
| 30 | 30 | pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { |
| 31 | 31 | @setRuntimeSafety(is_test); |
| ... | ... | @@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { |
| 65 | 65 | |
| 66 | 66 | // TODO https://github.com/ziglang/zig/issues/641 |
| 67 | 67 | // and then make the return types of some of these functions the enum instead of c_int |
| 68 | const GE_LESS = c_int(-1); | |
| 69 | const GE_EQUAL = c_int(0); | |
| 70 | const GE_GREATER = c_int(1); | |
| 71 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | |
| 68 | const GE_LESS = @as(c_int, -1); | |
| 69 | const GE_EQUAL = @as(c_int, 0); | |
| 70 | const GE_GREATER = @as(c_int, 1); | |
| 71 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED | |
| 72 | 72 | |
| 73 | 73 | pub extern fn __gesf2(a: fp_t, b: fp_t) c_int { |
| 74 | 74 | @setRuntimeSafety(is_test); |
lib/std/special/compiler_rt/comparetf2.zig+10-10| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | // TODO https://github.com/ziglang/zig/issues/641 |
| 2 | 2 | // and then make the return types of some of these functions the enum instead of c_int |
| 3 | const LE_LESS = c_int(-1); | |
| 4 | const LE_EQUAL = c_int(0); | |
| 5 | const LE_GREATER = c_int(1); | |
| 6 | const LE_UNORDERED = c_int(1); | |
| 3 | const LE_LESS = @as(c_int, -1); | |
| 4 | const LE_EQUAL = @as(c_int, 0); | |
| 5 | const LE_GREATER = @as(c_int, 1); | |
| 6 | const LE_UNORDERED = @as(c_int, 1); | |
| 7 | 7 | |
| 8 | 8 | const rep_t = u128; |
| 9 | 9 | const srep_t = i128; |
| ... | ... | @@ -11,9 +11,9 @@ const srep_t = i128; |
| 11 | 11 | const typeWidth = rep_t.bit_count; |
| 12 | 12 | const significandBits = 112; |
| 13 | 13 | const exponentBits = (typeWidth - significandBits - 1); |
| 14 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | |
| 14 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 15 | 15 | const absMask = signBit - 1; |
| 16 | const implicitBit = rep_t(1) << significandBits; | |
| 16 | const implicitBit = @as(rep_t, 1) << significandBits; | |
| 17 | 17 | const significandMask = implicitBit - 1; |
| 18 | 18 | const exponentMask = absMask ^ significandMask; |
| 19 | 19 | const infRep = exponentMask; |
| ... | ... | @@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int { |
| 60 | 60 | |
| 61 | 61 | // TODO https://github.com/ziglang/zig/issues/641 |
| 62 | 62 | // and then make the return types of some of these functions the enum instead of c_int |
| 63 | const GE_LESS = c_int(-1); | |
| 64 | const GE_EQUAL = c_int(0); | |
| 65 | const GE_GREATER = c_int(1); | |
| 66 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | |
| 63 | const GE_LESS = @as(c_int, -1); | |
| 64 | const GE_EQUAL = @as(c_int, 0); | |
| 65 | const GE_GREATER = @as(c_int, 1); | |
| 66 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED | |
| 67 | 67 | |
| 68 | 68 | pub extern fn __getf2(a: f128, b: f128) c_int { |
| 69 | 69 | @setRuntimeSafety(is_test); |
lib/std/special/compiler_rt/divdf3.zig+33-33| ... | ... | @@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 14 | 14 | const significandBits = std.math.floatMantissaBits(f64); |
| 15 | 15 | const exponentBits = std.math.floatExponentBits(f64); |
| 16 | 16 | |
| 17 | const signBit = (Z(1) << (significandBits + exponentBits)); | |
| 17 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); | |
| 18 | 18 | const maxExponent = ((1 << exponentBits) - 1); |
| 19 | 19 | const exponentBias = (maxExponent >> 1); |
| 20 | 20 | |
| 21 | const implicitBit = (Z(1) << significandBits); | |
| 21 | const implicitBit = (@as(Z, 1) << significandBits); | |
| 22 | 22 | const quietBit = implicitBit >> 1; |
| 23 | 23 | const significandMask = implicitBit - 1; |
| 24 | 24 | |
| ... | ... | @@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 91 | 91 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 92 | 92 | // is accurate to about 3.5 binary digits. |
| 93 | 93 | const q31b: u32 = @truncate(u32, bSignificand >> 21); |
| 94 | var recip32 = u32(0x7504f333) -% q31b; | |
| 94 | var recip32 = @as(u32, 0x7504f333) -% q31b; | |
| 95 | 95 | |
| 96 | 96 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: |
| 97 | 97 | // |
| ... | ... | @@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 101 | 101 | // with each iteration, so after three iterations, we have about 28 binary |
| 102 | 102 | // digits of accuracy. |
| 103 | 103 | 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); | |
| 110 | 110 | |
| 111 | 111 | // recip32 might have overflowed to exactly zero in the preceding |
| 112 | 112 | // computation if the high word of b is exactly 1.0. This would sabotage |
| ... | ... | @@ -119,10 +119,10 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 119 | 119 | const q63blo: u32 = @truncate(u32, bSignificand << 11); |
| 120 | 120 | var correction: u64 = undefined; |
| 121 | 121 | var reciprocal: u64 = undefined; |
| 122 | correction = ~(u64(recip32) *% q31b +% (u64(recip32) *% q63blo >> 32)) +% 1; | |
| 122 | correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1; | |
| 123 | 123 | const cHi = @truncate(u32, correction >> 32); |
| 124 | 124 | const cLo = @truncate(u32, correction); |
| 125 | reciprocal = u64(recip32) *% cHi +% (u64(recip32) *% cLo >> 32); | |
| 125 | reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32); | |
| 126 | 126 | |
| 127 | 127 | // We already adjusted the 32-bit estimate, now we need to adjust the final |
| 128 | 128 | // 64-bit reciprocal estimate downward to ensure that it is strictly smaller |
| ... | ... | @@ -195,7 +195,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 195 | 195 | // Clear the implicit bit |
| 196 | 196 | var absResult = quotient & significandMask; |
| 197 | 197 | // Insert the exponent |
| 198 | absResult |= @bitCast(Z, SignedZ(writtenExponent)) << significandBits; | |
| 198 | absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits; | |
| 199 | 199 | // Round |
| 200 | 200 | absResult +%= round; |
| 201 | 201 | // Insert the sign and return |
| ... | ... | @@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 208 | 208 | switch (Z) { |
| 209 | 209 | u32 => { |
| 210 | 210 | // 32x32 --> 64 bit multiply |
| 211 | const product = u64(a) * u64(b); | |
| 211 | const product = @as(u64, a) * @as(u64, b); | |
| 212 | 212 | hi.* = @truncate(u32, product >> 32); |
| 213 | 213 | lo.* = @truncate(u32, product); |
| 214 | 214 | }, |
| ... | ... | @@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 237 | 237 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; |
| 238 | 238 | }, |
| 239 | 239 | 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); | |
| 243 | 243 | const S = struct { |
| 244 | 244 | fn Word_1(x: u128) u64 { |
| 245 | 245 | return @truncate(u32, x >> 96); |
| ... | ... | @@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 275 | 275 | const product43: u64 = S.Word_4(a) * S.Word_3(b); |
| 276 | 276 | const product44: u64 = S.Word_4(a) * S.Word_4(b); |
| 277 | 277 | |
| 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); | |
| 294 | 294 | |
| 295 | 295 | const r0: u128 = (sum0 & Word_FullMask) +% |
| 296 | 296 | ((sum1 & Word_LoMask) << 32); |
| ... | ... | @@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 316 | 316 | @setRuntimeSafety(builtin.is_test); |
| 317 | 317 | const Z = @IntType(false, T.bit_count); |
| 318 | 318 | const significandBits = std.math.floatMantissaBits(T); |
| 319 | const implicitBit = Z(1) << significandBits; | |
| 319 | const implicitBit = @as(Z, 1) << significandBits; | |
| 320 | 320 | |
| 321 | 321 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); |
| 322 | 322 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
lib/std/special/compiler_rt/divsf3.zig+11-11| ... | ... | @@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 13 | 13 | const significandBits = std.math.floatMantissaBits(f32); |
| 14 | 14 | const exponentBits = std.math.floatExponentBits(f32); |
| 15 | 15 | |
| 16 | const signBit = (Z(1) << (significandBits + exponentBits)); | |
| 16 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); | |
| 17 | 17 | const maxExponent = ((1 << exponentBits) - 1); |
| 18 | 18 | const exponentBias = (maxExponent >> 1); |
| 19 | 19 | |
| 20 | const implicitBit = (Z(1) << significandBits); | |
| 20 | const implicitBit = (@as(Z, 1) << significandBits); | |
| 21 | 21 | const quietBit = implicitBit >> 1; |
| 22 | 22 | const significandMask = implicitBit - 1; |
| 23 | 23 | |
| ... | ... | @@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 90 | 90 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 91 | 91 | // is accurate to about 3.5 binary digits. |
| 92 | 92 | const q31b = bSignificand << 8; |
| 93 | var reciprocal = u32(0x7504f333) -% q31b; | |
| 93 | var reciprocal = @as(u32, 0x7504f333) -% q31b; | |
| 94 | 94 | |
| 95 | 95 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: |
| 96 | 96 | // |
| ... | ... | @@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 100 | 100 | // with each iteration, so after three iterations, we have about 28 binary |
| 101 | 101 | // digits of accuracy. |
| 102 | 102 | 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); | |
| 109 | 109 | |
| 110 | 110 | // Exhaustive testing shows that the error in reciprocal after three steps |
| 111 | 111 | // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our |
| ... | ... | @@ -127,7 +127,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 127 | 127 | // is the error in the reciprocal of b scaled by the maximum |
| 128 | 128 | // possible value of a. As a consequence of this error bound, |
| 129 | 129 | // 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); | |
| 131 | 131 | |
| 132 | 132 | // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). |
| 133 | 133 | // In either case, we are going to compute a residual of the form |
| ... | ... | @@ -189,7 +189,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 189 | 189 | @setRuntimeSafety(builtin.is_test); |
| 190 | 190 | const Z = @IntType(false, T.bit_count); |
| 191 | 191 | const significandBits = std.math.floatMantissaBits(T); |
| 192 | const implicitBit = Z(1) << significandBits; | |
| 192 | const implicitBit = @as(Z, 1) << significandBits; | |
| 193 | 193 | |
| 194 | 194 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); |
| 195 | 195 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
lib/std/special/compiler_rt/divti3_test.zig+4-4| ... | ... | @@ -14,8 +14,8 @@ test "divti3" { |
| 14 | 14 | test__divti3(-2, 1, -2); |
| 15 | 15 | test__divti3(-2, -1, 2); |
| 16 | 16 | |
| 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))); | |
| 21 | 21 | } |
lib/std/special/compiler_rt/extendXfYf2.zig+7-7| ... | ... | @@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 49 | 49 | const dstInfExp = (1 << dstExpBits) - 1; |
| 50 | 50 | const dstExpBias = dstInfExp >> 1; |
| 51 | 51 | |
| 52 | const dstMinNormal: dst_rep_t = dst_rep_t(1) << dstSigBits; | |
| 52 | const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits; | |
| 53 | 53 | |
| 54 | 54 | // Break a into a sign and representation of the absolute value |
| 55 | 55 | const aRep: src_rep_t = @bitCast(src_rep_t, a); |
| ... | ... | @@ -61,7 +61,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 61 | 61 | // a is a normal number. |
| 62 | 62 | // Extend to the destination type by shifting the significand and |
| 63 | 63 | // exponent into the proper position and rebiasing the exponent. |
| 64 | absResult = dst_rep_t(aAbs) << (dstSigBits - srcSigBits); | |
| 64 | absResult = @as(dst_rep_t, aAbs) << (dstSigBits - srcSigBits); | |
| 65 | 65 | absResult += (dstExpBias - srcExpBias) << dstSigBits; |
| 66 | 66 | } else if (aAbs >= srcInfinity) { |
| 67 | 67 | // a is NaN or infinity. |
| ... | ... | @@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 69 | 69 | // bit (if needed) and right-aligning the rest of the trailing NaN |
| 70 | 70 | // payload field. |
| 71 | 71 | 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); | |
| 74 | 74 | } else if (aAbs != 0) { |
| 75 | 75 | // a is denormal. |
| 76 | 76 | // renormalize the significand and clear the leading bit, then insert |
| 77 | 77 | // the correct adjusted exponent in the destination type. |
| 78 | 78 | 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); | |
| 81 | 81 | absResult ^= dstMinNormal; |
| 82 | 82 | const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; |
| 83 | 83 | absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits; |
| ... | ... | @@ -87,7 +87,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Apply the signbit to (dst_t)abs(a). |
| 90 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | dst_rep_t(sign) << (dstBits - srcBits); | |
| 90 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits); | |
| 91 | 91 | return @bitCast(dst_t, result); |
| 92 | 92 | } |
| 93 | 93 |
lib/std/special/compiler_rt/extendXfYf2_test.zig+4-4| ... | ... | @@ -134,11 +134,11 @@ test "extendsftf2" { |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | fn makeQNaN64() f64 { |
| 137 | return @bitCast(f64, u64(0x7ff8000000000000)); | |
| 137 | return @bitCast(f64, @as(u64, 0x7ff8000000000000)); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | fn makeInf64() f64 { |
| 141 | return @bitCast(f64, u64(0x7ff0000000000000)); | |
| 141 | return @bitCast(f64, @as(u64, 0x7ff0000000000000)); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | fn makeNaN64(rand: u64) f64 { |
| ... | ... | @@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 { |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | fn makeQNaN32() f32 { |
| 149 | return @bitCast(f32, u32(0x7fc00000)); | |
| 149 | return @bitCast(f32, @as(u32, 0x7fc00000)); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | fn makeNaN32(rand: u32) f32 { |
| ... | ... | @@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 { |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | fn makeInf32() f32 { |
| 157 | return @bitCast(f32, u32(0x7f800000)); | |
| 157 | return @bitCast(f32, @as(u32, 0x7f800000)); | |
| 158 | 158 | } |
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixdfdi(a: f64, expected: i64) void { |
| 8 | 8 | const x = __fixdfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixdfsi(a: f64, expected: i32) void { |
| 8 | 8 | const x = __fixdfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixdfti_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixdfti(a: f64, expected: i128) void { |
| 8 | 8 | const x = __fixdfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixint.zig+3-3| ... | ... | @@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { |
| 25 | 25 | |
| 26 | 26 | const typeWidth = rep_t.bit_count; |
| 27 | 27 | const exponentBits = (typeWidth - significandBits - 1); |
| 28 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | |
| 28 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 29 | 29 | const maxExponent = ((1 << exponentBits) - 1); |
| 30 | 30 | const exponentBias = (maxExponent >> 1); |
| 31 | 31 | |
| 32 | const implicitBit = (rep_t(1) << significandBits); | |
| 32 | const implicitBit = (@as(rep_t, 1) << significandBits); | |
| 33 | 33 | const significandMask = (implicitBit - 1); |
| 34 | 34 | |
| 35 | 35 | // Break a into sign, exponent, significand |
| ... | ... | @@ -51,7 +51,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { |
| 51 | 51 | |
| 52 | 52 | // If the value is too large for the integer type, saturate. |
| 53 | 53 | if (@intCast(usize, exponent) >= fixint_t.bit_count) { |
| 54 | return if (negative) fixint_t(minInt(fixint_t)) else fixint_t(maxInt(fixint_t)); | |
| 54 | return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t)); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | // If 0 <= exponent < significandBits, right shift else left shift |
lib/std/special/compiler_rt/fixint_test.zig+13-13| ... | ... | @@ -81,8 +81,8 @@ test "fixint.i3" { |
| 81 | 81 | test "fixint.i32" { |
| 82 | 82 | test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); |
| 83 | 83 | 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); | |
| 86 | 86 | test__fixint(f64, i32, -2.0, -2); |
| 87 | 87 | test__fixint(f64, i32, -1.9, -1); |
| 88 | 88 | test__fixint(f64, i32, -1.1, -1); |
| ... | ... | @@ -96,8 +96,8 @@ test "fixint.i32" { |
| 96 | 96 | test__fixint(f64, i32, 0.1, 0); |
| 97 | 97 | test__fixint(f64, i32, 0.9, 0); |
| 98 | 98 | 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)); | |
| 101 | 101 | test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); |
| 102 | 102 | test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); |
| 103 | 103 | } |
| ... | ... | @@ -105,9 +105,9 @@ test "fixint.i32" { |
| 105 | 105 | test "fixint.i64" { |
| 106 | 106 | test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); |
| 107 | 107 | 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); | |
| 111 | 111 | test__fixint(f64, i64, -2.0, -2); |
| 112 | 112 | test__fixint(f64, i64, -1.9, -1); |
| 113 | 113 | test__fixint(f64, i64, -1.1, -1); |
| ... | ... | @@ -121,8 +121,8 @@ test "fixint.i64" { |
| 121 | 121 | test__fixint(f64, i64, 0.1, 0); |
| 122 | 122 | test__fixint(f64, i64, 0.9, 0); |
| 123 | 123 | 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)); | |
| 126 | 126 | test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); |
| 127 | 127 | test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); |
| 128 | 128 | } |
| ... | ... | @@ -130,8 +130,8 @@ test "fixint.i64" { |
| 130 | 130 | test "fixint.i128" { |
| 131 | 131 | test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); |
| 132 | 132 | 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)); | |
| 135 | 135 | test__fixint(f64, i128, -2.0, -2); |
| 136 | 136 | test__fixint(f64, i128, -1.9, -1); |
| 137 | 137 | test__fixint(f64, i128, -1.1, -1); |
| ... | ... | @@ -145,8 +145,8 @@ test "fixint.i128" { |
| 145 | 145 | test__fixint(f64, i128, 0.1, 0); |
| 146 | 146 | test__fixint(f64, i128, 0.9, 0); |
| 147 | 147 | 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)); | |
| 150 | 150 | test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); |
| 151 | 151 | test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); |
| 152 | 152 | } |
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixsfdi(a: f32, expected: i64) void { |
| 8 | 8 | const x = __fixsfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixsfsi(a: f32, expected: i32) void { |
| 8 | 8 | const x = __fixsfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixsfti_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixsfti(a: f32, expected: i128) void { |
| 8 | 8 | const x = __fixsfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixtfdi(a: f128, expected: i64) void { |
| 8 | 8 | const x = __fixtfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixtfsi(a: f128, expected: i32) void { |
| 8 | 8 | const x = __fixtfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixtfti_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixtfti(a: f128, expected: i128) void { |
| 8 | 8 | const x = __fixtfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 10 | 10 | testing.expect(x == expected); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixuint.zig+4-4| ... | ... | @@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t |
| 19 | 19 | }; |
| 20 | 20 | const typeWidth = rep_t.bit_count; |
| 21 | 21 | const exponentBits = (typeWidth - significandBits - 1); |
| 22 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | |
| 22 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 23 | 23 | const maxExponent = ((1 << exponentBits) - 1); |
| 24 | 24 | const exponentBias = (maxExponent >> 1); |
| 25 | 25 | |
| 26 | const implicitBit = (rep_t(1) << significandBits); | |
| 26 | const implicitBit = (@as(rep_t, 1) << significandBits); | |
| 27 | 27 | const significandMask = (implicitBit - 1); |
| 28 | 28 | |
| 29 | 29 | // Break a into sign, exponent, significand |
| ... | ... | @@ -31,7 +31,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t |
| 31 | 31 | const absMask = signBit - 1; |
| 32 | 32 | const aAbs: rep_t = aRep & absMask; |
| 33 | 33 | |
| 34 | const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1); | |
| 34 | const sign = if ((aRep & signBit) != 0) @as(i32, -1) else @as(i32, 1); | |
| 35 | 35 | const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias; |
| 36 | 36 | const significand: rep_t = (aAbs & significandMask) | implicitBit; |
| 37 | 37 | |
| ... | ... | @@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t |
| 39 | 39 | if (sign == -1 or exponent < 0) return 0; |
| 40 | 40 | |
| 41 | 41 | // If the value is too large for the integer type, saturate. |
| 42 | if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~fixuint_t(0); | |
| 42 | if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0); | |
| 43 | 43 | |
| 44 | 44 | // If 0 <= exponent < significandBits, right shift to get the result. |
| 45 | 45 | // Otherwise, shift left. |
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void { |
| 6 | 6 | testing.expect(x == expected); |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); | |
| 9 | const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); | |
| 10 | 10 | |
| 11 | 11 | test "fixunstfsi" { |
| 12 | 12 | test__fixunstfsi(inf128, 0xffffffff); |
lib/std/special/compiler_rt/fixunstfti_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void { |
| 6 | 6 | testing.expect(x == expected); |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); | |
| 9 | const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); | |
| 10 | 10 | |
| 11 | 11 | test "fixunstfti" { |
| 12 | 12 | test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); |
lib/std/special/compiler_rt/floatsiXf.zig+5-5| ... | ... | @@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T { |
| 6 | 6 | @setRuntimeSafety(builtin.is_test); |
| 7 | 7 | |
| 8 | 8 | const Z = @IntType(false, T.bit_count); |
| 9 | const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); | |
| 9 | const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); | |
| 10 | 10 | |
| 11 | 11 | if (a == 0) { |
| 12 | return T(0.0); | |
| 12 | return @as(T, 0.0); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | const significandBits = std.math.floatMantissaBits(T); |
| 16 | 16 | const exponentBits = std.math.floatExponentBits(T); |
| 17 | 17 | const exponentBias = ((1 << exponentBits - 1) - 1); |
| 18 | 18 | |
| 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); | |
| 21 | 21 | |
| 22 | 22 | const sign = a >> 31; |
| 23 | 23 | // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31). |
| 24 | 24 | const abs_a = (a ^ sign) -% sign; |
| 25 | 25 | // The exponent is the width of abs(a) |
| 26 | const exp = Z(31 - @clz(i32, abs_a)); | |
| 26 | const exp = @as(Z, 31 - @clz(i32, abs_a)); | |
| 27 | 27 | |
| 28 | 28 | const sign_bit = if (sign < 0) signBit else 0; |
| 29 | 29 |
lib/std/special/compiler_rt/floattidf.zig+1-1| ... | ... | @@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 { |
| 47 | 47 | a += 1; // round - this step may add a significant bit |
| 48 | 48 | a >>= 2; // dump Q and R |
| 49 | 49 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits |
| 50 | if ((a & (u128(1) << DBL_MANT_DIG)) != 0) { | |
| 50 | if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { | |
| 51 | 51 | a >>= 1; |
| 52 | 52 | e += 1; |
| 53 | 53 | } |
lib/std/special/compiler_rt/floattisf.zig+1-1| ... | ... | @@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 { |
| 48 | 48 | a += 1; // round - this step may add a significant bit |
| 49 | 49 | a >>= 2; // dump Q and R |
| 50 | 50 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits |
| 51 | if ((a & (u128(1) << FLT_MANT_DIG)) != 0) { | |
| 51 | if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { | |
| 52 | 52 | a >>= 1; |
| 53 | 53 | e += 1; |
| 54 | 54 | } |
lib/std/special/compiler_rt/floattitf.zig+1-1| ... | ... | @@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 { |
| 47 | 47 | a += 1; // round - this step may add a significant bit |
| 48 | 48 | a >>= 2; // dump Q and R |
| 49 | 49 | // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits |
| 50 | if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) { | |
| 50 | if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) { | |
| 51 | 51 | a >>= 1; |
| 52 | 52 | e += 1; |
| 53 | 53 | } |
lib/std/special/compiler_rt/floatunsidf.zig+3-3| ... | ... | @@ -2,7 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const maxInt = std.math.maxInt; |
| 4 | 4 | |
| 5 | const implicitBit = u64(1) << 52; | |
| 5 | const implicitBit = @as(u64, 1) << 52; | |
| 6 | 6 | |
| 7 | 7 | pub extern fn __floatunsidf(arg: u32) f64 { |
| 8 | 8 | @setRuntimeSafety(builtin.is_test); |
| ... | ... | @@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 { |
| 10 | 10 | if (arg == 0) return 0.0; |
| 11 | 11 | |
| 12 | 12 | // The exponent is the width of abs(a) |
| 13 | const exp = u64(31) - @clz(u32, arg); | |
| 13 | const exp = @as(u64, 31) - @clz(u32, arg); | |
| 14 | 14 | // Shift a into the significand field and clear the implicit bit |
| 15 | 15 | const shift = @intCast(u6, 52 - exp); |
| 16 | const mant = u64(arg) << shift ^ implicitBit; | |
| 16 | const mant = @as(u64, arg) << shift ^ implicitBit; | |
| 17 | 17 | |
| 18 | 18 | return @bitCast(f64, mant | (exp + 1023) << 52); |
| 19 | 19 | } |
lib/std/special/compiler_rt/floatuntidf.zig+2-2| ... | ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { |
| 32 | 32 | const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd; |
| 33 | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 34 | 34 | a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) | |
| 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); | |
| 35 | @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); | |
| 36 | 36 | }, |
| 37 | 37 | } |
| 38 | 38 | // finish |
| ... | ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { |
| 40 | 40 | a += 1; // round - this step may add a significant bit |
| 41 | 41 | a >>= 2; // dump Q and R |
| 42 | 42 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits |
| 43 | if ((a & (u128(1) << DBL_MANT_DIG)) != 0) { | |
| 43 | if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { | |
| 44 | 44 | a >>= 1; |
| 45 | 45 | e += 1; |
| 46 | 46 | } |
lib/std/special/compiler_rt/floatuntisf.zig+2-2| ... | ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { |
| 32 | 32 | const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd; |
| 33 | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 34 | 34 | a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) | |
| 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); | |
| 35 | @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); | |
| 36 | 36 | }, |
| 37 | 37 | } |
| 38 | 38 | // finish |
| ... | ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { |
| 40 | 40 | a += 1; // round - this step may add a significant bit |
| 41 | 41 | a >>= 2; // dump Q and R |
| 42 | 42 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits |
| 43 | if ((a & (u128(1) << FLT_MANT_DIG)) != 0) { | |
| 43 | if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { | |
| 44 | 44 | a >>= 1; |
| 45 | 45 | e += 1; |
| 46 | 46 | } |
lib/std/special/compiler_rt/floatuntitf.zig+2-2| ... | ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { |
| 32 | 32 | const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; |
| 33 | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 34 | 34 | a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) | |
| 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); | |
| 35 | @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); | |
| 36 | 36 | }, |
| 37 | 37 | } |
| 38 | 38 | // finish |
| ... | ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { |
| 40 | 40 | a += 1; // round - this step may add a significant bit |
| 41 | 41 | a >>= 2; // dump Q and R |
| 42 | 42 | // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits |
| 43 | if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) { | |
| 43 | if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) { | |
| 44 | 44 | a >>= 1; |
| 45 | 45 | e += 1; |
| 46 | 46 | } |
lib/std/special/compiler_rt/mulXf3.zig+25-25| ... | ... | @@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T { |
| 24 | 24 | const significandBits = std.math.floatMantissaBits(T); |
| 25 | 25 | const exponentBits = std.math.floatExponentBits(T); |
| 26 | 26 | |
| 27 | const signBit = (Z(1) << (significandBits + exponentBits)); | |
| 27 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); | |
| 28 | 28 | const maxExponent = ((1 << exponentBits) - 1); |
| 29 | 29 | const exponentBias = (maxExponent >> 1); |
| 30 | 30 | |
| 31 | const implicitBit = (Z(1) << significandBits); | |
| 31 | const implicitBit = (@as(Z, 1) << significandBits); | |
| 32 | 32 | const quietBit = implicitBit >> 1; |
| 33 | 33 | const significandMask = implicitBit - 1; |
| 34 | 34 | |
| ... | ... | @@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { |
| 122 | 122 | // a zero of the appropriate sign. Mathematically there is no need to |
| 123 | 123 | // handle this case separately, but we make it a special case to |
| 124 | 124 | // simplify the shift logic. |
| 125 | const shift: u32 = @truncate(u32, Z(1) -% @bitCast(u32, productExponent)); | |
| 125 | const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent)); | |
| 126 | 126 | if (shift >= typeWidth) return @bitCast(T, productSign); |
| 127 | 127 | |
| 128 | 128 | // Otherwise, shift the significand of the result so that the round |
| ... | ... | @@ -131,7 +131,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { |
| 131 | 131 | } else { |
| 132 | 132 | // Result is normal before rounding; insert the exponent. |
| 133 | 133 | productHi &= significandMask; |
| 134 | productHi |= Z(@bitCast(u32, productExponent)) << significandBits; | |
| 134 | productHi |= @as(Z, @bitCast(u32, productExponent)) << significandBits; | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Insert the sign of the result: |
| ... | ... | @@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 150 | 150 | switch (Z) { |
| 151 | 151 | u32 => { |
| 152 | 152 | // 32x32 --> 64 bit multiply |
| 153 | const product = u64(a) * u64(b); | |
| 153 | const product = @as(u64, a) * @as(u64, b); | |
| 154 | 154 | hi.* = @truncate(u32, product >> 32); |
| 155 | 155 | lo.* = @truncate(u32, product); |
| 156 | 156 | }, |
| ... | ... | @@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 179 | 179 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; |
| 180 | 180 | }, |
| 181 | 181 | 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); | |
| 185 | 185 | const S = struct { |
| 186 | 186 | fn Word_1(x: u128) u64 { |
| 187 | 187 | return @truncate(u32, x >> 96); |
| ... | ... | @@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 217 | 217 | const product43: u64 = S.Word_4(a) * S.Word_3(b); |
| 218 | 218 | const product44: u64 = S.Word_4(a) * S.Word_4(b); |
| 219 | 219 | |
| 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); | |
| 236 | 236 | |
| 237 | 237 | const r0: u128 = (sum0 & Word_FullMask) +% |
| 238 | 238 | ((sum1 & Word_LoMask) << 32); |
| ... | ... | @@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 258 | 258 | @setRuntimeSafety(builtin.is_test); |
| 259 | 259 | const Z = @IntType(false, T.bit_count); |
| 260 | 260 | const significandBits = std.math.floatMantissaBits(T); |
| 261 | const implicitBit = Z(1) << significandBits; | |
| 261 | const implicitBit = @as(Z, 1) << significandBits; | |
| 262 | 262 | |
| 263 | 263 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); |
| 264 | 264 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
lib/std/special/compiler_rt/mulXf3_test.zig+9-9| ... | ... | @@ -2,8 +2,8 @@ |
| 2 | 2 | // |
| 3 | 3 | // https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c |
| 4 | 4 | |
| 5 | const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64); | |
| 6 | const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64); | |
| 5 | const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64); | |
| 6 | const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); | |
| 7 | 7 | |
| 8 | 8 | const __multf3 = @import("mulXf3.zig").__multf3; |
| 9 | 9 | |
| ... | ... | @@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | fn makeNaN128(rand: u64) f128 { |
| 42 | const int_result = u128(0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; | |
| 42 | const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; | |
| 43 | 43 | const float_result = @bitCast(f128, int_result); |
| 44 | 44 | return float_result; |
| 45 | 45 | } |
| ... | ... | @@ -55,15 +55,15 @@ test "multf3" { |
| 55 | 55 | |
| 56 | 56 | // any * any |
| 57 | 57 | test__multf3( |
| 58 | @bitCast(f128, u128(0x40042eab345678439abcdefea5678234)), | |
| 59 | @bitCast(f128, u128(0x3ffeedcb34a235253948765432134675)), | |
| 58 | @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)), | |
| 59 | @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)), | |
| 60 | 60 | 0x400423e7f9e3c9fc, |
| 61 | 61 | 0xd906c2c2a85777c4, |
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | 64 | test__multf3( |
| 65 | @bitCast(f128, u128(0x3fcd353e45674d89abacc3a2ebf3ff50)), | |
| 66 | @bitCast(f128, u128(0x3ff6ed8764648369535adf4be3214568)), | |
| 65 | @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)), | |
| 66 | @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)), | |
| 67 | 67 | 0x3fc52a163c6223fc, |
| 68 | 68 | 0xc94c4bf0430768b4, |
| 69 | 69 | ); |
| ... | ... | @@ -76,8 +76,8 @@ test "multf3" { |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | 78 | test__multf3( |
| 79 | @bitCast(f128, u128(0x3f154356473c82a9fabf2d22ace345df)), | |
| 80 | @bitCast(f128, u128(0x3e38eda98765476743ab21da23d45679)), | |
| 79 | @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)), | |
| 80 | @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)), | |
| 81 | 81 | 0x3d4f37c1a3137cae, |
| 82 | 82 | 0xfc6807048bc2836a, |
| 83 | 83 | ); |
lib/std/special/compiler_rt/muldi3.zig+1-1| ... | ... | @@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 { |
| 21 | 21 | @setRuntimeSafety(builtin.is_test); |
| 22 | 22 | |
| 23 | 23 | const bits_in_word_2 = @sizeOf(i32) * 8 / 2; |
| 24 | const lower_mask = (~u32(0)) >> bits_in_word_2; | |
| 24 | const lower_mask = (~@as(u32, 0)) >> bits_in_word_2; | |
| 25 | 25 | |
| 26 | 26 | var r: dwords = undefined; |
| 27 | 27 | r.s.low = (a & lower_mask) *% (b & lower_mask); |
lib/std/special/compiler_rt/mulodi4.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const minInt = std.math.minInt; |
| 6 | 6 | pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 { |
| 7 | 7 | @setRuntimeSafety(builtin.is_test); |
| 8 | 8 | |
| 9 | const min = @bitCast(i64, u64(1 << (i64.bit_count - 1))); | |
| 9 | const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1))); | |
| 10 | 10 | const max = ~min; |
| 11 | 11 | |
| 12 | 12 | overflow.* = 0; |
lib/std/special/compiler_rt/mulodi4_test.zig+24-24| ... | ... | @@ -52,34 +52,34 @@ test "mulodi4" { |
| 52 | 52 | |
| 53 | 53 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); |
| 54 | 54 | 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); | |
| 57 | 57 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); |
| 58 | 58 | test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); |
| 59 | 59 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); |
| 60 | 60 | 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); | |
| 63 | 63 | |
| 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); | |
| 74 | 74 | |
| 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); | |
| 85 | 85 | } |
lib/std/special/compiler_rt/muloti4.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig"); |
| 4 | 4 | pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 { |
| 5 | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | 6 | |
| 7 | const min = @bitCast(i128, u128(1 << (i128.bit_count - 1))); | |
| 7 | const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1))); | |
| 8 | 8 | const max = ~min; |
| 9 | 9 | overflow.* = 0; |
| 10 | 10 |
lib/std/special/compiler_rt/muloti4_test.zig+31-31| ... | ... | @@ -39,38 +39,38 @@ test "muloti4" { |
| 39 | 39 | test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); |
| 40 | 40 | test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); |
| 41 | 41 | |
| 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); | |
| 45 | 45 | |
| 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); | |
| 54 | 54 | |
| 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); | |
| 65 | 65 | |
| 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); | |
| 76 | 76 | } |
lib/std/special/compiler_rt/multi3.zig+1-1| ... | ... | @@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 { |
| 21 | 21 | |
| 22 | 22 | fn __mulddi3(a: u64, b: u64) i128 { |
| 23 | 23 | const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2; |
| 24 | const lower_mask = ~u64(0) >> bits_in_dword_2; | |
| 24 | const lower_mask = ~@as(u64, 0) >> bits_in_dword_2; | |
| 25 | 25 | var r: twords = undefined; |
| 26 | 26 | r.s.low = (a & lower_mask) *% (b & lower_mask); |
| 27 | 27 | var t: u64 = r.s.low >> bits_in_dword_2; |
lib/std/special/compiler_rt/negXf2.zig+1-1| ... | ... | @@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T { |
| 15 | 15 | const significandBits = std.math.floatMantissaBits(T); |
| 16 | 16 | const exponentBits = std.math.floatExponentBits(T); |
| 17 | 17 | |
| 18 | const signBit = (Z(1) << (significandBits + exponentBits)); | |
| 18 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); | |
| 19 | 19 | |
| 20 | 20 | return @bitCast(T, @bitCast(Z, a) ^ signBit); |
| 21 | 21 | } |
lib/std/special/compiler_rt/popcountdi2_test.zig+3-3| ... | ... | @@ -20,8 +20,8 @@ test "popcountdi2" { |
| 20 | 20 | test__popcountdi2(0); |
| 21 | 21 | test__popcountdi2(1); |
| 22 | 22 | 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))); | |
| 26 | 26 | // TODO some fuzz testing |
| 27 | 27 | } |
lib/std/special/compiler_rt/truncXfYf2.zig+1-1| ... | ... | @@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 69 | 69 | // destination format. We can convert by simply right-shifting with |
| 70 | 70 | // rounding and adjusting the exponent. |
| 71 | 71 | absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits)); |
| 72 | absResult -%= dst_rep_t(srcExpBias - dstExpBias) << dstSigBits; | |
| 72 | absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits; | |
| 73 | 73 | |
| 74 | 74 | const roundBits: src_rep_t = aAbs & roundMask; |
| 75 | 75 | if (roundBits > halfway) { |
lib/std/special/compiler_rt/truncXfYf2_test.zig+10-10| ... | ... | @@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void { |
| 152 | 152 | |
| 153 | 153 | test "trunctfsf2" { |
| 154 | 154 | // qnan |
| 155 | test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000); | |
| 155 | test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000); | |
| 156 | 156 | // nan |
| 157 | test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); | |
| 157 | test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); | |
| 158 | 158 | // inf |
| 159 | test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000); | |
| 159 | test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000); | |
| 160 | 160 | // zero |
| 161 | 161 | test__trunctfsf2(0.0, 0x0); |
| 162 | 162 | |
| ... | ... | @@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void { |
| 187 | 187 | |
| 188 | 188 | test "trunctfdf2" { |
| 189 | 189 | // qnan |
| 190 | test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000); | |
| 190 | test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000); | |
| 191 | 191 | // nan |
| 192 | test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); | |
| 192 | test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); | |
| 193 | 193 | // inf |
| 194 | test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000); | |
| 194 | test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000); | |
| 195 | 195 | // zero |
| 196 | 196 | test__trunctfdf2(0.0, 0x0); |
| 197 | 197 | |
| ... | ... | @@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void { |
| 224 | 224 | |
| 225 | 225 | test "truncdfsf2" { |
| 226 | 226 | // 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); | |
| 229 | 229 | // 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); | |
| 232 | 232 | |
| 233 | 233 | test__truncdfsf2(0.0, 0x0); |
| 234 | 234 | test__truncdfsf2(1.0, 0x3f800000); |
lib/std/special/compiler_rt/udivmod.zig+3-3| ... | ... | @@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 76 | 76 | // K K |
| 77 | 77 | // --- |
| 78 | 78 | // K 0 |
| 79 | sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high]))); | |
| 79 | sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); | |
| 80 | 80 | // 0 <= sr <= SingleInt.bit_count - 2 or sr large |
| 81 | 81 | if (sr > SingleInt.bit_count - 2) { |
| 82 | 82 | if (maybe_rem) |rem| { |
| ... | ... | @@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 114 | 114 | // K X |
| 115 | 115 | // --- |
| 116 | 116 | // 0 K |
| 117 | sr = 1 + SingleInt.bit_count + c_uint(@clz(SingleInt, d[low])) - c_uint(@clz(SingleInt, n[high])); | |
| 117 | sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high])); | |
| 118 | 118 | // 2 <= sr <= DoubleInt.bit_count - 1 |
| 119 | 119 | // q.all = a << (DoubleInt.bit_count - sr); |
| 120 | 120 | // r.all = a >> sr; |
| ... | ... | @@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 140 | 140 | // K X |
| 141 | 141 | // --- |
| 142 | 142 | // K K |
| 143 | sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high]))); | |
| 143 | sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); | |
| 144 | 144 | // 0 <= sr <= SingleInt.bit_count - 1 or sr large |
| 145 | 145 | if (sr > SingleInt.bit_count - 1) { |
| 146 | 146 | if (maybe_rem) |rem| { |
lib/std/target.zig+1-1| ... | ... | @@ -581,7 +581,7 @@ pub const Target = union(enum) { |
| 581 | 581 | }; |
| 582 | 582 | |
| 583 | 583 | pub fn getExternalExecutor(self: Target) Executor { |
| 584 | if (@TagType(Target)(self) == .Native) return .native; | |
| 584 | if (@as(@TagType(Target),self) == .Native) return .native; | |
| 585 | 585 | |
| 586 | 586 | // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture. |
| 587 | 587 | if (self.getOs() == builtin.os) { |
lib/std/thread.zig+1-1| ... | ... | @@ -344,7 +344,7 @@ pub const Thread = struct { |
| 344 | 344 | pub fn cpuCount() CpuCountError!usize { |
| 345 | 345 | if (builtin.os == .linux) { |
| 346 | 346 | 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 | |
| 348 | 348 | } |
| 349 | 349 | if (builtin.os == .windows) { |
| 350 | 350 | var system_info: windows.SYSTEM_INFO = undefined; |
lib/std/time.zig+4-4| ... | ... | @@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 { |
| 38 | 38 | const hns_per_ms = (ns_per_s / 100) / ms_per_s; |
| 39 | 39 | const epoch_adj = epoch.windows * ms_per_s; |
| 40 | 40 | |
| 41 | const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; | |
| 41 | const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime; | |
| 42 | 42 | return @divFloor(ft64, hns_per_ms) - -epoch_adj; |
| 43 | 43 | } |
| 44 | 44 | if (builtin.os == .wasi and !builtin.link_libc) { |
| ... | ... | @@ -142,10 +142,10 @@ pub const Timer = struct { |
| 142 | 142 | // seccomp is going to block us it will at least do so consistently |
| 143 | 143 | var ts: os.timespec = undefined; |
| 144 | 144 | os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported; |
| 145 | self.resolution = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); | |
| 145 | self.resolution = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); | |
| 146 | 146 | |
| 147 | 147 | os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported; |
| 148 | self.start_time = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); | |
| 148 | self.start_time = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | return self; |
| ... | ... | @@ -185,7 +185,7 @@ pub const Timer = struct { |
| 185 | 185 | } |
| 186 | 186 | var ts: os.timespec = undefined; |
| 187 | 187 | os.clock_gettime(monotonic_clock_id, &ts) catch unreachable; |
| 188 | return @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); | |
| 188 | return @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); | |
| 189 | 189 | } |
| 190 | 190 | }; |
| 191 | 191 |
lib/std/unicode.zig+5-5| ... | ... | @@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error |
| 68 | 68 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. |
| 69 | 69 | pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 { |
| 70 | 70 | return switch (bytes.len) { |
| 71 | 1 => u32(bytes[0]), | |
| 71 | 1 => @as(u32, bytes[0]), | |
| 72 | 72 | 2 => utf8Decode2(bytes), |
| 73 | 73 | 3 => utf8Decode3(bytes), |
| 74 | 74 | 4 => utf8Decode4(bytes), |
| ... | ... | @@ -226,7 +226,7 @@ pub const Utf8Iterator = struct { |
| 226 | 226 | const slice = it.nextCodepointSlice() orelse return null; |
| 227 | 227 | |
| 228 | 228 | switch (slice.len) { |
| 229 | 1 => return u32(slice[0]), | |
| 229 | 1 => return @as(u32, slice[0]), | |
| 230 | 230 | 2 => return utf8Decode2(slice) catch unreachable, |
| 231 | 231 | 3 => return utf8Decode3(slice) catch unreachable, |
| 232 | 232 | 4 => return utf8Decode4(slice) catch unreachable, |
| ... | ... | @@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct { |
| 250 | 250 | assert(it.i <= it.bytes.len); |
| 251 | 251 | if (it.i == it.bytes.len) return null; |
| 252 | 252 | const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); |
| 253 | if (c0 & ~u32(0x03ff) == 0xd800) { | |
| 253 | if (c0 & ~@as(u32, 0x03ff) == 0xd800) { | |
| 254 | 254 | // surrogate pair |
| 255 | 255 | it.i += 2; |
| 256 | 256 | if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; |
| 257 | 257 | const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); |
| 258 | if (c1 & ~u32(0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; | |
| 258 | if (c1 & ~@as(u32, 0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; | |
| 259 | 259 | it.i += 2; |
| 260 | 260 | return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff)); |
| 261 | } else if (c0 & ~u32(0x03ff) == 0xdc00) { | |
| 261 | } else if (c0 & ~@as(u32, 0x03ff) == 0xdc00) { | |
| 262 | 262 | return error.UnexpectedSecondSurrogateHalf; |
| 263 | 263 | } else { |
| 264 | 264 | it.i += 2; |
lib/std/valgrind.zig+1-1| ... | ... | @@ -76,7 +76,7 @@ pub const ClientRequest = extern enum { |
| 76 | 76 | InnerThreads = 6402, |
| 77 | 77 | }; |
| 78 | 78 | pub fn ToolBase(base: [2]u8) u32 { |
| 79 | return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16); | |
| 79 | return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16); | |
| 80 | 80 | } |
| 81 | 81 | pub fn IsTool(base: [2]u8, code: usize) bool { |
| 82 | 82 | return ToolBase(base) == (code & 0xffff0000); |
lib/std/zig/parse_string_literal.zig+1-1| ... | ... | @@ -19,7 +19,7 @@ pub fn parseStringLiteral( |
| 19 | 19 | bytes: []const u8, |
| 20 | 20 | bad_index: *usize, // populated if error.InvalidCharacter is returned |
| 21 | 21 | ) ParseStringLiteralError![]u8 { |
| 22 | const first_index = if (bytes[0] == 'c') usize(2) else usize(1); | |
| 22 | const first_index = if (bytes[0] == 'c') @as(usize, 2) else @as(usize, 1); | |
| 23 | 23 | assert(bytes[bytes.len - 1] == '"'); |
| 24 | 24 | |
| 25 | 25 | var list = std.ArrayList(u8).init(allocator); |
lib/std/zig/parser_test.zig+1-1| ... | ... | @@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" { |
| 37 | 37 | \\test "" { |
| 38 | 38 | \\ const result = while (returnError()) |value| { |
| 39 | 39 | \\ break value; |
| 40 | \\ } else |err| i32(2); | |
| 40 | \\ } else |err| @as(i32, 2); | |
| 41 | 41 | \\ expect(result == 2); |
| 42 | 42 | \\} |
| 43 | 43 | \\ |
lib/std/zig/render.zig+3-3| ... | ... | @@ -410,8 +410,8 @@ fn renderExpression( |
| 410 | 410 | switch (prefix_op_node.op) { |
| 411 | 411 | ast.Node.PrefixOp.Op.PtrType => |ptr_info| { |
| 412 | 412 | 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), | |
| 415 | 415 | }; |
| 416 | 416 | try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // * |
| 417 | 417 | if (ptr_info.allowzero_token) |allowzero_token| { |
| ... | ... | @@ -2097,7 +2097,7 @@ fn renderTokenOffset( |
| 2097 | 2097 | |
| 2098 | 2098 | while (true) { |
| 2099 | 2099 | assert(loc.line != 0); |
| 2100 | const newline_count = if (loc.line == 1) u8(1) else u8(2); | |
| 2100 | const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2); | |
| 2101 | 2101 | try stream.writeByteNTimes('\n', newline_count); |
| 2102 | 2102 | try stream.writeByteNTimes(' ', indent); |
| 2103 | 2103 | try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")); |
lib/std/zig/tokenizer.zig+1-1| ... | ... | @@ -350,7 +350,7 @@ pub const Tokenizer = struct { |
| 350 | 350 | }; |
| 351 | 351 | } else { |
| 352 | 352 | // Skip the UTF-8 BOM if present |
| 353 | const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0); | |
| 353 | const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else @as(usize, 0); | |
| 354 | 354 | return Tokenizer{ |
| 355 | 355 | .buffer = buffer, |
| 356 | 356 | .index = src_start, |
test/compare_output.zig+25-25| ... | ... | @@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 122 | 122 | \\ |
| 123 | 123 | \\pub fn main() void { |
| 124 | 124 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 125 | \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; | |
| 125 | \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable; | |
| 126 | 126 | \\} |
| 127 | 127 | , "Hello, world!\n 12 12 a\n"); |
| 128 | 128 | |
| ... | ... | @@ -166,54 +166,54 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 166 | 166 | \\ _ = c.printf(c"\n"); |
| 167 | 167 | \\ |
| 168 | 168 | \\ _ = c.printf(c"0.0: %.013a\n", |
| 169 | \\ f64(0.0)); | |
| 169 | \\ @as(f64, 0.0)); | |
| 170 | 170 | \\ _ = c.printf(c"0e0: %.013a\n", |
| 171 | \\ f64(0e0)); | |
| 171 | \\ @as(f64, 0e0)); | |
| 172 | 172 | \\ _ = c.printf(c"0.0e0: %.013a\n", |
| 173 | \\ f64(0.0e0)); | |
| 173 | \\ @as(f64, 0.0e0)); | |
| 174 | 174 | \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n", |
| 175 | \\ f64(000000000000000000000000000000000000000000000000000000000.0e0)); | |
| 175 | \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0)); | |
| 176 | 176 | \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n", |
| 177 | \\ f64(0.000000000000000000000000000000000000000000000000000000000e0)); | |
| 177 | \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0)); | |
| 178 | 178 | \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n", |
| 179 | \\ f64(0.0e000000000000000000000000000000000000000000000000000000000)); | |
| 179 | \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000)); | |
| 180 | 180 | \\ _ = c.printf(c"1.0: %.013a\n", |
| 181 | \\ f64(1.0)); | |
| 181 | \\ @as(f64, 1.0)); | |
| 182 | 182 | \\ _ = c.printf(c"10.0: %.013a\n", |
| 183 | \\ f64(10.0)); | |
| 183 | \\ @as(f64, 10.0)); | |
| 184 | 184 | \\ _ = c.printf(c"10.5: %.013a\n", |
| 185 | \\ f64(10.5)); | |
| 185 | \\ @as(f64, 10.5)); | |
| 186 | 186 | \\ _ = c.printf(c"10.5e5: %.013a\n", |
| 187 | \\ f64(10.5e5)); | |
| 187 | \\ @as(f64, 10.5e5)); | |
| 188 | 188 | \\ _ = c.printf(c"10.5e+5: %.013a\n", |
| 189 | \\ f64(10.5e+5)); | |
| 189 | \\ @as(f64, 10.5e+5)); | |
| 190 | 190 | \\ _ = c.printf(c"50.0e-2: %.013a\n", |
| 191 | \\ f64(50.0e-2)); | |
| 191 | \\ @as(f64, 50.0e-2)); | |
| 192 | 192 | \\ _ = c.printf(c"50e-2: %.013a\n", |
| 193 | \\ f64(50e-2)); | |
| 193 | \\ @as(f64, 50e-2)); | |
| 194 | 194 | \\ |
| 195 | 195 | \\ _ = c.printf(c"\n"); |
| 196 | 196 | \\ |
| 197 | 197 | \\ _ = c.printf(c"0x1.0: %.013a\n", |
| 198 | \\ f64(0x1.0)); | |
| 198 | \\ @as(f64, 0x1.0)); | |
| 199 | 199 | \\ _ = c.printf(c"0x10.0: %.013a\n", |
| 200 | \\ f64(0x10.0)); | |
| 200 | \\ @as(f64, 0x10.0)); | |
| 201 | 201 | \\ _ = c.printf(c"0x100.0: %.013a\n", |
| 202 | \\ f64(0x100.0)); | |
| 202 | \\ @as(f64, 0x100.0)); | |
| 203 | 203 | \\ _ = c.printf(c"0x103.0: %.013a\n", |
| 204 | \\ f64(0x103.0)); | |
| 204 | \\ @as(f64, 0x103.0)); | |
| 205 | 205 | \\ _ = c.printf(c"0x103.7: %.013a\n", |
| 206 | \\ f64(0x103.7)); | |
| 206 | \\ @as(f64, 0x103.7)); | |
| 207 | 207 | \\ _ = c.printf(c"0x103.70: %.013a\n", |
| 208 | \\ f64(0x103.70)); | |
| 208 | \\ @as(f64, 0x103.70)); | |
| 209 | 209 | \\ _ = c.printf(c"0x103.70p4: %.013a\n", |
| 210 | \\ f64(0x103.70p4)); | |
| 210 | \\ @as(f64, 0x103.70p4)); | |
| 211 | 211 | \\ _ = c.printf(c"0x103.70p5: %.013a\n", |
| 212 | \\ f64(0x103.70p5)); | |
| 212 | \\ @as(f64, 0x103.70p5)); | |
| 213 | 213 | \\ _ = c.printf(c"0x103.70p+5: %.013a\n", |
| 214 | \\ f64(0x103.70p+5)); | |
| 214 | \\ @as(f64, 0x103.70p+5)); | |
| 215 | 215 | \\ _ = c.printf(c"0x103.70p-5: %.013a\n", |
| 216 | \\ f64(0x103.70p-5)); | |
| 216 | \\ @as(f64, 0x103.70p-5)); | |
| 217 | 217 | \\ |
| 218 | 218 | \\ return 0; |
| 219 | 219 | \\} |
| ... | ... | @@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 323 | 323 | \\ const x: f64 = small; |
| 324 | 324 | \\ const y = @floatToInt(i32, x); |
| 325 | 325 | \\ const z = @intToFloat(f64, y); |
| 326 | \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4)); | |
| 326 | \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4)); | |
| 327 | 327 | \\ return 0; |
| 328 | 328 | \\} |
| 329 | 329 | , "3.25\n3\n3.00\n-0.40\n"); |
test/compile_errors.zig+26-26| ... | ... | @@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 186 | 186 | cases.add( |
| 187 | 187 | "shift amount has to be an integer type", |
| 188 | 188 | \\export fn entry() void { |
| 189 | \\ const x = 1 << &u8(10); | |
| 189 | \\ const x = 1 << &@as(u8, 10); | |
| 190 | 190 | \\} |
| 191 | 191 | , |
| 192 | 192 | "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'", |
| ... | ... | @@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 196 | 196 | cases.add( |
| 197 | 197 | "bit shifting only works on integer types", |
| 198 | 198 | \\export fn entry() void { |
| 199 | \\ const x = &u8(1) << 10; | |
| 199 | \\ const x = &@as(u8, 1) << 10; | |
| 200 | 200 | \\} |
| 201 | 201 | , |
| 202 | 202 | "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'", |
| ... | ... | @@ -241,7 +241,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 241 | 241 | \\ var x: []align(true) i32 = undefined; |
| 242 | 242 | \\} |
| 243 | 243 | \\export fn entry2() void { |
| 244 | \\ var x: *align(f64(12.34)) i32 = undefined; | |
| 244 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; | |
| 245 | 245 | \\} |
| 246 | 246 | , |
| 247 | 247 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| ... | ... | @@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1297 | 1297 | cases.add( |
| 1298 | 1298 | "@truncate undefined value", |
| 1299 | 1299 | \\export fn entry() void { |
| 1300 | \\ var z = @truncate(u8, u16(undefined)); | |
| 1300 | \\ var z = @truncate(u8, @as(u16, undefined)); | |
| 1301 | 1301 | \\} |
| 1302 | 1302 | , |
| 1303 | 1303 | "tmp.zig:2:30: error: use of undefined value here causes undefined behavior", |
| ... | ... | @@ -1686,7 +1686,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1686 | 1686 | cases.add( |
| 1687 | 1687 | "non float passed to @floatToInt", |
| 1688 | 1688 | \\export fn entry() void { |
| 1689 | \\ const x = @floatToInt(i32, i32(54)); | |
| 1689 | \\ const x = @floatToInt(i32, @as(i32, 54)); | |
| 1690 | 1690 | \\} |
| 1691 | 1691 | , |
| 1692 | 1692 | "tmp.zig:2:35: error: expected float type, found 'i32'", |
| ... | ... | @@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2197 | 2197 | cases.add( |
| 2198 | 2198 | "error when evaluating return type", |
| 2199 | 2199 | \\const Foo = struct { |
| 2200 | \\ map: i32(i32), | |
| 2200 | \\ map: @as(i32, i32), | |
| 2201 | 2201 | \\ |
| 2202 | 2202 | \\ fn init() Foo { |
| 2203 | 2203 | \\ return undefined; |
| ... | ... | @@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | 2338 | cases.add( |
| 2339 | 2339 | "var not allowed in structs", |
| 2340 | 2340 | \\export fn entry() void { |
| 2341 | \\ var s = (struct{v: var}){.v=i32(10)}; | |
| 2341 | \\ var s = (struct{v: var}){.v=@as(i32, 10)}; | |
| 2342 | 2342 | \\} |
| 2343 | 2343 | , |
| 2344 | 2344 | "tmp.zig:2:23: error: invalid token: 'var'", |
| ... | ... | @@ -2657,7 +2657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2657 | 2657 | cases.add( |
| 2658 | 2658 | "cast negative integer literal to usize", |
| 2659 | 2659 | \\export fn entry() void { |
| 2660 | \\ const x = usize(-10); | |
| 2660 | \\ const x = @as(usize, -10); | |
| 2661 | 2661 | \\} |
| 2662 | 2662 | , |
| 2663 | 2663 | "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| ... | ... | @@ -3384,7 +3384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3384 | 3384 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 3385 | 3385 | \\} |
| 3386 | 3386 | \\fn g(b: bool) void { |
| 3387 | \\ const y = if (b) h: { break :h i32(1); }; | |
| 3387 | \\ const y = if (b) h: { break :h @as(i32, 1); }; | |
| 3388 | 3388 | \\} |
| 3389 | 3389 | \\export fn entry() void { f(true); g(true); } |
| 3390 | 3390 | , |
| ... | ... | @@ -3520,7 +3520,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3520 | 3520 | cases.add( |
| 3521 | 3521 | "cast unreachable", |
| 3522 | 3522 | \\fn f() i32 { |
| 3523 | \\ return i32(return 1); | |
| 3523 | \\ return @as(i32, return 1); | |
| 3524 | 3524 | \\} |
| 3525 | 3525 | \\export fn entry() void { _ = f(); } |
| 3526 | 3526 | , |
| ... | ... | @@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3595 | 3595 | \\ switch (n) { |
| 3596 | 3596 | \\ Number.One => 1, |
| 3597 | 3597 | \\ Number.Two => 2, |
| 3598 | \\ Number.Three => i32(3), | |
| 3598 | \\ Number.Three => @as(i32, 3), | |
| 3599 | 3599 | \\ } |
| 3600 | 3600 | \\} |
| 3601 | 3601 | \\ |
| ... | ... | @@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3616 | 3616 | \\ switch (n) { |
| 3617 | 3617 | \\ Number.One => 1, |
| 3618 | 3618 | \\ Number.Two => 2, |
| 3619 | \\ Number.Three => i32(3), | |
| 3619 | \\ Number.Three => @as(i32, 3), | |
| 3620 | 3620 | \\ Number.Four => 4, |
| 3621 | 3621 | \\ Number.Two => 2, |
| 3622 | 3622 | \\ } |
| ... | ... | @@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3640 | 3640 | \\ switch (n) { |
| 3641 | 3641 | \\ Number.One => 1, |
| 3642 | 3642 | \\ Number.Two => 2, |
| 3643 | \\ Number.Three => i32(3), | |
| 3643 | \\ Number.Three => @as(i32, 3), | |
| 3644 | 3644 | \\ Number.Four => 4, |
| 3645 | 3645 | \\ Number.Two => 2, |
| 3646 | 3646 | \\ else => 10, |
| ... | ... | @@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3685 | 3685 | "switch expression - duplicate or overlapping integer value", |
| 3686 | 3686 | \\fn foo(x: u8) u8 { |
| 3687 | 3687 | \\ return switch (x) { |
| 3688 | \\ 0 ... 100 => u8(0), | |
| 3688 | \\ 0 ... 100 => @as(u8, 0), | |
| 3689 | 3689 | \\ 101 ... 200 => 1, |
| 3690 | 3690 | \\ 201, 203 ... 207 => 2, |
| 3691 | 3691 | \\ 206 ... 255 => 3, |
| ... | ... | @@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3722 | 3722 | cases.add( |
| 3723 | 3723 | "array concatenation with wrong type", |
| 3724 | 3724 | \\const src = "aoeu"; |
| 3725 | \\const derp = usize(1234); | |
| 3725 | \\const derp = @as(usize, 1234); | |
| 3726 | 3726 | \\const a = derp ++ "foo"; |
| 3727 | 3727 | \\ |
| 3728 | 3728 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| ... | ... | @@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3887 | 3887 | "division by zero", |
| 3888 | 3888 | \\const lit_int_x = 1 / 0; |
| 3889 | 3889 | \\const lit_float_x = 1.0 / 0.0; |
| 3890 | \\const int_x = u32(1) / u32(0); | |
| 3890 | \\const int_x = @as(u32, 1) / @as(u32, 0); | |
| 3891 | 3891 | \\const float_x = f32(1.0) / f32(0.0); |
| 3892 | 3892 | \\ |
| 3893 | 3893 | \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } |
| ... | ... | @@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4590 | 4590 | \\var bytes: [ext()]u8 = undefined; |
| 4591 | 4591 | \\export fn f() void { |
| 4592 | 4592 | \\ for (bytes) |*b, i| { |
| 4593 | \\ b.* = u8(i); | |
| 4593 | \\ b.* = @as(u8, i); | |
| 4594 | 4594 | \\ } |
| 4595 | 4595 | \\} |
| 4596 | 4596 | , |
| ... | ... | @@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4874 | 4874 | \\} |
| 4875 | 4875 | \\ |
| 4876 | 4876 | \\fn foo() i32 { |
| 4877 | \\ return add(i32(1234)); | |
| 4877 | \\ return add(@as(i32, 1234)); | |
| 4878 | 4878 | \\} |
| 4879 | 4879 | \\ |
| 4880 | 4880 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| ... | ... | @@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4886 | 4886 | cases.add( |
| 4887 | 4887 | "pass integer literal to var args", |
| 4888 | 4888 | \\fn add(args: ...) i32 { |
| 4889 | \\ var sum = i32(0); | |
| 4889 | \\ var sum = @as(i32, 0); | |
| 4890 | 4890 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { |
| 4891 | 4891 | \\ sum += args[i]; |
| 4892 | 4892 | \\ }} |
| ... | ... | @@ -5581,7 +5581,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5581 | 5581 | cases.add( |
| 5582 | 5582 | "explicit cast float literal to integer when there is a fraction component", |
| 5583 | 5583 | \\export fn entry() i32 { |
| 5584 | \\ return i32(12.34); | |
| 5584 | \\ return @as(i32, 12.34); | |
| 5585 | 5585 | \\} |
| 5586 | 5586 | , |
| 5587 | 5587 | "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| ... | ... | @@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5599 | 5599 | cases.add( |
| 5600 | 5600 | "@shlExact shifts out 1 bits", |
| 5601 | 5601 | \\comptime { |
| 5602 | \\ const x = @shlExact(u8(0b01010101), 2); | |
| 5602 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); | |
| 5603 | 5603 | \\} |
| 5604 | 5604 | , |
| 5605 | 5605 | "tmp.zig:2:15: error: operation caused overflow", |
| ... | ... | @@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5608 | 5608 | cases.add( |
| 5609 | 5609 | "@shrExact shifts out 1 bits", |
| 5610 | 5610 | \\comptime { |
| 5611 | \\ const x = @shrExact(u8(0b10101010), 2); | |
| 5611 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); | |
| 5612 | 5612 | \\} |
| 5613 | 5613 | , |
| 5614 | 5614 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| ... | ... | @@ -5699,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5699 | 5699 | cases.add( |
| 5700 | 5700 | "@alignCast expects pointer or slice", |
| 5701 | 5701 | \\export fn entry() void { |
| 5702 | \\ @alignCast(4, u32(3)); | |
| 5702 | \\ @alignCast(4, @as(u32, 3)); | |
| 5703 | 5703 | \\} |
| 5704 | 5704 | , |
| 5705 | 5705 | "tmp.zig:2:22: error: expected pointer or slice, found 'u32'", |
| ... | ... | @@ -5744,7 +5744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5744 | 5744 | \\const Derp = @OpaqueType(); |
| 5745 | 5745 | \\extern fn bar(d: *Derp) void; |
| 5746 | 5746 | \\export fn foo() void { |
| 5747 | \\ var x = u8(1); | |
| 5747 | \\ var x = @as(u8, 1); | |
| 5748 | 5748 | \\ bar(@ptrCast(*c_void, &x)); |
| 5749 | 5749 | \\} |
| 5750 | 5750 | , |
| ... | ... | @@ -5800,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5800 | 5800 | "wrong types given to atomic order args in cmpxchg", |
| 5801 | 5801 | \\export fn entry() void { |
| 5802 | 5802 | \\ var x: i32 = 1234; |
| 5803 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {} | |
| 5803 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} | |
| 5804 | 5804 | \\} |
| 5805 | 5805 | , |
| 5806 | 5806 | "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| ... | ... | @@ -5810,7 +5810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5810 | 5810 | "wrong types given to @export", |
| 5811 | 5811 | \\extern fn entry() void { } |
| 5812 | 5812 | \\comptime { |
| 5813 | \\ @export("entry", entry, u32(1234)); | |
| 5813 | \\ @export("entry", entry, @as(u32, 1234)); | |
| 5814 | 5814 | \\} |
| 5815 | 5815 | , |
| 5816 | 5816 | "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", |
test/stage1/behavior.zig+5-5| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | comptime { |
| 2 | _ = @import("behavior/align.zig"); | |
| 2 | //_ = @import("behavior/align.zig"); | |
| 3 | 3 | _ = @import("behavior/alignof.zig"); |
| 4 | _ = @import("behavior/array.zig"); | |
| 4 | //_ = @import("behavior/array.zig"); | |
| 5 | 5 | _ = @import("behavior/asm.zig"); |
| 6 | 6 | _ = @import("behavior/async_fn.zig"); |
| 7 | 7 | _ = @import("behavior/atomics.zig"); |
| ... | ... | @@ -50,7 +50,7 @@ comptime { |
| 50 | 50 | _ = @import("behavior/bugs/920.zig"); |
| 51 | 51 | _ = @import("behavior/byteswap.zig"); |
| 52 | 52 | _ = @import("behavior/byval_arg_var.zig"); |
| 53 | _ = @import("behavior/cast.zig"); | |
| 53 | //_ = @import("behavior/cast.zig"); | |
| 54 | 54 | _ = @import("behavior/const_slice_child.zig"); |
| 55 | 55 | _ = @import("behavior/defer.zig"); |
| 56 | 56 | _ = @import("behavior/enum.zig"); |
| ... | ... | @@ -59,7 +59,7 @@ comptime { |
| 59 | 59 | _ = @import("behavior/eval.zig"); |
| 60 | 60 | _ = @import("behavior/field_parent_ptr.zig"); |
| 61 | 61 | _ = @import("behavior/floatop.zig"); |
| 62 | _ = @import("behavior/fn.zig"); | |
| 62 | //_ = @import("behavior/fn.zig"); | |
| 63 | 63 | _ = @import("behavior/fn_in_struct_in_comptime.zig"); |
| 64 | 64 | _ = @import("behavior/fn_delegation.zig"); |
| 65 | 65 | _ = @import("behavior/for.zig"); |
| ... | ... | @@ -73,7 +73,7 @@ comptime { |
| 73 | 73 | _ = @import("behavior/ir_block_deps.zig"); |
| 74 | 74 | _ = @import("behavior/math.zig"); |
| 75 | 75 | _ = @import("behavior/merge_error_sets.zig"); |
| 76 | _ = @import("behavior/misc.zig"); | |
| 76 | //_ = @import("behavior/misc.zig"); | |
| 77 | 77 | _ = @import("behavior/muladd.zig"); |
| 78 | 78 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); |
| 79 | 79 | _ = @import("behavior/new_stack_call.zig"); |
test/stage1/behavior/align.zig+2-2| ... | ... | @@ -7,7 +7,7 @@ var foo: u8 align(4) = 100; |
| 7 | 7 | test "global variable alignment" { |
| 8 | 8 | expect(@typeOf(&foo).alignment == 4); |
| 9 | 9 | expect(@typeOf(&foo) == *align(4) u8); |
| 10 | const slice = (*[1]u8)(&foo)[0..]; | |
| 10 | const slice = @as(*[1]u8, &foo)[0..]; | |
| 11 | 11 | expect(@typeOf(slice) == []align(4) u8); |
| 12 | 12 | } |
| 13 | 13 | |
| ... | ... | @@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| 61 | 61 | test "implicitly decreasing slice alignment" { |
| 62 | 62 | const a: u32 align(4) = 3; |
| 63 | 63 | const b: u32 align(8) = 4; |
| 64 | expect(addUnalignedSlice((*const [1]u32)(&a)[0..], (*const [1]u32)(&b)[0..]) == 7); | |
| 64 | expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7); | |
| 65 | 65 | } |
| 66 | 66 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { |
| 67 | 67 | return a[0] + b[0]; |
test/stage1/behavior/array.zig+2-2| ... | ... | @@ -12,7 +12,7 @@ test "arrays" { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | i = 0; |
| 15 | var accumulator = u32(0); | |
| 15 | var accumulator = @as(u32, 0); | |
| 16 | 16 | while (i < 5) { |
| 17 | 17 | accumulator += array[i]; |
| 18 | 18 | |
| ... | ... | @@ -149,7 +149,7 @@ test "implicit cast single-item pointer" { |
| 149 | 149 | |
| 150 | 150 | fn testImplicitCastSingleItemPtr() void { |
| 151 | 151 | var byte: u8 = 100; |
| 152 | const slice = (*[1]u8)(&byte)[0..]; | |
| 152 | const slice = @as(*[1]u8, &byte)[0..]; | |
| 153 | 153 | slice[0] += 1; |
| 154 | 154 | expect(byte == 101); |
| 155 | 155 | } |
test/stage1/behavior/asm.zig+8-8| ... | ... | @@ -45,42 +45,42 @@ test "alternative constraints" { |
| 45 | 45 | test "sized integer/float in asm input" { |
| 46 | 46 | asm volatile ("" |
| 47 | 47 | : |
| 48 | : [_] "m" (usize(3)) | |
| 48 | : [_] "m" (@as(usize, 3)) | |
| 49 | 49 | : "" |
| 50 | 50 | ); |
| 51 | 51 | asm volatile ("" |
| 52 | 52 | : |
| 53 | : [_] "m" (i15(-3)) | |
| 53 | : [_] "m" (@as(i15, -3)) | |
| 54 | 54 | : "" |
| 55 | 55 | ); |
| 56 | 56 | asm volatile ("" |
| 57 | 57 | : |
| 58 | : [_] "m" (u3(3)) | |
| 58 | : [_] "m" (@as(u3, 3)) | |
| 59 | 59 | : "" |
| 60 | 60 | ); |
| 61 | 61 | asm volatile ("" |
| 62 | 62 | : |
| 63 | : [_] "m" (i3(3)) | |
| 63 | : [_] "m" (@as(i3, 3)) | |
| 64 | 64 | : "" |
| 65 | 65 | ); |
| 66 | 66 | asm volatile ("" |
| 67 | 67 | : |
| 68 | : [_] "m" (u121(3)) | |
| 68 | : [_] "m" (@as(u121, 3)) | |
| 69 | 69 | : "" |
| 70 | 70 | ); |
| 71 | 71 | asm volatile ("" |
| 72 | 72 | : |
| 73 | : [_] "m" (i121(3)) | |
| 73 | : [_] "m" (@as(i121, 3)) | |
| 74 | 74 | : "" |
| 75 | 75 | ); |
| 76 | 76 | asm volatile ("" |
| 77 | 77 | : |
| 78 | : [_] "m" (f32(3.17)) | |
| 78 | : [_] "m" (@as(f32, 3.17)) | |
| 79 | 79 | : "" |
| 80 | 80 | ); |
| 81 | 81 | asm volatile ("" |
| 82 | 82 | : |
| 83 | : [_] "m" (f64(3.17)) | |
| 83 | : [_] "m" (@as(f64, 3.17)) | |
| 84 | 84 | : "" |
| 85 | 85 | ); |
| 86 | 86 | } |
test/stage1/behavior/async_fn.zig+5-5| ... | ... | @@ -191,7 +191,7 @@ async fn testSuspendBlock() void { |
| 191 | 191 | |
| 192 | 192 | // Test to make sure that @frame() works as advertised (issue #1296) |
| 193 | 193 | // var our_handle: anyframe = @frame(); |
| 194 | expect(a_promise == anyframe(@frame())); | |
| 194 | expect(a_promise == @as(anyframe, @frame())); | |
| 195 | 195 | |
| 196 | 196 | global_result = true; |
| 197 | 197 | } |
| ... | ... | @@ -543,7 +543,7 @@ test "pass string literal to async function" { |
| 543 | 543 | fn hello(msg: []const u8) void { |
| 544 | 544 | frame = @frame(); |
| 545 | 545 | suspend; |
| 546 | expectEqual(([]const u8)("hello"), msg); | |
| 546 | expectEqual(@as([]const u8, "hello"), msg); | |
| 547 | 547 | ok = true; |
| 548 | 548 | } |
| 549 | 549 | }; |
| ... | ... | @@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" { |
| 1048 | 1048 | return await @asyncCall(frame, {}, amain, x - 1); |
| 1049 | 1049 | } |
| 1050 | 1050 | }; |
| 1051 | _ = async S.amain(u32(1)); | |
| 1051 | _ = async S.amain(@as(u32, 1)); | |
| 1052 | 1052 | resume S.global_frame; |
| 1053 | 1053 | expect(S.global_ok); |
| 1054 | 1054 | } |
| ... | ... | @@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" { |
| 1080 | 1080 | }; |
| 1081 | 1081 | }; |
| 1082 | 1082 | 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)); | |
| 1085 | 1085 | resume S.global_frame; |
| 1086 | 1086 | expect(S.global_ok); |
| 1087 | 1087 | expect(res.x == 1); |
test/stage1/behavior/atomics.zig+3-3| ... | ... | @@ -98,12 +98,12 @@ test "cmpxchg with ignored result" { |
| 98 | 98 | |
| 99 | 99 | _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic); |
| 100 | 100 | |
| 101 | expectEqual(i32(5678), x); | |
| 101 | expectEqual(@as(i32, 5678), x); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | var a_global_variable = u32(1234); | |
| 104 | var a_global_variable = @as(u32, 1234); | |
| 105 | 105 | |
| 106 | 106 | test "cmpxchg on a global variable" { |
| 107 | 107 | _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic); |
| 108 | expectEqual(u32(42), a_global_variable); | |
| 108 | expectEqual(@as(u32, 42), a_global_variable); | |
| 109 | 109 | } |
test/stage1/behavior/bitreverse.zig+14-14| ... | ... | @@ -46,24 +46,24 @@ fn testBitReverse() void { |
| 46 | 46 | expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); |
| 47 | 47 | |
| 48 | 48 | // 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))); | |
| 59 | 59 | |
| 60 | 60 | // using signed, negative. Compare to runtime ints returned from llvm. |
| 61 | 61 | var neg8: i8 = -18; |
| 62 | expect(@bitReverse(i8, i8(-18)) == @bitReverse(i8, neg8)); | |
| 62 | expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8)); | |
| 63 | 63 | var neg16: i16 = -32694; |
| 64 | expect(@bitReverse(i16, i16(-32694)) == @bitReverse(i16, neg16)); | |
| 64 | expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16)); | |
| 65 | 65 | var neg24: i24 = -6773785; |
| 66 | expect(@bitReverse(i24, i24(-6773785)) == @bitReverse(i24, neg24)); | |
| 66 | expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24)); | |
| 67 | 67 | var neg32: i32 = -16773785; |
| 68 | expect(@bitReverse(i32, i32(-16773785)) == @bitReverse(i32, neg32)); | |
| 68 | expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32)); | |
| 69 | 69 | } |
test/stage1/behavior/bool.zig+4-4| ... | ... | @@ -8,14 +8,14 @@ test "bool literals" { |
| 8 | 8 | test "cast bool to int" { |
| 9 | 9 | const t = true; |
| 10 | 10 | 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)); | |
| 13 | 13 | nonConstCastBoolToInt(t, f); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn 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)); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "bool cmp" { |
test/stage1/behavior/bugs/1322.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ const C = struct {}; |
| 13 | 13 | |
| 14 | 14 | test "tagged union with all void fields but a meaningful tag" { |
| 15 | 15 | var a: A = A{ .b = B{ .c = C{} } }; |
| 16 | std.testing.expect(@TagType(B)(a.b) == @TagType(B).c); | |
| 16 | std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c); | |
| 17 | 17 | a = A{ .b = B.None }; |
| 18 | std.testing.expect(@TagType(B)(a.b) == @TagType(B).None); | |
| 18 | std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None); | |
| 19 | 19 | } |
test/stage1/behavior/bugs/1421.zig+1-1| ... | ... | @@ -10,5 +10,5 @@ const S = struct { |
| 10 | 10 | |
| 11 | 11 | test "functions with return type required to be comptime are generic" { |
| 12 | 12 | const ti = S.method(); |
| 13 | expect(builtin.TypeId(ti) == builtin.TypeId.Struct); | |
| 13 | expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct); | |
| 14 | 14 | } |
test/stage1/behavior/bugs/2114.zig+4-4| ... | ... | @@ -12,8 +12,8 @@ test "fixed" { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | fn 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); | |
| 19 | 19 | } |
test/stage1/behavior/bugs/3046.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined; |
| 13 | 13 | |
| 14 | 14 | test "fixed" { |
| 15 | 15 | some_struct = SomeStruct{ |
| 16 | .field = couldFail() catch |_| i32(0), | |
| 16 | .field = couldFail() catch |_| @as(i32, 0), | |
| 17 | 17 | }; |
| 18 | 18 | expect(some_struct.field == 1); |
| 19 | 19 | } |
test/stage1/behavior/byteswap.zig+12-12| ... | ... | @@ -11,24 +11,24 @@ test "@byteSwap integers" { |
| 11 | 11 | t(u24, 0x123456, 0x563412); |
| 12 | 12 | t(u32, 0x12345678, 0x78563412); |
| 13 | 13 | t(u40, 0x123456789a, 0x9a78563412); |
| 14 | t(i48, 0x123456789abc, @bitCast(i48, u48(0xbc9a78563412))); | |
| 14 | t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412))); | |
| 15 | 15 | t(u56, 0x123456789abcde, 0xdebc9a78563412); |
| 16 | 16 | t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); |
| 17 | 17 | t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412); |
| 18 | 18 | |
| 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))); | |
| 28 | 28 | t( |
| 29 | 29 | i128, |
| 30 | @bitCast(i128, u128(0x123456789abcdef11121314151617181)), | |
| 31 | @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)), | |
| 30 | @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), | |
| 31 | @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)), | |
| 32 | 32 | ); |
| 33 | 33 | } |
| 34 | 34 | fn t(comptime I: type, input: I, expected_output: I) void { |
test/stage1/behavior/cast.zig+6-6| ... | ... | @@ -4,7 +4,7 @@ const mem = std.mem; |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | test "int to ptr cast" { |
| 7 | const x = usize(13); | |
| 7 | const x = @as(usize, 13); | |
| 8 | 8 | const y = @intToPtr(*u8, x); |
| 9 | 9 | const z = @ptrToInt(y); |
| 10 | 10 | expect(z == 13); |
| ... | ... | @@ -90,7 +90,7 @@ const A = struct { |
| 90 | 90 | a: i32, |
| 91 | 91 | }; |
| 92 | 92 | fn castToOptionalTypeError(z: i32) void { |
| 93 | const x = i32(1); | |
| 93 | const x = @as(i32, 1); | |
| 94 | 94 | const y: anyerror!?i32 = x; |
| 95 | 95 | expect((try y).? == 1); |
| 96 | 96 | |
| ... | ... | @@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" { |
| 134 | 134 | } |
| 135 | 135 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 136 | 136 | if (c) { |
| 137 | return if (b) null else usize(0); | |
| 137 | return if (b) null else @as(usize, 0); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | return usize(3); | |
| 140 | return @as(usize, 3); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "peer type resolution: [0]u8 and []const u8" { |
| ... | ... | @@ -256,7 +256,7 @@ test "@floatToInt" { |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | fn testFloatToInts() void { |
| 259 | const x = i32(1e4); | |
| 259 | const x = @as(i32, 1e4); | |
| 260 | 260 | expect(x == 10000); |
| 261 | 261 | const y = @floatToInt(i32, f32(1e4)); |
| 262 | 262 | expect(y == 10000); |
| ... | ... | @@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | test "*usize to *void" { |
| 445 | var i = usize(0); | |
| 445 | var i = @as(usize, 0); | |
| 446 | 446 | var v = @ptrCast(*void, &i); |
| 447 | 447 | v.* = {}; |
| 448 | 448 | } |
test/stage1/behavior/defer.zig+1-1| ... | ... | @@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void { |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | test "defer and labeled break" { |
| 55 | var i = usize(0); | |
| 55 | var i = @as(usize, 0); | |
| 56 | 56 | |
| 57 | 57 | blk: { |
| 58 | 58 | defer i += 1; |
test/stage1/behavior/enum.zig+2-2| ... | ... | @@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { |
| 788 | 788 | expect(1234 == switch (x) { |
| 789 | 789 | MultipleChoice.A => 1, |
| 790 | 790 | MultipleChoice.B => 2, |
| 791 | MultipleChoice.C => u32(1234), | |
| 791 | MultipleChoice.C => @as(u32, 1234), | |
| 792 | 792 | MultipleChoice.D => 4, |
| 793 | 793 | }); |
| 794 | 794 | } |
| ... | ... | @@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 816 | 816 | MultipleChoice2.A => 1, |
| 817 | 817 | MultipleChoice2.B => 2, |
| 818 | 818 | MultipleChoice2.C => 3, |
| 819 | MultipleChoice2.D => u32(1234), | |
| 819 | MultipleChoice2.D => @as(u32, 1234), | |
| 820 | 820 | MultipleChoice2.Unspecified1 => 5, |
| 821 | 821 | MultipleChoice2.Unspecified2 => 6, |
| 822 | 822 | MultipleChoice2.Unspecified3 => 7, |
test/stage1/behavior/error.zig+2-2| ... | ... | @@ -51,7 +51,7 @@ test "error binary operator" { |
| 51 | 51 | expect(b == 10); |
| 52 | 52 | } |
| 53 | 53 | fn errBinaryOperatorG(x: bool) anyerror!isize { |
| 54 | return if (x) error.ItBroke else isize(10); | |
| 54 | return if (x) error.ItBroke else @as(isize, 10); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | test "unwrap simple value from error" { |
| ... | ... | @@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" { |
| 295 | 295 | test "widen cast integer payload of error union function call" { |
| 296 | 296 | const S = struct { |
| 297 | 297 | fn errorable() !u64 { |
| 298 | var x = u64(try number()); | |
| 298 | var x = @as(u64, try number()); | |
| 299 | 299 | return x; |
| 300 | 300 | } |
| 301 | 301 |
test/stage1/behavior/eval.zig+18-18| ... | ... | @@ -405,19 +405,19 @@ test "float literal at compile time not lossy" { |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | test "f32 at compile time is lossy" { |
| 408 | expect(f32(1 << 24) + 1 == 1 << 24); | |
| 408 | expect(@as(f32, 1 << 24) + 1 == 1 << 24); | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | test "f64 at compile time is lossy" { |
| 412 | expect(f64(1 << 53) + 1 == 1 << 53); | |
| 412 | expect(@as(f64, 1 << 53) + 1 == 1 << 53); | |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | test "f128 at compile time is lossy" { |
| 416 | expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | |
| 416 | expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | comptime { |
| 420 | expect(f128(1 << 113) == 10384593717069655257060992658440192); | |
| 420 | expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192); | |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| ... | ... | @@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" { |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | test "comptime slice of undefined pointer of length 0" { |
| 437 | const slice1 = ([*]i32)(undefined)[0..0]; | |
| 437 | const slice1 = @as([*]i32, undefined)[0..0]; | |
| 438 | 438 | expect(slice1.len == 0); |
| 439 | const slice2 = ([*]i32)(undefined)[100..100]; | |
| 439 | const slice2 = @as([*]i32, undefined)[100..100]; | |
| 440 | 440 | expect(slice2.len == 0); |
| 441 | 441 | } |
| 442 | 442 | |
| ... | ... | @@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void { |
| 444 | 444 | comptime var i: usize = 0; |
| 445 | 445 | inline while (i < 4) : (i += 1) { |
| 446 | 446 | 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; | |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | |
| ... | ... | @@ -557,14 +557,14 @@ test "array concat of slices gives slice" { |
| 557 | 557 | |
| 558 | 558 | test "comptime shlWithOverflow" { |
| 559 | 559 | 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); | |
| 562 | 562 | break :amt amt; |
| 563 | 563 | }; |
| 564 | 564 | |
| 565 | 565 | 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); | |
| 568 | 568 | break :amt amt; |
| 569 | 569 | }; |
| 570 | 570 | |
| ... | ... | @@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void { |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | test "variable inside inline loop that has different types on different iterations" { |
| 673 | testVarInsideInlineLoop(true, u32(42)); | |
| 673 | testVarInsideInlineLoop(true, @as(u32, 42)); | |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | fn testVarInsideInlineLoop(args: ...) void { |
| ... | ... | @@ -757,11 +757,11 @@ test "comptime bitwise operators" { |
| 757 | 757 | expect(-3 | -1 == -1); |
| 758 | 758 | expect(3 ^ -1 == -4); |
| 759 | 759 | 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); | |
| 762 | 762 | expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); |
| 763 | 763 | expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); |
| 764 | expect(~u128(0) == 0xffffffffffffffffffffffffffffffff); | |
| 764 | expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff); | |
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | 767 |
test/stage1/behavior/floatop.zig+2-2| ... | ... | @@ -117,11 +117,11 @@ test "@ln" { |
| 117 | 117 | fn testLn() void { |
| 118 | 118 | { |
| 119 | 119 | var a: f32 = e; |
| 120 | expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, u32(0x3f7fffff))); | |
| 120 | expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, @as(u32, 0x3f7fffff))); | |
| 121 | 121 | } |
| 122 | 122 | { |
| 123 | 123 | var a: f64 = e; |
| 124 | expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, u64(0x3ff0000000000000))); | |
| 124 | expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, @as(u64, 0x3ff0000000000000))); | |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 |
test/stage1/behavior/fn.zig+2-2| ... | ... | @@ -29,7 +29,7 @@ test "mutable local variables" { |
| 29 | 29 | var zero: i32 = 0; |
| 30 | 30 | expect(zero == 0); |
| 31 | 31 | |
| 32 | var i = i32(0); | |
| 32 | var i = @as(i32, 0); | |
| 33 | 33 | while (i != 3) { |
| 34 | 34 | i += 1; |
| 35 | 35 | } |
| ... | ... | @@ -43,7 +43,7 @@ test "separate block scopes" { |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | const c = x: { |
| 46 | const no_conflict = i32(10); | |
| 46 | const no_conflict = @as(i32, 10); | |
| 47 | 47 | break :x no_conflict; |
| 48 | 48 | }; |
| 49 | 49 | expect(c == 10); |
test/stage1/behavior/if.zig+2-2| ... | ... | @@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 { |
| 32 | 32 | } else if (c == 1) { |
| 33 | 33 | return 1; |
| 34 | 34 | } else { |
| 35 | return u8(2); | |
| 35 | return @as(u8, 2); | |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| ... | ... | @@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" { |
| 58 | 58 | var c = true; |
| 59 | 59 | if (c) { |
| 60 | 60 | answer = if (true) blk: { |
| 61 | break :blk i32(42); | |
| 61 | break :blk @as(i32, 42); | |
| 62 | 62 | }; |
| 63 | 63 | } |
| 64 | 64 | expect(answer == 42); |
test/stage1/behavior/import.zig+2-2| ... | ... | @@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual; |
| 3 | 3 | const a_namespace = @import("import/a_namespace.zig"); |
| 4 | 4 | |
| 5 | 5 | test "call fn via namespace lookup" { |
| 6 | expectEqual(i32(1234), a_namespace.foo()); | |
| 6 | expectEqual(@as(i32, 1234), a_namespace.foo()); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "importing the same thing gives the same import" { |
| ... | ... | @@ -14,5 +14,5 @@ test "import in non-toplevel scope" { |
| 14 | 14 | const S = struct { |
| 15 | 15 | usingnamespace @import("import/a_namespace.zig"); |
| 16 | 16 | }; |
| 17 | expectEqual(i32(1234), S.foo()); | |
| 17 | expectEqual(@as(i32, 1234), S.foo()); | |
| 18 | 18 | } |
test/stage1/behavior/math.zig+12-12| ... | ... | @@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void { |
| 186 | 186 | assertFalse(90 >> 1 >> 2 != 90 >> 3); |
| 187 | 187 | assertFalse(100 - 1 + 1000 != 1099); |
| 188 | 188 | assertFalse(5 * 4 / 2 % 3 != 1); |
| 189 | assertFalse(i32(i32(5)) != 5); | |
| 189 | assertFalse(@as(i32, @as(i32, 5)) != 5); | |
| 190 | 190 | assertFalse(!!false); |
| 191 | assertFalse(i32(7) != --(i32(7))); | |
| 191 | assertFalse(@as(i32, 7) != --(@as(i32, 7))); | |
| 192 | 192 | } |
| 193 | 193 | fn assertFalse(b: bool) void { |
| 194 | 194 | expect(!b); |
| ... | ... | @@ -256,10 +256,10 @@ const DivResult = struct { |
| 256 | 256 | |
| 257 | 257 | test "binary not" { |
| 258 | 258 | expect(comptime x: { |
| 259 | break :x ~u16(0b1010101010101010) == 0b0101010101010101; | |
| 259 | break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101; | |
| 260 | 260 | }); |
| 261 | 261 | expect(comptime x: { |
| 262 | break :x ~u64(2147483647) == 18446744071562067968; | |
| 262 | break :x ~@as(u64, 2147483647) == 18446744071562067968; | |
| 263 | 263 | }); |
| 264 | 264 | testBinaryNot(0b1010101010101010); |
| 265 | 265 | } |
| ... | ... | @@ -472,7 +472,7 @@ test "comptime_int multiplication" { |
| 472 | 472 | |
| 473 | 473 | test "comptime_int shifting" { |
| 474 | 474 | comptime { |
| 475 | expect((u128(1) << 127) == 0x80000000000000000000000000000000); | |
| 475 | expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000); | |
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | |
| ... | ... | @@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" { |
| 480 | 480 | comptime { |
| 481 | 481 | var a = 0xefffffffa0000001eeeeeeefaaaaaaab; |
| 482 | 482 | |
| 483 | expect(u32(a & 0xffffffff) == 0xaaaaaaab); | |
| 483 | expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab); | |
| 484 | 484 | a >>= 32; |
| 485 | expect(u32(a & 0xffffffff) == 0xeeeeeeef); | |
| 485 | expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef); | |
| 486 | 486 | a >>= 32; |
| 487 | expect(u32(a & 0xffffffff) == 0xa0000001); | |
| 487 | expect(@as(u32, a & 0xffffffff) == 0xa0000001); | |
| 488 | 488 | a >>= 32; |
| 489 | expect(u32(a & 0xffffffff) == 0xefffffff); | |
| 489 | expect(@as(u32, a & 0xffffffff) == 0xefffffff); | |
| 490 | 490 | a >>= 32; |
| 491 | 491 | |
| 492 | 492 | expect(a == 0); |
| ... | ... | @@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void { |
| 552 | 552 | |
| 553 | 553 | test "comptime float rem int" { |
| 554 | 554 | comptime { |
| 555 | var x = f32(1) % 2; | |
| 555 | var x = @as(f32, 1) % 2; | |
| 556 | 556 | expect(x == 1.0); |
| 557 | 557 | } |
| 558 | 558 | } |
| ... | ... | @@ -568,8 +568,8 @@ test "remainder division" { |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | fn 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)); | |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | test "@sqrt" { |
test/stage1/behavior/misc.zig+3-3| ... | ... | @@ -268,7 +268,7 @@ fn outer() i64 { |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | test "pointer dereferencing" { |
| 271 | var x = i32(3); | |
| 271 | var x = @as(i32, 3); | |
| 272 | 272 | const y = &x; |
| 273 | 273 | |
| 274 | 274 | y.* += 1; |
| ... | ... | @@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type { |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | test "double implicit cast in same expression" { |
| 503 | var x = i32(u16(nine())); | |
| 503 | var x = @as(i32, @as(u16, nine())); | |
| 504 | 504 | expect(x == 9); |
| 505 | 505 | } |
| 506 | 506 | fn nine() u8 { |
| ... | ... | @@ -761,7 +761,7 @@ test "nested optional field in struct" { |
| 761 | 761 | |
| 762 | 762 | fn maybe(x: bool) anyerror!?u32 { |
| 763 | 763 | return switch (x) { |
| 764 | true => u32(42), | |
| 764 | true => @as(u32, 42), | |
| 765 | 765 | else => null, |
| 766 | 766 | }; |
| 767 | 767 | } |
test/stage1/behavior/popcount.zig+1-1| ... | ... | @@ -35,7 +35,7 @@ fn testPopCount() void { |
| 35 | 35 | expect(@popCount(i8, x) == 2); |
| 36 | 36 | } |
| 37 | 37 | comptime { |
| 38 | expect(@popCount(u8, @bitCast(u8, i8(-120))) == 2); | |
| 38 | expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2); | |
| 39 | 39 | } |
| 40 | 40 | comptime { |
| 41 | 41 | expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); |
test/stage1/behavior/pub_enum.zig+1-1| ... | ... | @@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void { |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | test "cast with imported symbol" { |
| 12 | expect(other.size_t(42) == 42); | |
| 12 | expect(@as(other.size_t, 42) == 42); | |
| 13 | 13 | } |
test/stage1/behavior/shuffle.zig+13-13| ... | ... | @@ -7,39 +7,39 @@ test "@shuffle" { |
| 7 | 7 | fn doTheTest() void { |
| 8 | 8 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 9 | 9 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 10 | const mask: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 3, ~i32(3) }; | |
| 10 | const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; | |
| 11 | 11 | var res = @shuffle(i32, v, x, mask); |
| 12 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 })); | |
| 12 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); | |
| 13 | 13 | |
| 14 | 14 | // 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 })); | |
| 17 | 17 | |
| 18 | 18 | // Undefined |
| 19 | 19 | const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; |
| 20 | 20 | res = @shuffle(i32, v, undefined, mask2); |
| 21 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 40, -2, 30, 2147483647 })); | |
| 21 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 })); | |
| 22 | 22 | |
| 23 | 23 | // Upcasting of b |
| 24 | 24 | var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; |
| 25 | const mask3: @Vector(4, i32) = [4]i32{ ~i32(0), 2, ~i32(0), 3 }; | |
| 25 | const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; | |
| 26 | 26 | res = @shuffle(i32, x, v2, mask3); |
| 27 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 2147483647, 4 })); | |
| 27 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 })); | |
| 28 | 28 | |
| 29 | 29 | // Upcasting of a |
| 30 | 30 | var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; |
| 31 | const mask4: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 1, ~i32(3) }; | |
| 31 | const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; | |
| 32 | 32 | res = @shuffle(i32, v3, x, mask4); |
| 33 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, -2, 4 })); | |
| 33 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 })); | |
| 34 | 34 | |
| 35 | 35 | // bool |
| 36 | 36 | // Disabled because of #3317 |
| 37 | 37 | if (@import("builtin").arch != .mipsel) { |
| 38 | 38 | var x2: @Vector(4, bool) = [4]bool{ false, true, false, true }; |
| 39 | 39 | var v4: @Vector(2, bool) = [2]bool{ true, false }; |
| 40 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 }; | |
| 40 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; | |
| 41 | 41 | var res2 = @shuffle(bool, x2, v4, mask5); |
| 42 | expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false })); | |
| 42 | expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // TODO re-enable when LLVM codegen is fixed |
| ... | ... | @@ -47,9 +47,9 @@ test "@shuffle" { |
| 47 | 47 | if (false) { |
| 48 | 48 | var x2: @Vector(3, bool) = [3]bool{ false, true, false }; |
| 49 | 49 | var v4: @Vector(2, bool) = [2]bool{ true, false }; |
| 50 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 }; | |
| 50 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; | |
| 51 | 51 | var res2 = @shuffle(bool, x2, v4, mask5); |
| 52 | expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false })); | |
| 52 | expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); | |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | }; |
test/stage1/behavior/slicetobytes.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" { |
| 10 | 10 | const S = struct { |
| 11 | 11 | fn doTheTest() void { |
| 12 | 12 | var foo: Foo = undefined; |
| 13 | var slice = @sliceToBytes(((*[1]Foo)(&foo))[0..1]); | |
| 13 | var slice = @sliceToBytes(@as(*[1]Foo, &foo)[0..1]); | |
| 14 | 14 | slice[0] = 0x13; |
| 15 | 15 | switch (builtin.endian) { |
| 16 | 16 | builtin.Endian.Big => { |
test/stage1/behavior/struct.zig+8-8| ... | ... | @@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" { |
| 388 | 388 | expect(s2.y == @intCast(u4, x2)); |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | var x1 = u4(1); | |
| 392 | var x2 = u8(2); | |
| 391 | var x1 = @as(u4, 1); | |
| 392 | var x2 = @as(u8, 2); | |
| 393 | 393 | |
| 394 | 394 | const Nibbles = packed struct { |
| 395 | 395 | x: u4, |
| ... | ... | @@ -545,9 +545,9 @@ test "packed struct with fp fields" { |
| 545 | 545 | s.data[1] = 2.0; |
| 546 | 546 | s.data[2] = 3.0; |
| 547 | 547 | 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]); | |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | test "use within struct scope" { |
| ... | ... | @@ -558,7 +558,7 @@ test "use within struct scope" { |
| 558 | 558 | } |
| 559 | 559 | }; |
| 560 | 560 | }; |
| 561 | expectEqual(i32(42), S.inner()); | |
| 561 | expectEqual(@as(i32, 42), S.inner()); | |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | test "default struct initialization fields" { |
| ... | ... | @@ -583,7 +583,7 @@ test "extern fn returns struct by value" { |
| 583 | 583 | const S = struct { |
| 584 | 584 | fn entry() void { |
| 585 | 585 | var x = makeBar(10); |
| 586 | expectEqual(i32(10), x.handle); | |
| 586 | expectEqual(@as(i32, 10), x.handle); | |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | const ExternBar = extern struct { |
| ... | ... | @@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" { |
| 614 | 614 | |
| 615 | 615 | const ArrayList = struct { |
| 616 | 616 | fn toSlice(self: *ArrayList) []*Foo { |
| 617 | return ([*]*Foo)(undefined)[0..0]; | |
| 617 | return @as([*]*Foo, undefined)[0..0]; | |
| 618 | 618 | } |
| 619 | 619 | }; |
| 620 | 620 |
test/stage1/behavior/switch.zig+4-4| ... | ... | @@ -68,7 +68,7 @@ test "switch statement" { |
| 68 | 68 | } |
| 69 | 69 | fn nonConstSwitch(foo: SwitchStatmentFoo) void { |
| 70 | 70 | const val = switch (foo) { |
| 71 | SwitchStatmentFoo.A => i32(1), | |
| 71 | SwitchStatmentFoo.A => @as(i32, 1), | |
| 72 | 72 | SwitchStatmentFoo.B => 2, |
| 73 | 73 | SwitchStatmentFoo.C => 3, |
| 74 | 74 | SwitchStatmentFoo.D => 4, |
| ... | ... | @@ -127,7 +127,7 @@ test "switch with multiple expressions" { |
| 127 | 127 | const x = switch (returnsFive()) { |
| 128 | 128 | 1, 2, 3 => 1, |
| 129 | 129 | 4, 5, 6 => 2, |
| 130 | else => i32(3), | |
| 130 | else => @as(i32, 3), | |
| 131 | 131 | }; |
| 132 | 132 | expect(x == 2); |
| 133 | 133 | } |
| ... | ... | @@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void { |
| 186 | 186 | |
| 187 | 187 | fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| 188 | 188 | return switch (x) { |
| 189 | 0 => u2(3), | |
| 189 | 0 => @as(u2, 3), | |
| 190 | 190 | 1 => 2, |
| 191 | 191 | 2 => 1, |
| 192 | 192 | 3 => 0, |
| ... | ... | @@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| 195 | 195 | |
| 196 | 196 | fn testSwitchHandleAllCasesRange(x: u8) u8 { |
| 197 | 197 | return switch (x) { |
| 198 | 0...100 => u8(0), | |
| 198 | 0...100 => @as(u8, 0), | |
| 199 | 199 | 101...200 => 1, |
| 200 | 200 | 201, 203 => 2, |
| 201 | 201 | 202 => 4, |
test/stage1/behavior/try.zig+3-3| ... | ... | @@ -8,7 +8,7 @@ test "try on error union" { |
| 8 | 8 | fn tryOnErrorUnionImpl() void { |
| 9 | 9 | const x = if (returnsTen()) |val| val + 1 else |err| switch (err) { |
| 10 | 10 | error.ItBroke, error.NoMem => 1, |
| 11 | error.CrappedOut => i32(2), | |
| 11 | error.CrappedOut => @as(i32, 2), | |
| 12 | 12 | else => unreachable, |
| 13 | 13 | }; |
| 14 | 14 | expect(x == 11); |
| ... | ... | @@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "try without vars" { |
| 22 | const result1 = if (failIfTrue(true)) 1 else |_| i32(2); | |
| 22 | const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2); | |
| 23 | 23 | expect(result1 == 2); |
| 24 | 24 | |
| 25 | const result2 = if (failIfTrue(false)) 1 else |_| i32(2); | |
| 25 | const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2); | |
| 26 | 26 | expect(result2 == 1); |
| 27 | 27 | } |
| 28 | 28 |
test/stage1/behavior/type_info.zig+23-23| ... | ... | @@ -13,7 +13,7 @@ test "type info: tag type, void info" { |
| 13 | 13 | fn testBasic() void { |
| 14 | 14 | expect(@TagType(TypeInfo) == TypeId); |
| 15 | 15 | const void_info = @typeInfo(void); |
| 16 | expect(TypeId(void_info) == TypeId.Void); | |
| 16 | expect(@as(TypeId, void_info) == TypeId.Void); | |
| 17 | 17 | expect(void_info.Void == {}); |
| 18 | 18 | } |
| 19 | 19 | |
| ... | ... | @@ -24,12 +24,12 @@ test "type info: integer, floating point type info" { |
| 24 | 24 | |
| 25 | 25 | fn testIntFloat() void { |
| 26 | 26 | const u8_info = @typeInfo(u8); |
| 27 | expect(TypeId(u8_info) == TypeId.Int); | |
| 27 | expect(@as(TypeId, u8_info) == TypeId.Int); | |
| 28 | 28 | expect(!u8_info.Int.is_signed); |
| 29 | 29 | expect(u8_info.Int.bits == 8); |
| 30 | 30 | |
| 31 | 31 | const f64_info = @typeInfo(f64); |
| 32 | expect(TypeId(f64_info) == TypeId.Float); | |
| 32 | expect(@as(TypeId, f64_info) == TypeId.Float); | |
| 33 | 33 | expect(f64_info.Float.bits == 64); |
| 34 | 34 | } |
| 35 | 35 | |
| ... | ... | @@ -40,7 +40,7 @@ test "type info: pointer type info" { |
| 40 | 40 | |
| 41 | 41 | fn testPointer() void { |
| 42 | 42 | const u32_ptr_info = @typeInfo(*u32); |
| 43 | expect(TypeId(u32_ptr_info) == TypeId.Pointer); | |
| 43 | expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer); | |
| 44 | 44 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); |
| 45 | 45 | expect(u32_ptr_info.Pointer.is_const == false); |
| 46 | 46 | expect(u32_ptr_info.Pointer.is_volatile == false); |
| ... | ... | @@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" { |
| 55 | 55 | |
| 56 | 56 | fn testUnknownLenPtr() void { |
| 57 | 57 | const u32_ptr_info = @typeInfo([*]const volatile f64); |
| 58 | expect(TypeId(u32_ptr_info) == TypeId.Pointer); | |
| 58 | expect(@as(TypeId,u32_ptr_info) == TypeId.Pointer); | |
| 59 | 59 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); |
| 60 | 60 | expect(u32_ptr_info.Pointer.is_const == true); |
| 61 | 61 | expect(u32_ptr_info.Pointer.is_volatile == true); |
| ... | ... | @@ -70,7 +70,7 @@ test "type info: C pointer type info" { |
| 70 | 70 | |
| 71 | 71 | fn testCPtr() void { |
| 72 | 72 | const ptr_info = @typeInfo([*c]align(4) const i8); |
| 73 | expect(TypeId(ptr_info) == TypeId.Pointer); | |
| 73 | expect(@as(TypeId,ptr_info) == TypeId.Pointer); | |
| 74 | 74 | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C); |
| 75 | 75 | expect(ptr_info.Pointer.is_const); |
| 76 | 76 | expect(!ptr_info.Pointer.is_volatile); |
| ... | ... | @@ -85,7 +85,7 @@ test "type info: slice type info" { |
| 85 | 85 | |
| 86 | 86 | fn testSlice() void { |
| 87 | 87 | const u32_slice_info = @typeInfo([]u32); |
| 88 | expect(TypeId(u32_slice_info) == TypeId.Pointer); | |
| 88 | expect(@as(TypeId, u32_slice_info) == TypeId.Pointer); | |
| 89 | 89 | expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); |
| 90 | 90 | expect(u32_slice_info.Pointer.is_const == false); |
| 91 | 91 | expect(u32_slice_info.Pointer.is_volatile == false); |
| ... | ... | @@ -100,7 +100,7 @@ test "type info: array type info" { |
| 100 | 100 | |
| 101 | 101 | fn testArray() void { |
| 102 | 102 | const arr_info = @typeInfo([42]bool); |
| 103 | expect(TypeId(arr_info) == TypeId.Array); | |
| 103 | expect(@as(TypeId, arr_info) == TypeId.Array); | |
| 104 | 104 | expect(arr_info.Array.len == 42); |
| 105 | 105 | expect(arr_info.Array.child == bool); |
| 106 | 106 | } |
| ... | ... | @@ -112,7 +112,7 @@ test "type info: optional type info" { |
| 112 | 112 | |
| 113 | 113 | fn testOptional() void { |
| 114 | 114 | const null_info = @typeInfo(?void); |
| 115 | expect(TypeId(null_info) == TypeId.Optional); | |
| 115 | expect(@as(TypeId, null_info) == TypeId.Optional); | |
| 116 | 116 | expect(null_info.Optional.child == void); |
| 117 | 117 | } |
| 118 | 118 | |
| ... | ... | @@ -129,18 +129,18 @@ fn testErrorSet() void { |
| 129 | 129 | }; |
| 130 | 130 | |
| 131 | 131 | const error_set_info = @typeInfo(TestErrorSet); |
| 132 | expect(TypeId(error_set_info) == TypeId.ErrorSet); | |
| 132 | expect(@as(TypeId, error_set_info) == TypeId.ErrorSet); | |
| 133 | 133 | expect(error_set_info.ErrorSet.?.len == 3); |
| 134 | 134 | expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); |
| 135 | 135 | expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third)); |
| 136 | 136 | |
| 137 | 137 | const error_union_info = @typeInfo(TestErrorSet!usize); |
| 138 | expect(TypeId(error_union_info) == TypeId.ErrorUnion); | |
| 138 | expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion); | |
| 139 | 139 | expect(error_union_info.ErrorUnion.error_set == TestErrorSet); |
| 140 | 140 | expect(error_union_info.ErrorUnion.payload == usize); |
| 141 | 141 | |
| 142 | 142 | const global_info = @typeInfo(anyerror); |
| 143 | expect(TypeId(global_info) == TypeId.ErrorSet); | |
| 143 | expect(@as(TypeId, global_info) == TypeId.ErrorSet); | |
| 144 | 144 | expect(global_info.ErrorSet == null); |
| 145 | 145 | } |
| 146 | 146 | |
| ... | ... | @@ -158,7 +158,7 @@ fn testEnum() void { |
| 158 | 158 | }; |
| 159 | 159 | |
| 160 | 160 | const os_info = @typeInfo(Os); |
| 161 | expect(TypeId(os_info) == TypeId.Enum); | |
| 161 | expect(@as(TypeId, os_info) == TypeId.Enum); | |
| 162 | 162 | expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); |
| 163 | 163 | expect(os_info.Enum.fields.len == 4); |
| 164 | 164 | expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); |
| ... | ... | @@ -174,7 +174,7 @@ test "type info: union info" { |
| 174 | 174 | |
| 175 | 175 | fn testUnion() void { |
| 176 | 176 | const typeinfo_info = @typeInfo(TypeInfo); |
| 177 | expect(TypeId(typeinfo_info) == TypeId.Union); | |
| 177 | expect(@as(TypeId, typeinfo_info) == TypeId.Union); | |
| 178 | 178 | expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 179 | 179 | expect(typeinfo_info.Union.tag_type.? == TypeId); |
| 180 | 180 | expect(typeinfo_info.Union.fields.len == 26); |
| ... | ... | @@ -189,7 +189,7 @@ fn testUnion() void { |
| 189 | 189 | }; |
| 190 | 190 | |
| 191 | 191 | const notag_union_info = @typeInfo(TestNoTagUnion); |
| 192 | expect(TypeId(notag_union_info) == TypeId.Union); | |
| 192 | expect(@as(TypeId, notag_union_info) == TypeId.Union); | |
| 193 | 193 | expect(notag_union_info.Union.tag_type == null); |
| 194 | 194 | expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 195 | 195 | expect(notag_union_info.Union.fields.len == 2); |
| ... | ... | @@ -214,7 +214,7 @@ test "type info: struct info" { |
| 214 | 214 | |
| 215 | 215 | fn testStruct() void { |
| 216 | 216 | const struct_info = @typeInfo(TestStruct); |
| 217 | expect(TypeId(struct_info) == TypeId.Struct); | |
| 217 | expect(@as(TypeId, struct_info) == TypeId.Struct); | |
| 218 | 218 | expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); |
| 219 | 219 | expect(struct_info.Struct.fields.len == 3); |
| 220 | 220 | expect(struct_info.Struct.fields[1].offset == null); |
| ... | ... | @@ -244,7 +244,7 @@ test "type info: function type info" { |
| 244 | 244 | |
| 245 | 245 | fn testFunction() void { |
| 246 | 246 | const fn_info = @typeInfo(@typeOf(foo)); |
| 247 | expect(TypeId(fn_info) == TypeId.Fn); | |
| 247 | expect(@as(TypeId, fn_info) == TypeId.Fn); | |
| 248 | 248 | expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); |
| 249 | 249 | expect(fn_info.Fn.is_generic); |
| 250 | 250 | expect(fn_info.Fn.args.len == 2); |
| ... | ... | @@ -253,7 +253,7 @@ fn testFunction() void { |
| 253 | 253 | |
| 254 | 254 | const test_instance: TestStruct = undefined; |
| 255 | 255 | const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); |
| 256 | expect(TypeId(bound_fn_info) == TypeId.BoundFn); | |
| 256 | expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); | |
| 257 | 257 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); |
| 258 | 258 | } |
| 259 | 259 | |
| ... | ... | @@ -275,7 +275,7 @@ test "type info: vectors" { |
| 275 | 275 | |
| 276 | 276 | fn testVector() void { |
| 277 | 277 | const vec_info = @typeInfo(@Vector(4, i32)); |
| 278 | expect(TypeId(vec_info) == TypeId.Vector); | |
| 278 | expect(@as(TypeId, vec_info) == TypeId.Vector); | |
| 279 | 279 | expect(vec_info.Vector.len == 4); |
| 280 | 280 | expect(vec_info.Vector.child == i32); |
| 281 | 281 | } |
| ... | ... | @@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" { |
| 288 | 288 | fn testAnyFrame() void { |
| 289 | 289 | { |
| 290 | 290 | const anyframe_info = @typeInfo(anyframe->i32); |
| 291 | expect(TypeId(anyframe_info) == .AnyFrame); | |
| 291 | expect(@as(TypeId,anyframe_info) == .AnyFrame); | |
| 292 | 292 | expect(anyframe_info.AnyFrame.child.? == i32); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | { |
| 296 | 296 | const anyframe_info = @typeInfo(anyframe); |
| 297 | expect(TypeId(anyframe_info) == .AnyFrame); | |
| 297 | expect(@as(TypeId,anyframe_info) == .AnyFrame); | |
| 298 | 298 | expect(anyframe_info.AnyFrame.child == null); |
| 299 | 299 | } |
| 300 | 300 | } |
| ... | ... | @@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" { |
| 334 | 334 | if (std.mem.eql(u8, decl.name, "bar1")) { |
| 335 | 335 | expect(decl.data.Fn.lib_name == null); |
| 336 | 336 | } else { |
| 337 | std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?); | |
| 337 | std.testing.expectEqual(@as([]const u8,"cool"), decl.data.Fn.lib_name.?); | |
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | } |
| ... | ... | @@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" { |
| 342 | 342 | |
| 343 | 343 | test "data field is a compile-time value" { |
| 344 | 344 | const S = struct { |
| 345 | const Bar = isize(-1); | |
| 345 | const Bar = @as(isize, -1); | |
| 346 | 346 | }; |
| 347 | 347 | comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize); |
| 348 | 348 | } |
test/stage1/behavior/union.zig+12-12| ... | ... | @@ -14,7 +14,7 @@ const Agg = struct { |
| 14 | 14 | const v1 = Value{ .Int = 1234 }; |
| 15 | 15 | const v2 = Value{ .Array = [_]u8{3} ** 9 }; |
| 16 | 16 | |
| 17 | const err = (anyerror!Agg)(Agg{ | |
| 17 | const err = @as(anyerror!Agg, Agg{ | |
| 18 | 18 | .val1 = v1, |
| 19 | 19 | .val2 = v2, |
| 20 | 20 | }); |
| ... | ... | @@ -110,11 +110,11 @@ fn doTest() void { |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | fn bar(value: Payload) i32 { |
| 113 | expect(Letter(value) == Letter.A); | |
| 113 | expect(@as(Letter,value) == Letter.A); | |
| 114 | 114 | return switch (value) { |
| 115 | 115 | 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, | |
| 118 | 118 | }; |
| 119 | 119 | } |
| 120 | 120 | |
| ... | ... | @@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) { |
| 127 | 127 | test "simple union(enum(u32))" { |
| 128 | 128 | var x = MultipleChoice.C; |
| 129 | 129 | expect(x == MultipleChoice.C); |
| 130 | expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60); | |
| 130 | expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | const MultipleChoice2 = union(enum(u32)) { |
| ... | ... | @@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 152 | expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60); | |
| 152 | expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60); | |
| 153 | 153 | expect(1123 == switch (x) { |
| 154 | 154 | MultipleChoice2.A => 1, |
| 155 | 155 | MultipleChoice2.B => 2, |
| 156 | MultipleChoice2.C => |v| i32(1000) + v, | |
| 156 | MultipleChoice2.C => |v| @as(i32, 1000) + v, | |
| 157 | 157 | MultipleChoice2.D => 4, |
| 158 | 158 | MultipleChoice2.Unspecified1 => 5, |
| 159 | 159 | MultipleChoice2.Unspecified2 => 6, |
| ... | ... | @@ -208,12 +208,12 @@ test "cast union to tag type of union" { |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | fn testCastUnionToTagType(x: TheUnion) void { |
| 211 | expect(TheTag(x) == TheTag.B); | |
| 211 | expect(@as(TheTag,x) == TheTag.B); | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | test "cast tag type of union to union" { |
| 215 | 215 | var x: Value2 = Letter2.B; |
| 216 | expect(Letter2(x) == Letter2.B); | |
| 216 | expect(@as(Letter2, x) == Letter2.B); | |
| 217 | 217 | } |
| 218 | 218 | const Letter2 = enum { |
| 219 | 219 | A, |
| ... | ... | @@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) { |
| 297 | 297 | |
| 298 | 298 | fn testTaggedUnionInit(x: var) bool { |
| 299 | 299 | const y = TaggedUnionWithAVoid{ .A = x }; |
| 300 | return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A; | |
| 300 | return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A; | |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | pub const UnionEnumNoPayloads = union(enum) { |
| ... | ... | @@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" { |
| 326 | 326 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 327 | 327 | const Tag = @TagType(Expr); |
| 328 | 328 | comptime expect(@TagType(Tag) == u0); |
| 329 | var t = Tag(e); | |
| 329 | var t = @as(Tag, e); | |
| 330 | 330 | expect(t == Expr.Literal); |
| 331 | 331 | } |
| 332 | 332 | |
| ... | ... | @@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 346 | 346 | |
| 347 | 347 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 348 | 348 | comptime expect(@TagType(Tag) == comptime_int); |
| 349 | var t = Tag(e); | |
| 349 | var t = @as(Tag, e); | |
| 350 | 350 | expect(t == Expr.Literal); |
| 351 | 351 | expect(@enumToInt(t) == 33); |
| 352 | 352 | comptime expect(@enumToInt(t) == 33); |
test/stage1/behavior/var_args.zig+5-5| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | fn add(args: ...) i32 { |
| 4 | var sum = i32(0); | |
| 4 | var sum = @as(i32, 0); | |
| 5 | 5 | { |
| 6 | 6 | comptime var i: usize = 0; |
| 7 | 7 | inline while (i < args.len) : (i += 1) { |
| ... | ... | @@ -12,8 +12,8 @@ fn add(args: ...) i32 { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "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); | |
| 17 | 17 | expect(add() == 0); |
| 18 | 18 | } |
| 19 | 19 | |
| ... | ... | @@ -26,8 +26,8 @@ test "send void arg to var args" { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "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); | |
| 31 | 31 | expect(addSomeStuff() == 0); |
| 32 | 32 | } |
| 33 | 33 |
test/stage1/behavior/vector.zig+25-25| ... | ... | @@ -20,11 +20,11 @@ test "vector wrap operators" { |
| 20 | 20 | fn doTheTest() void { |
| 21 | 21 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 22 | 22 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 23 | expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); | |
| 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 })); | |
| 26 | 26 | var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; |
| 27 | expect(mem.eql(i32, ([4]i32)(-%z), [4]i32{ -1, -2, -3, -2147483648 })); | |
| 27 | expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 })); | |
| 28 | 28 | } |
| 29 | 29 | }; |
| 30 | 30 | S.doTheTest(); |
| ... | ... | @@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" { |
| 36 | 36 | fn doTheTest() void { |
| 37 | 37 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 38 | 38 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; |
| 39 | expect(mem.eql(bool, ([4]bool)(v == x), [4]bool{ false, false, true, false })); | |
| 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 })); | |
| 45 | 45 | } |
| 46 | 46 | }; |
| 47 | 47 | S.doTheTest(); |
| ... | ... | @@ -53,10 +53,10 @@ test "vector int operators" { |
| 53 | 53 | fn doTheTest() void { |
| 54 | 54 | var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; |
| 55 | 55 | var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; |
| 56 | expect(mem.eql(i32, ([4]i32)(v + x), [4]i32{ 11, 22, 33, 44 })); | |
| 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 })); | |
| 60 | 60 | } |
| 61 | 61 | }; |
| 62 | 62 | S.doTheTest(); |
| ... | ... | @@ -68,10 +68,10 @@ test "vector float operators" { |
| 68 | 68 | fn doTheTest() void { |
| 69 | 69 | var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; |
| 70 | 70 | var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 }; |
| 71 | expect(mem.eql(f32, ([4]f32)(v + x), [4]f32{ 11, 22, 33, 44 })); | |
| 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 })); | |
| 75 | 75 | } |
| 76 | 76 | }; |
| 77 | 77 | S.doTheTest(); |
| ... | ... | @@ -83,9 +83,9 @@ test "vector bit operators" { |
| 83 | 83 | fn doTheTest() void { |
| 84 | 84 | var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; |
| 85 | 85 | var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; |
| 86 | expect(mem.eql(u8, ([4]u8)(v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); | |
| 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 })); | |
| 89 | 89 | } |
| 90 | 90 | }; |
| 91 | 91 | S.doTheTest(); |
| ... | ... | @@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" { |
| 120 | 120 | { |
| 121 | 121 | var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; |
| 122 | 122 | var x: [4]u3 = v; |
| 123 | expect(mem.eql(u3, x, ([4]u3)(v))); | |
| 123 | expect(mem.eql(u3, x, @as([4]u3, v))); | |
| 124 | 124 | } |
| 125 | 125 | { |
| 126 | 126 | var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; |
| 127 | 127 | var x: [4]u2 = v; |
| 128 | expect(mem.eql(u2, x, ([4]u2)(v))); | |
| 128 | expect(mem.eql(u2, x, @as([4]u2, v))); | |
| 129 | 129 | } |
| 130 | 130 | { |
| 131 | 131 | var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; |
| 132 | 132 | var x: [4]u1 = v; |
| 133 | expect(mem.eql(u1, x, ([4]u1)(v))); | |
| 133 | expect(mem.eql(u1, x, @as([4]u1, v))); | |
| 134 | 134 | } |
| 135 | 135 | { |
| 136 | 136 | var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; |
| 137 | 137 | var x: [4]bool = v; |
| 138 | expect(mem.eql(bool, x, ([4]bool)(v))); | |
| 138 | expect(mem.eql(bool, x, @as([4]bool, v))); | |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | }; |
test/stage1/behavior/void.zig+1-1| ... | ... | @@ -26,7 +26,7 @@ test "iterate over a void slice" { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | fn times(n: usize) []const void { |
| 29 | return ([*]void)(undefined)[0..n]; | |
| 29 | return @as([*]void, undefined)[0..n]; | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | test "void optional" { |
test/stage1/behavior/while.zig+8-8| ... | ... | @@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" { |
| 137 | 137 | const result = while (returnNull()) |value| { |
| 138 | 138 | break value; |
| 139 | 139 | } else |
| 140 | i32(2); | |
| 140 | @as(i32, 2); | |
| 141 | 141 | expect(result == 2); |
| 142 | 142 | } |
| 143 | 143 | |
| ... | ... | @@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" { |
| 145 | 145 | const result = while (returnOptional(10)) |value| { |
| 146 | 146 | break value; |
| 147 | 147 | } else |
| 148 | i32(2); | |
| 148 | @as(i32, 2); | |
| 149 | 149 | expect(result == 10); |
| 150 | 150 | } |
| 151 | 151 | |
| ... | ... | @@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" { |
| 153 | 153 | const result = while (returnError()) |value| { |
| 154 | 154 | break value; |
| 155 | 155 | } else |err| |
| 156 | i32(2); | |
| 156 | @as(i32, 2); | |
| 157 | 157 | expect(result == 2); |
| 158 | 158 | } |
| 159 | 159 | |
| ... | ... | @@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" { |
| 161 | 161 | const result = while (returnSuccess(10)) |value| { |
| 162 | 162 | break value; |
| 163 | 163 | } else |err| |
| 164 | i32(2); | |
| 164 | @as(i32, 2); | |
| 165 | 165 | expect(result == 10); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | test "while on bool with else result follow else prong" { |
| 169 | 169 | const result = while (returnFalse()) { |
| 170 | break i32(10); | |
| 170 | break @as(i32, 10); | |
| 171 | 171 | } else |
| 172 | i32(2); | |
| 172 | @as(i32, 2); | |
| 173 | 173 | expect(result == 2); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "while on bool with else result follow break prong" { |
| 177 | 177 | const result = while (returnTrue()) { |
| 178 | break i32(10); | |
| 178 | break @as(i32, 10); | |
| 179 | 179 | } else |
| 180 | i32(2); | |
| 180 | @as(i32, 2); | |
| 181 | 181 | expect(result == 10); |
| 182 | 182 | } |
| 183 | 183 |
test/tests.zig+2-2| ... | ... | @@ -411,7 +411,7 @@ pub fn addPkgTests( |
| 411 | 411 | const ArchTag = @TagType(builtin.Arch); |
| 412 | 412 | if (test_target.disable_native and |
| 413 | 413 | test_target.target.getOs() == builtin.os and |
| 414 | ArchTag(test_target.target.getArch()) == ArchTag(builtin.arch)) | |
| 414 | @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch)) | |
| 415 | 415 | { |
| 416 | 416 | continue; |
| 417 | 417 | } |
| ... | ... | @@ -429,7 +429,7 @@ pub fn addPkgTests( |
| 429 | 429 | "bare"; |
| 430 | 430 | |
| 431 | 431 | const triple_prefix = if (test_target.target == .Native) |
| 432 | ([]const u8)("native") | |
| 432 | @as([]const u8,"native") | |
| 433 | 433 | else |
| 434 | 434 | test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; |
| 435 | 435 |
test/translate_c.zig+31-31| ... | ... | @@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 28 | 28 | , |
| 29 | 29 | \\pub fn foo() void { |
| 30 | 30 | \\ var a: c_int = undefined; |
| 31 | \\ var b: u8 = u8(123); | |
| 31 | \\ var b: u8 = @as(u8, 123); | |
| 32 | 32 | \\ const c: c_int = undefined; |
| 33 | \\ const d: c_uint = c_uint(440); | |
| 33 | \\ const d: c_uint = @as(c_uint, 440); | |
| 34 | 34 | \\} |
| 35 | 35 | ); |
| 36 | 36 | |
| ... | ... | @@ -561,7 +561,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 561 | 561 | cases.add("u integer suffix after hex literal", |
| 562 | 562 | \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 563 | 563 | , |
| 564 | \\pub const SDL_INIT_VIDEO = c_uint(32); | |
| 564 | \\pub const SDL_INIT_VIDEO = @as(c_uint, 32); | |
| 565 | 565 | ); |
| 566 | 566 | |
| 567 | 567 | cases.add("l integer suffix after hex literal", |
| ... | ... | @@ -676,7 +676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 676 | 676 | \\pub export fn log2(_arg_a: c_uint) c_int { |
| 677 | 677 | \\ var a = _arg_a; |
| 678 | 678 | \\ var i: c_int = 0; |
| 679 | \\ while (a > c_uint(0)) { | |
| 679 | \\ while (a > @as(c_uint, 0)) { | |
| 680 | 680 | \\ a >>= @import("std").math.Log2Int(c_uint)(1); |
| 681 | 681 | \\ } |
| 682 | 682 | \\ return i; |
| ... | ... | @@ -848,7 +848,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 848 | 848 | \\pub export fn log2(_arg_a: u32) c_int { |
| 849 | 849 | \\ var a = _arg_a; |
| 850 | 850 | \\ var i: c_int = 0; |
| 851 | \\ while (a > c_uint(0)) { | |
| 851 | \\ while (a > @as(c_uint, 0)) { | |
| 852 | 852 | \\ a >>= u5(1); |
| 853 | 853 | \\ } |
| 854 | 854 | \\ return i; |
| ... | ... | @@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 937 | 937 | \\} |
| 938 | 938 | , |
| 939 | 939 | \\pub export fn float_to_int(a: f32) c_int { |
| 940 | \\ return c_int(a); | |
| 940 | \\ return @as(c_int, a); | |
| 941 | 941 | \\} |
| 942 | 942 | ); |
| 943 | 943 | |
| ... | ... | @@ -1103,35 +1103,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1103 | 1103 | \\} |
| 1104 | 1104 | , |
| 1105 | 1105 | \\pub export fn foo() void { |
| 1106 | \\ var a: c_uint = c_uint(0); | |
| 1106 | \\ var a: c_uint = @as(c_uint, 0); | |
| 1107 | 1107 | \\ a +%= (x: { |
| 1108 | 1108 | \\ const _ref = &a; |
| 1109 | \\ _ref.* = (_ref.* +% c_uint(1)); | |
| 1109 | \\ _ref.* = (_ref.* +% @as(c_uint, 1)); | |
| 1110 | 1110 | \\ break :x _ref.*; |
| 1111 | 1111 | \\ }); |
| 1112 | 1112 | \\ a -%= (x: { |
| 1113 | 1113 | \\ const _ref = &a; |
| 1114 | \\ _ref.* = (_ref.* -% c_uint(1)); | |
| 1114 | \\ _ref.* = (_ref.* -% @as(c_uint, 1)); | |
| 1115 | 1115 | \\ break :x _ref.*; |
| 1116 | 1116 | \\ }); |
| 1117 | 1117 | \\ a *%= (x: { |
| 1118 | 1118 | \\ const _ref = &a; |
| 1119 | \\ _ref.* = (_ref.* *% c_uint(1)); | |
| 1119 | \\ _ref.* = (_ref.* *% @as(c_uint, 1)); | |
| 1120 | 1120 | \\ break :x _ref.*; |
| 1121 | 1121 | \\ }); |
| 1122 | 1122 | \\ a &= (x: { |
| 1123 | 1123 | \\ const _ref = &a; |
| 1124 | \\ _ref.* = (_ref.* & c_uint(1)); | |
| 1124 | \\ _ref.* = (_ref.* & @as(c_uint, 1)); | |
| 1125 | 1125 | \\ break :x _ref.*; |
| 1126 | 1126 | \\ }); |
| 1127 | 1127 | \\ a |= (x: { |
| 1128 | 1128 | \\ const _ref = &a; |
| 1129 | \\ _ref.* = (_ref.* | c_uint(1)); | |
| 1129 | \\ _ref.* = (_ref.* | @as(c_uint, 1)); | |
| 1130 | 1130 | \\ break :x _ref.*; |
| 1131 | 1131 | \\ }); |
| 1132 | 1132 | \\ a ^= (x: { |
| 1133 | 1133 | \\ const _ref = &a; |
| 1134 | \\ _ref.* = (_ref.* ^ c_uint(1)); | |
| 1134 | \\ _ref.* = (_ref.* ^ @as(c_uint, 1)); | |
| 1135 | 1135 | \\ break :x _ref.*; |
| 1136 | 1136 | \\ }); |
| 1137 | 1137 | \\ a >>= @import("std").math.Log2Int(c_uint)((x: { |
| ... | ... | @@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1174 | 1174 | , |
| 1175 | 1175 | \\pub export fn foo() void { |
| 1176 | 1176 | \\ var i: c_int = 0; |
| 1177 | \\ var u: c_uint = c_uint(0); | |
| 1177 | \\ var u: c_uint = @as(c_uint, 0); | |
| 1178 | 1178 | \\ i += 1; |
| 1179 | 1179 | \\ i -= 1; |
| 1180 | 1180 | \\ u +%= 1; |
| ... | ... | @@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1222 | 1222 | , |
| 1223 | 1223 | \\pub export fn foo() void { |
| 1224 | 1224 | \\ var i: c_int = 0; |
| 1225 | \\ var u: c_uint = c_uint(0); | |
| 1225 | \\ var u: c_uint = @as(c_uint, 0); | |
| 1226 | 1226 | \\ i += 1; |
| 1227 | 1227 | \\ i -= 1; |
| 1228 | 1228 | \\ u +%= 1; |
| ... | ... | @@ -1646,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1646 | 1646 | cases.addC( |
| 1647 | 1647 | "u integer suffix after 0 (zero) in macro definition", |
| 1648 | 1648 | "#define ZERO 0U", |
| 1649 | "pub const ZERO = c_uint(0);", | |
| 1649 | "pub const ZERO = @as(c_uint, 0);", | |
| 1650 | 1650 | ); |
| 1651 | 1651 | |
| 1652 | 1652 | cases.addC( |
| ... | ... | @@ -1688,7 +1688,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1688 | 1688 | cases.addC( |
| 1689 | 1689 | "bitwise not on u-suffixed 0 (zero) in macro definition", |
| 1690 | 1690 | "#define NOT_ZERO (~0U)", |
| 1691 | "pub const NOT_ZERO = ~c_uint(0);", | |
| 1691 | "pub const NOT_ZERO = ~@as(c_uint, 0);", | |
| 1692 | 1692 | ); |
| 1693 | 1693 | |
| 1694 | 1694 | cases.addC("implicit casts", |
| ... | ... | @@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1733 | 1733 | \\ fn_int(1094861636); |
| 1734 | 1734 | \\ fn_f32(@intToFloat(f32, 3)); |
| 1735 | 1735 | \\ 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)); | |
| 1739 | 1739 | \\ fn_f32(3.000000); |
| 1740 | 1740 | \\ fn_f64(3.000000); |
| 1741 | 1741 | \\ fn_bool(true); |
| ... | ... | @@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1798 | 1798 | \\ |
| 1799 | 1799 | , |
| 1800 | 1800 | \\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, '\"'); | |
| 1812 | 1812 | \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; |
| 1813 | 1813 | \\} |
| 1814 | 1814 | \\ |