mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
std: make builtin.Type.{Int,Float}.bits a u16 instead of comptime_int
This commit is contained in:
parent
88b49ed00d
commit
1704971666
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 .{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user