authorgravatar for zach@raineri.softwareZachary Raineri <zach@raineri.software> 2023-07-24 05:34:16-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-24 10:23:51-07:00
logd82b35901035a325ca7afd38b28ff2386f90ae84
tree1a370e979308a3406ea42e55f16299d48ba19700
parent77b96231a6bc195cc482d05599e8c20ee01645a6

Use builtin inference over @as where possible


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,14 +38,14 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
38 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))38 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
39 {39 {
40 // NaN + anything = qNaN40 // 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 // anything + NaN = qNaN42 // 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);
4444
45 if (aAbs == infRep) {45 if (aAbs == infRep) {
46 // +/-infinity + -/+infinity = qNaN46 // +/-infinity + -/+infinity = qNaN
47 if ((@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) == signBit) {47 if ((@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) == signBit) {
48 return @as(T, @bitCast(qnanRep));48 return @bitCast(qnanRep);
49 }49 }
50 // +/-infinity + anything remaining = +/- infinity50 // +/-infinity + anything remaining = +/- infinity
51 else {51 else {
...@@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -60,7 +60,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
60 if (aAbs == 0) {60 if (aAbs == 0) {
61 // but we need to get the sign right for zero + zero61 // but we need to get the sign right for zero + zero
62 if (bAbs == 0) {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 } else {64 } else {
65 return b;65 return b;
66 }66 }
...@@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -78,8 +78,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
78 }78 }
7979
80 // Extract the exponent and significand from the (possibly swapped) a and b.80 // Extract the exponent and significand from the (possibly swapped) a and b.
81 var aExponent = @as(i32, @intCast((aRep >> significandBits) & maxExponent));81 var aExponent: i32 = @intCast((aRep >> significandBits) & maxExponent);
82 var bExponent = @as(i32, @intCast((bRep >> significandBits) & maxExponent));82 var bExponent: i32 = @intCast((bRep >> significandBits) & maxExponent);
83 var aSignificand = aRep & significandMask;83 var aSignificand = aRep & significandMask;
84 var bSignificand = bRep & significandMask;84 var bSignificand = bRep & significandMask;
8585
...@@ -101,7 +101,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -101,7 +101,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
101101
102 // Shift the significand of b by the difference in exponents, with a sticky102 // Shift the significand of b by the difference in exponents, with a sticky
103 // bottom bit to get rounding correct.103 // bottom bit to get rounding correct.
104 const @"align" = @as(u32, @intCast(aExponent - bExponent));104 const @"align": u32 = @intCast(aExponent - bExponent);
105 if (@"align" != 0) {105 if (@"align" != 0) {
106 if (@"align" < typeWidth) {106 if (@"align" < typeWidth) {
107 const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0;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,7 +113,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
113 if (subtraction) {113 if (subtraction) {
114 aSignificand -= bSignificand;114 aSignificand -= bSignificand;
115 // If a == -b, return +zero.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));
117117
118 // If partial cancellation occured, we need to left-shift the result118 // If partial cancellation occured, we need to left-shift the result
119 // and adjust the exponent:119 // and adjust the exponent:
...@@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -135,13 +135,13 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
135 }135 }
136136
137 // If we have overflowed the type, return +/- infinity: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);
139139
140 if (aExponent <= 0) {140 if (aExponent <= 0) {
141 // Result is denormal; the exponent and round/sticky bits are zero.141 // Result is denormal; the exponent and round/sticky bits are zero.
142 // All we need to do is shift the significand and apply the correct sign.142 // All we need to do is shift the significand and apply the correct sign.
143 aSignificand >>= @as(S, @intCast(4 - aExponent));143 aSignificand >>= @as(S, @intCast(4 - aExponent));
144 return @as(T, @bitCast(resultSign | aSignificand));144 return @bitCast(resultSign | aSignificand);
145 }145 }
146146
147 // Low three bits are round, guard, and sticky.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,7 +164,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
164 if ((result >> significandBits) != 0) result |= integerBit;164 if ((result >> significandBits) != 0) result |= integerBit;
165 }165 }
166166
167 return @as(T, @bitCast(result));167 return @bitCast(result);
168}168}
169169
170test {170test {
lib/compiler_rt/addf3_test.zig+9-9
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("std");6const std = @import("std");
7const math = std.math;7const math = std.math;
8const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));8const qnan128: f128 = @bitCast(@as(u128, 0x7fff800000000000) << 64);
99
10const __addtf3 = @import("addtf3.zig").__addtf3;10const __addtf3 = @import("addtf3.zig").__addtf3;
11const __addxf3 = @import("addxf3.zig").__addxf3;11const __addxf3 = @import("addxf3.zig").__addxf3;
...@@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3;...@@ -14,9 +14,9 @@ const __subtf3 = @import("subtf3.zig").__subtf3;
14fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {14fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
15 const x = __addtf3(a, b);15 const x = __addtf3(a, b);
1616
17 const rep = @as(u128, @bitCast(x));17 const rep: u128 = @bitCast(x);
18 const hi = @as(u64, @intCast(rep >> 64));18 const hi: u64 = @intCast(rep >> 64);
19 const lo = @as(u64, @truncate(rep));19 const lo: u64 = @truncate(rep);
2020
21 if (hi == expected_hi and lo == expected_lo) {21 if (hi == expected_hi and lo == expected_lo) {
22 return;22 return;
...@@ -53,9 +53,9 @@ test "addtf3" {...@@ -53,9 +53,9 @@ test "addtf3" {
53fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {53fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
54 const x = __subtf3(a, b);54 const x = __subtf3(a, b);
5555
56 const rep = @as(u128, @bitCast(x));56 const rep: u128 = @bitCast(x);
57 const hi = @as(u64, @intCast(rep >> 64));57 const hi: u64 = @intCast(rep >> 64);
58 const lo = @as(u64, @truncate(rep));58 const lo: u64 = @truncate(rep);
5959
60 if (hi == expected_hi and lo == expected_lo) {60 if (hi == expected_hi and lo == expected_lo) {
61 return;61 return;
...@@ -87,11 +87,11 @@ test "subtf3" {...@@ -87,11 +87,11 @@ test "subtf3" {
87 try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);87 try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);
88}88}
8989
90const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))));90const qnan80: f80 = @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1)));
9191
92fn test__addxf3(a: f80, b: f80, expected: u80) !void {92fn test__addxf3(a: f80, b: f80, expected: u80) !void {
93 const x = __addxf3(a, b);93 const x = __addxf3(a, b);
94 const rep = @as(u80, @bitCast(x));94 const rep: u80 = @bitCast(x);
9595
96 if (rep == expected)96 if (rep == expected)
97 return;97 return;
lib/compiler_rt/arm.zig+1-1
...@@ -192,6 +192,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {...@@ -192,6 +192,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {
192}192}
193193
194pub fn __aeabi_drsub(a: f64, b: f64) callconv(.AAPCS) f64 {194pub 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 return b + neg_a;196 return b + neg_a;
197}197}
lib/compiler_rt/ceil.zig+6-6
...@@ -27,11 +27,11 @@ comptime {...@@ -27,11 +27,11 @@ comptime {
2727
28pub fn __ceilh(x: f16) callconv(.C) f16 {28pub fn __ceilh(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @as(f16, @floatCast(ceilf(x)));30 return @floatCast(ceilf(x));
31}31}
3232
33pub fn ceilf(x: f32) callconv(.C) f32 {33pub fn ceilf(x: f32) callconv(.C) f32 {
34 var u = @as(u32, @bitCast(x));34 var u: u32 = @bitCast(x);
35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
36 var m: u32 = undefined;36 var m: u32 = undefined;
3737
...@@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {...@@ -52,7 +52,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
52 u += m;52 u += m;
53 }53 }
54 u &= ~m;54 u &= ~m;
55 return @as(f32, @bitCast(u));55 return @bitCast(u);
56 } else {56 } else {
57 math.doNotOptimizeAway(x + 0x1.0p120);57 math.doNotOptimizeAway(x + 0x1.0p120);
58 if (u >> 31 != 0) {58 if (u >> 31 != 0) {
...@@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {...@@ -66,7 +66,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
66pub fn ceil(x: f64) callconv(.C) f64 {66pub fn ceil(x: f64) callconv(.C) f64 {
67 const f64_toint = 1.0 / math.floatEps(f64);67 const f64_toint = 1.0 / math.floatEps(f64);
6868
69 const u = @as(u64, @bitCast(x));69 const u: u64 = @bitCast(x);
70 const e = (u >> 52) & 0x7FF;70 const e = (u >> 52) & 0x7FF;
71 var y: f64 = undefined;71 var y: f64 = undefined;
7272
...@@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 {...@@ -96,13 +96,13 @@ pub fn ceil(x: f64) callconv(.C) f64 {
9696
97pub fn __ceilx(x: f80) callconv(.C) f80 {97pub fn __ceilx(x: f80) callconv(.C) f80 {
98 // TODO: more efficient implementation98 // TODO: more efficient implementation
99 return @as(f80, @floatCast(ceilq(x)));99 return @floatCast(ceilq(x));
100}100}
101101
102pub fn ceilq(x: f128) callconv(.C) f128 {102pub fn ceilq(x: f128) callconv(.C) f128 {
103 const f128_toint = 1.0 / math.floatEps(f128);103 const f128_toint = 1.0 / math.floatEps(f128);
104104
105 const u = @as(u128, @bitCast(x));105 const u: u128 = @bitCast(x);
106 const e = (u >> 112) & 0x7FFF;106 const e = (u >> 112) & 0x7FFF;
107 var y: f128 = undefined;107 var y: f128 = undefined;
108108
lib/compiler_rt/clzdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");...@@ -2,7 +2,7 @@ const clz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__clzdi2(a: u64, expected: i64) !void {4fn test__clzdi2(a: u64, expected: i64) !void {
5 var x = @as(i64, @bitCast(a));5 var x: i64 = @bitCast(a);
6 var result = clz.__clzdi2(x);6 var result = clz.__clzdi2(x);
7 try testing.expectEqual(expected, result);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,7 +5,7 @@ const testing = @import("std").testing;
5fn test__clzsi2(a: u32, expected: i32) !void {5fn test__clzsi2(a: u32, expected: i32) !void {
6 const nakedClzsi2 = clz.__clzsi2;6 const nakedClzsi2 = clz.__clzsi2;
7 const actualClzsi2 = @as(*const fn (a: i32) callconv(.C) i32, @ptrCast(&nakedClzsi2));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 const result = actualClzsi2(x);9 const result = actualClzsi2(x);
10 try testing.expectEqual(expected, result);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,7 +2,7 @@ const clz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__clzti2(a: u128, expected: i64) !void {4fn test__clzti2(a: u128, expected: i64) !void {
5 var x = @as(i128, @bitCast(a));5 var x: i128 = @bitCast(a);
6 var result = clz.__clzti2(x);6 var result = clz.__clzti2(x);
7 try testing.expectEqual(expected, result);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,7 +35,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
35 const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D235 const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
36 const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D1836 const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
3737
38 var ix = @as(u32, @bitCast(x));38 var ix: u32 = @bitCast(x);
39 const sign = ix >> 31 != 0;39 const sign = ix >> 31 != 0;
40 ix &= 0x7fffffff;40 ix &= 0x7fffffff;
4141
...@@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 {...@@ -116,12 +116,12 @@ pub fn cos(x: f64) callconv(.C) f64 {
116116
117pub fn __cosx(a: f80) callconv(.C) f80 {117pub fn __cosx(a: f80) callconv(.C) f80 {
118 // TODO: more efficient implementation118 // TODO: more efficient implementation
119 return @as(f80, @floatCast(cosq(a)));119 return @floatCast(cosq(a));
120}120}
121121
122pub fn cosq(a: f128) callconv(.C) f128 {122pub fn cosq(a: f128) callconv(.C) f128 {
123 // TODO: more correct implementation123 // TODO: more correct implementation
124 return cos(@as(f64, @floatCast(a)));124 return cos(@floatCast(a));
125}125}
126126
127pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {127pub 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,7 +49,7 @@ inline fn clzXi2(comptime T: type, a: T) i32 {
49 x = y;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}
5454
55fn __clzsi2_thumb1() callconv(.Naked) void {55fn __clzsi2_thumb1() callconv(.Naked) void {
...@@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 {...@@ -187,7 +187,7 @@ inline fn ctzXi2(comptime T: type, a: T) i32 {
187 x = x >> shift;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}
192192
193pub fn __ctzsi2(a: i32) callconv(.C) i32 {193pub fn __ctzsi2(a: i32) callconv(.C) i32 {
...@@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 {...@@ -224,7 +224,7 @@ inline fn ffsXi2(comptime T: type, a: T) i32 {
224 }224 }
225 }225 }
226 // return ctz + 1226 // 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}
229229
230pub fn __ffssi2(a: i32) callconv(.C) i32 {230pub 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,7 +2,7 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzdi2(a: u64, expected: i32) !void {4fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x = @as(i64, @bitCast(a));5 var x: i64 = @bitCast(a);
6 var result = ctz.__ctzdi2(x);6 var result = ctz.__ctzdi2(x);
7 try testing.expectEqual(expected, result);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,7 +2,7 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzsi2(a: u32, expected: i32) !void {4fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x = @as(i32, @bitCast(a));5 var x: i32 = @bitCast(a);
6 var result = ctz.__ctzsi2(x);6 var result = ctz.__ctzsi2(x);
7 try testing.expectEqual(expected, result);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,7 +2,7 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzti2(a: u128, expected: i32) !void {4fn test__ctzti2(a: u128, expected: i32) !void {
5 var x = @as(i128, @bitCast(a));5 var x: i128 = @bitCast(a);
6 var result = ctz.__ctzti2(x);6 var result = ctz.__ctzti2(x);
7 try testing.expectEqual(expected, result);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,8 +49,8 @@ inline fn div(a: f64, b: f64) f64 {
49 const qnanRep = exponentMask | quietBit;49 const qnanRep = exponentMask | quietBit;
50 const infRep = @as(Z, @bitCast(std.math.inf(f64)));50 const infRep = @as(Z, @bitCast(std.math.inf(f64)));
5151
52 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));52 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
53 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));53 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
54 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;54 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5555
56 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;56 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
...@@ -63,36 +63,36 @@ inline fn div(a: f64, b: f64) f64 {...@@ -63,36 +63,36 @@ inline fn div(a: f64, b: f64) f64 {
63 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;63 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6464
65 // NaN / anything = qNaN65 // 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 // anything / NaN = qNaN67 // 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);
6969
70 if (aAbs == infRep) {70 if (aAbs == infRep) {
71 // infinity / infinity = NaN71 // infinity / infinity = NaN
72 if (bAbs == infRep) {72 if (bAbs == infRep) {
73 return @as(f64, @bitCast(qnanRep));73 return @bitCast(qnanRep);
74 }74 }
75 // infinity / anything else = +/- infinity75 // infinity / anything else = +/- infinity
76 else {76 else {
77 return @as(f64, @bitCast(aAbs | quotientSign));77 return @bitCast(aAbs | quotientSign);
78 }78 }
79 }79 }
8080
81 // anything else / infinity = +/- 081 // anything else / infinity = +/- 0
82 if (bAbs == infRep) return @as(f64, @bitCast(quotientSign));82 if (bAbs == infRep) return @bitCast(quotientSign);
8383
84 if (aAbs == 0) {84 if (aAbs == 0) {
85 // zero / zero = NaN85 // zero / zero = NaN
86 if (bAbs == 0) {86 if (bAbs == 0) {
87 return @as(f64, @bitCast(qnanRep));87 return @bitCast(qnanRep);
88 }88 }
89 // zero / anything else = +/- zero89 // zero / anything else = +/- zero
90 else {90 else {
91 return @as(f64, @bitCast(quotientSign));91 return @bitCast(quotientSign);
92 }92 }
93 }93 }
94 // anything else / zero = +/- infinity94 // anything else / zero = +/- infinity
95 if (bAbs == 0) return @as(f64, @bitCast(infRep | quotientSign));95 if (bAbs == 0) return @bitCast(infRep | quotientSign);
9696
97 // one or both of a or b is denormal, the other (if applicable) is a97 // one or both of a or b is denormal, the other (if applicable) is a
98 // normal number. Renormalize one or both of a and b, and set scale to98 // 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,7 +112,7 @@ inline fn div(a: f64, b: f64) f64 {
112 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax112 // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
113 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This113 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
114 // is accurate to about 3.5 binary digits.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 var recip32 = @as(u32, 0x7504f333) -% q31b;116 var recip32 = @as(u32, 0x7504f333) -% q31b;
117117
118 // Now refine the reciprocal estimate using a Newton-Raphson iteration:118 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
...@@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 {...@@ -123,12 +123,12 @@ inline fn div(a: f64, b: f64) f64 {
123 // with each iteration, so after three iterations, we have about 28 binary123 // with each iteration, so after three iterations, we have about 28 binary
124 // digits of accuracy.124 // digits of accuracy.
125 var correction32: u32 = undefined;125 var correction32: u32 = undefined;
126 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));126 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
127 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));127 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
128 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));128 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
129 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));129 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
130 correction32 = @as(u32, @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1));130 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
131 recip32 = @as(u32, @truncate(@as(u64, recip32) *% correction32 >> 31));131 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
132132
133 // recip32 might have overflowed to exactly zero in the preceding133 // recip32 might have overflowed to exactly zero in the preceding
134 // computation if the high word of b is exactly 1.0. This would sabotage134 // 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,12 +138,12 @@ inline fn div(a: f64, b: f64) f64 {
138138
139 // We need to perform one more iteration to get us to 56 binary digits;139 // We need to perform one more iteration to get us to 56 binary digits;
140 // The last iteration needs to happen with extra precision.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 var correction: u64 = undefined;142 var correction: u64 = undefined;
143 var reciprocal: u64 = undefined;143 var reciprocal: u64 = undefined;
144 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;144 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
145 const cHi = @as(u32, @truncate(correction >> 32));145 const cHi: u32 = @truncate(correction >> 32);
146 const cLo = @as(u32, @truncate(correction));146 const cLo: u32 = @truncate(correction);
147 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);147 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
148148
149 // We already adjusted the 32-bit estimate, now we need to adjust the final149 // 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,7 +195,7 @@ inline fn div(a: f64, b: f64) f64 {
195195
196 if (writtenExponent >= maxExponent) {196 if (writtenExponent >= maxExponent) {
197 // If we have overflowed the exponent, return infinity.197 // If we have overflowed the exponent, return infinity.
198 return @as(f64, @bitCast(infRep | quotientSign));198 return @bitCast(infRep | quotientSign);
199 } else if (writtenExponent < 1) {199 } else if (writtenExponent < 1) {
200 if (writtenExponent == 0) {200 if (writtenExponent == 0) {
201 // Check whether the rounded result is normal.201 // Check whether the rounded result is normal.
...@@ -206,12 +206,12 @@ inline fn div(a: f64, b: f64) f64 {...@@ -206,12 +206,12 @@ inline fn div(a: f64, b: f64) f64 {
206 absResult += round;206 absResult += round;
207 if ((absResult & ~significandMask) != 0) {207 if ((absResult & ~significandMask) != 0) {
208 // The rounded result is normal; return it.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 // Flush denormals to zero. In the future, it would be nice to add212 // Flush denormals to zero. In the future, it would be nice to add
213 // code to round them correctly.213 // code to round them correctly.
214 return @as(f64, @bitCast(quotientSign));214 return @bitCast(quotientSign);
215 } else {215 } else {
216 const round = @intFromBool((residual << 1) > bSignificand);216 const round = @intFromBool((residual << 1) > bSignificand);
217 // Clear the implicit bit217 // Clear the implicit bit
...@@ -221,7 +221,7 @@ inline fn div(a: f64, b: f64) f64 {...@@ -221,7 +221,7 @@ inline fn div(a: f64, b: f64) f64 {
221 // Round221 // Round
222 absResult +%= round;222 absResult +%= round;
223 // Insert the sign and return223 // Insert the sign and return
224 return @as(f64, @bitCast(absResult | quotientSign));224 return @bitCast(absResult | quotientSign);
225 }225 }
226}226}
227227
lib/compiler_rt/divdf3_test.zig+1-1
...@@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3;...@@ -6,7 +6,7 @@ const __divdf3 = @import("divdf3.zig").__divdf3;
6const testing = @import("std").testing;6const testing = @import("std").testing;
77
8fn compareResultD(result: f64, expected: u64) bool {8fn compareResultD(result: f64, expected: u64) bool {
9 const rep = @as(u64, @bitCast(result));9 const rep: u64 = @bitCast(result);
1010
11 if (rep == expected) {11 if (rep == expected) {
12 return true;12 return true;
lib/compiler_rt/divhf3.zig+1-1
...@@ -7,5 +7,5 @@ comptime {...@@ -7,5 +7,5 @@ comptime {
77
8pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 {8pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 {
9 // TODO: more efficient implementation9 // 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,10 +44,10 @@ inline fn div(a: f32, b: f32) f32 {
44 const absMask = signBit - 1;44 const absMask = signBit - 1;
45 const exponentMask = absMask ^ significandMask;45 const exponentMask = absMask ^ significandMask;
46 const qnanRep = exponentMask | quietBit;46 const qnanRep = exponentMask | quietBit;
47 const infRep = @as(Z, @bitCast(std.math.inf(f32)));47 const infRep: Z = @bitCast(std.math.inf(f32));
4848
49 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));49 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
50 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));50 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
51 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;51 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
5252
53 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;53 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
...@@ -60,36 +60,36 @@ inline fn div(a: f32, b: f32) f32 {...@@ -60,36 +60,36 @@ inline fn div(a: f32, b: f32) f32 {
60 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;60 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
6161
62 // NaN / anything = qNaN62 // 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 // anything / NaN = qNaN64 // 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);
6666
67 if (aAbs == infRep) {67 if (aAbs == infRep) {
68 // infinity / infinity = NaN68 // infinity / infinity = NaN
69 if (bAbs == infRep) {69 if (bAbs == infRep) {
70 return @as(f32, @bitCast(qnanRep));70 return @bitCast(qnanRep);
71 }71 }
72 // infinity / anything else = +/- infinity72 // infinity / anything else = +/- infinity
73 else {73 else {
74 return @as(f32, @bitCast(aAbs | quotientSign));74 return @bitCast(aAbs | quotientSign);
75 }75 }
76 }76 }
7777
78 // anything else / infinity = +/- 078 // anything else / infinity = +/- 0
79 if (bAbs == infRep) return @as(f32, @bitCast(quotientSign));79 if (bAbs == infRep) return @bitCast(quotientSign);
8080
81 if (aAbs == 0) {81 if (aAbs == 0) {
82 // zero / zero = NaN82 // zero / zero = NaN
83 if (bAbs == 0) {83 if (bAbs == 0) {
84 return @as(f32, @bitCast(qnanRep));84 return @bitCast(qnanRep);
85 }85 }
86 // zero / anything else = +/- zero86 // zero / anything else = +/- zero
87 else {87 else {
88 return @as(f32, @bitCast(quotientSign));88 return @bitCast(quotientSign);
89 }89 }
90 }90 }
91 // anything else / zero = +/- infinity91 // anything else / zero = +/- infinity
92 if (bAbs == 0) return @as(f32, @bitCast(infRep | quotientSign));92 if (bAbs == 0) return @bitCast(infRep | quotientSign);
9393
94 // one or both of a or b is denormal, the other (if applicable) is a94 // one or both of a or b is denormal, the other (if applicable) is a
95 // normal number. Renormalize one or both of a and b, and set scale to95 // 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,12 +120,12 @@ inline fn div(a: f32, b: f32) f32 {
120 // with each iteration, so after three iterations, we have about 28 binary120 // with each iteration, so after three iterations, we have about 28 binary
121 // digits of accuracy.121 // digits of accuracy.
122 var correction: u32 = undefined;122 var correction: u32 = undefined;
123 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));123 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
124 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));124 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
125 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));125 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
126 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));126 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
127 correction = @as(u32, @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1));127 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
128 reciprocal = @as(u32, @truncate(@as(u64, reciprocal) *% correction >> 31));128 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
129129
130 // Exhaustive testing shows that the error in reciprocal after three steps130 // Exhaustive testing shows that the error in reciprocal after three steps
131 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our131 // 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,7 +147,7 @@ inline fn div(a: f32, b: f32) f32 {
147 // is the error in the reciprocal of b scaled by the maximum147 // is the error in the reciprocal of b scaled by the maximum
148 // possible value of a. As a consequence of this error bound,148 // possible value of a. As a consequence of this error bound,
149 // either q or nextafter(q) is the correctly rounded149 // 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);
151151
152 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).152 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
153 // In either case, we are going to compute a residual of the form153 // 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,7 +175,7 @@ inline fn div(a: f32, b: f32) f32 {
175175
176 if (writtenExponent >= maxExponent) {176 if (writtenExponent >= maxExponent) {
177 // If we have overflowed the exponent, return infinity.177 // If we have overflowed the exponent, return infinity.
178 return @as(f32, @bitCast(infRep | quotientSign));178 return @bitCast(infRep | quotientSign);
179 } else if (writtenExponent < 1) {179 } else if (writtenExponent < 1) {
180 if (writtenExponent == 0) {180 if (writtenExponent == 0) {
181 // Check whether the rounded result is normal.181 // Check whether the rounded result is normal.
...@@ -186,12 +186,12 @@ inline fn div(a: f32, b: f32) f32 {...@@ -186,12 +186,12 @@ inline fn div(a: f32, b: f32) f32 {
186 absResult += round;186 absResult += round;
187 if ((absResult & ~significandMask) > 0) {187 if ((absResult & ~significandMask) > 0) {
188 // The rounded result is normal; return it.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 // Flush denormals to zero. In the future, it would be nice to add192 // Flush denormals to zero. In the future, it would be nice to add
193 // code to round them correctly.193 // code to round them correctly.
194 return @as(f32, @bitCast(quotientSign));194 return @bitCast(quotientSign);
195 } else {195 } else {
196 const round = @intFromBool((residual << 1) > bSignificand);196 const round = @intFromBool((residual << 1) > bSignificand);
197 // Clear the implicit bit197 // Clear the implicit bit
...@@ -201,7 +201,7 @@ inline fn div(a: f32, b: f32) f32 {...@@ -201,7 +201,7 @@ inline fn div(a: f32, b: f32) f32 {
201 // Round201 // Round
202 absResult +%= round;202 absResult +%= round;
203 // Insert the sign and return203 // Insert the sign and return
204 return @as(f32, @bitCast(absResult | quotientSign));204 return @bitCast(absResult | quotientSign);
205 }205 }
206}206}
207207
lib/compiler_rt/divsf3_test.zig+1-1
...@@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3;...@@ -6,7 +6,7 @@ const __divsf3 = @import("divsf3.zig").__divsf3;
6const testing = @import("std").testing;6const testing = @import("std").testing;
77
8fn compareResultF(result: f32, expected: u32) bool {8fn compareResultF(result: f32, expected: u32) bool {
9 const rep = @as(u32, @bitCast(result));9 const rep: u32 = @bitCast(result);
1010
11 if (rep == expected) {11 if (rep == expected) {
12 return true;12 return true;
lib/compiler_rt/divtf3.zig+29-29
...@@ -41,10 +41,10 @@ inline fn div(a: f128, b: f128) f128 {...@@ -41,10 +41,10 @@ inline fn div(a: f128, b: f128) f128 {
41 const absMask = signBit - 1;41 const absMask = signBit - 1;
42 const exponentMask = absMask ^ significandMask;42 const exponentMask = absMask ^ significandMask;
43 const qnanRep = exponentMask | quietBit;43 const qnanRep = exponentMask | quietBit;
44 const infRep = @as(Z, @bitCast(std.math.inf(f128)));44 const infRep: Z = @bitCast(std.math.inf(f128));
4545
46 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));46 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
47 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));47 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
48 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;48 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
4949
50 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;50 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
...@@ -57,36 +57,36 @@ inline fn div(a: f128, b: f128) f128 {...@@ -57,36 +57,36 @@ inline fn div(a: f128, b: f128) f128 {
57 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;57 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
5858
59 // NaN / anything = qNaN59 // 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 // anything / NaN = qNaN61 // 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);
6363
64 if (aAbs == infRep) {64 if (aAbs == infRep) {
65 // infinity / infinity = NaN65 // infinity / infinity = NaN
66 if (bAbs == infRep) {66 if (bAbs == infRep) {
67 return @as(f128, @bitCast(qnanRep));67 return @bitCast(qnanRep);
68 }68 }
69 // infinity / anything else = +/- infinity69 // infinity / anything else = +/- infinity
70 else {70 else {
71 return @as(f128, @bitCast(aAbs | quotientSign));71 return @bitCast(aAbs | quotientSign);
72 }72 }
73 }73 }
7474
75 // anything else / infinity = +/- 075 // anything else / infinity = +/- 0
76 if (bAbs == infRep) return @as(f128, @bitCast(quotientSign));76 if (bAbs == infRep) return @bitCast(quotientSign);
7777
78 if (aAbs == 0) {78 if (aAbs == 0) {
79 // zero / zero = NaN79 // zero / zero = NaN
80 if (bAbs == 0) {80 if (bAbs == 0) {
81 return @as(f128, @bitCast(qnanRep));81 return @bitCast(qnanRep);
82 }82 }
83 // zero / anything else = +/- zero83 // zero / anything else = +/- zero
84 else {84 else {
85 return @as(f128, @bitCast(quotientSign));85 return @bitCast(quotientSign);
86 }86 }
87 }87 }
88 // anything else / zero = +/- infinity88 // anything else / zero = +/- infinity
89 if (bAbs == 0) return @as(f128, @bitCast(infRep | quotientSign));89 if (bAbs == 0) return @bitCast(infRep | quotientSign);
9090
91 // one or both of a or b is denormal, the other (if applicable) is a91 // one or both of a or b is denormal, the other (if applicable) is a
92 // normal number. Renormalize one or both of a and b, and set scale to92 // 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,7 +106,7 @@ inline fn div(a: f128, b: f128) f128 {
106 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax106 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
107 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This107 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
108 // is accurate to about 3.5 binary digits.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 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;110 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
111 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)111 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
112112
...@@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 {...@@ -117,16 +117,16 @@ inline fn div(a: f128, b: f128) f128 {
117 // This doubles the number of correct binary digits in the approximation117 // This doubles the number of correct binary digits in the approximation
118 // with each iteration.118 // with each iteration.
119 var correction64: u64 = undefined;119 var correction64: u64 = undefined;
120 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));120 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
121 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));121 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
122 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));122 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
123 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));123 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
124 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));124 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
125 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));125 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
126 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));126 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
127 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));127 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
128 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));128 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
129 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));129 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
130130
131 // The reciprocal may have overflowed to zero if the upper half of b is131 // The reciprocal may have overflowed to zero if the upper half of b is
132 // exactly 1.0. This would sabatoge the full-width final stage of the132 // 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,7 +135,7 @@ inline fn div(a: f128, b: f128) f128 {
135135
136 // We need to perform one more iteration to get us to 112 binary digits;136 // We need to perform one more iteration to get us to 112 binary digits;
137 // The last iteration needs to happen with extra precision.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 var correction: u128 = undefined;139 var correction: u128 = undefined;
140 var reciprocal: u128 = undefined;140 var reciprocal: u128 = undefined;
141141
...@@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 {...@@ -151,8 +151,8 @@ inline fn div(a: f128, b: f128) f128 {
151151
152 correction = -%(r64q63 + (r64q127 >> 64));152 correction = -%(r64q63 + (r64q127 >> 64));
153153
154 const cHi = @as(u64, @truncate(correction >> 64));154 const cHi: u64 = @truncate(correction >> 64);
155 const cLo = @as(u64, @truncate(correction));155 const cLo: u64 = @truncate(correction);
156156
157 wideMultiply(u128, recip64, cHi, &dummy, &r64cH);157 wideMultiply(u128, recip64, cHi, &dummy, &r64cH);
158 wideMultiply(u128, recip64, cLo, &dummy, &r64cL);158 wideMultiply(u128, recip64, cLo, &dummy, &r64cL);
...@@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 {...@@ -210,7 +210,7 @@ inline fn div(a: f128, b: f128) f128 {
210210
211 if (writtenExponent >= maxExponent) {211 if (writtenExponent >= maxExponent) {
212 // If we have overflowed the exponent, return infinity.212 // If we have overflowed the exponent, return infinity.
213 return @as(f128, @bitCast(infRep | quotientSign));213 return @bitCast(infRep | quotientSign);
214 } else if (writtenExponent < 1) {214 } else if (writtenExponent < 1) {
215 if (writtenExponent == 0) {215 if (writtenExponent == 0) {
216 // Check whether the rounded result is normal.216 // Check whether the rounded result is normal.
...@@ -221,12 +221,12 @@ inline fn div(a: f128, b: f128) f128 {...@@ -221,12 +221,12 @@ inline fn div(a: f128, b: f128) f128 {
221 absResult += round;221 absResult += round;
222 if ((absResult & ~significandMask) > 0) {222 if ((absResult & ~significandMask) > 0) {
223 // The rounded result is normal; return it.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 // Flush denormals to zero. In the future, it would be nice to add227 // Flush denormals to zero. In the future, it would be nice to add
228 // code to round them correctly.228 // code to round them correctly.
229 return @as(f128, @bitCast(quotientSign));229 return @bitCast(quotientSign);
230 } else {230 } else {
231 const round = @intFromBool((residual << 1) >= bSignificand);231 const round = @intFromBool((residual << 1) >= bSignificand);
232 // Clear the implicit bit232 // Clear the implicit bit
...@@ -236,7 +236,7 @@ inline fn div(a: f128, b: f128) f128 {...@@ -236,7 +236,7 @@ inline fn div(a: f128, b: f128) f128 {
236 // Round236 // Round
237 absResult +%= round;237 absResult +%= round;
238 // Insert the sign and return238 // Insert the sign and return
239 return @as(f128, @bitCast(absResult | quotientSign));239 return @bitCast(absResult | quotientSign);
240 }240 }
241}241}
242242
lib/compiler_rt/divtf3_test.zig+3-3
...@@ -5,9 +5,9 @@ const testing = std.testing;...@@ -5,9 +5,9 @@ const testing = std.testing;
5const __divtf3 = @import("divtf3.zig").__divtf3;5const __divtf3 = @import("divtf3.zig").__divtf3;
66
7fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {7fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
8 const rep = @as(u128, @bitCast(result));8 const rep: u128 = @bitCast(result);
9 const hi = @as(u64, @truncate(rep >> 64));9 const hi: u64 = @truncate(rep >> 64);
10 const lo = @as(u64, @truncate(rep));10 const lo: u64 = @truncate(rep);
1111
12 if (hi == expectedHi and lo == expectedLo) {12 if (hi == expectedHi and lo == expectedLo) {
13 return true;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,10 +30,10 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
3030
31 const absMask = signBit - 1;31 const absMask = signBit - 1;
32 const qnanRep = @as(Z, @bitCast(std.math.nan(T))) | quietBit;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));
3434
35 const aExponent = @as(u32, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));35 const aExponent: u32 = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
36 const bExponent = @as(u32, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));36 const bExponent: u32 = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
37 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;37 const quotientSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit;
3838
39 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;39 var aSignificand: Z = @as(Z, @bitCast(a)) & significandMask;
...@@ -46,36 +46,36 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -46,36 +46,36 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
46 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;46 const bAbs: Z = @as(Z, @bitCast(b)) & absMask;
4747
48 // NaN / anything = qNaN48 // 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 // anything / NaN = qNaN50 // 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);
5252
53 if (aAbs == infRep) {53 if (aAbs == infRep) {
54 // infinity / infinity = NaN54 // infinity / infinity = NaN
55 if (bAbs == infRep) {55 if (bAbs == infRep) {
56 return @as(T, @bitCast(qnanRep));56 return @bitCast(qnanRep);
57 }57 }
58 // infinity / anything else = +/- infinity58 // infinity / anything else = +/- infinity
59 else {59 else {
60 return @as(T, @bitCast(aAbs | quotientSign));60 return @bitCast(aAbs | quotientSign);
61 }61 }
62 }62 }
6363
64 // anything else / infinity = +/- 064 // anything else / infinity = +/- 0
65 if (bAbs == infRep) return @as(T, @bitCast(quotientSign));65 if (bAbs == infRep) return @bitCast(quotientSign);
6666
67 if (aAbs == 0) {67 if (aAbs == 0) {
68 // zero / zero = NaN68 // zero / zero = NaN
69 if (bAbs == 0) {69 if (bAbs == 0) {
70 return @as(T, @bitCast(qnanRep));70 return @bitCast(qnanRep);
71 }71 }
72 // zero / anything else = +/- zero72 // zero / anything else = +/- zero
73 else {73 else {
74 return @as(T, @bitCast(quotientSign));74 return @bitCast(quotientSign);
75 }75 }
76 }76 }
77 // anything else / zero = +/- infinity77 // anything else / zero = +/- infinity
78 if (bAbs == 0) return @as(T, @bitCast(infRep | quotientSign));78 if (bAbs == 0) return @bitCast(infRep | quotientSign);
7979
80 // one or both of a or b is denormal, the other (if applicable) is a80 // one or both of a or b is denormal, the other (if applicable) is a
81 // normal number. Renormalize one or both of a and b, and set scale to81 // 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,7 +89,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
89 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax89 // [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
90 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This90 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
91 // is accurate to about 3.5 binary digits.91 // is accurate to about 3.5 binary digits.
92 const q63b = @as(u64, @intCast(bSignificand));92 const q63b: u64 = @intCast(bSignificand);
93 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;93 var recip64 = @as(u64, 0x7504f333F9DE6484) -% q63b;
94 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)94 // 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
9595
...@@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -100,16 +100,16 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
100 // This doubles the number of correct binary digits in the approximation100 // This doubles the number of correct binary digits in the approximation
101 // with each iteration.101 // with each iteration.
102 var correction64: u64 = undefined;102 var correction64: u64 = undefined;
103 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));103 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
104 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));104 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
105 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));105 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
106 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));106 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
107 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));107 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
108 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));108 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
109 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));109 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
110 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));110 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
111 correction64 = @as(u64, @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1));111 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
112 recip64 = @as(u64, @truncate(@as(u128, recip64) *% correction64 >> 63));112 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
113113
114 // The reciprocal may have overflowed to zero if the upper half of b is114 // The reciprocal may have overflowed to zero if the upper half of b is
115 // exactly 1.0. This would sabatoge the full-width final stage of the115 // 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,8 +128,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
128128
129 correction = -%correction;129 correction = -%correction;
130130
131 const cHi = @as(u64, @truncate(correction >> 64));131 const cHi: u64 = @truncate(correction >> 64);
132 const cLo = @as(u64, @truncate(correction));132 const cLo: u64 = @truncate(correction);
133133
134 var r64cH: u128 = undefined;134 var r64cH: u128 = undefined;
135 var r64cL: u128 = undefined;135 var r64cL: u128 = undefined;
lib/compiler_rt/divxf3_test.zig+3-3
...@@ -5,7 +5,7 @@ const testing = std.testing;...@@ -5,7 +5,7 @@ const testing = std.testing;
5const __divxf3 = @import("divxf3.zig").__divxf3;5const __divxf3 = @import("divxf3.zig").__divxf3;
66
7fn compareResult(result: f80, expected: u80) bool {7fn compareResult(result: f80, expected: u80) bool {
8 const rep = @as(u80, @bitCast(result));8 const rep: u80 = @bitCast(result);
99
10 if (rep == expected) return true;10 if (rep == expected) return true;
11 // test other possible NaN representations (signal NaN)11 // test other possible NaN representations (signal NaN)
...@@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void {...@@ -25,9 +25,9 @@ fn test__divxf3(a: f80, b: f80) !void {
25 const x = __divxf3(a, b);25 const x = __divxf3(a, b);
2626
27 // Next float (assuming normal, non-zero result)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 // Prev float (assuming normal, non-zero result)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);
3131
32 // Make sure result is more accurate than the adjacent floats32 // Make sure result is more accurate than the adjacent floats
33 const err_x = @fabs(@mulAdd(f80, x, b, -a));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,7 +125,7 @@ const ObjectArray = struct {
125 if (self.slots[index] == null) {125 if (self.slots[index] == null) {
126 // initialize the slot126 // initialize the slot
127 const size = control.size;127 const size = control.size;
128 const alignment = @as(u29, @truncate(control.alignment));128 const alignment: u29 = @truncate(control.alignment);
129129
130 var data = simple_allocator.advancedAlloc(alignment, size);130 var data = simple_allocator.advancedAlloc(alignment, size);
131 errdefer simple_allocator.free(data);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,8 +39,8 @@ pub fn expf(x_: f32) callconv(.C) f32 {
39 const P2 = -2.7667332906e-3;39 const P2 = -2.7667332906e-3;
4040
41 var x = x_;41 var x = x_;
42 var hx = @as(u32, @bitCast(x));42 var hx: u32 = @bitCast(x);
43 const sign = @as(i32, @intCast(hx >> 31));43 const sign: i32 = @intCast(hx >> 31);
44 hx &= 0x7FFFFFFF;44 hx &= 0x7FFFFFFF;
4545
46 if (math.isNan(x)) {46 if (math.isNan(x)) {
...@@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 {...@@ -74,12 +74,12 @@ pub fn expf(x_: f32) callconv(.C) f32 {
74 if (hx > 0x3EB17218) {74 if (hx > 0x3EB17218) {
75 // |x| > 1.5 * ln275 // |x| > 1.5 * ln2
76 if (hx > 0x3F851592) {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 } else {78 } else {
79 k = 1 - sign - sign;79 k = 1 - sign - sign;
80 }80 }
8181
82 const fk = @as(f32, @floatFromInt(k));82 const fk: f32 = @floatFromInt(k);
83 hi = x - fk * ln2hi;83 hi = x - fk * ln2hi;
84 lo = fk * ln2lo;84 lo = fk * ln2lo;
85 x = hi - lo;85 x = hi - lo;
...@@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -117,9 +117,9 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117 const P5: f64 = 4.13813679705723846039e-08;117 const P5: f64 = 4.13813679705723846039e-08;
118118
119 var x = x_;119 var x = x_;
120 var ux = @as(u64, @bitCast(x));120 var ux: u64 = @bitCast(x);
121 var hx = ux >> 32;121 var hx = ux >> 32;
122 const sign = @as(i32, @intCast(hx >> 31));122 const sign: i32 = @intCast(hx >> 31);
123 hx &= 0x7FFFFFFF;123 hx &= 0x7FFFFFFF;
124124
125 if (math.isNan(x)) {125 if (math.isNan(x)) {
...@@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -157,12 +157,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
157 if (hx > 0x3FD62E42) {157 if (hx > 0x3FD62E42) {
158 // |x| >= 1.5 * ln2158 // |x| >= 1.5 * ln2
159 if (hx > 0x3FF0A2B2) {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 } else {161 } else {
162 k = 1 - sign - sign;162 k = 1 - sign - sign;
163 }163 }
164164
165 const dk = @as(f64, @floatFromInt(k));165 const dk: f64 = @floatFromInt(k);
166 hi = x - dk * ln2hi;166 hi = x - dk * ln2hi;
167 lo = dk * ln2lo;167 lo = dk * ln2lo;
168 x = hi - lo;168 x = hi - lo;
...@@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -191,12 +191,12 @@ pub fn exp(x_: f64) callconv(.C) f64 {
191191
192pub fn __expx(a: f80) callconv(.C) f80 {192pub fn __expx(a: f80) callconv(.C) f80 {
193 // TODO: more efficient implementation193 // TODO: more efficient implementation
194 return @as(f80, @floatCast(expq(a)));194 return @floatCast(expq(a));
195}195}
196196
197pub fn expq(a: f128) callconv(.C) f128 {197pub fn expq(a: f128) callconv(.C) f128 {
198 // TODO: more correct implementation198 // TODO: more correct implementation
199 return exp(@as(f64, @floatCast(a)));199 return exp(@floatCast(a));
200}200}
201201
202pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {202pub 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,14 +31,14 @@ pub fn __exp2h(x: f16) callconv(.C) f16 {
31}31}
3232
33pub fn exp2f(x: f32) callconv(.C) f32 {33pub fn exp2f(x: f32) callconv(.C) f32 {
34 const tblsiz = @as(u32, @intCast(exp2ft.len));34 const tblsiz: u32 = @intCast(exp2ft.len);
35 const redux: f32 = 0x1.8p23 / @as(f32, @floatFromInt(tblsiz));35 const redux: f32 = 0x1.8p23 / @as(f32, @floatFromInt(tblsiz));
36 const P1: f32 = 0x1.62e430p-1;36 const P1: f32 = 0x1.62e430p-1;
37 const P2: f32 = 0x1.ebfbe0p-3;37 const P2: f32 = 0x1.ebfbe0p-3;
38 const P3: f32 = 0x1.c6b348p-5;38 const P3: f32 = 0x1.c6b348p-5;
39 const P4: f32 = 0x1.3b2c9cp-7;39 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u = @as(u32, @bitCast(x));41 var u: u32 = @bitCast(x);
42 const ix = u & 0x7FFFFFFF;42 const ix = u & 0x7FFFFFFF;
4343
44 // |x| > 12644 // |x| > 126
...@@ -72,11 +72,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 {...@@ -72,11 +72,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
72 // intended result but should confirm how GCC/Clang handle this to ensure.72 // intended result but should confirm how GCC/Clang handle this to ensure.
7373
74 var uf = x + redux;74 var uf = x + redux;
75 var i_0 = @as(u32, @bitCast(uf));75 var i_0: u32 = @bitCast(uf);
76 i_0 +%= tblsiz / 2;76 i_0 +%= tblsiz / 2;
7777
78 const k = i_0 / tblsiz;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 i_0 &= tblsiz - 1;80 i_0 &= tblsiz - 1;
81 uf -= redux;81 uf -= redux;
8282
...@@ -84,11 +84,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 {...@@ -84,11 +84,11 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
84 var r: f64 = exp2ft[@as(usize, @intCast(i_0))];84 var r: f64 = exp2ft[@as(usize, @intCast(i_0))];
85 const t: f64 = r * z;85 const t: f64 = r * z;
86 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);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}
8989
90pub fn exp2(x: f64) callconv(.C) f64 {90pub 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 const redux: f64 = 0x1.8p52 / @as(f64, @floatFromInt(tblsiz));92 const redux: f64 = 0x1.8p52 / @as(f64, @floatFromInt(tblsiz));
93 const P1: f64 = 0x1.62e42fefa39efp-1;93 const P1: f64 = 0x1.62e42fefa39efp-1;
94 const P2: f64 = 0x1.ebfbdff82c575p-3;94 const P2: f64 = 0x1.ebfbdff82c575p-3;
...@@ -96,7 +96,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {...@@ -96,7 +96,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
96 const P4: f64 = 0x1.3b2ab88f70400p-7;96 const P4: f64 = 0x1.3b2ab88f70400p-7;
97 const P5: f64 = 0x1.5d88003875c74p-10;97 const P5: f64 = 0x1.5d88003875c74p-10;
9898
99 const ux = @as(u64, @bitCast(x));99 const ux: u64 = @bitCast(x);
100 const ix = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;100 const ix = @as(u32, @intCast(ux >> 32)) & 0x7FFFFFFF;
101101
102 // TODO: This should be handled beneath.102 // TODO: This should be handled beneath.
...@@ -139,7 +139,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {...@@ -139,7 +139,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
139 // reduce x139 // reduce x
140 var uf: f64 = x + redux;140 var uf: f64 = x + redux;
141 // NOTE: musl performs an implicit 64-bit to 32-bit u32 truncation here141 // 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 i_0 +%= tblsiz / 2;143 i_0 +%= tblsiz / 2;
144144
145 const k: u32 = i_0 / tblsiz * tblsiz;145 const k: u32 = i_0 / tblsiz * tblsiz;
...@@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 {...@@ -158,12 +158,12 @@ pub fn exp2(x: f64) callconv(.C) f64 {
158158
159pub fn __exp2x(x: f80) callconv(.C) f80 {159pub fn __exp2x(x: f80) callconv(.C) f80 {
160 // TODO: more efficient implementation160 // TODO: more efficient implementation
161 return @as(f80, @floatCast(exp2q(x)));161 return @floatCast(exp2q(x));
162}162}
163163
164pub fn exp2q(x: f128) callconv(.C) f128 {164pub fn exp2q(x: f128) callconv(.C) f128 {
165 // TODO: more correct implementation165 // TODO: more correct implementation
166 return exp2(@as(f64, @floatCast(x)));166 return exp2(@floatCast(x));
167}167}
168168
169pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {169pub 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,7 +33,7 @@ pub inline fn extendf(
33 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;33 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;
3434
35 // Break a into a sign and representation of the absolute value35 // 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 const aAbs: src_rep_t = aRep & srcAbsMask;37 const aAbs: src_rep_t = aRep & srcAbsMask;
38 const sign: src_rep_t = aRep & srcSignMask;38 const sign: src_rep_t = aRep & srcSignMask;
39 var absResult: dst_rep_t = undefined;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,7 +104,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
104 // a is a normal number.104 // a is a normal number.
105 // Extend to the destination type by shifting the significand and105 // Extend to the destination type by shifting the significand and
106 // exponent into the proper position and rebiasing the exponent.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 dst.exp += dst_exp_bias - src_exp_bias;108 dst.exp += dst_exp_bias - src_exp_bias;
109 dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits);109 dst.fraction = @as(u64, a_abs) << (dst_sig_bits - src_sig_bits);
110 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers110 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,7 +126,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
126126
127 dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale));127 dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale));
128 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers128 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 dst.exp ^= 1;130 dst.exp ^= 1;
131 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;131 dst.exp |= dst_exp_bias - src_exp_bias - scale + 1;
132 } else {132 } else {
lib/compiler_rt/extendf_test.zig+17-17
...@@ -11,7 +11,7 @@ const F16T = @import("./common.zig").F16T;...@@ -11,7 +11,7 @@ const F16T = @import("./common.zig").F16T;
11fn test__extenddfxf2(a: f64, expected: u80) !void {11fn test__extenddfxf2(a: f64, expected: u80) !void {
12 const x = __extenddfxf2(a);12 const x = __extenddfxf2(a);
1313
14 const rep = @as(u80, @bitCast(x));14 const rep: u80 = @bitCast(x);
15 if (rep == expected)15 if (rep == expected)
16 return;16 return;
1717
...@@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void {...@@ -25,9 +25,9 @@ fn test__extenddfxf2(a: f64, expected: u80) !void {
25fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {25fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
26 const x = __extenddftf2(a);26 const x = __extenddftf2(a);
2727
28 const rep = @as(u128, @bitCast(x));28 const rep: u128 = @bitCast(x);
29 const hi = @as(u64, @intCast(rep >> 64));29 const hi: u64 = @intCast(rep >> 64);
30 const lo = @as(u64, @truncate(rep));30 const lo: u64 = @truncate(rep);
3131
32 if (hi == expected_hi and lo == expected_lo)32 if (hi == expected_hi and lo == expected_lo)
33 return;33 return;
...@@ -46,7 +46,7 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {...@@ -46,7 +46,7 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
4646
47fn test__extendhfsf2(a: u16, expected: u32) !void {47fn test__extendhfsf2(a: u16, expected: u32) !void {
48 const x = __extendhfsf2(@as(F16T(f32), @bitCast(a)));48 const x = __extendhfsf2(@as(F16T(f32), @bitCast(a)));
49 const rep = @as(u32, @bitCast(x));49 const rep: u32 = @bitCast(x);
5050
51 if (rep == expected) {51 if (rep == expected) {
52 if (rep & 0x7fffffff > 0x7f800000) {52 if (rep & 0x7fffffff > 0x7f800000) {
...@@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void {...@@ -63,9 +63,9 @@ fn test__extendhfsf2(a: u16, expected: u32) !void {
63fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void {63fn test__extendsftf2(a: f32, expected_hi: u64, expected_lo: u64) !void {
64 const x = __extendsftf2(a);64 const x = __extendsftf2(a);
6565
66 const rep = @as(u128, @bitCast(x));66 const rep: u128 = @bitCast(x);
67 const hi = @as(u64, @intCast(rep >> 64));67 const hi: u64 = @intCast(rep >> 64);
68 const lo = @as(u64, @truncate(rep));68 const lo: u64 = @truncate(rep);
6969
70 if (hi == expected_hi and lo == expected_lo)70 if (hi == expected_hi and lo == expected_lo)
71 return;71 return;
...@@ -184,35 +184,35 @@ test "extendsftf2" {...@@ -184,35 +184,35 @@ test "extendsftf2" {
184}184}
185185
186fn makeQNaN64() f64 {186fn makeQNaN64() f64 {
187 return @as(f64, @bitCast(@as(u64, 0x7ff8000000000000)));187 return @bitCast(@as(u64, 0x7ff8000000000000));
188}188}
189189
190fn makeInf64() f64 {190fn makeInf64() f64 {
191 return @as(f64, @bitCast(@as(u64, 0x7ff0000000000000)));191 return @bitCast(@as(u64, 0x7ff0000000000000));
192}192}
193193
194fn makeNaN64(rand: u64) f64 {194fn makeNaN64(rand: u64) f64 {
195 return @as(f64, @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff)));195 return @bitCast(0x7ff0000000000000 | (rand & 0xfffffffffffff));
196}196}
197197
198fn makeQNaN32() f32 {198fn makeQNaN32() f32 {
199 return @as(f32, @bitCast(@as(u32, 0x7fc00000)));199 return @bitCast(@as(u32, 0x7fc00000));
200}200}
201201
202fn makeNaN32(rand: u32) f32 {202fn makeNaN32(rand: u32) f32 {
203 return @as(f32, @bitCast(0x7f800000 | (rand & 0x7fffff)));203 return @bitCast(0x7f800000 | (rand & 0x7fffff));
204}204}
205205
206fn makeInf32() f32 {206fn makeInf32() f32 {
207 return @as(f32, @bitCast(@as(u32, 0x7f800000)));207 return @bitCast(@as(u32, 0x7f800000));
208}208}
209209
210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {
211 const x = __extendhftf2(@as(F16T(f128), @bitCast(a)));211 const x = __extendhftf2(@as(F16T(f128), @bitCast(a)));
212212
213 const rep = @as(u128, @bitCast(x));213 const rep: u128 = @bitCast(x);
214 const hi = @as(u64, @intCast(rep >> 64));214 const hi: u64 = @intCast(rep >> 64);
215 const lo = @as(u64, @truncate(rep));215 const lo: u64 = @truncate(rep);
216216
217 if (hi == expected_hi and lo == expected_lo)217 if (hi == expected_hi and lo == expected_lo)
218 return;218 return;
lib/compiler_rt/float_from_int_test.zig+6-6
...@@ -520,9 +520,9 @@ test "floatsitf" {...@@ -520,9 +520,9 @@ test "floatsitf" {
520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {520fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void {
521 const x = __floatunsitf(a);521 const x = __floatunsitf(a);
522522
523 const x_repr = @as(u128, @bitCast(x));523 const x_repr: u128 = @bitCast(x);
524 const x_hi = @as(u64, @intCast(x_repr >> 64));524 const x_hi: u64 = @intCast(x_repr >> 64);
525 const x_lo = @as(u64, @truncate(x_repr));525 const x_lo: u64 = @truncate(x_repr);
526526
527 if (x_hi == expected_hi and x_lo == expected_lo) {527 if (x_hi == expected_hi and x_lo == expected_lo) {
528 return;528 return;
...@@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void {...@@ -552,9 +552,9 @@ fn test__floatditf(a: i64, expected: f128) !void {
552fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {552fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
553 const x = __floatunditf(a);553 const x = __floatunditf(a);
554554
555 const x_repr = @as(u128, @bitCast(x));555 const x_repr: u128 = @bitCast(x);
556 const x_hi = @as(u64, @intCast(x_repr >> 64));556 const x_hi: u64 = @intCast(x_repr >> 64);
557 const x_lo = @as(u64, @truncate(x_repr));557 const x_lo: u64 = @truncate(x_repr);
558558
559 if (x_hi == expected_hi and x_lo == expected_lo) {559 if (x_hi == expected_hi and x_lo == expected_lo) {
560 return;560 return;
lib/compiler_rt/floor.zig+2-2
...@@ -26,7 +26,7 @@ comptime {...@@ -26,7 +26,7 @@ comptime {
26}26}
2727
28pub fn __floorh(x: f16) callconv(.C) f16 {28pub fn __floorh(x: f16) callconv(.C) f16 {
29 var u = @as(u16, @bitCast(x));29 var u: u16 = @bitCast(x);
30 const e = @as(i16, @intCast((u >> 10) & 31)) - 15;30 const e = @as(i16, @intCast((u >> 10) & 31)) - 15;
31 var m: u16 = undefined;31 var m: u16 = undefined;
3232
...@@ -132,7 +132,7 @@ pub fn __floorx(x: f80) callconv(.C) f80 {...@@ -132,7 +132,7 @@ pub fn __floorx(x: f80) callconv(.C) f80 {
132pub fn floorq(x: f128) callconv(.C) f128 {132pub fn floorq(x: f128) callconv(.C) f128 {
133 const f128_toint = 1.0 / math.floatEps(f128);133 const f128_toint = 1.0 / math.floatEps(f128);
134134
135 const u = @as(u128, @bitCast(x));135 const u: u128 = @bitCast(x);
136 const e = (u >> 112) & 0x7FFF;136 const e = (u >> 112) & 0x7FFF;
137 var y: f128 = undefined;137 var y: f128 = undefined;
138138
lib/compiler_rt/fmod.zig+15-15
...@@ -22,7 +22,7 @@ comptime {...@@ -22,7 +22,7 @@ comptime {
2222
23pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {23pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
24 // TODO: more efficient implementation24 // TODO: more efficient implementation
25 return @as(f16, @floatCast(fmodf(x, y)));25 return @floatCast(fmodf(x, y));
26}26}
2727
28pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {28pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {
...@@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -46,12 +46,12 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
46 const signBit = (@as(Z, 1) << (significandBits + exponentBits));46 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
47 const maxExponent = ((1 << exponentBits) - 1);47 const maxExponent = ((1 << exponentBits) - 1);
4848
49 var aRep = @as(Z, @bitCast(a));49 var aRep: Z = @bitCast(a);
50 var bRep = @as(Z, @bitCast(b));50 var bRep: Z = @bitCast(b);
5151
52 const signA = aRep & signBit;52 const signA = aRep & signBit;
53 var expA = @as(i32, @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent));53 var expA: i32 = @intCast((@as(Z, @bitCast(a)) >> significandBits) & maxExponent);
54 var expB = @as(i32, @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent));54 var expB: i32 = @intCast((@as(Z, @bitCast(b)) >> significandBits) & maxExponent);
5555
56 // There are 3 cases where the answer is undefined, check for:56 // There are 3 cases where the answer is undefined, check for:
57 // - fmodx(val, 0)57 // - fmodx(val, 0)
...@@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -123,11 +123,11 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
123123
124 // Combine the exponent with the sign and significand, normalize if happened to be denormalized124 // Combine the exponent with the sign and significand, normalize if happened to be denormalized
125 if (expA < -fractionalBits) {125 if (expA < -fractionalBits) {
126 return @as(T, @bitCast(signA));126 return @bitCast(signA);
127 } else if (expA <= 0) {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 } else {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}
133133
...@@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -155,8 +155,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
155 };155 };
156156
157 const signA = aPtr_u16[exp_and_sign_index] & 0x8000;157 const signA = aPtr_u16[exp_and_sign_index] & 0x8000;
158 var expA = @as(i32, @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff)));158 var expA: i32 = @intCast((aPtr_u16[exp_and_sign_index] & 0x7fff));
159 var expB = @as(i32, @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff)));159 var expB: i32 = @intCast((bPtr_u16[exp_and_sign_index] & 0x7fff));
160160
161 // There are 3 cases where the answer is undefined, check for:161 // There are 3 cases where the answer is undefined, check for:
162 // - fmodq(val, 0)162 // - fmodq(val, 0)
...@@ -270,10 +270,10 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -270,10 +270,10 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
270 const exp_bits = if (T == f32) 9 else 12;270 const exp_bits = if (T == f32) 9 else 12;
271 const bits_minus_1 = bits - 1;271 const bits_minus_1 = bits - 1;
272 const mask = if (T == f32) 0xff else 0x7ff;272 const mask = if (T == f32) 0xff else 0x7ff;
273 var ux = @as(uint, @bitCast(x));273 var ux: uint = @bitCast(x);
274 var uy = @as(uint, @bitCast(y));274 var uy: uint = @bitCast(y);
275 var ex = @as(i32, @intCast((ux >> digits) & mask));275 var ex: i32 = @intCast((ux >> digits) & mask);
276 var ey = @as(i32, @intCast((uy >> digits) & mask));276 var ey: i32 = @intCast((uy >> digits) & mask);
277 const sx = if (T == f32) @as(u32, @intCast(ux & 0x80000000)) else @as(i32, @intCast(ux >> bits_minus_1));277 const sx = if (T == f32) @as(u32, @intCast(ux & 0x80000000)) else @as(i32, @intCast(ux >> bits_minus_1));
278 var i: uint = undefined;278 var i: uint = undefined;
279279
...@@ -343,7 +343,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -343,7 +343,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T {
343 } else {343 } else {
344 ux |= @as(uint, @intCast(sx)) << bits_minus_1;344 ux |= @as(uint, @intCast(sx)) << bits_minus_1;
345 }345 }
346 return @as(T, @bitCast(ux));346 return @bitCast(ux);
347}347}
348348
349test "fmodf" {349test "fmodf" {
lib/compiler_rt/log.zig+12-12
...@@ -27,7 +27,7 @@ comptime {...@@ -27,7 +27,7 @@ comptime {
2727
28pub fn __logh(a: f16) callconv(.C) f16 {28pub fn __logh(a: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @as(f16, @floatCast(logf(a)));30 return @floatCast(logf(a));
31}31}
3232
33pub fn logf(x_: f32) callconv(.C) f32 {33pub fn logf(x_: f32) callconv(.C) f32 {
...@@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -39,7 +39,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
39 const Lg4: f32 = 0xf89e26.0p-26;39 const Lg4: f32 = 0xf89e26.0p-26;
4040
41 var x = x_;41 var x = x_;
42 var ix = @as(u32, @bitCast(x));42 var ix: u32 = @bitCast(x);
43 var k: i32 = 0;43 var k: i32 = 0;
4444
45 // x < 2^(-126)45 // x < 2^(-126)
...@@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -56,7 +56,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
56 // subnormal, scale x56 // subnormal, scale x
57 k -= 25;57 k -= 25;
58 x *= 0x1.0p25;58 x *= 0x1.0p25;
59 ix = @as(u32, @bitCast(x));59 ix = @bitCast(x);
60 } else if (ix >= 0x7F800000) {60 } else if (ix >= 0x7F800000) {
61 return x;61 return x;
62 } else if (ix == 0x3F800000) {62 } else if (ix == 0x3F800000) {
...@@ -67,7 +67,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -67,7 +67,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
67 ix += 0x3F800000 - 0x3F3504F3;67 ix += 0x3F800000 - 0x3F3504F3;
68 k += @as(i32, @intCast(ix >> 23)) - 0x7F;68 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
69 ix = (ix & 0x007FFFFF) + 0x3F3504F3;69 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
70 x = @as(f32, @bitCast(ix));70 x = @bitCast(ix);
7171
72 const f = x - 1.0;72 const f = x - 1.0;
73 const s = f / (2.0 + f);73 const s = f / (2.0 + f);
...@@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {...@@ -77,7 +77,7 @@ pub fn logf(x_: f32) callconv(.C) f32 {
77 const t2 = z * (Lg1 + w * Lg3);77 const t2 = z * (Lg1 + w * Lg3);
78 const R = t2 + t1;78 const R = t2 + t1;
79 const hfsq = 0.5 * f * f;79 const hfsq = 0.5 * f * f;
80 const dk = @as(f32, @floatFromInt(k));80 const dk: f32 = @floatFromInt(k);
8181
82 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;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,8 +94,8 @@ pub fn log(x_: f64) callconv(.C) f64 {
94 const Lg7: f64 = 1.479819860511658591e-01;94 const Lg7: f64 = 1.479819860511658591e-01;
9595
96 var x = x_;96 var x = x_;
97 var ix = @as(u64, @bitCast(x));97 var ix: u64 = @bitCast(x);
98 var hx = @as(u32, @intCast(ix >> 32));98 var hx: u32 = @intCast(ix >> 32);
99 var k: i32 = 0;99 var k: i32 = 0;
100100
101 if (hx < 0x00100000 or hx >> 31 != 0) {101 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -111,7 +111,7 @@ pub fn log(x_: f64) callconv(.C) f64 {
111 // subnormal, scale x111 // subnormal, scale x
112 k -= 54;112 k -= 54;
113 x *= 0x1.0p54;113 x *= 0x1.0p54;
114 hx = @as(u32, @intCast(@as(u64, @bitCast(ix)) >> 32));114 hx = @intCast(@as(u64, @bitCast(ix)) >> 32);
115 } else if (hx >= 0x7FF00000) {115 } else if (hx >= 0x7FF00000) {
116 return x;116 return x;
117 } else if (hx == 0x3FF00000 and ix << 32 == 0) {117 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -123,7 +123,7 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -123,7 +123,7 @@ pub fn log(x_: f64) callconv(.C) f64 {
123 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;123 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
124 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;124 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
125 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);125 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
126 x = @as(f64, @bitCast(ix));126 x = @bitCast(ix);
127127
128 const f = x - 1.0;128 const f = x - 1.0;
129 const hfsq = 0.5 * f * f;129 const hfsq = 0.5 * f * f;
...@@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 {...@@ -133,19 +133,19 @@ pub fn log(x_: f64) callconv(.C) f64 {
133 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));133 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
134 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));134 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
135 const R = t2 + t1;135 const R = t2 + t1;
136 const dk = @as(f64, @floatFromInt(k));136 const dk: f64 = @floatFromInt(k);
137137
138 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;138 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
139}139}
140140
141pub fn __logx(a: f80) callconv(.C) f80 {141pub fn __logx(a: f80) callconv(.C) f80 {
142 // TODO: more efficient implementation142 // TODO: more efficient implementation
143 return @as(f80, @floatCast(logq(a)));143 return @floatCast(logq(a));
144}144}
145145
146pub fn logq(a: f128) callconv(.C) f128 {146pub fn logq(a: f128) callconv(.C) f128 {
147 // TODO: more correct implementation147 // TODO: more correct implementation
148 return log(@as(f64, @floatCast(a)));148 return log(@floatCast(a));
149}149}
150150
151pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {151pub 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,11 +82,11 @@ pub fn log10f(x_: f32) callconv(.C) f32 {
82 const hfsq = 0.5 * f * f;82 const hfsq = 0.5 * f * f;
8383
84 var hi = f - hfsq;84 var hi = f - hfsq;
85 u = @as(u32, @bitCast(hi));85 u = @bitCast(hi);
86 u &= 0xFFFFF000;86 u &= 0xFFFFF000;
87 hi = @as(f32, @bitCast(u));87 hi = @bitCast(u);
88 const lo = f - hi - hfsq + s * (hfsq + R);88 const lo = f - hi - hfsq + s * (hfsq + R);
89 const dk = @as(f32, @floatFromInt(k));89 const dk: f32 = @floatFromInt(k);
9090
91 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;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,8 +105,8 @@ pub fn log10(x_: f64) callconv(.C) f64 {
105 const Lg7: f64 = 1.479819860511658591e-01;105 const Lg7: f64 = 1.479819860511658591e-01;
106106
107 var x = x_;107 var x = x_;
108 var ix = @as(u64, @bitCast(x));108 var ix: u64 = @bitCast(x);
109 var hx = @as(u32, @intCast(ix >> 32));109 var hx: u32 = @intCast(ix >> 32);
110 var k: i32 = 0;110 var k: i32 = 0;
111111
112 if (hx < 0x00100000 or hx >> 31 != 0) {112 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -122,7 +122,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {
122 // subnormal, scale x122 // subnormal, scale x
123 k -= 54;123 k -= 54;
124 x *= 0x1.0p54;124 x *= 0x1.0p54;
125 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));125 hx = @intCast(@as(u64, @bitCast(x)) >> 32);
126 } else if (hx >= 0x7FF00000) {126 } else if (hx >= 0x7FF00000) {
127 return x;127 return x;
128 } else if (hx == 0x3FF00000 and ix << 32 == 0) {128 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -134,7 +134,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -134,7 +134,7 @@ pub fn log10(x_: f64) callconv(.C) f64 {
134 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;134 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
135 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;135 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
136 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);136 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
137 x = @as(f64, @bitCast(ix));137 x = @bitCast(ix);
138138
139 const f = x - 1.0;139 const f = x - 1.0;
140 const hfsq = 0.5 * f * f;140 const hfsq = 0.5 * f * f;
...@@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 {...@@ -147,14 +147,14 @@ pub fn log10(x_: f64) callconv(.C) f64 {
147147
148 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)148 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
149 var hi = f - hfsq;149 var hi = f - hfsq;
150 var hii = @as(u64, @bitCast(hi));150 var hii: u64 = @bitCast(hi);
151 hii &= @as(u64, maxInt(u64)) << 32;151 hii &= @as(u64, maxInt(u64)) << 32;
152 hi = @as(f64, @bitCast(hii));152 hi = @bitCast(hii);
153 const lo = f - hi - hfsq + s * (hfsq + R);153 const lo = f - hi - hfsq + s * (hfsq + R);
154154
155 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)155 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)
156 var val_hi = hi * ivln10hi;156 var val_hi = hi * ivln10hi;
157 const dk = @as(f64, @floatFromInt(k));157 const dk: f64 = @floatFromInt(k);
158 const y = dk * log10_2hi;158 const y = dk * log10_2hi;
159 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;159 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;
160160
lib/compiler_rt/log2.zig+14-14
...@@ -28,7 +28,7 @@ comptime {...@@ -28,7 +28,7 @@ comptime {
2828
29pub fn __log2h(a: f16) callconv(.C) f16 {29pub fn __log2h(a: f16) callconv(.C) f16 {
30 // TODO: more efficient implementation30 // TODO: more efficient implementation
31 return @as(f16, @floatCast(log2f(a)));31 return @floatCast(log2f(a));
32}32}
3333
34pub fn log2f(x_: f32) callconv(.C) f32 {34pub fn log2f(x_: f32) callconv(.C) f32 {
...@@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
40 const Lg4: f32 = 0xf89e26.0p-26;40 const Lg4: f32 = 0xf89e26.0p-26;
4141
42 var x = x_;42 var x = x_;
43 var u = @as(u32, @bitCast(x));43 var u: u32 = @bitCast(x);
44 var ix = u;44 var ix = u;
45 var k: i32 = 0;45 var k: i32 = 0;
4646
...@@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
5757
58 k -= 25;58 k -= 25;
59 x *= 0x1.0p25;59 x *= 0x1.0p25;
60 ix = @as(u32, @bitCast(x));60 ix = @bitCast(x);
61 } else if (ix >= 0x7F800000) {61 } else if (ix >= 0x7F800000) {
62 return x;62 return x;
63 } else if (ix == 0x3F800000) {63 } else if (ix == 0x3F800000) {
...@@ -68,7 +68,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -68,7 +68,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
68 ix += 0x3F800000 - 0x3F3504F3;68 ix += 0x3F800000 - 0x3F3504F3;
69 k += @as(i32, @intCast(ix >> 23)) - 0x7F;69 k += @as(i32, @intCast(ix >> 23)) - 0x7F;
70 ix = (ix & 0x007FFFFF) + 0x3F3504F3;70 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
71 x = @as(f32, @bitCast(ix));71 x = @bitCast(ix);
7272
73 const f = x - 1.0;73 const f = x - 1.0;
74 const s = f / (2.0 + f);74 const s = f / (2.0 + f);
...@@ -80,9 +80,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 {...@@ -80,9 +80,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 {
80 const hfsq = 0.5 * f * f;80 const hfsq = 0.5 * f * f;
8181
82 var hi = f - hfsq;82 var hi = f - hfsq;
83 u = @as(u32, @bitCast(hi));83 u = @bitCast(hi);
84 u &= 0xFFFFF000;84 u &= 0xFFFFF000;
85 hi = @as(f32, @bitCast(u));85 hi = @bitCast(u);
86 const lo = f - hi - hfsq + s * (hfsq + R);86 const lo = f - hi - hfsq + s * (hfsq + R);
87 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @as(f32, @floatFromInt(k));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,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 {
99 const Lg7: f64 = 1.479819860511658591e-01;99 const Lg7: f64 = 1.479819860511658591e-01;
100100
101 var x = x_;101 var x = x_;
102 var ix = @as(u64, @bitCast(x));102 var ix: u64 = @bitCast(x);
103 var hx = @as(u32, @intCast(ix >> 32));103 var hx: u32 = @intCast(ix >> 32);
104 var k: i32 = 0;104 var k: i32 = 0;
105105
106 if (hx < 0x00100000 or hx >> 31 != 0) {106 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {
116 // subnormal, scale x116 // subnormal, scale x
117 k -= 54;117 k -= 54;
118 x *= 0x1.0p54;118 x *= 0x1.0p54;
119 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));119 hx = @intCast(@as(u64, @bitCast(x)) >> 32);
120 } else if (hx >= 0x7FF00000) {120 } else if (hx >= 0x7FF00000) {
121 return x;121 return x;
122 } else if (hx == 0x3FF00000 and ix << 32 == 0) {122 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -128,7 +128,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -128,7 +128,7 @@ pub fn log2(x_: f64) callconv(.C) f64 {
128 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;128 k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
129 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;129 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
130 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);130 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
131 x = @as(f64, @bitCast(ix));131 x = @bitCast(ix);
132132
133 const f = x - 1.0;133 const f = x - 1.0;
134 const hfsq = 0.5 * f * f;134 const hfsq = 0.5 * f * f;
...@@ -143,14 +143,14 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -143,14 +143,14 @@ pub fn log2(x_: f64) callconv(.C) f64 {
143 var hi = f - hfsq;143 var hi = f - hfsq;
144 var hii = @as(u64, @bitCast(hi));144 var hii = @as(u64, @bitCast(hi));
145 hii &= @as(u64, maxInt(u64)) << 32;145 hii &= @as(u64, maxInt(u64)) << 32;
146 hi = @as(f64, @bitCast(hii));146 hi = @bitCast(hii);
147 const lo = f - hi - hfsq + s * (hfsq + R);147 const lo = f - hi - hfsq + s * (hfsq + R);
148148
149 var val_hi = hi * ivln2hi;149 var val_hi = hi * ivln2hi;
150 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;150 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;
151151
152 // spadd(val_hi, val_lo, y)152 // spadd(val_hi, val_lo, y)
153 const y = @as(f64, @floatFromInt(k));153 const y: f64 = @floatFromInt(k);
154 const ww = y + val_hi;154 const ww = y + val_hi;
155 val_lo += (y - ww) + val_hi;155 val_lo += (y - ww) + val_hi;
156 val_hi = ww;156 val_hi = ww;
...@@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 {...@@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 {
160160
161pub fn __log2x(a: f80) callconv(.C) f80 {161pub fn __log2x(a: f80) callconv(.C) f80 {
162 // TODO: more efficient implementation162 // TODO: more efficient implementation
163 return @as(f80, @floatCast(log2q(a)));163 return @floatCast(log2q(a));
164}164}
165165
166pub fn log2q(a: f128) callconv(.C) f128 {166pub fn log2q(a: f128) callconv(.C) f128 {
167 // TODO: more correct implementation167 // TODO: more correct implementation
168 return log2(@as(f64, @floatCast(a)));168 return log2(@floatCast(a));
169}169}
170170
171pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {171pub 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,7 +24,7 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
24const v2u64 = @Vector(2, u64);24const v2u64 = @Vector(2, u64);
2525
26fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {26fn __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}
2929
30inline fn mod(a: i128, b: i128) i128 {30inline fn mod(a: i128, b: i128) i128 {
lib/compiler_rt/mulXi3.zig+4-4
...@@ -21,8 +21,8 @@ comptime {...@@ -21,8 +21,8 @@ comptime {
21}21}
2222
23pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {23pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
24 var ua = @as(u32, @bitCast(a));24 var ua: u32 = @bitCast(a);
25 var ub = @as(u32, @bitCast(b));25 var ub: u32 = @bitCast(b);
26 var r: u32 = 0;26 var r: u32 = 0;
2727
28 while (ua > 0) {28 while (ua > 0) {
...@@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {...@@ -31,7 +31,7 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
31 ub <<= 1;31 ub <<= 1;
32 }32 }
3333
34 return @as(i32, @bitCast(r));34 return @bitCast(r);
35}35}
3636
37pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {37pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
...@@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {...@@ -93,7 +93,7 @@ pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
93const v2u64 = @Vector(2, u64);93const v2u64 = @Vector(2, u64);
9494
95fn __multi3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 {95fn __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}
9898
99test {99test {
lib/compiler_rt/mulf3.zig+6-6
...@@ -54,27 +54,27 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {...@@ -54,27 +54,27 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T {
54 if (aAbs == infRep) {54 if (aAbs == infRep) {
55 // infinity * non-zero = +/- infinity55 // infinity * non-zero = +/- infinity
56 if (bAbs != 0) {56 if (bAbs != 0) {
57 return @as(T, @bitCast(aAbs | productSign));57 return @bitCast(aAbs | productSign);
58 } else {58 } else {
59 // infinity * zero = NaN59 // infinity * zero = NaN
60 return @as(T, @bitCast(qnanRep));60 return @bitCast(qnanRep);
61 }61 }
62 }62 }
6363
64 if (bAbs == infRep) {64 if (bAbs == infRep) {
65 //? non-zero * infinity = +/- infinity65 //? non-zero * infinity = +/- infinity
66 if (aAbs != 0) {66 if (aAbs != 0) {
67 return @as(T, @bitCast(bAbs | productSign));67 return @bitCast(bAbs | productSign);
68 } else {68 } else {
69 // zero * infinity = NaN69 // zero * infinity = NaN
70 return @as(T, @bitCast(qnanRep));70 return @bitCast(qnanRep);
71 }71 }
72 }72 }
7373
74 // zero * anything = +/- zero74 // zero * anything = +/- zero
75 if (aAbs == 0) return @as(T, @bitCast(productSign));75 if (aAbs == 0) return @bitCast(productSign);
76 // anything * zero = +/- zero76 // anything * zero = +/- zero
77 if (bAbs == 0) return @as(T, @bitCast(productSign));77 if (bAbs == 0) return @bitCast(productSign);
7878
79 // one or both of a or b is denormal, the other (if applicable) is a79 // one or both of a or b is denormal, the other (if applicable) is a
80 // normal number. Renormalize one or both of a and b, and set scale to80 // 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,8 +4,8 @@
44
5const std = @import("std");5const std = @import("std");
6const math = std.math;6const math = std.math;
7const qnan128 = @as(f128, @bitCast(@as(u128, 0x7fff800000000000) << 64));7const qnan128: f128 = @bitCast(@as(u128, 0x7fff800000000000) << 64);
8const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff000000000000) << 64));8const inf128: f128 = @bitCast(@as(u128, 0x7fff000000000000) << 64);
99
10const __multf3 = @import("multf3.zig").__multf3;10const __multf3 = @import("multf3.zig").__multf3;
11const __mulxf3 = @import("mulxf3.zig").__mulxf3;11const __mulxf3 = @import("mulxf3.zig").__mulxf3;
...@@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3;...@@ -16,9 +16,9 @@ const __mulsf3 = @import("mulsf3.zig").__mulsf3;
16// use two 64-bit integers intead of one 128-bit integer16// use two 64-bit integers intead of one 128-bit integer
17// because 128-bit integer constant can't be assigned directly17// because 128-bit integer constant can't be assigned directly
18fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {18fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
19 const rep = @as(u128, @bitCast(result));19 const rep: u128 = @bitCast(result);
20 const hi = @as(u64, @intCast(rep >> 64));20 const hi: u64 = @intCast(rep >> 64);
21 const lo = @as(u64, @truncate(rep));21 const lo: u64 = @truncate(rep);
2222
23 if (hi == expectedHi and lo == expectedLo) {23 if (hi == expectedHi and lo == expectedLo) {
24 return true;24 return true;
...@@ -45,8 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {...@@ -45,8 +45,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
4545
46fn makeNaN128(rand: u64) f128 {46fn makeNaN128(rand: u64) f128 {
47 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;47 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
48 const float_result = @as(f128, @bitCast(int_result));48 return @bitCast(int_result);
49 return float_result;
50}49}
51test "multf3" {50test "multf3" {
52 // qNaN * any = qNaN51 // qNaN * any = qNaN
...@@ -108,11 +107,11 @@ test "multf3" {...@@ -108,11 +107,11 @@ test "multf3" {
108 try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002);107 try test__multf3(2.0, math.floatTrueMin(f128), 0x0000_0000_0000_0000, 0x0000_0000_0000_0002);
109}108}
110109
111const qnan80 = @as(f80, @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1))));110const qnan80: f80 = @bitCast(@as(u80, @bitCast(math.nan(f80))) | (1 << (math.floatFractionalBits(f80) - 1)));
112111
113fn test__mulxf3(a: f80, b: f80, expected: u80) !void {112fn test__mulxf3(a: f80, b: f80, expected: u80) !void {
114 const x = __mulxf3(a, b);113 const x = __mulxf3(a, b);
115 const rep = @as(u80, @bitCast(x));114 const rep: u80 = @bitCast(x);
116115
117 if (rep == expected)116 if (rep == expected)
118 return;117 return;
lib/compiler_rt/parityti2_test.zig+1-1
...@@ -3,7 +3,7 @@ const parity = @import("parity.zig");...@@ -3,7 +3,7 @@ const parity = @import("parity.zig");
3const testing = std.testing;3const testing = std.testing;
44
5fn parityti2Naive(a: i128) i32 {5fn parityti2Naive(a: i128) i32 {
6 var x = @as(u128, @bitCast(a));6 var x: u128 = @bitCast(a);
7 var has_parity: bool = false;7 var has_parity: bool = false;
8 while (x > 0) {8 while (x > 0) {
9 has_parity = !has_parity;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,17 +57,17 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
57 w = @"fn" * pio2_1t;57 w = @"fn" * pio2_1t;
58 }58 }
59 y[0] = r - w;59 y[0] = r - w;
60 ui = @as(u64, @bitCast(y[0]));60 ui = @bitCast(y[0]);
61 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));61 ey = @intCast((ui >> 52) & 0x7ff);
62 ex = @as(i32, @intCast(ix >> 20));62 ex = @intCast(ix >> 20);
63 if (ex - ey > 16) { // 2nd round, good to 118 bits63 if (ex - ey > 16) { // 2nd round, good to 118 bits
64 t = r;64 t = r;
65 w = @"fn" * pio2_2;65 w = @"fn" * pio2_2;
66 r = t - w;66 r = t - w;
67 w = @"fn" * pio2_2t - ((t - r) - w);67 w = @"fn" * pio2_2t - ((t - r) - w);
68 y[0] = r - w;68 y[0] = r - w;
69 ui = @as(u64, @bitCast(y[0]));69 ui = @bitCast(y[0]);
70 ey = @as(i32, @intCast((ui >> 52) & 0x7ff));70 ey = @intCast((ui >> 52) & 0x7ff);
71 if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases71 if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases
72 t = r;72 t = r;
73 w = @"fn" * pio2_3;73 w = @"fn" * pio2_3;
...@@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {...@@ -95,9 +95,9 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
95 var i: i32 = undefined;95 var i: i32 = undefined;
96 var ui: u64 = undefined;96 var ui: u64 = undefined;
9797
98 ui = @as(u64, @bitCast(x));98 ui = @bitCast(x);
99 sign = ui >> 63 != 0;99 sign = ui >> 63 != 0;
100 ix = @as(u32, @truncate((ui >> 32) & 0x7fffffff));100 ix = @truncate((ui >> 32) & 0x7fffffff);
101 if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4101 if (ix <= 0x400f6a7a) { // |x| ~<= 5pi/4
102 if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2102 if ((ix & 0xfffff) == 0x921fb) { // |x| ~= pi/2 or 2pi/2
103 return medium(ix, x, y);103 return medium(ix, x, y);
...@@ -171,7 +171,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {...@@ -171,7 +171,7 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 {
171 return 0;171 return 0;
172 }172 }
173 // set z = scalbn(|x|,-ilogb(x)+23)173 // set z = scalbn(|x|,-ilogb(x)+23)
174 ui = @as(u64, @bitCast(x));174 ui = @bitCast(x);
175 ui &= std.math.maxInt(u64) >> 12;175 ui &= std.math.maxInt(u64) >> 12;
176 ui |= @as(u64, 0x3ff + 23) << 52;176 ui |= @as(u64, 0x3ff + 23) << 52;
177 z = @as(f64, @bitCast(ui));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,7 +322,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
322 i += 1;322 i += 1;
323 j -= 1;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 iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));326 iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
327 z = q[U(j - 1)] + fw;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,7 +330,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
330 // compute n330 // compute n
331 z = math.scalbn(z, q0); // actual value of z331 z = math.scalbn(z, q0); // actual value of z
332 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8332 z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8
333 n = @as(i32, @intFromFloat(z));333 n = @intFromFloat(z);
334 z -= @as(f64, @floatFromInt(n));334 z -= @as(f64, @floatFromInt(n));
335 ih = 0;335 ih = 0;
336 if (q0 > 0) { // need iq[jz-1] to determine n336 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,7 +414,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 {
414 } else { // break z into 24-bit if necessary414 } else { // break z into 24-bit if necessary
415 z = math.scalbn(z, -q0);415 z = math.scalbn(z, -q0);
416 if (z >= 0x1p24) {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 iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));418 iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw));
419 jz += 1;419 jz += 1;
420 q0 += 24;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,14 +30,14 @@ pub fn rem_pio2f(x: f32, y: *f64) i32 {
30 var e0: u32 = undefined;30 var e0: u32 = undefined;
31 var ui: u32 = undefined;31 var ui: u32 = undefined;
3232
33 ui = @as(u32, @bitCast(x));33 ui = @bitCast(x);
34 ix = ui & 0x7fffffff;34 ix = ui & 0x7fffffff;
3535
36 // 25+53 bit pi is good enough for medium size36 // 25+53 bit pi is good enough for medium size
37 if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size37 if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size
38 // Use a specialized rint() to get fn.38 // Use a specialized rint() to get fn.
39 @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint;39 @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint;
40 n = @as(i32, @intFromFloat(@"fn"));40 n = @intFromFloat(@"fn");
41 y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;41 y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
42 // Matters with directed rounding.42 // Matters with directed rounding.
43 if (y.* < -pio4) {43 if (y.* < -pio4) {
lib/compiler_rt/round.zig+5-5
...@@ -27,14 +27,14 @@ comptime {...@@ -27,14 +27,14 @@ comptime {
2727
28pub fn __roundh(x: f16) callconv(.C) f16 {28pub fn __roundh(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @as(f16, @floatCast(roundf(x)));30 return @floatCast(roundf(x));
31}31}
3232
33pub fn roundf(x_: f32) callconv(.C) f32 {33pub fn roundf(x_: f32) callconv(.C) f32 {
34 const f32_toint = 1.0 / math.floatEps(f32);34 const f32_toint = 1.0 / math.floatEps(f32);
3535
36 var x = x_;36 var x = x_;
37 const u = @as(u32, @bitCast(x));37 const u: u32 = @bitCast(x);
38 const e = (u >> 23) & 0xFF;38 const e = (u >> 23) & 0xFF;
39 var y: f32 = undefined;39 var y: f32 = undefined;
4040
...@@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 {...@@ -69,7 +69,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
69 const f64_toint = 1.0 / math.floatEps(f64);69 const f64_toint = 1.0 / math.floatEps(f64);
7070
71 var x = x_;71 var x = x_;
72 const u = @as(u64, @bitCast(x));72 const u: u64 = @bitCast(x);
73 const e = (u >> 52) & 0x7FF;73 const e = (u >> 52) & 0x7FF;
74 var y: f64 = undefined;74 var y: f64 = undefined;
7575
...@@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 {...@@ -102,14 +102,14 @@ pub fn round(x_: f64) callconv(.C) f64 {
102102
103pub fn __roundx(x: f80) callconv(.C) f80 {103pub fn __roundx(x: f80) callconv(.C) f80 {
104 // TODO: more efficient implementation104 // TODO: more efficient implementation
105 return @as(f80, @floatCast(roundq(x)));105 return @floatCast(roundq(x));
106}106}
107107
108pub fn roundq(x_: f128) callconv(.C) f128 {108pub fn roundq(x_: f128) callconv(.C) f128 {
109 const f128_toint = 1.0 / math.floatEps(f128);109 const f128_toint = 1.0 / math.floatEps(f128);
110110
111 var x = x_;111 var x = x_;
112 const u = @as(u128, @bitCast(x));112 const u: u128 = @bitCast(x);
113 const e = (u >> 112) & 0x7FFF;113 const e = (u >> 112) & 0x7FFF;
114 var y: f128 = undefined;114 var y: f128 = undefined;
115115
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,7 +218,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
218 const bits = @typeInfo(F).Float.bits;218 const bits = @typeInfo(F).Float.bits;
219 const I = std.meta.Int(.unsigned, bits);219 const I = std.meta.Int(.unsigned, bits);
220 const ix = @as(I, @bitCast(x)) & (math.maxInt(I) >> 1);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));
222222
223 if (se == 0x7fff) {223 if (se == 0x7fff) {
224 const result = x - x;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,7 +125,7 @@ pub fn sqrt(x: f64) callconv(.C) f64 {
125 }125 }
126126
127 // normalize x127 // normalize x
128 var m = @as(i32, @intCast(ix0 >> 20));128 var m: i32 = @intCast(ix0 >> 20);
129 if (m == 0) {129 if (m == 0) {
130 // subnormal130 // subnormal
131 while (ix0 == 0) {131 while (ix0 == 0) {
lib/compiler_rt/tan.zig+2-2
...@@ -33,7 +33,7 @@ comptime {...@@ -33,7 +33,7 @@ comptime {
3333
34pub fn __tanh(x: f16) callconv(.C) f16 {34pub fn __tanh(x: f16) callconv(.C) f16 {
35 // TODO: more efficient implementation35 // TODO: more efficient implementation
36 return @as(f16, @floatCast(tanf(x)));36 return @floatCast(tanf(x));
37}37}
3838
39pub fn tanf(x: f32) callconv(.C) f32 {39pub fn tanf(x: f32) callconv(.C) f32 {
...@@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {...@@ -43,7 +43,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
43 const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D243 const t3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
44 const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D1844 const t4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
4545
46 var ix = @as(u32, @bitCast(x));46 var ix: u32 = @bitCast(x);
47 const sign = ix >> 31 != 0;47 const sign = ix >> 31 != 0;
48 ix &= 0x7fffffff;48 ix &= 0x7fffffff;
4949
lib/compiler_rt/trig.zig+1-1
...@@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {...@@ -199,7 +199,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 {
199 var hx: u32 = undefined;199 var hx: u32 = undefined;
200 var sign: bool = undefined;200 var sign: bool = undefined;
201201
202 hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32));202 hx = @intCast(@as(u64, @bitCast(x)) >> 32);
203 const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744203 const big = (hx & 0x7fffffff) >= 0x3FE59428; // |x| >= 0.6744
204 if (big) {204 if (big) {
205 sign = hx >> 31 != 0;205 sign = hx >> 31 != 0;
lib/compiler_rt/trunc.zig+5-5
...@@ -27,11 +27,11 @@ comptime {...@@ -27,11 +27,11 @@ comptime {
2727
28pub fn __trunch(x: f16) callconv(.C) f16 {28pub fn __trunch(x: f16) callconv(.C) f16 {
29 // TODO: more efficient implementation29 // TODO: more efficient implementation
30 return @as(f16, @floatCast(truncf(x)));30 return @floatCast(truncf(x));
31}31}
3232
33pub fn truncf(x: f32) callconv(.C) f32 {33pub fn truncf(x: f32) callconv(.C) f32 {
34 const u = @as(u32, @bitCast(x));34 const u: u32 = @bitCast(x);
35 var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9;35 var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9;
36 var m: u32 = undefined;36 var m: u32 = undefined;
3737
...@@ -47,12 +47,12 @@ pub fn truncf(x: f32) callconv(.C) f32 {...@@ -47,12 +47,12 @@ pub fn truncf(x: f32) callconv(.C) f32 {
47 return x;47 return x;
48 } else {48 } else {
49 math.doNotOptimizeAway(x + 0x1p120);49 math.doNotOptimizeAway(x + 0x1p120);
50 return @as(f32, @bitCast(u & ~m));50 return @bitCast(u & ~m);
51 }51 }
52}52}
5353
54pub fn trunc(x: f64) callconv(.C) f64 {54pub fn trunc(x: f64) callconv(.C) f64 {
55 const u = @as(u64, @bitCast(x));55 const u: u64 = @bitCast(x);
56 var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12;56 var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12;
57 var m: u64 = undefined;57 var m: u64 = undefined;
5858
...@@ -68,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {...@@ -68,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {
68 return x;68 return x;
69 } else {69 } else {
70 math.doNotOptimizeAway(x + 0x1p120);70 math.doNotOptimizeAway(x + 0x1p120);
71 return @as(f64, @bitCast(u & ~m));71 return @bitCast(u & ~m);
72 }72 }
73}73}
7474
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,8 +72,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
72 // a underflows on conversion to the destination type or is an exact72 // a underflows on conversion to the destination type or is an exact
73 // zero. The result may be a denormal or zero. Extract the exponent73 // zero. The result may be a denormal or zero. Extract the exponent
74 // to get the shift amount for the denormalization.74 // to get the shift amount for the denormalization.
75 const aExp = @as(u32, @intCast(aAbs >> srcSigBits));75 const aExp: u32 = @intCast(aAbs >> srcSigBits);
76 const shift = @as(u32, @intCast(srcExpBias - dstExpBias - aExp + 1));76 const shift: u32 = @intCast(srcExpBias - dstExpBias - aExp + 1);
7777
78 const significand: src_rep_t = (aRep & srcSignificandMask) | srcMinNormal;78 const significand: src_rep_t = (aRep & srcSignificandMask) | srcMinNormal;
7979
lib/compiler_rt/truncf_test.zig+20-20
...@@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2;...@@ -10,7 +10,7 @@ const __trunctfdf2 = @import("trunctfdf2.zig").__trunctfdf2;
10const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2;10const __trunctfxf2 = @import("trunctfxf2.zig").__trunctfxf2;
1111
12fn test__truncsfhf2(a: u32, expected: u16) !void {12fn 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)));
1414
15 if (actual == expected) {15 if (actual == expected) {
16 return;16 return;
...@@ -73,7 +73,7 @@ test "truncsfhf2" {...@@ -73,7 +73,7 @@ test "truncsfhf2" {
73}73}
7474
75fn test__truncdfhf2(a: f64, expected: u16) void {75fn test__truncdfhf2(a: f64, expected: u16) void {
76 const rep = @as(u16, @bitCast(__truncdfhf2(a)));76 const rep: u16 = @bitCast(__truncdfhf2(a));
7777
78 if (rep == expected) {78 if (rep == expected) {
79 return;79 return;
...@@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void {...@@ -89,7 +89,7 @@ fn test__truncdfhf2(a: f64, expected: u16) void {
89}89}
9090
91fn test__truncdfhf2_raw(a: u64, expected: u16) void {91fn 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)));
9393
94 if (actual == expected) {94 if (actual == expected) {
95 return;95 return;
...@@ -141,7 +141,7 @@ test "truncdfhf2" {...@@ -141,7 +141,7 @@ test "truncdfhf2" {
141fn test__trunctfsf2(a: f128, expected: u32) void {141fn test__trunctfsf2(a: f128, expected: u32) void {
142 const x = __trunctfsf2(a);142 const x = __trunctfsf2(a);
143143
144 const rep = @as(u32, @bitCast(x));144 const rep: u32 = @bitCast(x);
145 if (rep == expected) {145 if (rep == expected) {
146 return;146 return;
147 }147 }
...@@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {...@@ -157,11 +157,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
157157
158test "trunctfsf2" {158test "trunctfsf2" {
159 // qnan159 // qnan
160 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7fc00000);160 test__trunctfsf2(@bitCast(@as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
161 // nan161 // 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 // inf163 // inf
164 test__trunctfsf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7f800000);164 test__trunctfsf2(@bitCast(@as(u128, 0x7fff000000000000 << 64)), 0x7f800000);
165 // zero165 // zero
166 test__trunctfsf2(0.0, 0x0);166 test__trunctfsf2(0.0, 0x0);
167167
...@@ -174,7 +174,7 @@ test "trunctfsf2" {...@@ -174,7 +174,7 @@ test "trunctfsf2" {
174fn test__trunctfdf2(a: f128, expected: u64) void {174fn test__trunctfdf2(a: f128, expected: u64) void {
175 const x = __trunctfdf2(a);175 const x = __trunctfdf2(a);
176176
177 const rep = @as(u64, @bitCast(x));177 const rep: u64 = @bitCast(x);
178 if (rep == expected) {178 if (rep == expected) {
179 return;179 return;
180 }180 }
...@@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {...@@ -190,11 +190,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
190190
191test "trunctfdf2" {191test "trunctfdf2" {
192 // qnan192 // qnan
193 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff800000000000 << 64))), 0x7ff8000000000000);193 test__trunctfdf2(@bitCast(@as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
194 // nan194 // 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 // inf196 // inf
197 test__trunctfdf2(@as(f128, @bitCast(@as(u128, 0x7fff000000000000 << 64))), 0x7ff0000000000000);197 test__trunctfdf2(@bitCast(@as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);
198 // zero198 // zero
199 test__trunctfdf2(0.0, 0x0);199 test__trunctfdf2(0.0, 0x0);
200200
...@@ -207,7 +207,7 @@ test "trunctfdf2" {...@@ -207,7 +207,7 @@ test "trunctfdf2" {
207fn test__truncdfsf2(a: f64, expected: u32) void {207fn test__truncdfsf2(a: f64, expected: u32) void {
208 const x = __truncdfsf2(a);208 const x = __truncdfsf2(a);
209209
210 const rep = @as(u32, @bitCast(x));210 const rep: u32 = @bitCast(x);
211 if (rep == expected) {211 if (rep == expected) {
212 return;212 return;
213 }213 }
...@@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {...@@ -225,11 +225,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
225225
226test "truncdfsf2" {226test "truncdfsf2" {
227 // nan & qnan227 // nan & qnan
228 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff8000000000000))), 0x7fc00000);228 test__truncdfsf2(@bitCast(@as(u64, 0x7ff8000000000000)), 0x7fc00000);
229 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000001))), 0x7fc00000);229 test__truncdfsf2(@bitCast(@as(u64, 0x7ff0000000000001)), 0x7fc00000);
230 // inf230 // inf
231 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0x7ff0000000000000))), 0x7f800000);231 test__truncdfsf2(@bitCast(@as(u64, 0x7ff0000000000000)), 0x7f800000);
232 test__truncdfsf2(@as(f64, @bitCast(@as(u64, 0xfff0000000000000))), 0xff800000);232 test__truncdfsf2(@bitCast(@as(u64, 0xfff0000000000000)), 0xff800000);
233233
234 test__truncdfsf2(0.0, 0x0);234 test__truncdfsf2(0.0, 0x0);
235 test__truncdfsf2(1.0, 0x3f800000);235 test__truncdfsf2(1.0, 0x3f800000);
...@@ -242,7 +242,7 @@ test "truncdfsf2" {...@@ -242,7 +242,7 @@ test "truncdfsf2" {
242fn test__trunctfhf2(a: f128, expected: u16) void {242fn test__trunctfhf2(a: f128, expected: u16) void {
243 const x = __trunctfhf2(a);243 const x = __trunctfhf2(a);
244244
245 const rep = @as(u16, @bitCast(x));245 const rep: u16 = @bitCast(x);
246 if (rep == expected) {246 if (rep == expected) {
247 return;247 return;
248 }248 }
...@@ -254,11 +254,11 @@ fn test__trunctfhf2(a: f128, expected: u16) void {...@@ -254,11 +254,11 @@ fn test__trunctfhf2(a: f128, expected: u16) void {
254254
255test "trunctfhf2" {255test "trunctfhf2" {
256 // qNaN256 // qNaN
257 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff8000000000000000000000000000))), 0x7e00);257 test__trunctfhf2(@bitCast(@as(u128, 0x7fff8000000000000000000000000000)), 0x7e00);
258 // NaN258 // NaN
259 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000001))), 0x7e00);259 test__trunctfhf2(@bitCast(@as(u128, 0x7fff0000000000000000000000000001)), 0x7e00);
260 // inf260 // inf
261 test__trunctfhf2(@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0x7c00);261 test__trunctfhf2(@bitCast(@as(u128, 0x7fff0000000000000000000000000000)), 0x7c00);
262 test__trunctfhf2(-@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0xfc00);262 test__trunctfhf2(-@as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))), 0xfc00);
263 // zero263 // zero
264 test__trunctfhf2(0.0, 0x0);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,7 +44,7 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
44 // destination format. We can convert by simply right-shifting with44 // destination format. We can convert by simply right-shifting with
45 // rounding, adding the explicit integer bit, and adjusting the exponent45 // rounding, adding the explicit integer bit, and adjusting the exponent
46 res.fraction = @as(u64, @truncate(a_abs >> (src_sig_bits - dst_sig_bits))) | integer_bit;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);
4848
49 const round_bits = a_abs & round_mask;49 const round_bits = a_abs & round_mask;
50 if (round_bits > halfway) {50 if (round_bits > halfway) {
lib/std/Build.zig+1-1
...@@ -1850,7 +1850,7 @@ pub fn hex64(x: u64) [16]u8 {...@@ -1850,7 +1850,7 @@ pub fn hex64(x: u64) [16]u8 {
1850 var result: [16]u8 = undefined;1850 var result: [16]u8 = undefined;
1851 var i: usize = 0;1851 var i: usize = 0;
1852 while (i < 8) : (i += 1) {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 result[i * 2 + 0] = hex_charset[byte >> 4];1854 result[i * 2 + 0] = hex_charset[byte >> 4];
1855 result[i * 2 + 1] = hex_charset[byte & 15];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,7 +206,7 @@ pub const Edwards25519 = struct {
206 var q = Edwards25519.identityElement;206 var q = Edwards25519.identityElement;
207 var pos: usize = 252;207 var pos: usize = 252;
208 while (true) : (pos -= 4) {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 if (vartime) {210 if (vartime) {
211 if (slot != 0) {211 if (slot != 0) {
212 q = q.add(pc[slot]);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,7 +90,7 @@ fn AesOcb(comptime Aes: anytype) type {
90 nx[16 - nonce_length - 1] = 1;90 nx[16 - nonce_length - 1] = 1;
91 nx[nx.len - nonce_length ..].* = npub;91 nx[nx.len - nonce_length ..].* = npub;
9292
93 const bottom = @as(u6, @truncate(nx[15]));93 const bottom: u6 = @truncate(nx[15]);
94 nx[15] &= 0xc0;94 nx[15] &= 0xc0;
95 var ktop_: Block = undefined;95 var ktop_: Block = undefined;
96 aes_enc_ctx.encrypt(&ktop_, &nx);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,18 +508,18 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
508 var need_sub = false;508 var need_sub = false;
509 var i: usize = t_bits - 1;509 var i: usize = t_bits - 1;
510 while (true) : (i -= 1) {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 var borrow: u1 = 0;512 var borrow: u1 = 0;
513 for (0..self.limbs_count()) |j| {513 for (0..self.limbs_count()) |j| {
514 const l = ct.select(need_sub, d_limbs[j], x_limbs[j]);514 const l = ct.select(need_sub, d_limbs[j], x_limbs[j]);
515 var res = (l << 1) + carry;515 var res = (l << 1) + carry;
516 x_limbs[j] = @as(TLimb, @truncate(res));516 x_limbs[j] = @as(TLimb, @truncate(res));
517 carry = @as(u1, @truncate(res >> t_bits));517 carry = @truncate(res >> t_bits);
518518
519 res = x_limbs[j] -% m_limbs[j] -% borrow;519 res = x_limbs[j] -% m_limbs[j] -% borrow;
520 d_limbs[j] = @as(TLimb, @truncate(res));520 d_limbs[j] = @as(TLimb, @truncate(res));
521521
522 borrow = @as(u1, @truncate(res >> t_bits));522 borrow = @truncate(res >> t_bits);
523 }523 }
524 need_sub = ct.eql(carry, borrow);524 need_sub = ct.eql(carry, borrow);
525 if (i == 0) break;525 if (i == 0) break;
...@@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -531,7 +531,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
531 pub fn add(self: Self, x: Fe, y: Fe) Fe {531 pub fn add(self: Self, x: Fe, y: Fe) Fe {
532 var out = x;532 var out = x;
533 const overflow = out.v.addWithOverflow(y.v);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 const need_sub = ct.eql(overflow, underflow);535 const need_sub = ct.eql(overflow, underflow);
536 _ = out.v.conditionalSubWithOverflow(need_sub, self.v);536 _ = out.v.conditionalSubWithOverflow(need_sub, self.v);
537 return out;537 return out;
...@@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {...@@ -540,7 +540,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
540 /// Subtracts two field elements (mod m).540 /// Subtracts two field elements (mod m).
541 pub fn sub(self: Self, x: Fe, y: Fe) Fe {541 pub fn sub(self: Self, x: Fe, y: Fe) Fe {
542 var out = x;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 _ = out.v.conditionalAddWithOverflow(underflow, self.v);544 _ = out.v.conditionalAddWithOverflow(underflow, self.v);
545 return out;545 return out;
546 }546 }
lib/std/crypto/isap.zig+1-1
...@@ -67,7 +67,7 @@ pub const IsapA128A = struct {...@@ -67,7 +67,7 @@ pub const IsapA128A = struct {
67 var i: usize = 0;67 var i: usize = 0;
68 while (i < y.len * 8 - 1) : (i += 1) {68 while (i < y.len * 8 - 1) : (i += 1) {
69 const cur_byte_pos = i / 8;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 const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7;71 const cur_bit = ((y[cur_byte_pos] >> cur_bit_pos) & 1) << 7;
72 isap.st.addByte(cur_bit, 0);72 isap.st.addByte(cur_bit, 0);
73 isap.st.permuteR(1);73 isap.st.permuteR(1);
lib/std/crypto/kyber_d00.zig+2-2
...@@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 {...@@ -638,7 +638,7 @@ fn montReduce(x: i32) i16 {
638 // Note that x q' might be as big as 2³² and could overflow the int32638 // Note that x q' might be as big as 2³² and could overflow the int32
639 // multiplication in the last line. However for any int32s a and b,639 // multiplication in the last line. However for any int32s a and b,
640 // we have int32(int64(a)*int64(b)) = int32(a*b) and so the result is ok.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)));
642642
643 // Note that x - m q is divisible by R; indeed modulo R we have643 // 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,7 +652,7 @@ fn montReduce(x: i32) i16 {
652 // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have652 // and as both 2¹⁵ q ≤ m q, x < 2¹⁵ q, we have
653 // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired.653 // 2¹⁶ q ≤ x - m q < 2¹⁶ and so q ≤ (x - m q) / R < q as desired.
654 const yR = x - @as(i32, m) * @as(i32, Q);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}
657657
658test "Test montReduce" {658test "Test montReduce" {
lib/std/hash/crc.zig+1-1
...@@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {...@@ -142,7 +142,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
142 var crc = tables[0][i];142 var crc = tables[0][i];
143 var j: usize = 1;143 var j: usize = 1;
144 while (j < 8) : (j += 1) {144 while (j < 8) : (j += 1) {
145 const index = @as(u8, @truncate(crc));145 const index: u8 = @truncate(crc);
146 crc = tables[0][index] ^ (crc >> 8);146 crc = tables[0][index] ^ (crc >> 8);
147 tables[j][i] = crc;147 tables[j][i] = crc;
148 }148 }
lib/std/hash/murmur.zig+2-2
...@@ -14,7 +14,7 @@ pub const Murmur2_32 = struct {...@@ -14,7 +14,7 @@ pub const Murmur2_32 = struct {
1414
15 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {15 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
16 const m: u32 = 0x5bd1e995;16 const m: u32 = 0x5bd1e995;
17 const len = @as(u32, @truncate(str.len));17 const len: u32 = @truncate(str.len);
18 var h1: u32 = seed ^ len;18 var h1: u32 = seed ^ len;
19 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {19 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
20 var k1: u32 = v;20 var k1: u32 = v;
...@@ -178,7 +178,7 @@ pub const Murmur3_32 = struct {...@@ -178,7 +178,7 @@ pub const Murmur3_32 = struct {
178 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {178 pub fn hashWithSeed(str: []const u8, seed: u32) u32 {
179 const c1: u32 = 0xcc9e2d51;179 const c1: u32 = 0xcc9e2d51;
180 const c2: u32 = 0x1b873593;180 const c2: u32 = 0x1b873593;
181 const len = @as(u32, @truncate(str.len));181 const len: u32 = @truncate(str.len);
182 var h1: u32 = seed;182 var h1: u32 = seed;
183 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {183 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
184 var k1: u32 = v;184 var k1: u32 = v;
lib/std/hash_map.zig+3-3
...@@ -899,7 +899,7 @@ pub fn HashMapUnmanaged(...@@ -899,7 +899,7 @@ pub fn HashMapUnmanaged(
899 }899 }
900900
901 fn capacityForSize(size: Size) Size {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 new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable;903 new_cap = math.ceilPowerOfTwo(u32, new_cap) catch unreachable;
904 return new_cap;904 return new_cap;
905 }905 }
...@@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged(...@@ -1480,7 +1480,7 @@ pub fn HashMapUnmanaged(
1480 const new_cap = capacityForSize(self.size);1480 const new_cap = capacityForSize(self.size);
1481 try other.allocate(allocator, new_cap);1481 try other.allocate(allocator, new_cap);
1482 other.initMetadatas();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);
14841484
1485 var i: Size = 0;1485 var i: Size = 0;
1486 var metadata = self.metadata.?;1486 var metadata = self.metadata.?;
...@@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged(...@@ -1515,7 +1515,7 @@ pub fn HashMapUnmanaged(
1515 defer map.deinit(allocator);1515 defer map.deinit(allocator);
1516 try map.allocate(allocator, new_cap);1516 try map.allocate(allocator, new_cap);
1517 map.initMetadatas();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);
15191519
1520 if (self.size != 0) {1520 if (self.size != 0) {
1521 const old_capacity = self.capacity();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,8 +10,8 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
1010
11 const max_group = (@typeInfo(U).Int.bits + 6) / 7;11 const max_group = (@typeInfo(U).Int.bits + 6) / 7;
1212
13 var value = @as(U, 0);13 var value: U = 0;
14 var group = @as(ShiftT, 0);14 var group: ShiftT = 0;
1515
16 while (group < max_group) : (group += 1) {16 while (group < max_group) : (group += 1) {
17 const byte = try reader.readByte();17 const byte = try reader.readByte();
...@@ -37,10 +37,10 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {...@@ -37,10 +37,10 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
37pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {37pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
38 const T = @TypeOf(uint_value);38 const T = @TypeOf(uint_value);
39 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;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);
4141
42 while (true) {42 while (true) {
43 const byte = @as(u8, @truncate(value & 0x7f));43 const byte: u8 = @truncate(value & 0x7f);
44 value >>= 7;44 value >>= 7;
45 if (value == 0) {45 if (value == 0) {
46 try writer.writeByte(byte);46 try writer.writeByte(byte);
...@@ -115,11 +115,11 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {...@@ -115,11 +115,11 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
115 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;115 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
116 const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);116 const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);
117117
118 var value = @as(S, @intCast(int_value));118 var value: S = @intCast(int_value);
119119
120 while (true) {120 while (true) {
121 const uvalue = @as(U, @bitCast(value));121 const uvalue: U = @bitCast(value);
122 const byte = @as(u8, @truncate(uvalue));122 const byte: u8 = @truncate(uvalue);
123 value >>= 6;123 value >>= 6;
124 if (value == -1 or value == 0) {124 if (value == -1 or value == 0) {
125 try writer.writeByte(byte & 0x7F);125 try writer.writeByte(byte & 0x7F);
...@@ -141,7 +141,7 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {...@@ -141,7 +141,7 @@ pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
141pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void {141pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.unsigned, l * 7)) void {
142 const T = @TypeOf(int);142 const T = @TypeOf(int);
143 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;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);
145145
146 comptime var i = 0;146 comptime var i = 0;
147 inline while (i < (l - 1)) : (i += 1) {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,11 +55,11 @@ fn atanh_32(x: f32) f32 {
55}55}
5656
57fn atanh_64(x: f64) f64 {57fn atanh_64(x: f64) f64 {
58 const u = @as(u64, @bitCast(x));58 const u: u64 = @bitCast(x);
59 const e = (u >> 52) & 0x7FF;59 const e = (u >> 52) & 0x7FF;
60 const s = u >> 63;60 const s = u >> 63;
6161
62 var y = @as(f64, @bitCast(u & (maxInt(u64) >> 1))); // |x|62 var y: f64 = @bitCast(u & (maxInt(u64) >> 1)); // |x|
6363
64 if (y == 1.0) {64 if (y == 1.0) {
65 return math.copysign(math.inf(f64), x);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,10 +26,10 @@ fn cosh32(z: Complex(f32)) Complex(f32) {
26 const x = z.re;26 const x = z.re;
27 const y = z.im;27 const y = z.im;
2828
29 const hx = @as(u32, @bitCast(x));29 const hx: u32 = @bitCast(x);
30 const ix = hx & 0x7fffffff;30 const ix = hx & 0x7fffffff;
3131
32 const hy = @as(u32, @bitCast(y));32 const hy: u32 = @bitCast(y);
33 const iy = hy & 0x7fffffff;33 const iy = hy & 0x7fffffff;
3434
35 if (ix < 0x7f800000 and iy < 0x7f800000) {35 if (ix < 0x7f800000 and iy < 0x7f800000) {
...@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {...@@ -89,14 +89,14 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
89 const x = z.re;89 const x = z.re;
90 const y = z.im;90 const y = z.im;
9191
92 const fx = @as(u64, @bitCast(x));92 const fx: u64 = @bitCast(x);
93 const hx = @as(u32, @intCast(fx >> 32));93 const hx: u32 = @intCast(fx >> 32);
94 const lx = @as(u32, @truncate(fx));94 const lx: u32 = @truncate(fx);
95 const ix = hx & 0x7fffffff;95 const ix = hx & 0x7fffffff;
9696
97 const fy = @as(u64, @bitCast(y));97 const fy: u64 = @bitCast(y);
98 const hy = @as(u32, @intCast(fy >> 32));98 const hy: u32 = @intCast(fy >> 32);
99 const ly = @as(u32, @truncate(fy));99 const ly: u32 = @truncate(fy);
100 const iy = hy & 0x7fffffff;100 const iy = hy & 0x7fffffff;
101101
102 // nearly non-exceptional case where x, y are finite102 // 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,18 +75,18 @@ fn exp64(z: Complex(f64)) Complex(f64) {
75 const x = z.re;75 const x = z.re;
76 const y = z.im;76 const y = z.im;
7777
78 const fy = @as(u64, @bitCast(y));78 const fy: u64 = @bitCast(y);
79 const hy = @as(u32, @intCast((fy >> 32) & 0x7fffffff));79 const hy: u32 = @intCast((fy >> 32) & 0x7fffffff);
80 const ly = @as(u32, @truncate(fy));80 const ly: u32 = @truncate(fy);
8181
82 // cexp(x + i0) = exp(x) + i082 // cexp(x + i0) = exp(x) + i0
83 if (hy | ly == 0) {83 if (hy | ly == 0) {
84 return Complex(f64).init(@exp(x), y);84 return Complex(f64).init(@exp(x), y);
85 }85 }
8686
87 const fx = @as(u64, @bitCast(x));87 const fx: u64 = @bitCast(x);
88 const hx = @as(u32, @intCast(fx >> 32));88 const hx: u32 = @intCast(fx >> 32);
89 const lx = @as(u32, @truncate(fx));89 const lx: u32 = @truncate(fx);
9090
91 // cexp(0 + iy) = cos(y) + isin(y)91 // cexp(0 + iy) = cos(y) + isin(y)
92 if ((hx & 0x7fffffff) | lx == 0) {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,14 +89,14 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
89 const x = z.re;89 const x = z.re;
90 const y = z.im;90 const y = z.im;
9191
92 const fx = @as(u64, @bitCast(x));92 const fx: u64 = @bitCast(x);
93 const hx = @as(u32, @intCast(fx >> 32));93 const hx: u32 = @intCast(fx >> 32);
94 const lx = @as(u32, @truncate(fx));94 const lx: u32 = @truncate(fx);
95 const ix = hx & 0x7fffffff;95 const ix = hx & 0x7fffffff;
9696
97 const fy = @as(u64, @bitCast(y));97 const fy: u64 = @bitCast(y);
98 const hy = @as(u32, @intCast(fy >> 32));98 const hy: u32 = @intCast(fy >> 32);
99 const ly = @as(u32, @truncate(fy));99 const ly: u32 = @truncate(fy);
100 const iy = hy & 0x7fffffff;100 const iy = hy & 0x7fffffff;
101101
102 if (ix < 0x7ff00000 and iy < 0x7ff00000) {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,11 +62,11 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
62 const x = z.re;62 const x = z.re;
63 const y = z.im;63 const y = z.im;
6464
65 const fx = @as(u64, @bitCast(x));65 const fx: u64 = @bitCast(x);
66 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily66 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily
67 // fits in range.67 // fits in range.
68 const hx = @as(u32, @intCast(fx >> 32));68 const hx: u32 = @intCast(fx >> 32);
69 const lx = @as(u32, @truncate(fx));69 const lx: u32 = @truncate(fx);
70 const ix = hx & 0x7fffffff;70 const ix = hx & 0x7fffffff;
7171
72 if (ix >= 0x7ff00000) {72 if (ix >= 0x7ff00000) {
...@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {...@@ -75,7 +75,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
75 return Complex(f64).init(x, r);75 return Complex(f64).init(x, r);
76 }76 }
7777
78 const xx = @as(f64, @bitCast((@as(u64, hx - 0x40000000) << 32) | lx));78 const xx: f64 = @bitCast((@as(u64, hx - 0x40000000) << 32) | lx);
79 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);79 const r = if (math.isInf(y)) y else @sin(y) * @cos(y);
80 return Complex(f64).init(xx, math.copysign(@as(f64, 0.0), r));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,7 +37,7 @@ pub fn modf(x: anytype) modf_result(@TypeOf(x)) {
37fn modf32(x: f32) modf32_result {37fn modf32(x: f32) modf32_result {
38 var result: modf32_result = undefined;38 var result: modf32_result = undefined;
3939
40 const u = @as(u32, @bitCast(x));40 const u: u32 = @bitCast(x);
41 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;41 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
42 const us = u & 0x80000000;42 const us = u & 0x80000000;
4343
...@@ -73,7 +73,7 @@ fn modf32(x: f32) modf32_result {...@@ -73,7 +73,7 @@ fn modf32(x: f32) modf32_result {
73 return result;73 return result;
74 }74 }
7575
76 const uf = @as(f32, @bitCast(u & ~mask));76 const uf: f32 = @bitCast(u & ~mask);
77 result.ipart = uf;77 result.ipart = uf;
78 result.fpart = x - uf;78 result.fpart = x - uf;
79 return result;79 return result;
...@@ -82,7 +82,7 @@ fn modf32(x: f32) modf32_result {...@@ -82,7 +82,7 @@ fn modf32(x: f32) modf32_result {
82fn modf64(x: f64) modf64_result {82fn modf64(x: f64) modf64_result {
83 var result: modf64_result = undefined;83 var result: modf64_result = undefined;
8484
85 const u = @as(u64, @bitCast(x));85 const u: u64 = @bitCast(x);
86 const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF;86 const e = @as(i32, @intCast((u >> 52) & 0x7FF)) - 0x3FF;
87 const us = u & (1 << 63);87 const us = u & (1 << 63);
8888
lib/std/os/linux.zig+7-7
...@@ -176,21 +176,21 @@ const require_aligned_register_pair =...@@ -176,21 +176,21 @@ const require_aligned_register_pair =
176// Split a 64bit value into a {LSB,MSB} pair.176// Split a 64bit value into a {LSB,MSB} pair.
177// The LE/BE variants specify the endianness to assume.177// The LE/BE variants specify the endianness to assume.
178fn splitValueLE64(val: i64) [2]u32 {178fn splitValueLE64(val: i64) [2]u32 {
179 const u = @as(u64, @bitCast(val));179 const u: u64 = @bitCast(val);
180 return [2]u32{180 return [2]u32{
181 @as(u32, @truncate(u)),181 @as(u32, @truncate(u)),
182 @as(u32, @truncate(u >> 32)),182 @as(u32, @truncate(u >> 32)),
183 };183 };
184}184}
185fn splitValueBE64(val: i64) [2]u32 {185fn splitValueBE64(val: i64) [2]u32 {
186 const u = @as(u64, @bitCast(val));186 const u: u64 = @bitCast(val);
187 return [2]u32{187 return [2]u32{
188 @as(u32, @truncate(u >> 32)),188 @as(u32, @truncate(u >> 32)),
189 @as(u32, @truncate(u)),189 @as(u32, @truncate(u)),
190 };190 };
191}191}
192fn splitValue64(val: i64) [2]u32 {192fn splitValue64(val: i64) [2]u32 {
193 const u = @as(u64, @bitCast(val));193 const u: u64 = @bitCast(val);
194 switch (native_endian) {194 switch (native_endian) {
195 .Little => return [2]u32{195 .Little => return [2]u32{
196 @as(u32, @truncate(u)),196 @as(u32, @truncate(u)),
...@@ -467,7 +467,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {...@@ -467,7 +467,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
467}467}
468468
469pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {469pub 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 return syscall5(471 return syscall5(
472 .preadv,472 .preadv,
473 @as(usize, @bitCast(@as(isize, fd))),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,7 +482,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
482}482}
483483
484pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize {484pub 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 return syscall6(486 return syscall6(
487 .preadv2,487 .preadv2,
488 @as(usize, @bitCast(@as(isize, fd))),488 @as(usize, @bitCast(@as(isize, fd))),
...@@ -504,7 +504,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {...@@ -504,7 +504,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
504}504}
505505
506pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {506pub 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 return syscall5(508 return syscall5(
509 .pwritev,509 .pwritev,
510 @as(usize, @bitCast(@as(isize, fd))),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,7 +517,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) us
517}517}
518518
519pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize {519pub 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 return syscall6(521 return syscall6(
522 .pwritev2,522 .pwritev2,
523 @as(usize, @bitCast(@as(isize, fd))),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,7 +1507,7 @@ pub fn io_uring_prep_renameat(
1507 0,1507 0,
1508 @intFromPtr(new_path),1508 @intFromPtr(new_path),
1509 );1509 );
1510 sqe.len = @as(u32, @bitCast(new_dir_fd));1510 sqe.len = @bitCast(new_dir_fd);
1511 sqe.rw_flags = flags;1511 sqe.rw_flags = flags;
1512}1512}
15131513
...@@ -1562,7 +1562,7 @@ pub fn io_uring_prep_linkat(...@@ -1562,7 +1562,7 @@ pub fn io_uring_prep_linkat(
1562 0,1562 0,
1563 @intFromPtr(new_path),1563 @intFromPtr(new_path),
1564 );1564 );
1565 sqe.len = @as(u32, @bitCast(new_dir_fd));1565 sqe.len = @bitCast(new_dir_fd);
1566 sqe.rw_flags = flags;1566 sqe.rw_flags = flags;
1567}1567}
15681568
...@@ -1576,7 +1576,7 @@ pub fn io_uring_prep_provide_buffers(...@@ -1576,7 +1576,7 @@ pub fn io_uring_prep_provide_buffers(
1576) void {1576) void {
1577 const ptr = @intFromPtr(buffers);1577 const ptr = @intFromPtr(buffers);
1578 io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @as(i32, @intCast(num)), ptr, buffer_len, buffer_id);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}
15811581
1582pub fn io_uring_prep_remove_buffers(1582pub fn io_uring_prep_remove_buffers(
...@@ -1585,7 +1585,7 @@ pub fn io_uring_prep_remove_buffers(...@@ -1585,7 +1585,7 @@ pub fn io_uring_prep_remove_buffers(
1585 group_id: usize,1585 group_id: usize,
1586) void {1586) void {
1587 io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @as(i32, @intCast(num)), 0, 0, 0);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}
15901590
1591test "structs/offsets/entries" {1591test "structs/offsets/entries" {
lib/std/os/windows.zig+1-1
...@@ -1918,7 +1918,7 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {...@@ -1918,7 +1918,7 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
19181918
1919/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.1919/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.
1920pub fn nanoSecondsToFileTime(ns: i128) FILETIME {1920pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
1921 const adjusted = @as(u64, @bitCast(toSysTime(ns)));1921 const adjusted: u64 = @bitCast(toSysTime(ns));
1922 return FILETIME{1922 return FILETIME{
1923 .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)),1923 .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)),
1924 .dwLowDateTime = @as(u32, @truncate(adjusted)),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,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000;
1275pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;1275pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
1276pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;1276pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
12771277
1278pub const CW_USEDEFAULT = @as(i32, @bitCast(@as(u32, 0x80000000)));1278pub const CW_USEDEFAULT: i32 = @bitCast(@as(u32, 0x80000000));
12791279
1280pub 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;1280pub 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;
1281pub 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 {1281pub 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,8 +29,8 @@ fn next(self: *Pcg) u32 {
29 const l = self.s;29 const l = self.s;
30 self.s = l *% default_multiplier +% (self.i | 1);30 self.s = l *% default_multiplier +% (self.i | 1);
3131
32 const xor_s = @as(u32, @truncate(((l >> 18) ^ l) >> 27));32 const xor_s: u32 = @truncate(((l >> 18) ^ l) >> 27);
33 const rot = @as(u32, @intCast(l >> 59));33 const rot: u32 = @intCast(l >> 59);
3434
35 return (xor_s >> @as(u5, @intCast(rot))) | (xor_s << @as(u5, @intCast((0 -% rot) & 31)));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,8 +206,8 @@ pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
206/// If tagp is empty, the function returns a NaN whose significand is zero.206/// If tagp is empty, the function returns a NaN whose significand is zero.
207pub inline fn __builtin_nanf(tagp: []const u8) f32 {207pub inline fn __builtin_nanf(tagp: []const u8) f32 {
208 const parsed = std.fmt.parseUnsigned(c_ulong, tagp, 0) catch 0;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 bits209 const bits: u23 = @truncate(parsed); // single-precision float trailing significand is 23 bits
210 return @as(f32, @bitCast(@as(u32, bits) | std.math.qnan_u32));210 return @bitCast(@as(u32, bits) | std.math.qnan_u32);
211}211}
212212
213pub inline fn __builtin_huge_valf() f32 {213pub inline fn __builtin_huge_valf() f32 {
lib/std/zig/system/arm.zig+1-1
...@@ -183,7 +183,7 @@ pub const aarch64 = struct {...@@ -183,7 +183,7 @@ pub const aarch64 = struct {
183 blk: {183 blk: {
184 if (info.implementer == 0x41) {184 if (info.implementer == 0x41) {
185 // ARM Ltd.185 // ARM Ltd.
186 const special_bits = @as(u4, @truncate(info.part >> 8));186 const special_bits: u4 = @truncate(info.part >> 8);
187 if (special_bits == 0x0 or special_bits == 0x7) {187 if (special_bits == 0x0 or special_bits == 0x7) {
188 // TODO Variant and arch encoded differently.188 // TODO Variant and arch encoded differently.
189 break :blk;189 break :blk;