| author | |
| committer | |
| log | 17e3fcc3a5accb31b9ea15f64bd9e968245000c2 |
| tree | f55dbabfa350662f74d42deeda046d42e4802ff3 |
| parent | d65318847ff4f8eb9d6655b27bf769ea94c2c3d7 |
Importantly, fixes incorrectly annotated types in `__aeabi_?2h`.56 files changed, 325 insertions(+), 358 deletions(-)
lib/compiler_rt/addf3.zig+7-8| ... | @@ -9,7 +9,6 @@ const normalize = common.normalize; | ... | @@ -9,7 +9,6 @@ const normalize = common.normalize; |
| 9 | pub inline fn addf3(comptime T: type, a: T, b: T) T { | 9 | pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 10 | const bits = @typeInfo(T).Float.bits; | 10 | const bits = @typeInfo(T).Float.bits; |
| 11 | const Z = std.meta.Int(.unsigned, bits); | 11 | const Z = std.meta.Int(.unsigned, bits); |
| 12 | const S = std.meta.Int(.unsigned, bits - @clz(@as(Z, bits) - 1)); | ||
| 13 | 12 | ||
| 14 | const typeWidth = bits; | 13 | const typeWidth = bits; |
| 15 | const significandBits = math.floatMantissaBits(T); | 14 | const significandBits = math.floatMantissaBits(T); |
| ... | @@ -26,12 +25,12 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { | ... | @@ -26,12 +25,12 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 26 | const absMask = signBit - 1; | 25 | const absMask = signBit - 1; |
| 27 | const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit; | 26 | const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit; |
| 28 | 27 | ||
| 29 | var aRep = @as(Z, @bitCast(a)); | 28 | var aRep: Z = @bitCast(a); |
| 30 | var bRep = @as(Z, @bitCast(b)); | 29 | var bRep: Z = @bitCast(b); |
| 31 | const aAbs = aRep & absMask; | 30 | const aAbs = aRep & absMask; |
| 32 | const bAbs = bRep & absMask; | 31 | const bAbs = bRep & absMask; |
| 33 | 32 | ||
| 34 | const infRep = @as(Z, @bitCast(math.inf(T))); | 33 | const infRep: Z = @bitCast(math.inf(T)); |
| 35 | 34 | ||
| 36 | // Detect if a or b is zero, infinity, or NaN. | 35 | // Detect if a or b is zero, infinity, or NaN. |
| 37 | if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or | 36 | if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or |
| ... | @@ -104,8 +103,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { | ... | @@ -104,8 +103,8 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 104 | const @"align": u32 = @intCast(aExponent - bExponent); | 103 | const @"align": u32 = @intCast(aExponent - bExponent); |
| 105 | if (@"align" != 0) { | 104 | if (@"align" != 0) { |
| 106 | if (@"align" < typeWidth) { | 105 | if (@"align" < typeWidth) { |
| 107 | const sticky = if (bSignificand << @as(S, @intCast(typeWidth - @"align")) != 0) @as(Z, 1) else 0; | 106 | const sticky = if (bSignificand << @intCast(typeWidth - @"align") != 0) @as(Z, 1) else 0; |
| 108 | bSignificand = (bSignificand >> @as(S, @truncate(@"align"))) | sticky; | 107 | bSignificand = (bSignificand >> @truncate(@"align")) | sticky; |
| 109 | } else { | 108 | } else { |
| 110 | bSignificand = 1; // sticky; b is known to be non-zero. | 109 | bSignificand = 1; // sticky; b is known to be non-zero. |
| 111 | } | 110 | } |
| ... | @@ -119,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { | ... | @@ -119,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 119 | // and adjust the exponent: | 118 | // and adjust the exponent: |
| 120 | if (aSignificand < integerBit << 3) { | 119 | if (aSignificand < integerBit << 3) { |
| 121 | const shift = @as(i32, @intCast(@clz(aSignificand))) - @as(i32, @intCast(@clz(integerBit << 3))); | 120 | const shift = @as(i32, @intCast(@clz(aSignificand))) - @as(i32, @intCast(@clz(integerBit << 3))); |
| 122 | aSignificand <<= @as(S, @intCast(shift)); | 121 | aSignificand <<= @intCast(shift); |
| 123 | aExponent -= shift; | 122 | aExponent -= shift; |
| 124 | } | 123 | } |
| 125 | } else { // addition | 124 | } else { // addition |
| ... | @@ -140,7 +139,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { | ... | @@ -140,7 +139,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 140 | if (aExponent <= 0) { | 139 | if (aExponent <= 0) { |
| 141 | // Result is denormal; the exponent and round/sticky bits are zero. | 140 | // 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. | 141 | // All we need to do is shift the significand and apply the correct sign. |
| 143 | aSignificand >>= @as(S, @intCast(4 - aExponent)); | 142 | aSignificand >>= @intCast(4 - aExponent); |
| 144 | return @bitCast(resultSign | aSignificand); | 143 | return @bitCast(resultSign | aSignificand); |
| 145 | } | 144 | } |
| 146 | 145 |
lib/compiler_rt/ceil.zig+1-1| ... | @@ -43,7 +43,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 { | ... | @@ -43,7 +43,7 @@ pub fn ceilf(x: f32) callconv(.C) f32 { |
| 43 | if (e >= 23) { | 43 | if (e >= 23) { |
| 44 | return x; | 44 | return x; |
| 45 | } else if (e >= 0) { | 45 | } else if (e >= 0) { |
| 46 | m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e)); | 46 | m = @as(u32, 0x007FFFFF) >> @intCast(e); |
| 47 | if (u & m == 0) { | 47 | if (u & m == 0) { |
| 48 | return x; | 48 | return x; |
| 49 | } | 49 | } |
lib/compiler_rt/clear_cache.zig+2-2| ... | @@ -102,7 +102,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { | ... | @@ -102,7 +102,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 102 | // If CTR_EL0.IDC is set, data cache cleaning to the point of unification | 102 | // If CTR_EL0.IDC is set, data cache cleaning to the point of unification |
| 103 | // is not required for instruction to data coherence. | 103 | // is not required for instruction to data coherence. |
| 104 | if (((ctr_el0 >> 28) & 0x1) == 0x0) { | 104 | if (((ctr_el0 >> 28) & 0x1) == 0x0) { |
| 105 | const dcache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 16) & 15)); | 105 | const dcache_line_size = @as(usize, 4) << @intCast((ctr_el0 >> 16) & 15); |
| 106 | addr = start & ~(dcache_line_size - 1); | 106 | addr = start & ~(dcache_line_size - 1); |
| 107 | while (addr < end) : (addr += dcache_line_size) { | 107 | while (addr < end) : (addr += dcache_line_size) { |
| 108 | asm volatile ("dc cvau, %[addr]" | 108 | asm volatile ("dc cvau, %[addr]" |
| ... | @@ -115,7 +115,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { | ... | @@ -115,7 +115,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 115 | // If CTR_EL0.DIC is set, instruction cache invalidation to the point of | 115 | // If CTR_EL0.DIC is set, instruction cache invalidation to the point of |
| 116 | // unification is not required for instruction to data coherence. | 116 | // unification is not required for instruction to data coherence. |
| 117 | if (((ctr_el0 >> 29) & 0x1) == 0x0) { | 117 | if (((ctr_el0 >> 29) & 0x1) == 0x0) { |
| 118 | const icache_line_size: usize = @as(usize, 4) << @as(u6, @intCast((ctr_el0 >> 0) & 15)); | 118 | const icache_line_size = @as(usize, 4) << @intCast((ctr_el0 >> 0) & 15); |
| 119 | addr = start & ~(icache_line_size - 1); | 119 | addr = start & ~(icache_line_size - 1); |
| 120 | while (addr < end) : (addr += icache_line_size) { | 120 | while (addr < end) : (addr += icache_line_size) { |
| 121 | asm volatile ("ic ivau, %[addr]" | 121 | asm volatile ("ic ivau, %[addr]" |
lib/compiler_rt/common.zig+8-8| ... | @@ -102,14 +102,14 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -102,14 +102,14 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 102 | u16 => { | 102 | u16 => { |
| 103 | // 16x16 --> 32 bit multiply | 103 | // 16x16 --> 32 bit multiply |
| 104 | const product = @as(u32, a) * @as(u32, b); | 104 | const product = @as(u32, a) * @as(u32, b); |
| 105 | hi.* = @as(u16, @intCast(product >> 16)); | 105 | hi.* = @intCast(product >> 16); |
| 106 | lo.* = @as(u16, @truncate(product)); | 106 | lo.* = @truncate(product); |
| 107 | }, | 107 | }, |
| 108 | u32 => { | 108 | u32 => { |
| 109 | // 32x32 --> 64 bit multiply | 109 | // 32x32 --> 64 bit multiply |
| 110 | const product = @as(u64, a) * @as(u64, b); | 110 | const product = @as(u64, a) * @as(u64, b); |
| 111 | hi.* = @as(u32, @truncate(product >> 32)); | 111 | hi.* = @truncate(product >> 32); |
| 112 | lo.* = @as(u32, @truncate(product)); | 112 | lo.* = @truncate(product); |
| 113 | }, | 113 | }, |
| 114 | u64 => { | 114 | u64 => { |
| 115 | const S = struct { | 115 | const S = struct { |
| ... | @@ -136,9 +136,9 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -136,9 +136,9 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 136 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; | 136 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; |
| 137 | }, | 137 | }, |
| 138 | u128 => { | 138 | u128 => { |
| 139 | const Word_LoMask = @as(u64, 0x00000000ffffffff); | 139 | const Word_LoMask: u64 = 0x00000000ffffffff; |
| 140 | const Word_HiMask = @as(u64, 0xffffffff00000000); | 140 | const Word_HiMask: u64 = 0xffffffff00000000; |
| 141 | const Word_FullMask = @as(u64, 0xffffffffffffffff); | 141 | const Word_FullMask: u64 = 0xffffffffffffffff; |
| 142 | const S = struct { | 142 | const S = struct { |
| 143 | fn Word_1(x: u128) u64 { | 143 | fn Word_1(x: u128) u64 { |
| 144 | return @as(u32, @truncate(x >> 96)); | 144 | return @as(u32, @truncate(x >> 96)); |
| ... | @@ -229,7 +229,7 @@ pub inline fn fneg(a: anytype) @TypeOf(a) { | ... | @@ -229,7 +229,7 @@ pub inline fn fneg(a: anytype) @TypeOf(a) { |
| 229 | } }); | 229 | } }); |
| 230 | const sign_bit_mask = @as(U, 1) << (bits - 1); | 230 | const sign_bit_mask = @as(U, 1) << (bits - 1); |
| 231 | const negated = @as(U, @bitCast(a)) ^ sign_bit_mask; | 231 | const negated = @as(U, @bitCast(a)) ^ sign_bit_mask; |
| 232 | return @as(F, @bitCast(negated)); | 232 | return @bitCast(negated); |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | /// Allows to access underlying bits as two equally sized lower and higher | 235 | /// Allows to access underlying bits as two equally sized lower and higher |
lib/compiler_rt/cos.zig+1-1| ... | @@ -25,7 +25,7 @@ comptime { | ... | @@ -25,7 +25,7 @@ comptime { |
| 25 | 25 | ||
| 26 | pub fn __cosh(a: f16) callconv(.C) f16 { | 26 | pub fn __cosh(a: f16) callconv(.C) f16 { |
| 27 | // TODO: more efficient implementation | 27 | // TODO: more efficient implementation |
| 28 | return @as(f16, @floatCast(cosf(a))); | 28 | return @floatCast(cosf(a)); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | pub fn cosf(x: f32) callconv(.C) f32 { | 31 | pub fn cosf(x: f32) callconv(.C) f32 { |
lib/compiler_rt/count0bits.zig+1-6| ... | @@ -203,12 +203,7 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 { | ... | @@ -203,12 +203,7 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 { |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | inline fn ffsXi2(comptime T: type, a: T) i32 { | 205 | inline fn ffsXi2(comptime T: type, a: T) i32 { |
| 206 | var x = switch (@bitSizeOf(T)) { | 206 | var x: std.meta.Int(.unsigned, @typeInfo(T).Int.bits) = @bitCast(a); |
| 207 | 32 => @as(u32, @bitCast(a)), | ||
| 208 | 64 => @as(u64, @bitCast(a)), | ||
| 209 | 128 => @as(u128, @bitCast(a)), | ||
| 210 | else => unreachable, | ||
| 211 | }; | ||
| 212 | var n: T = 1; | 207 | var n: T = 1; |
| 213 | // adapted from Number of trailing zeroes (see ctzXi2) | 208 | // adapted from Number of trailing zeroes (see ctzXi2) |
| 214 | var mask: @TypeOf(x) = std.math.maxInt(@TypeOf(x)); | 209 | var mask: @TypeOf(x) = std.math.maxInt(@TypeOf(x)); |
lib/compiler_rt/divti3.zig+2-2| ... | @@ -21,7 +21,7 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 { | ... | @@ -21,7 +21,7 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 { |
| 21 | const v128 = @Vector(2, u64); | 21 | const v128 = @Vector(2, u64); |
| 22 | 22 | ||
| 23 | fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { | 23 | fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { |
| 24 | return @as(v128, @bitCast(div(@as(i128, @bitCast(a)), @as(i128, @bitCast(b))))); | 24 | return @bitCast(div(@bitCast(a), @bitCast(b))); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | inline fn div(a: i128, b: i128) i128 { | 27 | inline fn div(a: i128, b: i128) i128 { |
| ... | @@ -31,7 +31,7 @@ inline fn div(a: i128, b: i128) i128 { | ... | @@ -31,7 +31,7 @@ inline fn div(a: i128, b: i128) i128 { |
| 31 | const an = (a ^ s_a) -% s_a; | 31 | const an = (a ^ s_a) -% s_a; |
| 32 | const bn = (b ^ s_b) -% s_b; | 32 | const bn = (b ^ s_b) -% s_b; |
| 33 | 33 | ||
| 34 | const r = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), null); | 34 | const r = udivmod(u128, @bitCast(an), @bitCast(bn), null); |
| 35 | const s = s_a ^ s_b; | 35 | const s = s_a ^ s_b; |
| 36 | return (@as(i128, @bitCast(r)) ^ s) -% s; | 36 | return (@as(i128, @bitCast(r)) ^ s) -% s; |
| 37 | } | 37 | } |
lib/compiler_rt/divxf3.zig+6-6| ... | @@ -164,8 +164,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -164,8 +164,8 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 164 | // exponent accordingly. | 164 | // exponent accordingly. |
| 165 | var quotient: u64 = if (quotient128 < (integerBit << 1)) b: { | 165 | var quotient: u64 = if (quotient128 < (integerBit << 1)) b: { |
| 166 | quotientExponent -= 1; | 166 | quotientExponent -= 1; |
| 167 | break :b @as(u64, @intCast(quotient128)); | 167 | break :b @intCast(quotient128); |
| 168 | } else @as(u64, @intCast(quotient128 >> 1)); | 168 | } else @intCast(quotient128 >> 1); |
| 169 | 169 | ||
| 170 | // We are going to compute a residual of the form | 170 | // We are going to compute a residual of the form |
| 171 | // | 171 | // |
| ... | @@ -182,18 +182,18 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -182,18 +182,18 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 182 | const writtenExponent = quotientExponent + exponentBias; | 182 | const writtenExponent = quotientExponent + exponentBias; |
| 183 | if (writtenExponent >= maxExponent) { | 183 | if (writtenExponent >= maxExponent) { |
| 184 | // If we have overflowed the exponent, return infinity. | 184 | // If we have overflowed the exponent, return infinity. |
| 185 | return @as(T, @bitCast(infRep | quotientSign)); | 185 | return @bitCast(infRep | quotientSign); |
| 186 | } else if (writtenExponent < 1) { | 186 | } else if (writtenExponent < 1) { |
| 187 | if (writtenExponent == 0) { | 187 | if (writtenExponent == 0) { |
| 188 | // Check whether the rounded result is normal. | 188 | // Check whether the rounded result is normal. |
| 189 | if (residual > (bSignificand >> 1)) { // round | 189 | if (residual > (bSignificand >> 1)) { // round |
| 190 | if (quotient == (integerBit - 1)) // If the rounded result is normal, return it | 190 | if (quotient == (integerBit - 1)) // If the rounded result is normal, return it |
| 191 | return @as(T, @bitCast(@as(Z, @bitCast(std.math.floatMin(T))) | quotientSign)); | 191 | return @bitCast(@as(Z, @bitCast(std.math.floatMin(T))) | quotientSign); |
| 192 | } | 192 | } |
| 193 | } | 193 | } |
| 194 | // Flush denormals to zero. In the future, it would be nice to add | 194 | // Flush denormals to zero. In the future, it would be nice to add |
| 195 | // code to round them correctly. | 195 | // code to round them correctly. |
| 196 | return @as(T, @bitCast(quotientSign)); | 196 | return @bitCast(quotientSign); |
| 197 | } else { | 197 | } else { |
| 198 | const round = @intFromBool(residual > (bSignificand >> 1)); | 198 | const round = @intFromBool(residual > (bSignificand >> 1)); |
| 199 | // Insert the exponent | 199 | // Insert the exponent |
| ... | @@ -201,7 +201,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -201,7 +201,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { |
| 201 | // Round | 201 | // Round |
| 202 | absResult +%= round; | 202 | absResult +%= round; |
| 203 | // Insert the sign and return | 203 | // Insert the sign and return |
| 204 | return @as(T, @bitCast(absResult | quotientSign | integerBit)); | 204 | return @bitCast(absResult | quotientSign | integerBit); |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | 207 |
lib/compiler_rt/emutls.zig+6-6| ... | @@ -52,19 +52,19 @@ const simple_allocator = struct { | ... | @@ -52,19 +52,19 @@ const simple_allocator = struct { |
| 52 | abort(); | 52 | abort(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | return @as([*]u8, @ptrCast(aligned_ptr)); | 55 | return @ptrCast(aligned_ptr); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /// Resize a slice. | 58 | /// Resize a slice. |
| 59 | pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T { | 59 | pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T { |
| 60 | var c_ptr: *anyopaque = @as(*anyopaque, @ptrCast(slice.ptr)); | 60 | var c_ptr: *anyopaque = @ptrCast(slice.ptr); |
| 61 | var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort())); | 61 | var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort())); |
| 62 | return new_array[0..len]; | 62 | return new_array[0..len]; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /// Free a memory chunk allocated with simple_allocator. | 65 | /// Free a memory chunk allocated with simple_allocator. |
| 66 | pub fn free(ptr: anytype) void { | 66 | pub fn free(ptr: anytype) void { |
| 67 | std.c.free(@as(*anyopaque, @ptrCast(ptr))); | 67 | std.c.free(@ptrCast(ptr)); |
| 68 | } | 68 | } |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| ... | @@ -138,7 +138,7 @@ const ObjectArray = struct { | ... | @@ -138,7 +138,7 @@ const ObjectArray = struct { |
| 138 | @memset(data[0..size], 0); | 138 | @memset(data[0..size], 0); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | self.slots[index] = @as(*anyopaque, @ptrCast(data)); | 141 | self.slots[index] = @ptrCast(data); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | return self.slots[index].?; | 144 | return self.slots[index].?; |
| ... | @@ -178,7 +178,7 @@ const current_thread_storage = struct { | ... | @@ -178,7 +178,7 @@ const current_thread_storage = struct { |
| 178 | 178 | ||
| 179 | /// Set casted thread specific value. | 179 | /// Set casted thread specific value. |
| 180 | fn setspecific(new: ?*ObjectArray) void { | 180 | fn setspecific(new: ?*ObjectArray) void { |
| 181 | if (std.c.pthread_setspecific(current_thread_storage.key, @as(*anyopaque, @ptrCast(new))) != 0) { | 181 | if (std.c.pthread_setspecific(current_thread_storage.key, @ptrCast(new)) != 0) { |
| 182 | abort(); | 182 | abort(); |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| ... | @@ -278,7 +278,7 @@ const emutls_control = extern struct { | ... | @@ -278,7 +278,7 @@ const emutls_control = extern struct { |
| 278 | .size = @sizeOf(T), | 278 | .size = @sizeOf(T), |
| 279 | .alignment = @alignOf(T), | 279 | .alignment = @alignOf(T), |
| 280 | .object = .{ .index = 0 }, | 280 | .object = .{ .index = 0 }, |
| 281 | .default_value = @as(?*const anyopaque, @ptrCast(default_value)), | 281 | .default_value = @ptrCast(default_value), |
| 282 | }; | 282 | }; |
| 283 | } | 283 | } |
| 284 | 284 |
lib/compiler_rt/exp.zig+3-3| ... | @@ -27,7 +27,7 @@ comptime { | ... | @@ -27,7 +27,7 @@ comptime { |
| 27 | 27 | ||
| 28 | pub fn __exph(a: f16) callconv(.C) f16 { | 28 | pub fn __exph(a: f16) callconv(.C) f16 { |
| 29 | // TODO: more efficient implementation | 29 | // TODO: more efficient implementation |
| 30 | return @as(f16, @floatCast(expf(a))); | 30 | return @floatCast(expf(a)); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | pub fn expf(x_: f32) callconv(.C) f32 { | 33 | pub fn expf(x_: f32) callconv(.C) f32 { |
| ... | @@ -74,7 +74,7 @@ pub fn expf(x_: f32) callconv(.C) f32 { | ... | @@ -74,7 +74,7 @@ pub fn expf(x_: f32) callconv(.C) f32 { |
| 74 | if (hx > 0x3EB17218) { | 74 | if (hx > 0x3EB17218) { |
| 75 | // |x| > 1.5 * ln2 | 75 | // |x| > 1.5 * ln2 |
| 76 | if (hx > 0x3F851592) { | 76 | if (hx > 0x3F851592) { |
| 77 | k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]); | 77 | k = @intFromFloat(invln2 * x + half[@intCast(sign)]); |
| 78 | } else { | 78 | } else { |
| 79 | k = 1 - sign - sign; | 79 | k = 1 - sign - sign; |
| 80 | } | 80 | } |
| ... | @@ -157,7 +157,7 @@ pub fn exp(x_: f64) callconv(.C) f64 { | ... | @@ -157,7 +157,7 @@ pub fn exp(x_: f64) callconv(.C) f64 { |
| 157 | if (hx > 0x3FD62E42) { | 157 | if (hx > 0x3FD62E42) { |
| 158 | // |x| >= 1.5 * ln2 | 158 | // |x| >= 1.5 * ln2 |
| 159 | if (hx > 0x3FF0A2B2) { | 159 | if (hx > 0x3FF0A2B2) { |
| 160 | k = @intFromFloat(invln2 * x + half[@as(usize, @intCast(sign))]); | 160 | k = @intFromFloat(invln2 * x + half[@intCast(sign)]); |
| 161 | } else { | 161 | } else { |
| 162 | k = 1 - sign - sign; | 162 | k = 1 - sign - sign; |
| 163 | } | 163 | } |
lib/compiler_rt/exp2.zig+4-4| ... | @@ -27,7 +27,7 @@ comptime { | ... | @@ -27,7 +27,7 @@ comptime { |
| 27 | 27 | ||
| 28 | pub fn __exp2h(x: f16) callconv(.C) f16 { | 28 | pub fn __exp2h(x: f16) callconv(.C) f16 { |
| 29 | // TODO: more efficient implementation | 29 | // TODO: more efficient implementation |
| 30 | return @as(f16, @floatCast(exp2f(x))); | 30 | return @floatCast(exp2f(x)); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | pub fn exp2f(x: f32) callconv(.C) f32 { | 33 | pub fn exp2f(x: f32) callconv(.C) f32 { |
| ... | @@ -81,7 +81,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 { | ... | @@ -81,7 +81,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 { |
| 81 | uf -= redux; | 81 | uf -= redux; |
| 82 | 82 | ||
| 83 | const z: f64 = x - uf; | 83 | const z: f64 = x - uf; |
| 84 | var r: f64 = exp2ft[@as(usize, @intCast(i_0))]; | 84 | var r: f64 = exp2ft[@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 @floatCast(r * uk); | 87 | return @floatCast(r * uk); |
| ... | @@ -149,8 +149,8 @@ pub fn exp2(x: f64) callconv(.C) f64 { | ... | @@ -149,8 +149,8 @@ pub fn exp2(x: f64) callconv(.C) f64 { |
| 149 | 149 | ||
| 150 | // r = exp2(y) = exp2t[i_0] * p(z - eps[i]) | 150 | // r = exp2(y) = exp2t[i_0] * p(z - eps[i]) |
| 151 | var z: f64 = x - uf; | 151 | var z: f64 = x - uf; |
| 152 | const t: f64 = exp2dt[@as(usize, @intCast(2 * i_0))]; | 152 | const t: f64 = exp2dt[@intCast(2 * i_0)]; |
| 153 | z -= exp2dt[@as(usize, @intCast(2 * i_0 + 1))]; | 153 | z -= exp2dt[@intCast(2 * i_0 + 1)]; |
| 154 | const r: f64 = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5)))); | 154 | const r: f64 = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5)))); |
| 155 | 155 | ||
| 156 | return math.scalbn(r, ik); | 156 | return math.scalbn(r, ik); |
lib/compiler_rt/extendf.zig+6-11| ... | @@ -9,7 +9,6 @@ pub inline fn extendf( | ... | @@ -9,7 +9,6 @@ pub inline fn extendf( |
| 9 | const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits); | 9 | const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits); |
| 10 | const srcSigBits = std.math.floatMantissaBits(src_t); | 10 | const srcSigBits = std.math.floatMantissaBits(src_t); |
| 11 | const dstSigBits = std.math.floatMantissaBits(dst_t); | 11 | const dstSigBits = std.math.floatMantissaBits(dst_t); |
| 12 | const DstShift = std.math.Log2Int(dst_rep_t); | ||
| 13 | 12 | ||
| 14 | // Various constants whose values follow from the type parameters. | 13 | // Various constants whose values follow from the type parameters. |
| 15 | // Any reasonable optimizer will fold and propagate all of these. | 14 | // Any reasonable optimizer will fold and propagate all of these. |
| ... | @@ -56,9 +55,8 @@ pub inline fn extendf( | ... | @@ -56,9 +55,8 @@ pub inline fn extendf( |
| 56 | // a is denormal. | 55 | // a is denormal. |
| 57 | // renormalize the significand and clear the leading bit, then insert | 56 | // renormalize the significand and clear the leading bit, then insert |
| 58 | // the correct adjusted exponent in the destination type. | 57 | // the correct adjusted exponent in the destination type. |
| 59 | const scale: u32 = @clz(aAbs) - | 58 | const scale: u32 = @clz(aAbs) - @clz(@as(src_rep_t, srcMinNormal)); |
| 60 | @clz(@as(src_rep_t, srcMinNormal)); | 59 | absResult = @as(dst_rep_t, aAbs) << @intCast(dstSigBits - srcSigBits + scale); |
| 61 | absResult = @as(dst_rep_t, aAbs) << @as(DstShift, @intCast(dstSigBits - srcSigBits + scale)); | ||
| 62 | absResult ^= dstMinNormal; | 60 | absResult ^= dstMinNormal; |
| 63 | const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; | 61 | const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; |
| 64 | absResult |= @as(dst_rep_t, @intCast(resultExponent)) << dstSigBits; | 62 | absResult |= @as(dst_rep_t, @intCast(resultExponent)) << dstSigBits; |
| ... | @@ -69,7 +67,7 @@ pub inline fn extendf( | ... | @@ -69,7 +67,7 @@ pub inline fn extendf( |
| 69 | 67 | ||
| 70 | // Apply the signbit to (dst_t)abs(a). | 68 | // Apply the signbit to (dst_t)abs(a). |
| 71 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits); | 69 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits); |
| 72 | return @as(dst_t, @bitCast(result)); | 70 | return @bitCast(result); |
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(src_t).Float.bits)) f80 { | 73 | pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(src_t).Float.bits)) f80 { |
| ... | @@ -92,8 +90,6 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI | ... | @@ -92,8 +90,6 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI |
| 92 | const src_qnan = 1 << (src_sig_bits - 1); | 90 | const src_qnan = 1 << (src_sig_bits - 1); |
| 93 | const src_nan_code = src_qnan - 1; | 91 | const src_nan_code = src_qnan - 1; |
| 94 | 92 | ||
| 95 | const SrcShift = std.math.Log2Int(src_rep_t); | ||
| 96 | |||
| 97 | var dst: std.math.F80 = undefined; | 93 | var dst: std.math.F80 = undefined; |
| 98 | 94 | ||
| 99 | // Break a into a sign and representation of the absolute value | 95 | // Break a into a sign and representation of the absolute value |
| ... | @@ -121,12 +117,11 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI | ... | @@ -121,12 +117,11 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI |
| 121 | // a is denormal. | 117 | // a is denormal. |
| 122 | // renormalize the significand and clear the leading bit, then insert | 118 | // renormalize the significand and clear the leading bit, then insert |
| 123 | // the correct adjusted exponent in the destination type. | 119 | // the correct adjusted exponent in the destination type. |
| 124 | const scale: u16 = @clz(a_abs) - | 120 | const scale: u16 = @clz(a_abs) - @clz(@as(src_rep_t, src_min_normal)); |
| 125 | @clz(@as(src_rep_t, src_min_normal)); | ||
| 126 | 121 | ||
| 127 | dst.fraction = @as(u64, a_abs) << @as(u6, @intCast(dst_sig_bits - src_sig_bits + scale)); | 122 | dst.fraction = @as(u64, a_abs) << @intCast(dst_sig_bits - src_sig_bits + scale); |
| 128 | dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers | 123 | dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers |
| 129 | dst.exp = @truncate(a_abs >> @as(SrcShift, @intCast(src_sig_bits - scale))); | 124 | dst.exp = @truncate(a_abs >> @intCast(src_sig_bits - scale)); |
| 130 | dst.exp ^= 1; | 125 | dst.exp ^= 1; |
| 131 | dst.exp |= dst_exp_bias - src_exp_bias - scale + 1; | 126 | dst.exp |= dst_exp_bias - src_exp_bias - scale + 1; |
| 132 | } else { | 127 | } else { |
lib/compiler_rt/extendxftf2.zig+2-2| ... | @@ -39,12 +39,12 @@ fn __extendxftf2(a: f80) callconv(.C) f128 { | ... | @@ -39,12 +39,12 @@ fn __extendxftf2(a: f80) callconv(.C) f128 { |
| 39 | // renormalize the significand and clear the leading bit and integer part, | 39 | // renormalize the significand and clear the leading bit and integer part, |
| 40 | // then insert the correct adjusted exponent in the destination type. | 40 | // then insert the correct adjusted exponent in the destination type. |
| 41 | const scale: u32 = @clz(a_rep.fraction); | 41 | const scale: u32 = @clz(a_rep.fraction); |
| 42 | abs_result = @as(u128, a_rep.fraction) << @as(u7, @intCast(dst_sig_bits - src_sig_bits + scale + 1)); | 42 | abs_result = @as(u128, a_rep.fraction) << @intCast(dst_sig_bits - src_sig_bits + scale + 1); |
| 43 | abs_result ^= dst_min_normal; | 43 | abs_result ^= dst_min_normal; |
| 44 | abs_result |= @as(u128, scale + 1) << dst_sig_bits; | 44 | abs_result |= @as(u128, scale + 1) << dst_sig_bits; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | // Apply the signbit to (dst_t)abs(a). | 47 | // Apply the signbit to (dst_t)abs(a). |
| 48 | const result: u128 align(@alignOf(f128)) = abs_result | @as(u128, sign) << (dst_bits - 16); | 48 | const result: u128 align(@alignOf(f128)) = abs_result | @as(u128, sign) << (dst_bits - 16); |
| 49 | return @as(f128, @bitCast(result)); | 49 | return @bitCast(result); |
| 50 | } | 50 | } |
lib/compiler_rt/fabs.zig+2-2| ... | @@ -51,7 +51,7 @@ pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble { | ... | @@ -51,7 +51,7 @@ pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble { |
| 51 | inline fn generic_fabs(x: anytype) @TypeOf(x) { | 51 | inline fn generic_fabs(x: anytype) @TypeOf(x) { |
| 52 | const T = @TypeOf(x); | 52 | const T = @TypeOf(x); |
| 53 | const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); | 53 | const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); |
| 54 | const float_bits = @as(TBits, @bitCast(x)); | 54 | const float_bits: TBits = @bitCast(x); |
| 55 | const remove_sign = ~@as(TBits, 0) >> 1; | 55 | const remove_sign = ~@as(TBits, 0) >> 1; |
| 56 | return @as(T, @bitCast(float_bits & remove_sign)); | 56 | return @bitCast(float_bits & remove_sign); |
| 57 | } | 57 | } |
lib/compiler_rt/fixdfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixdfti(a: f64) callconv(.C) i128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixdfti(a: f64) callconv(.C) i128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 { | 21 | fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(i128, a))); | 22 | return @bitCast(intFromFloat(i128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixhfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixhfti(a: f16) callconv(.C) i128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixhfti(a: f16) callconv(.C) i128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 { | 21 | fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(i128, a))); | 22 | return @bitCast(intFromFloat(i128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixsfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixsfti(a: f32) callconv(.C) i128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixsfti(a: f32) callconv(.C) i128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 { | 21 | fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(i128, a))); | 22 | return @bitCast(intFromFloat(i128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixtfti.zig+1-1| ... | @@ -21,5 +21,5 @@ pub fn __fixtfti(a: f128) callconv(.C) i128 { | ... | @@ -21,5 +21,5 @@ pub fn __fixtfti(a: f128) callconv(.C) i128 { |
| 21 | const v2u64 = @Vector(2, u64); | 21 | const v2u64 = @Vector(2, u64); |
| 22 | 22 | ||
| 23 | fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 { | 23 | fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 { |
| 24 | return @as(v2u64, @bitCast(intFromFloat(i128, a))); | 24 | return @bitCast(intFromFloat(i128, a)); |
| 25 | } | 25 | } |
lib/compiler_rt/fixunsdfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixunsdfti(a: f64) callconv(.C) u128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixunsdfti(a: f64) callconv(.C) u128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 { | 21 | fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(u128, a))); | 22 | return @bitCast(intFromFloat(u128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixunshfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixunshfti(a: f16) callconv(.C) u128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixunshfti(a: f16) callconv(.C) u128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 { | 21 | fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(u128, a))); | 22 | return @bitCast(intFromFloat(u128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixunssfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixunssfti(a: f32) callconv(.C) u128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixunssfti(a: f32) callconv(.C) u128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 { | 21 | fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(u128, a))); | 22 | return @bitCast(intFromFloat(u128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixunstfti.zig+1-1| ... | @@ -21,5 +21,5 @@ pub fn __fixunstfti(a: f128) callconv(.C) u128 { | ... | @@ -21,5 +21,5 @@ pub fn __fixunstfti(a: f128) callconv(.C) u128 { |
| 21 | const v2u64 = @Vector(2, u64); | 21 | const v2u64 = @Vector(2, u64); |
| 22 | 22 | ||
| 23 | fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 { | 23 | fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 { |
| 24 | return @as(v2u64, @bitCast(intFromFloat(u128, a))); | 24 | return @bitCast(intFromFloat(u128, a)); |
| 25 | } | 25 | } |
lib/compiler_rt/fixunsxfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixunsxfti(a: f80) callconv(.C) u128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixunsxfti(a: f80) callconv(.C) u128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 { | 21 | fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(u128, a))); | 22 | return @bitCast(intFromFloat(u128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/fixxfti.zig+1-1| ... | @@ -19,5 +19,5 @@ pub fn __fixxfti(a: f80) callconv(.C) i128 { | ... | @@ -19,5 +19,5 @@ pub fn __fixxfti(a: f80) callconv(.C) i128 { |
| 19 | const v2u64 = @Vector(2, u64); | 19 | const v2u64 = @Vector(2, u64); |
| 20 | 20 | ||
| 21 | fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v2u64 { | 21 | fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v2u64 { |
| 22 | return @as(v2u64, @bitCast(intFromFloat(i128, a))); | 22 | return @bitCast(intFromFloat(i128, a)); |
| 23 | } | 23 | } |
lib/compiler_rt/float_from_int.zig+4-4| ... | @@ -28,10 +28,10 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { | ... | @@ -28,10 +28,10 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { |
| 28 | const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp)); | 28 | const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp)); |
| 29 | 29 | ||
| 30 | // Shift up result to line up with the significand - no rounding required | 30 | // Shift up result to line up with the significand - no rounding required |
| 31 | result = (@as(uT, @intCast(abs_val)) << shift_amt); | 31 | result = @as(uT, @intCast(abs_val)) << shift_amt; |
| 32 | result ^= implicit_bit; // Remove implicit integer bit | 32 | result ^= implicit_bit; // Remove implicit integer bit |
| 33 | } else { | 33 | } else { |
| 34 | var shift_amt = @as(math.Log2Int(Z), @intCast(exp - fractional_bits)); | 34 | var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits); |
| 35 | const exact_tie: bool = @ctz(abs_val) == shift_amt - 1; | 35 | const exact_tie: bool = @ctz(abs_val) == shift_amt - 1; |
| 36 | 36 | ||
| 37 | // Shift down result and remove implicit integer bit | 37 | // Shift down result and remove implicit integer bit |
| ... | @@ -43,14 +43,14 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { | ... | @@ -43,14 +43,14 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { |
| 43 | 43 | ||
| 44 | // Compute exponent | 44 | // Compute exponent |
| 45 | if ((int_bits > max_exp) and (exp > max_exp)) // If exponent too large, overflow to infinity | 45 | if ((int_bits > max_exp) and (exp > max_exp)) // If exponent too large, overflow to infinity |
| 46 | return @as(T, @bitCast(sign_bit | @as(uT, @bitCast(inf)))); | 46 | return @bitCast(sign_bit | @as(uT, @bitCast(inf))); |
| 47 | 47 | ||
| 48 | result += (@as(uT, exp) + exp_bias) << math.floatMantissaBits(T); | 48 | result += (@as(uT, exp) + exp_bias) << math.floatMantissaBits(T); |
| 49 | 49 | ||
| 50 | // If the result included a carry, we need to restore the explicit integer bit | 50 | // If the result included a carry, we need to restore the explicit integer bit |
| 51 | if (T == f80) result |= 1 << fractional_bits; | 51 | if (T == f80) result |= 1 << fractional_bits; |
| 52 | 52 | ||
| 53 | return @as(T, @bitCast(sign_bit | result)); | 53 | return @bitCast(sign_bit | result); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | test { | 56 | test { |
lib/compiler_rt/float_from_int_test.zig+22-22| ... | @@ -43,7 +43,7 @@ test "floatsisf" { | ... | @@ -43,7 +43,7 @@ test "floatsisf" { |
| 43 | try test__floatsisf(1, 0x3f800000); | 43 | try test__floatsisf(1, 0x3f800000); |
| 44 | try test__floatsisf(-1, 0xbf800000); | 44 | try test__floatsisf(-1, 0xbf800000); |
| 45 | try test__floatsisf(0x7FFFFFFF, 0x4f000000); | 45 | try test__floatsisf(0x7FFFFFFF, 0x4f000000); |
| 46 | try test__floatsisf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xcf000000); | 46 | try test__floatsisf(@bitCast(@as(u32, @intCast(0x80000000))), 0xcf000000); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | test "floatunsisf" { | 49 | test "floatunsisf" { |
| ... | @@ -72,10 +72,10 @@ test "floatdisf" { | ... | @@ -72,10 +72,10 @@ test "floatdisf" { |
| 72 | try test__floatdisf(-2, -2.0); | 72 | try test__floatdisf(-2, -2.0); |
| 73 | try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | 73 | try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); |
| 74 | try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | 74 | try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); |
| 75 | try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000008000000000))), -0x1.FFFFFEp+62); | 75 | try test__floatdisf(@bitCast(@as(u64, 0x8000008000000000)), -0x1.FFFFFEp+62); |
| 76 | try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000010000000000))), -0x1.FFFFFCp+62); | 76 | try test__floatdisf(@bitCast(@as(u64, 0x8000010000000000)), -0x1.FFFFFCp+62); |
| 77 | try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), -0x1.000000p+63); | 77 | try test__floatdisf(@bitCast(@as(u64, 0x8000000000000000)), -0x1.000000p+63); |
| 78 | try test__floatdisf(@as(i64, @bitCast(@as(u64, 0x8000000000000001))), -0x1.000000p+63); | 78 | try test__floatdisf(@bitCast(@as(u64, 0x8000000000000001)), -0x1.000000p+63); |
| 79 | try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | 79 | try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); |
| 80 | try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | 80 | try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); |
| 81 | try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | 81 | try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); |
| ... | @@ -228,7 +228,7 @@ test "floatuntisf" { | ... | @@ -228,7 +228,7 @@ test "floatuntisf" { |
| 228 | try test__floatuntisf(make_uti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76); | 228 | try test__floatuntisf(make_uti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76); |
| 229 | 229 | ||
| 230 | // Test overflow to infinity | 230 | // Test overflow to infinity |
| 231 | try test__floatuntisf(@as(u128, math.maxInt(u128)), @as(f32, @bitCast(math.inf(f32)))); | 231 | try test__floatuntisf(math.maxInt(u128), @bitCast(math.inf(f32))); |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | fn test_one_floatsidf(a: i32, expected: u64) !void { | 234 | fn test_one_floatsidf(a: i32, expected: u64) !void { |
| ... | @@ -246,15 +246,15 @@ test "floatsidf" { | ... | @@ -246,15 +246,15 @@ test "floatsidf" { |
| 246 | try test_one_floatsidf(1, 0x3ff0000000000000); | 246 | try test_one_floatsidf(1, 0x3ff0000000000000); |
| 247 | try test_one_floatsidf(-1, 0xbff0000000000000); | 247 | try test_one_floatsidf(-1, 0xbff0000000000000); |
| 248 | try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000); | 248 | try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000); |
| 249 | try test_one_floatsidf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc1e0000000000000); | 249 | try test_one_floatsidf(@bitCast(@as(u32, @intCast(0x80000000))), 0xc1e0000000000000); |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | test "floatunsidf" { | 252 | test "floatunsidf" { |
| 253 | try test_one_floatunsidf(0, 0x0000000000000000); | 253 | try test_one_floatunsidf(0, 0x0000000000000000); |
| 254 | try test_one_floatunsidf(1, 0x3ff0000000000000); | 254 | try test_one_floatunsidf(1, 0x3ff0000000000000); |
| 255 | try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000); | 255 | try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000); |
| 256 | try test_one_floatunsidf(@as(u32, @intCast(0x80000000)), 0x41e0000000000000); | 256 | try test_one_floatunsidf(@intCast(0x80000000), 0x41e0000000000000); |
| 257 | try test_one_floatunsidf(@as(u32, @intCast(0xFFFFFFFF)), 0x41efffffffe00000); | 257 | try test_one_floatunsidf(@intCast(0xFFFFFFFF), 0x41efffffffe00000); |
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | fn test__floatdidf(a: i64, expected: f64) !void { | 260 | fn test__floatdidf(a: i64, expected: f64) !void { |
| ... | @@ -279,12 +279,12 @@ test "floatdidf" { | ... | @@ -279,12 +279,12 @@ test "floatdidf" { |
| 279 | try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | 279 | try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); |
| 280 | try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | 280 | try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); |
| 281 | try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | 281 | try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); |
| 282 | try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000008000000000)))), -0x1.FFFFFEp+62); | 282 | try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000008000000000))), -0x1.FFFFFEp+62); |
| 283 | try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000800)))), -0x1.FFFFFFFFFFFFEp+62); | 283 | try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000000800))), -0x1.FFFFFFFFFFFFEp+62); |
| 284 | try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000010000000000)))), -0x1.FFFFFCp+62); | 284 | try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000010000000000))), -0x1.FFFFFCp+62); |
| 285 | try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000001000)))), -0x1.FFFFFFFFFFFFCp+62); | 285 | try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000001000))), -0x1.FFFFFFFFFFFFCp+62); |
| 286 | try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))), -0x1.000000p+63); | 286 | try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000000000))), -0x1.000000p+63); |
| 287 | try test__floatdidf(@as(i64, @bitCast(@as(u64, @intCast(0x8000000000000001)))), -0x1.000000p+63); // 0x8000000000000001 | 287 | try test__floatdidf(@bitCast(@as(u64, @intCast(0x8000000000000001))), -0x1.000000p+63); // 0x8000000000000001 |
| 288 | try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | 288 | try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); |
| 289 | try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | 289 | try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); |
| 290 | try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | 290 | try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); |
| ... | @@ -513,8 +513,8 @@ test "floatsitf" { | ... | @@ -513,8 +513,8 @@ test "floatsitf" { |
| 513 | try test__floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000); | 513 | try test__floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000); |
| 514 | try test__floatsitf(0x12345678, 0x401b2345678000000000000000000000); | 514 | try test__floatsitf(0x12345678, 0x401b2345678000000000000000000000); |
| 515 | try test__floatsitf(-0x12345678, 0xc01b2345678000000000000000000000); | 515 | try test__floatsitf(-0x12345678, 0xc01b2345678000000000000000000000); |
| 516 | try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0xffffffff)))), 0xbfff0000000000000000000000000000); | 516 | try test__floatsitf(@bitCast(@as(u32, @intCast(0xffffffff))), 0xbfff0000000000000000000000000000); |
| 517 | try test__floatsitf(@as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 0xc01e0000000000000000000000000000); | 517 | try test__floatsitf(@bitCast(@as(u32, @intCast(0x80000000))), 0xc01e0000000000000000000000000000); |
| 518 | } | 518 | } |
| 519 | 519 | ||
| 520 | fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void { | 520 | fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void { |
| ... | @@ -575,10 +575,10 @@ test "floatditf" { | ... | @@ -575,10 +575,10 @@ test "floatditf" { |
| 575 | try test__floatditf(0x2, make_tf(0x4000000000000000, 0x0)); | 575 | try test__floatditf(0x2, make_tf(0x4000000000000000, 0x0)); |
| 576 | try test__floatditf(0x1, make_tf(0x3fff000000000000, 0x0)); | 576 | try test__floatditf(0x1, make_tf(0x3fff000000000000, 0x0)); |
| 577 | try test__floatditf(0x0, make_tf(0x0, 0x0)); | 577 | try test__floatditf(0x0, make_tf(0x0, 0x0)); |
| 578 | try test__floatditf(@as(i64, @bitCast(@as(u64, 0xffffffffffffffff))), make_tf(0xbfff000000000000, 0x0)); | 578 | try test__floatditf(@bitCast(@as(u64, 0xffffffffffffffff)), make_tf(0xbfff000000000000, 0x0)); |
| 579 | try test__floatditf(@as(i64, @bitCast(@as(u64, 0xfffffffffffffffe))), make_tf(0xc000000000000000, 0x0)); | 579 | try test__floatditf(@bitCast(@as(u64, 0xfffffffffffffffe)), make_tf(0xc000000000000000, 0x0)); |
| 580 | try test__floatditf(-0x123456789abcdef1, make_tf(0xc03b23456789abcd, 0xef10000000000000)); | 580 | try test__floatditf(-0x123456789abcdef1, make_tf(0xc03b23456789abcd, 0xef10000000000000)); |
| 581 | try test__floatditf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), make_tf(0xc03e000000000000, 0x0)); | 581 | try test__floatditf(@bitCast(@as(u64, 0x8000000000000000)), make_tf(0xc03e000000000000, 0x0)); |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | test "floatunditf" { | 584 | test "floatunditf" { |
| ... | @@ -773,7 +773,7 @@ fn make_ti(high: u64, low: u64) i128 { | ... | @@ -773,7 +773,7 @@ fn make_ti(high: u64, low: u64) i128 { |
| 773 | var result: u128 = high; | 773 | var result: u128 = high; |
| 774 | result <<= 64; | 774 | result <<= 64; |
| 775 | result |= low; | 775 | result |= low; |
| 776 | return @as(i128, @bitCast(result)); | 776 | return @bitCast(result); |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | fn make_uti(high: u64, low: u64) u128 { | 779 | fn make_uti(high: u64, low: u64) u128 { |
| ... | @@ -787,7 +787,7 @@ fn make_tf(high: u64, low: u64) f128 { | ... | @@ -787,7 +787,7 @@ fn make_tf(high: u64, low: u64) f128 { |
| 787 | var result: u128 = high; | 787 | var result: u128 = high; |
| 788 | result <<= 64; | 788 | result <<= 64; |
| 789 | result |= low; | 789 | result |= low; |
| 790 | return @as(f128, @bitCast(result)); | 790 | return @bitCast(result); |
| 791 | } | 791 | } |
| 792 | 792 | ||
| 793 | test "conversion to f16" { | 793 | test "conversion to f16" { |
lib/compiler_rt/floor.zig+7-7| ... | @@ -40,7 +40,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 { | ... | @@ -40,7 +40,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | if (e >= 0) { | 42 | if (e >= 0) { |
| 43 | m = @as(u16, 1023) >> @as(u4, @intCast(e)); | 43 | m = @as(u16, 1023) >> @intCast(e); |
| 44 | if (u & m == 0) { | 44 | if (u & m == 0) { |
| 45 | return x; | 45 | return x; |
| 46 | } | 46 | } |
| ... | @@ -48,7 +48,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 { | ... | @@ -48,7 +48,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 { |
| 48 | if (u >> 15 != 0) { | 48 | if (u >> 15 != 0) { |
| 49 | u += m; | 49 | u += m; |
| 50 | } | 50 | } |
| 51 | return @as(f16, @bitCast(u & ~m)); | 51 | return @bitCast(u & ~m); |
| 52 | } else { | 52 | } else { |
| 53 | math.doNotOptimizeAway(x + 0x1.0p120); | 53 | math.doNotOptimizeAway(x + 0x1.0p120); |
| 54 | if (u >> 15 == 0) { | 54 | if (u >> 15 == 0) { |
| ... | @@ -60,7 +60,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 { | ... | @@ -60,7 +60,7 @@ pub fn __floorh(x: f16) callconv(.C) f16 { |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | pub fn floorf(x: f32) callconv(.C) f32 { | 62 | pub fn floorf(x: f32) callconv(.C) f32 { |
| 63 | var u = @as(u32, @bitCast(x)); | 63 | var u: u32 = @bitCast(x); |
| 64 | const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; | 64 | const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; |
| 65 | var m: u32 = undefined; | 65 | var m: u32 = undefined; |
| 66 | 66 | ||
| ... | @@ -74,7 +74,7 @@ pub fn floorf(x: f32) callconv(.C) f32 { | ... | @@ -74,7 +74,7 @@ pub fn floorf(x: f32) callconv(.C) f32 { |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | if (e >= 0) { | 76 | if (e >= 0) { |
| 77 | m = @as(u32, 0x007FFFFF) >> @as(u5, @intCast(e)); | 77 | m = @as(u32, 0x007FFFFF) >> @intCast(e); |
| 78 | if (u & m == 0) { | 78 | if (u & m == 0) { |
| 79 | return x; | 79 | return x; |
| 80 | } | 80 | } |
| ... | @@ -82,7 +82,7 @@ pub fn floorf(x: f32) callconv(.C) f32 { | ... | @@ -82,7 +82,7 @@ pub fn floorf(x: f32) callconv(.C) f32 { |
| 82 | if (u >> 31 != 0) { | 82 | if (u >> 31 != 0) { |
| 83 | u += m; | 83 | u += m; |
| 84 | } | 84 | } |
| 85 | return @as(f32, @bitCast(u & ~m)); | 85 | return @bitCast(u & ~m); |
| 86 | } else { | 86 | } else { |
| 87 | math.doNotOptimizeAway(x + 0x1.0p120); | 87 | math.doNotOptimizeAway(x + 0x1.0p120); |
| 88 | if (u >> 31 == 0) { | 88 | if (u >> 31 == 0) { |
| ... | @@ -96,7 +96,7 @@ pub fn floorf(x: f32) callconv(.C) f32 { | ... | @@ -96,7 +96,7 @@ pub fn floorf(x: f32) callconv(.C) f32 { |
| 96 | pub fn floor(x: f64) callconv(.C) f64 { | 96 | pub fn floor(x: f64) callconv(.C) f64 { |
| 97 | const f64_toint = 1.0 / math.floatEps(f64); | 97 | const f64_toint = 1.0 / math.floatEps(f64); |
| 98 | 98 | ||
| 99 | const u = @as(u64, @bitCast(x)); | 99 | const u: u64 = @bitCast(x); |
| 100 | const e = (u >> 52) & 0x7FF; | 100 | const e = (u >> 52) & 0x7FF; |
| 101 | var y: f64 = undefined; | 101 | var y: f64 = undefined; |
| 102 | 102 | ||
| ... | @@ -126,7 +126,7 @@ pub fn floor(x: f64) callconv(.C) f64 { | ... | @@ -126,7 +126,7 @@ pub fn floor(x: f64) callconv(.C) f64 { |
| 126 | 126 | ||
| 127 | pub fn __floorx(x: f80) callconv(.C) f80 { | 127 | pub fn __floorx(x: f80) callconv(.C) f80 { |
| 128 | // TODO: more efficient implementation | 128 | // TODO: more efficient implementation |
| 129 | return @as(f80, @floatCast(floorq(x))); | 129 | return @floatCast(floorq(x)); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | pub fn floorq(x: f128) callconv(.C) f128 { | 132 | pub fn floorq(x: f128) callconv(.C) f128 { |
lib/compiler_rt/fma.zig+16-16| ... | @@ -28,7 +28,7 @@ comptime { | ... | @@ -28,7 +28,7 @@ comptime { |
| 28 | 28 | ||
| 29 | pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 { | 29 | pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 { |
| 30 | // TODO: more efficient implementation | 30 | // TODO: more efficient implementation |
| 31 | return @as(f16, @floatCast(fmaf(x, y, z))); | 31 | return @floatCast(fmaf(x, y, z)); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 { | 34 | pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 { |
| ... | @@ -38,10 +38,10 @@ pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 { | ... | @@ -38,10 +38,10 @@ pub fn fmaf(x: f32, y: f32, z: f32) callconv(.C) f32 { |
| 38 | const e = (u >> 52) & 0x7FF; | 38 | const e = (u >> 52) & 0x7FF; |
| 39 | 39 | ||
| 40 | if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or (xy_z - xy == z and xy_z - z == xy)) { | 40 | if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or (xy_z - xy == z and xy_z - z == xy)) { |
| 41 | return @as(f32, @floatCast(xy_z)); | 41 | return @floatCast(xy_z); |
| 42 | } else { | 42 | } else { |
| 43 | // TODO: Handle inexact case with double-rounding | 43 | // TODO: Handle inexact case with double-rounding |
| 44 | return @as(f32, @floatCast(xy_z)); | 44 | return @floatCast(xy_z); |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| 47 | 47 | ||
| ... | @@ -95,7 +95,7 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 { | ... | @@ -95,7 +95,7 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 { |
| 95 | 95 | ||
| 96 | pub fn __fmax(a: f80, b: f80, c: f80) callconv(.C) f80 { | 96 | pub fn __fmax(a: f80, b: f80, c: f80) callconv(.C) f80 { |
| 97 | // TODO: more efficient implementation | 97 | // TODO: more efficient implementation |
| 98 | return @as(f80, @floatCast(fmaq(a, b, c))); | 98 | return @floatCast(fmaq(a, b, c)); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | /// Fused multiply-add: Compute x * y + z with a single rounding error. | 101 | /// Fused multiply-add: Compute x * y + z with a single rounding error. |
| ... | @@ -201,12 +201,12 @@ fn dd_mul(a: f64, b: f64) dd { | ... | @@ -201,12 +201,12 @@ fn dd_mul(a: f64, b: f64) dd { |
| 201 | fn add_adjusted(a: f64, b: f64) f64 { | 201 | fn add_adjusted(a: f64, b: f64) f64 { |
| 202 | var sum = dd_add(a, b); | 202 | var sum = dd_add(a, b); |
| 203 | if (sum.lo != 0) { | 203 | if (sum.lo != 0) { |
| 204 | var uhii = @as(u64, @bitCast(sum.hi)); | 204 | var uhii: u64 = @bitCast(sum.hi); |
| 205 | if (uhii & 1 == 0) { | 205 | if (uhii & 1 == 0) { |
| 206 | // hibits += copysign(1.0, sum.hi, sum.lo) | 206 | // hibits += copysign(1.0, sum.hi, sum.lo) |
| 207 | const uloi = @as(u64, @bitCast(sum.lo)); | 207 | const uloi: u64 = @bitCast(sum.lo); |
| 208 | uhii += 1 - ((uhii ^ uloi) >> 62); | 208 | uhii += 1 - ((uhii ^ uloi) >> 62); |
| 209 | sum.hi = @as(f64, @bitCast(uhii)); | 209 | sum.hi = @bitCast(uhii); |
| 210 | } | 210 | } |
| 211 | } | 211 | } |
| 212 | return sum.hi; | 212 | return sum.hi; |
| ... | @@ -215,12 +215,12 @@ fn add_adjusted(a: f64, b: f64) f64 { | ... | @@ -215,12 +215,12 @@ fn add_adjusted(a: f64, b: f64) f64 { |
| 215 | fn add_and_denorm(a: f64, b: f64, scale: i32) f64 { | 215 | fn add_and_denorm(a: f64, b: f64, scale: i32) f64 { |
| 216 | var sum = dd_add(a, b); | 216 | var sum = dd_add(a, b); |
| 217 | if (sum.lo != 0) { | 217 | if (sum.lo != 0) { |
| 218 | var uhii = @as(u64, @bitCast(sum.hi)); | 218 | var uhii: u64 = @bitCast(sum.hi); |
| 219 | const bits_lost = -@as(i32, @intCast((uhii >> 52) & 0x7FF)) - scale + 1; | 219 | const bits_lost = -@as(i32, @intCast((uhii >> 52) & 0x7FF)) - scale + 1; |
| 220 | if ((bits_lost != 1) == (uhii & 1 != 0)) { | 220 | if ((bits_lost != 1) == (uhii & 1 != 0)) { |
| 221 | const uloi = @as(u64, @bitCast(sum.lo)); | 221 | const uloi: u64 = @bitCast(sum.lo); |
| 222 | uhii += 1 - (((uhii ^ uloi) >> 62) & 2); | 222 | uhii += 1 - (((uhii ^ uloi) >> 62) & 2); |
| 223 | sum.hi = @as(f64, @bitCast(uhii)); | 223 | sum.hi = @bitCast(uhii); |
| 224 | } | 224 | } |
| 225 | } | 225 | } |
| 226 | return math.scalbn(sum.hi, scale); | 226 | return math.scalbn(sum.hi, scale); |
| ... | @@ -257,12 +257,12 @@ fn dd_add128(a: f128, b: f128) dd128 { | ... | @@ -257,12 +257,12 @@ fn dd_add128(a: f128, b: f128) dd128 { |
| 257 | fn add_adjusted128(a: f128, b: f128) f128 { | 257 | fn add_adjusted128(a: f128, b: f128) f128 { |
| 258 | var sum = dd_add128(a, b); | 258 | var sum = dd_add128(a, b); |
| 259 | if (sum.lo != 0) { | 259 | if (sum.lo != 0) { |
| 260 | var uhii = @as(u128, @bitCast(sum.hi)); | 260 | var uhii: u128 = @bitCast(sum.hi); |
| 261 | if (uhii & 1 == 0) { | 261 | if (uhii & 1 == 0) { |
| 262 | // hibits += copysign(1.0, sum.hi, sum.lo) | 262 | // hibits += copysign(1.0, sum.hi, sum.lo) |
| 263 | const uloi = @as(u128, @bitCast(sum.lo)); | 263 | const uloi: u128 = @bitCast(sum.lo); |
| 264 | uhii += 1 - ((uhii ^ uloi) >> 126); | 264 | uhii += 1 - ((uhii ^ uloi) >> 126); |
| 265 | sum.hi = @as(f128, @bitCast(uhii)); | 265 | sum.hi = @bitCast(uhii); |
| 266 | } | 266 | } |
| 267 | } | 267 | } |
| 268 | return sum.hi; | 268 | return sum.hi; |
| ... | @@ -282,12 +282,12 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 { | ... | @@ -282,12 +282,12 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 { |
| 282 | // If we are losing only one bit to denormalization, however, we must | 282 | // If we are losing only one bit to denormalization, however, we must |
| 283 | // break the ties manually. | 283 | // break the ties manually. |
| 284 | if (sum.lo != 0) { | 284 | if (sum.lo != 0) { |
| 285 | var uhii = @as(u128, @bitCast(sum.hi)); | 285 | var uhii: u128 = @bitCast(sum.hi); |
| 286 | const bits_lost = -@as(i32, @intCast((uhii >> 112) & 0x7FFF)) - scale + 1; | 286 | const bits_lost = -@as(i32, @intCast((uhii >> 112) & 0x7FFF)) - scale + 1; |
| 287 | if ((bits_lost != 1) == (uhii & 1 != 0)) { | 287 | if ((bits_lost != 1) == (uhii & 1 != 0)) { |
| 288 | const uloi = @as(u128, @bitCast(sum.lo)); | 288 | const uloi: u128 = @bitCast(sum.lo); |
| 289 | uhii += 1 - (((uhii ^ uloi) >> 126) & 2); | 289 | uhii += 1 - (((uhii ^ uloi) >> 126) & 2); |
| 290 | sum.hi = @as(f128, @bitCast(uhii)); | 290 | sum.hi = @bitCast(uhii); |
| 291 | } | 291 | } |
| 292 | } | 292 | } |
| 293 | return math.scalbn(sum.hi, scale); | 293 | return math.scalbn(sum.hi, scale); |
lib/compiler_rt/fmod.zig+12-13| ... | @@ -82,8 +82,8 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -82,8 +82,8 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 82 | 82 | ||
| 83 | var highA: u64 = 0; | 83 | var highA: u64 = 0; |
| 84 | var highB: u64 = 0; | 84 | var highB: u64 = 0; |
| 85 | var lowA: u64 = @as(u64, @truncate(aRep)); | 85 | var lowA: u64 = @truncate(aRep); |
| 86 | var lowB: u64 = @as(u64, @truncate(bRep)); | 86 | var lowB: u64 = @truncate(bRep); |
| 87 | 87 | ||
| 88 | while (expA > expB) : (expA -= 1) { | 88 | while (expA > expB) : (expA -= 1) { |
| 89 | var high = highA -% highB; | 89 | var high = highA -% highB; |
| ... | @@ -125,7 +125,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -125,7 +125,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 125 | if (expA < -fractionalBits) { | 125 | if (expA < -fractionalBits) { |
| 126 | return @bitCast(signA); | 126 | return @bitCast(signA); |
| 127 | } else if (expA <= 0) { | 127 | } else if (expA <= 0) { |
| 128 | return @bitCast((lowA >> @as(math.Log2Int(u64), @intCast(1 - expA))) | signA); | 128 | return @bitCast((lowA >> @intCast(1 - expA)) | signA); |
| 129 | } else { | 129 | } else { |
| 130 | return @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA); | 130 | return @bitCast(lowA | (@as(Z, @as(u16, @intCast(expA))) << significandBits) | signA); |
| 131 | } | 131 | } |
| ... | @@ -136,10 +136,10 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { | ... | @@ -136,10 +136,10 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { |
| 136 | pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { | 136 | pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { |
| 137 | var amod = a; | 137 | var amod = a; |
| 138 | var bmod = b; | 138 | var bmod = b; |
| 139 | const aPtr_u64 = @as([*]u64, @ptrCast(&amod)); | 139 | const aPtr_u64: [*]u64 = @ptrCast(&amod); |
| 140 | const bPtr_u64 = @as([*]u64, @ptrCast(&bmod)); | 140 | const bPtr_u64: [*]u64 = @ptrCast(&bmod); |
| 141 | const aPtr_u16 = @as([*]u16, @ptrCast(&amod)); | 141 | const aPtr_u16: [*]u16 = @ptrCast(&amod); |
| 142 | const bPtr_u16 = @as([*]u16, @ptrCast(&bmod)); | 142 | const bPtr_u16: [*]u16 = @ptrCast(&bmod); |
| 143 | 143 | ||
| 144 | const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) { | 144 | const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) { |
| 145 | .Little => 7, | 145 | .Little => 7, |
| ... | @@ -173,8 +173,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { | ... | @@ -173,8 +173,8 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | // Remove the sign from both | 175 | // Remove the sign from both |
| 176 | aPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expA)))); | 176 | aPtr_u16[exp_and_sign_index] = @bitCast(@as(i16, @intCast(expA))); |
| 177 | bPtr_u16[exp_and_sign_index] = @as(u16, @bitCast(@as(i16, @intCast(expB)))); | 177 | bPtr_u16[exp_and_sign_index] = @bitCast(@as(i16, @intCast(expB))); |
| 178 | if (amod <= bmod) { | 178 | if (amod <= bmod) { |
| 179 | if (amod == bmod) { | 179 | if (amod == bmod) { |
| 180 | return 0 * a; | 180 | return 0 * a; |
| ... | @@ -264,7 +264,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble { | ... | @@ -264,7 +264,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble { |
| 264 | inline fn generic_fmod(comptime T: type, x: T, y: T) T { | 264 | inline fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 265 | const bits = @typeInfo(T).Float.bits; | 265 | const bits = @typeInfo(T).Float.bits; |
| 266 | const uint = std.meta.Int(.unsigned, bits); | 266 | const uint = std.meta.Int(.unsigned, bits); |
| 267 | const log2uint = math.Log2Int(uint); | ||
| 268 | comptime assert(T == f32 or T == f64); | 267 | comptime assert(T == f32 or T == f64); |
| 269 | const digits = if (T == f32) 23 else 52; | 268 | const digits = if (T == f32) 23 else 52; |
| 270 | const exp_bits = if (T == f32) 9 else 12; | 269 | const exp_bits = if (T == f32) 9 else 12; |
| ... | @@ -293,7 +292,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { | ... | @@ -293,7 +292,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 293 | ex -= 1; | 292 | ex -= 1; |
| 294 | i <<= 1; | 293 | i <<= 1; |
| 295 | }) {} | 294 | }) {} |
| 296 | ux <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1)))); | 295 | ux <<= @intCast(@as(u32, @bitCast(-ex + 1))); |
| 297 | } else { | 296 | } else { |
| 298 | ux &= math.maxInt(uint) >> exp_bits; | 297 | ux &= math.maxInt(uint) >> exp_bits; |
| 299 | ux |= 1 << digits; | 298 | ux |= 1 << digits; |
| ... | @@ -304,7 +303,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { | ... | @@ -304,7 +303,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 304 | ey -= 1; | 303 | ey -= 1; |
| 305 | i <<= 1; | 304 | i <<= 1; |
| 306 | }) {} | 305 | }) {} |
| 307 | uy <<= @as(log2uint, @intCast(@as(u32, @bitCast(-ey + 1)))); | 306 | uy <<= @intCast(@as(u32, @bitCast(-ey + 1))); |
| 308 | } else { | 307 | } else { |
| 309 | uy &= math.maxInt(uint) >> exp_bits; | 308 | uy &= math.maxInt(uint) >> exp_bits; |
| 310 | uy |= 1 << digits; | 309 | uy |= 1 << digits; |
| ... | @@ -336,7 +335,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { | ... | @@ -336,7 +335,7 @@ inline fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 336 | ux -%= 1 << digits; | 335 | ux -%= 1 << digits; |
| 337 | ux |= @as(uint, @as(u32, @bitCast(ex))) << digits; | 336 | ux |= @as(uint, @as(u32, @bitCast(ex))) << digits; |
| 338 | } else { | 337 | } else { |
| 339 | ux >>= @as(log2uint, @intCast(@as(u32, @bitCast(-ex + 1)))); | 338 | ux >>= @intCast(@as(u32, @bitCast(-ex + 1))); |
| 340 | } | 339 | } |
| 341 | if (T == f32) { | 340 | if (T == f32) { |
| 342 | ux |= sx; | 341 | ux |= sx; |
lib/compiler_rt/int.zig+33-33| ... | @@ -52,8 +52,8 @@ test "test_divmodti4" { | ... | @@ -52,8 +52,8 @@ test "test_divmodti4" { |
| 52 | [_]i128{ -7, 5, -1, -2 }, | 52 | [_]i128{ -7, 5, -1, -2 }, |
| 53 | [_]i128{ 19, 5, 3, 4 }, | 53 | [_]i128{ 19, 5, 3, 4 }, |
| 54 | [_]i128{ 19, -5, -3, 4 }, | 54 | [_]i128{ 19, -5, -3, 4 }, |
| 55 | [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000000))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000000))), 0 }, | 55 | [_]i128{ @bitCast(@as(u128, 0x80000000000000000000000000000000)), 8, @bitCast(@as(u128, 0xf0000000000000000000000000000000)), 0 }, |
| 56 | [_]i128{ @as(i128, @bitCast(@as(u128, 0x80000000000000000000000000000007))), 8, @as(i128, @bitCast(@as(u128, 0xf0000000000000000000000000000001))), -1 }, | 56 | [_]i128{ @bitCast(@as(u128, 0x80000000000000000000000000000007)), 8, @bitCast(@as(u128, 0xf0000000000000000000000000000001)), -1 }, |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | for (cases) |case| { | 59 | for (cases) |case| { |
| ... | @@ -85,8 +85,8 @@ test "test_divmoddi4" { | ... | @@ -85,8 +85,8 @@ test "test_divmoddi4" { |
| 85 | [_]i64{ -7, 5, -1, -2 }, | 85 | [_]i64{ -7, 5, -1, -2 }, |
| 86 | [_]i64{ 19, 5, 3, 4 }, | 86 | [_]i64{ 19, 5, 3, 4 }, |
| 87 | [_]i64{ 19, -5, -3, 4 }, | 87 | [_]i64{ 19, -5, -3, 4 }, |
| 88 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 }, | 88 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 8, @bitCast(@as(u64, 0xf000000000000000)), 0 }, |
| 89 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 }, | 89 | [_]i64{ @bitCast(@as(u64, 0x8000000000000007)), 8, @bitCast(@as(u64, 0xf000000000000001)), -1 }, |
| 90 | }; | 90 | }; |
| 91 | 91 | ||
| 92 | for (cases) |case| { | 92 | for (cases) |case| { |
| ... | @@ -110,14 +110,14 @@ test "test_udivmoddi4" { | ... | @@ -110,14 +110,14 @@ test "test_udivmoddi4" { |
| 110 | 110 | ||
| 111 | pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 { | 111 | pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 { |
| 112 | // Set aside the sign of the quotient. | 112 | // Set aside the sign of the quotient. |
| 113 | const sign = @as(u64, @bitCast((a ^ b) >> 63)); | 113 | const sign: u64 = @bitCast((a ^ b) >> 63); |
| 114 | // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63). | 114 | // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63). |
| 115 | const abs_a = (a ^ (a >> 63)) -% (a >> 63); | 115 | const abs_a = (a ^ (a >> 63)) -% (a >> 63); |
| 116 | const abs_b = (b ^ (b >> 63)) -% (b >> 63); | 116 | const abs_b = (b ^ (b >> 63)) -% (b >> 63); |
| 117 | // Unsigned division | 117 | // Unsigned division |
| 118 | const res = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), null); | 118 | const res = __udivmoddi4(@bitCast(abs_a), @bitCast(abs_b), null); |
| 119 | // Apply sign of quotient to result and return. | 119 | // Apply sign of quotient to result and return. |
| 120 | return @as(i64, @bitCast((res ^ sign) -% sign)); | 120 | return @bitCast((res ^ sign) -% sign); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | test "test_divdi3" { | 123 | test "test_divdi3" { |
| ... | @@ -151,7 +151,7 @@ pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 { | ... | @@ -151,7 +151,7 @@ pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 { |
| 151 | const abs_b = (b ^ (b >> 63)) -% (b >> 63); | 151 | const abs_b = (b ^ (b >> 63)) -% (b >> 63); |
| 152 | // Unsigned division | 152 | // Unsigned division |
| 153 | var r: u64 = undefined; | 153 | var r: u64 = undefined; |
| 154 | _ = __udivmoddi4(@as(u64, @bitCast(abs_a)), @as(u64, @bitCast(abs_b)), &r); | 154 | _ = __udivmoddi4(@bitCast(abs_a), @bitCast(abs_b), &r); |
| 155 | // Apply the sign of the dividend and return. | 155 | // Apply the sign of the dividend and return. |
| 156 | return (@as(i64, @bitCast(r)) ^ (a >> 63)) -% (a >> 63); | 156 | return (@as(i64, @bitCast(r)) ^ (a >> 63)) -% (a >> 63); |
| 157 | } | 157 | } |
| ... | @@ -165,12 +165,12 @@ test "test_moddi3" { | ... | @@ -165,12 +165,12 @@ test "test_moddi3" { |
| 165 | [_]i64{ -5, 3, -2 }, | 165 | [_]i64{ -5, 3, -2 }, |
| 166 | [_]i64{ -5, -3, -2 }, | 166 | [_]i64{ -5, -3, -2 }, |
| 167 | 167 | ||
| 168 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 1, 0 }, | 168 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 1, 0 }, |
| 169 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -1, 0 }, | 169 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), -1, 0 }, |
| 170 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 2, 0 }, | 170 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 2, 0 }, |
| 171 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -2, 0 }, | 171 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), -2, 0 }, |
| 172 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 3, -2 }, | 172 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), 3, -2 }, |
| 173 | [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), -3, -2 }, | 173 | [_]i64{ @bitCast(@as(u64, 0x8000000000000000)), -3, -2 }, |
| 174 | }; | 174 | }; |
| 175 | 175 | ||
| 176 | for (cases) |case| { | 176 | for (cases) |case| { |
| ... | @@ -225,8 +225,8 @@ test "test_divmodsi4" { | ... | @@ -225,8 +225,8 @@ test "test_divmodsi4" { |
| 225 | [_]i32{ 19, 5, 3, 4 }, | 225 | [_]i32{ 19, 5, 3, 4 }, |
| 226 | [_]i32{ 19, -5, -3, 4 }, | 226 | [_]i32{ 19, -5, -3, 4 }, |
| 227 | 227 | ||
| 228 | [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 8, @as(i32, @bitCast(@as(u32, 0xf0000000))), 0 }, | 228 | [_]i32{ @bitCast(@as(u32, 0x80000000)), 8, @bitCast(@as(u32, 0xf0000000)), 0 }, |
| 229 | [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000007))), 8, @as(i32, @bitCast(@as(u32, 0xf0000001))), -1 }, | 229 | [_]i32{ @bitCast(@as(u32, 0x80000007)), 8, @bitCast(@as(u32, 0xf0000001)), -1 }, |
| 230 | }; | 230 | }; |
| 231 | 231 | ||
| 232 | for (cases) |case| { | 232 | for (cases) |case| { |
| ... | @@ -242,7 +242,7 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void { | ... | @@ -242,7 +242,7 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void { |
| 242 | 242 | ||
| 243 | pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 { | 243 | pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 { |
| 244 | const d = __udivsi3(a, b); | 244 | const d = __udivsi3(a, b); |
| 245 | rem.* = @as(u32, @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b))))); | 245 | rem.* = @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b)))); |
| 246 | return d; | 246 | return d; |
| 247 | } | 247 | } |
| 248 | 248 | ||
| ... | @@ -256,14 +256,14 @@ fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 { | ... | @@ -256,14 +256,14 @@ fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 { |
| 256 | 256 | ||
| 257 | inline fn div_i32(n: i32, d: i32) i32 { | 257 | inline fn div_i32(n: i32, d: i32) i32 { |
| 258 | // Set aside the sign of the quotient. | 258 | // Set aside the sign of the quotient. |
| 259 | const sign = @as(u32, @bitCast((n ^ d) >> 31)); | 259 | const sign: u32 = @bitCast((n ^ d) >> 31); |
| 260 | // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31). | 260 | // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31). |
| 261 | const abs_n = (n ^ (n >> 31)) -% (n >> 31); | 261 | const abs_n = (n ^ (n >> 31)) -% (n >> 31); |
| 262 | const abs_d = (d ^ (d >> 31)) -% (d >> 31); | 262 | const abs_d = (d ^ (d >> 31)) -% (d >> 31); |
| 263 | // abs(a) / abs(b) | 263 | // abs(a) / abs(b) |
| 264 | const res = @as(u32, @bitCast(abs_n)) / @as(u32, @bitCast(abs_d)); | 264 | const res = @as(u32, @bitCast(abs_n)) / @as(u32, @bitCast(abs_d)); |
| 265 | // Apply sign of quotient to result and return. | 265 | // Apply sign of quotient to result and return. |
| 266 | return @as(i32, @bitCast((res ^ sign) -% sign)); | 266 | return @bitCast((res ^ sign) -% sign); |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | test "test_divsi3" { | 269 | test "test_divsi3" { |
| ... | @@ -275,10 +275,10 @@ test "test_divsi3" { | ... | @@ -275,10 +275,10 @@ test "test_divsi3" { |
| 275 | [_]i32{ -2, 1, -2 }, | 275 | [_]i32{ -2, 1, -2 }, |
| 276 | [_]i32{ -2, -1, 2 }, | 276 | [_]i32{ -2, -1, 2 }, |
| 277 | 277 | ||
| 278 | [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 1, @as(i32, @bitCast(@as(u32, 0x80000000))) }, | 278 | [_]i32{ @bitCast(@as(u32, 0x80000000)), 1, @bitCast(@as(u32, 0x80000000)) }, |
| 279 | [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -1, @as(i32, @bitCast(@as(u32, 0x80000000))) }, | 279 | [_]i32{ @bitCast(@as(u32, 0x80000000)), -1, @bitCast(@as(u32, 0x80000000)) }, |
| 280 | [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), -2, 0x40000000 }, | 280 | [_]i32{ @bitCast(@as(u32, 0x80000000)), -2, 0x40000000 }, |
| 281 | [_]i32{ @as(i32, @bitCast(@as(u32, 0x80000000))), 2, @as(i32, @bitCast(@as(u32, 0xC0000000))) }, | 281 | [_]i32{ @bitCast(@as(u32, 0x80000000)), 2, @bitCast(@as(u32, 0xC0000000)) }, |
| 282 | }; | 282 | }; |
| 283 | 283 | ||
| 284 | for (cases) |case| { | 284 | for (cases) |case| { |
| ... | @@ -317,12 +317,12 @@ inline fn div_u32(n: u32, d: u32) u32 { | ... | @@ -317,12 +317,12 @@ inline fn div_u32(n: u32, d: u32) u32 { |
| 317 | sr += 1; | 317 | sr += 1; |
| 318 | // 1 <= sr <= n_uword_bits - 1 | 318 | // 1 <= sr <= n_uword_bits - 1 |
| 319 | // Not a special case | 319 | // Not a special case |
| 320 | var q: u32 = n << @as(u5, @intCast(n_uword_bits - sr)); | 320 | var q: u32 = n << @intCast(n_uword_bits - sr); |
| 321 | var r: u32 = n >> @as(u5, @intCast(sr)); | 321 | var r: u32 = n >> @intCast(sr); |
| 322 | var carry: u32 = 0; | 322 | var carry: u32 = 0; |
| 323 | while (sr > 0) : (sr -= 1) { | 323 | while (sr > 0) : (sr -= 1) { |
| 324 | // r:q = ((r:q) << 1) | carry | 324 | // r:q = ((r:q) << 1) | carry |
| 325 | r = (r << 1) | (q >> @as(u5, @intCast(n_uword_bits - 1))); | 325 | r = (r << 1) | (q >> @intCast(n_uword_bits - 1)); |
| 326 | q = (q << 1) | carry; | 326 | q = (q << 1) | carry; |
| 327 | // carry = 0; | 327 | // carry = 0; |
| 328 | // if (r.all >= d.all) | 328 | // if (r.all >= d.all) |
| ... | @@ -330,8 +330,8 @@ inline fn div_u32(n: u32, d: u32) u32 { | ... | @@ -330,8 +330,8 @@ inline fn div_u32(n: u32, d: u32) u32 { |
| 330 | // r.all -= d.all; | 330 | // r.all -= d.all; |
| 331 | // carry = 1; | 331 | // carry = 1; |
| 332 | // } | 332 | // } |
| 333 | const s = @as(i32, @bitCast(d -% r -% 1)) >> @as(u5, @intCast(n_uword_bits - 1)); | 333 | const s = @as(i32, @bitCast(d -% r -% 1)) >> @intCast(n_uword_bits - 1); |
| 334 | carry = @as(u32, @intCast(s & 1)); | 334 | carry = @intCast(s & 1); |
| 335 | r -= d & @as(u32, @bitCast(s)); | 335 | r -= d & @as(u32, @bitCast(s)); |
| 336 | } | 336 | } |
| 337 | q = (q << 1) | carry; | 337 | q = (q << 1) | carry; |
| ... | @@ -496,11 +496,11 @@ test "test_modsi3" { | ... | @@ -496,11 +496,11 @@ test "test_modsi3" { |
| 496 | [_]i32{ 5, -3, 2 }, | 496 | [_]i32{ 5, -3, 2 }, |
| 497 | [_]i32{ -5, 3, -2 }, | 497 | [_]i32{ -5, 3, -2 }, |
| 498 | [_]i32{ -5, -3, -2 }, | 498 | [_]i32{ -5, -3, -2 }, |
| 499 | [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 1, 0x0 }, | 499 | [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), 1, 0x0 }, |
| 500 | [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 2, 0x0 }, | 500 | [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), 2, 0x0 }, |
| 501 | [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -2, 0x0 }, | 501 | [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), -2, 0x0 }, |
| 502 | [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), 3, -2 }, | 502 | [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), 3, -2 }, |
| 503 | [_]i32{ @as(i32, @bitCast(@as(u32, @intCast(0x80000000)))), -3, -2 }, | 503 | [_]i32{ @bitCast(@as(u32, @intCast(0x80000000))), -3, -2 }, |
| 504 | }; | 504 | }; |
| 505 | 505 | ||
| 506 | for (cases) |case| { | 506 | for (cases) |case| { |
lib/compiler_rt/int_from_float.zig+3-3| ... | @@ -17,7 +17,7 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I { | ... | @@ -17,7 +17,7 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I { |
| 17 | const sig_mask = (@as(rep_t, 1) << sig_bits) - 1; | 17 | const sig_mask = (@as(rep_t, 1) << sig_bits) - 1; |
| 18 | 18 | ||
| 19 | // Break a into sign, exponent, significand | 19 | // Break a into sign, exponent, significand |
| 20 | const a_rep: rep_t = @as(rep_t, @bitCast(a)); | 20 | const a_rep: rep_t = @bitCast(a); |
| 21 | const negative = (a_rep >> (float_bits - 1)) != 0; | 21 | const negative = (a_rep >> (float_bits - 1)) != 0; |
| 22 | const exponent = @as(i32, @intCast((a_rep << 1) >> (sig_bits + 1))) - exp_bias; | 22 | const exponent = @as(i32, @intCast((a_rep << 1) >> (sig_bits + 1))) - exp_bias; |
| 23 | const significand: rep_t = (a_rep & sig_mask) | implicit_bit; | 23 | const significand: rep_t = (a_rep & sig_mask) | implicit_bit; |
| ... | @@ -40,9 +40,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I { | ... | @@ -40,9 +40,9 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I { |
| 40 | // Otherwise, shift left. | 40 | // Otherwise, shift left. |
| 41 | var result: I = undefined; | 41 | var result: I = undefined; |
| 42 | if (exponent < fractional_bits) { | 42 | if (exponent < fractional_bits) { |
| 43 | result = @as(I, @intCast(significand >> @as(Log2Int(rep_t), @intCast(fractional_bits - exponent)))); | 43 | result = @intCast(significand >> @intCast(fractional_bits - exponent)); |
| 44 | } else { | 44 | } else { |
| 45 | result = @as(I, @intCast(significand)) << @as(Log2Int(I), @intCast(exponent - fractional_bits)); | 45 | result = @as(I, @intCast(significand)) << @intCast(exponent - fractional_bits); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | if ((@typeInfo(I).Int.signedness == .signed) and negative) | 48 | if ((@typeInfo(I).Int.signedness == .signed) and negative) |
lib/compiler_rt/log10.zig+6-6| ... | @@ -28,7 +28,7 @@ comptime { | ... | @@ -28,7 +28,7 @@ comptime { |
| 28 | 28 | ||
| 29 | pub fn __log10h(a: f16) callconv(.C) f16 { | 29 | pub fn __log10h(a: f16) callconv(.C) f16 { |
| 30 | // TODO: more efficient implementation | 30 | // TODO: more efficient implementation |
| 31 | return @as(f16, @floatCast(log10f(a))); | 31 | return @floatCast(log10f(a)); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn log10f(x_: f32) callconv(.C) f32 { | 34 | pub fn log10f(x_: f32) callconv(.C) f32 { |
| ... | @@ -42,7 +42,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 { | ... | @@ -42,7 +42,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 { |
| 42 | const Lg4: f32 = 0xf89e26.0p-26; | 42 | const Lg4: f32 = 0xf89e26.0p-26; |
| 43 | 43 | ||
| 44 | var x = x_; | 44 | var x = x_; |
| 45 | var u = @as(u32, @bitCast(x)); | 45 | var u: u32 = @bitCast(x); |
| 46 | var ix = u; | 46 | var ix = u; |
| 47 | var k: i32 = 0; | 47 | var k: i32 = 0; |
| 48 | 48 | ||
| ... | @@ -59,7 +59,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 { | ... | @@ -59,7 +59,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 { |
| 59 | 59 | ||
| 60 | k -= 25; | 60 | k -= 25; |
| 61 | x *= 0x1.0p25; | 61 | x *= 0x1.0p25; |
| 62 | ix = @as(u32, @bitCast(x)); | 62 | ix = @bitCast(x); |
| 63 | } else if (ix >= 0x7F800000) { | 63 | } else if (ix >= 0x7F800000) { |
| 64 | return x; | 64 | return x; |
| 65 | } else if (ix == 0x3F800000) { | 65 | } else if (ix == 0x3F800000) { |
| ... | @@ -70,7 +70,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 { | ... | @@ -70,7 +70,7 @@ pub fn log10f(x_: f32) callconv(.C) f32 { |
| 70 | ix += 0x3F800000 - 0x3F3504F3; | 70 | ix += 0x3F800000 - 0x3F3504F3; |
| 71 | k += @as(i32, @intCast(ix >> 23)) - 0x7F; | 71 | k += @as(i32, @intCast(ix >> 23)) - 0x7F; |
| 72 | ix = (ix & 0x007FFFFF) + 0x3F3504F3; | 72 | ix = (ix & 0x007FFFFF) + 0x3F3504F3; |
| 73 | x = @as(f32, @bitCast(ix)); | 73 | x = @bitCast(ix); |
| 74 | 74 | ||
| 75 | const f = x - 1.0; | 75 | const f = x - 1.0; |
| 76 | const s = f / (2.0 + f); | 76 | const s = f / (2.0 + f); |
| ... | @@ -168,12 +168,12 @@ pub fn log10(x_: f64) callconv(.C) f64 { | ... | @@ -168,12 +168,12 @@ pub fn log10(x_: f64) callconv(.C) f64 { |
| 168 | 168 | ||
| 169 | pub fn __log10x(a: f80) callconv(.C) f80 { | 169 | pub fn __log10x(a: f80) callconv(.C) f80 { |
| 170 | // TODO: more efficient implementation | 170 | // TODO: more efficient implementation |
| 171 | return @as(f80, @floatCast(log10q(a))); | 171 | return @floatCast(log10q(a)); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | pub fn log10q(a: f128) callconv(.C) f128 { | 174 | pub fn log10q(a: f128) callconv(.C) f128 { |
| 175 | // TODO: more correct implementation | 175 | // TODO: more correct implementation |
| 176 | return log10(@as(f64, @floatCast(a))); | 176 | return log10(@floatCast(a)); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble { | 179 | pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/modti3_test.zig+1-1| ... | @@ -33,5 +33,5 @@ fn make_ti(high: u64, low: u64) i128 { | ... | @@ -33,5 +33,5 @@ fn make_ti(high: u64, low: u64) i128 { |
| 33 | var result: u128 = high; | 33 | var result: u128 = high; |
| 34 | result <<= 64; | 34 | result <<= 64; |
| 35 | result |= low; | 35 | result |= low; |
| 36 | return @as(i128, @bitCast(result)); | 36 | return @bitCast(result); |
| 37 | } | 37 | } |
lib/compiler_rt/mulf3.zig+18-19| ... | @@ -29,16 +29,16 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { | ... | @@ -29,16 +29,16 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 29 | 29 | ||
| 30 | const absMask = signBit - 1; | 30 | const absMask = signBit - 1; |
| 31 | const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit; | 31 | const qnanRep = @as(Z, @bitCast(math.nan(T))) | quietBit; |
| 32 | const infRep = @as(Z, @bitCast(math.inf(T))); | 32 | const infRep: Z = @bitCast(math.inf(T)); |
| 33 | const minNormalRep = @as(Z, @bitCast(math.floatMin(T))); | 33 | const minNormalRep: Z = @bitCast(math.floatMin(T)); |
| 34 | 34 | ||
| 35 | const ZExp = if (typeWidth >= 32) u32 else Z; | 35 | const ZExp = if (typeWidth >= 32) u32 else Z; |
| 36 | const aExponent = @as(ZExp, @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent)); | 36 | const aExponent: ZExp = @truncate((@as(Z, @bitCast(a)) >> significandBits) & maxExponent); |
| 37 | const bExponent = @as(ZExp, @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent)); | 37 | const bExponent: ZExp = @truncate((@as(Z, @bitCast(b)) >> significandBits) & maxExponent); |
| 38 | const productSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit; | 38 | const productSign: Z = (@as(Z, @bitCast(a)) ^ @as(Z, @bitCast(b))) & signBit; |
| 39 | 39 | ||
| 40 | var aSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(a)) & significandMask)); | 40 | var aSignificand: ZSignificand = @intCast(@as(Z, @bitCast(a)) & significandMask); |
| 41 | var bSignificand: ZSignificand = @as(ZSignificand, @intCast(@as(Z, @bitCast(b)) & significandMask)); | 41 | var bSignificand: ZSignificand = @intCast(@as(Z, @bitCast(b)) & significandMask); |
| 42 | var scale: i32 = 0; | 42 | var scale: i32 = 0; |
| 43 | 43 | ||
| 44 | // Detect if a or b is zero, denormal, infinity, or NaN. | 44 | // Detect if a or b is zero, denormal, infinity, or NaN. |
| ... | @@ -47,9 +47,9 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { | ... | @@ -47,9 +47,9 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 47 | const bAbs: Z = @as(Z, @bitCast(b)) & absMask; | 47 | const bAbs: Z = @as(Z, @bitCast(b)) & absMask; |
| 48 | 48 | ||
| 49 | // NaN * anything = qNaN | 49 | // NaN * anything = qNaN |
| 50 | if (aAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(a)) | quietBit)); | 50 | if (aAbs > infRep) return @bitCast(@as(Z, @bitCast(a)) | quietBit); |
| 51 | // anything * NaN = qNaN | 51 | // anything * NaN = qNaN |
| 52 | if (bAbs > infRep) return @as(T, @bitCast(@as(Z, @bitCast(b)) | quietBit)); | 52 | if (bAbs > infRep) return @bitCast(@as(Z, @bitCast(b)) | quietBit); |
| 53 | 53 | ||
| 54 | if (aAbs == infRep) { | 54 | if (aAbs == infRep) { |
| 55 | // infinity * non-zero = +/- infinity | 55 | // infinity * non-zero = +/- infinity |
| ... | @@ -110,7 +110,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { | ... | @@ -110,7 +110,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | // If we have overflowed the type, return +/- infinity. | 112 | // If we have overflowed the type, return +/- infinity. |
| 113 | if (productExponent >= maxExponent) return @as(T, @bitCast(infRep | productSign)); | 113 | if (productExponent >= maxExponent) return @bitCast(infRep | productSign); |
| 114 | 114 | ||
| 115 | var result: Z = undefined; | 115 | var result: Z = undefined; |
| 116 | if (productExponent <= 0) { | 116 | if (productExponent <= 0) { |
| ... | @@ -120,8 +120,8 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { | ... | @@ -120,8 +120,8 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 120 | // a zero of the appropriate sign. Mathematically there is no need to | 120 | // a zero of the appropriate sign. Mathematically there is no need to |
| 121 | // handle this case separately, but we make it a special case to | 121 | // handle this case separately, but we make it a special case to |
| 122 | // simplify the shift logic. | 122 | // simplify the shift logic. |
| 123 | const shift: u32 = @as(u32, @truncate(@as(Z, 1) -% @as(u32, @bitCast(productExponent)))); | 123 | const shift: u32 = @truncate(@as(Z, 1) -% @as(u32, @bitCast(productExponent))); |
| 124 | if (shift >= ZSignificandBits) return @as(T, @bitCast(productSign)); | 124 | if (shift >= ZSignificandBits) return @bitCast(productSign); |
| 125 | 125 | ||
| 126 | // Otherwise, shift the significand of the result so that the round | 126 | // Otherwise, shift the significand of the result so that the round |
| 127 | // bit is the high bit of productLo. | 127 | // bit is the high bit of productLo. |
| ... | @@ -156,7 +156,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { | ... | @@ -156,7 +156,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 156 | // Insert the sign of the result: | 156 | // Insert the sign of the result: |
| 157 | result |= productSign; | 157 | result |= productSign; |
| 158 | 158 | ||
| 159 | return @as(T, @bitCast(result)); | 159 | return @bitCast(result); |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | /// Returns `true` if the right shift is inexact (i.e. any bit shifted out is non-zero) | 162 | /// Returns `true` if the right shift is inexact (i.e. any bit shifted out is non-zero) |
| ... | @@ -165,15 +165,14 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { | ... | @@ -165,15 +165,14 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 165 | fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool { | 165 | fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool { |
| 166 | @setRuntimeSafety(builtin.is_test); | 166 | @setRuntimeSafety(builtin.is_test); |
| 167 | const typeWidth = @typeInfo(Z).Int.bits; | 167 | const typeWidth = @typeInfo(Z).Int.bits; |
| 168 | const S = math.Log2Int(Z); | ||
| 169 | var inexact = false; | 168 | var inexact = false; |
| 170 | if (count < typeWidth) { | 169 | if (count < typeWidth) { |
| 171 | inexact = (lo.* << @as(S, @intCast(typeWidth -% count))) != 0; | 170 | inexact = (lo.* << @intCast(typeWidth -% count)) != 0; |
| 172 | lo.* = (hi.* << @as(S, @intCast(typeWidth -% count))) | (lo.* >> @as(S, @intCast(count))); | 171 | lo.* = (hi.* << @intCast(typeWidth -% count)) | (lo.* >> @intCast(count)); |
| 173 | hi.* = hi.* >> @as(S, @intCast(count)); | 172 | hi.* = hi.* >> @intCast(count); |
| 174 | } else if (count < 2 * typeWidth) { | 173 | } else if (count < 2 * typeWidth) { |
| 175 | inexact = (hi.* << @as(S, @intCast(2 * typeWidth -% count)) | lo.*) != 0; | 174 | inexact = (hi.* << @intCast(2 * typeWidth -% count) | lo.*) != 0; |
| 176 | lo.* = hi.* >> @as(S, @intCast(count -% typeWidth)); | 175 | lo.* = hi.* >> @intCast(count -% typeWidth); |
| 177 | hi.* = 0; | 176 | hi.* = 0; |
| 178 | } else { | 177 | } else { |
| 179 | inexact = (hi.* | lo.*) != 0; | 178 | inexact = (hi.* | lo.*) != 0; |
| ... | @@ -188,7 +187,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 { | ... | @@ -188,7 +187,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 { |
| 188 | const integerBit = @as(Z, 1) << math.floatFractionalBits(T); | 187 | const integerBit = @as(Z, 1) << math.floatFractionalBits(T); |
| 189 | 188 | ||
| 190 | const shift = @clz(significand.*) - @clz(integerBit); | 189 | const shift = @clz(significand.*) - @clz(integerBit); |
| 191 | significand.* <<= @as(math.Log2Int(Z), @intCast(shift)); | 190 | significand.* <<= @intCast(shift); |
| 192 | return @as(i32, 1) - shift; | 191 | return @as(i32, 1) - shift; |
| 193 | } | 192 | } |
| 194 | 193 |
lib/compiler_rt/parity.zig+2-7| ... | @@ -26,12 +26,7 @@ pub fn __parityti2(a: i128) callconv(.C) i32 { | ... | @@ -26,12 +26,7 @@ pub fn __parityti2(a: i128) callconv(.C) i32 { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | inline fn parityXi2(comptime T: type, a: T) i32 { | 28 | inline fn parityXi2(comptime T: type, a: T) i32 { |
| 29 | var x = switch (@bitSizeOf(T)) { | 29 | var x: std.meta.Int(.unsigned, @typeInfo(T).Int.bits) = @bitCast(a); |
| 30 | 32 => @as(u32, @bitCast(a)), | ||
| 31 | 64 => @as(u64, @bitCast(a)), | ||
| 32 | 128 => @as(u128, @bitCast(a)), | ||
| 33 | else => unreachable, | ||
| 34 | }; | ||
| 35 | // Bit Twiddling Hacks: Compute parity in parallel | 30 | // Bit Twiddling Hacks: Compute parity in parallel |
| 36 | comptime var shift: u8 = @bitSizeOf(T) / 2; | 31 | comptime var shift: u8 = @bitSizeOf(T) / 2; |
| 37 | inline while (shift > 2) { | 32 | inline while (shift > 2) { |
| ... | @@ -39,7 +34,7 @@ inline fn parityXi2(comptime T: type, a: T) i32 { | ... | @@ -39,7 +34,7 @@ inline fn parityXi2(comptime T: type, a: T) i32 { |
| 39 | shift = shift >> 1; | 34 | shift = shift >> 1; |
| 40 | } | 35 | } |
| 41 | x &= 0xf; | 36 | x &= 0xf; |
| 42 | return (@as(u16, @intCast(0x6996)) >> @as(u4, @intCast(x))) & 1; // optimization for >>2 and >>1 | 37 | return (@as(u16, 0x6996) >> @intCast(x)) & 1; // optimization for >>2 and >>1 |
| 43 | } | 38 | } |
| 44 | 39 | ||
| 45 | test { | 40 | test { |
lib/compiler_rt/paritydi2_test.zig+5-5| ... | @@ -3,13 +3,13 @@ const parity = @import("parity.zig"); | ... | @@ -3,13 +3,13 @@ const parity = @import("parity.zig"); |
| 3 | const testing = std.testing; | 3 | const testing = std.testing; |
| 4 | 4 | ||
| 5 | fn paritydi2Naive(a: i64) i32 { | 5 | fn paritydi2Naive(a: i64) i32 { |
| 6 | var x = @as(u64, @bitCast(a)); | 6 | var x: u64 = @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; |
| 10 | x = x & (x - 1); | 10 | x = x & (x - 1); |
| 11 | } | 11 | } |
| 12 | return @as(i32, @intCast(@intFromBool(has_parity))); | 12 | return @intCast(@intFromBool(has_parity)); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn test__paritydi2(a: i64) !void { | 15 | fn test__paritydi2(a: i64) !void { |
| ... | @@ -22,9 +22,9 @@ test "paritydi2" { | ... | @@ -22,9 +22,9 @@ test "paritydi2" { |
| 22 | try test__paritydi2(0); | 22 | try test__paritydi2(0); |
| 23 | try test__paritydi2(1); | 23 | try test__paritydi2(1); |
| 24 | try test__paritydi2(2); | 24 | try test__paritydi2(2); |
| 25 | try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffd)))); | 25 | try test__paritydi2(@bitCast(@as(u64, 0xffffffff_fffffffd))); |
| 26 | try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe)))); | 26 | try test__paritydi2(@bitCast(@as(u64, 0xffffffff_fffffffe))); |
| 27 | try test__paritydi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff)))); | 27 | try test__paritydi2(@bitCast(@as(u64, 0xffffffff_ffffffff))); |
| 28 | 28 | ||
| 29 | const RndGen = std.rand.DefaultPrng; | 29 | const RndGen = std.rand.DefaultPrng; |
| 30 | var rnd = RndGen.init(42); | 30 | var rnd = RndGen.init(42); |
lib/compiler_rt/paritysi2_test.zig+5-5| ... | @@ -3,13 +3,13 @@ const parity = @import("parity.zig"); | ... | @@ -3,13 +3,13 @@ const parity = @import("parity.zig"); |
| 3 | const testing = std.testing; | 3 | const testing = std.testing; |
| 4 | 4 | ||
| 5 | fn paritysi2Naive(a: i32) i32 { | 5 | fn paritysi2Naive(a: i32) i32 { |
| 6 | var x = @as(u32, @bitCast(a)); | 6 | var x: u32 = @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; |
| 10 | x = x & (x - 1); | 10 | x = x & (x - 1); |
| 11 | } | 11 | } |
| 12 | return @as(i32, @intCast(@intFromBool(has_parity))); | 12 | return @intCast(@intFromBool(has_parity)); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn test__paritysi2(a: i32) !void { | 15 | fn test__paritysi2(a: i32) !void { |
| ... | @@ -22,9 +22,9 @@ test "paritysi2" { | ... | @@ -22,9 +22,9 @@ test "paritysi2" { |
| 22 | try test__paritysi2(0); | 22 | try test__paritysi2(0); |
| 23 | try test__paritysi2(1); | 23 | try test__paritysi2(1); |
| 24 | try test__paritysi2(2); | 24 | try test__paritysi2(2); |
| 25 | try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffd)))); | 25 | try test__paritysi2(@bitCast(@as(u32, 0xfffffffd))); |
| 26 | try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xfffffffe)))); | 26 | try test__paritysi2(@bitCast(@as(u32, 0xfffffffe))); |
| 27 | try test__paritysi2(@as(i32, @bitCast(@as(u32, 0xffffffff)))); | 27 | try test__paritysi2(@bitCast(@as(u32, 0xffffffff))); |
| 28 | 28 | ||
| 29 | const RndGen = std.rand.DefaultPrng; | 29 | const RndGen = std.rand.DefaultPrng; |
| 30 | var rnd = RndGen.init(42); | 30 | var rnd = RndGen.init(42); |
lib/compiler_rt/parityti2_test.zig+4-4| ... | @@ -9,7 +9,7 @@ fn parityti2Naive(a: i128) i32 { | ... | @@ -9,7 +9,7 @@ fn parityti2Naive(a: i128) i32 { |
| 9 | has_parity = !has_parity; | 9 | has_parity = !has_parity; |
| 10 | x = x & (x - 1); | 10 | x = x & (x - 1); |
| 11 | } | 11 | } |
| 12 | return @as(i32, @intCast(@intFromBool(has_parity))); | 12 | return @intCast(@intFromBool(has_parity)); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn test__parityti2(a: i128) !void { | 15 | fn test__parityti2(a: i128) !void { |
| ... | @@ -22,9 +22,9 @@ test "parityti2" { | ... | @@ -22,9 +22,9 @@ test "parityti2" { |
| 22 | try test__parityti2(0); | 22 | try test__parityti2(0); |
| 23 | try test__parityti2(1); | 23 | try test__parityti2(1); |
| 24 | try test__parityti2(2); | 24 | try test__parityti2(2); |
| 25 | try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd)))); | 25 | try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffd))); |
| 26 | try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)))); | 26 | try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))); |
| 27 | try test__parityti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)))); | 27 | try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))); |
| 28 | 28 | ||
| 29 | const RndGen = std.rand.DefaultPrng; | 29 | const RndGen = std.rand.DefaultPrng; |
| 30 | var rnd = RndGen.init(42); | 30 | var rnd = RndGen.init(42); |
lib/compiler_rt/popcount.zig+2-2| ... | @@ -37,7 +37,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 { | ... | @@ -37,7 +37,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 { |
| 37 | i128 => u128, | 37 | i128 => u128, |
| 38 | else => unreachable, | 38 | else => unreachable, |
| 39 | }; | 39 | }; |
| 40 | var x = @as(UT, @bitCast(a)); | 40 | var x: UT = @bitCast(a); |
| 41 | x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos | 41 | x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos |
| 42 | x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles | 42 | x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles |
| 43 | + (x & (~@as(UT, 0) / 5)); | 43 | + (x & (~@as(UT, 0) / 5)); |
| ... | @@ -46,7 +46,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 { | ... | @@ -46,7 +46,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 { |
| 46 | // 8 most significant bits of x + (x<<8) + (x<<16) + .. | 46 | // 8 most significant bits of x + (x<<8) + (x<<16) + .. |
| 47 | x *%= ~@as(UT, 0) / 255; // 0x01...01 | 47 | x *%= ~@as(UT, 0) / 255; // 0x01...01 |
| 48 | x >>= (@bitSizeOf(ST) - 8); | 48 | x >>= (@bitSizeOf(ST) - 8); |
| 49 | return @as(i32, @intCast(x)); | 49 | return @intCast(x); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | test { | 52 | test { |
lib/compiler_rt/rem_pio2.zig+6-10| ... | @@ -25,10 +25,6 @@ const pio2_3 = 2.02226624871116645580e-21; // 0x3BA3198A, 0x2E000000 | ... | @@ -25,10 +25,6 @@ const pio2_3 = 2.02226624871116645580e-21; // 0x3BA3198A, 0x2E000000 |
| 25 | // pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) | 25 | // pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) |
| 26 | const pio2_3t = 8.47842766036889956997e-32; // 0x397B839A, 0x252049C1 | 26 | const pio2_3t = 8.47842766036889956997e-32; // 0x397B839A, 0x252049C1 |
| 27 | 27 | ||
| 28 | fn U(x: anytype) usize { | ||
| 29 | return @as(usize, @intCast(x)); | ||
| 30 | } | ||
| 31 | |||
| 32 | fn medium(ix: u32, x: f64, y: *[2]f64) i32 { | 28 | fn medium(ix: u32, x: f64, y: *[2]f64) i32 { |
| 33 | var w: f64 = undefined; | 29 | var w: f64 = undefined; |
| 34 | var t: f64 = undefined; | 30 | var t: f64 = undefined; |
| ... | @@ -41,7 +37,7 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 { | ... | @@ -41,7 +37,7 @@ fn medium(ix: u32, x: f64, y: *[2]f64) i32 { |
| 41 | 37 | ||
| 42 | // rint(x/(pi/2)) | 38 | // rint(x/(pi/2)) |
| 43 | @"fn" = x * invpio2 + toint - toint; | 39 | @"fn" = x * invpio2 + toint - toint; |
| 44 | n = @as(i32, @intFromFloat(@"fn")); | 40 | n = @intFromFloat(@"fn"); |
| 45 | r = x - @"fn" * pio2_1; | 41 | r = x - @"fn" * pio2_1; |
| 46 | w = @"fn" * pio2_1t; // 1st round, good to 85 bits | 42 | w = @"fn" * pio2_1t; // 1st round, good to 85 bits |
| 47 | // Matters with directed rounding. | 43 | // Matters with directed rounding. |
| ... | @@ -174,16 +170,16 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 { | ... | @@ -174,16 +170,16 @@ pub fn rem_pio2(x: f64, y: *[2]f64) i32 { |
| 174 | ui = @bitCast(x); | 170 | ui = @bitCast(x); |
| 175 | ui &= std.math.maxInt(u64) >> 12; | 171 | ui &= std.math.maxInt(u64) >> 12; |
| 176 | ui |= @as(u64, 0x3ff + 23) << 52; | 172 | ui |= @as(u64, 0x3ff + 23) << 52; |
| 177 | z = @as(f64, @bitCast(ui)); | 173 | z = @bitCast(ui); |
| 178 | 174 | ||
| 179 | i = 0; | 175 | i = 0; |
| 180 | while (i < 2) : (i += 1) { | 176 | while (i < 2) : (i += 1) { |
| 181 | tx[U(i)] = @as(f64, @floatFromInt(@as(i32, @intFromFloat(z)))); | 177 | tx[@intCast(i)] = @floatFromInt(@as(i32, @intFromFloat(z))); |
| 182 | z = (z - tx[U(i)]) * 0x1p24; | 178 | z = (z - tx[@intCast(i)]) * 0x1p24; |
| 183 | } | 179 | } |
| 184 | tx[U(i)] = z; | 180 | tx[@intCast(i)] = z; |
| 185 | // skip zero terms, first term is non-zero | 181 | // skip zero terms, first term is non-zero |
| 186 | while (tx[U(i)] == 0.0) { | 182 | while (tx[@intCast(i)] == 0.0) { |
| 187 | i -= 1; | 183 | i -= 1; |
| 188 | } | 184 | } |
| 189 | n = rem_pio2_large(tx[0..], ty[0..], @as(i32, @intCast((ix >> 20))) - (0x3ff + 23), i + 1, 1); | 185 | n = rem_pio2_large(tx[0..], ty[0..], @as(i32, @intCast((ix >> 20))) - (0x3ff + 23), i + 1, 1); |
lib/compiler_rt/rem_pio2_large.zig+38-42| ... | @@ -149,10 +149,6 @@ const PIo2 = [_]f64{ | ... | @@ -149,10 +149,6 @@ const PIo2 = [_]f64{ |
| 149 | 2.16741683877804819444e-51, // 0x3569F31D, 0x00000000 | 149 | 2.16741683877804819444e-51, // 0x3569F31D, 0x00000000 |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | fn U(x: anytype) usize { | ||
| 153 | return @as(usize, @intCast(x)); | ||
| 154 | } | ||
| 155 | |||
| 156 | /// Returns the last three digits of N with y = x - N*pi/2 so that |y| < pi/2. | 152 | /// Returns the last three digits of N with y = x - N*pi/2 so that |y| < pi/2. |
| 157 | /// | 153 | /// |
| 158 | /// The method is to compute the integer (mod 8) and fraction parts of | 154 | /// The method is to compute the integer (mod 8) and fraction parts of |
| ... | @@ -295,7 +291,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -295,7 +291,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 295 | i += 1; | 291 | i += 1; |
| 296 | j += 1; | 292 | j += 1; |
| 297 | }) { | 293 | }) { |
| 298 | f[U(i)] = if (j < 0) 0.0 else @as(f64, @floatFromInt(ipio2[U(j)])); | 294 | f[@intCast(i)] = if (j < 0) 0.0 else @floatFromInt(ipio2[@intCast(j)]); |
| 299 | } | 295 | } |
| 300 | 296 | ||
| 301 | // compute q[0],q[1],...q[jk] | 297 | // compute q[0],q[1],...q[jk] |
| ... | @@ -304,9 +300,9 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -304,9 +300,9 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 304 | j = 0; | 300 | j = 0; |
| 305 | fw = 0; | 301 | fw = 0; |
| 306 | while (j <= jx) : (j += 1) { | 302 | while (j <= jx) : (j += 1) { |
| 307 | fw += x[U(j)] * f[U(jx + i - j)]; | 303 | fw += x[@intCast(j)] * f[@intCast(jx + i - j)]; |
| 308 | } | 304 | } |
| 309 | q[U(i)] = fw; | 305 | q[@intCast(i)] = fw; |
| 310 | } | 306 | } |
| 311 | 307 | ||
| 312 | jz = jk; | 308 | jz = jk; |
| ... | @@ -317,29 +313,29 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -317,29 +313,29 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 317 | // distill q[] into iq[] reversingly | 313 | // distill q[] into iq[] reversingly |
| 318 | i = 0; | 314 | i = 0; |
| 319 | j = jz; | 315 | j = jz; |
| 320 | z = q[U(jz)]; | 316 | z = q[@intCast(jz)]; |
| 321 | while (j > 0) : ({ | 317 | while (j > 0) : ({ |
| 322 | i += 1; | 318 | i += 1; |
| 323 | j -= 1; | 319 | j -= 1; |
| 324 | }) { | 320 | }) { |
| 325 | fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))); | 321 | fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))); |
| 326 | iq[U(i)] = @as(i32, @intFromFloat(z - 0x1p24 * fw)); | 322 | iq[@intCast(i)] = @intFromFloat(z - 0x1p24 * fw); |
| 327 | z = q[U(j - 1)] + fw; | 323 | z = q[@intCast(j - 1)] + fw; |
| 328 | } | 324 | } |
| 329 | 325 | ||
| 330 | // compute n | 326 | // compute n |
| 331 | z = math.scalbn(z, q0); // actual value of z | 327 | z = math.scalbn(z, q0); // actual value of z |
| 332 | z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8 | 328 | z -= 8.0 * @floor(z * 0.125); // trim off integer >= 8 |
| 333 | n = @intFromFloat(z); | 329 | n = @intFromFloat(z); |
| 334 | z -= @as(f64, @floatFromInt(n)); | 330 | z -= @floatFromInt(n); |
| 335 | ih = 0; | 331 | ih = 0; |
| 336 | if (q0 > 0) { // need iq[jz-1] to determine n | 332 | if (q0 > 0) { // need iq[jz-1] to determine n |
| 337 | i = iq[U(jz - 1)] >> @as(u5, @intCast(24 - q0)); | 333 | i = iq[@intCast(jz - 1)] >> @intCast(24 - q0); |
| 338 | n += i; | 334 | n += i; |
| 339 | iq[U(jz - 1)] -= i << @as(u5, @intCast(24 - q0)); | 335 | iq[@intCast(jz - 1)] -= i << @intCast(24 - q0); |
| 340 | ih = iq[U(jz - 1)] >> @as(u5, @intCast(23 - q0)); | 336 | ih = iq[@intCast(jz - 1)] >> @intCast(23 - q0); |
| 341 | } else if (q0 == 0) { | 337 | } else if (q0 == 0) { |
| 342 | ih = iq[U(jz - 1)] >> 23; | 338 | ih = iq[@intCast(jz - 1)] >> 23; |
| 343 | } else if (z >= 0.5) { | 339 | } else if (z >= 0.5) { |
| 344 | ih = 2; | 340 | ih = 2; |
| 345 | } | 341 | } |
| ... | @@ -349,20 +345,20 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -349,20 +345,20 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 349 | carry = 0; | 345 | carry = 0; |
| 350 | i = 0; | 346 | i = 0; |
| 351 | while (i < jz) : (i += 1) { // compute 1-q | 347 | while (i < jz) : (i += 1) { // compute 1-q |
| 352 | j = iq[U(i)]; | 348 | j = iq[@intCast(i)]; |
| 353 | if (carry == 0) { | 349 | if (carry == 0) { |
| 354 | if (j != 0) { | 350 | if (j != 0) { |
| 355 | carry = 1; | 351 | carry = 1; |
| 356 | iq[U(i)] = 0x1000000 - j; | 352 | iq[@intCast(i)] = 0x1000000 - j; |
| 357 | } | 353 | } |
| 358 | } else { | 354 | } else { |
| 359 | iq[U(i)] = 0xffffff - j; | 355 | iq[@intCast(i)] = 0xffffff - j; |
| 360 | } | 356 | } |
| 361 | } | 357 | } |
| 362 | if (q0 > 0) { // rare case: chance is 1 in 12 | 358 | if (q0 > 0) { // rare case: chance is 1 in 12 |
| 363 | switch (q0) { | 359 | switch (q0) { |
| 364 | 1 => iq[U(jz - 1)] &= 0x7fffff, | 360 | 1 => iq[@intCast(jz - 1)] &= 0x7fffff, |
| 365 | 2 => iq[U(jz - 1)] &= 0x3fffff, | 361 | 2 => iq[@intCast(jz - 1)] &= 0x3fffff, |
| 366 | else => unreachable, | 362 | else => unreachable, |
| 367 | } | 363 | } |
| 368 | } | 364 | } |
| ... | @@ -379,24 +375,24 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -379,24 +375,24 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 379 | j = 0; | 375 | j = 0; |
| 380 | i = jz - 1; | 376 | i = jz - 1; |
| 381 | while (i >= jk) : (i -= 1) { | 377 | while (i >= jk) : (i -= 1) { |
| 382 | j |= iq[U(i)]; | 378 | j |= iq[@intCast(i)]; |
| 383 | } | 379 | } |
| 384 | 380 | ||
| 385 | if (j == 0) { // need recomputation | 381 | if (j == 0) { // need recomputation |
| 386 | k = 1; | 382 | k = 1; |
| 387 | while (iq[U(jk - k)] == 0) : (k += 1) { | 383 | while (iq[@intCast(jk - k)] == 0) : (k += 1) { |
| 388 | // k = no. of terms needed | 384 | // k = no. of terms needed |
| 389 | } | 385 | } |
| 390 | 386 | ||
| 391 | i = jz + 1; | 387 | i = jz + 1; |
| 392 | while (i <= jz + k) : (i += 1) { // add q[jz+1] to q[jz+k] | 388 | while (i <= jz + k) : (i += 1) { // add q[jz+1] to q[jz+k] |
| 393 | f[U(jx + i)] = @as(f64, @floatFromInt(ipio2[U(jv + i)])); | 389 | f[@intCast(jx + i)] = @floatFromInt(ipio2[@intCast(jv + i)]); |
| 394 | j = 0; | 390 | j = 0; |
| 395 | fw = 0; | 391 | fw = 0; |
| 396 | while (j <= jx) : (j += 1) { | 392 | while (j <= jx) : (j += 1) { |
| 397 | fw += x[U(j)] * f[U(jx + i - j)]; | 393 | fw += x[@intCast(j)] * f[@intCast(jx + i - j)]; |
| 398 | } | 394 | } |
| 399 | q[U(i)] = fw; | 395 | q[@intCast(i)] = fw; |
| 400 | } | 396 | } |
| 401 | jz += k; | 397 | jz += k; |
| 402 | continue :recompute; // mimic goto recompute | 398 | continue :recompute; // mimic goto recompute |
| ... | @@ -407,7 +403,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -407,7 +403,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 407 | if (z == 0.0) { | 403 | if (z == 0.0) { |
| 408 | jz -= 1; | 404 | jz -= 1; |
| 409 | q0 -= 24; | 405 | q0 -= 24; |
| 410 | while (iq[U(jz)] == 0) { | 406 | while (iq[@intCast(jz)] == 0) { |
| 411 | jz -= 1; | 407 | jz -= 1; |
| 412 | q0 -= 24; | 408 | q0 -= 24; |
| 413 | } | 409 | } |
| ... | @@ -415,12 +411,12 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -415,12 +411,12 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 415 | z = math.scalbn(z, -q0); | 411 | z = math.scalbn(z, -q0); |
| 416 | if (z >= 0x1p24) { | 412 | if (z >= 0x1p24) { |
| 417 | fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))); | 413 | fw = @floatFromInt(@as(i32, @intFromFloat(0x1p-24 * z))); |
| 418 | iq[U(jz)] = @as(i32, @intFromFloat(z - 0x1p24 * fw)); | 414 | iq[@intCast(jz)] = @intFromFloat(z - 0x1p24 * fw); |
| 419 | jz += 1; | 415 | jz += 1; |
| 420 | q0 += 24; | 416 | q0 += 24; |
| 421 | iq[U(jz)] = @as(i32, @intFromFloat(fw)); | 417 | iq[@intCast(jz)] = @intFromFloat(fw); |
| 422 | } else { | 418 | } else { |
| 423 | iq[U(jz)] = @as(i32, @intFromFloat(z)); | 419 | iq[@intCast(jz)] = @intFromFloat(z); |
| 424 | } | 420 | } |
| 425 | } | 421 | } |
| 426 | 422 | ||
| ... | @@ -428,7 +424,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -428,7 +424,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 428 | fw = math.scalbn(@as(f64, 1.0), q0); | 424 | fw = math.scalbn(@as(f64, 1.0), q0); |
| 429 | i = jz; | 425 | i = jz; |
| 430 | while (i >= 0) : (i -= 1) { | 426 | while (i >= 0) : (i -= 1) { |
| 431 | q[U(i)] = fw * @as(f64, @floatFromInt(iq[U(i)])); | 427 | q[@intCast(i)] = fw * @as(f64, @floatFromInt(iq[@intCast(i)])); |
| 432 | fw *= 0x1p-24; | 428 | fw *= 0x1p-24; |
| 433 | } | 429 | } |
| 434 | 430 | ||
| ... | @@ -438,9 +434,9 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -438,9 +434,9 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 438 | fw = 0; | 434 | fw = 0; |
| 439 | k = 0; | 435 | k = 0; |
| 440 | while (k <= jp and k <= jz - i) : (k += 1) { | 436 | while (k <= jp and k <= jz - i) : (k += 1) { |
| 441 | fw += PIo2[U(k)] * q[U(i + k)]; | 437 | fw += PIo2[@intCast(k)] * q[@intCast(i + k)]; |
| 442 | } | 438 | } |
| 443 | fq[U(jz - i)] = fw; | 439 | fq[@intCast(jz - i)] = fw; |
| 444 | } | 440 | } |
| 445 | 441 | ||
| 446 | // compress fq[] into y[] | 442 | // compress fq[] into y[] |
| ... | @@ -449,7 +445,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -449,7 +445,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 449 | fw = 0.0; | 445 | fw = 0.0; |
| 450 | i = jz; | 446 | i = jz; |
| 451 | while (i >= 0) : (i -= 1) { | 447 | while (i >= 0) : (i -= 1) { |
| 452 | fw += fq[U(i)]; | 448 | fw += fq[@intCast(i)]; |
| 453 | } | 449 | } |
| 454 | y[0] = if (ih == 0) fw else -fw; | 450 | y[0] = if (ih == 0) fw else -fw; |
| 455 | }, | 451 | }, |
| ... | @@ -458,7 +454,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -458,7 +454,7 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 458 | fw = 0.0; | 454 | fw = 0.0; |
| 459 | i = jz; | 455 | i = jz; |
| 460 | while (i >= 0) : (i -= 1) { | 456 | while (i >= 0) : (i -= 1) { |
| 461 | fw += fq[U(i)]; | 457 | fw += fq[@intCast(i)]; |
| 462 | } | 458 | } |
| 463 | // TODO: drop excess precision here once double_t is used | 459 | // TODO: drop excess precision here once double_t is used |
| 464 | fw = fw; | 460 | fw = fw; |
| ... | @@ -466,27 +462,27 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { | ... | @@ -466,27 +462,27 @@ pub fn rem_pio2_large(x: []f64, y: []f64, e0: i32, nx: i32, prec: usize) i32 { |
| 466 | fw = fq[0] - fw; | 462 | fw = fq[0] - fw; |
| 467 | i = 1; | 463 | i = 1; |
| 468 | while (i <= jz) : (i += 1) { | 464 | while (i <= jz) : (i += 1) { |
| 469 | fw += fq[U(i)]; | 465 | fw += fq[@intCast(i)]; |
| 470 | } | 466 | } |
| 471 | y[1] = if (ih == 0) fw else -fw; | 467 | y[1] = if (ih == 0) fw else -fw; |
| 472 | }, | 468 | }, |
| 473 | 3 => { // painful | 469 | 3 => { // painful |
| 474 | i = jz; | 470 | i = jz; |
| 475 | while (i > 0) : (i -= 1) { | 471 | while (i > 0) : (i -= 1) { |
| 476 | fw = fq[U(i - 1)] + fq[U(i)]; | 472 | fw = fq[@intCast(i - 1)] + fq[@intCast(i)]; |
| 477 | fq[U(i)] += fq[U(i - 1)] - fw; | 473 | fq[@intCast(i)] += fq[@intCast(i - 1)] - fw; |
| 478 | fq[U(i - 1)] = fw; | 474 | fq[@intCast(i - 1)] = fw; |
| 479 | } | 475 | } |
| 480 | i = jz; | 476 | i = jz; |
| 481 | while (i > 1) : (i -= 1) { | 477 | while (i > 1) : (i -= 1) { |
| 482 | fw = fq[U(i - 1)] + fq[U(i)]; | 478 | fw = fq[@intCast(i - 1)] + fq[@intCast(i)]; |
| 483 | fq[U(i)] += fq[U(i - 1)] - fw; | 479 | fq[@intCast(i)] += fq[@intCast(i - 1)] - fw; |
| 484 | fq[U(i - 1)] = fw; | 480 | fq[@intCast(i - 1)] = fw; |
| 485 | } | 481 | } |
| 486 | fw = 0; | 482 | fw = 0; |
| 487 | i = jz; | 483 | i = jz; |
| 488 | while (i >= 2) : (i -= 1) { | 484 | while (i >= 2) : (i -= 1) { |
| 489 | fw += fq[U(i)]; | 485 | fw += fq[@intCast(i)]; |
| 490 | } | 486 | } |
| 491 | if (ih == 0) { | 487 | if (ih == 0) { |
| 492 | y[0] = fq[0]; | 488 | y[0] = fq[0]; |
lib/compiler_rt/shift.zig+12-18| ... | @@ -30,20 +30,19 @@ comptime { | ... | @@ -30,20 +30,19 @@ comptime { |
| 30 | // Precondition: 0 <= b < bits_in_dword | 30 | // Precondition: 0 <= b < bits_in_dword |
| 31 | inline fn ashlXi3(comptime T: type, a: T, b: i32) T { | 31 | inline fn ashlXi3(comptime T: type, a: T, b: i32) T { |
| 32 | const word_t = common.HalveInt(T, false); | 32 | const word_t = common.HalveInt(T, false); |
| 33 | const S = Log2Int(word_t.HalfT); | ||
| 34 | 33 | ||
| 35 | const input = word_t{ .all = a }; | 34 | const input = word_t{ .all = a }; |
| 36 | var output: word_t = undefined; | 35 | var output: word_t = undefined; |
| 37 | 36 | ||
| 38 | if (b >= word_t.bits) { | 37 | if (b >= word_t.bits) { |
| 39 | output.s.low = 0; | 38 | output.s.low = 0; |
| 40 | output.s.high = input.s.low << @as(S, @intCast(b - word_t.bits)); | 39 | output.s.high = input.s.low << @intCast(b - word_t.bits); |
| 41 | } else if (b == 0) { | 40 | } else if (b == 0) { |
| 42 | return a; | 41 | return a; |
| 43 | } else { | 42 | } else { |
| 44 | output.s.low = input.s.low << @as(S, @intCast(b)); | 43 | output.s.low = input.s.low << @intCast(b); |
| 45 | output.s.high = input.s.high << @as(S, @intCast(b)); | 44 | output.s.high = input.s.high << @intCast(b); |
| 46 | output.s.high |= input.s.low >> @as(S, @intCast(word_t.bits - b)); | 45 | output.s.high |= input.s.low >> @intCast(word_t.bits - b); |
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | return output.all; | 48 | return output.all; |
| ... | @@ -53,24 +52,20 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T { | ... | @@ -53,24 +52,20 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T { |
| 53 | // Precondition: 0 <= b < T.bit_count | 52 | // Precondition: 0 <= b < T.bit_count |
| 54 | inline fn ashrXi3(comptime T: type, a: T, b: i32) T { | 53 | inline fn ashrXi3(comptime T: type, a: T, b: i32) T { |
| 55 | const word_t = common.HalveInt(T, true); | 54 | const word_t = common.HalveInt(T, true); |
| 56 | const S = Log2Int(word_t.HalfT); | ||
| 57 | 55 | ||
| 58 | const input = word_t{ .all = a }; | 56 | const input = word_t{ .all = a }; |
| 59 | var output: word_t = undefined; | 57 | var output: word_t = undefined; |
| 60 | 58 | ||
| 61 | if (b >= word_t.bits) { | 59 | if (b >= word_t.bits) { |
| 62 | output.s.high = input.s.high >> (word_t.bits - 1); | 60 | output.s.high = input.s.high >> (word_t.bits - 1); |
| 63 | output.s.low = input.s.high >> @as(S, @intCast(b - word_t.bits)); | 61 | output.s.low = input.s.high >> @intCast(b - word_t.bits); |
| 64 | } else if (b == 0) { | 62 | } else if (b == 0) { |
| 65 | return a; | 63 | return a; |
| 66 | } else { | 64 | } else { |
| 67 | output.s.high = input.s.high >> @as(S, @intCast(b)); | 65 | output.s.high = input.s.high >> @intCast(b); |
| 68 | output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b)); | 66 | output.s.low = input.s.high << @intCast(word_t.bits - b); |
| 69 | // Avoid sign-extension here | 67 | // Avoid sign-extension here |
| 70 | output.s.low |= @as( | 68 | output.s.low |= @bitCast(@as(word_t.HalfTU, @bitCast(input.s.low)) >> @intCast(b)); |
| 71 | word_t.HalfT, | ||
| 72 | @bitCast(@as(word_t.HalfTU, @bitCast(input.s.low)) >> @as(S, @intCast(b))), | ||
| 73 | ); | ||
| 74 | } | 69 | } |
| 75 | 70 | ||
| 76 | return output.all; | 71 | return output.all; |
| ... | @@ -80,20 +75,19 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T { | ... | @@ -80,20 +75,19 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T { |
| 80 | // Precondition: 0 <= b < T.bit_count | 75 | // Precondition: 0 <= b < T.bit_count |
| 81 | inline fn lshrXi3(comptime T: type, a: T, b: i32) T { | 76 | inline fn lshrXi3(comptime T: type, a: T, b: i32) T { |
| 82 | const word_t = common.HalveInt(T, false); | 77 | const word_t = common.HalveInt(T, false); |
| 83 | const S = Log2Int(word_t.HalfT); | ||
| 84 | 78 | ||
| 85 | const input = word_t{ .all = a }; | 79 | const input = word_t{ .all = a }; |
| 86 | var output: word_t = undefined; | 80 | var output: word_t = undefined; |
| 87 | 81 | ||
| 88 | if (b >= word_t.bits) { | 82 | if (b >= word_t.bits) { |
| 89 | output.s.high = 0; | 83 | output.s.high = 0; |
| 90 | output.s.low = input.s.high >> @as(S, @intCast(b - word_t.bits)); | 84 | output.s.low = input.s.high >> @intCast(b - word_t.bits); |
| 91 | } else if (b == 0) { | 85 | } else if (b == 0) { |
| 92 | return a; | 86 | return a; |
| 93 | } else { | 87 | } else { |
| 94 | output.s.high = input.s.high >> @as(S, @intCast(b)); | 88 | output.s.high = input.s.high >> @intCast(b); |
| 95 | output.s.low = input.s.high << @as(S, @intCast(word_t.bits - b)); | 89 | output.s.low = input.s.high << @intCast(word_t.bits - b); |
| 96 | output.s.low |= input.s.low >> @as(S, @intCast(b)); | 90 | output.s.low |= input.s.low >> @intCast(b); |
| 97 | } | 91 | } |
| 98 | 92 | ||
| 99 | return output.all; | 93 | return output.all; |
lib/compiler_rt/sin.zig+6-6| ... | @@ -31,7 +31,7 @@ comptime { | ... | @@ -31,7 +31,7 @@ comptime { |
| 31 | 31 | ||
| 32 | pub fn __sinh(x: f16) callconv(.C) f16 { | 32 | pub fn __sinh(x: f16) callconv(.C) f16 { |
| 33 | // TODO: more efficient implementation | 33 | // TODO: more efficient implementation |
| 34 | return @as(f16, @floatCast(sinf(x))); | 34 | return @floatCast(sinf(x)); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | pub fn sinf(x: f32) callconv(.C) f32 { | 37 | pub fn sinf(x: f32) callconv(.C) f32 { |
| ... | @@ -41,7 +41,7 @@ pub fn sinf(x: f32) callconv(.C) f32 { | ... | @@ -41,7 +41,7 @@ pub fn sinf(x: f32) callconv(.C) f32 { |
| 41 | const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2 | 41 | const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2 |
| 42 | const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18 | 42 | const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18 |
| 43 | 43 | ||
| 44 | var ix = @as(u32, @bitCast(x)); | 44 | var ix: u32 = @bitCast(x); |
| 45 | const sign = ix >> 31 != 0; | 45 | const sign = ix >> 31 != 0; |
| 46 | ix &= 0x7fffffff; | 46 | ix &= 0x7fffffff; |
| 47 | 47 | ||
| ... | @@ -120,12 +120,12 @@ pub fn sin(x: f64) callconv(.C) f64 { | ... | @@ -120,12 +120,12 @@ pub fn sin(x: f64) callconv(.C) f64 { |
| 120 | 120 | ||
| 121 | pub fn __sinx(x: f80) callconv(.C) f80 { | 121 | pub fn __sinx(x: f80) callconv(.C) f80 { |
| 122 | // TODO: more efficient implementation | 122 | // TODO: more efficient implementation |
| 123 | return @as(f80, @floatCast(sinq(x))); | 123 | return @floatCast(sinq(x)); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | pub fn sinq(x: f128) callconv(.C) f128 { | 126 | pub fn sinq(x: f128) callconv(.C) f128 { |
| 127 | // TODO: more correct implementation | 127 | // TODO: more correct implementation |
| 128 | return sin(@as(f64, @floatCast(x))); | 128 | return sin(@floatCast(x)); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble { | 131 | pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble { |
| ... | @@ -180,11 +180,11 @@ test "sin64.special" { | ... | @@ -180,11 +180,11 @@ test "sin64.special" { |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | test "sin32 #9901" { | 182 | test "sin32 #9901" { |
| 183 | const float = @as(f32, @bitCast(@as(u32, 0b11100011111111110000000000000000))); | 183 | const float: f32 = @bitCast(@as(u32, 0b11100011111111110000000000000000)); |
| 184 | _ = sinf(float); | 184 | _ = sinf(float); |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | test "sin64 #9901" { | 187 | test "sin64 #9901" { |
| 188 | const float = @as(f64, @bitCast(@as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001))); | 188 | const float: f64 = @bitCast(@as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001)); |
| 189 | _ = sin(float); | 189 | _ = sin(float); |
| 190 | } | 190 | } |
lib/compiler_rt/sqrt.zig+13-13| ... | @@ -20,13 +20,13 @@ comptime { | ... | @@ -20,13 +20,13 @@ comptime { |
| 20 | 20 | ||
| 21 | pub fn __sqrth(x: f16) callconv(.C) f16 { | 21 | pub fn __sqrth(x: f16) callconv(.C) f16 { |
| 22 | // TODO: more efficient implementation | 22 | // TODO: more efficient implementation |
| 23 | return @as(f16, @floatCast(sqrtf(x))); | 23 | return @floatCast(sqrtf(x)); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | pub fn sqrtf(x: f32) callconv(.C) f32 { | 26 | pub fn sqrtf(x: f32) callconv(.C) f32 { |
| 27 | const tiny: f32 = 1.0e-30; | 27 | const tiny: f32 = 1.0e-30; |
| 28 | const sign: i32 = @as(i32, @bitCast(@as(u32, 0x80000000))); | 28 | const sign: i32 = @bitCast(@as(u32, 0x80000000)); |
| 29 | var ix: i32 = @as(i32, @bitCast(x)); | 29 | var ix: i32 = @bitCast(x); |
| 30 | 30 | ||
| 31 | if ((ix & 0x7F800000) == 0x7F800000) { | 31 | if ((ix & 0x7F800000) == 0x7F800000) { |
| 32 | return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan | 32 | return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan |
| ... | @@ -96,7 +96,7 @@ pub fn sqrtf(x: f32) callconv(.C) f32 { | ... | @@ -96,7 +96,7 @@ pub fn sqrtf(x: f32) callconv(.C) f32 { |
| 96 | 96 | ||
| 97 | ix = (q >> 1) + 0x3f000000; | 97 | ix = (q >> 1) + 0x3f000000; |
| 98 | ix += m << 23; | 98 | ix += m << 23; |
| 99 | return @as(f32, @bitCast(ix)); | 99 | return @bitCast(ix); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | /// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound | 102 | /// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound |
| ... | @@ -105,10 +105,10 @@ pub fn sqrtf(x: f32) callconv(.C) f32 { | ... | @@ -105,10 +105,10 @@ pub fn sqrtf(x: f32) callconv(.C) f32 { |
| 105 | pub fn sqrt(x: f64) callconv(.C) f64 { | 105 | pub fn sqrt(x: f64) callconv(.C) f64 { |
| 106 | const tiny: f64 = 1.0e-300; | 106 | const tiny: f64 = 1.0e-300; |
| 107 | const sign: u32 = 0x80000000; | 107 | const sign: u32 = 0x80000000; |
| 108 | const u = @as(u64, @bitCast(x)); | 108 | const u: u64 = @bitCast(x); |
| 109 | 109 | ||
| 110 | var ix0 = @as(u32, @intCast(u >> 32)); | 110 | var ix0: u32 = @intCast(u >> 32); |
| 111 | var ix1 = @as(u32, @intCast(u & 0xFFFFFFFF)); | 111 | var ix1: u32 = @intCast(u & 0xFFFFFFFF); |
| 112 | 112 | ||
| 113 | // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan | 113 | // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan |
| 114 | if (ix0 & 0x7FF00000 == 0x7FF00000) { | 114 | if (ix0 & 0x7FF00000 == 0x7FF00000) { |
| ... | @@ -140,8 +140,8 @@ pub fn sqrt(x: f64) callconv(.C) f64 { | ... | @@ -140,8 +140,8 @@ pub fn sqrt(x: f64) callconv(.C) f64 { |
| 140 | ix0 <<= 1; | 140 | ix0 <<= 1; |
| 141 | } | 141 | } |
| 142 | m -= @as(i32, @intCast(i)) - 1; | 142 | m -= @as(i32, @intCast(i)) - 1; |
| 143 | ix0 |= ix1 >> @as(u5, @intCast(32 - i)); | 143 | ix0 |= ix1 >> @intCast(32 - i); |
| 144 | ix1 <<= @as(u5, @intCast(i)); | 144 | ix1 <<= @intCast(i); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | // unbias exponent | 147 | // unbias exponent |
| ... | @@ -225,21 +225,21 @@ pub fn sqrt(x: f64) callconv(.C) f64 { | ... | @@ -225,21 +225,21 @@ pub fn sqrt(x: f64) callconv(.C) f64 { |
| 225 | 225 | ||
| 226 | // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same | 226 | // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same |
| 227 | // behaviour at least. | 227 | // behaviour at least. |
| 228 | var iix0 = @as(i32, @intCast(ix0)); | 228 | var iix0: i32 = @intCast(ix0); |
| 229 | iix0 = iix0 +% (m << 20); | 229 | iix0 = iix0 +% (m << 20); |
| 230 | 230 | ||
| 231 | const uz = (@as(u64, @intCast(iix0)) << 32) | ix1; | 231 | const uz = (@as(u64, @intCast(iix0)) << 32) | ix1; |
| 232 | return @as(f64, @bitCast(uz)); | 232 | return @bitCast(uz); |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | pub fn __sqrtx(x: f80) callconv(.C) f80 { | 235 | pub fn __sqrtx(x: f80) callconv(.C) f80 { |
| 236 | // TODO: more efficient implementation | 236 | // TODO: more efficient implementation |
| 237 | return @as(f80, @floatCast(sqrtq(x))); | 237 | return @floatCast(sqrtq(x)); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | pub fn sqrtq(x: f128) callconv(.C) f128 { | 240 | pub fn sqrtq(x: f128) callconv(.C) f128 { |
| 241 | // TODO: more correct implementation | 241 | // TODO: more correct implementation |
| 242 | return sqrt(@as(f64, @floatCast(x))); | 242 | return sqrt(@floatCast(x)); |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble { | 245 | pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/tan.zig+2-2| ... | @@ -106,12 +106,12 @@ pub fn tan(x: f64) callconv(.C) f64 { | ... | @@ -106,12 +106,12 @@ pub fn tan(x: f64) callconv(.C) f64 { |
| 106 | 106 | ||
| 107 | pub fn __tanx(x: f80) callconv(.C) f80 { | 107 | pub fn __tanx(x: f80) callconv(.C) f80 { |
| 108 | // TODO: more efficient implementation | 108 | // TODO: more efficient implementation |
| 109 | return @as(f80, @floatCast(tanq(x))); | 109 | return @floatCast(tanq(x)); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | pub fn tanq(x: f128) callconv(.C) f128 { | 112 | pub fn tanq(x: f128) callconv(.C) f128 { |
| 113 | // TODO: more correct implementation | 113 | // TODO: more correct implementation |
| 114 | return tan(@as(f64, @floatCast(x))); | 114 | return tan(@floatCast(x)); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble { | 117 | pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble { |
lib/compiler_rt/trig.zig+5-5| ... | @@ -70,7 +70,7 @@ pub fn __cosdf(x: f64) f32 { | ... | @@ -70,7 +70,7 @@ pub fn __cosdf(x: f64) f32 { |
| 70 | const z = x * x; | 70 | const z = x * x; |
| 71 | const w = z * z; | 71 | const w = z * z; |
| 72 | const r = C2 + z * C3; | 72 | const r = C2 + z * C3; |
| 73 | return @as(f32, @floatCast(((1.0 + z * C0) + w * C1) + (w * z) * r)); | 73 | return @floatCast(((1.0 + z * C0) + w * C1) + (w * z) * r); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | /// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 | 76 | /// kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 |
| ... | @@ -131,7 +131,7 @@ pub fn __sindf(x: f64) f32 { | ... | @@ -131,7 +131,7 @@ pub fn __sindf(x: f64) f32 { |
| 131 | const w = z * z; | 131 | const w = z * z; |
| 132 | const r = S3 + z * S4; | 132 | const r = S3 + z * S4; |
| 133 | const s = z * x; | 133 | const s = z * x; |
| 134 | return @as(f32, @floatCast((x + s * (S1 + z * S2)) + s * w * r)); | 134 | return @floatCast((x + s * (S1 + z * S2)) + s * w * r); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | /// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 | 137 | /// kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 |
| ... | @@ -231,11 +231,11 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 { | ... | @@ -231,11 +231,11 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 { |
| 231 | } | 231 | } |
| 232 | // -1.0/(x+r) has up to 2ulp error, so compute it accurately | 232 | // -1.0/(x+r) has up to 2ulp error, so compute it accurately |
| 233 | w0 = w; | 233 | w0 = w; |
| 234 | w0 = @as(f64, @bitCast(@as(u64, @bitCast(w0)) & 0xffffffff00000000)); | 234 | w0 = @bitCast(@as(u64, @bitCast(w0)) & 0xffffffff00000000); |
| 235 | v = r - (w0 - x); // w0+v = r+x | 235 | v = r - (w0 - x); // w0+v = r+x |
| 236 | a = -1.0 / w; | 236 | a = -1.0 / w; |
| 237 | a0 = a; | 237 | a0 = a; |
| 238 | a0 = @as(f64, @bitCast(@as(u64, @bitCast(a0)) & 0xffffffff00000000)); | 238 | a0 = @bitCast(@as(u64, @bitCast(a0)) & 0xffffffff00000000); |
| 239 | return a0 + a * (1.0 + a0 * w0 + a0 * v); | 239 | return a0 + a * (1.0 + a0 * w0 + a0 * v); |
| 240 | } | 240 | } |
| 241 | 241 | ||
| ... | @@ -269,5 +269,5 @@ pub fn __tandf(x: f64, odd: bool) f32 { | ... | @@ -269,5 +269,5 @@ pub fn __tandf(x: f64, odd: bool) f32 { |
| 269 | const s = z * x; | 269 | const s = z * x; |
| 270 | const u = T[0] + z * T[1]; | 270 | const u = T[0] + z * T[1]; |
| 271 | const r0 = (x + s * u) + (s * w) * (t + w * r); | 271 | const r0 = (x + s * u) + (s * w) * (t + w * r); |
| 272 | return @as(f32, @floatCast(if (odd) -1.0 / r0 else r0)); | 272 | return @floatCast(if (odd) -1.0 / r0 else r0); |
| 273 | } | 273 | } |
lib/compiler_rt/trunc.zig+6-6| ... | @@ -42,7 +42,7 @@ pub fn truncf(x: f32) callconv(.C) f32 { | ... | @@ -42,7 +42,7 @@ pub fn truncf(x: f32) callconv(.C) f32 { |
| 42 | e = 1; | 42 | e = 1; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | m = @as(u32, math.maxInt(u32)) >> @as(u5, @intCast(e)); | 45 | m = @as(u32, math.maxInt(u32)) >> @intCast(e); |
| 46 | if (u & m == 0) { | 46 | if (u & m == 0) { |
| 47 | return x; | 47 | return x; |
| 48 | } else { | 48 | } else { |
| ... | @@ -63,7 +63,7 @@ pub fn trunc(x: f64) callconv(.C) f64 { | ... | @@ -63,7 +63,7 @@ pub fn trunc(x: f64) callconv(.C) f64 { |
| 63 | e = 1; | 63 | e = 1; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | m = @as(u64, math.maxInt(u64)) >> @as(u6, @intCast(e)); | 66 | m = @as(u64, math.maxInt(u64)) >> @intCast(e); |
| 67 | if (u & m == 0) { | 67 | if (u & m == 0) { |
| 68 | return x; | 68 | return x; |
| 69 | } else { | 69 | } else { |
| ... | @@ -74,11 +74,11 @@ pub fn trunc(x: f64) callconv(.C) f64 { | ... | @@ -74,11 +74,11 @@ pub fn trunc(x: f64) callconv(.C) f64 { |
| 74 | 74 | ||
| 75 | pub fn __truncx(x: f80) callconv(.C) f80 { | 75 | pub fn __truncx(x: f80) callconv(.C) f80 { |
| 76 | // TODO: more efficient implementation | 76 | // TODO: more efficient implementation |
| 77 | return @as(f80, @floatCast(truncq(x))); | 77 | return @floatCast(truncq(x)); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | pub fn truncq(x: f128) callconv(.C) f128 { | 80 | pub fn truncq(x: f128) callconv(.C) f128 { |
| 81 | const u = @as(u128, @bitCast(x)); | 81 | const u: u128 = @bitCast(x); |
| 82 | var e = @as(i32, @intCast(((u >> 112) & 0x7FFF))) - 0x3FFF + 16; | 82 | var e = @as(i32, @intCast(((u >> 112) & 0x7FFF))) - 0x3FFF + 16; |
| 83 | var m: u128 = undefined; | 83 | var m: u128 = undefined; |
| 84 | 84 | ||
| ... | @@ -89,12 +89,12 @@ pub fn truncq(x: f128) callconv(.C) f128 { | ... | @@ -89,12 +89,12 @@ pub fn truncq(x: f128) callconv(.C) f128 { |
| 89 | e = 1; | 89 | e = 1; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | m = @as(u128, math.maxInt(u128)) >> @as(u7, @intCast(e)); | 92 | m = @as(u128, math.maxInt(u128)) >> @intCast(e); |
| 93 | if (u & m == 0) { | 93 | if (u & m == 0) { |
| 94 | return x; | 94 | return x; |
| 95 | } else { | 95 | } else { |
| 96 | math.doNotOptimizeAway(x + 0x1p120); | 96 | math.doNotOptimizeAway(x + 0x1p120); |
| 97 | return @as(f128, @bitCast(u & ~m)); | 97 | return @bitCast(u & ~m); |
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| 100 | 100 |
lib/compiler_rt/truncdfhf2.zig+2-2| ... | @@ -12,9 +12,9 @@ comptime { | ... | @@ -12,9 +12,9 @@ comptime { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) { | 14 | pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) { |
| 15 | return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a))); | 15 | return @bitCast(truncf(f16, f64, a)); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 { | 18 | fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 { |
| 19 | return @as(common.F16T(f64), @bitCast(truncf(f16, f64, a))); | 19 | return @bitCast(truncf(f16, f64, a)); |
| 20 | } | 20 | } |
lib/compiler_rt/truncf.zig+14-15| ... | @@ -5,7 +5,6 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -5,7 +5,6 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 5 | const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits); | 5 | const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits); |
| 6 | const srcSigBits = std.math.floatMantissaBits(src_t); | 6 | const srcSigBits = std.math.floatMantissaBits(src_t); |
| 7 | const dstSigBits = std.math.floatMantissaBits(dst_t); | 7 | const dstSigBits = std.math.floatMantissaBits(dst_t); |
| 8 | const SrcShift = std.math.Log2Int(src_rep_t); | ||
| 9 | 8 | ||
| 10 | // Various constants whose values follow from the type parameters. | 9 | // Various constants whose values follow from the type parameters. |
| 11 | // Any reasonable optimizer will fold and propagate all of these. | 10 | // Any reasonable optimizer will fold and propagate all of these. |
| ... | @@ -38,7 +37,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -38,7 +37,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 38 | const dstNaNCode = dstQNaN - 1; | 37 | const dstNaNCode = dstQNaN - 1; |
| 39 | 38 | ||
| 40 | // Break a into a sign and representation of the absolute value | 39 | // Break a into a sign and representation of the absolute value |
| 41 | const aRep: src_rep_t = @as(src_rep_t, @bitCast(a)); | 40 | const aRep: src_rep_t = @bitCast(a); |
| 42 | const aAbs: src_rep_t = aRep & srcAbsMask; | 41 | const aAbs: src_rep_t = aRep & srcAbsMask; |
| 43 | const sign: src_rep_t = aRep & srcSignMask; | 42 | const sign: src_rep_t = aRep & srcSignMask; |
| 44 | var absResult: dst_rep_t = undefined; | 43 | var absResult: dst_rep_t = undefined; |
| ... | @@ -47,7 +46,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -47,7 +46,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 47 | // The exponent of a is within the range of normal numbers in the | 46 | // The exponent of a is within the range of normal numbers in the |
| 48 | // destination format. We can convert by simply right-shifting with | 47 | // destination format. We can convert by simply right-shifting with |
| 49 | // rounding and adjusting the exponent. | 48 | // rounding and adjusting the exponent. |
| 50 | absResult = @as(dst_rep_t, @truncate(aAbs >> (srcSigBits - dstSigBits))); | 49 | absResult = @truncate(aAbs >> (srcSigBits - dstSigBits)); |
| 51 | absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits; | 50 | absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits; |
| 52 | 51 | ||
| 53 | const roundBits: src_rep_t = aAbs & roundMask; | 52 | const roundBits: src_rep_t = aAbs & roundMask; |
| ... | @@ -64,7 +63,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -64,7 +63,7 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 64 | // bit and inserting the (truncated) trailing NaN field. | 63 | // bit and inserting the (truncated) trailing NaN field. |
| 65 | absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits; | 64 | absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits; |
| 66 | absResult |= dstQNaN; | 65 | absResult |= dstQNaN; |
| 67 | absResult |= @as(dst_rep_t, @intCast(((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode)); | 66 | absResult |= @intCast(((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode); |
| 68 | } else if (aAbs >= overflow) { | 67 | } else if (aAbs >= overflow) { |
| 69 | // a overflows to infinity. | 68 | // a overflows to infinity. |
| 70 | absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits; | 69 | absResult = @as(dst_rep_t, @intCast(dstInfExp)) << dstSigBits; |
| ... | @@ -81,9 +80,9 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -81,9 +80,9 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 81 | if (shift > srcSigBits) { | 80 | if (shift > srcSigBits) { |
| 82 | absResult = 0; | 81 | absResult = 0; |
| 83 | } else { | 82 | } else { |
| 84 | const sticky: src_rep_t = @intFromBool(significand << @as(SrcShift, @intCast(srcBits - shift)) != 0); | 83 | const sticky: src_rep_t = @intFromBool(significand << @intCast(srcBits - shift) != 0); |
| 85 | const denormalizedSignificand: src_rep_t = significand >> @as(SrcShift, @intCast(shift)) | sticky; | 84 | const denormalizedSignificand: src_rep_t = significand >> @intCast(shift) | sticky; |
| 86 | absResult = @as(dst_rep_t, @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits))); | 85 | absResult = @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits)); |
| 87 | const roundBits: src_rep_t = denormalizedSignificand & roundMask; | 86 | const roundBits: src_rep_t = denormalizedSignificand & roundMask; |
| 88 | if (roundBits > halfway) { | 87 | if (roundBits > halfway) { |
| 89 | // Round to nearest | 88 | // Round to nearest |
| ... | @@ -96,8 +95,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -96,8 +95,8 @@ pub inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | | 97 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | |
| 99 | @as(dst_rep_t, @truncate(sign >> @as(SrcShift, @intCast(srcBits - dstBits)))); | 98 | @as(dst_rep_t, @truncate(sign >> @intCast(srcBits - dstBits))); |
| 100 | return @as(dst_t, @bitCast(result)); | 99 | return @bitCast(result); |
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { | 102 | pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { |
| ... | @@ -133,7 +132,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { | ... | @@ -133,7 +132,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { |
| 133 | // destination format. We can convert by simply right-shifting with | 132 | // destination format. We can convert by simply right-shifting with |
| 134 | // rounding and adjusting the exponent. | 133 | // rounding and adjusting the exponent. |
| 135 | abs_result = @as(dst_rep_t, a_rep.exp) << dst_sig_bits; | 134 | abs_result = @as(dst_rep_t, a_rep.exp) << dst_sig_bits; |
| 136 | abs_result |= @as(dst_rep_t, @truncate(a_rep.fraction >> (src_sig_bits - dst_sig_bits))); | 135 | abs_result |= @truncate(a_rep.fraction >> (src_sig_bits - dst_sig_bits)); |
| 137 | abs_result -%= @as(dst_rep_t, src_exp_bias - dst_exp_bias) << dst_sig_bits; | 136 | abs_result -%= @as(dst_rep_t, src_exp_bias - dst_exp_bias) << dst_sig_bits; |
| 138 | 137 | ||
| 139 | const round_bits = a_rep.fraction & round_mask; | 138 | const round_bits = a_rep.fraction & round_mask; |
| ... | @@ -150,7 +149,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { | ... | @@ -150,7 +149,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { |
| 150 | // bit and inserting the (truncated) trailing NaN field. | 149 | // bit and inserting the (truncated) trailing NaN field. |
| 151 | abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits; | 150 | abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits; |
| 152 | abs_result |= dst_qnan; | 151 | abs_result |= dst_qnan; |
| 153 | abs_result |= @as(dst_rep_t, @intCast((a_rep.fraction >> (src_sig_bits - dst_sig_bits)) & dst_nan_mask)); | 152 | abs_result |= @intCast((a_rep.fraction >> (src_sig_bits - dst_sig_bits)) & dst_nan_mask); |
| 154 | } else if (a_rep.exp >= overflow) { | 153 | } else if (a_rep.exp >= overflow) { |
| 155 | // a overflows to infinity. | 154 | // a overflows to infinity. |
| 156 | abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits; | 155 | abs_result = @as(dst_rep_t, @intCast(dst_inf_exp)) << dst_sig_bits; |
| ... | @@ -164,9 +163,9 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { | ... | @@ -164,9 +163,9 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { |
| 164 | if (shift > src_sig_bits) { | 163 | if (shift > src_sig_bits) { |
| 165 | abs_result = 0; | 164 | abs_result = 0; |
| 166 | } else { | 165 | } else { |
| 167 | const sticky = @intFromBool(a_rep.fraction << @as(u6, @intCast(shift)) != 0); | 166 | const sticky = @intFromBool(a_rep.fraction << @intCast(shift) != 0); |
| 168 | const denormalized_significand = a_rep.fraction >> @as(u6, @intCast(shift)) | sticky; | 167 | const denormalized_significand = a_rep.fraction >> @intCast(shift) | sticky; |
| 169 | abs_result = @as(dst_rep_t, @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits))); | 168 | abs_result = @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits)); |
| 170 | const round_bits = denormalized_significand & round_mask; | 169 | const round_bits = denormalized_significand & round_mask; |
| 171 | if (round_bits > halfway) { | 170 | if (round_bits > halfway) { |
| 172 | // Round to nearest | 171 | // Round to nearest |
| ... | @@ -179,7 +178,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { | ... | @@ -179,7 +178,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t { |
| 179 | } | 178 | } |
| 180 | 179 | ||
| 181 | const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16; | 180 | const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16; |
| 182 | return @as(dst_t, @bitCast(result)); | 181 | return @bitCast(result); |
| 183 | } | 182 | } |
| 184 | 183 | ||
| 185 | test { | 184 | test { |
lib/compiler_rt/truncsfhf2.zig+3-3| ... | @@ -13,13 +13,13 @@ comptime { | ... | @@ -13,13 +13,13 @@ comptime { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) { | 15 | pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) { |
| 16 | return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a))); | 16 | return @bitCast(truncf(f16, f32, a)); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) { | 19 | fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) { |
| 20 | return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a))); | 20 | return @bitCast(truncf(f16, f32, a)); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 { | 23 | fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 { |
| 24 | return @as(common.F16T(f32), @bitCast(truncf(f16, f32, a))); | 24 | return @bitCast(truncf(f16, f32, a)); |
| 25 | } | 25 | } |
lib/compiler_rt/trunctfhf2.zig+1-1| ... | @@ -8,5 +8,5 @@ comptime { | ... | @@ -8,5 +8,5 @@ comptime { |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) { | 10 | pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) { |
| 11 | return @as(common.F16T(f128), @bitCast(truncf(f16, f128, a))); | 11 | return @bitCast(truncf(f16, f128, a)); |
| 12 | } | 12 | } |
lib/compiler_rt/truncxfhf2.zig+1-1| ... | @@ -8,5 +8,5 @@ comptime { | ... | @@ -8,5 +8,5 @@ comptime { |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) { | 10 | fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) { |
| 11 | return @as(common.F16T(f80), @bitCast(trunc_f80(f16, a))); | 11 | return @bitCast(trunc_f80(f16, a)); |
| 12 | } | 12 | } |
lib/compiler_rt/udivmod.zig+11-11| ... | @@ -21,11 +21,11 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { | ... | @@ -21,11 +21,11 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { |
| 21 | var un64: T = undefined; | 21 | var un64: T = undefined; |
| 22 | var un10: T = undefined; | 22 | var un10: T = undefined; |
| 23 | 23 | ||
| 24 | const s = @as(Log2Int(T), @intCast(@clz(v))); | 24 | const s: Log2Int(T) = @intCast(@clz(v)); |
| 25 | if (s > 0) { | 25 | if (s > 0) { |
| 26 | // Normalize divisor | 26 | // Normalize divisor |
| 27 | v <<= s; | 27 | v <<= s; |
| 28 | un64 = (_u1 << s) | (_u0 >> @as(Log2Int(T), @intCast((@bitSizeOf(T) - @as(T, @intCast(s)))))); | 28 | un64 = (_u1 << s) | (_u0 >> @intCast((@bitSizeOf(T) - @as(T, @intCast(s))))); |
| 29 | un10 = _u0 << s; | 29 | un10 = _u0 << s; |
| 30 | } else { | 30 | } else { |
| 31 | // Avoid undefined behavior of (u0 >> @bitSizeOf(T)) | 31 | // Avoid undefined behavior of (u0 >> @bitSizeOf(T)) |
| ... | @@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { | ... | @@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { |
| 101 | return 0; | 101 | return 0; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | var a = @as([2]HalfT, @bitCast(a_)); | 104 | var a: [2]HalfT = @bitCast(a_); |
| 105 | var b = @as([2]HalfT, @bitCast(b_)); | 105 | var b: [2]HalfT = @bitCast(b_); |
| 106 | var q: [2]HalfT = undefined; | 106 | var q: [2]HalfT = undefined; |
| 107 | var r: [2]HalfT = undefined; | 107 | var r: [2]HalfT = undefined; |
| 108 | 108 | ||
| ... | @@ -119,16 +119,16 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { | ... | @@ -119,16 +119,16 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { |
| 119 | q[lo] = divwide(HalfT, a[hi] % b[lo], a[lo], b[lo], &r[lo]); | 119 | q[lo] = divwide(HalfT, a[hi] % b[lo], a[lo], b[lo], &r[lo]); |
| 120 | } | 120 | } |
| 121 | if (maybe_rem) |rem| { | 121 | if (maybe_rem) |rem| { |
| 122 | rem.* = @as(T, @bitCast(r)); | 122 | rem.* = @bitCast(r); |
| 123 | } | 123 | } |
| 124 | return @as(T, @bitCast(q)); | 124 | return @bitCast(q); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | // 0 <= shift <= 63 | 127 | // 0 <= shift <= 63 |
| 128 | var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); | 128 | var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); |
| 129 | var af = @as(T, @bitCast(a)); | 129 | var af: T = @bitCast(a); |
| 130 | var bf = @as(T, @bitCast(b)) << shift; | 130 | var bf = @as(T, @bitCast(b)) << shift; |
| 131 | q = @as([2]HalfT, @bitCast(@as(T, 0))); | 131 | q = @bitCast(@as(T, 0)); |
| 132 | 132 | ||
| 133 | for (0..shift + 1) |_| { | 133 | for (0..shift + 1) |_| { |
| 134 | q[lo] <<= 1; | 134 | q[lo] <<= 1; |
| ... | @@ -138,12 +138,12 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { | ... | @@ -138,12 +138,12 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { |
| 138 | // q[lo] |= 1; | 138 | // q[lo] |= 1; |
| 139 | // } | 139 | // } |
| 140 | const s = @as(SignedT, @bitCast(bf -% af -% 1)) >> (@bitSizeOf(T) - 1); | 140 | const s = @as(SignedT, @bitCast(bf -% af -% 1)) >> (@bitSizeOf(T) - 1); |
| 141 | q[lo] |= @as(HalfT, @intCast(s & 1)); | 141 | q[lo] |= @intCast(s & 1); |
| 142 | af -= bf & @as(T, @bitCast(s)); | 142 | af -= bf & @as(T, @bitCast(s)); |
| 143 | bf >>= 1; | 143 | bf >>= 1; |
| 144 | } | 144 | } |
| 145 | if (maybe_rem) |rem| { | 145 | if (maybe_rem) |rem| { |
| 146 | rem.* = @as(T, @bitCast(af)); | 146 | rem.* = @bitCast(af); |
| 147 | } | 147 | } |
| 148 | return @as(T, @bitCast(q)); | 148 | return @bitCast(q); |
| 149 | } | 149 | } |
lib/compiler_rt/udivmodti4.zig+1-1| ... | @@ -20,7 +20,7 @@ pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 { | ... | @@ -20,7 +20,7 @@ pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 { |
| 20 | const v2u64 = @Vector(2, u64); | 20 | const v2u64 = @Vector(2, u64); |
| 21 | 21 | ||
| 22 | fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.C) v2u64 { | 22 | fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.C) v2u64 { |
| 23 | return @as(v2u64, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), maybe_rem))); | 23 | return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), maybe_rem)); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | test { | 26 | test { |
lib/compiler_rt/udivti3.zig+1-1| ... | @@ -20,5 +20,5 @@ pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 { | ... | @@ -20,5 +20,5 @@ pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 { |
| 20 | const v2u64 = @Vector(2, u64); | 20 | const v2u64 = @Vector(2, u64); |
| 21 | 21 | ||
| 22 | fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 { | 22 | fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 { |
| 23 | return @as(v2u64, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), null))); | 23 | return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), null)); |
| 24 | } | 24 | } |
lib/compiler_rt/umodti3.zig+2-2| ... | @@ -23,6 +23,6 @@ const v2u64 = @Vector(2, u64); | ... | @@ -23,6 +23,6 @@ const v2u64 = @Vector(2, u64); |
| 23 | 23 | ||
| 24 | fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 { | 24 | fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.C) v2u64 { |
| 25 | var r: u128 = undefined; | 25 | var r: u128 = undefined; |
| 26 | _ = udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), &r); | 26 | _ = udivmod(u128, @bitCast(a), @bitCast(b), &r); |
| 27 | return @as(v2u64, @bitCast(r)); | 27 | return @bitCast(r); |
| 28 | } | 28 | } |