Merge pull request #4231 from LemonBoy/more-builtin-work1

More patches for compiler-rt
This commit is contained in:
Andrew Kelley 2020-01-19 13:27:36 -05:00 committed by GitHub
commit e491b2f5a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 377 additions and 662 deletions

View File

@ -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;

View File

@ -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 });
@ -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 });
@ -226,20 +226,29 @@ 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/comparesf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .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/comparedf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .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 });
}
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;
}
@ -324,23 +322,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;

View File

@ -1,95 +0,0 @@
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
const ConditionalOperator = enum {
Eq,
Lt,
Le,
Ge,
Gt,
};
pub fn __aeabi_dcmpeq() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Eq});
unreachable;
}
pub fn __aeabi_dcmplt() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Lt});
unreachable;
}
pub fn __aeabi_dcmple() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Le});
unreachable;
}
pub fn __aeabi_dcmpge() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Ge});
unreachable;
}
pub fn __aeabi_dcmpgt() callconv(.Naked) noreturn {
@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 }
);
}

View File

@ -1,95 +0,0 @@
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
const ConditionalOperator = enum {
Eq,
Lt,
Le,
Ge,
Gt,
};
pub fn __aeabi_fcmpeq() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Eq});
unreachable;
}
pub fn __aeabi_fcmplt() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Lt});
unreachable;
}
pub fn __aeabi_fcmple() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Le});
unreachable;
}
pub fn __aeabi_fcmpge() callconv(.Naked) noreturn {
@setRuntimeSafety(false);
@call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Ge});
unreachable;
}
pub fn __aeabi_fcmpgt() callconv(.Naked) noreturn {
@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 }
);
}

View File

@ -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;
}

View File

@ -0,0 +1,253 @@
// 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 });
}
// 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 });
}
test "comparesf2" {
_ = @import("comparesf2_test.zig");
}
test "comparedf2" {
_ = @import("comparedf2_test.zig");
}

View File

@ -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");
}

View File

@ -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,

View File

@ -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");
}

View File

@ -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,

View File

@ -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);
}

View File

@ -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 });

View File

@ -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,