mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
Add const-eval for floor.
This Cl adds const-eval for the `floor` builtin. Bug: tint:1581 Change-Id: I992eba3aa6c66707e923907a4bb912c2f6f8d290 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108343 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
11cecc1e4f
commit
91e27f25f9
@@ -1905,6 +1905,18 @@ ConstEval::Result ConstEval::firstTrailingBit(const sem::Type* ty,
|
||||
return TransformElements(builder, ty, transform, args[0]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::floor(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source&) {
|
||||
auto transform = [&](const sem::Constant* c0) {
|
||||
auto create = [&](auto e) {
|
||||
return CreateElement(builder, c0->Type(), decltype(e)(std::floor(e)));
|
||||
};
|
||||
return Dispatch_fa_f32_f16(create, c0);
|
||||
};
|
||||
return TransformElements(builder, ty, transform, args[0]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::insertBits(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source) {
|
||||
|
||||
@@ -530,6 +530,15 @@ class ConstEval {
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// floor 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 floor(const sem::Type* ty,
|
||||
utils::VectorRef<const sem::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// insertBits builtin
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
|
||||
@@ -884,6 +884,37 @@ INSTANTIATE_TEST_SUITE_P( //
|
||||
testing::ValuesIn(Concat(FirstTrailingBitCases<i32>(), //
|
||||
FirstTrailingBitCases<u32>()))));
|
||||
|
||||
template <typename T, bool finite_only>
|
||||
std::vector<Case> FloorCases() {
|
||||
std::vector<Case> cases = {
|
||||
C({T(0)}, T(0)),
|
||||
C({-T(0)}, -T(0)),
|
||||
C({-T(1.5)}, -T(2.0)),
|
||||
C({T(1.5)}, T(1.0)),
|
||||
C({T::Lowest()}, T::Lowest()),
|
||||
C({T::Highest()}, T::Highest()),
|
||||
|
||||
C({Vec(T(0), T(1.5), -T(1.5))}, Vec(T(0), T(1.0), -T(2.0))),
|
||||
};
|
||||
|
||||
ConcatIntoIf<!finite_only>(
|
||||
cases, std::vector<Case>{
|
||||
C({-T::Inf()}, -T::Inf()),
|
||||
C({T::Inf()}, T::Inf()),
|
||||
C({T::NaN()}, T::NaN()),
|
||||
C({Vec(-T::Inf(), T::Inf(), T::NaN())}, Vec(-T::Inf(), T::Inf(), T::NaN())),
|
||||
});
|
||||
|
||||
return cases;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P( //
|
||||
Floor,
|
||||
ResolverConstEvalBuiltinTest,
|
||||
testing::Combine(testing::Values(sem::BuiltinType::kFloor),
|
||||
testing::ValuesIn(Concat(FloorCases<AFloat, true>(),
|
||||
FloorCases<f32, false>(),
|
||||
FloorCases<f16, false>()))));
|
||||
|
||||
template <typename T>
|
||||
std::vector<Case> InsertBitsCases() {
|
||||
using UT = Number<std::make_unsigned_t<UnwrapNumber<T>>>;
|
||||
|
||||
@@ -12153,24 +12153,24 @@ constexpr OverloadInfo kOverloads[] = {
|
||||
/* num parameters */ 1,
|
||||
/* num template types */ 1,
|
||||
/* num template numbers */ 0,
|
||||
/* template types */ &kTemplateTypes[22],
|
||||
/* template types */ &kTemplateTypes[23],
|
||||
/* template numbers */ &kTemplateNumbers[10],
|
||||
/* parameters */ &kParameters[908],
|
||||
/* return matcher indices */ &kMatcherIndices[1],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::floor,
|
||||
},
|
||||
{
|
||||
/* [319] */
|
||||
/* num parameters */ 1,
|
||||
/* num template types */ 1,
|
||||
/* num template numbers */ 1,
|
||||
/* template types */ &kTemplateTypes[22],
|
||||
/* template types */ &kTemplateTypes[23],
|
||||
/* template numbers */ &kTemplateNumbers[6],
|
||||
/* parameters */ &kParameters[907],
|
||||
/* return matcher indices */ &kMatcherIndices[30],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::floor,
|
||||
},
|
||||
{
|
||||
/* [320] */
|
||||
@@ -14265,8 +14265,8 @@ constexpr IntrinsicInfo kBuiltins[] = {
|
||||
},
|
||||
{
|
||||
/* [37] */
|
||||
/* fn floor<T : f32_f16>(T) -> T */
|
||||
/* fn floor<N : num, T : f32_f16>(vec<N, T>) -> vec<N, T> */
|
||||
/* fn floor<T : fa_f32_f16>(@test_value(1.5) T) -> T */
|
||||
/* fn floor<N : num, T : fa_f32_f16>(@test_value(1.5) vec<N, T>) -> vec<N, T> */
|
||||
/* num overloads */ 2,
|
||||
/* overloads */ &kOverloads[318],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user