Added some truncation constructors in Nucleus
Added some extra constructors that simply truncate from a type
which has a higher number of bits. The new constructors are:
- Byte from UInt
- Byte from UShort
- SByte from Int
- SByte from Short
- UShort from UInt
Also added an implementation of the RoundUInt function using the
UInt from Float constructor, which had to be fixed since it was
using createFPToSI instead of createFPToUI.
Change-Id: Ie7ee21ef20fbb8133b9f7c74afa1fec9e6c51957
Reviewed-on: https://swiftshader-review.googlesource.com/4300
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Reactor/Nucleus.cpp b/src/Reactor/Nucleus.cpp
index 66bbe46..3c19e3f 100644
--- a/src/Reactor/Nucleus.cpp
+++ b/src/Reactor/Nucleus.cpp
@@ -933,6 +933,20 @@
storeValue(integer);
}
+ Byte::Byte(RValue<UInt> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
+
+ storeValue(integer);
+ }
+
+ Byte::Byte(RValue<UShort> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
+
+ storeValue(integer);
+ }
+
Byte::Byte()
{
}
@@ -1178,6 +1192,20 @@
storeValue(argument);
}
+ SByte::SByte(RValue<Int> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
+
+ storeValue(integer);
+ }
+
+ SByte::SByte(RValue<Short> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
+
+ storeValue(integer);
+ }
+
SByte::SByte()
{
}
@@ -1665,6 +1693,13 @@
storeValue(argument);
}
+ UShort::UShort(RValue<UInt> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
+
+ storeValue(integer);
+ }
+
UShort::UShort()
{
}
@@ -4205,7 +4240,7 @@
UInt::UInt(RValue<Float> cast)
{
- Value *integer = Nucleus::createFPToSI(cast.value, UInt::getType());
+ Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType());
storeValue(integer);
}
diff --git a/src/Reactor/Nucleus.hpp b/src/Reactor/Nucleus.hpp
index aef1a24..f63d693 100644
--- a/src/Reactor/Nucleus.hpp
+++ b/src/Reactor/Nucleus.hpp
@@ -401,6 +401,8 @@
explicit Byte(llvm::Argument *argument);
explicit Byte(RValue<Int> cast);
+ explicit Byte(RValue<UInt> cast);
+ explicit Byte(RValue<UShort> cast);
Byte();
Byte(int x);
@@ -456,6 +458,9 @@
public:
explicit SByte(llvm::Argument *argument);
+ explicit SByte(RValue<Int> cast);
+ explicit SByte(RValue<Short> cast);
+
SByte();
SByte(signed char x);
SByte(RValue<SByte> rhs);
@@ -564,6 +569,8 @@
public:
explicit UShort(llvm::Argument *argument);
+ explicit UShort(RValue<UInt> cast);
+
UShort();
UShort(unsigned short x);
UShort(RValue<UShort> rhs);