diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc index c8dff2cc8d..16e0ab31c1 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/change_unary_operators.cc @@ -46,7 +46,7 @@ MutationList MutationFinderChangeUnaryOperators::FindMutations( type->Is() ? type->As()->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; } diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc index d32d569748..c9bed0656c 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_unary_operator.cc @@ -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; } diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc index d6612f5486..499a23f3a7 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc @@ -100,12 +100,12 @@ std::vector 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}; } diff --git a/src/tint/sem/type.cc b/src/tint/sem/type.cc index 51afc12a4a..1327c039fd 100644 --- a/src/tint/sem/type.cc +++ b/src/tint/sem/type.cc @@ -121,16 +121,16 @@ bool Type::is_unsigned_integer_vector() const { return Is([](const Vector* v) { return v->type()->Is(); }); } -bool Type::is_unsigned_scalar_or_vector() const { +bool Type::is_unsigned_integer_scalar_or_vector() const { return Is() || is_unsigned_integer_vector(); } -bool Type::is_signed_scalar_or_vector() const { +bool Type::is_signed_integer_scalar_or_vector() const { return IsAnyOf() || 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 { diff --git a/src/tint/sem/type.h b/src/tint/sem/type.h index 38f5ba8abc..5b6772b10a 100644 --- a/src/tint/sem/type.h +++ b/src/tint/sem/type.h @@ -126,9 +126,9 @@ class Type : public Castable { /// @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 diff --git a/src/tint/transform/builtin_polyfill.cc b/src/tint/transform/builtin_polyfill.cc index 62f8f4c906..310cb81e2b 100644 --- a/src/tint/transform/builtin_polyfill.cc +++ b/src/tint/transform/builtin_polyfill.cc @@ -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(expr); } if (ty->Is()) { @@ -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)); diff --git a/src/tint/transform/robustness.cc b/src/tint/transform/robustness.cc index c9f62923e5..6c94e90480 100644 --- a/src/tint/transform/robustness.cc +++ b/src/tint/transform/robustness.cc @@ -241,7 +241,7 @@ struct Robustness::State { // texture_dims is u32 or vecN 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)); diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 4f86d359ac..f72fe293ea 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -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); diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 944481c98c..25ac60664a 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -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; diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 1056026f95..a38e267ee0 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -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() @@ -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) { diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index b5910ffde9..670da7e53f 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -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);