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

This commit is contained in:
Meghan 2022-12-15 13:08:51 -08:00 committed by GitHub
parent 88b49ed00d
commit 1704971666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View File

@ -220,15 +220,13 @@ pub const Type = union(enum) {
/// therefore must be kept in sync with the compiler implementation.
pub const Int = struct {
signedness: Signedness,
/// TODO make this u16 instead of comptime_int
bits: comptime_int,
bits: u16,
};
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Float = struct {
/// TODO make this u16 instead of comptime_int
bits: comptime_int,
bits: u16,
};
/// This data structure is used by the Zig language code generation and

View File

@ -37,9 +37,12 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
if (@typeInfo(T).Int.bits <= 2) {
return if (value == 0) 0 else 1; // shortcut for small number of bits to simplify general case
} else {
const bits = @typeInfo(T).Int.bits;
const max = math.maxInt(T);
const minustwo = (@as(T, 2) ^ max) + 1; // unsigned int cannot represent -2
var op = value;
var res: T = 0;
var one: T = 1 << ((@typeInfo(T).Int.bits - 1) & -2); // highest power of four that fits into T
var one: T = 1 << ((bits - 1) & minustwo); // highest power of four that fits into T
// "one" starts at the highest power of four <= than the argument.
while (one > op) {

View File

@ -4586,7 +4586,7 @@ pub const Type = extern union {
}
/// Asserts the type is an integer, enum, error set, or vector of one of them.
pub fn intInfo(self: Type, target: Target) struct { signedness: std.builtin.Signedness, bits: u16 } {
pub fn intInfo(self: Type, target: Target) std.builtin.Type.Int {
var ty = self;
while (true) switch (ty.tag()) {
.int_unsigned => return .{