Move helper methods inside Scalar.
This CL moves ValueOf and IsPositiveZero into the Scalar class which was
the only usage.
Bug: tint:1718
Change-Id: I2c99831ac30d4d3f0b3bfe9ad25a85186bba0f1c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114123
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc
index 198197e..a035849 100644
--- a/src/tint/resolver/const_eval.cc
+++ b/src/tint/resolver/const_eval.cc
@@ -168,24 +168,6 @@
[&](const type::Bool*) { return f(static_cast<bool>(0)); });
}
-/// @returns `value` if `T` is not a Number, otherwise ValueOf returns the inner value of the
-/// Number.
-template <typename T>
-inline auto ValueOf(T value) {
- if constexpr (std::is_same_v<UnwrapNumber<T>, T>) {
- return value;
- } else {
- return value.value;
- }
-}
-
-/// @returns true if `value` is a positive zero.
-template <typename T>
-inline bool IsPositiveZero(T value) {
- using N = UnwrapNumber<T>;
- return Number<N>(value) == Number<N>(0); // Considers sign bit
-}
-
template <typename NumberT>
std::string OverflowErrorMessage(NumberT lhs, const char* op, NumberT rhs) {
std::stringstream ss;
@@ -278,10 +260,28 @@
}
}
const constant::Constant* Index(size_t) const override { return nullptr; }
- bool AllZero() const override { return IsPositiveZero(value); }
- bool AnyZero() const override { return IsPositiveZero(value); }
+
+ bool AllZero() const override { return IsPositiveZero(); }
+ bool AnyZero() const override { return IsPositiveZero(); }
+
bool AllEqual() const override { return true; }
- size_t Hash() const override { return utils::Hash(type, ValueOf(value)); }
+ size_t Hash() const override { return utils::Hash(type, ValueOf()); }
+
+ /// @returns `value` if `T` is not a Number, otherwise ValueOf returns the inner value of the
+ /// Number.
+ inline auto ValueOf() const {
+ if constexpr (std::is_same_v<UnwrapNumber<T>, T>) {
+ return value;
+ } else {
+ return value.value;
+ }
+ }
+
+ /// @returns true if `value` is a positive zero.
+ inline bool IsPositiveZero() const {
+ using N = UnwrapNumber<T>;
+ return Number<N>(value) == Number<N>(0); // Considers sign bit
+ }
type::Type const* const type;
const T value;
@@ -364,7 +364,7 @@
using FROM = T;
if constexpr (std::is_same_v<TO, bool>) {
// [x -> bool]
- return builder.create<Scalar<TO>>(target_ty, !IsPositiveZero(scalar->value));
+ return builder.create<Scalar<TO>>(target_ty, !scalar->IsPositiveZero());
} else if constexpr (std::is_same_v<FROM, bool>) {
// [bool -> x]
return builder.create<Scalar<TO>>(target_ty, TO(scalar->value ? 1 : 0));