@@ -24153,7 +24153,7 @@ fn zirDepositExtractBits(
24153
24153
extended: Zir.Inst.Extended.InstData,
24154
24154
air_tag: Air.Inst.Tag,
24155
24155
) CompileError!Air.Inst.Ref {
24156
- const target = sema.mod.getTarget() ;
24156
+ const mod = sema.mod;
24157
24157
const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
24158
24158
const src = LazySrcLoc.nodeOffset(extra.node);
24159
24159
@@ -24166,12 +24166,12 @@ fn zirDepositExtractBits(
24166
24166
const lhs_ty = sema.typeOf(uncasted_lhs);
24167
24167
const rhs_ty = sema.typeOf(uncasted_rhs);
24168
24168
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)});
24171
24171
}
24172
24172
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)});
24175
24175
}
24176
24176
24177
24177
const instructions = &[_]Air.Inst.Ref{ uncasted_lhs, uncasted_rhs };
@@ -24190,7 +24190,7 @@ fn zirDepositExtractBits(
24190
24190
error.AnalysisFail => {
24191
24191
const msg = sema.err orelse return err;
24192
24192
const val = (try sema.resolveMaybeUndefVal(uncasted_lhs)).?;
24193
- if (val.compareHetero(.lt, Value.zero, target) ) {
24193
+ if (val.orderAgainstZero(mod) == .lt ) {
24194
24194
try sema.errNote(block, src, msg, "parameters to {s} must be positive", .{builtin_name});
24195
24195
}
24196
24196
return err;
@@ -24202,7 +24202,7 @@ fn zirDepositExtractBits(
24202
24202
error.AnalysisFail => {
24203
24203
const msg = sema.err orelse return err;
24204
24204
const val = (try sema.resolveMaybeUndefVal(uncasted_rhs)).?;
24205
- if (val.compareHetero(.lt, Value.zero, target) ) {
24205
+ if (val.orderAgainstZero(mod) == .lt ) {
24206
24206
try sema.errNote(block, src, msg, "parameters to {s} must be positive", .{builtin_name});
24207
24207
}
24208
24208
return err;
@@ -24215,18 +24215,18 @@ fn zirDepositExtractBits(
24215
24215
24216
24216
// We check for negative values here only if the type is a comptime_int, as negative values
24217
24217
// 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) {
24219
24219
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)});
24222
24222
try sema.errNote(block, src, err, "parameters to {s} must be positive", .{builtin_name});
24223
24223
return sema.failWithOwnedErrorMsg(err);
24224
24224
}
24225
24225
}
24226
24226
24227
24227
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)});
24230
24230
try sema.errNote(block, src, err, "parameters to {s} must be positive", .{builtin_name});
24231
24231
return sema.failWithOwnedErrorMsg(err);
24232
24232
}
@@ -24236,19 +24236,19 @@ fn zirDepositExtractBits(
24236
24236
// If either of the operands are zero, the result is zero
24237
24237
// If either of the operands are undefined, the result is undefined
24238
24238
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);
24241
24241
}
24242
24242
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);
24245
24245
}
24246
24246
24247
24247
if (maybe_lhs_val) |lhs_val| {
24248
24248
if (maybe_rhs_val) |rhs_val| {
24249
24249
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 ),
24252
24252
else => unreachable,
24253
24253
};
24254
24254
@@ -36375,16 +36375,17 @@ fn intDepositBits(
36375
36375
sema: *Sema,
36376
36376
lhs: Value,
36377
36377
rhs: Value,
36378
+ ty: Type,
36378
36379
) !Value {
36379
36380
// TODO is this a performance issue? maybe we should try the operation without
36380
36381
// resorting to BigInt first. For non-bigints, @intDeposit could be used?
36381
- const target = sema.mod.getTarget() ;
36382
+ const mod = sema.mod;
36382
36383
const arena = sema.arena;
36383
36384
36384
36385
var lhs_space: Value.BigIntSpace = undefined;
36385
36386
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 );
36388
36389
36389
36390
const result_limbs = try arena.alloc(
36390
36391
std.math.big.Limb,
@@ -36394,24 +36395,25 @@ fn intDepositBits(
36394
36395
var result = std.math.big.int.Mutable{ .limbs = result_limbs, .positive = undefined, .len = undefined };
36395
36396
36396
36397
result.depositBits(source, mask);
36397
- return Value.fromBigInt(arena , result.toConst());
36398
+ return mod.intValue_big(ty , result.toConst());
36398
36399
}
36399
36400
36400
36401
/// Asserts that the values are positive
36401
36402
fn intExtractBits(
36402
36403
sema: *Sema,
36403
36404
lhs: Value,
36404
36405
rhs: Value,
36406
+ ty: Type,
36405
36407
) !Value {
36406
36408
// TODO is this a performance issue? maybe we should try the operation without
36407
36409
// resorting to BigInt first. For non-bigints, @intExtract could be used?
36408
- const target = sema.mod.getTarget() ;
36410
+ const mod = sema.mod;
36409
36411
const arena = sema.arena;
36410
36412
36411
36413
var lhs_space: Value.BigIntSpace = undefined;
36412
36414
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 );
36415
36417
36416
36418
const result_limbs = try arena.alloc(
36417
36419
std.math.big.Limb,
@@ -36421,7 +36423,7 @@ fn intExtractBits(
36421
36423
var result = std.math.big.int.Mutable{ .limbs = result_limbs, .positive = undefined, .len = undefined };
36422
36424
36423
36425
result.extractBits(source, mask);
36424
- return Value.fromBigInt(arena , result.toConst());
36426
+ return mod.intValue_big(ty , result.toConst());
36425
36427
}
36426
36428
36427
36429
/// Asserts the values are comparable. Both operands have type `ty`.
0 commit comments