Implement const-eval for acosh

This CL adds const-eval for the `acosh` test case. The generation of
`f16` values into test files is also fixed because `acosh` requires the
value to be `>= 1.0`

Bug: tint:1581
Change-Id: Iba2ca4d9d114034845475679346f042c8c66e571
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109341
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-11-10 02:39:08 +00:00
committed by Dawn LUCI CQ
parent da92e5cc84
commit e2fd5e09c6
174 changed files with 2721 additions and 777 deletions

View File

@@ -408,8 +408,8 @@ match storage
@const fn abs<N: num, T: fia_fiu32_f16>(vec<N, T>) -> vec<N, T>
@const fn acos<T: fa_f32_f16>(@test_value(0.96891242171) T) -> T
@const fn acos<N: num, T: fa_f32_f16>(@test_value(0.96891242171) vec<N, T>) -> vec<N, T>
fn acosh<T: f32_f16>(T) -> T
fn acosh<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T>
@const fn acosh<T: fa_f32_f16>(@test_value(2.0) T) -> T
@const fn acosh<N: num, T: fa_f32_f16>(@test_value(2.0) vec<N, T>) -> vec<N, T>
@const fn all(bool) -> bool
@const fn all<N: num>(vec<N, bool>) -> bool
@const fn any(bool) -> bool

View File

@@ -276,7 +276,12 @@ TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, Error_NoParams) {
TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Scalar_f32) {
auto param = GetParam();
auto* call = Call(param.name, 0.5_f);
auto val = 0.5_f;
if (param.name == std::string("acosh")) {
val = 1.0_f;
}
auto* call = Call(param.name, val);
WrapInFunction(call);
if (param.args_number == 1u) {
@@ -297,7 +302,10 @@ TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Scalar_f32) {
TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Vector_f32) {
auto param = GetParam();
auto* call = Call(param.name, vec3<f32>(0.5_f, 0.5_f, 0.8_f));
auto val = param.name == std::string("acosh") ? vec3<f32>(1.0_f, 2.0_f, 3.0_f)
: vec3<f32>(0.5_f, 0.5_f, 0.8_f);
auto* call = Call(param.name, val);
WrapInFunction(call);
if (param.args_number == 1u) {
@@ -462,7 +470,12 @@ TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Scalar_f16) {
Enable(ast::Extension::kF16);
auto* call = Call(param.name, 0.5_h);
auto val = 0.5_h;
if (param.name == std::string("acosh")) {
val = 1.0_h;
}
auto* call = Call(param.name, val);
WrapInFunction(call);
if (param.args_number == 1u) {
@@ -485,7 +498,10 @@ TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Vector_f16) {
Enable(ast::Extension::kF16);
auto* call = Call(param.name, vec3<f16>(0.5_h, 0.5_h, 0.8_h));
auto val = param.name == std::string("acosh") ? vec3<f16>(1.0_h, 2.0_h, 3.0_h)
: vec3<f16>(0.5_h, 0.5_h, 0.8_h);
auto* call = Call(param.name, val);
WrapInFunction(call);
if (param.args_number == 1u) {

View File

@@ -1674,6 +1674,24 @@ ConstEval::Result ConstEval::acos(const sem::Type* ty,
return TransformElements(builder, ty, transform, args[0]);
}
ConstEval::Result ConstEval::acosh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
auto transform = [&](const sem::Constant* c0) {
auto create = [&](auto i) -> ImplResult {
using NumberT = decltype(i);
if (i < NumberT(1.0)) {
AddError("acosh must be called with a value >= 1.0", source);
return utils::Failure;
}
return CreateElement(builder, c0->Type(), NumberT(std::acosh(i.value)));
};
return Dispatch_fa_f32_f16(create, c0);
};
return TransformElements(builder, ty, transform, args[0]);
}
ConstEval::Result ConstEval::all(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source&) {

View File

@@ -386,15 +386,6 @@ class ConstEval {
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// all builtin
/// @param ty the expression type
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result all(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// acos builtin
/// @param ty the expression type
/// @param args the input arguments
@@ -404,6 +395,24 @@ class ConstEval {
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// acosh builtin
/// @param ty the expression type
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result acosh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// all builtin
/// @param ty the expression type
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result all(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// any builtin
/// @param ty the expression type
/// @param args the input arguments

View File

@@ -506,6 +506,33 @@ INSTANTIATE_TEST_SUITE_P( //
AcosCases<f32, false>(),
AcosCases<f16, false>()))));
template <typename T, bool finite_only>
std::vector<Case> AcoshCases() {
std::vector<Case> cases = {
C({T(1.0)}, T(0.0)),
C({T(11.5919532755)}, kPi<T>).FloatComp(),
// Vector tests
C({Vec(T(1.0), T(11.5919532755))}, Vec(T(0), kPi<T>)).FloatComp(),
};
ConcatIntoIf<finite_only>( //
cases, std::vector<Case>{
E({T::Smallest()}, "12:34 error: acosh must be called with a value >= 1.0"),
E({-1.1_a}, "12:34 error: acosh must be called with a value >= 1.0"),
E({0_a}, "12:34 error: acosh must be called with a value >= 1.0"),
});
return cases;
}
INSTANTIATE_TEST_SUITE_P( //
Acosh,
ResolverConstEvalBuiltinTest,
testing::Combine(testing::Values(sem::BuiltinType::kAcosh),
testing::ValuesIn(Concat(AcoshCases<AFloat, true>(), //
AcoshCases<f32, false>(),
AcoshCases<f16, false>()))));
template <typename T, bool finite_only>
std::vector<Case> AsinCases() {
std::vector<Case> cases = {

View File

@@ -12153,24 +12153,24 @@ constexpr OverloadInfo kOverloads[] = {
/* num parameters */ 1,
/* num template types */ 1,
/* num template numbers */ 0,
/* template types */ &kTemplateTypes[25],
/* template types */ &kTemplateTypes[24],
/* template numbers */ &kTemplateNumbers[10],
/* parameters */ &kParameters[958],
/* return matcher indices */ &kMatcherIndices[1],
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* const eval */ nullptr,
/* const eval */ &ConstEval::acosh,
},
{
/* [319] */
/* num parameters */ 1,
/* num template types */ 1,
/* num template numbers */ 1,
/* template types */ &kTemplateTypes[25],
/* template types */ &kTemplateTypes[24],
/* template numbers */ &kTemplateNumbers[5],
/* parameters */ &kParameters[996],
/* return matcher indices */ &kMatcherIndices[30],
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* const eval */ nullptr,
/* const eval */ &ConstEval::acosh,
},
{
/* [320] */
@@ -14027,8 +14027,8 @@ constexpr IntrinsicInfo kBuiltins[] = {
},
{
/* [2] */
/* fn acosh<T : f32_f16>(T) -> T */
/* fn acosh<N : num, T : f32_f16>(vec<N, T>) -> vec<N, T> */
/* fn acosh<T : fa_f32_f16>(@test_value(2) T) -> T */
/* fn acosh<N : num, T : fa_f32_f16>(@test_value(2) vec<N, T>) -> vec<N, T> */
/* num overloads */ 2,
/* overloads */ &kOverloads[318],
},