)
set(SUBZERO_REACTOR_LIST
+ ${SOURCE_DIR}/Reactor/Reactor.cpp
${SOURCE_DIR}/Reactor/SubzeroReactor.cpp
${SOURCE_DIR}/Reactor/Routine.cpp
${SOURCE_DIR}/Reactor/Optimizer.cpp
)
set(REACTOR_LLVM_LIST
+ ${SOURCE_DIR}/Reactor/Reactor.cpp
${SOURCE_DIR}/Reactor/LLVMReactor.cpp
${SOURCE_DIR}/Reactor/Nucleus.hpp
${SOURCE_DIR}/Reactor/Routine.cpp
defaults: [ "libswiftshader_common_defaults" ],
srcs: [
+ "Reactor/Reactor.cpp",
"Reactor/LLVMReactor.cpp",
"Reactor/Routine.cpp",
"Reactor/LLVMRoutine.cpp",
device_supported: false,
srcs: [
+ "Reactor/Reactor.cpp",
"Reactor/SubzeroReactor.cpp",
"Reactor/Routine.cpp",
"Reactor/Optimizer.cpp",
Main/SwiftConfig.cpp
COMMON_SRC_FILES += \
+ Reactor/Reactor.cpp \
Reactor/Routine.cpp \
Reactor/Debug.cpp \
Reactor/DebugAndroid.cpp \
]
sources = [
+ "Reactor.cpp",
"Routine.cpp",
"Debug.cpp",
"ExecutableMemory.cpp",
::builder->CreateUnreachable();
}
- static Value *createSwizzle4(Value *val, unsigned char select)
- {
- int swizzle[4] =
- {
- (select >> 0) & 0x03,
- (select >> 2) & 0x03,
- (select >> 4) & 0x03,
- (select >> 6) & 0x03,
- };
-
- return Nucleus::createShuffleVector(val, val, swizzle);
- }
-
- static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
- {
- bool mask[4] = {false, false, false, false};
-
- mask[(select >> 0) & 0x03] = true;
- mask[(select >> 2) & 0x03] = true;
- mask[(select >> 4) & 0x03] = true;
- mask[(select >> 6) & 0x03] = true;
-
- int swizzle[4] =
- {
- mask[0] ? 4 : 0,
- mask[1] ? 5 : 1,
- mask[2] ? 6 : 2,
- mask[3] ? 7 : 3,
- };
-
- return Nucleus::createShuffleVector(lhs, rhs, swizzle);
- }
-
Type *Nucleus::getPointerType(Type *ElementType)
{
return T(llvm::PointerType::get(T(ElementType), 0));
return T(llvm::Type::getVoidTy(*::context));
}
- Bool::Bool(Argument<Bool> argument)
+ Type *Bool::getType()
{
- storeValue(argument.value);
+ return T(llvm::Type::getInt1Ty(*::context));
}
- Bool::Bool(bool x)
+ Type *Byte::getType()
{
- storeValue(Nucleus::createConstantBool(x));
+ return T(llvm::Type::getInt8Ty(*::context));
}
- Bool::Bool(RValue<Bool> rhs)
+ Type *SByte::getType()
{
- storeValue(rhs.value);
+ return T(llvm::Type::getInt8Ty(*::context));
}
- Bool::Bool(const Bool &rhs)
+ Type *Short::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(llvm::Type::getInt16Ty(*::context));
}
- Bool::Bool(const Reference<Bool> &rhs)
+ Type *UShort::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(llvm::Type::getInt16Ty(*::context));
}
- RValue<Bool> Bool::operator=(RValue<Bool> rhs)
+ Type *Byte4::getType()
{
- storeValue(rhs.value);
-
- return rhs;
+ return T(Type_v4i8);
}
- RValue<Bool> Bool::operator=(const Bool &rhs)
+ Type *SByte4::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Bool>(value);
+ return T(Type_v4i8);
}
- RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
+ RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Bool>(value);
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::paddusb(x, y);
+#else
+ return As<Byte8>(V(lowerPUADDSAT(V(x.value), V(y.value))));
+#endif
}
- RValue<Bool> operator!(RValue<Bool> val)
+ RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
{
- return RValue<Bool>(Nucleus::createNot(val.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psubusb(x, y);
+#else
+ return As<Byte8>(V(lowerPUSUBSAT(V(x.value), V(y.value))));
+#endif
}
- RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
+ RValue<Int> SignMask(RValue<Byte8> x)
{
- return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmovmskb(x);
+#else
+ return As<Int>(V(lowerSignMask(V(x.value), T(Int::getType()))));
+#endif
}
- RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
+// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
+// {
+//#if defined(__i386__) || defined(__x86_64__)
+// return x86::pcmpgtb(x, y); // FIXME: Signedness
+//#else
+// return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_SGT, V(x.value), V(y.value), T(Byte8::getType()))));
+//#endif
+// }
+
+ RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
{
- return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pcmpeqb(x, y);
+#else
+ return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_EQ, V(x.value), V(y.value), T(Byte8::getType()))));
+#endif
}
- Type *Bool::getType()
+ Type *Byte8::getType()
{
- return T(llvm::Type::getInt1Ty(*::context));
+ return T(Type_v8i8);
}
- Byte::Byte(Argument<Byte> argument)
+ RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
{
- storeValue(argument.value);
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::paddsb(x, y);
+#else
+ return As<SByte8>(V(lowerPSADDSAT(V(x.value), V(y.value))));
+#endif
}
- Byte::Byte(RValue<Int> cast)
+ RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
{
- Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
-
- storeValue(integer);
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psubsb(x, y);
+#else
+ return As<SByte8>(V(lowerPSSUBSAT(V(x.value), V(y.value))));
+#endif
}
- Byte::Byte(RValue<UInt> cast)
+ RValue<Int> SignMask(RValue<SByte8> x)
{
- Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
-
- storeValue(integer);
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmovmskb(As<Byte8>(x));
+#else
+ return As<Int>(V(lowerSignMask(V(x.value), T(Int::getType()))));
+#endif
}
- Byte::Byte(RValue<UShort> cast)
+ RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
{
- Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
-
- storeValue(integer);
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pcmpgtb(x, y);
+#else
+ return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_SGT, V(x.value), V(y.value), T(Byte8::getType()))));
+#endif
}
- Byte::Byte(int x)
+ RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
{
- storeValue(Nucleus::createConstantByte((unsigned char)x));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
+#else
+ return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_EQ, V(x.value), V(y.value), T(Byte8::getType()))));
+#endif
}
- Byte::Byte(unsigned char x)
+ Type *SByte8::getType()
{
- storeValue(Nucleus::createConstantByte(x));
+ return T(Type_v8i8);
}
- Byte::Byte(RValue<Byte> rhs)
+ Type *Byte16::getType()
{
- storeValue(rhs.value);
+ return T(llvm::VectorType::get(T(Byte::getType()), 16));
}
- Byte::Byte(const Byte &rhs)
+ Type *SByte16::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(llvm::VectorType::get(T(SByte::getType()), 16));
}
- Byte::Byte(const Reference<Byte> &rhs)
+ Type *Short2::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(Type_v2i16);
}
- RValue<Byte> Byte::operator=(RValue<Byte> rhs)
+ Type *UShort2::getType()
{
- storeValue(rhs.value);
-
- return rhs;
+ return T(Type_v2i16);
}
- RValue<Byte> Byte::operator=(const Byte &rhs)
+ Short4::Short4(RValue<Int4> cast)
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
+ Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
+
+ Value *packed = Nucleus::createShuffleVector(short8, short8, select);
+ Value *short4 = As<Short4>(Int2(As<Int4>(packed))).value;
- return RValue<Byte>(value);
+ storeValue(short4);
}
- RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
+// Short4::Short4(RValue<Float> cast)
+// {
+// }
+
+ Short4::Short4(RValue<Float4> cast)
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ Int4 v4i32 = Int4(cast);
+#if defined(__i386__) || defined(__x86_64__)
+ v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
+#else
+ Value *v = v4i32.loadValue();
+ v4i32 = As<Int4>(V(lowerPack(V(v), V(v), true)));
+#endif
- return RValue<Byte>(value);
+ storeValue(As<Short4>(Int2(v4i32)).value);
}
- RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
{
- return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
- }
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
- RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
+ return x86::psllw(lhs, rhs);
+#else
+ return As<Short4>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
{
- return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psraw(lhs, rhs);
+#else
+ return As<Short4>(V(lowerVectorAShr(V(lhs.value), rhs)));
+#endif
}
- RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmaxsw(x, y);
+#else
+ return RValue<Short4>(V(lowerPMINMAX(V(x.value), V(y.value), llvm::ICmpInst::ICMP_SGT)));
+#endif
}
- RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pminsw(x, y);
+#else
+ return RValue<Short4>(V(lowerPMINMAX(V(x.value), V(y.value), llvm::ICmpInst::ICMP_SLT)));
+#endif
}
- RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::paddsw(x, y);
+#else
+ return As<Short4>(V(lowerPSADDSAT(V(x.value), V(y.value))));
+#endif
}
- RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psubsw(x, y);
+#else
+ return As<Short4>(V(lowerPSSUBSAT(V(x.value), V(y.value))));
+#endif
}
- RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmulhw(x, y);
+#else
+ return As<Short4>(V(lowerMulHigh(V(x.value), V(y.value), true)));
+#endif
}
- RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmaddwd(x, y);
+#else
+ return As<Int2>(V(lowerMulAdd(V(x.value), V(y.value))));
+#endif
}
- RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ auto result = x86::packsswb(x, y);
+#else
+ auto result = V(lowerPack(V(x.value), V(y.value), true));
+#endif
+ return As<SByte8>(Swizzle(As<Int4>(result), 0x88));
}
- RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
+ RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y)
{
- return lhs = lhs + rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ auto result = x86::packuswb(x, y);
+#else
+ auto result = V(lowerPack(V(x.value), V(y.value), false));
+#endif
+ return As<Byte8>(Swizzle(As<Int4>(result), 0x88));
}
- RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
+ RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
{
- return lhs = lhs - rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pcmpgtw(x, y);
+#else
+ return As<Short4>(V(lowerPCMP(llvm::ICmpInst::ICMP_SGT, V(x.value), V(y.value), T(Short4::getType()))));
+#endif
}
- RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
+ RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
{
- return lhs = lhs * rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pcmpeqw(x, y);
+#else
+ return As<Short4>(V(lowerPCMP(llvm::ICmpInst::ICMP_EQ, V(x.value), V(y.value), T(Short4::getType()))));
+#endif
}
- RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
+ Type *Short4::getType()
{
- return lhs = lhs / rhs;
+ return T(Type_v4i16);
}
- RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
+ UShort4::UShort4(RValue<Float4> cast, bool saturate)
{
- return lhs = lhs % rhs;
+ if(saturate)
+ {
+#if defined(__i386__) || defined(__x86_64__)
+ if(CPUID::supportsSSE4_1())
+ {
+ Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
+ *this = As<Short4>(PackUnsigned(int4, int4));
+ }
+ else
+#endif
+ {
+ *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
+ }
+ }
+ else
+ {
+ *this = Short4(Int4(cast));
+ }
}
- RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
+ RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
{
- return lhs = lhs & rhs;
- }
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
- RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs | rhs;
+ return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
+#else
+ return As<UShort4>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
+ RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
{
- return lhs = lhs ^ rhs;
- }
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
- RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs << rhs;
+ return x86::psrlw(lhs, rhs);
+#else
+ return As<UShort4>(V(lowerVectorLShr(V(lhs.value), rhs)));
+#endif
}
- RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
+ RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
{
- return lhs = lhs >> rhs;
+ return RValue<UShort4>(Max(As<Short4>(x) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u), As<Short4>(y) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u)) + Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u));
}
- RValue<Byte> operator+(RValue<Byte> val)
+ RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
{
- return val;
+ return RValue<UShort4>(Min(As<Short4>(x) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u), As<Short4>(y) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u)) + Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u));
}
- RValue<Byte> operator-(RValue<Byte> val)
+ RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
{
- return RValue<Byte>(Nucleus::createNeg(val.value));
- }
-
- RValue<Byte> operator~(RValue<Byte> val)
- {
- return RValue<Byte>(Nucleus::createNot(val.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::paddusw(x, y);
+#else
+ return As<UShort4>(V(lowerPUADDSAT(V(x.value), V(y.value))));
+#endif
}
- RValue<Byte> operator++(Byte &val, int) // Post-increment
+ RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
{
- RValue<Byte> res = val;
-
- Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1));
- val.storeValue(inc);
-
- return res;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psubusw(x, y);
+#else
+ return As<UShort4>(V(lowerPUSUBSAT(V(x.value), V(y.value))));
+#endif
}
- const Byte &operator++(Byte &val) // Pre-increment
+ RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
{
- Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
- val.storeValue(inc);
-
- return val;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmulhuw(x, y);
+#else
+ return As<UShort4>(V(lowerMulHigh(V(x.value), V(y.value), false)));
+#endif
}
- RValue<Byte> operator--(Byte &val, int) // Post-decrement
+ RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
{
- RValue<Byte> res = val;
-
- Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1));
- val.storeValue(inc);
-
- return res;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pavgw(x, y);
+#else
+ return As<UShort4>(V(lowerPAVG(V(x.value), V(y.value))));
+#endif
}
- const Byte &operator--(Byte &val) // Pre-decrement
+ Type *UShort4::getType()
{
- Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
- val.storeValue(inc);
-
- return val;
+ return T(Type_v4i16);
}
- RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
{
- return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psllw(lhs, rhs);
+#else
+ return As<Short8>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
{
- return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psraw(lhs, rhs);
+#else
+ return As<Short8>(V(lowerVectorAShr(V(lhs.value), rhs)));
+#endif
}
- RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
{
- return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmaddwd(x, y);
+#else
+ return As<Int4>(V(lowerMulAdd(V(x.value), V(y.value))));
+#endif
}
- RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
{
- return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmulhw(x, y);
+#else
+ return As<Short8>(V(lowerMulHigh(V(x.value), V(y.value), true)));
+#endif
}
- RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
+ Type *Short8::getType()
{
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ return T(llvm::VectorType::get(T(Short::getType()), 8));
}
- RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
{
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs));
+#else
+ return As<UShort8>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- Type *Byte::getType()
+ RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
{
- return T(llvm::Type::getInt8Ty(*::context));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psrlw(lhs, rhs); // FIXME: Fallback required
+#else
+ return As<UShort8>(V(lowerVectorLShr(V(lhs.value), rhs)));
+#endif
}
- SByte::SByte(Argument<SByte> argument)
+ RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
{
- storeValue(argument.value);
- }
+ int pshufb[16] =
+ {
+ select0 + 0,
+ select0 + 1,
+ select1 + 0,
+ select1 + 1,
+ select2 + 0,
+ select2 + 1,
+ select3 + 0,
+ select3 + 1,
+ select4 + 0,
+ select4 + 1,
+ select5 + 0,
+ select5 + 1,
+ select6 + 0,
+ select6 + 1,
+ select7 + 0,
+ select7 + 1,
+ };
- SByte::SByte(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
+ Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
+ Value *shuffle = Nucleus::createShuffleVector(byte16, byte16, pshufb);
+ Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
- storeValue(integer);
+ return RValue<UShort8>(short8);
}
- SByte::SByte(RValue<Short> cast)
+ RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
{
- Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
-
- storeValue(integer);
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pmulhuw(x, y);
+#else
+ return As<UShort8>(V(lowerMulHigh(V(x.value), V(y.value), false)));
+#endif
}
- SByte::SByte(signed char x)
+ Type *UShort8::getType()
{
- storeValue(Nucleus::createConstantByte(x));
+ return T(llvm::VectorType::get(T(UShort::getType()), 8));
}
- SByte::SByte(RValue<SByte> rhs)
+ RValue<Int> operator++(Int &val, int) // Post-increment
{
- storeValue(rhs.value);
- }
+ RValue<Int> res = val;
- SByte::SByte(const SByte &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- SByte::SByte(const Reference<SByte> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
+ return res;
}
- RValue<SByte> SByte::operator=(RValue<SByte> rhs)
+ const Int &operator++(Int &val) // Pre-increment
{
- storeValue(rhs.value);
+ Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- return rhs;
+ return val;
}
- RValue<SByte> SByte::operator=(const SByte &rhs)
+ RValue<Int> operator--(Int &val, int) // Post-decrement
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ RValue<Int> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- return RValue<SByte>(value);
+ return res;
}
- RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
+ const Int &operator--(Int &val) // Pre-decrement
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- return RValue<SByte>(value);
+ return val;
}
- RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<Int> RoundInt(RValue<Float> cast)
{
- return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::cvtss2si(cast);
+#else
+ return RValue<Int>(V(lowerRoundInt(V(cast.value), T(Int::getType()))));
+#endif
}
- RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
+ Type *Int::getType()
{
- return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
+ return T(llvm::Type::getInt32Ty(*::context));
}
- RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
+ Type *Long::getType()
{
- return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
+ return T(llvm::Type::getInt64Ty(*::context));
}
- RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
+ UInt::UInt(RValue<Float> cast)
{
- return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
+ // Note: createFPToUI is broken, must perform conversion using createFPtoSI
+ // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType());
- RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
- }
+ // Smallest positive value representable in UInt, but not in Int
+ const unsigned int ustart = 0x80000000u;
+ const float ustartf = float(ustart);
- RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
+ // If the value is negative, store 0, otherwise store the result of the conversion
+ storeValue((~(As<Int>(cast) >> 31) &
+ // Check if the value can be represented as an Int
+ IfThenElse(cast >= ustartf,
+ // If the value is too large, subtract ustart and re-add it after conversion.
+ As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
+ // Otherwise, just convert normally
+ Int(cast))).value);
}
- RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<UInt> operator++(UInt &val, int) // Post-increment
{
- return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
- }
+ RValue<UInt> res = val;
- RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
- }
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
+ return res;
}
- RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
+ const UInt &operator++(UInt &val) // Pre-increment
{
- return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
- }
+ Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs + rhs;
+ return val;
}
- RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
+ RValue<UInt> operator--(UInt &val, int) // Post-decrement
{
- return lhs = lhs - rhs;
- }
+ RValue<UInt> res = val;
- RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs * rhs;
- }
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs / rhs;
+ return res;
}
- RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
+ const UInt &operator--(UInt &val) // Pre-decrement
{
- return lhs = lhs % rhs;
- }
+ Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
+ val.storeValue(inc);
- RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs & rhs;
+ return val;
}
- RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
+// RValue<UInt> RoundUInt(RValue<Float> cast)
+// {
+//#if defined(__i386__) || defined(__x86_64__)
+// return x86::cvtss2si(val); // FIXME: Unsigned
+//#else
+// return IfThenElse(cast > 0.0f, Int(cast + 0.5f), Int(cast - 0.5f));
+//#endif
+// }
+
+ Type *UInt::getType()
{
- return lhs = lhs | rhs;
+ return T(llvm::Type::getInt32Ty(*::context));
}
- RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
+// Int2::Int2(RValue<Int> cast)
+// {
+// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
+// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
+//
+// int shuffle[2] = {0, 0};
+// Value *replicate = Nucleus::createShuffleVector(vector, vector, shuffle);
+//
+// storeValue(replicate);
+// }
+
+ RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
{
- return lhs = lhs ^ rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return x86::pslld(lhs, rhs);
+#else
+ return As<Int2>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
+ RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
{
- return lhs = lhs << rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
+
+ return x86::psrad(lhs, rhs);
+#else
+ return As<Int2>(V(lowerVectorAShr(V(lhs.value), rhs)));
+#endif
}
- RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
+ Type *Int2::getType()
{
- return lhs = lhs >> rhs;
+ return T(Type_v2i32);
}
- RValue<SByte> operator+(RValue<SByte> val)
+ RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
{
- return val;
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
+#else
+ return As<UInt2>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<SByte> operator-(RValue<SByte> val)
+ RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
{
- return RValue<SByte>(Nucleus::createNeg(val.value));
+#if defined(__i386__) || defined(__x86_64__)
+ // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
+
+ return x86::psrld(lhs, rhs);
+#else
+ return As<UInt2>(V(lowerVectorLShr(V(lhs.value), rhs)));
+#endif
}
- RValue<SByte> operator~(RValue<SByte> val)
+ Type *UInt2::getType()
{
- return RValue<SByte>(Nucleus::createNot(val.value));
+ return T(Type_v2i32);
}
- RValue<SByte> operator++(SByte &val, int) // Post-increment
- {
- RValue<SByte> res = val;
-
- Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1));
- val.storeValue(inc);
-
- return res;
- }
-
- const SByte &operator++(SByte &val) // Pre-increment
- {
- Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<SByte> operator--(SByte &val, int) // Post-decrement
- {
- RValue<SByte> res = val;
-
- Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1));
- val.storeValue(inc);
-
- return res;
- }
-
- const SByte &operator--(SByte &val) // Pre-decrement
- {
- Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- Type *SByte::getType()
- {
- return T(llvm::Type::getInt8Ty(*::context));
- }
-
- Short::Short(Argument<Short> argument)
- {
- storeValue(argument.value);
- }
-
- Short::Short(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
-
- storeValue(integer);
- }
-
- Short::Short(short x)
- {
- storeValue(Nucleus::createConstantShort(x));
- }
-
- Short::Short(RValue<Short> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short::Short(const Short &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short::Short(const Reference<Short> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Short> Short::operator=(RValue<Short> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Short> Short::operator=(const Short &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short>(value);
- }
-
- RValue<Short> Short::operator=(const Reference<Short> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short>(value);
- }
-
- RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
-
- RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
- }
-
- RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<Short> operator+(RValue<Short> val)
- {
- return val;
- }
-
- RValue<Short> operator-(RValue<Short> val)
- {
- return RValue<Short>(Nucleus::createNeg(val.value));
- }
-
- RValue<Short> operator~(RValue<Short> val)
- {
- return RValue<Short>(Nucleus::createNot(val.value));
- }
-
- RValue<Short> operator++(Short &val, int) // Post-increment
- {
- RValue<Short> res = val;
-
- Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1));
- val.storeValue(inc);
-
- return res;
- }
-
- const Short &operator++(Short &val) // Pre-increment
- {
- Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<Short> operator--(Short &val, int) // Post-decrement
- {
- RValue<Short> res = val;
-
- Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1));
- val.storeValue(inc);
-
- return res;
- }
-
- const Short &operator--(Short &val) // Pre-decrement
- {
- Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- Type *Short::getType()
- {
- return T(llvm::Type::getInt16Ty(*::context));
- }
-
- UShort::UShort(Argument<UShort> argument)
- {
- storeValue(argument.value);
- }
-
- UShort::UShort(RValue<UInt> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
-
- storeValue(integer);
- }
-
- UShort::UShort(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
-
- storeValue(integer);
- }
-
- UShort::UShort(unsigned short x)
- {
- storeValue(Nucleus::createConstantShort(x));
- }
-
- UShort::UShort(RValue<UShort> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort::UShort(const UShort &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort::UShort(const Reference<UShort> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UShort> UShort::operator=(RValue<UShort> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UShort> UShort::operator=(const UShort &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort>(value);
- }
-
- RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort>(value);
- }
-
- RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<UShort> operator+(RValue<UShort> val)
- {
- return val;
- }
-
- RValue<UShort> operator-(RValue<UShort> val)
- {
- return RValue<UShort>(Nucleus::createNeg(val.value));
- }
-
- RValue<UShort> operator~(RValue<UShort> val)
- {
- return RValue<UShort>(Nucleus::createNot(val.value));
- }
-
- RValue<UShort> operator++(UShort &val, int) // Post-increment
- {
- RValue<UShort> res = val;
-
- Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1));
- val.storeValue(inc);
-
- return res;
- }
-
- const UShort &operator++(UShort &val) // Pre-increment
- {
- Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<UShort> operator--(UShort &val, int) // Post-decrement
- {
- RValue<UShort> res = val;
-
- Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1));
- val.storeValue(inc);
-
- return res;
- }
-
- const UShort &operator--(UShort &val) // Pre-decrement
- {
- Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- Type *UShort::getType()
- {
- return T(llvm::Type::getInt16Ty(*::context));
- }
-
- Byte4::Byte4(RValue<Byte8> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Byte4::Byte4(const Reference<Byte4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Type *Byte4::getType()
- {
- return T(Type_v4i8);
- }
-
- Type *SByte4::getType()
- {
- return T(Type_v4i8);
- }
-
- Byte8::Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
- {
- int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Byte8::Byte8(RValue<Byte8> rhs)
- {
- storeValue(rhs.value);
- }
-
- Byte8::Byte8(const Byte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Byte8::Byte8(const Reference<Byte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte8>(value);
- }
-
- RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte8>(value);
- }
-
- RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
-// {
-// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
-// {
-// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
-// }
-
-// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
-// {
-// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
-// }
-
- RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
-// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
-// {
-// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
-// }
-
-// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
-// {
-// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
-// }
-
- RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
-// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs << rhs;
-// }
-
-// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs >> rhs;
-// }
-
-// RValue<Byte8> operator+(RValue<Byte8> val)
-// {
-// return val;
-// }
-
-// RValue<Byte8> operator-(RValue<Byte8> val)
-// {
-// return RValue<Byte8>(Nucleus::createNeg(val.value));
-// }
-
- RValue<Byte8> operator~(RValue<Byte8> val)
- {
- return RValue<Byte8>(Nucleus::createNot(val.value));
- }
-
- RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::paddusb(x, y);
-#else
- return As<Byte8>(V(lowerPUADDSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psubusb(x, y);
-#else
- return As<Byte8>(V(lowerPUSUBSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<Short4> Unpack(RValue<Byte4> x)
- {
- int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
- return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
- }
-
- RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
- {
- return UnpackLow(As<Byte8>(x), As<Byte8>(y));
- }
-
- RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
- }
-
- RValue<Int> SignMask(RValue<Byte8> x)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmovmskb(x);
-#else
- return As<Int>(V(lowerSignMask(V(x.value), T(Int::getType()))));
-#endif
- }
-
-// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
-// {
-//#if defined(__i386__) || defined(__x86_64__)
-// return x86::pcmpgtb(x, y); // FIXME: Signedness
-//#else
-// return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_SGT, V(x.value), V(y.value), T(Byte8::getType()))));
-//#endif
-// }
-
- RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pcmpeqb(x, y);
-#else
- return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_EQ, V(x.value), V(y.value), T(Byte8::getType()))));
-#endif
- }
-
- Type *Byte8::getType()
- {
- return T(Type_v8i8);
- }
-
- SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
- {
- int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
- Value *vector = Nucleus::createConstantVector(constantVector, getType());
-
- storeValue(Nucleus::createBitCast(vector, getType()));
- }
-
- SByte8::SByte8(RValue<SByte8> rhs)
- {
- storeValue(rhs.value);
- }
-
- SByte8::SByte8(const SByte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- SByte8::SByte8(const Reference<SByte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<SByte8>(value);
- }
-
- RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<SByte8>(value);
- }
-
- RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
-// {
-// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
-// {
-// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
-// }
-
-// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
-// {
-// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
-// }
-
- RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
-// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
-// {
-// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
-// }
-
-// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
-// {
-// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
-// }
-
- RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
-// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs << rhs;
-// }
-
-// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs >> rhs;
-// }
-
-// RValue<SByte8> operator+(RValue<SByte8> val)
-// {
-// return val;
-// }
-
-// RValue<SByte8> operator-(RValue<SByte8> val)
-// {
-// return RValue<SByte8>(Nucleus::createNeg(val.value));
-// }
-
- RValue<SByte8> operator~(RValue<SByte8> val)
- {
- return RValue<SByte8>(Nucleus::createNot(val.value));
- }
-
- RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::paddsb(x, y);
-#else
- return As<SByte8>(V(lowerPSADDSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psubsb(x, y);
-#else
- return As<SByte8>(V(lowerPSSUBSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
- }
-
- RValue<Int> SignMask(RValue<SByte8> x)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmovmskb(As<Byte8>(x));
-#else
- return As<Int>(V(lowerSignMask(V(x.value), T(Int::getType()))));
-#endif
- }
-
- RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pcmpgtb(x, y);
-#else
- return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_SGT, V(x.value), V(y.value), T(Byte8::getType()))));
-#endif
- }
-
- RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
-#else
- return As<Byte8>(V(lowerPCMP(llvm::ICmpInst::ICMP_EQ, V(x.value), V(y.value), T(Byte8::getType()))));
-#endif
- }
-
- Type *SByte8::getType()
- {
- return T(Type_v8i8);
- }
-
- Byte16::Byte16(RValue<Byte16> rhs)
- {
- storeValue(rhs.value);
- }
-
- Byte16::Byte16(const Byte16 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Byte16::Byte16(const Reference<Byte16> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte16>(value);
- }
-
- RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte16>(value);
- }
-
- Type *Byte16::getType()
- {
- return T(llvm::VectorType::get(T(Byte::getType()), 16));
- }
-
- Type *SByte16::getType()
- {
- return T(llvm::VectorType::get(T(SByte::getType()), 16));
- }
-
- Short2::Short2(RValue<Short4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Type *Short2::getType()
- {
- return T(Type_v2i16);
- }
-
- UShort2::UShort2(RValue<UShort4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Type *UShort2::getType()
- {
- return T(Type_v2i16);
- }
-
- Short4::Short4(RValue<Int> cast)
- {
- Value *vector = loadValue();
- Value *element = Nucleus::createTrunc(cast.value, Short::getType());
- Value *insert = Nucleus::createInsertElement(vector, element, 0);
- Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
-
- storeValue(swizzle);
- }
-
- Short4::Short4(RValue<Int4> cast)
- {
- int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
- Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
-
- Value *packed = Nucleus::createShuffleVector(short8, short8, select);
- Value *short4 = As<Short4>(Int2(As<Int4>(packed))).value;
-
- storeValue(short4);
- }
-
-// Short4::Short4(RValue<Float> cast)
-// {
-// }
-
- Short4::Short4(RValue<Float4> cast)
- {
- Int4 v4i32 = Int4(cast);
-#if defined(__i386__) || defined(__x86_64__)
- v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
-#else
- Value *v = v4i32.loadValue();
- v4i32 = As<Int4>(V(lowerPack(V(v), V(v), true)));
-#endif
-
- storeValue(As<Short4>(Int2(v4i32)).value);
- }
-
- Short4::Short4(short xyzw)
- {
- int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short4::Short4(short x, short y, short z, short w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short4::Short4(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short4::Short4(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short4::Short4(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short4::Short4(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short4::Short4(const UShort4 &rhs)
- {
- storeValue(rhs.loadValue());
- }
-
- Short4::Short4(const Reference<UShort4> &rhs)
- {
- storeValue(rhs.loadValue());
- }
-
- RValue<Short4> Short4::operator=(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Short4> Short4::operator=(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<Short4>(rhs);
- }
-
- RValue<Short4> Short4::operator=(const UShort4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
-// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
-// {
-// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
-// }
-
-// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
-// {
-// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
-// }
-
- RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
-
- return x86::psllw(lhs, rhs);
-#else
- return As<Short4>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psraw(lhs, rhs);
-#else
- return As<Short4>(V(lowerVectorAShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs * rhs;
- }
-
-// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
-// RValue<Short4> operator+(RValue<Short4> val)
-// {
-// return val;
-// }
-
- RValue<Short4> operator-(RValue<Short4> val)
- {
- return RValue<Short4>(Nucleus::createNeg(val.value));
- }
-
- RValue<Short4> operator~(RValue<Short4> val)
- {
- return RValue<Short4>(Nucleus::createNot(val.value));
- }
-
- RValue<Short4> RoundShort4(RValue<Float4> cast)
- {
- RValue<Int4> int4 = RoundInt(cast);
- return As<Short4>(PackSigned(int4, int4));
- }
-
- RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmaxsw(x, y);
-#else
- return RValue<Short4>(V(lowerPMINMAX(V(x.value), V(y.value), llvm::ICmpInst::ICMP_SGT)));
-#endif
- }
-
- RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pminsw(x, y);
-#else
- return RValue<Short4>(V(lowerPMINMAX(V(x.value), V(y.value), llvm::ICmpInst::ICMP_SLT)));
-#endif
- }
-
- RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::paddsw(x, y);
-#else
- return As<Short4>(V(lowerPSADDSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psubsw(x, y);
-#else
- return As<Short4>(V(lowerPSSUBSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmulhw(x, y);
-#else
- return As<Short4>(V(lowerMulHigh(V(x.value), V(y.value), true)));
-#endif
- }
-
- RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmaddwd(x, y);
-#else
- return As<Int2>(V(lowerMulAdd(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- auto result = x86::packsswb(x, y);
-#else
- auto result = V(lowerPack(V(x.value), V(y.value), true));
-#endif
- return As<SByte8>(Swizzle(As<Int4>(result), 0x88));
- }
-
- RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- auto result = x86::packuswb(x, y);
-#else
- auto result = V(lowerPack(V(x.value), V(y.value), false));
-#endif
- return As<Byte8>(Swizzle(As<Int4>(result), 0x88));
- }
-
- RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
- {
- int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
- return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
- {
- int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
- auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
- }
-
- RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
- {
- // Real type is v8i16
- int shuffle[8] =
- {
- (select >> 0) & 0x03,
- (select >> 2) & 0x03,
- (select >> 4) & 0x03,
- (select >> 6) & 0x03,
- (select >> 0) & 0x03,
- (select >> 2) & 0x03,
- (select >> 4) & 0x03,
- (select >> 6) & 0x03,
- };
-
- return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
- }
-
- RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
- {
- return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<Short> Extract(RValue<Short4> val, int i)
- {
- return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
- }
-
- RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pcmpgtw(x, y);
-#else
- return As<Short4>(V(lowerPCMP(llvm::ICmpInst::ICMP_SGT, V(x.value), V(y.value), T(Short4::getType()))));
-#endif
- }
-
- RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pcmpeqw(x, y);
-#else
- return As<Short4>(V(lowerPCMP(llvm::ICmpInst::ICMP_EQ, V(x.value), V(y.value), T(Short4::getType()))));
-#endif
- }
-
- Type *Short4::getType()
- {
- return T(Type_v4i16);
- }
-
- UShort4::UShort4(RValue<Int4> cast)
- {
- *this = Short4(cast);
- }
-
- UShort4::UShort4(RValue<Float4> cast, bool saturate)
- {
- if(saturate)
- {
-#if defined(__i386__) || defined(__x86_64__)
- if(CPUID::supportsSSE4_1())
- {
- Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
- *this = As<Short4>(PackUnsigned(int4, int4));
- }
- else
-#endif
- {
- *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
- }
- }
- else
- {
- *this = Short4(Int4(cast));
- }
- }
-
- UShort4::UShort4(unsigned short xyzw)
- {
- int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort4::UShort4(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort4::UShort4(const UShort4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort4::UShort4(const Reference<UShort4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort4::UShort4(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort4::UShort4(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort4::UShort4(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<UShort4>(rhs);
- }
-
- RValue<UShort4> UShort4::operator=(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
-
- return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
-#else
- return As<UShort4>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
-
- return x86::psrlw(lhs, rhs);
-#else
- return As<UShort4>(V(lowerVectorLShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<UShort4> operator~(RValue<UShort4> val)
- {
- return RValue<UShort4>(Nucleus::createNot(val.value));
- }
-
- RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
- {
- return RValue<UShort4>(Max(As<Short4>(x) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u), As<Short4>(y) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u)) + Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u));
- }
-
- RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
- {
- return RValue<UShort4>(Min(As<Short4>(x) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u), As<Short4>(y) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u)) + Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u));
- }
-
- RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::paddusw(x, y);
-#else
- return As<UShort4>(V(lowerPUADDSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psubusw(x, y);
-#else
- return As<UShort4>(V(lowerPUSUBSAT(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmulhuw(x, y);
-#else
- return As<UShort4>(V(lowerMulHigh(V(x.value), V(y.value), false)));
-#endif
- }
-
- RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pavgw(x, y);
-#else
- return As<UShort4>(V(lowerPAVG(V(x.value), V(y.value))));
-#endif
- }
-
- Type *UShort4::getType()
- {
- return T(Type_v4i16);
- }
-
- Short8::Short8(short c)
- {
- int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
- {
- int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short8::Short8(RValue<Short8> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short8::Short8(const Reference<Short8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
- {
- int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
- {
- return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
- {
- return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psllw(lhs, rhs);
-#else
- return As<Short8>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psraw(lhs, rhs);
-#else
- return As<Short8>(V(lowerVectorAShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmaddwd(x, y);
-#else
- return As<Int4>(V(lowerMulAdd(V(x.value), V(y.value))));
-#endif
- }
-
- RValue<Int4> Abs(RValue<Int4> x)
- {
- auto negative = x >> 31;
- return (x ^ negative) - negative;
- }
-
- RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmulhw(x, y);
-#else
- return As<Short8>(V(lowerMulHigh(V(x.value), V(y.value), true)));
-#endif
- }
-
- Type *Short8::getType()
- {
- return T(llvm::VectorType::get(T(Short::getType()), 8));
- }
-
- UShort8::UShort8(unsigned short c)
- {
- int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort8::UShort8(unsigned short c0, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short c4, unsigned short c5, unsigned short c6, unsigned short c7)
- {
- int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort8::UShort8(RValue<UShort8> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort8::UShort8(const Reference<UShort8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
- {
- int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort8>(value);
- }
-
- RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort8>(value);
- }
-
- RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
- {
- return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs));
-#else
- return As<UShort8>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psrlw(lhs, rhs); // FIXME: Fallback required
-#else
- return As<UShort8>(V(lowerVectorLShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
- {
- return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
- {
- return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UShort8> operator~(RValue<UShort8> val)
- {
- return RValue<UShort8>(Nucleus::createNot(val.value));
- }
-
- RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
- {
- int pshufb[16] =
- {
- select0 + 0,
- select0 + 1,
- select1 + 0,
- select1 + 1,
- select2 + 0,
- select2 + 1,
- select3 + 0,
- select3 + 1,
- select4 + 0,
- select4 + 1,
- select5 + 0,
- select5 + 1,
- select6 + 0,
- select6 + 1,
- select7 + 0,
- select7 + 1,
- };
-
- Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
- Value *shuffle = Nucleus::createShuffleVector(byte16, byte16, pshufb);
- Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
-
- return RValue<UShort8>(short8);
- }
-
- RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pmulhuw(x, y);
-#else
- return As<UShort8>(V(lowerMulHigh(V(x.value), V(y.value), false)));
-#endif
- }
-
- Type *UShort8::getType()
- {
- return T(llvm::VectorType::get(T(UShort::getType()), 8));
- }
-
- Int::Int(Argument<Int> argument)
- {
- storeValue(argument.value);
- }
-
- Int::Int(RValue<Byte> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<SByte> cast)
- {
- Value *integer = Nucleus::createSExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<Short> cast)
- {
- Value *integer = Nucleus::createSExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<UShort> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<Int2> cast)
- {
- *this = Extract(cast, 0);
- }
-
- Int::Int(RValue<Long> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<Float> cast)
- {
- Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(int x)
- {
- storeValue(Nucleus::createConstantInt(x));
- }
-
- Int::Int(RValue<Int> rhs)
- {
- storeValue(rhs.value);
- }
-
- Int::Int(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
- }
-
- Int::Int(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int::Int(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int::Int(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int::Int(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Int> Int::operator=(int rhs)
- {
- return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
- }
-
- RValue<Int> Int::operator=(RValue<Int> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Int> Int::operator=(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<Int>(rhs);
- }
-
- RValue<Int> Int::operator=(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> Int::operator=(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> Int::operator=(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> Int::operator=(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
-
- RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
- }
-
- RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<Int> operator+(RValue<Int> val)
- {
- return val;
- }
-
- RValue<Int> operator-(RValue<Int> val)
- {
- return RValue<Int>(Nucleus::createNeg(val.value));
- }
-
- RValue<Int> operator~(RValue<Int> val)
- {
- return RValue<Int>(Nucleus::createNot(val.value));
- }
-
- RValue<Int> operator++(Int &val, int) // Post-increment
- {
- RValue<Int> res = val;
-
- Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return res;
- }
-
- const Int &operator++(Int &val) // Pre-increment
- {
- Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<Int> operator--(Int &val, int) // Post-decrement
- {
- RValue<Int> res = val;
-
- Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return res;
- }
-
- const Int &operator--(Int &val) // Pre-decrement
- {
- Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- RValue<Int> Max(RValue<Int> x, RValue<Int> y)
- {
- return IfThenElse(x > y, x, y);
- }
-
- RValue<Int> Min(RValue<Int> x, RValue<Int> y)
- {
- return IfThenElse(x < y, x, y);
- }
-
- RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
- {
- return Min(Max(x, min), max);
- }
-
- RValue<Int> RoundInt(RValue<Float> cast)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::cvtss2si(cast);
-#else
- return RValue<Int>(V(lowerRoundInt(V(cast.value), T(Int::getType()))));
-#endif
- }
-
- Type *Int::getType()
- {
- return T(llvm::Type::getInt32Ty(*::context));
- }
-
- Long::Long(RValue<Int> cast)
- {
- Value *integer = Nucleus::createSExt(cast.value, Long::getType());
-
- storeValue(integer);
- }
-
- Long::Long(RValue<UInt> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, Long::getType());
-
- storeValue(integer);
- }
-
- Long::Long(RValue<Long> rhs)
- {
- storeValue(rhs.value);
- }
-
- RValue<Long> Long::operator=(int64_t rhs)
- {
- return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
- }
-
- RValue<Long> Long::operator=(RValue<Long> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Long> Long::operator=(const Long &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Long>(value);
- }
-
- RValue<Long> Long::operator=(const Reference<Long> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Long>(value);
- }
-
- RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
- {
- return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
- }
-
- Type *Long::getType()
- {
- return T(llvm::Type::getInt64Ty(*::context));
- }
-
- UInt::UInt(Argument<UInt> argument)
- {
- storeValue(argument.value);
- }
-
- UInt::UInt(RValue<UShort> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
-
- storeValue(integer);
- }
-
- UInt::UInt(RValue<Long> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
-
- storeValue(integer);
- }
-
- UInt::UInt(RValue<Float> cast)
- {
- // Note: createFPToUI is broken, must perform conversion using createFPtoSI
- // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType());
-
- // Smallest positive value representable in UInt, but not in Int
- const unsigned int ustart = 0x80000000u;
- const float ustartf = float(ustart);
-
- // If the value is negative, store 0, otherwise store the result of the conversion
- storeValue((~(As<Int>(cast) >> 31) &
- // Check if the value can be represented as an Int
- IfThenElse(cast >= ustartf,
- // If the value is too large, subtract ustart and re-add it after conversion.
- As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
- // Otherwise, just convert normally
- Int(cast))).value);
- }
-
- UInt::UInt(int x)
- {
- storeValue(Nucleus::createConstantInt(x));
- }
-
- UInt::UInt(unsigned int x)
- {
- storeValue(Nucleus::createConstantInt(x));
- }
-
- UInt::UInt(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
- }
-
- UInt::UInt(RValue<Int> rhs)
- {
- storeValue(rhs.value);
- }
-
- UInt::UInt(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt::UInt(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt::UInt(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt::UInt(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UInt> UInt::operator=(unsigned int rhs)
- {
- return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
- }
-
- RValue<UInt> UInt::operator=(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UInt> UInt::operator=(RValue<Int> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<UInt>(rhs);
- }
-
- RValue<UInt> UInt::operator=(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> UInt::operator=(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<UInt> operator+(RValue<UInt> val)
- {
- return val;
- }
-
- RValue<UInt> operator-(RValue<UInt> val)
- {
- return RValue<UInt>(Nucleus::createNeg(val.value));
- }
-
- RValue<UInt> operator~(RValue<UInt> val)
- {
- return RValue<UInt>(Nucleus::createNot(val.value));
- }
-
- RValue<UInt> operator++(UInt &val, int) // Post-increment
- {
- RValue<UInt> res = val;
-
- Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return res;
- }
-
- const UInt &operator++(UInt &val) // Pre-increment
- {
- Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<UInt> operator--(UInt &val, int) // Post-decrement
- {
- RValue<UInt> res = val;
-
- Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return res;
- }
-
- const UInt &operator--(UInt &val) // Pre-decrement
- {
- Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
- val.storeValue(inc);
-
- return val;
- }
-
- RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
- {
- return IfThenElse(x > y, x, y);
- }
-
- RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
- {
- return IfThenElse(x < y, x, y);
- }
-
- RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
- {
- return Min(Max(x, min), max);
- }
-
- RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
-// RValue<UInt> RoundUInt(RValue<Float> cast)
-// {
-//#if defined(__i386__) || defined(__x86_64__)
-// return x86::cvtss2si(val); // FIXME: Unsigned
-//#else
-// return IfThenElse(cast > 0.0f, Int(cast + 0.5f), Int(cast - 0.5f));
-//#endif
-// }
-
- Type *UInt::getType()
- {
- return T(llvm::Type::getInt32Ty(*::context));
- }
-
-// Int2::Int2(RValue<Int> cast)
-// {
-// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
-// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
-//
-// int shuffle[2] = {0, 0};
-// Value *replicate = Nucleus::createShuffleVector(vector, vector, shuffle);
-//
-// storeValue(replicate);
-// }
-
- Int2::Int2(RValue<Int4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Int2::Int2(int x, int y)
- {
- int64_t constantVector[2] = {x, y};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Int2::Int2(RValue<Int2> rhs)
- {
- storeValue(rhs.value);
- }
-
- Int2::Int2(const Int2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int2::Int2(const Reference<Int2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int2::Int2(RValue<Int> lo, RValue<Int> hi)
- {
- int shuffle[4] = {0, 4, 1, 5};
- Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
-
- storeValue(Nucleus::createBitCast(packed, Int2::getType()));
- }
-
- RValue<Int2> Int2::operator=(RValue<Int2> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Int2> Int2::operator=(const Int2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int2>(value);
- }
-
- RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int2>(value);
- }
-
- RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
-// {
-// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
-// {
-// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
-// }
-
-// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
-// {
-// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
-// }
-
- RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
-
- return x86::pslld(lhs, rhs);
-#else
- return As<Int2>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
-
- return x86::psrad(lhs, rhs);
-#else
- return As<Int2>(V(lowerVectorAShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
-// RValue<Int2> operator+(RValue<Int2> val)
-// {
-// return val;
-// }
-
-// RValue<Int2> operator-(RValue<Int2> val)
-// {
-// return RValue<Int2>(Nucleus::createNeg(val.value));
-// }
-
- RValue<Int2> operator~(RValue<Int2> val)
- {
- return RValue<Int2>(Nucleus::createNot(val.value));
- }
-
- RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
- {
- int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
- return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
- {
- int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
- auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Short4>(Swizzle(lowHigh, 0xEE));
- }
-
- RValue<Int> Extract(RValue<Int2> val, int i)
- {
- return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
- }
-
- RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
- {
- return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- Type *Int2::getType()
- {
- return T(Type_v2i32);
- }
-
- UInt2::UInt2(unsigned int x, unsigned int y)
- {
- int64_t constantVector[2] = {x, y};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UInt2::UInt2(RValue<UInt2> rhs)
- {
- storeValue(rhs.value);
- }
-
- UInt2::UInt2(const UInt2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt2::UInt2(const Reference<UInt2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt2>(value);
- }
-
- RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt2>(value);
- }
-
- RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
-// {
-// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
-// {
-// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
-// }
-
-// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
-// {
-// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
-// }
-
- RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
-
- return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
-#else
- return As<UInt2>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
-
- return x86::psrld(lhs, rhs);
-#else
- return As<UInt2>(V(lowerVectorLShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
-// RValue<UInt2> operator+(RValue<UInt2> val)
-// {
-// return val;
-// }
-
-// RValue<UInt2> operator-(RValue<UInt2> val)
-// {
-// return RValue<UInt2>(Nucleus::createNeg(val.value));
-// }
-
- RValue<UInt2> operator~(RValue<UInt2> val)
- {
- return RValue<UInt2>(Nucleus::createNot(val.value));
- }
-
- Type *UInt2::getType()
- {
- return T(Type_v2i32);
- }
-
- Int4::Int4() : XYZW(this)
- {
- }
-
- Int4::Int4(RValue<Byte4> cast) : XYZW(this)
- {
-#if defined(__i386__) || defined(__x86_64__)
- if(CPUID::supportsSSE4_1())
- {
- *this = x86::pmovzxbd(As<Byte16>(cast));
- }
- else
-#endif
- {
- int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
- Value *a = Nucleus::createBitCast(cast.value, Byte16::getType());
- Value *b = Nucleus::createShuffleVector(a, Nucleus::createNullValue(Byte16::getType()), swizzle);
-
- int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
- Value *c = Nucleus::createBitCast(b, Short8::getType());
- Value *d = Nucleus::createShuffleVector(c, Nucleus::createNullValue(Short8::getType()), swizzle2);
-
- *this = As<Int4>(d);
- }
- }
-
- Int4::Int4(RValue<SByte4> cast) : XYZW(this)
- {
-#if defined(__i386__) || defined(__x86_64__)
- if(CPUID::supportsSSE4_1())
- {
- *this = x86::pmovsxbd(As<SByte16>(cast));
- }
- else
-#endif
- {
- int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
- Value *a = Nucleus::createBitCast(cast.value, Byte16::getType());
- Value *b = Nucleus::createShuffleVector(a, a, swizzle);
-
- int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
- Value *c = Nucleus::createBitCast(b, Short8::getType());
- Value *d = Nucleus::createShuffleVector(c, c, swizzle2);
-
- *this = As<Int4>(d) >> 24;
- }
- }
-
- Int4::Int4(RValue<Float4> cast) : XYZW(this)
- {
- Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
-
- storeValue(xyzw);
- }
-
- Int4::Int4(RValue<Short4> cast) : XYZW(this)
- {
-#if defined(__i386__) || defined(__x86_64__)
- if(CPUID::supportsSSE4_1())
- {
- *this = x86::pmovsxwd(As<Short8>(cast));
- }
- else
-#endif
- {
- int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
- Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
- *this = As<Int4>(c) >> 16;
- }
- }
-
- Int4::Int4(RValue<UShort4> cast) : XYZW(this)
- {
-#if defined(__i386__) || defined(__x86_64__)
- if(CPUID::supportsSSE4_1())
- {
- *this = x86::pmovzxwd(As<UShort8>(cast));
- }
- else
-#endif
- {
- int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
- Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
- *this = As<Int4>(c);
- }
- }
-
- Int4::Int4(int xyzw) : XYZW(this)
- {
- constant(xyzw, xyzw, xyzw, xyzw);
- }
-
- Int4::Int4(int x, int yzw) : XYZW(this)
- {
- constant(x, yzw, yzw, yzw);
- }
-
- Int4::Int4(int x, int y, int zw) : XYZW(this)
- {
- constant(x, y, zw, zw);
- }
-
- Int4::Int4(int x, int y, int z, int w) : XYZW(this)
- {
- constant(x, y, z, w);
- }
-
- void Int4::constant(int x, int y, int z, int w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Int4::Int4(RValue<Int4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- Int4::Int4(const Int4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(const Reference<Int4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(RValue<UInt4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- Int4::Int4(const UInt4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this)
- {
- int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- Int4::Int4(RValue<Int> rhs) : XYZW(this)
- {
- Value *vector = loadValue();
- Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
-
- int swizzle[4] = {0, 0, 0, 0};
- Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle);
-
- storeValue(replicate);
- }
-
- Int4::Int4(const Int &rhs) : XYZW(this)
- {
- *this = RValue<Int>(rhs.loadValue());
- }
-
- Int4::Int4(const Reference<Int> &rhs) : XYZW(this)
- {
- *this = RValue<Int>(rhs.loadValue());
- }
-
- RValue<Int4> Int4::operator=(RValue<Int4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Int4> Int4::operator=(const Int4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int4>(value);
- }
-
- RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int4>(value);
- }
-
- RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::pslld(lhs, rhs);
-#else
- return As<Int4>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psrad(lhs, rhs);
-#else
- return As<Int4>(V(lowerVectorAShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs * rhs;
- }
-
-// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<Int4> operator+(RValue<Int4> val)
- {
- return val;
- }
-
- RValue<Int4> operator-(RValue<Int4> val)
- {
- return RValue<Int4>(Nucleus::createNeg(val.value));
- }
-
- RValue<Int4> operator~(RValue<Int4> val)
- {
- return RValue<Int4>(Nucleus::createNot(val.value));
- }
-
- RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
- {
- // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
- // Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
- return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
- }
-
- RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
- {
- // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
- // Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
- return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
- }
-
- RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
- {
- // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
- // Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
- return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
- }
-
- RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
- {
- // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
- // Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
- return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
- }
-
- RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
- {
- // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
- // Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
- return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
- }
-
- RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
- {
- // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
- // Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
- return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
- }
-
- RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- if(CPUID::supportsSSE4_1())
- {
- return x86::pmaxsd(x, y);
- }
- else
-#endif
- {
- RValue<Int4> greater = CmpNLE(x, y);
- return (x & greater) | (y & ~greater);
- }
- }
-
- RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
+ Int4::Int4(RValue<Byte4> cast) : XYZW(this)
{
#if defined(__i386__) || defined(__x86_64__)
if(CPUID::supportsSSE4_1())
{
- return x86::pminsd(x, y);
- }
- else
-#endif
- {
- RValue<Int4> less = CmpLT(x, y);
- return (x & less) | (y & ~less);
- }
- }
-
- RValue<Int4> RoundInt(RValue<Float4> cast)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::cvtps2dq(cast);
-#else
- return As<Int4>(V(lowerRoundInt(V(cast.value), T(Int4::getType()))));
-#endif
- }
-
- RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y)
- {
- // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
- return As<Int4>(V(lowerMulHigh(V(x.value), V(y.value), true)));
- }
-
- RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y)
- {
- // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
- return As<UInt4>(V(lowerMulHigh(V(x.value), V(y.value), false)));
- }
-
- RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::packssdw(x, y);
-#else
- return As<Short8>(V(lowerPack(V(x.value), V(y.value), true)));
-#endif
- }
-
- RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::packusdw(x, y);
-#else
- return As<UShort8>(V(lowerPack(V(x.value), V(y.value), false)));
-#endif
- }
-
- RValue<Int> Extract(RValue<Int4> x, int i)
- {
- return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
- }
-
- RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
- {
- return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
- }
-
- RValue<Int> SignMask(RValue<Int4> x)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::movmskps(As<Float4>(x));
-#else
- return As<Int>(V(lowerSignMask(V(x.value), T(Int::getType()))));
-#endif
- }
-
- RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
- {
- return RValue<Int4>(createSwizzle4(x.value, select));
- }
-
- Type *Int4::getType()
- {
- return T(llvm::VectorType::get(T(Int::getType()), 4));
- }
-
- UInt4::UInt4() : XYZW(this)
- {
- }
-
- UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
- {
- // Note: createFPToUI is broken, must perform conversion using createFPtoSI
- // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
-
- // Smallest positive value representable in UInt, but not in Int
- const unsigned int ustart = 0x80000000u;
- const float ustartf = float(ustart);
-
- // Check if the value can be represented as an Int
- Int4 uiValue = CmpNLT(cast, Float4(ustartf));
- // If the value is too large, subtract ustart and re-add it after conversion.
- uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
- // Otherwise, just convert normally
- (~uiValue & Int4(cast));
- // If the value is negative, store 0, otherwise store the result of the conversion
- storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
- }
-
- UInt4::UInt4(int xyzw) : XYZW(this)
- {
- constant(xyzw, xyzw, xyzw, xyzw);
- }
-
- UInt4::UInt4(int x, int yzw) : XYZW(this)
- {
- constant(x, yzw, yzw, yzw);
- }
-
- UInt4::UInt4(int x, int y, int zw) : XYZW(this)
- {
- constant(x, y, zw, zw);
- }
-
- UInt4::UInt4(int x, int y, int z, int w) : XYZW(this)
- {
- constant(x, y, z, w);
- }
-
- void UInt4::constant(int x, int y, int z, int w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- UInt4::UInt4(const UInt4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt4::UInt4(RValue<Int4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- UInt4::UInt4(const Int4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this)
- {
- int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt4>(value);
- }
-
- RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt4>(value);
- }
-
- RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
-#else
- return As<UInt4>(V(lowerVectorShl(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
- {
-#if defined(__i386__) || defined(__x86_64__)
- return x86::psrld(lhs, rhs);
-#else
- return As<UInt4>(V(lowerVectorLShr(V(lhs.value), rhs)));
-#endif
- }
-
- RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
- {
- return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
- }
+ *this = x86::pmovzxbd(As<Byte16>(cast));
+ }
+ else
+#endif
+ {
+ int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
+ Value *a = Nucleus::createBitCast(cast.value, Byte16::getType());
+ Value *b = Nucleus::createShuffleVector(a, Nucleus::createNullValue(Byte16::getType()), swizzle);
- RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs + rhs;
- }
+ int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
+ Value *c = Nucleus::createBitCast(b, Short8::getType());
+ Value *d = Nucleus::createShuffleVector(c, Nucleus::createNullValue(Short8::getType()), swizzle2);
- RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs - rhs;
+ *this = As<Int4>(d);
+ }
}
- RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
+ Int4::Int4(RValue<SByte4> cast) : XYZW(this)
{
- return lhs = lhs * rhs;
- }
-
-// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
+#if defined(__i386__) || defined(__x86_64__)
+ if(CPUID::supportsSSE4_1())
+ {
+ *this = x86::pmovsxbd(As<SByte16>(cast));
+ }
+ else
+#endif
+ {
+ int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
+ Value *a = Nucleus::createBitCast(cast.value, Byte16::getType());
+ Value *b = Nucleus::createShuffleVector(a, a, swizzle);
-// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
+ int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
+ Value *c = Nucleus::createBitCast(b, Short8::getType());
+ Value *d = Nucleus::createShuffleVector(c, c, swizzle2);
- RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs & rhs;
+ *this = As<Int4>(d) >> 24;
+ }
}
- RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
+ Int4::Int4(RValue<Short4> cast) : XYZW(this)
{
- return lhs = lhs | rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ if(CPUID::supportsSSE4_1())
+ {
+ *this = x86::pmovsxwd(As<Short8>(cast));
+ }
+ else
+#endif
+ {
+ int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
+ Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
+ *this = As<Int4>(c) >> 16;
+ }
}
- RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
+ Int4::Int4(RValue<UShort4> cast) : XYZW(this)
{
- return lhs = lhs ^ rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ if(CPUID::supportsSSE4_1())
+ {
+ *this = x86::pmovzxwd(As<UShort8>(cast));
+ }
+ else
+#endif
+ {
+ int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
+ Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
+ *this = As<Int4>(c);
+ }
}
- RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
+ Int4::Int4(RValue<Int> rhs) : XYZW(this)
{
- return lhs = lhs << rhs;
- }
+ Value *vector = loadValue();
+ Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
- RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
+ int swizzle[4] = {0, 0, 0, 0};
+ Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle);
- RValue<UInt4> operator+(RValue<UInt4> val)
- {
- return val;
+ storeValue(replicate);
}
- RValue<UInt4> operator-(RValue<UInt4> val)
+ RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
{
- return RValue<UInt4>(Nucleus::createNeg(val.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::pslld(lhs, rhs);
+#else
+ return As<Int4>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<UInt4> operator~(RValue<UInt4> val)
+ RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
{
- return RValue<UInt4>(Nucleus::createNot(val.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psrad(lhs, rhs);
+#else
+ return As<Int4>(V(lowerVectorAShr(V(lhs.value), rhs)));
+#endif
}
- RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
{
// FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
// Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
- return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
+ // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
}
- RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
+ // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
+ // Restore the following line when LLVM is updated to a version where this issue is fixed.
+ // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
}
- RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
{
// FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
// Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
- return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
+ // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
}
- RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
+ // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
+ // Restore the following line when LLVM is updated to a version where this issue is fixed.
+ // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
}
- RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
{
// FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
// Restore the following line when LLVM is updated to a version where this issue is fixed.
- // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
- return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
+ // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
}
- RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
+ // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
+ // Restore the following line when LLVM is updated to a version where this issue is fixed.
+ // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
}
- RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
{
#if defined(__i386__) || defined(__x86_64__)
if(CPUID::supportsSSE4_1())
{
- return x86::pmaxud(x, y);
+ return x86::pmaxsd(x, y);
}
else
#endif
{
- RValue<UInt4> greater = CmpNLE(x, y);
+ RValue<Int4> greater = CmpNLE(x, y);
return (x & greater) | (y & ~greater);
}
}
- RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
{
#if defined(__i386__) || defined(__x86_64__)
if(CPUID::supportsSSE4_1())
{
- return x86::pminud(x, y);
+ return x86::pminsd(x, y);
}
else
#endif
{
- RValue<UInt4> less = CmpLT(x, y);
+ RValue<Int4> less = CmpLT(x, y);
return (x & less) | (y & ~less);
}
}
- Type *UInt4::getType()
- {
- return T(llvm::VectorType::get(T(UInt::getType()), 4));
- }
-
- Half::Half(RValue<Float> cast)
- {
- UInt fp32i = As<UInt>(cast);
- UInt abs = fp32i & 0x7FFFFFFF;
- UShort fp16i((fp32i & 0x80000000) >> 16); // sign
-
- If(abs > 0x47FFEFFF) // Infinity
- {
- fp16i |= UShort(0x7FFF);
- }
- Else
- {
- If(abs < 0x38800000) // Denormal
- {
- Int mantissa = (abs & 0x007FFFFF) | 0x00800000;
- Int e = 113 - (abs >> 23);
- abs = IfThenElse(e < 24, mantissa >> e, Int(0));
- fp16i |= UShort((abs + 0x00000FFF + ((abs >> 13) & 1)) >> 13);
- }
- Else
- {
- fp16i |= UShort((abs + 0xC8000000 + 0x00000FFF + ((abs >> 13) & 1)) >> 13);
- }
- }
-
- storeValue(fp16i.loadValue());
- }
-
- Type *Half::getType()
- {
- return T(llvm::Type::getInt16Ty(*::context));
- }
-
- Float::Float(RValue<Int> cast)
- {
- Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
-
- storeValue(integer);
- }
-
- Float::Float(RValue<UInt> cast)
- {
- RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) +
- As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u)));
-
- storeValue(result.value);
- }
-
- Float::Float(RValue<Half> cast)
- {
- Int fp16i(As<UShort>(cast));
-
- Int s = (fp16i >> 15) & 0x00000001;
- Int e = (fp16i >> 10) & 0x0000001F;
- Int m = fp16i & 0x000003FF;
-
- UInt fp32i(s << 31);
- If(e == 0)
- {
- If(m != 0)
- {
- While((m & 0x00000400) == 0)
- {
- m <<= 1;
- e -= 1;
- }
-
- fp32i |= As<UInt>(((e + (127 - 15) + 1) << 23) | ((m & ~0x00000400) << 13));
- }
- }
- Else
- {
- fp32i |= As<UInt>(((e + (127 - 15)) << 23) | (m << 13));
- }
-
- storeValue(As<Float>(fp32i).value);
- }
-
- Float::Float(float x)
- {
- storeValue(Nucleus::createConstantFloat(x));
- }
-
- Float::Float(RValue<Float> rhs)
- {
- storeValue(rhs.value);
- }
-
- Float::Float(const Float &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Float::Float(const Reference<Float> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Float> Float::operator=(RValue<Float> rhs)
+ RValue<Int4> RoundInt(RValue<Float4> cast)
{
- storeValue(rhs.value);
-
- return rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::cvtps2dq(cast);
+#else
+ return As<Int4>(V(lowerRoundInt(V(cast.value), T(Int4::getType()))));
+#endif
}
- RValue<Float> Float::operator=(const Float &rhs)
+ RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float>(value);
+ // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
+ return As<Int4>(V(lowerMulHigh(V(x.value), V(y.value), true)));
}
- RValue<Float> Float::operator=(const Reference<Float> &rhs)
+ RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float>(value);
+ // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
+ return As<UInt4>(V(lowerMulHigh(V(x.value), V(y.value), false)));
}
- RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::packssdw(x, y);
+#else
+ return As<Short8>(V(lowerPack(V(x.value), V(y.value), true)));
+#endif
}
- RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::packusdw(x, y);
+#else
+ return As<UShort8>(V(lowerPack(V(x.value), V(y.value), false)));
+#endif
}
- RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<Int> SignMask(RValue<Int4> x)
{
- return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::movmskps(As<Float4>(x));
+#else
+ return As<Int>(V(lowerSignMask(V(x.value), T(Int::getType()))));
+#endif
}
- RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
+ Type *Int4::getType()
{
- return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
+ return T(llvm::VectorType::get(T(Int::getType()), 4));
}
- RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
+ UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
{
- return lhs = lhs + rhs;
- }
+ // Note: createFPToUI is broken, must perform conversion using createFPtoSI
+ // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
- RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
- {
- return lhs = lhs - rhs;
- }
+ // Smallest positive value representable in UInt, but not in Int
+ const unsigned int ustart = 0x80000000u;
+ const float ustartf = float(ustart);
- RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
- {
- return lhs = lhs * rhs;
+ // Check if the value can be represented as an Int
+ Int4 uiValue = CmpNLT(cast, Float4(ustartf));
+ // If the value is too large, subtract ustart and re-add it after conversion.
+ uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
+ // Otherwise, just convert normally
+ (~uiValue & Int4(cast));
+ // If the value is negative, store 0, otherwise store the result of the conversion
+ storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
}
- RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
+ RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
{
- return lhs = lhs / rhs;
+#if defined(__i386__) || defined(__x86_64__)
+ return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
+#else
+ return As<UInt4>(V(lowerVectorShl(V(lhs.value), rhs)));
+#endif
}
- RValue<Float> operator+(RValue<Float> val)
+ RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
{
- return val;
+#if defined(__i386__) || defined(__x86_64__)
+ return x86::psrld(lhs, rhs);
+#else
+ return As<UInt4>(V(lowerVectorLShr(V(lhs.value), rhs)));
+#endif
}
- RValue<Float> operator-(RValue<Float> val)
+ RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Float>(Nucleus::createFNeg(val.value));
+ // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
+ // Restore the following line when LLVM is updated to a version where this issue is fixed.
+ // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
+ return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
}
- RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
+ return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
}
- RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
+ // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
+ // Restore the following line when LLVM is updated to a version where this issue is fixed.
+ // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
+ return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
}
- RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
+ return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
}
- RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
+ // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
+ // Restore the following line when LLVM is updated to a version where this issue is fixed.
+ // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
+ return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
}
- RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
+ return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
}
- RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
+#if defined(__i386__) || defined(__x86_64__)
+ if(CPUID::supportsSSE4_1())
+ {
+ return x86::pmaxud(x, y);
+ }
+ else
+#endif
+ {
+ RValue<UInt4> greater = CmpNLE(x, y);
+ return (x & greater) | (y & ~greater);
+ }
}
- RValue<Float> Abs(RValue<Float> x)
+ RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
{
- return IfThenElse(x > 0.0f, x, -x);
+#if defined(__i386__) || defined(__x86_64__)
+ if(CPUID::supportsSSE4_1())
+ {
+ return x86::pminud(x, y);
+ }
+ else
+#endif
+ {
+ RValue<UInt4> less = CmpLT(x, y);
+ return (x & less) | (y & ~less);
+ }
}
- RValue<Float> Max(RValue<Float> x, RValue<Float> y)
+ Type *UInt4::getType()
{
- return IfThenElse(x > y, x, y);
+ return T(llvm::VectorType::get(T(UInt::getType()), 4));
}
- RValue<Float> Min(RValue<Float> x, RValue<Float> y)
+ Type *Half::getType()
{
- return IfThenElse(x < y, x, y);
+ return T(llvm::Type::getInt16Ty(*::context));
}
RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
return T(llvm::Type::getFloatTy(*::context));
}
- Float2::Float2(RValue<Float4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
Type *Float2::getType()
{
return T(Type_v2f32);
}
- Float4::Float4(RValue<Byte4> cast) : XYZW(this)
- {
- Value *a = Int4(cast).loadValue();
- Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
-
- storeValue(xyzw);
- }
-
- Float4::Float4(RValue<SByte4> cast) : XYZW(this)
- {
- Value *a = Int4(cast).loadValue();
- Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
-
- storeValue(xyzw);
- }
-
- Float4::Float4(RValue<Short4> cast) : XYZW(this)
- {
- Int4 c(cast);
- storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
- }
-
- Float4::Float4(RValue<UShort4> cast) : XYZW(this)
- {
- Int4 c(cast);
- storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
- }
-
- Float4::Float4(RValue<Int4> cast) : XYZW(this)
- {
- Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
-
- storeValue(xyzw);
- }
-
- Float4::Float4(RValue<UInt4> cast) : XYZW(this)
- {
- RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
- As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
-
- storeValue(result.value);
- }
-
- Float4::Float4() : XYZW(this)
- {
- }
-
- Float4::Float4(float xyzw) : XYZW(this)
- {
- constant(xyzw, xyzw, xyzw, xyzw);
- }
-
- Float4::Float4(float x, float yzw) : XYZW(this)
- {
- constant(x, yzw, yzw, yzw);
- }
-
- Float4::Float4(float x, float y, float zw) : XYZW(this)
- {
- constant(x, y, zw, zw);
- }
-
- Float4::Float4(float x, float y, float z, float w) : XYZW(this)
- {
- constant(x, y, z, w);
- }
-
- void Float4::constant(float x, float y, float z, float w)
- {
- double constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Float4::Float4(RValue<Float4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- Float4::Float4(const Float4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Float4::Float4(const Reference<Float4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
Float4::Float4(RValue<Float> rhs) : XYZW(this)
{
Value *vector = loadValue();
storeValue(replicate);
}
- Float4::Float4(const Float &rhs) : XYZW(this)
- {
- *this = RValue<Float>(rhs.loadValue());
- }
-
- Float4::Float4(const Reference<Float> &rhs) : XYZW(this)
- {
- *this = RValue<Float>(rhs.loadValue());
- }
-
- RValue<Float4> Float4::operator=(float x)
- {
- return *this = Float4(x, x, x, x);
- }
-
- RValue<Float4> Float4::operator=(RValue<Float4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Float4> Float4::operator=(const Float4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float4>(value);
- }
-
- RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float4>(value);
- }
-
- RValue<Float4> Float4::operator=(RValue<Float> rhs)
- {
- return *this = Float4(rhs);
- }
-
- RValue<Float4> Float4::operator=(const Float &rhs)
- {
- return *this = Float4(rhs);
- }
-
- RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
- {
- return *this = Float4(rhs);
- }
-
- RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Float4> operator+(RValue<Float4> val)
- {
- return val;
- }
-
- RValue<Float4> operator-(RValue<Float4> val)
- {
- return RValue<Float4>(Nucleus::createFNeg(val.value));
- }
-
- RValue<Float4> Abs(RValue<Float4> x)
- {
- Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
- int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
- Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, Int4::getType()));
-
- return As<Float4>(result);
- }
-
RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
{
#if defined(__i386__) || defined(__x86_64__)
#endif
}
- RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
- {
- return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
- }
-
- RValue<Float> Extract(RValue<Float4> x, int i)
- {
- return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
- }
-
- RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
- {
- return RValue<Float4>(createSwizzle4(x.value, select));
- }
-
- RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
- {
- int shuffle[4] =
- {
- ((imm >> 0) & 0x03) + 0,
- ((imm >> 2) & 0x03) + 0,
- ((imm >> 4) & 0x03) + 4,
- ((imm >> 6) & 0x03) + 4,
- };
-
- return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
- {
- int shuffle[4] = {0, 4, 1, 5};
- return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
- {
- int shuffle[4] = {2, 6, 3, 7};
- return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
- {
- Value *vector = lhs.loadValue();
- Value *result = createMask4(vector, rhs.value, select);
- lhs.storeValue(result);
-
- return RValue<Float4>(result);
- }
-
RValue<Int> SignMask(RValue<Float4> x)
{
#if defined(__i386__) || defined(__x86_64__)
return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpUGT(x.value, y.value), Int4::getType()));
}
- RValue<Int4> IsInf(RValue<Float4> x)
- {
- return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000));
- }
-
- RValue<Int4> IsNan(RValue<Float4> x)
- {
- return ~CmpEQ(x, x);
- }
-
RValue<Float4> Round(RValue<Float4> x)
{
#if defined(__i386__) || defined(__x86_64__)
return T(llvm::VectorType::get(T(Float::getType()), 4));
}
- RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
- {
- return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
- }
-
- RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
- {
- return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
- }
-
- RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
- {
- return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
- }
-
- RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
- {
- return lhs = lhs + offset;
- }
-
- RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
- {
- return lhs = lhs + offset;
- }
-
- RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
- {
- return lhs = lhs + offset;
- }
-
- RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
- {
- return lhs + -offset;
- }
-
- RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
- {
- return lhs + -offset;
- }
-
- RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
- {
- return lhs + -offset;
- }
-
- RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
- {
- return lhs = lhs - offset;
- }
-
- RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
- {
- return lhs = lhs - offset;
- }
-
- RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
- {
- return lhs = lhs - offset;
- }
-
- void Return()
- {
- Nucleus::createRetVoid();
- Nucleus::setInsertBlock(Nucleus::createBasicBlock());
- Nucleus::createUnreachable();
- }
-
- void Return(RValue<Int> ret)
- {
- Nucleus::createRet(ret.value);
- Nucleus::setInsertBlock(Nucleus::createBasicBlock());
- Nucleus::createUnreachable();
- }
-
- void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
- {
- Nucleus::createCondBr(cmp.value, bodyBB, endBB);
- Nucleus::setInsertBlock(bodyBB);
- }
-
RValue<Long> Ticks()
{
llvm::Function *rdtsc = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::readcyclecounter);
--- /dev/null
+// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Reactor.hpp"
+
+namespace rr
+{
+ static Value *createSwizzle4(Value *val, unsigned char select)
+ {
+ int swizzle[4] =
+ {
+ (select >> 0) & 0x03,
+ (select >> 2) & 0x03,
+ (select >> 4) & 0x03,
+ (select >> 6) & 0x03,
+ };
+
+ return Nucleus::createShuffleVector(val, val, swizzle);
+ }
+
+ static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
+ {
+ bool mask[4] = {false, false, false, false};
+
+ mask[(select >> 0) & 0x03] = true;
+ mask[(select >> 2) & 0x03] = true;
+ mask[(select >> 4) & 0x03] = true;
+ mask[(select >> 6) & 0x03] = true;
+
+ int swizzle[4] =
+ {
+ mask[0] ? 4 : 0,
+ mask[1] ? 5 : 1,
+ mask[2] ? 6 : 2,
+ mask[3] ? 7 : 3,
+ };
+
+ return Nucleus::createShuffleVector(lhs, rhs, swizzle);
+ }
+
+ Bool::Bool(Argument<Bool> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ Bool::Bool(bool x)
+ {
+ storeValue(Nucleus::createConstantBool(x));
+ }
+
+ Bool::Bool(RValue<Bool> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Bool::Bool(const Bool &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Bool::Bool(const Reference<Bool> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Bool> Bool::operator=(RValue<Bool> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Bool> Bool::operator=(const Bool &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Bool>(value);
+ }
+
+ RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Bool>(value);
+ }
+
+ RValue<Bool> operator!(RValue<Bool> val)
+ {
+ return RValue<Bool>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
+ {
+ return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
+ {
+ return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ Byte::Byte(Argument<Byte> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ Byte::Byte(RValue<Int> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
+
+ 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(int x)
+ {
+ storeValue(Nucleus::createConstantByte((unsigned char)x));
+ }
+
+ Byte::Byte(unsigned char x)
+ {
+ storeValue(Nucleus::createConstantByte(x));
+ }
+
+ Byte::Byte(RValue<Byte> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Byte::Byte(const Byte &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Byte::Byte(const Reference<Byte> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Byte> Byte::operator=(RValue<Byte> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Byte> Byte::operator=(const Byte &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Byte>(value);
+ }
+
+ RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Byte>(value);
+ }
+
+ RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Byte> operator+(RValue<Byte> val)
+ {
+ return val;
+ }
+
+ RValue<Byte> operator-(RValue<Byte> val)
+ {
+ return RValue<Byte>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Byte> operator~(RValue<Byte> val)
+ {
+ return RValue<Byte>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Byte> operator++(Byte &val, int) // Post-increment
+ {
+ RValue<Byte> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const Byte &operator++(Byte &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<Byte> operator--(Byte &val, int) // Post-decrement
+ {
+ RValue<Byte> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const Byte &operator--(Byte &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ SByte::SByte(Argument<SByte> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ 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(signed char x)
+ {
+ storeValue(Nucleus::createConstantByte(x));
+ }
+
+ SByte::SByte(RValue<SByte> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ SByte::SByte(const SByte &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ SByte::SByte(const Reference<SByte> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<SByte> SByte::operator=(RValue<SByte> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<SByte> SByte::operator=(const SByte &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<SByte>(value);
+ }
+
+ RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<SByte>(value);
+ }
+
+ RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<SByte> operator+(RValue<SByte> val)
+ {
+ return val;
+ }
+
+ RValue<SByte> operator-(RValue<SByte> val)
+ {
+ return RValue<SByte>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<SByte> operator~(RValue<SByte> val)
+ {
+ return RValue<SByte>(Nucleus::createNot(val.value));
+ }
+
+ RValue<SByte> operator++(SByte &val, int) // Post-increment
+ {
+ RValue<SByte> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const SByte &operator++(SByte &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<SByte> operator--(SByte &val, int) // Post-decrement
+ {
+ RValue<SByte> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const SByte &operator--(SByte &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ Short::Short(Argument<Short> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ Short::Short(RValue<Int> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
+
+ storeValue(integer);
+ }
+
+ Short::Short(short x)
+ {
+ storeValue(Nucleus::createConstantShort(x));
+ }
+
+ Short::Short(RValue<Short> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Short::Short(const Short &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Short::Short(const Reference<Short> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Short> Short::operator=(RValue<Short> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Short> Short::operator=(const Short &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Short>(value);
+ }
+
+ RValue<Short> Short::operator=(const Reference<Short> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Short>(value);
+ }
+
+ RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Short> operator+(RValue<Short> val)
+ {
+ return val;
+ }
+
+ RValue<Short> operator-(RValue<Short> val)
+ {
+ return RValue<Short>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Short> operator~(RValue<Short> val)
+ {
+ return RValue<Short>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short> operator++(Short &val, int) // Post-increment
+ {
+ RValue<Short> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const Short &operator++(Short &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<Short> operator--(Short &val, int) // Post-decrement
+ {
+ RValue<Short> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const Short &operator--(Short &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ UShort::UShort(Argument<UShort> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ UShort::UShort(RValue<UInt> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
+
+ storeValue(integer);
+ }
+
+ UShort::UShort(RValue<Int> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
+
+ storeValue(integer);
+ }
+
+ UShort::UShort(unsigned short x)
+ {
+ storeValue(Nucleus::createConstantShort(x));
+ }
+
+ UShort::UShort(RValue<UShort> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UShort::UShort(const UShort &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UShort::UShort(const Reference<UShort> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<UShort> UShort::operator=(RValue<UShort> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<UShort> UShort::operator=(const UShort &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort>(value);
+ }
+
+ RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort>(value);
+ }
+
+ RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UShort> operator+(RValue<UShort> val)
+ {
+ return val;
+ }
+
+ RValue<UShort> operator-(RValue<UShort> val)
+ {
+ return RValue<UShort>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UShort> operator~(RValue<UShort> val)
+ {
+ return RValue<UShort>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UShort> operator++(UShort &val, int) // Post-increment
+ {
+ RValue<UShort> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const UShort &operator++(UShort &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<UShort> operator--(UShort &val, int) // Post-decrement
+ {
+ RValue<UShort> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1));
+ val.storeValue(inc);
+
+ return res;
+ }
+
+ const UShort &operator--(UShort &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
+ val.storeValue(inc);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ Byte4::Byte4(RValue<Byte8> cast)
+ {
+ storeValue(Nucleus::createBitCast(cast.value, getType()));
+ }
+
+ Byte4::Byte4(const Reference<Byte4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Byte8::Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
+ {
+ int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Byte8::Byte8(RValue<Byte8> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Byte8::Byte8(const Byte8 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Byte8::Byte8(const Reference<Byte8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Byte8>(value);
+ }
+
+ RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Byte8>(value);
+ }
+
+ RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
+ {
+ return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
+ {
+ return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
+// {
+// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
+// }
+
+// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
+// {
+// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
+// }
+
+// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
+// {
+// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
+// }
+
+ RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
+ {
+ return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
+ {
+ return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
+ {
+ return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
+// {
+// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
+// }
+
+// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
+// {
+// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
+// }
+
+ RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+// RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
+// {
+// return lhs = lhs * rhs;
+// }
+
+// RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
+// {
+// return lhs = lhs << rhs;
+// }
+
+// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
+// {
+// return lhs = lhs >> rhs;
+// }
+
+// RValue<Byte8> operator+(RValue<Byte8> val)
+// {
+// return val;
+// }
+
+// RValue<Byte8> operator-(RValue<Byte8> val)
+// {
+// return RValue<Byte8>(Nucleus::createNeg(val.value));
+// }
+
+ RValue<Byte8> operator~(RValue<Byte8> val)
+ {
+ return RValue<Byte8>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short4> Unpack(RValue<Byte4> x)
+ {
+ int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
+ return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
+ }
+
+ RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
+ {
+ return UnpackLow(As<Byte8>(x), As<Byte8>(y));
+ }
+
+ RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
+ {
+ int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
+ return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
+ {
+ int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
+ auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
+ }
+
+ SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
+ {
+ int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
+ Value *vector = Nucleus::createConstantVector(constantVector, getType());
+
+ storeValue(Nucleus::createBitCast(vector, getType()));
+ }
+
+ SByte8::SByte8(RValue<SByte8> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ SByte8::SByte8(const SByte8 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ SByte8::SByte8(const Reference<SByte8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<SByte8>(value);
+ }
+
+ RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<SByte8>(value);
+ }
+
+ RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
+ {
+ return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
+ {
+ return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
+// {
+// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
+// }
+
+// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
+// {
+// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
+// }
+
+// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
+// {
+// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
+// }
+
+ RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
+ {
+ return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
+ {
+ return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
+ {
+ return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
+// {
+// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
+// }
+
+// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
+// {
+// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
+// }
+
+ RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+// RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
+// {
+// return lhs = lhs * rhs;
+// }
+
+// RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
+// {
+// return lhs = lhs << rhs;
+// }
+
+// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
+// {
+// return lhs = lhs >> rhs;
+// }
+
+// RValue<SByte8> operator+(RValue<SByte8> val)
+// {
+// return val;
+// }
+
+// RValue<SByte8> operator-(RValue<SByte8> val)
+// {
+// return RValue<SByte8>(Nucleus::createNeg(val.value));
+// }
+
+ RValue<SByte8> operator~(RValue<SByte8> val)
+ {
+ return RValue<SByte8>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
+ {
+ int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
+ return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
+ {
+ int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
+ auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
+ }
+
+ Byte16::Byte16(RValue<Byte16> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Byte16::Byte16(const Byte16 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Byte16::Byte16(const Reference<Byte16> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Byte16>(value);
+ }
+
+ RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Byte16>(value);
+ }
+
+ Short2::Short2(RValue<Short4> cast)
+ {
+ storeValue(Nucleus::createBitCast(cast.value, getType()));
+ }
+
+ UShort2::UShort2(RValue<UShort4> cast)
+ {
+ storeValue(Nucleus::createBitCast(cast.value, getType()));
+ }
+
+ Short4::Short4(RValue<Int> cast)
+ {
+ Value *vector = loadValue();
+ Value *element = Nucleus::createTrunc(cast.value, Short::getType());
+ Value *insert = Nucleus::createInsertElement(vector, element, 0);
+ Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
+
+ storeValue(swizzle);
+ }
+
+// Short4::Short4(RValue<Float> cast)
+// {
+// }
+
+ Short4::Short4(short xyzw)
+ {
+ int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Short4::Short4(short x, short y, short z, short w)
+ {
+ int64_t constantVector[4] = {x, y, z, w};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Short4::Short4(RValue<Short4> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Short4::Short4(const Short4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Short4::Short4(const Reference<Short4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Short4::Short4(RValue<UShort4> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Short4::Short4(const UShort4 &rhs)
+ {
+ storeValue(rhs.loadValue());
+ }
+
+ Short4::Short4(const Reference<UShort4> &rhs)
+ {
+ storeValue(rhs.loadValue());
+ }
+
+ RValue<Short4> Short4::operator=(RValue<Short4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Short4> Short4::operator=(const Short4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Short4>(value);
+ }
+
+ RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Short4>(value);
+ }
+
+ RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return RValue<Short4>(rhs);
+ }
+
+ RValue<Short4> Short4::operator=(const UShort4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Short4>(value);
+ }
+
+ RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Short4>(value);
+ }
+
+ RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
+ {
+ return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
+ {
+ return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
+ {
+ return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
+// {
+// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
+// }
+
+// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
+// {
+// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
+// }
+
+ RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
+ {
+ return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
+ {
+ return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
+ {
+ return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+// RValue<Short4> operator+(RValue<Short4> val)
+// {
+// return val;
+// }
+
+ RValue<Short4> operator-(RValue<Short4> val)
+ {
+ return RValue<Short4>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Short4> operator~(RValue<Short4> val)
+ {
+ return RValue<Short4>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short4> RoundShort4(RValue<Float4> cast)
+ {
+ RValue<Int4> int4 = RoundInt(cast);
+ return As<Short4>(PackSigned(int4, int4));
+ }
+
+ RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
+ {
+ int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
+ return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
+ {
+ int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
+ auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
+ }
+
+ RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
+ {
+ // Real type is v8i16
+ int shuffle[8] =
+ {
+ (select >> 0) & 0x03,
+ (select >> 2) & 0x03,
+ (select >> 4) & 0x03,
+ (select >> 6) & 0x03,
+ (select >> 0) & 0x03,
+ (select >> 2) & 0x03,
+ (select >> 4) & 0x03,
+ (select >> 6) & 0x03,
+ };
+
+ return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
+ }
+
+ RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
+ {
+ return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
+ }
+
+ RValue<Short> Extract(RValue<Short4> val, int i)
+ {
+ return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
+ }
+
+ UShort4::UShort4(RValue<Int4> cast)
+ {
+ *this = Short4(cast);
+ }
+
+ UShort4::UShort4(unsigned short xyzw)
+ {
+ int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
+ {
+ int64_t constantVector[4] = {x, y, z, w};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ UShort4::UShort4(RValue<UShort4> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UShort4::UShort4(const UShort4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UShort4::UShort4(const Reference<UShort4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UShort4::UShort4(RValue<Short4> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UShort4::UShort4(const Short4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UShort4::UShort4(const Reference<Short4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort4>(value);
+ }
+
+ RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort4>(value);
+ }
+
+ RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return RValue<UShort4>(rhs);
+ }
+
+ RValue<UShort4> UShort4::operator=(const Short4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort4>(value);
+ }
+
+ RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort4>(value);
+ }
+
+ RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
+ {
+ return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
+ {
+ return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
+ {
+ return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
+ {
+ return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
+ {
+ return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
+ {
+ return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UShort4> operator~(RValue<UShort4> val)
+ {
+ return RValue<UShort4>(Nucleus::createNot(val.value));
+ }
+
+ Short8::Short8(short c)
+ {
+ int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
+ {
+ int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Short8::Short8(RValue<Short8> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Short8::Short8(const Reference<Short8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
+ {
+ int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
+ Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
+
+ storeValue(packed);
+ }
+
+ RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
+ {
+ return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
+ {
+ return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> Abs(RValue<Int4> x)
+ {
+ // TODO: Optimize.
+ auto negative = x >> 31;
+ return (x ^ negative) - negative;
+ }
+
+ UShort8::UShort8(unsigned short c)
+ {
+ int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ UShort8::UShort8(unsigned short c0, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short c4, unsigned short c5, unsigned short c6, unsigned short c7)
+ {
+ int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ UShort8::UShort8(RValue<UShort8> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UShort8::UShort8(const Reference<UShort8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
+ {
+ int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
+ Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
+
+ storeValue(packed);
+ }
+
+ RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort8>(value);
+ }
+
+ RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UShort8>(value);
+ }
+
+ RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
+ {
+ return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
+ {
+ return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
+ {
+ return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UShort8> operator~(RValue<UShort8> val)
+ {
+ return RValue<UShort8>(Nucleus::createNot(val.value));
+ }
+
+ Int::Int(Argument<Int> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ Int::Int(RValue<Byte> cast)
+ {
+ Value *integer = Nucleus::createZExt(cast.value, Int::getType());
+
+ storeValue(integer);
+ }
+
+ Int::Int(RValue<SByte> cast)
+ {
+ Value *integer = Nucleus::createSExt(cast.value, Int::getType());
+
+ storeValue(integer);
+ }
+
+ Int::Int(RValue<Short> cast)
+ {
+ Value *integer = Nucleus::createSExt(cast.value, Int::getType());
+
+ storeValue(integer);
+ }
+
+ Int::Int(RValue<UShort> cast)
+ {
+ Value *integer = Nucleus::createZExt(cast.value, Int::getType());
+
+ storeValue(integer);
+ }
+
+ Int::Int(RValue<Int2> cast)
+ {
+ *this = Extract(cast, 0);
+ }
+
+ Int::Int(RValue<Long> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
+
+ storeValue(integer);
+ }
+
+ Int::Int(RValue<Float> cast)
+ {
+ Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
+
+ storeValue(integer);
+ }
+
+ Int::Int(int x)
+ {
+ storeValue(Nucleus::createConstantInt(x));
+ }
+
+ Int::Int(RValue<Int> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Int::Int(RValue<UInt> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Int::Int(const Int &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int::Int(const Reference<Int> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int::Int(const UInt &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int::Int(const Reference<UInt> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Int> Int::operator=(int rhs)
+ {
+ return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
+ }
+
+ RValue<Int> Int::operator=(RValue<Int> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Int> Int::operator=(RValue<UInt> rhs)
+ {
+ storeValue(rhs.value);
+
+ return RValue<Int>(rhs);
+ }
+
+ RValue<Int> Int::operator=(const Int &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int>(value);
+ }
+
+ RValue<Int> Int::operator=(const Reference<Int> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int>(value);
+ }
+
+ RValue<Int> Int::operator=(const UInt &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int>(value);
+ }
+
+ RValue<Int> Int::operator=(const Reference<UInt> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int>(value);
+ }
+
+ RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Int> operator+(RValue<Int> val)
+ {
+ return val;
+ }
+
+ RValue<Int> operator-(RValue<Int> val)
+ {
+ return RValue<Int>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Int> operator~(RValue<Int> val)
+ {
+ return RValue<Int>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ RValue<Int> Max(RValue<Int> x, RValue<Int> y)
+ {
+ return IfThenElse(x > y, x, y);
+ }
+
+ RValue<Int> Min(RValue<Int> x, RValue<Int> y)
+ {
+ return IfThenElse(x < y, x, y);
+ }
+
+ RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
+ {
+ return Min(Max(x, min), max);
+ }
+
+ Long::Long(RValue<Int> cast)
+ {
+ Value *integer = Nucleus::createSExt(cast.value, Long::getType());
+
+ storeValue(integer);
+ }
+
+ Long::Long(RValue<UInt> cast)
+ {
+ Value *integer = Nucleus::createZExt(cast.value, Long::getType());
+
+ storeValue(integer);
+ }
+
+ Long::Long(RValue<Long> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ RValue<Long> Long::operator=(int64_t rhs)
+ {
+ return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
+ }
+
+ RValue<Long> Long::operator=(RValue<Long> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Long> Long::operator=(const Long &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Long>(value);
+ }
+
+ RValue<Long> Long::operator=(const Reference<Long> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Long>(value);
+ }
+
+ RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
+ {
+ return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
+ {
+ return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs)
+ {
+ return RValue<Long>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs)
+ {
+ return RValue<Long>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
+ {
+ return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
+ }
+
+ UInt::UInt(Argument<UInt> argument)
+ {
+ storeValue(argument.value);
+ }
+
+ UInt::UInt(RValue<UShort> cast)
+ {
+ Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
+
+ storeValue(integer);
+ }
+
+ UInt::UInt(RValue<Long> cast)
+ {
+ Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
+
+ storeValue(integer);
+ }
+
+ UInt::UInt(int x)
+ {
+ storeValue(Nucleus::createConstantInt(x));
+ }
+
+ UInt::UInt(unsigned int x)
+ {
+ storeValue(Nucleus::createConstantInt(x));
+ }
+
+ UInt::UInt(RValue<UInt> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UInt::UInt(RValue<Int> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UInt::UInt(const UInt &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt::UInt(const Reference<UInt> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt::UInt(const Int &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt::UInt(const Reference<Int> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<UInt> UInt::operator=(unsigned int rhs)
+ {
+ return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
+ }
+
+ RValue<UInt> UInt::operator=(RValue<UInt> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<UInt> UInt::operator=(RValue<Int> rhs)
+ {
+ storeValue(rhs.value);
+
+ return RValue<UInt>(rhs);
+ }
+
+ RValue<UInt> UInt::operator=(const UInt &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt>(value);
+ }
+
+ RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt>(value);
+ }
+
+ RValue<UInt> UInt::operator=(const Int &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt>(value);
+ }
+
+ RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt>(value);
+ }
+
+ RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UInt> operator+(RValue<UInt> val)
+ {
+ return val;
+ }
+
+ RValue<UInt> operator-(RValue<UInt> val)
+ {
+ return RValue<UInt>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UInt> operator~(RValue<UInt> val)
+ {
+ return RValue<UInt>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
+ {
+ return IfThenElse(x > y, x, y);
+ }
+
+ RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
+ {
+ return IfThenElse(x < y, x, y);
+ }
+
+ RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
+ {
+ return Min(Max(x, min), max);
+ }
+
+ RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ Int2::Int2(RValue<Int4> cast)
+ {
+ storeValue(Nucleus::createBitCast(cast.value, getType()));
+ }
+
+ Int2::Int2(int x, int y)
+ {
+ int64_t constantVector[2] = {x, y};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Int2::Int2(RValue<Int2> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Int2::Int2(const Int2 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int2::Int2(const Reference<Int2> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int2::Int2(RValue<Int> lo, RValue<Int> hi)
+ {
+ int shuffle[4] = {0, 4, 1, 5};
+ Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
+
+ storeValue(Nucleus::createBitCast(packed, Int2::getType()));
+ }
+
+ RValue<Int2> Int2::operator=(RValue<Int2> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Int2> Int2::operator=(const Int2 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int2>(value);
+ }
+
+ RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int2>(value);
+ }
+
+ RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
+ {
+ return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
+ {
+ return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
+// {
+// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
+// }
+
+// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
+// {
+// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
+// }
+
+// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
+// {
+// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
+// }
+
+ RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
+ {
+ return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
+ {
+ return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
+ {
+ return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
+// {
+// return lhs = lhs * rhs;
+// }
+
+// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+// RValue<Int2> operator+(RValue<Int2> val)
+// {
+// return val;
+// }
+
+// RValue<Int2> operator-(RValue<Int2> val)
+// {
+// return RValue<Int2>(Nucleus::createNeg(val.value));
+// }
+
+ RValue<Int2> operator~(RValue<Int2> val)
+ {
+ return RValue<Int2>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
+ {
+ int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
+ return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
+ {
+ int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
+ auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ return As<Short4>(Swizzle(lowHigh, 0xEE));
+ }
+
+ RValue<Int> Extract(RValue<Int2> val, int i)
+ {
+ return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
+ }
+
+ RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
+ {
+ return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
+ }
+
+ UInt2::UInt2(unsigned int x, unsigned int y)
+ {
+ int64_t constantVector[2] = {x, y};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ UInt2::UInt2(RValue<UInt2> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ UInt2::UInt2(const UInt2 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt2::UInt2(const Reference<UInt2> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt2>(value);
+ }
+
+ RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt2>(value);
+ }
+
+ RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
+ {
+ return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
+ {
+ return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
+// {
+// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
+// }
+
+// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
+// {
+// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
+// }
+
+// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
+// {
+// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
+// }
+
+ RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
+ {
+ return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
+ {
+ return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
+ {
+ return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
+// {
+// return lhs = lhs * rhs;
+// }
+
+// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+// RValue<UInt2> operator+(RValue<UInt2> val)
+// {
+// return val;
+// }
+
+// RValue<UInt2> operator-(RValue<UInt2> val)
+// {
+// return RValue<UInt2>(Nucleus::createNeg(val.value));
+// }
+
+ RValue<UInt2> operator~(RValue<UInt2> val)
+ {
+ return RValue<UInt2>(Nucleus::createNot(val.value));
+ }
+
+ Int4::Int4() : XYZW(this)
+ {
+ }
+
+ Int4::Int4(RValue<Float4> cast) : XYZW(this)
+ {
+ Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
+
+ storeValue(xyzw);
+ }
+
+ Int4::Int4(int xyzw) : XYZW(this)
+ {
+ constant(xyzw, xyzw, xyzw, xyzw);
+ }
+
+ Int4::Int4(int x, int yzw) : XYZW(this)
+ {
+ constant(x, yzw, yzw, yzw);
+ }
+
+ Int4::Int4(int x, int y, int zw) : XYZW(this)
+ {
+ constant(x, y, zw, zw);
+ }
+
+ Int4::Int4(int x, int y, int z, int w) : XYZW(this)
+ {
+ constant(x, y, z, w);
+ }
+
+ void Int4::constant(int x, int y, int z, int w)
+ {
+ int64_t constantVector[4] = {x, y, z, w};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Int4::Int4(RValue<Int4> rhs) : XYZW(this)
+ {
+ storeValue(rhs.value);
+ }
+
+ Int4::Int4(const Int4 &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int4::Int4(const Reference<Int4> &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int4::Int4(RValue<UInt4> rhs) : XYZW(this)
+ {
+ storeValue(rhs.value);
+ }
+
+ Int4::Int4(const UInt4 &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this)
+ {
+ int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
+ Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
+
+ storeValue(packed);
+ }
+
+ Int4::Int4(const Int &rhs) : XYZW(this)
+ {
+ *this = RValue<Int>(rhs.loadValue());
+ }
+
+ Int4::Int4(const Reference<Int> &rhs) : XYZW(this)
+ {
+ *this = RValue<Int>(rhs.loadValue());
+ }
+
+ RValue<Int4> Int4::operator=(RValue<Int4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Int4> Int4::operator=(const Int4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int4>(value);
+ }
+
+ RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Int4>(value);
+ }
+
+ RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
+ {
+ return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Int4> operator+(RValue<Int4> val)
+ {
+ return val;
+ }
+
+ RValue<Int4> operator-(RValue<Int4> val)
+ {
+ return RValue<Int4>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Int4> operator~(RValue<Int4> val)
+ {
+ return RValue<Int4>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Int> Extract(RValue<Int4> x, int i)
+ {
+ return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
+ }
+
+ RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
+ {
+ return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
+ }
+
+ RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
+ {
+ return RValue<Int4>(createSwizzle4(x.value, select));
+ }
+
+ UInt4::UInt4() : XYZW(this)
+ {
+ }
+
+ UInt4::UInt4(int xyzw) : XYZW(this)
+ {
+ constant(xyzw, xyzw, xyzw, xyzw);
+ }
+
+ UInt4::UInt4(int x, int yzw) : XYZW(this)
+ {
+ constant(x, yzw, yzw, yzw);
+ }
+
+ UInt4::UInt4(int x, int y, int zw) : XYZW(this)
+ {
+ constant(x, y, zw, zw);
+ }
+
+ UInt4::UInt4(int x, int y, int z, int w) : XYZW(this)
+ {
+ constant(x, y, z, w);
+ }
+
+ void UInt4::constant(int x, int y, int z, int w)
+ {
+ int64_t constantVector[4] = {x, y, z, w};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this)
+ {
+ storeValue(rhs.value);
+ }
+
+ UInt4::UInt4(const UInt4 &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt4::UInt4(RValue<Int4> rhs) : XYZW(this)
+ {
+ storeValue(rhs.value);
+ }
+
+ UInt4::UInt4(const Int4 &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this)
+ {
+ int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
+ Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
+
+ storeValue(packed);
+ }
+
+ RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt4>(value);
+ }
+
+ RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<UInt4>(value);
+ }
+
+ RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ {
+ return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
+// {
+// return lhs = lhs / rhs;
+// }
+
+// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
+// {
+// return lhs = lhs % rhs;
+// }
+
+ RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UInt4> operator+(RValue<UInt4> val)
+ {
+ return val;
+ }
+
+ RValue<UInt4> operator-(RValue<UInt4> val)
+ {
+ return RValue<UInt4>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UInt4> operator~(RValue<UInt4> val)
+ {
+ return RValue<UInt4>(Nucleus::createNot(val.value));
+ }
+
+ Half::Half(RValue<Float> cast)
+ {
+ UInt fp32i = As<UInt>(cast);
+ UInt abs = fp32i & 0x7FFFFFFF;
+ UShort fp16i((fp32i & 0x80000000) >> 16); // sign
+
+ If(abs > 0x47FFEFFF) // Infinity
+ {
+ fp16i |= UShort(0x7FFF);
+ }
+ Else
+ {
+ If(abs < 0x38800000) // Denormal
+ {
+ Int mantissa = (abs & 0x007FFFFF) | 0x00800000;
+ Int e = 113 - (abs >> 23);
+ abs = IfThenElse(e < 24, mantissa >> e, Int(0));
+ fp16i |= UShort((abs + 0x00000FFF + ((abs >> 13) & 1)) >> 13);
+ }
+ Else
+ {
+ fp16i |= UShort((abs + 0xC8000000 + 0x00000FFF + ((abs >> 13) & 1)) >> 13);
+ }
+ }
+
+ storeValue(fp16i.loadValue());
+ }
+
+ Float::Float(RValue<Int> cast)
+ {
+ Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
+
+ storeValue(integer);
+ }
+
+ Float::Float(RValue<UInt> cast)
+ {
+ RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) +
+ As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u)));
+
+ storeValue(result.value);
+ }
+
+ Float::Float(RValue<Half> cast)
+ {
+ Int fp16i(As<UShort>(cast));
+
+ Int s = (fp16i >> 15) & 0x00000001;
+ Int e = (fp16i >> 10) & 0x0000001F;
+ Int m = fp16i & 0x000003FF;
+
+ UInt fp32i(s << 31);
+ If(e == 0)
+ {
+ If(m != 0)
+ {
+ While((m & 0x00000400) == 0)
+ {
+ m <<= 1;
+ e -= 1;
+ }
+
+ fp32i |= As<UInt>(((e + (127 - 15) + 1) << 23) | ((m & ~0x00000400) << 13));
+ }
+ }
+ Else
+ {
+ fp32i |= As<UInt>(((e + (127 - 15)) << 23) | (m << 13));
+ }
+
+ storeValue(As<Float>(fp32i).value);
+ }
+
+ Float::Float(float x)
+ {
+ storeValue(Nucleus::createConstantFloat(x));
+ }
+
+ Float::Float(RValue<Float> rhs)
+ {
+ storeValue(rhs.value);
+ }
+
+ Float::Float(const Float &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Float::Float(const Reference<Float> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ RValue<Float> Float::operator=(RValue<Float> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Float> Float::operator=(const Float &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Float>(value);
+ }
+
+ RValue<Float> Float::operator=(const Reference<Float> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Float>(value);
+ }
+
+ RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Float> operator+(RValue<Float> val)
+ {
+ return val;
+ }
+
+ RValue<Float> operator-(RValue<Float> val)
+ {
+ return RValue<Float>(Nucleus::createFNeg(val.value));
+ }
+
+ RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
+ }
+
+ RValue<Float> Abs(RValue<Float> x)
+ {
+ return IfThenElse(x > 0.0f, x, -x);
+ }
+
+ RValue<Float> Max(RValue<Float> x, RValue<Float> y)
+ {
+ return IfThenElse(x > y, x, y);
+ }
+
+ RValue<Float> Min(RValue<Float> x, RValue<Float> y)
+ {
+ return IfThenElse(x < y, x, y);
+ }
+
+ Float2::Float2(RValue<Float4> cast)
+ {
+ storeValue(Nucleus::createBitCast(cast.value, getType()));
+ }
+
+ Float4::Float4(RValue<Byte4> cast) : XYZW(this)
+ {
+ Value *a = Int4(cast).loadValue();
+ Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
+
+ storeValue(xyzw);
+ }
+
+ Float4::Float4(RValue<SByte4> cast) : XYZW(this)
+ {
+ Value *a = Int4(cast).loadValue();
+ Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
+
+ storeValue(xyzw);
+ }
+
+ Float4::Float4(RValue<Short4> cast) : XYZW(this)
+ {
+ Int4 c(cast);
+ storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
+ }
+
+ Float4::Float4(RValue<UShort4> cast) : XYZW(this)
+ {
+ Int4 c(cast);
+ storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
+ }
+
+ Float4::Float4(RValue<Int4> cast) : XYZW(this)
+ {
+ Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
+
+ storeValue(xyzw);
+ }
+
+ Float4::Float4(RValue<UInt4> cast) : XYZW(this)
+ {
+ RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
+ As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
+
+ storeValue(result.value);
+ }
+
+ Float4::Float4() : XYZW(this)
+ {
+ }
+
+ Float4::Float4(float xyzw) : XYZW(this)
+ {
+ constant(xyzw, xyzw, xyzw, xyzw);
+ }
+
+ Float4::Float4(float x, float yzw) : XYZW(this)
+ {
+ constant(x, yzw, yzw, yzw);
+ }
+
+ Float4::Float4(float x, float y, float zw) : XYZW(this)
+ {
+ constant(x, y, zw, zw);
+ }
+
+ Float4::Float4(float x, float y, float z, float w) : XYZW(this)
+ {
+ constant(x, y, z, w);
+ }
+
+ void Float4::constant(float x, float y, float z, float w)
+ {
+ double constantVector[4] = {x, y, z, w};
+ storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ }
+
+ Float4::Float4(RValue<Float4> rhs) : XYZW(this)
+ {
+ storeValue(rhs.value);
+ }
+
+ Float4::Float4(const Float4 &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Float4::Float4(const Reference<Float4> &rhs) : XYZW(this)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+ }
+
+ Float4::Float4(const Float &rhs) : XYZW(this)
+ {
+ *this = RValue<Float>(rhs.loadValue());
+ }
+
+ Float4::Float4(const Reference<Float> &rhs) : XYZW(this)
+ {
+ *this = RValue<Float>(rhs.loadValue());
+ }
+
+ RValue<Float4> Float4::operator=(float x)
+ {
+ return *this = Float4(x, x, x, x);
+ }
+
+ RValue<Float4> Float4::operator=(RValue<Float4> rhs)
+ {
+ storeValue(rhs.value);
+
+ return rhs;
+ }
+
+ RValue<Float4> Float4::operator=(const Float4 &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Float4>(value);
+ }
+
+ RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
+ {
+ Value *value = rhs.loadValue();
+ storeValue(value);
+
+ return RValue<Float4>(value);
+ }
+
+ RValue<Float4> Float4::operator=(RValue<Float> rhs)
+ {
+ return *this = Float4(rhs);
+ }
+
+ RValue<Float4> Float4::operator=(const Float &rhs)
+ {
+ return *this = Float4(rhs);
+ }
+
+ RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
+ {
+ return *this = Float4(rhs);
+ }
+
+ RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
+ {
+ return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
+ {
+ return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
+ {
+ return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
+ {
+ return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
+ {
+ return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Float4> operator+(RValue<Float4> val)
+ {
+ return val;
+ }
+
+ RValue<Float4> operator-(RValue<Float4> val)
+ {
+ return RValue<Float4>(Nucleus::createFNeg(val.value));
+ }
+
+ RValue<Float4> Abs(RValue<Float4> x)
+ {
+ // TODO: Optimize.
+ Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
+ int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
+ Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, Int4::getType()));
+
+ return As<Float4>(result);
+ }
+
+ RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
+ {
+ return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
+ }
+
+ RValue<Float> Extract(RValue<Float4> x, int i)
+ {
+ return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
+ }
+
+ RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
+ {
+ return RValue<Float4>(createSwizzle4(x.value, select));
+ }
+
+ RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
+ {
+ int shuffle[4] =
+ {
+ ((imm >> 0) & 0x03) + 0,
+ ((imm >> 2) & 0x03) + 0,
+ ((imm >> 4) & 0x03) + 4,
+ ((imm >> 6) & 0x03) + 4,
+ };
+
+ return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
+ {
+ int shuffle[4] = {0, 4, 1, 5};
+ return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
+ {
+ int shuffle[4] = {2, 6, 3, 7};
+ return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
+ }
+
+ RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
+ {
+ Value *vector = lhs.loadValue();
+ Value *result = createMask4(vector, rhs.value, select);
+ lhs.storeValue(result);
+
+ return RValue<Float4>(result);
+ }
+
+ RValue<Int4> IsInf(RValue<Float4> x)
+ {
+ return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000));
+ }
+
+ RValue<Int4> IsNan(RValue<Float4> x)
+ {
+ return ~CmpEQ(x, x);
+ }
+
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
+ {
+ return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
+ }
+
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
+ {
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
+ }
+
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
+ {
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
+ }
+
+ RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
+ {
+ return lhs = lhs + offset;
+ }
+
+ RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
+ {
+ return lhs = lhs + offset;
+ }
+
+ RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
+ {
+ return lhs = lhs + offset;
+ }
+
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
+ {
+ return lhs + -offset;
+ }
+
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
+ {
+ return lhs + -offset;
+ }
+
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
+ {
+ return lhs + -offset;
+ }
+
+ RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
+ {
+ return lhs = lhs - offset;
+ }
+
+ RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
+ {
+ return lhs = lhs - offset;
+ }
+
+ RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
+ {
+ return lhs = lhs - offset;
+ }
+
+ void Return()
+ {
+ Nucleus::createRetVoid();
+ Nucleus::setInsertBlock(Nucleus::createBasicBlock());
+ Nucleus::createUnreachable();
+ }
+
+ void Return(RValue<Int> ret)
+ {
+ Nucleus::createRet(ret.value);
+ Nucleus::setInsertBlock(Nucleus::createBasicBlock());
+ Nucleus::createUnreachable();
+ }
+
+ void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
+ {
+ Nucleus::createCondBr(cmp.value, bodyBB, endBB);
+ Nucleus::setInsertBlock(bodyBB);
+ }
+}
<ClCompile Include="LLVMRoutineManager.cpp" />\r
<ClCompile Include="LLVMReactor.cpp" />\r
<ClCompile Include="ExecutableMemory.cpp" />\r
+ <ClCompile Include="Reactor.cpp" />\r
<ClCompile Include="Routine.cpp" />\r
<ClCompile Include="Thread.cpp" />\r
</ItemGroup>\r
<ClCompile Include="Thread.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
+ <ClCompile Include="Reactor.cpp">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="Nucleus.hpp">\r
<ClCompile Include="Debug.cpp" />\r
<ClCompile Include="ExecutableMemory.cpp" />\r
<ClCompile Include="Optimizer.cpp" />\r
+ <ClCompile Include="Reactor.cpp" />\r
<ClCompile Include="Routine.cpp" />\r
<ClCompile Include="SubzeroReactor.cpp" />\r
</ItemGroup>\r
<ClCompile Include="Debug.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
+ <ClCompile Include="Reactor.cpp">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="$(SolutionDir)third_party\subzero\src\IceAssembler.h">\r
::basicBlock->appendInst(unreachable);
}
- static Value *createSwizzle4(Value *val, unsigned char select)
- {
- int swizzle[4] =
- {
- (select >> 0) & 0x03,
- (select >> 2) & 0x03,
- (select >> 4) & 0x03,
- (select >> 6) & 0x03,
- };
-
- return Nucleus::createShuffleVector(val, val, swizzle);
- }
-
- static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
- {
- int64_t mask[4] = {0, 0, 0, 0};
-
- mask[(select >> 0) & 0x03] = -1;
- mask[(select >> 2) & 0x03] = -1;
- mask[(select >> 4) & 0x03] = -1;
- mask[(select >> 6) & 0x03] = -1;
-
- Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1));
- Value *result = Nucleus::createSelect(condition, rhs, lhs);
-
- return result;
- }
-
Type *Nucleus::getPointerType(Type *ElementType)
{
if(sizeof(void*) == 8)
return T(Ice::IceType_void);
}
- Bool::Bool(Argument<Bool> argument)
+ Type *Bool::getType()
{
- storeValue(argument.value);
+ return T(Ice::IceType_i1);
}
- Bool::Bool(bool x)
+ Type *Byte::getType()
{
- storeValue(Nucleus::createConstantBool(x));
+ return T(Ice::IceType_i8);
}
- Bool::Bool(RValue<Bool> rhs)
+ Type *SByte::getType()
{
- storeValue(rhs.value);
+ return T(Ice::IceType_i8);
}
- Bool::Bool(const Bool &rhs)
+ Type *Short::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(Ice::IceType_i16);
}
- Bool::Bool(const Reference<Bool> &rhs)
+ Type *UShort::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(Ice::IceType_i16);
}
- RValue<Bool> Bool::operator=(RValue<Bool> rhs)
+ Type *Byte4::getType()
{
- storeValue(rhs.value);
-
- return rhs;
+ return T(Type_v4i8);
}
- RValue<Bool> Bool::operator=(const Bool &rhs)
+ Type *SByte4::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Bool>(value);
+ return T(Type_v4i8);
}
- RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
+ namespace
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ RValue<Byte> SaturateUnsigned(RValue<Short> x)
+ {
+ return Byte(IfThenElse(Int(x) > 0xFF, Int(0xFF), IfThenElse(Int(x) < 0, Int(0), Int(x))));
+ }
- return RValue<Bool>(value);
- }
+ RValue<Byte> Extract(RValue<Byte8> val, int i)
+ {
+ return RValue<Byte>(Nucleus::createExtractElement(val.value, Byte::getType(), i));
+ }
- RValue<Bool> operator!(RValue<Bool> val)
- {
- return RValue<Bool>(Nucleus::createNot(val.value));
+ RValue<Byte8> Insert(RValue<Byte8> val, RValue<Byte> element, int i)
+ {
+ return RValue<Byte8>(Nucleus::createInsertElement(val.value, element.value, i));
+ }
}
- RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
+ RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
{
- return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
- }
+ if(emulateIntrinsics)
+ {
+ Byte8 result;
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7);
- RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
- {
- return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ paddusb->addArg(x.value);
+ paddusb->addArg(y.value);
+ ::basicBlock->appendInst(paddusb);
- Type *Bool::getType()
- {
- return T(Ice::IceType_i1);
+ return RValue<Byte8>(V(result));
+ }
}
- Byte::Byte(Argument<Byte> argument)
+ RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
{
- storeValue(argument.value);
- }
+ if(emulateIntrinsics)
+ {
+ Byte8 result;
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6);
+ result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7);
- Byte::Byte(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ psubusw->addArg(x.value);
+ psubusw->addArg(y.value);
+ ::basicBlock->appendInst(psubusw);
- storeValue(integer);
+ return RValue<Byte8>(V(result));
+ }
}
- Byte::Byte(RValue<UInt> cast)
+ RValue<SByte> Extract(RValue<SByte8> val, int i)
{
- Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
-
- storeValue(integer);
+ return RValue<SByte>(Nucleus::createExtractElement(val.value, SByte::getType(), i));
}
- Byte::Byte(RValue<UShort> cast)
+ RValue<SByte8> Insert(RValue<SByte8> val, RValue<SByte> element, int i)
{
- Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
-
- storeValue(integer);
+ return RValue<SByte8>(Nucleus::createInsertElement(val.value, element.value, i));
}
- Byte::Byte(int x)
+ RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
{
- storeValue(Nucleus::createConstantByte((unsigned char)x));
- }
+ if(emulateIntrinsics)
+ {
+ SByte8 result;
+ result = Insert(result, Extract(lhs, 0) >> SByte(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> SByte(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> SByte(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> SByte(rhs), 3);
+ result = Insert(result, Extract(lhs, 4) >> SByte(rhs), 4);
+ result = Insert(result, Extract(lhs, 5) >> SByte(rhs), 5);
+ result = Insert(result, Extract(lhs, 6) >> SByte(rhs), 6);
+ result = Insert(result, Extract(lhs, 7) >> SByte(rhs), 7);
- Byte::Byte(unsigned char x)
- {
- storeValue(Nucleus::createConstantByte(x));
+ return result;
+ }
+ else
+ {
+ #if defined(__i386__) || defined(__x86_64__)
+ // SSE2 doesn't support byte vector shifts, so shift as shorts and recombine.
+ RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00u);
+ RValue<Short4> lo = As<Short4>(As<UShort4>((As<Short4>(lhs) << 8) >> rhs) >> 8);
+
+ return As<SByte8>(hi | lo);
+ #else
+ return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ #endif
+ }
}
- Byte::Byte(RValue<Byte> rhs)
+ RValue<Int> SignMask(RValue<Byte8> x)
{
- storeValue(rhs.value);
+ if(emulateIntrinsics || CPUID::ARM)
+ {
+ Byte8 xx = As<Byte8>(As<SByte8>(x) >> 7) & Byte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80);
+ return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7));
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
+ movmsk->addArg(x.value);
+ ::basicBlock->appendInst(movmsk);
+
+ return RValue<Int>(V(result)) & 0xFF;
+ }
}
- Byte::Byte(const Byte &rhs)
+// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
+// {
+// return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value));
+// }
+
+ RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
}
- Byte::Byte(const Reference<Byte> &rhs)
+ Type *Byte8::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(Type_v8i8);
}
- RValue<Byte> Byte::operator=(RValue<Byte> rhs)
- {
- storeValue(rhs.value);
+// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
+// {
+// return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+// }
- return rhs;
- }
+// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
+// {
+// return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
+// }
- RValue<Byte> Byte::operator=(const Byte &rhs)
+ RValue<SByte> SaturateSigned(RValue<Short> x)
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte>(value);
+ return SByte(IfThenElse(Int(x) > 0x7F, Int(0x7F), IfThenElse(Int(x) < -0x80, Int(0x80), Int(x))));
}
- RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
+ RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ if(emulateIntrinsics)
+ {
+ SByte8 result;
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7);
- return RValue<Byte>(value);
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ paddsb->addArg(x.value);
+ paddsb->addArg(y.value);
+ ::basicBlock->appendInst(paddsb);
- RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
+ return RValue<SByte8>(V(result));
+ }
}
- RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
{
- return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
- }
+ if(emulateIntrinsics)
+ {
+ SByte8 result;
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6);
+ result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7);
- RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ psubsb->addArg(x.value);
+ psubsb->addArg(y.value);
+ ::basicBlock->appendInst(psubsb);
- RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
+ return RValue<SByte8>(V(result));
+ }
}
- RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Int> SignMask(RValue<SByte8> x)
{
- return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
- }
+ if(emulateIntrinsics || CPUID::ARM)
+ {
+ SByte8 xx = (x >> 7) & SByte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80);
+ return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7));
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
+ movmsk->addArg(x.value);
+ ::basicBlock->appendInst(movmsk);
- RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
+ return RValue<Int>(V(result)) & 0xFF;
+ }
}
- RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
{
- return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
+ return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
}
- RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
{
- return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
+ return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
}
- RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
+ Type *SByte8::getType()
{
- return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
+ return T(Type_v8i8);
}
- RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
+ Type *Byte16::getType()
{
- return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
+ return T(Ice::IceType_v16i8);
}
- RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
+ Type *SByte16::getType()
{
- return lhs = lhs + rhs;
+ return T(Ice::IceType_v16i8);
}
- RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
+ Type *Short2::getType()
{
- return lhs = lhs - rhs;
+ return T(Type_v2i16);
}
- RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
+ Type *UShort2::getType()
{
- return lhs = lhs * rhs;
+ return T(Type_v2i16);
}
- RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
+ Short4::Short4(RValue<Int4> cast)
{
- return lhs = lhs / rhs;
- }
-
- RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs << rhs;
- }
+ int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
+ Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
+ Value *packed = Nucleus::createShuffleVector(short8, short8, select);
- RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
- {
- return lhs = lhs >> rhs;
- }
+ Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value;
+ Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
- RValue<Byte> operator+(RValue<Byte> val)
- {
- return val;
+ storeValue(short4);
}
- RValue<Byte> operator-(RValue<Byte> val)
- {
- return RValue<Byte>(Nucleus::createNeg(val.value));
- }
+// Short4::Short4(RValue<Float> cast)
+// {
+// }
- RValue<Byte> operator~(RValue<Byte> val)
+ Short4::Short4(RValue<Float4> cast)
{
- return RValue<Byte>(Nucleus::createNot(val.value));
+ assert(false && "UNIMPLEMENTED");
}
- RValue<Byte> operator++(Byte &val, int) // Post-increment
+ RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
{
- RValue<Byte> res = val;
- val += Byte(1);
- return res;
- }
+ if(emulateIntrinsics)
+ {
+ Short4 result;
+ result = Insert(result, Extract(lhs, 0) << Short(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << Short(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) << Short(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) << Short(rhs), 3);
- const Byte &operator++(Byte &val) // Pre-increment
- {
- val += Byte(1);
- return val;
+ return result;
+ }
+ else
+ {
+ return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<Byte> operator--(Byte &val, int) // Post-decrement
+ RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
{
- RValue<Byte> res = val;
- val -= Byte(1);
- return res;
- }
+ if(emulateIntrinsics)
+ {
+ Short4 result;
+ result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3);
- const Byte &operator--(Byte &val) // Pre-decrement
- {
- val -= Byte(1);
- return val;
+ return result;
+ }
+ else
+ {
+ return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
- }
+ Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
+ ::basicBlock->appendInst(cmp);
- RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ ::basicBlock->appendInst(select);
- RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ return RValue<Short4>(V(result));
}
- RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
+ RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
- }
+ Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
+ ::basicBlock->appendInst(cmp);
- RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ ::basicBlock->appendInst(select);
- RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ return RValue<Short4>(V(result));
}
- Type *Byte::getType()
+ RValue<Short> SaturateSigned(RValue<Int> x)
{
- return T(Ice::IceType_i8);
+ return Short(IfThenElse(x > 0x7FFF, Int(0x7FFF), IfThenElse(x < -0x8000, Int(0x8000), x)));
}
- SByte::SByte(Argument<SByte> argument)
+ RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
{
- storeValue(argument.value);
- }
+ if(emulateIntrinsics)
+ {
+ Short4 result;
+ result = Insert(result, SaturateSigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0);
+ result = Insert(result, SaturateSigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1);
+ result = Insert(result, SaturateSigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2);
+ result = Insert(result, SaturateSigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3);
- SByte::SByte(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ paddsw->addArg(x.value);
+ paddsw->addArg(y.value);
+ ::basicBlock->appendInst(paddsw);
- storeValue(integer);
+ return RValue<Short4>(V(result));
+ }
}
- SByte::SByte(RValue<Short> cast)
+ RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
{
- Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
+ if(emulateIntrinsics)
+ {
+ Short4 result;
+ result = Insert(result, SaturateSigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0);
+ result = Insert(result, SaturateSigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1);
+ result = Insert(result, SaturateSigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2);
+ result = Insert(result, SaturateSigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3);
- storeValue(integer);
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ psubsw->addArg(x.value);
+ psubsw->addArg(y.value);
+ ::basicBlock->appendInst(psubsw);
- SByte::SByte(signed char x)
- {
- storeValue(Nucleus::createConstantByte(x));
+ return RValue<Short4>(V(result));
+ }
}
- SByte::SByte(RValue<SByte> rhs)
+ RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
{
- storeValue(rhs.value);
- }
+ if(emulateIntrinsics)
+ {
+ Short4 result;
+ result = Insert(result, Short((Int(Extract(x, 0)) * Int(Extract(y, 0))) >> 16), 0);
+ result = Insert(result, Short((Int(Extract(x, 1)) * Int(Extract(y, 1))) >> 16), 1);
+ result = Insert(result, Short((Int(Extract(x, 2)) * Int(Extract(y, 2))) >> 16), 2);
+ result = Insert(result, Short((Int(Extract(x, 3)) * Int(Extract(y, 3))) >> 16), 3);
- SByte::SByte(const SByte &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pmulhw->addArg(x.value);
+ pmulhw->addArg(y.value);
+ ::basicBlock->appendInst(pmulhw);
- SByte::SByte(const Reference<SByte> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
+ return RValue<Short4>(V(result));
+ }
}
- RValue<SByte> SByte::operator=(RValue<SByte> rhs)
+ RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
{
- storeValue(rhs.value);
-
- return rhs;
- }
+ if(emulateIntrinsics)
+ {
+ Int2 result;
+ result = Insert(result, Int(Extract(x, 0)) * Int(Extract(y, 0)) + Int(Extract(x, 1)) * Int(Extract(y, 1)), 0);
+ result = Insert(result, Int(Extract(x, 2)) * Int(Extract(y, 2)) + Int(Extract(x, 3)) * Int(Extract(y, 3)), 1);
- RValue<SByte> SByte::operator=(const SByte &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pmaddwd->addArg(x.value);
+ pmaddwd->addArg(y.value);
+ ::basicBlock->appendInst(pmaddwd);
- return RValue<SByte>(value);
+ return As<Int2>(V(result));
+ }
}
- RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
+ RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<SByte>(value);
- }
+ if(emulateIntrinsics)
+ {
+ SByte8 result;
+ result = Insert(result, SaturateSigned(Extract(x, 0)), 0);
+ result = Insert(result, SaturateSigned(Extract(x, 1)), 1);
+ result = Insert(result, SaturateSigned(Extract(x, 2)), 2);
+ result = Insert(result, SaturateSigned(Extract(x, 3)), 3);
+ result = Insert(result, SaturateSigned(Extract(y, 0)), 4);
+ result = Insert(result, SaturateSigned(Extract(y, 1)), 5);
+ result = Insert(result, SaturateSigned(Extract(y, 2)), 6);
+ result = Insert(result, SaturateSigned(Extract(y, 3)), 7);
- RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pack->addArg(x.value);
+ pack->addArg(y.value);
+ ::basicBlock->appendInst(pack);
- RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
+ return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
+ }
}
- RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
- }
+ if(emulateIntrinsics)
+ {
+ Byte8 result;
+ result = Insert(result, SaturateUnsigned(Extract(x, 0)), 0);
+ result = Insert(result, SaturateUnsigned(Extract(x, 1)), 1);
+ result = Insert(result, SaturateUnsigned(Extract(x, 2)), 2);
+ result = Insert(result, SaturateUnsigned(Extract(x, 3)), 3);
+ result = Insert(result, SaturateUnsigned(Extract(y, 0)), 4);
+ result = Insert(result, SaturateUnsigned(Extract(y, 1)), 5);
+ result = Insert(result, SaturateUnsigned(Extract(y, 2)), 6);
+ result = Insert(result, SaturateUnsigned(Extract(y, 3)), 7);
- RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pack->addArg(x.value);
+ pack->addArg(y.value);
+ ::basicBlock->appendInst(pack);
- RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
+ return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
+ }
}
- RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
+ return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
}
- RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
{
- return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
+ return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value));
}
- RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
+ Type *Short4::getType()
{
- return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
+ return T(Type_v4i16);
}
- RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
+ UShort4::UShort4(RValue<Float4> cast, bool saturate)
{
- return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<SByte> operator+(RValue<SByte> val)
- {
- return val;
+ if(saturate)
+ {
+ if(CPUID::SSE4_1)
+ {
+ // x86 produces 0x80000000 on 32-bit integer overflow/underflow.
+ // PackUnsigned takes care of 0x0000 saturation.
+ Int4 int4(Min(cast, Float4(0xFFFF)));
+ *this = As<UShort4>(PackUnsigned(int4, int4));
+ }
+ else if(CPUID::ARM)
+ {
+ // ARM saturates the 32-bit integer result on overflow/undeflow.
+ Int4 int4(cast);
+ *this = As<UShort4>(PackUnsigned(int4, int4));
+ }
+ else
+ {
+ *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
+ }
+ }
+ else
+ {
+ *this = Short4(Int4(cast));
+ }
}
- RValue<SByte> operator-(RValue<SByte> val)
+ RValue<UShort> Extract(RValue<UShort4> val, int i)
{
- return RValue<SByte>(Nucleus::createNeg(val.value));
+ return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i));
}
- RValue<SByte> operator~(RValue<SByte> val)
+ RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i)
{
- return RValue<SByte>(Nucleus::createNot(val.value));
+ return RValue<UShort4>(Nucleus::createInsertElement(val.value, element.value, i));
}
- RValue<SByte> operator++(SByte &val, int) // Post-increment
+ RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
{
- RValue<SByte> res = val;
- val += SByte(1);
- return res;
- }
+ if(emulateIntrinsics)
+ {
+ UShort4 result;
+ result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3);
- const SByte &operator++(SByte &val) // Pre-increment
- {
- val += SByte(1);
- return val;
+ return result;
+ }
+ else
+ {
+ return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<SByte> operator--(SByte &val, int) // Post-decrement
+ RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
{
- RValue<SByte> res = val;
- val -= SByte(1);
- return res;
- }
+ if(emulateIntrinsics)
+ {
+ UShort4 result;
+ result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3);
- const SByte &operator--(SByte &val) // Pre-decrement
- {
- val -= SByte(1);
- return val;
+ return result;
+ }
+ else
+ {
+ return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
{
- return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
- }
+ Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
+ ::basicBlock->appendInst(cmp);
- RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ ::basicBlock->appendInst(select);
- RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ return RValue<UShort4>(V(result));
}
- RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
+ RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
{
- return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
- }
+ Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
+ ::basicBlock->appendInst(cmp);
- RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ ::basicBlock->appendInst(select);
- RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ return RValue<UShort4>(V(result));
}
- Type *SByte::getType()
+ RValue<UShort> SaturateUnsigned(RValue<Int> x)
{
- return T(Ice::IceType_i8);
+ return UShort(IfThenElse(x > 0xFFFF, Int(0xFFFF), IfThenElse(x < 0, Int(0), x)));
}
- Short::Short(Argument<Short> argument)
+ RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
{
- storeValue(argument.value);
- }
+ if(emulateIntrinsics)
+ {
+ UShort4 result;
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0);
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1);
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2);
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3);
- Short::Short(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ paddusw->addArg(x.value);
+ paddusw->addArg(y.value);
+ ::basicBlock->appendInst(paddusw);
- storeValue(integer);
+ return RValue<UShort4>(V(result));
+ }
}
- Short::Short(short x)
+ RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
{
- storeValue(Nucleus::createConstantShort(x));
- }
+ if(emulateIntrinsics)
+ {
+ UShort4 result;
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0);
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1);
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2);
+ result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3);
- Short::Short(RValue<Short> rhs)
- {
- storeValue(rhs.value);
- }
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ psubusw->addArg(x.value);
+ psubusw->addArg(y.value);
+ ::basicBlock->appendInst(psubusw);
- Short::Short(const Short &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
+ return RValue<UShort4>(V(result));
+ }
}
- Short::Short(const Reference<Short> &rhs)
+ RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
- }
+ if(emulateIntrinsics)
+ {
+ UShort4 result;
+ result = Insert(result, UShort((UInt(Extract(x, 0)) * UInt(Extract(y, 0))) >> 16), 0);
+ result = Insert(result, UShort((UInt(Extract(x, 1)) * UInt(Extract(y, 1))) >> 16), 1);
+ result = Insert(result, UShort((UInt(Extract(x, 2)) * UInt(Extract(y, 2))) >> 16), 2);
+ result = Insert(result, UShort((UInt(Extract(x, 3)) * UInt(Extract(y, 3))) >> 16), 3);
- RValue<Short> Short::operator=(RValue<Short> rhs)
- {
- storeValue(rhs.value);
+ return result;
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pmulhuw->addArg(x.value);
+ pmulhuw->addArg(y.value);
+ ::basicBlock->appendInst(pmulhuw);
- return rhs;
+ return RValue<UShort4>(V(result));
+ }
}
- RValue<Short> Short::operator=(const Short &rhs)
+ RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y)
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short>(value);
- }
+ // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
- RValue<Short> Short::operator=(const Reference<Short> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
+ // Scalarized implementation.
+ Int4 result;
+ result = Insert(result, Int((Long(Extract(x, 0)) * Long(Extract(y, 0))) >> Long(Int(32))), 0);
+ result = Insert(result, Int((Long(Extract(x, 1)) * Long(Extract(y, 1))) >> Long(Int(32))), 1);
+ result = Insert(result, Int((Long(Extract(x, 2)) * Long(Extract(y, 2))) >> Long(Int(32))), 2);
+ result = Insert(result, Int((Long(Extract(x, 3)) * Long(Extract(y, 3))) >> Long(Int(32))), 3);
- return RValue<Short>(value);
+ return result;
}
- RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
+ RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
- }
+ // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
- RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
- }
+ if(false) // Partial product based implementation.
+ {
+ auto xh = x >> 16;
+ auto yh = y >> 16;
+ auto xl = x & UInt4(0x0000FFFF);
+ auto yl = y & UInt4(0x0000FFFF);
+ auto xlyh = xl * yh;
+ auto xhyl = xh * yl;
+ auto xlyhh = xlyh >> 16;
+ auto xhylh = xhyl >> 16;
+ auto xlyhl = xlyh & UInt4(0x0000FFFF);
+ auto xhyll = xhyl & UInt4(0x0000FFFF);
+ auto xlylh = (xl * yl) >> 16;
+ auto oflow = (xlyhl + xhyll + xlylh) >> 16;
- RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
- }
+ return (xh * yh) + (xlyhh + xhylh) + oflow;
+ }
- RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
+ // Scalarized implementation.
+ Int4 result;
+ result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 0))) * Long(UInt(Extract(As<Int4>(y), 0)))) >> Long(Int(32))), 0);
+ result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 1))) * Long(UInt(Extract(As<Int4>(y), 1)))) >> Long(Int(32))), 1);
+ result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 2))) * Long(UInt(Extract(As<Int4>(y), 2)))) >> Long(Int(32))), 2);
+ result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 3))) * Long(UInt(Extract(As<Int4>(y), 3)))) >> Long(Int(32))), 3);
- RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
+ return As<UInt4>(result);
}
- RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
+ RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
{
- return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
+ assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
}
- RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
+ Type *UShort4::getType()
{
- return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
+ return T(Type_v4i16);
}
- RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
+ RValue<Short> Extract(RValue<Short8> val, int i)
{
- return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
+ return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
}
- RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
+ RValue<Short8> Insert(RValue<Short8> val, RValue<Short> element, int i)
{
- return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
+ return RValue<Short8>(Nucleus::createInsertElement(val.value, element.value, i));
}
- RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<Short> operator+(RValue<Short> val)
- {
- return val;
- }
-
- RValue<Short> operator-(RValue<Short> val)
- {
- return RValue<Short>(Nucleus::createNeg(val.value));
- }
-
- RValue<Short> operator~(RValue<Short> val)
- {
- return RValue<Short>(Nucleus::createNot(val.value));
- }
-
- RValue<Short> operator++(Short &val, int) // Post-increment
- {
- RValue<Short> res = val;
- val += Short(1);
- return res;
- }
-
- const Short &operator++(Short &val) // Pre-increment
- {
- val += Short(1);
- return val;
- }
-
- RValue<Short> operator--(Short &val, int) // Post-decrement
- {
- RValue<Short> res = val;
- val -= Short(1);
- return res;
- }
-
- const Short &operator--(Short &val) // Pre-decrement
- {
- val -= Short(1);
- return val;
- }
-
- RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- Type *Short::getType()
- {
- return T(Ice::IceType_i16);
- }
-
- UShort::UShort(Argument<UShort> argument)
- {
- storeValue(argument.value);
- }
-
- UShort::UShort(RValue<UInt> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
-
- storeValue(integer);
- }
-
- UShort::UShort(RValue<Int> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
-
- storeValue(integer);
- }
-
- UShort::UShort(unsigned short x)
- {
- storeValue(Nucleus::createConstantShort(x));
- }
-
- UShort::UShort(RValue<UShort> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort::UShort(const UShort &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort::UShort(const Reference<UShort> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UShort> UShort::operator=(RValue<UShort> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UShort> UShort::operator=(const UShort &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort>(value);
- }
-
- RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort>(value);
- }
-
- RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
- }
-
- RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<UShort> operator+(RValue<UShort> val)
- {
- return val;
- }
-
- RValue<UShort> operator-(RValue<UShort> val)
- {
- return RValue<UShort>(Nucleus::createNeg(val.value));
- }
-
- RValue<UShort> operator~(RValue<UShort> val)
- {
- return RValue<UShort>(Nucleus::createNot(val.value));
- }
-
- RValue<UShort> operator++(UShort &val, int) // Post-increment
- {
- RValue<UShort> res = val;
- val += UShort(1);
- return res;
- }
-
- const UShort &operator++(UShort &val) // Pre-increment
- {
- val += UShort(1);
- return val;
- }
-
- RValue<UShort> operator--(UShort &val, int) // Post-decrement
- {
- RValue<UShort> res = val;
- val -= UShort(1);
- return res;
- }
-
- const UShort &operator--(UShort &val) // Pre-decrement
- {
- val -= UShort(1);
- return val;
- }
-
- RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- Type *UShort::getType()
- {
- return T(Ice::IceType_i16);
- }
-
- Byte4::Byte4(RValue<Byte8> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Byte4::Byte4(const Reference<Byte4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Type *Byte4::getType()
- {
- return T(Type_v4i8);
- }
-
- Type *SByte4::getType()
- {
- return T(Type_v4i8);
- }
-
- Byte8::Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
- {
- int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Byte8::Byte8(RValue<Byte8> rhs)
- {
- storeValue(rhs.value);
- }
-
- Byte8::Byte8(const Byte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Byte8::Byte8(const Reference<Byte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte8>(value);
- }
-
- RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte8>(value);
- }
-
- RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
-// {
-// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
-// {
-// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
-// }
-
-// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
-// {
-// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
-// }
-
- RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
- {
- return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
-// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
-// {
-// return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
-// }
-
-// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
-// {
-// return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
-// }
-
- RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
-// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs << rhs;
-// }
-
-// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
-// {
-// return lhs = lhs >> rhs;
-// }
-
-// RValue<Byte8> operator+(RValue<Byte8> val)
-// {
-// return val;
-// }
-
-// RValue<Byte8> operator-(RValue<Byte8> val)
-// {
-// return RValue<Byte8>(Nucleus::createNeg(val.value));
-// }
-
- RValue<Byte8> operator~(RValue<Byte8> val)
- {
- return RValue<Byte8>(Nucleus::createNot(val.value));
- }
-
- RValue<Byte> Extract(RValue<Byte8> val, int i)
- {
- return RValue<Byte>(Nucleus::createExtractElement(val.value, Byte::getType(), i));
- }
-
- RValue<Byte8> Insert(RValue<Byte8> val, RValue<Byte> element, int i)
- {
- return RValue<Byte8>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<Byte> SaturateUnsigned(RValue<Short> x)
- {
- return Byte(IfThenElse(Int(x) > 0xFF, Int(0xFF), IfThenElse(Int(x) < 0, Int(0), Int(x))));
- }
-
- RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
- {
- if(emulateIntrinsics)
- {
- Byte8 result;
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- paddusb->addArg(x.value);
- paddusb->addArg(y.value);
- ::basicBlock->appendInst(paddusb);
-
- return RValue<Byte8>(V(result));
- }
- }
-
- RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
- {
- if(emulateIntrinsics)
- {
- Byte8 result;
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6);
- result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- psubusw->addArg(x.value);
- psubusw->addArg(y.value);
- ::basicBlock->appendInst(psubusw);
-
- return RValue<Byte8>(V(result));
- }
- }
-
- RValue<Short4> Unpack(RValue<Byte4> x)
- {
- int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
- return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
- }
-
- RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
- {
- return UnpackLow(As<Byte8>(x), As<Byte8>(y));
- }
-
- RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
- }
-
- RValue<SByte> Extract(RValue<SByte8> val, int i)
- {
- return RValue<SByte>(Nucleus::createExtractElement(val.value, SByte::getType(), i));
- }
-
- RValue<SByte8> Insert(RValue<SByte8> val, RValue<SByte> element, int i)
- {
- return RValue<SByte8>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- SByte8 result;
- result = Insert(result, Extract(lhs, 0) >> SByte(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> SByte(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> SByte(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> SByte(rhs), 3);
- result = Insert(result, Extract(lhs, 4) >> SByte(rhs), 4);
- result = Insert(result, Extract(lhs, 5) >> SByte(rhs), 5);
- result = Insert(result, Extract(lhs, 6) >> SByte(rhs), 6);
- result = Insert(result, Extract(lhs, 7) >> SByte(rhs), 7);
-
- return result;
- }
- else
- {
- #if defined(__i386__) || defined(__x86_64__)
- // SSE2 doesn't support byte vector shifts, so shift as shorts and recombine.
- RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00u);
- RValue<Short4> lo = As<Short4>(As<UShort4>((As<Short4>(lhs) << 8) >> rhs) >> 8);
-
- return As<SByte8>(hi | lo);
- #else
- return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
- #endif
- }
- }
-
- RValue<Int> SignMask(RValue<Byte8> x)
- {
- if(emulateIntrinsics || CPUID::ARM)
- {
- Byte8 xx = As<Byte8>(As<SByte8>(x) >> 7) & Byte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80);
- return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7));
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
- movmsk->addArg(x.value);
- ::basicBlock->appendInst(movmsk);
-
- return RValue<Int>(V(result)) & 0xFF;
- }
- }
-
-// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
-// {
-// return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value));
-// }
-
- RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
- {
- return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
- }
-
- Type *Byte8::getType()
- {
- return T(Type_v8i8);
- }
-
- SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
- {
- int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
- Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
-
- storeValue(Nucleus::createBitCast(vector, getType()));
- }
-
- SByte8::SByte8(RValue<SByte8> rhs)
- {
- storeValue(rhs.value);
- }
-
- SByte8::SByte8(const SByte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- SByte8::SByte8(const Reference<SByte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<SByte8>(value);
- }
-
- RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<SByte8>(value);
- }
-
- RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
-// {
-// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
-// {
-// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
-// }
-
-// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
-// {
-// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
-// }
-
- RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
- {
- return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
-// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
-// {
-// return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
-// }
-
-// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
-// {
-// return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
-// }
-
- RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
-// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs << rhs;
-// }
-
-// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
-// {
-// return lhs = lhs >> rhs;
-// }
-
-// RValue<SByte8> operator+(RValue<SByte8> val)
-// {
-// return val;
-// }
-
-// RValue<SByte8> operator-(RValue<SByte8> val)
-// {
-// return RValue<SByte8>(Nucleus::createNeg(val.value));
-// }
-
- RValue<SByte8> operator~(RValue<SByte8> val)
- {
- return RValue<SByte8>(Nucleus::createNot(val.value));
- }
-
- RValue<SByte> SaturateSigned(RValue<Short> x)
- {
- return SByte(IfThenElse(Int(x) > 0x7F, Int(0x7F), IfThenElse(Int(x) < -0x80, Int(0x80), Int(x))));
- }
-
- RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
- {
- if(emulateIntrinsics)
- {
- SByte8 result;
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- paddsb->addArg(x.value);
- paddsb->addArg(y.value);
- ::basicBlock->appendInst(paddsb);
-
- return RValue<SByte8>(V(result));
- }
- }
-
- RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
- {
- if(emulateIntrinsics)
- {
- SByte8 result;
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6);
- result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- psubsb->addArg(x.value);
- psubsb->addArg(y.value);
- ::basicBlock->appendInst(psubsb);
-
- return RValue<SByte8>(V(result));
- }
- }
-
- RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
- {
- int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
- auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
- }
-
- RValue<Int> SignMask(RValue<SByte8> x)
- {
- if(emulateIntrinsics || CPUID::ARM)
- {
- SByte8 xx = (x >> 7) & SByte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80);
- return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7));
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
- movmsk->addArg(x.value);
- ::basicBlock->appendInst(movmsk);
-
- return RValue<Int>(V(result)) & 0xFF;
- }
- }
-
- RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
- {
- return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
- }
-
- RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
- {
- return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
- }
-
- Type *SByte8::getType()
- {
- return T(Type_v8i8);
- }
-
- Byte16::Byte16(RValue<Byte16> rhs)
- {
- storeValue(rhs.value);
- }
-
- Byte16::Byte16(const Byte16 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Byte16::Byte16(const Reference<Byte16> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte16>(value);
- }
-
- RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Byte16>(value);
- }
-
- Type *Byte16::getType()
- {
- return T(Ice::IceType_v16i8);
- }
-
- Type *SByte16::getType()
- {
- return T(Ice::IceType_v16i8);
- }
-
- Short2::Short2(RValue<Short4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Type *Short2::getType()
- {
- return T(Type_v2i16);
- }
-
- UShort2::UShort2(RValue<UShort4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Type *UShort2::getType()
- {
- return T(Type_v2i16);
- }
-
- Short4::Short4(RValue<Int> cast)
- {
- Value *vector = loadValue();
- Value *element = Nucleus::createTrunc(cast.value, Short::getType());
- Value *insert = Nucleus::createInsertElement(vector, element, 0);
- Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
-
- storeValue(swizzle);
- }
-
- Short4::Short4(RValue<Int4> cast)
- {
- int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
- Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
- Value *packed = Nucleus::createShuffleVector(short8, short8, select);
-
- Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value;
- Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
-
- storeValue(short4);
- }
-
-// Short4::Short4(RValue<Float> cast)
-// {
-// }
-
- Short4::Short4(RValue<Float4> cast)
- {
- assert(false && "UNIMPLEMENTED");
- }
-
- Short4::Short4(short xyzw)
- {
- int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short4::Short4(short x, short y, short z, short w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short4::Short4(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short4::Short4(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short4::Short4(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short4::Short4(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short4::Short4(const UShort4 &rhs)
- {
- storeValue(rhs.loadValue());
- }
-
- Short4::Short4(const Reference<UShort4> &rhs)
- {
- storeValue(rhs.loadValue());
- }
-
- RValue<Short4> Short4::operator=(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Short4> Short4::operator=(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<Short4>(rhs);
- }
-
- RValue<Short4> Short4::operator=(const UShort4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Short4>(value);
- }
-
- RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
-// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
-// {
-// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
-// }
-
-// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
-// {
-// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
-// }
-
- RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
- {
- return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Short4 result;
- result = Insert(result, Extract(lhs, 0) << Short(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << Short(rhs), 1);
- result = Insert(result, Extract(lhs, 2) << Short(rhs), 2);
- result = Insert(result, Extract(lhs, 3) << Short(rhs), 3);
-
- return result;
- }
- else
- {
- return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Short4 result;
- result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3);
-
- return result;
- }
- else
- {
- return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs * rhs;
- }
-
-// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
-// RValue<Short4> operator+(RValue<Short4> val)
-// {
-// return val;
-// }
-
- RValue<Short4> operator-(RValue<Short4> val)
- {
- return RValue<Short4>(Nucleus::createNeg(val.value));
- }
-
- RValue<Short4> operator~(RValue<Short4> val)
- {
- return RValue<Short4>(Nucleus::createNot(val.value));
- }
-
- RValue<Short4> RoundShort4(RValue<Float4> cast)
- {
- RValue<Int4> int4 = RoundInt(cast);
- return As<Short4>(PackSigned(int4, int4));
- }
-
- RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
- {
- Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
- ::basicBlock->appendInst(cmp);
-
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
- ::basicBlock->appendInst(select);
-
- return RValue<Short4>(V(result));
- }
-
- RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
- {
- Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
- ::basicBlock->appendInst(cmp);
-
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
- ::basicBlock->appendInst(select);
-
- return RValue<Short4>(V(result));
- }
-
- RValue<Short> SaturateSigned(RValue<Int> x)
- {
- return Short(IfThenElse(x > 0x7FFF, Int(0x7FFF), IfThenElse(x < -0x8000, Int(0x8000), x)));
- }
-
- RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
- {
- if(emulateIntrinsics)
- {
- Short4 result;
- result = Insert(result, SaturateSigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0);
- result = Insert(result, SaturateSigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1);
- result = Insert(result, SaturateSigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2);
- result = Insert(result, SaturateSigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- paddsw->addArg(x.value);
- paddsw->addArg(y.value);
- ::basicBlock->appendInst(paddsw);
-
- return RValue<Short4>(V(result));
- }
- }
-
- RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
- {
- if(emulateIntrinsics)
- {
- Short4 result;
- result = Insert(result, SaturateSigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0);
- result = Insert(result, SaturateSigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1);
- result = Insert(result, SaturateSigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2);
- result = Insert(result, SaturateSigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- psubsw->addArg(x.value);
- psubsw->addArg(y.value);
- ::basicBlock->appendInst(psubsw);
-
- return RValue<Short4>(V(result));
- }
- }
-
- RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
- {
- if(emulateIntrinsics)
- {
- Short4 result;
- result = Insert(result, Short((Int(Extract(x, 0)) * Int(Extract(y, 0))) >> 16), 0);
- result = Insert(result, Short((Int(Extract(x, 1)) * Int(Extract(y, 1))) >> 16), 1);
- result = Insert(result, Short((Int(Extract(x, 2)) * Int(Extract(y, 2))) >> 16), 2);
- result = Insert(result, Short((Int(Extract(x, 3)) * Int(Extract(y, 3))) >> 16), 3);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pmulhw->addArg(x.value);
- pmulhw->addArg(y.value);
- ::basicBlock->appendInst(pmulhw);
-
- return RValue<Short4>(V(result));
- }
- }
-
- RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
- {
- if(emulateIntrinsics)
- {
- Int2 result;
- result = Insert(result, Int(Extract(x, 0)) * Int(Extract(y, 0)) + Int(Extract(x, 1)) * Int(Extract(y, 1)), 0);
- result = Insert(result, Int(Extract(x, 2)) * Int(Extract(y, 2)) + Int(Extract(x, 3)) * Int(Extract(y, 3)), 1);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pmaddwd->addArg(x.value);
- pmaddwd->addArg(y.value);
- ::basicBlock->appendInst(pmaddwd);
-
- return As<Int2>(V(result));
- }
- }
-
- RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y)
- {
- if(emulateIntrinsics)
- {
- SByte8 result;
- result = Insert(result, SaturateSigned(Extract(x, 0)), 0);
- result = Insert(result, SaturateSigned(Extract(x, 1)), 1);
- result = Insert(result, SaturateSigned(Extract(x, 2)), 2);
- result = Insert(result, SaturateSigned(Extract(x, 3)), 3);
- result = Insert(result, SaturateSigned(Extract(y, 0)), 4);
- result = Insert(result, SaturateSigned(Extract(y, 1)), 5);
- result = Insert(result, SaturateSigned(Extract(y, 2)), 6);
- result = Insert(result, SaturateSigned(Extract(y, 3)), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pack->addArg(x.value);
- pack->addArg(y.value);
- ::basicBlock->appendInst(pack);
-
- return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
- }
- }
-
- RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y)
- {
- if(emulateIntrinsics)
- {
- Byte8 result;
- result = Insert(result, SaturateUnsigned(Extract(x, 0)), 0);
- result = Insert(result, SaturateUnsigned(Extract(x, 1)), 1);
- result = Insert(result, SaturateUnsigned(Extract(x, 2)), 2);
- result = Insert(result, SaturateUnsigned(Extract(x, 3)), 3);
- result = Insert(result, SaturateUnsigned(Extract(y, 0)), 4);
- result = Insert(result, SaturateUnsigned(Extract(y, 1)), 5);
- result = Insert(result, SaturateUnsigned(Extract(y, 2)), 6);
- result = Insert(result, SaturateUnsigned(Extract(y, 3)), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pack->addArg(x.value);
- pack->addArg(y.value);
- ::basicBlock->appendInst(pack);
-
- return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
- }
- }
-
- RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
- {
- int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
- return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
- {
- int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
- auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
- }
-
- RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
- {
- // Real type is v8i16
- int shuffle[8] =
- {
- (select >> 0) & 0x03,
- (select >> 2) & 0x03,
- (select >> 4) & 0x03,
- (select >> 6) & 0x03,
- (select >> 0) & 0x03,
- (select >> 2) & 0x03,
- (select >> 4) & 0x03,
- (select >> 6) & 0x03,
- };
-
- return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
- }
-
- RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
- {
- return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<Short> Extract(RValue<Short4> val, int i)
- {
- return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
- }
-
- RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
- {
- return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
- }
-
- RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
- {
- return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value));
- }
-
- Type *Short4::getType()
- {
- return T(Type_v4i16);
- }
-
- UShort4::UShort4(RValue<Int4> cast)
- {
- *this = Short4(cast);
- }
-
- UShort4::UShort4(RValue<Float4> cast, bool saturate)
- {
- if(saturate)
- {
- if(CPUID::SSE4_1)
- {
- // x86 produces 0x80000000 on 32-bit integer overflow/underflow.
- // PackUnsigned takes care of 0x0000 saturation.
- Int4 int4(Min(cast, Float4(0xFFFF)));
- *this = As<UShort4>(PackUnsigned(int4, int4));
- }
- else if(CPUID::ARM)
- {
- // ARM saturates the 32-bit integer result on overflow/undeflow.
- Int4 int4(cast);
- *this = As<UShort4>(PackUnsigned(int4, int4));
- }
- else
- {
- *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
- }
- }
- else
- {
- *this = Short4(Int4(cast));
- }
- }
-
- UShort4::UShort4(unsigned short xyzw)
- {
- int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort4::UShort4(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort4::UShort4(const UShort4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort4::UShort4(const Reference<UShort4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort4::UShort4(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort4::UShort4(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort4::UShort4(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<UShort4>(rhs);
- }
-
- RValue<UShort4> UShort4::operator=(const Short4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort4>(value);
- }
-
- RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
- {
- return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UShort> Extract(RValue<UShort4> val, int i)
- {
- return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i));
- }
-
- RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i)
- {
- return RValue<UShort4>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- UShort4 result;
- result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1);
- result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2);
- result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3);
-
- return result;
- }
- else
- {
- return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- UShort4 result;
- result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3);
-
- return result;
- }
- else
- {
- return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<UShort4> operator~(RValue<UShort4> val)
- {
- return RValue<UShort4>(Nucleus::createNot(val.value));
- }
-
- RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
- {
- Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
- ::basicBlock->appendInst(cmp);
-
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
- ::basicBlock->appendInst(select);
-
- return RValue<UShort4>(V(result));
- }
-
- RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
- {
- Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
- ::basicBlock->appendInst(cmp);
-
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
- ::basicBlock->appendInst(select);
-
- return RValue<UShort4>(V(result));
- }
-
- RValue<UShort> SaturateUnsigned(RValue<Int> x)
- {
- return UShort(IfThenElse(x > 0xFFFF, Int(0xFFFF), IfThenElse(x < 0, Int(0), x)));
- }
-
- RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
- {
- if(emulateIntrinsics)
- {
- UShort4 result;
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0);
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1);
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2);
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- paddusw->addArg(x.value);
- paddusw->addArg(y.value);
- ::basicBlock->appendInst(paddusw);
-
- return RValue<UShort4>(V(result));
- }
- }
-
- RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
- {
- if(emulateIntrinsics)
- {
- UShort4 result;
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0);
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1);
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2);
- result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- psubusw->addArg(x.value);
- psubusw->addArg(y.value);
- ::basicBlock->appendInst(psubusw);
-
- return RValue<UShort4>(V(result));
- }
- }
-
- RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
- {
- if(emulateIntrinsics)
- {
- UShort4 result;
- result = Insert(result, UShort((UInt(Extract(x, 0)) * UInt(Extract(y, 0))) >> 16), 0);
- result = Insert(result, UShort((UInt(Extract(x, 1)) * UInt(Extract(y, 1))) >> 16), 1);
- result = Insert(result, UShort((UInt(Extract(x, 2)) * UInt(Extract(y, 2))) >> 16), 2);
- result = Insert(result, UShort((UInt(Extract(x, 3)) * UInt(Extract(y, 3))) >> 16), 3);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pmulhuw->addArg(x.value);
- pmulhuw->addArg(y.value);
- ::basicBlock->appendInst(pmulhuw);
-
- return RValue<UShort4>(V(result));
- }
- }
-
- RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y)
- {
- // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
-
- // Scalarized implementation.
- Int4 result;
- result = Insert(result, Int((Long(Extract(x, 0)) * Long(Extract(y, 0))) >> Long(Int(32))), 0);
- result = Insert(result, Int((Long(Extract(x, 1)) * Long(Extract(y, 1))) >> Long(Int(32))), 1);
- result = Insert(result, Int((Long(Extract(x, 2)) * Long(Extract(y, 2))) >> Long(Int(32))), 2);
- result = Insert(result, Int((Long(Extract(x, 3)) * Long(Extract(y, 3))) >> Long(Int(32))), 3);
-
- return result;
- }
-
- RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y)
- {
- // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq.
-
- if(false) // Partial product based implementation.
- {
- auto xh = x >> 16;
- auto yh = y >> 16;
- auto xl = x & UInt4(0x0000FFFF);
- auto yl = y & UInt4(0x0000FFFF);
- auto xlyh = xl * yh;
- auto xhyl = xh * yl;
- auto xlyhh = xlyh >> 16;
- auto xhylh = xhyl >> 16;
- auto xlyhl = xlyh & UInt4(0x0000FFFF);
- auto xhyll = xhyl & UInt4(0x0000FFFF);
- auto xlylh = (xl * yl) >> 16;
- auto oflow = (xlyhl + xhyll + xlylh) >> 16;
-
- return (xh * yh) + (xlyhh + xhylh) + oflow;
- }
-
- // Scalarized implementation.
- Int4 result;
- result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 0))) * Long(UInt(Extract(As<Int4>(y), 0)))) >> Long(Int(32))), 0);
- result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 1))) * Long(UInt(Extract(As<Int4>(y), 1)))) >> Long(Int(32))), 1);
- result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 2))) * Long(UInt(Extract(As<Int4>(y), 2)))) >> Long(Int(32))), 2);
- result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 3))) * Long(UInt(Extract(As<Int4>(y), 3)))) >> Long(Int(32))), 3);
-
- return As<UInt4>(result);
- }
-
- RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
- {
- assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
- }
-
- Type *UShort4::getType()
- {
- return T(Type_v4i16);
- }
-
- Short8::Short8(short c)
- {
- int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
- {
- int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Short8::Short8(RValue<Short8> rhs)
- {
- storeValue(rhs.value);
- }
-
- Short8::Short8(const Reference<Short8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
- {
- int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
- {
- return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
- {
- return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Short> Extract(RValue<Short8> val, int i)
- {
- return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
- }
-
- RValue<Short8> Insert(RValue<Short8> val, RValue<Short> element, int i)
- {
- return RValue<Short8>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Short8 result;
- result = Insert(result, Extract(lhs, 0) << Short(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << Short(rhs), 1);
- result = Insert(result, Extract(lhs, 2) << Short(rhs), 2);
- result = Insert(result, Extract(lhs, 3) << Short(rhs), 3);
- result = Insert(result, Extract(lhs, 4) << Short(rhs), 4);
- result = Insert(result, Extract(lhs, 5) << Short(rhs), 5);
- result = Insert(result, Extract(lhs, 6) << Short(rhs), 6);
- result = Insert(result, Extract(lhs, 7) << Short(rhs), 7);
-
- return result;
- }
- else
- {
- return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Short8 result;
- result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3);
- result = Insert(result, Extract(lhs, 4) >> Short(rhs), 4);
- result = Insert(result, Extract(lhs, 5) >> Short(rhs), 5);
- result = Insert(result, Extract(lhs, 6) >> Short(rhs), 6);
- result = Insert(result, Extract(lhs, 7) >> Short(rhs), 7);
-
- return result;
- }
- else
- {
- return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
- {
- assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
- }
-
- RValue<Int4> Abs(RValue<Int4> x)
- {
- auto negative = x >> 31;
- return (x ^ negative) - negative;
- }
-
- RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
- {
- assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
- }
-
- Type *Short8::getType()
- {
- return T(Ice::IceType_v8i16);
- }
-
- UShort8::UShort8(unsigned short c)
- {
- int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort8::UShort8(unsigned short c0, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short c4, unsigned short c5, unsigned short c6, unsigned short c7)
- {
- int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UShort8::UShort8(RValue<UShort8> rhs)
- {
- storeValue(rhs.value);
- }
-
- UShort8::UShort8(const Reference<UShort8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
- {
- int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort8>(value);
- }
-
- RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UShort8>(value);
- }
-
- RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
- {
- return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UShort> Extract(RValue<UShort8> val, int i)
- {
- return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i));
- }
-
- RValue<UShort8> Insert(RValue<UShort8> val, RValue<UShort> element, int i)
- {
- return RValue<UShort8>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- UShort8 result;
- result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1);
- result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2);
- result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3);
- result = Insert(result, Extract(lhs, 4) << UShort(rhs), 4);
- result = Insert(result, Extract(lhs, 5) << UShort(rhs), 5);
- result = Insert(result, Extract(lhs, 6) << UShort(rhs), 6);
- result = Insert(result, Extract(lhs, 7) << UShort(rhs), 7);
-
- return result;
- }
- else
- {
- return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- UShort8 result;
- result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3);
- result = Insert(result, Extract(lhs, 4) >> UShort(rhs), 4);
- result = Insert(result, Extract(lhs, 5) >> UShort(rhs), 5);
- result = Insert(result, Extract(lhs, 6) >> UShort(rhs), 6);
- result = Insert(result, Extract(lhs, 7) >> UShort(rhs), 7);
-
- return result;
- }
- else
- {
- return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
- {
- return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
- {
- return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UShort8> operator~(RValue<UShort8> val)
- {
- return RValue<UShort8>(Nucleus::createNot(val.value));
- }
-
- RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
- {
- assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
- }
-
- RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
- {
- assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
- }
-
- // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
-// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
-// {
-// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
-// }
-
- Type *UShort8::getType()
- {
- return T(Ice::IceType_v8i16);
- }
-
- Int::Int(Argument<Int> argument)
- {
- storeValue(argument.value);
- }
-
- Int::Int(RValue<Byte> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<SByte> cast)
- {
- Value *integer = Nucleus::createSExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<Short> cast)
- {
- Value *integer = Nucleus::createSExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<UShort> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<Int2> cast)
- {
- *this = Extract(cast, 0);
- }
-
- Int::Int(RValue<Long> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(RValue<Float> cast)
- {
- Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
-
- storeValue(integer);
- }
-
- Int::Int(int x)
- {
- storeValue(Nucleus::createConstantInt(x));
- }
-
- Int::Int(RValue<Int> rhs)
- {
- storeValue(rhs.value);
- }
-
- Int::Int(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
- }
-
- Int::Int(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int::Int(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int::Int(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int::Int(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<Int> Int::operator=(int rhs)
- {
- return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
- }
-
- RValue<Int> Int::operator=(RValue<Int> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Int> Int::operator=(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<Int>(rhs);
- }
-
- RValue<Int> Int::operator=(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> Int::operator=(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> Int::operator=(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> Int::operator=(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int>(value);
- }
-
- RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
-
- RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
- }
-
- RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<Int> operator+(RValue<Int> val)
- {
- return val;
- }
-
- RValue<Int> operator-(RValue<Int> val)
- {
- return RValue<Int>(Nucleus::createNeg(val.value));
- }
-
- RValue<Int> operator~(RValue<Int> val)
- {
- return RValue<Int>(Nucleus::createNot(val.value));
- }
-
- RValue<Int> operator++(Int &val, int) // Post-increment
- {
- RValue<Int> res = val;
- val += 1;
- return res;
- }
-
- const Int &operator++(Int &val) // Pre-increment
- {
- val += 1;
- return val;
- }
-
- RValue<Int> operator--(Int &val, int) // Post-decrement
- {
- RValue<Int> res = val;
- val -= 1;
- return res;
- }
-
- const Int &operator--(Int &val) // Pre-decrement
- {
- val -= 1;
- return val;
- }
-
- RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
- RValue<Int> Max(RValue<Int> x, RValue<Int> y)
- {
- return IfThenElse(x > y, x, y);
- }
-
- RValue<Int> Min(RValue<Int> x, RValue<Int> y)
- {
- return IfThenElse(x < y, x, y);
- }
-
- RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
- {
- return Min(Max(x, min), max);
- }
-
- RValue<Int> RoundInt(RValue<Float> cast)
- {
- if(emulateIntrinsics || CPUID::ARM)
- {
- // Push the fractional part off the mantissa. Accurate up to +/-2^22.
- return Int((cast + Float(0x00C00000)) - Float(0x00C00000));
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
- nearbyint->addArg(cast.value);
- ::basicBlock->appendInst(nearbyint);
-
- return RValue<Int>(V(result));
- }
- }
-
- Type *Int::getType()
- {
- return T(Ice::IceType_i32);
- }
-
- Long::Long(RValue<Int> cast)
- {
- Value *integer = Nucleus::createSExt(cast.value, Long::getType());
-
- storeValue(integer);
- }
-
- Long::Long(RValue<UInt> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, Long::getType());
-
- storeValue(integer);
- }
-
- Long::Long(RValue<Long> rhs)
- {
- storeValue(rhs.value);
- }
-
- RValue<Long> Long::operator=(int64_t rhs)
- {
- return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
- }
-
- RValue<Long> Long::operator=(RValue<Long> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Long> Long::operator=(const Long &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Long>(value);
- }
-
- RValue<Long> Long::operator=(const Reference<Long> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Long>(value);
- }
-
- RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs)
- {
- return RValue<Long>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
- {
- return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
- }
-
- Type *Long::getType()
- {
- return T(Ice::IceType_i64);
- }
-
- UInt::UInt(Argument<UInt> argument)
- {
- storeValue(argument.value);
- }
-
- UInt::UInt(RValue<UShort> cast)
- {
- Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
-
- storeValue(integer);
- }
-
- UInt::UInt(RValue<Long> cast)
- {
- Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
-
- storeValue(integer);
- }
-
- UInt::UInt(RValue<Float> cast)
- {
- // Smallest positive value representable in UInt, but not in Int
- const unsigned int ustart = 0x80000000u;
- const float ustartf = float(ustart);
-
- // If the value is negative, store 0, otherwise store the result of the conversion
- storeValue((~(As<Int>(cast) >> 31) &
- // Check if the value can be represented as an Int
- IfThenElse(cast >= ustartf,
- // If the value is too large, subtract ustart and re-add it after conversion.
- As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
- // Otherwise, just convert normally
- Int(cast))).value);
- }
-
- UInt::UInt(int x)
- {
- storeValue(Nucleus::createConstantInt(x));
- }
-
- UInt::UInt(unsigned int x)
- {
- storeValue(Nucleus::createConstantInt(x));
- }
-
- UInt::UInt(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
- }
-
- UInt::UInt(RValue<Int> rhs)
- {
- storeValue(rhs.value);
- }
-
- UInt::UInt(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt::UInt(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt::UInt(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt::UInt(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UInt> UInt::operator=(unsigned int rhs)
- {
- return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
- }
-
- RValue<UInt> UInt::operator=(RValue<UInt> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UInt> UInt::operator=(RValue<Int> rhs)
- {
- storeValue(rhs.value);
-
- return RValue<UInt>(rhs);
- }
-
- RValue<UInt> UInt::operator=(const UInt &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> UInt::operator=(const Int &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt>(value);
- }
-
- RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
- }
-
- RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<UInt> operator+(RValue<UInt> val)
- {
- return val;
- }
-
- RValue<UInt> operator-(RValue<UInt> val)
- {
- return RValue<UInt>(Nucleus::createNeg(val.value));
- }
-
- RValue<UInt> operator~(RValue<UInt> val)
- {
- return RValue<UInt>(Nucleus::createNot(val.value));
- }
-
- RValue<UInt> operator++(UInt &val, int) // Post-increment
- {
- RValue<UInt> res = val;
- val += 1;
- return res;
- }
-
- const UInt &operator++(UInt &val) // Pre-increment
- {
- val += 1;
- return val;
- }
-
- RValue<UInt> operator--(UInt &val, int) // Post-decrement
- {
- RValue<UInt> res = val;
- val -= 1;
- return res;
- }
-
- const UInt &operator--(UInt &val) // Pre-decrement
- {
- val -= 1;
- return val;
- }
-
- RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
- {
- return IfThenElse(x > y, x, y);
- }
-
- RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
- {
- return IfThenElse(x < y, x, y);
- }
-
- RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
- {
- return Min(Max(x, min), max);
- }
-
- RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
- }
-
- RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
- {
- return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
- }
-
-// RValue<UInt> RoundUInt(RValue<Float> cast)
-// {
-// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
-// }
-
- Type *UInt::getType()
- {
- return T(Ice::IceType_i32);
- }
-
-// Int2::Int2(RValue<Int> cast)
-// {
-// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
-// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
-//
-// Constant *shuffle[2];
-// shuffle[0] = Nucleus::createConstantInt(0);
-// shuffle[1] = Nucleus::createConstantInt(0);
-//
-// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
-//
-// storeValue(replicate);
-// }
-
- Int2::Int2(RValue<Int4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
- Int2::Int2(int x, int y)
- {
- int64_t constantVector[2] = {x, y};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Int2::Int2(RValue<Int2> rhs)
- {
- storeValue(rhs.value);
- }
-
- Int2::Int2(const Int2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int2::Int2(const Reference<Int2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int2::Int2(RValue<Int> lo, RValue<Int> hi)
- {
- int shuffle[4] = {0, 4, 1, 5};
- Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
-
- storeValue(Nucleus::createBitCast(packed, Int2::getType()));
- }
-
- RValue<Int2> Int2::operator=(RValue<Int2> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Int2> Int2::operator=(const Int2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int2>(value);
- }
-
- RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int2>(value);
- }
-
- RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
-// {
-// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
-// {
-// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
-// }
-
-// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
-// {
-// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
-// }
-
- RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
- {
- return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Int2 result;
- result = Insert(result, Extract(lhs, 0) << Int(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << Int(rhs), 1);
-
- return result;
- }
- else
- {
- return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Int2 result;
- result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1);
-
- return result;
- }
- else
- {
- return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
-// RValue<Int2> operator+(RValue<Int2> val)
-// {
-// return val;
-// }
-
-// RValue<Int2> operator-(RValue<Int2> val)
-// {
-// return RValue<Int2>(Nucleus::createNeg(val.value));
-// }
-
- RValue<Int2> operator~(RValue<Int2> val)
- {
- return RValue<Int2>(Nucleus::createNot(val.value));
- }
-
- RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
- {
- int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
- return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
- {
- int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
- auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- return As<Short4>(Swizzle(lowHigh, 0xEE));
- }
-
- RValue<Int> Extract(RValue<Int2> val, int i)
- {
- return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
- }
-
- RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
- {
- return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- Type *Int2::getType()
- {
- return T(Type_v2i32);
- }
-
- UInt2::UInt2(unsigned int x, unsigned int y)
- {
- int64_t constantVector[2] = {x, y};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- UInt2::UInt2(RValue<UInt2> rhs)
- {
- storeValue(rhs.value);
- }
-
- UInt2::UInt2(const UInt2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- UInt2::UInt2(const Reference<UInt2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt2>(value);
- }
-
- RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt2>(value);
- }
-
- RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
-// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
-// {
-// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
-// }
-
-// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
-// {
-// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
-// }
-
-// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
-// {
-// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
-// }
-
- RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
- {
- return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<UInt> Extract(RValue<UInt2> val, int i)
- {
- return RValue<UInt>(Nucleus::createExtractElement(val.value, UInt::getType(), i));
- }
-
- RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i)
- {
- return RValue<UInt2>(Nucleus::createInsertElement(val.value, element.value, i));
- }
-
- RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- UInt2 result;
- result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1);
-
- return result;
- }
- else
- {
- return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- UInt2 result;
- result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1);
-
- return result;
- }
- else
- {
- return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs - rhs;
- }
-
-// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
-// {
-// return lhs = lhs * rhs;
-// }
-
-// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
-// RValue<UInt2> operator+(RValue<UInt2> val)
-// {
-// return val;
-// }
-
-// RValue<UInt2> operator-(RValue<UInt2> val)
-// {
-// return RValue<UInt2>(Nucleus::createNeg(val.value));
-// }
-
- RValue<UInt2> operator~(RValue<UInt2> val)
- {
- return RValue<UInt2>(Nucleus::createNot(val.value));
- }
-
- Type *UInt2::getType()
- {
- return T(Type_v2i32);
- }
-
- Int4::Int4() : XYZW(this)
- {
- }
-
- Int4::Int4(RValue<Byte4> cast) : XYZW(this)
- {
- Value *x = Nucleus::createBitCast(cast.value, Int::getType());
- Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
-
- Value *e;
- int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
- Value *b = Nucleus::createBitCast(a, Byte16::getType());
- Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
-
- int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
- Value *d = Nucleus::createBitCast(c, Short8::getType());
- e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
-
- Value *f = Nucleus::createBitCast(e, Int4::getType());
- storeValue(f);
- }
-
- Int4::Int4(RValue<SByte4> cast) : XYZW(this)
- {
- Value *x = Nucleus::createBitCast(cast.value, Int::getType());
- Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
-
- int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
- Value *b = Nucleus::createBitCast(a, Byte16::getType());
- Value *c = Nucleus::createShuffleVector(b, b, swizzle);
-
- int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
- Value *d = Nucleus::createBitCast(c, Short8::getType());
- Value *e = Nucleus::createShuffleVector(d, d, swizzle2);
-
- *this = As<Int4>(e) >> 24;
- }
-
- Int4::Int4(RValue<Float4> cast) : XYZW(this)
- {
- Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
-
- storeValue(xyzw);
- }
-
- Int4::Int4(RValue<Short4> cast) : XYZW(this)
- {
- int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
- Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
-
- *this = As<Int4>(c) >> 16;
- }
-
- Int4::Int4(RValue<UShort4> cast) : XYZW(this)
- {
- int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
- Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
- Value *d = Nucleus::createBitCast(c, Int4::getType());
- storeValue(d);
- }
-
- Int4::Int4(int xyzw) : XYZW(this)
- {
- constant(xyzw, xyzw, xyzw, xyzw);
- }
-
- Int4::Int4(int x, int yzw) : XYZW(this)
- {
- constant(x, yzw, yzw, yzw);
- }
-
- Int4::Int4(int x, int y, int zw) : XYZW(this)
- {
- constant(x, y, zw, zw);
- }
-
- Int4::Int4(int x, int y, int z, int w) : XYZW(this)
- {
- constant(x, y, z, w);
- }
-
- void Int4::constant(int x, int y, int z, int w)
- {
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Int4::Int4(RValue<Int4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- Int4::Int4(const Int4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(const Reference<Int4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(RValue<UInt4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- Int4::Int4(const UInt4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this)
- {
- int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
-
- storeValue(packed);
- }
-
- Int4::Int4(RValue<Int> rhs) : XYZW(this)
- {
- Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType());
-
- int swizzle[4] = {0, 0, 0, 0};
- Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
-
- storeValue(replicate);
- }
-
- Int4::Int4(const Int &rhs) : XYZW(this)
- {
- *this = RValue<Int>(rhs.loadValue());
- }
-
- Int4::Int4(const Reference<Int> &rhs) : XYZW(this)
- {
- *this = RValue<Int>(rhs.loadValue());
- }
-
- RValue<Int4> Int4::operator=(RValue<Int4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Int4> Int4::operator=(const Int4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int4>(value);
- }
-
- RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Int4>(value);
- }
-
- RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Int4 result;
- result = Insert(result, Extract(lhs, 0) << Int(rhs), 0);
- result = Insert(result, Extract(lhs, 1) << Int(rhs), 1);
- result = Insert(result, Extract(lhs, 2) << Int(rhs), 2);
- result = Insert(result, Extract(lhs, 3) << Int(rhs), 3);
-
- return result;
- }
- else
- {
- return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
- {
- if(emulateIntrinsics)
- {
- Int4 result;
- result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0);
- result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> Int(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> Int(rhs), 3);
-
- return result;
- }
- else
- {
- return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
- }
- }
-
- RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
- {
- return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
- }
-
- RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs * rhs;
- }
-
-// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
-
-// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
-
- RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs & rhs;
- }
-
- RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs | rhs;
- }
-
- RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
- {
- return lhs = lhs ^ rhs;
- }
-
- RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
- {
- return lhs = lhs << rhs;
- }
-
- RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
- {
- return lhs = lhs >> rhs;
- }
-
- RValue<Int4> operator+(RValue<Int4> val)
- {
- return val;
- }
-
- RValue<Int4> operator-(RValue<Int4> val)
- {
- return RValue<Int4>(Nucleus::createNeg(val.value));
- }
-
- RValue<Int4> operator~(RValue<Int4> val)
- {
- return RValue<Int4>(Nucleus::createNot(val.value));
- }
-
- RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
- {
- return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value));
- }
-
- RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
- {
- return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value));
- }
-
- RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
- {
- return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value));
- }
-
- RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
- {
- return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value));
- }
-
- RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
- {
- return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value));
- }
-
- RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
- {
- return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value));
- }
-
- RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
- {
- Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
- ::basicBlock->appendInst(cmp);
-
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
- ::basicBlock->appendInst(select);
-
- return RValue<Int4>(V(result));
- }
-
- RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
- {
- Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
- ::basicBlock->appendInst(cmp);
-
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
- ::basicBlock->appendInst(select);
-
- return RValue<Int4>(V(result));
- }
-
- RValue<Int4> RoundInt(RValue<Float4> cast)
- {
- if(emulateIntrinsics || CPUID::ARM)
- {
- // Push the fractional part off the mantissa. Accurate up to +/-2^22.
- return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000));
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
- nearbyint->addArg(cast.value);
- ::basicBlock->appendInst(nearbyint);
-
- return RValue<Int4>(V(result));
- }
- }
-
- RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y)
+ RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
{
if(emulateIntrinsics)
{
Short8 result;
- result = Insert(result, SaturateSigned(Extract(x, 0)), 0);
- result = Insert(result, SaturateSigned(Extract(x, 1)), 1);
- result = Insert(result, SaturateSigned(Extract(x, 2)), 2);
- result = Insert(result, SaturateSigned(Extract(x, 3)), 3);
- result = Insert(result, SaturateSigned(Extract(y, 0)), 4);
- result = Insert(result, SaturateSigned(Extract(y, 1)), 5);
- result = Insert(result, SaturateSigned(Extract(y, 2)), 6);
- result = Insert(result, SaturateSigned(Extract(y, 3)), 7);
-
- return result;
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pack->addArg(x.value);
- pack->addArg(y.value);
- ::basicBlock->appendInst(pack);
-
- return RValue<Short8>(V(result));
- }
- }
-
- RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y)
- {
- if(emulateIntrinsics || !(CPUID::SSE4_1 || CPUID::ARM))
- {
- RValue<Int4> sx = As<Int4>(x);
- RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000);
-
- RValue<Int4> sy = As<Int4>(y);
- RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000);
-
- return As<UShort8>(PackSigned(bx, by) + Short8(0x8000u));
- }
- else
- {
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
- pack->addArg(x.value);
- pack->addArg(y.value);
- ::basicBlock->appendInst(pack);
+ result = Insert(result, Extract(lhs, 0) << Short(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << Short(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) << Short(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) << Short(rhs), 3);
+ result = Insert(result, Extract(lhs, 4) << Short(rhs), 4);
+ result = Insert(result, Extract(lhs, 5) << Short(rhs), 5);
+ result = Insert(result, Extract(lhs, 6) << Short(rhs), 6);
+ result = Insert(result, Extract(lhs, 7) << Short(rhs), 7);
- return RValue<UShort8>(V(result));
+ return result;
+ }
+ else
+ {
+ return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
}
}
- RValue<Int> Extract(RValue<Int4> x, int i)
- {
- return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
- }
-
- RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
- {
- return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
- }
-
- RValue<Int> SignMask(RValue<Int4> x)
+ RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
{
- if(emulateIntrinsics || CPUID::ARM)
+ if(emulateIntrinsics)
{
- Int4 xx = (x >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008);
- return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3);
+ Short8 result;
+ result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3);
+ result = Insert(result, Extract(lhs, 4) >> Short(rhs), 4);
+ result = Insert(result, Extract(lhs, 5) >> Short(rhs), 5);
+ result = Insert(result, Extract(lhs, 6) >> Short(rhs), 6);
+ result = Insert(result, Extract(lhs, 7) >> Short(rhs), 7);
+
+ return result;
}
else
{
- Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
- const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
- auto target = ::context->getConstantUndef(Ice::IceType_i32);
- auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
- movmsk->addArg(x.value);
- ::basicBlock->appendInst(movmsk);
-
- return RValue<Int>(V(result));
+ return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
}
}
- RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
+ RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
{
- return RValue<Int4>(createSwizzle4(x.value, select));
+ assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
}
- Type *Int4::getType()
+ RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
{
- return T(Ice::IceType_v4i32);
+ assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
}
- UInt4::UInt4() : XYZW(this)
+ Type *Short8::getType()
{
+ return T(Ice::IceType_v8i16);
}
- UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
+ RValue<UShort> Extract(RValue<UShort8> val, int i)
{
- // Smallest positive value representable in UInt, but not in Int
- const unsigned int ustart = 0x80000000u;
- const float ustartf = float(ustart);
-
- // Check if the value can be represented as an Int
- Int4 uiValue = CmpNLT(cast, Float4(ustartf));
- // If the value is too large, subtract ustart and re-add it after conversion.
- uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
- // Otherwise, just convert normally
- (~uiValue & Int4(cast));
- // If the value is negative, store 0, otherwise store the result of the conversion
- storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
+ return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i));
}
- UInt4::UInt4(int xyzw) : XYZW(this)
+ RValue<UShort8> Insert(RValue<UShort8> val, RValue<UShort> element, int i)
{
- constant(xyzw, xyzw, xyzw, xyzw);
+ return RValue<UShort8>(Nucleus::createInsertElement(val.value, element.value, i));
}
- UInt4::UInt4(int x, int yzw) : XYZW(this)
+ RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
{
- constant(x, yzw, yzw, yzw);
- }
+ if(emulateIntrinsics)
+ {
+ UShort8 result;
+ result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3);
+ result = Insert(result, Extract(lhs, 4) << UShort(rhs), 4);
+ result = Insert(result, Extract(lhs, 5) << UShort(rhs), 5);
+ result = Insert(result, Extract(lhs, 6) << UShort(rhs), 6);
+ result = Insert(result, Extract(lhs, 7) << UShort(rhs), 7);
- UInt4::UInt4(int x, int y, int zw) : XYZW(this)
- {
- constant(x, y, zw, zw);
+ return result;
+ }
+ else
+ {
+ return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- UInt4::UInt4(int x, int y, int z, int w) : XYZW(this)
+ RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
{
- constant(x, y, z, w);
+ if(emulateIntrinsics)
+ {
+ UShort8 result;
+ result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3);
+ result = Insert(result, Extract(lhs, 4) >> UShort(rhs), 4);
+ result = Insert(result, Extract(lhs, 5) >> UShort(rhs), 5);
+ result = Insert(result, Extract(lhs, 6) >> UShort(rhs), 6);
+ result = Insert(result, Extract(lhs, 7) >> UShort(rhs), 7);
+
+ return result;
+ }
+ else
+ {
+ return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- void UInt4::constant(int x, int y, int z, int w)
+ RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
{
- int64_t constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
+ assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
}
- UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this)
+ RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
{
- storeValue(rhs.value);
+ assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
}
- UInt4::UInt4(const UInt4 &rhs) : XYZW(this)
+ // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
+// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
+// {
+// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
+// }
+
+ Type *UShort8::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ return T(Ice::IceType_v8i16);
}
- UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this)
+ RValue<Int> operator++(Int &val, int) // Post-increment
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ RValue<Int> res = val;
+ val += 1;
+ return res;
}
- UInt4::UInt4(RValue<Int4> rhs) : XYZW(this)
+ const Int &operator++(Int &val) // Pre-increment
{
- storeValue(rhs.value);
+ val += 1;
+ return val;
}
- UInt4::UInt4(const Int4 &rhs) : XYZW(this)
+ RValue<Int> operator--(Int &val, int) // Post-decrement
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ RValue<Int> res = val;
+ val -= 1;
+ return res;
}
- UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this)
+ const Int &operator--(Int &val) // Pre-decrement
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ val -= 1;
+ return val;
}
- UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this)
+ RValue<Int> RoundInt(RValue<Float> cast)
{
- int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
- Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
+ if(emulateIntrinsics || CPUID::ARM)
+ {
+ // Push the fractional part off the mantissa. Accurate up to +/-2^22.
+ return Int((cast + Float(0x00C00000)) - Float(0x00C00000));
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
+ nearbyint->addArg(cast.value);
+ ::basicBlock->appendInst(nearbyint);
- storeValue(packed);
+ return RValue<Int>(V(result));
+ }
}
- RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
+ Type *Int::getType()
{
- storeValue(rhs.value);
-
- return rhs;
+ return T(Ice::IceType_i32);
}
- RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
+ Type *Long::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<UInt4>(value);
+ return T(Ice::IceType_i64);
}
- RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
+ UInt::UInt(RValue<Float> cast)
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ // Smallest positive value representable in UInt, but not in Int
+ const unsigned int ustart = 0x80000000u;
+ const float ustartf = float(ustart);
- return RValue<UInt4>(value);
+ // If the value is negative, store 0, otherwise store the result of the conversion
+ storeValue((~(As<Int>(cast) >> 31) &
+ // Check if the value can be represented as an Int
+ IfThenElse(cast >= ustartf,
+ // If the value is too large, subtract ustart and re-add it after conversion.
+ As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
+ // Otherwise, just convert normally
+ Int(cast))).value);
}
- RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ RValue<UInt> operator++(UInt &val, int) // Post-increment
{
- return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
+ RValue<UInt> res = val;
+ val += 1;
+ return res;
}
- RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ const UInt &operator++(UInt &val) // Pre-increment
{
- return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
+ val += 1;
+ return val;
}
- RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ RValue<UInt> operator--(UInt &val, int) // Post-decrement
{
- return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
+ RValue<UInt> res = val;
+ val -= 1;
+ return res;
}
- RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ const UInt &operator--(UInt &val) // Pre-decrement
{
- return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
+ val -= 1;
+ return val;
}
- RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
+// RValue<UInt> RoundUInt(RValue<Float> cast)
+// {
+// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
+// }
+
+ Type *UInt::getType()
{
- return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
+ return T(Ice::IceType_i32);
}
- RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
+// Int2::Int2(RValue<Int> cast)
+// {
+// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
+// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
+//
+// Constant *shuffle[2];
+// shuffle[0] = Nucleus::createConstantInt(0);
+// shuffle[1] = Nucleus::createConstantInt(0);
+//
+// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
+//
+// storeValue(replicate);
+// }
+
+ RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
{
- return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
+ if(emulateIntrinsics)
+ {
+ Int2 result;
+ result = Insert(result, Extract(lhs, 0) << Int(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << Int(rhs), 1);
+
+ return result;
+ }
+ else
+ {
+ return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
{
- return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
+ if(emulateIntrinsics)
+ {
+ Int2 result;
+ result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1);
+
+ return result;
+ }
+ else
+ {
+ return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ Type *Int2::getType()
{
- return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
+ return T(Type_v2i32);
}
- RValue<UInt> Extract(RValue<UInt4> x, int i)
+ RValue<UInt> Extract(RValue<UInt2> val, int i)
{
- return RValue<UInt>(Nucleus::createExtractElement(x.value, UInt::getType(), i));
+ return RValue<UInt>(Nucleus::createExtractElement(val.value, UInt::getType(), i));
}
- RValue<UInt4> Insert(RValue<UInt4> x, RValue<UInt> element, int i)
+ RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i)
{
- return RValue<UInt4>(Nucleus::createInsertElement(x.value, element.value, i));
+ return RValue<UInt2>(Nucleus::createInsertElement(val.value, element.value, i));
}
- RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
+ RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
{
if(emulateIntrinsics)
{
- UInt4 result;
+ UInt2 result;
result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0);
result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1);
- result = Insert(result, Extract(lhs, 2) << UInt(rhs), 2);
- result = Insert(result, Extract(lhs, 3) << UInt(rhs), 3);
return result;
}
else
{
- return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
}
}
- RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
+ RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
{
if(emulateIntrinsics)
{
- UInt4 result;
+ UInt2 result;
result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0);
result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1);
- result = Insert(result, Extract(lhs, 2) >> UInt(rhs), 2);
- result = Insert(result, Extract(lhs, 3) >> UInt(rhs), 3);
return result;
}
else
{
- return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
}
}
- RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ Type *UInt2::getType()
{
- return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
+ return T(Type_v2i32);
}
- RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
+ Int4::Int4(RValue<Byte4> cast) : XYZW(this)
{
- return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
- }
+ Value *x = Nucleus::createBitCast(cast.value, Int::getType());
+ Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
- RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs + rhs;
- }
+ Value *e;
+ int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
+ Value *b = Nucleus::createBitCast(a, Byte16::getType());
+ Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
- RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs - rhs;
+ int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
+ Value *d = Nucleus::createBitCast(c, Short8::getType());
+ e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
+
+ Value *f = Nucleus::createBitCast(e, Int4::getType());
+ storeValue(f);
}
- RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
+ Int4::Int4(RValue<SByte4> cast) : XYZW(this)
{
- return lhs = lhs * rhs;
- }
+ Value *x = Nucleus::createBitCast(cast.value, Int::getType());
+ Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
-// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
-// {
-// return lhs = lhs / rhs;
-// }
+ int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
+ Value *b = Nucleus::createBitCast(a, Byte16::getType());
+ Value *c = Nucleus::createShuffleVector(b, b, swizzle);
-// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
-// {
-// return lhs = lhs % rhs;
-// }
+ int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
+ Value *d = Nucleus::createBitCast(c, Short8::getType());
+ Value *e = Nucleus::createShuffleVector(d, d, swizzle2);
- RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs & rhs;
+ *this = As<Int4>(e) >> 24;
}
- RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
+ Int4::Int4(RValue<Short4> cast) : XYZW(this)
{
- return lhs = lhs | rhs;
- }
+ int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
+ Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
- RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
- {
- return lhs = lhs ^ rhs;
+ *this = As<Int4>(c) >> 16;
}
- RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
+ Int4::Int4(RValue<UShort4> cast) : XYZW(this)
{
- return lhs = lhs << rhs;
+ int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
+ Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
+ Value *d = Nucleus::createBitCast(c, Int4::getType());
+ storeValue(d);
}
- RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
+ Int4::Int4(RValue<Int> rhs) : XYZW(this)
{
- return lhs = lhs >> rhs;
- }
+ Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType());
- RValue<UInt4> operator+(RValue<UInt4> val)
- {
- return val;
+ int swizzle[4] = {0, 0, 0, 0};
+ Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
+
+ storeValue(replicate);
}
- RValue<UInt4> operator-(RValue<UInt4> val)
+ RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
{
- return RValue<UInt4>(Nucleus::createNeg(val.value));
+ if(emulateIntrinsics)
+ {
+ Int4 result;
+ result = Insert(result, Extract(lhs, 0) << Int(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << Int(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) << Int(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) << Int(rhs), 3);
+
+ return result;
+ }
+ else
+ {
+ return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<UInt4> operator~(RValue<UInt4> val)
+ RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
{
- return RValue<UInt4>(Nucleus::createNot(val.value));
+ if(emulateIntrinsics)
+ {
+ Int4 result;
+ result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> Int(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> Int(rhs), 3);
+
+ return result;
+ }
+ else
+ {
+ return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value));
+ return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value));
}
- RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value));
+ return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value));
}
- RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value));
+ return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value));
}
- RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value));
+ return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value));
}
- RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value));
+ return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value));
}
- RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
{
- return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value));
+ return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value));
}
- RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
{
Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
::basicBlock->appendInst(cmp);
Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
::basicBlock->appendInst(select);
- return RValue<UInt4>(V(result));
+ return RValue<Int4>(V(result));
}
- RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
+ RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
{
Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
- auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
::basicBlock->appendInst(cmp);
Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
::basicBlock->appendInst(select);
- return RValue<UInt4>(V(result));
- }
-
- Type *UInt4::getType()
- {
- return T(Ice::IceType_v4i32);
+ return RValue<Int4>(V(result));
}
- Half::Half(RValue<Float> cast)
+ RValue<Int4> RoundInt(RValue<Float4> cast)
{
- UInt fp32i = As<UInt>(cast);
- UInt abs = fp32i & 0x7FFFFFFF;
- UShort fp16i((fp32i & 0x80000000) >> 16); // sign
-
- If(abs > 0x47FFEFFF) // Infinity
+ if(emulateIntrinsics || CPUID::ARM)
{
- fp16i |= UShort(0x7FFF);
+ // Push the fractional part off the mantissa. Accurate up to +/-2^22.
+ return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000));
}
- Else
+ else
{
- If(abs < 0x38800000) // Denormal
- {
- Int mantissa = (abs & 0x007FFFFF) | 0x00800000;
- Int e = 113 - (abs >> 23);
- abs = IfThenElse(e < 24, mantissa >> e, Int(0));
- fp16i |= UShort((abs + 0x00000FFF + ((abs >> 13) & 1)) >> 13);
- }
- Else
- {
- fp16i |= UShort((abs + 0xC8000000 + 0x00000FFF + ((abs >> 13) & 1)) >> 13);
- }
- }
-
- storeValue(fp16i.loadValue());
- }
-
- Type *Half::getType()
- {
- return T(Ice::IceType_i16);
- }
-
- Float::Float(RValue<Int> cast)
- {
- Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
-
- storeValue(integer);
- }
-
- Float::Float(RValue<UInt> cast)
- {
- RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) +
- As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u)));
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
+ nearbyint->addArg(cast.value);
+ ::basicBlock->appendInst(nearbyint);
- storeValue(result.value);
+ return RValue<Int4>(V(result));
+ }
}
- Float::Float(RValue<Half> cast)
+ RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y)
{
- Int fp16i(As<UShort>(cast));
-
- Int s = (fp16i >> 15) & 0x00000001;
- Int e = (fp16i >> 10) & 0x0000001F;
- Int m = fp16i & 0x000003FF;
-
- UInt fp32i(s << 31);
- If(e == 0)
+ if(emulateIntrinsics)
{
- If(m != 0)
- {
- While((m & 0x00000400) == 0)
- {
- m <<= 1;
- e -= 1;
- }
+ Short8 result;
+ result = Insert(result, SaturateSigned(Extract(x, 0)), 0);
+ result = Insert(result, SaturateSigned(Extract(x, 1)), 1);
+ result = Insert(result, SaturateSigned(Extract(x, 2)), 2);
+ result = Insert(result, SaturateSigned(Extract(x, 3)), 3);
+ result = Insert(result, SaturateSigned(Extract(y, 0)), 4);
+ result = Insert(result, SaturateSigned(Extract(y, 1)), 5);
+ result = Insert(result, SaturateSigned(Extract(y, 2)), 6);
+ result = Insert(result, SaturateSigned(Extract(y, 3)), 7);
- fp32i |= As<UInt>(((e + (127 - 15) + 1) << 23) | ((m & ~0x00000400) << 13));
- }
+ return result;
}
- Else
+ else
{
- fp32i |= As<UInt>(((e + (127 - 15)) << 23) | (m << 13));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pack->addArg(x.value);
+ pack->addArg(y.value);
+ ::basicBlock->appendInst(pack);
- storeValue(As<Float>(fp32i).value);
+ return RValue<Short8>(V(result));
+ }
}
- Float::Float(float x)
+ RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y)
{
- storeValue(Nucleus::createConstantFloat(x));
- }
+ if(emulateIntrinsics || !(CPUID::SSE4_1 || CPUID::ARM))
+ {
+ RValue<Int4> sx = As<Int4>(x);
+ RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000);
- Float::Float(RValue<Float> rhs)
- {
- storeValue(rhs.value);
- }
+ RValue<Int4> sy = As<Int4>(y);
+ RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000);
- Float::Float(const Float &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
+ return As<UShort8>(PackSigned(bx, by) + Short8(0x8000u));
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
+ pack->addArg(x.value);
+ pack->addArg(y.value);
+ ::basicBlock->appendInst(pack);
- Float::Float(const Reference<Float> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
+ return RValue<UShort8>(V(result));
+ }
}
- RValue<Float> Float::operator=(RValue<Float> rhs)
+ RValue<Int> SignMask(RValue<Int4> x)
{
- storeValue(rhs.value);
+ if(emulateIntrinsics || CPUID::ARM)
+ {
+ Int4 xx = (x >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008);
+ return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3);
+ }
+ else
+ {
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
+ const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
+ auto target = ::context->getConstantUndef(Ice::IceType_i32);
+ auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
+ movmsk->addArg(x.value);
+ ::basicBlock->appendInst(movmsk);
- return rhs;
+ return RValue<Int>(V(result));
+ }
}
- RValue<Float> Float::operator=(const Float &rhs)
+ Type *Int4::getType()
{
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float>(value);
+ return T(Ice::IceType_v4i32);
}
- RValue<Float> Float::operator=(const Reference<Float> &rhs)
+ UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
{
- Value *value = rhs.loadValue();
- storeValue(value);
+ // Smallest positive value representable in UInt, but not in Int
+ const unsigned int ustart = 0x80000000u;
+ const float ustartf = float(ustart);
- return RValue<Float>(value);
+ // Check if the value can be represented as an Int
+ Int4 uiValue = CmpNLT(cast, Float4(ustartf));
+ // If the value is too large, subtract ustart and re-add it after conversion.
+ uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
+ // Otherwise, just convert normally
+ (~uiValue & Int4(cast));
+ // If the value is negative, store 0, otherwise store the result of the conversion
+ storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
}
- RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt> Extract(RValue<UInt4> x, int i)
{
- return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
+ return RValue<UInt>(Nucleus::createExtractElement(x.value, UInt::getType(), i));
}
- RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> Insert(RValue<UInt4> x, RValue<UInt> element, int i)
{
- return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
+ return RValue<UInt4>(Nucleus::createInsertElement(x.value, element.value, i));
}
- RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
{
- return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
+ if(emulateIntrinsics)
+ {
+ UInt4 result;
+ result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) << UInt(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) << UInt(rhs), 3);
+
+ return result;
+ }
+ else
+ {
+ return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
{
- return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
- }
+ if(emulateIntrinsics)
+ {
+ UInt4 result;
+ result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0);
+ result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1);
+ result = Insert(result, Extract(lhs, 2) >> UInt(rhs), 2);
+ result = Insert(result, Extract(lhs, 3) >> UInt(rhs), 3);
- RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
- {
- return lhs = lhs + rhs;
+ return result;
+ }
+ else
+ {
+ return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
+ }
}
- RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
{
- return lhs = lhs - rhs;
+ return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value));
}
- RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
{
- return lhs = lhs * rhs;
+ return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value));
}
- RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
{
- return lhs = lhs / rhs;
+ return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value));
}
- RValue<Float> operator+(RValue<Float> val)
+ RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
{
- return val;
+ return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value));
}
- RValue<Float> operator-(RValue<Float> val)
+ RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Float>(Nucleus::createFNeg(val.value));
+ return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value));
}
- RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
+ return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value));
}
- RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
- }
+ Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
+ ::basicBlock->appendInst(cmp);
- RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
- {
- return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
+ auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ ::basicBlock->appendInst(select);
- RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
- {
- return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
+ return RValue<UInt4>(V(result));
}
- RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
+ RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
{
- return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
- }
+ Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
+ auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
+ ::basicBlock->appendInst(cmp);
- RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
- {
- return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
- }
+ Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
+ auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ ::basicBlock->appendInst(select);
- RValue<Float> Abs(RValue<Float> x)
- {
- return IfThenElse(x > 0.0f, x, -x);
+ return RValue<UInt4>(V(result));
}
- RValue<Float> Max(RValue<Float> x, RValue<Float> y)
+ Type *UInt4::getType()
{
- return IfThenElse(x > y, x, y);
+ return T(Ice::IceType_v4i32);
}
- RValue<Float> Min(RValue<Float> x, RValue<Float> y)
+ Type *Half::getType()
{
- return IfThenElse(x < y, x, y);
+ return T(Ice::IceType_i16);
}
RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
return T(Ice::IceType_f32);
}
- Float2::Float2(RValue<Float4> cast)
- {
- storeValue(Nucleus::createBitCast(cast.value, getType()));
- }
-
Type *Float2::getType()
{
return T(Type_v2f32);
}
- Float4::Float4(RValue<Byte4> cast) : XYZW(this)
- {
- Value *a = Int4(cast).loadValue();
- Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
-
- storeValue(xyzw);
- }
-
- Float4::Float4(RValue<SByte4> cast) : XYZW(this)
- {
- Value *a = Int4(cast).loadValue();
- Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
-
- storeValue(xyzw);
- }
-
- Float4::Float4(RValue<Short4> cast) : XYZW(this)
- {
- Int4 c(cast);
- storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
- }
-
- Float4::Float4(RValue<UShort4> cast) : XYZW(this)
- {
- Int4 c(cast);
- storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
- }
-
- Float4::Float4(RValue<Int4> cast) : XYZW(this)
- {
- Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
-
- storeValue(xyzw);
- }
-
- Float4::Float4(RValue<UInt4> cast) : XYZW(this)
- {
- RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
- As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
-
- storeValue(result.value);
- }
-
- Float4::Float4() : XYZW(this)
- {
- }
-
- Float4::Float4(float xyzw) : XYZW(this)
- {
- constant(xyzw, xyzw, xyzw, xyzw);
- }
-
- Float4::Float4(float x, float yzw) : XYZW(this)
- {
- constant(x, yzw, yzw, yzw);
- }
-
- Float4::Float4(float x, float y, float zw) : XYZW(this)
- {
- constant(x, y, zw, zw);
- }
-
- Float4::Float4(float x, float y, float z, float w) : XYZW(this)
- {
- constant(x, y, z, w);
- }
-
- void Float4::constant(float x, float y, float z, float w)
- {
- double constantVector[4] = {x, y, z, w};
- storeValue(Nucleus::createConstantVector(constantVector, getType()));
- }
-
- Float4::Float4(RValue<Float4> rhs) : XYZW(this)
- {
- storeValue(rhs.value);
- }
-
- Float4::Float4(const Float4 &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
- Float4::Float4(const Reference<Float4> &rhs) : XYZW(this)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
- }
-
Float4::Float4(RValue<Float> rhs) : XYZW(this)
{
Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType());
storeValue(replicate);
}
- Float4::Float4(const Float &rhs) : XYZW(this)
- {
- *this = RValue<Float>(rhs.loadValue());
- }
-
- Float4::Float4(const Reference<Float> &rhs) : XYZW(this)
- {
- *this = RValue<Float>(rhs.loadValue());
- }
-
- RValue<Float4> Float4::operator=(float x)
- {
- return *this = Float4(x, x, x, x);
- }
-
- RValue<Float4> Float4::operator=(RValue<Float4> rhs)
- {
- storeValue(rhs.value);
-
- return rhs;
- }
-
- RValue<Float4> Float4::operator=(const Float4 &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float4>(value);
- }
-
- RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
- {
- Value *value = rhs.loadValue();
- storeValue(value);
-
- return RValue<Float4>(value);
- }
-
- RValue<Float4> Float4::operator=(RValue<Float> rhs)
- {
- return *this = Float4(rhs);
- }
-
- RValue<Float4> Float4::operator=(const Float &rhs)
- {
- return *this = Float4(rhs);
- }
-
- RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
- {
- return *this = Float4(rhs);
- }
-
- RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
- {
- return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
- }
-
- RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs + rhs;
- }
-
- RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs - rhs;
- }
-
- RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs * rhs;
- }
-
- RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs / rhs;
- }
-
- RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
- {
- return lhs = lhs % rhs;
- }
-
- RValue<Float4> operator+(RValue<Float4> val)
- {
- return val;
- }
-
- RValue<Float4> operator-(RValue<Float4> val)
- {
- return RValue<Float4>(Nucleus::createFNeg(val.value));
- }
-
- RValue<Float4> Abs(RValue<Float4> x)
- {
- Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
- int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
- Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
-
- return As<Float4>(result);
- }
-
RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
{
Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
}
}
- RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
- {
- return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
- }
-
- RValue<Float> Extract(RValue<Float4> x, int i)
- {
- return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
- }
-
- RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
- {
- return RValue<Float4>(createSwizzle4(x.value, select));
- }
-
- RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
- {
- int shuffle[4] =
- {
- ((imm >> 0) & 0x03) + 0,
- ((imm >> 2) & 0x03) + 0,
- ((imm >> 4) & 0x03) + 4,
- ((imm >> 6) & 0x03) + 4,
- };
-
- return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
- {
- int shuffle[4] = {0, 4, 1, 5};
- return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
- {
- int shuffle[4] = {2, 6, 3, 7};
- return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
- }
-
- RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
- {
- Value *vector = lhs.loadValue();
- Value *result = createMask4(vector, rhs.value, select);
- lhs.storeValue(result);
-
- return RValue<Float4>(result);
- }
-
RValue<Int> SignMask(RValue<Float4> x)
{
if(emulateIntrinsics || CPUID::ARM)
return RValue<Int4>(Nucleus::createFCmpUGT(x.value, y.value));
}
- RValue<Int4> IsInf(RValue<Float4> x)
- {
- return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000));
- }
-
- RValue<Int4> IsNan(RValue<Float4> x)
- {
- return ~CmpEQ(x, x);
- }
-
RValue<Float4> Round(RValue<Float4> x)
{
if(emulateIntrinsics || CPUID::ARM)
return T(Ice::IceType_v4f32);
}
- RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
- {
- return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
- }
-
- RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
- {
- return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
- }
-
- RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
- {
- return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
- }
-
- RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
- {
- return lhs = lhs + offset;
- }
-
- RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
- {
- return lhs = lhs + offset;
- }
-
- RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
- {
- return lhs = lhs + offset;
- }
-
- RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
- {
- return lhs + -offset;
- }
-
- RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
- {
- return lhs + -offset;
- }
-
- RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
- {
- return lhs + -offset;
- }
-
- RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
- {
- return lhs = lhs - offset;
- }
-
- RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
- {
- return lhs = lhs - offset;
- }
-
- RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
- {
- return lhs = lhs - offset;
- }
-
- void Return()
- {
- Nucleus::createRetVoid();
- Nucleus::setInsertBlock(Nucleus::createBasicBlock());
- Nucleus::createUnreachable();
- }
-
- void Return(RValue<Int> ret)
- {
- Nucleus::createRet(ret.value);
- Nucleus::setInsertBlock(Nucleus::createBasicBlock());
- Nucleus::createUnreachable();
- }
-
- void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
- {
- Nucleus::createCondBr(cmp.value, bodyBB, endBB);
- Nucleus::setInsertBlock(bodyBB);
- }
-
RValue<Long> Ticks()
{
assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));