authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-12-15 13:08:51-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-15 23:08:51+02:00
log1704971666bce25add6b4f6e409658c5ce8b59aa
tree2a31b6d2dd10c83e79129c38ba33863b54d77d53
parent88b49ed00d6d2efb5b523ab15cbf8ffb37383c56
signature Signed by PGP key 4AEE18F83AFDEB23

std: make builtin.Type.{Int,Float}.bits a u16 instead of comptime_int


3 files changed, 7 insertions(+), 6 deletions(-)

lib/std/builtin.zig+2-4
......@@ -220,15 +220,13 @@ pub const Type = union(enum) {
220220 /// therefore must be kept in sync with the compiler implementation.
221221 pub const Int = struct {
222222 signedness: Signedness,
223 /// TODO make this u16 instead of comptime_int
224 bits: comptime_int,
223 bits: u16,
225224 };
226225
227226 /// This data structure is used by the Zig language code generation and
228227 /// therefore must be kept in sync with the compiler implementation.
229228 pub const Float = struct {
230 /// TODO make this u16 instead of comptime_int
231 bits: comptime_int,
229 bits: u16,
232230 };
233231
234232 /// This data structure is used by the Zig language code generation and
lib/std/math/sqrt.zig+4-1
......@@ -37,9 +37,12 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
3737 if (@typeInfo(T).Int.bits <= 2) {
3838 return if (value == 0) 0 else 1; // shortcut for small number of bits to simplify general case
3939 } else {
40 const bits = @typeInfo(T).Int.bits;
41 const max = math.maxInt(T);
42 const minustwo = (@as(T, 2) ^ max) + 1; // unsigned int cannot represent -2
4043 var op = value;
4144 var res: T = 0;
42 var one: T = 1 << ((@typeInfo(T).Int.bits - 1) & -2); // highest power of four that fits into T
45 var one: T = 1 << ((bits - 1) & minustwo); // highest power of four that fits into T
4346
4447 // "one" starts at the highest power of four <= than the argument.
4548 while (one > op) {
src/type.zig+1-1
......@@ -4586,7 +4586,7 @@ pub const Type = extern union {
45864586 }
45874587
45884588 /// Asserts the type is an integer, enum, error set, or vector of one of them.
4589 pub fn intInfo(self: Type, target: Target) struct { signedness: std.builtin.Signedness, bits: u16 } {
4589 pub fn intInfo(self: Type, target: Target) std.builtin.Type.Int {
45904590 var ty = self;
45914591 while (true) switch (ty.tag()) {
45924592 .int_unsigned => return .{