| author | |
| committer | |
| log | ad18078d53b448fc18a100dcebca88fe05a1e3ac |
| tree | 2977e9fa1fcbbc58057684adf86ceb0291e16ef2 |
| parent | 0bd53dd2033c60d3446abfb83209237c6eb6c9e2 |
15 files changed, 41 insertions(+), 41 deletions(-)
lib/std/crypto/benchmark.zig+5-5| ... | ... | @@ -47,7 +47,7 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64 |
| 47 | 47 | while (offset < bytes) : (offset += block.len) { |
| 48 | 48 | h.update(block[0..]); |
| 49 | 49 | } |
| 50 | mem.forceEval(&h); | |
| 50 | mem.doNotOptimizeAway(&h); | |
| 51 | 51 | const end = timer.read(); |
| 52 | 52 | |
| 53 | 53 | const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s; |
| ... | ... | @@ -82,7 +82,7 @@ pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 { |
| 82 | 82 | const start = timer.lap(); |
| 83 | 83 | while (offset < bytes) : (offset += in.len) { |
| 84 | 84 | Mac.create(mac[0..], in[0..], key[0..]); |
| 85 | mem.forceEval(&mac); | |
| 85 | mem.doNotOptimizeAway(&mac); | |
| 86 | 86 | } |
| 87 | 87 | const end = timer.read(); |
| 88 | 88 | |
| ... | ... | @@ -109,7 +109,7 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c |
| 109 | 109 | var i: usize = 0; |
| 110 | 110 | while (i < exchange_count) : (i += 1) { |
| 111 | 111 | _ = DhKeyExchange.create(out[0..], out[0..], in[0..]); |
| 112 | mem.forceEval(&out); | |
| 112 | mem.doNotOptimizeAway(&out); | |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | const end = timer.read(); |
| ... | ... | @@ -134,7 +134,7 @@ pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count |
| 134 | 134 | var i: usize = 0; |
| 135 | 135 | while (i < signatures_count) : (i += 1) { |
| 136 | 136 | const s = try Signature.sign(&msg, key_pair, null); |
| 137 | mem.forceEval(&s); | |
| 137 | mem.doNotOptimizeAway(&s); | |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | const end = timer.read(); |
| ... | ... | @@ -170,7 +170,7 @@ pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64 |
| 170 | 170 | Aead.encrypt(in[0..], tag[0..], in[0..], &[_]u8{}, nonce, key); |
| 171 | 171 | Aead.decrypt(in[0..], in[0..], tag, &[_]u8{}, nonce, key) catch unreachable; |
| 172 | 172 | } |
| 173 | mem.forceEval(&in); | |
| 173 | mem.doNotOptimizeAway(&in); | |
| 174 | 174 | const end = timer.read(); |
| 175 | 175 | |
| 176 | 176 | const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s; |
lib/std/math.zig+2-2| ... | ... | @@ -109,8 +109,8 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool { |
| 109 | 109 | return fabs(x - y) < epsilon; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | pub fn forceEval(value: anytype) void { | |
| 113 | mem.forceEval(value); | |
| 112 | pub fn doNotOptimizeAway(value: anytype) void { | |
| 113 | mem.doNotOptimizeAway(value); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | pub fn raiseInvalid() void { |
lib/std/math/asinh.zig+2-2| ... | ... | @@ -56,7 +56,7 @@ fn asinh32(x: f32) f32 { |
| 56 | 56 | } |
| 57 | 57 | // |x| < 0x1p-12, inexact if x != 0 |
| 58 | 58 | else { |
| 59 | math.forceEval(x + 0x1.0p120); | |
| 59 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | return if (s != 0) -rx else rx; |
| ... | ... | @@ -87,7 +87,7 @@ fn asinh64(x: f64) f64 { |
| 87 | 87 | } |
| 88 | 88 | // |x| < 0x1p-12, inexact if x != 0 |
| 89 | 89 | else { |
| 90 | math.forceEval(x + 0x1.0p120); | |
| 90 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return if (s != 0) -rx else rx; |
lib/std/math/atan.zig+2-2| ... | ... | @@ -72,7 +72,7 @@ fn atan32(x_: f32) f32 { |
| 72 | 72 | // |x| < 2^(-12) |
| 73 | 73 | if (ix < 0x39800000) { |
| 74 | 74 | if (ix < 0x00800000) { |
| 75 | math.forceEval(x * x); | |
| 75 | math.doNotOptimizeAway(x * x); | |
| 76 | 76 | } |
| 77 | 77 | return x; |
| 78 | 78 | } |
| ... | ... | @@ -170,7 +170,7 @@ fn atan64(x_: f64) f64 { |
| 170 | 170 | // |x| < 2^(-27) |
| 171 | 171 | if (ix < 0x3E400000) { |
| 172 | 172 | if (ix < 0x00100000) { |
| 173 | math.forceEval(@floatCast(f32, x)); | |
| 173 | math.doNotOptimizeAway(@floatCast(f32, x)); | |
| 174 | 174 | } |
| 175 | 175 | return x; |
| 176 | 176 | } |
lib/std/math/atanh.zig+2-2| ... | ... | @@ -45,7 +45,7 @@ fn atanh_32(x: f32) f32 { |
| 45 | 45 | if (u < 0x3F800000 - (32 << 23)) { |
| 46 | 46 | // underflow |
| 47 | 47 | if (u < (1 << 23)) { |
| 48 | math.forceEval(y * y); | |
| 48 | math.doNotOptimizeAway(y * y); | |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | // |x| < 0.5 |
| ... | ... | @@ -74,7 +74,7 @@ fn atanh_64(x: f64) f64 { |
| 74 | 74 | if (e < 0x3FF - 32) { |
| 75 | 75 | // underflow |
| 76 | 76 | if (e == 0) { |
| 77 | math.forceEval(@floatCast(f32, y)); | |
| 77 | math.doNotOptimizeAway(@floatCast(f32, y)); | |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | // |x| < 0.5 |
lib/std/math/ceil.zig+4-4| ... | ... | @@ -47,14 +47,14 @@ fn ceil32(x: f32) f32 { |
| 47 | 47 | if (u & m == 0) { |
| 48 | 48 | return x; |
| 49 | 49 | } |
| 50 | math.forceEval(x + 0x1.0p120); | |
| 50 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 51 | 51 | if (u >> 31 == 0) { |
| 52 | 52 | u += m; |
| 53 | 53 | } |
| 54 | 54 | u &= ~m; |
| 55 | 55 | return @bitCast(f32, u); |
| 56 | 56 | } else { |
| 57 | math.forceEval(x + 0x1.0p120); | |
| 57 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 58 | 58 | if (u >> 31 != 0) { |
| 59 | 59 | return -0.0; |
| 60 | 60 | } else { |
| ... | ... | @@ -79,7 +79,7 @@ fn ceil64(x: f64) f64 { |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | if (e <= 0x3FF - 1) { |
| 82 | math.forceEval(y); | |
| 82 | math.doNotOptimizeAway(y); | |
| 83 | 83 | if (u >> 63 != 0) { |
| 84 | 84 | return -0.0; |
| 85 | 85 | } else { |
| ... | ... | @@ -106,7 +106,7 @@ fn ceil128(x: f128) f128 { |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | if (e <= 0x3FFF - 1) { |
| 109 | math.forceEval(y); | |
| 109 | math.doNotOptimizeAway(y); | |
| 110 | 110 | if (u >> 127 != 0) { |
| 111 | 111 | return -0.0; |
| 112 | 112 | } else { |
lib/std/math/exp.zig+4-4| ... | ... | @@ -56,7 +56,7 @@ fn exp32(x_: f32) f32 { |
| 56 | 56 | return x * 0x1.0p127; |
| 57 | 57 | } |
| 58 | 58 | if (sign != 0) { |
| 59 | math.forceEval(-0x1.0p-149 / x); // overflow | |
| 59 | math.doNotOptimizeAway(-0x1.0p-149 / x); // overflow | |
| 60 | 60 | // x <= -103.972084 |
| 61 | 61 | if (hx >= 0x42CFF1B5) { |
| 62 | 62 | return 0; |
| ... | ... | @@ -88,7 +88,7 @@ fn exp32(x_: f32) f32 { |
| 88 | 88 | hi = x; |
| 89 | 89 | lo = 0; |
| 90 | 90 | } else { |
| 91 | math.forceEval(0x1.0p127 + x); // inexact | |
| 91 | math.doNotOptimizeAway(0x1.0p127 + x); // inexact | |
| 92 | 92 | return 1 + x; |
| 93 | 93 | } |
| 94 | 94 | |
| ... | ... | @@ -139,7 +139,7 @@ fn exp64(x_: f64) f64 { |
| 139 | 139 | } |
| 140 | 140 | if (x < -708.39641853226410622) { |
| 141 | 141 | // underflow if x != -inf |
| 142 | // math.forceEval(@as(f32, -0x1.0p-149 / x)); | |
| 142 | // math.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x)); | |
| 143 | 143 | if (x < -745.13321910194110842) { |
| 144 | 144 | return 0; |
| 145 | 145 | } |
| ... | ... | @@ -172,7 +172,7 @@ fn exp64(x_: f64) f64 { |
| 172 | 172 | lo = 0; |
| 173 | 173 | } else { |
| 174 | 174 | // inexact if x != 0 |
| 175 | // math.forceEval(0x1.0p1023 + x); | |
| 175 | // math.doNotOptimizeAway(0x1.0p1023 + x); | |
| 176 | 176 | return 1 + x; |
| 177 | 177 | } |
| 178 | 178 |
lib/std/math/exp2.zig+2-2| ... | ... | @@ -70,7 +70,7 @@ fn exp2_32(x: f32) f32 { |
| 70 | 70 | // x < -126 |
| 71 | 71 | if (u >= 0x80000000) { |
| 72 | 72 | if (u >= 0xC3160000 or u & 0x000FFFF != 0) { |
| 73 | math.forceEval(-0x1.0p-149 / x); | |
| 73 | math.doNotOptimizeAway(-0x1.0p-149 / x); | |
| 74 | 74 | } |
| 75 | 75 | // x <= -150 |
| 76 | 76 | if (u >= 0x3160000) { |
| ... | ... | @@ -393,7 +393,7 @@ fn exp2_64(x: f64) f64 { |
| 393 | 393 | if (ux >> 63 != 0) { |
| 394 | 394 | // underflow |
| 395 | 395 | if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) { |
| 396 | math.forceEval(@floatCast(f32, -0x1.0p-149 / x)); | |
| 396 | math.doNotOptimizeAway(@floatCast(f32, -0x1.0p-149 / x)); | |
| 397 | 397 | } |
| 398 | 398 | if (x <= -1075) { |
| 399 | 399 | return 0; |
lib/std/math/expm1.zig+2-2| ... | ... | @@ -106,7 +106,7 @@ fn expm1_32(x_: f32) f32 { |
| 106 | 106 | // |x| < 2^(-25) |
| 107 | 107 | else if (hx < 0x33000000) { |
| 108 | 108 | if (hx < 0x00800000) { |
| 109 | math.forceEval(x * x); | |
| 109 | math.doNotOptimizeAway(x * x); | |
| 110 | 110 | } |
| 111 | 111 | return x; |
| 112 | 112 | } else { |
| ... | ... | @@ -237,7 +237,7 @@ fn expm1_64(x_: f64) f64 { |
| 237 | 237 | // |x| < 2^(-54) |
| 238 | 238 | else if (hx < 0x3C900000) { |
| 239 | 239 | if (hx < 0x00100000) { |
| 240 | math.forceEval(@floatCast(f32, x)); | |
| 240 | math.doNotOptimizeAway(@floatCast(f32, x)); | |
| 241 | 241 | } |
| 242 | 242 | return x; |
| 243 | 243 | } else { |
lib/std/math/floor.zig+6-6| ... | ... | @@ -50,13 +50,13 @@ fn floor16(x: f16) f16 { |
| 50 | 50 | if (u & m == 0) { |
| 51 | 51 | return x; |
| 52 | 52 | } |
| 53 | math.forceEval(x + 0x1.0p120); | |
| 53 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 54 | 54 | if (u >> 15 != 0) { |
| 55 | 55 | u += m; |
| 56 | 56 | } |
| 57 | 57 | return @bitCast(f16, u & ~m); |
| 58 | 58 | } else { |
| 59 | math.forceEval(x + 0x1.0p120); | |
| 59 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 60 | 60 | if (u >> 15 == 0) { |
| 61 | 61 | return 0.0; |
| 62 | 62 | } else { |
| ... | ... | @@ -84,13 +84,13 @@ fn floor32(x: f32) f32 { |
| 84 | 84 | if (u & m == 0) { |
| 85 | 85 | return x; |
| 86 | 86 | } |
| 87 | math.forceEval(x + 0x1.0p120); | |
| 87 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 88 | 88 | if (u >> 31 != 0) { |
| 89 | 89 | u += m; |
| 90 | 90 | } |
| 91 | 91 | return @bitCast(f32, u & ~m); |
| 92 | 92 | } else { |
| 93 | math.forceEval(x + 0x1.0p120); | |
| 93 | math.doNotOptimizeAway(x + 0x1.0p120); | |
| 94 | 94 | if (u >> 31 == 0) { |
| 95 | 95 | return 0.0; |
| 96 | 96 | } else { |
| ... | ... | @@ -115,7 +115,7 @@ fn floor64(x: f64) f64 { |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if (e <= 0x3FF - 1) { |
| 118 | math.forceEval(y); | |
| 118 | math.doNotOptimizeAway(y); | |
| 119 | 119 | if (u >> 63 != 0) { |
| 120 | 120 | return -1.0; |
| 121 | 121 | } else { |
| ... | ... | @@ -142,7 +142,7 @@ fn floor128(x: f128) f128 { |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if (e <= 0x3FFF - 1) { |
| 145 | math.forceEval(y); | |
| 145 | math.doNotOptimizeAway(y); | |
| 146 | 146 | if (u >> 127 != 0) { |
| 147 | 147 | return -1.0; |
| 148 | 148 | } else { |
lib/std/math/log1p.zig+1-1| ... | ... | @@ -62,7 +62,7 @@ fn log1p_32(x: f32) f32 { |
| 62 | 62 | if ((ix << 1) < (0x33800000 << 1)) { |
| 63 | 63 | // underflow if subnormal |
| 64 | 64 | if (ix & 0x7F800000 == 0) { |
| 65 | math.forceEval(x * x); | |
| 65 | math.doNotOptimizeAway(x * x); | |
| 66 | 66 | } |
| 67 | 67 | return x; |
| 68 | 68 | } |
lib/std/math/round.zig+3-3| ... | ... | @@ -43,7 +43,7 @@ fn round32(x_: f32) f32 { |
| 43 | 43 | x = -x; |
| 44 | 44 | } |
| 45 | 45 | if (e < 0x7F - 1) { |
| 46 | math.forceEval(x + math.f32_toint); | |
| 46 | math.doNotOptimizeAway(x + math.f32_toint); | |
| 47 | 47 | return 0 * @bitCast(f32, u); |
| 48 | 48 | } |
| 49 | 49 | |
| ... | ... | @@ -76,7 +76,7 @@ fn round64(x_: f64) f64 { |
| 76 | 76 | x = -x; |
| 77 | 77 | } |
| 78 | 78 | if (e < 0x3ff - 1) { |
| 79 | math.forceEval(x + math.f64_toint); | |
| 79 | math.doNotOptimizeAway(x + math.f64_toint); | |
| 80 | 80 | return 0 * @bitCast(f64, u); |
| 81 | 81 | } |
| 82 | 82 | |
| ... | ... | @@ -109,7 +109,7 @@ fn round128(x_: f128) f128 { |
| 109 | 109 | x = -x; |
| 110 | 110 | } |
| 111 | 111 | if (e < 0x3FFF - 1) { |
| 112 | math.forceEval(x + math.f64_toint); | |
| 112 | math.doNotOptimizeAway(x + math.f64_toint); | |
| 113 | 113 | return 0 * @bitCast(f128, u); |
| 114 | 114 | } |
| 115 | 115 |
lib/std/math/tanh.zig+2-2| ... | ... | @@ -67,7 +67,7 @@ fn tanh32(x: f32) f32 { |
| 67 | 67 | } |
| 68 | 68 | // |x| is subnormal |
| 69 | 69 | else { |
| 70 | math.forceEval(x * x); | |
| 70 | math.doNotOptimizeAway(x * x); | |
| 71 | 71 | t = x; |
| 72 | 72 | } |
| 73 | 73 | |
| ... | ... | @@ -112,7 +112,7 @@ fn tanh64(x: f64) f64 { |
| 112 | 112 | } |
| 113 | 113 | // |x| is subnormal |
| 114 | 114 | else { |
| 115 | math.forceEval(@floatCast(f32, x)); | |
| 115 | math.doNotOptimizeAway(@floatCast(f32, x)); | |
| 116 | 116 | t = x; |
| 117 | 117 | } |
| 118 | 118 |
lib/std/math/trunc.zig+3-3| ... | ... | @@ -46,7 +46,7 @@ fn trunc32(x: f32) f32 { |
| 46 | 46 | if (u & m == 0) { |
| 47 | 47 | return x; |
| 48 | 48 | } else { |
| 49 | math.forceEval(x + 0x1p120); | |
| 49 | math.doNotOptimizeAway(x + 0x1p120); | |
| 50 | 50 | return @bitCast(f32, u & ~m); |
| 51 | 51 | } |
| 52 | 52 | } |
| ... | ... | @@ -67,7 +67,7 @@ fn trunc64(x: f64) f64 { |
| 67 | 67 | if (u & m == 0) { |
| 68 | 68 | return x; |
| 69 | 69 | } else { |
| 70 | math.forceEval(x + 0x1p120); | |
| 70 | math.doNotOptimizeAway(x + 0x1p120); | |
| 71 | 71 | return @bitCast(f64, u & ~m); |
| 72 | 72 | } |
| 73 | 73 | } |
| ... | ... | @@ -88,7 +88,7 @@ fn trunc128(x: f128) f128 { |
| 88 | 88 | if (u & m == 0) { |
| 89 | 89 | return x; |
| 90 | 90 | } else { |
| 91 | math.forceEval(x + 0x1p120); | |
| 91 | math.doNotOptimizeAway(x + 0x1p120); | |
| 92 | 92 | return @bitCast(f128, u & ~m); |
| 93 | 93 | } |
| 94 | 94 | } |
lib/std/mem.zig+1-1| ... | ... | @@ -2161,7 +2161,7 @@ pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T { |
| 2161 | 2161 | /// Force an evaluation of the expression; this tries to prevent |
| 2162 | 2162 | /// the compiler from optimizing the computation away even if the |
| 2163 | 2163 | /// result eventually gets discarded. |
| 2164 | pub fn forceEval(val: anytype) void { | |
| 2164 | pub fn doNotOptimizeAway(val: anytype) void { | |
| 2165 | 2165 | asm volatile ("" |
| 2166 | 2166 | : |
| 2167 | 2167 | : [val] "rm" (val) |