| author | |
| committer | |
| log | 62ff8871ed9c8c4e46d8acd1d227ed3fb802be7f |
| tree | b5bdd3f092ebc0b7e9c260df798b7019f69cdae7 |
| parent | 6c020cdb767192757b6c4b43e2f14c5394760431 |
Closes #12529
Closes #12511
Closes #683555 files changed, 264 insertions(+), 268 deletions(-)
doc/langref.html.in+10-10| ... | @@ -8031,8 +8031,8 @@ fn func(y: *i32) void { | ... | @@ -8031,8 +8031,8 @@ fn func(y: *i32) void { |
| 8031 | {#header_close#} | 8031 | {#header_close#} |
| 8032 | 8032 | ||
| 8033 | {#header_open|@byteSwap#} | 8033 | {#header_open|@byteSwap#} |
| 8034 | <pre>{#syntax#}@byteSwap(comptime T: type, operand: T) T{#endsyntax#}</pre> | 8034 | <pre>{#syntax#}@byteSwap(operand: anytype) T{#endsyntax#}</pre> |
| 8035 | <p>{#syntax#}T{#endsyntax#} must be an integer type with bit count evenly divisible by 8.</p> | 8035 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type with bit count evenly divisible by 8.</p> |
| 8036 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8036 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8037 | <p> | 8037 | <p> |
| 8038 | Swaps the byte order of the integer. This converts a big endian integer to a little endian integer, | 8038 | 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 { | ... | @@ -8049,8 +8049,8 @@ fn func(y: *i32) void { |
| 8049 | {#header_close#} | 8049 | {#header_close#} |
| 8050 | 8050 | ||
| 8051 | {#header_open|@bitReverse#} | 8051 | {#header_open|@bitReverse#} |
| 8052 | <pre>{#syntax#}@bitReverse(comptime T: type, integer: T) T{#endsyntax#}</pre> | 8052 | <pre>{#syntax#}@bitReverse(integer: anytype) T{#endsyntax#}</pre> |
| 8053 | <p>{#syntax#}T{#endsyntax#} accepts any integer type.</p> | 8053 | <p>{#syntax#}@TypeOf(anytype){#endsyntax#} accepts any integer type or integer vector type.</p> |
| 8054 | <p> | 8054 | <p> |
| 8055 | Reverses the bitpattern of an integer value, including the sign bit if applicable. | 8055 | Reverses the bitpattern of an integer value, including the sign bit if applicable. |
| 8056 | </p> | 8056 | </p> |
| ... | @@ -8189,8 +8189,8 @@ pub const CallOptions = struct { | ... | @@ -8189,8 +8189,8 @@ pub const CallOptions = struct { |
| 8189 | {#header_close#} | 8189 | {#header_close#} |
| 8190 | 8190 | ||
| 8191 | {#header_open|@clz#} | 8191 | {#header_open|@clz#} |
| 8192 | <pre>{#syntax#}@clz(comptime T: type, operand: T){#endsyntax#}</pre> | 8192 | <pre>{#syntax#}@clz(operand: anytype){#endsyntax#}</pre> |
| 8193 | <p>{#syntax#}T{#endsyntax#} must be an integer type.</p> | 8193 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p> |
| 8194 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8194 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8195 | <p> | 8195 | <p> |
| 8196 | This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer. | 8196 | This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer. |
| ... | @@ -8335,8 +8335,8 @@ test "main" { | ... | @@ -8335,8 +8335,8 @@ test "main" { |
| 8335 | {#header_close#} | 8335 | {#header_close#} |
| 8336 | 8336 | ||
| 8337 | {#header_open|@ctz#} | 8337 | {#header_open|@ctz#} |
| 8338 | <pre>{#syntax#}@ctz(comptime T: type, operand: T){#endsyntax#}</pre> | 8338 | <pre>{#syntax#}@ctz(operand: anytype){#endsyntax#}</pre> |
| 8339 | <p>{#syntax#}T{#endsyntax#} must be an integer type.</p> | 8339 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p> |
| 8340 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8340 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8341 | <p> | 8341 | <p> |
| 8342 | This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer. | 8342 | This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer. |
| ... | @@ -8972,8 +8972,8 @@ test "@wasmMemoryGrow" { | ... | @@ -8972,8 +8972,8 @@ test "@wasmMemoryGrow" { |
| 8972 | {#header_close#} | 8972 | {#header_close#} |
| 8973 | 8973 | ||
| 8974 | {#header_open|@popCount#} | 8974 | {#header_open|@popCount#} |
| 8975 | <pre>{#syntax#}@popCount(comptime T: type, operand: T){#endsyntax#}</pre> | 8975 | <pre>{#syntax#}@popCount(operand: anytype){#endsyntax#}</pre> |
| 8976 | <p>{#syntax#}T{#endsyntax#} must be an integer type.</p> | 8976 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p> |
| 8977 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8977 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8978 | <p>Counts the number of bits set in an integer.</p> | 8978 | <p>Counts the number of bits set in an integer.</p> |
| 8979 | <p> | 8979 | <p> |
lib/compiler_rt/addf3.zig+2-2| ... | @@ -9,7 +9,7 @@ const normalize = common.normalize; | ... | @@ -9,7 +9,7 @@ const normalize = common.normalize; |
| 9 | pub inline fn addf3(comptime T: type, a: T, b: T) T { | 9 | pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 10 | const bits = @typeInfo(T).Float.bits; | 10 | const bits = @typeInfo(T).Float.bits; |
| 11 | const Z = std.meta.Int(.unsigned, bits); | 11 | 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)); |
| 13 | 13 | ||
| 14 | const typeWidth = bits; | 14 | const typeWidth = bits; |
| 15 | const significandBits = math.floatMantissaBits(T); | 15 | const significandBits = math.floatMantissaBits(T); |
| ... | @@ -118,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { | ... | @@ -118,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { |
| 118 | // If partial cancellation occured, we need to left-shift the result | 118 | // If partial cancellation occured, we need to left-shift the result |
| 119 | // and adjust the exponent: | 119 | // and adjust the exponent: |
| 120 | if (aSignificand < integerBit << 3) { | 120 | 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)); |
| 122 | aSignificand <<= @intCast(S, shift); | 122 | aSignificand <<= @intCast(S, shift); |
| 123 | aExponent -= shift; | 123 | aExponent -= shift; |
| 124 | } | 124 | } |
lib/compiler_rt/common.zig+1-1| ... | @@ -192,7 +192,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn | ... | @@ -192,7 +192,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn |
| 192 | const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); | 192 | const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); |
| 193 | const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T); | 193 | const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T); |
| 194 | 194 | ||
| 195 | const shift = @clz(Z, significand.*) - @clz(Z, integerBit); | 195 | const shift = @clz(significand.*) - @clz(integerBit); |
| 196 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); | 196 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
| 197 | return @as(i32, 1) - shift; | 197 | return @as(i32, 1) - shift; |
| 198 | } | 198 | } |
lib/compiler_rt/extendf.zig+4-4| ... | @@ -56,8 +56,8 @@ pub inline fn extendf( | ... | @@ -56,8 +56,8 @@ pub inline fn extendf( |
| 56 | // a is denormal. | 56 | // a is denormal. |
| 57 | // renormalize the significand and clear the leading bit, then insert | 57 | // renormalize the significand and clear the leading bit, then insert |
| 58 | // the correct adjusted exponent in the destination type. | 58 | // the correct adjusted exponent in the destination type. |
| 59 | const scale: u32 = @clz(src_rep_t, aAbs) - | 59 | const scale: u32 = @clz(aAbs) - |
| 60 | @clz(src_rep_t, @as(src_rep_t, srcMinNormal)); | 60 | @clz(@as(src_rep_t, srcMinNormal)); |
| 61 | absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); | 61 | absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); |
| 62 | absResult ^= dstMinNormal; | 62 | absResult ^= dstMinNormal; |
| 63 | const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; | 63 | 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 | ... | @@ -119,8 +119,8 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI |
| 119 | // a is denormal. | 119 | // a is denormal. |
| 120 | // renormalize the significand and clear the leading bit, then insert | 120 | // renormalize the significand and clear the leading bit, then insert |
| 121 | // the correct adjusted exponent in the destination type. | 121 | // the correct adjusted exponent in the destination type. |
| 122 | const scale: u16 = @clz(src_rep_t, a_abs) - | 122 | const scale: u16 = @clz(a_abs) - |
| 123 | @clz(src_rep_t, @as(src_rep_t, src_min_normal)); | 123 | @clz(@as(src_rep_t, src_min_normal)); |
| 124 | 124 | ||
| 125 | dst.fraction = @as(u64, a_abs) << @intCast(u6, dst_sig_bits - src_sig_bits + scale); | 125 | dst.fraction = @as(u64, a_abs) << @intCast(u6, dst_sig_bits - src_sig_bits + scale); |
| 126 | dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers | 126 | 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 { | ... | @@ -38,7 +38,7 @@ fn __extendxftf2(a: f80) callconv(.C) f128 { |
| 38 | // a is denormal | 38 | // a is denormal |
| 39 | // renormalize the significand and clear the leading bit and integer part, | 39 | // renormalize the significand and clear the leading bit and integer part, |
| 40 | // then insert the correct adjusted exponent in the destination type. | 40 | // 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); |
| 42 | abs_result = @as(u128, a_rep.fraction) << @intCast(u7, dst_sig_bits - src_sig_bits + scale + 1); | 42 | abs_result = @as(u128, a_rep.fraction) << @intCast(u7, dst_sig_bits - src_sig_bits + scale + 1); |
| 43 | abs_result ^= dst_min_normal; | 43 | abs_result ^= dst_min_normal; |
| 44 | abs_result |= @as(u128, scale + 1) << dst_sig_bits; | 44 | 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 { | ... | @@ -243,7 +243,7 @@ inline fn div_u32(n: u32, d: u32) u32 { |
| 243 | // special cases | 243 | // special cases |
| 244 | if (d == 0) return 0; // ?! | 244 | if (d == 0) return 0; // ?! |
| 245 | if (n == 0) return 0; | 245 | 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))); |
| 247 | // 0 <= sr <= n_uword_bits - 1 or sr large | 247 | // 0 <= sr <= n_uword_bits - 1 or sr large |
| 248 | if (sr > n_uword_bits - 1) { | 248 | if (sr > n_uword_bits - 1) { |
| 249 | // d > r | 249 | // d > r |
lib/compiler_rt/int_to_float.zig+2-2| ... | @@ -23,7 +23,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T { | ... | @@ -23,7 +23,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T { |
| 23 | var result: uT = sign_bit; | 23 | var result: uT = sign_bit; |
| 24 | 24 | ||
| 25 | // Compute significand | 25 | // Compute significand |
| 26 | var exp = int_bits - @clz(Z, abs_val) - 1; | 26 | var exp = int_bits - @clz(abs_val) - 1; |
| 27 | if (int_bits <= fractional_bits or exp <= fractional_bits) { | 27 | if (int_bits <= fractional_bits or exp <= fractional_bits) { |
| 28 | const shift_amt = fractional_bits - @intCast(math.Log2Int(uT), exp); | 28 | const shift_amt = fractional_bits - @intCast(math.Log2Int(uT), exp); |
| 29 | 29 | ||
| ... | @@ -32,7 +32,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T { | ... | @@ -32,7 +32,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T { |
| 32 | result ^= implicit_bit; // Remove implicit integer bit | 32 | result ^= implicit_bit; // Remove implicit integer bit |
| 33 | } else { | 33 | } else { |
| 34 | var shift_amt = @intCast(math.Log2Int(Z), exp - fractional_bits); | 34 | 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; |
| 36 | 36 | ||
| 37 | // Shift down result and remove implicit integer bit | 37 | // Shift down result and remove implicit integer bit |
| 38 | result = @intCast(uT, (abs_val >> (shift_amt - 1))) ^ (implicit_bit << 1); | 38 | 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 { | ... | @@ -186,7 +186,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 { |
| 186 | const Z = PowerOfTwoSignificandZ(T); | 186 | const Z = PowerOfTwoSignificandZ(T); |
| 187 | const integerBit = @as(Z, 1) << math.floatFractionalBits(T); | 187 | const integerBit = @as(Z, 1) << math.floatFractionalBits(T); |
| 188 | 188 | ||
| 189 | const shift = @clz(Z, significand.*) - @clz(Z, integerBit); | 189 | const shift = @clz(significand.*) - @clz(integerBit); |
| 190 | significand.* <<= @intCast(math.Log2Int(Z), shift); | 190 | significand.* <<= @intCast(math.Log2Int(Z), shift); |
| 191 | return @as(i32, 1) - shift; | 191 | return @as(i32, 1) - shift; |
| 192 | } | 192 | } |
lib/compiler_rt/udivmod.zig+5-5| ... | @@ -75,12 +75,12 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: | ... | @@ -75,12 +75,12 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 75 | r[high] = n[high] & (d[high] - 1); | 75 | r[high] = n[high] & (d[high] - 1); |
| 76 | rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421 | 76 | rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421 |
| 77 | } | 77 | } |
| 78 | return n[high] >> @intCast(Log2SingleInt, @ctz(SingleInt, d[high])); | 78 | return n[high] >> @intCast(Log2SingleInt, @ctz(d[high])); |
| 79 | } | 79 | } |
| 80 | // K K | 80 | // K K |
| 81 | // --- | 81 | // --- |
| 82 | // K 0 | 82 | // 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]))); |
| 84 | // 0 <= sr <= single_int_bits - 2 or sr large | 84 | // 0 <= sr <= single_int_bits - 2 or sr large |
| 85 | if (sr > single_int_bits - 2) { | 85 | if (sr > single_int_bits - 2) { |
| 86 | if (maybe_rem) |rem| { | 86 | if (maybe_rem) |rem| { |
| ... | @@ -110,7 +110,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: | ... | @@ -110,7 +110,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 110 | if (d[low] == 1) { | 110 | if (d[low] == 1) { |
| 111 | return a; | 111 | return a; |
| 112 | } | 112 | } |
| 113 | sr = @ctz(SingleInt, d[low]); | 113 | sr = @ctz(d[low]); |
| 114 | q[high] = n[high] >> @intCast(Log2SingleInt, sr); | 114 | q[high] = n[high] >> @intCast(Log2SingleInt, sr); |
| 115 | q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr)); | 115 | q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr)); |
| 116 | return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421 | 116 | 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: | ... | @@ -118,7 +118,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 118 | // K X | 118 | // K X |
| 119 | // --- | 119 | // --- |
| 120 | // 0 K | 120 | // 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])); |
| 122 | // 2 <= sr <= double_int_bits - 1 | 122 | // 2 <= sr <= double_int_bits - 1 |
| 123 | // q.all = a << (double_int_bits - sr); | 123 | // q.all = a << (double_int_bits - sr); |
| 124 | // r.all = a >> sr; | 124 | // r.all = a >> sr; |
| ... | @@ -144,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: | ... | @@ -144,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 144 | // K X | 144 | // K X |
| 145 | // --- | 145 | // --- |
| 146 | // K K | 146 | // 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]))); |
| 148 | // 0 <= sr <= single_int_bits - 1 or sr large | 148 | // 0 <= sr <= single_int_bits - 1 or sr large |
| 149 | if (sr > single_int_bits - 1) { | 149 | if (sr > single_int_bits - 1) { |
| 150 | if (maybe_rem) |rem| { | 150 | if (maybe_rem) |rem| { |
lib/std/Thread/Futex.zig+2-2| ... | @@ -703,7 +703,7 @@ const PosixImpl = struct { | ... | @@ -703,7 +703,7 @@ const PosixImpl = struct { |
| 703 | const max_multiplier_bits = @bitSizeOf(usize); | 703 | const max_multiplier_bits = @bitSizeOf(usize); |
| 704 | const fibonacci_multiplier = 0x9E3779B97F4A7C15 >> (64 - max_multiplier_bits); | 704 | const fibonacci_multiplier = 0x9E3779B97F4A7C15 >> (64 - max_multiplier_bits); |
| 705 | 705 | ||
| 706 | const max_bucket_bits = @ctz(usize, buckets.len); | 706 | const max_bucket_bits = @ctz(buckets.len); |
| 707 | comptime assert(std.math.isPowerOfTwo(buckets.len)); | 707 | comptime assert(std.math.isPowerOfTwo(buckets.len)); |
| 708 | 708 | ||
| 709 | const index = (address *% fibonacci_multiplier) >> (max_multiplier_bits - max_bucket_bits); | 709 | const index = (address *% fibonacci_multiplier) >> (max_multiplier_bits - max_bucket_bits); |
| ... | @@ -721,7 +721,7 @@ const PosixImpl = struct { | ... | @@ -721,7 +721,7 @@ const PosixImpl = struct { |
| 721 | // then cut off the zero bits from the alignment to get the unique address. | 721 | // then cut off the zero bits from the alignment to get the unique address. |
| 722 | const addr = @ptrToInt(ptr); | 722 | const addr = @ptrToInt(ptr); |
| 723 | assert(addr & (alignment - 1) == 0); | 723 | assert(addr & (alignment - 1) == 0); |
| 724 | return addr >> @ctz(usize, alignment); | 724 | return addr >> @ctz(alignment); |
| 725 | } | 725 | } |
| 726 | }; | 726 | }; |
| 727 | 727 |
lib/std/Thread/Mutex.zig+1-1| ... | @@ -140,7 +140,7 @@ const FutexImpl = struct { | ... | @@ -140,7 +140,7 @@ const FutexImpl = struct { |
| 140 | // - they both seem to mark the cache-line as modified regardless: https://stackoverflow.com/a/63350048 | 140 | // - they both seem to mark the cache-line as modified regardless: https://stackoverflow.com/a/63350048 |
| 141 | // - `lock bts` is smaller instruction-wise which makes it better for inlining | 141 | // - `lock bts` is smaller instruction-wise which makes it better for inlining |
| 142 | if (comptime builtin.target.cpu.arch.isX86()) { | 142 | if (comptime builtin.target.cpu.arch.isX86()) { |
| 143 | const locked_bit = @ctz(u32, @as(u32, locked)); | 143 | const locked_bit = @ctz(@as(u32, locked)); |
| 144 | return self.state.bitSet(locked_bit, .Acquire) == 0; | 144 | return self.state.bitSet(locked_bit, .Acquire) == 0; |
| 145 | } | 145 | } |
| 146 | 146 |
lib/std/Thread/RwLock.zig+2-2| ... | @@ -168,8 +168,8 @@ pub const DefaultRwLock = struct { | ... | @@ -168,8 +168,8 @@ pub const DefaultRwLock = struct { |
| 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 + @bitSizeOf(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(WRITER); |
| 172 | const READER_MASK: usize = std.math.maxInt(Count) << @ctz(usize, READER); | 172 | const READER_MASK: usize = std.math.maxInt(Count) << @ctz(READER); |
| 173 | const Count = std.meta.Int(.unsigned, @divFloor(@bitSizeOf(usize) - 1, 2)); | 173 | const Count = std.meta.Int(.unsigned, @divFloor(@bitSizeOf(usize) - 1, 2)); |
| 174 | 174 | ||
| 175 | pub fn tryLock(rwl: *DefaultRwLock) bool { | 175 | pub fn tryLock(rwl: *DefaultRwLock) bool { |
lib/std/bit_set.zig+13-13| ... | @@ -91,7 +91,7 @@ pub fn IntegerBitSet(comptime size: u16) type { | ... | @@ -91,7 +91,7 @@ pub fn IntegerBitSet(comptime size: u16) type { |
| 91 | 91 | ||
| 92 | /// Returns the total number of set bits in this bit set. | 92 | /// Returns the total number of set bits in this bit set. |
| 93 | pub fn count(self: Self) usize { | 93 | pub fn count(self: Self) usize { |
| 94 | return @popCount(MaskInt, self.mask); | 94 | return @popCount(self.mask); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | /// Changes the value of the specified bit of the bit | 97 | /// Changes the value of the specified bit of the bit |
| ... | @@ -179,7 +179,7 @@ pub fn IntegerBitSet(comptime size: u16) type { | ... | @@ -179,7 +179,7 @@ pub fn IntegerBitSet(comptime size: u16) type { |
| 179 | pub fn findFirstSet(self: Self) ?usize { | 179 | pub fn findFirstSet(self: Self) ?usize { |
| 180 | const mask = self.mask; | 180 | const mask = self.mask; |
| 181 | if (mask == 0) return null; | 181 | if (mask == 0) return null; |
| 182 | return @ctz(MaskInt, mask); | 182 | return @ctz(mask); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | /// Finds the index of the first set bit, and unsets it. | 185 | /// Finds the index of the first set bit, and unsets it. |
| ... | @@ -187,7 +187,7 @@ pub fn IntegerBitSet(comptime size: u16) type { | ... | @@ -187,7 +187,7 @@ pub fn IntegerBitSet(comptime size: u16) type { |
| 187 | pub fn toggleFirstSet(self: *Self) ?usize { | 187 | pub fn toggleFirstSet(self: *Self) ?usize { |
| 188 | const mask = self.mask; | 188 | const mask = self.mask; |
| 189 | if (mask == 0) return null; | 189 | if (mask == 0) return null; |
| 190 | const index = @ctz(MaskInt, mask); | 190 | const index = @ctz(mask); |
| 191 | self.mask = mask & (mask - 1); | 191 | self.mask = mask & (mask - 1); |
| 192 | return index; | 192 | return index; |
| 193 | } | 193 | } |
| ... | @@ -222,12 +222,12 @@ pub fn IntegerBitSet(comptime size: u16) type { | ... | @@ -222,12 +222,12 @@ pub fn IntegerBitSet(comptime size: u16) type { |
| 222 | 222 | ||
| 223 | switch (direction) { | 223 | switch (direction) { |
| 224 | .forward => { | 224 | .forward => { |
| 225 | const next_index = @ctz(MaskInt, self.bits_remain); | 225 | const next_index = @ctz(self.bits_remain); |
| 226 | self.bits_remain &= self.bits_remain - 1; | 226 | self.bits_remain &= self.bits_remain - 1; |
| 227 | return next_index; | 227 | return next_index; |
| 228 | }, | 228 | }, |
| 229 | .reverse => { | 229 | .reverse => { |
| 230 | const leading_zeroes = @clz(MaskInt, self.bits_remain); | 230 | const leading_zeroes = @clz(self.bits_remain); |
| 231 | const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes; | 231 | const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes; |
| 232 | self.bits_remain &= (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1; | 232 | self.bits_remain &= (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1; |
| 233 | return top_bit; | 233 | return top_bit; |
| ... | @@ -347,7 +347,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -347,7 +347,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 347 | pub fn count(self: Self) usize { | 347 | pub fn count(self: Self) usize { |
| 348 | var total: usize = 0; | 348 | var total: usize = 0; |
| 349 | for (self.masks) |mask| { | 349 | for (self.masks) |mask| { |
| 350 | total += @popCount(MaskInt, mask); | 350 | total += @popCount(mask); |
| 351 | } | 351 | } |
| 352 | return total; | 352 | return total; |
| 353 | } | 353 | } |
| ... | @@ -475,7 +475,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -475,7 +475,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 475 | if (mask != 0) break mask; | 475 | if (mask != 0) break mask; |
| 476 | offset += @bitSizeOf(MaskInt); | 476 | offset += @bitSizeOf(MaskInt); |
| 477 | } else return null; | 477 | } else return null; |
| 478 | return offset + @ctz(MaskInt, mask); | 478 | return offset + @ctz(mask); |
| 479 | } | 479 | } |
| 480 | 480 | ||
| 481 | /// Finds the index of the first set bit, and unsets it. | 481 | /// 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 { | ... | @@ -486,7 +486,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 486 | if (mask.* != 0) break mask; | 486 | if (mask.* != 0) break mask; |
| 487 | offset += @bitSizeOf(MaskInt); | 487 | offset += @bitSizeOf(MaskInt); |
| 488 | } else return null; | 488 | } else return null; |
| 489 | const index = @ctz(MaskInt, mask.*); | 489 | const index = @ctz(mask.*); |
| 490 | mask.* &= (mask.* - 1); | 490 | mask.* &= (mask.* - 1); |
| 491 | return offset + index; | 491 | return offset + index; |
| 492 | } | 492 | } |
| ... | @@ -657,7 +657,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -657,7 +657,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 657 | var total: usize = 0; | 657 | var total: usize = 0; |
| 658 | for (self.masks[0..num_masks]) |mask| { | 658 | for (self.masks[0..num_masks]) |mask| { |
| 659 | // Note: This is where we depend on padding bits being zero | 659 | // Note: This is where we depend on padding bits being zero |
| 660 | total += @popCount(MaskInt, mask); | 660 | total += @popCount(mask); |
| 661 | } | 661 | } |
| 662 | return total; | 662 | return total; |
| 663 | } | 663 | } |
| ... | @@ -795,7 +795,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -795,7 +795,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 795 | mask += 1; | 795 | mask += 1; |
| 796 | offset += @bitSizeOf(MaskInt); | 796 | offset += @bitSizeOf(MaskInt); |
| 797 | } else return null; | 797 | } else return null; |
| 798 | return offset + @ctz(MaskInt, mask[0]); | 798 | return offset + @ctz(mask[0]); |
| 799 | } | 799 | } |
| 800 | 800 | ||
| 801 | /// Finds the index of the first set bit, and unsets it. | 801 | /// Finds the index of the first set bit, and unsets it. |
| ... | @@ -808,7 +808,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -808,7 +808,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 808 | mask += 1; | 808 | mask += 1; |
| 809 | offset += @bitSizeOf(MaskInt); | 809 | offset += @bitSizeOf(MaskInt); |
| 810 | } else return null; | 810 | } else return null; |
| 811 | const index = @ctz(MaskInt, mask[0]); | 811 | const index = @ctz(mask[0]); |
| 812 | mask[0] &= (mask[0] - 1); | 812 | mask[0] &= (mask[0] - 1); |
| 813 | return offset + index; | 813 | return offset + index; |
| 814 | } | 814 | } |
| ... | @@ -1067,12 +1067,12 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ | ... | @@ -1067,12 +1067,12 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ |
| 1067 | 1067 | ||
| 1068 | switch (direction) { | 1068 | switch (direction) { |
| 1069 | .forward => { | 1069 | .forward => { |
| 1070 | const next_index = @ctz(MaskInt, self.bits_remain) + self.bit_offset; | 1070 | const next_index = @ctz(self.bits_remain) + self.bit_offset; |
| 1071 | self.bits_remain &= self.bits_remain - 1; | 1071 | self.bits_remain &= self.bits_remain - 1; |
| 1072 | return next_index; | 1072 | return next_index; |
| 1073 | }, | 1073 | }, |
| 1074 | .reverse => { | 1074 | .reverse => { |
| 1075 | const leading_zeroes = @clz(MaskInt, self.bits_remain); | 1075 | const leading_zeroes = @clz(self.bits_remain); |
| 1076 | const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes; | 1076 | const top_bit = (@bitSizeOf(MaskInt) - 1) - leading_zeroes; |
| 1077 | const no_top_bit_mask = (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1; | 1077 | const no_top_bit_mask = (@as(MaskInt, 1) << @intCast(ShiftInt, top_bit)) - 1; |
| 1078 | self.bits_remain &= no_top_bit_mask; | 1078 | 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; | ... | @@ -2,7 +2,7 @@ const math = @import("std").math; |
| 2 | 2 | ||
| 3 | // Reverse bit-by-bit a N-bit code. | 3 | // Reverse bit-by-bit a N-bit code. |
| 4 | pub fn bitReverse(comptime T: type, value: T, N: usize) T { | 4 | pub fn bitReverse(comptime T: type, value: T, N: usize) T { |
| 5 | const r = @bitReverse(T, value); | 5 | const r = @bitReverse(value); |
| 6 | return r >> @intCast(math.Log2Int(T), @typeInfo(T).Int.bits - N); | 6 | return r >> @intCast(math.Log2Int(T), @typeInfo(T).Int.bits - N); |
| 7 | } | 7 | } |
| 8 | 8 |
lib/std/crypto/aes_ocb.zig+5-5| ... | @@ -66,7 +66,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -66,7 +66,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 66 | var offset = [_]u8{0} ** 16; | 66 | var offset = [_]u8{0} ** 16; |
| 67 | var i: usize = 0; | 67 | var i: usize = 0; |
| 68 | while (i < full_blocks) : (i += 1) { | 68 | while (i < full_blocks) : (i += 1) { |
| 69 | xorWith(&offset, lt[@ctz(usize, i + 1)]); | 69 | xorWith(&offset, lt[@ctz(i + 1)]); |
| 70 | var e = xorBlocks(offset, a[i * 16 ..][0..16].*); | 70 | var e = xorBlocks(offset, a[i * 16 ..][0..16].*); |
| 71 | aes_enc_ctx.encrypt(&e, &e); | 71 | aes_enc_ctx.encrypt(&e, &e); |
| 72 | xorWith(&sum, e); | 72 | xorWith(&sum, e); |
| ... | @@ -129,7 +129,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -129,7 +129,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 129 | var es: [16 * wb]u8 align(16) = undefined; | 129 | var es: [16 * wb]u8 align(16) = undefined; |
| 130 | var j: usize = 0; | 130 | var j: usize = 0; |
| 131 | while (j < wb) : (j += 1) { | 131 | while (j < wb) : (j += 1) { |
| 132 | xorWith(&offset, lt[@ctz(usize, i + 1 + j)]); | 132 | xorWith(&offset, lt[@ctz(i + 1 + j)]); |
| 133 | offsets[j] = offset; | 133 | offsets[j] = offset; |
| 134 | const p = m[(i + j) * 16 ..][0..16].*; | 134 | const p = m[(i + j) * 16 ..][0..16].*; |
| 135 | mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j])); | 135 | mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j])); |
| ... | @@ -143,7 +143,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -143,7 +143,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 143 | } | 143 | } |
| 144 | } | 144 | } |
| 145 | while (i < full_blocks) : (i += 1) { | 145 | while (i < full_blocks) : (i += 1) { |
| 146 | xorWith(&offset, lt[@ctz(usize, i + 1)]); | 146 | xorWith(&offset, lt[@ctz(i + 1)]); |
| 147 | const p = m[i * 16 ..][0..16].*; | 147 | const p = m[i * 16 ..][0..16].*; |
| 148 | var e = xorBlocks(p, offset); | 148 | var e = xorBlocks(p, offset); |
| 149 | aes_enc_ctx.encrypt(&e, &e); | 149 | aes_enc_ctx.encrypt(&e, &e); |
| ... | @@ -193,7 +193,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -193,7 +193,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 193 | var es: [16 * wb]u8 align(16) = undefined; | 193 | var es: [16 * wb]u8 align(16) = undefined; |
| 194 | var j: usize = 0; | 194 | var j: usize = 0; |
| 195 | while (j < wb) : (j += 1) { | 195 | while (j < wb) : (j += 1) { |
| 196 | xorWith(&offset, lt[@ctz(usize, i + 1 + j)]); | 196 | xorWith(&offset, lt[@ctz(i + 1 + j)]); |
| 197 | offsets[j] = offset; | 197 | offsets[j] = offset; |
| 198 | const q = c[(i + j) * 16 ..][0..16].*; | 198 | const q = c[(i + j) * 16 ..][0..16].*; |
| 199 | mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j])); | 199 | mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j])); |
| ... | @@ -207,7 +207,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -207,7 +207,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 207 | } | 207 | } |
| 208 | } | 208 | } |
| 209 | while (i < full_blocks) : (i += 1) { | 209 | while (i < full_blocks) : (i += 1) { |
| 210 | xorWith(&offset, lt[@ctz(usize, i + 1)]); | 210 | xorWith(&offset, lt[@ctz(i + 1)]); |
| 211 | const q = c[i * 16 ..][0..16].*; | 211 | const q = c[i * 16 ..][0..16].*; |
| 212 | var e = xorBlocks(q, offset); | 212 | var e = xorBlocks(q, offset); |
| 213 | aes_dec_ctx.decrypt(&e, &e); | 213 | aes_dec_ctx.decrypt(&e, &e); |
lib/std/crypto/ghash.zig+16-16| ... | @@ -41,8 +41,8 @@ pub const Ghash = struct { | ... | @@ -41,8 +41,8 @@ pub const Ghash = struct { |
| 41 | pub fn init(key: *const [key_length]u8) Ghash { | 41 | pub fn init(key: *const [key_length]u8) Ghash { |
| 42 | const h1 = mem.readIntBig(u64, key[0..8]); | 42 | const h1 = mem.readIntBig(u64, key[0..8]); |
| 43 | const h0 = mem.readIntBig(u64, key[8..16]); | 43 | const h0 = mem.readIntBig(u64, key[8..16]); |
| 44 | const h1r = @bitReverse(u64, h1); | 44 | const h1r = @bitReverse(h1); |
| 45 | const h0r = @bitReverse(u64, h0); | 45 | const h0r = @bitReverse(h0); |
| 46 | const h2 = h0 ^ h1; | 46 | const h2 = h0 ^ h1; |
| 47 | const h2r = h0r ^ h1r; | 47 | const h2r = h0r ^ h1r; |
| 48 | 48 | ||
| ... | @@ -68,8 +68,8 @@ pub const Ghash = struct { | ... | @@ -68,8 +68,8 @@ pub const Ghash = struct { |
| 68 | hh.update(key); | 68 | hh.update(key); |
| 69 | const hh1 = hh.y1; | 69 | const hh1 = hh.y1; |
| 70 | const hh0 = hh.y0; | 70 | const hh0 = hh.y0; |
| 71 | const hh1r = @bitReverse(u64, hh1); | 71 | const hh1r = @bitReverse(hh1); |
| 72 | const hh0r = @bitReverse(u64, hh0); | 72 | const hh0r = @bitReverse(hh0); |
| 73 | const hh2 = hh0 ^ hh1; | 73 | const hh2 = hh0 ^ hh1; |
| 74 | const hh2r = hh0r ^ hh1r; | 74 | const hh2r = hh0r ^ hh1r; |
| 75 | 75 | ||
| ... | @@ -156,8 +156,8 @@ pub const Ghash = struct { | ... | @@ -156,8 +156,8 @@ pub const Ghash = struct { |
| 156 | y1 ^= mem.readIntBig(u64, msg[i..][0..8]); | 156 | y1 ^= mem.readIntBig(u64, msg[i..][0..8]); |
| 157 | y0 ^= mem.readIntBig(u64, msg[i..][8..16]); | 157 | y0 ^= mem.readIntBig(u64, msg[i..][8..16]); |
| 158 | 158 | ||
| 159 | const y1r = @bitReverse(u64, y1); | 159 | const y1r = @bitReverse(y1); |
| 160 | const y0r = @bitReverse(u64, y0); | 160 | const y0r = @bitReverse(y0); |
| 161 | const y2 = y0 ^ y1; | 161 | const y2 = y0 ^ y1; |
| 162 | const y2r = y0r ^ y1r; | 162 | const y2r = y0r ^ y1r; |
| 163 | 163 | ||
| ... | @@ -172,8 +172,8 @@ pub const Ghash = struct { | ... | @@ -172,8 +172,8 @@ pub const Ghash = struct { |
| 172 | const sy1 = mem.readIntBig(u64, msg[i..][16..24]); | 172 | const sy1 = mem.readIntBig(u64, msg[i..][16..24]); |
| 173 | const sy0 = mem.readIntBig(u64, msg[i..][24..32]); | 173 | const sy0 = mem.readIntBig(u64, msg[i..][24..32]); |
| 174 | 174 | ||
| 175 | const sy1r = @bitReverse(u64, sy1); | 175 | const sy1r = @bitReverse(sy1); |
| 176 | const sy0r = @bitReverse(u64, sy0); | 176 | const sy0r = @bitReverse(sy0); |
| 177 | const sy2 = sy0 ^ sy1; | 177 | const sy2 = sy0 ^ sy1; |
| 178 | const sy2r = sy0r ^ sy1r; | 178 | const sy2r = sy0r ^ sy1r; |
| 179 | 179 | ||
| ... | @@ -191,9 +191,9 @@ pub const Ghash = struct { | ... | @@ -191,9 +191,9 @@ pub const Ghash = struct { |
| 191 | z0h ^= sz0h; | 191 | z0h ^= sz0h; |
| 192 | z1h ^= sz1h; | 192 | z1h ^= sz1h; |
| 193 | z2h ^= sz2h; | 193 | z2h ^= sz2h; |
| 194 | z0h = @bitReverse(u64, z0h) >> 1; | 194 | z0h = @bitReverse(z0h) >> 1; |
| 195 | z1h = @bitReverse(u64, z1h) >> 1; | 195 | z1h = @bitReverse(z1h) >> 1; |
| 196 | z2h = @bitReverse(u64, z2h) >> 1; | 196 | z2h = @bitReverse(z2h) >> 1; |
| 197 | 197 | ||
| 198 | var v3 = z1h; | 198 | var v3 = z1h; |
| 199 | var v2 = z1 ^ z2h; | 199 | var v2 = z1 ^ z2h; |
| ... | @@ -217,8 +217,8 @@ pub const Ghash = struct { | ... | @@ -217,8 +217,8 @@ pub const Ghash = struct { |
| 217 | y1 ^= mem.readIntBig(u64, msg[i..][0..8]); | 217 | y1 ^= mem.readIntBig(u64, msg[i..][0..8]); |
| 218 | y0 ^= mem.readIntBig(u64, msg[i..][8..16]); | 218 | y0 ^= mem.readIntBig(u64, msg[i..][8..16]); |
| 219 | 219 | ||
| 220 | const y1r = @bitReverse(u64, y1); | 220 | const y1r = @bitReverse(y1); |
| 221 | const y0r = @bitReverse(u64, y0); | 221 | const y0r = @bitReverse(y0); |
| 222 | const y2 = y0 ^ y1; | 222 | const y2 = y0 ^ y1; |
| 223 | const y2r = y0r ^ y1r; | 223 | const y2r = y0r ^ y1r; |
| 224 | 224 | ||
| ... | @@ -228,9 +228,9 @@ pub const Ghash = struct { | ... | @@ -228,9 +228,9 @@ pub const Ghash = struct { |
| 228 | var z0h = clmul(y0r, st.h0r); | 228 | var z0h = clmul(y0r, st.h0r); |
| 229 | var z1h = clmul(y1r, st.h1r); | 229 | var z1h = clmul(y1r, st.h1r); |
| 230 | var z2h = clmul(y2r, st.h2r) ^ z0h ^ z1h; | 230 | var z2h = clmul(y2r, st.h2r) ^ z0h ^ z1h; |
| 231 | z0h = @bitReverse(u64, z0h) >> 1; | 231 | z0h = @bitReverse(z0h) >> 1; |
| 232 | z1h = @bitReverse(u64, z1h) >> 1; | 232 | z1h = @bitReverse(z1h) >> 1; |
| 233 | z2h = @bitReverse(u64, z2h) >> 1; | 233 | z2h = @bitReverse(z2h) >> 1; |
| 234 | 234 | ||
| 235 | // shift & reduce | 235 | // shift & reduce |
| 236 | var v3 = z1h; | 236 | var v3 = z1h; |
lib/std/elf.zig+3-3| ... | @@ -387,7 +387,7 @@ pub const Header = struct { | ... | @@ -387,7 +387,7 @@ pub const Header = struct { |
| 387 | 387 | ||
| 388 | const machine = if (need_bswap) blk: { | 388 | const machine = if (need_bswap) blk: { |
| 389 | const value = @enumToInt(hdr32.e_machine); | 389 | const value = @enumToInt(hdr32.e_machine); |
| 390 | break :blk @intToEnum(EM, @byteSwap(@TypeOf(value), value)); | 390 | break :blk @intToEnum(EM, @byteSwap(value)); |
| 391 | } else hdr32.e_machine; | 391 | } else hdr32.e_machine; |
| 392 | 392 | ||
| 393 | return @as(Header, .{ | 393 | return @as(Header, .{ |
| ... | @@ -511,7 +511,7 @@ pub fn SectionHeaderIterator(ParseSource: anytype) type { | ... | @@ -511,7 +511,7 @@ pub fn SectionHeaderIterator(ParseSource: anytype) type { |
| 511 | pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) { | 511 | pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) { |
| 512 | if (is_64) { | 512 | if (is_64) { |
| 513 | if (need_bswap) { | 513 | if (need_bswap) { |
| 514 | return @byteSwap(@TypeOf(int_64), int_64); | 514 | return @byteSwap(int_64); |
| 515 | } else { | 515 | } else { |
| 516 | return int_64; | 516 | return int_64; |
| 517 | } | 517 | } |
| ... | @@ -522,7 +522,7 @@ pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @Typ | ... | @@ -522,7 +522,7 @@ pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @Typ |
| 522 | 522 | ||
| 523 | pub fn int32(need_bswap: bool, int_32: anytype, comptime Int64: anytype) Int64 { | 523 | pub fn int32(need_bswap: bool, int_32: anytype, comptime Int64: anytype) Int64 { |
| 524 | if (need_bswap) { | 524 | if (need_bswap) { |
| 525 | return @byteSwap(@TypeOf(int_32), int_32); | 525 | return @byteSwap(int_32); |
| 526 | } else { | 526 | } else { |
| 527 | return int_32; | 527 | return int_32; |
| 528 | } | 528 | } |
lib/std/event/channel.zig+1-1| ... | @@ -56,7 +56,7 @@ pub fn Channel(comptime T: type) type { | ... | @@ -56,7 +56,7 @@ pub fn Channel(comptime T: type) type { |
| 56 | pub fn init(self: *SelfChannel, buffer: []T) void { | 56 | pub fn init(self: *SelfChannel, buffer: []T) void { |
| 57 | // The ring buffer implementation only works with power of 2 buffer sizes | 57 | // The ring buffer implementation only works with power of 2 buffer sizes |
| 58 | // because of relying on subtracting across zero. For example (0 -% 1) % 10 == 5 | 58 | // 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); |
| 60 | 60 | ||
| 61 | self.* = SelfChannel{ | 61 | self.* = SelfChannel{ |
| 62 | .buffer_len = 0, | 62 | .buffer_len = 0, |
lib/std/fmt.zig+2-2| ... | @@ -195,7 +195,7 @@ pub fn format( | ... | @@ -195,7 +195,7 @@ pub fn format( |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | if (comptime arg_state.hasUnusedArgs()) { | 197 | 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); |
| 199 | switch (missing_count) { | 199 | switch (missing_count) { |
| 200 | 0 => unreachable, | 200 | 0 => unreachable, |
| 201 | 1 => @compileError("unused argument in '" ++ fmt ++ "'"), | 201 | 1 => @compileError("unused argument in '" ++ fmt ++ "'"), |
| ... | @@ -380,7 +380,7 @@ const ArgState = struct { | ... | @@ -380,7 +380,7 @@ const ArgState = struct { |
| 380 | args_len: usize, | 380 | args_len: usize, |
| 381 | 381 | ||
| 382 | fn hasUnusedArgs(self: *@This()) bool { | 382 | fn hasUnusedArgs(self: *@This()) bool { |
| 383 | return @popCount(ArgSetType, self.used_args) != self.args_len; | 383 | return @popCount(self.used_args) != self.args_len; |
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | fn nextArg(self: *@This(), arg_index: ?usize) ?usize { | 386 | 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) { | ... | @@ -36,7 +36,7 @@ pub fn convertEiselLemire(comptime T: type, q: i64, w_: u64) ?BiasedFp(f64) { |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | // Normalize our significant digits, so the most-significant bit is set. | 38 | // 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)); |
| 40 | w = math.shl(u64, w, lz); | 40 | w = math.shl(u64, w, lz); |
| 41 | 41 | ||
| 42 | const r = computeProductApprox(q, w, float_info.mantissa_explicit_bits + 3); | 42 | 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 { | ... | @@ -143,9 +143,9 @@ pub const CityHash32 = struct { |
| 143 | h = rotr32(h, 19); | 143 | h = rotr32(h, 19); |
| 144 | h = h *% 5 +% 0xe6546b64; | 144 | h = h *% 5 +% 0xe6546b64; |
| 145 | g ^= b4; | 145 | g ^= b4; |
| 146 | g = @byteSwap(u32, g) *% 5; | 146 | g = @byteSwap(g) *% 5; |
| 147 | h +%= b4 *% 5; | 147 | h +%= b4 *% 5; |
| 148 | h = @byteSwap(u32, h); | 148 | h = @byteSwap(h); |
| 149 | f +%= b0; | 149 | f +%= b0; |
| 150 | const t: u32 = h; | 150 | const t: u32 = h; |
| 151 | h = f; | 151 | h = f; |
| ... | @@ -252,11 +252,11 @@ pub const CityHash64 = struct { | ... | @@ -252,11 +252,11 @@ pub const CityHash64 = struct { |
| 252 | 252 | ||
| 253 | const u: u64 = rotr64(a +% g, 43) +% (rotr64(b, 30) +% c) *% 9; | 253 | const u: u64 = rotr64(a +% g, 43) +% (rotr64(b, 30) +% c) *% 9; |
| 254 | const v: u64 = ((a +% g) ^ d) +% f +% 1; | 254 | 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; |
| 256 | const x: u64 = rotr64(e +% f, 42) +% c; | 256 | 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; |
| 258 | const z: u64 = e +% f +% c; | 258 | 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; |
| 260 | const b1: u64 = shiftmix((z +% a1) *% mul +% d +% h) *% mul; | 260 | const b1: u64 = shiftmix((z +% a1) *% mul +% d +% h) *% mul; |
| 261 | return b1 +% x; | 261 | return b1 +% x; |
| 262 | } | 262 | } |
lib/std/hash/murmur.zig+11-11| ... | @@ -19,7 +19,7 @@ pub const Murmur2_32 = struct { | ... | @@ -19,7 +19,7 @@ pub const Murmur2_32 = struct { |
| 19 | for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| { | 19 | for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| { |
| 20 | var k1: u32 = v; | 20 | var k1: u32 = v; |
| 21 | if (native_endian == .Big) | 21 | if (native_endian == .Big) |
| 22 | k1 = @byteSwap(u32, k1); | 22 | k1 = @byteSwap(k1); |
| 23 | k1 *%= m; | 23 | k1 *%= m; |
| 24 | k1 ^= k1 >> 24; | 24 | k1 ^= k1 >> 24; |
| 25 | k1 *%= m; | 25 | k1 *%= m; |
| ... | @@ -104,7 +104,7 @@ pub const Murmur2_64 = struct { | ... | @@ -104,7 +104,7 @@ pub const Murmur2_64 = struct { |
| 104 | for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { | 104 | for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { |
| 105 | var k1: u64 = v; | 105 | var k1: u64 = v; |
| 106 | if (native_endian == .Big) | 106 | if (native_endian == .Big) |
| 107 | k1 = @byteSwap(u64, k1); | 107 | k1 = @byteSwap(k1); |
| 108 | k1 *%= m; | 108 | k1 *%= m; |
| 109 | k1 ^= k1 >> 47; | 109 | k1 ^= k1 >> 47; |
| 110 | k1 *%= m; | 110 | k1 *%= m; |
| ... | @@ -117,7 +117,7 @@ pub const Murmur2_64 = struct { | ... | @@ -117,7 +117,7 @@ pub const Murmur2_64 = struct { |
| 117 | var k1: u64 = 0; | 117 | var k1: u64 = 0; |
| 118 | @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest)); | 118 | @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest)); |
| 119 | if (native_endian == .Big) | 119 | if (native_endian == .Big) |
| 120 | k1 = @byteSwap(u64, k1); | 120 | k1 = @byteSwap(k1); |
| 121 | h1 ^= k1; | 121 | h1 ^= k1; |
| 122 | h1 *%= m; | 122 | h1 *%= m; |
| 123 | } | 123 | } |
| ... | @@ -184,7 +184,7 @@ pub const Murmur3_32 = struct { | ... | @@ -184,7 +184,7 @@ pub const Murmur3_32 = struct { |
| 184 | for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| { | 184 | for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| { |
| 185 | var k1: u32 = v; | 185 | var k1: u32 = v; |
| 186 | if (native_endian == .Big) | 186 | if (native_endian == .Big) |
| 187 | k1 = @byteSwap(u32, k1); | 187 | k1 = @byteSwap(k1); |
| 188 | k1 *%= c1; | 188 | k1 *%= c1; |
| 189 | k1 = rotl32(k1, 15); | 189 | k1 = rotl32(k1, 15); |
| 190 | k1 *%= c2; | 190 | k1 *%= c2; |
| ... | @@ -296,7 +296,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 { | ... | @@ -296,7 +296,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 { |
| 296 | 296 | ||
| 297 | var h = hash_fn(key[0..i], 256 - i); | 297 | var h = hash_fn(key[0..i], 256 - i); |
| 298 | if (native_endian == .Big) | 298 | if (native_endian == .Big) |
| 299 | h = @byteSwap(@TypeOf(h), h); | 299 | h = @byteSwap(h); |
| 300 | @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); | 300 | @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); |
| 301 | } | 301 | } |
| 302 | 302 | ||
| ... | @@ -310,8 +310,8 @@ test "murmur2_32" { | ... | @@ -310,8 +310,8 @@ test "murmur2_32" { |
| 310 | var v0le: u32 = v0; | 310 | var v0le: u32 = v0; |
| 311 | var v1le: u64 = v1; | 311 | var v1le: u64 = v1; |
| 312 | if (native_endian == .Big) { | 312 | if (native_endian == .Big) { |
| 313 | v0le = @byteSwap(u32, v0le); | 313 | v0le = @byteSwap(v0le); |
| 314 | v1le = @byteSwap(u64, v1le); | 314 | v1le = @byteSwap(v1le); |
| 315 | } | 315 | } |
| 316 | try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0)); | 316 | try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0)); |
| 317 | try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1)); | 317 | try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1)); |
| ... | @@ -324,8 +324,8 @@ test "murmur2_64" { | ... | @@ -324,8 +324,8 @@ test "murmur2_64" { |
| 324 | var v0le: u32 = v0; | 324 | var v0le: u32 = v0; |
| 325 | var v1le: u64 = v1; | 325 | var v1le: u64 = v1; |
| 326 | if (native_endian == .Big) { | 326 | if (native_endian == .Big) { |
| 327 | v0le = @byteSwap(u32, v0le); | 327 | v0le = @byteSwap(v0le); |
| 328 | v1le = @byteSwap(u64, v1le); | 328 | v1le = @byteSwap(v1le); |
| 329 | } | 329 | } |
| 330 | try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0)); | 330 | try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0)); |
| 331 | try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1)); | 331 | try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1)); |
| ... | @@ -338,8 +338,8 @@ test "murmur3_32" { | ... | @@ -338,8 +338,8 @@ test "murmur3_32" { |
| 338 | var v0le: u32 = v0; | 338 | var v0le: u32 = v0; |
| 339 | var v1le: u64 = v1; | 339 | var v1le: u64 = v1; |
| 340 | if (native_endian == .Big) { | 340 | if (native_endian == .Big) { |
| 341 | v0le = @byteSwap(u32, v0le); | 341 | v0le = @byteSwap(v0le); |
| 342 | v1le = @byteSwap(u64, v1le); | 342 | v1le = @byteSwap(v1le); |
| 343 | } | 343 | } |
| 344 | try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0)); | 344 | try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0)); |
| 345 | try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1)); | 345 | 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 { | ... | @@ -479,7 +479,7 @@ const WasmPageAllocator = struct { |
| 479 | @setCold(true); | 479 | @setCold(true); |
| 480 | for (self.data) |segment, i| { | 480 | for (self.data) |segment, i| { |
| 481 | const spills_into_next = @bitCast(i128, segment) < 0; | 481 | 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; |
| 483 | 483 | ||
| 484 | if (!spills_into_next and !has_enough_bits) continue; | 484 | if (!spills_into_next and !has_enough_bits) continue; |
| 485 | 485 | ||
| ... | @@ -1185,7 +1185,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void { | ... | @@ -1185,7 +1185,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void { |
| 1185 | const large_align = @as(u29, mem.page_size << 2); | 1185 | const large_align = @as(u29, mem.page_size << 2); |
| 1186 | 1186 | ||
| 1187 | var align_mask: usize = undefined; | 1187 | 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); |
| 1189 | 1189 | ||
| 1190 | var slice = try allocator.alignedAlloc(u8, large_align, 500); | 1190 | var slice = try allocator.alignedAlloc(u8, large_align, 500); |
| 1191 | try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | 1191 | 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 { | ... | @@ -317,7 +317,7 @@ fn test_write_leb128(value: anytype) !void { |
| 317 | const bytes_needed = bn: { | 317 | const bytes_needed = bn: { |
| 318 | if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1); | 318 | if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1); |
| 319 | 319 | ||
| 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); |
| 321 | const used_bits: u16 = (@typeInfo(T).Int.bits - unused_bits) + @boolToInt(t_signed); | 321 | const used_bits: u16 = (@typeInfo(T).Int.bits - unused_bits) + @boolToInt(t_signed); |
| 322 | if (used_bits <= 7) break :bn @as(u16, 1); | 322 | if (used_bits <= 7) break :bn @as(u16, 1); |
| 323 | break :bn ((used_bits + 6) / 7); | 323 | 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( | ... | @@ -1146,7 +1146,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo( |
| 1146 | assert(value != 0); | 1146 | assert(value != 0); |
| 1147 | const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1); | 1147 | const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1); |
| 1148 | const ShiftType = std.math.Log2Int(PromotedType); | 1148 | 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)); |
| 1150 | } | 1150 | } |
| 1151 | 1151 | ||
| 1152 | /// Returns the next power of two (if the value is not already a power of two). | 1152 | /// 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) { | ... | @@ -1212,7 +1212,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) { |
| 1212 | if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) | 1212 | if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) |
| 1213 | @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T)); | 1213 | @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T)); |
| 1214 | assert(x != 0); | 1214 | 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)); |
| 1216 | } | 1216 | } |
| 1217 | 1217 | ||
| 1218 | /// Return the log base 2 of integer value x, rounding up to the | 1218 | /// 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 { | ... | @@ -887,7 +887,7 @@ pub const Mutable = struct { |
| 887 | 887 | ||
| 888 | var sum: Limb = 0; | 888 | var sum: Limb = 0; |
| 889 | for (r.limbs[0..r.len]) |limb| { | 889 | for (r.limbs[0..r.len]) |limb| { |
| 890 | sum += @popCount(Limb, limb); | 890 | sum += @popCount(limb); |
| 891 | } | 891 | } |
| 892 | r.set(sum); | 892 | r.set(sum); |
| 893 | } | 893 | } |
| ... | @@ -1520,7 +1520,7 @@ pub const Mutable = struct { | ... | @@ -1520,7 +1520,7 @@ pub const Mutable = struct { |
| 1520 | ) void { | 1520 | ) void { |
| 1521 | // 0. | 1521 | // 0. |
| 1522 | // Normalize so that y[t] > b/2 | 1522 | // 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]); |
| 1524 | const norm_shift = if (lz == 0 and y.toConst().isOdd()) | 1524 | const norm_shift = if (lz == 0 and y.toConst().isOdd()) |
| 1525 | limb_bits // Force an extra limb so that y is even. | 1525 | limb_bits // Force an extra limb so that y is even. |
| 1526 | else | 1526 | else |
| ... | @@ -1917,7 +1917,7 @@ pub const Const = struct { | ... | @@ -1917,7 +1917,7 @@ pub const Const = struct { |
| 1917 | 1917 | ||
| 1918 | /// Returns the number of bits required to represent the absolute value of an integer. | 1918 | /// Returns the number of bits required to represent the absolute value of an integer. |
| 1919 | pub fn bitCountAbs(self: Const) usize { | 1919 | 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])); |
| 1921 | } | 1921 | } |
| 1922 | 1922 | ||
| 1923 | /// Returns the number of bits required to represent the integer in twos-complement form. | 1923 | /// Returns the number of bits required to represent the integer in twos-complement form. |
| ... | @@ -1936,9 +1936,9 @@ pub const Const = struct { | ... | @@ -1936,9 +1936,9 @@ pub const Const = struct { |
| 1936 | if (!self.positive) block: { | 1936 | if (!self.positive) block: { |
| 1937 | bits += 1; | 1937 | bits += 1; |
| 1938 | 1938 | ||
| 1939 | if (@popCount(Limb, self.limbs[self.limbs.len - 1]) == 1) { | 1939 | if (@popCount(self.limbs[self.limbs.len - 1]) == 1) { |
| 1940 | for (self.limbs[0 .. self.limbs.len - 1]) |limb| { | 1940 | for (self.limbs[0 .. self.limbs.len - 1]) |limb| { |
| 1941 | if (@popCount(Limb, limb) != 0) { | 1941 | if (@popCount(limb) != 0) { |
| 1942 | break :block; | 1942 | break :block; |
| 1943 | } | 1943 | } |
| 1944 | } | 1944 | } |
| ... | @@ -3895,8 +3895,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void { | ... | @@ -3895,8 +3895,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void { |
| 3895 | // The initial assignment makes the result end in `r` so an extra memory | 3895 | // The initial assignment makes the result end in `r` so an extra memory |
| 3896 | // copy is saved, each 1 flips the index twice so it's only the zeros that | 3896 | // copy is saved, each 1 flips the index twice so it's only the zeros that |
| 3897 | // matter. | 3897 | // matter. |
| 3898 | const b_leading_zeros = @clz(u32, b); | 3898 | const b_leading_zeros = @clz(b); |
| 3899 | const exp_zeros = @popCount(u32, ~b) - b_leading_zeros; | 3899 | const exp_zeros = @popCount(~b) - b_leading_zeros; |
| 3900 | if (exp_zeros & 1 != 0) { | 3900 | if (exp_zeros & 1 != 0) { |
| 3901 | tmp1 = tmp_limbs; | 3901 | tmp1 = tmp_limbs; |
| 3902 | tmp2 = r; | 3902 | tmp2 = r; |
lib/std/mem.zig+13-13| ... | @@ -1319,7 +1319,7 @@ pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int | ... | @@ -1319,7 +1319,7 @@ pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int |
| 1319 | /// This function cannot fail and cannot cause undefined behavior. | 1319 | /// This function cannot fail and cannot cause undefined behavior. |
| 1320 | /// Assumes the endianness of memory is foreign, so it must byte-swap. | 1320 | /// Assumes the endianness of memory is foreign, so it must byte-swap. |
| 1321 | pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T { | 1321 | pub 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)); |
| 1323 | } | 1323 | } |
| 1324 | 1324 | ||
| 1325 | pub const readIntLittle = switch (native_endian) { | 1325 | pub const readIntLittle = switch (native_endian) { |
| ... | @@ -1348,7 +1348,7 @@ pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T { | ... | @@ -1348,7 +1348,7 @@ pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T { |
| 1348 | /// The bit count of T must be evenly divisible by 8. | 1348 | /// The bit count of T must be evenly divisible by 8. |
| 1349 | /// Assumes the endianness of memory is foreign, so it must byte-swap. | 1349 | /// Assumes the endianness of memory is foreign, so it must byte-swap. |
| 1350 | pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T { | 1350 | pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T { |
| 1351 | return @byteSwap(T, readIntSliceNative(T, bytes)); | 1351 | return @byteSwap(readIntSliceNative(T, bytes)); |
| 1352 | } | 1352 | } |
| 1353 | 1353 | ||
| 1354 | pub const readIntSliceLittle = switch (native_endian) { | 1354 | pub const readIntSliceLittle = switch (native_endian) { |
| ... | @@ -1430,7 +1430,7 @@ pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u | ... | @@ -1430,7 +1430,7 @@ pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u |
| 1430 | /// the integer bit width must be divisible by 8. | 1430 | /// the integer bit width must be divisible by 8. |
| 1431 | /// This function stores in foreign endian, which means it does a @byteSwap first. | 1431 | /// This function stores in foreign endian, which means it does a @byteSwap first. |
| 1432 | pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T) void { | 1432 | pub 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)); |
| 1434 | } | 1434 | } |
| 1435 | 1435 | ||
| 1436 | pub const writeIntLittle = switch (native_endian) { | 1436 | pub const writeIntLittle = switch (native_endian) { |
| ... | @@ -1575,7 +1575,7 @@ pub const bswapAllFields = @compileError("bswapAllFields has been renamed to byt | ... | @@ -1575,7 +1575,7 @@ pub const bswapAllFields = @compileError("bswapAllFields has been renamed to byt |
| 1575 | pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { | 1575 | pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { |
| 1576 | if (@typeInfo(S) != .Struct) @compileError("byteSwapAllFields expects a struct as the first argument"); | 1576 | if (@typeInfo(S) != .Struct) @compileError("byteSwapAllFields expects a struct as the first argument"); |
| 1577 | inline for (std.meta.fields(S)) |f| { | 1577 | 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)); |
| 1579 | } | 1579 | } |
| 1580 | } | 1580 | } |
| 1581 | 1581 | ||
| ... | @@ -2752,14 +2752,14 @@ test "replaceOwned" { | ... | @@ -2752,14 +2752,14 @@ test "replaceOwned" { |
| 2752 | pub fn littleToNative(comptime T: type, x: T) T { | 2752 | pub fn littleToNative(comptime T: type, x: T) T { |
| 2753 | return switch (native_endian) { | 2753 | return switch (native_endian) { |
| 2754 | .Little => x, | 2754 | .Little => x, |
| 2755 | .Big => @byteSwap(T, x), | 2755 | .Big => @byteSwap(x), |
| 2756 | }; | 2756 | }; |
| 2757 | } | 2757 | } |
| 2758 | 2758 | ||
| 2759 | /// Converts a big-endian integer to host endianness. | 2759 | /// Converts a big-endian integer to host endianness. |
| 2760 | pub fn bigToNative(comptime T: type, x: T) T { | 2760 | pub fn bigToNative(comptime T: type, x: T) T { |
| 2761 | return switch (native_endian) { | 2761 | return switch (native_endian) { |
| 2762 | .Little => @byteSwap(T, x), | 2762 | .Little => @byteSwap(x), |
| 2763 | .Big => x, | 2763 | .Big => x, |
| 2764 | }; | 2764 | }; |
| 2765 | } | 2765 | } |
| ... | @@ -2784,14 +2784,14 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T { | ... | @@ -2784,14 +2784,14 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T { |
| 2784 | pub fn nativeToLittle(comptime T: type, x: T) T { | 2784 | pub fn nativeToLittle(comptime T: type, x: T) T { |
| 2785 | return switch (native_endian) { | 2785 | return switch (native_endian) { |
| 2786 | .Little => x, | 2786 | .Little => x, |
| 2787 | .Big => @byteSwap(T, x), | 2787 | .Big => @byteSwap(x), |
| 2788 | }; | 2788 | }; |
| 2789 | } | 2789 | } |
| 2790 | 2790 | ||
| 2791 | /// Converts an integer which has host endianness to big endian. | 2791 | /// Converts an integer which has host endianness to big endian. |
| 2792 | pub fn nativeToBig(comptime T: type, x: T) T { | 2792 | pub fn nativeToBig(comptime T: type, x: T) T { |
| 2793 | return switch (native_endian) { | 2793 | return switch (native_endian) { |
| 2794 | .Little => @byteSwap(T, x), | 2794 | .Little => @byteSwap(x), |
| 2795 | .Big => x, | 2795 | .Big => x, |
| 2796 | }; | 2796 | }; |
| 2797 | } | 2797 | } |
| ... | @@ -2803,7 +2803,7 @@ pub fn nativeToBig(comptime T: type, x: T) T { | ... | @@ -2803,7 +2803,7 @@ pub fn nativeToBig(comptime T: type, x: T) T { |
| 2803 | /// - The delta required to align the pointer is not a multiple of the pointee's | 2803 | /// - The delta required to align the pointer is not a multiple of the pointee's |
| 2804 | /// type. | 2804 | /// type. |
| 2805 | pub fn alignPointerOffset(ptr: anytype, align_to: u29) ?usize { | 2805 | pub 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); |
| 2807 | 2807 | ||
| 2808 | const T = @TypeOf(ptr); | 2808 | const T = @TypeOf(ptr); |
| 2809 | const info = @typeInfo(T); | 2809 | const info = @typeInfo(T); |
| ... | @@ -3293,7 +3293,7 @@ test "alignForward" { | ... | @@ -3293,7 +3293,7 @@ test "alignForward" { |
| 3293 | /// Round an address up to the previous aligned address | 3293 | /// Round an address up to the previous aligned address |
| 3294 | /// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2. | 3294 | /// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2. |
| 3295 | pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize { | 3295 | pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize { |
| 3296 | if (@popCount(usize, alignment) == 1) | 3296 | if (@popCount(alignment) == 1) |
| 3297 | return alignBackward(i, alignment); | 3297 | return alignBackward(i, alignment); |
| 3298 | assert(alignment != 0); | 3298 | assert(alignment != 0); |
| 3299 | return i - @mod(i, alignment); | 3299 | return i - @mod(i, alignment); |
| ... | @@ -3308,7 +3308,7 @@ pub fn alignBackward(addr: usize, alignment: usize) usize { | ... | @@ -3308,7 +3308,7 @@ pub fn alignBackward(addr: usize, alignment: usize) usize { |
| 3308 | /// Round an address up to the previous aligned address | 3308 | /// Round an address up to the previous aligned address |
| 3309 | /// The alignment must be a power of 2 and greater than 0. | 3309 | /// The alignment must be a power of 2 and greater than 0. |
| 3310 | pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { | 3310 | pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { |
| 3311 | assert(@popCount(T, alignment) == 1); | 3311 | assert(@popCount(alignment) == 1); |
| 3312 | // 000010000 // example alignment | 3312 | // 000010000 // example alignment |
| 3313 | // 000001111 // subtract 1 | 3313 | // 000001111 // subtract 1 |
| 3314 | // 111110000 // binary not | 3314 | // 111110000 // binary not |
| ... | @@ -3318,11 +3318,11 @@ pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { | ... | @@ -3318,11 +3318,11 @@ pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { |
| 3318 | /// Returns whether `alignment` is a valid alignment, meaning it is | 3318 | /// Returns whether `alignment` is a valid alignment, meaning it is |
| 3319 | /// a positive power of 2. | 3319 | /// a positive power of 2. |
| 3320 | pub fn isValidAlign(alignment: u29) bool { | 3320 | pub fn isValidAlign(alignment: u29) bool { |
| 3321 | return @popCount(u29, alignment) == 1; | 3321 | return @popCount(alignment) == 1; |
| 3322 | } | 3322 | } |
| 3323 | 3323 | ||
| 3324 | pub fn isAlignedAnyAlign(i: usize, alignment: usize) bool { | 3324 | pub fn isAlignedAnyAlign(i: usize, alignment: usize) bool { |
| 3325 | if (@popCount(usize, alignment) == 1) | 3325 | if (@popCount(alignment) == 1) |
| 3326 | return isAligned(i, alignment); | 3326 | return isAligned(i, alignment); |
| 3327 | assert(alignment != 0); | 3327 | assert(alignment != 0); |
| 3328 | return 0 == @mod(i, alignment); | 3328 | 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)); | ... | @@ -3377,7 +3377,7 @@ pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8)); |
| 3377 | pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { | 3377 | pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { |
| 3378 | var sum: cpu_count_t = 0; | 3378 | var sum: cpu_count_t = 0; |
| 3379 | for (set) |x| { | 3379 | for (set) |x| { |
| 3380 | sum += @popCount(usize, x); | 3380 | sum += @popCount(x); |
| 3381 | } | 3381 | } |
| 3382 | return sum; | 3382 | return sum; |
| 3383 | } | 3383 | } |
lib/std/os/uefi.zig+3-3| ... | @@ -55,9 +55,9 @@ pub const Guid = extern struct { | ... | @@ -55,9 +55,9 @@ pub const Guid = extern struct { |
| 55 | if (f.len == 0) { | 55 | if (f.len == 0) { |
| 56 | const fmt = std.fmt.fmtSliceHexLower; | 56 | const fmt = std.fmt.fmtSliceHexLower; |
| 57 | 57 | ||
| 58 | const time_low = @byteSwap(u32, self.time_low); | 58 | const time_low = @byteSwap(self.time_low); |
| 59 | const time_mid = @byteSwap(u16, self.time_mid); | 59 | const time_mid = @byteSwap(self.time_mid); |
| 60 | const time_high_and_version = @byteSwap(u16, self.time_high_and_version); | 60 | const time_high_and_version = @byteSwap(self.time_high_and_version); |
| 61 | 61 | ||
| 62 | return std.fmt.format(writer, "{:0>8}-{:0>4}-{:0>4}-{:0>2}{:0>2}-{:0>12}", .{ | 62 | return std.fmt.format(writer, "{:0>8}-{:0>4}-{:0>4}-{:0>2}{:0>2}-{:0>12}", .{ |
| 63 | fmt(std.mem.asBytes(&time_low)), | 63 | 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 { | ... | @@ -76,7 +76,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { |
| 76 | const value_ptr = @ptrCast(*align(1) const Container, &bytes[start_byte]); | 76 | const value_ptr = @ptrCast(*align(1) const Container, &bytes[start_byte]); |
| 77 | var value = value_ptr.*; | 77 | var value = value_ptr.*; |
| 78 | 78 | ||
| 79 | if (endian != native_endian) value = @byteSwap(Container, value); | 79 | if (endian != native_endian) value = @byteSwap(value); |
| 80 | 80 | ||
| 81 | switch (endian) { | 81 | switch (endian) { |
| 82 | .Big => { | 82 | .Big => { |
| ... | @@ -126,7 +126,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { | ... | @@ -126,7 +126,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { |
| 126 | const target_ptr = @ptrCast(*align(1) Container, &bytes[start_byte]); | 126 | const target_ptr = @ptrCast(*align(1) Container, &bytes[start_byte]); |
| 127 | var target = target_ptr.*; | 127 | var target = target_ptr.*; |
| 128 | 128 | ||
| 129 | if (endian != native_endian) target = @byteSwap(Container, target); | 129 | if (endian != native_endian) target = @byteSwap(target); |
| 130 | 130 | ||
| 131 | //zero the bits we want to replace in the existing bytes | 131 | //zero the bits we want to replace in the existing bytes |
| 132 | const inv_mask = @intCast(Container, std.math.maxInt(UnInt)) << keep_shift; | 132 | 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 { | ... | @@ -136,7 +136,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { |
| 136 | //merge the new value | 136 | //merge the new value |
| 137 | target |= value; | 137 | target |= value; |
| 138 | 138 | ||
| 139 | if (endian != native_endian) target = @byteSwap(Container, target); | 139 | if (endian != native_endian) target = @byteSwap(target); |
| 140 | 140 | ||
| 141 | //save it back | 141 | //save it back |
| 142 | target_ptr.* = target; | 142 | 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 | ... | @@ -69,7 +69,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar |
| 69 | // The first element is on a min layer; | 69 | // The first element is on a min layer; |
| 70 | // next two are on a max layer; | 70 | // next two are on a max layer; |
| 71 | // next four are on a min layer, and so on. | 71 | // 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); |
| 73 | const highest_set_bit = @bitSizeOf(usize) - 1 - leading_zeros; | 73 | const highest_set_bit = @bitSizeOf(usize) - 1 - leading_zeros; |
| 74 | return (highest_set_bit & 1) == 0; | 74 | return (highest_set_bit & 1) == 0; |
| 75 | } | 75 | } |
lib/std/rand.zig+5-5| ... | @@ -257,15 +257,15 @@ pub const Random = struct { | ... | @@ -257,15 +257,15 @@ pub const Random = struct { |
| 257 | // If all 41 bits are zero, generate additional random bits, until a | 257 | // If all 41 bits are zero, generate additional random bits, until a |
| 258 | // set bit is found, or 126 bits have been generated. | 258 | // set bit is found, or 126 bits have been generated. |
| 259 | const rand = r.int(u64); | 259 | const rand = r.int(u64); |
| 260 | var rand_lz = @clz(u64, rand); | 260 | var rand_lz = @clz(rand); |
| 261 | if (rand_lz >= 41) { | 261 | if (rand_lz >= 41) { |
| 262 | // TODO: when #5177 or #489 is implemented, | 262 | // TODO: when #5177 or #489 is implemented, |
| 263 | // tell the compiler it is unlikely (1/2^41) to reach this point. | 263 | // tell the compiler it is unlikely (1/2^41) to reach this point. |
| 264 | // (Same for the if branch and the f64 calculations below.) | 264 | // (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)); |
| 266 | if (rand_lz == 41 + 64) { | 266 | if (rand_lz == 41 + 64) { |
| 267 | // It is astronomically unlikely to reach this point. | 267 | // 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); |
| 269 | } | 269 | } |
| 270 | } | 270 | } |
| 271 | const mantissa = @truncate(u23, rand); | 271 | const mantissa = @truncate(u23, rand); |
| ... | @@ -277,12 +277,12 @@ pub const Random = struct { | ... | @@ -277,12 +277,12 @@ pub const Random = struct { |
| 277 | // If all 12 bits are zero, generate additional random bits, until a | 277 | // If all 12 bits are zero, generate additional random bits, until a |
| 278 | // set bit is found, or 1022 bits have been generated. | 278 | // set bit is found, or 1022 bits have been generated. |
| 279 | const rand = r.int(u64); | 279 | const rand = r.int(u64); |
| 280 | var rand_lz: u64 = @clz(u64, rand); | 280 | var rand_lz: u64 = @clz(rand); |
| 281 | if (rand_lz >= 12) { | 281 | if (rand_lz >= 12) { |
| 282 | rand_lz = 12; | 282 | rand_lz = 12; |
| 283 | while (true) { | 283 | while (true) { |
| 284 | // It is astronomically unlikely for this loop to execute more than once. | 284 | // 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)); |
| 286 | rand_lz += addl_rand_lz; | 286 | rand_lz += addl_rand_lz; |
| 287 | if (addl_rand_lz != 64) { | 287 | if (addl_rand_lz != 64) { |
| 288 | break; | 288 | break; |
lib/std/zig/c_builtins.zig+6-6| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub inline fn __builtin_bswap16(val: u16) u16 { | 3 | pub inline fn __builtin_bswap16(val: u16) u16 { |
| 4 | return @byteSwap(u16, val); | 4 | return @byteSwap(val); |
| 5 | } | 5 | } |
| 6 | pub inline fn __builtin_bswap32(val: u32) u32 { | 6 | pub inline fn __builtin_bswap32(val: u32) u32 { |
| 7 | return @byteSwap(u32, val); | 7 | return @byteSwap(val); |
| 8 | } | 8 | } |
| 9 | pub inline fn __builtin_bswap64(val: u64) u64 { | 9 | pub inline fn __builtin_bswap64(val: u64) u64 { |
| 10 | return @byteSwap(u64, val); | 10 | return @byteSwap(val); |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | pub inline fn __builtin_signbit(val: f64) c_int { | 13 | pub inline fn __builtin_signbit(val: f64) c_int { |
| ... | @@ -20,19 +20,19 @@ pub inline fn __builtin_signbitf(val: f32) c_int { | ... | @@ -20,19 +20,19 @@ pub inline fn __builtin_signbitf(val: f32) c_int { |
| 20 | pub inline fn __builtin_popcount(val: c_uint) c_int { | 20 | pub inline fn __builtin_popcount(val: c_uint) c_int { |
| 21 | // popcount of a c_uint will never exceed the capacity of a c_int | 21 | // popcount of a c_uint will never exceed the capacity of a c_int |
| 22 | @setRuntimeSafety(false); | 22 | @setRuntimeSafety(false); |
| 23 | return @bitCast(c_int, @as(c_uint, @popCount(c_uint, val))); | 23 | return @bitCast(c_int, @as(c_uint, @popCount(val))); |
| 24 | } | 24 | } |
| 25 | pub inline fn __builtin_ctz(val: c_uint) c_int { | 25 | pub inline fn __builtin_ctz(val: c_uint) c_int { |
| 26 | // Returns the number of trailing 0-bits in val, starting at the least significant bit position. | 26 | // Returns the number of trailing 0-bits in val, starting at the least significant bit position. |
| 27 | // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint | 27 | // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint |
| 28 | @setRuntimeSafety(false); | 28 | @setRuntimeSafety(false); |
| 29 | return @bitCast(c_int, @as(c_uint, @ctz(c_uint, val))); | 29 | return @bitCast(c_int, @as(c_uint, @ctz(val))); |
| 30 | } | 30 | } |
| 31 | pub inline fn __builtin_clz(val: c_uint) c_int { | 31 | pub inline fn __builtin_clz(val: c_uint) c_int { |
| 32 | // Returns the number of leading 0-bits in x, starting at the most significant bit position. | 32 | // Returns the number of leading 0-bits in x, starting at the most significant bit position. |
| 33 | // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint | 33 | // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint |
| 34 | @setRuntimeSafety(false); | 34 | @setRuntimeSafety(false); |
| 35 | return @bitCast(c_int, @as(c_uint, @clz(c_uint, val))); | 35 | return @bitCast(c_int, @as(c_uint, @clz(val))); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | pub inline fn __builtin_sqrt(val: f64) f64 { | 38 | pub inline fn __builtin_sqrt(val: f64) f64 { |
lib/std/zig/system/NativeTargetInfo.zig+2-2| ... | @@ -852,13 +852,13 @@ pub const LdInfo = struct { | ... | @@ -852,13 +852,13 @@ pub const LdInfo = struct { |
| 852 | pub fn elfInt(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) { | 852 | pub fn elfInt(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) { |
| 853 | if (is_64) { | 853 | if (is_64) { |
| 854 | if (need_bswap) { | 854 | if (need_bswap) { |
| 855 | return @byteSwap(@TypeOf(int_64), int_64); | 855 | return @byteSwap(int_64); |
| 856 | } else { | 856 | } else { |
| 857 | return int_64; | 857 | return int_64; |
| 858 | } | 858 | } |
| 859 | } else { | 859 | } else { |
| 860 | if (need_bswap) { | 860 | if (need_bswap) { |
| 861 | return @byteSwap(@TypeOf(int_32), int_32); | 861 | return @byteSwap(int_32); |
| 862 | } else { | 862 | } else { |
| 863 | return int_32; | 863 | return int_32; |
| 864 | } | 864 | } |
src/AstGen.zig+5-13| ... | @@ -7733,11 +7733,11 @@ fn builtinCall( | ... | @@ -7733,11 +7733,11 @@ fn builtinCall( |
| 7733 | .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl), | 7733 | .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl), |
| 7734 | .has_field => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_field), | 7734 | .has_field => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_field), |
| 7735 | 7735 | ||
| 7736 | .clz => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .clz), | 7736 | .clz => return bitBuiltin(gz, scope, rl, node, params[0], .clz), |
| 7737 | .ctz => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .ctz), | 7737 | .ctz => return bitBuiltin(gz, scope, rl, node, params[0], .ctz), |
| 7738 | .pop_count => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .pop_count), | 7738 | .pop_count => return bitBuiltin(gz, scope, rl, node, params[0], .pop_count), |
| 7739 | .byte_swap => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .byte_swap), | 7739 | .byte_swap => return bitBuiltin(gz, scope, rl, node, params[0], .byte_swap), |
| 7740 | .bit_reverse => return bitBuiltin(gz, scope, rl, node, params[0], params[1], .bit_reverse), | 7740 | .bit_reverse => return bitBuiltin(gz, scope, rl, node, params[0], .bit_reverse), |
| 7741 | 7741 | ||
| 7742 | .div_exact => return divBuiltin(gz, scope, rl, node, params[0], params[1], .div_exact), | 7742 | .div_exact => return divBuiltin(gz, scope, rl, node, params[0], params[1], .div_exact), |
| 7743 | .div_floor => return divBuiltin(gz, scope, rl, node, params[0], params[1], .div_floor), | 7743 | .div_floor => return divBuiltin(gz, scope, rl, node, params[0], params[1], .div_floor), |
| ... | @@ -8100,17 +8100,9 @@ fn bitBuiltin( | ... | @@ -8100,17 +8100,9 @@ fn bitBuiltin( |
| 8100 | scope: *Scope, | 8100 | scope: *Scope, |
| 8101 | rl: ResultLoc, | 8101 | rl: ResultLoc, |
| 8102 | node: Ast.Node.Index, | 8102 | node: Ast.Node.Index, |
| 8103 | int_type_node: Ast.Node.Index, | ||
| 8104 | operand_node: Ast.Node.Index, | 8103 | operand_node: Ast.Node.Index, |
| 8105 | tag: Zir.Inst.Tag, | 8104 | tag: Zir.Inst.Tag, |
| 8106 | ) InnerError!Zir.Inst.Ref { | 8105 | ) 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 | |||
| 8114 | const operand = try expr(gz, scope, .none, operand_node); | 8106 | const operand = try expr(gz, scope, .none, operand_node); |
| 8115 | const result = try gz.addUnNode(tag, operand, node); | 8107 | const result = try gz.addUnNode(tag, operand, node); |
| 8116 | return rvalue(gz, rl, result, node); | 8108 | return rvalue(gz, rl, result, node); |
src/BuiltinFn.zig+5-5| ... | @@ -250,14 +250,14 @@ pub const list = list: { | ... | @@ -250,14 +250,14 @@ pub const list = list: { |
| 250 | "@byteSwap", | 250 | "@byteSwap", |
| 251 | .{ | 251 | .{ |
| 252 | .tag = .byte_swap, | 252 | .tag = .byte_swap, |
| 253 | .param_count = 2, | 253 | .param_count = 1, |
| 254 | }, | 254 | }, |
| 255 | }, | 255 | }, |
| 256 | .{ | 256 | .{ |
| 257 | "@bitReverse", | 257 | "@bitReverse", |
| 258 | .{ | 258 | .{ |
| 259 | .tag = .bit_reverse, | 259 | .tag = .bit_reverse, |
| 260 | .param_count = 2, | 260 | .param_count = 1, |
| 261 | }, | 261 | }, |
| 262 | }, | 262 | }, |
| 263 | .{ | 263 | .{ |
| ... | @@ -301,7 +301,7 @@ pub const list = list: { | ... | @@ -301,7 +301,7 @@ pub const list = list: { |
| 301 | "@clz", | 301 | "@clz", |
| 302 | .{ | 302 | .{ |
| 303 | .tag = .clz, | 303 | .tag = .clz, |
| 304 | .param_count = 2, | 304 | .param_count = 1, |
| 305 | }, | 305 | }, |
| 306 | }, | 306 | }, |
| 307 | .{ | 307 | .{ |
| ... | @@ -336,7 +336,7 @@ pub const list = list: { | ... | @@ -336,7 +336,7 @@ pub const list = list: { |
| 336 | "@ctz", | 336 | "@ctz", |
| 337 | .{ | 337 | .{ |
| 338 | .tag = .ctz, | 338 | .tag = .ctz, |
| 339 | .param_count = 2, | 339 | .param_count = 1, |
| 340 | }, | 340 | }, |
| 341 | }, | 341 | }, |
| 342 | .{ | 342 | .{ |
| ... | @@ -614,7 +614,7 @@ pub const list = list: { | ... | @@ -614,7 +614,7 @@ pub const list = list: { |
| 614 | "@popCount", | 614 | "@popCount", |
| 615 | .{ | 615 | .{ |
| 616 | .tag = .pop_count, | 616 | .tag = .pop_count, |
| 617 | .param_count = 2, | 617 | .param_count = 1, |
| 618 | }, | 618 | }, |
| 619 | }, | 619 | }, |
| 620 | .{ | 620 | .{ |
src/Sema.zig+9-10| ... | @@ -13032,7 +13032,7 @@ fn analyzePtrArithmetic( | ... | @@ -13032,7 +13032,7 @@ fn analyzePtrArithmetic( |
| 13032 | // The resulting pointer is aligned to the lcd between the offset (an | 13032 | // The resulting pointer is aligned to the lcd between the offset (an |
| 13033 | // arbitrary number) and the alignment factor (always a power of two, | 13033 | // arbitrary number) and the alignment factor (always a power of two, |
| 13034 | // non zero). | 13034 | // 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")); |
| 13036 | 13036 | ||
| 13037 | break :t try Type.ptr(sema.arena, sema.mod, .{ | 13037 | break :t try Type.ptr(sema.arena, sema.mod, .{ |
| 13038 | .pointee_type = ptr_info.pointee_type, | 13038 | .pointee_type = ptr_info.pointee_type, |
| ... | @@ -17781,7 +17781,7 @@ fn zirBitCount( | ... | @@ -17781,7 +17781,7 @@ fn zirBitCount( |
| 17781 | ) CompileError!Air.Inst.Ref { | 17781 | ) CompileError!Air.Inst.Ref { |
| 17782 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 17782 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 17783 | const src = inst_data.src(); | 17783 | 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 }; |
| 17785 | const operand = try sema.resolveInst(inst_data.operand); | 17785 | const operand = try sema.resolveInst(inst_data.operand); |
| 17786 | const operand_ty = sema.typeOf(operand); | 17786 | const operand_ty = sema.typeOf(operand); |
| 17787 | _ = try checkIntOrVector(sema, block, operand, operand_src); | 17787 | _ = try checkIntOrVector(sema, block, operand, operand_src); |
| ... | @@ -17833,17 +17833,16 @@ fn zirBitCount( | ... | @@ -17833,17 +17833,16 @@ fn zirBitCount( |
| 17833 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17833 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17834 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 17834 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 17835 | const src = inst_data.src(); | 17835 | const src = inst_data.src(); |
| 17836 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 17836 | const operand_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 }; | ||
| 17838 | const operand = try sema.resolveInst(inst_data.operand); | 17837 | const operand = try sema.resolveInst(inst_data.operand); |
| 17839 | const operand_ty = sema.typeOf(operand); | 17838 | 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); |
| 17841 | const target = sema.mod.getTarget(); | 17840 | const target = sema.mod.getTarget(); |
| 17842 | const bits = scalar_ty.intInfo(target).bits; | 17841 | const bits = scalar_ty.intInfo(target).bits; |
| 17843 | if (bits % 8 != 0) { | 17842 | if (bits % 8 != 0) { |
| 17844 | return sema.fail( | 17843 | return sema.fail( |
| 17845 | block, | 17844 | block, |
| 17846 | ty_src, | 17845 | operand_src, |
| 17847 | "@byteSwap requires the number of bits to be evenly divisible by 8, but {} has {} bits", | 17846 | "@byteSwap requires the number of bits to be evenly divisible by 8, but {} has {} bits", |
| 17848 | .{ scalar_ty.fmt(sema.mod), bits }, | 17847 | .{ scalar_ty.fmt(sema.mod), bits }, |
| 17849 | ); | 17848 | ); |
| ... | @@ -17854,7 +17853,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17854,7 +17853,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17854 | } | 17853 | } |
| 17855 | 17854 | ||
| 17856 | switch (operand_ty.zigTypeTag()) { | 17855 | switch (operand_ty.zigTypeTag()) { |
| 17857 | .Int, .ComptimeInt => { | 17856 | .Int => { |
| 17858 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 17857 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 17859 | if (val.isUndef()) return sema.addConstUndef(operand_ty); | 17858 | if (val.isUndef()) return sema.addConstUndef(operand_ty); |
| 17860 | const result_val = try val.byteSwap(operand_ty, target, sema.arena); | 17859 | 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 | ... | @@ -17892,7 +17891,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17892 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17891 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17893 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 17892 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 17894 | const src = inst_data.src(); | 17893 | 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 }; |
| 17896 | const operand = try sema.resolveInst(inst_data.operand); | 17895 | const operand = try sema.resolveInst(inst_data.operand); |
| 17897 | const operand_ty = sema.typeOf(operand); | 17896 | const operand_ty = sema.typeOf(operand); |
| 17898 | _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); | 17897 | _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); |
| ... | @@ -21656,7 +21655,7 @@ fn structFieldPtrByIndex( | ... | @@ -21656,7 +21655,7 @@ fn structFieldPtrByIndex( |
| 21656 | const elem_size_bits = ptr_ty_data.pointee_type.bitSize(target); | 21655 | const elem_size_bits = ptr_ty_data.pointee_type.bitSize(target); |
| 21657 | if (elem_size_bytes * 8 == elem_size_bits) { | 21656 | if (elem_size_bytes * 8 == elem_size_bits) { |
| 21658 | const byte_offset = ptr_ty_data.bit_offset / 8; | 21657 | 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)); |
| 21660 | ptr_ty_data.bit_offset = 0; | 21659 | ptr_ty_data.bit_offset = 0; |
| 21661 | ptr_ty_data.host_size = 0; | 21660 | ptr_ty_data.host_size = 0; |
| 21662 | ptr_ty_data.@"align" = new_align; | 21661 | ptr_ty_data.@"align" = new_align; |
| ... | @@ -30426,7 +30425,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { | ... | @@ -30426,7 +30425,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { |
| 30426 | // The resulting pointer is aligned to the lcd between the offset (an | 30425 | // The resulting pointer is aligned to the lcd between the offset (an |
| 30427 | // arbitrary number) and the alignment factor (always a power of two, | 30426 | // arbitrary number) and the alignment factor (always a power of two, |
| 30428 | // non zero). | 30427 | // 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")); |
| 30430 | break :a new_align; | 30429 | break :a new_align; |
| 30431 | }; | 30430 | }; |
| 30432 | return try Type.ptr(sema.arena, sema.mod, .{ | 30431 | 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 { | ... | @@ -277,7 +277,7 @@ fn instructionSize(emit: *Emit, inst: Mir.Inst.Index) usize { |
| 277 | => return 2 * 4, | 277 | => return 2 * 4, |
| 278 | .pop_regs, .push_regs => { | 278 | .pop_regs, .push_regs => { |
| 279 | const reg_list = emit.mir.instructions.items(.data)[inst].reg_list; | 279 | 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); |
| 281 | const number_of_insts = std.math.divCeil(u6, number_of_regs, 2) catch unreachable; | 281 | const number_of_insts = std.math.divCeil(u6, number_of_regs, 2) catch unreachable; |
| 282 | return number_of_insts * 4; | 282 | return number_of_insts * 4; |
| 283 | }, | 283 | }, |
| ... | @@ -1183,7 +1183,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -1183,7 +1183,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 1183 | // sp must be aligned at all times, so we only use stp and ldp | 1183 | // sp must be aligned at all times, so we only use stp and ldp |
| 1184 | // instructions for minimal instruction count. However, if we do | 1184 | // instructions for minimal instruction count. However, if we do |
| 1185 | // not have an even number of registers, we use str and ldr | 1185 | // 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); |
| 1187 | 1187 | ||
| 1188 | switch (tag) { | 1188 | switch (tag) { |
| 1189 | .pop_regs => { | 1189 | .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 { | ... | @@ -343,7 +343,7 @@ fn emitMemArg(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { |
| 343 | try emit.code.append(@enumToInt(tag)); | 343 | try emit.code.append(@enumToInt(tag)); |
| 344 | 344 | ||
| 345 | // wasm encodes alignment as power of 2, rather than natural alignment | 345 | // 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); |
| 347 | try leb128.writeULEB128(emit.code.writer(), encoded_alignment); | 347 | try leb128.writeULEB128(emit.code.writer(), encoded_alignment); |
| 348 | try leb128.writeULEB128(emit.code.writer(), mem_arg.offset); | 348 | try leb128.writeULEB128(emit.code.writer(), mem_arg.offset); |
| 349 | } | 349 | } |
src/link/MachO/Object.zig+1-1| ... | @@ -391,7 +391,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) | ... | @@ -391,7 +391,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) |
| 391 | break :blk cc[start..][0..size]; | 391 | break :blk cc[start..][0..size]; |
| 392 | } else null; | 392 | } else null; |
| 393 | const atom_align = if (addr > 0) | 393 | const atom_align = if (addr > 0) |
| 394 | math.min(@ctz(u64, addr), sect.@"align") | 394 | math.min(@ctz(addr), sect.@"align") |
| 395 | else | 395 | else |
| 396 | sect.@"align"; | 396 | sect.@"align"; |
| 397 | const atom = try self.createAtomFromSubsection( | 397 | 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 { | ... | @@ -3135,12 +3135,12 @@ fn emitSegmentInfo(self: *Wasm, file: fs.File, arena: Allocator) !void { |
| 3135 | for (self.segment_info.items) |segment_info| { | 3135 | for (self.segment_info.items) |segment_info| { |
| 3136 | log.debug("Emit segment: {s} align({d}) flags({b})", .{ | 3136 | log.debug("Emit segment: {s} align({d}) flags({b})", .{ |
| 3137 | segment_info.name, | 3137 | segment_info.name, |
| 3138 | @ctz(u32, segment_info.alignment), | 3138 | @ctz(segment_info.alignment), |
| 3139 | segment_info.flags, | 3139 | segment_info.flags, |
| 3140 | }); | 3140 | }); |
| 3141 | try leb.writeULEB128(writer, @intCast(u32, segment_info.name.len)); | 3141 | try leb.writeULEB128(writer, @intCast(u32, segment_info.name.len)); |
| 3142 | try writer.writeAll(segment_info.name); | 3142 | 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)); |
| 3144 | try leb.writeULEB128(writer, segment_info.flags); | 3144 | try leb.writeULEB128(writer, segment_info.flags); |
| 3145 | } | 3145 | } |
| 3146 | 3146 |
src/stage1/astgen.cpp+2-4| ... | @@ -5374,10 +5374,8 @@ static Stage1ZirInst *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, Ast | ... | @@ -5374,10 +5374,8 @@ static Stage1ZirInst *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, Ast |
| 5374 | if (arg0_value == ag->codegen->invalid_inst_src) | 5374 | if (arg0_value == ag->codegen->invalid_inst_src) |
| 5375 | return arg0_value; | 5375 | return arg0_value; |
| 5376 | 5376 | ||
| 5377 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5377 | Stage1ZirInst *arg1_value = arg0_value; |
| 5378 | Stage1ZirInst *arg1_value = astgen_node(ag, arg1_node, scope); | 5378 | arg0_value = ir_build_typeof_1(ag, scope, arg0_node, arg1_value); |
| 5379 | if (arg1_value == ag->codegen->invalid_inst_src) | ||
| 5380 | return arg1_value; | ||
| 5381 | 5379 | ||
| 5382 | Stage1ZirInst *result; | 5380 | Stage1ZirInst *result; |
| 5383 | switch (builtin_fn->id) { | 5381 | switch (builtin_fn->id) { |
src/stage1/codegen.cpp+5-5| ... | @@ -9792,11 +9792,11 @@ static void define_builtin_fns(CodeGen *g) { | ... | @@ -9792,11 +9792,11 @@ static void define_builtin_fns(CodeGen *g) { |
| 9792 | create_builtin_fn(g, BuiltinFnIdCInclude, "cInclude", 1); | 9792 | create_builtin_fn(g, BuiltinFnIdCInclude, "cInclude", 1); |
| 9793 | create_builtin_fn(g, BuiltinFnIdCDefine, "cDefine", 2); | 9793 | create_builtin_fn(g, BuiltinFnIdCDefine, "cDefine", 2); |
| 9794 | create_builtin_fn(g, BuiltinFnIdCUndef, "cUndef", 1); | 9794 | create_builtin_fn(g, BuiltinFnIdCUndef, "cUndef", 1); |
| 9795 | create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 2); | 9795 | create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 1); |
| 9796 | create_builtin_fn(g, BuiltinFnIdClz, "clz", 2); | 9796 | create_builtin_fn(g, BuiltinFnIdClz, "clz", 1); |
| 9797 | create_builtin_fn(g, BuiltinFnIdPopCount, "popCount", 2); | 9797 | create_builtin_fn(g, BuiltinFnIdPopCount, "popCount", 1); |
| 9798 | create_builtin_fn(g, BuiltinFnIdBswap, "byteSwap", 2); | 9798 | create_builtin_fn(g, BuiltinFnIdBswap, "byteSwap", 1); |
| 9799 | create_builtin_fn(g, BuiltinFnIdBitReverse, "bitReverse", 2); | 9799 | create_builtin_fn(g, BuiltinFnIdBitReverse, "bitReverse", 1); |
| 9800 | create_builtin_fn(g, BuiltinFnIdImport, "import", 1); | 9800 | create_builtin_fn(g, BuiltinFnIdImport, "import", 1); |
| 9801 | create_builtin_fn(g, BuiltinFnIdCImport, "cImport", 1); | 9801 | create_builtin_fn(g, BuiltinFnIdCImport, "cImport", 1); |
| 9802 | create_builtin_fn(g, BuiltinFnIdErrName, "errorName", 1); | 9802 | create_builtin_fn(g, BuiltinFnIdErrName, "errorName", 1); |
src/value.zig+5-5| ... | @@ -1582,7 +1582,7 @@ pub const Value = extern union { | ... | @@ -1582,7 +1582,7 @@ pub const Value = extern union { |
| 1582 | .one, .bool_true => return ty_bits - 1, | 1582 | .one, .bool_true => return ty_bits - 1, |
| 1583 | 1583 | ||
| 1584 | .int_u64 => { | 1584 | .int_u64 => { |
| 1585 | const big = @clz(u64, val.castTag(.int_u64).?.data); | 1585 | const big = @clz(val.castTag(.int_u64).?.data); |
| 1586 | return big + ty_bits - 64; | 1586 | return big + ty_bits - 64; |
| 1587 | }, | 1587 | }, |
| 1588 | .int_i64 => { | 1588 | .int_i64 => { |
| ... | @@ -1599,7 +1599,7 @@ pub const Value = extern union { | ... | @@ -1599,7 +1599,7 @@ pub const Value = extern union { |
| 1599 | while (i != 0) { | 1599 | while (i != 0) { |
| 1600 | i -= 1; | 1600 | i -= 1; |
| 1601 | const limb = bigint.limbs[i]; | 1601 | const limb = bigint.limbs[i]; |
| 1602 | const this_limb_lz = @clz(std.math.big.Limb, limb); | 1602 | const this_limb_lz = @clz(limb); |
| 1603 | total_limb_lz += this_limb_lz; | 1603 | total_limb_lz += this_limb_lz; |
| 1604 | if (this_limb_lz != bits_per_limb) break; | 1604 | if (this_limb_lz != bits_per_limb) break; |
| 1605 | } | 1605 | } |
| ... | @@ -1626,7 +1626,7 @@ pub const Value = extern union { | ... | @@ -1626,7 +1626,7 @@ pub const Value = extern union { |
| 1626 | .one, .bool_true => return 0, | 1626 | .one, .bool_true => return 0, |
| 1627 | 1627 | ||
| 1628 | .int_u64 => { | 1628 | .int_u64 => { |
| 1629 | const big = @ctz(u64, val.castTag(.int_u64).?.data); | 1629 | const big = @ctz(val.castTag(.int_u64).?.data); |
| 1630 | return if (big == 64) ty_bits else big; | 1630 | return if (big == 64) ty_bits else big; |
| 1631 | }, | 1631 | }, |
| 1632 | .int_i64 => { | 1632 | .int_i64 => { |
| ... | @@ -1638,7 +1638,7 @@ pub const Value = extern union { | ... | @@ -1638,7 +1638,7 @@ pub const Value = extern union { |
| 1638 | // Limbs are stored in little-endian order. | 1638 | // Limbs are stored in little-endian order. |
| 1639 | var result: u64 = 0; | 1639 | var result: u64 = 0; |
| 1640 | for (bigint.limbs) |limb| { | 1640 | for (bigint.limbs) |limb| { |
| 1641 | const limb_tz = @ctz(std.math.big.Limb, limb); | 1641 | const limb_tz = @ctz(limb); |
| 1642 | result += limb_tz; | 1642 | result += limb_tz; |
| 1643 | if (limb_tz != @sizeOf(std.math.big.Limb) * 8) break; | 1643 | if (limb_tz != @sizeOf(std.math.big.Limb) * 8) break; |
| 1644 | } | 1644 | } |
| ... | @@ -1663,7 +1663,7 @@ pub const Value = extern union { | ... | @@ -1663,7 +1663,7 @@ pub const Value = extern union { |
| 1663 | .zero, .bool_false => return 0, | 1663 | .zero, .bool_false => return 0, |
| 1664 | .one, .bool_true => return 1, | 1664 | .one, .bool_true => return 1, |
| 1665 | 1665 | ||
| 1666 | .int_u64 => return @popCount(u64, val.castTag(.int_u64).?.data), | 1666 | .int_u64 => return @popCount(val.castTag(.int_u64).?.data), |
| 1667 | 1667 | ||
| 1668 | else => { | 1668 | else => { |
| 1669 | const info = ty.intInfo(target); | 1669 | const info = ty.intInfo(target); |
test/behavior/bitreverse.zig+47-47| ... | @@ -8,7 +8,7 @@ test "@bitReverse large exotic integer" { | ... | @@ -8,7 +8,7 @@ test "@bitReverse large exotic integer" { |
| 8 | // Currently failing on stage1 for big-endian targets | 8 | // Currently failing on stage1 for big-endian targets |
| 9 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | 9 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; |
| 10 | 10 | ||
| 11 | try expect(@bitReverse(u95, @as(u95, 0x123456789abcdef111213141)) == 0x4146424447bd9eac8f351624); | 11 | try expect(@bitReverse(@as(u95, 0x123456789abcdef111213141)) == 0x4146424447bd9eac8f351624); |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | test "@bitReverse" { | 14 | test "@bitReverse" { |
| ... | @@ -23,74 +23,74 @@ test "@bitReverse" { | ... | @@ -23,74 +23,74 @@ test "@bitReverse" { |
| 23 | 23 | ||
| 24 | fn testBitReverse() !void { | 24 | fn testBitReverse() !void { |
| 25 | // using comptime_ints, unsigned | 25 | // using comptime_ints, unsigned |
| 26 | try expect(@bitReverse(u0, @as(u0, 0)) == 0); | 26 | try expect(@bitReverse(@as(u0, 0)) == 0); |
| 27 | try expect(@bitReverse(u5, @as(u5, 0x12)) == 0x9); | 27 | try expect(@bitReverse(@as(u5, 0x12)) == 0x9); |
| 28 | try expect(@bitReverse(u8, @as(u8, 0x12)) == 0x48); | 28 | try expect(@bitReverse(@as(u8, 0x12)) == 0x48); |
| 29 | try expect(@bitReverse(u16, @as(u16, 0x1234)) == 0x2c48); | 29 | try expect(@bitReverse(@as(u16, 0x1234)) == 0x2c48); |
| 30 | try expect(@bitReverse(u24, @as(u24, 0x123456)) == 0x6a2c48); | 30 | try expect(@bitReverse(@as(u24, 0x123456)) == 0x6a2c48); |
| 31 | try expect(@bitReverse(u32, @as(u32, 0x12345678)) == 0x1e6a2c48); | 31 | try expect(@bitReverse(@as(u32, 0x12345678)) == 0x1e6a2c48); |
| 32 | try expect(@bitReverse(u40, @as(u40, 0x123456789a)) == 0x591e6a2c48); | 32 | try expect(@bitReverse(@as(u40, 0x123456789a)) == 0x591e6a2c48); |
| 33 | try expect(@bitReverse(u48, @as(u48, 0x123456789abc)) == 0x3d591e6a2c48); | 33 | try expect(@bitReverse(@as(u48, 0x123456789abc)) == 0x3d591e6a2c48); |
| 34 | try expect(@bitReverse(u56, @as(u56, 0x123456789abcde)) == 0x7b3d591e6a2c48); | 34 | try expect(@bitReverse(@as(u56, 0x123456789abcde)) == 0x7b3d591e6a2c48); |
| 35 | try expect(@bitReverse(u64, @as(u64, 0x123456789abcdef1)) == 0x8f7b3d591e6a2c48); | 35 | try expect(@bitReverse(@as(u64, 0x123456789abcdef1)) == 0x8f7b3d591e6a2c48); |
| 36 | try expect(@bitReverse(u96, @as(u96, 0x123456789abcdef111213141)) == 0x828c84888f7b3d591e6a2c48); | 36 | try expect(@bitReverse(@as(u96, 0x123456789abcdef111213141)) == 0x828c84888f7b3d591e6a2c48); |
| 37 | try expect(@bitReverse(u128, @as(u128, 0x123456789abcdef11121314151617181)) == 0x818e868a828c84888f7b3d591e6a2c48); | 37 | try expect(@bitReverse(@as(u128, 0x123456789abcdef11121314151617181)) == 0x818e868a828c84888f7b3d591e6a2c48); |
| 38 | 38 | ||
| 39 | // using runtime uints, unsigned | 39 | // using runtime uints, unsigned |
| 40 | var num0: u0 = 0; | 40 | var num0: u0 = 0; |
| 41 | try expect(@bitReverse(u0, num0) == 0); | 41 | try expect(@bitReverse(num0) == 0); |
| 42 | var num5: u5 = 0x12; | 42 | var num5: u5 = 0x12; |
| 43 | try expect(@bitReverse(u5, num5) == 0x9); | 43 | try expect(@bitReverse(num5) == 0x9); |
| 44 | var num8: u8 = 0x12; | 44 | var num8: u8 = 0x12; |
| 45 | try expect(@bitReverse(u8, num8) == 0x48); | 45 | try expect(@bitReverse(num8) == 0x48); |
| 46 | var num16: u16 = 0x1234; | 46 | var num16: u16 = 0x1234; |
| 47 | try expect(@bitReverse(u16, num16) == 0x2c48); | 47 | try expect(@bitReverse(num16) == 0x2c48); |
| 48 | var num24: u24 = 0x123456; | 48 | var num24: u24 = 0x123456; |
| 49 | try expect(@bitReverse(u24, num24) == 0x6a2c48); | 49 | try expect(@bitReverse(num24) == 0x6a2c48); |
| 50 | var num32: u32 = 0x12345678; | 50 | var num32: u32 = 0x12345678; |
| 51 | try expect(@bitReverse(u32, num32) == 0x1e6a2c48); | 51 | try expect(@bitReverse(num32) == 0x1e6a2c48); |
| 52 | var num40: u40 = 0x123456789a; | 52 | var num40: u40 = 0x123456789a; |
| 53 | try expect(@bitReverse(u40, num40) == 0x591e6a2c48); | 53 | try expect(@bitReverse(num40) == 0x591e6a2c48); |
| 54 | var num48: u48 = 0x123456789abc; | 54 | var num48: u48 = 0x123456789abc; |
| 55 | try expect(@bitReverse(u48, num48) == 0x3d591e6a2c48); | 55 | try expect(@bitReverse(num48) == 0x3d591e6a2c48); |
| 56 | var num56: u56 = 0x123456789abcde; | 56 | var num56: u56 = 0x123456789abcde; |
| 57 | try expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48); | 57 | try expect(@bitReverse(num56) == 0x7b3d591e6a2c48); |
| 58 | var num64: u64 = 0x123456789abcdef1; | 58 | var num64: u64 = 0x123456789abcdef1; |
| 59 | try expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48); | 59 | try expect(@bitReverse(num64) == 0x8f7b3d591e6a2c48); |
| 60 | var num128: u128 = 0x123456789abcdef11121314151617181; | 60 | var num128: u128 = 0x123456789abcdef11121314151617181; |
| 61 | try expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); | 61 | try expect(@bitReverse(num128) == 0x818e868a828c84888f7b3d591e6a2c48); |
| 62 | 62 | ||
| 63 | // using comptime_ints, signed, positive | 63 | // using comptime_ints, signed, positive |
| 64 | try expect(@bitReverse(u8, @as(u8, 0)) == 0); | 64 | try expect(@bitReverse(@as(u8, 0)) == 0); |
| 65 | try expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49))); | 65 | try expect(@bitReverse(@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))); | 66 | try expect(@bitReverse(@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))); | 67 | try expect(@bitReverse(@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))); | 68 | try expect(@bitReverse(@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))); | 69 | try expect(@bitReverse(@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))); | 70 | try expect(@bitReverse(@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))); | 71 | try expect(@bitReverse(@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))); | 72 | try expect(@bitReverse(@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))); | 73 | try expect(@bitReverse(@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))); | 74 | try expect(@bitReverse(@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))); | 75 | try expect(@bitReverse(@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))); | 76 | try expect(@bitReverse(@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))); | 77 | try expect(@bitReverse(@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))); | 78 | try expect(@bitReverse(@bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48))); |
| 79 | 79 | ||
| 80 | // using signed, negative. Compare to runtime ints returned from llvm. | 80 | // using signed, negative. Compare to runtime ints returned from llvm. |
| 81 | var neg8: i8 = -18; | 81 | var neg8: i8 = -18; |
| 82 | try expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8)); | 82 | try expect(@bitReverse(@as(i8, -18)) == @bitReverse(neg8)); |
| 83 | var neg16: i16 = -32694; | 83 | var neg16: i16 = -32694; |
| 84 | try expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16)); | 84 | try expect(@bitReverse(@as(i16, -32694)) == @bitReverse(neg16)); |
| 85 | var neg24: i24 = -6773785; | 85 | var neg24: i24 = -6773785; |
| 86 | try expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24)); | 86 | try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); |
| 87 | var neg32: i32 = -16773785; | 87 | var neg32: i32 = -16773785; |
| 88 | try expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32)); | 88 | try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32)); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | fn vector8() !void { | 91 | fn vector8() !void { |
| 92 | var v = @Vector(2, u8){ 0x12, 0x23 }; | 92 | var v = @Vector(2, u8){ 0x12, 0x23 }; |
| 93 | var result = @bitReverse(u8, v); | 93 | var result = @bitReverse(v); |
| 94 | try expect(result[0] == 0x48); | 94 | try expect(result[0] == 0x48); |
| 95 | try expect(result[1] == 0xc4); | 95 | try expect(result[1] == 0xc4); |
| 96 | } | 96 | } |
| ... | @@ -109,7 +109,7 @@ test "bitReverse vectors u8" { | ... | @@ -109,7 +109,7 @@ test "bitReverse vectors u8" { |
| 109 | 109 | ||
| 110 | fn vector16() !void { | 110 | fn vector16() !void { |
| 111 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; | 111 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; |
| 112 | var result = @bitReverse(u16, v); | 112 | var result = @bitReverse(v); |
| 113 | try expect(result[0] == 0x2c48); | 113 | try expect(result[0] == 0x2c48); |
| 114 | try expect(result[1] == 0xa2c4); | 114 | try expect(result[1] == 0xa2c4); |
| 115 | } | 115 | } |
| ... | @@ -128,7 +128,7 @@ test "bitReverse vectors u16" { | ... | @@ -128,7 +128,7 @@ test "bitReverse vectors u16" { |
| 128 | 128 | ||
| 129 | fn vector24() !void { | 129 | fn vector24() !void { |
| 130 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; | 130 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; |
| 131 | var result = @bitReverse(u24, v); | 131 | var result = @bitReverse(v); |
| 132 | try expect(result[0] == 0x6a2c48); | 132 | try expect(result[0] == 0x6a2c48); |
| 133 | try expect(result[1] == 0xe6a2c4); | 133 | try expect(result[1] == 0xe6a2c4); |
| 134 | } | 134 | } |
| ... | @@ -147,7 +147,7 @@ test "bitReverse vectors u24" { | ... | @@ -147,7 +147,7 @@ test "bitReverse vectors u24" { |
| 147 | 147 | ||
| 148 | fn vector0() !void { | 148 | fn vector0() !void { |
| 149 | var v = @Vector(2, u0){ 0, 0 }; | 149 | var v = @Vector(2, u0){ 0, 0 }; |
| 150 | var result = @bitReverse(u0, v); | 150 | var result = @bitReverse(v); |
| 151 | try expect(result[0] == 0); | 151 | try expect(result[0] == 0); |
| 152 | try expect(result[1] == 0); | 152 | try expect(result[1] == 0); |
| 153 | } | 153 | } |
test/behavior/bugs/10147.zig+3-2| ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); | ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | test "uses correct LLVM builtin" { | 4 | test "uses correct LLVM builtin" { |
| 5 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 5 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 6 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 6 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 7 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 8 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| ... | @@ -12,8 +13,8 @@ test "uses correct LLVM builtin" { | ... | @@ -12,8 +13,8 @@ test "uses correct LLVM builtin" { |
| 12 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; | 13 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; |
| 13 | // The stage1 compiler used to call the same builtin function for both | 14 | // The stage1 compiler used to call the same builtin function for both |
| 14 | // scalar and vector inputs, causing the LLVM module verification to fail. | 15 | // scalar and vector inputs, causing the LLVM module verification to fail. |
| 15 | var a = @clz(u32, x); | 16 | var a = @clz(x); |
| 16 | var b = @clz(u32, y); | 17 | var b = @clz(y); |
| 17 | try std.testing.expectEqual(@as(u6, 31), a); | 18 | try std.testing.expectEqual(@as(u6, 31), a); |
| 18 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); | 19 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); |
| 19 | } | 20 | } |
test/behavior/bugs/2114.zig+1-1| ... | @@ -4,7 +4,7 @@ const expect = std.testing.expect; | ... | @@ -4,7 +4,7 @@ const expect = std.testing.expect; |
| 4 | const math = std.math; | 4 | const math = std.math; |
| 5 | 5 | ||
| 6 | fn ctz(x: anytype) usize { | 6 | fn ctz(x: anytype) usize { |
| 7 | return @ctz(@TypeOf(x), x); | 7 | return @ctz(x); |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | test "fixed" { | 10 | test "fixed" { |
test/behavior/byteswap.zig+10-5| ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | const expect = std.testing.expect; | 3 | const expect = std.testing.expect; |
| 4 | 4 | ||
| 5 | test "@byteSwap integers" { | 5 | test "@byteSwap integers" { |
| 6 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 6 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | 7 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 7 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 8 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 9 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| ... | @@ -46,7 +47,7 @@ test "@byteSwap integers" { | ... | @@ -46,7 +47,7 @@ test "@byteSwap integers" { |
| 46 | ); | 47 | ); |
| 47 | } | 48 | } |
| 48 | fn t(comptime I: type, input: I, expected_output: I) !void { | 49 | 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)); |
| 50 | } | 51 | } |
| 51 | }; | 52 | }; |
| 52 | comptime try ByteSwapIntTest.run(); | 53 | comptime try ByteSwapIntTest.run(); |
| ... | @@ -55,12 +56,13 @@ test "@byteSwap integers" { | ... | @@ -55,12 +56,13 @@ test "@byteSwap integers" { |
| 55 | 56 | ||
| 56 | fn vector8() !void { | 57 | fn vector8() !void { |
| 57 | var v = @Vector(2, u8){ 0x12, 0x13 }; | 58 | var v = @Vector(2, u8){ 0x12, 0x13 }; |
| 58 | var result = @byteSwap(u8, v); | 59 | var result = @byteSwap(v); |
| 59 | try expect(result[0] == 0x12); | 60 | try expect(result[0] == 0x12); |
| 60 | try expect(result[1] == 0x13); | 61 | try expect(result[1] == 0x13); |
| 61 | } | 62 | } |
| 62 | 63 | ||
| 63 | test "@byteSwap vectors u8" { | 64 | test "@byteSwap vectors u8" { |
| 65 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 64 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | 66 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 65 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 67 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 66 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 68 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| ... | @@ -73,12 +75,13 @@ test "@byteSwap vectors u8" { | ... | @@ -73,12 +75,13 @@ test "@byteSwap vectors u8" { |
| 73 | 75 | ||
| 74 | fn vector16() !void { | 76 | fn vector16() !void { |
| 75 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; | 77 | var v = @Vector(2, u16){ 0x1234, 0x2345 }; |
| 76 | var result = @byteSwap(u16, v); | 78 | var result = @byteSwap(v); |
| 77 | try expect(result[0] == 0x3412); | 79 | try expect(result[0] == 0x3412); |
| 78 | try expect(result[1] == 0x4523); | 80 | try expect(result[1] == 0x4523); |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | test "@byteSwap vectors u16" { | 83 | test "@byteSwap vectors u16" { |
| 84 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 82 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | 85 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 83 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 86 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 84 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 87 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| ... | @@ -91,12 +94,13 @@ test "@byteSwap vectors u16" { | ... | @@ -91,12 +94,13 @@ test "@byteSwap vectors u16" { |
| 91 | 94 | ||
| 92 | fn vector24() !void { | 95 | fn vector24() !void { |
| 93 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; | 96 | var v = @Vector(2, u24){ 0x123456, 0x234567 }; |
| 94 | var result = @byteSwap(u24, v); | 97 | var result = @byteSwap(v); |
| 95 | try expect(result[0] == 0x563412); | 98 | try expect(result[0] == 0x563412); |
| 96 | try expect(result[1] == 0x674523); | 99 | try expect(result[1] == 0x674523); |
| 97 | } | 100 | } |
| 98 | 101 | ||
| 99 | test "@byteSwap vectors u24" { | 102 | test "@byteSwap vectors u24" { |
| 103 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 100 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | 104 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 101 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 105 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 102 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 106 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| ... | @@ -109,12 +113,13 @@ test "@byteSwap vectors u24" { | ... | @@ -109,12 +113,13 @@ test "@byteSwap vectors u24" { |
| 109 | 113 | ||
| 110 | fn vector0() !void { | 114 | fn vector0() !void { |
| 111 | var v = @Vector(2, u0){ 0, 0 }; | 115 | var v = @Vector(2, u0){ 0, 0 }; |
| 112 | var result = @byteSwap(u0, v); | 116 | var result = @byteSwap(v); |
| 113 | try expect(result[0] == 0); | 117 | try expect(result[0] == 0); |
| 114 | try expect(result[1] == 0); | 118 | try expect(result[1] == 0); |
| 115 | } | 119 | } |
| 116 | 120 | ||
| 117 | test "@byteSwap vectors u0" { | 121 | test "@byteSwap vectors u0" { |
| 122 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 118 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | 123 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 119 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 124 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 120 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 125 | 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" { | ... | @@ -82,7 +82,7 @@ test "type pun value and struct" { |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | fn bigToNativeEndian(comptime T: type, v: T) T { | 84 | fn 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); |
| 86 | } | 86 | } |
| 87 | test "type pun endianness" { | 87 | test "type pun endianness" { |
| 88 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | 88 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; |
test/behavior/math.zig+7-7| ... | @@ -90,10 +90,11 @@ fn testClzBigInts() !void { | ... | @@ -90,10 +90,11 @@ fn testClzBigInts() !void { |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | fn testOneClz(comptime T: type, x: T) u32 { | 92 | fn testOneClz(comptime T: type, x: T) u32 { |
| 93 | return @clz(T, x); | 93 | return @clz(x); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | test "@clz vectors" { | 96 | test "@clz vectors" { |
| 97 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 97 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 98 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 98 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 99 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 99 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 100 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| ... | @@ -120,7 +121,7 @@ fn testOneClzVector( | ... | @@ -120,7 +121,7 @@ fn testOneClzVector( |
| 120 | x: @Vector(len, T), | 121 | x: @Vector(len, T), |
| 121 | expected: @Vector(len, u32), | 122 | expected: @Vector(len, u32), |
| 122 | ) !void { | 123 | ) !void { |
| 123 | try expectVectorsEqual(@clz(T, x), expected); | 124 | try expectVectorsEqual(@clz(x), expected); |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | fn expectVectorsEqual(a: anytype, b: anytype) !void { | 127 | fn expectVectorsEqual(a: anytype, b: anytype) !void { |
| ... | @@ -151,19 +152,18 @@ fn testCtz() !void { | ... | @@ -151,19 +152,18 @@ fn testCtz() !void { |
| 151 | } | 152 | } |
| 152 | 153 | ||
| 153 | fn testOneCtz(comptime T: type, x: T) u32 { | 154 | fn testOneCtz(comptime T: type, x: T) u32 { |
| 154 | return @ctz(T, x); | 155 | return @ctz(x); |
| 155 | } | 156 | } |
| 156 | 157 | ||
| 157 | test "@ctz vectors" { | 158 | test "@ctz vectors" { |
| 159 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 158 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 160 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 159 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 161 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 160 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 162 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 161 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 163 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 162 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | 164 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| 163 | 165 | ||
| 164 | if ((builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) and | 166 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { |
| 165 | builtin.cpu.arch == .aarch64) | ||
| 166 | { | ||
| 167 | // This regressed with LLVM 14: | 167 | // This regressed with LLVM 14: |
| 168 | // https://github.com/ziglang/zig/issues/12013 | 168 | // https://github.com/ziglang/zig/issues/12013 |
| 169 | return error.SkipZigTest; | 169 | return error.SkipZigTest; |
| ... | @@ -187,7 +187,7 @@ fn testOneCtzVector( | ... | @@ -187,7 +187,7 @@ fn testOneCtzVector( |
| 187 | x: @Vector(len, T), | 187 | x: @Vector(len, T), |
| 188 | expected: @Vector(len, u32), | 188 | expected: @Vector(len, u32), |
| 189 | ) !void { | 189 | ) !void { |
| 190 | try expectVectorsEqual(@ctz(T, x), expected); | 190 | try expectVectorsEqual(@ctz(x), expected); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | test "const number literal" { | 193 | test "const number literal" { |
test/behavior/popcount.zig+15-14| ... | @@ -18,53 +18,54 @@ test "@popCount 128bit integer" { | ... | @@ -18,53 +18,54 @@ test "@popCount 128bit integer" { |
| 18 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 18 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 19 | 19 | ||
| 20 | comptime { | 20 | comptime { |
| 21 | try expect(@popCount(u128, @as(u128, 0b11111111000110001100010000100001000011000011100101010001)) == 24); | 21 | try expect(@popCount(@as(u128, 0b11111111000110001100010000100001000011000011100101010001)) == 24); |
| 22 | try expect(@popCount(i128, @as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24); | 22 | try expect(@popCount(@as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | { | 25 | { |
| 26 | var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; | 26 | var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; |
| 27 | try expect(@popCount(u128, x) == 24); | 27 | try expect(@popCount(x) == 24); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | try expect(@popCount(i128, @as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24); | 30 | try expect(@popCount(@as(i128, 0b11111111000110001100010000100001000011000011100101010001)) == 24); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | fn testPopCountIntegers() !void { | 33 | fn testPopCountIntegers() !void { |
| 34 | { | 34 | { |
| 35 | var x: u32 = 0xffffffff; | 35 | var x: u32 = 0xffffffff; |
| 36 | try expect(@popCount(u32, x) == 32); | 36 | try expect(@popCount(x) == 32); |
| 37 | } | 37 | } |
| 38 | { | 38 | { |
| 39 | var x: u5 = 0x1f; | 39 | var x: u5 = 0x1f; |
| 40 | try expect(@popCount(u5, x) == 5); | 40 | try expect(@popCount(x) == 5); |
| 41 | } | 41 | } |
| 42 | { | 42 | { |
| 43 | var x: u32 = 0xaa; | 43 | var x: u32 = 0xaa; |
| 44 | try expect(@popCount(u32, x) == 4); | 44 | try expect(@popCount(x) == 4); |
| 45 | } | 45 | } |
| 46 | { | 46 | { |
| 47 | var x: u32 = 0xaaaaaaaa; | 47 | var x: u32 = 0xaaaaaaaa; |
| 48 | try expect(@popCount(u32, x) == 16); | 48 | try expect(@popCount(x) == 16); |
| 49 | } | 49 | } |
| 50 | { | 50 | { |
| 51 | var x: u32 = 0xaaaaaaaa; | 51 | var x: u32 = 0xaaaaaaaa; |
| 52 | try expect(@popCount(u32, x) == 16); | 52 | try expect(@popCount(x) == 16); |
| 53 | } | 53 | } |
| 54 | { | 54 | { |
| 55 | var x: i16 = -1; | 55 | var x: i16 = -1; |
| 56 | try expect(@popCount(i16, x) == 16); | 56 | try expect(@popCount(x) == 16); |
| 57 | } | 57 | } |
| 58 | { | 58 | { |
| 59 | var x: i8 = -120; | 59 | var x: i8 = -120; |
| 60 | try expect(@popCount(i8, x) == 2); | 60 | try expect(@popCount(x) == 2); |
| 61 | } | 61 | } |
| 62 | comptime { | 62 | comptime { |
| 63 | try expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2); | 63 | try expect(@popCount(@bitCast(u8, @as(i8, -120))) == 2); |
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | test "@popCount vectors" { | 67 | test "@popCount vectors" { |
| 68 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; | ||
| 68 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | 69 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| 69 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 70 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 70 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 71 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| ... | @@ -79,13 +80,13 @@ fn testPopCountVectors() !void { | ... | @@ -79,13 +80,13 @@ fn testPopCountVectors() !void { |
| 79 | { | 80 | { |
| 80 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; | 81 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; |
| 81 | const expected = [1]u6{32} ** 8; | 82 | const expected = [1]u6{32} ** 8; |
| 82 | const result: [8]u6 = @popCount(u32, x); | 83 | const result: [8]u6 = @popCount(x); |
| 83 | try expect(std.mem.eql(u6, &expected, &result)); | 84 | try expect(std.mem.eql(u6, &expected, &result)); |
| 84 | } | 85 | } |
| 85 | { | 86 | { |
| 86 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; | 87 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; |
| 87 | const expected = [1]u5{16} ** 8; | 88 | const expected = [1]u5{16} ** 8; |
| 88 | const result: [8]u5 = @popCount(i16, x); | 89 | const result: [8]u5 = @popCount(x); |
| 89 | try expect(std.mem.eql(u5, &expected, &result)); | 90 | try expect(std.mem.eql(u5, &expected, &result)); |
| 90 | } | 91 | } |
| 91 | } | 92 | } |
test/cases/compile_errors/errors_in_for_loop_bodies_are_propagated.zig+2-2| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | pub export fn entry() void { | 1 | pub export fn entry() void { |
| 2 | var arr: [100]u8 = undefined; | 2 | var arr: [100]u8 = undefined; |
| 3 | for (arr) |bits| _ = @popCount(bits); | 3 | for (arr) |bits| _ = @popCount(u8, bits); |
| 4 | } | 4 | } |
| 5 | 5 | ||
| 6 | // error | 6 | // error |
| 7 | // backend=stage2 | 7 | // backend=stage2 |
| 8 | // target=native | 8 | // target=native |
| 9 | // | 9 | // |
| 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 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | export fn entry(x: f32) u32 { | 1 | export fn entry(x: f32) u32 { |
| 2 | return @popCount(f32, x); | 2 | return @popCount(x); |
| 3 | } | 3 | } |
| 4 | 4 | ||
| 5 | // error | 5 | // error |
| 6 | // backend=stage2 | 6 | // backend=stage2 |
| 7 | // target=native | 7 | // target=native |
| 8 | // | 8 | // |
| 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( | ... | @@ -299,11 +299,11 @@ fn renderBitEnum( |
| 299 | for (enumerants) |enumerant, i| { | 299 | for (enumerants) |enumerant, i| { |
| 300 | if (enumerant.value != .bitflag) return error.InvalidRegistry; | 300 | if (enumerant.value != .bitflag) return error.InvalidRegistry; |
| 301 | const value = try parseHexInt(enumerant.value.bitflag); | 301 | const value = try parseHexInt(enumerant.value.bitflag); |
| 302 | if (@popCount(u32, value) == 0) { | 302 | if (@popCount(value) == 0) { |
| 303 | continue; // Skip 'none' items | 303 | continue; // Skip 'none' items |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | std.debug.assert(@popCount(u32, value) == 1); | 306 | std.debug.assert(@popCount(value) == 1); |
| 307 | 307 | ||
| 308 | var bitpos = std.math.log2_int(u32, value); | 308 | var bitpos = std.math.log2_int(u32, value); |
| 309 | if (flags_by_bitpos[bitpos]) |*existing| { | 309 | 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) | ... | @@ -389,7 +389,7 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) |
| 389 | const S = struct { | 389 | const S = struct { |
| 390 | fn endianSwap(x: anytype) @TypeOf(x) { | 390 | fn endianSwap(x: anytype) @TypeOf(x) { |
| 391 | if (endian != native_endian) { | 391 | if (endian != native_endian) { |
| 392 | return @byteSwap(@TypeOf(x), x); | 392 | return @byteSwap(x); |
| 393 | } else { | 393 | } else { |
| 394 | return x; | 394 | return x; |
| 395 | } | 395 | } |