| author | |
| committer | |
| log | d82b35901035a325ca7afd38b28ff2386f90ae84 |
| tree | 1a370e979308a3406ea42e55f16299d48ba19700 |
| parent | 77b96231a6bc195cc482d05599e8c20ee01645a6 |
72 files changed, 390 insertions(+), 391 deletions(-)
lib/compiler_rt/addf3.zig+11-11| ... | ... | @@ -38,14 +38,14 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 38 | 38 | bAbs -% @as(Z, 1) >= infRep - @as(Z, 1)) |
| 39 | 39 | { |
| 40 | 40 | // NaN + anything = qNaN |
| 41 | if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit)); | |
| 41 | if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit); | |
| 42 | 42 | // anything + NaN = qNaN |
| 43 | if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit)); | |
| 43 | if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit); | |
| 44 | 44 | |
| 45 | 45 | if (aAbs == infRep) { |
| 46 | 46 | // +/-infinity + -/+infinity = qNaN |
| 47 | 47 | if ((@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) == signBit) { |
| 48 | return @as(T, @bitCast(qnanRep)); | |
| 48 | return @bitCast(qnanRep); | |
| 49 | 49 | } |
| 50 | 50 | // +/-infinity + anything remaining = +/- infinity |
| 51 | 51 | else { |
| ... | ... | @@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 60 | 60 | if (aAbs == 0) { |
| 61 | 61 | // but we need to get the sign right for zero + zero |
| 62 | 62 | if (bAbs == 0) { |
| 63 | return @as(T, @bitCast(@as(Z, @bitCast(a)) & @as(Z, @bitCast(b)))); | |
| 63 | return @bitCast(@as(Z, @bitCast(a)) & @as(Z, @bitCast(b))); | |
| 64 | 64 | } else { |
| 65 | 65 | return b; |
| 66 | 66 | } |
| ... | ... | @@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Extract the exponent and significand from the (possibly swapped) a and b. |
| 81 | var aExponent = @as(i32, @intCast((aRep >> significandBits) & maxExponent)); | |
| 82 | var bExponent = @as(i32, @intCast((bRep >> significandBits) & maxExponent)); | |
| 81 | var aExponent: i32 = @intCast((aRep >> significandBits) & maxExponent); | |
| 82 | var bExponent: i32 = @intCast((bRep >> significandBits) & maxExponent); | |
| 83 | 83 | var aSignificand = aRep & significandMask; |
| 84 | 84 | var bSignificand = bRep & significandMask; |
| 85 | 85 | |
| ... | ... | @@ -101,7 +101,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 101 | 101 | |
| 102 | 102 | // Shift the significand of b by the difference in exponents, with a sticky |
| 103 | 103 | // bottom bit to get rounding correct. |
| 104 | const @"align" = @as(u32, @intCast(aExponent - bExponent)); | |
| 104 | const @"align": u32 = @intCast(aExponent - bExponent); | |
| 105 | 105 | if (@"align" != 0) { |
| 106 | 106 | if (@"align" < typeWidth) { |
| 107 | 107 | const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0; |
| ... | ... | @@ -113,7 +113,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 113 | 113 | if (subtraction) { |
| 114 | 114 | aSignificand -= bSignificand; |
| 115 | 115 | // If a == -b, return +zero. |
| 116 | if (aSignificand == 0) return @as(T, @bitCast(@as(Z, 0))); | |
| 116 | if (aSignificand == 0) return @bitCast(@as(Z, 0)); | |
| 117 | 117 | |
| 118 | 118 | // If partial cancellation occured, we need to left-shift the result |
| 119 | 119 | // and adjust the exponent: |
| ... | ... | @@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // If we have overflowed the type, return +/- infinity: |
| 138 | if (aExponent >= maxExponent) return @as(T, @bitCast(infRep | resultSign)); | |
| 138 | if (aExponent >= maxExponent) return @bitCast(infRep | resultSign); | |
| 139 | 139 | |
| 140 | 140 | if (aExponent <= 0) { |
| 141 | 141 | // Result is denormal; the exponent and round/sticky bits are zero. |
| 142 | 142 | // All we need to do is shift the significand and apply the correct sign. |
| 143 | 143 | aSignificand >>= @as(S, @intCast(4 - aExponent)); |
| 144 | return @as(T, @bitCast(resultSign | aSignificand)); | |
| 144 | return @bitCast(resultSign | aSignificand); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Low three bits are round, guard, and sticky. |
| ... | ... | @@ -164,7 +164,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 164 | 164 | if ((result >> significandBits) != 0) result |= integerBit; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | return @as(T, @bitCast(result)); | |
| 167 | return @bitCast(result); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | test { |
lib/compiler_rt/addf3_test.zig+9-9| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | const std = @import("std"); |
| 7 | 7 | const math = std.math; |
| 8 | const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64)); | |
| 8 | const qnan128: f128 = @bitCast(@as(u128, 0x7fff800000000000) << 64); | |
| 9 | 9 | |
| 10 | 10 | const __addtf3 = @import("addtf3.zig").__addtf3; |
| 11 | 11 | const __addxf3 = @import("addxf3.zig").__addxf3; |
| ... | ... | @@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3; |
| 14 | 14 | fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void { |
| 15 | 15 | const x = __addtf3(a, b); |
| 16 | 16 | |
| 17 | const rep = @as(u128, @bitCast(x)); | |
| 18 | const hi = @as(u64, @intCast(rep >> 64)); | |
| 19 | const lo = @as(u64, @truncate(rep)); | |
| 17 | const rep: u128 = @bitCast(x); | |
| 18 | const hi: u64 = @intCast(rep >> 64); | |
| 19 | const lo: u64 = @truncate(rep); | |
| 20 | 20 | |
| 21 | 21 | if (hi == expected_hi and lo == expected_lo) { |
| 22 | 22 | return; |
| ... | ... | @@ -53,9 +53,9 @@ test "addtf3" { |
| 53 | 53 | fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void { |
| 54 | 54 | const x = __subtf3(a, b); |
| 55 | 55 | |
| 56 | const rep = @as(u128, @bitCast(x)); | |
| 57 | const hi = @as(u64, @intCast(rep >> 64)); | |
| 58 | const lo = @as(u64, @truncate(rep)); | |
| 56 | const rep: u128 = @bitCast(x); | |
| 57 | const hi: u64 = @intCast(rep >> 64); | |
| 58 | const lo: u64 = @truncate(rep); | |
| 59 | 59 | |
| 60 | 60 | if (hi == expected_hi and lo == expected_lo) { |
| 61 | 61 | return; |
| ... | ... | @@ -87,11 +87,11 @@ test "subtf3" { |
| 87 | 87 | try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1)))); | |
| 90 | const qnan80: f80 = @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))); | |
| 91 | 91 | |
| 92 | 92 | fn test__addxf3(a: f80, b: f80, expected: u80) !void { |
| 93 | 93 | const x = __addxf3(a, b); |
| 94 | const rep = @as(u80, @bitCast(x)); | |
| 94 | const rep: u80 = @bitCast(x); | |
| 95 | 95 | |
| 96 | 96 | if (rep == expected) |
| 97 | 97 | return; |
lib/compiler_rt/arm.zig+1-1| ... | ... | @@ -192,6 +192,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void { |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | pub fn __aeabi_drsub(a: f64, b: f64) callconv(.AAPCS) f64 { |
| 195 | const neg_a = @as(f64, @bitCast(@as(u64, @bitCast(a)) ^ (@as(u64, 1) << 63))); | |
| 195 | const neg_a: f64 = @bitCast(@as(u64, @bitCast(a)) ^ (@as(u64, 1) << 63)); | |
| 196 | 196 | return b + neg_a; |
| 197 | 197 | } |
lib/compiler_rt/ceil.zig+6-6| ... | ... | @@ -27,11 +27,11 @@ comptime { |
| 27 | 27 | |
| 28 | 28 | pub fn __ceilh(x: f16) callconv(.C) f16 { |
| 29 | 29 | // TODO: more efficient implementation |
| 30 | return @as(f16, @floatCast(ceilf(x))); | |
| 30 | return @floatCast(ceilf(x)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | pub fn ceilf(x: f32) callconv(.C) f32 { |
| 34 | var u = @as(u32, @bitCast(x)); | |
| 34 | var u: u32 = @bitCast(x); | |
| 35 | 35 | var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; |
| 36 | 36 | var m: u32 = undefined; |
| 37 | 37 | |
| ... | ... | @@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 { |
| 52 | 52 | u += m; |
| 53 | 53 | } |
| 54 | 54 | u &= ~m; |
| 55 | return @as(f32, @bitCast(u)); | |
| 55 | return @bitCast(u); | |
| 56 | 56 | } else { |
| 57 | 57 | math.doNotOptimizeAway(x + 0x1.0p120); |
| 58 | 58 | if (u >> 31 != 0) { |
| ... | ... | @@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 { |
| 66 | 66 | pub fn ceil(x: f64) callconv(.C) f64 { |
| 67 | 67 | const f64_toint = 1.0 / math.floatEps(f64); |
| 68 | 68 | |
| 69 | const u = @as(u64, @bitCast(x)); | |
| 69 | const u: u64 = @bitCast(x); | |
| 70 | 70 | const e = (u >> 52) & 0x7FF; |
| 71 | 71 | var y: f64 = undefined; |
| 72 | 72 | |
| ... | ... | @@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 { |
| 96 | 96 | |
| 97 | 97 | pub fn __ceilx(x: f80) callconv(.C) f80 { |
| 98 | 98 | // TODO: more efficient implementation |
| 99 | return @as(f80, @floatCast(ceilq(x))); | |
| 99 | return @floatCast(ceilq(x)); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | pub fn ceilq(x: f128) callconv(.C) f128 { |
| 103 | 103 | const f128_toint = 1.0 / math.floatEps(f128); |
| 104 | 104 | |
| 105 | const u = @as(u128, @bitCast(x)); | |
| 105 | const u: u128 = @bitCast(x); | |
| 106 | 106 | const e = (u >> 112) & 0x7FFF; |
| 107 | 107 | var y: f128 = undefined; |
| 108 | 108 |
lib/compiler_rt/clzdi2_test.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const clz = @import("count0bits.zig"); |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__clzdi2(a: u64, expected: i64) !void { |
| 5 | var x = @as(i64, @bitCast(a)); | |
| 5 | var x: i64 = @bitCast(a); | |
| 6 | 6 | var result = clz.__clzdi2(x); |
| 7 | 7 | try testing.expectEqual(expected, result); |
| 8 | 8 | } |
lib/compiler_rt/clzsi2_test.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ const testing = @import("std").testing; |
| 5 | 5 | fn test__clzsi2(a: u32, expected: i32) !void { |
| 6 | 6 | const nakedClzsi2 = clz.__clzsi2; |
| 7 | 7 | const actualClzsi2 = @as(*const fn (a: i32) callconv(.C) i32, @ptrCast(&nakedClzsi2)); |
| 8 | const x = @as(i32, @bitCast(a)); | |
| 8 | const x: i32 = @bitCast(a); | |
| 9 | 9 | const result = actualClzsi2(x); |
| 10 | 10 | try testing.expectEqual(expected, result); |
| 11 | 11 | } |
lib/compiler_rt/clzti2_test.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const clz = @import("count0bits.zig"); |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__clzti2(a: u128, expected: i64) !void { |
| 5 | var x = @as(i128, @bitCast(a)); | |
| 5 | var x: i128 = @bitCast(a); | |
| 6 | 6 | var result = clz.__clzti2(x); |
| 7 | 7 | try testing.expectEqual(expected, result); |
| 8 | 8 | } |
lib/compiler_rt/cos.zig+3-3| ... | ... | @@ -35,7 +35,7 @@ pub fn cosf(x: f32) callconv(.C) f32 { |
| 35 | 35 | const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2 |
| 36 | 36 | const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18 |
| 37 | 37 | |
| 38 | var ix = @as(u32, @bitCast(x)); | |
| 38 | var ix: u32 = @bitCast(x); | |
| 39 | 39 | const sign = ix >> 31 != 0; |
| 40 | 40 | ix &= 0x7fffffff; |
| 41 | 41 | |
| ... | ... | @@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 { |
| 116 | 116 | |
| 117 | 117 | pub fn __cosx(a: f80) callconv(.C) f80 { |
| 118 | 118 | // TODO: more efficient implementation |
| 119 | return @as(f80, @floatCast(cosq(a))); | |
| 119 | return @floatCast(cosq(a)); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | pub fn cosq(a: f128) callconv(.C) f128 { |
| 123 | 123 | // TODO: more correct implementation |
| 124 | return cos(@as(f64, @floatCast(a))); | |
| 124 | return cos(@floatCast(a)); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/count0bits.zig+3-3| ... | ... | @@ -49,7 +49,7 @@ inline fn clzXi2(comptime T: type, a: T) i32 { |
| 49 | 49 | x = y; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | return @as(i32, @intCast(n - @as(T, @bitCast(x)))); | |
| 52 | return @intCast(n - @as(T, @bitCast(x))); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | fn __clzsi2_thumb1() callconv(.Naked) void { |
| ... | ... | @@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 { |
| 187 | 187 | x = x >> shift; |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | return @as(i32, @intCast(n - @as(T, @bitCast((x & 1))))); | |
| 190 | return @intCast(n - @as(T, @bitCast((x & 1)))); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | pub fn __ctzsi2(a: i32) callconv(.C) i32 { |
| ... | ... | @@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 { |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | // return ctz + 1 |
| 227 | return @as(i32, @intCast(n - @as(T, @bitCast((x & 1))))) + @as(i32, 1); | |
| 227 | return @as(i32, @intCast(n - @as(T, @bitCast((x & 1))))) + 1; | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | pub fn __ffssi2(a: i32) callconv(.C) i32 { |
lib/compiler_rt/ctzdi2_test.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig"); |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__ctzdi2(a: u64, expected: i32) !void { |
| 5 | var x = @as(i64, @bitCast(a)); | |
| 5 | var x: i64 = @bitCast(a); | |
| 6 | 6 | var result = ctz.__ctzdi2(x); |
| 7 | 7 | try testing.expectEqual(expected, result); |
| 8 | 8 | } |
lib/compiler_rt/ctzsi2_test.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig"); |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__ctzsi2(a: u32, expected: i32) !void { |
| 5 | var x = @as(i32, @bitCast(a)); | |
| 5 | var x: i32 = @bitCast(a); | |
| 6 | 6 | var result = ctz.__ctzsi2(x); |
| 7 | 7 | try testing.expectEqual(expected, result); |
| 8 | 8 | } |
lib/compiler_rt/ctzti2_test.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const ctz = @import("count0bits.zig"); |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__ctzti2(a: u128, expected: i32) !void { |
| 5 | var x = @as(i128, @bitCast(a)); | |
| 5 | var x: i128 = @bitCast(a); | |
| 6 | 6 | var result = ctz.__ctzti2(x); |
| 7 | 7 | try testing.expectEqual(expected, result); |
| 8 | 8 | } |
lib/compiler_rt/divdf3.zig+24-24| ... | ... | @@ -49,8 +49,8 @@ inline fn div(a: f64, b: f64) f64 { |
| 49 | 49 | const qnanRep = exponentMask | quietBit; |
| 50 | 50 | const infRep = @as(Z, @bitCast(std.math.inf(f64))); |
| 51 | 51 | |
| 52 | const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent)); | |
| 53 | const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent)); | |
| 52 | const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent); | |
| 53 | const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent); | |
| 54 | 54 | const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit; |
| 55 | 55 | |
| 56 | 56 | var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask; |
| ... | ... | @@ -63,36 +63,36 @@ inline fn div(a: f64, b: f64) f64 { |
| 63 | 63 | const bAbs: Z = @as(Z, @bitCast(b)) & absMask; |
| 64 | 64 | |
| 65 | 65 | // NaN / anything = qNaN |
| 66 | if (aAbs > infRep) return @as(f64, @bitCast(@as(Z, @bitCast(a)) | quietBit)); | |
| 66 | if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit); | |
| 67 | 67 | // anything / NaN = qNaN |
| 68 | if (bAbs > infRep) return @as(f64, @bitCast(@as(Z, @bitCast(b)) | quietBit)); | |
| 68 | if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit); | |
| 69 | 69 | |
| 70 | 70 | if (aAbs == infRep) { |
| 71 | 71 | // infinity / infinity = NaN |
| 72 | 72 | if (bAbs == infRep) { |
| 73 | return @as(f64, @bitCast(qnanRep)); | |
| 73 | return @bitCast(qnanRep); | |
| 74 | 74 | } |
| 75 | 75 | // infinity / anything else = +/- infinity |
| 76 | 76 | else { |
| 77 | return @as(f64, @bitCast(aAbs | quotientSign)); | |
| 77 | return @bitCast(aAbs | quotientSign); | |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // anything else / infinity = +/- 0 |
| 82 | if (bAbs == infRep) return @as(f64, @bitCast(quotientSign)); | |
| 82 | if (bAbs == infRep) return @bitCast(quotientSign); | |
| 83 | 83 | |
| 84 | 84 | if (aAbs == 0) { |
| 85 | 85 | // zero / zero = NaN |
| 86 | 86 | if (bAbs == 0) { |
| 87 | return @as(f64, @bitCast(qnanRep)); | |
| 87 | return @bitCast(qnanRep); | |
| 88 | 88 | } |
| 89 | 89 | // zero / anything else = +/- zero |
| 90 | 90 | else { |
| 91 | return @as(f64, @bitCast(quotientSign)); | |
| 91 | return @bitCast(quotientSign); | |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | // anything else / zero = +/- infinity |
| 95 | if (bAbs == 0) return @as(f64, @bitCast(infRep | quotientSign)); | |
| 95 | if (bAbs == 0) return @bitCast(infRep | quotientSign); | |
| 96 | 96 | |
| 97 | 97 | // one or both of a or b is denormal, the other (if applicable) is a |
| 98 | 98 | // normal number. Renormalize one or both of a and b, and set scale to |
| ... | ... | @@ -112,7 +112,7 @@ inline fn div(a: f64, b: f64) f64 { |
| 112 | 112 | // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax |
| 113 | 113 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 114 | 114 | // is accurate to about 3.5 binary digits. |
| 115 | const q31b: u32 = @as(u32, @truncate(bSignificand >> 21)); | |
| 115 | const q31b: u32 = @truncate(bSignificand >> 21); | |
| 116 | 116 | var recip32 = @as(u32, 0x7504f333) -% q31b; |
| 117 | 117 | |
| 118 | 118 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: |
| ... | ... | @@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 { |
| 123 | 123 | // with each iteration, so after three iterations, we have about 28 binary |
| 124 | 124 | // digits of accuracy. |
| 125 | 125 | var correction32: u32 = undefined; |
| 126 | correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1)); | |
| 127 | recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31)); | |
| 128 | correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1)); | |
| 129 | recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31)); | |
| 130 | correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1)); | |
| 131 | recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31)); | |
| 126 | correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1); | |
| 127 | recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31); | |
| 128 | correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1); | |
| 129 | recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31); | |
| 130 | correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1); | |
| 131 | recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31); | |
| 132 | 132 | |
| 133 | 133 | // recip32 might have overflowed to exactly zero in the preceding |
| 134 | 134 | // computation if the high word of b is exactly 1.0. This would sabotage |
| ... | ... | @@ -138,12 +138,12 @@ inline fn div(a: f64, b: f64) f64 { |
| 138 | 138 | |
| 139 | 139 | // We need to perform one more iteration to get us to 56 binary digits; |
| 140 | 140 | // The last iteration needs to happen with extra precision. |
| 141 | const q63blo: u32 = @as(u32, @truncate(bSignificand << 11)); | |
| 141 | const q63blo: u32 = @truncate(bSignificand << 11); | |
| 142 | 142 | var correction: u64 = undefined; |
| 143 | 143 | var reciprocal: u64 = undefined; |
| 144 | 144 | correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1; |
| 145 | const cHi = @as(u32, @truncate(correction >> 32)); | |
| 146 | const cLo = @as(u32, @truncate(correction)); | |
| 145 | const cHi: u32 = @truncate(correction >> 32); | |
| 146 | const cLo: u32 = @truncate(correction); | |
| 147 | 147 | reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32); |
| 148 | 148 | |
| 149 | 149 | // We already adjusted the 32-bit estimate, now we need to adjust the final |
| ... | ... | @@ -195,7 +195,7 @@ inline fn div(a: f64, b: f64) f64 { |
| 195 | 195 | |
| 196 | 196 | if (writtenExponent >= maxExponent) { |
| 197 | 197 | // If we have overflowed the exponent, return infinity. |
| 198 | return @as(f64, @bitCast(infRep | quotientSign)); | |
| 198 | return @bitCast(infRep | quotientSign); | |
| 199 | 199 | } else if (writtenExponent < 1) { |
| 200 | 200 | if (writtenExponent == 0) { |
| 201 | 201 | // Check whether the rounded result is normal. |
| ... | ... | @@ -206,12 +206,12 @@ inline fn div(a: f64, b: f64) f64 { |
| 206 | 206 | absResult += round; |
| 207 | 207 | if ((absResult & ~significandMask) != 0) { |
| 208 | 208 | // The rounded result is normal; return it. |
| 209 | return @as(f64, @bitCast(absResult | quotientSign)); | |
| 209 | return @bitCast(absResult | quotientSign); | |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | // Flush denormals to zero. In the future, it would be nice to add |
| 213 | 213 | // code to round them correctly. |
| 214 | return @as(f64, @bitCast(quotientSign)); | |
| 214 | return @bitCast(quotientSign); | |
| 215 | 215 | } else { |
| 216 | 216 | const round = @intFromBool((residual << 1) > bSignificand); |
| 217 | 217 | // Clear the implicit bit |
| ... | ... | @@ -221,7 +221,7 @@ inline fn div(a: f64, b: f64) f64 { |
| 221 | 221 | // Round |
| 222 | 222 | absResult +%= round; |
| 223 | 223 | // Insert the sign and return |
| 224 | return @as(f64, @bitCast(absResult | quotientSign)); | |
| 224 | return @bitCast(absResult | quotientSign); | |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 |
lib/compiler_rt/divdf3_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3; |
| 6 | 6 | const testing = @import("std").testing; |
| 7 | 7 | |
| 8 | 8 | fn compareResultD(result: f64, expected: u64) bool { |
| 9 | const rep = @as(u64, @bitCast(result)); | |
| 9 | const rep: u64 = @bitCast(result); | |
| 10 | 10 | |
| 11 | 11 | if (rep == expected) { |
| 12 | 12 | return true; |
lib/compiler_rt/divhf3.zig+1-1| ... | ... | @@ -7,5 +7,5 @@ comptime { |
| 7 | 7 | |
| 8 | 8 | pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 { |
| 9 | 9 | // TODO: more efficient implementation |
| 10 | return @as(f16, @floatCast(divsf3.__divsf3(a, b))); | |
| 10 | return @floatCast(divsf3.__divsf3(a, b)); | |
| 11 | 11 | } |
lib/compiler_rt/divsf3.zig+22-22| ... | ... | @@ -44,10 +44,10 @@ inline fn div(a: f32, b: f32) f32 { |
| 44 | 44 | const absMask = signBit - 1; |
| 45 | 45 | const exponentMask = absMask ^ significandMask; |
| 46 | 46 | const qnanRep = exponentMask | quietBit; |
| 47 | const infRep = @as(Z, @bitCast(std.math.inf(f32))); | |
| 47 | const infRep: Z = @bitCast(std.math.inf(f32)); | |
| 48 | 48 | |
| 49 | const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent)); | |
| 50 | const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent)); | |
| 49 | const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent); | |
| 50 | const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent); | |
| 51 | 51 | const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit; |
| 52 | 52 | |
| 53 | 53 | var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask; |
| ... | ... | @@ -60,36 +60,36 @@ inline fn div(a: f32, b: f32) f32 { |
| 60 | 60 | const bAbs: Z = @as(Z, @bitCast(b)) & absMask; |
| 61 | 61 | |
| 62 | 62 | // NaN / anything = qNaN |
| 63 | if (aAbs > infRep) return @as(f32, @bitCast(@as(Z, @bitCast(a)) | quietBit)); | |
| 63 | if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit); | |
| 64 | 64 | // anything / NaN = qNaN |
| 65 | if (bAbs > infRep) return @as(f32, @bitCast(@as(Z, @bitCast(b)) | quietBit)); | |
| 65 | if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit); | |
| 66 | 66 | |
| 67 | 67 | if (aAbs == infRep) { |
| 68 | 68 | // infinity / infinity = NaN |
| 69 | 69 | if (bAbs == infRep) { |
| 70 | return @as(f32, @bitCast(qnanRep)); | |
| 70 | return @bitCast(qnanRep); | |
| 71 | 71 | } |
| 72 | 72 | // infinity / anything else = +/- infinity |
| 73 | 73 | else { |
| 74 | return @as(f32, @bitCast(aAbs | quotientSign)); | |
| 74 | return @bitCast(aAbs | quotientSign); | |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // anything else / infinity = +/- 0 |
| 79 | if (bAbs == infRep) return @as(f32, @bitCast(quotientSign)); | |
| 79 | if (bAbs == infRep) return @bitCast(quotientSign); | |
| 80 | 80 | |
| 81 | 81 | if (aAbs == 0) { |
| 82 | 82 | // zero / zero = NaN |
| 83 | 83 | if (bAbs == 0) { |
| 84 | return @as(f32, @bitCast(qnanRep)); | |
| 84 | return @bitCast(qnanRep); | |
| 85 | 85 | } |
| 86 | 86 | // zero / anything else = +/- zero |
| 87 | 87 | else { |
| 88 | return @as(f32, @bitCast(quotientSign)); | |
| 88 | return @bitCast(quotientSign); | |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | // anything else / zero = +/- infinity |
| 92 | if (bAbs == 0) return @as(f32, @bitCast(infRep | quotientSign)); | |
| 92 | if (bAbs == 0) return @bitCast(infRep | quotientSign); | |
| 93 | 93 | |
| 94 | 94 | // one or both of a or b is denormal, the other (if applicable) is a |
| 95 | 95 | // normal number. Renormalize one or both of a and b, and set scale to |
| ... | ... | @@ -120,12 +120,12 @@ inline fn div(a: f32, b: f32) f32 { |
| 120 | 120 | // with each iteration, so after three iterations, we have about 28 binary |
| 121 | 121 | // digits of accuracy. |
| 122 | 122 | var correction: u32 = undefined; |
| 123 | correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1)); | |
| 124 | reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31)); | |
| 125 | correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1)); | |
| 126 | reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31)); | |
| 127 | correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1)); | |
| 128 | reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31)); | |
| 123 | correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1); | |
| 124 | reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31); | |
| 125 | correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1); | |
| 126 | reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31); | |
| 127 | correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1); | |
| 128 | reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31); | |
| 129 | 129 | |
| 130 | 130 | // Exhaustive testing shows that the error in reciprocal after three steps |
| 131 | 131 | // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our |
| ... | ... | @@ -147,7 +147,7 @@ inline fn div(a: f32, b: f32) f32 { |
| 147 | 147 | // is the error in the reciprocal of b scaled by the maximum |
| 148 | 148 | // possible value of a. As a consequence of this error bound, |
| 149 | 149 | // either q or nextafter(q) is the correctly rounded |
| 150 | var quotient: Z = @as(u32, @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32)); | |
| 150 | var quotient: Z = @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32); | |
| 151 | 151 | |
| 152 | 152 | // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). |
| 153 | 153 | // In either case, we are going to compute a residual of the form |
| ... | ... | @@ -175,7 +175,7 @@ inline fn div(a: f32, b: f32) f32 { |
| 175 | 175 | |
| 176 | 176 | if (writtenExponent >= maxExponent) { |
| 177 | 177 | // If we have overflowed the exponent, return infinity. |
| 178 | return @as(f32, @bitCast(infRep | quotientSign)); | |
| 178 | return @bitCast(infRep | quotientSign); | |
| 179 | 179 | } else if (writtenExponent < 1) { |
| 180 | 180 | if (writtenExponent == 0) { |
| 181 | 181 | // Check whether the rounded result is normal. |
| ... | ... | @@ -186,12 +186,12 @@ inline fn div(a: f32, b: f32) f32 { |
| 186 | 186 | absResult += round; |
| 187 | 187 | if ((absResult & ~significandMask) > 0) { |
| 188 | 188 | // The rounded result is normal; return it. |
| 189 | return @as(f32, @bitCast(absResult | quotientSign)); | |
| 189 | return @bitCast(absResult | quotientSign); | |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | // Flush denormals to zero. In the future, it would be nice to add |
| 193 | 193 | // code to round them correctly. |
| 194 | return @as(f32, @bitCast(quotientSign)); | |
| 194 | return @bitCast(quotientSign); | |
| 195 | 195 | } else { |
| 196 | 196 | const round = @intFromBool((residual << 1) > bSignificand); |
| 197 | 197 | // Clear the implicit bit |
| ... | ... | @@ -201,7 +201,7 @@ inline fn div(a: f32, b: f32) f32 { |
| 201 | 201 | // Round |
| 202 | 202 | absResult +%= round; |
| 203 | 203 | // Insert the sign and return |
| 204 | return @as(f32, @bitCast(absResult | quotientSign)); | |
| 204 | return @bitCast(absResult | quotientSign); | |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 |
lib/compiler_rt/divsf3_test.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3; |
| 6 | 6 | const testing = @import("std").testing; |
| 7 | 7 | |
| 8 | 8 | fn compareResultF(result: f32, expected: u32) bool { |
| 9 | const rep = @as(u32, @bitCast(result)); | |
| 9 | const rep: u32 = @bitCast(result); | |
| 10 | 10 | |
| 11 | 11 | if (rep == expected) { |
| 12 | 12 | return true; |
lib/compiler_rt/divtf3.zig+29-29| ... | ... | @@ -41,10 +41,10 @@ inline fn div(a: f128, b: f128) f128 { |
| 41 | 41 | const absMask = signBit - 1; |
| 42 | 42 | const exponentMask = absMask ^ significandMask; |
| 43 | 43 | const qnanRep = exponentMask | quietBit; |
| 44 | const infRep = @as(Z, @bitCast(std.math.inf(f128))); | |
| 44 | const infRep: Z = @bitCast(std.math.inf(f128)); | |
| 45 | 45 | |
| 46 | const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent)); | |
| 47 | const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent)); | |
| 46 | const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent); | |
| 47 | const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent); | |
| 48 | 48 | const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit; |
| 49 | 49 | |
| 50 | 50 | var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask; |
| ... | ... | @@ -57,36 +57,36 @@ inline fn div(a: f128, b: f128) f128 { |
| 57 | 57 | const bAbs: Z = @as(Z, @bitCast(b)) & absMask; |
| 58 | 58 | |
| 59 | 59 | // NaN / anything = qNaN |
| 60 | if (aAbs > infRep) return @as(f128, @bitCast(@as(Z, @bitCast(a)) | quietBit)); | |
| 60 | if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit); | |
| 61 | 61 | // anything / NaN = qNaN |
| 62 | if (bAbs > infRep) return @as(f128, @bitCast(@as(Z, @bitCast(b)) | quietBit)); | |
| 62 | if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit); | |
| 63 | 63 | |
| 64 | 64 | if (aAbs == infRep) { |
| 65 | 65 | // infinity / infinity = NaN |
| 66 | 66 | if (bAbs == infRep) { |
| 67 | return @as(f128, @bitCast(qnanRep)); | |
| 67 | return @bitCast(qnanRep); | |
| 68 | 68 | } |
| 69 | 69 | // infinity / anything else = +/- infinity |
| 70 | 70 | else { |
| 71 | return @as(f128, @bitCast(aAbs | quotientSign)); | |
| 71 | return @bitCast(aAbs | quotientSign); | |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // anything else / infinity = +/- 0 |
| 76 | if (bAbs == infRep) return @as(f128, @bitCast(quotientSign)); | |
| 76 | if (bAbs == infRep) return @bitCast(quotientSign); | |
| 77 | 77 | |
| 78 | 78 | if (aAbs == 0) { |
| 79 | 79 | // zero / zero = NaN |
| 80 | 80 | if (bAbs == 0) { |
| 81 | return @as(f128, @bitCast(qnanRep)); | |
| 81 | return @bitCast(qnanRep); | |
| 82 | 82 | } |
| 83 | 83 | // zero / anything else = +/- zero |
| 84 | 84 | else { |
| 85 | return @as(f128, @bitCast(quotientSign)); | |
| 85 | return @bitCast(quotientSign); | |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | // anything else / zero = +/- infinity |
| 89 | if (bAbs == 0) return @as(f128, @bitCast(infRep | quotientSign)); | |
| 89 | if (bAbs == 0) return @bitCast(infRep | quotientSign); | |
| 90 | 90 | |
| 91 | 91 | // one or both of a or b is denormal, the other (if applicable) is a |
| 92 | 92 | // normal number. Renormalize one or both of a and b, and set scale to |
| ... | ... | @@ -106,7 +106,7 @@ inline fn div(a: f128, b: f128) f128 { |
| 106 | 106 | // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax |
| 107 | 107 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 108 | 108 | // is accurate to about 3.5 binary digits. |
| 109 | const q63b = @as(u64, @truncate(bSignificand >> 49)); | |
| 109 | const q63b: u64 = @truncate(bSignificand >> 49); | |
| 110 | 110 | var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b; |
| 111 | 111 | // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2) |
| 112 | 112 | |
| ... | ... | @@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 { |
| 117 | 117 | // This doubles the number of correct binary digits in the approximation |
| 118 | 118 | // with each iteration. |
| 119 | 119 | var correction64: u64 = undefined; |
| 120 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 121 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 122 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 123 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 124 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 125 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 126 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 127 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 128 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 129 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 120 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 121 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 122 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 123 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 124 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 125 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 126 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 127 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 128 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 129 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 130 | 130 | |
| 131 | 131 | // The reciprocal may have overflowed to zero if the upper half of b is |
| 132 | 132 | // exactly 1.0. This would sabatoge the full-width final stage of the |
| ... | ... | @@ -135,7 +135,7 @@ inline fn div(a: f128, b: f128) f128 { |
| 135 | 135 | |
| 136 | 136 | // We need to perform one more iteration to get us to 112 binary digits; |
| 137 | 137 | // The last iteration needs to happen with extra precision. |
| 138 | const q127blo: u64 = @as(u64, @truncate(bSignificand << 15)); | |
| 138 | const q127blo: u64 = @truncate(bSignificand << 15); | |
| 139 | 139 | var correction: u128 = undefined; |
| 140 | 140 | var reciprocal: u128 = undefined; |
| 141 | 141 | |
| ... | ... | @@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 { |
| 151 | 151 | |
| 152 | 152 | correction = -%(r64q63 + (r64q127 >> 64)); |
| 153 | 153 | |
| 154 | const cHi = @as(u64, @truncate(correction >> 64)); | |
| 155 | const cLo = @as(u64, @truncate(correction)); | |
| 154 | const cHi: u64 = @truncate(correction >> 64); | |
| 155 | const cLo: u64 = @truncate(correction); | |
| 156 | 156 | |
| 157 | 157 | wideMultiply(u128, recip64, cHi, &dummy, &r64cH); |
| 158 | 158 | wideMultiply(u128, recip64, cLo, &dummy, &r64cL); |
| ... | ... | @@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 { |
| 210 | 210 | |
| 211 | 211 | if (writtenExponent >= maxExponent) { |
| 212 | 212 | // If we have overflowed the exponent, return infinity. |
| 213 | return @as(f128, @bitCast(infRep | quotientSign)); | |
| 213 | return @bitCast(infRep | quotientSign); | |
| 214 | 214 | } else if (writtenExponent < 1) { |
| 215 | 215 | if (writtenExponent == 0) { |
| 216 | 216 | // Check whether the rounded result is normal. |
| ... | ... | @@ -221,12 +221,12 @@ inline fn div(a: f128, b: f128) f128 { |
| 221 | 221 | absResult += round; |
| 222 | 222 | if ((absResult & ~significandMask) > 0) { |
| 223 | 223 | // The rounded result is normal; return it. |
| 224 | return @as(f128, @bitCast(absResult | quotientSign)); | |
| 224 | return @bitCast(absResult | quotientSign); | |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | // Flush denormals to zero. In the future, it would be nice to add |
| 228 | 228 | // code to round them correctly. |
| 229 | return @as(f128, @bitCast(quotientSign)); | |
| 229 | return @bitCast(quotientSign); | |
| 230 | 230 | } else { |
| 231 | 231 | const round = @intFromBool((residual << 1) >= bSignificand); |
| 232 | 232 | // Clear the implicit bit |
| ... | ... | @@ -236,7 +236,7 @@ inline fn div(a: f128, b: f128) f128 { |
| 236 | 236 | // Round |
| 237 | 237 | absResult +%= round; |
| 238 | 238 | // Insert the sign and return |
| 239 | return @as(f128, @bitCast(absResult | quotientSign)); | |
| 239 | return @bitCast(absResult | quotientSign); | |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 |
lib/compiler_rt/divtf3_test.zig+3-3| ... | ... | @@ -5,9 +5,9 @@ const testing = std.testing; |
| 5 | 5 | const __divtf3 = @import("divtf3.zig").__divtf3; |
| 6 | 6 | |
| 7 | 7 | fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool { |
| 8 | const rep = @as(u128, @bitCast(result)); | |
| 9 | const hi = @as(u64, @truncate(rep >> 64)); | |
| 10 | const lo = @as(u64, @truncate(rep)); | |
| 8 | const rep: u128 = @bitCast(result); | |
| 9 | const hi: u64 = @truncate(rep >> 64); | |
| 10 | const lo: u64 = @truncate(rep); | |
| 11 | 11 | |
| 12 | 12 | if (hi == expectedHi and lo == expectedLo) { |
| 13 | 13 | return true; |
lib/compiler_rt/divxf3.zig+24-24| ... | ... | @@ -30,10 +30,10 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 30 | 30 | |
| 31 | 31 | const absMask = signBit - 1; |
| 32 | 32 | const qnanRep = @as(Z, @bitCast(std.math.nan(T))) | quietBit; |
| 33 | const infRep = @as(Z, @bitCast(std.math.inf(T))); | |
| 33 | const infRep: Z = @bitCast(std.math.inf(T)); | |
| 34 | 34 | |
| 35 | const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent)); | |
| 36 | const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent)); | |
| 35 | const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent); | |
| 36 | const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent); | |
| 37 | 37 | const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit; |
| 38 | 38 | |
| 39 | 39 | var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask; |
| ... | ... | @@ -46,36 +46,36 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 46 | 46 | const bAbs: Z = @as(Z, @bitCast(b)) & absMask; |
| 47 | 47 | |
| 48 | 48 | // NaN / anything = qNaN |
| 49 | if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit)); | |
| 49 | if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit); | |
| 50 | 50 | // anything / NaN = qNaN |
| 51 | if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit)); | |
| 51 | if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit); | |
| 52 | 52 | |
| 53 | 53 | if (aAbs == infRep) { |
| 54 | 54 | // infinity / infinity = NaN |
| 55 | 55 | if (bAbs == infRep) { |
| 56 | return @as(T, @bitCast(qnanRep)); | |
| 56 | return @bitCast(qnanRep); | |
| 57 | 57 | } |
| 58 | 58 | // infinity / anything else = +/- infinity |
| 59 | 59 | else { |
| 60 | return @as(T, @bitCast(aAbs | quotientSign)); | |
| 60 | return @bitCast(aAbs | quotientSign); | |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // anything else / infinity = +/- 0 |
| 65 | if (bAbs == infRep) return @as(T, @bitCast(quotientSign)); | |
| 65 | if (bAbs == infRep) return @bitCast(quotientSign); | |
| 66 | 66 | |
| 67 | 67 | if (aAbs == 0) { |
| 68 | 68 | // zero / zero = NaN |
| 69 | 69 | if (bAbs == 0) { |
| 70 | return @as(T, @bitCast(qnanRep)); | |
| 70 | return @bitCast(qnanRep); | |
| 71 | 71 | } |
| 72 | 72 | // zero / anything else = +/- zero |
| 73 | 73 | else { |
| 74 | return @as(T, @bitCast(quotientSign)); | |
| 74 | return @bitCast(quotientSign); | |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | // anything else / zero = +/- infinity |
| 78 | if (bAbs == 0) return @as(T, @bitCast(infRep | quotientSign)); | |
| 78 | if (bAbs == 0) return @bitCast(infRep | quotientSign); | |
| 79 | 79 | |
| 80 | 80 | // one or both of a or b is denormal, the other (if applicable) is a |
| 81 | 81 | // normal number. Renormalize one or both of a and b, and set scale to |
| ... | ... | @@ -89,7 +89,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 89 | 89 | // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax |
| 90 | 90 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 91 | 91 | // is accurate to about 3.5 binary digits. |
| 92 | const q63b = @as(u64, @intCast(bSignificand)); | |
| 92 | const q63b: u64 = @intCast(bSignificand); | |
| 93 | 93 | var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b; |
| 94 | 94 | // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2) |
| 95 | 95 | |
| ... | ... | @@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 100 | 100 | // This doubles the number of correct binary digits in the approximation |
| 101 | 101 | // with each iteration. |
| 102 | 102 | var correction64: u64 = undefined; |
| 103 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 104 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 105 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 106 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 107 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 108 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 109 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 110 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 111 | correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1)); | |
| 112 | recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63)); | |
| 103 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 104 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 105 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 106 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 107 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 108 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 109 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 110 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 111 | correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1); | |
| 112 | recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63); | |
| 113 | 113 | |
| 114 | 114 | // The reciprocal may have overflowed to zero if the upper half of b is |
| 115 | 115 | // exactly 1.0. This would sabatoge the full-width final stage of the |
| ... | ... | @@ -128,8 +128,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 128 | 128 | |
| 129 | 129 | correction = -%correction; |
| 130 | 130 | |
| 131 | const cHi = @as(u64, @truncate(correction >> 64)); | |
| 132 | const cLo = @as(u64, @truncate(correction)); | |
| 131 | const cHi: u64 = @truncate(correction >> 64); | |
| 132 | const cLo: u64 = @truncate(correction); | |
| 133 | 133 | |
| 134 | 134 | var r64cH: u128 = undefined; |
| 135 | 135 | var r64cL: u128 = undefined; |
lib/compiler_rt/divxf3_test.zig+3-3| ... | ... | @@ -5,7 +5,7 @@ const testing = std.testing; |
| 5 | 5 | const __divxf3 = @import("divxf3.zig").__divxf3; |
| 6 | 6 | |
| 7 | 7 | fn compareResult(result: f80, expected: u80) bool { |
| 8 | const rep = @as(u80, @bitCast(result)); | |
| 8 | const rep: u80 = @bitCast(result); | |
| 9 | 9 | |
| 10 | 10 | if (rep == expected) return true; |
| 11 | 11 | // test other possible NaN representations (signal NaN) |
| ... | ... | @@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void { |
| 25 | 25 | const x = __divxf3(a, b); |
| 26 | 26 | |
| 27 | 27 | // Next float (assuming normal, non-zero result) |
| 28 | const x_plus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) + 1) | integerBit)); | |
| 28 | const x_plus_eps: f80 = @bitCast((@as(u80, @bitCast(x)) + 1) | integerBit); | |
| 29 | 29 | // Prev float (assuming normal, non-zero result) |
| 30 | const x_minus_eps = @as(f80, @bitCast((@as(u80, @bitCast(x)) - 1) | integerBit)); | |
| 30 | const x_minus_eps: f80 = @bitCast((@as(u80, @bitCast(x)) - 1) | integerBit); | |
| 31 | 31 | |
| 32 | 32 | // Make sure result is more accurate than the adjacent floats |
| 33 | 33 | const err_x = @fabs(@mulAdd(f80, x, b, -a)); |
lib/compiler_rt/emutls.zig+1-1| ... | ... | @@ -125,7 +125,7 @@ const ObjectArray = struct { |
| 125 | 125 | if (self.slots[index] == null) { |
| 126 | 126 | // initialize the slot |
| 127 | 127 | const size = control.size; |
| 128 | const alignment = @as(u29, @truncate(control.alignment)); | |
| 128 | const alignment: u29 = @truncate(control.alignment); | |
| 129 | 129 | |
| 130 | 130 | var data = simple_allocator.advancedAlloc(alignment, size); |
| 131 | 131 | errdefer simple_allocator.free(data); |
lib/compiler_rt/exp.zig+10-10| ... | ... | @@ -39,8 +39,8 @@ pub fn expf(x_: f32) callconv(.C) f32 { |
| 39 | 39 | const P2 = -2.7667332906e-3; |
| 40 | 40 | |
| 41 | 41 | var x = x_; |
| 42 | var hx = @as(u32, @bitCast(x)); | |
| 43 | const sign = @as(i32, @intCast(hx >> 31)); | |
| 42 | var hx: u32 = @bitCast(x); | |
| 43 | const sign: i32 = @intCast(hx >> 31); | |
| 44 | 44 | hx &= 0x7FFFFFFF; |
| 45 | 45 | |
| 46 | 46 | if (math.isNan(x)) { |
| ... | ... | @@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 { |
| 74 | 74 | if (hx > 0x3EB17218) { |
| 75 | 75 | // |x| > 1.5 * ln2 |
| 76 | 76 | if (hx > 0x3F851592) { |
| 77 | k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))])); | |
| 77 | k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]); | |
| 78 | 78 | } else { |
| 79 | 79 | k = 1 - sign - sign; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | const fk = @as(f32, @floatFromInt(k)); | |
| 82 | const fk: f32 = @floatFromInt(k); | |
| 83 | 83 | hi = x - fk * ln2hi; |
| 84 | 84 | lo = fk * ln2lo; |
| 85 | 85 | x = hi - lo; |
| ... | ... | @@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 { |
| 117 | 117 | const P5: f64 = 4.13813679705723846039e-08; |
| 118 | 118 | |
| 119 | 119 | var x = x_; |
| 120 | var ux = @as(u64, @bitCast(x)); | |
| 120 | var ux: u64 = @bitCast(x); | |
| 121 | 121 | var hx = ux >> 32; |
| 122 | const sign = @as(i32, @intCast(hx >> 31)); | |
| 122 | const sign: i32 = @intCast(hx >> 31); | |
| 123 | 123 | hx &= 0x7FFFFFFF; |
| 124 | 124 | |
| 125 | 125 | if (math.isNan(x)) { |
| ... | ... | @@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 { |
| 157 | 157 | if (hx > 0x3FD62E42) { |
| 158 | 158 | // |x| >= 1.5 * ln2 |
| 159 | 159 | if (hx > 0x3FF0A2B2) { |
| 160 | k = @as(i32, @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))])); | |
| 160 | k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]); | |
| 161 | 161 | } else { |
| 162 | 162 | k = 1 - sign - sign; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | const dk = @as(f64, @floatFromInt(k)); | |
| 165 | const dk: f64 = @floatFromInt(k); | |
| 166 | 166 | hi = x - dk * ln2hi; |
| 167 | 167 | lo = dk * ln2lo; |
| 168 | 168 | x = hi - lo; |
| ... | ... | @@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 { |
| 191 | 191 | |
| 192 | 192 | pub fn __expx(a: f80) callconv(.C) f80 { |
| 193 | 193 | // TODO: more efficient implementation |
| 194 | return @as(f80, @floatCast(expq(a))); | |
| 194 | return @floatCast(expq(a)); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | pub fn expq(a: f128) callconv(.C) f128 { |
| 198 | 198 | // TODO: more correct implementation |
| 199 | return exp(@as(f64, @floatCast(a))); | |
| 199 | return exp(@floatCast(a)); | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | pub fn expl(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/exp2.zig+10-10| ... | ... | @@ -31,14 +31,14 @@ pub fn __exp2h(x: f16) callconv(.C) f16 { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | pub fn exp2f(x: f32) callconv(.C) f32 { |
| 34 | const tblsiz = @as(u32, @intCast(exp2ft.len)); | |
| 34 | const tblsiz: u32 = @intCast(exp2ft.len); | |
| 35 | 35 | const redux: f32 = 0x1.8p23 / @as(f32, @floatFromInt(tblsiz)); |
| 36 | 36 | const P1: f32 = 0x1.62e430p-1; |
| 37 | 37 | const P2: f32 = 0x1.ebfbe0p-3; |
| 38 | 38 | const P3: f32 = 0x1.c6b348p-5; |
| 39 | 39 | const P4: f32 = 0x1.3b2c9cp-7; |
| 40 | 40 | |
| 41 | var u = @as(u32, @bitCast(x)); | |
| 41 | var u: u32 = @bitCast(x); | |
| 42 | 42 | const ix = u & 0x7FFFFFFF; |
| 43 | 43 | |
| 44 | 44 | // |x| > 126 |
| ... | ... | @@ -72,11 +72,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 { |
| 72 | 72 | // intended result but should confirm how GCC/Clang handle this to ensure. |
| 73 | 73 | |
| 74 | 74 | var uf = x + redux; |
| 75 | var i_0 = @as(u32, @bitCast(uf)); | |
| 75 | var i_0: u32 = @bitCast(uf); | |
| 76 | 76 | i_0 +%= tblsiz / 2; |
| 77 | 77 | |
| 78 | 78 | const k = i_0 / tblsiz; |
| 79 | const uk = @as(f64, @bitCast(@as(u64, 0x3FF + k) << 52)); | |
| 79 | const uk: f64 = @bitCast(@as(u64, 0x3FF + k) << 52); | |
| 80 | 80 | i_0 &= tblsiz - 1; |
| 81 | 81 | uf -= redux; |
| 82 | 82 | |
| ... | ... | @@ -84,11 +84,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 { |
| 84 | 84 | var r: f64 = exp2ft[@as(usize, @intCast(i_0))]; |
| 85 | 85 | const t: f64 = r * z; |
| 86 | 86 | r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4); |
| 87 | return @as(f32, @floatCast(r * uk)); | |
| 87 | return @floatCast(r * uk); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | pub fn exp2(x: f64) callconv(.C) f64 { |
| 91 | const tblsiz: u32 = @as(u32, @intCast(exp2dt.len / 2)); | |
| 91 | const tblsiz: u32 = @intCast(exp2dt.len / 2); | |
| 92 | 92 | const redux: f64 = 0x1.8p52 / @as(f64, @floatFromInt(tblsiz)); |
| 93 | 93 | const P1: f64 = 0x1.62e42fefa39efp-1; |
| 94 | 94 | const P2: f64 = 0x1.ebfbdff82c575p-3; |
| ... | ... | @@ -96,7 +96,7 @@ pub fn exp2(x: f64) callconv(.C) f64 { |
| 96 | 96 | const P4: f64 = 0x1.3b2ab88f70400p-7; |
| 97 | 97 | const P5: f64 = 0x1.5d88003875c74p-10; |
| 98 | 98 | |
| 99 | const ux = @as(u64, @bitCast(x)); | |
| 99 | const ux: u64 = @bitCast(x); | |
| 100 | 100 | const ix = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF; |
| 101 | 101 | |
| 102 | 102 | // TODO: This should be handled beneath. |
| ... | ... | @@ -139,7 +139,7 @@ pub fn exp2(x: f64) callconv(.C) f64 { |
| 139 | 139 | // reduce x |
| 140 | 140 | var uf: f64 = x + redux; |
| 141 | 141 | // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here |
| 142 | var i_0: u32 = @as(u32, @truncate(@as(u64, @bitCast(uf)))); | |
| 142 | var i_0: u32 = @truncate(@as(u64, @bitCast(uf))); | |
| 143 | 143 | i_0 +%= tblsiz / 2; |
| 144 | 144 | |
| 145 | 145 | const k: u32 = i_0 / tblsiz * tblsiz; |
| ... | ... | @@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 { |
| 158 | 158 | |
| 159 | 159 | pub fn __exp2x(x: f80) callconv(.C) f80 { |
| 160 | 160 | // TODO: more efficient implementation |
| 161 | return @as(f80, @floatCast(exp2q(x))); | |
| 161 | return @floatCast(exp2q(x)); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | pub fn exp2q(x: f128) callconv(.C) f128 { |
| 165 | 165 | // TODO: more correct implementation |
| 166 | return exp2(@as(f64, @floatCast(x))); | |
| 166 | return exp2(@floatCast(x)); | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/extendf.zig+3-3| ... | ... | @@ -33,7 +33,7 @@ pub inline fn extendf( |
| 33 | 33 | const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits; |
| 34 | 34 | |
| 35 | 35 | // Break a into a sign and representation of the absolute value |
| 36 | const aRep: src_rep_t = @as(src_rep_t, @bitCast(a)); | |
| 36 | const aRep: src_rep_t = @bitCast(a); | |
| 37 | 37 | const aAbs: src_rep_t = aRep & srcAbsMask; |
| 38 | 38 | const sign: src_rep_t = aRep & srcSignMask; |
| 39 | 39 | var absResult: dst_rep_t = undefined; |
| ... | ... | @@ -104,7 +104,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI |
| 104 | 104 | // a is a normal number. |
| 105 | 105 | // Extend to the destination type by shifting the significand and |
| 106 | 106 | // exponent into the proper position and rebiasing the exponent. |
| 107 | dst.exp = @as(u16, @intCast(a_abs >> src_sig_bits)); | |
| 107 | dst.exp = @intCast(a_abs >> src_sig_bits); | |
| 108 | 108 | dst.exp += dst_exp_bias - src_exp_bias; |
| 109 | 109 | dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits); |
| 110 | 110 | dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers |
| ... | ... | @@ -126,7 +126,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI |
| 126 | 126 | |
| 127 | 127 | dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale)); |
| 128 | 128 | dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers |
| 129 | dst.exp = @as(u16, @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale)))); | |
| 129 | dst.exp = @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale))); | |
| 130 | 130 | dst.exp ^= 1; |
| 131 | 131 | dst.exp |= dst_exp_bias - src_exp_bias - scale + 1; |
| 132 | 132 | } else { |
lib/compiler_rt/extendf_test.zig+17-17| ... | ... | @@ -11,7 +11,7 @@ const F16T = @import("./common.zig").F16T; |
| 11 | 11 | fn test__extenddfxf2(a: f64, expected: u80) !void { |
| 12 | 12 | const x = __extenddfxf2(a); |
| 13 | 13 | |
| 14 | const rep = @as(u80, @bitCast(x)); | |
| 14 | const rep: u80 = @bitCast(x); | |
| 15 | 15 | if (rep == expected) |
| 16 | 16 | return; |
| 17 | 17 | |
| ... | ... | @@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void { |
| 25 | 25 | fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void { |
| 26 | 26 | const x = __extenddftf2(a); |
| 27 | 27 | |
| 28 | const rep = @as(u128, @bitCast(x)); | |
| 29 | const hi = @as(u64, @intCast(rep >> 64)); | |
| 30 | const lo = @as(u64, @truncate(rep)); | |
| 28 | const rep: u128 = @bitCast(x); | |
| 29 | const hi: u64 = @intCast(rep >> 64); | |
| 30 | const lo: u64 = @truncate(rep); | |
| 31 | 31 | |
| 32 | 32 | if (hi == expected_hi and lo == expected_lo) |
| 33 | 33 | return; |
| ... | ... | @@ -46,7 +46,7 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void { |
| 46 | 46 | |
| 47 | 47 | fn test__extendhfsf2(a: u16, expected: u32) !void { |
| 48 | 48 | const x = __extendhfsf2(@as(F16T(f32), @bitCast(a))); |
| 49 | const rep = @as(u32, @bitCast(x)); | |
| 49 | const rep: u32 = @bitCast(x); | |
| 50 | 50 | |
| 51 | 51 | if (rep == expected) { |
| 52 | 52 | if (rep & 0x7fffffff > 0x7f800000) { |
| ... | ... | @@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void { |
| 63 | 63 | fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void { |
| 64 | 64 | const x = __extendsftf2(a); |
| 65 | 65 | |
| 66 | const rep = @as(u128, @bitCast(x)); | |
| 67 | const hi = @as(u64, @intCast(rep >> 64)); | |
| 68 | const lo = @as(u64, @truncate(rep)); | |
| 66 | const rep: u128 = @bitCast(x); | |
| 67 | const hi: u64 = @intCast(rep >> 64); | |
| 68 | const lo: u64 = @truncate(rep); | |
| 69 | 69 | |
| 70 | 70 | if (hi == expected_hi and lo == expected_lo) |
| 71 | 71 | return; |
| ... | ... | @@ -184,35 +184,35 @@ test "extendsftf2" { |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | fn makeQNaN64() f64 { |
| 187 | return @as(f64, @bitCast(@as(u64, 0x7ff8000000000000))); | |
| 187 | return @bitCast(@as(u64, 0x7ff8000000000000)); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | fn makeInf64() f64 { |
| 191 | return @as(f64, @bitCast(@as(u64, 0x7ff0000000000000))); | |
| 191 | return @bitCast(@as(u64, 0x7ff0000000000000)); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | fn makeNaN64(rand: u64) f64 { |
| 195 | return @as(f64, @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff))); | |
| 195 | return @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff)); | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | fn makeQNaN32() f32 { |
| 199 | return @as(f32, @bitCast(@as(u32, 0x7fc00000))); | |
| 199 | return @bitCast(@as(u32, 0x7fc00000)); | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | fn makeNaN32(rand: u32) f32 { |
| 203 | return @as(f32, @bitCast(0x7f800000 | (rand & 0x7fffff))); | |
| 203 | return @bitCast(0x7f800000 | (rand & 0x7fffff)); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | fn makeInf32() f32 { |
| 207 | return @as(f32, @bitCast(@as(u32, 0x7f800000))); | |
| 207 | return @bitCast(@as(u32, 0x7f800000)); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void { |
| 211 | 211 | const x = __extendhftf2(@as(F16T(f128), @bitCast(a))); |
| 212 | 212 | |
| 213 | const rep = @as(u128, @bitCast(x)); | |
| 214 | const hi = @as(u64, @intCast(rep >> 64)); | |
| 215 | const lo = @as(u64, @truncate(rep)); | |
| 213 | const rep: u128 = @bitCast(x); | |
| 214 | const hi: u64 = @intCast(rep >> 64); | |
| 215 | const lo: u64 = @truncate(rep); | |
| 216 | 216 | |
| 217 | 217 | if (hi == expected_hi and lo == expected_lo) |
| 218 | 218 | return; |
lib/compiler_rt/float_from_int_test.zig+6-6| ... | ... | @@ -520,9 +520,9 @@ test "floatsitf" { |
| 520 | 520 | fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void { |
| 521 | 521 | const x = __floatunsitf(a); |
| 522 | 522 | |
| 523 | const x_repr = @as(u128, @bitCast(x)); | |
| 524 | const x_hi = @as(u64, @intCast(x_repr >> 64)); | |
| 525 | const x_lo = @as(u64, @truncate(x_repr)); | |
| 523 | const x_repr: u128 = @bitCast(x); | |
| 524 | const x_hi: u64 = @intCast(x_repr >> 64); | |
| 525 | const x_lo: u64 = @truncate(x_repr); | |
| 526 | 526 | |
| 527 | 527 | if (x_hi == expected_hi and x_lo == expected_lo) { |
| 528 | 528 | return; |
| ... | ... | @@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void { |
| 552 | 552 | fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void { |
| 553 | 553 | const x = __floatunditf(a); |
| 554 | 554 | |
| 555 | const x_repr = @as(u128, @bitCast(x)); | |
| 556 | const x_hi = @as(u64, @intCast(x_repr >> 64)); | |
| 557 | const x_lo = @as(u64, @truncate(x_repr)); | |
| 555 | const x_repr: u128 = @bitCast(x); | |
| 556 | const x_hi: u64 = @intCast(x_repr >> 64); | |
| 557 | const x_lo: u64 = @truncate(x_repr); | |
| 558 | 558 | |
| 559 | 559 | if (x_hi == expected_hi and x_lo == expected_lo) { |
| 560 | 560 | return; |
lib/compiler_rt/floor.zig+2-2| ... | ... | @@ -26,7 +26,7 @@ comptime { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | pub fn __floorh(x: f16) callconv(.C) f16 { |
| 29 | var u = @as(u16, @bitCast(x)); | |
| 29 | var u: u16 = @bitCast(x); | |
| 30 | 30 | const e = @as(i16, @intCast((u >> 10) & 31)) - 15; |
| 31 | 31 | var m: u16 = undefined; |
| 32 | 32 | |
| ... | ... | @@ -132,7 +132,7 @@ pub fn __floorx(x: f80) callconv(.C) f80 { |
| 132 | 132 | pub fn floorq(x: f128) callconv(.C) f128 { |
| 133 | 133 | const f128_toint = 1.0 / math.floatEps(f128); |
| 134 | 134 | |
| 135 | const u = @as(u128, @bitCast(x)); | |
| 135 | const u: u128 = @bitCast(x); | |
| 136 | 136 | const e = (u >> 112) & 0x7FFF; |
| 137 | 137 | var y: f128 = undefined; |
| 138 | 138 |
lib/compiler_rt/fmod.zig+15-15| ... | ... | @@ -22,7 +22,7 @@ comptime { |
| 22 | 22 | |
| 23 | 23 | pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 { |
| 24 | 24 | // TODO: more efficient implementation |
| 25 | return @as(f16, @floatCast(fmodf(x, y))); | |
| 25 | return @floatCast(fmodf(x, y)); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | pub fn fmodf(x: f32, y: f32) callconv(.C) f32 { |
| ... | ... | @@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 46 | 46 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); |
| 47 | 47 | const maxExponent = ((1 << exponentBits) - 1); |
| 48 | 48 | |
| 49 | var aRep = @as(Z, @bitCast(a)); | |
| 50 | var bRep = @as(Z, @bitCast(b)); | |
| 49 | var aRep: Z = @bitCast(a); | |
| 50 | var bRep: Z = @bitCast(b); | |
| 51 | 51 | |
| 52 | 52 | const signA = aRep & signBit; |
| 53 | var expA = @as(i32, @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent)); | |
| 54 | var expB = @as(i32, @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent)); | |
| 53 | var expA: i32 = @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent); | |
| 54 | var expB: i32 = @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent); | |
| 55 | 55 | |
| 56 | 56 | // There are 3 cases where the answer is undefined, check for: |
| 57 | 57 | // - fmodx(val, 0) |
| ... | ... | @@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 123 | 123 | |
| 124 | 124 | // Combine the exponent with the sign and significand, normalize if happened to be denormalized |
| 125 | 125 | if (expA < -fractionalBits) { |
| 126 | return @as(T, @bitCast(signA)); | |
| 126 | return @bitCast(signA); | |
| 127 | 127 | } else if (expA <= 0) { |
| 128 | return @as(T, @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA)); | |
| 128 | return @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA); | |
| 129 | 129 | } else { |
| 130 | return @as(T, @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA)); | |
| 130 | return @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA); | |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| ... | ... | @@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { |
| 155 | 155 | }; |
| 156 | 156 | |
| 157 | 157 | const signA = aPtr_u16[exp_and_sign_index] & 0x8000; |
| 158 | var expA = @as(i32, @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff))); | |
| 159 | var expB = @as(i32, @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff))); | |
| 158 | var expA: i32 = @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff)); | |
| 159 | var expB: i32 = @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff)); | |
| 160 | 160 | |
| 161 | 161 | // There are 3 cases where the answer is undefined, check for: |
| 162 | 162 | // - fmodq(val, 0) |
| ... | ... | @@ -270,10 +270,10 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 270 | 270 | const exp_bits = if (T == f32) 9 else 12; |
| 271 | 271 | const bits_minus_1 = bits - 1; |
| 272 | 272 | const mask = if (T == f32) 0xff else 0x7ff; |
| 273 | var ux = @as(uint, @bitCast(x)); | |
| 274 | var uy = @as(uint, @bitCast(y)); | |
| 275 | var ex = @as(i32, @intCast((ux >> digits) & mask)); | |
| 276 | var ey = @as(i32, @intCast((uy >> digits) & mask)); | |
| 273 | var ux: uint = @bitCast(x); | |
| 274 | var uy: uint = @bitCast(y); | |
| 275 | var ex: i32 = @intCast((ux >> digits) & mask); | |
| 276 | var ey: i32 = @intCast((uy >> digits) & mask); | |
| 277 | 277 | const sx = if (T == f32) @as(u32, @intCast(ux & 0x80000000)) else @as(i32, @intCast(ux >> bits_minus_1)); |
| 278 | 278 | var i: uint = undefined; |
| 279 | 279 | |
| ... | ... | @@ -343,7 +343,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 343 | 343 | } else { |
| 344 | 344 | ux |= @as(uint, @intCast(sx)) << bits_minus_1; |
| 345 | 345 | } |
| 346 | return @as(T, @bitCast(ux)); | |
| 346 | return @bitCast(ux); | |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | test "fmodf" { |
lib/compiler_rt/log.zig+12-12| ... | ... | @@ -27,7 +27,7 @@ comptime { |
| 27 | 27 | |
| 28 | 28 | pub fn __logh(a: f16) callconv(.C) f16 { |
| 29 | 29 | // TODO: more efficient implementation |
| 30 | return @as(f16, @floatCast(logf(a))); | |
| 30 | return @floatCast(logf(a)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | pub fn logf(x_: f32) callconv(.C) f32 { |
| ... | ... | @@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 { |
| 39 | 39 | const Lg4: f32 = 0xf89e26.0p-26; |
| 40 | 40 | |
| 41 | 41 | var x = x_; |
| 42 | var ix = @as(u32, @bitCast(x)); | |
| 42 | var ix: u32 = @bitCast(x); | |
| 43 | 43 | var k: i32 = 0; |
| 44 | 44 | |
| 45 | 45 | // x < 2^(-126) |
| ... | ... | @@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 { |
| 56 | 56 | // subnormal, scale x |
| 57 | 57 | k -= 25; |
| 58 | 58 | x *= 0x1.0p25; |
| 59 | ix = @as(u32, @bitCast(x)); | |
| 59 | ix = @bitCast(x); | |
| 60 | 60 | } else if (ix >= 0x7F800000) { |
| 61 | 61 | return x; |
| 62 | 62 | } else if (ix == 0x3F800000) { |
| ... | ... | @@ -67,7 +67,7 @@ pub fn logf(x_: f32) callconv(.C) f32 { |
| 67 | 67 | ix += 0x3F800000 - 0x3F3504F3; |
| 68 | 68 | k += @as(i32, @intCast(ix >> 23)) - 0x7F; |
| 69 | 69 | ix = (ix & 0x007FFFFF) + 0x3F3504F3; |
| 70 | x = @as(f32, @bitCast(ix)); | |
| 70 | x = @bitCast(ix); | |
| 71 | 71 | |
| 72 | 72 | const f = x - 1.0; |
| 73 | 73 | const s = f / (2.0 + f); |
| ... | ... | @@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 { |
| 77 | 77 | const t2 = z * (Lg1 + w * Lg3); |
| 78 | 78 | const R = t2 + t1; |
| 79 | 79 | const hfsq = 0.5 * f * f; |
| 80 | const dk = @as(f32, @floatFromInt(k)); | |
| 80 | const dk: f32 = @floatFromInt(k); | |
| 81 | 81 | |
| 82 | 82 | return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi; |
| 83 | 83 | } |
| ... | ... | @@ -94,8 +94,8 @@ pub fn log(x_: f64) callconv(.C) f64 { |
| 94 | 94 | const Lg7: f64 = 1.479819860511658591e-01; |
| 95 | 95 | |
| 96 | 96 | var x = x_; |
| 97 | var ix = @as(u64, @bitCast(x)); | |
| 98 | var hx = @as(u32, @intCast(ix >> 32)); | |
| 97 | var ix: u64 = @bitCast(x); | |
| 98 | var hx: u32 = @intCast(ix >> 32); | |
| 99 | 99 | var k: i32 = 0; |
| 100 | 100 | |
| 101 | 101 | if (hx < 0x00100000 or hx >> 31 != 0) { |
| ... | ... | @@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 { |
| 111 | 111 | // subnormal, scale x |
| 112 | 112 | k -= 54; |
| 113 | 113 | x *= 0x1.0p54; |
| 114 | hx = @as(u32, @intCast(@as(u64, @bitCast(ix)) >> 32)); | |
| 114 | hx = @intCast(@as(u64, @bitCast(ix)) >> 32); | |
| 115 | 115 | } else if (hx >= 0x7FF00000) { |
| 116 | 116 | return x; |
| 117 | 117 | } else if (hx == 0x3FF00000 and ix << 32 == 0) { |
| ... | ... | @@ -123,7 +123,7 @@ pub fn log(x_: f64) callconv(.C) f64 { |
| 123 | 123 | k += @as(i32, @intCast(hx >> 20)) - 0x3FF; |
| 124 | 124 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 125 | 125 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); |
| 126 | x = @as(f64, @bitCast(ix)); | |
| 126 | x = @bitCast(ix); | |
| 127 | 127 | |
| 128 | 128 | const f = x - 1.0; |
| 129 | 129 | const hfsq = 0.5 * f * f; |
| ... | ... | @@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 { |
| 133 | 133 | const t1 = w * (Lg2 + w * (Lg4 + w * Lg6)); |
| 134 | 134 | const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7))); |
| 135 | 135 | const R = t2 + t1; |
| 136 | const dk = @as(f64, @floatFromInt(k)); | |
| 136 | const dk: f64 = @floatFromInt(k); | |
| 137 | 137 | |
| 138 | 138 | return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | pub fn __logx(a: f80) callconv(.C) f80 { |
| 142 | 142 | // TODO: more efficient implementation |
| 143 | return @as(f80, @floatCast(logq(a))); | |
| 143 | return @floatCast(logq(a)); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | pub fn logq(a: f128) callconv(.C) f128 { |
| 147 | 147 | // TODO: more correct implementation |
| 148 | return log(@as(f64, @floatCast(a))); | |
| 148 | return log(@floatCast(a)); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | pub fn logl(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/log10.zig+10-10| ... | ... | @@ -82,11 +82,11 @@ pub fn log10f(x_: f32) callconv(.C) f32 { |
| 82 | 82 | const hfsq = 0.5 * f * f; |
| 83 | 83 | |
| 84 | 84 | var hi = f - hfsq; |
| 85 | u = @as(u32, @bitCast(hi)); | |
| 85 | u = @bitCast(hi); | |
| 86 | 86 | u &= 0xFFFFF000; |
| 87 | hi = @as(f32, @bitCast(u)); | |
| 87 | hi = @bitCast(u); | |
| 88 | 88 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 89 | const dk = @as(f32, @floatFromInt(k)); | |
| 89 | const dk: f32 = @floatFromInt(k); | |
| 90 | 90 | |
| 91 | 91 | return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi; |
| 92 | 92 | } |
| ... | ... | @@ -105,8 +105,8 @@ pub fn log10(x_: f64) callconv(.C) f64 { |
| 105 | 105 | const Lg7: f64 = 1.479819860511658591e-01; |
| 106 | 106 | |
| 107 | 107 | var x = x_; |
| 108 | var ix = @as(u64, @bitCast(x)); | |
| 109 | var hx = @as(u32, @intCast(ix >> 32)); | |
| 108 | var ix: u64 = @bitCast(x); | |
| 109 | var hx: u32 = @intCast(ix >> 32); | |
| 110 | 110 | var k: i32 = 0; |
| 111 | 111 | |
| 112 | 112 | if (hx < 0x00100000 or hx >> 31 != 0) { |
| ... | ... | @@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 { |
| 122 | 122 | // subnormal, scale x |
| 123 | 123 | k -= 54; |
| 124 | 124 | x *= 0x1.0p54; |
| 125 | hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32)); | |
| 125 | hx = @intCast(@as(u64, @bitCast(x)) >> 32); | |
| 126 | 126 | } else if (hx >= 0x7FF00000) { |
| 127 | 127 | return x; |
| 128 | 128 | } else if (hx == 0x3FF00000 and ix << 32 == 0) { |
| ... | ... | @@ -134,7 +134,7 @@ pub fn log10(x_: f64) callconv(.C) f64 { |
| 134 | 134 | k += @as(i32, @intCast(hx >> 20)) - 0x3FF; |
| 135 | 135 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 136 | 136 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); |
| 137 | x = @as(f64, @bitCast(ix)); | |
| 137 | x = @bitCast(ix); | |
| 138 | 138 | |
| 139 | 139 | const f = x - 1.0; |
| 140 | 140 | const hfsq = 0.5 * f * f; |
| ... | ... | @@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 { |
| 147 | 147 | |
| 148 | 148 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 149 | 149 | var hi = f - hfsq; |
| 150 | var hii = @as(u64, @bitCast(hi)); | |
| 150 | var hii: u64 = @bitCast(hi); | |
| 151 | 151 | hii &= @as(u64, maxInt(u64)) << 32; |
| 152 | hi = @as(f64, @bitCast(hii)); | |
| 152 | hi = @bitCast(hii); | |
| 153 | 153 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 154 | 154 | |
| 155 | 155 | // val_hi + val_lo ~ log10(1 + f) + k * log10(2) |
| 156 | 156 | var val_hi = hi * ivln10hi; |
| 157 | const dk = @as(f64, @floatFromInt(k)); | |
| 157 | const dk: f64 = @floatFromInt(k); | |
| 158 | 158 | const y = dk * log10_2hi; |
| 159 | 159 | var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi; |
| 160 | 160 |
lib/compiler_rt/log2.zig+14-14| ... | ... | @@ -28,7 +28,7 @@ comptime { |
| 28 | 28 | |
| 29 | 29 | pub fn __log2h(a: f16) callconv(.C) f16 { |
| 30 | 30 | // TODO: more efficient implementation |
| 31 | return @as(f16, @floatCast(log2f(a))); | |
| 31 | return @floatCast(log2f(a)); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | pub fn log2f(x_: f32) callconv(.C) f32 { |
| ... | ... | @@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 { |
| 40 | 40 | const Lg4: f32 = 0xf89e26.0p-26; |
| 41 | 41 | |
| 42 | 42 | var x = x_; |
| 43 | var u = @as(u32, @bitCast(x)); | |
| 43 | var u: u32 = @bitCast(x); | |
| 44 | 44 | var ix = u; |
| 45 | 45 | var k: i32 = 0; |
| 46 | 46 | |
| ... | ... | @@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 { |
| 57 | 57 | |
| 58 | 58 | k -= 25; |
| 59 | 59 | x *= 0x1.0p25; |
| 60 | ix = @as(u32, @bitCast(x)); | |
| 60 | ix = @bitCast(x); | |
| 61 | 61 | } else if (ix >= 0x7F800000) { |
| 62 | 62 | return x; |
| 63 | 63 | } else if (ix == 0x3F800000) { |
| ... | ... | @@ -68,7 +68,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 { |
| 68 | 68 | ix += 0x3F800000 - 0x3F3504F3; |
| 69 | 69 | k += @as(i32, @intCast(ix >> 23)) - 0x7F; |
| 70 | 70 | ix = (ix & 0x007FFFFF) + 0x3F3504F3; |
| 71 | x = @as(f32, @bitCast(ix)); | |
| 71 | x = @bitCast(ix); | |
| 72 | 72 | |
| 73 | 73 | const f = x - 1.0; |
| 74 | 74 | const s = f / (2.0 + f); |
| ... | ... | @@ -80,9 +80,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 { |
| 80 | 80 | const hfsq = 0.5 * f * f; |
| 81 | 81 | |
| 82 | 82 | var hi = f - hfsq; |
| 83 | u = @as(u32, @bitCast(hi)); | |
| 83 | u = @bitCast(hi); | |
| 84 | 84 | u &= 0xFFFFF000; |
| 85 | hi = @as(f32, @bitCast(u)); | |
| 85 | hi = @bitCast(u); | |
| 86 | 86 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 87 | 87 | return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @as(f32, @floatFromInt(k)); |
| 88 | 88 | } |
| ... | ... | @@ -99,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 { |
| 99 | 99 | const Lg7: f64 = 1.479819860511658591e-01; |
| 100 | 100 | |
| 101 | 101 | var x = x_; |
| 102 | var ix = @as(u64, @bitCast(x)); | |
| 103 | var hx = @as(u32, @intCast(ix >> 32)); | |
| 102 | var ix: u64 = @bitCast(x); | |
| 103 | var hx: u32 = @intCast(ix >> 32); | |
| 104 | 104 | var k: i32 = 0; |
| 105 | 105 | |
| 106 | 106 | if (hx < 0x00100000 or hx >> 31 != 0) { |
| ... | ... | @@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 { |
| 116 | 116 | // subnormal, scale x |
| 117 | 117 | k -= 54; |
| 118 | 118 | x *= 0x1.0p54; |
| 119 | hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32)); | |
| 119 | hx = @intCast(@as(u64, @bitCast(x)) >> 32); | |
| 120 | 120 | } else if (hx >= 0x7FF00000) { |
| 121 | 121 | return x; |
| 122 | 122 | } else if (hx == 0x3FF00000 and ix << 32 == 0) { |
| ... | ... | @@ -128,7 +128,7 @@ pub fn log2(x_: f64) callconv(.C) f64 { |
| 128 | 128 | k += @as(i32, @intCast(hx >> 20)) - 0x3FF; |
| 129 | 129 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 130 | 130 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); |
| 131 | x = @as(f64, @bitCast(ix)); | |
| 131 | x = @bitCast(ix); | |
| 132 | 132 | |
| 133 | 133 | const f = x - 1.0; |
| 134 | 134 | const hfsq = 0.5 * f * f; |
| ... | ... | @@ -143,14 +143,14 @@ pub fn log2(x_: f64) callconv(.C) f64 { |
| 143 | 143 | var hi = f - hfsq; |
| 144 | 144 | var hii = @as(u64, @bitCast(hi)); |
| 145 | 145 | hii &= @as(u64, maxInt(u64)) << 32; |
| 146 | hi = @as(f64, @bitCast(hii)); | |
| 146 | hi = @bitCast(hii); | |
| 147 | 147 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 148 | 148 | |
| 149 | 149 | var val_hi = hi * ivln2hi; |
| 150 | 150 | var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi; |
| 151 | 151 | |
| 152 | 152 | // spadd(val_hi, val_lo, y) |
| 153 | const y = @as(f64, @floatFromInt(k)); | |
| 153 | const y: f64 = @floatFromInt(k); | |
| 154 | 154 | const ww = y + val_hi; |
| 155 | 155 | val_lo += (y - ww) + val_hi; |
| 156 | 156 | val_hi = ww; |
| ... | ... | @@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 { |
| 160 | 160 | |
| 161 | 161 | pub fn __log2x(a: f80) callconv(.C) f80 { |
| 162 | 162 | // TODO: more efficient implementation |
| 163 | return @as(f80, @floatCast(log2q(a))); | |
| 163 | return @floatCast(log2q(a)); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | pub fn log2q(a: f128) callconv(.C) f128 { |
| 167 | 167 | // TODO: more correct implementation |
| 168 | return log2(@as(f64, @floatCast(a))); | |
| 168 | return log2(@floatCast(a)); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/modti3.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 { |
| 24 | 24 | const v2u64 = @Vector(2, u64); |
| 25 | 25 | |
| 26 | 26 | fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 { |
| 27 | return @as(v2u64, @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b))))); | |
| 27 | return @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))); | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | inline fn mod(a: i128, b: i128) i128 { |
lib/compiler_rt/mulXi3.zig+4-4| ... | ... | @@ -21,8 +21,8 @@ comptime { |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 { |
| 24 | var ua = @as(u32, @bitCast(a)); | |
| 25 | var ub = @as(u32, @bitCast(b)); | |
| 24 | var ua: u32 = @bitCast(a); | |
| 25 | var ub: u32 = @bitCast(b); | |
| 26 | 26 | var r: u32 = 0; |
| 27 | 27 | |
| 28 | 28 | while (ua > 0) { |
| ... | ... | @@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 { |
| 31 | 31 | ub <<= 1; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | return @as(i32, @bitCast(r)); | |
| 34 | return @bitCast(r); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 { |
| ... | ... | @@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 { |
| 93 | 93 | const v2u64 = @Vector(2, u64); |
| 94 | 94 | |
| 95 | 95 | fn __multi3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 { |
| 96 | return @as(v2u64, @bitCast(mulX(i128, @as(i128, @bitCast(a)), @as(i128, @bitCast(b))))); | |
| 96 | return @bitCast(mulX(i128, @as(i128, @bitCast(a)), @as(i128, @bitCast(b)))); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | test { |
lib/compiler_rt/mulf3.zig+6-6| ... | ... | @@ -54,27 +54,27 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 54 | 54 | if (aAbs == infRep) { |
| 55 | 55 | // infinity * non-zero = +/- infinity |
| 56 | 56 | if (bAbs != 0) { |
| 57 | return @as(T, @bitCast(aAbs | productSign)); | |
| 57 | return @bitCast(aAbs | productSign); | |
| 58 | 58 | } else { |
| 59 | 59 | // infinity * zero = NaN |
| 60 | return @as(T, @bitCast(qnanRep)); | |
| 60 | return @bitCast(qnanRep); | |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if (bAbs == infRep) { |
| 65 | 65 | //? non-zero * infinity = +/- infinity |
| 66 | 66 | if (aAbs != 0) { |
| 67 | return @as(T, @bitCast(bAbs | productSign)); | |
| 67 | return @bitCast(bAbs | productSign); | |
| 68 | 68 | } else { |
| 69 | 69 | // zero * infinity = NaN |
| 70 | return @as(T, @bitCast(qnanRep)); | |
| 70 | return @bitCast(qnanRep); | |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // zero * anything = +/- zero |
| 75 | if (aAbs == 0) return @as(T, @bitCast(productSign)); | |
| 75 | if (aAbs == 0) return @bitCast(productSign); | |
| 76 | 76 | // anything * zero = +/- zero |
| 77 | if (bAbs == 0) return @as(T, @bitCast(productSign)); | |
| 77 | if (bAbs == 0) return @bitCast(productSign); | |
| 78 | 78 | |
| 79 | 79 | // one or both of a or b is denormal, the other (if applicable) is a |
| 80 | 80 | // normal number. Renormalize one or both of a and b, and set scale to |
lib/compiler_rt/mulf3_test.zig+8-9| ... | ... | @@ -4,8 +4,8 @@ |
| 4 | 4 | |
| 5 | 5 | const std = @import("std"); |
| 6 | 6 | const math = std.math; |
| 7 | const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64)); | |
| 8 | const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff000000000000) << 64)); | |
| 7 | const qnan128: f128 = @bitCast(@as(u128, 0x7fff800000000000) << 64); | |
| 8 | const inf128: f128 = @bitCast(@as(u128, 0x7fff000000000000) << 64); | |
| 9 | 9 | |
| 10 | 10 | const __multf3 = @import("multf3.zig").__multf3; |
| 11 | 11 | const __mulxf3 = @import("mulxf3.zig").__mulxf3; |
| ... | ... | @@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3; |
| 16 | 16 | // use two 64-bit integers intead of one 128-bit integer |
| 17 | 17 | // because 128-bit integer constant can't be assigned directly |
| 18 | 18 | fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool { |
| 19 | const rep = @as(u128, @bitCast(result)); | |
| 20 | const hi = @as(u64, @intCast(rep >> 64)); | |
| 21 | const lo = @as(u64, @truncate(rep)); | |
| 19 | const rep: u128 = @bitCast(result); | |
| 20 | const hi: u64 = @intCast(rep >> 64); | |
| 21 | const lo: u64 = @truncate(rep); | |
| 22 | 22 | |
| 23 | 23 | if (hi == expectedHi and lo == expectedLo) { |
| 24 | 24 | return true; |
| ... | ... | @@ -45,8 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void { |
| 45 | 45 | |
| 46 | 46 | fn makeNaN128(rand: u64) f128 { |
| 47 | 47 | const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; |
| 48 | const float_result = @as(f128, @bitCast(int_result)); | |
| 49 | return float_result; | |
| 48 | return @bitCast(int_result); | |
| 50 | 49 | } |
| 51 | 50 | test "multf3" { |
| 52 | 51 | // qNaN * any = qNaN |
| ... | ... | @@ -108,11 +107,11 @@ test "multf3" { |
| 108 | 107 | try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002); |
| 109 | 108 | } |
| 110 | 109 | |
| 111 | const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1)))); | |
| 110 | const qnan80: f80 = @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))); | |
| 112 | 111 | |
| 113 | 112 | fn test__mulxf3(a: f80, b: f80, expected: u80) !void { |
| 114 | 113 | const x = __mulxf3(a, b); |
| 115 | const rep = @as(u80, @bitCast(x)); | |
| 114 | const rep: u80 = @bitCast(x); | |
| 116 | 115 | |
| 117 | 116 | if (rep == expected) |
| 118 | 117 | return; |
lib/compiler_rt/parityti2_test.zig+1-1| ... | ... | @@ -3,7 +3,7 @@ const parity = @import("parity.zig"); |
| 3 | 3 | const testing = std.testing; |
| 4 | 4 | |
| 5 | 5 | fn parityti2Naive(a: i128) i32 { |
| 6 | var x = @as(u128, @bitCast(a)); | |
| 6 | var x: u128 = @bitCast(a); | |
| 7 | 7 | var has_parity: bool = false; |
| 8 | 8 | while (x > 0) { |
| 9 | 9 | has_parity = !has_parity; |
lib/compiler_rt/rem_pio2.zig+8-8| ... | ... | @@ -57,17 +57,17 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 { |
| 57 | 57 | w = @"fn" * pio2_1t; |
| 58 | 58 | } |
| 59 | 59 | y[0] = r - w; |
| 60 | ui = @as(u64, @bitCast(y[0])); | |
| 61 | ey = @as(i32, @intCast((ui >> 52) & 0x7ff)); | |
| 62 | ex = @as(i32, @intCast(ix >> 20)); | |
| 60 | ui = @bitCast(y[0]); | |
| 61 | ey = @intCast((ui >> 52) & 0x7ff); | |
| 62 | ex = @intCast(ix >> 20); | |
| 63 | 63 | if (ex - ey > 16) { // 2nd round, good to 118 bits |
| 64 | 64 | t = r; |
| 65 | 65 | w = @"fn" * pio2_2; |
| 66 | 66 | r = t - w; |
| 67 | 67 | w = @"fn" * pio2_2t - ((t - r) - w); |
| 68 | 68 | y[0] = r - w; |
| 69 | ui = @as(u64, @bitCast(y[0])); | |
| 70 | ey = @as(i32, @intCast((ui >> 52) & 0x7ff)); | |
| 69 | ui = @bitCast(y[0]); | |
| 70 | ey = @intCast((ui >> 52) & 0x7ff); | |
| 71 | 71 | if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases |
| 72 | 72 | t = r; |
| 73 | 73 | w = @"fn" * pio2_3; |
| ... | ... | @@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 { |
| 95 | 95 | var i: i32 = undefined; |
| 96 | 96 | var ui: u64 = undefined; |
| 97 | 97 | |
| 98 | ui = @as(u64, @bitCast(x)); | |
| 98 | ui = @bitCast(x); | |
| 99 | 99 | sign = ui >> 63 != 0; |
| 100 | ix = @as(u32, @truncate((ui >> 32) & 0x7fffffff)); | |
| 100 | ix = @truncate((ui >> 32) & 0x7fffffff); | |
| 101 | 101 | if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4 |
| 102 | 102 | if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2 |
| 103 | 103 | return medium(ix, x, y); |
| ... | ... | @@ -171,7 +171,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 { |
| 171 | 171 | return 0; |
| 172 | 172 | } |
| 173 | 173 | // set z = scalbn(|x|,-ilogb(x)+23) |
| 174 | ui = @as(u64, @bitCast(x)); | |
| 174 | ui = @bitCast(x); | |
| 175 | 175 | ui &= std.math.maxInt(u64) >> 12; |
| 176 | 176 | ui |= @as(u64, 0x3ff + 23) << 52; |
| 177 | 177 | z = @as(f64, @bitCast(ui)); |
lib/compiler_rt/rem_pio2_large.zig+3-3| ... | ... | @@ -322,7 +322,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 322 | 322 | i += 1; |
| 323 | 323 | j -= 1; |
| 324 | 324 | }) { |
| 325 | fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z)))); | |
| 325 | fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))); | |
| 326 | 326 | iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw)); |
| 327 | 327 | z = q[U(j - 1)] + fw; |
| 328 | 328 | } |
| ... | ... | @@ -330,7 +330,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 330 | 330 | // compute n |
| 331 | 331 | z = math.scalbn(z, q0); // actual value of z |
| 332 | 332 | z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8 |
| 333 | n = @as(i32, @intFromFloat(z)); | |
| 333 | n = @intFromFloat(z); | |
| 334 | 334 | z -= @as(f64, @floatFromInt(n)); |
| 335 | 335 | ih = 0; |
| 336 | 336 | if (q0 > 0) { // need iq[jz-1] to determine n |
| ... | ... | @@ -414,7 +414,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 414 | 414 | } else { // break z into 24-bit if necessary |
| 415 | 415 | z = math.scalbn(z, -q0); |
| 416 | 416 | if (z >= 0x1p24) { |
| 417 | fw = @as(f64, @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z)))); | |
| 417 | fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))); | |
| 418 | 418 | iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw)); |
| 419 | 419 | jz += 1; |
| 420 | 420 | q0 += 24; |
lib/compiler_rt/rem_pio2f.zig+2-2| ... | ... | @@ -30,14 +30,14 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 { |
| 30 | 30 | var e0: u32 = undefined; |
| 31 | 31 | var ui: u32 = undefined; |
| 32 | 32 | |
| 33 | ui = @as(u32, @bitCast(x)); | |
| 33 | ui = @bitCast(x); | |
| 34 | 34 | ix = ui & 0x7fffffff; |
| 35 | 35 | |
| 36 | 36 | // 25+53 bit pi is good enough for medium size |
| 37 | 37 | if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size |
| 38 | 38 | // Use a specialized rint() to get fn. |
| 39 | 39 | @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint; |
| 40 | n = @as(i32, @intFromFloat(@"fn")); | |
| 40 | n = @intFromFloat(@"fn"); | |
| 41 | 41 | y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t; |
| 42 | 42 | // Matters with directed rounding. |
| 43 | 43 | if (y.* < -pio4) { |
lib/compiler_rt/round.zig+5-5| ... | ... | @@ -27,14 +27,14 @@ comptime { |
| 27 | 27 | |
| 28 | 28 | pub fn __roundh(x: f16) callconv(.C) f16 { |
| 29 | 29 | // TODO: more efficient implementation |
| 30 | return @as(f16, @floatCast(roundf(x))); | |
| 30 | return @floatCast(roundf(x)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | pub fn roundf(x_: f32) callconv(.C) f32 { |
| 34 | 34 | const f32_toint = 1.0 / math.floatEps(f32); |
| 35 | 35 | |
| 36 | 36 | var x = x_; |
| 37 | const u = @as(u32, @bitCast(x)); | |
| 37 | const u: u32 = @bitCast(x); | |
| 38 | 38 | const e = (u >> 23) & 0xFF; |
| 39 | 39 | var y: f32 = undefined; |
| 40 | 40 | |
| ... | ... | @@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 { |
| 69 | 69 | const f64_toint = 1.0 / math.floatEps(f64); |
| 70 | 70 | |
| 71 | 71 | var x = x_; |
| 72 | const u = @as(u64, @bitCast(x)); | |
| 72 | const u: u64 = @bitCast(x); | |
| 73 | 73 | const e = (u >> 52) & 0x7FF; |
| 74 | 74 | var y: f64 = undefined; |
| 75 | 75 | |
| ... | ... | @@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 { |
| 102 | 102 | |
| 103 | 103 | pub fn __roundx(x: f80) callconv(.C) f80 { |
| 104 | 104 | // TODO: more efficient implementation |
| 105 | return @as(f80, @floatCast(roundq(x))); | |
| 105 | return @floatCast(roundq(x)); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | pub fn roundq(x_: f128) callconv(.C) f128 { |
| 109 | 109 | const f128_toint = 1.0 / math.floatEps(f128); |
| 110 | 110 | |
| 111 | 111 | var x = x_; |
| 112 | const u = @as(u128, @bitCast(x)); | |
| 112 | const u: u128 = @bitCast(x); | |
| 113 | 113 | const e = (u >> 112) & 0x7FFF; |
| 114 | 114 | var y: f128 = undefined; |
| 115 | 115 |
lib/compiler_rt/sincos.zig+1-1| ... | ... | @@ -218,7 +218,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void { |
| 218 | 218 | const bits = @typeInfo(F).Float.bits; |
| 219 | 219 | const I = std.meta.Int(.unsigned, bits); |
| 220 | 220 | const ix = @as(I, @bitCast(x)) & (math.maxInt(I) >> 1); |
| 221 | const se = @as(u16, @truncate(ix >> (bits - 16))); | |
| 221 | const se: u16 = @truncate(ix >> (bits - 16)); | |
| 222 | 222 | |
| 223 | 223 | if (se == 0x7fff) { |
| 224 | 224 | const result = x - x; |
lib/compiler_rt/sqrt.zig+1-1| ... | ... | @@ -125,7 +125,7 @@ pub fn sqrt(x: f64) callconv(.C) f64 { |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // normalize x |
| 128 | var m = @as(i32, @intCast(ix0 >> 20)); | |
| 128 | var m: i32 = @intCast(ix0 >> 20); | |
| 129 | 129 | if (m == 0) { |
| 130 | 130 | // subnormal |
| 131 | 131 | while (ix0 == 0) { |
lib/compiler_rt/tan.zig+2-2| ... | ... | @@ -33,7 +33,7 @@ comptime { |
| 33 | 33 | |
| 34 | 34 | pub fn __tanh(x: f16) callconv(.C) f16 { |
| 35 | 35 | // TODO: more efficient implementation |
| 36 | return @as(f16, @floatCast(tanf(x))); | |
| 36 | return @floatCast(tanf(x)); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | pub fn tanf(x: f32) callconv(.C) f32 { |
| ... | ... | @@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 { |
| 43 | 43 | const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2 |
| 44 | 44 | const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18 |
| 45 | 45 | |
| 46 | var ix = @as(u32, @bitCast(x)); | |
| 46 | var ix: u32 = @bitCast(x); | |
| 47 | 47 | const sign = ix >> 31 != 0; |
| 48 | 48 | ix &= 0x7fffffff; |
| 49 | 49 |
lib/compiler_rt/trig.zig+1-1| ... | ... | @@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 { |
| 199 | 199 | var hx: u32 = undefined; |
| 200 | 200 | var sign: bool = undefined; |
| 201 | 201 | |
| 202 | hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32)); | |
| 202 | hx = @intCast(@as(u64, @bitCast(x)) >> 32); | |
| 203 | 203 | const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744 |
| 204 | 204 | if (big) { |
| 205 | 205 | sign = hx >> 31 != 0; |
lib/compiler_rt/trunc.zig+5-5| ... | ... | @@ -27,11 +27,11 @@ comptime { |
| 27 | 27 | |
| 28 | 28 | pub fn __trunch(x: f16) callconv(.C) f16 { |
| 29 | 29 | // TODO: more efficient implementation |
| 30 | return @as(f16, @floatCast(truncf(x))); | |
| 30 | return @floatCast(truncf(x)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | pub fn truncf(x: f32) callconv(.C) f32 { |
| 34 | const u = @as(u32, @bitCast(x)); | |
| 34 | const u: u32 = @bitCast(x); | |
| 35 | 35 | var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9; |
| 36 | 36 | var m: u32 = undefined; |
| 37 | 37 | |
| ... | ... | @@ -47,12 +47,12 @@ pub fn truncf(x: f32) callconv(.C) f32 { |
| 47 | 47 | return x; |
| 48 | 48 | } else { |
| 49 | 49 | math.doNotOptimizeAway(x + 0x1p120); |
| 50 | return @as(f32, @bitCast(u & ~m)); | |
| 50 | return @bitCast(u & ~m); | |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | pub fn trunc(x: f64) callconv(.C) f64 { |
| 55 | const u = @as(u64, @bitCast(x)); | |
| 55 | const u: u64 = @bitCast(x); | |
| 56 | 56 | var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12; |
| 57 | 57 | var m: u64 = undefined; |
| 58 | 58 | |
| ... | ... | @@ -68,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 { |
| 68 | 68 | return x; |
| 69 | 69 | } else { |
| 70 | 70 | math.doNotOptimizeAway(x + 0x1p120); |
| 71 | return @as(f64, @bitCast(u & ~m)); | |
| 71 | return @bitCast(u & ~m); | |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 |
lib/compiler_rt/truncf.zig+2-2| ... | ... | @@ -72,8 +72,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 72 | 72 | // a underflows on conversion to the destination type or is an exact |
| 73 | 73 | // zero. The result may be a denormal or zero. Extract the exponent |
| 74 | 74 | // to get the shift amount for the denormalization. |
| 75 | const aExp = @as(u32, @intCast(aAbs >> srcSigBits)); | |
| 76 | const shift = @as(u32, @intCast(srcExpBias - dstExpBias - aExp + 1)); | |
| 75 | const aExp: u32 = @intCast(aAbs >> srcSigBits); | |
| 76 | const shift: u32 = @intCast(srcExpBias - dstExpBias - aExp + 1); | |
| 77 | 77 | |
| 78 | 78 | const significand: src_rep_t = (aRep & srcSignificandMask) | srcMinNormal; |
| 79 | 79 |
lib/compiler_rt/truncf_test.zig+20-20| ... | ... | @@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2; |
| 10 | 10 | const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2; |
| 11 | 11 | |
| 12 | 12 | fn test__truncsfhf2(a: u32, expected: u16) !void { |
| 13 | const actual = @as(u16, @bitCast(__truncsfhf2(@as(f32, @bitCast(a))))); | |
| 13 | const actual: u16 = @bitCast(__truncsfhf2(@bitCast(a))); | |
| 14 | 14 | |
| 15 | 15 | if (actual == expected) { |
| 16 | 16 | return; |
| ... | ... | @@ -73,7 +73,7 @@ test "truncsfhf2" { |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | fn test__truncdfhf2(a: f64, expected: u16) void { |
| 76 | const rep = @as(u16, @bitCast(__truncdfhf2(a))); | |
| 76 | const rep: u16 = @bitCast(__truncdfhf2(a)); | |
| 77 | 77 | |
| 78 | 78 | if (rep == expected) { |
| 79 | 79 | return; |
| ... | ... | @@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | fn test__truncdfhf2_raw(a: u64, expected: u16) void { |
| 92 | const actual = @as(u16, @bitCast(__truncdfhf2(@as(f64, @bitCast(a))))); | |
| 92 | const actual: u16 = @bitCast(__truncdfhf2(@bitCast(a))); | |
| 93 | 93 | |
| 94 | 94 | if (actual == expected) { |
| 95 | 95 | return; |
| ... | ... | @@ -141,7 +141,7 @@ test "truncdfhf2" { |
| 141 | 141 | fn test__trunctfsf2(a: f128, expected: u32) void { |
| 142 | 142 | const x = __trunctfsf2(a); |
| 143 | 143 | |
| 144 | const rep = @as(u32, @bitCast(x)); | |
| 144 | const rep: u32 = @bitCast(x); | |
| 145 | 145 | if (rep == expected) { |
| 146 | 146 | return; |
| 147 | 147 | } |
| ... | ... | @@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void { |
| 157 | 157 | |
| 158 | 158 | test "trunctfsf2" { |
| 159 | 159 | // qnan |
| 160 | test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7fc00000); | |
| 160 | test__trunctfsf2(@bitCast(@as(u128, 0x7fff800000000000 << 64)), 0x7fc00000); | |
| 161 | 161 | // nan |
| 162 | test__trunctfsf2(@as(f128, @bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64))), 0x7fc08000); | |
| 162 | test__trunctfsf2(@bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); | |
| 163 | 163 | // inf |
| 164 | test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7f800000); | |
| 164 | test__trunctfsf2(@bitCast(@as(u128, 0x7fff000000000000 << 64)), 0x7f800000); | |
| 165 | 165 | // zero |
| 166 | 166 | test__trunctfsf2(0.0, 0x0); |
| 167 | 167 | |
| ... | ... | @@ -174,7 +174,7 @@ test "trunctfsf2" { |
| 174 | 174 | fn test__trunctfdf2(a: f128, expected: u64) void { |
| 175 | 175 | const x = __trunctfdf2(a); |
| 176 | 176 | |
| 177 | const rep = @as(u64, @bitCast(x)); | |
| 177 | const rep: u64 = @bitCast(x); | |
| 178 | 178 | if (rep == expected) { |
| 179 | 179 | return; |
| 180 | 180 | } |
| ... | ... | @@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void { |
| 190 | 190 | |
| 191 | 191 | test "trunctfdf2" { |
| 192 | 192 | // qnan |
| 193 | test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7ff8000000000000); | |
| 193 | test__trunctfdf2(@bitCast(@as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000); | |
| 194 | 194 | // nan |
| 195 | test__trunctfdf2(@as(f128, @bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64))), 0x7ff8100000000000); | |
| 195 | test__trunctfdf2(@bitCast(@as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); | |
| 196 | 196 | // inf |
| 197 | test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7ff0000000000000); | |
| 197 | test__trunctfdf2(@bitCast(@as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000); | |
| 198 | 198 | // zero |
| 199 | 199 | test__trunctfdf2(0.0, 0x0); |
| 200 | 200 | |
| ... | ... | @@ -207,7 +207,7 @@ test "trunctfdf2" { |
| 207 | 207 | fn test__truncdfsf2(a: f64, expected: u32) void { |
| 208 | 208 | const x = __truncdfsf2(a); |
| 209 | 209 | |
| 210 | const rep = @as(u32, @bitCast(x)); | |
| 210 | const rep: u32 = @bitCast(x); | |
| 211 | 211 | if (rep == expected) { |
| 212 | 212 | return; |
| 213 | 213 | } |
| ... | ... | @@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void { |
| 225 | 225 | |
| 226 | 226 | test "truncdfsf2" { |
| 227 | 227 | // nan & qnan |
| 228 | test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff8000000000000))), 0x7fc00000); | |
| 229 | test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000001))), 0x7fc00000); | |
| 228 | test__truncdfsf2(@bitCast(@as(u64, 0x7ff8000000000000)), 0x7fc00000); | |
| 229 | test__truncdfsf2(@bitCast(@as(u64, 0x7ff0000000000001)), 0x7fc00000); | |
| 230 | 230 | // inf |
| 231 | test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000000))), 0x7f800000); | |
| 232 | test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0xfff0000000000000))), 0xff800000); | |
| 231 | test__truncdfsf2(@bitCast(@as(u64, 0x7ff0000000000000)), 0x7f800000); | |
| 232 | test__truncdfsf2(@bitCast(@as(u64, 0xfff0000000000000)), 0xff800000); | |
| 233 | 233 | |
| 234 | 234 | test__truncdfsf2(0.0, 0x0); |
| 235 | 235 | test__truncdfsf2(1.0, 0x3f800000); |
| ... | ... | @@ -242,7 +242,7 @@ test "truncdfsf2" { |
| 242 | 242 | fn test__trunctfhf2(a: f128, expected: u16) void { |
| 243 | 243 | const x = __trunctfhf2(a); |
| 244 | 244 | |
| 245 | const rep = @as(u16, @bitCast(x)); | |
| 245 | const rep: u16 = @bitCast(x); | |
| 246 | 246 | if (rep == expected) { |
| 247 | 247 | return; |
| 248 | 248 | } |
| ... | ... | @@ -254,11 +254,11 @@ fn test__trunctfhf2(a: f128, expected: u16) void { |
| 254 | 254 | |
| 255 | 255 | test "trunctfhf2" { |
| 256 | 256 | // qNaN |
| 257 | test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff8000000000000000000000000000))), 0x7e00); | |
| 257 | test__trunctfhf2(@bitCast(@as(u128, 0x7fff8000000000000000000000000000)), 0x7e00); | |
| 258 | 258 | // NaN |
| 259 | test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000001))), 0x7e00); | |
| 259 | test__trunctfhf2(@bitCast(@as(u128, 0x7fff0000000000000000000000000001)), 0x7e00); | |
| 260 | 260 | // inf |
| 261 | test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0x7c00); | |
| 261 | test__trunctfhf2(@bitCast(@as(u128, 0x7fff0000000000000000000000000000)), 0x7c00); | |
| 262 | 262 | test__trunctfhf2(-@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0xfc00); |
| 263 | 263 | // zero |
| 264 | 264 | test__trunctfhf2(0.0, 0x0); |
lib/compiler_rt/trunctfxf2.zig+1-1| ... | ... | @@ -44,7 +44,7 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 { |
| 44 | 44 | // destination format. We can convert by simply right-shifting with |
| 45 | 45 | // rounding, adding the explicit integer bit, and adjusting the exponent |
| 46 | 46 | res.fraction = @as(u64, @truncate(a_abs >> (src_sig_bits - dst_sig_bits))) | integer_bit; |
| 47 | res.exp = @as(u16, @truncate(a_abs >> src_sig_bits)); | |
| 47 | res.exp = @truncate(a_abs >> src_sig_bits); | |
| 48 | 48 | |
| 49 | 49 | const round_bits = a_abs & round_mask; |
| 50 | 50 | if (round_bits > halfway) { |
lib/std/Build.zig+1-1| ... | ... | @@ -1850,7 +1850,7 @@ pub fn hex64(x: u64) [16]u8 { |
| 1850 | 1850 | var result: [16]u8 = undefined; |
| 1851 | 1851 | var i: usize = 0; |
| 1852 | 1852 | while (i < 8) : (i += 1) { |
| 1853 | const byte = @as(u8, @truncate(x >> @as(u6, @intCast(8 * i)))); | |
| 1853 | const byte: u8 = @truncate(x >> @as(u6, @intCast(8 * i))); | |
| 1854 | 1854 | result[i * 2 + 0] = hex_charset[byte >> 4]; |
| 1855 | 1855 | result[i * 2 + 1] = hex_charset[byte & 15]; |
| 1856 | 1856 | } |
lib/std/crypto/25519/edwards25519.zig+1-1| ... | ... | @@ -206,7 +206,7 @@ pub const Edwards25519 = struct { |
| 206 | 206 | var q = Edwards25519.identityElement; |
| 207 | 207 | var pos: usize = 252; |
| 208 | 208 | while (true) : (pos -= 4) { |
| 209 | const slot = @as(u4, @truncate((s[pos >> 3] >> @as(u3, @truncate(pos))))); | |
| 209 | const slot: u4 = @truncate((s[pos >> 3] >> @as(u3, @truncate(pos)))); | |
| 210 | 210 | if (vartime) { |
| 211 | 211 | if (slot != 0) { |
| 212 | 212 | q = q.add(pc[slot]); |
lib/std/crypto/aes_ocb.zig+1-1| ... | ... | @@ -90,7 +90,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 90 | 90 | nx[16 - nonce_length - 1] = 1; |
| 91 | 91 | nx[nx.len - nonce_length ..].* = npub; |
| 92 | 92 | |
| 93 | const bottom = @as(u6, @truncate(nx[15])); | |
| 93 | const bottom: u6 = @truncate(nx[15]); | |
| 94 | 94 | nx[15] &= 0xc0; |
| 95 | 95 | var ktop_: Block = undefined; |
| 96 | 96 | aes_enc_ctx.encrypt(&ktop_, &nx); |
lib/std/crypto/ff.zig+5-5| ... | ... | @@ -508,18 +508,18 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 508 | 508 | var need_sub = false; |
| 509 | 509 | var i: usize = t_bits - 1; |
| 510 | 510 | while (true) : (i -= 1) { |
| 511 | var carry = @as(u1, @truncate(math.shr(Limb, y, i))); | |
| 511 | var carry: u1 = @truncate(math.shr(Limb, y, i)); | |
| 512 | 512 | var borrow: u1 = 0; |
| 513 | 513 | for (0..self.limbs_count()) |j| { |
| 514 | 514 | const l = ct.select(need_sub, d_limbs[j], x_limbs[j]); |
| 515 | 515 | var res = (l << 1) + carry; |
| 516 | 516 | x_limbs[j] = @as(TLimb, @truncate(res)); |
| 517 | carry = @as(u1, @truncate(res >> t_bits)); | |
| 517 | carry = @truncate(res >> t_bits); | |
| 518 | 518 | |
| 519 | 519 | res = x_limbs[j] -% m_limbs[j] -% borrow; |
| 520 | 520 | d_limbs[j] = @as(TLimb, @truncate(res)); |
| 521 | 521 | |
| 522 | borrow = @as(u1, @truncate(res >> t_bits)); | |
| 522 | borrow = @truncate(res >> t_bits); | |
| 523 | 523 | } |
| 524 | 524 | need_sub = ct.eql(carry, borrow); |
| 525 | 525 | if (i == 0) break; |
| ... | ... | @@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 531 | 531 | pub fn add(self: Self, x: Fe, y: Fe) Fe { |
| 532 | 532 | var out = x; |
| 533 | 533 | const overflow = out.v.addWithOverflow(y.v); |
| 534 | const underflow = @as(u1, @bitCast(ct.limbsCmpLt(out.v, self.v))); | |
| 534 | const underflow: u1 = @bitCast(ct.limbsCmpLt(out.v, self.v)); | |
| 535 | 535 | const need_sub = ct.eql(overflow, underflow); |
| 536 | 536 | _ = out.v.conditionalSubWithOverflow(need_sub, self.v); |
| 537 | 537 | return out; |
| ... | ... | @@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 540 | 540 | /// Subtracts two field elements (mod m). |
| 541 | 541 | pub fn sub(self: Self, x: Fe, y: Fe) Fe { |
| 542 | 542 | var out = x; |
| 543 | const underflow = @as(bool, @bitCast(out.v.subWithOverflow(y.v))); | |
| 543 | const underflow: bool = @bitCast(out.v.subWithOverflow(y.v)); | |
| 544 | 544 | _ = out.v.conditionalAddWithOverflow(underflow, self.v); |
| 545 | 545 | return out; |
| 546 | 546 | } |
lib/std/crypto/isap.zig+1-1| ... | ... | @@ -67,7 +67,7 @@ pub const IsapA128A = struct { |
| 67 | 67 | var i: usize = 0; |
| 68 | 68 | while (i < y.len * 8 - 1) : (i += 1) { |
| 69 | 69 | const cur_byte_pos = i / 8; |
| 70 | const cur_bit_pos = @as(u3, @truncate(7 - (i % 8))); | |
| 70 | const cur_bit_pos: u3 = @truncate(7 - (i % 8)); | |
| 71 | 71 | const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7; |
| 72 | 72 | isap.st.addByte(cur_bit, 0); |
| 73 | 73 | isap.st.permuteR(1); |
lib/std/crypto/kyber_d00.zig+2-2| ... | ... | @@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 { |
| 638 | 638 | // Note that x q' might be as big as 2³² and could overflow the int32 |
| 639 | 639 | // multiplication in the last line. However for any int32s a and b, |
| 640 | 640 | // we have int32(int64(a)*int64(b)) = int32(a*b) and so the result is ok. |
| 641 | const m = @as(i16, @truncate(@as(i32, @truncate(x *% qInv)))); | |
| 641 | const m: i16 = @truncate(@as(i32, @truncate(x *% qInv))); | |
| 642 | 642 | |
| 643 | 643 | // Note that x - m q is divisible by R; indeed modulo R we have |
| 644 | 644 | // |
| ... | ... | @@ -652,7 +652,7 @@ fn montReduce(x: i32) i16 { |
| 652 | 652 | // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have |
| 653 | 653 | // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired. |
| 654 | 654 | const yR = x - @as(i32, m) * @as(i32, Q); |
| 655 | return @as(i16, @bitCast(@as(u16, @truncate(@as(u32, @bitCast(yR)) >> 16)))); | |
| 655 | return @bitCast(@as(u16, @truncate(@as(u32, @bitCast(yR)) >> 16))); | |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | test "Test montReduce" { |
lib/std/hash/crc.zig+1-1| ... | ... | @@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { |
| 142 | 142 | var crc = tables[0][i]; |
| 143 | 143 | var j: usize = 1; |
| 144 | 144 | while (j < 8) : (j += 1) { |
| 145 | const index = @as(u8, @truncate(crc)); | |
| 145 | const index: u8 = @truncate(crc); | |
| 146 | 146 | crc = tables[0][index] ^ (crc >> 8); |
| 147 | 147 | tables[j][i] = crc; |
| 148 | 148 | } |
lib/std/hash/murmur.zig+2-2| ... | ... | @@ -14,7 +14,7 @@ pub const Murmur2_32 = struct { |
| 14 | 14 | |
| 15 | 15 | pub fn hashWithSeed(str: []const u8, seed: u32) u32 { |
| 16 | 16 | const m: u32 = 0x5bd1e995; |
| 17 | const len = @as(u32, @truncate(str.len)); | |
| 17 | const len: u32 = @truncate(str.len); | |
| 18 | 18 | var h1: u32 = seed ^ len; |
| 19 | 19 | for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { |
| 20 | 20 | var k1: u32 = v; |
| ... | ... | @@ -178,7 +178,7 @@ pub const Murmur3_32 = struct { |
| 178 | 178 | pub fn hashWithSeed(str: []const u8, seed: u32) u32 { |
| 179 | 179 | const c1: u32 = 0xcc9e2d51; |
| 180 | 180 | const c2: u32 = 0x1b873593; |
| 181 | const len = @as(u32, @truncate(str.len)); | |
| 181 | const len: u32 = @truncate(str.len); | |
| 182 | 182 | var h1: u32 = seed; |
| 183 | 183 | for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { |
| 184 | 184 | var k1: u32 = v; |
lib/std/hash_map.zig+3-3| ... | ... | @@ -899,7 +899,7 @@ pub fn HashMapUnmanaged( |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | fn capacityForSize(size: Size) Size { |
| 902 | var new_cap = @as(u32, @truncate((@as(u64, size) * 100) / max_load_percentage + 1)); | |
| 902 | var new_cap: u32 = @truncate((@as(u64, size) * 100) / max_load_percentage + 1); | |
| 903 | 903 | new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable; |
| 904 | 904 | return new_cap; |
| 905 | 905 | } |
| ... | ... | @@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged( |
| 1480 | 1480 | const new_cap = capacityForSize(self.size); |
| 1481 | 1481 | try other.allocate(allocator, new_cap); |
| 1482 | 1482 | other.initMetadatas(); |
| 1483 | other.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100)); | |
| 1483 | other.available = @truncate((new_cap * max_load_percentage) / 100); | |
| 1484 | 1484 | |
| 1485 | 1485 | var i: Size = 0; |
| 1486 | 1486 | var metadata = self.metadata.?; |
| ... | ... | @@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged( |
| 1515 | 1515 | defer map.deinit(allocator); |
| 1516 | 1516 | try map.allocate(allocator, new_cap); |
| 1517 | 1517 | map.initMetadatas(); |
| 1518 | map.available = @as(u32, @truncate((new_cap * max_load_percentage) / 100)); | |
| 1518 | map.available = @truncate((new_cap * max_load_percentage) / 100); | |
| 1519 | 1519 | |
| 1520 | 1520 | if (self.size != 0) { |
| 1521 | 1521 | const old_capacity = self.capacity(); |
lib/std/leb128.zig+8-8| ... | ... | @@ -10,8 +10,8 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T { |
| 10 | 10 | |
| 11 | 11 | const max_group = (@typeInfo(U).Int.bits + 6) / 7; |
| 12 | 12 | |
| 13 | var value = @as(U, 0); | |
| 14 | var group = @as(ShiftT, 0); | |
| 13 | var value: U = 0; | |
| 14 | var group: ShiftT = 0; | |
| 15 | 15 | |
| 16 | 16 | while (group < max_group) : (group += 1) { |
| 17 | 17 | const byte = try reader.readByte(); |
| ... | ... | @@ -37,10 +37,10 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T { |
| 37 | 37 | pub fn writeULEB128(writer: anytype, uint_value: anytype) !void { |
| 38 | 38 | const T = @TypeOf(uint_value); |
| 39 | 39 | const U = if (@typeInfo(T).Int.bits < 8) u8 else T; |
| 40 | var value = @as(U, @intCast(uint_value)); | |
| 40 | var value: U = @intCast(uint_value); | |
| 41 | 41 | |
| 42 | 42 | while (true) { |
| 43 | const byte = @as(u8, @truncate(value & 0x7f)); | |
| 43 | const byte: u8 = @truncate(value & 0x7f); | |
| 44 | 44 | value >>= 7; |
| 45 | 45 | if (value == 0) { |
| 46 | 46 | try writer.writeByte(byte); |
| ... | ... | @@ -115,11 +115,11 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void { |
| 115 | 115 | const S = if (@typeInfo(T).Int.bits < 8) i8 else T; |
| 116 | 116 | const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits); |
| 117 | 117 | |
| 118 | var value = @as(S, @intCast(int_value)); | |
| 118 | var value: S = @intCast(int_value); | |
| 119 | 119 | |
| 120 | 120 | while (true) { |
| 121 | const uvalue = @as(U, @bitCast(value)); | |
| 122 | const byte = @as(u8, @truncate(uvalue)); | |
| 121 | const uvalue: U = @bitCast(value); | |
| 122 | const byte: u8 = @truncate(uvalue); | |
| 123 | 123 | value >>= 6; |
| 124 | 124 | if (value == -1 or value == 0) { |
| 125 | 125 | try writer.writeByte(byte & 0x7F); |
| ... | ... | @@ -141,7 +141,7 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void { |
| 141 | 141 | pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void { |
| 142 | 142 | const T = @TypeOf(int); |
| 143 | 143 | const U = if (@typeInfo(T).Int.bits < 8) u8 else T; |
| 144 | var value = @as(U, @intCast(int)); | |
| 144 | var value: U = @intCast(int); | |
| 145 | 145 | |
| 146 | 146 | comptime var i = 0; |
| 147 | 147 | inline while (i < (l - 1)) : (i += 1) { |
lib/std/math/atanh.zig+2-2| ... | ... | @@ -55,11 +55,11 @@ fn atanh_32(x: f32) f32 { |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | fn atanh_64(x: f64) f64 { |
| 58 | const u = @as(u64, @bitCast(x)); | |
| 58 | const u: u64 = @bitCast(x); | |
| 59 | 59 | const e = (u >> 52) & 0x7FF; |
| 60 | 60 | const s = u >> 63; |
| 61 | 61 | |
| 62 | var y = @as(f64, @bitCast(u & (maxInt(u64) >> 1))); // |x| | |
| 62 | var y: f64 = @bitCast(u & (maxInt(u64) >> 1)); // |x| | |
| 63 | 63 | |
| 64 | 64 | if (y == 1.0) { |
| 65 | 65 | return math.copysign(math.inf(f64), x); |
lib/std/math/complex/cosh.zig+8-8| ... | ... | @@ -26,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) { |
| 26 | 26 | const x = z.re; |
| 27 | 27 | const y = z.im; |
| 28 | 28 | |
| 29 | const hx = @as(u32, @bitCast(x)); | |
| 29 | const hx: u32 = @bitCast(x); | |
| 30 | 30 | const ix = hx & 0x7fffffff; |
| 31 | 31 | |
| 32 | const hy = @as(u32, @bitCast(y)); | |
| 32 | const hy: u32 = @bitCast(y); | |
| 33 | 33 | const iy = hy & 0x7fffffff; |
| 34 | 34 | |
| 35 | 35 | if (ix < 0x7f800000 and iy < 0x7f800000) { |
| ... | ... | @@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) { |
| 89 | 89 | const x = z.re; |
| 90 | 90 | const y = z.im; |
| 91 | 91 | |
| 92 | const fx = @as(u64, @bitCast(x)); | |
| 93 | const hx = @as(u32, @intCast(fx >> 32)); | |
| 94 | const lx = @as(u32, @truncate(fx)); | |
| 92 | const fx: u64 = @bitCast(x); | |
| 93 | const hx: u32 = @intCast(fx >> 32); | |
| 94 | const lx: u32 = @truncate(fx); | |
| 95 | 95 | const ix = hx & 0x7fffffff; |
| 96 | 96 | |
| 97 | const fy = @as(u64, @bitCast(y)); | |
| 98 | const hy = @as(u32, @intCast(fy >> 32)); | |
| 99 | const ly = @as(u32, @truncate(fy)); | |
| 97 | const fy: u64 = @bitCast(y); | |
| 98 | const hy: u32 = @intCast(fy >> 32); | |
| 99 | const ly: u32 = @truncate(fy); | |
| 100 | 100 | const iy = hy & 0x7fffffff; |
| 101 | 101 | |
| 102 | 102 | // nearly non-exceptional case where x, y are finite |
lib/std/math/complex/exp.zig+6-6| ... | ... | @@ -75,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) { |
| 75 | 75 | const x = z.re; |
| 76 | 76 | const y = z.im; |
| 77 | 77 | |
| 78 | const fy = @as(u64, @bitCast(y)); | |
| 79 | const hy = @as(u32, @intCast((fy >> 32) & 0x7fffffff)); | |
| 80 | const ly = @as(u32, @truncate(fy)); | |
| 78 | const fy: u64 = @bitCast(y); | |
| 79 | const hy: u32 = @intCast((fy >> 32) & 0x7fffffff); | |
| 80 | const ly: u32 = @truncate(fy); | |
| 81 | 81 | |
| 82 | 82 | // cexp(x + i0) = exp(x) + i0 |
| 83 | 83 | if (hy | ly == 0) { |
| 84 | 84 | return Complex(f64).init(@exp(x), y); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | const fx = @as(u64, @bitCast(x)); | |
| 88 | const hx = @as(u32, @intCast(fx >> 32)); | |
| 89 | const lx = @as(u32, @truncate(fx)); | |
| 87 | const fx: u64 = @bitCast(x); | |
| 88 | const hx: u32 = @intCast(fx >> 32); | |
| 89 | const lx: u32 = @truncate(fx); | |
| 90 | 90 | |
| 91 | 91 | // cexp(0 + iy) = cos(y) + isin(y) |
| 92 | 92 | if ((hx & 0x7fffffff) | lx == 0) { |
lib/std/math/complex/sinh.zig+6-6| ... | ... | @@ -89,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) { |
| 89 | 89 | const x = z.re; |
| 90 | 90 | const y = z.im; |
| 91 | 91 | |
| 92 | const fx = @as(u64, @bitCast(x)); | |
| 93 | const hx = @as(u32, @intCast(fx >> 32)); | |
| 94 | const lx = @as(u32, @truncate(fx)); | |
| 92 | const fx: u64 = @bitCast(x); | |
| 93 | const hx: u32 = @intCast(fx >> 32); | |
| 94 | const lx: u32 = @truncate(fx); | |
| 95 | 95 | const ix = hx & 0x7fffffff; |
| 96 | 96 | |
| 97 | const fy = @as(u64, @bitCast(y)); | |
| 98 | const hy = @as(u32, @intCast(fy >> 32)); | |
| 99 | const ly = @as(u32, @truncate(fy)); | |
| 97 | const fy: u64 = @bitCast(y); | |
| 98 | const hy: u32 = @intCast(fy >> 32); | |
| 99 | const ly: u32 = @truncate(fy); | |
| 100 | 100 | const iy = hy & 0x7fffffff; |
| 101 | 101 | |
| 102 | 102 | if (ix < 0x7ff00000 and iy < 0x7ff00000) { |
lib/std/math/complex/tanh.zig+4-4| ... | ... | @@ -62,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) { |
| 62 | 62 | const x = z.re; |
| 63 | 63 | const y = z.im; |
| 64 | 64 | |
| 65 | const fx = @as(u64, @bitCast(x)); | |
| 65 | const fx: u64 = @bitCast(x); | |
| 66 | 66 | // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily |
| 67 | 67 | // fits in range. |
| 68 | const hx = @as(u32, @intCast(fx >> 32)); | |
| 69 | const lx = @as(u32, @truncate(fx)); | |
| 68 | const hx: u32 = @intCast(fx >> 32); | |
| 69 | const lx: u32 = @truncate(fx); | |
| 70 | 70 | const ix = hx & 0x7fffffff; |
| 71 | 71 | |
| 72 | 72 | if (ix >= 0x7ff00000) { |
| ... | ... | @@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) { |
| 75 | 75 | return Complex(f64).init(x, r); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | const xx = @as(f64, @bitCast((@as(u64, hx - 0x40000000) << 32) | lx)); | |
| 78 | const xx: f64 = @bitCast((@as(u64, hx - 0x40000000) << 32) | lx); | |
| 79 | 79 | const r = if (math.isInf(y)) y else @sin(y) * @cos(y); |
| 80 | 80 | return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r)); |
| 81 | 81 | } |
lib/std/math/modf.zig+3-3| ... | ... | @@ -37,7 +37,7 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) { |
| 37 | 37 | fn modf32(x: f32) modf32_result { |
| 38 | 38 | var result: modf32_result = undefined; |
| 39 | 39 | |
| 40 | const u = @as(u32, @bitCast(x)); | |
| 40 | const u: u32 = @bitCast(x); | |
| 41 | 41 | const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; |
| 42 | 42 | const us = u & 0x80000000; |
| 43 | 43 | |
| ... | ... | @@ -73,7 +73,7 @@ fn modf32(x: f32) modf32_result { |
| 73 | 73 | return result; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | const uf = @as(f32, @bitCast(u & ~mask)); | |
| 76 | const uf: f32 = @bitCast(u & ~mask); | |
| 77 | 77 | result.ipart = uf; |
| 78 | 78 | result.fpart = x - uf; |
| 79 | 79 | return result; |
| ... | ... | @@ -82,7 +82,7 @@ fn modf32(x: f32) modf32_result { |
| 82 | 82 | fn modf64(x: f64) modf64_result { |
| 83 | 83 | var result: modf64_result = undefined; |
| 84 | 84 | |
| 85 | const u = @as(u64, @bitCast(x)); | |
| 85 | const u: u64 = @bitCast(x); | |
| 86 | 86 | const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF; |
| 87 | 87 | const us = u & (1 << 63); |
| 88 | 88 |
lib/std/os/linux.zig+7-7| ... | ... | @@ -176,21 +176,21 @@ const require_aligned_register_pair = |
| 176 | 176 | // Split a 64bit value into a {LSB,MSB} pair. |
| 177 | 177 | // The LE/BE variants specify the endianness to assume. |
| 178 | 178 | fn splitValueLE64(val: i64) [2]u32 { |
| 179 | const u = @as(u64, @bitCast(val)); | |
| 179 | const u: u64 = @bitCast(val); | |
| 180 | 180 | return [2]u32{ |
| 181 | 181 | @as(u32, @truncate(u)), |
| 182 | 182 | @as(u32, @truncate(u >> 32)), |
| 183 | 183 | }; |
| 184 | 184 | } |
| 185 | 185 | fn splitValueBE64(val: i64) [2]u32 { |
| 186 | const u = @as(u64, @bitCast(val)); | |
| 186 | const u: u64 = @bitCast(val); | |
| 187 | 187 | return [2]u32{ |
| 188 | 188 | @as(u32, @truncate(u >> 32)), |
| 189 | 189 | @as(u32, @truncate(u)), |
| 190 | 190 | }; |
| 191 | 191 | } |
| 192 | 192 | fn splitValue64(val: i64) [2]u32 { |
| 193 | const u = @as(u64, @bitCast(val)); | |
| 193 | const u: u64 = @bitCast(val); | |
| 194 | 194 | switch (native_endian) { |
| 195 | 195 | .Little => return [2]u32{ |
| 196 | 196 | @as(u32, @truncate(u)), |
| ... | ... | @@ -467,7 +467,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize { |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize { |
| 470 | const offset_u = @as(u64, @bitCast(offset)); | |
| 470 | const offset_u: u64 = @bitCast(offset); | |
| 471 | 471 | return syscall5( |
| 472 | 472 | .preadv, |
| 473 | 473 | @as(usize, @bitCast(@as(isize, fd))), |
| ... | ... | @@ -482,7 +482,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize { |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize { |
| 485 | const offset_u = @as(u64, @bitCast(offset)); | |
| 485 | const offset_u: u64 = @bitCast(offset); | |
| 486 | 486 | return syscall6( |
| 487 | 487 | .preadv2, |
| 488 | 488 | @as(usize, @bitCast(@as(isize, fd))), |
| ... | ... | @@ -504,7 +504,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize { |
| 507 | const offset_u = @as(u64, @bitCast(offset)); | |
| 507 | const offset_u: u64 = @bitCast(offset); | |
| 508 | 508 | return syscall5( |
| 509 | 509 | .pwritev, |
| 510 | 510 | @as(usize, @bitCast(@as(isize, fd))), |
| ... | ... | @@ -517,7 +517,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) us |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize { |
| 520 | const offset_u = @as(u64, @bitCast(offset)); | |
| 520 | const offset_u: u64 = @bitCast(offset); | |
| 521 | 521 | return syscall6( |
| 522 | 522 | .pwritev2, |
| 523 | 523 | @as(usize, @bitCast(@as(isize, fd))), |
lib/std/os/linux/io_uring.zig+4-4| ... | ... | @@ -1507,7 +1507,7 @@ pub fn io_uring_prep_renameat( |
| 1507 | 1507 | 0, |
| 1508 | 1508 | @intFromPtr(new_path), |
| 1509 | 1509 | ); |
| 1510 | sqe.len = @as(u32, @bitCast(new_dir_fd)); | |
| 1510 | sqe.len = @bitCast(new_dir_fd); | |
| 1511 | 1511 | sqe.rw_flags = flags; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| ... | ... | @@ -1562,7 +1562,7 @@ pub fn io_uring_prep_linkat( |
| 1562 | 1562 | 0, |
| 1563 | 1563 | @intFromPtr(new_path), |
| 1564 | 1564 | ); |
| 1565 | sqe.len = @as(u32, @bitCast(new_dir_fd)); | |
| 1565 | sqe.len = @bitCast(new_dir_fd); | |
| 1566 | 1566 | sqe.rw_flags = flags; |
| 1567 | 1567 | } |
| 1568 | 1568 | |
| ... | ... | @@ -1576,7 +1576,7 @@ pub fn io_uring_prep_provide_buffers( |
| 1576 | 1576 | ) void { |
| 1577 | 1577 | const ptr = @intFromPtr(buffers); |
| 1578 | 1578 | io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @as(i32, @intCast(num)), ptr, buffer_len, buffer_id); |
| 1579 | sqe.buf_index = @as(u16, @intCast(group_id)); | |
| 1579 | sqe.buf_index = @intCast(group_id); | |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | pub fn io_uring_prep_remove_buffers( |
| ... | ... | @@ -1585,7 +1585,7 @@ pub fn io_uring_prep_remove_buffers( |
| 1585 | 1585 | group_id: usize, |
| 1586 | 1586 | ) void { |
| 1587 | 1587 | io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @as(i32, @intCast(num)), 0, 0, 0); |
| 1588 | sqe.buf_index = @as(u16, @intCast(group_id)); | |
| 1588 | sqe.buf_index = @intCast(group_id); | |
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | test "structs/offsets/entries" { |
lib/std/os/windows.zig+1-1| ... | ... | @@ -1918,7 +1918,7 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 { |
| 1918 | 1918 | |
| 1919 | 1919 | /// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME. |
| 1920 | 1920 | pub fn nanoSecondsToFileTime(ns: i128) FILETIME { |
| 1921 | const adjusted = @as(u64, @bitCast(toSysTime(ns))); | |
| 1921 | const adjusted: u64 = @bitCast(toSysTime(ns)); | |
| 1922 | 1922 | return FILETIME{ |
| 1923 | 1923 | .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)), |
| 1924 | 1924 | .dwLowDateTime = @as(u32, @truncate(adjusted)), |
lib/std/os/windows/user32.zig+1-1| ... | ... | @@ -1275,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000; |
| 1275 | 1275 | pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE; |
| 1276 | 1276 | pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST; |
| 1277 | 1277 | |
| 1278 | pub const CW_USEDEFAULT = @as(i32, @bitCast(@as(u32, 0x80000000))); | |
| 1278 | pub const CW_USEDEFAULT: i32 = @bitCast(@as(u32, 0x80000000)); | |
| 1279 | 1279 | |
| 1280 | 1280 | pub extern "user32" fn CreateWindowExA(dwExStyle: DWORD, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: DWORD, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?LPVOID) callconv(WINAPI) ?HWND; |
| 1281 | 1281 | pub fn createWindowExA(dwExStyle: u32, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: u32, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?*anyopaque) !HWND { |
lib/std/rand/Pcg.zig+2-2| ... | ... | @@ -29,8 +29,8 @@ fn next(self: *Pcg) u32 { |
| 29 | 29 | const l = self.s; |
| 30 | 30 | self.s = l *% default_multiplier +% (self.i | 1); |
| 31 | 31 | |
| 32 | const xor_s = @as(u32, @truncate(((l >> 18) ^ l) >> 27)); | |
| 33 | const rot = @as(u32, @intCast(l >> 59)); | |
| 32 | const xor_s: u32 = @truncate(((l >> 18) ^ l) >> 27); | |
| 33 | const rot: u32 = @intCast(l >> 59); | |
| 34 | 34 | |
| 35 | 35 | return (xor_s >> @as(u5, @intCast(rot))) | (xor_s << @as(u5, @intCast((0 -% rot) & 31))); |
| 36 | 36 | } |
lib/std/zig/c_builtins.zig+2-2| ... | ... | @@ -206,8 +206,8 @@ pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long { |
| 206 | 206 | /// If tagp is empty, the function returns a NaN whose significand is zero. |
| 207 | 207 | pub inline fn __builtin_nanf(tagp: []const u8) f32 { |
| 208 | 208 | const parsed = std.fmt.parseUnsigned(c_ulong, tagp, 0) catch 0; |
| 209 | const bits = @as(u23, @truncate(parsed)); // single-precision float trailing significand is 23 bits | |
| 210 | return @as(f32, @bitCast(@as(u32, bits) | std.math.qnan_u32)); | |
| 209 | const bits: u23 = @truncate(parsed); // single-precision float trailing significand is 23 bits | |
| 210 | return @bitCast(@as(u32, bits) | std.math.qnan_u32); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | pub inline fn __builtin_huge_valf() f32 { |
lib/std/zig/system/arm.zig+1-1| ... | ... | @@ -183,7 +183,7 @@ pub const aarch64 = struct { |
| 183 | 183 | blk: { |
| 184 | 184 | if (info.implementer == 0x41) { |
| 185 | 185 | // ARM Ltd. |
| 186 | const special_bits = @as(u4, @truncate(info.part >> 8)); | |
| 186 | const special_bits: u4 = @truncate(info.part >> 8); | |
| 187 | 187 | if (special_bits == 0x0 or special_bits == 0x7) { |
| 188 | 188 | // TODO Variant and arch encoded differently. |
| 189 | 189 | break :blk; |