From 60242e96dfd509eeb7a5746128410f471eb06dac Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 6 May 2019 21:39:02 +0200 Subject: [PATCH 1/5] Fix definition of epoll_* struct on non x86_64 arches --- std/os/linux.zig | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/std/os/linux.zig b/std/os/linux.zig index 8471a1861b..f39c184ffc 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -1390,17 +1390,19 @@ pub fn sched_getaffinity(pid: i32, set: []usize) usize { return syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), set.len * @sizeOf(usize), @ptrToInt(set.ptr)); } -pub const epoll_data = packed union { +pub const epoll_data = extern union { ptr: usize, fd: i32, @"u32": u32, @"u64": u64, }; -pub const epoll_event = packed struct { - events: u32, - data: epoll_data, -}; +// On x86_64 the structure is packed so that it matches the definition of its +// 32bit counterpart +pub const epoll_event = if (builtin.arch != .x86_64) + extern struct { events: u32, data: epoll_data } + else + packed struct { events: u32, data: epoll_data }; pub fn epoll_create() usize { return epoll_create1(0); From 939ec878a00803502f2e07347c09fa6736c5f44a Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 6 May 2019 21:41:08 +0200 Subject: [PATCH 2/5] Fix edge case in addXf3 The operands may be zero, use the wrapping operators and avoid a spurious integer-overflow error. --- std/special/compiler_rt/addXf3.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/special/compiler_rt/addXf3.zig b/std/special/compiler_rt/addXf3.zig index 3a70461eca..5852f3e50d 100644 --- a/std/special/compiler_rt/addXf3.zig +++ b/std/special/compiler_rt/addXf3.zig @@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T { const infRep = @bitCast(Z, std.math.inf(T)); // Detect if a or b is zero, infinity, or NaN. - if (aAbs - Z(1) >= infRep - Z(1) or - bAbs - Z(1) >= infRep - Z(1)) + if (aAbs -% Z(1) >= infRep - Z(1) or + bAbs -% Z(1) >= infRep - Z(1)) { // NaN + anything = qNaN if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit); From a3beda27fc9093b6d4d5538104d2704590d7cf2b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 6 May 2019 21:42:52 +0200 Subject: [PATCH 3/5] Add missing cast to usize --- std/io.zig | 2 +- std/zig/render.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/std/io.zig b/std/io.zig index 63809c99c9..1f363b47b1 100644 --- a/std/io.zig +++ b/std/io.zig @@ -290,7 +290,7 @@ pub fn readFileAllocAligned(allocator: *mem.Allocator, path: []const u8, comptim var file = try File.openRead(path); defer file.close(); - const size = try file.getEndPos(); + const size = try math.cast(usize, try file.getEndPos()); const buf = try allocator.alignedAlloc(u8, A, size); errdefer allocator.free(buf); diff --git a/std/zig/render.zig b/std/zig/render.zig index 74c1e2acfc..cabc4ea9ef 100644 --- a/std/zig/render.zig +++ b/std/zig/render.zig @@ -748,7 +748,7 @@ fn renderExpression( counting_stream.bytes_written = 0; var dummy_col: usize = 0; try renderExpression(allocator, &counting_stream.stream, tree, 0, &dummy_col, expr.*, Space.None); - const width = counting_stream.bytes_written; + const width = @intCast(usize, counting_stream.bytes_written); const col = i % row_size; column_widths[col] = std.math.max(column_widths[col], width); expr_widths[i] = width; From 94b504c9e41c84825708701a2bf7a3cc7bdca375 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 6 May 2019 21:43:34 +0200 Subject: [PATCH 4/5] Fix float comparison result in __aeabi_{f,d}cmp* --- std/special/compiler_rt/arm/aeabi_dcmp.zig | 2 +- std/special/compiler_rt/arm/aeabi_fcmp.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/std/special/compiler_rt/arm/aeabi_dcmp.zig b/std/special/compiler_rt/arm/aeabi_dcmp.zig index bf2e51b21e..a51d9854ce 100644 --- a/std/special/compiler_rt/arm/aeabi_dcmp.zig +++ b/std/special/compiler_rt/arm/aeabi_dcmp.zig @@ -87,7 +87,7 @@ inline fn aeabi_dcmp(comptime cond: ConditionalOperator) void { .Ge => asm volatile ( \\ bl __ltdf2 \\ cmp r0, #0 - \\ blt 1f + \\ bge 1f \\ movs r0, #0 \\ pop { r4, pc } \\ 1: diff --git a/std/special/compiler_rt/arm/aeabi_fcmp.zig b/std/special/compiler_rt/arm/aeabi_fcmp.zig index 192f7485f3..f82dd25270 100644 --- a/std/special/compiler_rt/arm/aeabi_fcmp.zig +++ b/std/special/compiler_rt/arm/aeabi_fcmp.zig @@ -87,7 +87,7 @@ inline fn aeabi_fcmp(comptime cond: ConditionalOperator) void { .Ge => asm volatile ( \\ bl __ltsf2 \\ cmp r0, #0 - \\ blt 1f + \\ bge 1f \\ movs r0, #0 \\ pop { r4, pc } \\ 1: From 4ab7b459dfea45d1dbdfe301eeb840eaa796a4e7 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 6 May 2019 21:48:10 +0200 Subject: [PATCH 5/5] Avoid endless recursion in __extendhfsf2 On some platforms the conversion ended up creating a dangerous recursive loop that ate all the stack. The conversion to f16 is also pointless since we're operating on the raw bits anyway. --- std/special/compiler_rt/extendXfYf2.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/std/special/compiler_rt/extendXfYf2.zig b/std/special/compiler_rt/extendXfYf2.zig index 099e27b74a..953072b9e3 100644 --- a/std/special/compiler_rt/extendXfYf2.zig +++ b/std/special/compiler_rt/extendXfYf2.zig @@ -3,20 +3,20 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; pub extern fn __extenddftf2(a: f64) f128 { - return extendXfYf2(f128, f64, a); + return extendXfYf2(f128, f64, @bitCast(u64, a)); } pub extern fn __extendsftf2(a: f32) f128 { - return extendXfYf2(f128, f32, a); + return extendXfYf2(f128, f32, @bitCast(u32, a)); } pub extern fn __extendhfsf2(a: u16) f32 { - return extendXfYf2(f32, f16, @bitCast(f16, a)); + return extendXfYf2(f32, f16, a); } const CHAR_BIT = 8; -inline fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t { +inline fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @typeInfo(src_t).Float.bits)) dst_t { const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits); const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits); const srcSigBits = std.math.floatMantissaBits(src_t);