mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 23:56:16 +00:00
tint: const eval of fract
Bug: tint:1581 Change-Id: I14207080b14e45e7520f50230c85cd902f25dc71 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113943 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
60eac72504
commit
bed9c98a07
@@ -494,8 +494,8 @@ fn dot4U8Packed(u32, u32) -> u32
|
||||
@const fn floor<N: num, T: fa_f32_f16>(@test_value(1.5) vec<N, T>) -> vec<N, T>
|
||||
@const fn fma<T: fa_f32_f16>(T, T, T) -> T
|
||||
@const fn fma<N: num, T: fa_f32_f16>(vec<N, T>, vec<N, T>, vec<N, T>) -> vec<N, T>
|
||||
fn fract<T: f32_f16>(T) -> T
|
||||
fn fract<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T>
|
||||
@const fn fract<T: fa_f32_f16>(@test_value(1.25) T) -> T
|
||||
@const fn fract<N: num, T: fa_f32_f16>(@test_value(1.25) vec<N, T>) -> vec<N, T>
|
||||
@const fn frexp<T: fa_f32_f16>(T) -> __frexp_result<T>
|
||||
@const fn frexp<N: num, T: fa_f32_f16>(vec<N, T>) -> __frexp_result_vec<N, T>
|
||||
@stage("fragment") fn fwidth(f32) -> f32
|
||||
|
||||
@@ -2680,6 +2680,20 @@ ConstEval::Result ConstEval::fma(const type::Type* ty,
|
||||
return TransformElements(builder, ty, transform, args[0], args[1], args[2]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::fract(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto transform = [&](const constant::Constant* c1) {
|
||||
auto create = [&](auto e) -> ImplResult {
|
||||
using NumberT = decltype(e);
|
||||
auto r = e - std::floor(e);
|
||||
return CreateElement(builder, source, c1->Type(), NumberT{r});
|
||||
};
|
||||
return Dispatch_fa_f32_f16(create, c1);
|
||||
};
|
||||
return TransformElements(builder, ty, transform, args[0]);
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::frexp(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
|
||||
@@ -689,6 +689,15 @@ class ConstEval {
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// fract builtin
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
/// @param source the source location
|
||||
/// @return the result value, or null if the value cannot be calculated
|
||||
Result fract(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source);
|
||||
|
||||
/// frexp builtin
|
||||
/// @param ty the expression type
|
||||
/// @param args the input arguments
|
||||
|
||||
@@ -1172,6 +1172,38 @@ INSTANTIATE_TEST_SUITE_P( //
|
||||
FmaCases<f32>(),
|
||||
FmaCases<f16>()))));
|
||||
|
||||
template <typename T>
|
||||
std::vector<Case> FractCases() {
|
||||
auto r = std::vector<Case>{
|
||||
C({T(0)}, T(0)),
|
||||
C({T(0.1)}, T(0.1)),
|
||||
C({T(-0.1)}, T(0.9)),
|
||||
C({T(0.0000001)}, T(0.0000001)),
|
||||
C({T(-0.0000001)}, T(0.9999999)),
|
||||
C({T(12.34567)}, T(0.34567)).FloatComp(0.002),
|
||||
C({T(-12.34567)}, T(0.65433)).FloatComp(0.002),
|
||||
C({T::Lowest()}, T(0)),
|
||||
C({T::Highest()}, T(0)),
|
||||
// Vector tests
|
||||
C({Vec(T(0.1), T(-0.1), T(-0.0000001))}, Vec(T(0.1), T(0.9), T(0.9999999))),
|
||||
};
|
||||
// Note: Valid results are in the closed interval [0, 1.0]. For example, if e is a very small
|
||||
// negative number, then fract(e) may be 1.0.
|
||||
ConcatIntoIf<!std::is_same_v<T, f16>>( //
|
||||
r, std::vector<Case>{
|
||||
C({T(-0.000000000000000001)}, T(1)),
|
||||
});
|
||||
|
||||
return r;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P( //
|
||||
Fract,
|
||||
ResolverConstEvalBuiltinTest,
|
||||
testing::Combine(testing::Values(sem::BuiltinType::kFract),
|
||||
testing::ValuesIn(Concat(FractCases<AFloat>(), //
|
||||
FractCases<f32>(),
|
||||
FractCases<f16>()))));
|
||||
|
||||
template <typename T>
|
||||
std::vector<Case> FrexpCases() {
|
||||
using F = T; // fract type
|
||||
|
||||
@@ -12461,24 +12461,24 @@ constexpr OverloadInfo kOverloads[] = {
|
||||
/* num parameters */ 1,
|
||||
/* num template types */ 1,
|
||||
/* num template numbers */ 0,
|
||||
/* template types */ &kTemplateTypes[26],
|
||||
/* template types */ &kTemplateTypes[23],
|
||||
/* template numbers */ &kTemplateNumbers[10],
|
||||
/* parameters */ &kParameters[856],
|
||||
/* return matcher indices */ &kMatcherIndices[3],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::fract,
|
||||
},
|
||||
{
|
||||
/* [348] */
|
||||
/* num parameters */ 1,
|
||||
/* num template types */ 1,
|
||||
/* num template numbers */ 1,
|
||||
/* template types */ &kTemplateTypes[26],
|
||||
/* template types */ &kTemplateTypes[23],
|
||||
/* template numbers */ &kTemplateNumbers[4],
|
||||
/* parameters */ &kParameters[857],
|
||||
/* return matcher indices */ &kMatcherIndices[30],
|
||||
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
|
||||
/* const eval */ nullptr,
|
||||
/* const eval */ &ConstEval::fract,
|
||||
},
|
||||
{
|
||||
/* [349] */
|
||||
@@ -14203,8 +14203,8 @@ constexpr IntrinsicInfo kBuiltins[] = {
|
||||
},
|
||||
{
|
||||
/* [39] */
|
||||
/* fn fract<T : f32_f16>(T) -> T */
|
||||
/* fn fract<N : num, T : f32_f16>(vec<N, T>) -> vec<N, T> */
|
||||
/* fn fract<T : fa_f32_f16>(@test_value(1.25) T) -> T */
|
||||
/* fn fract<N : num, T : fa_f32_f16>(@test_value(1.25) vec<N, T>) -> vec<N, T> */
|
||||
/* num overloads */ 2,
|
||||
/* overloads */ &kOverloads[347],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user