authorgravatar for mrjbq7@gmail.comJohn Benediktsson <mrjbq7@gmail.com> 2023-11-23 12:06:32-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-23 15:06:32-05:00
log54f4abae2f811c6de1d5c5156961e1bd75405aa6
tree924e25ffeecbeaa82331b2f9a43b7c14ff457fdc
parent464ce8ac67eb0ef15cc535d2b10394343dd44a2c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011)


17 files changed, 59 insertions(+), 45 deletions(-)

lib/compiler_rt/ceil.zig+5-4
......@@ -8,6 +8,7 @@ const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213const common = @import("common.zig");
1314
......@@ -47,14 +48,14 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
4748 if (u & m == 0) {
4849 return x;
4950 }
50 math.doNotOptimizeAway(x + 0x1.0p120);
51 mem.doNotOptimizeAway(x + 0x1.0p120);
5152 if (u >> 31 == 0) {
5253 u += m;
5354 }
5455 u &= ~m;
5556 return @bitCast(u);
5657 } else {
57 math.doNotOptimizeAway(x + 0x1.0p120);
58 mem.doNotOptimizeAway(x + 0x1.0p120);
5859 if (u >> 31 != 0) {
5960 return -0.0;
6061 } else {
......@@ -81,7 +82,7 @@ pub fn ceil(x: f64) callconv(.C) f64 {
8182 }
8283
8384 if (e <= 0x3FF - 1) {
84 math.doNotOptimizeAway(y);
85 mem.doNotOptimizeAway(y);
8586 if (u >> 63 != 0) {
8687 return -0.0;
8788 } else {
......@@ -115,7 +116,7 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
115116 }
116117
117118 if (e <= 0x3FFF - 1) {
118 math.doNotOptimizeAway(y);
119 mem.doNotOptimizeAway(y);
119120 if (u >> 127 != 0) {
120121 return -0.0;
121122 } else {
lib/compiler_rt/cos.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const math = std.math;
3const mem = std.mem;
34const expect = std.testing.expect;
45const common = @import("common.zig");
56
......@@ -40,7 +41,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
4041 if (ix <= 0x3f490fda) { // |x| ~<= pi/4
4142 if (ix < 0x39800000) { // |x| < 2**-12
4243 // raise inexact if x != 0
43 math.doNotOptimizeAway(x + 0x1p120);
44 mem.doNotOptimizeAway(x + 0x1p120);
4445 return 1.0;
4546 }
4647 return trig.__cosdf(x);
......@@ -91,7 +92,7 @@ pub fn cos(x: f64) callconv(.C) f64 {
9192 if (ix <= 0x3fe921fb) {
9293 if (ix < 0x3e46a09e) { // |x| < 2**-27 * sqrt(2)
9394 // raise inexact if x!=0
94 math.doNotOptimizeAway(x + 0x1p120);
95 mem.doNotOptimizeAway(x + 0x1p120);
9596 return 1.0;
9697 }
9798 return trig.__cos(x, 0);
lib/compiler_rt/exp.zig+5-4
......@@ -8,6 +8,7 @@ const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213const common = @import("common.zig");
1314
......@@ -58,7 +59,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
5859 return x * 0x1.0p127;
5960 }
6061 if (sign != 0) {
61 math.doNotOptimizeAway(-0x1.0p-149 / x); // overflow
62 mem.doNotOptimizeAway(-0x1.0p-149 / x); // overflow
6263 // x <= -103.972084
6364 if (hx >= 0x42CFF1B5) {
6465 return 0;
......@@ -90,7 +91,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
9091 hi = x;
9192 lo = 0;
9293 } else {
93 math.doNotOptimizeAway(0x1.0p127 + x); // inexact
94 mem.doNotOptimizeAway(0x1.0p127 + x); // inexact
9495 return 1 + x;
9596 }
9697
......@@ -141,7 +142,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
141142 }
142143 if (x < -708.39641853226410622) {
143144 // underflow if x != -inf
144 // math.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x));
145 // mem.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x));
145146 if (x < -745.13321910194110842) {
146147 return 0;
147148 }
......@@ -174,7 +175,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
174175 lo = 0;
175176 } else {
176177 // inexact if x != 0
177 // math.doNotOptimizeAway(0x1.0p1023 + x);
178 // mem.doNotOptimizeAway(0x1.0p1023 + x);
178179 return 1 + x;
179180 }
180181
lib/compiler_rt/exp2.zig+3-2
......@@ -8,6 +8,7 @@ const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213const common = @import("common.zig");
1314
......@@ -54,7 +55,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
5455 // x < -126
5556 if (u >= 0x80000000) {
5657 if (u >= 0xC3160000 or u & 0x000FFFF != 0) {
57 math.doNotOptimizeAway(-0x1.0p-149 / x);
58 mem.doNotOptimizeAway(-0x1.0p-149 / x);
5859 }
5960 // x <= -150
6061 if (u >= 0x3160000) {
......@@ -119,7 +120,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
119120 if (ux >> 63 != 0) {
120121 // underflow
121122 if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {
122 math.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x)));
123 mem.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x)));
123124 }
124125 if (x <= -1075) {
125126 return 0;
lib/compiler_rt/floor.zig+7-6
......@@ -7,6 +7,7 @@
77const std = @import("std");
88const builtin = @import("builtin");
99const math = std.math;
10const mem = std.mem;
1011const expect = std.testing.expect;
1112const arch = builtin.cpu.arch;
1213const common = @import("common.zig");
......@@ -44,13 +45,13 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
4445 if (u & m == 0) {
4546 return x;
4647 }
47 math.doNotOptimizeAway(x + 0x1.0p120);
48 mem.doNotOptimizeAway(x + 0x1.0p120);
4849 if (u >> 15 != 0) {
4950 u += m;
5051 }
5152 return @bitCast(u & ~m);
5253 } else {
53 math.doNotOptimizeAway(x + 0x1.0p120);
54 mem.doNotOptimizeAway(x + 0x1.0p120);
5455 if (u >> 15 == 0) {
5556 return 0.0;
5657 } else {
......@@ -78,13 +79,13 @@ pub fn floorf(x: f32) callconv(.C) f32 {
7879 if (u & m == 0) {
7980 return x;
8081 }
81 math.doNotOptimizeAway(x + 0x1.0p120);
82 mem.doNotOptimizeAway(x + 0x1.0p120);
8283 if (u >> 31 != 0) {
8384 u += m;
8485 }
8586 return @bitCast(u & ~m);
8687 } else {
87 math.doNotOptimizeAway(x + 0x1.0p120);
88 mem.doNotOptimizeAway(x + 0x1.0p120);
8889 if (u >> 31 == 0) {
8990 return 0.0;
9091 } else {
......@@ -111,7 +112,7 @@ pub fn floor(x: f64) callconv(.C) f64 {
111112 }
112113
113114 if (e <= 0x3FF - 1) {
114 math.doNotOptimizeAway(y);
115 mem.doNotOptimizeAway(y);
115116 if (u >> 63 != 0) {
116117 return -1.0;
117118 } else {
......@@ -145,7 +146,7 @@ pub fn floorq(x: f128) callconv(.C) f128 {
145146 }
146147
147148 if (e <= 0x3FFF - 1) {
148 math.doNotOptimizeAway(y);
149 mem.doNotOptimizeAway(y);
149150 if (u >> 127 != 0) {
150151 return -1.0;
151152 } else {
lib/compiler_rt/round.zig+4-3
......@@ -7,6 +7,7 @@
77const std = @import("std");
88const builtin = @import("builtin");
99const math = std.math;
10const mem = std.mem;
1011const expect = std.testing.expect;
1112const arch = builtin.cpu.arch;
1213const common = @import("common.zig");
......@@ -45,7 +46,7 @@ pub fn roundf(x_: f32) callconv(.C) f32 {
4546 x = -x;
4647 }
4748 if (e < 0x7F - 1) {
48 math.doNotOptimizeAway(x + f32_toint);
49 mem.doNotOptimizeAway(x + f32_toint);
4950 return 0 * @as(f32, @bitCast(u));
5051 }
5152
......@@ -80,7 +81,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
8081 x = -x;
8182 }
8283 if (e < 0x3ff - 1) {
83 math.doNotOptimizeAway(x + f64_toint);
84 mem.doNotOptimizeAway(x + f64_toint);
8485 return 0 * @as(f64, @bitCast(u));
8586 }
8687
......@@ -120,7 +121,7 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
120121 x = -x;
121122 }
122123 if (e < 0x3FFF - 1) {
123 math.doNotOptimizeAway(x + f128_toint);
124 mem.doNotOptimizeAway(x + f128_toint);
124125 return 0 * @as(f128, @bitCast(u));
125126 }
126127
lib/compiler_rt/sin.zig+3-2
......@@ -8,6 +8,7 @@ const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213const common = @import("common.zig");
1314
......@@ -48,7 +49,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
4849 if (ix <= 0x3f490fda) { // |x| ~<= pi/4
4950 if (ix < 0x39800000) { // |x| < 2**-12
5051 // raise inexact if x!=0 and underflow if subnormal
51 math.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
52 mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
5253 return x;
5354 }
5455 return trig.__sindf(x);
......@@ -97,7 +98,7 @@ pub fn sin(x: f64) callconv(.C) f64 {
9798 if (ix <= 0x3fe921fb) {
9899 if (ix < 0x3e500000) { // |x| < 2**-26
99100 // raise inexact if x != 0 and underflow if subnormal
100 math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
101 mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
101102 return x;
102103 }
103104 return trig.__sin(x, 0.0, 0);
lib/compiler_rt/sincos.zig+4-3
......@@ -2,6 +2,7 @@ const std = @import("std");
22const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
44const math = std.math;
5const mem = std.mem;
56const trig = @import("trig.zig");
67const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
78const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
......@@ -45,7 +46,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
4546 // |x| < 2**-12
4647 if (ix < 0x39800000) {
4748 // raise inexact if x!=0 and underflow if subnormal
48 math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
49 mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
4950 r_sin.* = x;
5051 r_cos.* = 1.0;
5152 return;
......@@ -133,7 +134,7 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.C) void {
133134 // if |x| < 2**-27 * sqrt(2)
134135 if (ix < 0x3e46a09e) {
135136 // raise inexact if x != 0 and underflow if subnormal
136 math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
137 mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
137138 r_sin.* = x;
138139 r_cos.* = 1.0;
139140 return;
......@@ -231,7 +232,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
231232 if (se < 0x3fff - math.floatFractionalBits(F) - 1) {
232233 // raise underflow if subnormal
233234 if (se == 0) {
234 math.doNotOptimizeAway(x * 0x1p-120);
235 mem.doNotOptimizeAway(x * 0x1p-120);
235236 }
236237 r_sin.* = x;
237238 // raise inexact if x!=0
lib/compiler_rt/tan.zig+3-2
......@@ -8,6 +8,7 @@
88const std = @import("std");
99const builtin = @import("builtin");
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213
1314const kernel = @import("trig.zig");
......@@ -50,7 +51,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
5051 if (ix <= 0x3f490fda) { // |x| ~<= pi/4
5152 if (ix < 0x39800000) { // |x| < 2**-12
5253 // raise inexact if x!=0 and underflow if subnormal
53 math.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
54 mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
5455 return x;
5556 }
5657 return kernel.__tandf(x, false);
......@@ -88,7 +89,7 @@ pub fn tan(x: f64) callconv(.C) f64 {
8889 if (ix <= 0x3fe921fb) {
8990 if (ix < 0x3e400000) { // |x| < 2**-27
9091 // raise inexact if x!=0 and underflow if subnormal
91 math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
92 mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
9293 return x;
9394 }
9495 return kernel.__tan(x, 0.0, false);
lib/compiler_rt/trunc.zig+4-3
......@@ -8,6 +8,7 @@ const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213const common = @import("common.zig");
1314
......@@ -46,7 +47,7 @@ pub fn truncf(x: f32) callconv(.C) f32 {
4647 if (u & m == 0) {
4748 return x;
4849 } else {
49 math.doNotOptimizeAway(x + 0x1p120);
50 mem.doNotOptimizeAway(x + 0x1p120);
5051 return @bitCast(u & ~m);
5152 }
5253}
......@@ -67,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {
6768 if (u & m == 0) {
6869 return x;
6970 } else {
70 math.doNotOptimizeAway(x + 0x1p120);
71 mem.doNotOptimizeAway(x + 0x1p120);
7172 return @bitCast(u & ~m);
7273 }
7374}
......@@ -93,7 +94,7 @@ pub fn truncq(x: f128) callconv(.C) f128 {
9394 if (u & m == 0) {
9495 return x;
9596 } else {
96 math.doNotOptimizeAway(x + 0x1p120);
97 mem.doNotOptimizeAway(x + 0x1p120);
9798 return @bitCast(u & ~m);
9899 }
99100}
lib/std/math.zig+1-3
......@@ -186,9 +186,7 @@ test "approxEqAbs and approxEqRel" {
186186 }
187187}
188188
189pub fn doNotOptimizeAway(val: anytype) void {
190 return mem.doNotOptimizeAway(val);
191}
189pub const doNotOptimizeAway = @compileError("Deprecated: use `std.mem.doNotOptimizeAway` instead");
192190
193191pub fn raiseInvalid() void {
194192 // Raise INVALID fpu exception
lib/std/math/asinh.zig+3-2
......@@ -6,6 +6,7 @@
66
77const std = @import("../std.zig");
88const math = std.math;
9const mem = std.mem;
910const expect = std.testing.expect;
1011const maxInt = std.math.maxInt;
1112
......@@ -46,7 +47,7 @@ fn asinh32(x: f32) f32 {
4647 }
4748 // |x| < 0x1p-12, inexact if x != 0
4849 else {
49 math.doNotOptimizeAway(rx + 0x1.0p120);
50 mem.doNotOptimizeAway(rx + 0x1.0p120);
5051 }
5152
5253 return if (s != 0) -rx else rx;
......@@ -73,7 +74,7 @@ fn asinh64(x: f64) f64 {
7374 }
7475 // |x| < 0x1p-12, inexact if x != 0
7576 else {
76 math.doNotOptimizeAway(rx + 0x1.0p120);
77 mem.doNotOptimizeAway(rx + 0x1.0p120);
7778 }
7879
7980 return if (s != 0) -rx else rx;
lib/std/math/atan.zig+3-2
......@@ -6,6 +6,7 @@
66
77const std = @import("../std.zig");
88const math = std.math;
9const mem = std.mem;
910const expect = std.testing.expect;
1011
1112/// Returns the arc-tangent of x.
......@@ -67,7 +68,7 @@ fn atan32(x_: f32) f32 {
6768 // |x| < 2^(-12)
6869 if (ix < 0x39800000) {
6970 if (ix < 0x00800000) {
70 math.doNotOptimizeAway(x * x);
71 mem.doNotOptimizeAway(x * x);
7172 }
7273 return x;
7374 }
......@@ -165,7 +166,7 @@ fn atan64(x_: f64) f64 {
165166 // |x| < 2^(-27)
166167 if (ix < 0x3E400000) {
167168 if (ix < 0x00100000) {
168 math.doNotOptimizeAway(@as(f32, @floatCast(x)));
169 mem.doNotOptimizeAway(@as(f32, @floatCast(x)));
169170 }
170171 return x;
171172 }
lib/std/math/atanh.zig+3-2
......@@ -6,6 +6,7 @@
66
77const std = @import("../std.zig");
88const math = std.math;
9const mem = std.mem;
910const expect = std.testing.expect;
1011const maxInt = std.math.maxInt;
1112
......@@ -40,7 +41,7 @@ fn atanh_32(x: f32) f32 {
4041 if (u < 0x3F800000 - (32 << 23)) {
4142 // underflow
4243 if (u < (1 << 23)) {
43 math.doNotOptimizeAway(y * y);
44 mem.doNotOptimizeAway(y * y);
4445 }
4546 }
4647 // |x| < 0.5
......@@ -69,7 +70,7 @@ fn atanh_64(x: f64) f64 {
6970 if (e < 0x3FF - 32) {
7071 // underflow
7172 if (e == 0) {
72 math.doNotOptimizeAway(@as(f32, @floatCast(y)));
73 mem.doNotOptimizeAway(@as(f32, @floatCast(y)));
7374 }
7475 }
7576 // |x| < 0.5
lib/std/math/expm1.zig+3-2
......@@ -8,6 +8,7 @@
88
99const std = @import("../std.zig");
1010const math = std.math;
11const mem = std.mem;
1112const expect = std.testing.expect;
1213
1314/// Returns e raised to the power of x, minus 1 (e^x - 1). This is more accurate than exp(e, x) - 1
......@@ -100,7 +101,7 @@ fn expm1_32(x_: f32) f32 {
100101 // |x| < 2^(-25)
101102 else if (hx < 0x33000000) {
102103 if (hx < 0x00800000) {
103 math.doNotOptimizeAway(x * x);
104 mem.doNotOptimizeAway(x * x);
104105 }
105106 return x;
106107 } else {
......@@ -231,7 +232,7 @@ fn expm1_64(x_: f64) f64 {
231232 // |x| < 2^(-54)
232233 else if (hx < 0x3C900000) {
233234 if (hx < 0x00100000) {
234 math.doNotOptimizeAway(@as(f32, @floatCast(x)));
235 mem.doNotOptimizeAway(@as(f32, @floatCast(x)));
235236 }
236237 return x;
237238 } else {
lib/std/math/log1p.zig+2-1
......@@ -6,6 +6,7 @@
66
77const std = @import("../std.zig");
88const math = std.math;
9const mem = std.mem;
910const expect = std.testing.expect;
1011
1112/// Returns the natural logarithm of 1 + x with greater accuracy when x is near zero.
......@@ -56,7 +57,7 @@ fn log1p_32(x: f32) f32 {
5657 if ((ix << 1) < (0x33800000 << 1)) {
5758 // underflow if subnormal
5859 if (ix & 0x7F800000 == 0) {
59 math.doNotOptimizeAway(x * x);
60 mem.doNotOptimizeAway(x * x);
6061 }
6162 return x;
6263 }
lib/std/math/tanh.zig+3-2
......@@ -6,6 +6,7 @@
66
77const std = @import("../std.zig");
88const math = std.math;
9const mem = std.mem;
910const expect = std.testing.expect;
1011const expo2 = @import("expo2.zig").expo2;
1112const maxInt = std.math.maxInt;
......@@ -58,7 +59,7 @@ fn tanh32(x: f32) f32 {
5859 }
5960 // |x| is subnormal
6061 else {
61 math.doNotOptimizeAway(ax * ax);
62 mem.doNotOptimizeAway(ax * ax);
6263 t = ax;
6364 }
6465
......@@ -96,7 +97,7 @@ fn tanh64(x: f64) f64 {
9697 }
9798 // |x| is subnormal
9899 else {
99 math.doNotOptimizeAway(@as(f32, @floatCast(ax)));
100 mem.doNotOptimizeAway(@as(f32, @floatCast(ax)));
100101 t = ax;
101102 }
102103