tint/sem: Rename [un]signed Type helper methods
These only consider integers. Include that fact in their name Change-Id: I7b54c3fb0a6efd6f8de06fac7734a59eaf7829e5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113241 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
507736a43c
commit
6c337aa18e
|
@ -46,7 +46,7 @@ MutationList MutationFinderChangeUnaryOperators::FindMutations(
|
|||
type->Is<sem::Reference>() ? type->As<sem::Reference>()->StoreType() : type;
|
||||
|
||||
// Only signed integer or vector of signed integer can be mutated.
|
||||
if (!basic_type->is_signed_scalar_or_vector()) {
|
||||
if (!basic_type->is_signed_integer_scalar_or_vector()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ bool MutationChangeUnaryOperator::IsApplicable(const tint::Program& program,
|
|||
|
||||
// Only signed integer or vector of signed integer has more than 1
|
||||
// unary operators to change between.
|
||||
if (!basic_type->is_signed_scalar_or_vector()) {
|
||||
if (!basic_type->is_signed_integer_scalar_or_vector()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,12 +100,12 @@ std::vector<ast::UnaryOp> MutationWrapUnaryOperator::GetValidUnaryWrapper(
|
|||
return {ast::UnaryOp::kNot};
|
||||
}
|
||||
|
||||
if (expr_type->is_signed_scalar_or_vector() ||
|
||||
if (expr_type->is_signed_integer_scalar_or_vector() ||
|
||||
expr_type->is_abstract_integer_scalar_or_vector()) {
|
||||
return {ast::UnaryOp::kNegation, ast::UnaryOp::kComplement};
|
||||
}
|
||||
|
||||
if (expr_type->is_unsigned_scalar_or_vector()) {
|
||||
if (expr_type->is_unsigned_integer_scalar_or_vector()) {
|
||||
return {ast::UnaryOp::kComplement};
|
||||
}
|
||||
|
||||
|
|
|
@ -121,16 +121,16 @@ bool Type::is_unsigned_integer_vector() const {
|
|||
return Is([](const Vector* v) { return v->type()->Is<U32>(); });
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_scalar_or_vector() const {
|
||||
bool Type::is_unsigned_integer_scalar_or_vector() const {
|
||||
return Is<U32>() || is_unsigned_integer_vector();
|
||||
}
|
||||
|
||||
bool Type::is_signed_scalar_or_vector() const {
|
||||
bool Type::is_signed_integer_scalar_or_vector() const {
|
||||
return IsAnyOf<I32, AbstractInt>() || is_signed_integer_vector();
|
||||
}
|
||||
|
||||
bool Type::is_integer_scalar_or_vector() const {
|
||||
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
||||
return is_unsigned_integer_scalar_or_vector() || is_signed_integer_scalar_or_vector();
|
||||
}
|
||||
|
||||
bool Type::is_abstract_integer_vector() const {
|
||||
|
|
|
@ -126,9 +126,9 @@ class Type : public Castable<Type, Node> {
|
|||
/// @returns true if this type is an unsigned vector
|
||||
bool is_unsigned_integer_vector() const;
|
||||
/// @returns true if this type is an unsigned scalar or vector
|
||||
bool is_unsigned_scalar_or_vector() const;
|
||||
bool is_unsigned_integer_scalar_or_vector() const;
|
||||
/// @returns true if this type is a signed scalar or vector
|
||||
bool is_signed_scalar_or_vector() const;
|
||||
bool is_signed_integer_scalar_or_vector() const;
|
||||
/// @returns true if this type is an integer scalar or vector
|
||||
bool is_integer_scalar_or_vector() const;
|
||||
/// @returns true if this type is an abstract integer vector
|
||||
|
|
|
@ -359,7 +359,7 @@ struct BuiltinPolyfill::State {
|
|||
};
|
||||
|
||||
const ast::Expression* x = nullptr;
|
||||
if (ty->is_unsigned_scalar_or_vector()) {
|
||||
if (ty->is_unsigned_integer_scalar_or_vector()) {
|
||||
x = b.Expr("v");
|
||||
} else {
|
||||
// If ty is signed, then the value is inverted if the sign is negative
|
||||
|
@ -484,7 +484,7 @@ struct BuiltinPolyfill::State {
|
|||
|
||||
auto V = [&](auto value) -> const ast::Expression* {
|
||||
const ast::Expression* expr = b.Expr(value);
|
||||
if (!ty->is_unsigned_scalar_or_vector()) {
|
||||
if (!ty->is_unsigned_integer_scalar_or_vector()) {
|
||||
expr = b.Construct<i32>(expr);
|
||||
}
|
||||
if (ty->Is<sem::Vector>()) {
|
||||
|
@ -691,7 +691,7 @@ struct BuiltinPolyfill::State {
|
|||
|
||||
auto name = b.Symbols().New(is_div ? "tint_div" : "tint_mod");
|
||||
auto* use_one = b.Equal(rhs, ScalarOrVector(width, 0_a));
|
||||
if (lhs_ty->is_signed_scalar_or_vector()) {
|
||||
if (lhs_ty->is_signed_integer_scalar_or_vector()) {
|
||||
const auto bits = lhs_el_ty->Size() * 8;
|
||||
auto min_int = AInt(AInt::kLowestValue >> (AInt::kNumBits - bits));
|
||||
const ast::Expression* lhs_is_min = b.Equal(lhs, ScalarOrVector(width, min_int));
|
||||
|
|
|
@ -241,7 +241,7 @@ struct Robustness::State {
|
|||
|
||||
// texture_dims is u32 or vecN<u32>
|
||||
const auto* unsigned_max = b.Sub(texture_dims, scalar_or_vec(b.Expr(1_a), width));
|
||||
if (target_ty->is_signed_scalar_or_vector()) {
|
||||
if (target_ty->is_signed_integer_scalar_or_vector()) {
|
||||
const auto* zero = scalar_or_vec(b.Expr(0_a), width);
|
||||
const auto* signed_max = cast_to_signed(unsigned_max, width);
|
||||
ctx.Replace(coords_arg, b.Call("clamp", ctx.Clone(coords_arg), zero, signed_max));
|
||||
|
|
|
@ -396,13 +396,16 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression*
|
|||
return EmitExpression(out, expr->expr);
|
||||
}
|
||||
|
||||
if (src_type->is_float_scalar_or_vector() && dst_type->is_signed_scalar_or_vector()) {
|
||||
if (src_type->is_float_scalar_or_vector() && dst_type->is_signed_integer_scalar_or_vector()) {
|
||||
out << "floatBitsToInt";
|
||||
} else if (src_type->is_float_scalar_or_vector() && dst_type->is_unsigned_scalar_or_vector()) {
|
||||
} else if (src_type->is_float_scalar_or_vector() &&
|
||||
dst_type->is_unsigned_integer_scalar_or_vector()) {
|
||||
out << "floatBitsToUint";
|
||||
} else if (src_type->is_signed_scalar_or_vector() && dst_type->is_float_scalar_or_vector()) {
|
||||
} else if (src_type->is_signed_integer_scalar_or_vector() &&
|
||||
dst_type->is_float_scalar_or_vector()) {
|
||||
out << "intBitsToFloat";
|
||||
} else if (src_type->is_unsigned_scalar_or_vector() && dst_type->is_float_scalar_or_vector()) {
|
||||
} else if (src_type->is_unsigned_integer_scalar_or_vector() &&
|
||||
dst_type->is_float_scalar_or_vector()) {
|
||||
out << "uintBitsToFloat";
|
||||
} else {
|
||||
if (!EmitType(out, dst_type, ast::AddressSpace::kNone, ast::Access::kReadWrite, "")) {
|
||||
|
@ -823,7 +826,7 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out,
|
|||
return EmitEmulatedFMA(out, expr);
|
||||
}
|
||||
if (builtin->Type() == sem::BuiltinType::kAbs &&
|
||||
TypeOf(expr->args[0])->UnwrapRef()->is_unsigned_scalar_or_vector()) {
|
||||
TypeOf(expr->args[0])->UnwrapRef()->is_unsigned_integer_scalar_or_vector()) {
|
||||
// GLSL does not support abs() on unsigned arguments. However, it's a no-op.
|
||||
return EmitExpression(out, expr->args[0]);
|
||||
}
|
||||
|
@ -1401,7 +1404,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
|||
|
||||
auto emit_expr_as_signed = [&](const ast::Expression* e) {
|
||||
auto* ty = TypeOf(e)->UnwrapRef();
|
||||
if (!ty->is_unsigned_scalar_or_vector()) {
|
||||
if (!ty->is_unsigned_integer_scalar_or_vector()) {
|
||||
return EmitExpression(out, e);
|
||||
}
|
||||
emit_signed_int_type(ty);
|
||||
|
|
|
@ -987,7 +987,7 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out,
|
|||
// crbug.com/tint/1550
|
||||
if (type == sem::BuiltinType::kCountOneBits || type == sem::BuiltinType::kReverseBits) {
|
||||
auto* arg = call->Arguments()[0];
|
||||
if (arg->Type()->UnwrapRef()->is_signed_scalar_or_vector()) {
|
||||
if (arg->Type()->UnwrapRef()->is_signed_integer_scalar_or_vector()) {
|
||||
out << "asint(" << name << "(asuint(";
|
||||
if (!EmitExpression(out, arg->Declaration())) {
|
||||
return false;
|
||||
|
|
|
@ -528,7 +528,8 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, const ast::BinaryExpression* e
|
|||
|
||||
// Handle +/-/* of signed values
|
||||
if ((expr->IsAdd() || expr->IsSubtract() || expr->IsMultiply()) &&
|
||||
lhs_type->is_signed_scalar_or_vector() && rhs_type->is_signed_scalar_or_vector()) {
|
||||
lhs_type->is_signed_integer_scalar_or_vector() &&
|
||||
rhs_type->is_signed_integer_scalar_or_vector()) {
|
||||
// If lhs or rhs is a vector, use that type (support implicit scalar to
|
||||
// vector promotion)
|
||||
auto* target_type = lhs_type->Is<sem::Vector>()
|
||||
|
@ -561,7 +562,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, const ast::BinaryExpression* e
|
|||
// TODO(crbug.com/tint/1077): This may not be necessary. The MSL spec
|
||||
// seems to imply that left shifting a signed value is treated the same as
|
||||
// left shifting an unsigned value, but we need to make sure.
|
||||
if (expr->IsShiftLeft() && lhs_type->is_signed_scalar_or_vector()) {
|
||||
if (expr->IsShiftLeft() && lhs_type->is_signed_integer_scalar_or_vector()) {
|
||||
// Shift left: discards top bits, so convert first operand to unsigned
|
||||
// first, then convert result back to signed
|
||||
ScopedBitCast outer_int_cast(this, out, lhs_type, signed_type_of(lhs_type));
|
||||
|
@ -2918,7 +2919,7 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, const ast::UnaryOpExpression*
|
|||
// Handle `-e` when `e` is signed, so that we ensure that if `e` is the
|
||||
// largest negative value, it returns `e`.
|
||||
auto* expr_type = TypeOf(expr->expr)->UnwrapRef();
|
||||
if (expr->op == ast::UnaryOp::kNegation && expr_type->is_signed_scalar_or_vector()) {
|
||||
if (expr->op == ast::UnaryOp::kNegation && expr_type->is_signed_integer_scalar_or_vector()) {
|
||||
auto fn = utils::GetOrCreate(unary_minus_funcs_, expr_type, [&]() -> std::string {
|
||||
// e.g.:
|
||||
// int tint_unary_minus(const int v) {
|
||||
|
|
|
@ -117,7 +117,7 @@ uint32_t builtin_to_glsl_method(const sem::Builtin* builtin) {
|
|||
case BuiltinType::kClamp:
|
||||
if (builtin->ReturnType()->is_float_scalar_or_vector()) {
|
||||
return GLSLstd450NClamp;
|
||||
} else if (builtin->ReturnType()->is_unsigned_scalar_or_vector()) {
|
||||
} else if (builtin->ReturnType()->is_unsigned_integer_scalar_or_vector()) {
|
||||
return GLSLstd450UClamp;
|
||||
} else {
|
||||
return GLSLstd450SClamp;
|
||||
|
@ -161,7 +161,7 @@ uint32_t builtin_to_glsl_method(const sem::Builtin* builtin) {
|
|||
case BuiltinType::kMax:
|
||||
if (builtin->ReturnType()->is_float_scalar_or_vector()) {
|
||||
return GLSLstd450NMax;
|
||||
} else if (builtin->ReturnType()->is_unsigned_scalar_or_vector()) {
|
||||
} else if (builtin->ReturnType()->is_unsigned_integer_scalar_or_vector()) {
|
||||
return GLSLstd450UMax;
|
||||
} else {
|
||||
return GLSLstd450SMax;
|
||||
|
@ -169,7 +169,7 @@ uint32_t builtin_to_glsl_method(const sem::Builtin* builtin) {
|
|||
case BuiltinType::kMin:
|
||||
if (builtin->ReturnType()->is_float_scalar_or_vector()) {
|
||||
return GLSLstd450NMin;
|
||||
} else if (builtin->ReturnType()->is_unsigned_scalar_or_vector()) {
|
||||
} else if (builtin->ReturnType()->is_unsigned_integer_scalar_or_vector()) {
|
||||
return GLSLstd450UMin;
|
||||
} else {
|
||||
return GLSLstd450SMin;
|
||||
|
@ -2052,7 +2052,7 @@ uint32_t Builder::GenerateBinaryExpression(const ast::BinaryExpression* expr) {
|
|||
bool lhs_is_float_or_vec = lhs_type->is_float_scalar_or_vector();
|
||||
bool lhs_is_bool_or_vec = lhs_type->is_bool_scalar_or_vector();
|
||||
bool lhs_is_integer_or_vec = lhs_type->is_integer_scalar_or_vector();
|
||||
bool lhs_is_unsigned = lhs_type->is_unsigned_scalar_or_vector();
|
||||
bool lhs_is_unsigned = lhs_type->is_unsigned_integer_scalar_or_vector();
|
||||
|
||||
spv::Op op = spv::Op::OpNop;
|
||||
if (expr->IsAnd()) {
|
||||
|
@ -2187,7 +2187,7 @@ uint32_t Builder::GenerateBinaryExpression(const ast::BinaryExpression* expr) {
|
|||
}
|
||||
} else if (expr->IsShiftLeft()) {
|
||||
op = spv::Op::OpShiftLeftLogical;
|
||||
} else if (expr->IsShiftRight() && lhs_type->is_signed_scalar_or_vector()) {
|
||||
} else if (expr->IsShiftRight() && lhs_type->is_signed_integer_scalar_or_vector()) {
|
||||
// A shift right with a signed LHS is an arithmetic shift.
|
||||
op = spv::Op::OpShiftRightArithmetic;
|
||||
} else if (expr->IsShiftRight()) {
|
||||
|
@ -2458,7 +2458,7 @@ uint32_t Builder::GenerateBuiltinCall(const sem::Call* call, const sem::Builtin*
|
|||
op = spv::Op::OpDPdyFine;
|
||||
break;
|
||||
case BuiltinType::kExtractBits:
|
||||
op = builtin->Parameters()[0]->Type()->is_unsigned_scalar_or_vector()
|
||||
op = builtin->Parameters()[0]->Type()->is_unsigned_integer_scalar_or_vector()
|
||||
? spv::Op::OpBitFieldUExtract
|
||||
: spv::Op::OpBitFieldSExtract;
|
||||
break;
|
||||
|
@ -2543,7 +2543,7 @@ uint32_t Builder::GenerateBuiltinCall(const sem::Call* call, const sem::Builtin*
|
|||
op = spv::Op::OpTranspose;
|
||||
break;
|
||||
case BuiltinType::kAbs:
|
||||
if (builtin->ReturnType()->is_unsigned_scalar_or_vector()) {
|
||||
if (builtin->ReturnType()->is_unsigned_integer_scalar_or_vector()) {
|
||||
// abs() only operates on *signed* integers.
|
||||
// This is a no-op for unsigned integers.
|
||||
return get_arg_as_value_id(0);
|
||||
|
|
Loading…
Reference in New Issue