Skip to content

Commit

Permalink
Merge pull request #20758 from pavelverigo/stage2-wasm-compiler-rt-te…
Browse files Browse the repository at this point in the history
…st-pass

stage2-wasm: pass compiler_rt test suite
  • Loading branch information
andrewrk authored Jul 24, 2024
2 parents 399f4fe + ba8522e commit fa95c89
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 49 deletions.
8 changes: 4 additions & 4 deletions lib/compiler_rt/ceil.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
if (u & m == 0) {
return x;
}
mem.doNotOptimizeAway(x + 0x1.0p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 == 0) {
u += m;
}
u &= ~m;
return @bitCast(u);
} else {
mem.doNotOptimizeAway(x + 0x1.0p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 != 0) {
return -0.0;
} else {
Expand All @@ -82,7 +82,7 @@ pub fn ceil(x: f64) callconv(.C) f64 {
}

if (e <= 0x3FF - 1) {
mem.doNotOptimizeAway(y);
if (common.want_float_exceptions) mem.doNotOptimizeAway(y);
if (u >> 63 != 0) {
return -0.0;
} else {
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
}

if (e <= 0x3FFF - 1) {
mem.doNotOptimizeAway(y);
if (common.want_float_exceptions) mem.doNotOptimizeAway(y);
if (u >> 127 != 0) {
return -0.0;
} else {
Expand Down
2 changes: 2 additions & 0 deletions lib/compiler_rt/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub const want_aeabi = switch (builtin.abi) {
};
pub const want_ppc_abi = builtin.cpu.arch.isPPC() or builtin.cpu.arch.isPPC64();

pub const want_float_exceptions = !builtin.cpu.arch.isWasm();

// Libcalls that involve u128 on Windows x86-64 are expected by LLVM to use the
// calling convention of @Vector(2, u64), rather than what's standard.
pub const want_windows_v2u64_abi = builtin.os.tag == .windows and builtin.cpu.arch == .x86_64 and @import("builtin").object_format != .c;
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler_rt/cos.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x != 0
mem.doNotOptimizeAway(x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
return 1.0;
}
return trig.__cosdf(x);
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn cos(x: f64) callconv(.C) f64 {
if (ix <= 0x3fe921fb) {
if (ix < 0x3e46a09e) { // |x| < 2**-27 * sqrt(2)
// raise inexact if x!=0
mem.doNotOptimizeAway(x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
return 1.0;
}
return trig.__cos(x, 0);
Expand Down
8 changes: 4 additions & 4 deletions lib/compiler_rt/exp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
return x * 0x1.0p127;
}
if (sign != 0) {
mem.doNotOptimizeAway(-0x1.0p-149 / x); // overflow
if (common.want_float_exceptions) mem.doNotOptimizeAway(-0x1.0p-149 / x); // overflow
// x <= -103.972084
if (hx >= 0x42CFF1B5) {
return 0;
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
hi = x;
lo = 0;
} else {
mem.doNotOptimizeAway(0x1.0p127 + x); // inexact
if (common.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p127 + x); // inexact
return 1 + x;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
}
if (x < -708.39641853226410622) {
// underflow if x != -inf
// mem.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x));
// if (common.want_float_exceptions) mem.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x));
if (x < -745.13321910194110842) {
return 0;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
lo = 0;
} else {
// inexact if x != 0
// mem.doNotOptimizeAway(0x1.0p1023 + x);
// if (common.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p1023 + x);
return 1 + x;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/compiler_rt/exp2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
// x < -126
if (u >= 0x80000000) {
if (u >= 0xC3160000 or u & 0x000FFFF != 0) {
mem.doNotOptimizeAway(-0x1.0p-149 / x);
if (common.want_float_exceptions) mem.doNotOptimizeAway(-0x1.0p-149 / x);
}
// x <= -150
if (u >= 0x3160000) {
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
if (ux >> 63 != 0) {
// underflow
if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {
mem.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x)));
if (common.want_float_exceptions) mem.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x)));
}
if (x <= -1075) {
return 0;
Expand Down
12 changes: 6 additions & 6 deletions lib/compiler_rt/floor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
if (u & m == 0) {
return x;
}
mem.doNotOptimizeAway(x + 0x1.0p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 15 != 0) {
u += m;
}
return @bitCast(u & ~m);
} else {
mem.doNotOptimizeAway(x + 0x1.0p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 15 == 0) {
return 0.0;
} else {
Expand Down Expand Up @@ -79,13 +79,13 @@ pub fn floorf(x: f32) callconv(.C) f32 {
if (u & m == 0) {
return x;
}
mem.doNotOptimizeAway(x + 0x1.0p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 != 0) {
u += m;
}
return @bitCast(u & ~m);
} else {
mem.doNotOptimizeAway(x + 0x1.0p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 == 0) {
return 0.0;
} else {
Expand All @@ -112,7 +112,7 @@ pub fn floor(x: f64) callconv(.C) f64 {
}

if (e <= 0x3FF - 1) {
mem.doNotOptimizeAway(y);
if (common.want_float_exceptions) mem.doNotOptimizeAway(y);
if (u >> 63 != 0) {
return -1.0;
} else {
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn floorq(x: f128) callconv(.C) f128 {
}

if (e <= 0x3FFF - 1) {
mem.doNotOptimizeAway(y);
if (common.want_float_exceptions) mem.doNotOptimizeAway(y);
if (u >> 127 != 0) {
return -1.0;
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler_rt/round.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn roundf(x_: f32) callconv(.C) f32 {
x = -x;
}
if (e < 0x7F - 1) {
mem.doNotOptimizeAway(x + f32_toint);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + f32_toint);
return 0 * @as(f32, @bitCast(u));
}

Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
x = -x;
}
if (e < 0x3ff - 1) {
mem.doNotOptimizeAway(x + f64_toint);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + f64_toint);
return 0 * @as(f64, @bitCast(u));
}

Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
x = -x;
}
if (e < 0x3FFF - 1) {
mem.doNotOptimizeAway(x + f128_toint);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + f128_toint);
return 0 * @as(f128, @bitCast(u));
}

Expand Down
4 changes: 2 additions & 2 deletions lib/compiler_rt/sin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x!=0 and underflow if subnormal
mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
return x;
}
return trig.__sindf(x);
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn sin(x: f64) callconv(.C) f64 {
if (ix <= 0x3fe921fb) {
if (ix < 0x3e500000) { // |x| < 2**-26
// raise inexact if x != 0 and underflow if subnormal
mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
return x;
}
return trig.__sin(x, 0.0, 0);
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler_rt/sincos.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
// |x| < 2**-12
if (ix < 0x39800000) {
// raise inexact if x!=0 and underflow if subnormal
mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
r_sin.* = x;
r_cos.* = 1.0;
return;
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.C) void {
// if |x| < 2**-27 * sqrt(2)
if (ix < 0x3e46a09e) {
// raise inexact if x != 0 and underflow if subnormal
mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
r_sin.* = x;
r_cos.* = 1.0;
return;
Expand Down Expand Up @@ -232,7 +232,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
if (se < 0x3fff - math.floatFractionalBits(F) - 1) {
// raise underflow if subnormal
if (se == 0) {
mem.doNotOptimizeAway(x * 0x1p-120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x * 0x1p-120);
}
r_sin.* = x;
// raise inexact if x!=0
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler_rt/tan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x!=0 and underflow if subnormal
mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
return x;
}
return kernel.__tandf(x, false);
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn tan(x: f64) callconv(.C) f64 {
if (ix <= 0x3fe921fb) {
if (ix < 0x3e400000) { // |x| < 2**-27
// raise inexact if x!=0 and underflow if subnormal
mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
return x;
}
return kernel.__tan(x, 0.0, false);
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler_rt/trunc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn truncf(x: f32) callconv(.C) f32 {
if (u & m == 0) {
return x;
} else {
mem.doNotOptimizeAway(x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
return @bitCast(u & ~m);
}
}
Expand All @@ -68,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {
if (u & m == 0) {
return x;
} else {
mem.doNotOptimizeAway(x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
return @bitCast(u & ~m);
}
}
Expand All @@ -94,7 +94,7 @@ pub fn truncq(x: f128) callconv(.C) f128 {
if (u & m == 0) {
return x;
} else {
mem.doNotOptimizeAway(x + 0x1p120);
if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
return @bitCast(u & ~m);
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/compiler_rt/udivmodei4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)

test "__udivei4/__umodei4" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;

const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42);
Expand Down
Loading

0 comments on commit fa95c89

Please sign in to comment.