Skip to content

Commit 19abab9

Browse files
committed
Bring changes up-to-date with master
1 parent 77c3ab9 commit 19abab9

File tree

5 files changed

+40
-34
lines changed

5 files changed

+40
-34
lines changed

lib/std/math/big/int.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ pub const Mutable = struct {
17411741
assert(mask.positive);
17421742

17431743
r.positive = true;
1744-
std.mem.set(Limb, r.limbs, 0);
1744+
@memset(r.limbs, 0);
17451745

17461746
var mask_limb: Limb = mask.limbs[0];
17471747
var mask_limb_index: Limb = 0;
@@ -1787,7 +1787,7 @@ pub const Mutable = struct {
17871787
assert(mask.positive);
17881788

17891789
r.positive = true;
1790-
std.mem.set(Limb, r.limbs, 0);
1790+
@memset(r.limbs, 0);
17911791

17921792
var mask_limb: Limb = mask.limbs[0];
17931793
var mask_limb_index: Limb = 0;

src/Air.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,8 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
17511751
.work_item_id,
17521752
.work_group_size,
17531753
.work_group_id,
1754+
.deposit_bits,
1755+
.extract_bits,
17541756
=> false,
17551757

17561758
.assembly => @truncate(u1, air.extraData(Air.Asm, data.ty_pl.payload).data.flags >> 31) != 0,

src/Liveness/Verify.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
261261
.memset,
262262
.memset_safe,
263263
.memcpy,
264+
.deposit_bits,
265+
.extract_bits,
264266
=> {
265267
const bin_op = data[inst].bin_op;
266268
try self.verifyInstOperands(inst, .{ bin_op.lhs, bin_op.rhs, .none });

src/Sema.zig

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24153,7 +24153,7 @@ fn zirDepositExtractBits(
2415324153
extended: Zir.Inst.Extended.InstData,
2415424154
air_tag: Air.Inst.Tag,
2415524155
) CompileError!Air.Inst.Ref {
24156-
const target = sema.mod.getTarget();
24156+
const mod = sema.mod;
2415724157
const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2415824158
const src = LazySrcLoc.nodeOffset(extra.node);
2415924159

@@ -24166,12 +24166,12 @@ fn zirDepositExtractBits(
2416624166
const lhs_ty = sema.typeOf(uncasted_lhs);
2416724167
const rhs_ty = sema.typeOf(uncasted_rhs);
2416824168

24169-
if (!lhs_ty.isUnsignedInt() and lhs_ty.zigTypeTag() != .ComptimeInt) {
24170-
return sema.fail(block, lhs_src, "expected unsigned integer or 'comptime_int', found '{}'", .{lhs_ty.fmt(sema.mod)});
24169+
if (!lhs_ty.isUnsignedInt(mod) and lhs_ty.zigTypeTag(mod) != .ComptimeInt) {
24170+
return sema.fail(block, lhs_src, "expected unsigned integer or 'comptime_int', found '{}'", .{lhs_ty.fmt(mod)});
2417124171
}
2417224172

24173-
if (!rhs_ty.isUnsignedInt() and rhs_ty.zigTypeTag() != .ComptimeInt) {
24174-
return sema.fail(block, rhs_src, "expected unsigned integer or 'comptime_int', found '{}'", .{rhs_ty.fmt(sema.mod)});
24173+
if (!rhs_ty.isUnsignedInt(mod) and rhs_ty.zigTypeTag(mod) != .ComptimeInt) {
24174+
return sema.fail(block, rhs_src, "expected unsigned integer or 'comptime_int', found '{}'", .{rhs_ty.fmt(mod)});
2417524175
}
2417624176

2417724177
const instructions = &[_]Air.Inst.Ref{ uncasted_lhs, uncasted_rhs };
@@ -24190,7 +24190,7 @@ fn zirDepositExtractBits(
2419024190
error.AnalysisFail => {
2419124191
const msg = sema.err orelse return err;
2419224192
const val = (try sema.resolveMaybeUndefVal(uncasted_lhs)).?;
24193-
if (val.compareHetero(.lt, Value.zero, target)) {
24193+
if (val.orderAgainstZero(mod) == .lt) {
2419424194
try sema.errNote(block, src, msg, "parameters to {s} must be positive", .{builtin_name});
2419524195
}
2419624196
return err;
@@ -24202,7 +24202,7 @@ fn zirDepositExtractBits(
2420224202
error.AnalysisFail => {
2420324203
const msg = sema.err orelse return err;
2420424204
const val = (try sema.resolveMaybeUndefVal(uncasted_rhs)).?;
24205-
if (val.compareHetero(.lt, Value.zero, target)) {
24205+
if (val.orderAgainstZero(mod) == .lt) {
2420624206
try sema.errNote(block, src, msg, "parameters to {s} must be positive", .{builtin_name});
2420724207
}
2420824208
return err;
@@ -24215,18 +24215,18 @@ fn zirDepositExtractBits(
2421524215

2421624216
// We check for negative values here only if the type is a comptime_int, as negative values
2421724217
// would have otherwise been filtered out by coercion and the unsigned type restriction
24218-
if (dest_ty.zigTypeTag() == .ComptimeInt) {
24218+
if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
2421924219
if (maybe_lhs_val) |lhs_val| {
24220-
if (!lhs_val.isUndef() and lhs_val.compareHetero(.lt, Value.zero, target)) {
24221-
const err = try sema.errMsg(block, lhs_src, "use of negative value '{}'", .{lhs_val.fmtValue(lhs_ty, sema.mod)});
24220+
if (!lhs_val.isUndef(mod) and lhs_val.orderAgainstZero(mod) == .lt) {
24221+
const err = try sema.errMsg(block, lhs_src, "use of negative value '{}'", .{lhs_val.fmtValue(lhs_ty, mod)});
2422224222
try sema.errNote(block, src, err, "parameters to {s} must be positive", .{builtin_name});
2422324223
return sema.failWithOwnedErrorMsg(err);
2422424224
}
2422524225
}
2422624226

2422724227
if (maybe_rhs_val) |rhs_val| {
24228-
if (!rhs_val.isUndef() and rhs_val.compareHetero(.lt, Value.zero, target)) {
24229-
const err = try sema.errMsg(block, rhs_src, "use of negative value '{}'", .{rhs_val.fmtValue(rhs_ty, sema.mod)});
24228+
if (!rhs_val.isUndef(mod) and rhs_val.orderAgainstZero(mod) == .lt) {
24229+
const err = try sema.errMsg(block, rhs_src, "use of negative value '{}'", .{rhs_val.fmtValue(rhs_ty, mod)});
2423024230
try sema.errNote(block, src, err, "parameters to {s} must be positive", .{builtin_name});
2423124231
return sema.failWithOwnedErrorMsg(err);
2423224232
}
@@ -24236,19 +24236,19 @@ fn zirDepositExtractBits(
2423624236
// If either of the operands are zero, the result is zero
2423724237
// If either of the operands are undefined, the result is undefined
2423824238
if (maybe_lhs_val) |lhs_val| {
24239-
if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) return sema.addConstant(dest_ty, Value.zero);
24240-
if (lhs_val.isUndef()) return sema.addConstUndef(dest_ty);
24239+
if (lhs_val.orderAgainstZero(mod) == .eq) return sema.addConstant(dest_ty, try mod.intValue(dest_ty, 0));
24240+
if (lhs_val.isUndef(mod)) return sema.addConstUndef(dest_ty);
2424124241
}
2424224242
if (maybe_rhs_val) |rhs_val| {
24243-
if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) return sema.addConstant(dest_ty, Value.zero);
24244-
if (rhs_val.isUndef()) return sema.addConstUndef(dest_ty);
24243+
if (rhs_val.orderAgainstZero(mod) == .lt) return sema.addConstant(dest_ty, try mod.intValue(dest_ty, 0));
24244+
if (rhs_val.isUndef(mod)) return sema.addConstUndef(dest_ty);
2424524245
}
2424624246

2424724247
if (maybe_lhs_val) |lhs_val| {
2424824248
if (maybe_rhs_val) |rhs_val| {
2424924249
const dest_val = switch (air_tag) {
24250-
.deposit_bits => try sema.intDepositBits(lhs_val, rhs_val),
24251-
.extract_bits => try sema.intExtractBits(lhs_val, rhs_val),
24250+
.deposit_bits => try sema.intDepositBits(lhs_val, rhs_val, dest_ty),
24251+
.extract_bits => try sema.intExtractBits(lhs_val, rhs_val, dest_ty),
2425224252
else => unreachable,
2425324253
};
2425424254

@@ -36375,16 +36375,17 @@ fn intDepositBits(
3637536375
sema: *Sema,
3637636376
lhs: Value,
3637736377
rhs: Value,
36378+
ty: Type,
3637836379
) !Value {
3637936380
// TODO is this a performance issue? maybe we should try the operation without
3638036381
// resorting to BigInt first. For non-bigints, @intDeposit could be used?
36381-
const target = sema.mod.getTarget();
36382+
const mod = sema.mod;
3638236383
const arena = sema.arena;
3638336384

3638436385
var lhs_space: Value.BigIntSpace = undefined;
3638536386
var rhs_space: Value.BigIntSpace = undefined;
36386-
const source = lhs.toBigInt(&lhs_space, target);
36387-
const mask = rhs.toBigInt(&rhs_space, target);
36387+
const source = lhs.toBigInt(&lhs_space, mod);
36388+
const mask = rhs.toBigInt(&rhs_space, mod);
3638836389

3638936390
const result_limbs = try arena.alloc(
3639036391
std.math.big.Limb,
@@ -36394,24 +36395,25 @@ fn intDepositBits(
3639436395
var result = std.math.big.int.Mutable{ .limbs = result_limbs, .positive = undefined, .len = undefined };
3639536396

3639636397
result.depositBits(source, mask);
36397-
return Value.fromBigInt(arena, result.toConst());
36398+
return mod.intValue_big(ty, result.toConst());
3639836399
}
3639936400

3640036401
/// Asserts that the values are positive
3640136402
fn intExtractBits(
3640236403
sema: *Sema,
3640336404
lhs: Value,
3640436405
rhs: Value,
36406+
ty: Type,
3640536407
) !Value {
3640636408
// TODO is this a performance issue? maybe we should try the operation without
3640736409
// resorting to BigInt first. For non-bigints, @intExtract could be used?
36408-
const target = sema.mod.getTarget();
36410+
const mod = sema.mod;
3640936411
const arena = sema.arena;
3641036412

3641136413
var lhs_space: Value.BigIntSpace = undefined;
3641236414
var rhs_space: Value.BigIntSpace = undefined;
36413-
const source = lhs.toBigInt(&lhs_space, target);
36414-
const mask = rhs.toBigInt(&rhs_space, target);
36415+
const source = lhs.toBigInt(&lhs_space, mod);
36416+
const mask = rhs.toBigInt(&rhs_space, mod);
3641536417

3641636418
const result_limbs = try arena.alloc(
3641736419
std.math.big.Limb,
@@ -36421,7 +36423,7 @@ fn intExtractBits(
3642136423
var result = std.math.big.int.Mutable{ .limbs = result_limbs, .positive = undefined, .len = undefined };
3642236424

3642336425
result.extractBits(source, mask);
36424-
return Value.fromBigInt(arena, result.toConst());
36426+
return mod.intValue_big(ty, result.toConst());
3642536427
}
3642636428

3642736429
/// Asserts the values are comparable. Both operands have type `ty`.

src/codegen/llvm.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9456,7 +9456,7 @@ pub const FuncGen = struct {
94569456
const bin_op = self.air.instructions.items(.data)[inst].bin_op;
94579457
const lhs = try self.resolveInst(bin_op.lhs);
94589458
const rhs = try self.resolveInst(bin_op.rhs);
9459-
const inst_ty = self.air.typeOfIndex(inst);
9459+
const inst_ty = self.typeOfIndex(inst);
94609460

94619461
const target = self.dg.module.getTarget();
94629462
const params = [2]*llvm.Value{ lhs, rhs };
@@ -9465,7 +9465,7 @@ pub const FuncGen = struct {
94659465
// Doesn't have pdep
94669466
if (!std.Target.x86.featureSetHas(target.cpu.features, .bmi2)) break :blk;
94679467

9468-
const bits = inst_ty.intInfo(target).bits;
9468+
const bits = inst_ty.intInfo(self.dg.module).bits;
94699469
const supports_64 = tag == .x86_64;
94709470
// Integer size doesn't match the available instruction(s)
94719471
if (!(bits <= 32 or (bits <= 64 and supports_64))) break :blk;
@@ -9488,7 +9488,7 @@ pub const FuncGen = struct {
94889488
assert(target.cpu.arch.isX86());
94899489
assert(std.Target.x86.featureSetHas(target.cpu.features, .bmi2));
94909490

9491-
const bits = ty.intInfo(target).bits;
9491+
const bits = ty.intInfo(self.dg.module).bits;
94929492
const intrinsic_name = switch (bits) {
94939493
1...32 => "llvm.x86.bmi.pdep.32",
94949494
33...64 => "llvm.x86.bmi.pdep.64",
@@ -9603,7 +9603,7 @@ pub const FuncGen = struct {
96039603
const bin_op = self.air.instructions.items(.data)[inst].bin_op;
96049604
const lhs = try self.resolveInst(bin_op.lhs);
96059605
const rhs = try self.resolveInst(bin_op.rhs);
9606-
const inst_ty = self.air.typeOfIndex(inst);
9606+
const inst_ty = self.typeOfIndex(inst);
96079607

96089608
const target = self.dg.module.getTarget();
96099609
const params = [2]*llvm.Value{ lhs, rhs };
@@ -9612,7 +9612,7 @@ pub const FuncGen = struct {
96129612
// Doesn't have pext
96139613
if (!std.Target.x86.featureSetHas(target.cpu.features, .bmi2)) break :blk;
96149614

9615-
const bits = inst_ty.intInfo(target).bits;
9615+
const bits = inst_ty.intInfo(self.dg.module).bits;
96169616
const supports_64 = tag == .x86_64;
96179617
// Integer size doesn't match the available instruction(s)
96189618
if (!(bits <= 32 or (bits <= 64 and supports_64))) break :blk;
@@ -9635,7 +9635,7 @@ pub const FuncGen = struct {
96359635
assert(target.cpu.arch.isX86());
96369636
assert(std.Target.x86.featureSetHas(target.cpu.features, .bmi2));
96379637

9638-
const bits = ty.intInfo(target).bits;
9638+
const bits = ty.intInfo(self.dg.module).bits;
96399639
const intrinsic_name = switch (bits) {
96409640
1...32 => "llvm.x86.bmi.pext.32",
96419641
33...64 => "llvm.x86.bmi.pext.64",

0 commit comments

Comments
 (0)