aboutsummaryrefslogtreecommitdiff
path: root/lib/std/special
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2020-09-05 13:58:02 +0300
committerGitHub <noreply@github.com>2020-09-05 13:58:02 +0300
commit41bbadbb9a27107da539e27e175f5bdb52656bd5 (patch)
tree48a89b9ef19eedded7d5b8f3ab9e5e40efacf528 /lib/std/special
parentcff14dc2c67d9a35ae2c3e07bd6d2c5594d8a0a1 (diff)
parent09c861b829480be525a787e54117c108705256e6 (diff)
downloadzig-41bbadbb9a27107da539e27e175f5bdb52656bd5.tar.gz
zig-41bbadbb9a27107da539e27e175f5bdb52656bd5.zip
Merge pull request #6246 from Vexu/field
Remove deprecated fields on `type`
Diffstat (limited to 'lib/std/special')
-rw-r--r--lib/std/special/build_runner.zig2
-rw-r--r--lib/std/special/c.zig5
-rw-r--r--lib/std/special/compiler_rt/addXf3.zig18
-rw-r--r--lib/std/special/compiler_rt/aulldiv.zig4
-rw-r--r--lib/std/special/compiler_rt/aullrem.zig4
-rw-r--r--lib/std/special/compiler_rt/compareXf2.zig7
-rw-r--r--lib/std/special/compiler_rt/divdf3.zig9
-rw-r--r--lib/std/special/compiler_rt/divsf3.zig7
-rw-r--r--lib/std/special/compiler_rt/divtf3.zig5
-rw-r--r--lib/std/special/compiler_rt/divti3.zig4
-rw-r--r--lib/std/special/compiler_rt/fixint.zig9
-rw-r--r--lib/std/special/compiler_rt/fixuint.zig6
-rw-r--r--lib/std/special/compiler_rt/floatXisf.zig9
-rw-r--r--lib/std/special/compiler_rt/floatsiXf.zig7
-rw-r--r--lib/std/special/compiler_rt/floatundisf.zig2
-rw-r--r--lib/std/special/compiler_rt/floatunditf.zig2
-rw-r--r--lib/std/special/compiler_rt/floatunsitf.zig2
-rw-r--r--lib/std/special/compiler_rt/int.zig2
-rw-r--r--lib/std/special/compiler_rt/modti3.zig4
-rw-r--r--lib/std/special/compiler_rt/mulXf3.zig10
-rw-r--r--lib/std/special/compiler_rt/mulodi4.zig2
-rw-r--r--lib/std/special/compiler_rt/muloti4.zig6
-rw-r--r--lib/std/special/compiler_rt/negXf2.zig3
-rw-r--r--lib/std/special/compiler_rt/shift.zig25
-rw-r--r--lib/std/special/compiler_rt/truncXfYf2.zig4
-rw-r--r--lib/std/special/compiler_rt/udivmod.zig70
26 files changed, 117 insertions, 111 deletions
diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig
index 46d3b0b615..3ab74a11a2 100644
--- a/lib/std/special/build_runner.zig
+++ b/lib/std/special/build_runner.zig
@@ -133,7 +133,7 @@ pub fn main() !void {
}
fn runBuild(builder: *Builder) anyerror!void {
- switch (@typeInfo(@TypeOf(root.build).ReturnType)) {
+ switch (@typeInfo(@typeInfo(@TypeOf(root.build)).Fn.return_type.?)) {
.Void => root.build(builder),
.ErrorUnion => try root.build(builder),
else => @compileError("expected return type of build to be 'void' or '!void'"),
diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig
index d5903ece02..ce8d1c29cc 100644
--- a/lib/std/special/c.zig
+++ b/lib/std/special/c.zig
@@ -516,11 +516,12 @@ export fn roundf(a: f32) f32 {
fn generic_fmod(comptime T: type, x: T, y: T) T {
@setRuntimeSafety(false);
- const uint = std.meta.Int(false, T.bit_count);
+ const bits = @typeInfo(T).Float.bits;
+ const uint = std.meta.Int(false, bits);
const log2uint = math.Log2Int(uint);
const digits = if (T == f32) 23 else 52;
const exp_bits = if (T == f32) 9 else 12;
- const bits_minus_1 = T.bit_count - 1;
+ const bits_minus_1 = bits - 1;
const mask = if (T == f32) 0xff else 0x7ff;
var ux = @bitCast(uint, x);
var uy = @bitCast(uint, y);
diff --git a/lib/std/special/compiler_rt/addXf3.zig b/lib/std/special/compiler_rt/addXf3.zig
index 6dd0faaebb..da1238010e 100644
--- a/lib/std/special/compiler_rt/addXf3.zig
+++ b/lib/std/special/compiler_rt/addXf3.zig
@@ -59,23 +59,25 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
}
// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
-fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
- const Z = std.meta.Int(false, T.bit_count);
- const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
+fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
+ const bits = @typeInfo(T).Float.bits;
+ const Z = std.meta.Int(false, bits);
+ const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
const significandBits = std.math.floatMantissaBits(T);
const implicitBit = @as(Z, 1) << significandBits;
- const shift = @clz(std.meta.Int(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
+ const shift = @clz(std.meta.Int(false, bits), significand.*) - @clz(Z, implicitBit);
significand.* <<= @intCast(S, shift);
return 1 - shift;
}
// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
fn addXf3(comptime T: type, a: T, b: T) T {
- const Z = std.meta.Int(false, T.bit_count);
- const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
+ const bits = @typeInfo(T).Float.bits;
+ const Z = std.meta.Int(false, bits);
+ const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
- const typeWidth = T.bit_count;
+ const typeWidth = bits;
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
@@ -187,7 +189,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
// If partial cancellation occured, we need to left-shift the result
// and adjust the exponent:
if (aSignificand < implicitBit << 3) {
- const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.Int(false, T.bit_count), implicitBit << 3));
+ const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.Int(false, bits), implicitBit << 3));
aSignificand <<= @intCast(S, shift);
aExponent -= shift;
}
diff --git a/lib/std/special/compiler_rt/aulldiv.zig b/lib/std/special/compiler_rt/aulldiv.zig
index cf9b26c5a6..321ff288bb 100644
--- a/lib/std/special/compiler_rt/aulldiv.zig
+++ b/lib/std/special/compiler_rt/aulldiv.zig
@@ -7,8 +7,8 @@ const builtin = @import("builtin");
pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
@setRuntimeSafety(builtin.is_test);
- const s_a = a >> (i64.bit_count - 1);
- const s_b = b >> (i64.bit_count - 1);
+ const s_a = a >> (64 - 1);
+ const s_b = b >> (64 - 1);
const an = (a ^ s_a) -% s_a;
const bn = (b ^ s_b) -% s_b;
diff --git a/lib/std/special/compiler_rt/aullrem.zig b/lib/std/special/compiler_rt/aullrem.zig
index 7c981cc088..a14eb99be3 100644
--- a/lib/std/special/compiler_rt/aullrem.zig
+++ b/lib/std/special/compiler_rt/aullrem.zig
@@ -7,8 +7,8 @@ const builtin = @import("builtin");
pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
@setRuntimeSafety(builtin.is_test);
- const s_a = a >> (i64.bit_count - 1);
- const s_b = b >> (i64.bit_count - 1);
+ const s_a = a >> (64 - 1);
+ const s_b = b >> (64 - 1);
const an = (a ^ s_a) -% s_a;
const bn = (b ^ s_b) -% s_b;
diff --git a/lib/std/special/compiler_rt/compareXf2.zig b/lib/std/special/compiler_rt/compareXf2.zig
index f50dc67474..05af1e533c 100644
--- a/lib/std/special/compiler_rt/compareXf2.zig
+++ b/lib/std/special/compiler_rt/compareXf2.zig
@@ -27,8 +27,9 @@ const GE = extern enum(i32) {
pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
@setRuntimeSafety(builtin.is_test);
- const srep_t = std.meta.Int(true, T.bit_count);
- const rep_t = std.meta.Int(false, T.bit_count);
+ const bits = @typeInfo(T).Float.bits;
+ const srep_t = std.meta.Int(true, bits);
+ const rep_t = std.meta.Int(false, bits);
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
@@ -73,7 +74,7 @@ pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
pub fn unordcmp(comptime T: type, a: T, b: T) i32 {
@setRuntimeSafety(builtin.is_test);
- const rep_t = std.meta.Int(false, T.bit_count);
+ const rep_t = std.meta.Int(false, @typeInfo(T).Float.bits);
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
diff --git a/lib/std/special/compiler_rt/divdf3.zig b/lib/std/special/compiler_rt/divdf3.zig
index ad72f96057..11ede3af66 100644
--- a/lib/std/special/compiler_rt/divdf3.zig
+++ b/lib/std/special/compiler_rt/divdf3.zig
@@ -12,10 +12,9 @@ const builtin = @import("builtin");
pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, f64.bit_count);
- const SignedZ = std.meta.Int(true, f64.bit_count);
+ const Z = std.meta.Int(false, 64);
+ const SignedZ = std.meta.Int(true, 64);
- const typeWidth = f64.bit_count;
const significandBits = std.math.floatMantissaBits(f64);
const exponentBits = std.math.floatExponentBits(f64);
@@ -317,9 +316,9 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
}
}
-pub fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
+pub fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, T.bit_count);
+ const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
const significandBits = std.math.floatMantissaBits(T);
const implicitBit = @as(Z, 1) << significandBits;
diff --git a/lib/std/special/compiler_rt/divsf3.zig b/lib/std/special/compiler_rt/divsf3.zig
index 80af806eb1..13f4d8e68d 100644
--- a/lib/std/special/compiler_rt/divsf3.zig
+++ b/lib/std/special/compiler_rt/divsf3.zig
@@ -12,9 +12,8 @@ const builtin = @import("builtin");
pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, f32.bit_count);
+ const Z = std.meta.Int(false, 32);
- const typeWidth = f32.bit_count;
const significandBits = std.math.floatMantissaBits(f32);
const exponentBits = std.math.floatExponentBits(f32);
@@ -190,9 +189,9 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
}
}
-fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
+fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, T.bit_count);
+ const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
const significandBits = std.math.floatMantissaBits(T);
const implicitBit = @as(Z, 1) << significandBits;
diff --git a/lib/std/special/compiler_rt/divtf3.zig b/lib/std/special/compiler_rt/divtf3.zig
index f6f7c1bf7d..0582400ce3 100644
--- a/lib/std/special/compiler_rt/divtf3.zig
+++ b/lib/std/special/compiler_rt/divtf3.zig
@@ -11,10 +11,9 @@ const wideMultiply = @import("divdf3.zig").wideMultiply;
pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, f128.bit_count);
- const SignedZ = std.meta.Int(true, f128.bit_count);
+ const Z = std.meta.Int(false, 128);
+ const SignedZ = std.meta.Int(true, 128);
- const typeWidth = f128.bit_count;
const significandBits = std.math.floatMantissaBits(f128);
const exponentBits = std.math.floatExponentBits(f128);
diff --git a/lib/std/special/compiler_rt/divti3.zig b/lib/std/special/compiler_rt/divti3.zig
index 4b7d459991..a065111510 100644
--- a/lib/std/special/compiler_rt/divti3.zig
+++ b/lib/std/special/compiler_rt/divti3.zig
@@ -9,8 +9,8 @@ const builtin = @import("builtin");
pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
@setRuntimeSafety(builtin.is_test);
- const s_a = a >> (i128.bit_count - 1);
- const s_b = b >> (i128.bit_count - 1);
+ const s_a = a >> (128 - 1);
+ const s_b = b >> (128 - 1);
const an = (a ^ s_a) -% s_a;
const bn = (b ^ s_b) -% s_b;
diff --git a/lib/std/special/compiler_rt/fixint.zig b/lib/std/special/compiler_rt/fixint.zig
index 0bf0c8be1e..1512641be4 100644
--- a/lib/std/special/compiler_rt/fixint.zig
+++ b/lib/std/special/compiler_rt/fixint.zig
@@ -28,7 +28,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
else => unreachable,
};
- const typeWidth = rep_t.bit_count;
+ const typeWidth = @typeInfo(rep_t).Int.bits;
const exponentBits = (typeWidth - significandBits - 1);
const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
const maxExponent = ((1 << exponentBits) - 1);
@@ -50,12 +50,13 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
if (exponent < 0) return 0;
// The unsigned result needs to be large enough to handle an fixint_t or rep_t
- const fixuint_t = std.meta.Int(false, fixint_t.bit_count);
- const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t;
+ const fixint_bits = @typeInfo(fixint_t).Int.bits;
+ const fixuint_t = std.meta.Int(false, fixint_bits);
+ const UintResultType = if (fixint_bits > typeWidth) fixuint_t else rep_t;
var uint_result: UintResultType = undefined;
// If the value is too large for the integer type, saturate.
- if (@intCast(usize, exponent) >= fixint_t.bit_count) {
+ if (@intCast(usize, exponent) >= fixint_bits) {
return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t));
}
diff --git a/lib/std/special/compiler_rt/fixuint.zig b/lib/std/special/compiler_rt/fixuint.zig
index 01eb03baa5..3f2d661244 100644
--- a/lib/std/special/compiler_rt/fixuint.zig
+++ b/lib/std/special/compiler_rt/fixuint.zig
@@ -15,14 +15,14 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
f128 => u128,
else => unreachable,
};
- const srep_t = @import("std").meta.Int(true, rep_t.bit_count);
+ const typeWidth = @typeInfo(rep_t).Int.bits;
+ const srep_t = @import("std").meta.Int(true, typeWidth);
const significandBits = switch (fp_t) {
f32 => 23,
f64 => 52,
f128 => 112,
else => unreachable,
};
- const typeWidth = rep_t.bit_count;
const exponentBits = (typeWidth - significandBits - 1);
const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
const maxExponent = ((1 << exponentBits) - 1);
@@ -44,7 +44,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
if (sign == -1 or exponent < 0) return 0;
// If the value is too large for the integer type, saturate.
- if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0);
+ if (@intCast(c_uint, exponent) >= @typeInfo(fixuint_t).Int.bits) return ~@as(fixuint_t, 0);
// If 0 <= exponent < significandBits, right shift to get the result.
// Otherwise, shift left.
diff --git a/lib/std/special/compiler_rt/floatXisf.zig b/lib/std/special/compiler_rt/floatXisf.zig
index 650b948396..134a1eba61 100644
--- a/lib/std/special/compiler_rt/floatXisf.zig
+++ b/lib/std/special/compiler_rt/floatXisf.zig
@@ -12,15 +12,16 @@ const FLT_MANT_DIG = 24;
fn __floatXisf(comptime T: type, arg: T) f32 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, T.bit_count);
- const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
+ const bits = @typeInfo(T).Int.bits;
+ const Z = std.meta.Int(false, bits);
+ const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
if (arg == 0) {
return @as(f32, 0.0);
}
var ai = arg;
- const N: u32 = T.bit_count;
+ const N: u32 = bits;
const si = ai >> @intCast(S, (N - 1));
ai = ((ai ^ si) -% si);
var a = @bitCast(Z, ai);
@@ -66,7 +67,7 @@ fn __floatXisf(comptime T: type, arg: T) f32 {
// a is now rounded to FLT_MANT_DIG bits
}
- const s = @bitCast(Z, arg) >> (T.bit_count - 32);
+ const s = @bitCast(Z, arg) >> (@typeInfo(T).Int.bits - 32);
const r = (@intCast(u32, s) & 0x80000000) | // sign
(@intCast(u32, (e + 127)) << 23) | // exponent
(@truncate(u32, a) & 0x007fffff); // mantissa-high
diff --git a/lib/std/special/compiler_rt/floatsiXf.zig b/lib/std/special/compiler_rt/floatsiXf.zig
index 75db3d7040..b6ce36b6f7 100644
--- a/lib/std/special/compiler_rt/floatsiXf.zig
+++ b/lib/std/special/compiler_rt/floatsiXf.zig
@@ -10,8 +10,9 @@ const maxInt = std.math.maxInt;
fn floatsiXf(comptime T: type, a: i32) T {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, T.bit_count);
- const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
+ const bits = @typeInfo(T).Float.bits;
+ const Z = std.meta.Int(false, bits);
+ const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
if (a == 0) {
return @as(T, 0.0);
@@ -22,7 +23,7 @@ fn floatsiXf(comptime T: type, a: i32) T {
const exponentBias = ((1 << exponentBits - 1) - 1);
const implicitBit = @as(Z, 1) << significandBits;
- const signBit = @as(Z, 1 << Z.bit_count - 1);
+ const signBit = @as(Z, 1 << bits - 1);
const sign = a >> 31;
// Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31).
diff --git a/lib/std/special/compiler_rt/floatundisf.zig b/lib/std/special/compiler_rt/floatundisf.zig
index b580ec91fd..67cd53b21c 100644
--- a/lib/std/special/compiler_rt/floatundisf.zig
+++ b/lib/std/special/compiler_rt/floatundisf.zig
@@ -15,7 +15,7 @@ pub fn __floatundisf(arg: u64) callconv(.C) f32 {
if (arg == 0) return 0;
var a = arg;
- const N: usize = @TypeOf(a).bit_count;
+ const N: usize = @typeInfo(@TypeOf(a)).Int.bits;
// Number of significant digits
const sd = N - @clz(u64, a);
// 8 exponent
diff --git a/lib/std/special/compiler_rt/floatunditf.zig b/lib/std/special/compiler_rt/floatunditf.zig
index 90191c6388..014a479c5f 100644
--- a/lib/std/special/compiler_rt/floatunditf.zig
+++ b/lib/std/special/compiler_rt/floatunditf.zig
@@ -19,7 +19,7 @@ pub fn __floatunditf(a: u64) callconv(.C) f128 {
const exponent_bias = (1 << (exponent_bits - 1)) - 1;
const implicit_bit = 1 << mantissa_bits;
- const exp: u128 = (u64.bit_count - 1) - @clz(u64, a);
+ const exp: u128 = (64 - 1) - @clz(u64, a);
const shift: u7 = mantissa_bits - @intCast(u7, exp);
var result: u128 = (@intCast(u128, a) << shift) ^ implicit_bit;
diff --git a/lib/std/special/compiler_rt/floatunsitf.zig b/lib/std/special/compiler_rt/floatunsitf.zig
index ceb55f12c8..f59446abac 100644
--- a/lib/std/special/compiler_rt/floatunsitf.zig
+++ b/lib/std/special/compiler_rt/floatunsitf.zig
@@ -19,7 +19,7 @@ pub fn __floatunsitf(a: u64) callconv(.C) f128 {
const exponent_bias = (1 << (exponent_bits - 1)) - 1;
const implicit_bit = 1 << mantissa_bits;
- const exp = (u64.bit_count - 1) - @clz(u64, a);
+ const exp = (64 - 1) - @clz(u64, a);
const shift = mantissa_bits - @intCast(u7, exp);
// TODO(#1148): @bitCast alignment error
diff --git a/lib/std/special/compiler_rt/int.zig b/lib/std/special/compiler_rt/int.zig
index 141c4e52c1..1fb2c263e1 100644
--- a/lib/std/special/compiler_rt/int.zig
+++ b/lib/std/special/compiler_rt/int.zig
@@ -219,7 +219,7 @@ fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
@setRuntimeSafety(builtin.is_test);
- const n_uword_bits: c_uint = u32.bit_count;
+ const n_uword_bits: c_uint = 32;
// special cases
if (d == 0) return 0; // ?!
if (n == 0) return 0;
diff --git a/lib/std/special/compiler_rt/modti3.zig b/lib/std/special/compiler_rt/modti3.zig
index 1f859c2329..9c3de44395 100644
--- a/lib/std/special/compiler_rt/modti3.zig
+++ b/lib/std/special/compiler_rt/modti3.zig
@@ -14,8 +14,8 @@ const compiler_rt = @import("../compiler_rt.zig");
pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
@setRuntimeSafety(builtin.is_test);
- const s_a = a >> (i128.bit_count - 1); // s = a < 0 ? -1 : 0
- const s_b = b >> (i128.bit_count - 1); // s = b < 0 ? -1 : 0
+ const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0
+ const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0
const an = (a ^ s_a) -% s_a; // negate if s == -1
const bn = (b ^ s_b) -% s_b; // negate if s == -1
diff --git a/lib/std/special/compiler_rt/mulXf3.zig b/lib/std/special/compiler_rt/mulXf3.zig
index b6984ebbb6..40b5b4f658 100644
--- a/lib/std/special/compiler_rt/mulXf3.zig
+++ b/lib/std/special/compiler_rt/mulXf3.zig
@@ -33,9 +33,9 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {
fn mulXf3(comptime T: type, a: T, b: T) T {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, T.bit_count);
+ const typeWidth = @typeInfo(T).Float.bits;
+ const Z = std.meta.Int(false, typeWidth);
- const typeWidth = T.bit_count;
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
@@ -269,9 +269,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
}
}
-fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
+fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
@setRuntimeSafety(builtin.is_test);
- const Z = std.meta.Int(false, T.bit_count);
+ const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
const significandBits = std.math.floatMantissaBits(T);
const implicitBit = @as(Z, 1) << significandBits;
@@ -282,7 +282,7 @@ fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i
fn wideRightShiftWithSticky(comptime Z: type, hi: *Z, lo: *Z, count: u32) void {
@setRuntimeSafety(builtin.is_test);
- const typeWidth = Z.bit_count;
+ const typeWidth = @typeInfo(Z).Int.bits;
const S = std.math.Log2Int(Z);
if (count < typeWidth) {
const sticky = @truncate(u8, lo.* << @intCast(S, typeWidth -% count));
diff --git a/lib/std/special/compiler_rt/mulodi4.zig b/lib/std/special/compiler_rt/mulodi4.zig
index b05931e937..fab345fa47 100644
--- a/lib/std/special/compiler_rt/mulodi4.zig
+++ b/lib/std/special/compiler_rt/mulodi4.zig
@@ -11,7 +11,7 @@ const minInt = std.math.minInt;
pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
@setRuntimeSafety(builtin.is_test);
- const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1)));
+ const min = @bitCast(i64, @as(u64, 1 << (64 - 1)));
const max = ~min;
overflow.* = 0;
diff --git a/lib/std/special/compiler_rt/muloti4.zig b/lib/std/special/compiler_rt/muloti4.zig
index 4beafa3e15..b1ad82da29 100644
--- a/lib/std/special/compiler_rt/muloti4.zig
+++ b/lib/std/special/compiler_rt/muloti4.zig
@@ -9,7 +9,7 @@ const compiler_rt = @import("../compiler_rt.zig");
pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
@setRuntimeSafety(builtin.is_test);
- const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1)));
+ const min = @bitCast(i128, @as(u128, 1 << (128 - 1)));
const max = ~min;
overflow.* = 0;
@@ -27,9 +27,9 @@ pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
return r;
}
- const sa = a >> (i128.bit_count - 1);
+ const sa = a >> (128 - 1);
const abs_a = (a ^ sa) -% sa;
- const sb = b >> (i128.bit_count - 1);
+ const sb = b >> (128 - 1);
const abs_b = (b ^ sb) -% sb;
if (abs_a < 2 or abs_b < 2) {
diff --git a/lib/std/special/compiler_rt/negXf2.zig b/lib/std/special/compiler_rt/negXf2.zig
index 11f9e401e9..ae01e10776 100644
--- a/lib/std/special/compiler_rt/negXf2.zig
+++ b/lib/std/special/compiler_rt/negXf2.zig
@@ -24,9 +24,8 @@ pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
}
fn negXf2(comptime T: type, a: T) T {
- const Z = std.meta.Int(false, T.bit_count);
+ const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
- const typeWidth = T.bit_count;
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
diff --git a/lib/std/special/compiler_rt/shift.zig b/lib/std/special/compiler_rt/shift.zig
index 1609cb115c..acb14c969a 100644
--- a/lib/std/special/compiler_rt/shift.zig
+++ b/lib/std/special/compiler_rt/shift.zig
@@ -9,8 +9,9 @@ const Log2Int = std.math.Log2Int;
fn Dwords(comptime T: type, comptime signed_half: bool) type {
return extern union {
- pub const HalfTU = std.meta.Int(false, @divExact(T.bit_count, 2));
- pub const HalfTS = std.meta.Int(true, @divExact(T.bit_count, 2));
+ pub const bits = @divExact(@typeInfo(T).Int.bits, 2);
+ pub const HalfTU = std.meta.Int(false, bits);
+ pub const HalfTS = std.meta.Int(true, bits);
pub const HalfT = if (signed_half) HalfTS else HalfTU;
all: T,
@@ -30,15 +31,15 @@ pub fn ashlXi3(comptime T: type, a: T, b: i32) T {
const input = dwords{ .all = a };
var output: dwords = undefined;
- if (b >= dwords.HalfT.bit_count) {
+ if (b >= dwords.bits) {
output.s.low = 0;
- output.s.high = input.s.low << @intCast(S, b - dwords.HalfT.bit_count);
+ output.s.high = input.s.low << @intCast(S, b - dwords.bits);
} else if (b == 0) {
return a;
} else {
output.s.low = input.s.low << @intCast(S, b);
output.s.high = input.s.high << @intCast(S, b);
- output.s.high |= input.s.low >> @intCast(S, dwords.HalfT.bit_count - b);
+ output.s.high |= input.s.low >> @intCast(S, dwords.bits - b);
}
return output.all;
@@ -53,14 +54,14 @@ pub fn ashrXi3(comptime T: type, a: T, b: i32) T {
const input = dwords{ .all = a };
var output: dwords = undefined;
- if (b >= dwords.HalfT.bit_count) {
- output.s.high = input.s.high >> (dwords.HalfT.bit_count - 1);
- output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count);
+ if (b >= dwords.bits) {
+ output.s.high = input.s.high >> (dwords.bits - 1);
+ output.s.low = input.s.high >> @intCast(S, b - dwords.bits);
} else if (b == 0) {
return a;
} else {
output.s.high = input.s.high >> @intCast(S, b);
- output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b);
+ output.s.low = input.s.high << @intCast(S, dwords.bits - b);
// Avoid sign-extension here
output.s.low |= @bitCast(
dwords.HalfT,
@@ -80,14 +81,14 @@ pub fn lshrXi3(comptime T: type, a: T, b: i32) T {
const input = dwords{ .all = a };
var output: dwords = undefined;
- if (b >= dwords.HalfT.bit_count) {
+ if (b >= dwords.bits) {
output.s.high = 0;
- output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count);
+ output.s.low = input.s.high >> @intCast(S, b - dwords.bits);
} else if (b == 0) {
return a;
} else {
output.s.high = input.s.high >> @intCast(S, b);
- output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b);
+ output.s.low = input.s.high << @intCast(S, dwords.bits - b);
output.s.low |= input.s.low >> @intCast(S, b);
}
diff --git a/lib/std/special/compiler_rt/truncXfYf2.zig b/lib/std/special/compiler_rt/truncXfYf2.zig
index e096e7e4f0..b5823607ea 100644
--- a/lib/std/special/compiler_rt/truncXfYf2.zig
+++ b/lib/std/special/compiler_rt/truncXfYf2.zig
@@ -50,7 +50,7 @@ fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
// Various constants whose values follow from the type parameters.
// Any reasonable optimizer will fold and propagate all of these.
- const srcBits = src_t.bit_count;
+ const srcBits = @typeInfo(src_t).Float.bits;
const srcExpBits = srcBits - srcSigBits - 1;
const srcInfExp = (1 << srcExpBits) - 1;
const srcExpBias = srcInfExp >> 1;
@@ -65,7 +65,7 @@ fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
const srcQNaN = 1 << (srcSigBits - 1);
const srcNaNCode = srcQNaN - 1;
- const dstBits = dst_t.bit_count;
+ const dstBits = @typeInfo(dst_t).Float.bits;
const dstExpBits = dstBits - dstSigBits - 1;
const dstInfExp = (1 << dstExpBits) - 1;
const dstExpBias = dstInfExp >> 1;
diff --git a/lib/std/special/compiler_rt/udivmod.zig b/lib/std/special/compiler_rt/udivmod.zig
index 2836f34c85..f8c7e1298b 100644
--- a/lib/std/special/compiler_rt/udivmod.zig
+++ b/lib/std/special/compiler_rt/udivmod.zig
@@ -15,8 +15,10 @@ const high = 1 - low;
pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {
@setRuntimeSafety(is_test);
- const SingleInt = @import("std").meta.Int(false, @divExact(DoubleInt.bit_count, 2));
- const SignedDoubleInt = @import("std").meta.Int(true, DoubleInt.bit_count);
+ const double_int_bits = @typeInfo(DoubleInt).Int.bits;
+ const single_int_bits = @divExact(double_int_bits, 2);
+ const SingleInt = @import("std").meta.Int(false, single_int_bits);
+ const SignedDoubleInt = @import("std").meta.Int(true, double_int_bits);
const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
@@ -82,21 +84,21 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// ---
// K 0
sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
- // 0 <= sr <= SingleInt.bit_count - 2 or sr large
- if (sr > SingleInt.bit_count - 2) {
+ // 0 <= sr <= single_int_bits - 2 or sr large
+ if (sr > single_int_bits - 2) {
if (maybe_rem) |rem| {
rem.* = a;
}
return 0;
}
sr += 1;
- // 1 <= sr <= SingleInt.bit_count - 1
- // q.all = a << (DoubleInt.bit_count - sr);
+ // 1 <= sr <= single_int_bits - 1
+ // q.all = a << (double_int_bits - sr);
q[low] = 0;
- q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
+ q[high] = n[low] << @intCast(Log2SingleInt, single_int_bits - sr);
// r.all = a >> sr;
r[high] = n[high] >> @intCast(Log2SingleInt, sr);
- r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
+ r[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
} else {
// d[low] != 0
if (d[high] == 0) {
@@ -113,74 +115,74 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
}
sr = @ctz(SingleInt, d[low]);
q[high] = n[high] >> @intCast(Log2SingleInt, sr);
- q[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
+ q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
}
// K X
// ---
// 0 K
- sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
- // 2 <= sr <= DoubleInt.bit_count - 1
- // q.all = a << (DoubleInt.bit_count - sr);
+ sr = 1 + single_int_bits + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
+ // 2 <= sr <= double_int_bits - 1
+ // q.all = a << (double_int_bits - sr);
// r.all = a >> sr;
- if (sr == SingleInt.bit_count) {
+ if (sr == single_int_bits) {
q[low] = 0;
q[high] = n[low];
r[high] = 0;
r[low] = n[high];
- } else if (sr < SingleInt.bit_count) {
- // 2 <= sr <= SingleInt.bit_count - 1
+ } else if (sr < single_int_bits) {
+ // 2 <= sr <= single_int_bits - 1
q[low] = 0;
- q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
+ q[high] = n[low] << @intCast(Log2SingleInt, single_int_bits - sr);
r[high] = n[high] >> @intCast(Log2SingleInt, sr);
- r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
+ r[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
} else {
- // SingleInt.bit_count + 1 <= sr <= DoubleInt.bit_count - 1
- q[low] = n[low] << @intCast(Log2SingleInt, DoubleInt.bit_count - sr);
- q[high] = (n[high] << @intCast(Log2SingleInt, DoubleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr - SingleInt.bit_count));
+ // single_int_bits + 1 <= sr <= double_int_bits - 1
+ q[low] = n[low] << @intCast(Log2SingleInt, double_int_bits - sr);
+ q[high] = (n[high] << @intCast(Log2SingleInt, double_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr - single_int_bits));
r[high] = 0;
- r[low] = n[high] >> @intCast(Log2SingleInt, sr - SingleInt.bit_count);
+ r[low] = n[high] >> @intCast(Log2SingleInt, sr - single_int_bits);
}
} else {
// K X
// ---
// K K
sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
- // 0 <= sr <= SingleInt.bit_count - 1 or sr large
- if (sr > SingleInt.bit_count - 1) {
+ // 0 <= sr <= single_int_bits - 1 or sr large
+ if (sr > single_int_bits - 1) {
if (maybe_rem) |rem| {
rem.* = a;
}
return 0;
}
sr += 1;
- // 1 <= sr <= SingleInt.bit_count
- // q.all = a << (DoubleInt.bit_count - sr);
+ // 1 <= sr <= single_int_bits
+ // q.all = a << (double_int_bits - sr);
// r.all = a >> sr;
q[low] = 0;
- if (sr == SingleInt.bit_count) {
+ if (sr == single_int_bits) {
q[high] = n[low];
r[high] = 0;
r[low] = n[high];
} else {
r[high] = n[high] >> @intCast(Log2SingleInt, sr);
- r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
- q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
+ r[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
+ q[high] = n[low] << @intCast(Log2SingleInt, single_int_bits - sr);
}
}
}
// Not a special case
// q and r are initialized with:
- // q.all = a << (DoubleInt.bit_count - sr);
+ // q.all = a << (double_int_bits - sr);
// r.all = a >> sr;
- // 1 <= sr <= DoubleInt.bit_count - 1
+ // 1 <= sr <= double_int_bits - 1
var carry: u32 = 0;
var r_all: DoubleInt = undefined;
while (sr > 0) : (sr -= 1) {
// r:q = ((r:q) << 1) | carry
- r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
- r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
- q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
+ r[high] = (r[high] << 1) | (r[low] >> (single_int_bits - 1));
+ r[low] = (r[low] << 1) | (q[high] >> (single_int_bits - 1));
+ q[high] = (q[high] << 1) | (q[low] >> (single_int_bits - 1));
q[low] = (q[low] << 1) | carry;
// carry = 0;
// if (r.all >= b)
@@ -189,7 +191,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// carry = 1;
// }
r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
- const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
+ const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (double_int_bits - 1);
carry = @intCast(u32, s & 1);
r_all -= b & @bitCast(DoubleInt, s);
r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421