From fa52c9e36efde38f6d1c6e280636ba7f6cb6f83a Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 18 Jan 2020 18:11:20 +0100 Subject: [PATCH 1/7] Small cleanups --- lib/std/os/bits/linux.zig | 2 +- lib/std/special/compiler_rt/clzsi2.zig | 70 +++++++++++++------------- lib/std/start.zig | 13 +---- lib/std/target.zig | 38 ++++++++++++++ 4 files changed, 75 insertions(+), 48 deletions(-) diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 51ea49005e..f4024e1f1d 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -18,7 +18,7 @@ pub usingnamespace switch (builtin.arch) { else => struct {}, }; -const is_mips = builtin.arch == .mipsel; +const is_mips = builtin.arch.isMIPS(); pub const pid_t = i32; pub const fd_t = i32; diff --git a/lib/std/special/compiler_rt/clzsi2.zig b/lib/std/special/compiler_rt/clzsi2.zig index 0cbfdb8db1..6a69ae75f1 100644 --- a/lib/std/special/compiler_rt/clzsi2.zig +++ b/lib/std/special/compiler_rt/clzsi2.zig @@ -1,10 +1,5 @@ -// Ported from: -// -// https://github.com/llvm-mirror/compiler-rt/blob/f0745e8476f069296a7c71accedd061dce4cdf79/lib/builtins/clzsi2.c -// https://github.com/llvm-mirror/compiler-rt/blob/f0745e8476f069296a7c71accedd061dce4cdf79/lib/builtins/arm/clzsi2.S const builtin = @import("builtin"); -// Precondition: a != 0 fn __clzsi2_generic(a: i32) callconv(.C) i32 { @setRuntimeSafety(builtin.is_test); @@ -24,15 +19,42 @@ fn __clzsi2_generic(a: i32) callconv(.C) i32 { return n - @bitCast(i32, x); } -fn __clzsi2_arm_clz(a: i32) callconv(.Naked) noreturn { +fn __clzsi2_thumb1() callconv(.Naked) void { + @setRuntimeSafety(builtin.is_test); + + // Similar to the generic version with the last two rounds replaced by a LUT asm volatile ( - \\ clz r0,r0 + \\ movs r1, #32 + \\ lsrs r2, r0, #16 + \\ beq 1f + \\ subs r1, #16 + \\ movs r0, r2 + \\ 1: + \\ lsrs r2, r0, #8 + \\ beq 1f + \\ subs r1, #8 + \\ movs r0, r2 + \\ 1: + \\ lsrs r2, r0, #4 + \\ beq 1f + \\ subs r1, #4 + \\ movs r0, r2 + \\ 1: + \\ ldr r3, =LUT + \\ ldrb r0, [r3, r0] + \\ subs r0, r1, r0 \\ bx lr + \\ .p2align 2 + \\ LUT: + \\ .byte 4,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 ); + unreachable; } -fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { +fn __clzsi2_arm32() callconv(.Naked) void { + @setRuntimeSafety(builtin.is_test); + asm volatile ( \\ // Assumption: n != 0 \\ // r0: n @@ -75,39 +97,15 @@ fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { \\ sub r0, r1, r0, lsr #1 \\ bx lr ); + unreachable; } -const can_use_arm_clz = switch (builtin.arch) { - .arm, .armeb => |sub_arch| switch (sub_arch) { - .v4t => false, - .v6m => false, - else => true, - }, - .thumb, .thumbeb => |sub_arch| switch (sub_arch) { - .v6, - .v6k, - .v5, - .v5te, - .v4t, - => false, - else => true, - }, - else => false, -}; - -const is_arm32_no_thumb = switch (builtin.arch) { - builtin.Arch.arm, - builtin.Arch.armeb, - => true, - else => false, -}; - pub const __clzsi2 = blk: { - if (comptime can_use_arm_clz) { - break :blk __clzsi2_arm_clz; - } else if (comptime is_arm32_no_thumb) { + if (builtin.arch.isARM()) { break :blk __clzsi2_arm32; + } else if (builtin.arch.isThumb()) { + break :blk __clzsi2_thumb1; } else { break :blk __clzsi2_generic; } diff --git a/lib/std/start.zig b/lib/std/start.zig index c3844e4d1e..bf6f61f25f 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -8,16 +8,7 @@ const uefi = std.os.uefi; var starting_stack_ptr: [*]usize = undefined; -const is_wasm = switch (builtin.arch) { - .wasm32, .wasm64 => true, - else => false, -}; - -const is_mips = switch (builtin.arch) { - .mips, .mipsel, .mips64, .mips64el => true, - else => false, -}; -const start_sym_name = if (is_mips) "__start" else "_start"; +const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start"; comptime { if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { @@ -35,7 +26,7 @@ comptime { } } else if (builtin.os == .uefi) { if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); - } else if (is_wasm and builtin.os == .freestanding) { + } else if (builtin.arch.isWasm() and builtin.os == .freestanding) { if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name }); } else if (builtin.os != .other and builtin.os != .freestanding) { if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); diff --git a/lib/std/target.zig b/lib/std/target.zig index 22fea691c4..d62786ff7f 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -125,6 +125,16 @@ pub const Target = union(enum) { v5, v5te, v4t, + + pub fn version(version: Arm32) comptime_int { + return switch (version) { + .v8_5a, .v8_4a, .v8_3a, .v8_2a, .v8_1a, .v8, .v8r, .v8m_baseline, .v8m_mainline, .v8_1m_mainline => 8, + .v7, .v7em, .v7m, .v7s, .v7k, .v7ve => 7, + .v6, .v6m, .v6k, .v6t2 => 6, + .v5, .v5te => 5, + .v4t => 4, + }; + } }; pub const Arm64 = enum { v8_5a, @@ -146,6 +156,34 @@ pub const Target = union(enum) { r6, }; + pub fn isARM(arch: Arch) bool { + return switch (arch) { + .arm, .armeb => true, + else => false, + }; + } + + pub fn isThumb(arch: Arch) bool { + return switch (arch) { + .thumb, .thumbeb => true, + else => false, + }; + } + + pub fn isWasm(arch: Arch) bool { + return switch (arch) { + .wasm32, .wasm64 => true, + else => false, + }; + } + + pub fn isMIPS(arch: Arch) bool { + return switch (arch) { + .mips, .mipsel, .mips64, .mips64el => true, + else => false, + }; + } + pub fn toElfMachine(arch: Arch) std.elf.EM { return switch (arch) { .avr => ._AVR, From 7d94e712f125e10f234338e800953aa4837206ef Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 18 Jan 2020 23:05:17 +0100 Subject: [PATCH 2/7] Remove useless wrappers around f32/f64 aeabi builtins --- .../special/compiler_rt/arm/aeabi_dcmp.zig | 87 +++---------------- .../special/compiler_rt/arm/aeabi_fcmp.zig | 87 +++---------------- 2 files changed, 22 insertions(+), 152 deletions(-) diff --git a/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig b/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig index a8ed182901..47e7fac81a 100644 --- a/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig +++ b/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig @@ -2,94 +2,29 @@ // // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_dcmp.S -const ConditionalOperator = enum { - Eq, - Lt, - Le, - Ge, - Gt, -}; +const comparedf2 = @import("../comparedf2.zig"); -pub fn __aeabi_dcmpeq() callconv(.Naked) noreturn { +pub fn __aeabi_dcmpeq(a: f64, b: f64) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Eq}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__eqdf2, .{ a, b }) == 0); } -pub fn __aeabi_dcmplt() callconv(.Naked) noreturn { +pub fn __aeabi_dcmplt(a: f64, b: f64) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Lt}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__ltdf2, .{ a, b }) < 0); } -pub fn __aeabi_dcmple() callconv(.Naked) noreturn { +pub fn __aeabi_dcmple(a: f64, b: f64) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Le}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__ledf2, .{ a, b }) <= 0); } -pub fn __aeabi_dcmpge() callconv(.Naked) noreturn { +pub fn __aeabi_dcmpge(a: f64, b: f64) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Ge}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__gedf2, .{ a, b }) >= 0); } -pub fn __aeabi_dcmpgt() callconv(.Naked) noreturn { +pub fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Gt}); - unreachable; -} - -fn aeabi_dcmp(comptime cond: ConditionalOperator) void { - @setRuntimeSafety(false); - asm volatile ( - \\ push { r4, lr } - ); - - switch (cond) { - .Eq => asm volatile ( - \\ bl __eqdf2 - \\ cmp r0, #0 - \\ beq 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Lt => asm volatile ( - \\ bl __ltdf2 - \\ cmp r0, #0 - \\ blt 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Le => asm volatile ( - \\ bl __ledf2 - \\ cmp r0, #0 - \\ ble 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Ge => asm volatile ( - \\ bl __ltdf2 - \\ cmp r0, #0 - \\ bge 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Gt => asm volatile ( - \\ bl __gtdf2 - \\ cmp r0, #0 - \\ bgt 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - } - asm volatile ( - \\ movs r0, #1 - \\ pop { r4, pc } - ); + return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__gtdf2, .{ a, b }) > 0); } diff --git a/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig b/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig index 0b4c0f0d41..c53643b368 100644 --- a/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig +++ b/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig @@ -2,94 +2,29 @@ // // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_fcmp.S -const ConditionalOperator = enum { - Eq, - Lt, - Le, - Ge, - Gt, -}; +const comparesf2 = @import("../comparesf2.zig"); -pub fn __aeabi_fcmpeq() callconv(.Naked) noreturn { +pub fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Eq}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__eqsf2, .{ a, b }) == 0); } -pub fn __aeabi_fcmplt() callconv(.Naked) noreturn { +pub fn __aeabi_fcmplt(a: f32, b: f32) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Lt}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__ltsf2, .{ a, b }) < 0); } -pub fn __aeabi_fcmple() callconv(.Naked) noreturn { +pub fn __aeabi_fcmple(a: f32, b: f32) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Le}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__lesf2, .{ a, b }) <= 0); } -pub fn __aeabi_fcmpge() callconv(.Naked) noreturn { +pub fn __aeabi_fcmpge(a: f32, b: f32) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Ge}); - unreachable; + return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__gesf2, .{ a, b }) >= 0); } -pub fn __aeabi_fcmpgt() callconv(.Naked) noreturn { +pub fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.AAPCS) i32 { @setRuntimeSafety(false); - @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Gt}); - unreachable; -} - -fn aeabi_fcmp(comptime cond: ConditionalOperator) void { - @setRuntimeSafety(false); - asm volatile ( - \\ push { r4, lr } - ); - - switch (cond) { - .Eq => asm volatile ( - \\ bl __eqsf2 - \\ cmp r0, #0 - \\ beq 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Lt => asm volatile ( - \\ bl __ltsf2 - \\ cmp r0, #0 - \\ blt 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Le => asm volatile ( - \\ bl __lesf2 - \\ cmp r0, #0 - \\ ble 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Ge => asm volatile ( - \\ bl __ltsf2 - \\ cmp r0, #0 - \\ bge 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - .Gt => asm volatile ( - \\ bl __gtsf2 - \\ cmp r0, #0 - \\ bgt 1f - \\ movs r0, #0 - \\ pop { r4, pc } - \\ 1: - ), - } - asm volatile ( - \\ movs r0, #1 - \\ pop { r4, pc } - ); + return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__gtsf2, .{ a, b }) > 0); } From 6b056d1fb93bba68c03bda5039994d4df338ef13 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 18 Jan 2020 23:37:13 +0100 Subject: [PATCH 3/7] Nuke some repeated code --- lib/std/special/compiler_rt.zig | 52 +++--- lib/std/special/compiler_rt/compareXf2.zig | 201 +++++++++++++++++++++ lib/std/special/compiler_rt/comparedf2.zig | 127 ------------- lib/std/special/compiler_rt/comparesf2.zig | 127 ------------- lib/std/special/compiler_rt/comparetf2.zig | 99 ---------- 5 files changed, 227 insertions(+), 379 deletions(-) create mode 100644 lib/std/special/compiler_rt/compareXf2.zig delete mode 100644 lib/std/special/compiler_rt/comparedf2.zig delete mode 100644 lib/std/special/compiler_rt/comparesf2.zig delete mode 100644 lib/std/special/compiler_rt/comparetf2.zig diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 9b225dbad6..920707d1c4 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -16,42 +16,42 @@ comptime { else => {}, } - @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage }); - @export(@import("compiler_rt/comparesf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage }); if (!is_test) { - @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage }); - @export(@import("compiler_rt/comparesf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage }); - @export(@import("compiler_rt/comparesf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage }); - @export(@import("compiler_rt/comparesf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage }); - @export(@import("compiler_rt/comparesf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage }); @export(@import("compiler_rt/extendXfYf2.zig").__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = linkage }); @export(@import("compiler_rt/truncXfYf2.zig").__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = linkage }); } - @export(@import("compiler_rt/comparesf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage }); - @export(@import("compiler_rt/comparetf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage }); @export(@import("compiler_rt/addXf3.zig").__addsf3, .{ .name = "__addsf3", .linkage = linkage }); @export(@import("compiler_rt/addXf3.zig").__adddf3, .{ .name = "__adddf3", .linkage = linkage }); @@ -231,14 +231,14 @@ comptime { @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage }); - @export(@import("compiler_rt/comparesf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage }); @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage }); - @export(@import("compiler_rt/comparedf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); } if (builtin.os == .windows) { // Default stack-probe functions emitted by LLVM diff --git a/lib/std/special/compiler_rt/compareXf2.zig b/lib/std/special/compiler_rt/compareXf2.zig new file mode 100644 index 0000000000..3253abe871 --- /dev/null +++ b/lib/std/special/compiler_rt/compareXf2.zig @@ -0,0 +1,201 @@ +// Ported from: +// +// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c + +const std = @import("std"); +const builtin = @import("builtin"); + +const LE = extern enum(i32) { + Less = -1, + Equal = 0, + Greater = 1, + Unordered = 1, +}; + +const GE = extern enum(i32) { + Less = -1, + Equal = 0, + Greater = 1, + Unordered = -1, +}; + +pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT { + @setRuntimeSafety(builtin.is_test); + + const srep_t = @IntType(true, T.bit_count); + const rep_t = @IntType(false, T.bit_count); + + const significandBits = std.math.floatMantissaBits(T); + const exponentBits = std.math.floatExponentBits(T); + const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); + const absMask = signBit - 1; + const infRep = @bitCast(rep_t, std.math.inf(T)); + + const aInt = @bitCast(srep_t, a); + const bInt = @bitCast(srep_t, b); + const aAbs = @bitCast(rep_t, aInt) & absMask; + const bAbs = @bitCast(rep_t, bInt) & absMask; + + // If either a or b is NaN, they are unordered. + if (aAbs > infRep or bAbs > infRep) return .Unordered; + + // If a and b are both zeros, they are equal. + if ((aAbs | bAbs) == 0) return .Equal; + + // If at least one of a and b is positive, we get the same result comparing + // a and b as signed integers as we would with a fp_ting-point compare. + if ((aInt & bInt) >= 0) { + if (aInt < bInt) { + return .Less; + } else if (aInt == bInt) { + return .Equal; + } else return .Greater; + } + + // Otherwise, both are negative, so we need to flip the sense of the + // comparison to get the correct result. (This assumes a twos- or ones- + // complement integer representation; if integers are represented in a + // sign-magnitude representation, then this flip is incorrect). + else { + if (aInt > bInt) { + return .Less; + } else if (aInt == bInt) { + return .Equal; + } else return .Greater; + } +} + +pub fn unordcmp(comptime T: type, a: T, b: T) i32 { + @setRuntimeSafety(builtin.is_test); + + const rep_t = @IntType(false, T.bit_count); + + const significandBits = std.math.floatMantissaBits(T); + const exponentBits = std.math.floatExponentBits(T); + const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); + const absMask = signBit - 1; + const infRep = @bitCast(rep_t, std.math.inf(T)); + + const aAbs: rep_t = @bitCast(rep_t, a) & absMask; + const bAbs: rep_t = @bitCast(rep_t, b) & absMask; + + return @boolToInt(aAbs > infRep or bAbs > infRep); +} + +// Comparison between f32 + +pub fn __lesf2(a: f32, b: f32) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f32, LE, a, b })); +} + +pub fn __gesf2(a: f32, b: f32) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f32, GE, a, b })); +} + +pub fn __eqsf2(a: f32, b: f32) callconv(.C) i32 { + return __lesf2(a, b); +} + +pub fn __ltsf2(a: f32, b: f32) callconv(.C) i32 { + return __lesf2(a, b); +} + +pub fn __nesf2(a: f32, b: f32) callconv(.C) i32 { + return __lesf2(a, b); +} + +pub fn __gtsf2(a: f32, b: f32) callconv(.C) i32 { + return __gesf2(a, b); +} + +// Comparison between f64 + +pub fn __ledf2(a: f64, b: f64) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f64, LE, a, b })); +} + +pub fn __gedf2(a: f64, b: f64) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f64, GE, a, b })); +} + +pub fn __eqdf2(a: f64, b: f64) callconv(.C) i32 { + return __ledf2(a, b); +} + +pub fn __ltdf2(a: f64, b: f64) callconv(.C) i32 { + return __ledf2(a, b); +} + +pub fn __nedf2(a: f64, b: f64) callconv(.C) i32 { + return __ledf2(a, b); +} + +pub fn __gtdf2(a: f64, b: f64) callconv(.C) i32 { + return __gedf2(a, b); +} + +// Comparison between f128 + +pub fn __letf2(a: f128, b: f128) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f128, LE, a, b })); +} + +pub fn __getf2(a: f128, b: f128) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f128, GE, a, b })); +} + +pub fn __eqtf2(a: f128, b: f128) callconv(.C) i32 { + return __letf2(a, b); +} + +pub fn __lttf2(a: f128, b: f128) callconv(.C) i32 { + return __letf2(a, b); +} + +pub fn __netf2(a: f128, b: f128) callconv(.C) i32 { + return __letf2(a, b); +} + +pub fn __gttf2(a: f128, b: f128) callconv(.C) i32 { + return __getf2(a, b); +} + +// Unordered comparison between f32/f64/f128 + +pub fn __unordsf2(a: f32, b: f32) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @call(.{ .modifier = .always_inline }, unordcmp, .{ f32, a, b }); +} + +pub fn __unorddf2(a: f64, b: f64) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @call(.{ .modifier = .always_inline }, unordcmp, .{ f64, a, b }); +} + +pub fn __unordtf2(a: f128, b: f128) callconv(.C) i32 { + @setRuntimeSafety(builtin.is_test); + return @call(.{ .modifier = .always_inline }, unordcmp, .{ f128, a, b }); +} + +pub fn __aeabi_fcmpun(a: f32, b: f32) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b }); +} + +pub fn __aeabi_dcmpun(a: f64, b: f64) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b }); +} + +test "comparesf2" { + _ = @import("comparesf2_test.zig"); +} +test "comparedf2" { + _ = @import("comparedf2_test.zig"); +} diff --git a/lib/std/special/compiler_rt/comparedf2.zig b/lib/std/special/compiler_rt/comparedf2.zig deleted file mode 100644 index 98cca106f7..0000000000 --- a/lib/std/special/compiler_rt/comparedf2.zig +++ /dev/null @@ -1,127 +0,0 @@ -// Ported from: -// -// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparedf2.c - -const std = @import("std"); -const builtin = @import("builtin"); -const is_test = builtin.is_test; - -const fp_t = f64; -const rep_t = u64; -const srep_t = i64; - -const typeWidth = rep_t.bit_count; -const significandBits = std.math.floatMantissaBits(fp_t); -const exponentBits = std.math.floatExponentBits(fp_t); -const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); -const absMask = signBit - 1; -const implicitBit = @as(rep_t, 1) << significandBits; -const significandMask = implicitBit - 1; -const exponentMask = absMask ^ significandMask; -const infRep = @bitCast(rep_t, std.math.inf(fp_t)); - -// TODO https://github.com/ziglang/zig/issues/641 -// and then make the return types of some of these functions the enum instead of c_int -const LE_LESS = @as(c_int, -1); -const LE_EQUAL = @as(c_int, 0); -const LE_GREATER = @as(c_int, 1); -const LE_UNORDERED = @as(c_int, 1); - -pub fn __ledf2(a: fp_t, b: fp_t) callconv(.C) c_int { - @setRuntimeSafety(is_test); - const aInt: srep_t = @bitCast(srep_t, a); - const bInt: srep_t = @bitCast(srep_t, b); - const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; - const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; - - // If either a or b is NaN, they are unordered. - if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED; - - // If a and b are both zeros, they are equal. - if ((aAbs | bAbs) == 0) return LE_EQUAL; - - // If at least one of a and b is positive, we get the same result comparing - // a and b as signed integers as we would with a fp_ting-point compare. - if ((aInt & bInt) >= 0) { - if (aInt < bInt) { - return LE_LESS; - } else if (aInt == bInt) { - return LE_EQUAL; - } else return LE_GREATER; - } - - // Otherwise, both are negative, so we need to flip the sense of the - // comparison to get the correct result. (This assumes a twos- or ones- - // complement integer representation; if integers are represented in a - // sign-magnitude representation, then this flip is incorrect). - else { - if (aInt > bInt) { - return LE_LESS; - } else if (aInt == bInt) { - return LE_EQUAL; - } else return LE_GREATER; - } -} - -// TODO https://github.com/ziglang/zig/issues/641 -// and then make the return types of some of these functions the enum instead of c_int -const GE_LESS = @as(c_int, -1); -const GE_EQUAL = @as(c_int, 0); -const GE_GREATER = @as(c_int, 1); -const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED - -pub fn __gedf2(a: fp_t, b: fp_t) callconv(.C) c_int { - @setRuntimeSafety(is_test); - const aInt: srep_t = @bitCast(srep_t, a); - const bInt: srep_t = @bitCast(srep_t, b); - const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; - const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; - - if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; - if ((aAbs | bAbs) == 0) return GE_EQUAL; - if ((aInt & bInt) >= 0) { - if (aInt < bInt) { - return GE_LESS; - } else if (aInt == bInt) { - return GE_EQUAL; - } else return GE_GREATER; - } else { - if (aInt > bInt) { - return GE_LESS; - } else if (aInt == bInt) { - return GE_EQUAL; - } else return GE_GREATER; - } -} - -pub fn __unorddf2(a: fp_t, b: fp_t) callconv(.C) c_int { - @setRuntimeSafety(is_test); - const aAbs: rep_t = @bitCast(rep_t, a) & absMask; - const bAbs: rep_t = @bitCast(rep_t, b) & absMask; - return @boolToInt(aAbs > infRep or bAbs > infRep); -} - -pub fn __eqdf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __ledf2(a, b); -} - -pub fn __ltdf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __ledf2(a, b); -} - -pub fn __nedf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __ledf2(a, b); -} - -pub fn __gtdf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __gedf2(a, b); -} - -pub fn __aeabi_dcmpun(a: fp_t, b: fp_t) callconv(.AAPCS) c_int { - @setRuntimeSafety(false); - return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b }); -} - -test "import comparedf2" { - _ = @import("comparedf2_test.zig"); -} diff --git a/lib/std/special/compiler_rt/comparesf2.zig b/lib/std/special/compiler_rt/comparesf2.zig deleted file mode 100644 index bd881af2a1..0000000000 --- a/lib/std/special/compiler_rt/comparesf2.zig +++ /dev/null @@ -1,127 +0,0 @@ -// Ported from: -// -// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c - -const std = @import("std"); -const builtin = @import("builtin"); -const is_test = builtin.is_test; - -const fp_t = f32; -const rep_t = u32; -const srep_t = i32; - -const typeWidth = rep_t.bit_count; -const significandBits = std.math.floatMantissaBits(fp_t); -const exponentBits = std.math.floatExponentBits(fp_t); -const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); -const absMask = signBit - 1; -const implicitBit = @as(rep_t, 1) << significandBits; -const significandMask = implicitBit - 1; -const exponentMask = absMask ^ significandMask; -const infRep = @bitCast(rep_t, std.math.inf(fp_t)); - -// TODO https://github.com/ziglang/zig/issues/641 -// and then make the return types of some of these functions the enum instead of c_int -const LE_LESS = @as(c_int, -1); -const LE_EQUAL = @as(c_int, 0); -const LE_GREATER = @as(c_int, 1); -const LE_UNORDERED = @as(c_int, 1); - -pub fn __lesf2(a: fp_t, b: fp_t) callconv(.C) c_int { - @setRuntimeSafety(is_test); - const aInt: srep_t = @bitCast(srep_t, a); - const bInt: srep_t = @bitCast(srep_t, b); - const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; - const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; - - // If either a or b is NaN, they are unordered. - if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED; - - // If a and b are both zeros, they are equal. - if ((aAbs | bAbs) == 0) return LE_EQUAL; - - // If at least one of a and b is positive, we get the same result comparing - // a and b as signed integers as we would with a fp_ting-point compare. - if ((aInt & bInt) >= 0) { - if (aInt < bInt) { - return LE_LESS; - } else if (aInt == bInt) { - return LE_EQUAL; - } else return LE_GREATER; - } - - // Otherwise, both are negative, so we need to flip the sense of the - // comparison to get the correct result. (This assumes a twos- or ones- - // complement integer representation; if integers are represented in a - // sign-magnitude representation, then this flip is incorrect). - else { - if (aInt > bInt) { - return LE_LESS; - } else if (aInt == bInt) { - return LE_EQUAL; - } else return LE_GREATER; - } -} - -// TODO https://github.com/ziglang/zig/issues/641 -// and then make the return types of some of these functions the enum instead of c_int -const GE_LESS = @as(c_int, -1); -const GE_EQUAL = @as(c_int, 0); -const GE_GREATER = @as(c_int, 1); -const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED - -pub fn __gesf2(a: fp_t, b: fp_t) callconv(.C) c_int { - @setRuntimeSafety(is_test); - const aInt: srep_t = @bitCast(srep_t, a); - const bInt: srep_t = @bitCast(srep_t, b); - const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; - const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; - - if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; - if ((aAbs | bAbs) == 0) return GE_EQUAL; - if ((aInt & bInt) >= 0) { - if (aInt < bInt) { - return GE_LESS; - } else if (aInt == bInt) { - return GE_EQUAL; - } else return GE_GREATER; - } else { - if (aInt > bInt) { - return GE_LESS; - } else if (aInt == bInt) { - return GE_EQUAL; - } else return GE_GREATER; - } -} - -pub fn __unordsf2(a: fp_t, b: fp_t) callconv(.C) c_int { - @setRuntimeSafety(is_test); - const aAbs: rep_t = @bitCast(rep_t, a) & absMask; - const bAbs: rep_t = @bitCast(rep_t, b) & absMask; - return @boolToInt(aAbs > infRep or bAbs > infRep); -} - -pub fn __eqsf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __lesf2(a, b); -} - -pub fn __ltsf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __lesf2(a, b); -} - -pub fn __nesf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __lesf2(a, b); -} - -pub fn __gtsf2(a: fp_t, b: fp_t) callconv(.C) c_int { - return __gesf2(a, b); -} - -pub fn __aeabi_fcmpun(a: fp_t, b: fp_t) callconv(.AAPCS) c_int { - @setRuntimeSafety(false); - return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b }); -} - -test "import comparesf2" { - _ = @import("comparesf2_test.zig"); -} diff --git a/lib/std/special/compiler_rt/comparetf2.zig b/lib/std/special/compiler_rt/comparetf2.zig deleted file mode 100644 index f2969f2112..0000000000 --- a/lib/std/special/compiler_rt/comparetf2.zig +++ /dev/null @@ -1,99 +0,0 @@ -// TODO https://github.com/ziglang/zig/issues/641 -// and then make the return types of some of these functions the enum instead of c_int -const LE_LESS = @as(c_int, -1); -const LE_EQUAL = @as(c_int, 0); -const LE_GREATER = @as(c_int, 1); -const LE_UNORDERED = @as(c_int, 1); - -const rep_t = u128; -const srep_t = i128; - -const typeWidth = rep_t.bit_count; -const significandBits = 112; -const exponentBits = (typeWidth - significandBits - 1); -const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); -const absMask = signBit - 1; -const implicitBit = @as(rep_t, 1) << significandBits; -const significandMask = implicitBit - 1; -const exponentMask = absMask ^ significandMask; -const infRep = exponentMask; - -const builtin = @import("builtin"); -const is_test = builtin.is_test; - -pub fn __letf2(a: f128, b: f128) callconv(.C) c_int { - @setRuntimeSafety(is_test); - - const aInt = @bitCast(rep_t, a); - const bInt = @bitCast(rep_t, b); - - const aAbs: rep_t = aInt & absMask; - const bAbs: rep_t = bInt & absMask; - - // If either a or b is NaN, they are unordered. - if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED; - - // If a and b are both zeros, they are equal. - if ((aAbs | bAbs) == 0) return LE_EQUAL; - - // If at least one of a and b is positive, we get the same result comparing - // a and b as signed integers as we would with a floating-point compare. - return if ((aInt & bInt) >= 0) - if (aInt < bInt) - LE_LESS - else if (aInt == bInt) - LE_EQUAL - else - LE_GREATER - else - // Otherwise, both are negative, so we need to flip the sense of the - // comparison to get the correct result. (This assumes a twos- or ones- - // complement integer representation; if integers are represented in a - // sign-magnitude representation, then this flip is incorrect). - if (aInt > bInt) - LE_LESS - else if (aInt == bInt) - LE_EQUAL - else - LE_GREATER; -} - -// TODO https://github.com/ziglang/zig/issues/641 -// and then make the return types of some of these functions the enum instead of c_int -const GE_LESS = @as(c_int, -1); -const GE_EQUAL = @as(c_int, 0); -const GE_GREATER = @as(c_int, 1); -const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED - -pub fn __getf2(a: f128, b: f128) callconv(.C) c_int { - @setRuntimeSafety(is_test); - - const aInt = @bitCast(srep_t, a); - const bInt = @bitCast(srep_t, b); - const aAbs = @bitCast(rep_t, aInt) & absMask; - const bAbs = @bitCast(rep_t, bInt) & absMask; - - if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; - if ((aAbs | bAbs) == 0) return GE_EQUAL; - return if ((aInt & bInt) >= 0) - if (aInt < bInt) - GE_LESS - else if (aInt == bInt) - GE_EQUAL - else - GE_GREATER - else if (aInt > bInt) - GE_LESS - else if (aInt == bInt) - GE_EQUAL - else - GE_GREATER; -} - -pub fn __unordtf2(a: f128, b: f128) callconv(.C) c_int { - @setRuntimeSafety(is_test); - - const aAbs = @bitCast(rep_t, a) & absMask; - const bAbs = @bitCast(rep_t, b) & absMask; - return @boolToInt(aAbs > infRep or bAbs > infRep); -} From ae31da9334851dfca226ece1a66457d8df3e4abe Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 18 Jan 2020 23:40:58 +0100 Subject: [PATCH 4/7] Minor cleanup --- lib/std/special/compiler_rt.zig | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 920707d1c4..213348f0d0 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -148,7 +148,7 @@ comptime { @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage }); - if (is_arm_arch and !is_arm_64 and !is_test) { + if (builtin.arch.isARM() and !is_test) { @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage }); @@ -324,23 +324,3 @@ extern var __stack_chk_guard: usize = blk: { buf[@sizeOf(usize) - 2] = '\n'; break :blk @bitCast(usize, buf); }; - -const is_arm_64 = switch (builtin.arch) { - builtin.Arch.aarch64, - builtin.Arch.aarch64_be, - => true, - else => false, -}; - -const is_arm_arch = switch (builtin.arch) { - builtin.Arch.arm, - builtin.Arch.armeb, - builtin.Arch.aarch64, - builtin.Arch.aarch64_be, - builtin.Arch.thumb, - builtin.Arch.thumbeb, - => true, - else => false, -}; - -const is_arm_32 = is_arm_arch and !is_arm_64; From 3247fd7862bc5277a2c931f56b41f4f7c085611c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 18 Jan 2020 23:50:00 +0100 Subject: [PATCH 5/7] Export MSVC builtins inconditionally --- lib/std/special/compiler_rt.zig | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 213348f0d0..0867629091 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -240,6 +240,15 @@ comptime { @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage }); @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); } + + if (builtin.arch == .i386 and builtin.abi == .msvc) { + // Don't let LLVM apply the stdcall name mangling on those MSVC builtins + @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage }); + @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage }); + @export(@import("compiler_rt/aullrem.zig")._allrem, .{ .name = "\x01__allrem", .linkage = strong_linkage }); + @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage }); + } + if (builtin.os == .windows) { // Default stack-probe functions emitted by LLVM if (is_mingw) { @@ -258,13 +267,6 @@ comptime { switch (builtin.arch) { .i386 => { - // Don't let LLVM apply the stdcall name mangling on those MSVC - // builtin functions - @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage }); - @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage }); - @export(@import("compiler_rt/aullrem.zig")._allrem, .{ .name = "\x01__allrem", .linkage = strong_linkage }); - @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage }); - @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage }); @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage }); @export(@import("compiler_rt/multi3.zig").__multi3, .{ .name = "__multi3", .linkage = linkage }); @@ -299,16 +301,12 @@ comptime { @export(@import("compiler_rt/mulodi4.zig").__mulodi4, .{ .name = "__mulodi4", .linkage = linkage }); } -const std = @import("std"); -const assert = std.debug.assert; -const testing = std.testing; - // Avoid dragging in the runtime safety mechanisms into this .o file, // unless we're trying to test this file. pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { @setCold(true); if (is_test) { - std.debug.panic("{}", .{msg}); + @import("std").debug.panic("{}", .{msg}); } else { unreachable; } From 5fbc1c28121c1030de5ba8ca106a3dd8516cfd87 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 19 Jan 2020 00:10:42 +0100 Subject: [PATCH 6/7] Nuke some more code --- lib/std/special/compiler_rt.zig | 20 +++---- .../special/compiler_rt/arm/aeabi_dcmp.zig | 30 ----------- .../special/compiler_rt/arm/aeabi_fcmp.zig | 30 ----------- lib/std/special/compiler_rt/compareXf2.zig | 52 +++++++++++++++++++ 4 files changed, 62 insertions(+), 70 deletions(-) delete mode 100644 lib/std/special/compiler_rt/arm/aeabi_dcmp.zig delete mode 100644 lib/std/special/compiler_rt/arm/aeabi_fcmp.zig diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 0867629091..90dbf0cdf4 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -226,18 +226,18 @@ comptime { @export(@import("compiler_rt/divsf3.zig").__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage }); @export(@import("compiler_rt/divdf3.zig").__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage }); @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage }); - @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage }); @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); } diff --git a/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig b/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig deleted file mode 100644 index 47e7fac81a..0000000000 --- a/lib/std/special/compiler_rt/arm/aeabi_dcmp.zig +++ /dev/null @@ -1,30 +0,0 @@ -// Ported from: -// -// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_dcmp.S - -const comparedf2 = @import("../comparedf2.zig"); - -pub fn __aeabi_dcmpeq(a: f64, b: f64) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__eqdf2, .{ a, b }) == 0); -} - -pub fn __aeabi_dcmplt(a: f64, b: f64) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__ltdf2, .{ a, b }) < 0); -} - -pub fn __aeabi_dcmple(a: f64, b: f64) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__ledf2, .{ a, b }) <= 0); -} - -pub fn __aeabi_dcmpge(a: f64, b: f64) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__gedf2, .{ a, b }) >= 0); -} - -pub fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparedf2.__gtdf2, .{ a, b }) > 0); -} diff --git a/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig b/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig deleted file mode 100644 index c53643b368..0000000000 --- a/lib/std/special/compiler_rt/arm/aeabi_fcmp.zig +++ /dev/null @@ -1,30 +0,0 @@ -// Ported from: -// -// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_fcmp.S - -const comparesf2 = @import("../comparesf2.zig"); - -pub fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__eqsf2, .{ a, b }) == 0); -} - -pub fn __aeabi_fcmplt(a: f32, b: f32) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__ltsf2, .{ a, b }) < 0); -} - -pub fn __aeabi_fcmple(a: f32, b: f32) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__lesf2, .{ a, b }) <= 0); -} - -pub fn __aeabi_fcmpge(a: f32, b: f32) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__gesf2, .{ a, b }) >= 0); -} - -pub fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.AAPCS) i32 { - @setRuntimeSafety(false); - return @boolToInt(@call(.{ .modifier = .always_inline }, comparesf2.__gtsf2, .{ a, b }) > 0); -} diff --git a/lib/std/special/compiler_rt/compareXf2.zig b/lib/std/special/compiler_rt/compareXf2.zig index 3253abe871..15e49e3cc1 100644 --- a/lib/std/special/compiler_rt/compareXf2.zig +++ b/lib/std/special/compiler_rt/compareXf2.zig @@ -183,11 +183,63 @@ pub fn __unordtf2(a: f128, b: f128) callconv(.C) i32 { return @call(.{ .modifier = .always_inline }, unordcmp, .{ f128, a, b }); } +// ARM EABI intrinsics + +pub fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __eqsf2, .{ a, b }) == 0); +} + +pub fn __aeabi_fcmplt(a: f32, b: f32) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __ltsf2, .{ a, b }) < 0); +} + +pub fn __aeabi_fcmple(a: f32, b: f32) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __lesf2, .{ a, b }) <= 0); +} + +pub fn __aeabi_fcmpge(a: f32, b: f32) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __gesf2, .{ a, b }) >= 0); +} + +pub fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __gtsf2, .{ a, b }) > 0); +} + pub fn __aeabi_fcmpun(a: f32, b: f32) callconv(.AAPCS) i32 { @setRuntimeSafety(false); return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b }); } +pub fn __aeabi_dcmpeq(a: f64, b: f64) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __eqdf2, .{ a, b }) == 0); +} + +pub fn __aeabi_dcmplt(a: f64, b: f64) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __ltdf2, .{ a, b }) < 0); +} + +pub fn __aeabi_dcmple(a: f64, b: f64) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __ledf2, .{ a, b }) <= 0); +} + +pub fn __aeabi_dcmpge(a: f64, b: f64) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __gedf2, .{ a, b }) >= 0); +} + +pub fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.AAPCS) i32 { + @setRuntimeSafety(false); + return @boolToInt(@call(.{ .modifier = .always_inline }, __gtdf2, .{ a, b }) > 0); +} + pub fn __aeabi_dcmpun(a: f64, b: f64) callconv(.AAPCS) i32 { @setRuntimeSafety(false); return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b }); From 861724bcf045327204a32b0e97517c0004122434 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 19 Jan 2020 09:31:45 +0100 Subject: [PATCH 7/7] Fix some tests broken by the renamed files --- lib/std/special/compiler_rt/comparedf2_test.zig | 2 +- lib/std/special/compiler_rt/comparesf2_test.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/special/compiler_rt/comparedf2_test.zig b/lib/std/special/compiler_rt/comparedf2_test.zig index b0e5757ec0..16a2a258ce 100644 --- a/lib/std/special/compiler_rt/comparedf2_test.zig +++ b/lib/std/special/compiler_rt/comparedf2_test.zig @@ -6,7 +6,7 @@ const std = @import("std"); const builtin = @import("builtin"); const is_test = builtin.is_test; -const comparedf2 = @import("comparedf2.zig"); +const comparedf2 = @import("compareXf2.zig"); const TestVector = struct { a: f64, diff --git a/lib/std/special/compiler_rt/comparesf2_test.zig b/lib/std/special/compiler_rt/comparesf2_test.zig index d736988bfb..e3966c021b 100644 --- a/lib/std/special/compiler_rt/comparesf2_test.zig +++ b/lib/std/special/compiler_rt/comparesf2_test.zig @@ -6,7 +6,7 @@ const std = @import("std"); const builtin = @import("builtin"); const is_test = builtin.is_test; -const comparesf2 = @import("comparesf2.zig"); +const comparesf2 = @import("compareXf2.zig"); const TestVector = struct { a: f32,