Implement partially ordered operator precedence

This commit is contained in:
CMDRZero authored and Alex Rønne Petersen committed 2026-10-22 12:21:43 +02:00
1 parent 16894c484c
commit 64e4f9db8f
108 files changed
+722 -406

No files matched your search

+2 -2
View File
@@ -355,7 +355,7 @@ fn pow10f(x: f32) callconv(.c) f32 {
fn rint(x: f64) callconv(.c) f64 {
const toint: f64 = 1.0 / math.floatEps(f64);
const a: u64 = @bitCast(x);
const e = a >> 52 & 0x7ff;
const e = (a >> 52) & 0x7ff;
const s = a >> 63;
var y: f64 = undefined;
@@ -376,7 +376,7 @@ fn rint(x: f64) callconv(.c) f64 {
fn rintf(x: f32) callconv(.c) f32 {
const toint: f32 = 1.0 / math.floatEps(f32);
const a: u32 = @bitCast(x);
const e = a >> 23 & 0xff;
const e = (a >> 23) & 0xff;
const s = a >> 31;
var y: f32 = undefined;
+6 -6
View File
@@ -30,7 +30,7 @@ var lcg: Lcg = .init(0, default_multiplier, default_addend);
var seed48_xi: [3]c_ushort = undefined;
fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {
const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
const next_xi = separate_lcg.next();
@@ -40,7 +40,7 @@ fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {
}
fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
const next_xi = separate_lcg.next();
@@ -50,7 +50,7 @@ fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
}
fn nrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
const next_xi = separate_lcg.next();
@@ -74,14 +74,14 @@ fn mrand48() callconv(.c) c_long {
// 0..3 is `Xi`, 3..6 is `a`, 6 is `c`
// first low 16-bits, then mid, then high.
fn lcong48(param: *[7]c_ushort) callconv(.c) void {
lcg.xi = (@as(u48, @as(u16, @truncate(param[0]))) | (@as(u48, @as(u16, @truncate(param[1])))) << 16) | (@as(u48, @as(u16, @truncate(param[2]))) << 32);
lcg.a = (@as(u48, @as(u16, @truncate(param[3]))) | (@as(u48, @as(u16, @truncate(param[4])))) << 16) | (@as(u48, @as(u16, @truncate(param[5]))) << 32);
lcg.xi = (@as(u48, @as(u16, @truncate(param[0]))) | ((@as(u48, @as(u16, @truncate(param[1])))) << 16)) | (@as(u48, @as(u16, @truncate(param[2]))) << 32);
lcg.a = (@as(u48, @as(u16, @truncate(param[3]))) | ((@as(u48, @as(u16, @truncate(param[4])))) << 16)) | (@as(u48, @as(u16, @truncate(param[5]))) << 32);
lcg.c = @as(u16, @truncate(param[6]));
}
fn seed48(seed16v: *[3]c_ushort) callconv(.c) *[3]c_ushort {
seed48_xi = .{ @truncate(lcg.xi & 0xFFFF), @truncate((lcg.xi >> 16) & 0xFFFF), @truncate((lcg.xi >> 32) & 0xFFFF) };
const xi = (@as(u48, @as(u16, @truncate(seed16v[0]))) | (@as(u48, @as(u16, @truncate(seed16v[1])))) << 16) | (@as(u48, @as(u16, @truncate(seed16v[2]))) << 32);
const xi = (@as(u48, @as(u16, @truncate(seed16v[0]))) | ((@as(u48, @as(u16, @truncate(seed16v[1])))) << 16)) | (@as(u48, @as(u16, @truncate(seed16v[2]))) << 32);
lcg = .init(xi, default_multiplier, default_addend);
return &seed48_xi;
}
+1 -1
View File
@@ -45,7 +45,7 @@ pub fn make(
try lowerZigArgs(arena, compile_index, maker, progress_node, &argv, false);
const incremental = conf_comp.flags4.incremental.toBool() orelse graph.incremental == true;
const incremental = conf_comp.flags4.incremental.toBool() orelse graph.incremental orelse false;
const opt_cache_digest = Step.evalZigProcess(
compile_index,
+3 -3
View File
@@ -287,7 +287,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
const gnuc_version = comp.langopts.gnuc_version orelse comp.langopts.emulate.defaultGccVersion();
if (gnuc_version > 0) {
try w.print("#define __GNUC__ {d}\n", .{gnuc_version / 10_000});
try w.print("#define __GNUC_MINOR__ {d}\n", .{gnuc_version / 100 % 100});
try w.print("#define __GNUC_MINOR__ {d}\n", .{(gnuc_version / 100) % 100});
try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{gnuc_version % 100});
}
@@ -962,7 +962,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
try define(w, "__ARM_ARCH_EXT_IDIV__");
}
var sat = false;
if (arm_version == 6 and !target.cpu.has(.arm, .mclass) or arm_version > 6) {
if ((arm_version == 6 and !target.cpu.has(.arm, .mclass)) or arm_version > 6) {
try define(w, "__ARM_FEATURE_SAT");
sat = true;
}
@@ -2856,7 +2856,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {
if (buf[j] == alphabet[0]) buf[j - 1] = alphabet[(idx + 1) % alen] else break;
}
}
try std.testing.expect(source_count == std.math.powi(usize, alen, alen) catch unreachable);
try std.testing.expect(source_count == (std.math.powi(usize, alen, alen) catch unreachable));
}
test "ignore BOM at beginning of file" {
+1 -1
View File
@@ -1373,7 +1373,7 @@ fn getOutFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) !
if (d.only_preprocess_and_compile) ".s" else d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch),
};
return d.output_name orelse
mem.print(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args);
(mem.print(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args));
}
return d.getRandomFilename(buf, d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch));
+1 -1
View File
@@ -7084,7 +7084,7 @@ pub const Result = struct {
const b_child_qt = b.qt.get(p.comp, .pointer).?.child;
if (!a_child_qt.eql(b_child_qt, p.comp)) try p.err(tok, .incompatible_pointers, .{ a.qt, b.qt });
if (a.qt.childType(p.comp).sizeofOrNull(p.comp) orelse 1 == 0) try p.err(tok, .subtract_pointers_zero_elem_size, .{a.qt.childType(p.comp)});
if ((a.qt.childType(p.comp).sizeofOrNull(p.comp) orelse 1) == 0) try p.err(tok, .subtract_pointers_zero_elem_size, .{a.qt.childType(p.comp)});
a.qt = p.comp.type_store.ptrdiff;
}
+3 -3
View File
@@ -310,13 +310,13 @@ pub const InitOptions = struct {
};
pub fn init(comp: *Compilation, options: InitOptions) !Preprocessor {
const source_epoch: SourceEpoch = options.source_epoch orelse comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
const source_epoch: SourceEpoch = options.source_epoch orelse (comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
error.InvalidEpoch => blk: {
const diagnostic: Diagnostic = .invalid_source_epoch;
try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null });
break :blk .default;
},
};
});
var pp: Preprocessor = .{
.comp = comp,
@@ -3882,7 +3882,7 @@ pub fn prettyPrintTokens(pp: *Preprocessor, w: *std.Io.Writer, macro_dump_mode:
},
.keyword_pragma => {
const pragma_name = pp.expandedSlice(pp.tokens.get(i + 1));
const end_idx = mem.findScalarPos(Token.Id, tok_ids, i, .nl) orelse i + 1;
const end_idx = mem.findScalarPos(Token.Id, tok_ids, i, .nl) orelse (i + 1);
const pragma_len = @as(u32, @intCast(end_idx)) - i;
if (pp.comp.getPragma(pragma_name)) |prag| {
+1 -1
View File
@@ -323,7 +323,7 @@ fn binaryExpr(p: *Parser, min_prec: Token.Precedence, eval: bool) Error!?Value {
const else_res = try p.binaryExpr(op_prec, eval_else) orelse return null;
lhs = if (lhs.toBool()) rhs else else_res;
if (eval and rhs == .unsigned or else_res == .unsigned) {
if ((eval and rhs == .unsigned) or else_res == .unsigned) {
try lhs.toUnsigned(p, operator, "right");
}
},
+2 -2
View File
@@ -492,7 +492,7 @@ pub fn isXidStart(c: u21) bool {
assert(c > 0x7F);
const idx = c / 8 / tables.chunk;
const chunk: usize = if (idx < tables.trie_start.len) tables.trie_start[idx] else 0;
const offset = chunk * tables.chunk / 2 + c / 8 % tables.chunk;
const offset = chunk * tables.chunk / 2 + (c / 8) % tables.chunk;
return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;
}
@@ -500,7 +500,7 @@ pub fn isXidContinue(c: u21) bool {
assert(c > 0x7F);
const idx = c / 8 / tables.chunk;
const chunk: usize = if (idx < tables.trie_continue.len) tables.trie_continue[idx] else 0;
const offset = chunk * tables.chunk / 2 + c / 8 % tables.chunk;
const offset = chunk * tables.chunk / 2 + (c / 8) % tables.chunk;
return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;
}
+1 -1
View File
@@ -324,7 +324,7 @@ const SysVContext = struct {
// On Clang, the alignment requested by annotations is not respected if it is
// larger than the value of #pragma pack. See test case 0083.
if (annotation_alignment <= self.max_field_align_bits orelse std.math.maxInt(u29)) {
if (annotation_alignment <= (self.max_field_align_bits orelse std.math.maxInt(u29))) {
field_align_bits = @max(field_align_bits, annotation_alignment);
}
// On Clang, if there are no packing annotations and the field would cross a
+1 -1
View File
@@ -11,7 +11,7 @@ pub inline fn absv(comptime ST: type, a: ST) ST {
// compute the integer absolute value (abs) without branching
var x: ST = a;
const N: UT = @bitSizeOf(ST);
const sign: ST = a >> N - 1;
const sign: ST = a >> (N - 1);
x +%= sign;
x ^= sign;
if (x < 0) @panic("integer overflow");
+1 -1
View File
@@ -259,7 +259,7 @@ inline fn addf3(comptime T: type, a: T, b: T) T {
// adjust the exponent:
if (aSignificand & (integerBit << 4) != 0) {
const sticky = aSignificand & 1;
aSignificand = aSignificand >> 1 | sticky;
aSignificand = (aSignificand >> 1) | sticky;
aExponent += 1;
}
}
+1 -1
View File
@@ -241,7 +241,7 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
while (true) {
const old = @as(T, @truncate((wide_old & mask) >> inner_shift));
const new = update(val, old);
const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);
const wide_new = (wide_old & ~mask) | (@as(WideAtomic, new) << inner_shift);
if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .seq_cst, .seq_cst)) |new_wide_old| {
wide_old = new_wide_old;
} else {
+4 -4
View File
@@ -130,13 +130,13 @@ fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f32(a, b) == .lt);
}
fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f32(a, b) orelse .gt != .gt);
return @intFromBool((cmp_f32(a, b) orelse .gt) != .gt);
}
fn __gesf2(a: compiler_rt.f32.Abi, b: compiler_rt.f32.Abi) callconv(.c) Order {
return cmp_f32(compiler_rt.f32.fromAbi(a), compiler_rt.f32.fromAbi(b)) orelse .lt;
}
fn __aeabi_fcmpge(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f32(a, b) orelse .lt != .lt);
return @intFromBool((cmp_f32(a, b) orelse .lt) != .lt);
}
fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f32(a, b) == .gt);
@@ -164,13 +164,13 @@ fn __aeabi_dcmplt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f64(a, b) == .lt);
}
fn __aeabi_dcmple(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f64(a, b) orelse .gt != .gt);
return @intFromBool((cmp_f64(a, b) orelse .gt) != .gt);
}
fn __gedf2(a: compiler_rt.f64.Abi, b: compiler_rt.f64.Abi) callconv(.c) Order {
return cmp_f64(compiler_rt.f64.fromAbi(a), compiler_rt.f64.fromAbi(b)) orelse .lt;
}
fn __aeabi_dcmpge(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f64(a, b) orelse .lt != .lt);
return @intFromBool((cmp_f64(a, b) orelse .lt) != .lt);
}
fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
return @intFromBool(cmp_f64(a, b) == .gt);
+8 -8
View File
@@ -119,12 +119,12 @@ pub fn div_f64(a: f64, b: f64) f64 {
// with each iteration, so after three iterations, we have about 28 binary
// digits of accuracy.
var correction32: u32 = undefined;
correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
// recip32 might have overflowed to exactly zero in the preceding
// computation if the high word of b is exactly 1.0. This would sabotage
@@ -137,10 +137,10 @@ pub fn div_f64(a: f64, b: f64) f64 {
const q63blo: u32 = @truncate(bSignificand << 11);
var correction: u64 = undefined;
var reciprocal: u64 = undefined;
correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
correction = ~(@as(u64, recip32) *% q31b +% ((@as(u64, recip32) *% q63blo) >> 32)) +% 1;
const cHi: u32 = @truncate(correction >> 32);
const cLo: u32 = @truncate(correction);
reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
reciprocal = @as(u64, recip32) *% cHi +% ((@as(u64, recip32) *% cLo) >> 32);
// We already adjusted the 32-bit estimate, now we need to adjust the final
// 64-bit reciprocal estimate downward to ensure that it is strictly smaller
+7 -7
View File
@@ -126,12 +126,12 @@ pub fn div_f32(a: f32, b: f32) f32 {
// with each iteration, so after three iterations, we have about 28 binary
// digits of accuracy.
var correction: u32 = undefined;
correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
// Exhaustive testing shows that the error in reciprocal after three steps
// is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
@@ -153,7 +153,7 @@ pub fn div_f32(a: f32, b: f32) f32 {
// is the error in the reciprocal of b scaled by the maximum
// possible value of a. As a consequence of this error bound,
// either q or nextafter(q) is the correctly rounded
var quotient: Z = @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32);
var quotient: Z = @truncate((@as(u64, reciprocal) *% (aSignificand << 1)) >> 32);
// Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
// In either case, we are going to compute a residual of the form
+10 -10
View File
@@ -119,16 +119,16 @@ pub fn div_f128(a: f128, b: f128) f128 {
// This doubles the number of correct binary digits in the approximation
// with each iteration.
var correction64: u64 = undefined;
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
// The reciprocal may have overflowed to zero if the upper half of b is
// exactly 1.0. This would sabatoge the full-width final stage of the
+10 -10
View File
@@ -102,16 +102,16 @@ pub fn div_f80(a: f80, b: f80) f80 {
// This doubles the number of correct binary digits in the approximation
// with each iteration.
var correction64: u64 = undefined;
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
// The reciprocal may have overflowed to zero if the upper half of b is
// exactly 1.0. This would sabatoge the full-width final stage of the
+1 -1
View File
@@ -251,7 +251,7 @@ fn setThreadPointer(addr: usize) void {
// Update the %gs selector
asm volatile ("movl %[gs_val], %%gs"
:
: [gs_val] "r" (gdt_entry_number << 3 | 3),
: [gs_val] "r" ((gdt_entry_number << 3) | 3),
);
},
.x86_64 => {
+2 -2
View File
@@ -165,7 +165,7 @@ pub fn f128_floatCast_f80(a: f80) f128 {
}
// Apply the signbit to (dst_t)abs(a).
const result: u128 = abs_result | @as(u128, sign) << (dst_bits - 16);
const result: u128 = abs_result | (@as(u128, sign) << (dst_bits - 16));
return @bitCast(result);
}
@@ -232,7 +232,7 @@ inline fn extendf(comptime dst_t: type, comptime src_t: type, f: src_t) dst_t {
}
// Apply the signbit to (dst_t)abs(a).
const result: dst_rep_t = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);
const result: dst_rep_t = absResult | (@as(dst_rep_t, sign) << (dstBits - srcBits));
return @bitCast(result);
}
+4 -4
View File
@@ -141,13 +141,13 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {
const m = (@as(U, 1) << @intCast(mantissa - e)) - 1;
if (u & m == 0) return x;
if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> bits - 1 == @intFromBool(op == .floor)) u += m;
if (u >> (bits - 1) == @intFromBool(op == .floor)) u += m;
return @bitCast(u & ~m);
} else {
if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
return switch (op) {
.floor => if (u >> bits - 1 == 0) 0.0 else if (u << 1 != 0) -1.0 else x,
.ceil => if (u >> bits - 1 != 0) -0.0 else if (u << 1 != 0) 1.0 else x,
.floor => if (u >> (bits - 1) == 0) 0.0 else if (u << 1 != 0) -1.0 else x,
.ceil => if (u >> (bits - 1) != 0) -0.0 else if (u << 1 != 0) 1.0 else x,
};
}
},
@@ -155,7 +155,7 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {
const e = (u >> mantissa) & mask;
if (e >= bias + math.floatFractionalBits(T) or x == 0) return x;
const positive = u >> @bitSizeOf(T) - 1 == 0;
const positive = u >> (@bitSizeOf(T) - 1) == 0;
const y: T = if (positive)
x + C - C - x
else
+2 -2
View File
@@ -204,8 +204,8 @@ pub fn fmod_f128(a: f128, b: f128) f128 {
}
// OR in extra non-stored mantissa digit
var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | (1 << 48);
const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | (1 << 48);
var lowA: u64 = aPtr_u64[low_index];
const lowB: u64 = bPtr_u64[low_index];
+1 -1
View File
@@ -237,7 +237,7 @@ fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {
lo.* = (hi.* << @intCast(typeWidth -% count)) | (lo.* >> @intCast(count));
hi.* = hi.* >> @intCast(count);
} else if (count < 2 * typeWidth) {
inexact = (hi.* << @intCast(2 * typeWidth -% count) | lo.*) != 0;
inexact = ((hi.* << @intCast(2 * typeWidth -% count)) | lo.*) != 0;
lo.* = hi.* >> @intCast(count -% typeWidth);
hi.* = 0;
} else {
+1 -1
View File
@@ -37,7 +37,7 @@ pub fn rem_pio2l(comptime T: type, x: T, y: *[2]T) i32 {
const se = ld.signExponent(x_val);
const top = ld.mantissaTop(x_val);
const lhs = (@as(u32, se & 0x7fff) << 16) | top;
const rhs: u32 = ((0x3fff + 25) << 16) | 0x921f >> 1 | 0x8000;
const rhs: u32 = ((0x3fff + 25) << 16) | (0x921f >> 1) | 0x8000;
return lhs < rhs;
}
+5 -5
View File
@@ -523,15 +523,15 @@ const rsqrt_tab: [128]u16 = .{
};
inline fn mul16(a: u16, b: u16) u16 {
return @intCast(@as(u32, a) * b >> 16);
return @intCast((@as(u32, a) * b) >> 16);
}
inline fn mul32(a: u32, b: u32) u32 {
return @intCast(@as(u64, a) * b >> 32);
return @intCast((@as(u64, a) * b) >> 32);
}
inline fn mul64(a: u64, b: u64) u64 {
return @intCast(@as(u128, a) * b >> 64);
return @intCast((@as(u128, a) * b) >> 64);
}
inline fn mul80(a: u80, b: u80) u80 {
@@ -539,7 +539,7 @@ inline fn mul80(a: u80, b: u80) u80 {
const alo = a & 0xFF_FFFF_FFFF;
const bhi = b >> 40;
const blo = b & 0xFF_FFFF_FFFF;
return ahi * bhi + (ahi * blo >> 40) + (alo * bhi >> 40);
return ahi * bhi + ((ahi * blo) >> 40) + ((alo * bhi) >> 40);
}
inline fn mul128(a: u128, b: u128) u128 {
@@ -547,7 +547,7 @@ inline fn mul128(a: u128, b: u128) u128 {
const alo = a & 0xFFFF_FFFF_FFFF_FFFF;
const bhi = b >> 64;
const blo = b & 0xFFFF_FFFF_FFFF_FFFF;
return ahi * bhi + (ahi * blo >> 64) + (alo * bhi >> 64);
return ahi * bhi + ((ahi * blo) >> 64) + ((alo * bhi) >> 64);
}
inline fn mul80_tail(a: u80, b: u80) u80 {
+3 -3
View File
@@ -279,7 +279,7 @@ inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
absResult = 0;
} else {
const sticky: src_rep_t = @intFromBool(significand << @intCast(srcBits - shift) != 0);
const denormalizedSignificand: src_rep_t = significand >> @intCast(shift) | sticky;
const denormalizedSignificand: src_rep_t = (significand >> @intCast(shift)) | sticky;
absResult = @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits));
const roundBits: src_rep_t = denormalizedSignificand & roundMask;
if (roundBits > halfway) {
@@ -362,7 +362,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
abs_result = 0;
} else {
const sticky = @intFromBool(a_rep.fraction << @intCast(shift) != 0);
const denormalized_significand = a_rep.fraction >> @intCast(shift) | sticky;
const denormalized_significand = (a_rep.fraction >> @intCast(shift)) | sticky;
abs_result = @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits));
const round_bits = denormalized_significand & round_mask;
if (round_bits > halfway) {
@@ -375,7 +375,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
}
}
const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16;
const result align(@alignOf(dst_t)) = abs_result | (@as(dst_rep_t, sign) << (dst_bits - 16));
return @bitCast(result);
}
+2 -2
View File
@@ -1931,10 +1931,10 @@ const BatchWaiter = struct {
fn batchAwaitAsync(userdata: ?*anyopaque, batch: *Io.Batch) Io.Cancelable!void {
const ev: *Evented = @ptrCast(@alignCast(userdata));
const queue = ev.batchDrainSubmitted(batch, false) catch |err| switch (err) {
const queue = (ev.batchDrainSubmitted(batch, false) catch |err| switch (err) {
error.ConcurrencyUnavailable => unreachable, // passed concurrency=false
error.Canceled => |e| return e,
} orelse return;
}) orelse return;
if (batch.pending.head == .none) return;
var waiter: BatchWaiter = .{
.sleeper = .init(ev.queue, Thread.current().currentFiber()),
+1 -1
View File
@@ -164,7 +164,7 @@ pub const InitError = Allocator.Error || CreateFileDescriptorError;
pub fn init(k: *Kqueue, gpa: Allocator, options: InitOptions) !void {
assert(options.n_threads != 0);
const n_threads = @max(1, options.n_threads orelse std.Thread.getCpuCount() catch 1);
const n_threads = @max(1, options.n_threads orelse (std.Thread.getCpuCount() catch 1));
const threads_size = n_threads * @sizeOf(Thread);
const idle_stack_end_offset = std.mem.alignForward(usize, threads_size + idle_stack_size, std.heap.page_size_max);
const allocated_slice = try gpa.alignedAlloc(u8, .of(Thread), idle_stack_end_offset);
+1 -1
View File
@@ -36,7 +36,7 @@ fn put(io: Io, queue: *Io.Queue(u8)) void {
}
fn get(io: Io, queue: *Io.Queue(u8)) void {
assert(queue.getOneUncancelable(io) catch unreachable == 42);
assert((queue.getOneUncancelable(io) catch unreachable) == 42);
}
test "concurrent vs concurrent prevents deadlock via oversubscription" {
+1 -1
View File
@@ -1827,7 +1827,7 @@ pub fn printFloatHex(w: *Writer, value: anytype, case: std.fmt.Case, opt_precisi
// Restore the alignment.
mantissa <<= @as(std.math.Log2Int(TU), @intCast((mantissa_digits - precision) * 4));
const overflow = mantissa & (1 << 1 + mantissa_digits * 4) != 0;
const overflow = mantissa & (1 << (1 + mantissa_digits * 4)) != 0;
// Prefer a normalized result in case of overflow.
if (overflow) {
mantissa >>= 1;
+1 -1
View File
@@ -230,7 +230,7 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [
i += 1 + label_len;
} else {
return .{
len orelse i - start_i + 1,
len orelse (i - start_i + 1),
try .init(dest[0..dest_i]),
};
}
+3 -3
View File
@@ -148,7 +148,7 @@ pub const Base64Encoder = struct {
if (idx + 2 < source.len) {
dest[out_idx] = encoder.alphabet_chars[source[idx] >> 2];
dest[out_idx + 1] = encoder.alphabet_chars[((source[idx] & 0x3) << 4) | (source[idx + 1] >> 4)];
dest[out_idx + 2] = encoder.alphabet_chars[(source[idx + 1] & 0xf) << 2 | (source[idx + 2] >> 6)];
dest[out_idx + 2] = encoder.alphabet_chars[((source[idx + 1] & 0xf) << 2) | (source[idx + 2] >> 6)];
dest[out_idx + 3] = encoder.alphabet_chars[source[idx + 2] & 0x3f];
out_idx += 4;
} else if (idx + 1 < source.len) {
@@ -282,7 +282,7 @@ pub const Base64Decoder = struct {
dest_idx += 1;
}
}
if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) {
if (acc_len > 4 or (acc & ((@as(u12, 1) << acc_len) - 1)) != 0) {
return error.InvalidPadding;
}
if (leftover_idx == null) return;
@@ -357,7 +357,7 @@ pub const Base64DecoderWithIgnore = struct {
dest_idx += 1;
}
}
if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) {
if (acc_len > 4 or (acc & ((@as(u12, 1) << acc_len) - 1)) != 0) {
return error.InvalidPadding;
}
const padding_len = acc_len / 2;
+4 -4
View File
@@ -468,11 +468,11 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type {
if (start_mask_index == end_mask_index) {
var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
var mask2 = std.math.boolMask(MaskInt, true) >> (mask_len - 1) - (end_bit - 1);
var mask2 = std.math.boolMask(MaskInt, true) >> ((mask_len - 1) - (end_bit - 1));
self.masks[start_mask_index] &= ~(mask1 & mask2);
mask1 = std.math.boolMask(MaskInt, value) << start_bit;
mask2 = std.math.boolMask(MaskInt, value) >> (mask_len - 1) - (end_bit - 1);
mask2 = std.math.boolMask(MaskInt, value) >> ((mask_len - 1) - (end_bit - 1));
self.masks[start_mask_index] |= mask1 & mask2;
} else {
var bulk_mask_index: usize = undefined;
@@ -875,11 +875,11 @@ pub const Dynamic = struct {
if (start_mask_index == end_mask_index) {
var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
var mask2 = std.math.boolMask(MaskInt, true) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1);
var mask2 = std.math.boolMask(MaskInt, true) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1));
self.masks[start_mask_index] &= ~(mask1 & mask2);
mask1 = std.math.boolMask(MaskInt, value) << start_bit;
mask2 = std.math.boolMask(MaskInt, value) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1);
mask2 = std.math.boolMask(MaskInt, value) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1));
self.masks[start_mask_index] |= mask1 & mask2;
} else {
var bulk_mask_index: usize = undefined;
+1 -1
View File
@@ -2035,7 +2035,7 @@ pub const ArchiveMemberHeader = extern struct {
if (trim.len == 0) return error.BadName;
return if (trim[0] == '/') name: {
if (trim.len == 1 or
trim.len == 2 and trim[1] == '/')
(trim.len == 2 and trim[1] == '/'))
break :name trim;
const offset = std.fmt.parseUnsigned(u50, trim[1..], 10) catch
+2 -2
View File
@@ -1333,8 +1333,8 @@ const huffman = struct {
const incomplete_allowed = smith.value(bool);
while (nfreqs < @as(u8, @intFromBool(!incomplete_allowed)) + 1 or
nfreqs != freqs_buf.len and freqs_limit != 0 and
smith.eosWeightedSimple(15, 1))
(nfreqs != freqs_buf.len and freqs_limit != 0 and
smith.eosWeightedSimple(15, 1)))
{
const f = smith.valueWeighted(u16, &.{
.rangeAtMost(u16, 0, @min(31, freqs_limit), @max(freqs_limit, 1)),
+1 -1
View File
@@ -728,7 +728,7 @@ pub const Aes256 = struct {
// constants
// Rijndael's irreducible polynomial.
const poly: u9 = 1 << 8 | 1 << 4 | 1 << 3 | 1 << 1 | 1 << 0; // x⁸ + x⁴ + x³ + x + 1
const poly: u9 = (1 << 8) | (1 << 4) | (1 << 3) | (1 << 1) | (1 << 0); // x⁸ + x⁴ + x³ + x + 1
// Powers of x mod poly in GF(2).
const powx = init: {
+1 -1
View File
@@ -29,7 +29,7 @@ pub const hex = struct {
const c: u16 = v & 0xf;
const off = if (case == .upper) 32 else 0;
const x =
((87 - off + c + (((c -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff) << 8 |
(((87 - off + c + (((c -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff) << 8) |
((87 - off + b + (((b -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff);
encoded[i * 2] = @truncate(x);
encoded[i * 2 + 1] = @truncate(x >> 8);
+1 -1
View File
@@ -1264,7 +1264,7 @@ const Poly = struct {
const b1 = @as(i16, buf[3 * i + 1]);
const b2 = @as(i16, buf[3 * i + 2]);
ret.cs[2 * i] = b0 | ((b1 & 0xf) << 8);
ret.cs[2 * i + 1] = (b1 >> 4) | b2 << 4;
ret.cs[2 * i + 1] = (b1 >> 4) | (b2 << 4);
}
return ret;
}
+1 -1
View File
@@ -82,7 +82,7 @@ fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16)
fn integerify(b: []align(16) const u32, r: u30) u64 {
const j = (2 * r - 1) * 16;
return @as(u64, b[j]) | @as(u64, b[j + 1]) << 32;
return @as(u64, b[j]) | (@as(u64, b[j + 1]) << 32);
}
fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
+1 -1
View File
@@ -557,7 +557,7 @@ fn Sha2x64(comptime iv: Iv64, digest_bits: comptime_int) type {
}
if (digest_bits % 8 != 0) @compileError("impl doesn't support non-byte digest_len");
const bytes_left = digest_bits / 8 % 8;
const bytes_left = (digest_bits / 8) % 8;
if (bytes_left > 0) {
const rest = d.s[(digest_bits / 64)];
var buf: [8]u8 = undefined;
+1 -1
View File
@@ -1306,7 +1306,7 @@ fn printLineInfo(
try writer.print("0x{x} in {s} ({s})", .{
address,
symbol.name orelse "???",
symbol.compile_unit_name orelse debug_info.getModuleName(io, address) catch "???",
symbol.compile_unit_name orelse (debug_info.getModuleName(io, address) catch "???"),
});
t.setColor(.reset) catch {};
try writer.writeAll("\n");
+4 -4
View File
@@ -16,11 +16,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
const gpa = std.debug.getDebugInfoAllocator();
for (si.modules.items) |*mod| {
unwind: {
const u = &(mod.unwind orelse break :unwind catch break :unwind);
const u = &((mod.unwind orelse break :unwind) catch break :unwind);
for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);
}
loaded: {
const l = &(mod.loaded_elf orelse break :loaded catch break :loaded);
const l = &((mod.loaded_elf orelse break :loaded) catch break :loaded);
l.file.deinit(gpa);
}
}
@@ -431,11 +431,11 @@ fn findModule(si: *SelfInfo, gpa: Allocator, io: Io, address: usize, lock: enum
}
for (si.modules.items) |*mod| {
unwind: {
const u = &(mod.unwind orelse break :unwind catch break :unwind);
const u = &((mod.unwind orelse break :unwind) catch break :unwind);
for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);
}
loaded: {
const l = &(mod.loaded_elf orelse break :loaded catch break :loaded);
const l = &((mod.loaded_elf orelse break :loaded) catch break :loaded);
l.file.deinit(gpa);
}
}
+2 -2
View File
@@ -11,11 +11,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
const gpa = std.debug.getDebugInfoAllocator();
for (si.modules.keys()) |*module| {
unwind: {
const u = &(module.unwind orelse break :unwind catch break :unwind);
const u = &((module.unwind orelse break :unwind) catch break :unwind);
if (u.dwarf) |*dwarf| dwarf.deinit(gpa);
}
file: {
const f = &(module.file orelse break :file catch break :file);
const f = &((module.file orelse break :file) catch break :file);
f.deinit(gpa);
}
}
+4 -4
View File
@@ -280,7 +280,7 @@ const Module = struct {
// we have no information to add to the address
break :pdb;
};
const module = pdb.getModule(mod_index) catch |err| switch (err) {
const module = (pdb.getModule(mod_index) catch |err| switch (err) {
error.InvalidDebugInfo,
error.MissingDebugInfo,
error.OutOfMemory,
@@ -289,7 +289,7 @@ const Module = struct {
error.ReadFailed,
error.EndOfStream,
=> return error.InvalidDebugInfo,
} orelse {
}) orelse {
return error.InvalidDebugInfo; // bad module index
};
@@ -539,9 +539,9 @@ const Module = struct {
}
var opt_pdb: ?Pdb = pdb: {
const path = coff_obj.getPdbPath() catch {
const path = (coff_obj.getPdbPath() catch {
return error.InvalidDebugInfo;
} orelse {
}) orelse {
break :pdb null;
};
const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {
+7 -7
View File
@@ -13,7 +13,7 @@ const posix = std.posix;
/// Platform-specific functionality is available through the `inner` field.
pub const DynLib = struct {
const InnerType = switch (native_os) {
.linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)
.linux => if (!builtin.link_libc or (builtin.abi == .musl and builtin.link_mode == .static))
ElfDynLib
else
DlDynLib,
@@ -434,15 +434,15 @@ pub const ElfDynLib = struct {
pub fn lookupAddress(self: *const ElfDynLib, vername: []const u8, name: []const u8) ?usize {
const maybe_versym = if (self.verdef == null) null else self.versym;
const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);
const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);
const OK_TYPES = (1 << elf.STT_NOTYPE) | (1 << elf.STT_OBJECT) | (1 << elf.STT_FUNC) | (1 << elf.STT_COMMON);
const OK_BINDS = (1 << elf.STB_GLOBAL) | (1 << elf.STB_WEAK) | (1 << elf.STB_GNU_UNIQUE);
switch (self.hash_table) {
.dt_hash => |hashtab| {
var i: usize = 0;
while (i < hashtab[1]) : (i += 1) {
if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf)) & OK_TYPES)) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4)) & OK_BINDS)) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf))) & OK_TYPES) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4))) & OK_BINDS) continue;
if (0 == self.syms[i].st_shndx) continue;
if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;
if (maybe_versym) |versym| {
@@ -494,8 +494,8 @@ pub const ElfDynLib = struct {
const symbol_index = current_index + gnu_hash_header.symoffset;
const symbol = self.syms[symbol_index];
if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info & 0xf)) & OK_TYPES)) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info >> 4)) & OK_BINDS)) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info & 0xf))) & OK_TYPES) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info >> 4))) & OK_BINDS) continue;
if (0 == symbol.st_shndx) continue;
const symbol_name = mem.sliceTo(self.strings + symbol.st_name, 0);
+1 -1
View File
@@ -82,7 +82,7 @@ pub fn isDigit(c: u8, comptime base: u8) bool {
return if (base == 10)
'0' <= c and c <= '9'
else
'0' <= c and c <= '9' or 'a' <= c and c <= 'f' or 'A' <= c and c <= 'F';
('0' <= c and c <= '9') or ('a' <= c and c <= 'f') or ('A' <= c and c <= 'F');
}
/// Returns the underlying storage type used for the mantissa of floating-point type.
+1 -1
View File
@@ -222,7 +222,7 @@ pub const CityHash64 = struct {
const c: u8 = str[str.len - 1];
const y: u32 = @as(u32, @intCast(a)) +% (@as(u32, @intCast(b)) << 8);
const z: u32 = @as(u32, @truncate(str.len)) +% (@as(u32, @intCast(c)) << 2);
return shiftmix(@as(u64, @intCast(y)) *% k2 ^ @as(u64, @intCast(z)) *% k0) *% k2;
return shiftmix((@as(u64, @intCast(y)) *% k2) ^ (@as(u64, @intCast(z)) *% k0)) *% k2;
}
return k2;
}
+1 -1
View File
@@ -398,7 +398,7 @@ pub const XxHash32 = struct {
}
fn avalanche(value: u32) u32 {
var acc = value ^ value >> 15;
var acc = value ^ (value >> 15);
acc *%= prime_2;
acc ^= acc >> 13;
acc *%= prime_3;
+1 -1
View File
@@ -2019,7 +2019,7 @@ test "getOrPutAdapted" {
const AdaptedContext = struct {
fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {
_ = self;
return std.fmt.parseInt(u64, adapted_key, 10) catch unreachable == test_key;
return (std.fmt.parseInt(u64, adapted_key, 10) catch unreachable) == test_key;
}
fn hash(self: @This(), adapted_key: []const u8) u64 {
_ = self;
+1 -1
View File
@@ -211,7 +211,7 @@ const Bucket = struct {
fn of(s: *SafeAllocator, ptr: [*]u8) *Bucket {
const size_log2 = s.bucket_size_log2;
return @ptrFromInt(@intFromPtr(ptr) >> @intCast(size_log2) << @intCast(size_log2));
return @ptrFromInt((@intFromPtr(ptr) >> @intCast(size_log2)) << @intCast(size_log2));
}
fn fillAt(s: *SafeAllocator, ptr: [*]const u8) u32 {
+14 -14
View File
@@ -710,7 +710,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
return x >> ar | x << (1 +% ~ar);
return (x >> ar) | (x << (1 +% ~ar));
} else {
const ar = @mod(r, @typeInfo(T).int.bits);
return shr(T, x, ar) | shl(T, x, @typeInfo(T).int.bits - ar);
@@ -753,7 +753,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
return x << ar | x >> 1 +% ~ar;
return (x << ar) | (x >> (1 +% ~ar));
} else {
const ar = @mod(r, @typeInfo(T).int.bits);
return shl(T, x, ar) | shr(T, x, @typeInfo(T).int.bits - ar);
@@ -1542,21 +1542,21 @@ pub const Order = enum {
const neg: i32 = -1;
const zero: i32 = 0;
const pos: i32 = 1;
try testing.expect(order(zero, neg).differ() orelse
order(pos, zero) == .gt);
try testing.expect(order(zero, zero).differ() orelse
order(zero, zero) == .eq);
try testing.expect(order(pos, pos).differ() orelse
order(neg, zero) == .lt);
try testing.expect(order(zero, zero).differ() orelse
try testing.expect((order(zero, neg).differ() orelse
order(pos, zero)) == .gt);
try testing.expect((order(zero, zero).differ() orelse
order(zero, zero)) == .eq);
try testing.expect((order(pos, pos).differ() orelse
order(neg, zero)) == .lt);
try testing.expect((order(zero, zero).differ() orelse
order(pos, neg).differ() orelse
order(neg, zero) == .gt);
try testing.expect(order(pos, pos).differ() orelse
order(neg, zero)) == .gt);
try testing.expect((order(pos, pos).differ() orelse
order(pos, pos).differ() orelse
order(neg, neg) == .eq);
try testing.expect(order(zero, pos).differ() orelse
order(neg, neg)) == .eq);
try testing.expect((order(zero, pos).differ() orelse
order(neg, pos).differ() orelse
order(pos, neg) == .lt);
order(pos, neg)) == .lt);
}
pub fn compare(self: Order, op: CompareOperator) bool {
+1 -1
View File
@@ -176,7 +176,7 @@ fn acosBinary64(x: f64) f64 {
// |x| >= 1 or nan
if (ix >= 0x3ff0_0000) {
const lx: u32 = @truncate(@as(u64, @bitCast(x)));
if ((ix - 0x3ff0_0000 | lx) == 0) {
if (((ix - 0x3ff0_0000) | lx) == 0) {
if (hx >> 31 != 0) {
return 2.0 * pio2_hi + 0x1.0p-120;
}
+1 -1
View File
@@ -156,7 +156,7 @@ fn asinBinary64(x: f64) f64 {
if (ix >= 0x3ff0_0000) {
const lx: u32 = @truncate(@as(u64, @bitCast(x)));
// asin(1) = +-pi/2 with inexact
if ((ix - 0x3ff0_0000 | lx) == 0) {
if (((ix - 0x3ff0_0000) | lx) == 0) {
return x * pio2_hi + 0x1.0p-120;
}
return 0.0 / (x - x);
+3 -3
View File
@@ -2401,7 +2401,7 @@ pub const Const = struct {
const shift: usize = @intCast(exponent - @bitSizeOf(Repr.Normalized.Fraction));
mantissa.shiftRight(normalized_abs, shift);
const final_limb_index = (shift - 1) / limb_bits;
const round_bits = normalized_abs.limbs[final_limb_index] << @truncate(-%shift) |
const round_bits = (normalized_abs.limbs[final_limb_index] << @truncate(-%shift)) |
@intFromBool(!std.mem.allEqual(Limb, normalized_abs.limbs[0..final_limb_index], 0));
if (round_bits == 0) break :exactness .exact;
round: switch (round) {
@@ -4902,10 +4902,10 @@ test "format" {
try a.set(20000000000000000000); // > maxInt(u64)
try testFormat(a, "20000000000000000000");
try a.set(1 << 64 * @sizeOf(usize) * 8);
try a.set(1 << (64 * @sizeOf(usize) * 8));
try testFormat(a, "(BigInt)");
try a.set(-(1 << 64 * @sizeOf(usize) * 8));
try a.set(-(1 << (64 * @sizeOf(usize) * 8)));
try testFormat(a, "(BigInt)");
}
+16 -16
View File
@@ -2489,14 +2489,14 @@ test "truncate to minimum signed integer" {
.len = undefined,
.positive = undefined,
};
res.truncate(.{ .positive = true, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .signed, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(-1 << @bitSizeOf(Limb) - 1).compare(.eq));
res.truncate(.{ .positive = false, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .signed, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(-1 << @bitSizeOf(Limb) - 1).compare(.eq));
res.truncate(.{ .positive = true, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .unsigned, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(1 << @bitSizeOf(Limb) - 1).compare(.eq));
res.truncate(.{ .positive = false, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .unsigned, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(1 << @bitSizeOf(Limb) - 1).compare(.eq));
res.truncate(.{ .positive = true, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .signed, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(-1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
res.truncate(.{ .positive = false, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .signed, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(-1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
res.truncate(.{ .positive = true, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .unsigned, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
res.truncate(.{ .positive = false, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .unsigned, @bitSizeOf(Limb));
try testing.expect(res.toConst().orderAgainstScalar(1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
}
test "saturate single signed positive" {
@@ -3880,7 +3880,7 @@ test "clz" {
try testing.expectEqual(0, neg_limb_max_squared_plus_one.clz(@bitSizeOf(Limb) * 2 + 1));
const neg_limb_msb_squared: std.math.big.int.Const = .{
.limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
.limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
.positive = false,
};
try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
@@ -3896,7 +3896,7 @@ test "clz" {
try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
const neg_limb_msb: std.math.big.int.Const = .{
.limbs = &.{1 << @bitSizeOf(Limb) - 1},
.limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
.positive = false,
};
try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb)));
@@ -3936,7 +3936,7 @@ test "clz" {
try testing.expectEqual(@bitSizeOf(Limb) * 2, one.clz(@bitSizeOf(Limb) * 2 + 1));
const limb_msb: std.math.big.int.Const = .{
.limbs = &.{1 << @bitSizeOf(Limb) - 1},
.limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
.positive = true,
};
try testing.expectEqual(0, limb_msb.clz(@bitSizeOf(Limb)));
@@ -3956,7 +3956,7 @@ test "clz" {
try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
const limb_msb_squared: std.math.big.int.Const = .{
.limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
.limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
.positive = true,
};
try testing.expectEqual(0, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1));
@@ -3992,7 +3992,7 @@ test "ctz" {
try testing.expectEqual(@bitSizeOf(Limb) + 1, neg_limb_max_squared_plus_one.ctz(@bitSizeOf(Limb) * 2 + 1));
const neg_limb_msb_squared: std.math.big.int.Const = .{
.limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
.limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
.positive = false,
};
try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
@@ -4008,7 +4008,7 @@ test "ctz" {
try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
const neg_limb_msb: std.math.big.int.Const = .{
.limbs = &.{1 << @bitSizeOf(Limb) - 1},
.limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
.positive = false,
};
try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb)));
@@ -4048,7 +4048,7 @@ test "ctz" {
try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 + 1));
const limb_msb: std.math.big.int.Const = .{
.limbs = &.{1 << @bitSizeOf(Limb) - 1},
.limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
.positive = true,
};
try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb)));
@@ -4068,7 +4068,7 @@ test "ctz" {
try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
const limb_msb_squared: std.math.big.int.Const = .{
.limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
.limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
.positive = true,
};
try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1));
+2 -2
View File
@@ -281,7 +281,7 @@ pub inline fn nan(comptime Type: type) Type {
return reconstructFloat(
RuntimeType,
floatExponentMax(RuntimeType) + 1,
mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 1),
mantissaOne(RuntimeType) | (1 << (floatFractionalBits(RuntimeType) - 1)),
);
}
@@ -297,7 +297,7 @@ pub inline fn snan(comptime Type: type) Type {
return reconstructFloat(
RuntimeType,
floatExponentMax(RuntimeType) + 1,
mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 2),
mantissaOne(RuntimeType) | (1 << (floatFractionalBits(RuntimeType) - 2)),
);
}
+1 -1
View File
@@ -4354,7 +4354,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
@compileError("expected many item pointer, got " ++ @typeName(T));
// Do nothing if the pointer is already well-aligned.
if (align_to <= info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child))
if (align_to <= (info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child)))
return 0;
// Calculate the aligned base address with an eye out for overflow.
+4 -4
View File
@@ -62,13 +62,13 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
const hashtab = maybe_hashtab orelse return 0;
if (maybe_verdef == null) maybe_versym = null;
const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);
const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);
const OK_TYPES = (1 << elf.STT_NOTYPE) | (1 << elf.STT_OBJECT) | (1 << elf.STT_FUNC) | (1 << elf.STT_COMMON);
const OK_BINDS = (1 << elf.STB_GLOBAL) | (1 << elf.STB_WEAK) | (1 << elf.STB_GNU_UNIQUE);
var i: usize = 0;
while (i < hashtab[1]) : (i += 1) {
if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf)) & OK_TYPES)) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4)) & OK_BINDS)) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf))) & OK_TYPES) continue;
if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4))) & OK_BINDS) continue;
if (0 == syms[i].st_shndx) continue;
const sym_name = @as([*:0]u8, @ptrCast(strings + syms[i].st_name));
if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;
+1 -1
View File
@@ -1,6 +1,6 @@
const testing = @import("std").testing;
const high_bit = 1 << @typeInfo(usize).int.bits - 1;
const high_bit = 1 << (@typeInfo(usize).int.bits - 1);
pub const Status = enum(usize) {
/// The operation completed successfully.
+1 -1
View File
@@ -485,7 +485,7 @@ pub fn utf16DecodeSurrogatePair(surrogate_pair: []const u16) !u21 {
const high_half: u21 = surrogate_pair[0];
const low_half = surrogate_pair[1];
if (!utf16IsLowSurrogate(low_half)) return error.ExpectedSecondSurrogateHalf;
return 0x10000 + ((high_half & 0x03ff) << 10) | (low_half & 0x03ff);
return (0x10000 + ((high_half & 0x03ff) << 10)) | (low_half & 0x03ff);
}
pub const Utf16LeIterator = struct {
+32
View File
@@ -555,6 +555,33 @@ pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void
.var_const_decl => {
return w.writeAll("use 'var' or 'const' to declare variable");
},
.ambiguous_operator_precedence => {
return w.print("ambiguous operator precedence with operators … {s} … {s} …; use parentheses to disambiguate", .{
tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
tree.tokenTag(parse_error.token).lexeme().?,
});
},
.previous_ambiguous_operator => {
return w.writeAll("previous ambiguous operator here");
},
.illegal_chained_operators => {
return w.print("repetition of non-chainable operators … {s} … {s} …; use parentheses to disambiguate", .{
tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
tree.tokenTag(parse_error.token).lexeme().?,
});
},
.hint_operator_precedence_left => {
return w.print("did you mean `(… {s} …) {s} …` ?", .{
tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
tree.tokenTag(parse_error.token).lexeme().?,
});
},
.hint_operator_precedence_right => {
return w.print("did you mean `… {s} (… {s} …)` ?", .{
tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
tree.tokenTag(parse_error.token).lexeme().?,
});
},
.invalid_byte => {
const tok_slice = tree.source[tree.tokens.items(.start)[parse_error.token]..];
@@ -2893,6 +2920,11 @@ pub const Error = struct {
expected_var_const,
wrong_equal_var_decl,
var_const_decl,
ambiguous_operator_precedence,
previous_ambiguous_operator,
hint_operator_precedence_left,
hint_operator_precedence_right,
illegal_chained_operators,
zig_style_container,
previous_field,
+3 -3
View File
@@ -1483,9 +1483,9 @@ fn renderThenElse(
last_else_token = error_token + 1; // |
}
const indent_else_expr = indent_then_expr and
const indent_else_expr = (indent_then_expr and
!nodeIsBlock(tree.nodeTag(else_expr)) and
!nodeIsIfForWhileSwitch(tree.nodeTag(else_expr)) or
!nodeIsIfForWhileSwitch(tree.nodeTag(else_expr))) or
tree.tokenTag(tree.firstToken(else_expr)) ==
.multiline_string_literal_line;
if (indent_else_expr) {
@@ -3195,7 +3195,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
}
}
index = 1 + (newline orelse end - 1);
index = 1 + (newline orelse (end - 1));
const comment_content = mem.trimStart(u8, trimmed_comment["//".len..], &std.ascii.whitespace);
if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) {
+296 -49
View File
@@ -1512,7 +1512,7 @@ fn expectAssignExpr(p: *Parse) !Node.Index {
}
fn parseExpr(p: *Parse) Error!?Node.Index {
return p.parseExprPrecedence(0);
return p.parseExprPrecedence(.start, p.tok_i);
}
fn expectExpr(p: *Parse) Error!Node.Index {
@@ -1524,67 +1524,317 @@ const Assoc = enum {
none,
};
const OperInfo = struct {
prec: i8,
tag: Node.Tag,
const PrecClass = struct {
group: Group,
assoc: Assoc = Assoc.left,
const Group = enum {
const num_distinct = std.meta.fieldNames(Group).len;
arithmetic_product_chainable,
arithmetic_mod_nonchainable,
arithmetic_sum,
bitwise_shift,
bitwise_and,
bitwise_xor,
bitwise_or,
comparison,
bool_and,
bool_or,
recovery_orelse,
recovery_catch,
root,
/// For this to work correctly we require that all subgroups are strictly adjacent
/// Major groups are defined by the first text before an underscore
const Major: type = b: {
var major_names: []const []const u8 = &.{};
for (std.meta.fieldNames(Group)) |fieldname| {
var major_name: []const u8 = fieldname[0..];
for (fieldname, 0..) |c, i| {
if (c == '_') {
major_name = fieldname[0..i];
break;
}
}
if (major_names.len == 0 or !std.mem.eql(u8, major_name, major_names[major_names.len - 1])) {
major_names = major_names ++ &[1][]const u8{major_name};
}
}
const IntType = std.math.IntFittingRange(0, major_names.len - 1);
var values: [major_names.len]IntType = undefined;
for (0..major_names.len) |i| values[i] = i;
break :b @Enum(
IntType,
.exhaustive,
major_names,
&values,
);
};
};
pub const start: PrecClass = .{ .group = .root };
pub const Rel = enum(i2) {
lt = -1,
eq = 0,
gt = 1,
fn inverted(self: Rel) Rel {
return @enumFromInt(-@intFromEnum(self));
}
};
const PrecedenceArray = [Group.num_distinct][Group.num_distinct]?Rel;
fn setMajorRelation(prec_array: *PrecedenceArray, major_a: Group.Major, rel: Rel, major_b: Group.Major) void {
for (std.meta.fieldNames(Group), 0..) |fieldname_i, i| {
if (!std.mem.startsWith(u8, fieldname_i, @tagName(major_a))) continue;
for (std.meta.fieldNames(Group), 0..) |fieldname_j, j| {
if (!std.mem.startsWith(u8, fieldname_j, @tagName(major_b))) continue;
prec_array.*[i][j] = rel;
}
}
}
fn setMinorRelation(prec_array: *PrecedenceArray, minor_a: Group, rel: Rel, minor_b: Group) void {
prec_array.*[@intFromEnum(minor_a)][@intFromEnum(minor_b)] = rel;
}
/// Arithmetic_* > Comparison
/// Bitwise_* > Comparison
/// Comparison > Bool_* > Root
/// Recovery > Root
///
/// *_Product > *_Sum
///
/// order[y][x] --> y cmp x
const precedence_ordering = b: {
@setEvalBranchQuota(20_000);
const major_greater_than_relations = [_][2]Group.Major{
// zig fmt: off
.{ .arithmetic, .comparison },
.{ .bitwise, .comparison },
.{ .comparison, .bool },
.{ .bool, .root },
.{ .recovery, .root },
// zig fmt: on
};
var order: PrecedenceArray = @splat(@splat(null));
for (major_greater_than_relations) |relation| {
setMajorRelation(&order, relation[0], .gt, relation[1]);
}
setMinorRelation(&order, .arithmetic_mod_nonchainable, .gt, .arithmetic_sum);
setMinorRelation(&order, .arithmetic_product_chainable, .gt, .arithmetic_sum);
computeTransativeOrdering(&order);
break :b order;
};
/// Uses the table from Zig-0.16.0
/// * / % *% *| ||
/// + - ++ +% -% +| -|
/// << >> <<|
/// & ^ | orelse catch
/// == != < > <= >=
/// and
/// or
const v16_precedence_ordering = b: {
@setEvalBranchQuota(20_000);
var order: PrecedenceArray = @splat(@splat(null));
setMinorRelation(&order, .arithmetic_product_chainable, .eq, .arithmetic_mod_nonchainable);
setMinorRelation(&order, .arithmetic_mod_nonchainable, .gt, .arithmetic_sum);
setMinorRelation(&order, .arithmetic_product_chainable, .gt, .arithmetic_sum);
setMinorRelation(&order, .arithmetic_sum, .gt, .bitwise_shift);
// Here since the transative ordering computer cant leverage equals to derive a = b < c --> a < c, we have to manually list these
setMinorRelation(&order, .bitwise_shift, .gt, .bitwise_and);
setMinorRelation(&order, .bitwise_shift, .gt, .bitwise_xor);
setMinorRelation(&order, .bitwise_shift, .gt, .bitwise_or);
setMinorRelation(&order, .bitwise_shift, .gt, .recovery_catch);
setMinorRelation(&order, .bitwise_shift, .gt, .recovery_orelse);
setMinorRelation(&order, .bitwise_and, .eq, .bitwise_xor);
setMinorRelation(&order, .bitwise_xor, .eq, .bitwise_or);
setMinorRelation(&order, .bitwise_or, .eq, .recovery_catch);
setMinorRelation(&order, .recovery_catch, .eq, .recovery_orelse);
setMinorRelation(&order, .recovery_orelse, .eq, .bitwise_and);
setMinorRelation(&order, .bitwise_and, .gt, .comparison);
setMinorRelation(&order, .bitwise_xor, .gt, .comparison);
setMinorRelation(&order, .bitwise_or, .gt, .comparison);
setMinorRelation(&order, .recovery_catch, .gt, .comparison);
setMinorRelation(&order, .recovery_orelse, .gt, .comparison);
setMinorRelation(&order, .comparison, .gt, .bool_and);
setMinorRelation(&order, .bool_and, .gt, .bool_or);
setMinorRelation(&order, .bool_or, .gt, .root);
computeTransativeOrdering(&order);
for (order) |row| {
for (row) |item| {
if (item == null) @compileError("Null entry in old precedence ordering which had none.");
}
}
break :b order;
};
pub fn cmp(lhs: PrecClass, rhs: PrecClass) ?Rel {
return PrecClass.precedence_ordering[@intFromEnum(lhs.group)][@intFromEnum(rhs.group)];
}
pub fn v16_cmp(lhs: PrecClass, rhs: PrecClass) Rel {
return PrecClass.v16_precedence_ordering[@intFromEnum(lhs.group)][@intFromEnum(rhs.group)].?;
}
fn computeTransativeOrdering(order: *PrecedenceArray) void {
for (0..Group.num_distinct) |i| for (0..Group.num_distinct) |j| for (0..Group.num_distinct) |k| {
if (order[i][k] == order[k][j] and order[i][k] != null) order[i][j] = order[i][k];
};
for (0..Group.num_distinct) |i| for (0..Group.num_distinct) |j| {
if (i == j) order[i][j] = .eq;
if (order[i][j] == null and order[j][i] != null) order[i][j] = order[j][i].?.inverted();
};
}
};
// A table of binary operator information. Higher precedence numbers are
// stickier. All operators at the same precedence level should have the same
// associativity.
const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec = -1, .tag = Node.Tag.root }, 0, .{
.keyword_or = .{ .prec = 10, .tag = .bool_or },
const OperInfo = struct {
prec: PrecClass,
tag: Node.Tag,
};
.keyword_and = .{ .prec = 20, .tag = .bool_and },
const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec = .start, .tag = Node.Tag.root }, 0, .{
// zig fmt: off
.keyword_or = .{ .prec = .{ .group = .bool_or }, .tag = .bool_or },
.equal_equal = .{ .prec = 30, .tag = .equal_equal, .assoc = Assoc.none },
.bang_equal = .{ .prec = 30, .tag = .bang_equal, .assoc = Assoc.none },
.angle_bracket_left = .{ .prec = 30, .tag = .less_than, .assoc = Assoc.none },
.angle_bracket_right = .{ .prec = 30, .tag = .greater_than, .assoc = Assoc.none },
.angle_bracket_left_equal = .{ .prec = 30, .tag = .less_or_equal, .assoc = Assoc.none },
.angle_bracket_right_equal = .{ .prec = 30, .tag = .greater_or_equal, .assoc = Assoc.none },
.keyword_and = .{ .prec = .{ .group = .bool_and }, .tag = .bool_and },
.ampersand = .{ .prec = 40, .tag = .bit_and },
.caret = .{ .prec = 40, .tag = .bit_xor },
.pipe = .{ .prec = 40, .tag = .bit_or },
.keyword_orelse = .{ .prec = 40, .tag = .@"orelse" },
.keyword_catch = .{ .prec = 40, .tag = .@"catch" },
.equal_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .equal_equal },
.bang_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .bang_equal },
.angle_bracket_left = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .less_than },
.angle_bracket_right = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .greater_than },
.angle_bracket_left_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .less_or_equal },
.angle_bracket_right_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .greater_or_equal },
.angle_bracket_angle_bracket_left = .{ .prec = 50, .tag = .shl },
.angle_bracket_angle_bracket_left_pipe = .{ .prec = 50, .tag = .shl_sat },
.angle_bracket_angle_bracket_right = .{ .prec = 50, .tag = .shr },
.ampersand = .{ .prec = .{ .group = .bitwise_and }, .tag = .bit_and },
.caret = .{ .prec = .{ .group = .bitwise_xor }, .tag = .bit_xor },
.pipe = .{ .prec = .{ .group = .bitwise_or }, .tag = .bit_or },
.plus = .{ .prec = 60, .tag = .add },
.minus = .{ .prec = 60, .tag = .sub },
.plus_plus = .{ .prec = 60, .tag = .array_cat },
.plus_percent = .{ .prec = 60, .tag = .add_wrap },
.minus_percent = .{ .prec = 60, .tag = .sub_wrap },
.plus_pipe = .{ .prec = 60, .tag = .add_sat },
.minus_pipe = .{ .prec = 60, .tag = .sub_sat },
.keyword_orelse = .{ .prec = .{ .group = .recovery_orelse }, .tag = .@"orelse" },
.keyword_catch = .{ .prec = .{ .group = .recovery_catch }, .tag = .@"catch" },
.pipe_pipe = .{ .prec = 70, .tag = .merge_error_sets },
.asterisk = .{ .prec = 70, .tag = .mul },
.slash = .{ .prec = 70, .tag = .div },
.percent = .{ .prec = 70, .tag = .mod },
.asterisk_percent = .{ .prec = 70, .tag = .mul_wrap },
.asterisk_pipe = .{ .prec = 70, .tag = .mul_sat },
.angle_bracket_angle_bracket_left = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shl },
.angle_bracket_angle_bracket_left_pipe = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shl_sat },
.angle_bracket_angle_bracket_right = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shr },
.plus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add },
.minus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub },
.plus_plus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .array_cat },
.plus_percent = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add_wrap },
.minus_percent = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub_wrap },
.plus_pipe = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add_sat },
.minus_pipe = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub_sat },
.pipe_pipe = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .merge_error_sets },
.asterisk = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul },
.slash = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .div },
.asterisk_percent = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul_wrap },
.asterisk_pipe = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul_sat },
.percent = .{ .prec = .{ .group = .arithmetic_mod_nonchainable, .assoc = Assoc.none }, .tag = .mod },
// zig fmt: on
});
fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
assert(min_prec >= 0);
fn parseExprPrecedence(p: *Parse, min_exc_prec: PrecClass, prev_token_const: u32) Error!?Node.Index {
var node = try p.parsePrefixExpr() orelse return null;
var banned_prec: i8 = -1;
var prev_operator_token = prev_token_const;
while (true) {
const tok_tag = p.tokenTag(p.tok_i);
const info = operTable[@as(usize, @intCast(@backingInt(tok_tag)))];
if (info.prec < min_prec) {
const info = operTable[@intFromEnum(tok_tag)];
const rel = info.prec.cmp(min_exc_prec) orelse b: {
const prev_op_tok_tag = p.tokenTag(prev_operator_token);
const prev_op_info = operTable[@intFromEnum(prev_op_tok_tag)];
const v16_rel = prev_op_info.prec.v16_cmp(info.prec);
try p.warnMsg(.{
.tag = .ambiguous_operator_precedence,
.is_note = false,
.token = p.tok_i,
.extra = .{ .offset = p.tok_i - prev_operator_token },
});
try p.warnMsg(.{
.tag = .previous_ambiguous_operator,
.is_note = true,
.token = prev_operator_token,
});
if (v16_rel == .gt or v16_rel == .eq) {
try p.warnMsg(.{
.tag = .hint_operator_precedence_left,
.is_note = true,
.token = p.tok_i,
.extra = .{ .offset = p.tok_i - prev_operator_token },
});
} else {
try p.warnMsg(.{
.tag = .hint_operator_precedence_right,
.is_note = true,
.token = p.tok_i,
.extra = .{ .offset = p.tok_i - prev_operator_token },
});
}
break :b .gt;
};
if (rel == .lt) {
break;
}
if (info.prec == banned_prec) {
return p.fail(.chained_comparison_operators);
if (min_exc_prec.group == info.prec.group and min_exc_prec.assoc == .none and info.prec.assoc == .none) {
//Special cased check to maintain the old more helpful error for chained comparisons.
if (info.prec.group == .comparison) {
try p.warn(.chained_comparison_operators);
} else {
try p.warnMsg(.{
.tag = .illegal_chained_operators,
.is_note = false,
.token = p.tok_i,
.extra = .{ .offset = p.tok_i - prev_operator_token },
});
try p.warnMsg(.{
.tag = .previous_ambiguous_operator,
.is_note = true,
.token = prev_operator_token,
});
try p.warnMsg(.{
.tag = .hint_operator_precedence_left,
.is_note = true,
.token = p.tok_i,
.extra = .{ .offset = p.tok_i - prev_operator_token },
});
}
}
if (rel == .eq) {
break;
}
const oper_token = p.nextToken();
@@ -1614,7 +1864,8 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
}
}
const rhs = try p.parseExprPrecedence(info.prec + 1) orelse {
prev_operator_token = oper_token;
const rhs = try p.parseExprPrecedence(info.prec, prev_operator_token) orelse {
try p.warn(.expected_expr);
return node;
};
@@ -1624,10 +1875,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
.main_token = oper_token,
.data = .{ .node_and_node = .{ node, rhs } },
});
if (info.assoc == Assoc.none) {
banned_prec = info.prec;
}
}
return node;
+1 -1
View File
@@ -160,7 +160,7 @@ pub fn gen(smith: *Smith) TokenSmith {
var no_period = false;
var not_exponent = true;
for (t.source_buf[t.source_len..][0..len], 0..) |*c, i| {
const invalid_period = no_period and c.* == '.' or i + 1 == len;
const invalid_period = (no_period and c.* == '.') or i + 1 == len;
const is_exponent = c.* == '-' or c.* == '+';
const invalid_exponent = not_exponent and is_exponent;
const valid_exponent = !not_exponent and is_exponent;
+1 -1
View File
@@ -404,7 +404,7 @@ fn readFixed(bc: *BitcodeReader, comptime T: type, bits: u7) !T {
if (bc.bit_offset == 0) bc.bit_buffer = try bc.read32Bits();
const chunk_len = @min(@as(u6, 32) - bc.bit_offset, remaining);
const chunk_mask = @as(u32, std.math.maxInt(u32)) >> @intCast(32 - chunk_len);
result |= @as(T, @intCast(bc.bit_buffer >> bc.bit_offset & chunk_mask)) << @intCast(shift);
result |= @as(T, @intCast((bc.bit_buffer >> bc.bit_offset) & chunk_mask)) << @intCast(shift);
shift += @intCast(chunk_len);
remaining -= chunk_len;
bc.bit_offset = @truncate(bc.bit_offset + chunk_len);
+26 -26
View File
@@ -1076,7 +1076,7 @@ pub const Type = enum(u32) {
child: Type,
fn length(self: Array) u64 {
return @as(u64, self.len_hi) << 32 | self.len_lo;
return (@as(u64, self.len_hi) << 32) | self.len_lo;
}
};
@@ -9520,7 +9520,7 @@ pub const Metadata = packed struct(u32) {
size_in_bits_hi: u32,
pub fn bitSize(self: BasicType) u64 {
return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
}
};
@@ -9537,10 +9537,10 @@ pub const Metadata = packed struct(u32) {
fields_tuple: Metadata.Optional,
pub fn bitSize(self: CompositeType) u64 {
return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
}
pub fn bitAlign(self: CompositeType) u64 {
return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
return (@as(u64, self.align_in_bits_hi) << 32) | self.align_in_bits_lo;
}
};
@@ -9558,13 +9558,13 @@ pub const Metadata = packed struct(u32) {
offset_in_bits_hi: u32,
pub fn bitSize(self: DerivedType) u64 {
return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
}
pub fn bitAlign(self: DerivedType) u64 {
return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
return (@as(u64, self.align_in_bits_hi) << 32) | self.align_in_bits_lo;
}
pub fn bitOffset(self: DerivedType) u64 {
return @as(u64, self.offset_in_bits_hi) << 32 | self.offset_in_bits_lo;
return (@as(u64, self.offset_in_bits_hi) << 32) | self.offset_in_bits_lo;
}
};
@@ -12457,7 +12457,7 @@ fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant {
if (ctx.builder.constant_items.items(.tag)[rhs_index] != .double) return false;
const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
const rhs_extra = ctx.builder.constantExtraData(Constant.Double, rhs_data);
return @as(u64, @bitCast(lhs_key)) == @as(u64, rhs_extra.hi) << 32 | rhs_extra.lo;
return @as(u64, @bitCast(lhs_key)) == (@as(u64, rhs_extra.hi) << 32) | rhs_extra.lo;
}
};
const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
@@ -12488,8 +12488,8 @@ fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant {
if (ctx.builder.constant_items.items(.tag)[rhs_index] != .fp128) return false;
const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
return @as(u128, @bitCast(lhs_key)) == @as(u128, rhs_extra.hi_hi) << 96 |
@as(u128, rhs_extra.hi_lo) << 64 | @as(u128, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
return @as(u128, @bitCast(lhs_key)) == (@as(u128, rhs_extra.hi_hi) << 96) |
(@as(u128, rhs_extra.hi_lo) << 64) | (@as(u128, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo;
}
};
const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
@@ -12522,8 +12522,8 @@ fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant {
if (ctx.builder.constant_items.items(.tag)[rhs_index] != .x86_fp80) return false;
const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
const rhs_extra = ctx.builder.constantExtraData(Constant.Fp80, rhs_data);
return @as(u80, @bitCast(lhs_key)) == @as(u80, rhs_extra.hi) << 64 |
@as(u80, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
return @as(u80, @bitCast(lhs_key)) == (@as(u80, rhs_extra.hi) << 64) |
(@as(u80, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo;
}
};
const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
@@ -12555,8 +12555,8 @@ fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant {
if (ctx.builder.constant_items.items(.tag)[rhs_index] != .ppc_fp128) return false;
const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
return @as(u64, @bitCast(lhs_key[0])) == @as(u64, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo and
@as(u64, @bitCast(lhs_key[1])) == @as(u64, rhs_extra.hi_hi) << 32 | rhs_extra.hi_lo;
return @as(u64, @bitCast(lhs_key[0])) == (@as(u64, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo and
@as(u64, @bitCast(lhs_key[1])) == (@as(u64, rhs_extra.hi_hi) << 32) | rhs_extra.hi_lo;
}
};
const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
@@ -15225,18 +15225,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
for (limbs) |*limb| {
const val = std.mem.littleToNative(i64, @bitCast(limb.*));
limb.* = @bitCast(if (val >= 0)
val << 1 | 0
(val << 1) | 0
else
-%val << 1 | 1);
(-%val << 1) | 1);
}
try constants_block.writeUnabbrev(5, record.items);
continue;
};
try constants_block.writeAbbrev(ConstantsBlock.Integer{
.value = @bitCast(if (val >= 0)
val << 1 | 0
(val << 1) | 0
else
-%val << 1 | 1),
(-%val << 1) | 1),
});
},
.half,
@@ -15252,8 +15252,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
.x86_fp80 => {
const extra = self.constantExtraData(Constant.Fp80, data);
try constants_block.writeAbbrev(ConstantsBlock.Fp80{
.hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |
extra.lo_lo >> 16,
.hi = (@as(u64, extra.hi) << 48) | (@as(u64, extra.lo_hi) << 16) |
(extra.lo_lo >> 16),
.lo = @truncate(extra.lo_lo),
});
},
@@ -15262,8 +15262,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
=> {
const extra = self.constantExtraData(Constant.Fp128, data);
try constants_block.writeAbbrev(ConstantsBlock.Fp128{
.lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),
.hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),
.lo = (@as(u64, extra.lo_hi) << 32) | @as(u64, extra.lo_lo),
.hi = (@as(u64, extra.hi_hi) << 32) | @as(u64, extra.hi_lo),
});
},
.array,
@@ -15724,9 +15724,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
for (limbs) |*limb| {
const val = std.mem.littleToNative(i64, @bitCast(limb.*));
limb.* = @bitCast(if (val >= 0)
val << 1 | 0
(val << 1) | 0
else
-%val << 1 | 1);
(-%val << 1) | 1);
}
try metadata_block.writeUnabbrev(@backingInt(MetadataBlock.Code.ENUMERATOR), record.items);
continue;
@@ -15736,9 +15736,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
.bit_width = extra.bit_width,
.name = extra.name,
.value = @bitCast(if (val >= 0)
val << 1 | 0
(val << 1) | 0
else
-%val << 1 | 1),
(-%val << 1) | 1),
}, metadata_adapter);
},
.subrange => {
+1 -1
View File
@@ -102,7 +102,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
// If input is larger than one VBR block can store
// then store vbr_bits - 1 bits and a continue bit
while (in_buffer > mask) {
try self.writeBits(in_buffer & mask | continue_bit, vbr_bits);
try self.writeBits((in_buffer & mask) | continue_bit, vbr_bits);
in_buffer >>= @intCast(vbr_bits - 1);
}
+42 -6
View File
@@ -3046,19 +3046,14 @@ test "zig fmt: precedence" {
\\ !(a{});
\\ a + b{};
\\ (a + b){};
\\ a << b + c;
\\ (a << b) + c;
\\ a & b << c;
\\ (a & b) << c;
\\ a ^ b & c;
\\ (a ^ b) & c;
\\ a | b ^ c;
\\ (a | b) ^ c;
\\ a == b | c;
\\ (a == b) | c;
\\ a and b == c;
\\ (a and b) == c;
\\ a or b and c;
\\ (a or b) and c;
\\ (a or b) and c;
\\ a == b and c == d;
@@ -3067,6 +3062,47 @@ test "zig fmt: precedence" {
);
}
test "zig fmt: ambiguous precedence" {
try testError(
\\test "ambiguous precedence" {
\\ a & b << c;
\\ a << b + c;
\\ a << b | c;
\\ a ^ b & c;
\\ a | b ^ c;
\\ a or b and c;
\\ a orelse b catch c;
\\ a % b % c;
\\}
\\
, &[_]Error{
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_right,
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_right,
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_left,
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_left,
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_left,
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_right,
.ambiguous_operator_precedence,
.previous_ambiguous_operator,
.hint_operator_precedence_left,
.illegal_chained_operators,
.previous_ambiguous_operator,
.hint_operator_precedence_left,
});
}
test "zig fmt: prefix operators" {
try testCanonical(
\\test "prefix operators" {
@@ -7205,7 +7241,7 @@ test "recovery: missing comma" {
\\ 2 => {}
\\ 3 => {}
\\ else => {
\\ foo & bar +;
\\ foo & bar &;
\\ }
\\ }
\\}
+5 -5
View File
@@ -266,8 +266,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
// Minor * 1(0),000 summed has been convention since FreeBSD 2.2 (1997)
// e.g. 492101 = 4.11-STABLE = 4.(9+2)
const major = value / 100_000;
const minor1 = value % 100_000 / 10_000; // usually 0 since 5.1
const minor2 = value % 10_000 / 1_000; // 0 before 5.1, minor version since
const minor1 = (value % 100_000) / 10_000; // usually 0 since 5.1
const minor2 = (value % 10_000) / 1_000; // 0 before 5.1, minor version since
const patch = value % 1_000;
os.version_range.semver.min = .{ .major = major, .minor = minor1 + minor2, .patch = patch };
os.version_range.semver.max = os.version_range.semver.min;
@@ -280,8 +280,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
// r = 0 (*)
// p = patchlevel
const major = value / 100_000_000;
const minor = value % 100_000_000 / 1_000_000;
const patch = value % 10_000 / 100;
const minor = (value % 100_000_000) / 1_000_000;
const patch = (value % 10_000) / 100;
os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };
os.version_range.semver.max = os.version_range.semver.min;
},
@@ -292,7 +292,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
// m = minor; odd-numbers indicate current dev branch
// p = patch
const major = value / 100_000;
const minor = value % 100_000 / 100;
const minor = (value % 100_000) / 100;
const patch = value % 100;
os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };
os.version_range.semver.max = os.version_range.semver.min;
+2 -2
View File
@@ -25,7 +25,7 @@ pub fn detectRuntimeVersion() WindowsVersion {
// `---` `` ``--> Sub-version (Starting from Windows 10 onwards)
// \ `--> Service pack (Always zero in the constants defined)
// `--> OS version (Major & minor)
const os_ver: u16 = @as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8 |
const os_ver: u16 = (@as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8) |
@as(u16, @intCast(version_info.dwMinorVersion & 0xff));
const sp_ver: u8 = 0;
const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {
@@ -40,7 +40,7 @@ pub fn detectRuntimeVersion() WindowsVersion {
break :subver @as(u8, @truncate(last_idx));
} else 0;
const version: u32 = @as(u32, os_ver) << 16 | @as(u16, sp_ver) << 8 | sub_ver;
const version: u32 = (@as(u32, os_ver) << 16) | (@as(u16, sp_ver) << 8) | sub_ver;
return @as(WindowsVersion, @fromBackingInt(@intCast(version)));
}
+1 -1
View File
@@ -1505,7 +1505,7 @@ pub const ShuffleTwoMask = enum(u32) {
return @fromBackingInt(@intCast(idx << 1));
}
pub fn bElem(idx: u32) ShuffleTwoMask {
return @fromBackingInt(@intCast(idx << 1 | 1));
return @fromBackingInt(@intCast((idx << 1) | 1));
}
pub const Unwrapped = union(enum) {
/// The resulting element is this index into the first runtime vector.
+2 -2
View File
@@ -1990,7 +1990,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
.path = try options.dirs.global_cache.join(arena, &.{zir_sub_dir}),
};
const std_mod = options.std_mod orelse Module.create(arena, .{
const std_mod = options.std_mod orelse (Module.create(arena, .{
.paths = .{
.root = try .fromRoot(arena, options.dirs, .zig_lib, "std"),
.root_src_path = "std.zig",
@@ -2015,7 +2015,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
error.StackProtectorUnsupportedByTarget => unreachable,
error.StackProtectorUnavailableWithoutLibC => unreachable,
error.PatchableFunctionEntryUnsupportedByBackend => unreachable,
};
});
const zcu = try arena.create(Zcu);
zcu.* = .{
+2 -2
View File
@@ -243,7 +243,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const
for (zcu.incremental_debug_state.types.keys()) |type_ip_index| {
const ty: Type = .fromInterned(type_ip_index);
const ty_name = ty.containerTypeName(ip).fqn.toSlice(ip);
const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) {
const success = switch ((@as(u2, @intFromBool(anchor_start)) << 1) | @intFromBool(anchor_end)) {
0b00 => std.mem.find(u8, ty_name, query) != null,
0b01 => std.mem.endsWith(u8, ty_name, query),
0b10 => std.mem.startsWith(u8, ty_name, query),
@@ -264,7 +264,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const
for (zcu.incremental_debug_state.navs.keys()) |nav_index| {
const nav = ip.getNav(nav_index);
const nav_fqn = nav.fqn.toSlice(ip);
const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) {
const success = switch ((@as(u2, @intFromBool(anchor_start)) << 1) | @intFromBool(anchor_end)) {
0b00 => std.mem.find(u8, nav_fqn, query) != null,
0b01 => std.mem.endsWith(u8, nav_fqn, query),
0b10 => std.mem.startsWith(u8, nav_fqn, query),
+18 -18
View File
@@ -215,7 +215,7 @@ pub const TrackedInst = extern struct {
};
pub fn unwrap(tracked_inst_index: TrackedInst.Index, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(tracked_inst_index) >> ip.tid_shift_32 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(tracked_inst_index) >> ip.tid_shift_32) & ip.getTidMask())),
.index = @backingInt(tracked_inst_index) & ip.getIndexMask(u32),
};
}
@@ -517,7 +517,7 @@ pub const ComptimeUnit = extern struct {
};
fn unwrap(id: Id, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(id) >> ip.tid_shift_32 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(id) >> ip.tid_shift_32) & ip.getTidMask())),
.index = @backingInt(id) & ip.getIndexMask(u31),
};
}
@@ -655,7 +655,7 @@ pub const Nav = struct {
};
fn unwrap(nav_index: Nav.Index, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(nav_index) >> ip.tid_shift_30 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(nav_index) >> ip.tid_shift_30) & ip.getTidMask())),
.index = @backingInt(nav_index) & ip.getIndexMask(u30),
};
}
@@ -1627,7 +1627,7 @@ pub const MapIndex = enum(u32) {
};
fn unwrap(map_index: MapIndex, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(map_index) >> ip.tid_shift_32 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(map_index) >> ip.tid_shift_32) & ip.getTidMask())),
.index = @backingInt(map_index) & ip.getIndexMask(u32),
};
}
@@ -1648,14 +1648,14 @@ pub const NamespaceIndex = enum(u32) {
assert(unwrapped.bucket_index <= ip.getIndexMask(u32) >> Local.namespaces_bucket_width);
assert(unwrapped.index <= Local.namespaces_bucket_mask);
return @fromBackingInt(@intCast(@shlExact(@as(u32, @backingInt(unwrapped.tid)), ip.tid_shift_32) |
unwrapped.bucket_index << Local.namespaces_bucket_width |
(unwrapped.bucket_index << Local.namespaces_bucket_width) |
unwrapped.index));
}
};
fn unwrap(namespace_index: NamespaceIndex, ip: *const InternPool) Unwrapped {
const index = @backingInt(namespace_index) & ip.getIndexMask(u32);
return .{
.tid = @fromBackingInt(@intCast(@backingInt(namespace_index) >> ip.tid_shift_32 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(namespace_index) >> ip.tid_shift_32) & ip.getTidMask())),
.bucket_index = index >> Local.namespaces_bucket_width,
.index = index & Local.namespaces_bucket_mask,
};
@@ -1696,7 +1696,7 @@ pub const FileIndex = enum(u32) {
};
pub fn unwrap(file_index: FileIndex, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(file_index) >> ip.tid_shift_32 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(file_index) >> ip.tid_shift_32) & ip.getTidMask())),
.index = @backingInt(file_index) & ip.getIndexMask(u32),
};
}
@@ -1755,7 +1755,7 @@ pub const String = enum(u32) {
};
fn unwrap(string: String, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(string) >> ip.tid_shift_32 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(string) >> ip.tid_shift_32) & ip.getTidMask())),
.index = @backingInt(string) & ip.getIndexMask(u32),
};
}
@@ -4199,7 +4199,7 @@ pub const Index = enum(u32) {
};
pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped {
return .{
.tid = @fromBackingInt(@intCast(@backingInt(index) >> ip.tid_shift_30 & ip.getTidMask())),
.tid = @fromBackingInt(@intCast((@backingInt(index) >> ip.tid_shift_30) & ip.getTidMask())),
.index = @backingInt(index) & ip.getIndexMask(u30),
};
}
@@ -6062,7 +6062,7 @@ pub const PtrNav = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6080,7 +6080,7 @@ pub const PtrUav = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6101,7 +6101,7 @@ pub const PtrUavAligned = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6119,7 +6119,7 @@ pub const PtrComptimeAlloc = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6137,7 +6137,7 @@ pub const PtrComptimeField = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6155,7 +6155,7 @@ pub const PtrBase = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6175,7 +6175,7 @@ pub const PtrBaseIndex = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -6191,7 +6191,7 @@ pub const PtrInt = struct {
};
}
fn byteOffset(data: @This()) u64 {
return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
}
};
@@ -12634,7 +12634,7 @@ const PackedCallingConvention = packed struct(u18) {
std.lang.CallingConvention.SpirvFragmentOptions => .{
.tag = tag,
.incoming_stack_alignment = .none,
.extra = @as(u4, @backingInt(pl.depth_assumption)) << 1 | @intFromBool(pl.pixel_centered_integer),
.extra = (@as(u4, @backingInt(pl.depth_assumption)) << 1) | @intFromBool(pl.pixel_centered_integer),
},
std.lang.CallingConvention.SpirvMeshOptions => .{
.tag = tag,
+2 -2
View File
@@ -29942,10 +29942,10 @@ fn coerceVarArgParam(
if (!uncasted_ty.validateExtern(.param_ty, zcu)) break :int inst;
const target = zcu.getTarget();
const uncasted_info = uncasted_ty.intInfo(zcu);
if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
if (uncasted_info.bits <= (target.cTypeBitSize(switch (uncasted_info.signedness) {
.signed => .int,
.unsigned => .uint,
}) orelse break :int inst) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
}) orelse break :int inst)) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
.signed => .c_int,
.unsigned => .c_uint,
}, inst, inst_src);
+2 -2
View File
@@ -164,7 +164,7 @@ const matchers = matchers: {
return @call(.auto, encode, args);
} else if (pattern_token[0] == '<') {
const symbol_name = comptime pattern_token[1 .. std.mem.findScalarPos(u8, pattern_token, 1, '|') orelse
pattern_token.len - 1];
(pattern_token.len - 1)];
const symbol = @field(Symbol, symbol_name);
const symbol_ptr = &@field(symbols, symbol_name);
const symbol_value = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).parse(source_token) orelse {
@@ -453,7 +453,7 @@ const SymbolSpec = union(enum) {
} else {
const Repr = std.math.FloatRepr(f16);
const repr: Repr = @bitCast(fimm);
if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 != 0 or switch (repr.exponent) {
if ((repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5)) != 0 or switch (repr.exponent) {
.denormal, .infinite => true,
else => std.math.cast(i3, repr.exponent.unbias() - 1) == null,
}) {
+4 -4
View File
@@ -31,7 +31,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
.unallocated => break :unallocated,
.pc_relative_addressing => |pc_relative_addressing| {
const group = pc_relative_addressing.group;
const imm = (@as(i33, group.immhi) << 2 | @as(i33, group.immlo) << 0) + @as(i33, switch (group.op) {
const imm = ((@as(i33, group.immhi) << 2) | (@as(i33, group.immlo) << 0)) + @as(i33, switch (group.op) {
.adr => aarch64.encoding.Instruction.size,
.adrp => 0,
});
@@ -311,7 +311,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
.hint => |hint| return writer.print("{f}{s}#0x{x}", .{
fmtCase(.hint, dis.case),
dis.mnemonic_operands_separator,
@as(u7, hint.CRm) << 3 | @as(u7, hint.op2) << 0,
(@as(u7, hint.CRm) << 3) | (@as(u7, hint.op2) << 0),
}),
else => |decoded| return writer.print("{f}", .{fmtCase(decoded, dis.case)}),
},
@@ -365,8 +365,8 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
dis.mnemonic_operands_separator,
group.Rt.decode(.{}).general(@fromBackingInt(@intCast(group.b5))).fmtCase(dis.case),
dis.operands_separator,
@as(u6, group.b5) << 5 |
@as(u6, group.b40) << 0,
(@as(u6, group.b5) << 5) |
(@as(u6, group.b40) << 0),
dis.operands_separator,
@as(u8, if (imm < 0) '-' else '+'),
@abs(imm) << 2,
+3 -3
View File
@@ -208,7 +208,7 @@ fn emitReloc(
};
try atom.addReloc(gpa, .{
.r_offset = offset,
.r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
.r_addend = @bitCast(addend),
}, zo);
} else if (lf.cast(.macho)) |mf| {
@@ -265,7 +265,7 @@ fn emitReloc(
};
try atom.addReloc(gpa, .{
.r_offset = offset,
.r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
.r_addend = @bitCast(addend),
}, zo);
} else if (lf.cast(.macho)) |mf| {
@@ -328,7 +328,7 @@ fn emitReloc(
};
try atom.addReloc(gpa, .{
.r_offset = offset,
.r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
.r_addend = @bitCast(addend),
}, zo);
} else if (lf.cast(.macho)) |mf| {
+4 -4
View File
@@ -8099,7 +8099,7 @@ fn movImmediate(isel: *Select, dst_reg: Register, src_imm: u64) !void {
.{ .immediate = .{
.N = @fromBackingInt(@intCast(elem_width >> 6)),
.immr = hi + mid_masked,
.imms = ((((lo + hi) & smask) | mid_masked) - 1) | -%@as(u6, @truncate(elem_width)) << 1,
.imms = ((((lo + hi) & smask) | mid_masked) - 1) | (-%@as(u6, @truncate(elem_width)) << 1),
} },
));
}
@@ -10831,7 +10831,7 @@ pub const Value = struct {
if (feat_fp16) {
const Repr = std.math.FloatRepr(f16);
const repr: Repr = @bitCast(imm);
if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {
if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
.denormal, .infinite => false,
else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
}) break :free try isel.emit(.fmov(mat.ra.h(), .{ .immediate = imm }));
@@ -10855,7 +10855,7 @@ pub const Value = struct {
} };
const Repr = std.math.FloatRepr(f32);
const repr: Repr = @bitCast(imm);
if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {
if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
.denormal, .infinite => false,
else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
}) break :free try isel.emit(.fmov(mat.ra.s(), .{ .immediate = @floatCast(imm) }));
@@ -10878,7 +10878,7 @@ pub const Value = struct {
} };
const Repr = std.math.FloatRepr(f64);
const repr: Repr = @bitCast(imm);
if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {
if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
.denormal, .infinite => false,
else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
}) break :free try isel.emit(.fmov(mat.ra.d(), .{ .immediate = @floatCast(imm) }));
+19 -19
View File
@@ -11886,9 +11886,9 @@ pub const Instruction = packed union {
.cmode = switch (arrangement) {
else => unreachable,
.@"4h", .@"8h" => @as(u3, 0b100) |
@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
(@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
.@"2s", .@"4s" => @as(u3, 0b000) |
@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
(@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
},
.imm3 = @intCast(shifted_immediate.immediate >> 5),
.Q = arrangement.size(),
@@ -12384,7 +12384,7 @@ pub const Instruction = packed union {
.dup = .{
.Rd = d.alias.encode(.{ .V = true }),
.Rn = n.alias.encode(.{ .V = true }),
.imm5 = @shlExact(@as(u5, n.format.element.index) << 1 | @as(u5, 0b1), @backingInt(elem_size)),
.imm5 = @shlExact((@as(u5, n.format.element.index) << 1) | @as(u5, 0b1), @backingInt(elem_size)),
},
} } };
},
@@ -12400,7 +12400,7 @@ pub const Instruction = packed union {
.Rd = d.alias.encode(.{ .V = true }),
.Rn = n.alias.encode(.{ .V = true }),
.imm4 = .element,
.imm5 = @shlExact(@as(u5, element.index) << 1 | @as(u5, 0b1), @backingInt(elem_size)),
.imm5 = @shlExact((@as(u5, element.index) << 1) | @as(u5, 0b1), @backingInt(elem_size)),
.Q = arrangement.size(),
},
} } };
@@ -14195,7 +14195,7 @@ pub const Instruction = packed union {
.Rd = d.alias.encode(.{ .V = true }),
.Rn = n.alias.encode(.{ .V = true }),
.imm4 = .{ .element = element.index << @intCast(@backingInt(elem_size)) },
.imm5 = (@as(u5, d.format.element.index) << 1 | @as(u5, 0b1) << 0) << @backingInt(elem_size),
.imm5 = ((@as(u5, d.format.element.index) << 1) | (@as(u5, 0b1) << 0)) << @backingInt(elem_size),
.op = .element,
},
} } };
@@ -14211,7 +14211,7 @@ pub const Instruction = packed union {
.Rd = d.alias.encode(.{ .V = true }),
.Rn = n.alias.encode(.{}),
.imm4 = .{ .general = .general },
.imm5 = (@as(u5, d.format.element.index) << 1 | @as(u5, 0b1) << 0) << @backingInt(elem_size),
.imm5 = ((@as(u5, d.format.element.index) << 1) | (@as(u5, 0b1) << 0)) << @backingInt(elem_size),
.op = .general,
},
} } };
@@ -15072,16 +15072,16 @@ pub const Instruction = packed union {
.lsl => |amount| switch (arrangement) {
else => unreachable,
.@"8b", .@"16b" => @as(u4, 0b1110) |
@as(u4, @as(u0, @intCast(@shrExact(amount, 3)))) << 1,
(@as(u4, @as(u0, @intCast(@shrExact(amount, 3)))) << 1),
.@"4h", .@"8h" => @as(u4, 0b1000) |
@as(u4, @as(u1, @intCast(@shrExact(amount, 3)))) << 1,
(@as(u4, @as(u1, @intCast(@shrExact(amount, 3)))) << 1),
.@"2s", .@"4s" => @as(u4, 0b0000) |
@as(u4, @as(u2, @intCast(@shrExact(amount, 3)))) << 1,
(@as(u4, @as(u2, @intCast(@shrExact(amount, 3)))) << 1),
},
.msl => |amount| switch (arrangement) {
else => unreachable,
.@"2s", .@"4s" => @as(u4, 0b1100) |
@as(u4, @as(u1, @intCast(@shrExact(amount, 3) - 1))) << 0,
(@as(u4, @as(u1, @intCast(@shrExact(amount, 3) - 1))) << 0),
},
.replicate => switch (arrangement) {
else => unreachable,
@@ -15345,9 +15345,9 @@ pub const Instruction = packed union {
.cmode = switch (arrangement) {
else => unreachable,
.@"4h", .@"8h" => @as(u3, 0b100) |
@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
(@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
.@"2s", .@"4s" => @as(u3, 0b000) |
@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
(@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
},
.imm3 = @intCast(shifted_immediate.immediate >> 5),
.Q = arrangement.size(),
@@ -15660,9 +15660,9 @@ pub const Instruction = packed union {
.Rn = n.alias.encode(.{ .V = true }),
.imm5 = switch (vs) {
else => unreachable,
.byte => @as(u5, @as(u4, @intCast(n.format.element.index))) << 1 | @as(u5, 0b1) << 0,
.half => @as(u5, @as(u3, @intCast(n.format.element.index))) << 2 | @as(u5, 0b10) << 0,
.single => @as(u5, @as(u2, @intCast(n.format.element.index))) << 3 | @as(u5, 0b100) << 0,
.byte => (@as(u5, @as(u4, @intCast(n.format.element.index))) << 1) | (@as(u5, 0b1) << 0),
.half => (@as(u5, @as(u3, @intCast(n.format.element.index))) << 2) | (@as(u5, 0b10) << 0),
.single => (@as(u5, @as(u2, @intCast(n.format.element.index))) << 3) | (@as(u5, 0b100) << 0),
},
.Q = sf,
},
@@ -16492,10 +16492,10 @@ pub const Instruction = packed union {
.Rn = n.alias.encode(.{ .V = true }),
.imm5 = switch (vs) {
else => unreachable,
.byte => @as(u5, @as(u4, @intCast(n.format.element.index))) << 1 | @as(u5, 0b1) << 0,
.half => @as(u5, @as(u3, @intCast(n.format.element.index))) << 2 | @as(u5, 0b10) << 0,
.single => @as(u5, @as(u2, @intCast(n.format.element.index))) << 3 | @as(u5, 0b100) << 0,
.double => @as(u5, @as(u1, @intCast(n.format.element.index))) << 4 | @as(u5, 0b1000) << 0,
.byte => (@as(u5, @as(u4, @intCast(n.format.element.index))) << 1) | (@as(u5, 0b1) << 0),
.half => (@as(u5, @as(u3, @intCast(n.format.element.index))) << 2) | (@as(u5, 0b10) << 0),
.single => (@as(u5, @as(u2, @intCast(n.format.element.index))) << 3) | (@as(u5, 0b100) << 0),
.double => (@as(u5, @as(u1, @intCast(n.format.element.index))) << 4) | (@as(u5, 0b1000) << 0),
},
.Q = sf,
},
+1 -1
View File
@@ -181,7 +181,7 @@ fn emitReloc(
const atom = zo.symbol(@backingInt(atom_index)).atom(ef).?;
try atom.addReloc(zcu.gpa, .{
.r_offset = offset,
.r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(reloc_type),
.r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(reloc_type),
.r_addend = @bitCast(addend),
}, zo);
} else unreachable;
+2 -2
View File
@@ -1764,7 +1764,7 @@ fn finishAir(
) !void {
const tomb_bits = func.liveness.getTombBits(inst);
for (0.., operands) |op_index, op| {
if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
if (func.reused_operands.isSet(op_index)) continue;
try func.processDeath(op.toIndexAllowNone() orelse continue);
}
@@ -6272,7 +6272,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {
"";
op.* = switch (args.items[
arg_map.get(op_str["%[".len .. mod_index orelse op_str.len - "]".len]) orelse
arg_map.get(op_str["%[".len .. mod_index orelse (op_str.len - "]".len)]) orelse
return func.fail("no matching constraint: '{s}'", .{op_str})
]) {
.lea_symbol => |sym_off| if (mem.eql(u8, modifier, "plt")) blk: {
+2 -2
View File
@@ -582,8 +582,8 @@ pub const Instruction = union(Lir.Format) {
.opcode = opcode,
.funct3 = @backingInt(amo.width),
.funct7 = @as(u7, amo.funct5) << 2 |
@as(u7, @intFromBool(ops[3].barrier == .rl)) << 1 |
.funct7 = (@as(u7, amo.funct5) << 2) |
(@as(u7, @intFromBool(ops[3].barrier == .rl)) << 1) |
@as(u7, @intFromBool(ops[4].barrier == .aq)),
},
else => unreachable,
+2 -2
View File
@@ -3475,11 +3475,11 @@ fn finishAirBookkeeping(self: *Self) void {
fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Air.Liveness.bpi - 1]Air.Inst.Ref) void {
const tomb_bits = self.liveness.getTombBits(inst);
for (0.., operands) |op_index, op| {
if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
if (self.reused_operands.isSet(op_index)) continue;
self.processDeath(op.toIndexAllowNone() orelse continue);
}
if (tomb_bits & 1 << (Air.Liveness.bpi - 1) == 0) {
if (tomb_bits & (1 << (Air.Liveness.bpi - 1)) == 0) {
log.debug("%{d} => {}", .{ inst, result });
const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
branch.inst_table.putAssumeCapacityNoClobber(inst, result);
+1 -1
View File
@@ -1191,7 +1191,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {
const truncated_value = if (backing_bits == 64)
value64
else
value64 & (@as(u64, 1) << @intCast(backing_bits)) - 1;
value64 & ((@as(u64, 1) << @intCast(backing_bits)) - 1);
break :blk switch (backing_bits) {
1...32 => .{ .uint32 = @truncate(truncated_value) },
+17 -17
View File
@@ -173255,7 +173255,7 @@ fn finishAir(
) !void {
const tomb_bits = self.liveness.getTombBits(inst);
for (0.., operands) |op_index, op| {
if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
if (self.reused_operands.isSet(op_index)) continue;
try self.processDeath(op.toIndexAllowNone() orelse continue, .{});
}
@@ -176321,7 +176321,7 @@ fn lowerSwitchBr(
const unsigned_condition_ty = try cg.pt.intType(.unsigned, cg.intInfo(condition_ty).?.bits);
const ExpectedContents = extern struct {
liveness_deaths: [1 << 8 | 1]Air.Inst.Index,
liveness_deaths: [(1 << 8) | 1]Air.Inst.Index,
bigint_limbs: [std.math.big.int.calcTwosCompLimbCount(1 << 10)]std.math.big.Limb,
relocs: [1 << 6]Mir.Inst.Index,
};
@@ -177310,7 +177310,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
else
"";
op.* = switch (args[
arg_map.get(op_str["%[".len .. colon orelse op_str.len - "]".len]) orelse
arg_map.get(op_str["%[".len .. colon orelse (op_str.len - "]".len)]) orelse
return self.fail("no matching constraint: '{s}'", .{op_str})
]) {
.immediate => |imm| if (std.mem.eql(u8, modifier, "") or
@@ -177454,7 +177454,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
else
"";
break :disp switch (args[
arg_map.get(op_str["%[".len .. colon orelse open - "]".len]) orelse
arg_map.get(op_str["%[".len .. colon orelse (open - "]".len)]) orelse
return self.fail("no matching constraint: '{s}'", .{op_str})
]) {
.immediate => |imm| if (std.mem.eql(u8, modifier, "") or
@@ -179566,7 +179566,7 @@ fn atomicOp(
};
defer if (mem_lock) |lock| self.register_manager.unlockReg(lock);
const use_sse = rmw_op orelse .Xchg != .Xchg and val_ty.isRuntimeFloat();
const use_sse = (rmw_op orelse .Xchg) != .Xchg and val_ty.isRuntimeFloat();
const strat: enum { lock, loop, libcall } = if (use_sse) .loop else switch (rmw_op orelse .Xchg) {
.Xchg,
.Add,
@@ -179626,7 +179626,7 @@ fn atomicOp(
try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);
const loop: Mir.Inst.Index = @intCast(self.mir_instructions.len);
if (!use_sse and rmw_op orelse .Xchg != .Xchg) {
if (!use_sse and (rmw_op orelse .Xchg) != .Xchg) {
try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax }, .{});
}
if (rmw_op) |op| if (use_sse) {
@@ -188854,7 +188854,7 @@ const Temp = struct {
for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {
if (op_temp.index == temp.index) continue;
if (op_temp.tracking(cg).short != .dead) try op_temp.die(cg);
if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
if (cg.reused_operands.isSet(op_index)) continue;
try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});
}
@@ -188916,7 +188916,7 @@ const Temp = struct {
}
for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {
if (op_temp.index != temp.index) continue;
if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
if (cg.reused_operands.isSet(op_index)) continue;
try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});
}
@@ -190117,9 +190117,9 @@ const Select = struct {
(@as(u64, std.math.maxInt(u64)) >> @intCast(res_scalar_info.bits - scalar_info.bits))),
.@"0x1p63_mem" => switch (res_scalar_info.bits) {
else => unreachable,
16 => @as(i64, @as(i16, @bitCast(@as(f16, 0x1p63)))) << 64 - 16,
32 => @as(i64, @as(i32, @bitCast(@as(f32, 0x1p63)))) << 64 - 32,
64 => @as(i64, @as(i64, @bitCast(@as(f64, 0x1p63)))) << 64 - 64,
16 => @as(i64, @as(i16, @bitCast(@as(f16, 0x1p63)))) << (64 - 16),
32 => @as(i64, @as(i32, @bitCast(@as(f32, 0x1p63)))) << (64 - 32),
64 => @as(i64, @as(i64, @bitCast(@as(f64, 0x1p63)))) << (64 - 64),
},
};
const shift: u6 = @intCast(64 - res_scalar_info.bits);
@@ -191518,8 +191518,8 @@ const Select = struct {
@as(SignedImm, @intCast(s.cg.nonBoolScalarBitSize(op.flags.base.ref.typeOf(s)))),
.log2_src0_elem_size => @intCast(std.math.log2(Select.Operand.Ref.src0.typeOf(s).indexableElem(s.cg.pt.zcu).abiSize(s.cg.pt.zcu))),
.elem_mask => @as(u8, std.math.maxInt(u8)) >> @intCast(
8 - ((s.cg.unalignedSize(op.flags.base.ref.typeOf(s)) - 1) %
@divExact(op.flags.base.size.bitSize(s.cg.target), 8) + 1 >>
8 - (((s.cg.unalignedSize(op.flags.base.ref.typeOf(s)) - 1) %
@divExact(op.flags.base.size.bitSize(s.cg.target), 8) + 1) >>
op.flags.index.scale.toLog2()),
),
inline .smin, .smax, .umax, .smin_shr_src1, .smax_shr_src1, .umax_shr_src1 => |adjust| switch (op.flags.base.size) {
@@ -191548,7 +191548,7 @@ const Select = struct {
},
.repeat => switch (SignedImm) {
else => unreachable,
i64 => return @as(i64, op.imm) << 32 | @as(u32, @bitCast(op.imm)),
i64 => return (@as(i64, op.imm) << 32) | @as(u32, @bitCast(op.imm)),
},
};
const rhs = op.flags.adjust.rhs.toLog2();
@@ -191559,10 +191559,10 @@ const Select = struct {
break :op_res op_res[0];
},
.div => @shrExact(lhs, rhs),
.div_8_down => lhs >> 3 & @as(SignedImm, -1) << rhs,
.div_8_down => (lhs >> 3) & (@as(SignedImm, -1) << rhs),
.rem_8_mul => lhs & ((@as(SignedImm, 8) << rhs) - 1),
.up_2_mul => ((lhs - 1) & @as(SignedImm, -2) << rhs) + (@as(SignedImm, 2) << rhs),
.up_32_mul => ((lhs - 1) & @as(SignedImm, -32) << rhs) + (@as(SignedImm, 32) << rhs),
.up_2_mul => ((lhs - 1) & (@as(SignedImm, -2) << rhs)) + (@as(SignedImm, 2) << rhs),
.up_32_mul => ((lhs - 1) & (@as(SignedImm, -32) << rhs)) + (@as(SignedImm, 32) << rhs),
};
const disp: SignedImm = @bitCast(@as(UnsignedImm, @as(u32, @bitCast(op.imm))));
return switch (op.flags.adjust.sign) {
+1 -1
View File
@@ -378,7 +378,7 @@ fn parseEncoding(dis: *Disassembler, prefixes: Prefixes) !?Encoding {
}
fn parseGpRegister(low_enc: u3, is_extended: bool, rex: Rex, bit_size: u64) Register {
const reg_id: u4 = @as(u4, @intCast(@intFromBool(is_extended))) << 3 | low_enc;
const reg_id: u4 = (@as(u4, @intCast(@intFromBool(is_extended))) << 3) | low_enc;
const reg = @as(Register, @fromBackingInt(@intCast(reg_id))).toBitSize(bit_size);
return switch (reg) {
.spl => if (rex.present or rex.isSet()) .spl else .ah,
+6 -6
View File
@@ -694,13 +694,13 @@ pub fn emitMir(emit: *Emit) Error!void {
for (emit.table_relocs.items) |table_reloc| try atom.addReloc(gpa, .{
.r_offset = table_reloc.source_offset,
.r_info = @as(u64, @backingInt(emit.atom_id)) << 32 | @backingInt(std.elf.R_X86_64.@"32S"),
.r_info = (@as(u64, @backingInt(emit.atom_id)) << 32) | @backingInt(std.elf.R_X86_64.@"32S"),
.r_addend = @as(i64, table_offset) + table_reloc.target_offset,
}, zo);
for (emit.lower.mir.table) |entry| {
try atom.addReloc(gpa, .{
.r_offset = table_offset,
.r_info = @as(u64, @backingInt(emit.atom_id)) << 32 | @backingInt(std.elf.R_X86_64.@"64"),
.r_info = (@as(u64, @backingInt(emit.atom_id)) << 32) | @backingInt(std.elf.R_X86_64.@"64"),
.r_addend = emit.code_offset_mapping.items[entry],
}, zo);
table_offset += ptr_size;
@@ -812,7 +812,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
.PC32;
try atom.addReloc(gpa, .{
.r_offset = end_offset - 4,
.r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
.r_addend = if (emit.pic) reloc.off - 4 else reloc.off,
}, zo);
} else if (emit.bin_file.cast(.macho)) |macho_file| {
@@ -854,7 +854,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
const r_type: std.elf.R_X86_64 = .PLT32;
try atom.addReloc(gpa, .{
.r_offset = end_offset - 4,
.r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
.r_addend = reloc.off - 4,
}, zo);
} else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
@@ -894,7 +894,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
const r_type: std.elf.R_X86_64 = if (emit.pic) .TLSLD else unreachable;
try atom.addReloc(gpa, .{
.r_offset = end_offset - 4,
.r_info = @as(u64, @backingInt(target_symbol)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(target_symbol)) << 32) | @backingInt(r_type),
.r_addend = reloc.off - 4,
}, zo);
} else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
@@ -912,7 +912,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
const r_type: std.elf.R_X86_64 = if (emit.pic) .DTPOFF32 else .TPOFF32;
try atom.addReloc(gpa, .{
.r_offset = end_offset - 4,
.r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),
.r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
.r_addend = reloc.off,
}, zo);
} else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
+1 -1
View File
@@ -1949,7 +1949,7 @@ pub const Memory = struct {
assert(mem.info.base == .reg);
return encoder.Instruction.Memory.initMoffs(
@fromBackingInt(@intCast(mem.base)),
@as(u64, mem.extra) << 32 | mem.off,
(@as(u64, mem.extra) << 32) | mem.off,
);
},
}
+1 -1
View File
@@ -664,7 +664,7 @@ pub const Register = enum(u8) {
.general_purpose, .gphi => if (reg.isExtended())
reg.enc()
else
@as(u3, @truncate(@as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3)),
@as(u3, @truncate(@as(u24, 0o54673120) >> (@as(u5, reg.enc()) * 3))),
.sse => 17 + @as(u6, reg.enc()),
.x87 => 33 + @as(u6, reg.enc()),
.mmx => 41 + @as(u6, reg.enc()),
+14 -14
View File
@@ -844,25 +844,25 @@ fn Encoder(comptime opts: Options) type {
try self.w.writeByte(0b1100_0100);
try self.w.writeByte(
@as(u8, ~@intFromBool(fields.r)) << 7 |
@as(u8, ~@intFromBool(fields.x)) << 6 |
@as(u8, ~@intFromBool(fields.b)) << 5 |
@as(u8, @backingInt(fields.m)) << 0,
(@as(u8, ~@intFromBool(fields.r)) << 7) |
(@as(u8, ~@intFromBool(fields.x)) << 6) |
(@as(u8, ~@intFromBool(fields.b)) << 5) |
(@as(u8, @backingInt(fields.m)) << 0),
);
try self.w.writeByte(
@as(u8, @intFromBool(fields.w)) << 7 |
@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3 |
@as(u8, @intFromBool(fields.l)) << 2 |
@as(u8, @backingInt(fields.p)) << 0,
(@as(u8, @intFromBool(fields.w)) << 7) |
(@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3) |
(@as(u8, @intFromBool(fields.l)) << 2) |
(@as(u8, @backingInt(fields.p)) << 0),
);
} else {
try self.w.writeByte(0b1100_0101);
try self.w.writeByte(
@as(u8, ~@intFromBool(fields.r)) << 7 |
@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3 |
@as(u8, @intFromBool(fields.l)) << 2 |
@as(u8, @backingInt(fields.p)) << 0,
(@as(u8, ~@intFromBool(fields.r)) << 7) |
(@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3) |
(@as(u8, @intFromBool(fields.l)) << 2) |
(@as(u8, @backingInt(fields.p)) << 0),
);
}
}
@@ -910,7 +910,7 @@ fn Encoder(comptime opts: Options) type {
///
/// Remember to add a REX prefix byte if reg or rm are extended!
pub fn modRm(self: Self, mod: u2, reg_or_opx: u3, rm: u3) !void {
try self.w.writeByte(@as(u8, mod) << 6 | @as(u8, reg_or_opx) << 3 | rm);
try self.w.writeByte((@as(u8, mod) << 6) | (@as(u8, reg_or_opx) << 3) | rm);
}
/// Construct a ModR/M byte using direct r/m addressing
@@ -996,7 +996,7 @@ fn Encoder(comptime opts: Options) type {
///
/// Remember to add a REX prefix byte if index or base are extended!
pub fn sib(self: Self, scale: u2, index: u3, base: u3) !void {
try self.w.writeByte(@as(u8, scale) << 6 | @as(u8, index) << 3 | base);
try self.w.writeByte((@as(u8, scale) << 6) | (@as(u8, index) << 3) | base);
}
/// Construct a SIB byte with scale * index + base, no frills.
+2 -1
View File
@@ -323,7 +323,8 @@ fn fmtPathDir(
if (mem.startsWith(u8, entry.name, ".")) continue;
if (is_dir or entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"))) {
const is_zig_or_zon = entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"));
if (is_dir or is_zig_or_zon) {
const full_path = try fs.path.join(fmt.gpa, &[_][]const u8{ file_path, entry.name });
defer fmt.gpa.free(full_path);
+3 -3
View File
@@ -697,7 +697,7 @@ const Unit = struct {
fw.writeByte(DW.LNS.extended_op) catch unreachable;
const extended_op_bytes = fw.end;
var op_len_bytes: u5 = 1;
while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) {
while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << (7 * op_len_bytes))) {
.lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,
.eq => {
// no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
@@ -893,7 +893,7 @@ const Entry = struct {
fw.writeUleb128(try dwarf.refAbbrevCode(.pad_n)) catch unreachable;
const abbrev_code_bytes = fw.end;
var block_len_bytes: u5 = 1;
while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) {
while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << (7 * block_len_bytes))) {
.lt => break fw.writeUleb128(len - abbrev_code_bytes - block_len_bytes) catch unreachable,
.eq => {
// no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
@@ -915,7 +915,7 @@ const Entry = struct {
fw.writeByte(DW.LNS.extended_op) catch unreachable;
const extended_op_bytes = fw.end;
var op_len_bytes: u5 = 1;
while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) {
while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << (7 * op_len_bytes))) {
.lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,
.eq => {
// no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
+2 -2
View File
@@ -1891,7 +1891,7 @@ pub fn genDebugInfoPadding(dwarf: *Dwarf, di_w: *std.Io.Writer, size: u64) std.I
var block_len_size: u5 = 1;
while (true) switch (std.math.order(
size - abbrev_code_size - block_len_size,
@as(u64, 1) << 7 * block_len_size,
@as(u64, 1) << (7 * block_len_size),
)) {
.lt => break try di_w.writeUleb128(size - abbrev_code_size - block_len_size),
.eq => {
@@ -2023,7 +2023,7 @@ pub fn genDebugLinePadding(dl_w: *std.Io.Writer, size: u64) std.Io.Writer.Error!
var op_len_size: u5 = 1;
while (true) switch (std.math.order(
size - extended_op_size - op_len_size,
@as(u64, 1) << 7 * op_len_size,
@as(u64, 1) << (7 * op_len_size),
)) {
.lt => break try dl_w.writeUleb128(size - extended_op_size - op_len_size),
.eq => {
+4 -4
View File
@@ -7694,11 +7694,11 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load
{
break :load_object;
}
const member = header.name() orelse member: {
const strtab_offset = header.nameOffset() catch |err| switch (err) {
const member = header.name() orelse (member: {
const strtab_offset = (header.nameOffset() catch |err| switch (err) {
error.Overflow => break :member error.Overflow,
error.InvalidCharacter => break :load_object,
} orelse break :load_object;
}) orelse break :load_object;
const strtab_written = strtab.written();
if (strtab_offset > strtab_written.len) break :member error.Overflow;
const member = std.mem.sliceTo(strtab_written[strtab_offset..], '\n');
@@ -7708,7 +7708,7 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load
member;
} catch |err| switch (err) {
error.Overflow => return diags.failParse(path, "bad member name offset", .{}),
};
});
try elf.loadObject(path, member, fr, .{ .offset = offset, .size = size });
}
try fr.seekTo(std.mem.alignForward(u64, offset + size, 2));
+1 -1
View File
@@ -228,7 +228,7 @@ pub fn generate(info: *UnwindInfo, macho_file: *MachO) !void {
if (next.getAtomAddress(macho_file) >= range_start_max) {
break;
} else if (info.getCommonEncoding(next.enc) != null or
page.getPageEncoding(next.enc) != null and !is_dwarf)
(page.getPageEncoding(next.enc) != null and !is_dwarf))
{
i += 1;
space_left -= 1;
+2 -2
View File
@@ -266,8 +266,8 @@ pub fn writeDylibIdLC(macho_file: *MachO, writer: *Writer) !void {
try writeDylibLC(.{
.cmd = .ID_DYLIB,
.name = install_name,
.current_version = @as(u32, @intCast(curr.major << 16 | curr.minor << 8 | curr.patch)),
.compatibility_version = @as(u32, @intCast(compat.major << 16 | compat.minor << 8 | compat.patch)),
.current_version = @as(u32, @intCast((curr.major << 16) | (curr.minor << 8) | curr.patch)),
.compatibility_version = @as(u32, @intCast((compat.major << 16) | (compat.minor << 8) | compat.patch)),
}, writer);
}
+1 -1
View File
@@ -1128,7 +1128,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
// indirect function table elements
const table_index: u32 = @intCast(
wasm.table_imports.getIndex(wasm.preloaded_strings.__indirect_function_table) orelse
wasm.table_imports.entries.len + wasm.tables.getIndex(.__indirect_function_table).?,
(wasm.table_imports.entries.len + wasm.tables.getIndex(.__indirect_function_table).?),
);
// passive with implicit 0-index table or set table index manually
const flags: u32 = if (table_index == 0) 0x0 else 0x02;
+2 -2
View File
@@ -90,8 +90,8 @@ fn bitSlice(
value: anytype,
comptime high: comptime_int,
comptime low: comptime_int,
) std.math.IntFittingRange(0, 1 << high - low) {
return @truncate((value >> low) & (1 << (high - low + 1)) - 1);
) std.math.IntFittingRange(0, 1 << (high - low)) {
return @truncate((value >> low) & ((1 << (high - low + 1)) - 1));
}
pub const Eflags = packed struct(u32) {
+1 -1
View File
@@ -3524,7 +3524,7 @@ fn buildOutputType(
};
const thread_limit = @min(
@max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1),
@max(n_jobs orelse (std.Thread.getCpuCount() catch 1), 1),
std.math.maxInt(Zcu.PerThread.IdBacking),
);
try setThreadLimit(arena, thread_limit);
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff. Show more