| author | |
| committer | |
| log | e491b2f5a7af5bff98cf8fb7ce8ce8ab27dfb9bc |
| tree | a2b1389ae26b4983fab9cae910d80130765ed451 |
| parent | 7bb4c855ad3776d7f7d21f2bf1c5c93366205ff2 |
| parent | 861724bcf045327204a32b0e97517c0004122434 |
| signature |
More patches for compiler-rt13 files changed, 378 insertions(+), 663 deletions(-)
lib/std/os/bits/linux.zig+1-1| ... | ... | @@ -18,7 +18,7 @@ pub usingnamespace switch (builtin.arch) { |
| 18 | 18 | else => struct {}, |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | const is_mips = builtin.arch == .mipsel; | |
| 21 | const is_mips = builtin.arch.isMIPS(); | |
| 22 | 22 | |
| 23 | 23 | pub const pid_t = i32; |
| 24 | 24 | pub const fd_t = i32; |
lib/std/special/compiler_rt.zig+48-70| ... | ... | @@ -16,42 +16,42 @@ comptime { |
| 16 | 16 | else => {}, |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage }); | |
| 20 | @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage }); | |
| 21 | @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage }); | |
| 19 | @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage }); | |
| 20 | @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage }); | |
| 21 | @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage }); | |
| 22 | 22 | |
| 23 | @export(@import("compiler_rt/comparesf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage }); | |
| 24 | @export(@import("compiler_rt/comparedf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage }); | |
| 25 | @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage }); | |
| 23 | @export(@import("compiler_rt/compareXf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage }); | |
| 24 | @export(@import("compiler_rt/compareXf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage }); | |
| 25 | @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage }); | |
| 26 | 26 | |
| 27 | 27 | if (!is_test) { |
| 28 | @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage }); | |
| 29 | @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage }); | |
| 30 | @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage }); | |
| 28 | @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage }); | |
| 29 | @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage }); | |
| 30 | @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage }); | |
| 31 | 31 | |
| 32 | @export(@import("compiler_rt/comparesf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage }); | |
| 33 | @export(@import("compiler_rt/comparedf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage }); | |
| 34 | @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage }); | |
| 32 | @export(@import("compiler_rt/compareXf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage }); | |
| 33 | @export(@import("compiler_rt/compareXf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage }); | |
| 34 | @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage }); | |
| 35 | 35 | |
| 36 | @export(@import("compiler_rt/comparesf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage }); | |
| 37 | @export(@import("compiler_rt/comparedf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage }); | |
| 38 | @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage }); | |
| 36 | @export(@import("compiler_rt/compareXf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage }); | |
| 37 | @export(@import("compiler_rt/compareXf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage }); | |
| 38 | @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage }); | |
| 39 | 39 | |
| 40 | @export(@import("compiler_rt/comparesf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage }); | |
| 41 | @export(@import("compiler_rt/comparedf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage }); | |
| 42 | @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage }); | |
| 40 | @export(@import("compiler_rt/compareXf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage }); | |
| 41 | @export(@import("compiler_rt/compareXf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage }); | |
| 42 | @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage }); | |
| 43 | 43 | |
| 44 | @export(@import("compiler_rt/comparesf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage }); | |
| 45 | @export(@import("compiler_rt/comparedf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage }); | |
| 46 | @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage }); | |
| 44 | @export(@import("compiler_rt/compareXf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage }); | |
| 45 | @export(@import("compiler_rt/compareXf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage }); | |
| 46 | @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage }); | |
| 47 | 47 | |
| 48 | 48 | @export(@import("compiler_rt/extendXfYf2.zig").__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = linkage }); |
| 49 | 49 | @export(@import("compiler_rt/truncXfYf2.zig").__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = linkage }); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | @export(@import("compiler_rt/comparesf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage }); | |
| 53 | @export(@import("compiler_rt/comparedf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage }); | |
| 54 | @export(@import("compiler_rt/comparetf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage }); | |
| 52 | @export(@import("compiler_rt/compareXf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage }); | |
| 53 | @export(@import("compiler_rt/compareXf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage }); | |
| 54 | @export(@import("compiler_rt/compareXf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage }); | |
| 55 | 55 | |
| 56 | 56 | @export(@import("compiler_rt/addXf3.zig").__addsf3, .{ .name = "__addsf3", .linkage = linkage }); |
| 57 | 57 | @export(@import("compiler_rt/addXf3.zig").__adddf3, .{ .name = "__adddf3", .linkage = linkage }); |
| ... | ... | @@ -148,7 +148,7 @@ comptime { |
| 148 | 148 | |
| 149 | 149 | @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage }); |
| 150 | 150 | |
| 151 | if (is_arm_arch and !is_arm_64 and !is_test) { | |
| 151 | if (builtin.arch.isARM() and !is_test) { | |
| 152 | 152 | @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage }); |
| 153 | 153 | @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage }); |
| 154 | 154 | @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage }); |
| ... | ... | @@ -226,20 +226,29 @@ comptime { |
| 226 | 226 | @export(@import("compiler_rt/divsf3.zig").__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage }); |
| 227 | 227 | @export(@import("compiler_rt/divdf3.zig").__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage }); |
| 228 | 228 | |
| 229 | @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage }); | |
| 230 | @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage }); | |
| 231 | @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage }); | |
| 232 | @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage }); | |
| 233 | @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage }); | |
| 234 | @export(@import("compiler_rt/comparesf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage }); | |
| 235 | ||
| 236 | @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage }); | |
| 237 | @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage }); | |
| 238 | @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage }); | |
| 239 | @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage }); | |
| 240 | @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage }); | |
| 241 | @export(@import("compiler_rt/comparedf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); | |
| 229 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage }); | |
| 230 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage }); | |
| 231 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage }); | |
| 232 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage }); | |
| 233 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage }); | |
| 234 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage }); | |
| 235 | ||
| 236 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage }); | |
| 237 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage }); | |
| 238 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage }); | |
| 239 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage }); | |
| 240 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage }); | |
| 241 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); | |
| 242 | 242 | } |
| 243 | ||
| 244 | if (builtin.arch == .i386 and builtin.abi == .msvc) { | |
| 245 | // Don't let LLVM apply the stdcall name mangling on those MSVC builtins | |
| 246 | @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage }); | |
| 247 | @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage }); | |
| 248 | @export(@import("compiler_rt/aullrem.zig")._allrem, .{ .name = "\x01__allrem", .linkage = strong_linkage }); | |
| 249 | @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage }); | |
| 250 | } | |
| 251 | ||
| 243 | 252 | if (builtin.os == .windows) { |
| 244 | 253 | // Default stack-probe functions emitted by LLVM |
| 245 | 254 | if (is_mingw) { |
| ... | ... | @@ -258,13 +267,6 @@ comptime { |
| 258 | 267 | |
| 259 | 268 | switch (builtin.arch) { |
| 260 | 269 | .i386 => { |
| 261 | // Don't let LLVM apply the stdcall name mangling on those MSVC | |
| 262 | // builtin functions | |
| 263 | @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage }); | |
| 264 | @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage }); | |
| 265 | @export(@import("compiler_rt/aullrem.zig")._allrem, .{ .name = "\x01__allrem", .linkage = strong_linkage }); | |
| 266 | @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage }); | |
| 267 | ||
| 268 | 270 | @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage }); |
| 269 | 271 | @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage }); |
| 270 | 272 | @export(@import("compiler_rt/multi3.zig").__multi3, .{ .name = "__multi3", .linkage = linkage }); |
| ... | ... | @@ -299,16 +301,12 @@ comptime { |
| 299 | 301 | @export(@import("compiler_rt/mulodi4.zig").__mulodi4, .{ .name = "__mulodi4", .linkage = linkage }); |
| 300 | 302 | } |
| 301 | 303 | |
| 302 | const std = @import("std"); | |
| 303 | const assert = std.debug.assert; | |
| 304 | const testing = std.testing; | |
| 305 | ||
| 306 | 304 | // Avoid dragging in the runtime safety mechanisms into this .o file, |
| 307 | 305 | // unless we're trying to test this file. |
| 308 | 306 | pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 309 | 307 | @setCold(true); |
| 310 | 308 | if (is_test) { |
| 311 | std.debug.panic("{}", .{msg}); | |
| 309 | @import("std").debug.panic("{}", .{msg}); | |
| 312 | 310 | } else { |
| 313 | 311 | unreachable; |
| 314 | 312 | } |
| ... | ... | @@ -324,23 +322,3 @@ extern var __stack_chk_guard: usize = blk: { |
| 324 | 322 | buf[@sizeOf(usize) - 2] = '\n'; |
| 325 | 323 | break :blk @bitCast(usize, buf); |
| 326 | 324 | }; |
| 327 | ||
| 328 | const is_arm_64 = switch (builtin.arch) { | |
| 329 | builtin.Arch.aarch64, | |
| 330 | builtin.Arch.aarch64_be, | |
| 331 | => true, | |
| 332 | else => false, | |
| 333 | }; | |
| 334 | ||
| 335 | const is_arm_arch = switch (builtin.arch) { | |
| 336 | builtin.Arch.arm, | |
| 337 | builtin.Arch.armeb, | |
| 338 | builtin.Arch.aarch64, | |
| 339 | builtin.Arch.aarch64_be, | |
| 340 | builtin.Arch.thumb, | |
| 341 | builtin.Arch.thumbeb, | |
| 342 | => true, | |
| 343 | else => false, | |
| 344 | }; | |
| 345 | ||
| 346 | const is_arm_32 = is_arm_arch and !is_arm_64; |
lib/std/special/compiler_rt/arm/aeabi_dcmp.zig deleted-95| ... | ... | @@ -1,95 +0,0 @@ |
| 1 | // Ported from: | |
| 2 | // | |
| 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_dcmp.S | |
| 4 | ||
| 5 | const ConditionalOperator = enum { | |
| 6 | Eq, | |
| 7 | Lt, | |
| 8 | Le, | |
| 9 | Ge, | |
| 10 | Gt, | |
| 11 | }; | |
| 12 | ||
| 13 | pub fn __aeabi_dcmpeq() callconv(.Naked) noreturn { | |
| 14 | @setRuntimeSafety(false); | |
| 15 | @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Eq}); | |
| 16 | unreachable; | |
| 17 | } | |
| 18 | ||
| 19 | pub fn __aeabi_dcmplt() callconv(.Naked) noreturn { | |
| 20 | @setRuntimeSafety(false); | |
| 21 | @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Lt}); | |
| 22 | unreachable; | |
| 23 | } | |
| 24 | ||
| 25 | pub fn __aeabi_dcmple() callconv(.Naked) noreturn { | |
| 26 | @setRuntimeSafety(false); | |
| 27 | @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Le}); | |
| 28 | unreachable; | |
| 29 | } | |
| 30 | ||
| 31 | pub fn __aeabi_dcmpge() callconv(.Naked) noreturn { | |
| 32 | @setRuntimeSafety(false); | |
| 33 | @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Ge}); | |
| 34 | unreachable; | |
| 35 | } | |
| 36 | ||
| 37 | pub fn __aeabi_dcmpgt() callconv(.Naked) noreturn { | |
| 38 | @setRuntimeSafety(false); | |
| 39 | @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Gt}); | |
| 40 | unreachable; | |
| 41 | } | |
| 42 | ||
| 43 | fn aeabi_dcmp(comptime cond: ConditionalOperator) void { | |
| 44 | @setRuntimeSafety(false); | |
| 45 | asm volatile ( | |
| 46 | \\ push { r4, lr } | |
| 47 | ); | |
| 48 | ||
| 49 | switch (cond) { | |
| 50 | .Eq => asm volatile ( | |
| 51 | \\ bl __eqdf2 | |
| 52 | \\ cmp r0, #0 | |
| 53 | \\ beq 1f | |
| 54 | \\ movs r0, #0 | |
| 55 | \\ pop { r4, pc } | |
| 56 | \\ 1: | |
| 57 | ), | |
| 58 | .Lt => asm volatile ( | |
| 59 | \\ bl __ltdf2 | |
| 60 | \\ cmp r0, #0 | |
| 61 | \\ blt 1f | |
| 62 | \\ movs r0, #0 | |
| 63 | \\ pop { r4, pc } | |
| 64 | \\ 1: | |
| 65 | ), | |
| 66 | .Le => asm volatile ( | |
| 67 | \\ bl __ledf2 | |
| 68 | \\ cmp r0, #0 | |
| 69 | \\ ble 1f | |
| 70 | \\ movs r0, #0 | |
| 71 | \\ pop { r4, pc } | |
| 72 | \\ 1: | |
| 73 | ), | |
| 74 | .Ge => asm volatile ( | |
| 75 | \\ bl __ltdf2 | |
| 76 | \\ cmp r0, #0 | |
| 77 | \\ bge 1f | |
| 78 | \\ movs r0, #0 | |
| 79 | \\ pop { r4, pc } | |
| 80 | \\ 1: | |
| 81 | ), | |
| 82 | .Gt => asm volatile ( | |
| 83 | \\ bl __gtdf2 | |
| 84 | \\ cmp r0, #0 | |
| 85 | \\ bgt 1f | |
| 86 | \\ movs r0, #0 | |
| 87 | \\ pop { r4, pc } | |
| 88 | \\ 1: | |
| 89 | ), | |
| 90 | } | |
| 91 | asm volatile ( | |
| 92 | \\ movs r0, #1 | |
| 93 | \\ pop { r4, pc } | |
| 94 | ); | |
| 95 | } |
lib/std/special/compiler_rt/arm/aeabi_fcmp.zig deleted-95| ... | ... | @@ -1,95 +0,0 @@ |
| 1 | // Ported from: | |
| 2 | // | |
| 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/arm/aeabi_fcmp.S | |
| 4 | ||
| 5 | const ConditionalOperator = enum { | |
| 6 | Eq, | |
| 7 | Lt, | |
| 8 | Le, | |
| 9 | Ge, | |
| 10 | Gt, | |
| 11 | }; | |
| 12 | ||
| 13 | pub fn __aeabi_fcmpeq() callconv(.Naked) noreturn { | |
| 14 | @setRuntimeSafety(false); | |
| 15 | @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Eq}); | |
| 16 | unreachable; | |
| 17 | } | |
| 18 | ||
| 19 | pub fn __aeabi_fcmplt() callconv(.Naked) noreturn { | |
| 20 | @setRuntimeSafety(false); | |
| 21 | @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Lt}); | |
| 22 | unreachable; | |
| 23 | } | |
| 24 | ||
| 25 | pub fn __aeabi_fcmple() callconv(.Naked) noreturn { | |
| 26 | @setRuntimeSafety(false); | |
| 27 | @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Le}); | |
| 28 | unreachable; | |
| 29 | } | |
| 30 | ||
| 31 | pub fn __aeabi_fcmpge() callconv(.Naked) noreturn { | |
| 32 | @setRuntimeSafety(false); | |
| 33 | @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Ge}); | |
| 34 | unreachable; | |
| 35 | } | |
| 36 | ||
| 37 | pub fn __aeabi_fcmpgt() callconv(.Naked) noreturn { | |
| 38 | @setRuntimeSafety(false); | |
| 39 | @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Gt}); | |
| 40 | unreachable; | |
| 41 | } | |
| 42 | ||
| 43 | fn aeabi_fcmp(comptime cond: ConditionalOperator) void { | |
| 44 | @setRuntimeSafety(false); | |
| 45 | asm volatile ( | |
| 46 | \\ push { r4, lr } | |
| 47 | ); | |
| 48 | ||
| 49 | switch (cond) { | |
| 50 | .Eq => asm volatile ( | |
| 51 | \\ bl __eqsf2 | |
| 52 | \\ cmp r0, #0 | |
| 53 | \\ beq 1f | |
| 54 | \\ movs r0, #0 | |
| 55 | \\ pop { r4, pc } | |
| 56 | \\ 1: | |
| 57 | ), | |
| 58 | .Lt => asm volatile ( | |
| 59 | \\ bl __ltsf2 | |
| 60 | \\ cmp r0, #0 | |
| 61 | \\ blt 1f | |
| 62 | \\ movs r0, #0 | |
| 63 | \\ pop { r4, pc } | |
| 64 | \\ 1: | |
| 65 | ), | |
| 66 | .Le => asm volatile ( | |
| 67 | \\ bl __lesf2 | |
| 68 | \\ cmp r0, #0 | |
| 69 | \\ ble 1f | |
| 70 | \\ movs r0, #0 | |
| 71 | \\ pop { r4, pc } | |
| 72 | \\ 1: | |
| 73 | ), | |
| 74 | .Ge => asm volatile ( | |
| 75 | \\ bl __ltsf2 | |
| 76 | \\ cmp r0, #0 | |
| 77 | \\ bge 1f | |
| 78 | \\ movs r0, #0 | |
| 79 | \\ pop { r4, pc } | |
| 80 | \\ 1: | |
| 81 | ), | |
| 82 | .Gt => asm volatile ( | |
| 83 | \\ bl __gtsf2 | |
| 84 | \\ cmp r0, #0 | |
| 85 | \\ bgt 1f | |
| 86 | \\ movs r0, #0 | |
| 87 | \\ pop { r4, pc } | |
| 88 | \\ 1: | |
| 89 | ), | |
| 90 | } | |
| 91 | asm volatile ( | |
| 92 | \\ movs r0, #1 | |
| 93 | \\ pop { r4, pc } | |
| 94 | ); | |
| 95 | } |
lib/std/special/compiler_rt/clzsi2.zig+34-36| ... | ... | @@ -1,10 +1,5 @@ |
| 1 | // Ported from: | |
| 2 | // | |
| 3 | // https://github.com/llvm-mirror/compiler-rt/blob/f0745e8476f069296a7c71accedd061dce4cdf79/lib/builtins/clzsi2.c | |
| 4 | // https://github.com/llvm-mirror/compiler-rt/blob/f0745e8476f069296a7c71accedd061dce4cdf79/lib/builtins/arm/clzsi2.S | |
| 5 | 1 | const builtin = @import("builtin"); |
| 6 | 2 | |
| 7 | // Precondition: a != 0 | |
| 8 | 3 | fn __clzsi2_generic(a: i32) callconv(.C) i32 { |
| 9 | 4 | @setRuntimeSafety(builtin.is_test); |
| 10 | 5 | |
| ... | ... | @@ -24,15 +19,42 @@ fn __clzsi2_generic(a: i32) callconv(.C) i32 { |
| 24 | 19 | return n - @bitCast(i32, x); |
| 25 | 20 | } |
| 26 | 21 | |
| 27 | fn __clzsi2_arm_clz(a: i32) callconv(.Naked) noreturn { | |
| 22 | fn __clzsi2_thumb1() callconv(.Naked) void { | |
| 23 | @setRuntimeSafety(builtin.is_test); | |
| 24 | ||
| 25 | // Similar to the generic version with the last two rounds replaced by a LUT | |
| 28 | 26 | asm volatile ( |
| 29 | \\ clz r0,r0 | |
| 27 | \\ movs r1, #32 | |
| 28 | \\ lsrs r2, r0, #16 | |
| 29 | \\ beq 1f | |
| 30 | \\ subs r1, #16 | |
| 31 | \\ movs r0, r2 | |
| 32 | \\ 1: | |
| 33 | \\ lsrs r2, r0, #8 | |
| 34 | \\ beq 1f | |
| 35 | \\ subs r1, #8 | |
| 36 | \\ movs r0, r2 | |
| 37 | \\ 1: | |
| 38 | \\ lsrs r2, r0, #4 | |
| 39 | \\ beq 1f | |
| 40 | \\ subs r1, #4 | |
| 41 | \\ movs r0, r2 | |
| 42 | \\ 1: | |
| 43 | \\ ldr r3, =LUT | |
| 44 | \\ ldrb r0, [r3, r0] | |
| 45 | \\ subs r0, r1, r0 | |
| 30 | 46 | \\ bx lr |
| 47 | \\ .p2align 2 | |
| 48 | \\ LUT: | |
| 49 | \\ .byte 4,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 | |
| 31 | 50 | ); |
| 51 | ||
| 32 | 52 | unreachable; |
| 33 | 53 | } |
| 34 | 54 | |
| 35 | fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { | |
| 55 | fn __clzsi2_arm32() callconv(.Naked) void { | |
| 56 | @setRuntimeSafety(builtin.is_test); | |
| 57 | ||
| 36 | 58 | asm volatile ( |
| 37 | 59 | \\ // Assumption: n != 0 |
| 38 | 60 | \\ // r0: n |
| ... | ... | @@ -75,39 +97,15 @@ fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { |
| 75 | 97 | \\ sub r0, r1, r0, lsr #1 |
| 76 | 98 | \\ bx lr |
| 77 | 99 | ); |
| 100 | ||
| 78 | 101 | unreachable; |
| 79 | 102 | } |
| 80 | 103 | |
| 81 | const can_use_arm_clz = switch (builtin.arch) { | |
| 82 | .arm, .armeb => |sub_arch| switch (sub_arch) { | |
| 83 | .v4t => false, | |
| 84 | .v6m => false, | |
| 85 | else => true, | |
| 86 | }, | |
| 87 | .thumb, .thumbeb => |sub_arch| switch (sub_arch) { | |
| 88 | .v6, | |
| 89 | .v6k, | |
| 90 | .v5, | |
| 91 | .v5te, | |
| 92 | .v4t, | |
| 93 | => false, | |
| 94 | else => true, | |
| 95 | }, | |
| 96 | else => false, | |
| 97 | }; | |
| 98 | ||
| 99 | const is_arm32_no_thumb = switch (builtin.arch) { | |
| 100 | builtin.Arch.arm, | |
| 101 | builtin.Arch.armeb, | |
| 102 | => true, | |
| 103 | else => false, | |
| 104 | }; | |
| 105 | ||
| 106 | 104 | pub const __clzsi2 = blk: { |
| 107 | if (comptime can_use_arm_clz) { | |
| 108 | break :blk __clzsi2_arm_clz; | |
| 109 | } else if (comptime is_arm32_no_thumb) { | |
| 105 | if (builtin.arch.isARM()) { | |
| 110 | 106 | break :blk __clzsi2_arm32; |
| 107 | } else if (builtin.arch.isThumb()) { | |
| 108 | break :blk __clzsi2_thumb1; | |
| 111 | 109 | } else { |
| 112 | 110 | break :blk __clzsi2_generic; |
| 113 | 111 | } |
lib/std/special/compiler_rt/compareXf2.zig created+253| ... | ... | @@ -0,0 +1,253 @@ |
| 1 | // Ported from: | |
| 2 | // | |
| 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c | |
| 4 | ||
| 5 | const std = @import("std"); | |
| 6 | const builtin = @import("builtin"); | |
| 7 | ||
| 8 | const LE = extern enum(i32) { | |
| 9 | Less = -1, | |
| 10 | Equal = 0, | |
| 11 | Greater = 1, | |
| 12 | Unordered = 1, | |
| 13 | }; | |
| 14 | ||
| 15 | const GE = extern enum(i32) { | |
| 16 | Less = -1, | |
| 17 | Equal = 0, | |
| 18 | Greater = 1, | |
| 19 | Unordered = -1, | |
| 20 | }; | |
| 21 | ||
| 22 | pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT { | |
| 23 | @setRuntimeSafety(builtin.is_test); | |
| 24 | ||
| 25 | const srep_t = @IntType(true, T.bit_count); | |
| 26 | const rep_t = @IntType(false, T.bit_count); | |
| 27 | ||
| 28 | const significandBits = std.math.floatMantissaBits(T); | |
| 29 | const exponentBits = std.math.floatExponentBits(T); | |
| 30 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 31 | const absMask = signBit - 1; | |
| 32 | const infRep = @bitCast(rep_t, std.math.inf(T)); | |
| 33 | ||
| 34 | const aInt = @bitCast(srep_t, a); | |
| 35 | const bInt = @bitCast(srep_t, b); | |
| 36 | const aAbs = @bitCast(rep_t, aInt) & absMask; | |
| 37 | const bAbs = @bitCast(rep_t, bInt) & absMask; | |
| 38 | ||
| 39 | // If either a or b is NaN, they are unordered. | |
| 40 | if (aAbs > infRep or bAbs > infRep) return .Unordered; | |
| 41 | ||
| 42 | // If a and b are both zeros, they are equal. | |
| 43 | if ((aAbs | bAbs) == 0) return .Equal; | |
| 44 | ||
| 45 | // If at least one of a and b is positive, we get the same result comparing | |
| 46 | // a and b as signed integers as we would with a fp_ting-point compare. | |
| 47 | if ((aInt & bInt) >= 0) { | |
| 48 | if (aInt < bInt) { | |
| 49 | return .Less; | |
| 50 | } else if (aInt == bInt) { | |
| 51 | return .Equal; | |
| 52 | } else return .Greater; | |
| 53 | } | |
| 54 | ||
| 55 | // Otherwise, both are negative, so we need to flip the sense of the | |
| 56 | // comparison to get the correct result. (This assumes a twos- or ones- | |
| 57 | // complement integer representation; if integers are represented in a | |
| 58 | // sign-magnitude representation, then this flip is incorrect). | |
| 59 | else { | |
| 60 | if (aInt > bInt) { | |
| 61 | return .Less; | |
| 62 | } else if (aInt == bInt) { | |
| 63 | return .Equal; | |
| 64 | } else return .Greater; | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | pub fn unordcmp(comptime T: type, a: T, b: T) i32 { | |
| 69 | @setRuntimeSafety(builtin.is_test); | |
| 70 | ||
| 71 | const rep_t = @IntType(false, T.bit_count); | |
| 72 | ||
| 73 | const significandBits = std.math.floatMantissaBits(T); | |
| 74 | const exponentBits = std.math.floatExponentBits(T); | |
| 75 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 76 | const absMask = signBit - 1; | |
| 77 | const infRep = @bitCast(rep_t, std.math.inf(T)); | |
| 78 | ||
| 79 | const aAbs: rep_t = @bitCast(rep_t, a) & absMask; | |
| 80 | const bAbs: rep_t = @bitCast(rep_t, b) & absMask; | |
| 81 | ||
| 82 | return @boolToInt(aAbs > infRep or bAbs > infRep); | |
| 83 | } | |
| 84 | ||
| 85 | // Comparison between f32 | |
| 86 | ||
| 87 | pub fn __lesf2(a: f32, b: f32) callconv(.C) i32 { | |
| 88 | @setRuntimeSafety(builtin.is_test); | |
| 89 | return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f32, LE, a, b })); | |
| 90 | } | |
| 91 | ||
| 92 | pub fn __gesf2(a: f32, b: f32) callconv(.C) i32 { | |
| 93 | @setRuntimeSafety(builtin.is_test); | |
| 94 | return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f32, GE, a, b })); | |
| 95 | } | |
| 96 | ||
| 97 | pub fn __eqsf2(a: f32, b: f32) callconv(.C) i32 { | |
| 98 | return __lesf2(a, b); | |
| 99 | } | |
| 100 | ||
| 101 | pub fn __ltsf2(a: f32, b: f32) callconv(.C) i32 { | |
| 102 | return __lesf2(a, b); | |
| 103 | } | |
| 104 | ||
| 105 | pub fn __nesf2(a: f32, b: f32) callconv(.C) i32 { | |
| 106 | return __lesf2(a, b); | |
| 107 | } | |
| 108 | ||
| 109 | pub fn __gtsf2(a: f32, b: f32) callconv(.C) i32 { | |
| 110 | return __gesf2(a, b); | |
| 111 | } | |
| 112 | ||
| 113 | // Comparison between f64 | |
| 114 | ||
| 115 | pub fn __ledf2(a: f64, b: f64) callconv(.C) i32 { | |
| 116 | @setRuntimeSafety(builtin.is_test); | |
| 117 | return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f64, LE, a, b })); | |
| 118 | } | |
| 119 | ||
| 120 | pub fn __gedf2(a: f64, b: f64) callconv(.C) i32 { | |
| 121 | @setRuntimeSafety(builtin.is_test); | |
| 122 | return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f64, GE, a, b })); | |
| 123 | } | |
| 124 | ||
| 125 | pub fn __eqdf2(a: f64, b: f64) callconv(.C) i32 { | |
| 126 | return __ledf2(a, b); | |
| 127 | } | |
| 128 | ||
| 129 | pub fn __ltdf2(a: f64, b: f64) callconv(.C) i32 { | |
| 130 | return __ledf2(a, b); | |
| 131 | } | |
| 132 | ||
| 133 | pub fn __nedf2(a: f64, b: f64) callconv(.C) i32 { | |
| 134 | return __ledf2(a, b); | |
| 135 | } | |
| 136 | ||
| 137 | pub fn __gtdf2(a: f64, b: f64) callconv(.C) i32 { | |
| 138 | return __gedf2(a, b); | |
| 139 | } | |
| 140 | ||
| 141 | // Comparison between f128 | |
| 142 | ||
| 143 | pub fn __letf2(a: f128, b: f128) callconv(.C) i32 { | |
| 144 | @setRuntimeSafety(builtin.is_test); | |
| 145 | return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f128, LE, a, b })); | |
| 146 | } | |
| 147 | ||
| 148 | pub fn __getf2(a: f128, b: f128) callconv(.C) i32 { | |
| 149 | @setRuntimeSafety(builtin.is_test); | |
| 150 | return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f128, GE, a, b })); | |
| 151 | } | |
| 152 | ||
| 153 | pub fn __eqtf2(a: f128, b: f128) callconv(.C) i32 { | |
| 154 | return __letf2(a, b); | |
| 155 | } | |
| 156 | ||
| 157 | pub fn __lttf2(a: f128, b: f128) callconv(.C) i32 { | |
| 158 | return __letf2(a, b); | |
| 159 | } | |
| 160 | ||
| 161 | pub fn __netf2(a: f128, b: f128) callconv(.C) i32 { | |
| 162 | return __letf2(a, b); | |
| 163 | } | |
| 164 | ||
| 165 | pub fn __gttf2(a: f128, b: f128) callconv(.C) i32 { | |
| 166 | return __getf2(a, b); | |
| 167 | } | |
| 168 | ||
| 169 | // Unordered comparison between f32/f64/f128 | |
| 170 | ||
| 171 | pub fn __unordsf2(a: f32, b: f32) callconv(.C) i32 { | |
| 172 | @setRuntimeSafety(builtin.is_test); | |
| 173 | return @call(.{ .modifier = .always_inline }, unordcmp, .{ f32, a, b }); | |
| 174 | } | |
| 175 | ||
| 176 | pub fn __unorddf2(a: f64, b: f64) callconv(.C) i32 { | |
| 177 | @setRuntimeSafety(builtin.is_test); | |
| 178 | return @call(.{ .modifier = .always_inline }, unordcmp, .{ f64, a, b }); | |
| 179 | } | |
| 180 | ||
| 181 | pub fn __unordtf2(a: f128, b: f128) callconv(.C) i32 { | |
| 182 | @setRuntimeSafety(builtin.is_test); | |
| 183 | return @call(.{ .modifier = .always_inline }, unordcmp, .{ f128, a, b }); | |
| 184 | } | |
| 185 | ||
| 186 | // ARM EABI intrinsics | |
| 187 | ||
| 188 | pub fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 { | |
| 189 | @setRuntimeSafety(false); | |
| 190 | return @boolToInt(@call(.{ .modifier = .always_inline }, __eqsf2, .{ a, b }) == 0); | |
| 191 | } | |
| 192 | ||
| 193 | pub fn __aeabi_fcmplt(a: f32, b: f32) callconv(.AAPCS) i32 { | |
| 194 | @setRuntimeSafety(false); | |
| 195 | return @boolToInt(@call(.{ .modifier = .always_inline }, __ltsf2, .{ a, b }) < 0); | |
| 196 | } | |
| 197 | ||
| 198 | pub fn __aeabi_fcmple(a: f32, b: f32) callconv(.AAPCS) i32 { | |
| 199 | @setRuntimeSafety(false); | |
| 200 | return @boolToInt(@call(.{ .modifier = .always_inline }, __lesf2, .{ a, b }) <= 0); | |
| 201 | } | |
| 202 | ||
| 203 | pub fn __aeabi_fcmpge(a: f32, b: f32) callconv(.AAPCS) i32 { | |
| 204 | @setRuntimeSafety(false); | |
| 205 | return @boolToInt(@call(.{ .modifier = .always_inline }, __gesf2, .{ a, b }) >= 0); | |
| 206 | } | |
| 207 | ||
| 208 | pub fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.AAPCS) i32 { | |
| 209 | @setRuntimeSafety(false); | |
| 210 | return @boolToInt(@call(.{ .modifier = .always_inline }, __gtsf2, .{ a, b }) > 0); | |
| 211 | } | |
| 212 | ||
| 213 | pub fn __aeabi_fcmpun(a: f32, b: f32) callconv(.AAPCS) i32 { | |
| 214 | @setRuntimeSafety(false); | |
| 215 | return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b }); | |
| 216 | } | |
| 217 | ||
| 218 | pub fn __aeabi_dcmpeq(a: f64, b: f64) callconv(.AAPCS) i32 { | |
| 219 | @setRuntimeSafety(false); | |
| 220 | return @boolToInt(@call(.{ .modifier = .always_inline }, __eqdf2, .{ a, b }) == 0); | |
| 221 | } | |
| 222 | ||
| 223 | pub fn __aeabi_dcmplt(a: f64, b: f64) callconv(.AAPCS) i32 { | |
| 224 | @setRuntimeSafety(false); | |
| 225 | return @boolToInt(@call(.{ .modifier = .always_inline }, __ltdf2, .{ a, b }) < 0); | |
| 226 | } | |
| 227 | ||
| 228 | pub fn __aeabi_dcmple(a: f64, b: f64) callconv(.AAPCS) i32 { | |
| 229 | @setRuntimeSafety(false); | |
| 230 | return @boolToInt(@call(.{ .modifier = .always_inline }, __ledf2, .{ a, b }) <= 0); | |
| 231 | } | |
| 232 | ||
| 233 | pub fn __aeabi_dcmpge(a: f64, b: f64) callconv(.AAPCS) i32 { | |
| 234 | @setRuntimeSafety(false); | |
| 235 | return @boolToInt(@call(.{ .modifier = .always_inline }, __gedf2, .{ a, b }) >= 0); | |
| 236 | } | |
| 237 | ||
| 238 | pub fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.AAPCS) i32 { | |
| 239 | @setRuntimeSafety(false); | |
| 240 | return @boolToInt(@call(.{ .modifier = .always_inline }, __gtdf2, .{ a, b }) > 0); | |
| 241 | } | |
| 242 | ||
| 243 | pub fn __aeabi_dcmpun(a: f64, b: f64) callconv(.AAPCS) i32 { | |
| 244 | @setRuntimeSafety(false); | |
| 245 | return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b }); | |
| 246 | } | |
| 247 | ||
| 248 | test "comparesf2" { | |
| 249 | _ = @import("comparesf2_test.zig"); | |
| 250 | } | |
| 251 | test "comparedf2" { | |
| 252 | _ = @import("comparedf2_test.zig"); | |
| 253 | } |
lib/std/special/compiler_rt/comparedf2.zig deleted-127| ... | ... | @@ -1,127 +0,0 @@ |
| 1 | // Ported from: | |
| 2 | // | |
| 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparedf2.c | |
| 4 | ||
| 5 | const std = @import("std"); | |
| 6 | const builtin = @import("builtin"); | |
| 7 | const is_test = builtin.is_test; | |
| 8 | ||
| 9 | const fp_t = f64; | |
| 10 | const rep_t = u64; | |
| 11 | const srep_t = i64; | |
| 12 | ||
| 13 | const typeWidth = rep_t.bit_count; | |
| 14 | const significandBits = std.math.floatMantissaBits(fp_t); | |
| 15 | const exponentBits = std.math.floatExponentBits(fp_t); | |
| 16 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 17 | const absMask = signBit - 1; | |
| 18 | const implicitBit = @as(rep_t, 1) << significandBits; | |
| 19 | const significandMask = implicitBit - 1; | |
| 20 | const exponentMask = absMask ^ significandMask; | |
| 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); | |
| 22 | ||
| 23 | // TODO https://github.com/ziglang/zig/issues/641 | |
| 24 | // and then make the return types of some of these functions the enum instead of c_int | |
| 25 | const LE_LESS = @as(c_int, -1); | |
| 26 | const LE_EQUAL = @as(c_int, 0); | |
| 27 | const LE_GREATER = @as(c_int, 1); | |
| 28 | const LE_UNORDERED = @as(c_int, 1); | |
| 29 | ||
| 30 | pub fn __ledf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 31 | @setRuntimeSafety(is_test); | |
| 32 | const aInt: srep_t = @bitCast(srep_t, a); | |
| 33 | const bInt: srep_t = @bitCast(srep_t, b); | |
| 34 | const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; | |
| 35 | const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; | |
| 36 | ||
| 37 | // If either a or b is NaN, they are unordered. | |
| 38 | if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED; | |
| 39 | ||
| 40 | // If a and b are both zeros, they are equal. | |
| 41 | if ((aAbs | bAbs) == 0) return LE_EQUAL; | |
| 42 | ||
| 43 | // If at least one of a and b is positive, we get the same result comparing | |
| 44 | // a and b as signed integers as we would with a fp_ting-point compare. | |
| 45 | if ((aInt & bInt) >= 0) { | |
| 46 | if (aInt < bInt) { | |
| 47 | return LE_LESS; | |
| 48 | } else if (aInt == bInt) { | |
| 49 | return LE_EQUAL; | |
| 50 | } else return LE_GREATER; | |
| 51 | } | |
| 52 | ||
| 53 | // Otherwise, both are negative, so we need to flip the sense of the | |
| 54 | // comparison to get the correct result. (This assumes a twos- or ones- | |
| 55 | // complement integer representation; if integers are represented in a | |
| 56 | // sign-magnitude representation, then this flip is incorrect). | |
| 57 | else { | |
| 58 | if (aInt > bInt) { | |
| 59 | return LE_LESS; | |
| 60 | } else if (aInt == bInt) { | |
| 61 | return LE_EQUAL; | |
| 62 | } else return LE_GREATER; | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | // TODO https://github.com/ziglang/zig/issues/641 | |
| 67 | // and then make the return types of some of these functions the enum instead of c_int | |
| 68 | const GE_LESS = @as(c_int, -1); | |
| 69 | const GE_EQUAL = @as(c_int, 0); | |
| 70 | const GE_GREATER = @as(c_int, 1); | |
| 71 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED | |
| 72 | ||
| 73 | pub fn __gedf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 74 | @setRuntimeSafety(is_test); | |
| 75 | const aInt: srep_t = @bitCast(srep_t, a); | |
| 76 | const bInt: srep_t = @bitCast(srep_t, b); | |
| 77 | const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; | |
| 78 | const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; | |
| 79 | ||
| 80 | if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; | |
| 81 | if ((aAbs | bAbs) == 0) return GE_EQUAL; | |
| 82 | if ((aInt & bInt) >= 0) { | |
| 83 | if (aInt < bInt) { | |
| 84 | return GE_LESS; | |
| 85 | } else if (aInt == bInt) { | |
| 86 | return GE_EQUAL; | |
| 87 | } else return GE_GREATER; | |
| 88 | } else { | |
| 89 | if (aInt > bInt) { | |
| 90 | return GE_LESS; | |
| 91 | } else if (aInt == bInt) { | |
| 92 | return GE_EQUAL; | |
| 93 | } else return GE_GREATER; | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | pub fn __unorddf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 98 | @setRuntimeSafety(is_test); | |
| 99 | const aAbs: rep_t = @bitCast(rep_t, a) & absMask; | |
| 100 | const bAbs: rep_t = @bitCast(rep_t, b) & absMask; | |
| 101 | return @boolToInt(aAbs > infRep or bAbs > infRep); | |
| 102 | } | |
| 103 | ||
| 104 | pub fn __eqdf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 105 | return __ledf2(a, b); | |
| 106 | } | |
| 107 | ||
| 108 | pub fn __ltdf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 109 | return __ledf2(a, b); | |
| 110 | } | |
| 111 | ||
| 112 | pub fn __nedf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 113 | return __ledf2(a, b); | |
| 114 | } | |
| 115 | ||
| 116 | pub fn __gtdf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 117 | return __gedf2(a, b); | |
| 118 | } | |
| 119 | ||
| 120 | pub fn __aeabi_dcmpun(a: fp_t, b: fp_t) callconv(.AAPCS) c_int { | |
| 121 | @setRuntimeSafety(false); | |
| 122 | return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b }); | |
| 123 | } | |
| 124 | ||
| 125 | test "import comparedf2" { | |
| 126 | _ = @import("comparedf2_test.zig"); | |
| 127 | } |
lib/std/special/compiler_rt/comparedf2_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const std = @import("std"); |
| 6 | 6 | const builtin = @import("builtin"); |
| 7 | 7 | const is_test = builtin.is_test; |
| 8 | 8 | |
| 9 | const comparedf2 = @import("comparedf2.zig"); | |
| 9 | const comparedf2 = @import("compareXf2.zig"); | |
| 10 | 10 | |
| 11 | 11 | const TestVector = struct { |
| 12 | 12 | a: f64, |
lib/std/special/compiler_rt/comparesf2.zig deleted-127| ... | ... | @@ -1,127 +0,0 @@ |
| 1 | // Ported from: | |
| 2 | // | |
| 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c | |
| 4 | ||
| 5 | const std = @import("std"); | |
| 6 | const builtin = @import("builtin"); | |
| 7 | const is_test = builtin.is_test; | |
| 8 | ||
| 9 | const fp_t = f32; | |
| 10 | const rep_t = u32; | |
| 11 | const srep_t = i32; | |
| 12 | ||
| 13 | const typeWidth = rep_t.bit_count; | |
| 14 | const significandBits = std.math.floatMantissaBits(fp_t); | |
| 15 | const exponentBits = std.math.floatExponentBits(fp_t); | |
| 16 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 17 | const absMask = signBit - 1; | |
| 18 | const implicitBit = @as(rep_t, 1) << significandBits; | |
| 19 | const significandMask = implicitBit - 1; | |
| 20 | const exponentMask = absMask ^ significandMask; | |
| 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); | |
| 22 | ||
| 23 | // TODO https://github.com/ziglang/zig/issues/641 | |
| 24 | // and then make the return types of some of these functions the enum instead of c_int | |
| 25 | const LE_LESS = @as(c_int, -1); | |
| 26 | const LE_EQUAL = @as(c_int, 0); | |
| 27 | const LE_GREATER = @as(c_int, 1); | |
| 28 | const LE_UNORDERED = @as(c_int, 1); | |
| 29 | ||
| 30 | pub fn __lesf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 31 | @setRuntimeSafety(is_test); | |
| 32 | const aInt: srep_t = @bitCast(srep_t, a); | |
| 33 | const bInt: srep_t = @bitCast(srep_t, b); | |
| 34 | const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; | |
| 35 | const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; | |
| 36 | ||
| 37 | // If either a or b is NaN, they are unordered. | |
| 38 | if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED; | |
| 39 | ||
| 40 | // If a and b are both zeros, they are equal. | |
| 41 | if ((aAbs | bAbs) == 0) return LE_EQUAL; | |
| 42 | ||
| 43 | // If at least one of a and b is positive, we get the same result comparing | |
| 44 | // a and b as signed integers as we would with a fp_ting-point compare. | |
| 45 | if ((aInt & bInt) >= 0) { | |
| 46 | if (aInt < bInt) { | |
| 47 | return LE_LESS; | |
| 48 | } else if (aInt == bInt) { | |
| 49 | return LE_EQUAL; | |
| 50 | } else return LE_GREATER; | |
| 51 | } | |
| 52 | ||
| 53 | // Otherwise, both are negative, so we need to flip the sense of the | |
| 54 | // comparison to get the correct result. (This assumes a twos- or ones- | |
| 55 | // complement integer representation; if integers are represented in a | |
| 56 | // sign-magnitude representation, then this flip is incorrect). | |
| 57 | else { | |
| 58 | if (aInt > bInt) { | |
| 59 | return LE_LESS; | |
| 60 | } else if (aInt == bInt) { | |
| 61 | return LE_EQUAL; | |
| 62 | } else return LE_GREATER; | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | // TODO https://github.com/ziglang/zig/issues/641 | |
| 67 | // and then make the return types of some of these functions the enum instead of c_int | |
| 68 | const GE_LESS = @as(c_int, -1); | |
| 69 | const GE_EQUAL = @as(c_int, 0); | |
| 70 | const GE_GREATER = @as(c_int, 1); | |
| 71 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED | |
| 72 | ||
| 73 | pub fn __gesf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 74 | @setRuntimeSafety(is_test); | |
| 75 | const aInt: srep_t = @bitCast(srep_t, a); | |
| 76 | const bInt: srep_t = @bitCast(srep_t, b); | |
| 77 | const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask; | |
| 78 | const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask; | |
| 79 | ||
| 80 | if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; | |
| 81 | if ((aAbs | bAbs) == 0) return GE_EQUAL; | |
| 82 | if ((aInt & bInt) >= 0) { | |
| 83 | if (aInt < bInt) { | |
| 84 | return GE_LESS; | |
| 85 | } else if (aInt == bInt) { | |
| 86 | return GE_EQUAL; | |
| 87 | } else return GE_GREATER; | |
| 88 | } else { | |
| 89 | if (aInt > bInt) { | |
| 90 | return GE_LESS; | |
| 91 | } else if (aInt == bInt) { | |
| 92 | return GE_EQUAL; | |
| 93 | } else return GE_GREATER; | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | pub fn __unordsf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 98 | @setRuntimeSafety(is_test); | |
| 99 | const aAbs: rep_t = @bitCast(rep_t, a) & absMask; | |
| 100 | const bAbs: rep_t = @bitCast(rep_t, b) & absMask; | |
| 101 | return @boolToInt(aAbs > infRep or bAbs > infRep); | |
| 102 | } | |
| 103 | ||
| 104 | pub fn __eqsf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 105 | return __lesf2(a, b); | |
| 106 | } | |
| 107 | ||
| 108 | pub fn __ltsf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 109 | return __lesf2(a, b); | |
| 110 | } | |
| 111 | ||
| 112 | pub fn __nesf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 113 | return __lesf2(a, b); | |
| 114 | } | |
| 115 | ||
| 116 | pub fn __gtsf2(a: fp_t, b: fp_t) callconv(.C) c_int { | |
| 117 | return __gesf2(a, b); | |
| 118 | } | |
| 119 | ||
| 120 | pub fn __aeabi_fcmpun(a: fp_t, b: fp_t) callconv(.AAPCS) c_int { | |
| 121 | @setRuntimeSafety(false); | |
| 122 | return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b }); | |
| 123 | } | |
| 124 | ||
| 125 | test "import comparesf2" { | |
| 126 | _ = @import("comparesf2_test.zig"); | |
| 127 | } |
lib/std/special/compiler_rt/comparesf2_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const std = @import("std"); |
| 6 | 6 | const builtin = @import("builtin"); |
| 7 | 7 | const is_test = builtin.is_test; |
| 8 | 8 | |
| 9 | const comparesf2 = @import("comparesf2.zig"); | |
| 9 | const comparesf2 = @import("compareXf2.zig"); | |
| 10 | 10 | |
| 11 | 11 | const TestVector = struct { |
| 12 | 12 | a: f32, |
lib/std/special/compiler_rt/comparetf2.zig deleted-99| ... | ... | @@ -1,99 +0,0 @@ |
| 1 | // TODO https://github.com/ziglang/zig/issues/641 | |
| 2 | // and then make the return types of some of these functions the enum instead of c_int | |
| 3 | const LE_LESS = @as(c_int, -1); | |
| 4 | const LE_EQUAL = @as(c_int, 0); | |
| 5 | const LE_GREATER = @as(c_int, 1); | |
| 6 | const LE_UNORDERED = @as(c_int, 1); | |
| 7 | ||
| 8 | const rep_t = u128; | |
| 9 | const srep_t = i128; | |
| 10 | ||
| 11 | const typeWidth = rep_t.bit_count; | |
| 12 | const significandBits = 112; | |
| 13 | const exponentBits = (typeWidth - significandBits - 1); | |
| 14 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); | |
| 15 | const absMask = signBit - 1; | |
| 16 | const implicitBit = @as(rep_t, 1) << significandBits; | |
| 17 | const significandMask = implicitBit - 1; | |
| 18 | const exponentMask = absMask ^ significandMask; | |
| 19 | const infRep = exponentMask; | |
| 20 | ||
| 21 | const builtin = @import("builtin"); | |
| 22 | const is_test = builtin.is_test; | |
| 23 | ||
| 24 | pub fn __letf2(a: f128, b: f128) callconv(.C) c_int { | |
| 25 | @setRuntimeSafety(is_test); | |
| 26 | ||
| 27 | const aInt = @bitCast(rep_t, a); | |
| 28 | const bInt = @bitCast(rep_t, b); | |
| 29 | ||
| 30 | const aAbs: rep_t = aInt & absMask; | |
| 31 | const bAbs: rep_t = bInt & absMask; | |
| 32 | ||
| 33 | // If either a or b is NaN, they are unordered. | |
| 34 | if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED; | |
| 35 | ||
| 36 | // If a and b are both zeros, they are equal. | |
| 37 | if ((aAbs | bAbs) == 0) return LE_EQUAL; | |
| 38 | ||
| 39 | // If at least one of a and b is positive, we get the same result comparing | |
| 40 | // a and b as signed integers as we would with a floating-point compare. | |
| 41 | return if ((aInt & bInt) >= 0) | |
| 42 | if (aInt < bInt) | |
| 43 | LE_LESS | |
| 44 | else if (aInt == bInt) | |
| 45 | LE_EQUAL | |
| 46 | else | |
| 47 | LE_GREATER | |
| 48 | else | |
| 49 | // Otherwise, both are negative, so we need to flip the sense of the | |
| 50 | // comparison to get the correct result. (This assumes a twos- or ones- | |
| 51 | // complement integer representation; if integers are represented in a | |
| 52 | // sign-magnitude representation, then this flip is incorrect). | |
| 53 | if (aInt > bInt) | |
| 54 | LE_LESS | |
| 55 | else if (aInt == bInt) | |
| 56 | LE_EQUAL | |
| 57 | else | |
| 58 | LE_GREATER; | |
| 59 | } | |
| 60 | ||
| 61 | // TODO https://github.com/ziglang/zig/issues/641 | |
| 62 | // and then make the return types of some of these functions the enum instead of c_int | |
| 63 | const GE_LESS = @as(c_int, -1); | |
| 64 | const GE_EQUAL = @as(c_int, 0); | |
| 65 | const GE_GREATER = @as(c_int, 1); | |
| 66 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED | |
| 67 | ||
| 68 | pub fn __getf2(a: f128, b: f128) callconv(.C) c_int { | |
| 69 | @setRuntimeSafety(is_test); | |
| 70 | ||
| 71 | const aInt = @bitCast(srep_t, a); | |
| 72 | const bInt = @bitCast(srep_t, b); | |
| 73 | const aAbs = @bitCast(rep_t, aInt) & absMask; | |
| 74 | const bAbs = @bitCast(rep_t, bInt) & absMask; | |
| 75 | ||
| 76 | if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; | |
| 77 | if ((aAbs | bAbs) == 0) return GE_EQUAL; | |
| 78 | return if ((aInt & bInt) >= 0) | |
| 79 | if (aInt < bInt) | |
| 80 | GE_LESS | |
| 81 | else if (aInt == bInt) | |
| 82 | GE_EQUAL | |
| 83 | else | |
| 84 | GE_GREATER | |
| 85 | else if (aInt > bInt) | |
| 86 | GE_LESS | |
| 87 | else if (aInt == bInt) | |
| 88 | GE_EQUAL | |
| 89 | else | |
| 90 | GE_GREATER; | |
| 91 | } | |
| 92 | ||
| 93 | pub fn __unordtf2(a: f128, b: f128) callconv(.C) c_int { | |
| 94 | @setRuntimeSafety(is_test); | |
| 95 | ||
| 96 | const aAbs = @bitCast(rep_t, a) & absMask; | |
| 97 | const bAbs = @bitCast(rep_t, b) & absMask; | |
| 98 | return @boolToInt(aAbs > infRep or bAbs > infRep); | |
| 99 | } |
lib/std/start.zig+2-11| ... | ... | @@ -8,16 +8,7 @@ const uefi = std.os.uefi; |
| 8 | 8 | |
| 9 | 9 | var starting_stack_ptr: [*]usize = undefined; |
| 10 | 10 | |
| 11 | const is_wasm = switch (builtin.arch) { | |
| 12 | .wasm32, .wasm64 => true, | |
| 13 | else => false, | |
| 14 | }; | |
| 15 | ||
| 16 | const is_mips = switch (builtin.arch) { | |
| 17 | .mips, .mipsel, .mips64, .mips64el => true, | |
| 18 | else => false, | |
| 19 | }; | |
| 20 | const start_sym_name = if (is_mips) "__start" else "_start"; | |
| 11 | const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start"; | |
| 21 | 12 | |
| 22 | 13 | comptime { |
| 23 | 14 | if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { |
| ... | ... | @@ -35,7 +26,7 @@ comptime { |
| 35 | 26 | } |
| 36 | 27 | } else if (builtin.os == .uefi) { |
| 37 | 28 | if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); |
| 38 | } else if (is_wasm and builtin.os == .freestanding) { | |
| 29 | } else if (builtin.arch.isWasm() and builtin.os == .freestanding) { | |
| 39 | 30 | if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name }); |
| 40 | 31 | } else if (builtin.os != .other and builtin.os != .freestanding) { |
| 41 | 32 | if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); |
lib/std/target.zig+38| ... | ... | @@ -125,6 +125,16 @@ pub const Target = union(enum) { |
| 125 | 125 | v5, |
| 126 | 126 | v5te, |
| 127 | 127 | v4t, |
| 128 | ||
| 129 | pub fn version(version: Arm32) comptime_int { | |
| 130 | return switch (version) { | |
| 131 | .v8_5a, .v8_4a, .v8_3a, .v8_2a, .v8_1a, .v8, .v8r, .v8m_baseline, .v8m_mainline, .v8_1m_mainline => 8, | |
| 132 | .v7, .v7em, .v7m, .v7s, .v7k, .v7ve => 7, | |
| 133 | .v6, .v6m, .v6k, .v6t2 => 6, | |
| 134 | .v5, .v5te => 5, | |
| 135 | .v4t => 4, | |
| 136 | }; | |
| 137 | } | |
| 128 | 138 | }; |
| 129 | 139 | pub const Arm64 = enum { |
| 130 | 140 | v8_5a, |
| ... | ... | @@ -146,6 +156,34 @@ pub const Target = union(enum) { |
| 146 | 156 | r6, |
| 147 | 157 | }; |
| 148 | 158 | |
| 159 | pub fn isARM(arch: Arch) bool { | |
| 160 | return switch (arch) { | |
| 161 | .arm, .armeb => true, | |
| 162 | else => false, | |
| 163 | }; | |
| 164 | } | |
| 165 | ||
| 166 | pub fn isThumb(arch: Arch) bool { | |
| 167 | return switch (arch) { | |
| 168 | .thumb, .thumbeb => true, | |
| 169 | else => false, | |
| 170 | }; | |
| 171 | } | |
| 172 | ||
| 173 | pub fn isWasm(arch: Arch) bool { | |
| 174 | return switch (arch) { | |
| 175 | .wasm32, .wasm64 => true, | |
| 176 | else => false, | |
| 177 | }; | |
| 178 | } | |
| 179 | ||
| 180 | pub fn isMIPS(arch: Arch) bool { | |
| 181 | return switch (arch) { | |
| 182 | .mips, .mipsel, .mips64, .mips64el => true, | |
| 183 | else => false, | |
| 184 | }; | |
| 185 | } | |
| 186 | ||
| 149 | 187 | pub fn toElfMachine(arch: Arch) std.elf.EM { |
| 150 | 188 | return switch (arch) { |
| 151 | 189 | .avr => ._AVR, |