authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-21 17:24:04+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-22 11:19:20+03:00
log62ff8871ed9c8c4e46d8acd1d227ed3fb802be7f
treeb5bdd3f092ebc0b7e9c260df798b7019f69cdae7
parent6c020cdb767192757b6c4b43e2f14c5394760431

stage2+stage1: remove type parameter from bit builtins

Closes #12529 Closes #12511 Closes #6835

55 files changed, 264 insertions(+), 268 deletions(-)

doc/langref.html.in+10-10
......@@ -8031,8 +8031,8 @@ fn func(y: *i32) void {
80318031 {#header_close#}
80328032
80338033 {#header_open|@byteSwap#}
8034 <pre>{#syntax#}@byteSwap(comptime T: type, operand: T) T{#endsyntax#}</pre>
8035 <p>{#syntax#}T{#endsyntax#} must be an integer type with bit count evenly divisible by 8.</p>
8034 <pre>{#syntax#}@byteSwap(operand: anytype) T{#endsyntax#}</pre>
8035 <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type with bit count evenly divisible by 8.</p>
80368036 <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
80378037 <p>
80388038 Swaps the byte order of the integer. This converts a big endian integer to a little endian integer,
......@@ -8049,8 +8049,8 @@ fn func(y: *i32) void {
80498049 {#header_close#}
80508050
80518051 {#header_open|@bitReverse#}
8052 <pre>{#syntax#}@bitReverse(comptime T: type, integer: T) T{#endsyntax#}</pre>
8053 <p>{#syntax#}T{#endsyntax#} accepts any integer type.</p>
8052 <pre>{#syntax#}@bitReverse(integer: anytype) T{#endsyntax#}</pre>
8053 <p>{#syntax#}@TypeOf(anytype){#endsyntax#} accepts any integer type or integer vector type.</p>
80548054 <p>
80558055 Reverses the bitpattern of an integer value, including the sign bit if applicable.
80568056 </p>
......@@ -8189,8 +8189,8 @@ pub const CallOptions = struct {
81898189 {#header_close#}
81908190
81918191 {#header_open|@clz#}
8192 <pre>{#syntax#}@clz(comptime T: type, operand: T){#endsyntax#}</pre>
8193 <p>{#syntax#}T{#endsyntax#} must be an integer type.</p>
8192 <pre>{#syntax#}@clz(operand: anytype){#endsyntax#}</pre>
8193 <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
81948194 <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
81958195 <p>
81968196 This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer.
......@@ -8335,8 +8335,8 @@ test "main" {
83358335 {#header_close#}
83368336
83378337 {#header_open|@ctz#}
8338 <pre>{#syntax#}@ctz(comptime T: type, operand: T){#endsyntax#}</pre>
8339 <p>{#syntax#}T{#endsyntax#} must be an integer type.</p>
8338 <pre>{#syntax#}@ctz(operand: anytype){#endsyntax#}</pre>
8339 <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
83408340 <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
83418341 <p>
83428342 This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer.
......@@ -8972,8 +8972,8 @@ test "@wasmMemoryGrow" {
89728972 {#header_close#}
89738973
89748974 {#header_open|@popCount#}
8975 <pre>{#syntax#}@popCount(comptime T: type, operand: T){#endsyntax#}</pre>
8976 <p>{#syntax#}T{#endsyntax#} must be an integer type.</p>
8975 <pre>{#syntax#}@popCount(operand: anytype){#endsyntax#}</pre>
8976 <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p>
89778977 <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
89788978 <p>Counts the number of bits set in an integer.</p>
89798979 <p>
lib/compiler_rt/addf3.zig+2-2
......@@ -9,7 +9,7 @@ const normalize = common.normalize;
99pub inline fn addf3(comptime T: type, a: T, b: T) T {
1010 const bits = @typeInfo(T).Float.bits;
1111 const Z = std.meta.Int(.unsigned, bits);
12 const S = std.meta.Int(.unsigned, bits - @clz(Z, @as(Z, bits) - 1));
12 const S = std.meta.Int(.unsigned, bits - @clz(@as(Z, bits) - 1));
1313
1414 const typeWidth = bits;
1515 const significandBits = math.floatMantissaBits(T);
......@@ -118,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T {
118118 // If partial cancellation occured, we need to left-shift the result
119119 // and adjust the exponent:
120120 if (aSignificand < integerBit << 3) {
121 const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.Int(.unsigned, bits), integerBit << 3));
121 const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(integerBit << 3));
122122 aSignificand <<= @intCast(S, shift);
123123 aExponent -= shift;
124124 }
lib/compiler_rt/common.zig+1-1
......@@ -192,7 +192,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn
192192 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
193193 const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T);
194194
195 const shift = @clz(Z, significand.*) - @clz(Z, integerBit);
195 const shift = @clz(significand.*) - @clz(integerBit);
196196 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
197197 return @as(i32, 1) - shift;
198198}
lib/compiler_rt/extendf.zig+4-4
......@@ -56,8 +56,8 @@ pub inline fn extendf(
5656 // a is denormal.
5757 // renormalize the significand and clear the leading bit, then insert
5858 // the correct adjusted exponent in the destination type.
59 const scale: u32 = @clz(src_rep_t, aAbs) -
60 @clz(src_rep_t, @as(src_rep_t, srcMinNormal));
59 const scale: u32 = @clz(aAbs) -
60 @clz(@as(src_rep_t, srcMinNormal));
6161 absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
6262 absResult ^= dstMinNormal;
6363 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
......@@ -119,8 +119,8 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
119119 // a is denormal.
120120 // renormalize the significand and clear the leading bit, then insert
121121 // the correct adjusted exponent in the destination type.
122 const scale: u16 = @clz(src_rep_t, a_abs) -
123 @clz(src_rep_t, @as(src_rep_t, src_min_normal));
122 const scale: u16 = @clz(a_abs) -
123 @clz(@as(src_rep_t, src_min_normal));
124124
125125 dst.fraction = @as(u64, a_abs) << @intCast(u6, dst_sig_bits - src_sig_bits + scale);
126126 dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers
lib/compiler_rt/extendxftf2.zig+1-1
......@@ -38,7 +38,7 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {
3838 // a is denormal
3939 // renormalize the significand and clear the leading bit and integer part,
4040 // then insert the correct adjusted exponent in the destination type.
41 const scale: u32 = @clz(u64, a_rep.fraction);
41 const scale: u32 = @clz(a_rep.fraction);
4242 abs_result = @as(u128, a_rep.fraction) << @intCast(u7, dst_sig_bits - src_sig_bits + scale + 1);
4343 abs_result ^= dst_min_normal;
4444 abs_result |= @as(u128, scale + 1) << dst_sig_bits;
lib/compiler_rt/int.zig+1-1
......@@ -243,7 +243,7 @@ inline fn div_u32(n: u32, d: u32) u32 {
243243 // special cases
244244 if (d == 0) return 0; // ?!
245245 if (n == 0) return 0;
246 var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n)));
246 var sr = @bitCast(c_uint, @as(c_int, @clz(d)) - @as(c_int, @clz(n)));
247247 // 0 <= sr <= n_uword_bits - 1 or sr large
248248 if (sr > n_uword_bits - 1) {
249249 // d > r
lib/compiler_rt/int_to_float.zig+2-2
......@@ -23,7 +23,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T {
2323 var result: uT = sign_bit;
2424
2525 // Compute significand
26 var exp = int_bits - @clz(Z, abs_val) - 1;
26 var exp = int_bits - @clz(abs_val) - 1;
2727 if (int_bits <= fractional_bits or exp <= fractional_bits) {
2828 const shift_amt = fractional_bits - @intCast(math.Log2Int(uT), exp);
2929
......@@ -32,7 +32,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T {
3232 result ^= implicit_bit; // Remove implicit integer bit
3333 } else {
3434 var shift_amt = @intCast(math.Log2Int(Z), exp - fractional_bits);
35 const exact_tie: bool = @ctz(Z, abs_val) == shift_amt - 1;
35 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
3737 // Shift down result and remove implicit integer bit
3838 result = @intCast(uT, (abs_val >> (shift_amt - 1))) ^ (implicit_bit << 1);
lib/compiler_rt/mulf3.zig+1-1
......@@ -186,7 +186,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 {
186186 const Z = PowerOfTwoSignificandZ(T);
187187 const integerBit = @as(Z, 1) << math.floatFractionalBits(T);
188188
189 const shift = @clz(Z, significand.*) - @clz(Z, integerBit);
189 const shift = @clz(significand.*) - @clz(integerBit);
190190 significand.* <<= @intCast(math.Log2Int(Z), shift);
191191 return @as(i32, 1) - shift;
192192}
lib/compiler_rt/udivmod.zig+5-5
......@@ -75,12 +75,12 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
7575 r[high] = n[high] & (d[high] - 1);
7676 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
7777 }
78 return n[high] >> @intCast(Log2SingleInt, @ctz(SingleInt, d[high]));
78 return n[high] >> @intCast(Log2SingleInt, @ctz(d[high]));
7979 }
8080 // K K
8181 // ---
8282 // K 0
83 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
83 sr = @bitCast(c_uint, @as(c_int, @clz(d[high])) - @as(c_int, @clz(n[high])));
8484 // 0 <= sr <= single_int_bits - 2 or sr large
8585 if (sr > single_int_bits - 2) {
8686 if (maybe_rem) |rem| {
......@@ -110,7 +110,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
110110 if (d[low] == 1) {
111111 return a;
112112 }
113 sr = @ctz(SingleInt, d[low]);
113 sr = @ctz(d[low]);
114114 q[high] = n[high] >> @intCast(Log2SingleInt, sr);
115115 q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
116116 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
......@@ -118,7 +118,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
118118 // K X
119119 // ---
120120 // 0 K
121 sr = 1 + single_int_bits + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
121 sr = 1 + single_int_bits + @as(c_uint, @clz(d[low])) - @as(c_uint, @clz(n[high]));
122122 // 2 <= sr <= double_int_bits - 1
123123 // q.all = a << (double_int_bits - sr);
124124 // r.all = a >> sr;
......@@ -144,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
144144 // K X
145145 // ---
146146 // K K
147 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
147 sr = @bitCast(c_uint, @as(c_int, @clz(d[high])) - @as(c_int, @clz(n[high])));
148148 // 0 <= sr <= single_int_bits - 1 or sr large
149149 if (sr > single_int_bits - 1) {
150150 if (maybe_rem) |rem| {
lib/std/Thread/Futex.zig+2-2
......@@ -703,7 +703,7 @@ const PosixImpl = struct {
703703 const max_multiplier_bits = @bitSizeOf(usize);
704704 const fibonacci_multiplier = 0x9E3779B97F4A7C15 >> (64 - max_multiplier_bits);
705705
706 const max_bucket_bits = @ctz(usize, buckets.len);
706 const max_bucket_bits = @ctz(buckets.len);
707707 comptime assert(std.math.isPowerOfTwo(buckets.len));
708708
709709 const index = (address *% fibonacci_multiplier) >> (max_multiplier_bits - max_bucket_bits);
......@@ -721,7 +721,7 @@ const PosixImpl = struct {
721721 // then cut off the zero bits from the alignment to get the unique address.
722722 const addr = @ptrToInt(ptr);
723723 assert(addr & (alignment - 1) == 0);
724 return addr >> @ctz(usize, alignment);
724 return addr >> @ctz(alignment);
725725 }
726726 };
727727
lib/std/Thread/Mutex.zig+1-1
......@@ -140,7 +140,7 @@ const FutexImpl = struct {
140140 // - they both seem to mark the cache-line as modified regardless: https://stackoverflow.com/a/63350048
141141 // - `lock bts` is smaller instruction-wise which makes it better for inlining
142142 if (comptime builtin.target.cpu.arch.isX86()) {
143 const locked_bit = @ctz(u32, @as(u32, locked));
143 const locked_bit = @ctz(@as(u32, locked));
144144 return self.state.bitSet(locked_bit, .Acquire) == 0;
145145 }
146146
lib/std/Thread/RwLock.zig+2-2
......@@ -168,8 +168,8 @@ pub const DefaultRwLock = struct {
168168 const IS_WRITING: usize = 1;
169169 const WRITER: usize = 1 << 1;
170170 const READER: usize = 1 << (1 + @bitSizeOf(Count));
171 const WRITER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, WRITER);
172 const READER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, READER);
171 const WRITER_MASK: usize = std.math.maxInt(Count) << @ctz(WRITER);
172 const READER_MASK: usize = std.math.maxInt(Count) << @ctz(READER);
173173 const Count = std.meta.Int(.unsigned, @divFloor(@bitSizeOf(usize) - 1, 2));
174174
175175 pub fn tryLock(rwl: *DefaultRwLock) bool {
lib/std/bit_set.zig+13-13
......@@ -91,7 +91,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
9191
9292 /// Returns the total number of set bits in this bit set.
9393 pub fn count(self: Self) usize {
94 return @popCount(MaskInt, self.mask);
94 return @popCount(self.mask);
9595 }
9696
9797 /// Changes the value of the specified bit of the bit
......@@ -179,7 +179,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
179179 pub fn findFirstSet(self: Self) ?usize {
180180 const mask = self.mask;
181181 if (mask == 0) return null;
182 return @ctz(MaskInt, mask);
182 return @ctz(mask);
183183 }
184184
185185 /// Finds the index of the first set bit, and unsets it.
......@@ -187,7 +187,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
187187 pub fn toggleFirstSet(self: *Self) ?usize {
188188 const mask = self.mask;
189189 if (mask == 0) return null;
190 const index = @ctz(MaskInt, mask);
190 const index = @ctz(mask);
191191 self.mask = mask & (mask - 1);
192192 return index;
193193 }
......@@ -222,12 +222,12 @@ pub fn IntegerBitSet(comptime size: u16) type {
222222
223223 switch (direction) {
224224 .forward => {
225 const next_index = @ctz(MaskInt, self.bits_remain);
225 const next_index = @ctz(self.bits_remain);
226226 self.bits_remain &= self.bits_remain - 1;
227227 return next_index;
228228 },
229229 .reverse => {
230 const leading_zeroes = @clz(MaskInt, self.bits_remain);
230 const leading_zeroes = @clz(self.bits_remain);
231231 const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes;
232232 self.bits_remain &= (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1;
233233 return top_bit;
......@@ -347,7 +347,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
347347 pub fn count(self: Self) usize {
348348 var total: usize = 0;
349349 for (self.masks) |mask| {
350 total += @popCount(MaskInt, mask);
350 total += @popCount(mask);
351351 }
352352 return total;
353353 }
......@@ -475,7 +475,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
475475 if (mask != 0) break mask;
476476 offset += @bitSizeOf(MaskInt);
477477 } else return null;
478 return offset + @ctz(MaskInt, mask);
478 return offset + @ctz(mask);
479479 }
480480
481481 /// Finds the index of the first set bit, and unsets it.
......@@ -486,7 +486,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
486486 if (mask.* != 0) break mask;
487487 offset += @bitSizeOf(MaskInt);
488488 } else return null;
489 const index = @ctz(MaskInt, mask.*);
489 const index = @ctz(mask.*);
490490 mask.* &= (mask.* - 1);
491491 return offset + index;
492492 }
......@@ -657,7 +657,7 @@ pub const DynamicBitSetUnmanaged = struct {
657657 var total: usize = 0;
658658 for (self.masks[0..num_masks]) |mask| {
659659 // Note: This is where we depend on padding bits being zero
660 total += @popCount(MaskInt, mask);
660 total += @popCount(mask);
661661 }
662662 return total;
663663 }
......@@ -795,7 +795,7 @@ pub const DynamicBitSetUnmanaged = struct {
795795 mask += 1;
796796 offset += @bitSizeOf(MaskInt);
797797 } else return null;
798 return offset + @ctz(MaskInt, mask[0]);
798 return offset + @ctz(mask[0]);
799799 }
800800
801801 /// Finds the index of the first set bit, and unsets it.
......@@ -808,7 +808,7 @@ pub const DynamicBitSetUnmanaged = struct {
808808 mask += 1;
809809 offset += @bitSizeOf(MaskInt);
810810 } else return null;
811 const index = @ctz(MaskInt, mask[0]);
811 const index = @ctz(mask[0]);
812812 mask[0] &= (mask[0] - 1);
813813 return offset + index;
814814 }
......@@ -1067,12 +1067,12 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
10671067
10681068 switch (direction) {
10691069 .forward => {
1070 const next_index = @ctz(MaskInt, self.bits_remain) + self.bit_offset;
1070 const next_index = @ctz(self.bits_remain) + self.bit_offset;
10711071 self.bits_remain &= self.bits_remain - 1;
10721072 return next_index;
10731073 },
10741074 .reverse => {
1075 const leading_zeroes = @clz(MaskInt, self.bits_remain);
1075 const leading_zeroes = @clz(self.bits_remain);
10761076 const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes;
10771077 const no_top_bit_mask = (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1;
10781078 self.bits_remain &= no_top_bit_mask;
lib/std/compress/deflate/bits_utils.zig+1-1
......@@ -2,7 +2,7 @@ const math = @import("std").math;
22
33// Reverse bit-by-bit a N-bit code.
44pub fn bitReverse(comptime T: type, value: T, N: usize) T {
5 const r = @bitReverse(T, value);
5 const r = @bitReverse(value);
66 return r >> @intCast(math.Log2Int(T), @typeInfo(T).Int.bits - N);
77}
88
lib/std/crypto/aes_ocb.zig+5-5
......@@ -66,7 +66,7 @@ fn AesOcb(comptime Aes: anytype) type {
6666 var offset = [_]u8{0} ** 16;
6767 var i: usize = 0;
6868 while (i < full_blocks) : (i += 1) {
69 xorWith(&offset, lt[@ctz(usize, i + 1)]);
69 xorWith(&offset, lt[@ctz(i + 1)]);
7070 var e = xorBlocks(offset, a[i * 16 ..][0..16].*);
7171 aes_enc_ctx.encrypt(&e, &e);
7272 xorWith(&sum, e);
......@@ -129,7 +129,7 @@ fn AesOcb(comptime Aes: anytype) type {
129129 var es: [16 * wb]u8 align(16) = undefined;
130130 var j: usize = 0;
131131 while (j < wb) : (j += 1) {
132 xorWith(&offset, lt[@ctz(usize, i + 1 + j)]);
132 xorWith(&offset, lt[@ctz(i + 1 + j)]);
133133 offsets[j] = offset;
134134 const p = m[(i + j) * 16 ..][0..16].*;
135135 mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j]));
......@@ -143,7 +143,7 @@ fn AesOcb(comptime Aes: anytype) type {
143143 }
144144 }
145145 while (i < full_blocks) : (i += 1) {
146 xorWith(&offset, lt[@ctz(usize, i + 1)]);
146 xorWith(&offset, lt[@ctz(i + 1)]);
147147 const p = m[i * 16 ..][0..16].*;
148148 var e = xorBlocks(p, offset);
149149 aes_enc_ctx.encrypt(&e, &e);
......@@ -193,7 +193,7 @@ fn AesOcb(comptime Aes: anytype) type {
193193 var es: [16 * wb]u8 align(16) = undefined;
194194 var j: usize = 0;
195195 while (j < wb) : (j += 1) {
196 xorWith(&offset, lt[@ctz(usize, i + 1 + j)]);
196 xorWith(&offset, lt[@ctz(i + 1 + j)]);
197197 offsets[j] = offset;
198198 const q = c[(i + j) * 16 ..][0..16].*;
199199 mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j]));
......@@ -207,7 +207,7 @@ fn AesOcb(comptime Aes: anytype) type {
207207 }
208208 }
209209 while (i < full_blocks) : (i += 1) {
210 xorWith(&offset, lt[@ctz(usize, i + 1)]);
210 xorWith(&offset, lt[@ctz(i + 1)]);
211211 const q = c[i * 16 ..][0..16].*;
212212 var e = xorBlocks(q, offset);
213213 aes_dec_ctx.decrypt(&e, &e);
lib/std/crypto/ghash.zig+16-16
......@@ -41,8 +41,8 @@ pub const Ghash = struct {
4141 pub fn init(key: *const [key_length]u8) Ghash {
4242 const h1 = mem.readIntBig(u64, key[0..8]);
4343 const h0 = mem.readIntBig(u64, key[8..16]);
44 const h1r = @bitReverse(u64, h1);
45 const h0r = @bitReverse(u64, h0);
44 const h1r = @bitReverse(h1);
45 const h0r = @bitReverse(h0);
4646 const h2 = h0 ^ h1;
4747 const h2r = h0r ^ h1r;
4848
......@@ -68,8 +68,8 @@ pub const Ghash = struct {
6868 hh.update(key);
6969 const hh1 = hh.y1;
7070 const hh0 = hh.y0;
71 const hh1r = @bitReverse(u64, hh1);
72 const hh0r = @bitReverse(u64, hh0);
71 const hh1r = @bitReverse(hh1);
72 const hh0r = @bitReverse(hh0);
7373 const hh2 = hh0 ^ hh1;
7474 const hh2r = hh0r ^ hh1r;
7575
......@@ -156,8 +156,8 @@ pub const Ghash = struct {
156156 y1 ^= mem.readIntBig(u64, msg[i..][0..8]);
157157 y0 ^= mem.readIntBig(u64, msg[i..][8..16]);
158158
159 const y1r = @bitReverse(u64, y1);
160 const y0r = @bitReverse(u64, y0);
159 const y1r = @bitReverse(y1);
160 const y0r = @bitReverse(y0);
161161 const y2 = y0 ^ y1;
162162 const y2r = y0r ^ y1r;
163163
......@@ -172,8 +172,8 @@ pub const Ghash = struct {
172172 const sy1 = mem.readIntBig(u64, msg[i..][16..24]);
173173 const sy0 = mem.readIntBig(u64, msg[i..][24..32]);
174174
175 const sy1r = @bitReverse(u64, sy1);
176 const sy0r = @bitReverse(u64, sy0);
175 const sy1r = @bitReverse(sy1);
176 const sy0r = @bitReverse(sy0);
177177 const sy2 = sy0 ^ sy1;
178178 const sy2r = sy0r ^ sy1r;
179179
......@@ -191,9 +191,9 @@ pub const Ghash = struct {
191191 z0h ^= sz0h;
192192 z1h ^= sz1h;
193193 z2h ^= sz2h;
194 z0h = @bitReverse(u64, z0h) >> 1;
195 z1h = @bitReverse(u64, z1h) >> 1;
196 z2h = @bitReverse(u64, z2h) >> 1;
194 z0h = @bitReverse(z0h) >> 1;
195 z1h = @bitReverse(z1h) >> 1;
196 z2h = @bitReverse(z2h) >> 1;
197197
198198 var v3 = z1h;
199199 var v2 = z1 ^ z2h;
......@@ -217,8 +217,8 @@ pub const Ghash = struct {
217217 y1 ^= mem.readIntBig(u64, msg[i..][0..8]);
218218 y0 ^= mem.readIntBig(u64, msg[i..][8..16]);
219219
220 const y1r = @bitReverse(u64, y1);
221 const y0r = @bitReverse(u64, y0);
220 const y1r = @bitReverse(y1);
221 const y0r = @bitReverse(y0);
222222 const y2 = y0 ^ y1;
223223 const y2r = y0r ^ y1r;
224224
......@@ -228,9 +228,9 @@ pub const Ghash = struct {
228228 var z0h = clmul(y0r, st.h0r);
229229 var z1h = clmul(y1r, st.h1r);
230230 var z2h = clmul(y2r, st.h2r) ^ z0h ^ z1h;
231 z0h = @bitReverse(u64, z0h) >> 1;
232 z1h = @bitReverse(u64, z1h) >> 1;
233 z2h = @bitReverse(u64, z2h) >> 1;
231 z0h = @bitReverse(z0h) >> 1;
232 z1h = @bitReverse(z1h) >> 1;
233 z2h = @bitReverse(z2h) >> 1;
234234
235235 // shift & reduce
236236 var v3 = z1h;
lib/std/elf.zig+3-3
......@@ -387,7 +387,7 @@ pub const Header = struct {
387387
388388 const machine = if (need_bswap) blk: {
389389 const value = @enumToInt(hdr32.e_machine);
390 break :blk @intToEnum(EM, @byteSwap(@TypeOf(value), value));
390 break :blk @intToEnum(EM, @byteSwap(value));
391391 } else hdr32.e_machine;
392392
393393 return @as(Header, .{
......@@ -511,7 +511,7 @@ pub fn SectionHeaderIterator(ParseSource: anytype) type {
511511pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) {
512512 if (is_64) {
513513 if (need_bswap) {
514 return @byteSwap(@TypeOf(int_64), int_64);
514 return @byteSwap(int_64);
515515 } else {
516516 return int_64;
517517 }
......@@ -522,7 +522,7 @@ pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @Typ
522522
523523pub fn int32(need_bswap: bool, int_32: anytype, comptime Int64: anytype) Int64 {
524524 if (need_bswap) {
525 return @byteSwap(@TypeOf(int_32), int_32);
525 return @byteSwap(int_32);
526526 } else {
527527 return int_32;
528528 }
lib/std/event/channel.zig+1-1
......@@ -56,7 +56,7 @@ pub fn Channel(comptime T: type) type {
5656 pub fn init(self: *SelfChannel, buffer: []T) void {
5757 // The ring buffer implementation only works with power of 2 buffer sizes
5858 // because of relying on subtracting across zero. For example (0 -% 1) % 10 == 5
59 assert(buffer.len == 0 or @popCount(usize, buffer.len) == 1);
59 assert(buffer.len == 0 or @popCount(buffer.len) == 1);
6060
6161 self.* = SelfChannel{
6262 .buffer_len = 0,
lib/std/fmt.zig+2-2
......@@ -195,7 +195,7 @@ pub fn format(
195195 }
196196
197197 if (comptime arg_state.hasUnusedArgs()) {
198 const missing_count = arg_state.args_len - @popCount(ArgSetType, arg_state.used_args);
198 const missing_count = arg_state.args_len - @popCount(arg_state.used_args);
199199 switch (missing_count) {
200200 0 => unreachable,
201201 1 => @compileError("unused argument in '" ++ fmt ++ "'"),
......@@ -380,7 +380,7 @@ const ArgState = struct {
380380 args_len: usize,
381381
382382 fn hasUnusedArgs(self: *@This()) bool {
383 return @popCount(ArgSetType, self.used_args) != self.args_len;
383 return @popCount(self.used_args) != self.args_len;
384384 }
385385
386386 fn nextArg(self: *@This(), arg_index: ?usize) ?usize {
lib/std/fmt/parse_float/convert_eisel_lemire.zig+1-1
......@@ -36,7 +36,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) {
3636 }
3737
3838 // Normalize our significant digits, so the most-significant bit is set.
39 const lz = @clz(u64, @bitCast(u64, w));
39 const lz = @clz(@bitCast(u64, w));
4040 w = math.shl(u64, w, lz);
4141
4242 const r = computeProductApprox(q, w, float_info.mantissa_explicit_bits + 3);
lib/std/hash/cityhash.zig+5-5
......@@ -143,9 +143,9 @@ pub const CityHash32 = struct {
143143 h = rotr32(h, 19);
144144 h = h *% 5 +% 0xe6546b64;
145145 g ^= b4;
146 g = @byteSwap(u32, g) *% 5;
146 g = @byteSwap(g) *% 5;
147147 h +%= b4 *% 5;
148 h = @byteSwap(u32, h);
148 h = @byteSwap(h);
149149 f +%= b0;
150150 const t: u32 = h;
151151 h = f;
......@@ -252,11 +252,11 @@ pub const CityHash64 = struct {
252252
253253 const u: u64 = rotr64(a +% g, 43) +% (rotr64(b, 30) +% c) *% 9;
254254 const v: u64 = ((a +% g) ^ d) +% f +% 1;
255 const w: u64 = @byteSwap(u64, (u +% v) *% mul) +% h;
255 const w: u64 = @byteSwap((u +% v) *% mul) +% h;
256256 const x: u64 = rotr64(e +% f, 42) +% c;
257 const y: u64 = (@byteSwap(u64, (v +% w) *% mul) +% g) *% mul;
257 const y: u64 = (@byteSwap((v +% w) *% mul) +% g) *% mul;
258258 const z: u64 = e +% f +% c;
259 const a1: u64 = @byteSwap(u64, (x +% z) *% mul +% y) +% b;
259 const a1: u64 = @byteSwap((x +% z) *% mul +% y) +% b;
260260 const b1: u64 = shiftmix((z +% a1) *% mul +% d +% h) *% mul;
261261 return b1 +% x;
262262 }
lib/std/hash/murmur.zig+11-11
......@@ -19,7 +19,7 @@ pub const Murmur2_32 = struct {
1919 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
2020 var k1: u32 = v;
2121 if (native_endian == .Big)
22 k1 = @byteSwap(u32, k1);
22 k1 = @byteSwap(k1);
2323 k1 *%= m;
2424 k1 ^= k1 >> 24;
2525 k1 *%= m;
......@@ -104,7 +104,7 @@ pub const Murmur2_64 = struct {
104104 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
105105 var k1: u64 = v;
106106 if (native_endian == .Big)
107 k1 = @byteSwap(u64, k1);
107 k1 = @byteSwap(k1);
108108 k1 *%= m;
109109 k1 ^= k1 >> 47;
110110 k1 *%= m;
......@@ -117,7 +117,7 @@ pub const Murmur2_64 = struct {
117117 var k1: u64 = 0;
118118 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
119119 if (native_endian == .Big)
120 k1 = @byteSwap(u64, k1);
120 k1 = @byteSwap(k1);
121121 h1 ^= k1;
122122 h1 *%= m;
123123 }
......@@ -184,7 +184,7 @@ pub const Murmur3_32 = struct {
184184 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
185185 var k1: u32 = v;
186186 if (native_endian == .Big)
187 k1 = @byteSwap(u32, k1);
187 k1 = @byteSwap(k1);
188188 k1 *%= c1;
189189 k1 = rotl32(k1, 15);
190190 k1 *%= c2;
......@@ -296,7 +296,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
296296
297297 var h = hash_fn(key[0..i], 256 - i);
298298 if (native_endian == .Big)
299 h = @byteSwap(@TypeOf(h), h);
299 h = @byteSwap(h);
300300 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
301301 }
302302
......@@ -310,8 +310,8 @@ test "murmur2_32" {
310310 var v0le: u32 = v0;
311311 var v1le: u64 = v1;
312312 if (native_endian == .Big) {
313 v0le = @byteSwap(u32, v0le);
314 v1le = @byteSwap(u64, v1le);
313 v0le = @byteSwap(v0le);
314 v1le = @byteSwap(v1le);
315315 }
316316 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
317317 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
......@@ -324,8 +324,8 @@ test "murmur2_64" {
324324 var v0le: u32 = v0;
325325 var v1le: u64 = v1;
326326 if (native_endian == .Big) {
327 v0le = @byteSwap(u32, v0le);
328 v1le = @byteSwap(u64, v1le);
327 v0le = @byteSwap(v0le);
328 v1le = @byteSwap(v1le);
329329 }
330330 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
331331 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
......@@ -338,8 +338,8 @@ test "murmur3_32" {
338338 var v0le: u32 = v0;
339339 var v1le: u64 = v1;
340340 if (native_endian == .Big) {
341 v0le = @byteSwap(u32, v0le);
342 v1le = @byteSwap(u64, v1le);
341 v0le = @byteSwap(v0le);
342 v1le = @byteSwap(v1le);
343343 }
344344 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
345345 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
lib/std/heap.zig+2-2
......@@ -479,7 +479,7 @@ const WasmPageAllocator = struct {
479479 @setCold(true);
480480 for (self.data) |segment, i| {
481481 const spills_into_next = @bitCast(i128, segment) < 0;
482 const has_enough_bits = @popCount(u128, segment) >= num_pages;
482 const has_enough_bits = @popCount(segment) >= num_pages;
483483
484484 if (!spills_into_next and !has_enough_bits) continue;
485485
......@@ -1185,7 +1185,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void {
11851185 const large_align = @as(u29, mem.page_size << 2);
11861186
11871187 var align_mask: usize = undefined;
1188 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
1188 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(large_align)), &align_mask);
11891189
11901190 var slice = try allocator.alignedAlloc(u8, large_align, 500);
11911191 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
lib/std/leb128.zig+1-1
......@@ -317,7 +317,7 @@ fn test_write_leb128(value: anytype) !void {
317317 const bytes_needed = bn: {
318318 if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1);
319319
320 const unused_bits = if (value < 0) @clz(T, ~value) else @clz(T, value);
320 const unused_bits = if (value < 0) @clz(~value) else @clz(value);
321321 const used_bits: u16 = (@typeInfo(T).Int.bits - unused_bits) + @boolToInt(t_signed);
322322 if (used_bits <= 7) break :bn @as(u16, 1);
323323 break :bn ((used_bits + 6) / 7);
lib/std/math.zig+2-2
......@@ -1146,7 +1146,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(
11461146 assert(value != 0);
11471147 const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1);
11481148 const ShiftType = std.math.Log2Int(PromotedType);
1149 return @as(PromotedType, 1) << @intCast(ShiftType, @typeInfo(T).Int.bits - @clz(T, value - 1));
1149 return @as(PromotedType, 1) << @intCast(ShiftType, @typeInfo(T).Int.bits - @clz(value - 1));
11501150}
11511151
11521152/// Returns the next power of two (if the value is not already a power of two).
......@@ -1212,7 +1212,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
12121212 if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned)
12131213 @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T));
12141214 assert(x != 0);
1215 return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(T, x));
1215 return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(x));
12161216}
12171217
12181218/// Return the log base 2 of integer value x, rounding up to the
lib/std/math/big/int.zig+7-7
......@@ -887,7 +887,7 @@ pub const Mutable = struct {
887887
888888 var sum: Limb = 0;
889889 for (r.limbs[0..r.len]) |limb| {
890 sum += @popCount(Limb, limb);
890 sum += @popCount(limb);
891891 }
892892 r.set(sum);
893893 }
......@@ -1520,7 +1520,7 @@ pub const Mutable = struct {
15201520 ) void {
15211521 // 0.
15221522 // Normalize so that y[t] > b/2
1523 const lz = @clz(Limb, y.limbs[y.len - 1]);
1523 const lz = @clz(y.limbs[y.len - 1]);
15241524 const norm_shift = if (lz == 0 and y.toConst().isOdd())
15251525 limb_bits // Force an extra limb so that y is even.
15261526 else
......@@ -1917,7 +1917,7 @@ pub const Const = struct {
19171917
19181918 /// Returns the number of bits required to represent the absolute value of an integer.
19191919 pub fn bitCountAbs(self: Const) usize {
1920 return (self.limbs.len - 1) * limb_bits + (limb_bits - @clz(Limb, self.limbs[self.limbs.len - 1]));
1920 return (self.limbs.len - 1) * limb_bits + (limb_bits - @clz(self.limbs[self.limbs.len - 1]));
19211921 }
19221922
19231923 /// Returns the number of bits required to represent the integer in twos-complement form.
......@@ -1936,9 +1936,9 @@ pub const Const = struct {
19361936 if (!self.positive) block: {
19371937 bits += 1;
19381938
1939 if (@popCount(Limb, self.limbs[self.limbs.len - 1]) == 1) {
1939 if (@popCount(self.limbs[self.limbs.len - 1]) == 1) {
19401940 for (self.limbs[0 .. self.limbs.len - 1]) |limb| {
1941 if (@popCount(Limb, limb) != 0) {
1941 if (@popCount(limb) != 0) {
19421942 break :block;
19431943 }
19441944 }
......@@ -3895,8 +3895,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
38953895 // The initial assignment makes the result end in `r` so an extra memory
38963896 // copy is saved, each 1 flips the index twice so it's only the zeros that
38973897 // matter.
3898 const b_leading_zeros = @clz(u32, b);
3899 const exp_zeros = @popCount(u32, ~b) - b_leading_zeros;
3898 const b_leading_zeros = @clz(b);
3899 const exp_zeros = @popCount(~b) - b_leading_zeros;
39003900 if (exp_zeros & 1 != 0) {
39013901 tmp1 = tmp_limbs;
39023902 tmp2 = r;
lib/std/mem.zig+13-13
......@@ -1319,7 +1319,7 @@ pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int
13191319/// This function cannot fail and cannot cause undefined behavior.
13201320/// Assumes the endianness of memory is foreign, so it must byte-swap.
13211321pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {
1322 return @byteSwap(T, readIntNative(T, bytes));
1322 return @byteSwap(readIntNative(T, bytes));
13231323}
13241324
13251325pub const readIntLittle = switch (native_endian) {
......@@ -1348,7 +1348,7 @@ pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T {
13481348/// The bit count of T must be evenly divisible by 8.
13491349/// Assumes the endianness of memory is foreign, so it must byte-swap.
13501350pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
1351 return @byteSwap(T, readIntSliceNative(T, bytes));
1351 return @byteSwap(readIntSliceNative(T, bytes));
13521352}
13531353
13541354pub const readIntSliceLittle = switch (native_endian) {
......@@ -1430,7 +1430,7 @@ pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u
14301430/// the integer bit width must be divisible by 8.
14311431/// This function stores in foreign endian, which means it does a @byteSwap first.
14321432pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T) void {
1433 writeIntNative(T, buf, @byteSwap(T, value));
1433 writeIntNative(T, buf, @byteSwap(value));
14341434}
14351435
14361436pub const writeIntLittle = switch (native_endian) {
......@@ -1575,7 +1575,7 @@ pub const bswapAllFields = @compileError("bswapAllFields has been renamed to byt
15751575pub fn byteSwapAllFields(comptime S: type, ptr: *S) void {
15761576 if (@typeInfo(S) != .Struct) @compileError("byteSwapAllFields expects a struct as the first argument");
15771577 inline for (std.meta.fields(S)) |f| {
1578 @field(ptr, f.name) = @byteSwap(f.field_type, @field(ptr, f.name));
1578 @field(ptr, f.name) = @byteSwap(@field(ptr, f.name));
15791579 }
15801580}
15811581
......@@ -2752,14 +2752,14 @@ test "replaceOwned" {
27522752pub fn littleToNative(comptime T: type, x: T) T {
27532753 return switch (native_endian) {
27542754 .Little => x,
2755 .Big => @byteSwap(T, x),
2755 .Big => @byteSwap(x),
27562756 };
27572757}
27582758
27592759/// Converts a big-endian integer to host endianness.
27602760pub fn bigToNative(comptime T: type, x: T) T {
27612761 return switch (native_endian) {
2762 .Little => @byteSwap(T, x),
2762 .Little => @byteSwap(x),
27632763 .Big => x,
27642764 };
27652765}
......@@ -2784,14 +2784,14 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T {
27842784pub fn nativeToLittle(comptime T: type, x: T) T {
27852785 return switch (native_endian) {
27862786 .Little => x,
2787 .Big => @byteSwap(T, x),
2787 .Big => @byteSwap(x),
27882788 };
27892789}
27902790
27912791/// Converts an integer which has host endianness to big endian.
27922792pub fn nativeToBig(comptime T: type, x: T) T {
27932793 return switch (native_endian) {
2794 .Little => @byteSwap(T, x),
2794 .Little => @byteSwap(x),
27952795 .Big => x,
27962796 };
27972797}
......@@ -2803,7 +2803,7 @@ pub fn nativeToBig(comptime T: type, x: T) T {
28032803/// - The delta required to align the pointer is not a multiple of the pointee's
28042804/// type.
28052805pub fn alignPointerOffset(ptr: anytype, align_to: u29) ?usize {
2806 assert(align_to != 0 and @popCount(u29, align_to) == 1);
2806 assert(align_to != 0 and @popCount(align_to) == 1);
28072807
28082808 const T = @TypeOf(ptr);
28092809 const info = @typeInfo(T);
......@@ -3293,7 +3293,7 @@ test "alignForward" {
32933293/// Round an address up to the previous aligned address
32943294/// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2.
32953295pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize {
3296 if (@popCount(usize, alignment) == 1)
3296 if (@popCount(alignment) == 1)
32973297 return alignBackward(i, alignment);
32983298 assert(alignment != 0);
32993299 return i - @mod(i, alignment);
......@@ -3308,7 +3308,7 @@ pub fn alignBackward(addr: usize, alignment: usize) usize {
33083308/// Round an address up to the previous aligned address
33093309/// The alignment must be a power of 2 and greater than 0.
33103310pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
3311 assert(@popCount(T, alignment) == 1);
3311 assert(@popCount(alignment) == 1);
33123312 // 000010000 // example alignment
33133313 // 000001111 // subtract 1
33143314 // 111110000 // binary not
......@@ -3318,11 +3318,11 @@ pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
33183318/// Returns whether `alignment` is a valid alignment, meaning it is
33193319/// a positive power of 2.
33203320pub fn isValidAlign(alignment: u29) bool {
3321 return @popCount(u29, alignment) == 1;
3321 return @popCount(alignment) == 1;
33223322}
33233323
33243324pub fn isAlignedAnyAlign(i: usize, alignment: usize) bool {
3325 if (@popCount(usize, alignment) == 1)
3325 if (@popCount(alignment) == 1)
33263326 return isAligned(i, alignment);
33273327 assert(alignment != 0);
33283328 return 0 == @mod(i, alignment);
lib/std/os/linux.zig+1-1
......@@ -3377,7 +3377,7 @@ pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
33773377pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
33783378 var sum: cpu_count_t = 0;
33793379 for (set) |x| {
3380 sum += @popCount(usize, x);
3380 sum += @popCount(x);
33813381 }
33823382 return sum;
33833383}
lib/std/os/uefi.zig+3-3
......@@ -55,9 +55,9 @@ pub const Guid = extern struct {
5555 if (f.len == 0) {
5656 const fmt = std.fmt.fmtSliceHexLower;
5757
58 const time_low = @byteSwap(u32, self.time_low);
59 const time_mid = @byteSwap(u16, self.time_mid);
60 const time_high_and_version = @byteSwap(u16, self.time_high_and_version);
58 const time_low = @byteSwap(self.time_low);
59 const time_mid = @byteSwap(self.time_mid);
60 const time_high_and_version = @byteSwap(self.time_high_and_version);
6161
6262 return std.fmt.format(writer, "{:0>8}-{:0>4}-{:0>4}-{:0>2}{:0>2}-{:0>12}", .{
6363 fmt(std.mem.asBytes(&time_low)),
lib/std/packed_int_array.zig+3-3
......@@ -76,7 +76,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
7676 const value_ptr = @ptrCast(*align(1) const Container, &bytes[start_byte]);
7777 var value = value_ptr.*;
7878
79 if (endian != native_endian) value = @byteSwap(Container, value);
79 if (endian != native_endian) value = @byteSwap(value);
8080
8181 switch (endian) {
8282 .Big => {
......@@ -126,7 +126,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
126126 const target_ptr = @ptrCast(*align(1) Container, &bytes[start_byte]);
127127 var target = target_ptr.*;
128128
129 if (endian != native_endian) target = @byteSwap(Container, target);
129 if (endian != native_endian) target = @byteSwap(target);
130130
131131 //zero the bits we want to replace in the existing bytes
132132 const inv_mask = @intCast(Container, std.math.maxInt(UnInt)) << keep_shift;
......@@ -136,7 +136,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
136136 //merge the new value
137137 target |= value;
138138
139 if (endian != native_endian) target = @byteSwap(Container, target);
139 if (endian != native_endian) target = @byteSwap(target);
140140
141141 //save it back
142142 target_ptr.* = target;
lib/std/priority_dequeue.zig+1-1
......@@ -69,7 +69,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
6969 // The first element is on a min layer;
7070 // next two are on a max layer;
7171 // next four are on a min layer, and so on.
72 const leading_zeros = @clz(usize, index + 1);
72 const leading_zeros = @clz(index + 1);
7373 const highest_set_bit = @bitSizeOf(usize) - 1 - leading_zeros;
7474 return (highest_set_bit & 1) == 0;
7575 }
lib/std/rand.zig+5-5
......@@ -257,15 +257,15 @@ pub const Random = struct {
257257 // If all 41 bits are zero, generate additional random bits, until a
258258 // set bit is found, or 126 bits have been generated.
259259 const rand = r.int(u64);
260 var rand_lz = @clz(u64, rand);
260 var rand_lz = @clz(rand);
261261 if (rand_lz >= 41) {
262262 // TODO: when #5177 or #489 is implemented,
263263 // tell the compiler it is unlikely (1/2^41) to reach this point.
264264 // (Same for the if branch and the f64 calculations below.)
265 rand_lz = 41 + @clz(u64, r.int(u64));
265 rand_lz = 41 + @clz(r.int(u64));
266266 if (rand_lz == 41 + 64) {
267267 // It is astronomically unlikely to reach this point.
268 rand_lz += @clz(u32, r.int(u32) | 0x7FF);
268 rand_lz += @clz(r.int(u32) | 0x7FF);
269269 }
270270 }
271271 const mantissa = @truncate(u23, rand);
......@@ -277,12 +277,12 @@ pub const Random = struct {
277277 // If all 12 bits are zero, generate additional random bits, until a
278278 // set bit is found, or 1022 bits have been generated.
279279 const rand = r.int(u64);
280 var rand_lz: u64 = @clz(u64, rand);
280 var rand_lz: u64 = @clz(rand);
281281 if (rand_lz >= 12) {
282282 rand_lz = 12;
283283 while (true) {
284284 // It is astronomically unlikely for this loop to execute more than once.
285 const addl_rand_lz = @clz(u64, r.int(u64));
285 const addl_rand_lz = @clz(r.int(u64));
286286 rand_lz += addl_rand_lz;
287287 if (addl_rand_lz != 64) {
288288 break;
lib/std/zig/c_builtins.zig+6-6
......@@ -1,13 +1,13 @@
11const std = @import("std");
22
33pub inline fn __builtin_bswap16(val: u16) u16 {
4 return @byteSwap(u16, val);
4 return @byteSwap(val);
55}
66pub inline fn __builtin_bswap32(val: u32) u32 {
7 return @byteSwap(u32, val);
7 return @byteSwap(val);
88}
99pub inline fn __builtin_bswap64(val: u64) u64 {
10 return @byteSwap(u64, val);
10 return @byteSwap(val);
1111}
1212
1313pub inline fn __builtin_signbit(val: f64) c_int {
......@@ -20,19 +20,19 @@ pub inline fn __builtin_signbitf(val: f32) c_int {
2020pub inline fn __builtin_popcount(val: c_uint) c_int {
2121 // popcount of a c_uint will never exceed the capacity of a c_int
2222 @setRuntimeSafety(false);
23 return @bitCast(c_int, @as(c_uint, @popCount(c_uint, val)));
23 return @bitCast(c_int, @as(c_uint, @popCount(val)));
2424}
2525pub inline fn __builtin_ctz(val: c_uint) c_int {
2626 // Returns the number of trailing 0-bits in val, starting at the least significant bit position.
2727 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
2828 @setRuntimeSafety(false);
29 return @bitCast(c_int, @as(c_uint, @ctz(c_uint, val)));
29 return @bitCast(c_int, @as(c_uint, @ctz(val)));
3030}
3131pub inline fn __builtin_clz(val: c_uint) c_int {
3232 // Returns the number of leading 0-bits in x, starting at the most significant bit position.
3333 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
3434 @setRuntimeSafety(false);
35 return @bitCast(c_int, @as(c_uint, @clz(c_uint, val)));
35 return @bitCast(c_int, @as(c_uint, @clz(val)));
3636}
3737
3838pub inline fn __builtin_sqrt(val: f64) f64 {
lib/std/zig/system/NativeTargetInfo.zig+2-2
......@@ -852,13 +852,13 @@ pub const LdInfo = struct {
852852pub fn elfInt(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) {
853853 if (is_64) {
854854 if (need_bswap) {
855 return @byteSwap(@TypeOf(int_64), int_64);
855 return @byteSwap(int_64);
856856 } else {
857857 return int_64;
858858 }
859859 } else {
860860 if (need_bswap) {
861 return @byteSwap(@TypeOf(int_32), int_32);
861 return @byteSwap(int_32);
862862 } else {
863863 return int_32;
864864 }
src/AstGen.zig+5-13
......@@ -7733,11 +7733,11 @@ fn builtinCall(
77337733 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),
77347734 .has_field => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_field),
77357735
7736 .clz => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .clz),
7737 .ctz => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .ctz),
7738 .pop_count => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .pop_count),
7739 .byte_swap => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .byte_swap),
7740 .bit_reverse => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .bit_reverse),
7736 .clz => return bitBuiltin(gz, scope, rl, node, params[0], .clz),
7737 .ctz => return bitBuiltin(gz, scope, rl, node, params[0], .ctz),
7738 .pop_count => return bitBuiltin(gz, scope, rl, node, params[0], .pop_count),
7739 .byte_swap => return bitBuiltin(gz, scope, rl, node, params[0], .byte_swap),
7740 .bit_reverse => return bitBuiltin(gz, scope, rl, node, params[0], .bit_reverse),
77417741
77427742 .div_exact => return divBuiltin(gz, scope, rl, node, params[0], params[1], .div_exact),
77437743 .div_floor => return divBuiltin(gz, scope, rl, node, params[0], params[1], .div_floor),
......@@ -8100,17 +8100,9 @@ fn bitBuiltin(
81008100 scope: *Scope,
81018101 rl: ResultLoc,
81028102 node: Ast.Node.Index,
8103 int_type_node: Ast.Node.Index,
81048103 operand_node: Ast.Node.Index,
81058104 tag: Zir.Inst.Tag,
81068105) InnerError!Zir.Inst.Ref {
8107 // The accepted proposal https://github.com/ziglang/zig/issues/6835
8108 // tells us to remove the type parameter from these builtins. To stay
8109 // source-compatible with stage1, we still observe the parameter here,
8110 // but we do not encode it into the ZIR. To implement this proposal in
8111 // stage2, only AstGen code will need to be changed.
8112 _ = try typeExpr(gz, scope, int_type_node);
8113
81148106 const operand = try expr(gz, scope, .none, operand_node);
81158107 const result = try gz.addUnNode(tag, operand, node);
81168108 return rvalue(gz, rl, result, node);
src/BuiltinFn.zig+5-5
......@@ -250,14 +250,14 @@ pub const list = list: {
250250 "@byteSwap",
251251 .{
252252 .tag = .byte_swap,
253 .param_count = 2,
253 .param_count = 1,
254254 },
255255 },
256256 .{
257257 "@bitReverse",
258258 .{
259259 .tag = .bit_reverse,
260 .param_count = 2,
260 .param_count = 1,
261261 },
262262 },
263263 .{
......@@ -301,7 +301,7 @@ pub const list = list: {
301301 "@clz",
302302 .{
303303 .tag = .clz,
304 .param_count = 2,
304 .param_count = 1,
305305 },
306306 },
307307 .{
......@@ -336,7 +336,7 @@ pub const list = list: {
336336 "@ctz",
337337 .{
338338 .tag = .ctz,
339 .param_count = 2,
339 .param_count = 1,
340340 },
341341 },
342342 .{
......@@ -614,7 +614,7 @@ pub const list = list: {
614614 "@popCount",
615615 .{
616616 .tag = .pop_count,
617 .param_count = 2,
617 .param_count = 1,
618618 },
619619 },
620620 .{
src/Sema.zig+9-10
......@@ -13032,7 +13032,7 @@ fn analyzePtrArithmetic(
1303213032 // The resulting pointer is aligned to the lcd between the offset (an
1303313033 // arbitrary number) and the alignment factor (always a power of two,
1303413034 // non zero).
13035 const new_align = @as(u32, 1) << @intCast(u5, @ctz(u64, addend | ptr_info.@"align"));
13035 const new_align = @as(u32, 1) << @intCast(u5, @ctz(addend | ptr_info.@"align"));
1303613036
1303713037 break :t try Type.ptr(sema.arena, sema.mod, .{
1303813038 .pointee_type = ptr_info.pointee_type,
......@@ -17781,7 +17781,7 @@ fn zirBitCount(
1778117781) CompileError!Air.Inst.Ref {
1778217782 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1778317783 const src = inst_data.src();
17784 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
17784 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1778517785 const operand = try sema.resolveInst(inst_data.operand);
1778617786 const operand_ty = sema.typeOf(operand);
1778717787 _ = try checkIntOrVector(sema, block, operand, operand_src);
......@@ -17833,17 +17833,16 @@ fn zirBitCount(
1783317833fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1783417834 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1783517835 const src = inst_data.src();
17836 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
17837 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
17836 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1783817837 const operand = try sema.resolveInst(inst_data.operand);
1783917838 const operand_ty = sema.typeOf(operand);
17840 const scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
17839 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
1784117840 const target = sema.mod.getTarget();
1784217841 const bits = scalar_ty.intInfo(target).bits;
1784317842 if (bits % 8 != 0) {
1784417843 return sema.fail(
1784517844 block,
17846 ty_src,
17845 operand_src,
1784717846 "@byteSwap requires the number of bits to be evenly divisible by 8, but {} has {} bits",
1784817847 .{ scalar_ty.fmt(sema.mod), bits },
1784917848 );
......@@ -17854,7 +17853,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1785417853 }
1785517854
1785617855 switch (operand_ty.zigTypeTag()) {
17857 .Int, .ComptimeInt => {
17856 .Int => {
1785817857 const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
1785917858 if (val.isUndef()) return sema.addConstUndef(operand_ty);
1786017859 const result_val = try val.byteSwap(operand_ty, target, sema.arena);
......@@ -17892,7 +17891,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1789217891fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1789317892 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1789417893 const src = inst_data.src();
17895 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
17894 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1789617895 const operand = try sema.resolveInst(inst_data.operand);
1789717896 const operand_ty = sema.typeOf(operand);
1789817897 _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
......@@ -21656,7 +21655,7 @@ fn structFieldPtrByIndex(
2165621655 const elem_size_bits = ptr_ty_data.pointee_type.bitSize(target);
2165721656 if (elem_size_bytes * 8 == elem_size_bits) {
2165821657 const byte_offset = ptr_ty_data.bit_offset / 8;
21659 const new_align = @as(u32, 1) << @intCast(u5, @ctz(u64, byte_offset | parent_align));
21658 const new_align = @as(u32, 1) << @intCast(u5, @ctz(byte_offset | parent_align));
2166021659 ptr_ty_data.bit_offset = 0;
2166121660 ptr_ty_data.host_size = 0;
2166221661 ptr_ty_data.@"align" = new_align;
......@@ -30426,7 +30425,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3042630425 // The resulting pointer is aligned to the lcd between the offset (an
3042730426 // arbitrary number) and the alignment factor (always a power of two,
3042830427 // non zero).
30429 const new_align = @as(u32, 1) << @intCast(u5, @ctz(u64, addend | ptr_info.@"align"));
30428 const new_align = @as(u32, 1) << @intCast(u5, @ctz(addend | ptr_info.@"align"));
3043030429 break :a new_align;
3043130430 };
3043230431 return try Type.ptr(sema.arena, sema.mod, .{
src/arch/aarch64/Emit.zig+2-2
......@@ -277,7 +277,7 @@ fn instructionSize(emit: *Emit, inst: Mir.Inst.Index) usize {
277277 => return 2 * 4,
278278 .pop_regs, .push_regs => {
279279 const reg_list = emit.mir.instructions.items(.data)[inst].reg_list;
280 const number_of_regs = @popCount(u32, reg_list);
280 const number_of_regs = @popCount(reg_list);
281281 const number_of_insts = std.math.divCeil(u6, number_of_regs, 2) catch unreachable;
282282 return number_of_insts * 4;
283283 },
......@@ -1183,7 +1183,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void {
11831183 // sp must be aligned at all times, so we only use stp and ldp
11841184 // instructions for minimal instruction count. However, if we do
11851185 // not have an even number of registers, we use str and ldr
1186 const number_of_regs = @popCount(u32, reg_list);
1186 const number_of_regs = @popCount(reg_list);
11871187
11881188 switch (tag) {
11891189 .pop_regs => {
src/arch/wasm/Emit.zig+1-1
......@@ -343,7 +343,7 @@ fn emitMemArg(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void {
343343 try emit.code.append(@enumToInt(tag));
344344
345345 // wasm encodes alignment as power of 2, rather than natural alignment
346 const encoded_alignment = @ctz(u32, mem_arg.alignment);
346 const encoded_alignment = @ctz(mem_arg.alignment);
347347 try leb128.writeULEB128(emit.code.writer(), encoded_alignment);
348348 try leb128.writeULEB128(emit.code.writer(), mem_arg.offset);
349349}
src/link/MachO/Object.zig+1-1
......@@ -391,7 +391,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32)
391391 break :blk cc[start..][0..size];
392392 } else null;
393393 const atom_align = if (addr > 0)
394 math.min(@ctz(u64, addr), sect.@"align")
394 math.min(@ctz(addr), sect.@"align")
395395 else
396396 sect.@"align";
397397 const atom = try self.createAtomFromSubsection(
src/link/Wasm.zig+2-2
......@@ -3135,12 +3135,12 @@ fn emitSegmentInfo(self: *Wasm, file: fs.File, arena: Allocator) !void {
31353135 for (self.segment_info.items) |segment_info| {
31363136 log.debug("Emit segment: {s} align({d}) flags({b})", .{
31373137 segment_info.name,
3138 @ctz(u32, segment_info.alignment),
3138 @ctz(segment_info.alignment),
31393139 segment_info.flags,
31403140 });
31413141 try leb.writeULEB128(writer, @intCast(u32, segment_info.name.len));
31423142 try writer.writeAll(segment_info.name);
3143 try leb.writeULEB128(writer, @ctz(u32, segment_info.alignment));
3143 try leb.writeULEB128(writer, @ctz(segment_info.alignment));
31443144 try leb.writeULEB128(writer, segment_info.flags);
31453145 }
31463146
src/stage1/astgen.cpp+2-4
......@@ -5374,10 +5374,8 @@ static Stage1ZirInst *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, Ast
53745374 if (arg0_value == ag->codegen->invalid_inst_src)
53755375 return arg0_value;
53765376
5377 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5378 Stage1ZirInst *arg1_value = astgen_node(ag, arg1_node, scope);
5379 if (arg1_value == ag->codegen->invalid_inst_src)
5380 return arg1_value;
5377 Stage1ZirInst *arg1_value = arg0_value;
5378 arg0_value = ir_build_typeof_1(ag, scope, arg0_node, arg1_value);
53815379
53825380 Stage1ZirInst *result;
53835381 switch (builtin_fn->id) {
src/stage1/codegen.cpp+5-5
......@@ -9792,11 +9792,11 @@ static void define_builtin_fns(CodeGen *g) {
97929792 create_builtin_fn(g, BuiltinFnIdCInclude, "cInclude", 1);
97939793 create_builtin_fn(g, BuiltinFnIdCDefine, "cDefine", 2);
97949794 create_builtin_fn(g, BuiltinFnIdCUndef, "cUndef", 1);
9795 create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 2);
9796 create_builtin_fn(g, BuiltinFnIdClz, "clz", 2);
9797 create_builtin_fn(g, BuiltinFnIdPopCount, "popCount", 2);
9798 create_builtin_fn(g, BuiltinFnIdBswap, "byteSwap", 2);
9799 create_builtin_fn(g, BuiltinFnIdBitReverse, "bitReverse", 2);
9795 create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 1);
9796 create_builtin_fn(g, BuiltinFnIdClz, "clz", 1);
9797 create_builtin_fn(g, BuiltinFnIdPopCount, "popCount", 1);
9798 create_builtin_fn(g, BuiltinFnIdBswap, "byteSwap", 1);
9799 create_builtin_fn(g, BuiltinFnIdBitReverse, "bitReverse", 1);
98009800 create_builtin_fn(g, BuiltinFnIdImport, "import", 1);
98019801 create_builtin_fn(g, BuiltinFnIdCImport, "cImport", 1);
98029802 create_builtin_fn(g, BuiltinFnIdErrName, "errorName", 1);
src/value.zig+5-5
......@@ -1582,7 +1582,7 @@ pub const Value = extern union {
15821582 .one, .bool_true => return ty_bits - 1,
15831583
15841584 .int_u64 => {
1585 const big = @clz(u64, val.castTag(.int_u64).?.data);
1585 const big = @clz(val.castTag(.int_u64).?.data);
15861586 return big + ty_bits - 64;
15871587 },
15881588 .int_i64 => {
......@@ -1599,7 +1599,7 @@ pub const Value = extern union {
15991599 while (i != 0) {
16001600 i -= 1;
16011601 const limb = bigint.limbs[i];
1602 const this_limb_lz = @clz(std.math.big.Limb, limb);
1602 const this_limb_lz = @clz(limb);
16031603 total_limb_lz += this_limb_lz;
16041604 if (this_limb_lz != bits_per_limb) break;
16051605 }
......@@ -1626,7 +1626,7 @@ pub const Value = extern union {
16261626 .one, .bool_true => return 0,
16271627
16281628 .int_u64 => {
1629 const big = @ctz(u64, val.castTag(.int_u64).?.data);
1629 const big = @ctz(val.castTag(.int_u64).?.data);
16301630 return if (big == 64) ty_bits else big;
16311631 },
16321632 .int_i64 => {
......@@ -1638,7 +1638,7 @@ pub const Value = extern union {
16381638 // Limbs are stored in little-endian order.
16391639 var result: u64 = 0;
16401640 for (bigint.limbs) |limb| {
1641 const limb_tz = @ctz(std.math.big.Limb, limb);
1641 const limb_tz = @ctz(limb);
16421642 result += limb_tz;
16431643 if (limb_tz != @sizeOf(std.math.big.Limb) * 8) break;
16441644 }
......@@ -1663,7 +1663,7 @@ pub const Value = extern union {
16631663 .zero, .bool_false => return 0,
16641664 .one, .bool_true => return 1,
16651665
1666 .int_u64 => return @popCount(u64, val.castTag(.int_u64).?.data),
1666 .int_u64 => return @popCount(val.castTag(.int_u64).?.data),
16671667
16681668 else => {
16691669 const info = ty.intInfo(target);
test/behavior/bitreverse.zig+47-47
......@@ -8,7 +8,7 @@ test "@bitReverse large exotic integer" {
88 // Currently failing on stage1 for big-endian targets
99 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
1010
11 try expect(@bitReverse(u95, @as(u95, 0x123456789abcdef111213141)) == 0x4146424447bd9eac8f351624);
11 try expect(@bitReverse(@as(u95, 0x123456789abcdef111213141)) == 0x4146424447bd9eac8f351624);
1212}
1313
1414test "@bitReverse" {
......@@ -23,74 +23,74 @@ test "@bitReverse" {
2323
2424fn testBitReverse() !void {
2525 // using comptime_ints, unsigned
26 try expect(@bitReverse(u0, @as(u0, 0)) == 0);
27 try expect(@bitReverse(u5, @as(u5, 0x12)) == 0x9);
28 try expect(@bitReverse(u8, @as(u8, 0x12)) == 0x48);
29 try expect(@bitReverse(u16, @as(u16, 0x1234)) == 0x2c48);
30 try expect(@bitReverse(u24, @as(u24, 0x123456)) == 0x6a2c48);
31 try expect(@bitReverse(u32, @as(u32, 0x12345678)) == 0x1e6a2c48);
32 try expect(@bitReverse(u40, @as(u40, 0x123456789a)) == 0x591e6a2c48);
33 try expect(@bitReverse(u48, @as(u48, 0x123456789abc)) == 0x3d591e6a2c48);
34 try expect(@bitReverse(u56, @as(u56, 0x123456789abcde)) == 0x7b3d591e6a2c48);
35 try expect(@bitReverse(u64, @as(u64, 0x123456789abcdef1)) == 0x8f7b3d591e6a2c48);
36 try expect(@bitReverse(u96, @as(u96, 0x123456789abcdef111213141)) == 0x828c84888f7b3d591e6a2c48);
37 try expect(@bitReverse(u128, @as(u128, 0x123456789abcdef11121314151617181)) == 0x818e868a828c84888f7b3d591e6a2c48);
26 try expect(@bitReverse(@as(u0, 0)) == 0);
27 try expect(@bitReverse(@as(u5, 0x12)) == 0x9);
28 try expect(@bitReverse(@as(u8, 0x12)) == 0x48);
29 try expect(@bitReverse(@as(u16, 0x1234)) == 0x2c48);
30 try expect(@bitReverse(@as(u24, 0x123456)) == 0x6a2c48);
31 try expect(@bitReverse(@as(u32, 0x12345678)) == 0x1e6a2c48);
32 try expect(@bitReverse(@as(u40, 0x123456789a)) == 0x591e6a2c48);
33 try expect(@bitReverse(@as(u48, 0x123456789abc)) == 0x3d591e6a2c48);
34 try expect(@bitReverse(@as(u56, 0x123456789abcde)) == 0x7b3d591e6a2c48);
35 try expect(@bitReverse(@as(u64, 0x123456789abcdef1)) == 0x8f7b3d591e6a2c48);
36 try expect(@bitReverse(@as(u96, 0x123456789abcdef111213141)) == 0x828c84888f7b3d591e6a2c48);
37 try expect(@bitReverse(@as(u128, 0x123456789abcdef11121314151617181)) == 0x818e868a828c84888f7b3d591e6a2c48);
3838
3939 // using runtime uints, unsigned
4040 var num0: u0 = 0;
41 try expect(@bitReverse(u0, num0) == 0);
41 try expect(@bitReverse(num0) == 0);
4242 var num5: u5 = 0x12;
43 try expect(@bitReverse(u5, num5) == 0x9);
43 try expect(@bitReverse(num5) == 0x9);
4444 var num8: u8 = 0x12;
45 try expect(@bitReverse(u8, num8) == 0x48);
45 try expect(@bitReverse(num8) == 0x48);
4646 var num16: u16 = 0x1234;
47 try expect(@bitReverse(u16, num16) == 0x2c48);
47 try expect(@bitReverse(num16) == 0x2c48);
4848 var num24: u24 = 0x123456;
49 try expect(@bitReverse(u24, num24) == 0x6a2c48);
49 try expect(@bitReverse(num24) == 0x6a2c48);
5050 var num32: u32 = 0x12345678;
51 try expect(@bitReverse(u32, num32) == 0x1e6a2c48);
51 try expect(@bitReverse(num32) == 0x1e6a2c48);
5252 var num40: u40 = 0x123456789a;
53 try expect(@bitReverse(u40, num40) == 0x591e6a2c48);
53 try expect(@bitReverse(num40) == 0x591e6a2c48);
5454 var num48: u48 = 0x123456789abc;
55 try expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);
55 try expect(@bitReverse(num48) == 0x3d591e6a2c48);
5656 var num56: u56 = 0x123456789abcde;
57 try expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);
57 try expect(@bitReverse(num56) == 0x7b3d591e6a2c48);
5858 var num64: u64 = 0x123456789abcdef1;
59 try expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);
59 try expect(@bitReverse(num64) == 0x8f7b3d591e6a2c48);
6060 var num128: u128 = 0x123456789abcdef11121314151617181;
61 try expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
61 try expect(@bitReverse(num128) == 0x818e868a828c84888f7b3d591e6a2c48);
6262
6363 // using comptime_ints, signed, positive
64 try expect(@bitReverse(u8, @as(u8, 0)) == 0);
65 try expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
66 try expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
67 try expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
68 try expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x12345f))) == @bitCast(i24, @as(u24, 0xfa2c48)));
69 try expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0xf23456))) == @bitCast(i24, @as(u24, 0x6a2c4f)));
70 try expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
71 try expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0xf2345678))) == @bitCast(i32, @as(u32, 0x1e6a2c4f)));
72 try expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x1234567f))) == @bitCast(i32, @as(u32, 0xfe6a2c48)));
73 try expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
74 try expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
75 try expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
76 try expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
77 try expect(@bitReverse(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141))) == @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48)));
78 try expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
64 try expect(@bitReverse(@as(u8, 0)) == 0);
65 try expect(@bitReverse(@bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
66 try expect(@bitReverse(@bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
67 try expect(@bitReverse(@bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
68 try expect(@bitReverse(@bitCast(i24, @as(u24, 0x12345f))) == @bitCast(i24, @as(u24, 0xfa2c48)));
69 try expect(@bitReverse(@bitCast(i24, @as(u24, 0xf23456))) == @bitCast(i24, @as(u24, 0x6a2c4f)));
70 try expect(@bitReverse(@bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
71 try expect(@bitReverse(@bitCast(i32, @as(u32, 0xf2345678))) == @bitCast(i32, @as(u32, 0x1e6a2c4f)));
72 try expect(@bitReverse(@bitCast(i32, @as(u32, 0x1234567f))) == @bitCast(i32, @as(u32, 0xfe6a2c48)));
73 try expect(@bitReverse(@bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
74 try expect(@bitReverse(@bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
75 try expect(@bitReverse(@bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
76 try expect(@bitReverse(@bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
77 try expect(@bitReverse(@bitCast(i96, @as(u96, 0x123456789abcdef111213141))) == @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48)));
78 try expect(@bitReverse(@bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
7979
8080 // using signed, negative. Compare to runtime ints returned from llvm.
8181 var neg8: i8 = -18;
82 try expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
82 try expect(@bitReverse(@as(i8, -18)) == @bitReverse(neg8));
8383 var neg16: i16 = -32694;
84 try expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
84 try expect(@bitReverse(@as(i16, -32694)) == @bitReverse(neg16));
8585 var neg24: i24 = -6773785;
86 try expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
86 try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24));
8787 var neg32: i32 = -16773785;
88 try expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
88 try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32));
8989}
9090
9191fn vector8() !void {
9292 var v = @Vector(2, u8){ 0x12, 0x23 };
93 var result = @bitReverse(u8, v);
93 var result = @bitReverse(v);
9494 try expect(result[0] == 0x48);
9595 try expect(result[1] == 0xc4);
9696}
......@@ -109,7 +109,7 @@ test "bitReverse vectors u8" {
109109
110110fn vector16() !void {
111111 var v = @Vector(2, u16){ 0x1234, 0x2345 };
112 var result = @bitReverse(u16, v);
112 var result = @bitReverse(v);
113113 try expect(result[0] == 0x2c48);
114114 try expect(result[1] == 0xa2c4);
115115}
......@@ -128,7 +128,7 @@ test "bitReverse vectors u16" {
128128
129129fn vector24() !void {
130130 var v = @Vector(2, u24){ 0x123456, 0x234567 };
131 var result = @bitReverse(u24, v);
131 var result = @bitReverse(v);
132132 try expect(result[0] == 0x6a2c48);
133133 try expect(result[1] == 0xe6a2c4);
134134}
......@@ -147,7 +147,7 @@ test "bitReverse vectors u24" {
147147
148148fn vector0() !void {
149149 var v = @Vector(2, u0){ 0, 0 };
150 var result = @bitReverse(u0, v);
150 var result = @bitReverse(v);
151151 try expect(result[0] == 0);
152152 try expect(result[1] == 0);
153153}
test/behavior/bugs/10147.zig+3-2
......@@ -2,6 +2,7 @@ const builtin = @import("builtin");
22const std = @import("std");
33
44test "uses correct LLVM builtin" {
5 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
56 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
67 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
78 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
......@@ -12,8 +13,8 @@ test "uses correct LLVM builtin" {
1213 var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };
1314 // The stage1 compiler used to call the same builtin function for both
1415 // scalar and vector inputs, causing the LLVM module verification to fail.
15 var a = @clz(u32, x);
16 var b = @clz(u32, y);
16 var a = @clz(x);
17 var b = @clz(y);
1718 try std.testing.expectEqual(@as(u6, 31), a);
1819 try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
1920}
test/behavior/bugs/2114.zig+1-1
......@@ -4,7 +4,7 @@ const expect = std.testing.expect;
44const math = std.math;
55
66fn ctz(x: anytype) usize {
7 return @ctz(@TypeOf(x), x);
7 return @ctz(x);
88}
99
1010test "fixed" {
test/behavior/byteswap.zig+10-5
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const expect = std.testing.expect;
44
55test "@byteSwap integers" {
6 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
67 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
78 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
89 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
......@@ -46,7 +47,7 @@ test "@byteSwap integers" {
4647 );
4748 }
4849 fn t(comptime I: type, input: I, expected_output: I) !void {
49 try std.testing.expect(expected_output == @byteSwap(I, input));
50 try std.testing.expect(expected_output == @byteSwap(input));
5051 }
5152 };
5253 comptime try ByteSwapIntTest.run();
......@@ -55,12 +56,13 @@ test "@byteSwap integers" {
5556
5657fn vector8() !void {
5758 var v = @Vector(2, u8){ 0x12, 0x13 };
58 var result = @byteSwap(u8, v);
59 var result = @byteSwap(v);
5960 try expect(result[0] == 0x12);
6061 try expect(result[1] == 0x13);
6162}
6263
6364test "@byteSwap vectors u8" {
65 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
6466 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
6567 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
6668 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
......@@ -73,12 +75,13 @@ test "@byteSwap vectors u8" {
7375
7476fn vector16() !void {
7577 var v = @Vector(2, u16){ 0x1234, 0x2345 };
76 var result = @byteSwap(u16, v);
78 var result = @byteSwap(v);
7779 try expect(result[0] == 0x3412);
7880 try expect(result[1] == 0x4523);
7981}
8082
8183test "@byteSwap vectors u16" {
84 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
8285 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
8386 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
8487 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
......@@ -91,12 +94,13 @@ test "@byteSwap vectors u16" {
9194
9295fn vector24() !void {
9396 var v = @Vector(2, u24){ 0x123456, 0x234567 };
94 var result = @byteSwap(u24, v);
97 var result = @byteSwap(v);
9598 try expect(result[0] == 0x563412);
9699 try expect(result[1] == 0x674523);
97100}
98101
99102test "@byteSwap vectors u24" {
103 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
100104 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
101105 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
102106 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
......@@ -109,12 +113,13 @@ test "@byteSwap vectors u24" {
109113
110114fn vector0() !void {
111115 var v = @Vector(2, u0){ 0, 0 };
112 var result = @byteSwap(u0, v);
116 var result = @byteSwap(v);
113117 try expect(result[0] == 0);
114118 try expect(result[1] == 0);
115119}
116120
117121test "@byteSwap vectors u0" {
122 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
118123 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
119124 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
120125 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
test/behavior/comptime_memory.zig+1-1
......@@ -82,7 +82,7 @@ test "type pun value and struct" {
8282}
8383
8484fn bigToNativeEndian(comptime T: type, v: T) T {
85 return if (endian == .Big) v else @byteSwap(T, v);
85 return if (endian == .Big) v else @byteSwap(v);
8686}
8787test "type pun endianness" {
8888 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
test/behavior/math.zig+7-7
......@@ -90,10 +90,11 @@ fn testClzBigInts() !void {
9090}
9191
9292fn testOneClz(comptime T: type, x: T) u32 {
93 return @clz(T, x);
93 return @clz(x);
9494}
9595
9696test "@clz vectors" {
97 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
9798 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
9899 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
99100 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
......@@ -120,7 +121,7 @@ fn testOneClzVector(
120121 x: @Vector(len, T),
121122 expected: @Vector(len, u32),
122123) !void {
123 try expectVectorsEqual(@clz(T, x), expected);
124 try expectVectorsEqual(@clz(x), expected);
124125}
125126
126127fn expectVectorsEqual(a: anytype, b: anytype) !void {
......@@ -151,19 +152,18 @@ fn testCtz() !void {
151152}
152153
153154fn testOneCtz(comptime T: type, x: T) u32 {
154 return @ctz(T, x);
155 return @ctz(x);
155156}
156157
157158test "@ctz vectors" {
159 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
158160 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
159161 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
160162 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
161163 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
162164 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
163165
164 if ((builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) and
165 builtin.cpu.arch == .aarch64)
166 {
166 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
167167 // This regressed with LLVM 14:
168168 // https://github.com/ziglang/zig/issues/12013
169169 return error.SkipZigTest;
......@@ -187,7 +187,7 @@ fn testOneCtzVector(
187187 x: @Vector(len, T),
188188 expected: @Vector(len, u32),
189189) !void {
190 try expectVectorsEqual(@ctz(T, x), expected);
190 try expectVectorsEqual(@ctz(x), expected);
191191}
192192
193193test "const number literal" {
test/behavior/popcount.zig+15-14
......@@ -18,53 +18,54 @@ test "@popCount 128bit integer" {
1818 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1919
2020 comptime {
21 try expect(@popCount(u128, @as(u128, 0b11111111000110001100010000100001000011000011100101010001)) == 24);
22 try expect(@popCount(i128, @as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24);
21 try expect(@popCount(@as(u128, 0b11111111000110001100010000100001000011000011100101010001)) == 24);
22 try expect(@popCount(@as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24);
2323 }
2424
2525 {
2626 var x: u128 = 0b11111111000110001100010000100001000011000011100101010001;
27 try expect(@popCount(u128, x) == 24);
27 try expect(@popCount(x) == 24);
2828 }
2929
30 try expect(@popCount(i128, @as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24);
30 try expect(@popCount(@as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24);
3131}
3232
3333fn testPopCountIntegers() !void {
3434 {
3535 var x: u32 = 0xffffffff;
36 try expect(@popCount(u32, x) == 32);
36 try expect(@popCount(x) == 32);
3737 }
3838 {
3939 var x: u5 = 0x1f;
40 try expect(@popCount(u5, x) == 5);
40 try expect(@popCount(x) == 5);
4141 }
4242 {
4343 var x: u32 = 0xaa;
44 try expect(@popCount(u32, x) == 4);
44 try expect(@popCount(x) == 4);
4545 }
4646 {
4747 var x: u32 = 0xaaaaaaaa;
48 try expect(@popCount(u32, x) == 16);
48 try expect(@popCount(x) == 16);
4949 }
5050 {
5151 var x: u32 = 0xaaaaaaaa;
52 try expect(@popCount(u32, x) == 16);
52 try expect(@popCount(x) == 16);
5353 }
5454 {
5555 var x: i16 = -1;
56 try expect(@popCount(i16, x) == 16);
56 try expect(@popCount(x) == 16);
5757 }
5858 {
5959 var x: i8 = -120;
60 try expect(@popCount(i8, x) == 2);
60 try expect(@popCount(x) == 2);
6161 }
6262 comptime {
63 try expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
63 try expect(@popCount(@bitCast(u8, @as(i8, -120))) == 2);
6464 }
6565}
6666
6767test "@popCount vectors" {
68 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
6869 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
6970 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
7071 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
......@@ -79,13 +80,13 @@ fn testPopCountVectors() !void {
7980 {
8081 var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8;
8182 const expected = [1]u6{32} ** 8;
82 const result: [8]u6 = @popCount(u32, x);
83 const result: [8]u6 = @popCount(x);
8384 try expect(std.mem.eql(u6, &expected, &result));
8485 }
8586 {
8687 var x: @Vector(8, i16) = [1]i16{-1} ** 8;
8788 const expected = [1]u5{16} ** 8;
88 const result: [8]u5 = @popCount(i16, x);
89 const result: [8]u5 = @popCount(x);
8990 try expect(std.mem.eql(u5, &expected, &result));
9091 }
9192}
test/cases/compile_errors/errors_in_for_loop_bodies_are_propagated.zig+2-2
......@@ -1,10 +1,10 @@
11pub export fn entry() void {
22 var arr: [100]u8 = undefined;
3 for (arr) |bits| _ = @popCount(bits);
3 for (arr) |bits| _ = @popCount(u8, bits);
44}
55
66// error
77// backend=stage2
88// target=native
99//
10// :3:26: error: expected 2 arguments, found 1
10// :3:26: error: expected 1 argument, found 2
test/cases/compile_errors/popCount-non-integer.zig+2-2
......@@ -1,9 +1,9 @@
11export fn entry(x: f32) u32 {
2 return @popCount(f32, x);
2 return @popCount(x);
33}
44
55// error
66// backend=stage2
77// target=native
88//
9// :2:27: error: expected integer or vector, found 'f32'
9// :2:22: error: expected integer or vector, found 'f32'
tools/gen_spirv_spec.zig+2-2
......@@ -299,11 +299,11 @@ fn renderBitEnum(
299299 for (enumerants) |enumerant, i| {
300300 if (enumerant.value != .bitflag) return error.InvalidRegistry;
301301 const value = try parseHexInt(enumerant.value.bitflag);
302 if (@popCount(u32, value) == 0) {
302 if (@popCount(value) == 0) {
303303 continue; // Skip 'none' items
304304 }
305305
306 std.debug.assert(@popCount(u32, value) == 1);
306 std.debug.assert(@popCount(value) == 1);
307307
308308 var bitpos = std.math.log2_int(u32, value);
309309 if (flags_by_bitpos[bitpos]) |*existing| {
tools/gen_stubs.zig+1-1
......@@ -389,7 +389,7 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian)
389389 const S = struct {
390390 fn endianSwap(x: anytype) @TypeOf(x) {
391391 if (endian != native_endian) {
392 return @byteSwap(@TypeOf(x), x);
392 return @byteSwap(x);
393393 } else {
394394 return x;
395395 }