Commit e5720880 by Nicolas Capens Committed by Nicolas Capens

Replace positive/negative_inf() with infinity()

This matches the std::numeric_limits<> method name. Negative infinity can be obtained using -infinity() just like in C++. Also replace the use of C99 INFINITY with the C++ constant. Bug: b/140302841 Change-Id: Ifd5e5d1fa4fa2d9ccce6d334af22903ea7597a69 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40148 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent cd55f051
......@@ -410,7 +410,7 @@ SpirvShader::EmitResult SpirvShader::EmitGroupNonUniform(InsnIterator insn, Emit
using Type = SIMD::Float;
Impl::Group::BinaryOperation(
this, insn, state, dst,
Type::positive_inf(),
Type::infinity(),
[](RValue<Type> a, RValue<Type> b) { return NMin(a, b); });
break;
}
......@@ -438,9 +438,10 @@ SpirvShader::EmitResult SpirvShader::EmitGroupNonUniform(InsnIterator insn, Emit
case spv::OpGroupNonUniformFMax:
{
using Type = SIMD::Float;
SIMD::Float negative_inf = -SIMD::Float::infinity();
Impl::Group::BinaryOperation(
this, insn, state, dst,
Type::negative_inf(),
negative_inf,
[](RValue<Type> a, RValue<Type> b) { return NMax(a, b); });
break;
}
......
......@@ -3880,14 +3880,28 @@ Float::Float(float x)
// being reinterpreted as float and then bitcast to integer again,
// which does not guarantee preserving the integer value.
//
// Should infinity and NaN constants be required, methods like
// infinity(), quiet_NaN(), and signaling_NaN() should be added
// to the Float class.
// The inifinity() method can be used to obtain positive infinity.
// Should NaN constants be required, methods like quiet_NaN() and
// signaling_NaN() should be added (matching std::numeric_limits).
ASSERT(std::isfinite(x));
storeValue(Nucleus::createConstantFloat(x));
}
// TODO(b/140302841): Negative infinity can be obtained by using '-infinity()'.
// This comes at a minor run-time JIT cost, and the backend may or may not
// perform constant folding. This can be optimized by having Reactor perform
// the folding, which would still be cheaper than having a capable backend do it.
Float Float::infinity()
{
Float result;
constexpr double inf = std::numeric_limits<double>::infinity();
result.storeValue(Nucleus::createConstantFloat(inf));
return result;
}
Float::Float(RValue<Float> rhs)
{
storeValue(rhs.value);
......@@ -4111,25 +4125,15 @@ Float4::Float4(float x, float y, float z, float w)
constant(x, y, z, w);
}
Float4 Float4::positive_inf()
Float4 Float4::infinity()
{
Float4 result;
result.infinity_constant(false);
return result;
}
Float4 Float4::negative_inf()
{
Float4 result;
result.infinity_constant(true);
return result;
}
void Float4::infinity_constant(bool negative)
{
double inf = negative ? -INFINITY : INFINITY;
constexpr double inf = std::numeric_limits<double>::infinity();
double constantVector[4] = { inf, inf, inf, inf };
storeValue(Nucleus::createConstantVector(constantVector, getType()));
result.storeValue(Nucleus::createConstantVector(constantVector, getType()));
return result;
}
void Float4::constant(float x, float y, float z, float w)
......
......@@ -22,7 +22,7 @@
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <limits>
#include <tuple>
#include <unordered_set>
......@@ -2081,6 +2081,8 @@ public:
template<int T>
RValue<Float> operator=(const SwizzleMask1<Float4, T> &rhs);
static Float infinity();
static Type *getType();
};
......@@ -2243,13 +2245,12 @@ public:
template<int T>
RValue<Float4> operator=(const Swizzle4<Float4, T> &rhs);
static Float4 infinity();
static Type *getType();
static Float4 negative_inf();
static Float4 positive_inf();
private:
void constant(float x, float y, float z, float w);
void infinity_constant(bool negative);
};
RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs);
......
......@@ -460,7 +460,7 @@ TEST(ReactorUnitTests, Swizzle)
}
}
TEST(ReactorUnitTests, Blend)
TEST(ReactorUnitTests, Shuffle)
{
{
// |select| is [0aaa:0bbb:0ccc:0ddd] where |aaa|, |bbb|, |ccc|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment