mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
parent
c842deea75
commit
1e7dcaa3ae
2 changed files with 21 additions and 4 deletions
12
src/Sema.zig
12
src/Sema.zig
|
|
@ -30158,15 +30158,19 @@ fn cmpVector(
|
|||
assert(rhs_ty.zigTypeTag() == .Vector);
|
||||
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
|
||||
|
||||
const resolved_ty = try sema.resolvePeerTypes(block, src, &.{ lhs, rhs }, .{ .override = &.{ lhs_src, rhs_src } });
|
||||
const casted_lhs = try sema.coerce(block, resolved_ty, lhs, lhs_src);
|
||||
const casted_rhs = try sema.coerce(block, resolved_ty, rhs, rhs_src);
|
||||
|
||||
const result_ty = try Type.vector(sema.arena, lhs_ty.vectorLen(), Type.bool);
|
||||
|
||||
const runtime_src: LazySrcLoc = src: {
|
||||
if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
|
||||
if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
|
||||
if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
|
||||
if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
|
||||
if (lhs_val.isUndef() or rhs_val.isUndef()) {
|
||||
return sema.addConstUndef(result_ty);
|
||||
}
|
||||
const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, lhs_ty);
|
||||
const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty);
|
||||
return sema.addConstant(result_ty, cmp_val);
|
||||
} else {
|
||||
break :src rhs_src;
|
||||
|
|
@ -30177,7 +30181,7 @@ fn cmpVector(
|
|||
};
|
||||
|
||||
try sema.requireRuntimeBlock(block, src, runtime_src);
|
||||
return block.addCmpVector(lhs, rhs, op);
|
||||
return block.addCmpVector(casted_lhs, casted_rhs, op);
|
||||
}
|
||||
|
||||
fn wrapOptional(
|
||||
|
|
|
|||
|
|
@ -1330,3 +1330,16 @@ test "addition of vectors represented as strings" {
|
|||
const bar: V = @typeName(u32).*;
|
||||
try expectEqual(V{ 219, 162, 161 }, foo + bar);
|
||||
}
|
||||
|
||||
test "compare vectors with different element types" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
|
||||
|
||||
var a: @Vector(2, u8) = .{ 1, 2 };
|
||||
var b: @Vector(2, u9) = .{ 3, 0 };
|
||||
try expectEqual(@Vector(2, bool){ true, false }, a < b);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue