update the codebase to use @as
This commit is contained in:
parent
2a6fbbd8fb
commit
e0db54e89d
@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
|
||||
) catch unreachable;
|
||||
for (dep.system_libs.toSliceConst()) |lib| {
|
||||
const static_bare_name = if (mem.eql(u8, lib, "curses"))
|
||||
([]const u8)("libncurses.a")
|
||||
@as([]const u8,"libncurses.a")
|
||||
else
|
||||
b.fmt("lib{}.a", lib);
|
||||
const static_lib_name = fs.path.join(
|
||||
|
@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" {
|
||||
try list.append(7);
|
||||
|
||||
//remove from middle
|
||||
testing.expectEqual(i32(4), list.orderedRemove(3));
|
||||
testing.expectEqual(i32(5), list.at(3));
|
||||
testing.expectEqual(usize(6), list.len);
|
||||
testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
|
||||
testing.expectEqual(@as(i32, 5), list.at(3));
|
||||
testing.expectEqual(@as(usize, 6), list.len);
|
||||
|
||||
//remove from end
|
||||
testing.expectEqual(i32(7), list.orderedRemove(5));
|
||||
testing.expectEqual(usize(5), list.len);
|
||||
testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
|
||||
testing.expectEqual(@as(usize, 5), list.len);
|
||||
|
||||
//remove from front
|
||||
testing.expectEqual(i32(1), list.orderedRemove(0));
|
||||
testing.expectEqual(i32(2), list.at(0));
|
||||
testing.expectEqual(usize(4), list.len);
|
||||
testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
|
||||
testing.expectEqual(@as(i32, 2), list.at(0));
|
||||
testing.expectEqual(@as(usize, 4), list.len);
|
||||
}
|
||||
|
||||
test "std.ArrayList.swapRemove" {
|
||||
|
@ -129,26 +129,26 @@ const combinedTable = init: {
|
||||
comptime var i = 0;
|
||||
inline while (i < 128) : (i += 1) {
|
||||
table[i] =
|
||||
u8(alpha[i]) << @enumToInt(tIndex.Alpha) |
|
||||
u8(hex[i]) << @enumToInt(tIndex.Hex) |
|
||||
u8(space[i]) << @enumToInt(tIndex.Space) |
|
||||
u8(digit[i]) << @enumToInt(tIndex.Digit) |
|
||||
u8(lower[i]) << @enumToInt(tIndex.Lower) |
|
||||
u8(upper[i]) << @enumToInt(tIndex.Upper) |
|
||||
u8(punct[i]) << @enumToInt(tIndex.Punct) |
|
||||
u8(graph[i]) << @enumToInt(tIndex.Graph);
|
||||
@as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) |
|
||||
@as(u8, hex[i]) << @enumToInt(tIndex.Hex) |
|
||||
@as(u8, space[i]) << @enumToInt(tIndex.Space) |
|
||||
@as(u8, digit[i]) << @enumToInt(tIndex.Digit) |
|
||||
@as(u8, lower[i]) << @enumToInt(tIndex.Lower) |
|
||||
@as(u8, upper[i]) << @enumToInt(tIndex.Upper) |
|
||||
@as(u8, punct[i]) << @enumToInt(tIndex.Punct) |
|
||||
@as(u8, graph[i]) << @enumToInt(tIndex.Graph);
|
||||
}
|
||||
mem.set(u8, table[128..256], 0);
|
||||
break :init table;
|
||||
};
|
||||
|
||||
fn inTable(c: u8, t: tIndex) bool {
|
||||
return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0;
|
||||
return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
|
||||
}
|
||||
|
||||
pub fn isAlNum(c: u8) bool {
|
||||
return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) |
|
||||
u8(1) << @enumToInt(tIndex.Digit))) != 0;
|
||||
return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
|
||||
@as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
|
||||
}
|
||||
|
||||
pub fn isAlpha(c: u8) bool {
|
||||
|
@ -214,8 +214,8 @@ test "std.atomic.Queue" {
|
||||
std.debug.panic(
|
||||
"failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
|
||||
context.get_count,
|
||||
u32(puts_per_thread),
|
||||
u32(put_thread_count),
|
||||
@as(u32, puts_per_thread),
|
||||
@as(u32, put_thread_count),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type {
|
||||
root: ?*Node,
|
||||
lock: @typeOf(lock_init),
|
||||
|
||||
const lock_init = if (builtin.single_threaded) {} else u8(0);
|
||||
const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);
|
||||
|
||||
pub const Self = @This();
|
||||
|
||||
@ -141,8 +141,8 @@ test "std.atomic.stack" {
|
||||
std.debug.panic(
|
||||
"failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
|
||||
context.get_count,
|
||||
u32(puts_per_thread),
|
||||
u32(put_thread_count),
|
||||
@as(u32, puts_per_thread),
|
||||
@as(u32, put_thread_count),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ test "std.BloomFilter" {
|
||||
testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
|
||||
}
|
||||
testing.expectEqual(BF.Index(0), bf.popCount());
|
||||
testing.expectEqual(f64(0), bf.estimateItems());
|
||||
testing.expectEqual(@as(f64, 0), bf.estimateItems());
|
||||
// fill in a few items
|
||||
bf.incrementCell(42);
|
||||
bf.incrementCell(255);
|
||||
@ -197,7 +197,7 @@ test "std.BloomFilter" {
|
||||
testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
|
||||
}
|
||||
testing.expectEqual(BF.Index(0), bf.popCount());
|
||||
testing.expectEqual(f64(0), bf.estimateItems());
|
||||
testing.expectEqual(@as(f64, 0), bf.estimateItems());
|
||||
|
||||
// Lets add a string
|
||||
bf.add("foo");
|
||||
@ -219,7 +219,7 @@ test "std.BloomFilter" {
|
||||
testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
|
||||
}
|
||||
testing.expectEqual(BF.Index(0), bf.popCount());
|
||||
testing.expectEqual(f64(0), bf.estimateItems());
|
||||
testing.expectEqual(@as(f64, 0), bf.estimateItems());
|
||||
|
||||
comptime var teststrings = [_][]const u8{
|
||||
"foo",
|
||||
|
@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo
|
||||
pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
|
||||
|
||||
pub fn sigaddset(set: *sigset_t, signo: u5) void {
|
||||
set.* |= u32(1) << (signo - 1);
|
||||
set.* |= @as(u32, 1) << (signo - 1);
|
||||
}
|
||||
|
||||
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
||||
|
@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void {
|
||||
// Child of fork calls this to report an error to the fork parent.
|
||||
// Then the child exits.
|
||||
fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
|
||||
writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};
|
||||
writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {};
|
||||
os.exit(1);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ const testing = std.testing;
|
||||
|
||||
// Apply sbox0 to each byte in w.
|
||||
fn subw(w: u32) u32 {
|
||||
return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]);
|
||||
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]);
|
||||
}
|
||||
|
||||
fn rotw(w: u32) u32 {
|
||||
@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
|
||||
}
|
||||
|
||||
// Last round uses s-box directly and XORs to produce output.
|
||||
s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]);
|
||||
s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | u32(sbox0[t0 & 0xff]);
|
||||
s2 = u32(sbox0[t2 >> 24]) << 24 | u32(sbox0[t3 >> 16 & 0xff]) << 16 | u32(sbox0[t0 >> 8 & 0xff]) << 8 | u32(sbox0[t1 & 0xff]);
|
||||
s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 0xff]);
|
||||
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]);
|
||||
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]);
|
||||
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]);
|
||||
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]);
|
||||
|
||||
s0 ^= xk[k + 0];
|
||||
s1 ^= xk[k + 1];
|
||||
@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
|
||||
}
|
||||
|
||||
// Last round uses s-box directly and XORs to produce output.
|
||||
s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]);
|
||||
s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | u32(sbox1[t2 & 0xff]);
|
||||
s2 = u32(sbox1[t2 >> 24]) << 24 | u32(sbox1[t1 >> 16 & 0xff]) << 16 | u32(sbox1[t0 >> 8 & 0xff]) << 8 | u32(sbox1[t3 & 0xff]);
|
||||
s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 0xff]);
|
||||
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]);
|
||||
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]);
|
||||
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]);
|
||||
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]);
|
||||
|
||||
s0 ^= xk[k + 0];
|
||||
s1 ^= xk[k + 1];
|
||||
@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void {
|
||||
while (i < enc.len) : (i += 1) {
|
||||
var t = enc[i - 1];
|
||||
if (i % nk == 0) {
|
||||
t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24);
|
||||
t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24);
|
||||
} else if (nk > 6 and i % nk == 4) {
|
||||
t = subw(t);
|
||||
}
|
||||
|
@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type {
|
||||
inline while (j < 10) : (j += 1) {
|
||||
inline for (rounds) |r| {
|
||||
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
|
||||
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16));
|
||||
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16));
|
||||
v[r.c] = v[r.c] +% v[r.d];
|
||||
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12));
|
||||
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12));
|
||||
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
|
||||
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8));
|
||||
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8));
|
||||
v[r.c] = v[r.c] +% v[r.d];
|
||||
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7));
|
||||
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7));
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type {
|
||||
inline while (j < 12) : (j += 1) {
|
||||
inline for (rounds) |r| {
|
||||
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
|
||||
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32));
|
||||
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32));
|
||||
v[r.c] = v[r.c] +% v[r.d];
|
||||
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24));
|
||||
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24));
|
||||
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
|
||||
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16));
|
||||
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16));
|
||||
v[r.c] = v[r.c] +% v[r.d];
|
||||
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63));
|
||||
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {
|
||||
// two-round cycles
|
||||
inline for (rounds) |r| {
|
||||
x[r.a] +%= x[r.b];
|
||||
x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(16));
|
||||
x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 16));
|
||||
x[r.c] +%= x[r.d];
|
||||
x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(12));
|
||||
x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 12));
|
||||
x[r.a] +%= x[r.b];
|
||||
x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(8));
|
||||
x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 8));
|
||||
x[r.c] +%= x[r.d];
|
||||
x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(7));
|
||||
x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 7));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,9 @@ pub const State = struct {
|
||||
|
||||
pub fn permute(self: *Self) void {
|
||||
const state = &self.data;
|
||||
var round = u32(24);
|
||||
var round = @as(u32, 24);
|
||||
while (round > 0) : (round -= 1) {
|
||||
var column = usize(0);
|
||||
var column = @as(usize, 0);
|
||||
while (column < 4) : (column += 1) {
|
||||
const x = math.rotl(u32, state[column], 24);
|
||||
const y = math.rotl(u32, state[4 + column], 9);
|
||||
@ -61,7 +61,7 @@ pub const State = struct {
|
||||
}
|
||||
|
||||
pub fn squeeze(self: *Self, out: []u8) void {
|
||||
var i = usize(0);
|
||||
var i = @as(usize, 0);
|
||||
while (i + RATE <= out.len) : (i += RATE) {
|
||||
self.permute();
|
||||
mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]);
|
||||
@ -79,7 +79,7 @@ test "permute" {
|
||||
var state = State{
|
||||
.data = blk: {
|
||||
var input: [12]u32 = undefined;
|
||||
var i = u32(0);
|
||||
var i = @as(u32, 0);
|
||||
while (i < 12) : (i += 1) {
|
||||
input[i] = i * i * i + i *% 0x9e3779b9;
|
||||
}
|
||||
|
@ -126,10 +126,10 @@ pub const Md5 = struct {
|
||||
while (i < 16) : (i += 1) {
|
||||
// NOTE: Performing or's separately improves perf by ~10%
|
||||
s[i] = 0;
|
||||
s[i] |= u32(b[i * 4 + 0]);
|
||||
s[i] |= u32(b[i * 4 + 1]) << 8;
|
||||
s[i] |= u32(b[i * 4 + 2]) << 16;
|
||||
s[i] |= u32(b[i * 4 + 3]) << 24;
|
||||
s[i] |= @as(u32, b[i * 4 + 0]);
|
||||
s[i] |= @as(u32, b[i * 4 + 1]) << 8;
|
||||
s[i] |= @as(u32, b[i * 4 + 2]) << 16;
|
||||
s[i] |= @as(u32, b[i * 4 + 3]) << 24;
|
||||
}
|
||||
|
||||
var v: [4]u32 = [_]u32{
|
||||
|
@ -87,11 +87,11 @@ pub const Poly1305 = struct {
|
||||
// ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff
|
||||
fn polyBlock(ctx: *Self) void {
|
||||
// s = h + c, without carry propagation
|
||||
const s0 = u64(ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
|
||||
const s1 = u64(ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
|
||||
const s2 = u64(ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
|
||||
const s3 = u64(ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
|
||||
const s4 = u64(ctx.h[4]) + ctx.c[4]; // s4 <= 5
|
||||
const s0 = @as(u64, ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
|
||||
const s1 = @as(u64, ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
|
||||
const s2 = @as(u64, ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
|
||||
const s3 = @as(u64, ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
|
||||
const s4 = @as(u64, ctx.h[4]) + ctx.c[4]; // s4 <= 5
|
||||
|
||||
// Local all the things!
|
||||
const r0 = ctx.r[0]; // r0 <= 0fffffff
|
||||
@ -197,7 +197,7 @@ pub const Poly1305 = struct {
|
||||
|
||||
// check if we should subtract 2^130-5 by performing the
|
||||
// corresponding carry propagation.
|
||||
const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004
|
||||
const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004
|
||||
const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000
|
||||
const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000
|
||||
const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000
|
||||
|
@ -146,10 +146,10 @@ pub const Sha1 = struct {
|
||||
Rp(0, 1, 2, 3, 4, 15),
|
||||
};
|
||||
inline for (round0a) |r| {
|
||||
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);
|
||||
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);
|
||||
|
||||
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]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
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]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
|
||||
}
|
||||
|
||||
const round0b = comptime [_]RoundParam{
|
||||
@ -160,10 +160,10 @@ pub const Sha1 = struct {
|
||||
};
|
||||
inline for (round0b) |r| {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
|
||||
|
||||
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]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
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]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
|
||||
}
|
||||
|
||||
const round1 = comptime [_]RoundParam{
|
||||
@ -190,10 +190,10 @@ pub const Sha1 = struct {
|
||||
};
|
||||
inline for (round1) |r| {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
|
||||
|
||||
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]);
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
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]);
|
||||
v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
|
||||
}
|
||||
|
||||
const round2 = comptime [_]RoundParam{
|
||||
@ -220,10 +220,10 @@ pub const Sha1 = struct {
|
||||
};
|
||||
inline for (round2) |r| {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
|
||||
|
||||
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]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
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]));
|
||||
v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
|
||||
}
|
||||
|
||||
const round3 = comptime [_]RoundParam{
|
||||
@ -250,10 +250,10 @@ pub const Sha1 = struct {
|
||||
};
|
||||
inline for (round3) |r| {
|
||||
const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
|
||||
s[r.i & 0xf] = math.rotl(u32, t, u32(1));
|
||||
s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
|
||||
|
||||
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]);
|
||||
v[r.b] = math.rotl(u32, v[r.b], u32(30));
|
||||
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]);
|
||||
v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
|
||||
}
|
||||
|
||||
d.s[0] +%= v[0];
|
||||
|
@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type {
|
||||
var i: usize = 0;
|
||||
while (i < 16) : (i += 1) {
|
||||
s[i] = 0;
|
||||
s[i] |= u32(b[i * 4 + 0]) << 24;
|
||||
s[i] |= u32(b[i * 4 + 1]) << 16;
|
||||
s[i] |= u32(b[i * 4 + 2]) << 8;
|
||||
s[i] |= u32(b[i * 4 + 3]) << 0;
|
||||
s[i] |= @as(u32, b[i * 4 + 0]) << 24;
|
||||
s[i] |= @as(u32, b[i * 4 + 1]) << 16;
|
||||
s[i] |= @as(u32, b[i * 4 + 2]) << 8;
|
||||
s[i] |= @as(u32, b[i * 4 + 3]) << 0;
|
||||
}
|
||||
while (i < 64) : (i += 1) {
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
var v: [8]u32 = [_]u32{
|
||||
@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type {
|
||||
Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2),
|
||||
};
|
||||
inline for (round0) |r| {
|
||||
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];
|
||||
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];
|
||||
|
||||
v[r.d] = v[r.d] +% v[r.h];
|
||||
|
||||
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]));
|
||||
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]));
|
||||
}
|
||||
|
||||
d.s[0] +%= v[0];
|
||||
@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type {
|
||||
var i: usize = 0;
|
||||
while (i < 16) : (i += 1) {
|
||||
s[i] = 0;
|
||||
s[i] |= u64(b[i * 8 + 0]) << 56;
|
||||
s[i] |= u64(b[i * 8 + 1]) << 48;
|
||||
s[i] |= u64(b[i * 8 + 2]) << 40;
|
||||
s[i] |= u64(b[i * 8 + 3]) << 32;
|
||||
s[i] |= u64(b[i * 8 + 4]) << 24;
|
||||
s[i] |= u64(b[i * 8 + 5]) << 16;
|
||||
s[i] |= u64(b[i * 8 + 6]) << 8;
|
||||
s[i] |= u64(b[i * 8 + 7]) << 0;
|
||||
s[i] |= @as(u64, b[i * 8 + 0]) << 56;
|
||||
s[i] |= @as(u64, b[i * 8 + 1]) << 48;
|
||||
s[i] |= @as(u64, b[i * 8 + 2]) << 40;
|
||||
s[i] |= @as(u64, b[i * 8 + 3]) << 32;
|
||||
s[i] |= @as(u64, b[i * 8 + 4]) << 24;
|
||||
s[i] |= @as(u64, b[i * 8 + 5]) << 16;
|
||||
s[i] |= @as(u64, b[i * 8 + 6]) << 8;
|
||||
s[i] |= @as(u64, b[i * 8 + 7]) << 0;
|
||||
}
|
||||
while (i < 80) : (i += 1) {
|
||||
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));
|
||||
s[i] = s[i - 16] +% s[i - 7] +%
|
||||
(math.rotr(u64, s[i - 15], @as(u64, 1)) ^ math.rotr(u64, s[i - 15], @as(u64, 8)) ^ (s[i - 15] >> 7)) +%
|
||||
(math.rotr(u64, s[i - 2], @as(u64, 19)) ^ math.rotr(u64, s[i - 2], @as(u64, 61)) ^ (s[i - 2] >> 6));
|
||||
}
|
||||
|
||||
var v: [8]u64 = [_]u64{
|
||||
@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type {
|
||||
Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817),
|
||||
};
|
||||
inline for (round0) |r| {
|
||||
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];
|
||||
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];
|
||||
|
||||
v[r.d] = v[r.d] +% v[r.h];
|
||||
|
||||
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]));
|
||||
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]));
|
||||
}
|
||||
|
||||
d.s[0] +%= v[0];
|
||||
|
@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
|
||||
}
|
||||
x = 0;
|
||||
inline while (x < 5) : (x += 1) {
|
||||
t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], usize(1));
|
||||
t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], @as(usize, 1));
|
||||
y = 0;
|
||||
inline while (y < 5) : (y += 1) {
|
||||
s[x + y * 5] ^= t[0];
|
||||
|
@ -256,15 +256,15 @@ const Fe = struct {
|
||||
var t: [10]i64 = undefined;
|
||||
|
||||
t[0] = readIntSliceLittle(u32, s[0..4]);
|
||||
t[1] = u32(readIntSliceLittle(u24, s[4..7])) << 6;
|
||||
t[2] = u32(readIntSliceLittle(u24, s[7..10])) << 5;
|
||||
t[3] = u32(readIntSliceLittle(u24, s[10..13])) << 3;
|
||||
t[4] = u32(readIntSliceLittle(u24, s[13..16])) << 2;
|
||||
t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6;
|
||||
t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5;
|
||||
t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3;
|
||||
t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2;
|
||||
t[5] = readIntSliceLittle(u32, s[16..20]);
|
||||
t[6] = u32(readIntSliceLittle(u24, s[20..23])) << 7;
|
||||
t[7] = u32(readIntSliceLittle(u24, s[23..26])) << 5;
|
||||
t[8] = u32(readIntSliceLittle(u24, s[26..29])) << 4;
|
||||
t[9] = (u32(readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
|
||||
t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7;
|
||||
t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5;
|
||||
t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4;
|
||||
t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
|
||||
|
||||
carry1(h, t[0..]);
|
||||
}
|
||||
@ -500,7 +500,7 @@ const Fe = struct {
|
||||
if (i + 1 < 10) {
|
||||
t[i + 1] += c[i];
|
||||
}
|
||||
t[i] -= c[i] * (i32(1) << shift);
|
||||
t[i] -= c[i] * (@as(i32, 1) << shift);
|
||||
}
|
||||
|
||||
fn toBytes(s: []u8, h: *const Fe) void {
|
||||
@ -511,7 +511,7 @@ const Fe = struct {
|
||||
t[i] = h.b[i];
|
||||
}
|
||||
|
||||
var q = (19 * t[9] + ((i32(1) << 24))) >> 25;
|
||||
var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25;
|
||||
{
|
||||
var i: usize = 0;
|
||||
while (i < 5) : (i += 1) {
|
||||
|
@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
|
||||
const word = try stream.readIntLittle(u32);
|
||||
var bit_i: u5 = 0;
|
||||
while (true) : (bit_i += 1) {
|
||||
if (word & (u32(1) << bit_i) != 0) {
|
||||
if (word & (@as(u32, 1) << bit_i) != 0) {
|
||||
try list.append(word_i * 32 + bit_i);
|
||||
}
|
||||
if (bit_i == maxInt(u5)) break;
|
||||
@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
|
||||
|
||||
// TODO the noasyncs here are workarounds
|
||||
fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 {
|
||||
return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32));
|
||||
return if (is_64) try noasync in_stream.readIntLittle(u64) else @as(u64, try noasync in_stream.readIntLittle(u32));
|
||||
}
|
||||
|
||||
// TODO the noasyncs here are workarounds
|
||||
fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
|
||||
if (@sizeOf(usize) == 4) {
|
||||
return u64(try noasync in_stream.readIntLittle(u32));
|
||||
// TODO this cast should not be needed
|
||||
return @as(u64, try noasync in_stream.readIntLittle(u32));
|
||||
} else if (@sizeOf(usize) == 8) {
|
||||
return noasync in_stream.readIntLittle(u64);
|
||||
} else {
|
||||
@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
|
||||
// special opcodes
|
||||
const adjusted_opcode = opcode - opcode_base;
|
||||
const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
|
||||
const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);
|
||||
const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
|
||||
prog.line += inc_line;
|
||||
prog.address += inc_addr;
|
||||
if (try prog.checkLineMatch()) |info| return info;
|
||||
@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
|
||||
if (unit_length == 0) {
|
||||
return error.MissingDebugInfo;
|
||||
}
|
||||
const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
|
||||
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
|
||||
|
||||
const version = try di.dwarf_in_stream.readInt(u16, di.endian);
|
||||
// TODO support 3 and 5
|
||||
@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
|
||||
// special opcodes
|
||||
const adjusted_opcode = opcode - opcode_base;
|
||||
const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
|
||||
const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);
|
||||
const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
|
||||
prog.line += inc_line;
|
||||
prog.address += inc_addr;
|
||||
if (try prog.checkLineMatch()) |info| return info;
|
||||
@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {
|
||||
var is_64: bool = undefined;
|
||||
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
|
||||
if (unit_length == 0) return;
|
||||
const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
|
||||
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
|
||||
|
||||
const version = try di.dwarf_in_stream.readInt(u16, di.endian);
|
||||
if (version < 2 or version > 5) return error.InvalidDebugInfo;
|
||||
@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void {
|
||||
var is_64: bool = undefined;
|
||||
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
|
||||
if (unit_length == 0) return;
|
||||
const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
|
||||
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
|
||||
|
||||
const version = try di.dwarf_in_stream.readInt(u16, di.endian);
|
||||
if (version < 2 or version > 5) return error.InvalidDebugInfo;
|
||||
@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {
|
||||
} else {
|
||||
if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
|
||||
ptr.* += 4;
|
||||
return u64(first_32_bits);
|
||||
// TODO this cast should not be needed
|
||||
return @as(u64, first_32_bits);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool)
|
||||
return in_stream.readIntLittle(u64);
|
||||
} else {
|
||||
if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
|
||||
return u64(first_32_bits);
|
||||
// TODO this cast should not be needed
|
||||
return @as(u64, first_32_bits);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
|
||||
var shift: usize = 0;
|
||||
|
||||
while (true) {
|
||||
const byte = u8(try in_stream.readByte());
|
||||
const byte: u8 = try in_stream.readByte();
|
||||
|
||||
if (shift > T.bit_count)
|
||||
return error.Overflow;
|
||||
|
||||
var operand: UT = undefined;
|
||||
if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
|
||||
if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
|
||||
if (byte != 0x7f)
|
||||
return error.Overflow;
|
||||
}
|
||||
|
@ -215,8 +215,8 @@ pub const ElfLib = struct {
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < self.hashtab[1]) : (i += 1) {
|
||||
if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
|
||||
if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
|
||||
if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
|
||||
if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
|
||||
if (0 == self.syms[i].st_shndx) continue;
|
||||
if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
|
||||
if (maybe_versym) |versym| {
|
||||
|
@ -441,9 +441,9 @@ pub const Elf = struct {
|
||||
elf.program_header_offset = try in.readInt(u64, elf.endian);
|
||||
elf.section_header_offset = try in.readInt(u64, elf.endian);
|
||||
} else {
|
||||
elf.entry_addr = u64(try in.readInt(u32, elf.endian));
|
||||
elf.program_header_offset = u64(try in.readInt(u32, elf.endian));
|
||||
elf.section_header_offset = u64(try in.readInt(u32, elf.endian));
|
||||
elf.entry_addr = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf.program_header_offset = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf.section_header_offset = @as(u64, try in.readInt(u32, elf.endian));
|
||||
}
|
||||
|
||||
// skip over flags
|
||||
@ -458,13 +458,13 @@ pub const Elf = struct {
|
||||
const ph_entry_count = try in.readInt(u16, elf.endian);
|
||||
const sh_entry_size = try in.readInt(u16, elf.endian);
|
||||
const sh_entry_count = try in.readInt(u16, elf.endian);
|
||||
elf.string_section_index = usize(try in.readInt(u16, elf.endian));
|
||||
elf.string_section_index = @as(usize, try in.readInt(u16, elf.endian));
|
||||
|
||||
if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat;
|
||||
|
||||
const sh_byte_count = u64(sh_entry_size) * u64(sh_entry_count);
|
||||
const sh_byte_count = @as(u64, sh_entry_size) * @as(u64, sh_entry_count);
|
||||
const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count);
|
||||
const ph_byte_count = u64(ph_entry_size) * u64(ph_entry_count);
|
||||
const ph_byte_count = @as(u64, ph_entry_size) * @as(u64, ph_entry_count);
|
||||
const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count);
|
||||
|
||||
const stream_end = try seekable_stream.getEndPos();
|
||||
@ -499,14 +499,14 @@ pub const Elf = struct {
|
||||
// TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ?
|
||||
elf_section.name = try in.readInt(u32, elf.endian);
|
||||
elf_section.sh_type = try in.readInt(u32, elf.endian);
|
||||
elf_section.flags = u64(try in.readInt(u32, elf.endian));
|
||||
elf_section.addr = u64(try in.readInt(u32, elf.endian));
|
||||
elf_section.offset = u64(try in.readInt(u32, elf.endian));
|
||||
elf_section.size = u64(try in.readInt(u32, elf.endian));
|
||||
elf_section.flags = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf_section.addr = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf_section.offset = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf_section.size = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf_section.link = try in.readInt(u32, elf.endian);
|
||||
elf_section.info = try in.readInt(u32, elf.endian);
|
||||
elf_section.addr_align = u64(try in.readInt(u32, elf.endian));
|
||||
elf_section.ent_size = u64(try in.readInt(u32, elf.endian));
|
||||
elf_section.addr_align = @as(u64, try in.readInt(u32, elf.endian));
|
||||
elf_section.ent_size = @as(u64, try in.readInt(u32, elf.endian));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize {
|
||||
windows.ERROR.IO_PENDING => unreachable,
|
||||
windows.ERROR.OPERATION_ABORTED => return error.OperationAborted,
|
||||
windows.ERROR.BROKEN_PIPE => return error.BrokenPipe,
|
||||
windows.ERROR.HANDLE_EOF => return usize(bytes_transferred),
|
||||
windows.ERROR.HANDLE_EOF => return @as(usize, bytes_transferred),
|
||||
else => |err| return windows.unexpectedError(err),
|
||||
}
|
||||
}
|
||||
return usize(bytes_transferred);
|
||||
return @as(usize, bytes_transferred);
|
||||
}
|
||||
|
||||
/// iovecs must live until preadv frame completes
|
||||
|
@ -257,7 +257,7 @@ test "ByteFifo" {
|
||||
defer fifo.deinit();
|
||||
|
||||
try fifo.write("HELLO");
|
||||
testing.expectEqual(usize(5), fifo.readableLength());
|
||||
testing.expectEqual(@as(usize, 5), fifo.readableLength());
|
||||
testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
|
||||
|
||||
{
|
||||
@ -265,34 +265,34 @@ test "ByteFifo" {
|
||||
while (i < 5) : (i += 1) {
|
||||
try fifo.write([_]u8{try fifo.peekItem(i)});
|
||||
}
|
||||
testing.expectEqual(usize(10), fifo.readableLength());
|
||||
testing.expectEqual(@as(usize, 10), fifo.readableLength());
|
||||
testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
|
||||
}
|
||||
|
||||
{
|
||||
testing.expectEqual(u8('H'), try fifo.readItem());
|
||||
testing.expectEqual(u8('E'), try fifo.readItem());
|
||||
testing.expectEqual(u8('L'), try fifo.readItem());
|
||||
testing.expectEqual(u8('L'), try fifo.readItem());
|
||||
testing.expectEqual(u8('O'), try fifo.readItem());
|
||||
testing.expectEqual(@as(u8, 'H'), try fifo.readItem());
|
||||
testing.expectEqual(@as(u8, 'E'), try fifo.readItem());
|
||||
testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
|
||||
testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
|
||||
testing.expectEqual(@as(u8, 'O'), try fifo.readItem());
|
||||
}
|
||||
testing.expectEqual(usize(5), fifo.readableLength());
|
||||
testing.expectEqual(@as(usize, 5), fifo.readableLength());
|
||||
|
||||
{ // Writes that wrap around
|
||||
testing.expectEqual(usize(11), fifo.writableLength());
|
||||
testing.expectEqual(usize(6), fifo.writableSlice(0).len);
|
||||
testing.expectEqual(@as(usize, 11), fifo.writableLength());
|
||||
testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
|
||||
fifo.writeAssumeCapacity("6<chars<11");
|
||||
testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
|
||||
testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
|
||||
fifo.discard(11);
|
||||
testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
|
||||
fifo.discard(4);
|
||||
testing.expectEqual(usize(0), fifo.readableLength());
|
||||
testing.expectEqual(@as(usize, 0), fifo.readableLength());
|
||||
}
|
||||
|
||||
{
|
||||
const buf = try fifo.writeableWithSize(12);
|
||||
testing.expectEqual(usize(12), buf.len);
|
||||
testing.expectEqual(@as(usize, 12), buf.len);
|
||||
var i: u8 = 0;
|
||||
while (i < 10) : (i += 1) {
|
||||
buf[i] = i + 'a';
|
||||
@ -313,6 +313,6 @@ test "ByteFifo" {
|
||||
try fifo.print("{}, {}!", "Hello", "World");
|
||||
var result: [30]u8 = undefined;
|
||||
testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result));
|
||||
testing.expectEqual(usize(0), fifo.readableLength());
|
||||
testing.expectEqual(@as(usize, 0), fifo.readableLength());
|
||||
}
|
||||
}
|
||||
|
102
lib/std/fmt.zig
102
lib/std/fmt.zig
@ -512,7 +512,7 @@ pub fn formatIntValue(
|
||||
uppercase = false;
|
||||
} else if (comptime std.mem.eql(u8, fmt, "c")) {
|
||||
if (@typeOf(int_value).bit_count <= 8) {
|
||||
return formatAsciiChar(u8(int_value), options, context, Errors, output);
|
||||
return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
|
||||
} else {
|
||||
@compileError("Cannot print integer that is larger than 8 bits as a ascii");
|
||||
}
|
||||
@ -594,7 +594,7 @@ pub fn formatBuf(
|
||||
var leftover_padding = if (width > buf.len) (width - buf.len) else return;
|
||||
const pad_byte: u8 = options.fill;
|
||||
while (leftover_padding > 0) : (leftover_padding -= 1) {
|
||||
try output(context, (*const [1]u8)(&pad_byte)[0..1]);
|
||||
try output(context, @as(*const [1]u8, &pad_byte)[0..1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -668,7 +668,7 @@ pub fn formatFloatScientific(
|
||||
try output(context, float_decimal.digits[0..1]);
|
||||
try output(context, ".");
|
||||
if (float_decimal.digits.len > 1) {
|
||||
const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len;
|
||||
const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
|
||||
|
||||
try output(context, float_decimal.digits[1..num_digits]);
|
||||
} else {
|
||||
@ -703,7 +703,7 @@ pub fn formatFloatDecimal(
|
||||
comptime Errors: type,
|
||||
output: fn (@typeOf(context), []const u8) Errors!void,
|
||||
) Errors!void {
|
||||
var x = f64(value);
|
||||
var x = @as(f64, value);
|
||||
|
||||
// Errol doesn't handle these special cases.
|
||||
if (math.signbit(x)) {
|
||||
@ -921,14 +921,14 @@ fn formatIntSigned(
|
||||
const uint = @IntType(false, @typeOf(value).bit_count);
|
||||
if (value < 0) {
|
||||
const minus_sign: u8 = '-';
|
||||
try output(context, (*const [1]u8)(&minus_sign)[0..]);
|
||||
try output(context, @as(*const [1]u8, &minus_sign)[0..]);
|
||||
const new_value = @intCast(uint, -(value + 1)) + 1;
|
||||
return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
|
||||
} else if (options.width == null or options.width.? == 0) {
|
||||
return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);
|
||||
} else {
|
||||
const plus_sign: u8 = '+';
|
||||
try output(context, (*const [1]u8)(&plus_sign)[0..]);
|
||||
try output(context, @as(*const [1]u8, &plus_sign)[0..]);
|
||||
const new_value = @intCast(uint, value);
|
||||
return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
|
||||
}
|
||||
@ -966,7 +966,7 @@ fn formatIntUnsigned(
|
||||
const zero_byte: u8 = options.fill;
|
||||
var leftover_padding = padding - index;
|
||||
while (true) {
|
||||
try output(context, (*const [1]u8)(&zero_byte)[0..]);
|
||||
try output(context, @as(*const [1]u8, &zero_byte)[0..]);
|
||||
leftover_padding -= 1;
|
||||
if (leftover_padding == 0) break;
|
||||
}
|
||||
@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
|
||||
fn digitToChar(digit: u8, uppercase: bool) u8 {
|
||||
return switch (digit) {
|
||||
0...9 => digit + '0',
|
||||
10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
|
||||
10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10),
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
|
||||
test "bufPrintInt" {
|
||||
var buffer: [100]u8 = undefined;
|
||||
const buf = buffer[0..];
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, FormatOptions{}), "-BC614E"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E"));
|
||||
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, FormatOptions{}), "12345678"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678"));
|
||||
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, FormatOptions{ .width = 6 }), " 666"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
|
||||
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, FormatOptions{ .width = 3 }), "+42"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, FormatOptions{ .width = 3 }), "-42"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42"));
|
||||
testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
|
||||
}
|
||||
|
||||
fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
|
||||
@ -1208,8 +1208,8 @@ test "int.specifier" {
|
||||
}
|
||||
|
||||
test "int.padded" {
|
||||
try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1));
|
||||
try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", u8(1));
|
||||
try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));
|
||||
try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));
|
||||
}
|
||||
|
||||
test "buffer" {
|
||||
@ -1287,8 +1287,8 @@ test "filesize" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024));
|
||||
try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", usize(63 * 1024 * 1024));
|
||||
try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024));
|
||||
try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024));
|
||||
}
|
||||
|
||||
test "struct" {
|
||||
@ -1327,8 +1327,8 @@ test "float.scientific" {
|
||||
}
|
||||
try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));
|
||||
try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));
|
||||
try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10));
|
||||
try testFmt("f64: 9.99996e-40", "f64: {e}", f64(9.999960e-40));
|
||||
try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
|
||||
try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
|
||||
}
|
||||
|
||||
test "float.scientific.precision" {
|
||||
@ -1336,12 +1336,12 @@ test "float.scientific.precision" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42));
|
||||
try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563))));
|
||||
try testFmt("f64: 7.81250e-03", "f64: {e:.5}", f64(@bitCast(f32, u32(1006632960))));
|
||||
try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42));
|
||||
try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563))));
|
||||
try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));
|
||||
// libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
|
||||
// In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
|
||||
try testFmt("f64: 1.00001e+05", "f64: {e:.5}", f64(@bitCast(f32, u32(1203982400))));
|
||||
try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400))));
|
||||
}
|
||||
|
||||
test "float.special" {
|
||||
@ -1364,21 +1364,21 @@ test "float.decimal" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29));
|
||||
try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
|
||||
try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));
|
||||
try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));
|
||||
// -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
|
||||
// -11.12339... is rounded back up to -11.1234
|
||||
try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));
|
||||
try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));
|
||||
try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0));
|
||||
try testFmt("f64: 6", "f64: {d:.0}", f64(5.700));
|
||||
try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999));
|
||||
try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0));
|
||||
try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", f64(9.999960e-40));
|
||||
try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
|
||||
try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
|
||||
try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));
|
||||
try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));
|
||||
try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));
|
||||
}
|
||||
|
||||
test "float.libc.sanity" {
|
||||
@ -1386,22 +1386,22 @@ test "float.libc.sanity" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781))));
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389))));
|
||||
try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278))));
|
||||
try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133))));
|
||||
try testFmt("f64: 10.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1092616192))));
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781))));
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389))));
|
||||
try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278))));
|
||||
try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));
|
||||
try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));
|
||||
|
||||
// libc differences
|
||||
//
|
||||
// This is 0.015625 exactly according to gdb. We thus round down,
|
||||
// however glibc rounds up for some reason. This occurs for all
|
||||
// floats of the form x.yyyy25 on a precision point.
|
||||
try testFmt("f64: 0.01563", "f64: {d:.5}", f64(@bitCast(f32, u32(1015021568))));
|
||||
try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568))));
|
||||
// errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
|
||||
// also rounds to 630 so I'm inclined to believe libc is not
|
||||
// optimal here.
|
||||
try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1518338049))));
|
||||
try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049))));
|
||||
}
|
||||
|
||||
test "custom" {
|
||||
@ -1677,17 +1677,17 @@ test "formatType max_depth" {
|
||||
}
|
||||
|
||||
test "positional" {
|
||||
try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2));
|
||||
try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2));
|
||||
try testFmt("0 0", "{0} {0}", usize(0));
|
||||
try testFmt("0 1", "{} {1}", usize(0), usize(1));
|
||||
try testFmt("1 0 0 1", "{1} {} {0} {}", usize(0), usize(1));
|
||||
try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
|
||||
try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
|
||||
try testFmt("0 0", "{0} {0}", @as(usize, 0));
|
||||
try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));
|
||||
try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));
|
||||
}
|
||||
|
||||
test "positional with specifier" {
|
||||
try testFmt("10.0", "{0d:.1}", f64(9.999));
|
||||
try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
|
||||
}
|
||||
|
||||
test "positional/alignment/width/precision" {
|
||||
try testFmt("10.0", "{0d: >3.1}", f64(9.999));
|
||||
try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void {
|
||||
/// @buf: The output buffer.
|
||||
/// &return: The exponent.
|
||||
fn errolInt(val: f64, buffer: []u8) FloatDecimal {
|
||||
const pow19 = u128(1e19);
|
||||
const pow19 = @as(u128, 1e19);
|
||||
|
||||
assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
|
||||
|
||||
@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 {
|
||||
const bits = @bitCast(u64, from);
|
||||
assert((bits & ((1 << 52) - 1)) == 0);
|
||||
|
||||
return u128(1) << @truncate(u7, (bits >> 52) -% 1023);
|
||||
return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023);
|
||||
}
|
||||
|
||||
/// Given two different integers with the same length in terms of the number
|
||||
|
@ -59,29 +59,29 @@ const Z96 = struct {
|
||||
|
||||
// d += s
|
||||
inline fn add(d: *Z96, s: Z96) void {
|
||||
var w = u64(d.d0) + u64(s.d0);
|
||||
var w = @as(u64, d.d0) + @as(u64, s.d0);
|
||||
d.d0 = @truncate(u32, w);
|
||||
|
||||
w >>= 32;
|
||||
w += u64(d.d1) + u64(s.d1);
|
||||
w += @as(u64, d.d1) + @as(u64, s.d1);
|
||||
d.d1 = @truncate(u32, w);
|
||||
|
||||
w >>= 32;
|
||||
w += u64(d.d2) + u64(s.d2);
|
||||
w += @as(u64, d.d2) + @as(u64, s.d2);
|
||||
d.d2 = @truncate(u32, w);
|
||||
}
|
||||
|
||||
// d -= s
|
||||
inline fn sub(d: *Z96, s: Z96) void {
|
||||
var w = u64(d.d0) -% u64(s.d0);
|
||||
var w = @as(u64, d.d0) -% @as(u64, s.d0);
|
||||
d.d0 = @truncate(u32, w);
|
||||
|
||||
w >>= 32;
|
||||
w += u64(d.d1) -% u64(s.d1);
|
||||
w += @as(u64, d.d1) -% @as(u64, s.d1);
|
||||
d.d1 = @truncate(u32, w);
|
||||
|
||||
w >>= 32;
|
||||
w += u64(d.d2) -% u64(s.d2);
|
||||
w += @as(u64, d.d2) -% @as(u64, s.d2);
|
||||
d.d2 = @truncate(u32, w);
|
||||
}
|
||||
};
|
||||
@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {
|
||||
break :blk if (n.negative) f64_minus_zero else f64_plus_zero;
|
||||
} else if (s.d2 != 0) {
|
||||
const binexs2 = @intCast(u64, binary_exponent) << 52;
|
||||
const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2;
|
||||
const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2;
|
||||
break :blk if (n.negative) rr | (1 << 63) else rr;
|
||||
} else {
|
||||
break :blk 0;
|
||||
|
@ -272,9 +272,9 @@ pub const File = struct {
|
||||
return Stat{
|
||||
.size = @bitCast(u64, st.size),
|
||||
.mode = st.mode,
|
||||
.atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
|
||||
.mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
|
||||
.ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
|
||||
.atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
|
||||
.mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
|
||||
.ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ test "hash struct deep" {
|
||||
test "testHash optional" {
|
||||
const a: ?u32 = 123;
|
||||
const b: ?u32 = null;
|
||||
testing.expectEqual(testHash(a), testHash(u32(123)));
|
||||
testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
|
||||
testing.expect(testHash(a) != testHash(b));
|
||||
testing.expectEqual(testHash(b), 0);
|
||||
}
|
||||
@ -315,9 +315,9 @@ test "testHash array" {
|
||||
const a = [_]u32{ 1, 2, 3 };
|
||||
const h = testHash(a);
|
||||
var hasher = Wyhash.init(0);
|
||||
autoHash(&hasher, u32(1));
|
||||
autoHash(&hasher, u32(2));
|
||||
autoHash(&hasher, u32(3));
|
||||
autoHash(&hasher, @as(u32, 1));
|
||||
autoHash(&hasher, @as(u32, 2));
|
||||
autoHash(&hasher, @as(u32, 3));
|
||||
testing.expectEqual(h, hasher.final());
|
||||
}
|
||||
|
||||
@ -330,9 +330,9 @@ test "testHash struct" {
|
||||
const f = Foo{};
|
||||
const h = testHash(f);
|
||||
var hasher = Wyhash.init(0);
|
||||
autoHash(&hasher, u32(1));
|
||||
autoHash(&hasher, u32(2));
|
||||
autoHash(&hasher, u32(3));
|
||||
autoHash(&hasher, @as(u32, 1));
|
||||
autoHash(&hasher, @as(u32, 2));
|
||||
autoHash(&hasher, @as(u32, 3));
|
||||
testing.expectEqual(h, hasher.final());
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ pub const CityHash64 = struct {
|
||||
}
|
||||
|
||||
fn hashLen0To16(str: []const u8) u64 {
|
||||
const len: u64 = u64(str.len);
|
||||
const len: u64 = @as(u64, str.len);
|
||||
if (len >= 8) {
|
||||
const mul: u64 = k2 +% len *% 2;
|
||||
const a: u64 = fetch64(str.ptr) +% k2;
|
||||
@ -240,7 +240,7 @@ pub const CityHash64 = struct {
|
||||
}
|
||||
|
||||
fn hashLen17To32(str: []const u8) u64 {
|
||||
const len: u64 = u64(str.len);
|
||||
const len: u64 = @as(u64, str.len);
|
||||
const mul: u64 = k2 +% len *% 2;
|
||||
const a: u64 = fetch64(str.ptr) *% k1;
|
||||
const b: u64 = fetch64(str.ptr + 8);
|
||||
@ -251,7 +251,7 @@ pub const CityHash64 = struct {
|
||||
}
|
||||
|
||||
fn hashLen33To64(str: []const u8) u64 {
|
||||
const len: u64 = u64(str.len);
|
||||
const len: u64 = @as(u64, str.len);
|
||||
const mul: u64 = k2 +% len *% 2;
|
||||
const a: u64 = fetch64(str.ptr) *% k2;
|
||||
const b: u64 = fetch64(str.ptr + 8);
|
||||
@ -305,7 +305,7 @@ pub const CityHash64 = struct {
|
||||
return hashLen33To64(str);
|
||||
}
|
||||
|
||||
var len: u64 = u64(str.len);
|
||||
var len: u64 = @as(u64, str.len);
|
||||
|
||||
var x: u64 = fetch64(str.ptr + str.len - 40);
|
||||
var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56);
|
||||
|
@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
|
||||
const p = input[i .. i + 8];
|
||||
|
||||
// Unrolling this way gives ~50Mb/s increase
|
||||
self.crc ^= (u32(p[0]) << 0);
|
||||
self.crc ^= (u32(p[1]) << 8);
|
||||
self.crc ^= (u32(p[2]) << 16);
|
||||
self.crc ^= (u32(p[3]) << 24);
|
||||
self.crc ^= (@as(u32, p[0]) << 0);
|
||||
self.crc ^= (@as(u32, p[1]) << 8);
|
||||
self.crc ^= (@as(u32, p[2]) << 16);
|
||||
self.crc ^= (@as(u32, p[3]) << 24);
|
||||
|
||||
self.crc =
|
||||
lookup_tables[0][p[7]] ^
|
||||
|
@ -98,7 +98,7 @@ pub const Murmur2_64 = struct {
|
||||
|
||||
pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
|
||||
const m: u64 = 0xc6a4a7935bd1e995;
|
||||
const len = u64(str.len);
|
||||
const len = @as(u64, str.len);
|
||||
var h1: u64 = seed ^ (len *% m);
|
||||
for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
|
||||
var k1: u64 = v;
|
||||
|
@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
|
||||
}
|
||||
|
||||
const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3;
|
||||
return (u128(b2) << 64) | b1;
|
||||
return (@as(u128, b2) << 64) | b1;
|
||||
}
|
||||
|
||||
fn round(self: *Self, b: []const u8) void {
|
||||
@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
|
||||
|
||||
fn sipRound(d: *Self) void {
|
||||
d.v0 +%= d.v1;
|
||||
d.v1 = math.rotl(u64, d.v1, u64(13));
|
||||
d.v1 = math.rotl(u64, d.v1, @as(u64, 13));
|
||||
d.v1 ^= d.v0;
|
||||
d.v0 = math.rotl(u64, d.v0, u64(32));
|
||||
d.v0 = math.rotl(u64, d.v0, @as(u64, 32));
|
||||
d.v2 +%= d.v3;
|
||||
d.v3 = math.rotl(u64, d.v3, u64(16));
|
||||
d.v3 = math.rotl(u64, d.v3, @as(u64, 16));
|
||||
d.v3 ^= d.v2;
|
||||
d.v0 +%= d.v3;
|
||||
d.v3 = math.rotl(u64, d.v3, u64(21));
|
||||
d.v3 = math.rotl(u64, d.v3, @as(u64, 21));
|
||||
d.v3 ^= d.v0;
|
||||
d.v2 +%= d.v1;
|
||||
d.v1 = math.rotl(u64, d.v1, u64(17));
|
||||
d.v1 = math.rotl(u64, d.v1, @as(u64, 17));
|
||||
d.v1 ^= d.v2;
|
||||
d.v2 = math.rotl(u64, d.v2, u64(32));
|
||||
d.v2 = math.rotl(u64, d.v2, @as(u64, 32));
|
||||
}
|
||||
|
||||
pub fn hash(key: []const u8, input: []const u8) T {
|
||||
|
@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
|
||||
}
|
||||
|
||||
fn keyToIndex(hm: Self, key: K) usize {
|
||||
return hm.constrainIndex(usize(hash(key)));
|
||||
return hm.constrainIndex(@as(usize, hash(key)));
|
||||
}
|
||||
|
||||
fn constrainIndex(hm: Self, i: usize) usize {
|
||||
|
@ -896,7 +896,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
|
||||
const large_align = u29(mem.page_size << 2);
|
||||
|
||||
var align_mask: usize = undefined;
|
||||
_ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask);
|
||||
_ = @shlWithOverflow(usize, ~@as(usize, 0), USizeShift(@ctz(u29, large_align)), &align_mask);
|
||||
|
||||
var slice = try allocator.alignedAlloc(u8, large_align, 500);
|
||||
testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
|
||||
|
@ -399,7 +399,7 @@ test "Headers.iterator" {
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
testing.expectEqual(i32(2), count);
|
||||
testing.expectEqual(@as(i32, 2), count);
|
||||
}
|
||||
|
||||
test "Headers.contains" {
|
||||
@ -420,10 +420,10 @@ test "Headers.delete" {
|
||||
try h.append("cookie", "somevalue", null);
|
||||
|
||||
testing.expectEqual(false, h.delete("not-present"));
|
||||
testing.expectEqual(usize(3), h.count());
|
||||
testing.expectEqual(@as(usize, 3), h.count());
|
||||
|
||||
testing.expectEqual(true, h.delete("foo"));
|
||||
testing.expectEqual(usize(2), h.count());
|
||||
testing.expectEqual(@as(usize, 2), h.count());
|
||||
{
|
||||
const e = h.at(0);
|
||||
testing.expectEqualSlices(u8, "baz", e.name);
|
||||
@ -448,7 +448,7 @@ test "Headers.orderedRemove" {
|
||||
try h.append("cookie", "somevalue", null);
|
||||
|
||||
h.orderedRemove(0);
|
||||
testing.expectEqual(usize(2), h.count());
|
||||
testing.expectEqual(@as(usize, 2), h.count());
|
||||
{
|
||||
const e = h.at(0);
|
||||
testing.expectEqualSlices(u8, "baz", e.name);
|
||||
@ -471,7 +471,7 @@ test "Headers.swapRemove" {
|
||||
try h.append("cookie", "somevalue", null);
|
||||
|
||||
h.swapRemove(0);
|
||||
testing.expectEqual(usize(2), h.count());
|
||||
testing.expectEqual(@as(usize, 2), h.count());
|
||||
{
|
||||
const e = h.at(0);
|
||||
testing.expectEqualSlices(u8, "cookie", e.name);
|
||||
|
@ -353,7 +353,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
|
||||
const Buf = @IntType(false, buf_bit_count);
|
||||
const BufShift = math.Log2Int(Buf);
|
||||
|
||||
out_bits.* = usize(0);
|
||||
out_bits.* = @as(usize, 0);
|
||||
if (U == u0 or bits == 0) return 0;
|
||||
var out_buffer = Buf(0);
|
||||
|
||||
@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
|
||||
var self = @fieldParentPtr(Self, "stream", self_stream);
|
||||
|
||||
var out_bits: usize = undefined;
|
||||
var out_bits_total = usize(0);
|
||||
var out_bits_total = @as(usize, 0);
|
||||
//@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
|
||||
if (self.bit_count > 0) {
|
||||
for (buffer) |*b, i| {
|
||||
|
@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type {
|
||||
}
|
||||
|
||||
pub fn writeByte(self: *Self, byte: u8) Error!void {
|
||||
const slice = (*const [1]u8)(&byte)[0..];
|
||||
const slice = @as(*const [1]u8, &byte)[0..];
|
||||
return self.writeFn(self, slice);
|
||||
}
|
||||
|
||||
pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {
|
||||
const slice = (*const [1]u8)(&byte)[0..];
|
||||
const slice = @as(*const [1]u8, &byte)[0..];
|
||||
var i: usize = 0;
|
||||
while (i < n) : (i += 1) {
|
||||
try self.writeFn(self, slice);
|
||||
|
@ -228,8 +228,8 @@ test "BitOutStream" {
|
||||
|
||||
try bit_stream_be.writeBits(u2(1), 1);
|
||||
try bit_stream_be.writeBits(u5(2), 2);
|
||||
try bit_stream_be.writeBits(u128(3), 3);
|
||||
try bit_stream_be.writeBits(u8(4), 4);
|
||||
try bit_stream_be.writeBits(@as(u128, 3), 3);
|
||||
try bit_stream_be.writeBits(@as(u8, 4), 4);
|
||||
try bit_stream_be.writeBits(u9(5), 5);
|
||||
try bit_stream_be.writeBits(u1(1), 1);
|
||||
|
||||
@ -242,33 +242,33 @@ test "BitOutStream" {
|
||||
expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
|
||||
|
||||
mem_out_be.pos = 0;
|
||||
try bit_stream_be.writeBits(u32(0b110011010000101), 16);
|
||||
try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
|
||||
expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
|
||||
|
||||
try bit_stream_be.writeBits(u0(0), 0);
|
||||
try bit_stream_be.writeBits(@as(u0, 0), 0);
|
||||
|
||||
var mem_out_le = io.SliceOutStream.init(mem_le[0..]);
|
||||
var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream);
|
||||
|
||||
try bit_stream_le.writeBits(u2(1), 1);
|
||||
try bit_stream_le.writeBits(u5(2), 2);
|
||||
try bit_stream_le.writeBits(u128(3), 3);
|
||||
try bit_stream_le.writeBits(u8(4), 4);
|
||||
try bit_stream_le.writeBits(u9(5), 5);
|
||||
try bit_stream_le.writeBits(u1(1), 1);
|
||||
try bit_stream_le.writeBits(@as(u2, 1), 1);
|
||||
try bit_stream_le.writeBits(@as(u5, 2), 2);
|
||||
try bit_stream_le.writeBits(@as(u128, 3), 3);
|
||||
try bit_stream_le.writeBits(@as(u8, 4), 4);
|
||||
try bit_stream_le.writeBits(@as(u9, 5), 5);
|
||||
try bit_stream_le.writeBits(@as(u1, 1), 1);
|
||||
|
||||
expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
|
||||
|
||||
mem_out_le.pos = 0;
|
||||
try bit_stream_le.writeBits(u15(0b110011010000101), 15);
|
||||
try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
|
||||
try bit_stream_le.flushBits();
|
||||
expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
|
||||
|
||||
mem_out_le.pos = 0;
|
||||
try bit_stream_le.writeBits(u32(0b1100110100001011), 16);
|
||||
try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
|
||||
expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
|
||||
|
||||
try bit_stream_le.writeBits(u0(0), 0);
|
||||
try bit_stream_le.writeBits(@as(u0, 0), 0);
|
||||
}
|
||||
|
||||
test "BitStreams with File Stream" {
|
||||
@ -282,12 +282,12 @@ test "BitStreams with File Stream" {
|
||||
const OutError = File.WriteError;
|
||||
var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream);
|
||||
|
||||
try bit_stream.writeBits(u2(1), 1);
|
||||
try bit_stream.writeBits(u5(2), 2);
|
||||
try bit_stream.writeBits(u128(3), 3);
|
||||
try bit_stream.writeBits(u8(4), 4);
|
||||
try bit_stream.writeBits(u9(5), 5);
|
||||
try bit_stream.writeBits(u1(1), 1);
|
||||
try bit_stream.writeBits(@as(u2, 1), 1);
|
||||
try bit_stream.writeBits(@as(u5, 2), 2);
|
||||
try bit_stream.writeBits(@as(u128, 3), 3);
|
||||
try bit_stream.writeBits(@as(u8, 4), 4);
|
||||
try bit_stream.writeBits(@as(u9, 5), 5);
|
||||
try bit_stream.writeBits(@as(u1, 1), 1);
|
||||
try bit_stream.flushBits();
|
||||
}
|
||||
{
|
||||
@ -603,7 +603,7 @@ test "c out stream" {
|
||||
}
|
||||
|
||||
const out_stream = &io.COutStream.init(out_file).stream;
|
||||
try out_stream.print("hi: {}\n", i32(123));
|
||||
try out_stream.print("hi: {}\n", @as(i32, 123));
|
||||
}
|
||||
|
||||
test "File seek ops" {
|
||||
|
@ -1343,7 +1343,7 @@ test "write json then parse it" {
|
||||
try jw.emitBool(true);
|
||||
|
||||
try jw.objectField("int");
|
||||
try jw.emitNumber(i32(1234));
|
||||
try jw.emitNumber(@as(i32, 1234));
|
||||
|
||||
try jw.objectField("array");
|
||||
try jw.beginArray();
|
||||
@ -1352,7 +1352,7 @@ test "write json then parse it" {
|
||||
try jw.emitNull();
|
||||
|
||||
try jw.arrayElem();
|
||||
try jw.emitNumber(f64(12.34));
|
||||
try jw.emitNumber(@as(f64, 12.34));
|
||||
|
||||
try jw.endArray();
|
||||
|
||||
|
136
lib/std/math.zig
136
lib/std/math.zig
@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079;
|
||||
pub const sqrt1_2 = 0.707106781186547524400844362104849039;
|
||||
|
||||
// From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128)
|
||||
pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001));
|
||||
pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000));
|
||||
pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
|
||||
pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000));
|
||||
pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001));
|
||||
pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000));
|
||||
pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
|
||||
pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000));
|
||||
pub const f128_toint = 1.0 / f128_epsilon;
|
||||
|
||||
// float.h details
|
||||
@ -69,28 +69,28 @@ pub const f16_max = 65504;
|
||||
pub const f16_epsilon = 0.0009765625; // 2**-10
|
||||
pub const f16_toint = 1.0 / f16_epsilon;
|
||||
|
||||
pub const nan_u16 = u16(0x7C01);
|
||||
pub const nan_u16 = @as(u16, 0x7C01);
|
||||
pub const nan_f16 = @bitCast(f16, nan_u16);
|
||||
|
||||
pub const inf_u16 = u16(0x7C00);
|
||||
pub const inf_u16 = @as(u16, 0x7C00);
|
||||
pub const inf_f16 = @bitCast(f16, inf_u16);
|
||||
|
||||
pub const nan_u32 = u32(0x7F800001);
|
||||
pub const nan_u32 = @as(u32, 0x7F800001);
|
||||
pub const nan_f32 = @bitCast(f32, nan_u32);
|
||||
|
||||
pub const inf_u32 = u32(0x7F800000);
|
||||
pub const inf_u32 = @as(u32, 0x7F800000);
|
||||
pub const inf_f32 = @bitCast(f32, inf_u32);
|
||||
|
||||
pub const nan_u64 = u64(0x7FF << 52) | 1;
|
||||
pub const nan_u64 = @as(u64, 0x7FF << 52) | 1;
|
||||
pub const nan_f64 = @bitCast(f64, nan_u64);
|
||||
|
||||
pub const inf_u64 = u64(0x7FF << 52);
|
||||
pub const inf_u64 = @as(u64, 0x7FF << 52);
|
||||
pub const inf_f64 = @bitCast(f64, inf_u64);
|
||||
|
||||
pub const nan_u128 = u128(0x7fff0000000000000000000000000001);
|
||||
pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
|
||||
pub const nan_f128 = @bitCast(f128, nan_u128);
|
||||
|
||||
pub const inf_u128 = u128(0x7fff0000000000000000000000000000);
|
||||
pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000);
|
||||
pub const inf_f128 = @bitCast(f128, inf_u128);
|
||||
|
||||
pub const nan = @import("math/nan.zig").nan;
|
||||
@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type {
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
return @typeOf(A(0) + B(0));
|
||||
return @typeOf(@as(A, 0) + @as(B, 0));
|
||||
}
|
||||
|
||||
/// 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)) {
|
||||
}
|
||||
|
||||
test "math.min" {
|
||||
testing.expect(min(i32(-1), i32(2)) == -1);
|
||||
testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
|
||||
{
|
||||
var a: u16 = 999;
|
||||
var b: u32 = 10;
|
||||
@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
|
||||
}
|
||||
|
||||
test "math.max" {
|
||||
testing.expect(max(i32(-1), i32(2)) == 2);
|
||||
testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
test "math.shl" {
|
||||
testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000);
|
||||
testing.expect(shl(u8, 0b11111111, usize(8)) == 0);
|
||||
testing.expect(shl(u8, 0b11111111, usize(9)) == 0);
|
||||
testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111);
|
||||
testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
|
||||
testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
|
||||
testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
|
||||
testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
|
||||
testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
|
||||
testing.expect(shl(u8, 0b11111111, 8) == 0);
|
||||
testing.expect(shl(u8, 0b11111111, 9) == 0);
|
||||
@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
|
||||
}
|
||||
|
||||
test "math.shr" {
|
||||
testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111);
|
||||
testing.expect(shr(u8, 0b11111111, usize(8)) == 0);
|
||||
testing.expect(shr(u8, 0b11111111, usize(9)) == 0);
|
||||
testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100);
|
||||
testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
|
||||
testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
|
||||
testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
|
||||
testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
|
||||
testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
|
||||
testing.expect(shr(u8, 0b11111111, 8) == 0);
|
||||
testing.expect(shr(u8, 0b11111111, 9) == 0);
|
||||
@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
|
||||
}
|
||||
|
||||
test "math.rotr" {
|
||||
testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001);
|
||||
testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000);
|
||||
testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001);
|
||||
testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000);
|
||||
testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);
|
||||
testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
|
||||
testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
|
||||
testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
|
||||
testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
|
||||
testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
|
||||
}
|
||||
|
||||
/// Rotates left. Only unsigned values can be rotated.
|
||||
@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
|
||||
}
|
||||
|
||||
test "math.rotl" {
|
||||
testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001);
|
||||
testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010);
|
||||
testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001);
|
||||
testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000);
|
||||
testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);
|
||||
testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
|
||||
testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
|
||||
testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
|
||||
testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
|
||||
testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
|
||||
}
|
||||
|
||||
pub fn Log2Int(comptime T: type) type {
|
||||
@ -532,8 +532,8 @@ test "math.absInt" {
|
||||
comptime testAbsInt();
|
||||
}
|
||||
fn testAbsInt() void {
|
||||
testing.expect((absInt(i32(-10)) catch unreachable) == 10);
|
||||
testing.expect((absInt(i32(10)) catch unreachable) == 10);
|
||||
testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
|
||||
testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
|
||||
}
|
||||
|
||||
pub const absFloat = fabs;
|
||||
@ -679,14 +679,14 @@ pub fn absCast(x: var) t: {
|
||||
}
|
||||
|
||||
test "math.absCast" {
|
||||
testing.expect(absCast(i32(-999)) == 999);
|
||||
testing.expect(@typeOf(absCast(i32(-999))) == u32);
|
||||
testing.expect(absCast(@as(i32, -999)) == 999);
|
||||
testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);
|
||||
|
||||
testing.expect(absCast(i32(999)) == 999);
|
||||
testing.expect(@typeOf(absCast(i32(999))) == u32);
|
||||
testing.expect(absCast(@as(i32, 999)) == 999);
|
||||
testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);
|
||||
|
||||
testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));
|
||||
testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);
|
||||
testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
|
||||
testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);
|
||||
|
||||
testing.expect(absCast(-999) == 999);
|
||||
}
|
||||
@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
|
||||
}
|
||||
|
||||
test "math.negateCast" {
|
||||
testing.expect((negateCast(u32(999)) catch unreachable) == -999);
|
||||
testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
|
||||
testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
|
||||
testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
|
||||
|
||||
testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
|
||||
testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
|
||||
testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
|
||||
testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
|
||||
|
||||
testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10)));
|
||||
testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
}
|
||||
|
||||
test "math.cast" {
|
||||
testing.expectError(error.Overflow, cast(u8, u32(300)));
|
||||
testing.expectError(error.Overflow, cast(i8, i32(-200)));
|
||||
testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
|
||||
testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
|
||||
testing.expectError(error.Overflow, cast(u8, i8(-1)));
|
||||
testing.expectError(error.Overflow, cast(u64, i8(-1)));
|
||||
|
||||
testing.expect((try cast(u8, u32(255))) == u8(255));
|
||||
testing.expect(@typeOf(try cast(u8, u32(255))) == u8);
|
||||
testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
|
||||
testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
|
||||
}
|
||||
|
||||
pub const AlignCastError = error{UnalignedMemory};
|
||||
@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" {
|
||||
}
|
||||
|
||||
fn testCeilPowerOfTwoPromote() void {
|
||||
testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1));
|
||||
testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2));
|
||||
testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63));
|
||||
testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64));
|
||||
testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65));
|
||||
testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7));
|
||||
testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8));
|
||||
testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9));
|
||||
testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9));
|
||||
testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
|
||||
testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
|
||||
testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
|
||||
testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
|
||||
testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
|
||||
testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
|
||||
testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
|
||||
testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
|
||||
testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
|
||||
}
|
||||
|
||||
test "math.ceilPowerOfTwo" {
|
||||
@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" {
|
||||
}
|
||||
|
||||
fn testCeilPowerOfTwo() !void {
|
||||
testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1));
|
||||
testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2));
|
||||
testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63));
|
||||
testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64));
|
||||
testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65));
|
||||
testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7));
|
||||
testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8));
|
||||
testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9));
|
||||
testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
|
||||
testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
|
||||
testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
|
||||
testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
|
||||
testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
|
||||
testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
|
||||
testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
|
||||
testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
|
||||
testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
|
||||
}
|
||||
|
||||
@ -944,7 +944,7 @@ test "max value type" {
|
||||
|
||||
pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
|
||||
const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
|
||||
return ResultInt(a) * ResultInt(b);
|
||||
return @as(ResultInt, a) * @as(ResultInt, b);
|
||||
}
|
||||
|
||||
test "math.mulWide" {
|
||||
|
@ -149,8 +149,8 @@ fn acos64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.acos" {
|
||||
expect(acos(f32(0.0)) == acos32(0.0));
|
||||
expect(acos(f64(0.0)) == acos64(0.0));
|
||||
expect(acos(@as(f32, 0.0)) == acos32(0.0));
|
||||
expect(acos(@as(f64, 0.0)) == acos64(0.0));
|
||||
}
|
||||
|
||||
test "math.acos32" {
|
||||
|
@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.acosh" {
|
||||
expect(acosh(f32(1.5)) == acosh32(1.5));
|
||||
expect(acosh(f64(1.5)) == acosh64(1.5));
|
||||
expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
|
||||
expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
|
||||
}
|
||||
|
||||
test "math.acosh32" {
|
||||
|
@ -142,8 +142,8 @@ fn asin64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.asin" {
|
||||
expect(asin(f32(0.0)) == asin32(0.0));
|
||||
expect(asin(f64(0.0)) == asin64(0.0));
|
||||
expect(asin(@as(f32, 0.0)) == asin32(0.0));
|
||||
expect(asin(@as(f64, 0.0)) == asin64(0.0));
|
||||
}
|
||||
|
||||
test "math.asin32" {
|
||||
|
@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.asinh" {
|
||||
expect(asinh(f32(0.0)) == asinh32(0.0));
|
||||
expect(asinh(f64(0.0)) == asinh64(0.0));
|
||||
expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
|
||||
expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
|
||||
}
|
||||
|
||||
test "math.asinh32" {
|
||||
|
@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.atan" {
|
||||
expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));
|
||||
expect(atan(f64(0.2)) == atan64(0.2));
|
||||
expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
|
||||
expect(atan(@as(f64, 0.2)) == atan64(0.2));
|
||||
}
|
||||
|
||||
test "math.atan32" {
|
||||
|
@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.atanh" {
|
||||
expect(atanh(f32(0.0)) == atanh_32(0.0));
|
||||
expect(atanh(f64(0.0)) == atanh_64(0.0));
|
||||
expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
|
||||
expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
|
||||
}
|
||||
|
||||
test "math.atanh_32" {
|
||||
|
@ -261,7 +261,7 @@ pub const Int = struct {
|
||||
/// the minus sign. This is used for determining the number of characters needed to print the
|
||||
/// value. It is inexact and may exceed the given value by ~1-2 bytes.
|
||||
pub fn sizeInBase(self: Int, base: usize) usize {
|
||||
const bit_count = usize(@boolToInt(!self.isPositive())) + self.bitCountAbs();
|
||||
const bit_count = @as(usize, @boolToInt(!self.isPositive())) + self.bitCountAbs();
|
||||
return (bit_count / math.log2(base)) + 1;
|
||||
}
|
||||
|
||||
|
@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 {
|
||||
// first step newton to 16 bits
|
||||
var t: f64 = @bitCast(f32, u);
|
||||
var r: f64 = t * t * t;
|
||||
t = t * (f64(x) + x + r) / (x + r + r);
|
||||
t = t * (@as(f64, x) + x + r) / (x + r + r);
|
||||
|
||||
// second step newton to 47 bits
|
||||
r = t * t * t;
|
||||
t = t * (f64(x) + x + r) / (x + r + r);
|
||||
t = t * (@as(f64, x) + x + r) / (x + r + r);
|
||||
|
||||
return @floatCast(f32, t);
|
||||
}
|
||||
@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 {
|
||||
}
|
||||
|
||||
u &= 1 << 63;
|
||||
u |= u64(hx) << 32;
|
||||
u |= @as(u64, hx) << 32;
|
||||
var t = @bitCast(f64, u);
|
||||
|
||||
// cbrt to 23 bits
|
||||
@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.cbrt" {
|
||||
expect(cbrt(f32(0.0)) == cbrt32(0.0));
|
||||
expect(cbrt(f64(0.0)) == cbrt64(0.0));
|
||||
expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
|
||||
expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
|
||||
}
|
||||
|
||||
test "math.cbrt32" {
|
||||
|
@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 {
|
||||
if (e >= 23) {
|
||||
return x;
|
||||
} else if (e >= 0) {
|
||||
m = u32(0x007FFFFF) >> @intCast(u5, e);
|
||||
m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
|
||||
if (u & m == 0) {
|
||||
return x;
|
||||
}
|
||||
@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.ceil" {
|
||||
expect(ceil(f32(0.0)) == ceil32(0.0));
|
||||
expect(ceil(f64(0.0)) == ceil64(0.0));
|
||||
expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
|
||||
expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
|
||||
}
|
||||
|
||||
test "math.ceil32" {
|
||||
|
@ -59,7 +59,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
|
||||
expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
|
||||
|
||||
const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
|
||||
return @bitCast(f64, (u64(high_word) << 32) | lx);
|
||||
return @bitCast(f64, (@as(u64, high_word) << 32) | lx);
|
||||
}
|
||||
|
||||
fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
|
||||
|
@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {
|
||||
// y = nan special case is handled fine below
|
||||
|
||||
// double-precision avoids overflow with correct rounding.
|
||||
const dx = f64(x);
|
||||
const dy = f64(y);
|
||||
const dx = @as(f64, x);
|
||||
const dy = @as(f64, y);
|
||||
|
||||
if (dx >= 0) {
|
||||
const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
|
||||
|
@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
|
||||
return Complex(f64).new(x, r);
|
||||
}
|
||||
|
||||
const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx);
|
||||
const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);
|
||||
const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y);
|
||||
return Complex(f64).new(xx, math.copysign(f64, 0, r));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 {
|
||||
const uy = @bitCast(u16, y);
|
||||
|
||||
const h1 = ux & (maxInt(u16) / 2);
|
||||
const h2 = uy & (u16(1) << 15);
|
||||
const h2 = uy & (@as(u16, 1) << 15);
|
||||
return @bitCast(f16, h1 | h2);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 {
|
||||
const uy = @bitCast(u32, y);
|
||||
|
||||
const h1 = ux & (maxInt(u32) / 2);
|
||||
const h2 = uy & (u32(1) << 31);
|
||||
const h2 = uy & (@as(u32, 1) << 31);
|
||||
return @bitCast(f32, h1 | h2);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 {
|
||||
const uy = @bitCast(u64, y);
|
||||
|
||||
const h1 = ux & (maxInt(u64) / 2);
|
||||
const h2 = uy & (u64(1) << 63);
|
||||
const h2 = uy & (@as(u64, 1) << 63);
|
||||
return @bitCast(f64, h1 | h2);
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T {
|
||||
}
|
||||
|
||||
test "math.cos" {
|
||||
expect(cos(f32(0.0)) == cos_(f32, 0.0));
|
||||
expect(cos(f64(0.0)) == cos_(f64, 0.0));
|
||||
expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
|
||||
expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
|
||||
}
|
||||
|
||||
test "math.cos32" {
|
||||
|
@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.cosh" {
|
||||
expect(cosh(f32(1.5)) == cosh32(1.5));
|
||||
expect(cosh(f64(1.5)) == cosh64(1.5));
|
||||
expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
|
||||
expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
|
||||
}
|
||||
|
||||
test "math.cosh32" {
|
||||
|
@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.exp" {
|
||||
assert(exp(f32(0.0)) == exp32(0.0));
|
||||
assert(exp(f64(0.0)) == exp64(0.0));
|
||||
assert(exp(@as(f32, 0.0)) == exp32(0.0));
|
||||
assert(exp(@as(f64, 0.0)) == exp64(0.0));
|
||||
}
|
||||
|
||||
test "math.exp32" {
|
||||
|
@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 {
|
||||
const k = i_0 / tblsiz;
|
||||
// NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the
|
||||
// intended result but should confirm how GCC/Clang handle this to ensure.
|
||||
const uk = @bitCast(f64, u64(0x3FF + k) << 52);
|
||||
const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52);
|
||||
i_0 &= tblsiz - 1;
|
||||
uf -= redux;
|
||||
|
||||
@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.exp2" {
|
||||
expect(exp2(f32(0.8923)) == exp2_32(0.8923));
|
||||
expect(exp2(f64(0.8923)) == exp2_64(0.8923));
|
||||
expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
|
||||
expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
|
||||
}
|
||||
|
||||
test "math.exp2_32" {
|
||||
|
@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.exp1m" {
|
||||
expect(expm1(f32(0.0)) == expm1_32(0.0));
|
||||
expect(expm1(f64(0.0)) == expm1_64(0.0));
|
||||
expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
|
||||
expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
|
||||
}
|
||||
|
||||
test "math.expm1_32" {
|
||||
|
@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {
|
||||
const kln2 = 0x1.62066151ADD8BP+10;
|
||||
|
||||
const u = (0x3FF + k / 2) << 20;
|
||||
const scale = @bitCast(f64, u64(u) << 32);
|
||||
const scale = @bitCast(f64, @as(u64, u) << 32);
|
||||
return math.exp(x - kln2) * scale * scale;
|
||||
}
|
||||
|
@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 {
|
||||
}
|
||||
|
||||
test "math.fabs" {
|
||||
expect(fabs(f16(1.0)) == fabs16(1.0));
|
||||
expect(fabs(f32(1.0)) == fabs32(1.0));
|
||||
expect(fabs(f64(1.0)) == fabs64(1.0));
|
||||
expect(fabs(f128(1.0)) == fabs128(1.0));
|
||||
expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
|
||||
expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
|
||||
expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
|
||||
expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
|
||||
}
|
||||
|
||||
test "math.fabs16" {
|
||||
|
@ -40,7 +40,7 @@ fn floor16(x: f16) f16 {
|
||||
}
|
||||
|
||||
if (e >= 0) {
|
||||
m = u16(1023) >> @intCast(u4, e);
|
||||
m = @as(u16, 1023) >> @intCast(u4, e);
|
||||
if (u & m == 0) {
|
||||
return x;
|
||||
}
|
||||
@ -74,7 +74,7 @@ fn floor32(x: f32) f32 {
|
||||
}
|
||||
|
||||
if (e >= 0) {
|
||||
m = u32(0x007FFFFF) >> @intCast(u5, e);
|
||||
m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
|
||||
if (u & m == 0) {
|
||||
return x;
|
||||
}
|
||||
@ -123,9 +123,9 @@ fn floor64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.floor" {
|
||||
expect(floor(f16(1.3)) == floor16(1.3));
|
||||
expect(floor(f32(1.3)) == floor32(1.3));
|
||||
expect(floor(f64(1.3)) == floor64(1.3));
|
||||
expect(floor(@as(f16, 1.3)) == floor16(1.3));
|
||||
expect(floor(@as(f32, 1.3)) == floor32(1.3));
|
||||
expect(floor(@as(f64, 1.3)) == floor64(1.3));
|
||||
}
|
||||
|
||||
test "math.floor16" {
|
||||
|
@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T {
|
||||
}
|
||||
|
||||
fn fma32(x: f32, y: f32, z: f32) f32 {
|
||||
const xy = f64(x) * y;
|
||||
const xy = @as(f64, x) * y;
|
||||
const xy_z = xy + z;
|
||||
const u = @bitCast(u64, xy_z);
|
||||
const e = (u >> 52) & 0x7FF;
|
||||
|
@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result {
|
||||
}
|
||||
|
||||
test "math.frexp" {
|
||||
const a = frexp(f32(1.3));
|
||||
const a = frexp(@as(f32, 1.3));
|
||||
const b = frexp32(1.3);
|
||||
expect(a.significand == b.significand and a.exponent == b.exponent);
|
||||
|
||||
const c = frexp(f64(1.3));
|
||||
const c = frexp(@as(f64, 1.3));
|
||||
const d = frexp64(1.3);
|
||||
expect(c.significand == d.significand and c.exponent == d.exponent);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {
|
||||
yy *= 0x1.0p-90;
|
||||
}
|
||||
|
||||
return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y));
|
||||
return z * math.sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y));
|
||||
}
|
||||
|
||||
fn sq(hi: *f64, lo: *f64, x: f64) void {
|
||||
|
@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 {
|
||||
}
|
||||
|
||||
// NOTE: Should these be exposed publicly?
|
||||
const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1);
|
||||
const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1);
|
||||
const fp_ilogb0 = fp_ilogbnan;
|
||||
|
||||
fn ilogb32(x: f32) i32 {
|
||||
@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 {
|
||||
}
|
||||
|
||||
test "math.ilogb" {
|
||||
expect(ilogb(f32(0.2)) == ilogb32(0.2));
|
||||
expect(ilogb(f64(0.2)) == ilogb64(0.2));
|
||||
expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
|
||||
expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
|
||||
}
|
||||
|
||||
test "math.ilogb32" {
|
||||
|
@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool {
|
||||
}
|
||||
|
||||
test "math.isFinite" {
|
||||
expect(isFinite(f16(0.0)));
|
||||
expect(isFinite(f16(-0.0)));
|
||||
expect(isFinite(f32(0.0)));
|
||||
expect(isFinite(f32(-0.0)));
|
||||
expect(isFinite(f64(0.0)));
|
||||
expect(isFinite(f64(-0.0)));
|
||||
expect(isFinite(@as(f16, 0.0)));
|
||||
expect(isFinite(@as(f16, -0.0)));
|
||||
expect(isFinite(@as(f32, 0.0)));
|
||||
expect(isFinite(@as(f32, -0.0)));
|
||||
expect(isFinite(@as(f64, 0.0)));
|
||||
expect(isFinite(@as(f64, -0.0)));
|
||||
expect(!isFinite(math.inf(f16)));
|
||||
expect(!isFinite(-math.inf(f16)));
|
||||
expect(!isFinite(math.inf(f32)));
|
||||
|
@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool {
|
||||
}
|
||||
|
||||
test "math.isInf" {
|
||||
expect(!isInf(f16(0.0)));
|
||||
expect(!isInf(f16(-0.0)));
|
||||
expect(!isInf(f32(0.0)));
|
||||
expect(!isInf(f32(-0.0)));
|
||||
expect(!isInf(f64(0.0)));
|
||||
expect(!isInf(f64(-0.0)));
|
||||
expect(!isInf(f128(0.0)));
|
||||
expect(!isInf(f128(-0.0)));
|
||||
expect(!isInf(@as(f16, 0.0)));
|
||||
expect(!isInf(@as(f16, -0.0)));
|
||||
expect(!isInf(@as(f32, 0.0)));
|
||||
expect(!isInf(@as(f32, -0.0)));
|
||||
expect(!isInf(@as(f64, 0.0)));
|
||||
expect(!isInf(@as(f64, -0.0)));
|
||||
expect(!isInf(@as(f128, 0.0)));
|
||||
expect(!isInf(@as(f128, -0.0)));
|
||||
expect(isInf(math.inf(f16)));
|
||||
expect(isInf(-math.inf(f16)));
|
||||
expect(isInf(math.inf(f32)));
|
||||
@ -93,14 +93,14 @@ test "math.isInf" {
|
||||
}
|
||||
|
||||
test "math.isPositiveInf" {
|
||||
expect(!isPositiveInf(f16(0.0)));
|
||||
expect(!isPositiveInf(f16(-0.0)));
|
||||
expect(!isPositiveInf(f32(0.0)));
|
||||
expect(!isPositiveInf(f32(-0.0)));
|
||||
expect(!isPositiveInf(f64(0.0)));
|
||||
expect(!isPositiveInf(f64(-0.0)));
|
||||
expect(!isPositiveInf(f128(0.0)));
|
||||
expect(!isPositiveInf(f128(-0.0)));
|
||||
expect(!isPositiveInf(@as(f16, 0.0)));
|
||||
expect(!isPositiveInf(@as(f16, -0.0)));
|
||||
expect(!isPositiveInf(@as(f32, 0.0)));
|
||||
expect(!isPositiveInf(@as(f32, -0.0)));
|
||||
expect(!isPositiveInf(@as(f64, 0.0)));
|
||||
expect(!isPositiveInf(@as(f64, -0.0)));
|
||||
expect(!isPositiveInf(@as(f128, 0.0)));
|
||||
expect(!isPositiveInf(@as(f128, -0.0)));
|
||||
expect(isPositiveInf(math.inf(f16)));
|
||||
expect(!isPositiveInf(-math.inf(f16)));
|
||||
expect(isPositiveInf(math.inf(f32)));
|
||||
@ -112,14 +112,14 @@ test "math.isPositiveInf" {
|
||||
}
|
||||
|
||||
test "math.isNegativeInf" {
|
||||
expect(!isNegativeInf(f16(0.0)));
|
||||
expect(!isNegativeInf(f16(-0.0)));
|
||||
expect(!isNegativeInf(f32(0.0)));
|
||||
expect(!isNegativeInf(f32(-0.0)));
|
||||
expect(!isNegativeInf(f64(0.0)));
|
||||
expect(!isNegativeInf(f64(-0.0)));
|
||||
expect(!isNegativeInf(f128(0.0)));
|
||||
expect(!isNegativeInf(f128(-0.0)));
|
||||
expect(!isNegativeInf(@as(f16, 0.0)));
|
||||
expect(!isNegativeInf(@as(f16, -0.0)));
|
||||
expect(!isNegativeInf(@as(f32, 0.0)));
|
||||
expect(!isNegativeInf(@as(f32, -0.0)));
|
||||
expect(!isNegativeInf(@as(f64, 0.0)));
|
||||
expect(!isNegativeInf(@as(f64, -0.0)));
|
||||
expect(!isNegativeInf(@as(f128, 0.0)));
|
||||
expect(!isNegativeInf(@as(f128, -0.0)));
|
||||
expect(!isNegativeInf(math.inf(f16)));
|
||||
expect(isNegativeInf(-math.inf(f16)));
|
||||
expect(!isNegativeInf(math.inf(f32)));
|
||||
|
@ -20,8 +20,8 @@ test "math.isNan" {
|
||||
expect(isNan(math.nan(f32)));
|
||||
expect(isNan(math.nan(f64)));
|
||||
expect(isNan(math.nan(f128)));
|
||||
expect(!isNan(f16(1.0)));
|
||||
expect(!isNan(f32(1.0)));
|
||||
expect(!isNan(f64(1.0)));
|
||||
expect(!isNan(f128(1.0)));
|
||||
expect(!isNan(@as(f16, 1.0)));
|
||||
expect(!isNan(@as(f32, 1.0)));
|
||||
expect(!isNan(@as(f64, 1.0)));
|
||||
expect(!isNan(@as(f128, 1.0)));
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ test "math.isNormal" {
|
||||
expect(!isNormal(math.nan(f16)));
|
||||
expect(!isNormal(math.nan(f32)));
|
||||
expect(!isNormal(math.nan(f64)));
|
||||
expect(!isNormal(f16(0)));
|
||||
expect(!isNormal(f32(0)));
|
||||
expect(!isNormal(f64(0)));
|
||||
expect(isNormal(f16(1.0)));
|
||||
expect(isNormal(f32(1.0)));
|
||||
expect(isNormal(f64(1.0)));
|
||||
expect(!isNormal(@as(f16, 0)));
|
||||
expect(!isNormal(@as(f32, 0)));
|
||||
expect(!isNormal(@as(f64, 0)));
|
||||
expect(isNormal(@as(f16, 1.0)));
|
||||
expect(isNormal(@as(f32, 1.0)));
|
||||
expect(isNormal(@as(f64, 1.0)));
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) {
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
return @typeOf(1)(math.floor(ln_64(f64(x))));
|
||||
return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
|
||||
},
|
||||
TypeId.Int => {
|
||||
return T(math.floor(ln_64(f64(x))));
|
||||
return T(math.floor(ln_64(@as(f64, x))));
|
||||
},
|
||||
else => @compileError("ln not implemented for " ++ @typeName(T)),
|
||||
}
|
||||
@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 {
|
||||
hx += 0x3FF00000 - 0x3FE6A09E;
|
||||
k += @intCast(i32, hx >> 20) - 0x3FF;
|
||||
hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
|
||||
ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
|
||||
ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
|
||||
x = @bitCast(f64, ix);
|
||||
|
||||
const f = x - 1.0;
|
||||
@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.ln" {
|
||||
expect(ln(f32(0.2)) == ln_32(0.2));
|
||||
expect(ln(f64(0.2)) == ln_64(0.2));
|
||||
expect(ln(@as(f32, 0.2)) == ln_32(0.2));
|
||||
expect(ln(@as(f64, 0.2)) == ln_64(0.2));
|
||||
}
|
||||
|
||||
test "math.ln32" {
|
||||
|
@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
|
||||
const float_base = math.lossyCast(f64, base);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base));
|
||||
return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base)));
|
||||
return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
|
||||
},
|
||||
builtin.TypeId.Int => {
|
||||
// TODO implement integer log without using float math
|
||||
@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
|
||||
|
||||
builtin.TypeId.Float => {
|
||||
switch (T) {
|
||||
f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)),
|
||||
f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),
|
||||
f64 => return math.ln(x) / math.ln(float_base),
|
||||
else => @compileError("log not implemented for " ++ @typeName(T)),
|
||||
}
|
||||
@ -67,6 +67,6 @@ test "math.log float_special" {
|
||||
expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
|
||||
expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
|
||||
|
||||
expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));
|
||||
expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));
|
||||
expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
|
||||
expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
return @typeOf(1)(math.floor(log10_64(f64(x))));
|
||||
return @typeOf(1)(math.floor(log10_64(@as(f64, x))));
|
||||
},
|
||||
TypeId.Int => {
|
||||
return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
|
||||
@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 {
|
||||
hx += 0x3FF00000 - 0x3FE6A09E;
|
||||
k += @intCast(i32, hx >> 20) - 0x3FF;
|
||||
hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
|
||||
ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
|
||||
ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
|
||||
x = @bitCast(f64, ix);
|
||||
|
||||
const f = x - 1.0;
|
||||
@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 {
|
||||
// hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
|
||||
var hi = f - hfsq;
|
||||
var hii = @bitCast(u64, hi);
|
||||
hii &= u64(maxInt(u64)) << 32;
|
||||
hii &= @as(u64, maxInt(u64)) << 32;
|
||||
hi = @bitCast(f64, hii);
|
||||
const lo = f - hi - hfsq + s * (hfsq + R);
|
||||
|
||||
@ -178,7 +178,7 @@ pub fn log10_64(x_: f64) f64 {
|
||||
|
||||
test "math.log10" {
|
||||
testing.expect(log10(f32(0.2)) == log10_32(0.2));
|
||||
testing.expect(log10(f64(0.2)) == log10_64(0.2));
|
||||
testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
|
||||
}
|
||||
|
||||
test "math.log10_32" {
|
||||
|
@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {
|
||||
|
||||
// u into [sqrt(2)/2, sqrt(2)]
|
||||
iu = (iu & 0x000FFFFF) + 0x3FE6A09E;
|
||||
const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF);
|
||||
const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);
|
||||
f = @bitCast(f64, iq) - 1;
|
||||
}
|
||||
|
||||
@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.log1p" {
|
||||
expect(log1p(f32(0.0)) == log1p_32(0.0));
|
||||
expect(log1p(f64(0.0)) == log1p_64(0.0));
|
||||
expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
|
||||
expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
|
||||
}
|
||||
|
||||
test "math.log1p_32" {
|
||||
|
@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 {
|
||||
hx += 0x3FF00000 - 0x3FE6A09E;
|
||||
k += @intCast(i32, hx >> 20) - 0x3FF;
|
||||
hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
|
||||
ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
|
||||
ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
|
||||
x = @bitCast(f64, ix);
|
||||
|
||||
const f = x - 1.0;
|
||||
@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 {
|
||||
// hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
|
||||
var hi = f - hfsq;
|
||||
var hii = @bitCast(u64, hi);
|
||||
hii &= u64(maxInt(u64)) << 32;
|
||||
hii &= @as(u64, maxInt(u64)) << 32;
|
||||
hi = @bitCast(f64, hii);
|
||||
const lo = f - hi - hfsq + s * (hfsq + R);
|
||||
|
||||
@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.log2" {
|
||||
expect(log2(f32(0.2)) == log2_32(0.2));
|
||||
expect(log2(f64(0.2)) == log2_64(0.2));
|
||||
expect(log2(@as(f32, 0.2)) == log2_32(0.2));
|
||||
expect(log2(@as(f64, 0.2)) == log2_64(0.2));
|
||||
}
|
||||
|
||||
test "math.log2_32" {
|
||||
|
@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result {
|
||||
return result;
|
||||
}
|
||||
|
||||
const mask = u32(0x007FFFFF) >> @intCast(u5, e);
|
||||
const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
|
||||
if (u & mask == 0) {
|
||||
result.ipart = x;
|
||||
result.fpart = @bitCast(f32, us);
|
||||
@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result {
|
||||
return result;
|
||||
}
|
||||
|
||||
const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e);
|
||||
const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e);
|
||||
if (u & mask == 0) {
|
||||
result.ipart = x;
|
||||
result.fpart = @bitCast(f64, us);
|
||||
@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result {
|
||||
}
|
||||
|
||||
test "math.modf" {
|
||||
const a = modf(f32(1.0));
|
||||
const a = modf(@as(f32, 1.0));
|
||||
const b = modf32(1.0);
|
||||
// NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
|
||||
expect(a.ipart == b.ipart and a.fpart == b.fpart);
|
||||
|
||||
const c = modf(f64(1.0));
|
||||
const c = modf(@as(f64, 1.0));
|
||||
const d = modf64(1.0);
|
||||
expect(a.ipart == b.ipart and a.fpart == b.fpart);
|
||||
}
|
||||
|
@ -91,8 +91,8 @@ fn round64(x_: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.round" {
|
||||
expect(round(f32(1.3)) == round32(1.3));
|
||||
expect(round(f64(1.3)) == round64(1.3));
|
||||
expect(round(@as(f32, 1.3)) == round32(1.3));
|
||||
expect(round(@as(f64, 1.3)) == round64(1.3));
|
||||
}
|
||||
|
||||
test "math.round32" {
|
||||
|
@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 {
|
||||
}
|
||||
|
||||
test "math.scalbn" {
|
||||
expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));
|
||||
expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));
|
||||
expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
|
||||
expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
|
||||
}
|
||||
|
||||
test "math.scalbn32" {
|
||||
|
@ -29,9 +29,9 @@ fn signbit64(x: f64) bool {
|
||||
}
|
||||
|
||||
test "math.signbit" {
|
||||
expect(signbit(f16(4.0)) == signbit16(4.0));
|
||||
expect(signbit(f32(4.0)) == signbit32(4.0));
|
||||
expect(signbit(f64(4.0)) == signbit64(4.0));
|
||||
expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
|
||||
expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
|
||||
expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
|
||||
}
|
||||
|
||||
test "math.signbit16" {
|
||||
|
@ -88,9 +88,9 @@ test "math.sin" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
expect(sin(f32(0.0)) == sin_(f32, 0.0));
|
||||
expect(sin(f64(0.0)) == sin_(f64, 0.0));
|
||||
expect(comptime (math.sin(f64(2))) == math.sin(f64(2)));
|
||||
expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
|
||||
expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
|
||||
expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
|
||||
}
|
||||
|
||||
test "math.sin32" {
|
||||
|
@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.sinh" {
|
||||
expect(sinh(f32(1.5)) == sinh32(1.5));
|
||||
expect(sinh(f64(1.5)) == sinh64(1.5));
|
||||
expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
|
||||
expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
|
||||
}
|
||||
|
||||
test "math.sinh32" {
|
||||
|
@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
|
||||
}
|
||||
|
||||
test "math.sqrt" {
|
||||
expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
|
||||
expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
|
||||
expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
|
||||
expect(sqrt(@as(f16, 0.0)) == @sqrt(f16, 0.0));
|
||||
expect(sqrt(@as(f32, 0.0)) == @sqrt(f32, 0.0));
|
||||
expect(sqrt(@as(f64, 0.0)) == @sqrt(f64, 0.0));
|
||||
}
|
||||
|
||||
test "math.sqrt16" {
|
||||
|
@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T {
|
||||
}
|
||||
|
||||
test "math.tan" {
|
||||
expect(tan(f32(0.0)) == tan_(f32, 0.0));
|
||||
expect(tan(f64(0.0)) == tan_(f64, 0.0));
|
||||
expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
|
||||
expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
|
||||
}
|
||||
|
||||
test "math.tan32" {
|
||||
|
@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.tanh" {
|
||||
expect(tanh(f32(1.5)) == tanh32(1.5));
|
||||
expect(tanh(f64(1.5)) == tanh64(1.5));
|
||||
expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
|
||||
expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
|
||||
}
|
||||
|
||||
test "math.tanh32" {
|
||||
|
@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 {
|
||||
e = 1;
|
||||
}
|
||||
|
||||
m = u32(maxInt(u32)) >> @intCast(u5, e);
|
||||
m = @as(u32, maxInt(u32)) >> @intCast(u5, e);
|
||||
if (u & m == 0) {
|
||||
return x;
|
||||
} else {
|
||||
@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 {
|
||||
e = 1;
|
||||
}
|
||||
|
||||
m = u64(maxInt(u64)) >> @intCast(u6, e);
|
||||
m = @as(u64, maxInt(u64)) >> @intCast(u6, e);
|
||||
if (u & m == 0) {
|
||||
return x;
|
||||
} else {
|
||||
@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 {
|
||||
}
|
||||
|
||||
test "math.trunc" {
|
||||
expect(trunc(f32(1.3)) == trunc32(1.3));
|
||||
expect(trunc(f64(1.3)) == trunc64(1.3));
|
||||
expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
|
||||
expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
|
||||
}
|
||||
|
||||
test "math.trunc32" {
|
||||
|
@ -118,7 +118,7 @@ pub const Allocator = struct {
|
||||
} else @alignOf(T);
|
||||
|
||||
if (n == 0) {
|
||||
return ([*]align(a) T)(undefined)[0..0];
|
||||
return @as([*]align(a) T, undefined)[0..0];
|
||||
}
|
||||
|
||||
const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
|
||||
@ -170,7 +170,7 @@ pub const Allocator = struct {
|
||||
}
|
||||
if (new_n == 0) {
|
||||
self.free(old_mem);
|
||||
return ([*]align(new_alignment) T)(undefined)[0..0];
|
||||
return @as([*]align(new_alignment) T, undefined)[0..0];
|
||||
}
|
||||
|
||||
const old_byte_slice = @sliceToBytes(old_mem);
|
||||
@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.
|
||||
builtin.Endian.Little => {
|
||||
const ShiftType = math.Log2Int(ReturnType);
|
||||
for (bytes) |b, index| {
|
||||
result = result | (ReturnType(b) << @intCast(ShiftType, index * 8));
|
||||
result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type {
|
||||
if (comptime !trait.isSingleItemPtr(P))
|
||||
@compileError("expected single item " ++ "pointer, passed " ++ @typeName(P));
|
||||
|
||||
const size = usize(@sizeOf(meta.Child(P)));
|
||||
const size = @as(usize, @sizeOf(meta.Child(P)));
|
||||
const alignment = comptime meta.alignment(P);
|
||||
|
||||
if (alignment == 0) {
|
||||
@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {
|
||||
}
|
||||
|
||||
test "asBytes" {
|
||||
const deadbeef = u32(0xDEADBEEF);
|
||||
const deadbeef = @as(u32, 0xDEADBEEF);
|
||||
const deadbeef_bytes = switch (builtin.endian) {
|
||||
builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
|
||||
builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
|
||||
@ -1361,7 +1361,7 @@ test "asBytes" {
|
||||
|
||||
testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
|
||||
|
||||
var codeface = u32(0xC0DEFACE);
|
||||
var codeface = @as(u32, 0xC0DEFACE);
|
||||
for (asBytes(&codeface).*) |*b|
|
||||
b.* = 0;
|
||||
testing.expect(codeface == 0);
|
||||
@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
|
||||
}
|
||||
|
||||
test "toBytes" {
|
||||
var my_bytes = toBytes(u32(0x12345678));
|
||||
var my_bytes = toBytes(@as(u32, 0x12345678));
|
||||
switch (builtin.endian) {
|
||||
builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
|
||||
builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
|
||||
@ -1406,7 +1406,7 @@ test "toBytes" {
|
||||
}
|
||||
|
||||
fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
|
||||
const size = usize(@sizeOf(T));
|
||||
const size = @as(usize, @sizeOf(T));
|
||||
|
||||
if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) {
|
||||
@compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
|
||||
@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ
|
||||
}
|
||||
|
||||
test "bytesAsValue" {
|
||||
const deadbeef = u32(0xDEADBEEF);
|
||||
const deadbeef = @as(u32, 0xDEADBEEF);
|
||||
const deadbeef_bytes = switch (builtin.endian) {
|
||||
builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
|
||||
builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
|
||||
@ -1472,7 +1472,7 @@ test "bytesToValue" {
|
||||
};
|
||||
|
||||
const deadbeef = bytesToValue(u32, deadbeef_bytes);
|
||||
testing.expect(deadbeef == u32(0xDEADBEEF));
|
||||
testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
|
||||
}
|
||||
|
||||
fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
|
||||
|
@ -505,7 +505,7 @@ test "std.meta.eql" {
|
||||
const EU = struct {
|
||||
fn tst(err: bool) !u8 {
|
||||
if (err) return error.Error;
|
||||
return u8(5);
|
||||
return @as(u8, 5);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool {
|
||||
}
|
||||
|
||||
test "std.meta.trait.isConstPtr" {
|
||||
var t = u8(0);
|
||||
const c = u8(0);
|
||||
var t = @as(u8, 0);
|
||||
const c = @as(u8, 0);
|
||||
testing.expect(isConstPtr(*const @typeOf(t)));
|
||||
testing.expect(isConstPtr(@typeOf(&c)));
|
||||
testing.expect(!isConstPtr(*@typeOf(t)));
|
||||
|
@ -611,7 +611,7 @@ fn linuxLookupName(
|
||||
// TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
|
||||
mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
|
||||
}
|
||||
if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
|
||||
if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
|
||||
if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
|
||||
prefixlen = prefixMatch(sa6.addr, da6.addr);
|
||||
} else |_| {}
|
||||
@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
|
||||
// address. However the definition of the source prefix length is
|
||||
// not clear and thus this limiting is not yet implemented.
|
||||
var i: u8 = 0;
|
||||
while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
|
||||
while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -1194,23 +1194,23 @@ fn dnsParse(
|
||||
if (r.len < 12) return error.InvalidDnsPacket;
|
||||
if ((r[3] & 15) != 0) return;
|
||||
var p = r.ptr + 12;
|
||||
var qdcount = r[4] * usize(256) + r[5];
|
||||
var ancount = r[6] * usize(256) + r[7];
|
||||
var qdcount = r[4] * @as(usize, 256) + r[5];
|
||||
var ancount = r[6] * @as(usize, 256) + r[7];
|
||||
if (qdcount + ancount > 64) return error.InvalidDnsPacket;
|
||||
while (qdcount != 0) {
|
||||
qdcount -= 1;
|
||||
while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
|
||||
if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
|
||||
return error.InvalidDnsPacket;
|
||||
p += usize(5) + @boolToInt(p[0] != 0);
|
||||
p += @as(usize, 5) + @boolToInt(p[0] != 0);
|
||||
}
|
||||
while (ancount != 0) {
|
||||
ancount -= 1;
|
||||
while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
|
||||
if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
|
||||
return error.InvalidDnsPacket;
|
||||
p += usize(1) + @boolToInt(p[0] != 0);
|
||||
const len = p[8] * usize(256) + p[9];
|
||||
p += @as(usize, 1) + @boolToInt(p[0] != 0);
|
||||
const len = p[8] * @as(usize, 256) + p[9];
|
||||
if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket;
|
||||
try callback(ctx, p[1], p[10 .. 10 + len], r);
|
||||
p += 10 + len;
|
||||
|
@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
|
||||
|
||||
var index: usize = 0;
|
||||
while (index < bytes.len) {
|
||||
const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len));
|
||||
const amt_to_write = math.min(bytes.len - index, @as(usize, max_bytes_len));
|
||||
const rc = system.write(fd, bytes.ptr + index, amt_to_write);
|
||||
switch (errno(rc)) {
|
||||
0 => {
|
||||
@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool {
|
||||
}
|
||||
if (builtin.os == .linux) {
|
||||
var wsz: linux.winsize = undefined;
|
||||
return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
|
||||
return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
|
||||
}
|
||||
|
||||
const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
|
||||
const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
|
||||
const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];
|
||||
const name_wide = @bytesToSlice(u16, name_bytes);
|
||||
return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
|
||||
mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
|
||||
@ -2897,7 +2897,7 @@ pub fn res_mkquery(
|
||||
// Construct query template - ID will be filled later
|
||||
var q: [280]u8 = undefined;
|
||||
@memset(&q, 0, n);
|
||||
q[2] = u8(op) * 8 + 1;
|
||||
q[2] = @as(u8, op) * 8 + 1;
|
||||
q[5] = 1;
|
||||
mem.copy(u8, q[13..], name);
|
||||
var i: usize = 13;
|
||||
@ -3143,7 +3143,7 @@ pub fn dn_expand(
|
||||
// loop invariants: p<end, dest<dend
|
||||
if ((p[0] & 0xc0) != 0) {
|
||||
if (p + 1 == end) return error.InvalidDnsPacket;
|
||||
var j = ((p[0] & usize(0x3f)) << 8) | p[1];
|
||||
var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
|
||||
if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr);
|
||||
if (j >= msg.len) return error.InvalidDnsPacket;
|
||||
p = msg.ptr + j;
|
||||
|
@ -315,7 +315,7 @@ pub const dirent = extern struct {
|
||||
d_name: [256]u8,
|
||||
|
||||
pub fn reclen(self: dirent) u16 {
|
||||
return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7);
|
||||
return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400;
|
||||
pub const EPOLLERR = 0x008;
|
||||
pub const EPOLLHUP = 0x010;
|
||||
pub const EPOLLRDHUP = 0x2000;
|
||||
pub const EPOLLEXCLUSIVE = (u32(1) << 28);
|
||||
pub const EPOLLWAKEUP = (u32(1) << 29);
|
||||
pub const EPOLLONESHOT = (u32(1) << 30);
|
||||
pub const EPOLLET = (u32(1) << 31);
|
||||
pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28);
|
||||
pub const EPOLLWAKEUP = (@as(u32, 1) << 29);
|
||||
pub const EPOLLONESHOT = (@as(u32, 1) << 30);
|
||||
pub const EPOLLET = (@as(u32, 1) << 31);
|
||||
|
||||
pub const CLOCK_REALTIME = 0;
|
||||
pub const CLOCK_MONOTONIC = 1;
|
||||
@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool {
|
||||
}
|
||||
|
||||
pub fn CAP_TO_MASK(cap: u8) u32 {
|
||||
return u32(1) << u5(cap & 31);
|
||||
return @as(u32, 1) << u5(cap & 31);
|
||||
}
|
||||
|
||||
pub fn CAP_TO_INDEX(cap: u8) u8 {
|
||||
|
@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 {
|
||||
|
||||
pub fn dup2(old: i32, new: i32) usize {
|
||||
if (@hasDecl(@This(), "SYS_dup2")) {
|
||||
return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)));
|
||||
return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));
|
||||
} else {
|
||||
if (old == new) {
|
||||
if (std.debug.runtime_safety) {
|
||||
const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD);
|
||||
const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD);
|
||||
if (@bitCast(isize, rc) < 0) return rc;
|
||||
}
|
||||
return @intCast(usize, old);
|
||||
} else {
|
||||
return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0);
|
||||
return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dup3(old: i32, new: i32, flags: u32) usize {
|
||||
return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags);
|
||||
return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize {
|
||||
return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
|
||||
return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
|
||||
}
|
||||
|
||||
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 {
|
||||
pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
|
||||
return syscall3(
|
||||
SYS_getdents,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(dirp),
|
||||
std.math.min(len, maxInt(c_int)),
|
||||
);
|
||||
@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
|
||||
pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
|
||||
return syscall3(
|
||||
SYS_getdents64,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(dirp),
|
||||
std.math.min(len, maxInt(c_int)),
|
||||
);
|
||||
@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize {
|
||||
}
|
||||
|
||||
pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize {
|
||||
return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask);
|
||||
return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
|
||||
}
|
||||
|
||||
pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
|
||||
return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd)));
|
||||
return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
|
||||
}
|
||||
|
||||
// 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
|
||||
if (@hasDecl(@This(), "SYS_readlink")) {
|
||||
return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
} else {
|
||||
return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
|
||||
return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
|
||||
if (@hasDecl(@This(), "SYS_mkdir")) {
|
||||
return syscall2(SYS_mkdir, @ptrToInt(path), mode);
|
||||
} else {
|
||||
return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode);
|
||||
return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize {
|
||||
return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode);
|
||||
return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
|
||||
}
|
||||
|
||||
// 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
|
||||
if (@hasDecl(@This(), "SYS_mmap2")) {
|
||||
// Make sure the offset is also specified in multiples of page size
|
||||
if ((offset & (MMAP2_UNIT - 1)) != 0)
|
||||
return @bitCast(usize, isize(-EINVAL));
|
||||
return @bitCast(usize, @as(isize, -EINVAL));
|
||||
|
||||
return syscall6(
|
||||
SYS_mmap2,
|
||||
@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
|
||||
length,
|
||||
prot,
|
||||
flags,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@truncate(usize, offset / MMAP2_UNIT),
|
||||
);
|
||||
} else {
|
||||
@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
|
||||
length,
|
||||
prot,
|
||||
flags,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
offset,
|
||||
);
|
||||
}
|
||||
@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
|
||||
}
|
||||
|
||||
pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
|
||||
return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);
|
||||
return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
|
||||
}
|
||||
|
||||
pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
|
||||
return syscall5(
|
||||
SYS_preadv,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(iov),
|
||||
count,
|
||||
@truncate(usize, offset),
|
||||
@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
|
||||
pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
|
||||
return syscall6(
|
||||
SYS_preadv2,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(iov),
|
||||
count,
|
||||
@truncate(usize, offset),
|
||||
@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k
|
||||
}
|
||||
|
||||
pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
|
||||
return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);
|
||||
return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
|
||||
}
|
||||
|
||||
pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
|
||||
return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);
|
||||
return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
|
||||
}
|
||||
|
||||
pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
|
||||
return syscall5(
|
||||
SYS_pwritev,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(iov),
|
||||
count,
|
||||
@truncate(usize, offset),
|
||||
@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us
|
||||
pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
|
||||
return syscall6(
|
||||
SYS_pwritev2,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(iov),
|
||||
count,
|
||||
@truncate(usize, offset),
|
||||
@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize {
|
||||
if (@hasDecl(@This(), "SYS_rmdir")) {
|
||||
return syscall1(SYS_rmdir, @ptrToInt(path));
|
||||
} else {
|
||||
return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
|
||||
return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
|
||||
if (@hasDecl(@This(), "SYS_symlink")) {
|
||||
return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
|
||||
} else {
|
||||
return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));
|
||||
return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize {
|
||||
return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath));
|
||||
return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
|
||||
return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);
|
||||
return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize {
|
||||
if (@hasDecl(@This(), "SYS_access")) {
|
||||
return syscall2(SYS_access, @ptrToInt(path), mode);
|
||||
} else {
|
||||
return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0);
|
||||
return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
|
||||
return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags);
|
||||
return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
|
||||
}
|
||||
|
||||
pub fn pipe(fd: *[2]i32) usize {
|
||||
@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {
|
||||
}
|
||||
|
||||
pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
|
||||
return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);
|
||||
return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
|
||||
}
|
||||
|
||||
pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
|
||||
return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);
|
||||
return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {
|
||||
if (@hasDecl(@This(), "SYS_rename")) {
|
||||
return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
|
||||
} else if (@hasDecl(@This(), "SYS_renameat")) {
|
||||
return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));
|
||||
return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
|
||||
} else {
|
||||
return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0);
|
||||
return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
|
||||
if (@hasDecl(@This(), "SYS_renameat")) {
|
||||
return syscall4(
|
||||
SYS_renameat,
|
||||
@bitCast(usize, isize(oldfd)),
|
||||
@bitCast(usize, @as(isize, oldfd)),
|
||||
@ptrToInt(old),
|
||||
@bitCast(usize, isize(newfd)),
|
||||
@bitCast(usize, @as(isize, newfd)),
|
||||
@ptrToInt(new),
|
||||
);
|
||||
} else {
|
||||
return syscall5(
|
||||
SYS_renameat2,
|
||||
@bitCast(usize, isize(oldfd)),
|
||||
@bitCast(usize, @as(isize, oldfd)),
|
||||
@ptrToInt(old),
|
||||
@bitCast(usize, isize(newfd)),
|
||||
@bitCast(usize, @as(isize, newfd)),
|
||||
@ptrToInt(new),
|
||||
0,
|
||||
);
|
||||
@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
|
||||
pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize {
|
||||
return syscall5(
|
||||
SYS_renameat2,
|
||||
@bitCast(usize, isize(oldfd)),
|
||||
@bitCast(usize, @as(isize, oldfd)),
|
||||
@ptrToInt(oldpath),
|
||||
@bitCast(usize, isize(newfd)),
|
||||
@bitCast(usize, @as(isize, newfd)),
|
||||
@ptrToInt(newpath),
|
||||
flags,
|
||||
);
|
||||
@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
|
||||
} else {
|
||||
return syscall4(
|
||||
SYS_openat,
|
||||
@bitCast(usize, isize(AT_FDCWD)),
|
||||
@bitCast(usize, @as(isize, AT_FDCWD)),
|
||||
@ptrToInt(path),
|
||||
flags,
|
||||
perm,
|
||||
@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize {
|
||||
// dirfd could be negative, for example AT_FDCWD is -100
|
||||
return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode);
|
||||
return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
|
||||
}
|
||||
|
||||
/// See also `clone` (from the arch-specific include)
|
||||
@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
|
||||
}
|
||||
|
||||
pub fn close(fd: i32) usize {
|
||||
return syscall1(SYS_close, @bitCast(usize, isize(fd)));
|
||||
return syscall1(SYS_close, @bitCast(usize, @as(isize, fd)));
|
||||
}
|
||||
|
||||
/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
|
||||
pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
|
||||
return syscall5(
|
||||
SYS__llseek,
|
||||
@bitCast(usize, isize(fd)),
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@truncate(usize, offset >> 32),
|
||||
@truncate(usize, offset),
|
||||
@ptrToInt(result),
|
||||
@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
|
||||
|
||||
/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
|
||||
pub fn lseek(fd: i32, offset: i64, whence: usize) usize {
|
||||
return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence);
|
||||
return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);
|
||||
}
|
||||
|
||||
pub fn exit(status: i32) noreturn {
|
||||
_ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
|
||||
_ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status)));
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub fn exit_group(status: i32) noreturn {
|
||||
_ = syscall1(SYS_exit_group, @bitCast(usize, isize(status)));
|
||||
_ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status)));
|
||||
unreachable;
|
||||
}
|
||||
|
||||
@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
|
||||
}
|
||||
|
||||
pub fn kill(pid: i32, sig: i32) usize {
|
||||
return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));
|
||||
return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize {
|
||||
if (@hasDecl(@This(), "SYS_unlink")) {
|
||||
return syscall1(SYS_unlink, @ptrToInt(path));
|
||||
} else {
|
||||
return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0);
|
||||
return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize {
|
||||
return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags);
|
||||
return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
|
||||
}
|
||||
|
||||
pub fn waitpid(pid: i32, status: *u32, flags: u32) usize {
|
||||
return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0);
|
||||
return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
|
||||
}
|
||||
|
||||
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 {
|
||||
const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
|
||||
const rc = f(clk_id, tp);
|
||||
switch (rc) {
|
||||
0, @bitCast(usize, isize(-EINVAL)) => return rc,
|
||||
0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
|
||||
return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
|
||||
}
|
||||
|
||||
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 {
|
||||
const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
|
||||
return f(clk, ts);
|
||||
}
|
||||
return @bitCast(usize, isize(-ENOSYS));
|
||||
return @bitCast(usize, @as(isize, -ENOSYS));
|
||||
}
|
||||
|
||||
pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
|
||||
return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
|
||||
return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
|
||||
}
|
||||
|
||||
pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
|
||||
return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
|
||||
return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
|
||||
}
|
||||
|
||||
pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
|
||||
@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize {
|
||||
|
||||
pub fn getuid() u32 {
|
||||
if (@hasDecl(@This(), "SYS_getuid32")) {
|
||||
return u32(syscall0(SYS_getuid32));
|
||||
return @as(u32, syscall0(SYS_getuid32));
|
||||
} else {
|
||||
return u32(syscall0(SYS_getuid));
|
||||
return @as(u32, syscall0(SYS_getuid));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getgid() u32 {
|
||||
if (@hasDecl(@This(), "SYS_getgid32")) {
|
||||
return u32(syscall0(SYS_getgid32));
|
||||
return @as(u32, syscall0(SYS_getgid32));
|
||||
} else {
|
||||
return u32(syscall0(SYS_getgid));
|
||||
return @as(u32, syscall0(SYS_getgid));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geteuid() u32 {
|
||||
if (@hasDecl(@This(), "SYS_geteuid32")) {
|
||||
return u32(syscall0(SYS_geteuid32));
|
||||
return @as(u32, syscall0(SYS_geteuid32));
|
||||
} else {
|
||||
return u32(syscall0(SYS_geteuid));
|
||||
return @as(u32, syscall0(SYS_geteuid));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getegid() u32 {
|
||||
if (@hasDecl(@This(), "SYS_getegid32")) {
|
||||
return u32(syscall0(SYS_getegid32));
|
||||
return @as(u32, syscall0(SYS_getegid32));
|
||||
} else {
|
||||
return u32(syscall0(SYS_getegid));
|
||||
return @as(u32, syscall0(SYS_getegid));
|
||||
}
|
||||
}
|
||||
|
||||
@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
|
||||
}
|
||||
|
||||
pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
|
||||
return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));
|
||||
return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
|
||||
}
|
||||
|
||||
pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
|
||||
return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));
|
||||
return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
|
||||
return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
|
||||
return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
|
||||
}
|
||||
|
||||
pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
|
||||
return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
|
||||
return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
|
||||
}
|
||||
|
||||
pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
|
||||
return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags);
|
||||
return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
|
||||
}
|
||||
|
||||
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
|
||||
// batch-send all messages up to the current message
|
||||
if (next_unsent < i) {
|
||||
const batch_size = i - next_unsent;
|
||||
const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
||||
const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
||||
if (getErrno(r) != 0) return next_unsent;
|
||||
if (r < batch_size) return next_unsent + r;
|
||||
}
|
||||
@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
|
||||
}
|
||||
if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
|
||||
const batch_size = kvlen - next_unsent;
|
||||
const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
||||
const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
||||
if (getErrno(r) != 0) return r;
|
||||
return next_unsent + r;
|
||||
}
|
||||
return kvlen;
|
||||
}
|
||||
return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags);
|
||||
return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags);
|
||||
}
|
||||
|
||||
pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
|
||||
return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len);
|
||||
return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
|
||||
}
|
||||
|
||||
pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
|
||||
return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags);
|
||||
return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
|
||||
}
|
||||
|
||||
pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
|
||||
return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
|
||||
return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
|
||||
}
|
||||
|
||||
pub fn shutdown(fd: i32, how: i32) usize {
|
||||
return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how)));
|
||||
return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
|
||||
}
|
||||
|
||||
pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
|
||||
return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len));
|
||||
return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
|
||||
}
|
||||
|
||||
pub fn listen(fd: i32, backlog: u32) usize {
|
||||
return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog);
|
||||
return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog);
|
||||
}
|
||||
|
||||
pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
|
||||
return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
|
||||
return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {
|
||||
return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags);
|
||||
return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
|
||||
}
|
||||
|
||||
pub fn fstat(fd: i32, stat_buf: *Stat) usize {
|
||||
if (@hasDecl(@This(), "SYS_fstat64")) {
|
||||
return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
|
||||
return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
|
||||
} else {
|
||||
return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
|
||||
return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
|
||||
}
|
||||
}
|
||||
|
||||
@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
|
||||
if (@hasDecl(@This(), "SYS_fstatat64")) {
|
||||
return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
||||
return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
||||
} else {
|
||||
return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
||||
return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
||||
}
|
||||
}
|
||||
|
||||
@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
|
||||
if (@hasDecl(@This(), "SYS_statx")) {
|
||||
return syscall5(
|
||||
SYS_statx,
|
||||
@bitCast(usize, isize(dirfd)),
|
||||
@bitCast(usize, @as(isize, dirfd)),
|
||||
@ptrToInt(path),
|
||||
flags,
|
||||
mask,
|
||||
@ptrToInt(statx_buf),
|
||||
);
|
||||
}
|
||||
return @bitCast(usize, isize(-ENOSYS));
|
||||
return @bitCast(usize, @as(isize, -ENOSYS));
|
||||
}
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265
|
||||
@ -959,7 +959,7 @@ pub fn sched_yield() usize {
|
||||
}
|
||||
|
||||
pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize {
|
||||
const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set));
|
||||
const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set));
|
||||
if (@bitCast(isize, rc) < 0) return rc;
|
||||
if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
|
||||
return 0;
|
||||
@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize {
|
||||
}
|
||||
|
||||
pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
|
||||
return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev));
|
||||
return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev));
|
||||
}
|
||||
|
||||
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
|
||||
pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {
|
||||
return syscall6(
|
||||
SYS_epoll_pwait,
|
||||
@bitCast(usize, isize(epoll_fd)),
|
||||
@bitCast(usize, @as(isize, epoll_fd)),
|
||||
@ptrToInt(events),
|
||||
@intCast(usize, maxevents),
|
||||
@bitCast(usize, isize(timeout)),
|
||||
@bitCast(usize, @as(isize, timeout)),
|
||||
@ptrToInt(sigmask),
|
||||
@sizeOf(sigset_t),
|
||||
);
|
||||
@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
|
||||
}
|
||||
|
||||
pub fn timerfd_create(clockid: i32, flags: u32) usize {
|
||||
return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags);
|
||||
return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
|
||||
}
|
||||
|
||||
pub const itimerspec = extern struct {
|
||||
@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct {
|
||||
};
|
||||
|
||||
pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
|
||||
return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value));
|
||||
return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value));
|
||||
}
|
||||
|
||||
pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
|
||||
return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
|
||||
return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
|
||||
}
|
||||
|
||||
pub fn unshare(flags: usize) usize {
|
||||
@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
|
||||
}
|
||||
|
||||
pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
|
||||
return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
|
||||
return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
|
||||
}
|
||||
|
||||
pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {
|
||||
return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args);
|
||||
return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
|
||||
}
|
||||
|
||||
test "" {
|
||||
|
@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize {
|
||||
pub nakedcc fn restore() void {
|
||||
return asm volatile ("svc #0"
|
||||
:
|
||||
: [number] "{r7}" (usize(SYS_sigreturn))
|
||||
: [number] "{r7}" (@as(usize, SYS_sigreturn))
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
@ -108,7 +108,7 @@ pub nakedcc fn restore() void {
|
||||
pub nakedcc fn restore_rt() void {
|
||||
return asm volatile ("svc #0"
|
||||
:
|
||||
: [number] "{r7}" (usize(SYS_rt_sigreturn))
|
||||
: [number] "{r7}" (@as(usize, SYS_rt_sigreturn))
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ pub const restore = restore_rt;
|
||||
pub nakedcc fn restore_rt() void {
|
||||
return asm volatile ("svc #0"
|
||||
:
|
||||
: [number] "{x8}" (usize(SYS_rt_sigreturn))
|
||||
: [number] "{x8}" (@as(usize, SYS_rt_sigreturn))
|
||||
: "memory", "cc"
|
||||
);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
|
||||
\\ sw $3, 4($4)
|
||||
\\ 2:
|
||||
: [ret] "={$2}" (-> usize)
|
||||
: [number] "{$2}" (usize(SYS_pipe))
|
||||
: [number] "{$2}" (@as(usize, SYS_pipe))
|
||||
: "memory", "cc", "$7"
|
||||
);
|
||||
}
|
||||
@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
|
||||
pub nakedcc fn restore() void {
|
||||
return asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{$2}" (usize(SYS_sigreturn))
|
||||
: [number] "{$2}" (@as(usize, SYS_sigreturn))
|
||||
: "memory", "cc", "$7"
|
||||
);
|
||||
}
|
||||
@ -155,7 +155,7 @@ pub nakedcc fn restore() void {
|
||||
pub nakedcc fn restore_rt() void {
|
||||
return asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{$2}" (usize(SYS_rt_sigreturn))
|
||||
: [number] "{$2}" (@as(usize, SYS_rt_sigreturn))
|
||||
: "memory", "cc", "$7"
|
||||
);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ pub const restore = restore_rt;
|
||||
pub nakedcc fn restore_rt() void {
|
||||
return asm volatile ("ecall"
|
||||
:
|
||||
: [number] "{x17}" (usize(SYS_rt_sigreturn))
|
||||
: [number] "{x17}" (@as(usize, SYS_rt_sigreturn))
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < hashtab[1]) : (i += 1) {
|
||||
if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
|
||||
if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
|
||||
if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
|
||||
if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
|
||||
if (0 == syms[i].st_shndx) continue;
|
||||
if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;
|
||||
if (maybe_versym) |versym| {
|
||||
|
@ -93,7 +93,7 @@ pub const restore = restore_rt;
|
||||
pub nakedcc fn restore_rt() void {
|
||||
return asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (usize(SYS_rt_sigreturn))
|
||||
: [number] "{rax}" (@as(usize, SYS_rt_sigreturn))
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {
|
||||
|
||||
var counter = data.?;
|
||||
// Count how many libraries are loaded
|
||||
counter.* += usize(1);
|
||||
counter.* += @as(usize, 1);
|
||||
|
||||
// The image should contain at least a PT_LOAD segment
|
||||
if (info.dlpi_phnum < 1) return -1;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user