authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2022-04-26 17:08:54+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2022-04-27 11:10:52+02:00
log6f4343b61afe36a709e713735947561a2b76bce8
tree19517971ce99ed10afeac53ed4e19c97c60da7cc
parent6c0719fd5f29f524b789d5038fdc9fc0878f2e6a

std: replace usage of std.meta.bitCount() with @bitSizeOf()


13 files changed, 22 insertions(+), 22 deletions(-)

lib/std/Thread/RwLock.zig+2-2
...@@ -167,10 +167,10 @@ pub const DefaultRwLock = struct {...@@ -167,10 +167,10 @@ pub const DefaultRwLock = struct {
167167
168 const IS_WRITING: usize = 1;168 const IS_WRITING: usize = 1;
169 const WRITER: usize = 1 << 1;169 const WRITER: usize = 1 << 1;
170 const READER: usize = 1 << (1 + std.meta.bitCount(Count));170 const READER: usize = 1 << (1 + @bitSizeOf(Count));
171 const WRITER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, WRITER);171 const WRITER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, WRITER);
172 const READER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, READER);172 const READER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, READER);
173 const Count = std.meta.Int(.unsigned, @divFloor(std.meta.bitCount(usize) - 1, 2));173 const Count = std.meta.Int(.unsigned, @divFloor(@bitSizeOf(usize) - 1, 2));
174174
175 pub fn tryLock(rwl: *DefaultRwLock) bool {175 pub fn tryLock(rwl: *DefaultRwLock) bool {
176 if (rwl.mutex.tryLock()) {176 if (rwl.mutex.tryLock()) {
lib/std/atomic/Atomic.zig+3-3
...@@ -542,7 +542,7 @@ test "Atomic.bitSet" {...@@ -542,7 +542,7 @@ test "Atomic.bitSet" {
542 inline for (atomicIntTypes()) |Int| {542 inline for (atomicIntTypes()) |Int| {
543 inline for (atomic_rmw_orderings) |ordering| {543 inline for (atomic_rmw_orderings) |ordering| {
544 var x = Atomic(Int).init(0);544 var x = Atomic(Int).init(0);
545 const bit_array = @as([std.meta.bitCount(Int)]void, undefined);545 const bit_array = @as([@bitSizeOf(Int)]void, undefined);
546546
547 for (bit_array) |_, bit_index| {547 for (bit_array) |_, bit_index| {
548 const bit = @intCast(std.math.Log2Int(Int), bit_index);548 const bit = @intCast(std.math.Log2Int(Int), bit_index);
...@@ -572,7 +572,7 @@ test "Atomic.bitReset" {...@@ -572,7 +572,7 @@ test "Atomic.bitReset" {
572 inline for (atomicIntTypes()) |Int| {572 inline for (atomicIntTypes()) |Int| {
573 inline for (atomic_rmw_orderings) |ordering| {573 inline for (atomic_rmw_orderings) |ordering| {
574 var x = Atomic(Int).init(0);574 var x = Atomic(Int).init(0);
575 const bit_array = @as([std.meta.bitCount(Int)]void, undefined);575 const bit_array = @as([@bitSizeOf(Int)]void, undefined);
576576
577 for (bit_array) |_, bit_index| {577 for (bit_array) |_, bit_index| {
578 const bit = @intCast(std.math.Log2Int(Int), bit_index);578 const bit = @intCast(std.math.Log2Int(Int), bit_index);
...@@ -603,7 +603,7 @@ test "Atomic.bitToggle" {...@@ -603,7 +603,7 @@ test "Atomic.bitToggle" {
603 inline for (atomicIntTypes()) |Int| {603 inline for (atomicIntTypes()) |Int| {
604 inline for (atomic_rmw_orderings) |ordering| {604 inline for (atomic_rmw_orderings) |ordering| {
605 var x = Atomic(Int).init(0);605 var x = Atomic(Int).init(0);
606 const bit_array = @as([std.meta.bitCount(Int)]void, undefined);606 const bit_array = @as([@bitSizeOf(Int)]void, undefined);
607607
608 for (bit_array) |_, bit_index| {608 for (bit_array) |_, bit_index| {
609 const bit = @intCast(std.math.Log2Int(Int), bit_index);609 const bit = @intCast(std.math.Log2Int(Int), bit_index);
lib/std/crypto/pcurves/common.zig+1-1
...@@ -235,7 +235,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -235,7 +235,7 @@ pub fn Field(comptime params: FieldParams) type {
235 }235 }
236 var v_opp: Limbs = undefined;236 var v_opp: Limbs = undefined;
237 fiat.opp(&v_opp, v);237 fiat.opp(&v_opp, v);
238 fiat.selectznz(&v, @truncate(u1, f[f.len - 1] >> (meta.bitCount(Word) - 1)), v, v_opp);238 fiat.selectznz(&v, @truncate(u1, f[f.len - 1] >> (@bitSizeOf(Word) - 1)), v, v_opp);
239 var fe: Fe = undefined;239 var fe: Fe = undefined;
240 fiat.mul(&fe.limbs, v, precomp);240 fiat.mul(&fe.limbs, v, precomp);
241 return fe;241 return fe;
lib/std/crypto/scrypt.zig+1-1
...@@ -348,7 +348,7 @@ const crypt_format = struct {...@@ -348,7 +348,7 @@ const crypt_format = struct {
348 }348 }
349 }349 }
350350
351 fn intDecode(comptime T: type, src: *const [(meta.bitCount(T) + 5) / 6]u8) !T {351 fn intDecode(comptime T: type, src: *const [(@bitSizeOf(T) + 5) / 6]u8) !T {
352 var v: T = 0;352 var v: T = 0;
353 for (src) |x, i| {353 for (src) |x, i| {
354 const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;354 const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;
lib/std/event/wait_group.zig+1-1
...@@ -14,7 +14,7 @@ const Loop = std.event.Loop;...@@ -14,7 +14,7 @@ const Loop = std.event.Loop;
14/// `begin` will return error.Overflow when the limit is reached, even14/// `begin` will return error.Overflow when the limit is reached, even
15/// if the integer type has not has not overflowed.15/// if the integer type has not has not overflowed.
16/// By default `max_value` is set to std.math.maxInt(CounterType).16/// By default `max_value` is set to std.math.maxInt(CounterType).
17pub const WaitGroup = WaitGroupGeneric(std.meta.bitCount(usize));17pub const WaitGroup = WaitGroupGeneric(@bitSizeOf(usize));
1818
19pub fn WaitGroupGeneric(comptime counter_size: u16) type {19pub fn WaitGroupGeneric(comptime counter_size: u16) type {
20 const CounterType = std.meta.Int(.unsigned, counter_size);20 const CounterType = std.meta.Int(.unsigned, counter_size);
lib/std/fmt.zig+1-1
...@@ -1121,7 +1121,7 @@ pub fn formatFloatHexadecimal(...@@ -1121,7 +1121,7 @@ pub fn formatFloatHexadecimal(
1121 }1121 }
11221122
1123 const T = @TypeOf(value);1123 const T = @TypeOf(value);
1124 const TU = std.meta.Int(.unsigned, std.meta.bitCount(T));1124 const TU = std.meta.Int(.unsigned, @bitSizeOf(T));
11251125
1126 const mantissa_bits = math.floatMantissaBits(T);1126 const mantissa_bits = math.floatMantissaBits(T);
1127 const fractional_bits = math.floatFractionalBits(T);1127 const fractional_bits = math.floatFractionalBits(T);
lib/std/heap.zig+1-1
...@@ -1181,7 +1181,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void {...@@ -1181,7 +1181,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void {
1181 // very near usize?1181 // very near usize?
1182 if (mem.page_size << 2 > maxInt(usize)) return;1182 if (mem.page_size << 2 > maxInt(usize)) return;
11831183
1184 const USizeShift = std.meta.Int(.unsigned, std.math.log2(std.meta.bitCount(usize)));1184 const USizeShift = std.meta.Int(.unsigned, std.math.log2(@bitSizeOf(usize)));
1185 const large_align = @as(u29, mem.page_size << 2);1185 const large_align = @as(u29, mem.page_size << 2);
11861186
1187 var align_mask: usize = undefined;1187 var align_mask: usize = undefined;
lib/std/io/bit_reader.zig+4-4
...@@ -17,9 +17,9 @@ pub fn BitReader(endian: std.builtin.Endian, comptime ReaderType: type) type {...@@ -17,9 +17,9 @@ pub fn BitReader(endian: std.builtin.Endian, comptime ReaderType: type) type {
17 pub const Reader = io.Reader(*Self, Error, read);17 pub const Reader = io.Reader(*Self, Error, read);
1818
19 const Self = @This();19 const Self = @This();
20 const u8_bit_count = meta.bitCount(u8);20 const u8_bit_count = @bitSizeOf(u8);
21 const u7_bit_count = meta.bitCount(u7);21 const u7_bit_count = @bitSizeOf(u7);
22 const u4_bit_count = meta.bitCount(u4);22 const u4_bit_count = @bitSizeOf(u4);
2323
24 pub fn init(forward_reader: ReaderType) Self {24 pub fn init(forward_reader: ReaderType) Self {
25 return Self{25 return Self{
...@@ -47,7 +47,7 @@ pub fn BitReader(endian: std.builtin.Endian, comptime ReaderType: type) type {...@@ -47,7 +47,7 @@ pub fn BitReader(endian: std.builtin.Endian, comptime ReaderType: type) type {
4747
48 //by extending the buffer to a minimum of u8 we can cover a number of edge cases48 //by extending the buffer to a minimum of u8 we can cover a number of edge cases
49 // related to shifting and casting.49 // related to shifting and casting.
50 const u_bit_count = comptime meta.bitCount(U);50 const u_bit_count = @bitSizeOf(U);
51 const buf_bit_count = bc: {51 const buf_bit_count = bc: {
52 assert(u_bit_count >= bits);52 assert(u_bit_count >= bits);
53 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;53 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
lib/std/io/bit_writer.zig+3-3
...@@ -17,8 +17,8 @@ pub fn BitWriter(endian: std.builtin.Endian, comptime WriterType: type) type {...@@ -17,8 +17,8 @@ pub fn BitWriter(endian: std.builtin.Endian, comptime WriterType: type) type {
17 pub const Writer = io.Writer(*Self, Error, write);17 pub const Writer = io.Writer(*Self, Error, write);
1818
19 const Self = @This();19 const Self = @This();
20 const u8_bit_count = meta.bitCount(u8);20 const u8_bit_count = @bitSizeOf(u8);
21 const u4_bit_count = meta.bitCount(u4);21 const u4_bit_count = @bitSizeOf(u4);
2222
23 pub fn init(forward_writer: WriterType) Self {23 pub fn init(forward_writer: WriterType) Self {
24 return Self{24 return Self{
...@@ -39,7 +39,7 @@ pub fn BitWriter(endian: std.builtin.Endian, comptime WriterType: type) type {...@@ -39,7 +39,7 @@ pub fn BitWriter(endian: std.builtin.Endian, comptime WriterType: type) type {
3939
40 //by extending the buffer to a minimum of u8 we can cover a number of edge cases40 //by extending the buffer to a minimum of u8 we can cover a number of edge cases
41 // related to shifting and casting.41 // related to shifting and casting.
42 const u_bit_count = comptime meta.bitCount(U);42 const u_bit_count = @bitSizeOf(U);
43 const buf_bit_count = bc: {43 const buf_bit_count = bc: {
44 assert(u_bit_count >= bits);44 assert(u_bit_count >= bits);
45 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;45 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
lib/std/math.zig+2-2
...@@ -947,10 +947,10 @@ test "absCast" {...@@ -947,10 +947,10 @@ test "absCast" {
947947
948/// Returns the negation of the integer parameter.948/// Returns the negation of the integer parameter.
949/// Result is a signed integer.949/// Result is a signed integer.
950pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x))) {950pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) {
951 if (@typeInfo(@TypeOf(x)).Int.signedness == .signed) return negate(x);951 if (@typeInfo(@TypeOf(x)).Int.signedness == .signed) return negate(x);
952952
953 const int = std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x)));953 const int = std.meta.Int(.signed, @bitSizeOf(@TypeOf(x)));
954 if (x > -minInt(int)) return error.Overflow;954 if (x > -minInt(int)) return error.Overflow;
955955
956 if (x == -minInt(int)) return minInt(int);956 if (x == -minInt(int)) return minInt(int);
lib/std/os.zig+1-1
...@@ -5561,7 +5561,7 @@ pub fn res_mkquery(...@@ -5561,7 +5561,7 @@ pub fn res_mkquery(
5561 // Make a reasonably unpredictable id5561 // Make a reasonably unpredictable id
5562 var ts: timespec = undefined;5562 var ts: timespec = undefined;
5563 clock_gettime(CLOCK.REALTIME, &ts) catch {};5563 clock_gettime(CLOCK.REALTIME, &ts) catch {};
5564 const UInt = std.meta.Int(.unsigned, std.meta.bitCount(@TypeOf(ts.tv_nsec)));5564 const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.tv_nsec)));
5565 const unsec = @bitCast(UInt, ts.tv_nsec);5565 const unsec = @bitCast(UInt, ts.tv_nsec);
5566 const id = @truncate(u32, unsec + unsec / 65536);5566 const id = @truncate(u32, unsec + unsec / 65536);
5567 q[0] = @truncate(u8, id / 256);5567 q[0] = @truncate(u8, id / 256);
src/codegen/spirv.zig+1-1
...@@ -341,7 +341,7 @@ pub const DeclGen = struct {...@@ -341,7 +341,7 @@ pub const DeclGen = struct {
341 // We can just use toSignedInt/toUnsignedInt here as it returns u64 - a type large enough to hold any341 // We can just use toSignedInt/toUnsignedInt here as it returns u64 - a type large enough to hold any
342 // SPIR-V native type (up to i/u64 with Int64). If SPIR-V ever supports native ints of a larger size, this342 // SPIR-V native type (up to i/u64 with Int64). If SPIR-V ever supports native ints of a larger size, this
343 // might need to be updated.343 // might need to be updated.
344 assert(self.largestSupportedIntBits() <= std.meta.bitCount(u64));344 assert(self.largestSupportedIntBits() <= @bitSizeOf(u64));
345345
346 // Note, value is required to be sign-extended, so we don't need to mask off the upper bits.346 // Note, value is required to be sign-extended, so we don't need to mask off the upper bits.
347 // See https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#Literal347 // See https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#Literal
src/codegen/spirv/Section.zig+1-1
...@@ -170,7 +170,7 @@ fn writeString(section: *Section, str: []const u8) void {...@@ -170,7 +170,7 @@ fn writeString(section: *Section, str: []const u8) void {
170170
171 var j: usize = 0;171 var j: usize = 0;
172 while (j < @sizeOf(Word) and i + j < str.len) : (j += 1) {172 while (j < @sizeOf(Word) and i + j < str.len) : (j += 1) {
173 word |= @as(Word, str[i + j]) << @intCast(Log2Word, j * std.meta.bitCount(u8));173 word |= @as(Word, str[i + j]) << @intCast(Log2Word, j * @bitSizeOf(u8));
174 }174 }
175175
176 section.instructions.appendAssumeCapacity(word);176 section.instructions.appendAssumeCapacity(word);