mirror of
https://github.com/ziglang/zig.git
synced 2025-12-09 15:53:08 +00:00
stage1: Allow comparison with comptime-known vectors
Since comptime_{int,float} vectors are not allowed (thanks $DEITY) we
can use the element type infos to determine the minimum operand size.
This commit is contained in:
parent
56b52dd0a3
commit
cbbcf60968
14
src/ir.cpp
14
src/ir.cpp
@ -16715,16 +16715,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
|
|||||||
}
|
}
|
||||||
ZigType *dest_float_type = nullptr;
|
ZigType *dest_float_type = nullptr;
|
||||||
uint32_t op1_bits;
|
uint32_t op1_bits;
|
||||||
if (instr_is_comptime(op1)) {
|
if (instr_is_comptime(op1) && result_type->id != ZigTypeIdVector) {
|
||||||
ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
|
ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
|
||||||
if (op1_val == nullptr)
|
if (op1_val == nullptr)
|
||||||
return ira->codegen->invalid_inst_gen;
|
return ira->codegen->invalid_inst_gen;
|
||||||
if (op1_val->special == ConstValSpecialUndef)
|
if (op1_val->special == ConstValSpecialUndef)
|
||||||
return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
|
return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
|
||||||
if (result_type->id == ZigTypeIdVector) {
|
|
||||||
ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
|
|
||||||
return ira->codegen->invalid_inst_gen;
|
|
||||||
}
|
|
||||||
bool is_unsigned;
|
bool is_unsigned;
|
||||||
if (op1_is_float) {
|
if (op1_is_float) {
|
||||||
BigInt bigint = {};
|
BigInt bigint = {};
|
||||||
@ -16750,6 +16746,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
|
|||||||
op1_bits += 1;
|
op1_bits += 1;
|
||||||
}
|
}
|
||||||
} else if (op1_is_float) {
|
} else if (op1_is_float) {
|
||||||
|
ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr);
|
||||||
dest_float_type = op1_scalar_type;
|
dest_float_type = op1_scalar_type;
|
||||||
} else {
|
} else {
|
||||||
ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);
|
ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);
|
||||||
@ -16759,16 +16756,12 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t op2_bits;
|
uint32_t op2_bits;
|
||||||
if (instr_is_comptime(op2)) {
|
if (instr_is_comptime(op2) && result_type->id != ZigTypeIdVector) {
|
||||||
ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
|
ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
|
||||||
if (op2_val == nullptr)
|
if (op2_val == nullptr)
|
||||||
return ira->codegen->invalid_inst_gen;
|
return ira->codegen->invalid_inst_gen;
|
||||||
if (op2_val->special == ConstValSpecialUndef)
|
if (op2_val->special == ConstValSpecialUndef)
|
||||||
return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
|
return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
|
||||||
if (result_type->id == ZigTypeIdVector) {
|
|
||||||
ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
|
|
||||||
return ira->codegen->invalid_inst_gen;
|
|
||||||
}
|
|
||||||
bool is_unsigned;
|
bool is_unsigned;
|
||||||
if (op2_is_float) {
|
if (op2_is_float) {
|
||||||
BigInt bigint = {};
|
BigInt bigint = {};
|
||||||
@ -16794,6 +16787,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
|
|||||||
op2_bits += 1;
|
op2_bits += 1;
|
||||||
}
|
}
|
||||||
} else if (op2_is_float) {
|
} else if (op2_is_float) {
|
||||||
|
ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr);
|
||||||
dest_float_type = op2_scalar_type;
|
dest_float_type = op2_scalar_type;
|
||||||
} else {
|
} else {
|
||||||
ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);
|
ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);
|
||||||
|
|||||||
@ -274,6 +274,14 @@ test "vector comparison operators" {
|
|||||||
expectEqual(@splat(4, true), v1 != v3);
|
expectEqual(@splat(4, true), v1 != v3);
|
||||||
expectEqual(@splat(4, false), v1 != v2);
|
expectEqual(@splat(4, false), v1 != v2);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// Comptime-known LHS/RHS
|
||||||
|
var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
|
||||||
|
const v2 = @splat(4, @as(u32, 2));
|
||||||
|
const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
|
||||||
|
expectEqual(v3, v1 == v2);
|
||||||
|
expectEqual(v3, v2 == v1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
S.doTheTest();
|
S.doTheTest();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user