mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
Add const-eval for trunc
This CL adds const-eval for `trunc`. Bug: tint:1581 Change-Id: If58f79ea70fe490746e30ed118d847c61edd8023 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110173 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
130b8b3941
commit
92af2b5693
@@ -2401,6 +2401,18 @@ ConstEval::Result ConstEval::tanh(const sem::Type* ty,
|
||||
return TransformElements(builder, ty, transform, args[0]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::trunc(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source&) {
|
||||
auto transform = [&](const sem::Constant* c0) {
|
||||
auto create = [&](auto i) {
|
||||
return CreateElement(builder, c0->Type(), decltype(i)(std::trunc(i.value)));
|
||||
};
|
||||
return Dispatch_fa_f32_f16(create, c0);
|
||||
};
|
||||
return TransformElements(builder, ty, transform, args[0]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::unpack2x16float(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source) {
|
||||
|
||||
@@ -737,6 +737,15 @@ class ConstEval {
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// trunc 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 trunc(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// unpack2x16float builtin
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
|
||||
@@ -1693,6 +1693,26 @@ INSTANTIATE_TEST_SUITE_P( //
|
||||
TanhCases<f32>(),
|
||||
TanhCases<f16>()))));
|
||||
|
||||
template <typename T>
|
||||
std::vector<Case> TruncCases() {
|
||||
std::vector<Case> cases = {C({T(0)}, T(0)), //
|
||||
C({-T(0)}, -T(0)), //
|
||||
C({T(1.5)}, T(1)), //
|
||||
C({-T(1.5)}, -T(1)),
|
||||
|
||||
// Vector tests
|
||||
C({Vec(T(0.0), T(1.5), -T(2.2))}, Vec(T(0), T(1), -T(2)))};
|
||||
|
||||
return cases;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P( //
|
||||
Trunc,
|
||||
ResolverConstEvalBuiltinTest,
|
||||
testing::Combine(testing::Values(sem::BuiltinType::kTrunc),
|
||||
testing::ValuesIn(Concat(TruncCases<AFloat>(), //
|
||||
TruncCases<f32>(),
|
||||
TruncCases<f16>()))));
|
||||
|
||||
std::vector<Case> Unpack4x8snormCases() {
|
||||
return {
|
||||
C({Val(u32(0x0000'0000))}, Vec(f32(0), f32(0), f32(0), f32(0))),
|
||||
|
||||
@@ -12729,24 +12729,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[977],
|
||||
/* return matcher indices */ &kMatcherIndices[1],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::trunc,
|
||||
},
|
||||
{
|
||||
/* [367] */
|
||||
/* 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[976],
|
||||
/* return matcher indices */ &kMatcherIndices[30],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::trunc,
|
||||
},
|
||||
{
|
||||
/* [368] */
|
||||
@@ -14551,8 +14551,8 @@ constexpr IntrinsicInfo kBuiltins[] = {
|
||||
},
|
||||
{
|
||||
/* [79] */
|
||||
/* fn trunc<T : f32_f16>(T) -> T */
|
||||
/* fn trunc<N : num, T : f32_f16>(vec<N, T>) -> vec<N, T> */
|
||||
/* fn trunc<T : fa_f32_f16>(@test_value(1.5) T) -> T */
|
||||
/* fn trunc<N : num, T : fa_f32_f16>(@test_value(1.5) vec<N, T>) -> vec<N, T> */
|
||||
/* num overloads */ 2,
|
||||
/* overloads */ &kOverloads[366],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user