Commit f3b57974 by Ben Clayton

Reactor: Add tests for casts from C to Reactor types

Change-Id: I20e249c56167fc9c37adc02b798cb60781cc757b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27251 Presubmit-Ready: Ben Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 49d8158b
...@@ -114,6 +114,16 @@ namespace rr ...@@ -114,6 +114,16 @@ namespace rr
return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
} }
RValue<Bool> operator!=(RValue<Bool> lhs, RValue<Bool> rhs)
{
return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
}
RValue<Bool> operator==(RValue<Bool> lhs, RValue<Bool> rhs)
{
return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
}
Byte::Byte(Argument<Byte> argument) Byte::Byte(Argument<Byte> argument)
{ {
storeValue(argument.value); storeValue(argument.value);
...@@ -3589,6 +3599,11 @@ namespace rr ...@@ -3589,6 +3599,11 @@ namespace rr
storeValue(value); storeValue(value);
} }
Float::Float(Argument<Float> argument)
{
storeValue(argument.value);
}
RValue<Float> Float::operator=(RValue<Float> rhs) RValue<Float> Float::operator=(RValue<Float> rhs)
{ {
storeValue(rhs.value); storeValue(rhs.value);
......
...@@ -220,6 +220,8 @@ namespace rr ...@@ -220,6 +220,8 @@ namespace rr
RValue<Bool> operator!(RValue<Bool> val); RValue<Bool> operator!(RValue<Bool> val);
RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs); RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs);
RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs); RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs);
RValue<Bool> operator!=(RValue<Bool> lhs, RValue<Bool> rhs);
RValue<Bool> operator==(RValue<Bool> lhs, RValue<Bool> rhs);
class Byte : public LValue<Byte> class Byte : public LValue<Byte>
{ {
...@@ -1966,6 +1968,7 @@ namespace rr ...@@ -1966,6 +1968,7 @@ namespace rr
Float(RValue<Float> rhs); Float(RValue<Float> rhs);
Float(const Float &rhs); Float(const Float &rhs);
Float(const Reference<Float> &rhs); Float(const Reference<Float> &rhs);
Float(Argument<Float> argument);
template<int T> template<int T>
Float(const SwizzleMask1<Float4, T> &rhs); Float(const SwizzleMask1<Float4, T> &rhs);
...@@ -2767,6 +2770,7 @@ namespace rr ...@@ -2767,6 +2770,7 @@ namespace rr
{ {
Nucleus::createRet(Nucleus::createLoad(ret.address, Pointer<T>::getType())); Nucleus::createRet(Nucleus::createLoad(ret.address, Pointer<T>::getType()));
Nucleus::setInsertBlock(Nucleus::createBasicBlock()); Nucleus::setInsertBlock(Nucleus::createBasicBlock());
Nucleus::createUnreachable();
} }
template<class T> template<class T>
...@@ -2774,6 +2778,7 @@ namespace rr ...@@ -2774,6 +2778,7 @@ namespace rr
{ {
Nucleus::createRet(ret.value); Nucleus::createRet(ret.value);
Nucleus::setInsertBlock(Nucleus::createBasicBlock()); Nucleus::setInsertBlock(Nucleus::createBasicBlock());
Nucleus::createUnreachable();
} }
template<typename Return, typename... Arguments> template<typename Return, typename... Arguments>
......
...@@ -1118,6 +1118,56 @@ TEST(ReactorUnitTests, PreserveXMMRegisters) ...@@ -1118,6 +1118,56 @@ TEST(ReactorUnitTests, PreserveXMMRegisters)
} }
template <typename T> template <typename T>
class CToReactorCastTest : public ::testing::Test {
public:
using CType = typename std::tuple_element<0, T>::type;
using ReactorType = typename std::tuple_element<1, T>::type;
};
using CToReactorCastTestTypes = ::testing::Types
< // Subset of types that can be used as arguments.
std::pair<bool, Bool>,
std::pair<uint8_t, Byte>,
std::pair<int8_t, SByte>,
std::pair<int16_t, Short>,
std::pair<uint16_t, UShort>,
std::pair<int, Int>,
std::pair<unsigned int, UInt>,
std::pair<float, Float>
>;
TYPED_TEST_CASE(CToReactorCastTest, CToReactorCastTestTypes);
TYPED_TEST(CToReactorCastTest, Casts) {
using CType = typename TestFixture::CType;
using ReactorType = typename TestFixture::ReactorType;
Routine *routine = nullptr;
{
Function< Int(ReactorType) > function;
{
ReactorType a = function.template Arg<0>();
ReactorType b = CType{};
RValue<ReactorType> c = RValue<ReactorType>(CType{});
Bool same = (a == b) && (a == c);
Return(IfThenElse(same, Int(1), Int(0))); // TODO: Ability to use Bools as return values.
}
routine = function("one");
if(routine)
{
auto callable = (int(*)(CType))routine->getEntry();
CType in = {};
EXPECT_EQ(callable(in), 1);
}
}
delete routine;
}
template <typename T>
class GEPTest : public ::testing::Test { class GEPTest : public ::testing::Test {
public: public:
using CType = typename std::tuple_element<0, T>::type; using CType = typename std::tuple_element<0, T>::type;
...@@ -1126,7 +1176,7 @@ public: ...@@ -1126,7 +1176,7 @@ public:
using GEPTestTypes = ::testing::Types using GEPTestTypes = ::testing::Types
< <
std::pair<int8_t, Bool>, std::pair<bool, Bool>,
std::pair<int8_t, Byte>, std::pair<int8_t, Byte>,
std::pair<int8_t, SByte>, std::pair<int8_t, SByte>,
std::pair<int8_t[4], Byte4>, std::pair<int8_t[4], Byte4>,
......
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