Add SwiftShader source to repo
Oct 6 code drop from Transgaming
Review URL: https://chromereviews.googleplex.com/3846015
diff --git a/src/Reactor/MemoryManager.cpp b/src/Reactor/MemoryManager.cpp
new file mode 100644
index 0000000..aaa85ae
--- /dev/null
+++ b/src/Reactor/MemoryManager.cpp
@@ -0,0 +1,126 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#include "MemoryManager.hpp"
+
+#include "Nucleus.hpp"
+
+namespace sw
+{
+ using namespace llvm;
+
+ MemoryManager::MemoryManager()
+ {
+ routine = 0;
+ }
+
+ MemoryManager::~MemoryManager()
+ {
+ delete routine;
+ }
+
+ void MemoryManager::AllocateGOT()
+ {
+ // FIXME: ASSERT(false);
+ }
+
+ unsigned char *MemoryManager::allocateStub(const GlobalValue *function, unsigned stubSize, unsigned alignment)
+ {
+ // FIXME: ASSERT(false);
+
+ return 0;
+ }
+
+ unsigned char *MemoryManager::startFunctionBody(const llvm::Function *function, uintptr_t &actualSize)
+ {
+ if(actualSize == 0)
+ {
+ actualSize = 4096;
+ }
+
+ actualSize = (actualSize + 15) & -16;
+
+ delete routine;
+ routine = new Routine(actualSize);
+
+ return (unsigned char*)routine->getBuffer();
+ }
+
+ void MemoryManager::endFunctionBody(const llvm::Function *function, unsigned char *functionStart, unsigned char *functionEnd)
+ {
+ routine->setFunctionSize(functionEnd - functionStart);
+ }
+
+ unsigned char *MemoryManager::startExceptionTable(const llvm::Function* F, uintptr_t &ActualSize)
+ {
+ // FIXME: ASSERT(false);
+
+ return 0;
+ }
+
+ void MemoryManager::endExceptionTable(const llvm::Function *F, unsigned char *TableStart, unsigned char *TableEnd, unsigned char* FrameRegister)
+ {
+ // FIXME: ASSERT(false);
+ }
+
+ unsigned char *MemoryManager::getGOTBase() const
+ {
+ return 0;
+ }
+
+ unsigned char *MemoryManager::allocateSpace(intptr_t Size, unsigned Alignment)
+ {
+ return 0;
+ }
+
+ unsigned char *MemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment)
+ {
+ return 0;
+ }
+
+ void MemoryManager::deallocateFunctionBody(void *Body)
+ {
+ }
+
+ void MemoryManager::deallocateExceptionTable(void *ET)
+ {
+ }
+
+ void MemoryManager::setMemoryWritable()
+ {
+ }
+
+ void MemoryManager::setMemoryExecutable()
+ {
+ }
+
+ void MemoryManager::setPoisonMemory(bool poison)
+ {
+ }
+
+ Routine *MemoryManager::acquireRoutine()
+ {
+ Routine *result = routine;
+
+ routine = 0;
+
+ return result;
+ }
+
+ void MemoryManager::SetDlsymTable(void *pointer)
+ {
+ }
+
+ void *MemoryManager::getDlsymTable() const
+ {
+ return 0;
+ }
+}
diff --git a/src/Reactor/MemoryManager.hpp b/src/Reactor/MemoryManager.hpp
new file mode 100644
index 0000000..b578f62
--- /dev/null
+++ b/src/Reactor/MemoryManager.hpp
@@ -0,0 +1,54 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#ifndef sw_MemoryManager_hpp
+#define sw_MemoryManager_hpp
+
+#include "llvm/GlobalValue.h"
+#include "llvm/ExecutionEngine/JITMemoryManager.h"
+
+namespace sw
+{
+ class Routine;
+
+ class MemoryManager : public llvm::JITMemoryManager
+ {
+ public:
+ MemoryManager();
+
+ ~MemoryManager();
+
+ void AllocateGOT();
+
+ unsigned char *allocateStub(const llvm::GlobalValue *function, unsigned stubSize, unsigned alignment);
+ unsigned char *startFunctionBody(const llvm::Function *function, uintptr_t &actualSize);
+ void endFunctionBody(const llvm::Function *function, unsigned char *functionStart, unsigned char *functionEnd);
+ unsigned char *startExceptionTable(const llvm::Function *function, uintptr_t &ActualSize);
+ void endExceptionTable(const llvm::Function *function, unsigned char *tableStart, unsigned char *tableEnd, unsigned char *frameRegister);
+ unsigned char *getGOTBase() const;
+ unsigned char *allocateSpace(intptr_t Size, unsigned Alignment);
+ unsigned char *allocateGlobal(uintptr_t Size, unsigned int Alignment);
+ void deallocateFunctionBody(void *Body);
+ void deallocateExceptionTable(void *ET);
+ void setMemoryWritable();
+ void setMemoryExecutable();
+ void setPoisonMemory(bool poison);
+ void SetDlsymTable(void *pointer);
+ void *getDlsymTable() const;
+
+ Routine *acquireRoutine();
+
+ private:
+ Routine *routine;
+ };
+}
+
+#endif // sw_MemoryManager_hpp
diff --git a/src/Reactor/Nucleus.cpp b/src/Reactor/Nucleus.cpp
new file mode 100644
index 0000000..3c793a1
--- /dev/null
+++ b/src/Reactor/Nucleus.cpp
@@ -0,0 +1,7063 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#include "Nucleus.hpp"
+
+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Function.h"
+#include "llvm/GlobalVariable.h"
+#include "llvm/Module.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/Constants.h"
+#include "llvm/Intrinsics.h"
+#include "llvm/Passmanager.h"
+#include "llvm/Instructions.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
+#include "llvm/Support/CFG.h"
+#include "../lib/ExecutionEngine/JIT/JIT.h"
+#include "llvm/ExecutionEngine/JIT.h"
+#include "llvm/CallingConv.h"
+
+#include "MemoryManager.hpp"
+#include "x86.hpp"
+#include "CPUID.hpp"
+#include "Thread.hpp"
+#include "Memory.hpp"
+
+#include <fstream>
+
+extern "C" void LLVMInitializeX86Target();
+extern "C" void LLVMInitializeX86TargetInfo();
+
+extern "C"
+{
+ bool (*CodeAnalystInitialize)() = 0;
+ void (*CodeAnalystCompleteJITLog)() = 0;
+ bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0;
+}
+
+namespace llvm
+{
+ extern bool JITEmitDebugInfo;
+}
+
+namespace sw
+{
+ Optimization optimization[10] = {InstructionCombining, Disabled};
+
+ using namespace llvm;
+
+ MemoryManager *Nucleus::memoryManager = 0;
+ ExecutionEngine *Nucleus::executionEngine = 0;
+ Builder *Nucleus::builder = 0;
+ LLVMContext *Nucleus::context = 0;
+ Module *Nucleus::module = 0;
+ llvm::Function *Nucleus::function = 0;
+
+ class Builder : public IRBuilder<>
+ {
+ };
+
+ Routine::Routine(int bufferSize) : bufferSize(bufferSize), dynamic(true)
+ {
+ void *memory = allocateExecutable(bufferSize);
+
+ buffer = memory;
+ entry = memory;
+ functionSize = bufferSize; // Updated by MemoryManager::endFunctionBody
+
+ bindCount = 0;
+ }
+
+ Routine::Routine(void *memory, int bufferSize, int offset) : bufferSize(bufferSize), functionSize(bufferSize), dynamic(false)
+ {
+ buffer = (unsigned char*)memory - offset;
+ entry = memory;
+
+ bindCount = 0;
+ }
+
+ Routine::~Routine()
+ {
+ if(dynamic)
+ {
+ deallocateExecutable(buffer, bufferSize);
+ }
+ }
+
+ void Routine::setFunctionSize(int functionSize)
+ {
+ this->functionSize = functionSize;
+ }
+
+ const void *Routine::getBuffer()
+ {
+ return buffer;
+ }
+
+ const void *Routine::getEntry()
+ {
+ return entry;
+ }
+
+ int Routine::getBufferSize()
+ {
+ return bufferSize;
+ }
+
+ int Routine::getFunctionSize()
+ {
+ return functionSize;
+ }
+
+ int Routine::getCodeSize()
+ {
+ return functionSize - ((uintptr_t)entry - (uintptr_t)buffer);
+ }
+
+ bool Routine::isDynamic()
+ {
+ return dynamic;
+ }
+
+ void Routine::bind()
+ {
+ atomicIncrement(&bindCount);
+ }
+
+ void Routine::unbind()
+ {
+ long count = atomicDecrement(&bindCount);
+
+ if(count == 0)
+ {
+ delete this;
+ }
+ }
+
+ Nucleus::Nucleus()
+ {
+ LLVMInitializeX86Target();
+ LLVMInitializeX86TargetInfo();
+ JITEmitDebugInfo = false;
+
+ if(!context)
+ {
+ context = new LLVMContext();
+ }
+
+ module = new Module("", *context);
+ memoryManager = new MemoryManager();
+
+ #if defined(__x86_64__)
+ const char *architecture = "x86-64";
+ #else
+ const char *architecture = "x86";
+ #endif
+
+ SmallVector<std::string, 1> MAttrs;
+ MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx");
+ MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov");
+ MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse");
+ MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2");
+ MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3");
+ MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3");
+ MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41");
+
+ executionEngine = JIT::createJIT(module, 0, memoryManager, CodeGenOpt::Aggressive, true, CodeModel::Default, architecture, "", MAttrs);
+
+ if(!builder)
+ {
+ builder = static_cast<Builder*>(new IRBuilder<>(*context));
+
+ HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll");
+ if(CodeAnalyst)
+ {
+ CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize");
+ CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog");
+ CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode");
+
+ CodeAnalystInitialize();
+ }
+ }
+ }
+
+ Nucleus::~Nucleus()
+ {
+ delete executionEngine;
+ executionEngine = 0;
+
+ memoryManager = 0;
+ function = 0;
+ module = 0;
+ }
+
+ Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
+ {
+ #if !(defined(_M_AMD64) || defined(_M_X64))
+ x86::emms();
+ #endif
+
+ Nucleus::createRetVoid();
+
+ if(false)
+ {
+ module->print(raw_fd_ostream("llvm-dump-unopt.txt", std::string()), 0);
+ }
+
+ if(runOptimizations)
+ {
+ optimize();
+ }
+
+ if(false)
+ {
+ module->print(raw_fd_ostream("llvm-dump-opt.txt", std::string()), 0);
+ }
+
+ void *entry = executionEngine->getPointerToFunction(function);
+
+ Routine *routine = memoryManager->acquireRoutine();
+ routine->entry = entry;
+ markExecutable(routine->buffer, routine->bufferSize);
+
+ if(CodeAnalystLogJITCode)
+ {
+ CodeAnalystLogJITCode(routine->entry, routine->getCodeSize(), name);
+ }
+
+ return routine;
+ }
+
+ void Nucleus::optimize()
+ {
+ static PassManager *passManager = 0;
+
+ if(!passManager)
+ {
+ passManager = new PassManager();
+
+ UnsafeFPMath = true;
+ // NoInfsFPMath = true;
+ // NoNaNsFPMath = true;
+
+ passManager->add(new TargetData(*executionEngine->getTargetData()));
+ passManager->add(createScalarReplAggregatesPass());
+
+ for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++)
+ {
+ switch(optimization[pass])
+ {
+ case Disabled: break;
+ case CFGSimplification: passManager->add(createCFGSimplificationPass()); break;
+ case LICM: passManager->add(createLICMPass()); break;
+ case AggressiveDCE: passManager->add(createAggressiveDCEPass()); break;
+ case GVN: passManager->add(createGVNPass()); break;
+ case InstructionCombining: passManager->add(createInstructionCombiningPass()); break;
+ case Reassociate: passManager->add(createReassociatePass()); break;
+ case DeadStoreElimination: passManager->add(createDeadStoreEliminationPass()); break;
+ case SCCP: passManager->add(createSCCPPass()); break;
+ default:
+ assert(false);
+ }
+ }
+ }
+
+ passManager->run(*module);
+ }
+
+ void Nucleus::setFunction(llvm::Function *function)
+ {
+ Nucleus::function = function;
+
+ builder->SetInsertPoint(BasicBlock::Create(*context, function));
+ }
+
+ Module *Nucleus::getModule()
+ {
+ return module;
+ }
+
+ Builder *Nucleus::getBuilder()
+ {
+ return builder;
+ }
+
+ llvm::Function *Nucleus::getFunction()
+ {
+ return function;
+ }
+
+ llvm::LLVMContext *Nucleus::getContext()
+ {
+ return context;
+ }
+
+ Value *Nucleus::allocateStackVariable(const Type *type, int arraySize)
+ {
+ // Need to allocate it in the entry block for mem2reg to work
+ llvm::Function *function = getFunction();
+ BasicBlock &entryBlock = function->getEntryBlock();
+
+ Instruction *declaration;
+
+ if(arraySize)
+ {
+ declaration = new AllocaInst(type, Nucleus::createConstantInt(arraySize));
+ }
+ else
+ {
+ declaration = new AllocaInst(type, (Value*)0);
+ }
+
+ entryBlock.getInstList().push_front(declaration);
+
+ return declaration;
+ }
+
+ BasicBlock *Nucleus::createBasicBlock()
+ {
+ return BasicBlock::Create(*context, Nucleus::getFunction());
+ }
+
+ BasicBlock *Nucleus::getInsertBlock()
+ {
+ return builder->GetInsertBlock();
+ }
+
+ void Nucleus::setInsertBlock(BasicBlock *basicBlock)
+ {
+ return builder->SetInsertPoint(basicBlock);
+ }
+
+ BasicBlock *Nucleus::getPredecessor(BasicBlock *basicBlock)
+ {
+ return *pred_begin(basicBlock);
+ }
+
+ llvm::Function *Nucleus::createFunction(const llvm::Type *ReturnType, const std::vector<const llvm::Type*> &Params)
+ {
+ llvm::FunctionType *functionType = llvm::FunctionType::get(ReturnType, Params, false);
+ llvm::Function *function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", Nucleus::getModule());
+ function->setCallingConv(llvm::CallingConv::C);
+
+ return function;
+ }
+
+ llvm::Argument *Nucleus::getArgument(llvm::Function *function, unsigned int index)
+ {
+ llvm::Function::arg_iterator args = function->arg_begin();
+
+ while(index)
+ {
+ args++;
+ index--;
+ }
+
+ return &*args;
+ }
+
+ Value *Nucleus::createRetVoid()
+ {
+ return builder->CreateRetVoid();
+ }
+
+ Value *Nucleus::createRet(Value *V)
+ {
+ return builder->CreateRet(V);
+ }
+
+ Value *Nucleus::createBr(BasicBlock *dest)
+ {
+ return builder->CreateBr(dest);
+ }
+
+ Value *Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
+ {
+ return builder->CreateCondBr(cond, ifTrue, ifFalse);
+ }
+
+ Value *Nucleus::createAdd(Value *lhs, Value *rhs)
+ {
+ return builder->CreateAdd(lhs, rhs);
+ }
+
+ Value *Nucleus::createSub(Value *lhs, Value *rhs)
+ {
+ return builder->CreateSub(lhs, rhs);
+ }
+
+ Value *Nucleus::createMul(Value *lhs, Value *rhs)
+ {
+ return builder->CreateMul(lhs, rhs);
+ }
+
+ Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
+ {
+ return builder->CreateUDiv(lhs, rhs);
+ }
+
+ Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
+ {
+ return builder->CreateSDiv(lhs, rhs);
+ }
+
+ Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFAdd(lhs, rhs);
+ }
+
+ Value *Nucleus::createFSub(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFSub(lhs, rhs);
+ }
+
+ Value *Nucleus::createFMul(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFMul(lhs, rhs);
+ }
+
+ Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFDiv(lhs, rhs);
+ }
+
+ Value *Nucleus::createURem(Value *lhs, Value *rhs)
+ {
+ return builder->CreateURem(lhs, rhs);
+ }
+
+ Value *Nucleus::createSRem(Value *lhs, Value *rhs)
+ {
+ return builder->CreateSRem(lhs, rhs);
+ }
+
+ Value *Nucleus::createFRem(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFRem(lhs, rhs);
+ }
+
+ Value *Nucleus::createShl(Value *lhs, Value *rhs)
+ {
+ return builder->CreateShl(lhs, rhs);
+ }
+
+ Value *Nucleus::createLShr(Value *lhs, Value *rhs)
+ {
+ return builder->CreateLShr(lhs, rhs);
+ }
+
+ Value *Nucleus::createAShr(Value *lhs, Value *rhs)
+ {
+ return builder->CreateAShr(lhs, rhs);
+ }
+
+ Value *Nucleus::createAnd(Value *lhs, Value *rhs)
+ {
+ return builder->CreateAnd(lhs, rhs);
+ }
+
+ Value *Nucleus::createOr(Value *lhs, Value *rhs)
+ {
+ return builder->CreateOr(lhs, rhs);
+ }
+
+ Value *Nucleus::createXor(Value *lhs, Value *rhs)
+ {
+ return builder->CreateXor(lhs, rhs);
+ }
+
+ Value *Nucleus::createNeg(Value *V)
+ {
+ return builder->CreateNeg(V);
+ }
+
+ Value *Nucleus::createFNeg(Value *V)
+ {
+ return builder->CreateFNeg(V);
+ }
+
+ Value *Nucleus::createNot(Value *V)
+ {
+ return builder->CreateNot(V);
+ }
+
+ Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align)
+ {
+ return builder->Insert(new LoadInst(ptr, isVolatile, align));
+ }
+
+ Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align)
+ {
+ return builder->Insert(new StoreInst(value, ptr, isVolatile, align));
+ }
+
+ Value *Nucleus::createGEP(Value *ptr, Value *index)
+ {
+ return builder->CreateGEP(ptr, index);
+ }
+
+ Value *Nucleus::createTrunc(Value *V, const Type *destType)
+ {
+ return builder->CreateTrunc(V, destType);
+ }
+
+ Value *Nucleus::createZExt(Value *V, const Type *destType)
+ {
+ return builder->CreateZExt(V, destType);
+ }
+
+ Value *Nucleus::createSExt(Value *V, const Type *destType)
+ {
+ return builder->CreateSExt(V, destType);
+ }
+
+ Value *Nucleus::createFPToUI(Value *V, const Type *destType)
+ {
+ return builder->CreateFPToUI(V, destType);
+ }
+
+ Value *Nucleus::createFPToSI(Value *V, const Type *destType)
+ {
+ return builder->CreateFPToSI(V, destType);
+ }
+
+ Value *Nucleus::createUIToFP(Value *V, const Type *destType)
+ {
+ return builder->CreateUIToFP(V, destType);
+ }
+
+ Value *Nucleus::createSIToFP(Value *V, const Type *destType)
+ {
+ return builder->CreateSIToFP(V, destType);
+ }
+
+ Value *Nucleus::createFPTrunc(Value *V, const Type *destType)
+ {
+ return builder->CreateFPTrunc(V, destType);
+ }
+
+ Value *Nucleus::createFPExt(Value *V, const Type *destType)
+ {
+ return builder->CreateFPExt(V, destType);
+ }
+
+ Value *Nucleus::createPtrToInt(Value *V, const Type *destType)
+ {
+ return builder->CreatePtrToInt(V, destType);
+ }
+
+ Value *Nucleus::createIntToPtr(Value *V, const Type *destType)
+ {
+ return builder->CreateIntToPtr(V, destType);
+ }
+
+ Value *Nucleus::createBitCast(Value *V, const Type *destType)
+ {
+ return builder->CreateBitCast(V, destType);
+ }
+
+ Value *Nucleus::createIntCast(Value *V, const Type *destType, bool isSigned)
+ {
+ return builder->CreateIntCast(V, destType, isSigned);
+ }
+
+ Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpEQ(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpNE(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpUGT(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpUGE(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpULT(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpULE(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpSGT(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpSGE(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpSLT(lhs, rhs);
+ }
+
+ Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateICmpSLE(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpOEQ(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpOGT(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpOGE(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpOLT(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpOLE(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpONE(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpORD(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpUNO(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpUEQ(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpUGT(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpUGE(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpULT(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpULE(lhs, rhs);
+ }
+
+ Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
+ {
+ return builder->CreateFCmpULE(lhs, rhs);
+ }
+
+ Value *Nucleus::createCall(Value *callee)
+ {
+ return builder->CreateCall(callee);
+ }
+
+ Value *Nucleus::createCall(Value *callee, Value *arg)
+ {
+ return builder->CreateCall(callee, arg);
+ }
+
+ Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2)
+ {
+ return builder->CreateCall2(callee, arg1, arg2);
+ }
+
+ Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3)
+ {
+ return builder->CreateCall3(callee, arg1, arg2, arg3);
+ }
+
+ Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3, Value *arg4)
+ {
+ return builder->CreateCall4(callee, arg1, arg2, arg3, arg4);
+ }
+
+ Value *Nucleus::createExtractElement(Value *vector, int index)
+ {
+ return builder->CreateExtractElement(vector, createConstantInt(index));
+ }
+
+ Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
+ {
+ return builder->CreateInsertElement(vector, element, createConstantInt(index));
+ }
+
+ Value *Nucleus::createShuffleVector(Value *V1, Value *V2, Value *mask)
+ {
+ return builder->CreateShuffleVector(V1, V2, mask);
+ }
+
+ Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
+ {
+ return builder->CreateSelect(C, ifTrue, ifFalse);
+ }
+
+ Value *Nucleus::createSwitch(llvm::Value *V, llvm::BasicBlock *Dest, unsigned NumCases)
+ {
+ return builder->CreateSwitch(V, Dest, NumCases);
+ }
+
+ void Nucleus::addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch)
+ {
+ static_cast<SwitchInst*>(Switch)->addCase(Nucleus::createConstantInt(Case), Branch);
+ }
+
+ Value *Nucleus::createUnreachable()
+ {
+ return builder->CreateUnreachable();
+ }
+
+ Value *Nucleus::createSwizzle(Value *val, unsigned char select)
+ {
+ Constant *swizzle[4];
+ swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03);
+ swizzle[1] = Nucleus::createConstantInt((select >> 2) & 0x03);
+ swizzle[2] = Nucleus::createConstantInt((select >> 4) & 0x03);
+ swizzle[3] = Nucleus::createConstantInt((select >> 6) & 0x03);
+
+ Value *shuffle = Nucleus::createShuffleVector(val, UndefValue::get(val->getType()), Nucleus::createConstantVector(swizzle, 4));
+
+ return shuffle;
+ }
+
+ Value *Nucleus::createMask(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;
+
+ Constant *swizzle[4];
+ swizzle[0] = Nucleus::createConstantInt(mask[0] ? 4 : 0);
+ swizzle[1] = Nucleus::createConstantInt(mask[1] ? 5 : 1);
+ swizzle[2] = Nucleus::createConstantInt(mask[2] ? 6 : 2);
+ swizzle[3] = Nucleus::createConstantInt(mask[3] ? 7 : 3);
+
+ Value *shuffle = Nucleus::createShuffleVector(lhs, rhs, Nucleus::createConstantVector(swizzle, 4));
+
+ return shuffle;
+ }
+
+ const llvm::GlobalValue *Nucleus::getGlobalValueAtAddress(void *Addr)
+ {
+ return executionEngine->getGlobalValueAtAddress(Addr);
+ }
+
+ void Nucleus::addGlobalMapping(const llvm::GlobalValue *GV, void *Addr)
+ {
+ executionEngine->addGlobalMapping(GV, Addr);
+ }
+
+ llvm::GlobalValue *Nucleus::createGlobalValue(const llvm::Type *Ty, bool isConstant, unsigned int Align)
+ {
+ llvm::GlobalValue *global = new llvm::GlobalVariable(Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, "", false);
+ global->setAlignment(Align);
+
+ return global;
+ }
+
+ llvm::Type *Nucleus::getPointerType(const llvm::Type *ElementType)
+ {
+ return llvm::PointerType::get(ElementType, 0);
+ }
+
+ llvm::Constant *Nucleus::createNullValue(const llvm::Type *Ty)
+ {
+ return llvm::Constant::getNullValue(Ty);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantLong(int64_t i)
+ {
+ return llvm::ConstantInt::get(Type::getInt64Ty(*context), i, true);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantInt(int i)
+ {
+ return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, true);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantInt(unsigned int i)
+ {
+ return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, false);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantBool(bool b)
+ {
+ return llvm::ConstantInt::get(Type::getInt1Ty(*context), b);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantByte(signed char i)
+ {
+ return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, true);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantByte(unsigned char i)
+ {
+ return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, false);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantShort(short i)
+ {
+ return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, true);
+ }
+
+ llvm::ConstantInt *Nucleus::createConstantShort(unsigned short i)
+ {
+ return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, false);
+ }
+
+ llvm::Constant *Nucleus::createConstantFloat(float x)
+ {
+ return ConstantFP::get(Float::getType(), x);
+ }
+
+ llvm::Value *Nucleus::createNullPointer(const llvm::Type *Ty)
+ {
+ return llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0));
+ }
+
+ llvm::Value *Nucleus::createConstantVector(Constant* const* Vals, unsigned NumVals)
+ {
+ return llvm::ConstantVector::get(Vals, NumVals);
+ }
+
+ const Type *Void::getType()
+ {
+ return Type::getVoidTy(*Nucleus::getContext());
+ }
+
+ Bool::Bool(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ Bool::Bool()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Bool::Bool(bool x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantBool(x), address);
+ }
+
+ Bool::Bool(const RValue<Bool> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Bool::Bool(const Bool &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Bool> Bool::operator=(const RValue<Bool> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Bool> Bool::operator=(const Bool &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Bool>(value);
+ }
+
+ RValue<Pointer<Bool>> Bool::operator&()
+ {
+ return RValue<Pointer<Bool>>(address);
+ }
+
+ RValue<Bool> operator!(const RValue<Bool> &val)
+ {
+ return RValue<Bool>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Bool> operator&&(const RValue<Bool> &lhs, const RValue<Bool> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator||(const RValue<Bool> &lhs, const RValue<Bool> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ Bool *Bool::getThis()
+ {
+ return this;
+ }
+
+ const Type *Bool::getType()
+ {
+ return Type::getInt1Ty(*Nucleus::getContext());
+ }
+
+ Byte::Byte(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ Byte::Byte(const RValue<Int> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Byte::Byte()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Byte::Byte(int x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantByte((unsigned char)x), address);
+ }
+
+ Byte::Byte(unsigned char x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantByte(x), address);
+ }
+
+ Byte::Byte(const RValue<Byte> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Byte::Byte(const Byte &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Byte> Byte::operator=(const RValue<Byte> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Byte> Byte::operator=(const Byte &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Byte>(value);
+ }
+
+ RValue<Pointer<Byte>> Byte::operator&()
+ {
+ return RValue<Pointer<Byte>>(address);
+ }
+
+ RValue<Byte> operator+(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator-(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator*(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator/(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator%(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator&(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator|(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator^(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator<<(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator>>(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<Byte> operator+=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Byte> operator-=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Byte> operator*=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Byte> operator/=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Byte> operator%=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Byte> operator&=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Byte> operator|=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Byte> operator^=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Byte> operator<<=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Byte> operator>>=(const Byte &lhs, const RValue<Byte> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Byte> operator+(const RValue<Byte> &val)
+ {
+ return val;
+ }
+
+ RValue<Byte> operator-(const RValue<Byte> &val)
+ {
+ return RValue<Byte>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Byte> operator~(const RValue<Byte> &val)
+ {
+ return RValue<Byte>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Byte> operator++(const Byte &val, int) // Post-increment
+ {
+ RValue<Byte> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const Byte &operator++(const Byte &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(Nucleus::createLoad(val.address), Nucleus::createConstantByte((unsigned char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Byte> operator--(const Byte &val, int) // Post-decrement
+ {
+ RValue<Byte> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const Byte &operator--(const Byte &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(Nucleus::createLoad(val.address), Nucleus::createConstantByte((unsigned char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<Byte> &lhs, const RValue<Byte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ Byte *Byte::getThis()
+ {
+ return this;
+ }
+
+ const Type *Byte::getType()
+ {
+ return Type::getInt8Ty(*Nucleus::getContext());
+ }
+
+ SByte::SByte(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ SByte::SByte()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ SByte::SByte(signed char x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantByte(x), address);
+ }
+
+ SByte::SByte(const RValue<SByte> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ SByte::SByte(const SByte &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<SByte> SByte::operator=(const RValue<SByte> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<SByte> SByte::operator=(const SByte &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<SByte>(value);
+ }
+
+ RValue<Pointer<SByte>> SByte::operator&()
+ {
+ return RValue<Pointer<SByte>>(address);
+ }
+
+ RValue<SByte> operator+(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator-(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator*(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator/(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator%(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator&(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator|(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator^(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator<<(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator>>(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<SByte> operator+=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<SByte> operator-=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<SByte> operator*=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<SByte> operator/=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<SByte> operator%=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<SByte> operator&=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<SByte> operator|=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<SByte> operator^=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<SByte> operator<<=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<SByte> operator>>=(const SByte &lhs, const RValue<SByte> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<SByte> operator+(const RValue<SByte> &val)
+ {
+ return val;
+ }
+
+ RValue<SByte> operator-(const RValue<SByte> &val)
+ {
+ return RValue<SByte>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<SByte> operator~(const RValue<SByte> &val)
+ {
+ return RValue<SByte>(Nucleus::createNot(val.value));
+ }
+
+ RValue<SByte> operator++(const SByte &val, int) // Post-increment
+ {
+ RValue<SByte> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const SByte &operator++(const SByte &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(Nucleus::createLoad(val.address), Nucleus::createConstantByte((signed char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<SByte> operator--(const SByte &val, int) // Post-decrement
+ {
+ RValue<SByte> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const SByte &operator--(const SByte &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(Nucleus::createLoad(val.address), Nucleus::createConstantByte((signed char)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<SByte> &lhs, const RValue<SByte> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ SByte *SByte::getThis()
+ {
+ return this;
+ }
+
+ const Type *SByte::getType()
+ {
+ return Type::getInt8Ty(*Nucleus::getContext());
+ }
+
+ Short::Short(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ Short::Short(const RValue<Int> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Short::Short()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Short::Short(short x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantShort(x), address);
+ }
+
+ Short::Short(const RValue<Short> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Short::Short(const Short &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Short> Short::operator=(const RValue<Short> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Short> Short::operator=(const Short &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Short>(value);
+ }
+
+ RValue<Pointer<Short>> Short::operator&()
+ {
+ return RValue<Pointer<Short>>(address);
+ }
+
+ RValue<Short> operator+(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator-(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator*(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator/(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator%(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator&(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator|(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator^(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator<<(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator>>(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<Short> operator+=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Short> operator-=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Short> operator*=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Short> operator/=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Short> operator%=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Short> operator&=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Short> operator|=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Short> operator^=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Short> operator<<=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Short> operator>>=(const Short &lhs, const RValue<Short> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Short> operator+(const RValue<Short> &val)
+ {
+ return val;
+ }
+
+ RValue<Short> operator-(const RValue<Short> &val)
+ {
+ return RValue<Short>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Short> operator~(const RValue<Short> &val)
+ {
+ return RValue<Short>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short> operator++(const Short &val, int) // Post-increment
+ {
+ RValue<Short> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const Short &operator++(const Short &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(Nucleus::createLoad(val.address), Nucleus::createConstantShort((short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Short> operator--(const Short &val, int) // Post-decrement
+ {
+ RValue<Short> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const Short &operator--(const Short &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(Nucleus::createLoad(val.address), Nucleus::createConstantShort((short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<Short> &lhs, const RValue<Short> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ Short *Short::getThis()
+ {
+ return this;
+ }
+
+ const Type *Short::getType()
+ {
+ return Type::getInt16Ty(*Nucleus::getContext());
+ }
+
+ UShort::UShort(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ UShort::UShort()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ UShort::UShort(unsigned short x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantShort(x), address);
+ }
+
+ UShort::UShort(const RValue<UShort> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UShort::UShort(const UShort &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<UShort> UShort::operator=(const RValue<UShort> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UShort> UShort::operator=(const UShort &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UShort>(value);
+ }
+
+ RValue<Pointer<UShort>> UShort::operator&()
+ {
+ return RValue<Pointer<UShort>>(address);
+ }
+
+ RValue<UShort> operator+(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator-(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator*(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator/(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator%(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator&(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator|(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator^(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator<<(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator>>(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<UShort> operator+=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UShort> operator-=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UShort> operator*=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<UShort> operator/=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<UShort> operator%=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<UShort> operator&=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UShort> operator|=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UShort> operator^=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UShort> operator<<=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UShort> operator>>=(const UShort &lhs, const RValue<UShort> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UShort> operator+(const RValue<UShort> &val)
+ {
+ return val;
+ }
+
+ RValue<UShort> operator-(const RValue<UShort> &val)
+ {
+ return RValue<UShort>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UShort> operator~(const RValue<UShort> &val)
+ {
+ return RValue<UShort>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UShort> operator++(const UShort &val, int) // Post-increment
+ {
+ RValue<UShort> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const UShort &operator++(const UShort &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(Nucleus::createLoad(val.address), Nucleus::createConstantShort((unsigned short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<UShort> operator--(const UShort &val, int) // Post-decrement
+ {
+ RValue<UShort> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const UShort &operator--(const UShort &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(Nucleus::createLoad(val.address), Nucleus::createConstantShort((unsigned short)1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<UShort> &lhs, const RValue<UShort> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ UShort *UShort::getThis()
+ {
+ return this;
+ }
+
+ const Type *UShort::getType()
+ {
+ return Type::getInt16Ty(*Nucleus::getContext());
+ }
+
+ Byte4 *Byte4::getThis()
+ {
+ return this;
+ }
+
+ const Type *Byte4::getType()
+ {
+ #if 0
+ return VectorType::get(Byte::getType(), 4);
+ #else
+ return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
+ #endif
+ }
+
+ SByte4 *SByte4::getThis()
+ {
+ return this;
+ }
+
+ const Type *SByte4::getType()
+ {
+ #if 0
+ return VectorType::get(SByte::getType(), 4);
+ #else
+ return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
+ #endif
+ }
+
+ Byte8::Byte8()
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Byte8::Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[8];
+ constantVector[0] = Nucleus::createConstantByte(x0);
+ constantVector[1] = Nucleus::createConstantByte(x1);
+ constantVector[2] = Nucleus::createConstantByte(x2);
+ constantVector[3] = Nucleus::createConstantByte(x3);
+ constantVector[4] = Nucleus::createConstantByte(x4);
+ constantVector[5] = Nucleus::createConstantByte(x5);
+ constantVector[6] = Nucleus::createConstantByte(x6);
+ constantVector[7] = Nucleus::createConstantByte(x7);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 8), address);
+ }
+
+ Byte8::Byte8(int64_t x)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[8];
+ constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
+ constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
+ constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
+ constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
+ constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
+ constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
+ constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
+ constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 8), address);
+ }
+
+ Byte8::Byte8(const RValue<Byte8> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Byte8::Byte8(const Byte8 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Byte8> Byte8::operator=(const RValue<Byte8> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Byte8>(value);
+ }
+
+ RValue<Byte8> operator+(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator-(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator*(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator/(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator%(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator&(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator|(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Byte8> operator^(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs)
+ {
+ return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+// RValue<Byte8> operator<<(const RValue<Byte8> &lhs, unsigned char rhs)
+// {
+// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
+// }
+
+// RValue<Byte8> operator>>(const RValue<Byte8> &lhs, unsigned char rhs)
+// {
+// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
+// }
+
+ RValue<Byte8> operator+=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Byte8> operator-=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Byte8> operator*=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Byte8> operator/=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Byte8> operator%=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Byte8> operator&=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Byte8> operator|=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Byte8> operator^=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+// RValue<Byte8> operator<<=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+// {
+// return lhs = lhs << rhs;
+// }
+
+// RValue<Byte8> operator>>=(const Byte8 &lhs, const RValue<Byte8> &rhs)
+// {
+// return lhs = lhs >> rhs;
+// }
+
+ RValue<Byte8> operator+(const RValue<Byte8> &val)
+ {
+ return val;
+ }
+
+ RValue<Byte8> operator-(const RValue<Byte8> &val)
+ {
+ return RValue<Byte8>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Byte8> operator~(const RValue<Byte8> &val)
+ {
+ return RValue<Byte8>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Byte8> AddSat(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ return x86::paddusb(x, y);
+ }
+
+ RValue<Byte8> SubSat(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ return x86::psubusb(x, y);
+ }
+
+ RValue<Short4> UnpackLow(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ Constant *shuffle[8];
+ shuffle[0] = Nucleus::createConstantInt(0);
+ shuffle[1] = Nucleus::createConstantInt(8);
+ shuffle[2] = Nucleus::createConstantInt(1);
+ shuffle[3] = Nucleus::createConstantInt(9);
+ shuffle[4] = Nucleus::createConstantInt(2);
+ shuffle[5] = Nucleus::createConstantInt(10);
+ shuffle[6] = Nucleus::createConstantInt(3);
+ shuffle[7] = Nucleus::createConstantInt(11);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
+
+ return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
+ }
+
+ RValue<Short4> UnpackHigh(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ Constant *shuffle[8];
+ shuffle[0] = Nucleus::createConstantInt(4);
+ shuffle[1] = Nucleus::createConstantInt(12);
+ shuffle[2] = Nucleus::createConstantInt(5);
+ shuffle[3] = Nucleus::createConstantInt(13);
+ shuffle[4] = Nucleus::createConstantInt(6);
+ shuffle[5] = Nucleus::createConstantInt(14);
+ shuffle[6] = Nucleus::createConstantInt(7);
+ shuffle[7] = Nucleus::createConstantInt(15);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
+
+ return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
+ }
+
+ RValue<Int> SignMask(const RValue<Byte8> &x)
+ {
+ return x86::pmovmskb(x);
+ }
+
+// RValue<Byte8> CmpGT(const RValue<Byte8> &x, const RValue<Byte8> &y)
+// {
+// return x86::pcmpgtb(x, y); // FIXME: Signedness
+// }
+
+ RValue<Byte8> CmpEQ(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ return x86::pcmpeqb(x, y);
+ }
+
+ Byte8 *Byte8::getThis()
+ {
+ return this;
+ }
+
+ const Type *Byte8::getType()
+ {
+ return VectorType::get(Byte::getType(), 8);
+ }
+
+ SByte8::SByte8()
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ SByte8::SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[8];
+ constantVector[0] = Nucleus::createConstantByte(x0);
+ constantVector[1] = Nucleus::createConstantByte(x1);
+ constantVector[2] = Nucleus::createConstantByte(x2);
+ constantVector[3] = Nucleus::createConstantByte(x3);
+ constantVector[4] = Nucleus::createConstantByte(x4);
+ constantVector[5] = Nucleus::createConstantByte(x5);
+ constantVector[6] = Nucleus::createConstantByte(x6);
+ constantVector[7] = Nucleus::createConstantByte(x7);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 8), address);
+ }
+
+ SByte8::SByte8(int64_t x)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[8];
+ constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
+ constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
+ constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
+ constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
+ constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
+ constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
+ constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
+ constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 8), address);
+ }
+
+ SByte8::SByte8(const RValue<SByte8> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ SByte8::SByte8(const SByte8 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<SByte8> SByte8::operator=(const RValue<SByte8> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<SByte8>(value);
+ }
+
+ RValue<SByte8> operator+(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator-(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator*(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator/(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator%(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator&(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator|(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<SByte8> operator^(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs)
+ {
+ return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+// RValue<SByte8> operator<<(const RValue<SByte8> &lhs, unsigned char rhs)
+// {
+// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
+// }
+
+// RValue<SByte8> operator>>(const RValue<SByte8> &lhs, unsigned char rhs)
+// {
+// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
+// }
+
+ RValue<SByte8> operator+=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<SByte8> operator-=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<SByte8> operator*=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<SByte8> operator/=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<SByte8> operator%=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<SByte8> operator&=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<SByte8> operator|=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<SByte8> operator^=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+// RValue<SByte8> operator<<=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+// {
+// return lhs = lhs << rhs;
+// }
+
+// RValue<SByte8> operator>>=(const SByte8 &lhs, const RValue<SByte8> &rhs)
+// {
+// return lhs = lhs >> rhs;
+// }
+
+ RValue<SByte8> operator+(const RValue<SByte8> &val)
+ {
+ return val;
+ }
+
+ RValue<SByte8> operator-(const RValue<SByte8> &val)
+ {
+ return RValue<SByte8>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<SByte8> operator~(const RValue<SByte8> &val)
+ {
+ return RValue<SByte8>(Nucleus::createNot(val.value));
+ }
+
+ RValue<SByte8> AddSat(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ return x86::paddsb(x, y);
+ }
+
+ RValue<SByte8> SubSat(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ return x86::psubsb(x, y);
+ }
+
+ RValue<Short4> UnpackLow(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ Constant *shuffle[8];
+ shuffle[0] = Nucleus::createConstantInt(0);
+ shuffle[1] = Nucleus::createConstantInt(8);
+ shuffle[2] = Nucleus::createConstantInt(1);
+ shuffle[3] = Nucleus::createConstantInt(9);
+ shuffle[4] = Nucleus::createConstantInt(2);
+ shuffle[5] = Nucleus::createConstantInt(10);
+ shuffle[6] = Nucleus::createConstantInt(3);
+ shuffle[7] = Nucleus::createConstantInt(11);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
+
+ return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
+ }
+
+ RValue<Short4> UnpackHigh(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ Constant *shuffle[8];
+ shuffle[0] = Nucleus::createConstantInt(4);
+ shuffle[1] = Nucleus::createConstantInt(12);
+ shuffle[2] = Nucleus::createConstantInt(5);
+ shuffle[3] = Nucleus::createConstantInt(13);
+ shuffle[4] = Nucleus::createConstantInt(6);
+ shuffle[5] = Nucleus::createConstantInt(14);
+ shuffle[6] = Nucleus::createConstantInt(7);
+ shuffle[7] = Nucleus::createConstantInt(15);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
+
+ return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
+ }
+
+ RValue<Int> SignMask(const RValue<SByte8> &x)
+ {
+ return x86::pmovmskb(As<Byte8>(x));
+ }
+
+ RValue<Byte8> CmpGT(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ return x86::pcmpgtb(x, y);
+ }
+
+ RValue<Byte8> CmpEQ(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
+ }
+
+ SByte8 *SByte8::getThis()
+ {
+ return this;
+ }
+
+ const Type *SByte8::getType()
+ {
+ return VectorType::get(SByte::getType(), 8);
+ }
+
+ Byte16::Byte16(const RValue<Byte16> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Byte16::Byte16(const Byte16 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Byte16> Byte16::operator=(const RValue<Byte16> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Byte16>(value);
+ }
+
+ Byte16 *Byte16::getThis()
+ {
+ return this;
+ }
+
+ const Type *Byte16::getType()
+ {
+ return VectorType::get(Byte::getType(), 16);
+ }
+
+ SByte16 *SByte16::getThis()
+ {
+ return this;
+ }
+
+ const Type *SByte16::getType()
+ {
+ return VectorType::get(SByte::getType(), 16);
+ }
+
+ Short4::Short4(const RValue<Int> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *extend = Nucleus::createZExt(cast.value, Long::getType());
+ Value *vector = Nucleus::createBitCast(extend, Short4::getType());
+ Value *swizzle = Nucleus::createSwizzle(vector, 0x00);
+
+ Nucleus::createStore(swizzle, address);
+ }
+
+ Short4::Short4(const RValue<Int4> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
+
+ #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd)
+ Constant *pack[8];
+ pack[0] = Nucleus::createConstantInt(0);
+ pack[1] = Nucleus::createConstantInt(2);
+ pack[2] = Nucleus::createConstantInt(4);
+ pack[3] = Nucleus::createConstantInt(6);
+
+ Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4));
+ #else
+ Value *packed;
+
+ // FIXME: Use Swizzle<Short8>
+ if(!CPUID::supportsSSSE3())
+ {
+ Constant *pshuflw[8];
+ pshuflw[0] = Nucleus::createConstantInt(0);
+ pshuflw[1] = Nucleus::createConstantInt(2);
+ pshuflw[2] = Nucleus::createConstantInt(0);
+ pshuflw[3] = Nucleus::createConstantInt(2);
+ pshuflw[4] = Nucleus::createConstantInt(4);
+ pshuflw[5] = Nucleus::createConstantInt(5);
+ pshuflw[6] = Nucleus::createConstantInt(6);
+ pshuflw[7] = Nucleus::createConstantInt(7);
+
+ Constant *pshufhw[8];
+ pshufhw[0] = Nucleus::createConstantInt(0);
+ pshufhw[1] = Nucleus::createConstantInt(1);
+ pshufhw[2] = Nucleus::createConstantInt(2);
+ pshufhw[3] = Nucleus::createConstantInt(3);
+ pshufhw[4] = Nucleus::createConstantInt(4);
+ pshufhw[5] = Nucleus::createConstantInt(6);
+ pshufhw[6] = Nucleus::createConstantInt(4);
+ pshufhw[7] = Nucleus::createConstantInt(6);
+
+ Value *shuffle1 = Nucleus::createShuffleVector(short8, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshuflw, 8));
+ Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshufhw, 8));
+ Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType());
+ packed = Nucleus::createSwizzle(int4, 0x88);
+ }
+ else
+ {
+ Constant *pshufb[16];
+ pshufb[0] = Nucleus::createConstantInt(0);
+ pshufb[1] = Nucleus::createConstantInt(1);
+ pshufb[2] = Nucleus::createConstantInt(4);
+ pshufb[3] = Nucleus::createConstantInt(5);
+ pshufb[4] = Nucleus::createConstantInt(8);
+ pshufb[5] = Nucleus::createConstantInt(9);
+ pshufb[6] = Nucleus::createConstantInt(12);
+ pshufb[7] = Nucleus::createConstantInt(13);
+ pshufb[8] = Nucleus::createConstantInt(0);
+ pshufb[9] = Nucleus::createConstantInt(1);
+ pshufb[10] = Nucleus::createConstantInt(4);
+ pshufb[11] = Nucleus::createConstantInt(5);
+ pshufb[12] = Nucleus::createConstantInt(8);
+ pshufb[13] = Nucleus::createConstantInt(9);
+ pshufb[14] = Nucleus::createConstantInt(12);
+ pshufb[15] = Nucleus::createConstantInt(13);
+
+ Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType());
+ packed = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
+ }
+
+ #if 0 // FIXME: No optimal instruction selection
+ Value *qword2 = Nucleus::createBitCast(packed, Long2::getType());
+ Value *element = Nucleus::createExtractElement(qword2, 0);
+ Value *short4 = Nucleus::createBitCast(element, Short4::getType());
+ #else // FIXME: Requires SSE
+ Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
+ Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
+ #endif
+ #endif
+
+ Nucleus::createStore(short4, address);
+ }
+
+// Short4::Short4(const RValue<Float> &cast)
+// {
+// }
+
+ Short4::Short4(const RValue<Float4> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Int4 v4i32 = Int4(cast);
+ v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
+
+ Nucleus::createStore(As<Short4>(Int2(v4i32)).value, address);
+ }
+
+ Short4::Short4()
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Short4::Short4(short x, short y, short z, short w)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantShort(x);
+ constantVector[1] = Nucleus::createConstantShort(y);
+ constantVector[2] = Nucleus::createConstantShort(z);
+ constantVector[3] = Nucleus::createConstantShort(w);
+ Nucleus::createConstantVector(constantVector, 4);
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 4), address);
+ }
+
+ Short4::Short4(const RValue<Short4> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Short4::Short4(const Short4 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ Short4::Short4(const RValue<UShort4> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Short4::Short4(const UShort4 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Short4> Short4::operator=(const RValue<Short4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Short4> Short4::operator=(const Short4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Short4>(value);
+ }
+
+ RValue<Short4> Short4::operator=(const RValue<UShort4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Short4> Short4::operator=(const UShort4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Short4>(value);
+ }
+
+ RValue<Short4> operator+(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator-(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator*(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator/(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator%(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator&(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator|(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator^(const RValue<Short4> &lhs, const RValue<Short4> &rhs)
+ {
+ return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Short4> operator<<(const RValue<Short4> &lhs, unsigned char rhs)
+ {
+ // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return x86::psllw(lhs, rhs);
+ }
+
+ RValue<Short4> operator>>(const RValue<Short4> &lhs, unsigned char rhs)
+ {
+ // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
+
+ return x86::psraw(lhs, rhs);
+ }
+
+ RValue<Short4> operator<<(const RValue<Short4> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return x86::psllw(lhs, rhs);
+ }
+
+ RValue<Short4> operator>>(const RValue<Short4> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
+
+ return x86::psraw(lhs, rhs);
+ }
+
+ RValue<Short4> operator+=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Short4> operator-=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Short4> operator*=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Short4> operator/=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Short4> operator%=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Short4> operator&=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Short4> operator|=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Short4> operator^=(const Short4 &lhs, const RValue<Short4> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Short4> operator<<=(const Short4 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Short4> operator>>=(const Short4 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Short4> operator+(const RValue<Short4> &val)
+ {
+ return val;
+ }
+
+ RValue<Short4> operator-(const RValue<Short4> &val)
+ {
+ return RValue<Short4>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Short4> operator~(const RValue<Short4> &val)
+ {
+ return RValue<Short4>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Short4> RoundShort4(const RValue<Float4> &cast)
+ {
+ RValue<Int4> v4i32 = x86::cvtps2dq(cast);
+ v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
+
+ return As<Short4>(Int2(v4i32));
+ }
+
+ RValue<Short4> Max(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::pmaxsw(x, y);
+ }
+
+ RValue<Short4> Min(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::pminsw(x, y);
+ }
+
+ RValue<Short4> AddSat(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::paddsw(x, y);
+ }
+
+ RValue<Short4> SubSat(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::psubsw(x, y);
+ }
+
+ RValue<Short4> MulHigh(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::pmulhw(x, y);
+ }
+
+ RValue<Int2> MulAdd(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::pmaddwd(x, y);
+ }
+
+ RValue<SByte8> Pack(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::packsswb(x, y);
+ }
+
+ RValue<Int2> UnpackLow(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Constant *shuffle[4];
+ shuffle[0] = Nucleus::createConstantInt(0);
+ shuffle[1] = Nucleus::createConstantInt(4);
+ shuffle[2] = Nucleus::createConstantInt(1);
+ shuffle[3] = Nucleus::createConstantInt(5);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
+
+ return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
+ }
+
+ RValue<Int2> UnpackHigh(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Constant *shuffle[4];
+ shuffle[0] = Nucleus::createConstantInt(2);
+ shuffle[1] = Nucleus::createConstantInt(6);
+ shuffle[2] = Nucleus::createConstantInt(3);
+ shuffle[3] = Nucleus::createConstantInt(7);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
+
+ return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
+ }
+
+ RValue<Short4> Swizzle(const RValue<Short4> &x, unsigned char select)
+ {
+ return RValue<Short4>(Nucleus::createSwizzle(x.value, select));
+ }
+
+ RValue<Short4> Insert(const RValue<Short4> &val, const RValue<Short> &element, int i)
+ {
+ return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
+ }
+
+ RValue<Short> Extract(const RValue<Short4> &val, int i)
+ {
+ return RValue<Short>(Nucleus::createExtractElement(val.value, i));
+ }
+
+ RValue<Short4> CmpGT(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::pcmpgtw(x, y);
+ }
+
+ RValue<Short4> CmpEQ(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ return x86::pcmpeqw(x, y);
+ }
+
+ Short4 *Short4::getThis()
+ {
+ return this;
+ }
+
+ const Type *Short4::getType()
+ {
+ return VectorType::get(Short::getType(), 4);
+ }
+
+ UShort4::UShort4(const RValue<Int4> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = Short4(cast);
+ }
+
+ UShort4::UShort4(const RValue<Float4> &cast, bool saturate)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Float4 sat;
+
+ if(saturate)
+ {
+ if(CPUID::supportsSSE4_1())
+ {
+ sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation
+ }
+ else
+ {
+ sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000));
+ }
+ }
+ else
+ {
+ sat = cast;
+ }
+
+ Int4 int4(sat);
+
+ if(!saturate || !CPUID::supportsSSE4_1())
+ {
+ *this = Short4(Int4(int4));
+ }
+ else
+ {
+ *this = As<Short4>(Int2(As<Int4>(x86::packusdw(As<UInt4>(int4), As<UInt4>(int4)))));
+ }
+ }
+
+ UShort4::UShort4()
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantShort(x);
+ constantVector[1] = Nucleus::createConstantShort(y);
+ constantVector[2] = Nucleus::createConstantShort(z);
+ constantVector[3] = Nucleus::createConstantShort(w);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 4), address);
+ }
+
+ UShort4::UShort4(const RValue<UShort4> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UShort4::UShort4(const UShort4 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ UShort4::UShort4(const RValue<Short4> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UShort4::UShort4(const Short4 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<UShort4> UShort4::operator=(const RValue<UShort4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UShort4>(value);
+ }
+
+ RValue<UShort4> UShort4::operator=(const RValue<Short4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UShort4> UShort4::operator=(const Short4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UShort4>(value);
+ }
+
+ RValue<UShort4> operator+(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs)
+ {
+ return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator-(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs)
+ {
+ return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator*(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs)
+ {
+ return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UShort4> operator<<(const RValue<UShort4> &lhs, unsigned char rhs)
+ {
+ // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
+ }
+
+ RValue<UShort4> operator>>(const RValue<UShort4> &lhs, unsigned char rhs)
+ {
+ // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
+
+ return x86::psrlw(lhs, rhs);
+ }
+
+ RValue<UShort4> operator<<(const RValue<UShort4> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
+ }
+
+ RValue<UShort4> operator>>(const RValue<UShort4> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
+
+ return x86::psrlw(lhs, rhs);
+ }
+
+ RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UShort4> operator<<=(const UShort4 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UShort4> operator>>=(const UShort4 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UShort4> operator~(const RValue<UShort4> &val)
+ {
+ return RValue<UShort4>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UShort4> Max(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return Max(As<Short4>(x) - Short4(0x8000, 0x8000, 0x8000, 0x8000), As<Short4>(y) - Short4(0x8000, 0x8000, 0x8000, 0x8000)) + Short4(0x8000, 0x8000, 0x8000, 0x8000);;
+ }
+
+ RValue<UShort4> Min(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return Min(As<Short4>(x) - Short4(0x8000, 0x8000, 0x8000, 0x8000), As<Short4>(y) - Short4(0x8000, 0x8000, 0x8000, 0x8000)) + Short4(0x8000, 0x8000, 0x8000, 0x8000);;
+ }
+
+ RValue<UShort4> AddSat(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return x86::paddusw(x, y);
+ }
+
+ RValue<UShort4> SubSat(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return x86::psubusw(x, y);
+ }
+
+ RValue<UShort4> MulHigh(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return x86::pmulhuw(x, y);
+ }
+
+ RValue<UShort4> Average(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return x86::pavgw(x, y);
+ }
+
+ RValue<Byte8> Pack(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ return x86::packuswb(x, y);
+ }
+
+ UShort4 *UShort4::getThis()
+ {
+ return this;
+ }
+
+ const Type *UShort4::getType()
+ {
+ return VectorType::get(UShort::getType(), 4);
+ }
+
+ Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[8];
+ constantVector[0] = Nucleus::createConstantShort(c0);
+ constantVector[1] = Nucleus::createConstantShort(c1);
+ constantVector[2] = Nucleus::createConstantShort(c2);
+ constantVector[3] = Nucleus::createConstantShort(c3);
+ constantVector[4] = Nucleus::createConstantShort(c4);
+ constantVector[5] = Nucleus::createConstantShort(c5);
+ constantVector[6] = Nucleus::createConstantShort(c6);
+ constantVector[7] = Nucleus::createConstantShort(c7);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 8), address);
+ }
+
+ Short8::Short8(const RValue<Short8> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ RValue<Short8> operator+(const RValue<Short8> &lhs, const RValue<Short8> &rhs)
+ {
+ return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Short8> operator&(const RValue<Short8> &lhs, const RValue<Short8> &rhs)
+ {
+ return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Short8> operator<<(const RValue<Short8> &lhs, unsigned char rhs)
+ {
+ return x86::psllw(lhs, rhs); // FIXME: Fallback required
+ }
+
+ RValue<Short8> operator>>(const RValue<Short8> &lhs, unsigned char rhs)
+ {
+ return x86::psraw(lhs, rhs); // FIXME: Fallback required
+ }
+
+ RValue<Short8> Concatenate(const RValue<Short4> &lo, const RValue<Short4> &hi)
+ {
+ Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
+ Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
+
+ Value *long2 = UndefValue::get(Long2::getType());
+ long2 = Nucleus::createInsertElement(long2, loLong, 0);
+ long2 = Nucleus::createInsertElement(long2, hiLong, 1);
+ Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
+
+ return RValue<Short8>(short8);
+ }
+
+ RValue<Int4> MulAdd(const RValue<Short8> &x, const RValue<Short8> &y)
+ {
+ return x86::pmaddwd(x, y); // FIXME: Fallback required
+ }
+
+ RValue<Short8> MulHigh(const RValue<Short8> &x, const RValue<Short8> &y)
+ {
+ return x86::pmulhw(x, y); // FIXME: Fallback required
+ }
+
+ Short8 *Short8::getThis()
+ {
+ return this;
+ }
+
+ const Type *Short8::getType()
+ {
+ return VectorType::get(Short::getType(), 8);
+ }
+
+ 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)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[8];
+ constantVector[0] = Nucleus::createConstantShort(c0);
+ constantVector[1] = Nucleus::createConstantShort(c1);
+ constantVector[2] = Nucleus::createConstantShort(c2);
+ constantVector[3] = Nucleus::createConstantShort(c3);
+ constantVector[4] = Nucleus::createConstantShort(c4);
+ constantVector[5] = Nucleus::createConstantShort(c5);
+ constantVector[6] = Nucleus::createConstantShort(c6);
+ constantVector[7] = Nucleus::createConstantShort(c7);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 8), address);
+ }
+
+ UShort8::UShort8(const RValue<UShort8> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ RValue<UShort8> UShort8::operator=(const RValue<UShort8> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UShort8>(value);
+ }
+
+ RValue<UShort8> operator&(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs)
+ {
+ return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort8> operator<<(const RValue<UShort8> &lhs, unsigned char rhs)
+ {
+ return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required
+ }
+
+ RValue<UShort8> operator>>(const RValue<UShort8> &lhs, unsigned char rhs)
+ {
+ return x86::psrlw(lhs, rhs); // FIXME: Fallback required
+ }
+
+ RValue<UShort8> operator+(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs)
+ {
+ return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UShort8> operator*(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs)
+ {
+ return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UShort8> operator+=(const UShort8 &lhs, const RValue<UShort8> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UShort8> operator~(const RValue<UShort8> &val)
+ {
+ return RValue<UShort8>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UShort8> Swizzle(const RValue<UShort8> &x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
+ {
+ Constant *pshufb[16];
+ pshufb[0] = Nucleus::createConstantInt(select0 + 0);
+ pshufb[1] = Nucleus::createConstantInt(select0 + 1);
+ pshufb[2] = Nucleus::createConstantInt(select1 + 0);
+ pshufb[3] = Nucleus::createConstantInt(select1 + 1);
+ pshufb[4] = Nucleus::createConstantInt(select2 + 0);
+ pshufb[5] = Nucleus::createConstantInt(select2 + 1);
+ pshufb[6] = Nucleus::createConstantInt(select3 + 0);
+ pshufb[7] = Nucleus::createConstantInt(select3 + 1);
+ pshufb[8] = Nucleus::createConstantInt(select4 + 0);
+ pshufb[9] = Nucleus::createConstantInt(select4 + 1);
+ pshufb[10] = Nucleus::createConstantInt(select5 + 0);
+ pshufb[11] = Nucleus::createConstantInt(select5 + 1);
+ pshufb[12] = Nucleus::createConstantInt(select6 + 0);
+ pshufb[13] = Nucleus::createConstantInt(select6 + 1);
+ pshufb[14] = Nucleus::createConstantInt(select7 + 0);
+ pshufb[15] = Nucleus::createConstantInt(select7 + 1);
+
+ Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
+ Value *shuffle = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
+ Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
+
+ return RValue<UShort8>(short8);
+ }
+
+ RValue<UShort8> Concatenate(const RValue<UShort4> &lo, const RValue<UShort4> &hi)
+ {
+ Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
+ Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
+
+ Value *long2 = UndefValue::get(Long2::getType());
+ long2 = Nucleus::createInsertElement(long2, loLong, 0);
+ long2 = Nucleus::createInsertElement(long2, hiLong, 1);
+ Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
+
+ return RValue<UShort8>(short8);
+ }
+
+ RValue<UShort8> MulHigh(const RValue<UShort8> &x, const RValue<UShort8> &y)
+ {
+ return x86::pmulhuw(x, y); // FIXME: Fallback required
+ }
+
+ // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
+// RValue<UShort8> PackRepeat(const RValue<Byte16> &x, const RValue<Byte16> &y, int element)
+// {
+// Constant *pshufb[16];
+// pshufb[0] = Nucleus::createConstantInt(element + 0);
+// pshufb[1] = Nucleus::createConstantInt(element + 0);
+// pshufb[2] = Nucleus::createConstantInt(element + 4);
+// pshufb[3] = Nucleus::createConstantInt(element + 4);
+// pshufb[4] = Nucleus::createConstantInt(element + 8);
+// pshufb[5] = Nucleus::createConstantInt(element + 8);
+// pshufb[6] = Nucleus::createConstantInt(element + 12);
+// pshufb[7] = Nucleus::createConstantInt(element + 12);
+// pshufb[8] = Nucleus::createConstantInt(element + 16);
+// pshufb[9] = Nucleus::createConstantInt(element + 16);
+// pshufb[10] = Nucleus::createConstantInt(element + 20);
+// pshufb[11] = Nucleus::createConstantInt(element + 20);
+// pshufb[12] = Nucleus::createConstantInt(element + 24);
+// pshufb[13] = Nucleus::createConstantInt(element + 24);
+// pshufb[14] = Nucleus::createConstantInt(element + 28);
+// pshufb[15] = Nucleus::createConstantInt(element + 28);
+//
+// Value *shuffle = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(pshufb, 16));
+// Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
+//
+// return RValue<UShort8>(short8);
+// }
+
+ UShort8 *UShort8::getThis()
+ {
+ return this;
+ }
+
+ const Type *UShort8::getType()
+ {
+ return VectorType::get(UShort::getType(), 8);
+ }
+
+ Int::Int(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ Int::Int(const RValue<Byte> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createZExt(cast.value, Int::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Int::Int(const RValue<SByte> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createSExt(cast.value, Int::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Int::Int(const RValue<Short> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createSExt(cast.value, Int::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Int::Int(const RValue<UShort> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createZExt(cast.value, Int::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Int::Int(const RValue<Int2> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = Extract(cast, 0);
+ }
+
+ Int::Int(const RValue<Long> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Int::Int(const RValue<Float> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Int::Int()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Int::Int(int x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantInt(x), address);
+ }
+
+ Int::Int(const RValue<Int> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Int::Int(const RValue<UInt> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Int::Int(const Int &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ Int::Int(const UInt &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Int> Int::operator=(int rhs) const
+ {
+ return RValue<Int>(Nucleus::createStore(Nucleus::createConstantInt(rhs), address));
+ }
+
+ RValue<Int> Int::operator=(const RValue<Int> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Int> Int::operator=(const RValue<UInt> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Int> Int::operator=(const Int &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Int>(value);
+ }
+
+ RValue<Int> Int::operator=(const UInt &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Int>(value);
+ }
+
+ RValue<Pointer<Int>> Int::operator&()
+ {
+ return RValue<Pointer<Int>>(address);
+ }
+
+ RValue<Int> operator+(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator-(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator*(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator/(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator%(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator&(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator|(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator^(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator<<(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator>>(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
+ }
+
+ RValue<Int> operator+=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Int> operator-=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Int> operator*=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Int> operator/=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Int> operator%=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Int> operator&=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Int> operator|=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Int> operator^=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Int> operator<<=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int> operator>>=(const Int &lhs, const RValue<Int> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Int> operator+(const RValue<Int> &val)
+ {
+ return val;
+ }
+
+ RValue<Int> operator-(const RValue<Int> &val)
+ {
+ return RValue<Int>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Int> operator~(const RValue<Int> &val)
+ {
+ return RValue<Int>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Int> operator++(const Int &val, int) // Post-increment
+ {
+ RValue<Int> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const Int &operator++(const Int &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(Nucleus::createLoad(val.address), Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Int> operator--(const Int &val, int) // Post-decrement
+ {
+ RValue<Int> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const Int &operator--(const Int &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(Nucleus::createLoad(val.address), Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<Int> &lhs, const RValue<Int> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+ RValue<Int> RoundInt(const RValue<Float> &cast)
+ {
+ return x86::cvtss2si(cast);
+
+ // return IfThenElse(val > Float(0), Int(val + Float(0.5f)), Int(val - Float(0.5f)));
+ }
+
+ Int *Int::getThis()
+ {
+ return this;
+ }
+
+ const Type *Int::getType()
+ {
+ return Type::getInt32Ty(*Nucleus::getContext());
+ }
+
+ Long::Long(const RValue<Int> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createSExt(cast.value, Long::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Long::Long(const RValue<UInt> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createZExt(cast.value, Long::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Long::Long()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Long::Long(const RValue<Long> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ RValue<Long> Long::operator=(int64_t rhs) const
+ {
+ return RValue<Long>(Nucleus::createStore(Nucleus::createConstantLong(rhs), address));
+ }
+
+ RValue<Long> Long::operator=(const RValue<Long> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Long> Long::operator=(const Long &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Long>(value);
+ }
+
+ RValue<Long> operator+(const RValue<Long> &lhs, const RValue<Long> &rhs)
+ {
+ return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Long> operator-(const RValue<Long> &lhs, const RValue<Long> &rhs)
+ {
+ return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Long> operator+=(const Long &lhs, const RValue<Long> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Long> operator-=(const Long &lhs, const RValue<Long> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Long> AddAtomic(const RValue<Pointer<Long>> &x, const RValue<Long> &y)
+ {
+ Module *module = Nucleus::getModule();
+ const llvm::Type *type = Long::getType();
+ llvm::Function *atomic = Intrinsic::getDeclaration(module, Intrinsic::atomic_load_add, &type, 1);
+
+ return RValue<Long>(Nucleus::createCall(atomic, x.value, y.value));
+ }
+
+ Long *Long::getThis()
+ {
+ return this;
+ }
+
+ const Type *Long::getType()
+ {
+ return Type::getInt64Ty(*Nucleus::getContext());
+ }
+
+ Long1::Long1(const Reference<UInt> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *uint = Nucleus::createLoad(cast.address);
+ Value *int64 = Nucleus::createZExt(uint, Long::getType());
+ Value *long1 = Nucleus::createBitCast(int64, Long1::getType());
+
+ Nucleus::createStore(long1, address);
+ }
+
+ Long1::Long1(const RValue<Long1> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Long1 *Long1::getThis()
+ {
+ return this;
+ }
+
+ const Type *Long1::getType()
+ {
+ return VectorType::get(Long::getType(), 1);
+ }
+
+ RValue<Long2> UnpackHigh(const RValue<Long2> &x, const RValue<Long2> &y)
+ {
+ Constant *shuffle[2];
+ shuffle[0] = Nucleus::createConstantInt(1);
+ shuffle[1] = Nucleus::createConstantInt(3);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
+
+ return RValue<Long2>(packed);
+ }
+
+ Long2 *Long2::getThis()
+ {
+ return this;
+ }
+
+ const Type *Long2::getType()
+ {
+ return VectorType::get(Long::getType(), 2);
+ }
+
+ UInt::UInt(Argument *argument)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(argument, address);
+ }
+
+ UInt::UInt(const RValue<UShort> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ UInt::UInt(const RValue<Long> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ UInt::UInt(const RValue<Float> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createFPToSI(cast.value, UInt::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ UInt::UInt()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ UInt::UInt(int x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantInt(x), address);
+ }
+
+ UInt::UInt(unsigned int x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantInt(x), address);
+ }
+
+ UInt::UInt(const RValue<UInt> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UInt::UInt(const RValue<Int> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UInt::UInt(const UInt &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ UInt::UInt(const Int &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<UInt> UInt::operator=(unsigned int rhs) const
+ {
+ return RValue<UInt>(Nucleus::createStore(Nucleus::createConstantInt(rhs), address));
+ }
+
+ RValue<UInt> UInt::operator=(const RValue<UInt> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UInt> UInt::operator=(const RValue<Int> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UInt> UInt::operator=(const UInt &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UInt>(value);
+ }
+
+ RValue<UInt> UInt::operator=(const Int &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UInt>(value);
+ }
+
+ RValue<Pointer<UInt>> UInt::operator&()
+ {
+ return RValue<Pointer<UInt>>(address);
+ }
+
+ RValue<UInt> operator+(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator-(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator*(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator/(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator%(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator&(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator|(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator^(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator<<(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator>>(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt> operator+=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UInt> operator-=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UInt> operator*=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<UInt> operator/=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<UInt> operator%=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<UInt> operator&=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UInt> operator|=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UInt> operator^=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UInt> operator<<=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt> operator>>=(const UInt &lhs, const RValue<UInt> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UInt> operator+(const RValue<UInt> &val)
+ {
+ return val;
+ }
+
+ RValue<UInt> operator-(const RValue<UInt> &val)
+ {
+ return RValue<UInt>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UInt> operator~(const RValue<UInt> &val)
+ {
+ return RValue<UInt>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UInt> operator++(const UInt &val, int) // Post-increment
+ {
+ RValue<UInt> res = val;
+
+ Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const UInt &operator++(const UInt &val) // Pre-increment
+ {
+ Value *inc = Nucleus::createAdd(Nucleus::createLoad(val.address), Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<UInt> operator--(const UInt &val, int) // Post-decrement
+ {
+ RValue<UInt> res = val;
+
+ Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return res;
+ }
+
+ const UInt &operator--(const UInt &val) // Pre-decrement
+ {
+ Value *inc = Nucleus::createSub(Nucleus::createLoad(val.address), Nucleus::createConstantInt(1));
+ Nucleus::createStore(inc, val.address);
+
+ return val;
+ }
+
+ RValue<Bool> operator<(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<UInt> &lhs, const RValue<UInt> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
+ }
+
+// RValue<UInt> RoundUInt(const RValue<Float> &cast)
+// {
+// return x86::cvtss2si(val); // FIXME: Unsigned
+//
+// // return IfThenElse(val > Float(0), Int(val + Float(0.5f)), Int(val - Float(0.5f)));
+// }
+
+ UInt *UInt::getThis()
+ {
+ return this;
+ }
+
+ const Type *UInt::getType()
+ {
+ return Type::getInt32Ty(*Nucleus::getContext());
+ }
+
+ Int2::Int2(const RValue<Int> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ 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));
+
+ Nucleus::createStore(replicate, address);
+ }
+
+ Int2::Int2(const RValue<Int4> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType());
+ Value *element = Nucleus::createExtractElement(long2, 0);
+ Value *int2 = Nucleus::createBitCast(element, Int2::getType());
+
+ Nucleus::createStore(int2, address);
+ }
+
+ Int2::Int2()
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Int2::Int2(int x, int y)
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[2];
+ constantVector[0] = Nucleus::createConstantInt(x);
+ constantVector[1] = Nucleus::createConstantInt(y);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 2), address);
+ }
+
+ Int2::Int2(const RValue<Int2> &rhs)
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Int2::Int2(const Int2 &rhs)
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Int2> Int2::operator=(const RValue<Int2> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Int2> Int2::operator=(const Int2 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Int2>(value);
+ }
+
+ RValue<Int2> operator+(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator-(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator*(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator/(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator%(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator&(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator|(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator^(const RValue<Int2> &lhs, const RValue<Int2> &rhs)
+ {
+ return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Int2> operator<<(const RValue<Int2> &lhs, unsigned char rhs)
+ {
+ // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return x86::pslld(lhs, rhs);
+ }
+
+ RValue<Int2> operator>>(const RValue<Int2> &lhs, unsigned char rhs)
+ {
+ // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
+
+ return x86::psrad(lhs, rhs);
+ }
+
+ RValue<Int2> operator<<(const RValue<Int2> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return x86::pslld(lhs, rhs);
+ }
+
+ RValue<Int2> operator>>(const RValue<Int2> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
+
+ return x86::psrad(lhs, rhs);
+ }
+
+ RValue<Int2> operator+=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Int2> operator-=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Int2> operator*=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Int2> operator/=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Int2> operator%=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Int2> operator&=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Int2> operator|=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Int2> operator^=(const Int2 &lhs, const RValue<Int2> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Int2> operator<<=(const Int2 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int2> operator>>=(const Int2 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Int2> operator+(const RValue<Int2> &val)
+ {
+ return val;
+ }
+
+ RValue<Int2> operator-(const RValue<Int2> &val)
+ {
+ return RValue<Int2>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Int2> operator~(const RValue<Int2> &val)
+ {
+ return RValue<Int2>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Long1> UnpackLow(const RValue<Int2> &x, const RValue<Int2> &y)
+ {
+ Constant *shuffle[2];
+ shuffle[0] = Nucleus::createConstantInt(0);
+ shuffle[1] = Nucleus::createConstantInt(2);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
+
+ return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
+ }
+
+ RValue<Long1> UnpackHigh(const RValue<Int2> &x, const RValue<Int2> &y)
+ {
+ Constant *shuffle[2];
+ shuffle[0] = Nucleus::createConstantInt(1);
+ shuffle[1] = Nucleus::createConstantInt(3);
+
+ Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
+
+ return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
+ }
+
+ RValue<Int> Extract(const RValue<Int2> &val, int i)
+ {
+ if(false) // FIXME: LLVM does not generate optimal code
+ {
+ return RValue<Int>(Nucleus::createExtractElement(val.value, i));
+ }
+ else
+ {
+ if(i == 0)
+ {
+ return RValue<Int>(Nucleus::createExtractElement(val.value, 0));
+ }
+ else
+ {
+ Int2 val2 = As<Int2>(UnpackHigh(val, val));
+
+ return Extract(val2, 0);
+ }
+ }
+ }
+
+ // FIXME: Crashes LLVM
+// RValue<Int2> Insert(const RValue<Int2> &val, const RValue<Int> &element, int i)
+// {
+// return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, Nucleus::createConstantInt(i)));
+// }
+
+ Int2 *Int2::getThis()
+ {
+ return this;
+ }
+
+ const Type *Int2::getType()
+ {
+ return VectorType::get(Int::getType(), 2);
+ }
+
+ UInt2::UInt2()
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ UInt2::UInt2(unsigned int x, unsigned int y)
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[2];
+ constantVector[0] = Nucleus::createConstantInt(x);
+ constantVector[1] = Nucleus::createConstantInt(y);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 2), address);
+ }
+
+ UInt2::UInt2(const RValue<UInt2> &rhs)
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UInt2::UInt2(const UInt2 &rhs)
+ {
+ // xy.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<UInt2> UInt2::operator=(const RValue<UInt2> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UInt2>(value);
+ }
+
+ RValue<UInt2> operator+(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator-(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator*(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator/(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator%(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator&(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator|(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator^(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs)
+ {
+ return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UInt2> operator<<(const RValue<UInt2> &lhs, unsigned char rhs)
+ {
+ // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
+ }
+
+ RValue<UInt2> operator>>(const RValue<UInt2> &lhs, unsigned char rhs)
+ {
+ // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
+
+ return x86::psrld(lhs, rhs);
+ }
+
+ RValue<UInt2> operator<<(const RValue<UInt2> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
+ }
+
+ RValue<UInt2> operator>>(const RValue<UInt2> &lhs, const RValue<Long1> &rhs)
+ {
+ // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
+
+ return x86::psrld(lhs, rhs);
+ }
+
+ RValue<UInt2> operator+=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UInt2> operator-=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UInt2> operator*=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<UInt2> operator/=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<UInt2> operator%=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<UInt2> operator&=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UInt2> operator|=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UInt2> operator^=(const UInt2 &lhs, const RValue<UInt2> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UInt2> operator<<=(const UInt2 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt2> operator>>=(const UInt2 &lhs, const RValue<Long1> &rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UInt2> operator+(const RValue<UInt2> &val)
+ {
+ return val;
+ }
+
+ RValue<UInt2> operator-(const RValue<UInt2> &val)
+ {
+ return RValue<UInt2>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UInt2> operator~(const RValue<UInt2> &val)
+ {
+ return RValue<UInt2>(Nucleus::createNot(val.value));
+ }
+
+ UInt2 *UInt2::getThis()
+ {
+ return this;
+ }
+
+ const Type *UInt2::getType()
+ {
+ return Int2::getType();
+ }
+
+ Int4::Int4(const RValue<Float4> &cast)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
+ // Value *xyzw = x86::cvttps2dq(cast).value;
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Int4::Int4()
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Int4::Int4(int xyzw)
+ {
+ constant(xyzw, xyzw, xyzw, xyzw);
+ }
+
+ Int4::Int4(int x, int yzw)
+ {
+ constant(x, yzw, yzw, yzw);
+ }
+
+ Int4::Int4(int x, int y, int zw)
+ {
+ constant(x, y, zw, zw);
+ }
+
+ Int4::Int4(int x, int y, int z, int w)
+ {
+ constant(x, y, z, w);
+ }
+
+ void Int4::constant(int x, int y, int z, int w)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantInt(x);
+ constantVector[1] = Nucleus::createConstantInt(y);
+ constantVector[2] = Nucleus::createConstantInt(z);
+ constantVector[3] = Nucleus::createConstantInt(w);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 4), address);
+ }
+
+ Int4::Int4(const RValue<Int4> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Int4::Int4(const Int4 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Int4> Int4::operator=(const RValue<Int4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Int4> Int4::operator=(const Int4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Int4>(value);
+ }
+
+ RValue<Int4> operator+(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator-(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator*(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator/(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator%(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator&(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator|(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator^(const RValue<Int4> &lhs, const RValue<Int4> &rhs)
+ {
+ return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<Int4> operator<<(const RValue<Int4> &lhs, unsigned char rhs)
+ {
+ // return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return x86::pslld(lhs, rhs);
+ }
+
+ RValue<Int4> operator>>(const RValue<Int4> &lhs, unsigned char rhs)
+ {
+ // return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
+
+ return x86::psrad(lhs, rhs);
+ }
+
+ RValue<Int4> operator+=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Int4> operator-=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Int4> operator*=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Int4> operator/=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Int4> operator%=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Int4> operator&=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<Int4> operator|=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<Int4> operator^=(const Int4 &lhs, const RValue<Int4> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<Int4> operator+(const RValue<Int4> &val)
+ {
+ return val;
+ }
+
+ RValue<Int4> operator-(const RValue<Int4> &val)
+ {
+ return RValue<Int4>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<Int4> operator~(const RValue<Int4> &val)
+ {
+ return RValue<Int4>(Nucleus::createNot(val.value));
+ }
+
+ RValue<Int4> RoundInt(const RValue<Float4> &cast)
+ {
+ return x86::cvtps2dq(cast);
+ }
+
+ RValue<Short8> Pack(const RValue<Int4> &x, const RValue<Int4> &y)
+ {
+ return x86::packssdw(x, y);
+ }
+
+ RValue<Int4> Concatenate(const RValue<Int2> &lo, const RValue<Int2> &hi)
+ {
+ Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
+ Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
+
+ Value *long2 = UndefValue::get(Long2::getType());
+ long2 = Nucleus::createInsertElement(long2, loLong, 0);
+ long2 = Nucleus::createInsertElement(long2, hiLong, 1);
+ Value *int4 = Nucleus::createBitCast(long2, Int4::getType());
+
+ return RValue<Int4>(int4);
+ }
+
+ RValue<Int> Extract(const RValue<Int4> &x, int i)
+ {
+ return RValue<Int>(Nucleus::createExtractElement(x.value, i));
+ }
+
+ RValue<Int4> Insert(const RValue<Int4> &x, const RValue<Int> &element, int i)
+ {
+ return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
+ }
+
+ RValue<Int> SignMask(const RValue<Int4> &x)
+ {
+ return x86::movmskps(As<Float4>(x));
+ }
+
+ RValue<Int4> Swizzle(const RValue<Int4> &x, unsigned char select)
+ {
+ return RValue<Int4>(Nucleus::createSwizzle(x.value, select));
+ }
+
+ Int4 *Int4::getThis()
+ {
+ return this;
+ }
+
+ const Type *Int4::getType()
+ {
+ return VectorType::get(Int::getType(), 4);
+ }
+
+ UInt4::UInt4(const RValue<Float4> &cast)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ UInt4::UInt4()
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ UInt4::UInt4(unsigned int x, unsigned int y, unsigned int z, unsigned int w)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantInt(x);
+ constantVector[1] = Nucleus::createConstantInt(y);
+ constantVector[2] = Nucleus::createConstantInt(z);
+ constantVector[3] = Nucleus::createConstantInt(w);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 4), address);
+ }
+
+ UInt4::UInt4(const RValue<UInt4> &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ UInt4::UInt4(const UInt4 &rhs)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<UInt4> UInt4::operator=(const RValue<UInt4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<UInt4>(value);
+ }
+
+ RValue<UInt4> operator+(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator-(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator*(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator/(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator%(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator&(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator|(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator^(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs)
+ {
+ return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
+ }
+
+ RValue<UInt4> operator<<(const RValue<UInt4> &lhs, unsigned char rhs)
+ {
+ // return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
+
+ return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
+ }
+
+ RValue<UInt4> operator>>(const RValue<UInt4> &lhs, unsigned char rhs)
+ {
+ // return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
+
+ return x86::psrld(lhs, rhs);
+ }
+
+ RValue<UInt4> operator+=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<UInt4> operator-=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<UInt4> operator*=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<UInt4> operator/=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<UInt4> operator%=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<UInt4> operator&=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs & rhs;
+ }
+
+ RValue<UInt4> operator|=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs | rhs;
+ }
+
+ RValue<UInt4> operator^=(const UInt4 &lhs, const RValue<UInt4> &rhs)
+ {
+ return lhs = lhs ^ rhs;
+ }
+
+ RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs << rhs;
+ }
+
+ RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
+ {
+ return lhs = lhs >> rhs;
+ }
+
+ RValue<UInt4> operator+(const RValue<UInt4> &val)
+ {
+ return val;
+ }
+
+ RValue<UInt4> operator-(const RValue<UInt4> &val)
+ {
+ return RValue<UInt4>(Nucleus::createNeg(val.value));
+ }
+
+ RValue<UInt4> operator~(const RValue<UInt4> &val)
+ {
+ return RValue<UInt4>(Nucleus::createNot(val.value));
+ }
+
+ RValue<UShort8> Pack(const RValue<UInt4> &x, const RValue<UInt4> &y)
+ {
+ return x86::packusdw(x, y); // FIXME: Fallback required
+ }
+
+ RValue<UInt4> Concatenate(const RValue<UInt2> &lo, const RValue<UInt2> &hi)
+ {
+ Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
+ Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
+
+ Value *long2 = UndefValue::get(Long2::getType());
+ long2 = Nucleus::createInsertElement(long2, loLong, 0);
+ long2 = Nucleus::createInsertElement(long2, hiLong, 1);
+ Value *uint4 = Nucleus::createBitCast(long2, Int4::getType());
+
+ return RValue<UInt4>(uint4);
+ }
+
+ UInt4 *UInt4::getThis()
+ {
+ return this;
+ }
+
+ const Type *UInt4::getType()
+ {
+ return VectorType::get(UInt::getType(), 4);
+ }
+
+ Float::Float(const RValue<Int> &cast)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
+
+ Nucleus::createStore(integer, address);
+ }
+
+ Float::Float()
+ {
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Float::Float(float x)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(Nucleus::createConstantFloat(x), address);
+ }
+
+ Float::Float(const RValue<Float> &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Float::Float(const Float &rhs)
+ {
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ RValue<Float> Float::operator=(const RValue<Float> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Float> Float::operator=(const Float &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Float>(value);
+ }
+
+ RValue<Pointer<Float>> Float::operator&()
+ {
+ return RValue<Pointer<Float>>(address);
+ }
+
+ RValue<Float> operator+(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator-(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator*(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator/(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Float> operator+=(const Float &lhs, const RValue<Float> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Float> operator-=(const Float &lhs, const RValue<Float> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Float> operator*=(const Float &lhs, const RValue<Float> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Float> operator/=(const Float &lhs, const RValue<Float> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Float> operator+(const RValue<Float> &val)
+ {
+ return val;
+ }
+
+ RValue<Float> operator-(const RValue<Float> &val)
+ {
+ return RValue<Float>(Nucleus::createFNeg(val.value));
+ }
+
+ RValue<Bool> operator<(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator<=(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator>=(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator!=(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
+ }
+
+ RValue<Bool> operator==(const RValue<Float> &lhs, const RValue<Float> &rhs)
+ {
+ return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
+ }
+
+ RValue<Float> Abs(const RValue<Float> &x)
+ {
+ return IfThenElse(x > Float(0), x, -x);
+ }
+
+ RValue<Float> Max(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return IfThenElse(x > y, x, y);
+ }
+
+ RValue<Float> Min(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return IfThenElse(x < y, x, y);
+ }
+
+ RValue<Float> Rcp_pp(const RValue<Float> &x)
+ {
+ return x86::rcpss(x);
+ }
+
+ RValue<Float> RcpSqrt_pp(const RValue<Float> &x)
+ {
+ return x86::rsqrtss(x);
+ }
+
+ RValue<Float> Sqrt(const RValue<Float> &x)
+ {
+ return x86::sqrtss(x);
+ }
+
+ RValue<Float> Fraction(const RValue<Float> &x)
+ {
+ if(CPUID::supportsSSE4_1())
+ {
+ return x - x86::floorss(x);
+ }
+ else
+ {
+ return Float4(Fraction(Float4(x))).x;
+ }
+ }
+
+ RValue<Float> Floor(const RValue<Float> &x)
+ {
+ if(CPUID::supportsSSE4_1())
+ {
+ return x86::floorss(x);
+ }
+ else
+ {
+ return Float4(Floor(Float4(x))).x;
+ }
+ }
+
+ Float *Float::getThis()
+ {
+ return this;
+ }
+
+ const Type *Float::getType()
+ {
+ return Type::getFloatTy(*Nucleus::getContext());
+ }
+
+ Float2::Float2(const RValue<Float4> &cast)
+ {
+ // xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
+ Value *int64 = Nucleus::createExtractElement(int64x2, 0);
+ Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
+
+ Nucleus::createStore(float2, address);
+ }
+
+ Float2 *Float2::getThis()
+ {
+ return this;
+ }
+
+ const Type *Float2::getType()
+ {
+ return VectorType::get(Float::getType(), 2);
+ }
+
+ Float4::Float4(const RValue<Byte4> &cast)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ #if 0
+ Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
+ #elif 0
+ Value *vector = Nucleus::createLoad(address);
+
+ Value *i8x = Nucleus::createExtractElement(cast.value, 0);
+ Value *f32x = Nucleus::createUIToFP(i8x, Float::getType());
+ Value *x = Nucleus::createInsertElement(vector, f32x, 0);
+
+ Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
+ Value *f32y = Nucleus::createUIToFP(i8y, Float::getType());
+ Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
+
+ Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
+ Value *f32z = Nucleus::createUIToFP(i8z, Float::getType());
+ Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
+
+ Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
+ Value *f32w = Nucleus::createUIToFP(i8w, Float::getType());
+ Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
+ #else
+ Value *x = Nucleus::createBitCast(cast.value, Int::getType());
+ Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
+
+ Value *e;
+
+ if(CPUID::supportsSSE4_1())
+ {
+ e = x86::pmovzxbd(RValue<Int4>(a)).value;
+ }
+ else
+ {
+ Constant *swizzle[16];
+ swizzle[0] = Nucleus::createConstantInt(0);
+ swizzle[1] = Nucleus::createConstantInt(16);
+ swizzle[2] = Nucleus::createConstantInt(1);
+ swizzle[3] = Nucleus::createConstantInt(17);
+ swizzle[4] = Nucleus::createConstantInt(2);
+ swizzle[5] = Nucleus::createConstantInt(18);
+ swizzle[6] = Nucleus::createConstantInt(3);
+ swizzle[7] = Nucleus::createConstantInt(19);
+ swizzle[8] = Nucleus::createConstantInt(4);
+ swizzle[9] = Nucleus::createConstantInt(20);
+ swizzle[10] = Nucleus::createConstantInt(5);
+ swizzle[11] = Nucleus::createConstantInt(21);
+ swizzle[12] = Nucleus::createConstantInt(6);
+ swizzle[13] = Nucleus::createConstantInt(22);
+ swizzle[14] = Nucleus::createConstantInt(7);
+ swizzle[15] = Nucleus::createConstantInt(23);
+
+ Value *b = Nucleus::createBitCast(a, Byte16::getType());
+ Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16));
+
+ Constant *swizzle2[8];
+ swizzle2[0] = Nucleus::createConstantInt(0);
+ swizzle2[1] = Nucleus::createConstantInt(8);
+ swizzle2[2] = Nucleus::createConstantInt(1);
+ swizzle2[3] = Nucleus::createConstantInt(9);
+ swizzle2[4] = Nucleus::createConstantInt(2);
+ swizzle2[5] = Nucleus::createConstantInt(10);
+ swizzle2[6] = Nucleus::createConstantInt(3);
+ swizzle2[7] = Nucleus::createConstantInt(11);
+
+ Value *d = Nucleus::createBitCast(c, Short8::getType());
+ e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8));
+ }
+
+ Value *f = Nucleus::createBitCast(e, Int4::getType());
+ // Value *g = Nucleus::createSIToFP(f, Float4::getType());
+ Value *g = x86::cvtdq2ps(RValue<Int4>(f)).value;
+ Value *xyzw = g;
+ #endif
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Float4::Float4(const RValue<SByte4> &cast)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ #if 0
+ Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
+ #elif 0
+ Value *vector = Nucleus::createLoad(address);
+
+ Value *i8x = Nucleus::createExtractElement(cast.value, 0);
+ Value *f32x = Nucleus::createSIToFP(i8x, Float::getType());
+ Value *x = Nucleus::createInsertElement(vector, f32x, 0);
+
+ Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
+ Value *f32y = Nucleus::createSIToFP(i8y, Float::getType());
+ Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
+
+ Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
+ Value *f32z = Nucleus::createSIToFP(i8z, Float::getType());
+ Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
+
+ Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
+ Value *f32w = Nucleus::createSIToFP(i8w, Float::getType());
+ Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
+ #else
+ Value *x = Nucleus::createBitCast(cast.value, Int::getType());
+ Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
+
+ Value *g;
+
+ if(CPUID::supportsSSE4_1())
+ {
+ g = x86::pmovsxbd(RValue<Int4>(a)).value;
+ }
+ else
+ {
+ Constant *swizzle[16];
+ swizzle[0] = Nucleus::createConstantInt(0);
+ swizzle[1] = Nucleus::createConstantInt(0);
+ swizzle[2] = Nucleus::createConstantInt(1);
+ swizzle[3] = Nucleus::createConstantInt(1);
+ swizzle[4] = Nucleus::createConstantInt(2);
+ swizzle[5] = Nucleus::createConstantInt(2);
+ swizzle[6] = Nucleus::createConstantInt(3);
+ swizzle[7] = Nucleus::createConstantInt(3);
+ swizzle[8] = Nucleus::createConstantInt(4);
+ swizzle[9] = Nucleus::createConstantInt(4);
+ swizzle[10] = Nucleus::createConstantInt(5);
+ swizzle[11] = Nucleus::createConstantInt(5);
+ swizzle[12] = Nucleus::createConstantInt(6);
+ swizzle[13] = Nucleus::createConstantInt(6);
+ swizzle[14] = Nucleus::createConstantInt(7);
+ swizzle[15] = Nucleus::createConstantInt(7);
+
+ Value *b = Nucleus::createBitCast(a, Byte16::getType());
+ Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16));
+
+ Constant *swizzle2[8];
+ swizzle2[0] = Nucleus::createConstantInt(0);
+ swizzle2[1] = Nucleus::createConstantInt(0);
+ swizzle2[2] = Nucleus::createConstantInt(1);
+ swizzle2[3] = Nucleus::createConstantInt(1);
+ swizzle2[4] = Nucleus::createConstantInt(2);
+ swizzle2[5] = Nucleus::createConstantInt(2);
+ swizzle2[6] = Nucleus::createConstantInt(3);
+ swizzle2[7] = Nucleus::createConstantInt(3);
+
+ Value *d = Nucleus::createBitCast(c, Short8::getType());
+ Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8));
+
+ Value *f = Nucleus::createBitCast(e, Int4::getType());
+ // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24));
+ g = x86::psrad(RValue<Int4>(f), 24).value;
+ }
+
+ // Value *h = Nucleus::createSIToFP(g, Float4::getType());
+ Value *h = x86::cvtdq2ps(RValue<Int4>(g)).value;
+ Value *xyzw = h;
+ #endif
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Float4::Float4(const RValue<Short4> &cast)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ #if 0
+ Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
+ #elif 0
+ Value *vector = Nucleus::createLoad(address);
+
+ Value *i16x = Nucleus::createExtractElement(cast.value, 0);
+ Value *f32x = Nucleus::createSIToFP(i16x, Float::getType());
+ Value *x = Nucleus::createInsertElement(vector, f32x, 0);
+
+ Value *i16y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
+ Value *f32y = Nucleus::createSIToFP(i16y, Float::getType());
+ Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
+
+ Value *i16z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
+ Value *f32z = Nucleus::createSIToFP(i16z, Float::getType());
+ Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
+
+ Value *i16w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
+ Value *f32w = Nucleus::createSIToFP(i16w, Float::getType());
+ Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
+ #else
+ Value *long2 = UndefValue::get(Long2::getType());
+ Value *element = Nucleus::createBitCast(cast.value, Long::getType());
+ long2 = Nucleus::createInsertElement(long2, element, 0);
+ RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
+
+ Value *xyzw;
+
+ if(CPUID::supportsSSE4_1())
+ {
+ Value *c = x86::pmovsxwd(vector).value;
+
+ // xyzw = Nucleus::createSIToFP(d, Float4::getType());
+ xyzw = x86::cvtdq2ps(RValue<Int4>(c)).value;
+ }
+ else
+ {
+ Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
+
+ Constant *swizzle[8];
+ swizzle[0] = Nucleus::createConstantInt(0);
+ swizzle[1] = Nucleus::createConstantInt(0);
+ swizzle[2] = Nucleus::createConstantInt(1);
+ swizzle[3] = Nucleus::createConstantInt(1);
+ swizzle[4] = Nucleus::createConstantInt(2);
+ swizzle[5] = Nucleus::createConstantInt(2);
+ swizzle[6] = Nucleus::createConstantInt(3);
+ swizzle[7] = Nucleus::createConstantInt(3);
+
+ Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8));
+ Value *d = Nucleus::createBitCast(c, Int4::getType());
+
+ // Value *e = Nucleus::createSIToFP(d, Float4::getType());
+ Value *e = x86::cvtdq2ps(RValue<Int4>(d)).value;
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantFloat(1.0f / (1 << 16));
+ constantVector[1] = Nucleus::createConstantFloat(1.0f / (1 << 16));
+ constantVector[2] = Nucleus::createConstantFloat(1.0f / (1 << 16));
+ constantVector[3] = Nucleus::createConstantFloat(1.0f / (1 << 16));
+
+ xyzw = Nucleus::createFMul(e, Nucleus::createConstantVector(constantVector, 4));
+ }
+ #endif
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Float4::Float4(const RValue<UShort4> &cast)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ #if 0
+ Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
+ #elif 0
+ Value *vector = Nucleus::createLoad(address);
+
+ Value *i16x = Nucleus::createExtractElement(cast.value, 0);
+ Value *f32x = Nucleus::createUIToFP(i16x, Float::getType());
+ Value *x = Nucleus::createInsertElement(vector, f32x, 0);
+
+ Value *i16y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
+ Value *f32y = Nucleus::createUIToFP(i16y, Float::getType());
+ Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
+
+ Value *i16z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
+ Value *f32z = Nucleus::createUIToFP(i16z, Float::getType());
+ Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
+
+ Value *i16w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
+ Value *f32w = Nucleus::createUIToFP(i16w, Float::getType());
+ Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
+ #else
+ Value *long2 = UndefValue::get(Long2::getType());
+ Value *element = Nucleus::createBitCast(cast.value, Long::getType());
+ long2 = Nucleus::createInsertElement(long2, element, 0);
+ RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
+
+ Value *c;
+
+ if(CPUID::supportsSSE4_1())
+ {
+ c = x86::pmovzxwd(RValue<Int4>(vector)).value;
+ }
+ else
+ {
+ Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
+
+ Constant *swizzle[8];
+ swizzle[0] = Nucleus::createConstantInt(0);
+ swizzle[1] = Nucleus::createConstantInt(8);
+ swizzle[2] = Nucleus::createConstantInt(1);
+ swizzle[3] = Nucleus::createConstantInt(9);
+ swizzle[4] = Nucleus::createConstantInt(2);
+ swizzle[5] = Nucleus::createConstantInt(10);
+ swizzle[6] = Nucleus::createConstantInt(3);
+ swizzle[7] = Nucleus::createConstantInt(11);
+
+ c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8));
+ }
+
+ Value *d = Nucleus::createBitCast(c, Int4::getType());
+ // Value *e = Nucleus::createSIToFP(d, Float4::getType());
+ Value *e = x86::cvtdq2ps(RValue<Int4>(d)).value;
+ Value *xyzw = e;
+ #endif
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Float4::Float4(const RValue<Int4> &cast)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
+ // Value *xyzw = x86::cvtdq2ps(cast).value;
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Float4::Float4(const RValue<UInt4> &cast)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
+
+ Nucleus::createStore(xyzw, address);
+ }
+
+ Float4::Float4()
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+ }
+
+ Float4::Float4(float xyzw)
+ {
+ constant(xyzw, xyzw, xyzw, xyzw);
+ }
+
+ Float4::Float4(float x, float yzw)
+ {
+ constant(x, yzw, yzw, yzw);
+ }
+
+ Float4::Float4(float x, float y, float zw)
+ {
+ constant(x, y, zw, zw);
+ }
+
+ Float4::Float4(float x, float y, float z, float w)
+ {
+ constant(x, y, z, w);
+ }
+
+ void Float4::constant(float x, float y, float z, float w)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantFloat(x);
+ constantVector[1] = Nucleus::createConstantFloat(y);
+ constantVector[2] = Nucleus::createConstantFloat(z);
+ constantVector[3] = Nucleus::createConstantFloat(w);
+
+ Nucleus::createStore(Nucleus::createConstantVector(constantVector, 4), address);
+ }
+
+ Float4::Float4(const RValue<Float4> &rhs)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ Float4::Float4(const Float4 &rhs)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ Float4::Float4(const RValue<Float> &rhs)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *vector = Nucleus::createLoad(address);
+ Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
+
+ Constant *swizzle[4];
+ swizzle[0] = Nucleus::createConstantInt(0);
+ swizzle[1] = Nucleus::createConstantInt(0);
+ swizzle[2] = Nucleus::createConstantInt(0);
+ swizzle[3] = Nucleus::createConstantInt(0);
+
+ Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4));
+
+ Nucleus::createStore(replicate, address);
+ }
+
+ Float4::Float4(const Float &rhs)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ Value *vector = Nucleus::createLoad(address);
+ Value *element = Nucleus::createLoad(rhs.address);
+ Value *insert = Nucleus::createInsertElement(vector, element, 0);
+
+ Constant *swizzle[4];
+ swizzle[0] = Nucleus::createConstantInt(0);
+ swizzle[1] = Nucleus::createConstantInt(0);
+ swizzle[2] = Nucleus::createConstantInt(0);
+ swizzle[3] = Nucleus::createConstantInt(0);
+
+ Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4));
+
+ Nucleus::createStore(replicate, address);
+ }
+
+ RValue<Float4> Float4::operator=(float x) const
+ {
+ return *this = Float4(x, x, x, x);
+ }
+
+ RValue<Float4> Float4::operator=(const RValue<Float4> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ RValue<Float4> Float4::operator=(const Float4 &rhs) const
+ {
+ Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Float4>(value);
+ }
+
+ RValue<Float4> Float4::operator=(const RValue<Float> &rhs) const
+ {
+ return *this = Float4(rhs);
+ }
+
+ RValue<Float4> Float4::operator=(const Float &rhs) const
+ {
+ return *this = Float4(rhs);
+ }
+
+ RValue<Pointer<Float4>> Float4::operator&()
+ {
+ return RValue<Pointer<Float4>>(address);
+ }
+
+ RValue<Float4> operator+(const RValue<Float4> &lhs, const RValue<Float4> &rhs)
+ {
+ return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator-(const RValue<Float4> &lhs, const RValue<Float4> &rhs)
+ {
+ return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator*(const RValue<Float4> &lhs, const RValue<Float4> &rhs)
+ {
+ return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator/(const RValue<Float4> &lhs, const RValue<Float4> &rhs)
+ {
+ return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator%(const RValue<Float4> &lhs, const RValue<Float4> &rhs)
+ {
+ return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
+ }
+
+ RValue<Float4> operator+=(const Float4 &lhs, const RValue<Float4> &rhs)
+ {
+ return lhs = lhs + rhs;
+ }
+
+ RValue<Float4> operator-=(const Float4 &lhs, const RValue<Float4> &rhs)
+ {
+ return lhs = lhs - rhs;
+ }
+
+ RValue<Float4> operator*=(const Float4 &lhs, const RValue<Float4> &rhs)
+ {
+ return lhs = lhs * rhs;
+ }
+
+ RValue<Float4> operator/=(const Float4 &lhs, const RValue<Float4> &rhs)
+ {
+ return lhs = lhs / rhs;
+ }
+
+ RValue<Float4> operator%=(const Float4 &lhs, const RValue<Float4> &rhs)
+ {
+ return lhs = lhs % rhs;
+ }
+
+ RValue<Float4> operator+(const RValue<Float4> &val)
+ {
+ return val;
+ }
+
+ RValue<Float4> operator-(const RValue<Float4> &val)
+ {
+ return RValue<Float4>(Nucleus::createFNeg(val.value));
+ }
+
+ RValue<Float4> Abs(const RValue<Float4> &x)
+ {
+ Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
+
+ Constant *constantVector[4];
+ constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF);
+ constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF);
+ constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF);
+ constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF);
+
+ Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4));
+
+ return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType()));
+ }
+
+ RValue<Float4> Max(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return x86::maxps(x, y);
+ }
+
+ RValue<Float4> Min(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return x86::minps(x, y);
+ }
+
+ RValue<Float4> Rcp_pp(const RValue<Float4> &x)
+ {
+ return x86::rcpps(x);
+ }
+
+ RValue<Float4> RcpSqrt_pp(const RValue<Float4> &x)
+ {
+ return x86::rsqrtps(x);
+ }
+
+ RValue<Float4> Sqrt(const RValue<Float4> &x)
+ {
+ return x86::sqrtps(x);
+ }
+
+ RValue<Float4> Insert(const Float4 &val, const RValue<Float> &element, int i)
+ {
+ llvm::Value *value = Nucleus::createLoad(val.address);
+ llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i);
+
+ val = RValue<Float4>(insert);
+
+ return val;
+ }
+
+ RValue<Float> Extract(const RValue<Float4> &x, int i)
+ {
+ return RValue<Float>(Nucleus::createExtractElement(x.value, i));
+ }
+
+ RValue<Float4> Swizzle(const RValue<Float4> &x, unsigned char select)
+ {
+ return RValue<Float4>(Nucleus::createSwizzle(x.value, select));
+ }
+
+ RValue<Float4> ShuffleLowHigh(const RValue<Float4> &x, const RValue<Float4> &y, unsigned char imm)
+ {
+ Constant *shuffle[4];
+ shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0);
+ shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0);
+ shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4);
+ shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4);
+
+ return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
+ }
+
+ RValue<Float4> UnpackLow(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ Constant *shuffle[4];
+ shuffle[0] = Nucleus::createConstantInt(0);
+ shuffle[1] = Nucleus::createConstantInt(4);
+ shuffle[2] = Nucleus::createConstantInt(1);
+ shuffle[3] = Nucleus::createConstantInt(5);
+
+ return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
+ }
+
+ RValue<Float4> UnpackHigh(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ Constant *shuffle[4];
+ shuffle[0] = Nucleus::createConstantInt(2);
+ shuffle[1] = Nucleus::createConstantInt(6);
+ shuffle[2] = Nucleus::createConstantInt(3);
+ shuffle[3] = Nucleus::createConstantInt(7);
+
+ return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
+ }
+
+ RValue<Float4> Mask(Float4 &lhs, const RValue<Float4> &rhs, unsigned char select)
+ {
+ Value *vector = Nucleus::createLoad(lhs.address);
+ Value *shuffle = Nucleus::createMask(vector, rhs.value, select);
+ Nucleus::createStore(shuffle, lhs.address);
+
+ return RValue<Float4>(shuffle);
+ }
+
+ RValue<Int> SignMask(const RValue<Float4> &x)
+ {
+ return x86::movmskps(x);
+ }
+
+ RValue<Int4> CmpEQ(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ // return As<Int4>(x86::cmpeqps(x, y));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
+ }
+
+ RValue<Int4> CmpLT(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ // return As<Int4>(x86::cmpltps(x, y));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
+ }
+
+ RValue<Int4> CmpLE(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ // return As<Int4>(x86::cmpleps(x, y));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
+ }
+
+ RValue<Int4> CmpNEQ(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ // return As<Int4>(x86::cmpneqps(x, y));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
+ }
+
+ RValue<Int4> CmpNLT(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ // return As<Int4>(x86::cmpnltps(x, y));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
+ }
+
+ RValue<Int4> CmpNLE(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ // return As<Int4>(x86::cmpnleps(x, y));
+ return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
+ }
+
+ RValue<Float4> Fraction(const RValue<Float4> &x)
+ {
+ if(CPUID::supportsSSE4_1())
+ {
+ return x - x86::floorps(x);
+ }
+ else
+ {
+ Float4 frc = x - Float4(Int4(x)); // Signed fraction
+
+ return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0, 0, 0, 0), frc)) & As<Int4>(Float4(1, 1, 1, 1)));
+ }
+ }
+
+ RValue<Float4> Floor(const RValue<Float4> &x)
+ {
+ if(CPUID::supportsSSE4_1())
+ {
+ return x86::floorps(x);
+ }
+ else
+ {
+ Float4 trunc = Float4(Int4(x)); // Rounded toward zero
+
+ return trunc + As<Float4>(As<Int4>(CmpNLE(Float4(0, 0, 0, 0), trunc)) & As<Int4>(Float4(1, 1, 1, 1)));
+ }
+ }
+
+ Float4 *Float4::getThis()
+ {
+ return this;
+ }
+
+ const Type *Float4::getType()
+ {
+ return VectorType::get(Float::getType(), 4);
+ }
+
+ RValue<Pointer<Byte>> operator+(const RValue<Pointer<Byte>> &lhs, int offset)
+ {
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
+ }
+
+ RValue<Pointer<Byte>> operator+(const RValue<Pointer<Byte>> &lhs, const RValue<Int> &offset)
+ {
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
+ }
+
+ RValue<Pointer<Byte>> operator+(const RValue<Pointer<Byte>> &lhs, const RValue<UInt> &offset)
+ {
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
+ }
+
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
+ {
+ return lhs = lhs + offset;
+ }
+
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, const RValue<Int> &offset)
+ {
+ return lhs = lhs + offset;
+ }
+
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, const RValue<UInt> &offset)
+ {
+ return lhs = lhs + offset;
+ }
+
+ RValue<Pointer<Byte>> operator-(const RValue<Pointer<Byte>> &lhs, int offset)
+ {
+ return lhs + -offset;
+ }
+
+ RValue<Pointer<Byte>> operator-(const RValue<Pointer<Byte>> &lhs, const RValue<Int> &offset)
+ {
+ return lhs + -offset;
+ }
+
+ RValue<Pointer<Byte>> operator-(const RValue<Pointer<Byte>> &lhs, const RValue<UInt> &offset)
+ {
+ return lhs + -offset;
+ }
+
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset)
+ {
+ return lhs = lhs - offset;
+ }
+
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, const RValue<Int> &offset)
+ {
+ return lhs = lhs - offset;
+ }
+
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, const RValue<UInt> &offset)
+ {
+ return lhs = lhs - offset;
+ }
+
+ void Return()
+ {
+ #if !(defined(_M_AMD64) || defined(_M_X64))
+ x86::emms();
+ #endif
+
+ Nucleus::createRetVoid();
+ Nucleus::setInsertBlock(Nucleus::createBasicBlock());
+ }
+
+ void Return(const Int &ret)
+ {
+ #if !(defined(_M_AMD64) || defined(_M_X64))
+ x86::emms();
+ #endif
+
+ Nucleus::createRet(Nucleus::createLoad(ret.address));
+ Nucleus::setInsertBlock(Nucleus::createBasicBlock());
+ }
+
+ BasicBlock *beginLoop()
+ {
+ BasicBlock *loopBB = Nucleus::createBasicBlock();
+
+ Nucleus::createBr(loopBB);
+ Nucleus::getBuilder()->SetInsertPoint(loopBB);
+
+ return loopBB;
+ }
+
+ bool branch(const RValue<Bool> &cmp, BasicBlock *bodyBB, BasicBlock *endBB)
+ {
+ Nucleus::createCondBr(cmp.value, bodyBB, endBB);
+ Nucleus::getBuilder()->SetInsertPoint(bodyBB);
+
+ return true;
+ }
+
+ bool elseBlock(BasicBlock *falseBB)
+ {
+ falseBB->back().eraseFromParent();
+ Nucleus::getBuilder()->SetInsertPoint(falseBB);
+
+ return true;
+ }
+
+ RValue<Long> Ticks()
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *rdtsc = Intrinsic::getDeclaration(module, Intrinsic::readcyclecounter);
+
+ return RValue<Long>(Nucleus::createCall(rdtsc));
+ }
+
+ void Emms()
+ {
+ x86::emms();
+ }
+}
+
+namespace sw
+{
+ namespace x86
+ {
+ RValue<Int> cvtss2si(const RValue<Float> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvtss2si = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtss2si);
+
+ Float4 vector;
+ vector.x = val;
+
+ return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value));
+ }
+
+ RValue<Int2> cvtps2pi(const RValue<Float4> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvtps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtps2pi);
+
+ return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value));
+ }
+
+ RValue<Int2> cvttps2pi(const RValue<Float4> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvttps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvttps2pi);
+
+ return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value));
+ }
+
+ RValue<Int4> cvtps2dq(const RValue<Float4> &val)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvtps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtps2dq);
+
+ return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value));
+ }
+ else
+ {
+ Int2 lo = x86::cvtps2pi(val);
+ Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE));
+
+ return Concatenate(lo, hi);
+ }
+ }
+
+ RValue<Int4> cvttps2dq(const RValue<Float4> &val)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvttps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvttps2dq);
+
+ return RValue<Int4>(Nucleus::createCall(cvttps2dq, val.value));
+ }
+ else
+ {
+ Int2 lo = x86::cvttps2pi(val);
+ Int2 hi = x86::cvttps2pi(Swizzle(val, 0xEE));
+
+ return Concatenate(lo, hi);
+ }
+ }
+
+ RValue<Float4> cvtpi2ps(const RValue<Float4> &x, const RValue<Int2> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvtpi2ps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtpi2ps);
+
+ return RValue<Float4>(Nucleus::createCall(cvtpi2ps, x.value, y.value));
+ }
+
+ RValue<Float4> cvtdq2ps(const RValue<Int4> &val)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cvtdq2ps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtdq2ps);
+
+ return RValue<Float4>(Nucleus::createCall(cvtdq2ps, val.value));
+ }
+ else
+ {
+ Int2 lo = Int2(val);
+ Int2 hi = Int2(Swizzle(val, 0xEE));
+
+ Float4 scratch1;
+ Float4 scratch2;
+
+ return Float4(Float4(x86::cvtpi2ps(scratch1, lo)).xy, Float4(x86::cvtpi2ps(scratch2, hi)).xy);
+ }
+ }
+
+ RValue<Float> rcpss(const RValue<Float> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *rcpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ss);
+
+ Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
+
+ return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rcpss, vector), 0));
+ }
+
+ RValue<Float> sqrtss(const RValue<Float> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *sqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ss);
+
+ Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
+
+ return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0));
+ }
+
+ RValue<Float> rsqrtss(const RValue<Float> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *rsqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ss);
+
+ Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
+
+ return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0));
+ }
+
+ RValue<Float4> rcpps(const RValue<Float4> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *rcpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ps);
+
+ return RValue<Float4>(Nucleus::createCall(rcpps, val.value));
+ }
+
+ RValue<Float4> sqrtps(const RValue<Float4> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *sqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ps);
+
+ return RValue<Float4>(Nucleus::createCall(sqrtps, val.value));
+ }
+
+ RValue<Float4> rsqrtps(const RValue<Float4> &val)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *rsqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ps);
+
+ return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value));
+ }
+
+ RValue<Float4> maxps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *maxps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_max_ps);
+
+ return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value));
+ }
+
+ RValue<Float4> minps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *minps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_min_ps);
+
+ return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value));
+ }
+
+ RValue<Float> roundss(const RValue<Float> &val, unsigned char imm)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *roundss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ss);
+
+ Value *undef = UndefValue::get(Float4::getType());
+ Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
+
+ return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0));
+ }
+
+ RValue<Float> floorss(const RValue<Float> &val)
+ {
+ return roundss(val, 1);
+ }
+
+ RValue<Float> ceilss(const RValue<Float> &val)
+ {
+ return roundss(val, 2);
+ }
+
+ RValue<Float4> roundps(const RValue<Float4> &val, unsigned char imm)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *roundps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ps);
+
+ return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm)));
+ }
+
+ RValue<Float4> floorps(const RValue<Float4> &val)
+ {
+ return roundps(val, 1);
+ }
+
+ RValue<Float4> ceilps(const RValue<Float4> &val)
+ {
+ return roundps(val, 2);
+ }
+
+ RValue<Float4> cmpps(const RValue<Float4> &x, const RValue<Float4> &y, unsigned char imm)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cmpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ps);
+
+ return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm)));
+ }
+
+ RValue<Float4> cmpeqps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 0);
+ }
+
+ RValue<Float4> cmpltps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 1);
+ }
+
+ RValue<Float4> cmpleps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 2);
+ }
+
+ RValue<Float4> cmpunordps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 3);
+ }
+
+ RValue<Float4> cmpneqps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 4);
+ }
+
+ RValue<Float4> cmpnltps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 5);
+ }
+
+ RValue<Float4> cmpnleps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 6);
+ }
+
+ RValue<Float4> cmpordps(const RValue<Float4> &x, const RValue<Float4> &y)
+ {
+ return cmpps(x, y, 7);
+ }
+
+ RValue<Float> cmpss(const RValue<Float> &x, const RValue<Float> &y, unsigned char imm)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *cmpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ss);
+
+ Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0);
+ Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0);
+
+ return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0));
+ }
+
+ RValue<Float> cmpeqss(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 0);
+ }
+
+ RValue<Float> cmpltss(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 1);
+ }
+
+ RValue<Float> cmpless(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 2);
+ }
+
+ RValue<Float> cmpunordss(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 3);
+ }
+
+ RValue<Float> cmpneqss(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 4);
+ }
+
+ RValue<Float> cmpnltss(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 5);
+ }
+
+ RValue<Float> cmpnless(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 6);
+ }
+
+ RValue<Float> cmpordss(const RValue<Float> &x, const RValue<Float> &y)
+ {
+ return cmpss(x, y, 7);
+ }
+
+ RValue<Int4> pabsd(const RValue<Int4> &x, const RValue<Int4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pabsd = Intrinsic::getDeclaration(module, Intrinsic::x86_ssse3_pabs_d_128);
+
+ return RValue<Int4>(Nucleus::createCall(pabsd, x.value, y.value));
+ }
+
+ RValue<Short4> paddsw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *paddsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_w);
+
+ return RValue<Short4>(Nucleus::createCall(paddsw, x.value, y.value));
+ }
+
+ RValue<Short4> psubsw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psubsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_w);
+
+ return RValue<Short4>(Nucleus::createCall(psubsw, x.value, y.value));
+ }
+
+ RValue<UShort4> paddusw(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *paddusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_w);
+
+ return RValue<UShort4>(Nucleus::createCall(paddusw, x.value, y.value));
+ }
+
+ RValue<UShort4> psubusw(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psubusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_w);
+
+ return RValue<UShort4>(Nucleus::createCall(psubusw, x.value, y.value));
+ }
+
+ RValue<SByte8> paddsb(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *paddsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_b);
+
+ return RValue<SByte8>(Nucleus::createCall(paddsb, x.value, y.value));
+ }
+
+ RValue<SByte8> psubsb(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psubsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_b);
+
+ return RValue<SByte8>(Nucleus::createCall(psubsb, x.value, y.value));
+ }
+
+ RValue<Byte8> paddusb(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *paddusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_b);
+
+ return RValue<Byte8>(Nucleus::createCall(paddusb, x.value, y.value));
+ }
+
+ RValue<Byte8> psubusb(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psubusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_b);
+
+ return RValue<Byte8>(Nucleus::createCall(psubusb, x.value, y.value));
+ }
+
+ RValue<UShort4> pavgw(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pavgw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pavg_w);
+
+ return RValue<UShort4>(Nucleus::createCall(pavgw, x.value, y.value));
+ }
+
+ RValue<Short4> pmaxsw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmaxsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmaxs_w);
+
+ return RValue<Short4>(Nucleus::createCall(pmaxsw, x.value, y.value));
+ }
+
+ RValue<Short4> pminsw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pminsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmins_w);
+
+ return RValue<Short4>(Nucleus::createCall(pminsw, x.value, y.value));
+ }
+
+ RValue<Short4> pcmpgtw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pcmpgtw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_w);
+
+ return RValue<Short4>(Nucleus::createCall(pcmpgtw, x.value, y.value));
+ }
+
+ RValue<Short4> pcmpeqw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pcmpeqw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_w);
+
+ return RValue<Short4>(Nucleus::createCall(pcmpeqw, x.value, y.value));
+ }
+
+ RValue<Byte8> pcmpgtb(const RValue<SByte8> &x, const RValue<SByte8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pcmpgtb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_b);
+
+ return RValue<Byte8>(Nucleus::createCall(pcmpgtb, x.value, y.value));
+ }
+
+ RValue<Byte8> pcmpeqb(const RValue<Byte8> &x, const RValue<Byte8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pcmpeqb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_b);
+
+ return RValue<Byte8>(Nucleus::createCall(pcmpeqb, x.value, y.value));
+ }
+
+ RValue<Short4> packssdw(const RValue<Int2> &x, const RValue<Int2> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packssdw);
+
+ return RValue<Short4>(Nucleus::createCall(packssdw, x.value, y.value));
+ }
+
+ RValue<Short8> packssdw(const RValue<Int4> &x, const RValue<Int4> &y)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_packssdw_128);
+
+ return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value));
+ }
+ else
+ {
+ Int2 loX = Int2(x);
+ Int2 hiX = Int2(Swizzle(x, 0xEE));
+
+ Int2 loY = Int2(y);
+ Int2 hiY = Int2(Swizzle(y, 0xEE));
+
+ Short4 lo = x86::packssdw(loX, hiX);
+ Short4 hi = x86::packssdw(loY, hiY);
+
+ return Concatenate(lo, hi);
+ }
+ }
+
+ RValue<SByte8> packsswb(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *packsswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packsswb);
+
+ return RValue<SByte8>(Nucleus::createCall(packsswb, x.value, y.value));
+ }
+
+ RValue<Byte8> packuswb(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *packuswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packuswb);
+
+ return RValue<Byte8>(Nucleus::createCall(packuswb, x.value, y.value));
+ }
+
+ RValue<UShort8> packusdw(const RValue<UInt4> &x, const RValue<UInt4> &y)
+ {
+ if(CPUID::supportsSSE4_1())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *packusdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_packusdw);
+
+ return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value));
+ }
+ else
+ {
+ // FIXME: Not an exact replacement!
+ return As<UShort8>(packssdw(As<Int4>(x - UInt4(0x00008000, 0x00008000, 0x00008000, 0x00008000)), As<Int4>(y - UInt4(0x00008000, 0x00008000, 0x00008000, 0x00008000))) + Short8(0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000));
+ }
+ }
+
+ RValue<UShort4> psrlw(const RValue<UShort4> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_w);
+
+ return RValue<UShort4>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<UShort8> psrlw(const RValue<UShort8> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_w);
+
+ return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Short4> psraw(const RValue<Short4> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_w);
+
+ return RValue<Short4>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Short8> psraw(const RValue<Short8> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_w);
+
+ return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Short4> psllw(const RValue<Short4> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_w);
+
+ return RValue<Short4>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Short8> psllw(const RValue<Short8> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_w);
+
+ return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Int2> pslld(const RValue<Int2> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_d);
+
+ return RValue<Int2>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Int4> pslld(const RValue<Int4> &x, unsigned char y)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_d);
+
+ return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y)));
+ }
+ else
+ {
+ Int2 lo = Int2(x);
+ Int2 hi = Int2(Swizzle(x, 0xEE));
+
+ lo = x86::pslld(lo, y);
+ hi = x86::pslld(hi, y);
+
+ return Concatenate(lo, hi);
+ }
+ }
+
+ RValue<Int2> psrad(const RValue<Int2> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_d);
+
+ return RValue<Int2>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<Int4> psrad(const RValue<Int4> &x, unsigned char y)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_d);
+
+ return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y)));
+ }
+ else
+ {
+ Int2 lo = Int2(x);
+ Int2 hi = Int2(Swizzle(x, 0xEE));
+
+ lo = x86::psrad(lo, y);
+ hi = x86::psrad(hi, y);
+
+ return Concatenate(lo, hi);
+ }
+ }
+
+ RValue<UInt2> psrld(const RValue<UInt2> &x, unsigned char y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_d);
+
+ return RValue<UInt2>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y)));
+ }
+
+ RValue<UInt4> psrld(const RValue<UInt4> &x, unsigned char y)
+ {
+ if(CPUID::supportsSSE2())
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_d);
+
+ return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y)));
+ }
+ else
+ {
+ UInt2 lo = As<UInt2>(Int2(As<Int4>(x)));
+ UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE)));
+
+ lo = x86::psrld(lo, y);
+ hi = x86::psrld(hi, y);
+
+ return Concatenate(lo, hi);
+ }
+ }
+
+ RValue<UShort4> psrlw(const RValue<UShort4> &x, const RValue<Long1> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_w);
+
+ return RValue<UShort4>(Nucleus::createCall(psrlw, x.value, y.value));
+ }
+
+ RValue<Short4> psraw(const RValue<Short4> &x, const RValue<Long1> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_w);
+
+ return RValue<Short4>(Nucleus::createCall(psraw, x.value, y.value));
+ }
+
+ RValue<Short4> psllw(const RValue<Short4> &x, const RValue<Long1> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_w);
+
+ return RValue<Short4>(Nucleus::createCall(psllw, x.value, y.value));
+ }
+
+ RValue<Int2> pslld(const RValue<Int2> &x, const RValue<Long1> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_d);
+
+ return RValue<Int2>(Nucleus::createCall(pslld, x.value, y.value));
+ }
+
+ RValue<UInt2> psrld(const RValue<UInt2> &x, const RValue<Long1> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_d);
+
+ return RValue<UInt2>(Nucleus::createCall(psrld, x.value, y.value));
+ }
+
+ RValue<Int2> psrad(const RValue<Int2> &x, const RValue<Long1> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_d);
+
+ return RValue<Int2>(Nucleus::createCall(psrld, x.value, y.value));
+ }
+
+ RValue<Short4> pmulhw(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulh_w);
+
+ return RValue<Short4>(Nucleus::createCall(pmulhw, x.value, y.value));
+ }
+
+ RValue<UShort4> pmulhuw(const RValue<UShort4> &x, const RValue<UShort4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulhu_w);
+
+ return RValue<UShort4>(Nucleus::createCall(pmulhuw, x.value, y.value));
+ }
+
+ RValue<Int2> pmaddwd(const RValue<Short4> &x, const RValue<Short4> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmadd_wd);
+
+ return RValue<Int2>(Nucleus::createCall(pmaddwd, x.value, y.value));
+ }
+
+ RValue<Short8> pmulhw(const RValue<Short8> &x, const RValue<Short8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulh_w);
+
+ return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value));
+ }
+
+ RValue<UShort8> pmulhuw(const RValue<UShort8> &x, const RValue<UShort8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulhu_w);
+
+ return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value));
+ }
+
+ RValue<Int4> pmaddwd(const RValue<Short8> &x, const RValue<Short8> &y)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmadd_wd);
+
+ return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value));
+ }
+
+ RValue<Int> movmskps(const RValue<Float4> &x)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *movmskps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_movmsk_ps);
+
+ return RValue<Int>(Nucleus::createCall(movmskps, x.value));
+ }
+
+ RValue<Int> pmovmskb(const RValue<Byte8> &x)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmovmskb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmovmskb);
+
+ return RValue<Int>(Nucleus::createCall(pmovmskb, x.value));
+ }
+
+ //RValue<Int2> movd(const RValue<Pointer<Int>> &x)
+ //{
+ // Value *element = Nucleus::createLoad(x.value);
+
+ //// Value *int2 = UndefValue::get(Int2::getType());
+ //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0));
+
+ // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType());
+
+ // return RValue<Int2>(int2);
+ //}
+
+ //RValue<Int2> movdq2q(const RValue<Int4> &x)
+ //{
+ // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType());
+ // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0));
+
+ // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType()));
+ //}
+
+ RValue<Int4> pmovzxbd(const RValue<Int4> &x)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmovzxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxbd);
+
+ return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType())));
+ }
+
+ RValue<Int4> pmovsxbd(const RValue<Int4> &x)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmovsxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxbd);
+
+ return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType())));
+ }
+
+ RValue<Int4> pmovzxwd(const RValue<Int4> &x)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmovzxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxwd);
+
+ return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType())));
+ }
+
+ RValue<Int4> pmovsxwd(const RValue<Int4> &x)
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *pmovsxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxwd);
+
+ return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType())));
+ }
+
+ void emms()
+ {
+ Module *module = Nucleus::getModule();
+ llvm::Function *emms = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_emms);
+
+ Nucleus::createCall(emms);
+ }
+ }
+}
diff --git a/src/Reactor/Nucleus.hpp b/src/Reactor/Nucleus.hpp
new file mode 100644
index 0000000..0fa1d82
--- /dev/null
+++ b/src/Reactor/Nucleus.hpp
@@ -0,0 +1,2868 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#ifndef sw_Nucleus_hpp
+#define sw_Nucleus_hpp
+
+#include "Common/Types.hpp"
+
+#include <stdarg.h>
+#include <vector>
+
+#undef abs
+#undef max
+#undef min
+
+namespace llvm
+{
+ class Function;
+ class Module;
+ class BasicBlock;
+ class Value;
+ class Constant;
+ class ConstantInt;
+ class ConstantFP;
+ class Type;
+ class Argument;
+ class GlobalVariable;
+ class GlobalValue;
+ class ExecutionEngine;
+ class LLVMContext;
+}
+
+namespace sw
+{
+ enum Optimization
+ {
+ Disabled,
+ InstructionCombining,
+ CFGSimplification,
+ LICM,
+ AggressiveDCE,
+ GVN,
+ Reassociate,
+ DeadStoreElimination,
+ SCCP,
+
+ OptimizationCount
+ };
+
+ extern Optimization optimization[10];
+
+ class MemoryManager;
+ class Builder;
+ class Nucleus;
+
+ class Routine
+ {
+ friend Nucleus;
+
+ public:
+ Routine(int bufferSize);
+ Routine(void *memory, int bufferSize, int offset);
+
+ ~Routine();
+
+ void setFunctionSize(int functionSize);
+
+ const void *getBuffer();
+ const void *getEntry();
+ int getBufferSize();
+ int getFunctionSize(); // Includes constants before the entry point
+ int getCodeSize(); // Executable code only
+ bool isDynamic();
+
+ void bind();
+ void unbind();
+
+ private:
+ void *buffer;
+ const void *entry;
+ int bufferSize;
+ int functionSize;
+
+ volatile int bindCount;
+ const bool dynamic; // Generated or precompiled
+ };
+
+ class Nucleus
+ {
+ public:
+ Nucleus();
+
+ virtual ~Nucleus();
+
+ Routine *acquireRoutine(const wchar_t *name, bool runOptimizations = true);
+
+ static void setFunction(llvm::Function *function);
+
+ static llvm::Module *getModule();
+ static Builder *getBuilder();
+ static llvm::Function *getFunction();
+ static llvm::LLVMContext *getContext();
+
+ static llvm::Value *allocateStackVariable(const llvm::Type *type, int arraySize = 0);
+ static llvm::BasicBlock *createBasicBlock();
+ static llvm::BasicBlock *getInsertBlock();
+ static void setInsertBlock(llvm::BasicBlock *basicBlock);
+ static llvm::BasicBlock *getPredecessor(llvm::BasicBlock *basicBlock);
+
+ static llvm::Function *createFunction(const llvm::Type *ReturnType, const std::vector<const llvm::Type*> &Params);
+ static llvm::Argument *getArgument(llvm::Function *function, unsigned int index);
+
+ // Terminators
+ static llvm::Value *createRetVoid();
+ static llvm::Value *createRet(llvm::Value *V);
+ static llvm::Value *createBr(llvm::BasicBlock *dest);
+ static llvm::Value *createCondBr(llvm::Value *cond, llvm::BasicBlock *ifTrue, llvm::BasicBlock *ifFalse);
+
+ // Binary operators
+ static llvm::Value *createAdd(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createSub(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createMul(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createUDiv(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createSDiv(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFAdd(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFSub(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFMul(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFDiv(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createURem(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createSRem(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFRem(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createShl(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createLShr(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createAShr(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createAnd(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createOr(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createXor(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createNeg(llvm::Value *V);
+ static llvm::Value *createFNeg(llvm::Value *V);
+ static llvm::Value *createNot(llvm::Value *V);
+
+ // Memory instructions
+ static llvm::Value *createLoad(llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
+ static llvm::Value *createStore(llvm::Value *value, llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
+ static llvm::Value *createGEP(llvm::Value *ptr, llvm::Value *index);
+
+ // Cast/Conversion Operators
+ static llvm::Value *createTrunc(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createZExt(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createSExt(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createFPToUI(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createFPToSI(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createUIToFP(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createSIToFP(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createFPTrunc(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createFPExt(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createPtrToInt(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createIntToPtr(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createBitCast(llvm::Value *V, const llvm::Type *destType);
+ static llvm::Value *createIntCast(llvm::Value *V, const llvm::Type *destType, bool isSigned);
+
+ // Compare instructions
+ static llvm::Value *createICmpEQ(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpNE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpUGT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpUGE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpULT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpULE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpSGT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpSGE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpSLT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createICmpSLE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpOEQ(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpOGT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpOGE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpOLT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpOLE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpONE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpORD(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpUNO(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpUEQ(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpUGT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpUGE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpULT(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpULE(llvm::Value *lhs, llvm::Value *rhs);
+ static llvm::Value *createFCmpUNE(llvm::Value *lhs, llvm::Value *rhs);
+
+ // Call instructions
+ static llvm::Value *createCall(llvm::Value *callee);
+ static llvm::Value *createCall(llvm::Value *callee, llvm::Value *Arg);
+ static llvm::Value *createCall(llvm::Value *callee, llvm::Value *Arg1, llvm::Value *Arg2);
+ static llvm::Value *createCall(llvm::Value *callee, llvm::Value *Arg1, llvm::Value *Arg2, llvm::Value *Arg3);
+ static llvm::Value *createCall(llvm::Value *callee, llvm::Value *Arg1, llvm::Value *Arg2, llvm::Value *Arg3,llvm::Value *Arg4);
+
+ // Vector instructions
+ static llvm::Value *createExtractElement(llvm::Value *vector, int index);
+ static llvm::Value *createInsertElement(llvm::Value *vector, llvm::Value *element, int index);
+ static llvm::Value *createShuffleVector(llvm::Value *V1, llvm::Value *V2, llvm::Value *mask);
+
+ // Other instructions
+ static llvm::Value *createSelect(llvm::Value *C, llvm::Value *ifTrue, llvm::Value *ifFalse);
+ static llvm::Value *createSwitch(llvm::Value *V, llvm::BasicBlock *Dest, unsigned NumCases = 10);
+ static void addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch);
+ static llvm::Value *createUnreachable();
+
+ // Derived instructions
+ static llvm::Value *createSwizzle(llvm::Value *val, unsigned char select);
+ static llvm::Value *createMask(llvm::Value *lhs, llvm::Value *rhs, unsigned char select);
+
+ // Global values
+ static const llvm::GlobalValue *getGlobalValueAtAddress(void *Addr);
+ static void addGlobalMapping(const llvm::GlobalValue *GV, void *Addr);
+ static llvm::GlobalValue *createGlobalValue(const llvm::Type *Ty, bool isConstant, unsigned int Align);
+ static llvm::Type *getPointerType(const llvm::Type *ElementType);
+
+ // Constant values
+ static llvm::Constant *createNullValue(const llvm::Type *Ty);
+ static llvm::ConstantInt *createConstantLong(int64_t i);
+ static llvm::ConstantInt *createConstantInt(int i);
+ static llvm::ConstantInt *createConstantInt(unsigned int i);
+ static llvm::ConstantInt *createConstantBool(bool b);
+ static llvm::ConstantInt *createConstantByte(signed char i);
+ static llvm::ConstantInt *createConstantByte(unsigned char i);
+ static llvm::ConstantInt *createConstantShort(short i);
+ static llvm::ConstantInt *createConstantShort(unsigned short i);
+ static llvm::Constant *createConstantFloat(float x);
+ static llvm::Value *createNullPointer(const llvm::Type *Ty);
+ static llvm::Value *createConstantVector(llvm::Constant* const* Vals, unsigned NumVals);
+
+ private:
+ void optimize();
+
+ static llvm::ExecutionEngine *executionEngine;
+ static Builder *builder;
+ static llvm::Function *function;
+ static llvm::LLVMContext *context;
+ static llvm::Module *module;
+ static MemoryManager *memoryManager;
+ };
+
+ class Byte;
+ class SByte;
+ class Byte4;
+ class SByte4;
+ class Byte8;
+ class SByte8;
+ class Byte16;
+ class SByte16;
+ class Short;
+ class UShort;
+ class Short4;
+ class UShort4;
+ class Short8;
+ class UShort8;
+ class Int;
+ class UInt;
+ class Int2;
+ class UInt2;
+ class Int4;
+ class UInt4;
+ class Long;
+ class Long1;
+ class Long2;
+ class Float;
+ class Float2;
+ class Float4;
+
+ class Void
+ {
+ public:
+ static const llvm::Type *getType();
+
+ static bool isVoid()
+ {
+ return true;
+ }
+
+ typedef void ctype;
+ };
+
+ template<class T>
+ class Variable
+ {
+ public:
+ static bool isVoid()
+ {
+ return false;
+ }
+
+ llvm::Value *address;
+ typedef T ctype;
+ };
+
+ template<class T>
+ class RValue;
+
+ template<class T>
+ class Reference
+ {
+ friend Long1;
+
+ public:
+ explicit Reference(llvm::Value *pointer, int alignment = 1);
+
+ RValue<T> operator=(const RValue<T> &rhs) const;
+ operator RValue<T>() const;
+ RValue<T> operator=(const Reference<T> &ref) const;
+
+ RValue<T> operator+=(const RValue<T> &rhs) const;
+
+ private:
+ llvm::Value *address;
+
+ const int alignment;
+ };
+
+ template<class T>
+ struct IntLiteral
+ {
+ struct type;
+ };
+
+ template<> struct
+ IntLiteral<Int>
+ {
+ typedef int type;
+ };
+
+ template<class T>
+ class RValue
+ {
+ public:
+ explicit RValue(llvm::Value *rvalue);
+
+ RValue(const T &lvalue);
+ RValue(typename IntLiteral<T>::type i);
+
+ llvm::Value *value; // FIXME: Make private
+ };
+
+ template<class T>
+ class Pointer;
+
+ class Bool : public Variable<bool>
+ {
+ public:
+ explicit Bool(llvm::Argument *argument);
+
+ Bool();
+ Bool(bool x);
+ Bool(const RValue<Bool> &rhs);
+ Bool(const Bool &rhs);
+
+ // RValue<Bool> operator=(bool rhs) const; // FIXME: Implement
+ RValue<Bool> operator=(const RValue<Bool> &rhs) const;
+ RValue<Bool> operator=(const Bool &rhs) const;
+
+ RValue<Pointer<Bool>> operator&();
+
+ friend RValue<Bool> operator!(const RValue<Bool> &val);
+ friend RValue<Bool> operator&&(const RValue<Bool> &lhs, const RValue<Bool> &rhs);
+ friend RValue<Bool> operator||(const RValue<Bool> &lhs, const RValue<Bool> &rhs);
+
+ Bool *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Byte : public Variable<unsigned char>
+ {
+ public:
+ explicit Byte(llvm::Argument *argument);
+
+ explicit Byte(const RValue<Int> &cast);
+
+ Byte();
+ Byte(int x);
+ Byte(unsigned char x);
+ Byte(const RValue<Byte> &rhs);
+ Byte(const Byte &rhs);
+
+ // RValue<Byte> operator=(unsigned char rhs) const; // FIXME: Implement
+ RValue<Byte> operator=(const RValue<Byte> &rhs) const;
+ RValue<Byte> operator=(const Byte &rhs) const;
+ RValue<Pointer<Byte>> operator&();
+
+ friend RValue<Byte> operator+(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator-(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator*(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator/(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator%(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator&(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator|(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator^(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator<<(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator>>(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator+=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator-=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator*=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator/=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator%=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator&=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator|=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator^=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator<<=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator>>=(const Byte &lhs, const RValue<Byte> &rhs);
+ friend RValue<Byte> operator+(const RValue<Byte> &val);
+ friend RValue<Byte> operator-(const RValue<Byte> &val);
+ friend RValue<Byte> operator~(const RValue<Byte> &val);
+ friend RValue<Byte> operator++(const Byte &val, int); // Post-increment
+ friend const Byte &operator++(const Byte &val); // Pre-increment
+ friend RValue<Byte> operator--(const Byte &val, int); // Post-decrement
+ friend const Byte &operator--(const Byte &val); // Pre-decrement
+ friend RValue<Bool> operator<(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Bool> operator<=(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Bool> operator>(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Bool> operator>=(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Bool> operator!=(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+ friend RValue<Bool> operator==(const RValue<Byte> &lhs, const RValue<Byte> &rhs);
+
+ Byte *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class SByte : public Variable<signed char>
+ {
+ public:
+ explicit SByte(llvm::Argument *argument);
+
+ SByte();
+ SByte(signed char x);
+ SByte(const RValue<SByte> &rhs);
+ SByte(const SByte &rhs);
+
+ // RValue<SByte> operator=(signed char rhs) const; // FIXME: Implement
+ RValue<SByte> operator=(const RValue<SByte> &rhs) const;
+ RValue<SByte> operator=(const SByte &rhs) const;
+ RValue<Pointer<SByte>> operator&();
+
+ friend RValue<SByte> operator+(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator-(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator*(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator/(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator%(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator&(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator|(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator^(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator<<(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator>>(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator+=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator-=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator*=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator/=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator%=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator&=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator|=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator^=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator<<=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator>>=(const SByte &lhs, const RValue<SByte> &rhs);
+ friend RValue<SByte> operator+(const RValue<SByte> &val);
+ friend RValue<SByte> operator-(const RValue<SByte> &val);
+ friend RValue<SByte> operator~(const RValue<SByte> &val);
+ friend RValue<SByte> operator++(const SByte &val, int); // Post-increment
+ friend const SByte &operator++(const SByte &val); // Pre-increment
+ friend RValue<SByte> operator--(const SByte &val, int); // Post-decrement
+ friend const SByte &operator--(const SByte &val); // Pre-decrement
+ friend RValue<Bool> operator<(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<Bool> operator<=(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<Bool> operator>(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<Bool> operator>=(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<Bool> operator!=(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+ friend RValue<Bool> operator==(const RValue<SByte> &lhs, const RValue<SByte> &rhs);
+
+ SByte *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Short : public Variable<short>
+ {
+ public:
+ explicit Short(llvm::Argument *argument);
+
+ explicit Short(const RValue<Int> &cast);
+
+ Short();
+ Short(short x);
+ Short(const RValue<Short> &rhs);
+ Short(const Short &rhs);
+
+ // RValue<Short> operator=(short rhs) const; // FIXME: Implement
+ RValue<Short> operator=(const RValue<Short> &rhs) const;
+ RValue<Short> operator=(const Short &rhs) const;
+ RValue<Pointer<Short>> operator&();
+
+ friend RValue<Short> operator+(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator-(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator*(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator/(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator%(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator&(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator|(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator^(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator<<(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator>>(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator+=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator-=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator*=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator/=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator%=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator&=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator|=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator^=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator<<=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator>>=(const Short &lhs, const RValue<Short> &rhs);
+ friend RValue<Short> operator+(const RValue<Short> &val);
+ friend RValue<Short> operator-(const RValue<Short> &val);
+ friend RValue<Short> operator~(const RValue<Short> &val);
+ friend RValue<Short> operator++(const Short &val, int); // Post-increment
+ friend const Short &operator++(const Short &val); // Pre-increment
+ friend RValue<Short> operator--(const Short &val, int); // Post-decrement
+ friend const Short &operator--(const Short &val); // Pre-decrement
+ friend RValue<Bool> operator<(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Bool> operator<=(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Bool> operator>(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Bool> operator>=(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Bool> operator!=(const RValue<Short> &lhs, const RValue<Short> &rhs);
+ friend RValue<Bool> operator==(const RValue<Short> &lhs, const RValue<Short> &rhs);
+
+ Short *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class UShort : public Variable<unsigned short>
+ {
+ public:
+ explicit UShort(llvm::Argument *argument);
+
+ UShort();
+ UShort(unsigned short x);
+ UShort(const RValue<UShort> &rhs);
+ UShort(const UShort &rhs);
+
+ // RValue<UShort> operator=(unsigned short rhs) const; // FIXME: Implement
+ RValue<UShort> operator=(const RValue<UShort> &rhs) const;
+ RValue<UShort> operator=(const UShort &rhs) const;
+ RValue<Pointer<UShort>> operator&();
+
+ friend RValue<UShort> operator+(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator-(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator*(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator/(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator%(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator&(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator|(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator^(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator<<(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator>>(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator+=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator-=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator*=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator/=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator%=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator&=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator|=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator^=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator<<=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator>>=(const UShort &lhs, const RValue<UShort> &rhs);
+ friend RValue<UShort> operator+(const RValue<UShort> &val);
+ friend RValue<UShort> operator-(const RValue<UShort> &val);
+ friend RValue<UShort> operator~(const RValue<UShort> &val);
+ friend RValue<UShort> operator++(const UShort &val, int); // Post-increment
+ friend const UShort &operator++(const UShort &val); // Pre-increment
+ friend RValue<UShort> operator--(const UShort &val, int); // Post-decrement
+ friend const UShort &operator--(const UShort &val); // Pre-decrement
+ friend RValue<Bool> operator<(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<Bool> operator<=(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<Bool> operator>(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<Bool> operator>=(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<Bool> operator!=(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+ friend RValue<Bool> operator==(const RValue<UShort> &lhs, const RValue<UShort> &rhs);
+
+ UShort *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Byte4 : public Variable<byte4>
+ {
+ public:
+ // Byte4();
+ // Byte4(int x, int y, int z, int w);
+ // Byte4(const RValue<Byte4> &rhs);
+ // Byte4(const Byte4 &rhs);
+
+ // RValue<Byte4> operator=(const RValue<Byte4> &rhs) const;
+ // RValue<Byte4> operator=(const Byte4 &rhs) const;
+ // RValue<Pointer<Byte4>> operator&();
+
+ // friend RValue<Byte4> operator+(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator-(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator*(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator/(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator%(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator&(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator|(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator^(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator<<(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator>>(const RValue<Byte4> &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator+=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator-=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator*=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator/=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator%=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator&=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator|=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator^=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator<<=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator>>=(const Byte4 &lhs, const RValue<Byte4> &rhs);
+ // friend RValue<Byte4> operator+(const RValue<Byte4> &val);
+ // friend RValue<Byte4> operator-(const RValue<Byte4> &val);
+ // friend RValue<Byte4> operator~(const RValue<Byte4> &val);
+ // friend RValue<Byte4> operator++(const Byte4 &val, int); // Post-increment
+ // friend const Byte4 &operator++(const Byte4 &val); // Pre-increment
+ // friend RValue<Byte4> operator--(const Byte4 &val, int); // Post-decrement
+ // friend const Byte4 &operator--(const Byte4 &val); // Pre-decrement
+
+ Byte4 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class SByte4 : public Variable<sbyte4>
+ {
+ public:
+ // SByte4();
+ // SByte4(int x, int y, int z, int w);
+ // SByte4(const RValue<SByte4> &rhs);
+ // SByte4(const SByte4 &rhs);
+
+ // RValue<SByte4> operator=(const RValue<SByte4> &rhs) const;
+ // RValue<SByte4> operator=(const SByte4 &rhs) const;
+ // RValue<Pointer<SByte4>> operator&();
+
+ // friend RValue<SByte4> operator+(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator-(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator*(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator/(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator%(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator&(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator|(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator^(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator<<(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator>>(const RValue<SByte4> &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator+=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator-=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator*=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator/=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator%=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator&=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator|=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator^=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator<<=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator>>=(const SByte4 &lhs, const RValue<SByte4> &rhs);
+ // friend RValue<SByte4> operator+(const RValue<SByte4> &val);
+ // friend RValue<SByte4> operator-(const RValue<SByte4> &val);
+ // friend RValue<SByte4> operator~(const RValue<SByte4> &val);
+ // friend RValue<SByte4> operator++(const SByte4 &val, int); // Post-increment
+ // friend const SByte4 &operator++(const SByte4 &val); // Pre-increment
+ // friend RValue<SByte4> operator--(const SByte4 &val, int); // Post-decrement
+ // friend const SByte4 &operator--(const SByte4 &val); // Pre-decrement
+
+ SByte4 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Byte8 : public Variable<byte8>
+ {
+ public:
+ Byte8();
+ Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7);
+ Byte8(int64_t x);
+ Byte8(const RValue<Byte8> &rhs);
+ Byte8(const Byte8 &rhs);
+
+ RValue<Byte8> operator=(const RValue<Byte8> &rhs) const;
+ RValue<Byte8> operator=(const Byte8 &rhs) const;
+ // RValue<Pointer<Byte8>> operator&();
+
+ friend RValue<Byte8> operator+(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator-(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator*(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator/(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator%(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator&(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator|(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator^(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ // friend RValue<Byte8> operator<<(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ // friend RValue<Byte8> operator>>(const RValue<Byte8> &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator+=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator-=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator*=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator/=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator%=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator&=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator|=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator^=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ // friend RValue<Byte8> operator<<=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ // friend RValue<Byte8> operator>>=(const Byte8 &lhs, const RValue<Byte8> &rhs);
+ friend RValue<Byte8> operator+(const RValue<Byte8> &val);
+ friend RValue<Byte8> operator-(const RValue<Byte8> &val);
+ friend RValue<Byte8> operator~(const RValue<Byte8> &val);
+ // friend RValue<Byte8> operator++(const Byte8 &val, int); // Post-increment
+ // friend const Byte8 &operator++(const Byte8 &val); // Pre-increment
+ // friend RValue<Byte8> operator--(const Byte8 &val, int); // Post-decrement
+ // friend const Byte8 &operator--(const Byte8 &val); // Pre-decrement
+
+ friend RValue<Byte8> AddSat(const RValue<Byte8> &x, const RValue<Byte8> &y);
+ friend RValue<Byte8> SubSat(const RValue<Byte8> &x, const RValue<Byte8> &y);
+
+ friend RValue<Short4> UnpackLow(const RValue<Byte8> &x, const RValue<Byte8> &y);
+ friend RValue<Short4> UnpackHigh(const RValue<Byte8> &x, const RValue<Byte8> &y);
+ friend RValue<Int> SignMask(const RValue<Byte8> &x);
+
+ // friend RValue<Byte8> CmpGT(const RValue<Byte8> &x, const RValue<Byte8> &y);
+ friend RValue<Byte8> CmpEQ(const RValue<Byte8> &x, const RValue<Byte8> &y);
+
+ Byte8 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class SByte8 : public Variable<sbyte8>
+ {
+ public:
+ SByte8();
+ SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7);
+ SByte8(int64_t x);
+ SByte8(const RValue<SByte8> &rhs);
+ SByte8(const SByte8 &rhs);
+
+ RValue<SByte8> operator=(const RValue<SByte8> &rhs) const;
+ RValue<SByte8> operator=(const SByte8 &rhs) const;
+ // RValue<Pointer<SByte8>> operator&();
+
+ friend RValue<SByte8> operator+(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator-(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator*(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator/(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator%(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator&(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator|(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator^(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ // friend RValue<SByte8> operator<<(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ // friend RValue<SByte8> operator>>(const RValue<SByte8> &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator+=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator-=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator*=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator/=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator%=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator&=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator|=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator^=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ // friend RValue<SByte8> operator<<=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ // friend RValue<SByte8> operator>>=(const SByte8 &lhs, const RValue<SByte8> &rhs);
+ friend RValue<SByte8> operator+(const RValue<SByte8> &val);
+ friend RValue<SByte8> operator-(const RValue<SByte8> &val);
+ friend RValue<SByte8> operator~(const RValue<SByte8> &val);
+ // friend RValue<SByte8> operator++(const SByte8 &val, int); // Post-increment
+ // friend const SByte8 &operator++(const SByte8 &val); // Pre-increment
+ // friend RValue<SByte8> operator--(const SByte8 &val, int); // Post-decrement
+ // friend const SByte8 &operator--(const SByte8 &val); // Pre-decrement
+
+ friend RValue<SByte8> AddSat(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ friend RValue<SByte8> SubSat(const RValue<SByte8> &x, const RValue<SByte8> &y);
+
+ friend RValue<Short4> UnpackLow(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ friend RValue<Short4> UnpackHigh(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ friend RValue<Int> SignMask(const RValue<SByte8> &x);
+
+ friend RValue<Byte8> CmpGT(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ friend RValue<Byte8> CmpEQ(const RValue<SByte8> &x, const RValue<SByte8> &y);
+
+ SByte8 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Byte16 : public Variable<byte16>
+ {
+ public:
+ // Byte16();
+ // Byte16(int x, int y, int z, int w);
+ Byte16(const RValue<Byte16> &rhs);
+ Byte16(const Byte16 &rhs);
+
+ RValue<Byte16> operator=(const RValue<Byte16> &rhs) const;
+ RValue<Byte16> operator=(const Byte16 &rhs) const;
+ // RValue<Pointer<Byte16>> operator&();
+
+ // friend RValue<Byte16> operator+(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator-(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator*(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator/(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator%(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator&(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator|(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator^(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator<<(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator>>(const RValue<Byte16> &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator+=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator-=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator*=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator/=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator%=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator&=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator|=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator^=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator<<=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator>>=(const Byte16 &lhs, const RValue<Byte16> &rhs);
+ // friend RValue<Byte16> operator+(const RValue<Byte16> &val);
+ // friend RValue<Byte16> operator-(const RValue<Byte16> &val);
+ // friend RValue<Byte16> operator~(const RValue<Byte16> &val);
+ // friend RValue<Byte16> operator++(const Byte16 &val, int); // Post-increment
+ // friend const Byte16 &operator++(const Byte16 &val); // Pre-increment
+ // friend RValue<Byte16> operator--(const Byte16 &val, int); // Post-decrement
+ // friend const Byte16 &operator--(const Byte16 &val); // Pre-decrement
+
+ Byte16 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class SByte16 : public Variable<sbyte16>
+ {
+ public:
+ // SByte16();
+ // SByte16(int x, int y, int z, int w);
+ // SByte16(const RValue<SByte16> &rhs);
+ // SByte16(const SByte16 &rhs);
+
+ // RValue<SByte16> operator=(const RValue<SByte16> &rhs) const;
+ // RValue<SByte16> operator=(const SByte16 &rhs) const;
+ // RValue<Pointer<SByte16>> operator&();
+
+ // friend RValue<SByte16> operator+(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator-(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator*(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator/(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator%(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator&(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator|(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator^(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator<<(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator>>(const RValue<SByte16> &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator+=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator-=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator*=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator/=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator%=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator&=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator|=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator^=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator<<=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator>>=(const SByte16 &lhs, const RValue<SByte16> &rhs);
+ // friend RValue<SByte16> operator+(const RValue<SByte16> &val);
+ // friend RValue<SByte16> operator-(const RValue<SByte16> &val);
+ // friend RValue<SByte16> operator~(const RValue<SByte16> &val);
+ // friend RValue<SByte16> operator++(const SByte16 &val, int); // Post-increment
+ // friend const SByte16 &operator++(const SByte16 &val); // Pre-increment
+ // friend RValue<SByte16> operator--(const SByte16 &val, int); // Post-decrement
+ // friend const SByte16 &operator--(const SByte16 &val); // Pre-decrement
+
+ SByte16 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Short4 : public Variable<short4>
+ {
+ public:
+ explicit Short4(const RValue<Int> &cast);
+ explicit Short4(const RValue<Int4> &cast);
+ // explicit Short4(const RValue<Float> &cast);
+ explicit Short4(const RValue<Float4> &cast);
+
+ Short4();
+ Short4(short x, short y, short z, short w);
+ Short4(const RValue<Short4> &rhs);
+ Short4(const Short4 &rhs);
+ Short4(const RValue<UShort4> &rhs);
+ Short4(const UShort4 &rhs);
+
+ RValue<Short4> operator=(const RValue<Short4> &rhs) const;
+ RValue<Short4> operator=(const Short4 &rhs) const;
+ RValue<Short4> operator=(const RValue<UShort4> &rhs) const;
+ RValue<Short4> operator=(const UShort4 &rhs) const;
+ RValue<Pointer<Short4>> operator&();
+
+ friend RValue<Short4> operator+(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator-(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator*(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator/(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator%(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator&(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator|(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator^(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator<<(const RValue<Short4> &lhs, unsigned char rhs);
+ friend RValue<Short4> operator>>(const RValue<Short4> &lhs, unsigned char rhs);
+ friend RValue<Short4> operator<<(const RValue<Short4> &lhs, const RValue<Long1> &rhs);
+ friend RValue<Short4> operator>>(const RValue<Short4> &lhs, const RValue<Long1> &rhs);
+ friend RValue<Short4> operator+=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator-=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator*=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator/=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator%=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator&=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator|=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator^=(const Short4 &lhs, const RValue<Short4> &rhs);
+ friend RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs);
+ friend RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs);
+ friend RValue<Short4> operator<<=(const Short4 &lhs, const RValue<Long1> &rhs);
+ friend RValue<Short4> operator>>=(const Short4 &lhs, const RValue<Long1> &rhs);
+ friend RValue<Short4> operator+(const RValue<Short4> &val);
+ friend RValue<Short4> operator-(const RValue<Short4> &val);
+ friend RValue<Short4> operator~(const RValue<Short4> &val);
+ // friend RValue<Short4> operator++(const Short4 &val, int); // Post-increment
+ // friend const Short4 &operator++(const Short4 &val); // Pre-increment
+ // friend RValue<Short4> operator--(const Short4 &val, int); // Post-decrement
+ // friend const Short4 &operator--(const Short4 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Short4> &lhs, const RValue<Short4> &rhs);
+
+ friend RValue<Short4> RoundShort4(const RValue<Float4> &cast);
+
+ friend RValue<Short4> Max(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Short4> Min(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Short4> AddSat(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Short4> SubSat(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Short4> MulHigh(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Int2> MulAdd(const RValue<Short4> &x, const RValue<Short4> &y);
+
+ friend RValue<SByte8> Pack(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Int2> UnpackLow(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Int2> UnpackHigh(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Short4> Swizzle(const RValue<Short4> &x, unsigned char select);
+ friend RValue<Short4> Insert(const RValue<Short4> &val, const RValue<Short> &element, int i);
+ friend RValue<Short> Extract(const RValue<Short4> &val, int i);
+
+ friend RValue<Short4> CmpGT(const RValue<Short4> &x, const RValue<Short4> &y);
+ friend RValue<Short4> CmpEQ(const RValue<Short4> &x, const RValue<Short4> &y);
+
+ Short4 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class UShort4 : public Variable<ushort4>
+ {
+ public:
+ explicit UShort4(const RValue<Int4> &cast);
+ explicit UShort4(const RValue<Float4> &cast, bool saturate = false);
+
+ UShort4();
+ UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
+ UShort4(const RValue<UShort4> &rhs);
+ UShort4(const UShort4 &rhs);
+ UShort4(const RValue<Short4> &rhs);
+ UShort4(const Short4 &rhs);
+
+ RValue<UShort4> operator=(const RValue<UShort4> &rhs) const;
+ RValue<UShort4> operator=(const UShort4 &rhs) const;
+ RValue<UShort4> operator=(const RValue<Short4> &rhs) const;
+ RValue<UShort4> operator=(const Short4 &rhs) const;
+ // RValue<Pointer<UShort4>> operator&();
+
+ friend RValue<UShort4> operator+(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ friend RValue<UShort4> operator-(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ friend RValue<UShort4> operator*(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator/(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator%(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator&(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator|(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator^(const RValue<UShort4> &lhs, const RValue<UShort4> &rhs);
+ friend RValue<UShort4> operator<<(const RValue<UShort4> &lhs, unsigned char rhs);
+ friend RValue<UShort4> operator>>(const RValue<UShort4> &lhs, unsigned char rhs);
+ friend RValue<UShort4> operator<<(const RValue<UShort4> &lhs, const RValue<Long1> &rhs);
+ friend RValue<UShort4> operator>>(const RValue<UShort4> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<UShort4> operator+=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator-=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator*=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator/=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator%=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator&=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator|=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ // friend RValue<UShort4> operator^=(const UShort4 &lhs, const RValue<UShort4> &rhs);
+ friend RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs);
+ friend RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs);
+ friend RValue<UShort4> operator<<=(const UShort4 &lhs, const RValue<Long1> &rhs);
+ friend RValue<UShort4> operator>>=(const UShort4 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<UShort4> operator+(const RValue<UShort4> &val);
+ // friend RValue<UShort4> operator-(const RValue<UShort4> &val);
+ friend RValue<UShort4> operator~(const RValue<UShort4> &val);
+ // friend RValue<UShort4> operator++(const UShort4 &val, int); // Post-increment
+ // friend const UShort4 &operator++(const UShort4 &val); // Pre-increment
+ // friend RValue<UShort4> operator--(const UShort4 &val, int); // Post-decrement
+ // friend const UShort4 &operator--(const UShort4 &val); // Pre-decrement
+
+ friend RValue<UShort4> Max(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ friend RValue<UShort4> Min(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ friend RValue<UShort4> AddSat(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ friend RValue<UShort4> SubSat(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ friend RValue<UShort4> MulHigh(const RValue<UShort4> &x, const RValue<UShort4> &y);
+
+ friend RValue<UShort4> Average(const RValue<UShort4> &x, const RValue<UShort4> &y);
+
+ friend RValue<Byte8> Pack(const RValue<UShort4> &x, const RValue<UShort4> &y);
+
+ UShort4 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Short8 : public Variable<short8>
+ {
+ public:
+ // Short8();
+ Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7);
+ Short8(const RValue<Short8> &rhs);
+ // Short8(const Short8 &rhs);
+
+ // RValue<Short8> operator=(const RValue<Short8> &rhs) const;
+ // RValue<Short8> operator=(const Short8 &rhs) const;
+ // RValue<Pointer<Short8>> operator&();
+
+ friend RValue<Short8> operator+(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator-(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator*(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator/(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator%(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ friend RValue<Short8> operator&(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator|(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator^(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ friend RValue<Short8> operator<<(const RValue<Short8> &lhs, unsigned char rhs);
+ friend RValue<Short8> operator>>(const RValue<Short8> &lhs, unsigned char rhs);
+ // friend RValue<Short8> operator<<(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator>>(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator+=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator-=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator*=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator/=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator%=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator&=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator|=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator^=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator<<=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator>>=(const Short8 &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Short8> operator+(const RValue<Short8> &val);
+ // friend RValue<Short8> operator-(const RValue<Short8> &val);
+ // friend RValue<Short8> operator~(const RValue<Short8> &val);
+ // friend RValue<Short8> operator++(const Short8 &val, int); // Post-increment
+ // friend const Short8 &operator++(const Short8 &val); // Pre-increment
+ // friend RValue<Short8> operator--(const Short8 &val, int); // Post-decrement
+ // friend const Short8 &operator--(const Short8 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Short8> &lhs, const RValue<Short8> &rhs);
+
+ friend RValue<Short8> Concatenate(const RValue<Short4> &lo, const RValue<Short4> &hi);
+
+ friend RValue<Short8> MulHigh(const RValue<Short8> &x, const RValue<Short8> &y);
+ friend RValue<Int4> MulAdd(const RValue<Short8> &x, const RValue<Short8> &y);
+
+ Short8 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class UShort8 : public Variable<ushort8>
+ {
+ public:
+ // 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);
+ UShort8(const RValue<UShort8> &rhs);
+ // UShort8(const UShort8 &rhs);
+
+ RValue<UShort8> operator=(const RValue<UShort8> &rhs) const;
+ RValue<UShort8> operator=(const UShort8 &rhs) const;
+ // RValue<Pointer<UShort8>> operator&();
+
+ friend RValue<UShort8> operator+(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator-(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ friend RValue<UShort8> operator*(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator/(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator%(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ friend RValue<UShort8> operator&(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator|(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator^(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ friend RValue<UShort8> operator<<(const RValue<UShort8> &lhs, unsigned char rhs);
+ friend RValue<UShort8> operator>>(const RValue<UShort8> &lhs, unsigned char rhs);
+ // friend RValue<UShort8> operator<<(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator>>(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ friend RValue<UShort8> operator+=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator-=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator*=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator/=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator%=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator&=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator|=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator^=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator<<=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator>>=(const UShort8 &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<UShort8> operator+(const RValue<UShort8> &val);
+ // friend RValue<UShort8> operator-(const RValue<UShort8> &val);
+ friend RValue<UShort8> operator~(const RValue<UShort8> &val);
+ // friend RValue<UShort8> operator++(const UShort8 &val, int); // Post-increment
+ // friend const UShort8 &operator++(const UShort8 &val); // Pre-increment
+ // friend RValue<UShort8> operator--(const UShort8 &val, int); // Post-decrement
+ // friend const UShort8 &operator--(const UShort8 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<Bool> operator>(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+ // friend RValue<Bool> operator==(const RValue<UShort8> &lhs, const RValue<UShort8> &rhs);
+
+ friend RValue<UShort8> Swizzle(const RValue<UShort8> &x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7);
+ friend RValue<UShort8> Concatenate(const RValue<UShort4> &lo, const RValue<UShort4> &hi);
+
+ friend RValue<UShort8> MulHigh(const RValue<UShort8> &x, const RValue<UShort8> &y);
+
+ UShort8 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Int : public Variable<int>
+ {
+ public:
+ explicit Int(llvm::Argument *argument);
+
+ explicit Int(const RValue<Byte> &cast);
+ explicit Int(const RValue<SByte> &cast);
+ explicit Int(const RValue<Short> &cast);
+ explicit Int(const RValue<UShort> &cast);
+ explicit Int(const RValue<Int2> &cast);
+ explicit Int(const RValue<Long> &cast);
+ explicit Int(const RValue<Float> &cast);
+
+ Int();
+ Int(int x);
+ Int(const RValue<Int> &rhs);
+ Int(const RValue<UInt> &rhs);
+ Int(const Int &rhs);
+ Int(const UInt &rhs);
+
+ RValue<Int> operator=(int rhs) const;
+ RValue<Int> operator=(const RValue<Int> &rhs) const;
+ RValue<Int> operator=(const RValue<UInt> &rhs) const;
+ RValue<Int> operator=(const Int &rhs) const;
+ RValue<Int> operator=(const UInt &rhs) const;
+ RValue<Pointer<Int>> operator&();
+
+ friend RValue<Int> operator+(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator-(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator*(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator/(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator%(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator&(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator|(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator^(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator<<(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator>>(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator+=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator-=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator*=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator/=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator%=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator&=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator|=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator^=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator<<=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator>>=(const Int &lhs, const RValue<Int> &rhs);
+ friend RValue<Int> operator+(const RValue<Int> &val);
+ friend RValue<Int> operator-(const RValue<Int> &val);
+ friend RValue<Int> operator~(const RValue<Int> &val);
+ friend RValue<Int> operator++(const Int &val, int); // Post-increment
+ friend const Int &operator++(const Int &val); // Pre-increment
+ friend RValue<Int> operator--(const Int &val, int); // Post-decrement
+ friend const Int &operator--(const Int &val); // Pre-decrement
+ friend RValue<Bool> operator<(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Bool> operator<=(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Bool> operator>(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Bool> operator>=(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Bool> operator!=(const RValue<Int> &lhs, const RValue<Int> &rhs);
+ friend RValue<Bool> operator==(const RValue<Int> &lhs, const RValue<Int> &rhs);
+
+ friend RValue<Int> RoundInt(const RValue<Float> &cast);
+
+ Int *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Long : public Variable<qword>
+ {
+ public:
+ // explicit Long(llvm::Argument *argument);
+
+ // explicit Long(const RValue<Short> &cast);
+ // explicit Long(const RValue<UShort> &cast);
+ explicit Long(const RValue<Int> &cast);
+ explicit Long(const RValue<UInt> &cast);
+ // explicit Long(const RValue<Float> &cast);
+
+ Long();
+ // Long(qword x);
+ Long(const RValue<Long> &rhs);
+ // Long(const RValue<ULong> &rhs);
+ // Long(const Long &rhs);
+ // Long(const ULong &rhs);
+
+ RValue<Long> operator=(int64_t rhs) const;
+ RValue<Long> operator=(const RValue<Long> &rhs) const;
+ // RValue<Long> operator=(const RValue<ULong> &rhs) const;
+ RValue<Long> operator=(const Long &rhs) const;
+ // RValue<Long> operator=(const ULong &rhs) const;
+ // RValue<Pointer<Long>> operator&();
+
+ friend RValue<Long> operator+(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ friend RValue<Long> operator-(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator*(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator/(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator%(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator&(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator|(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator^(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator<<(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator>>(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ friend RValue<Long> operator+=(const Long &lhs, const RValue<Long> &rhs);
+ friend RValue<Long> operator-=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator*=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator/=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator%=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator&=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator|=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator^=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator<<=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator>>=(const Long &lhs, const RValue<Long> &rhs);
+ // friend RValue<Long> operator+(const RValue<Long> &val);
+ // friend RValue<Long> operator-(const RValue<Long> &val);
+ // friend RValue<Long> operator~(const RValue<Long> &val);
+ // friend RValue<Long> operator++(const Long &val, int); // Post-increment
+ // friend const Long &operator++(const Long &val); // Pre-increment
+ // friend RValue<Long> operator--(const Long &val, int); // Post-decrement
+ // friend const Long &operator--(const Long &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Long> &lhs, const RValue<Long> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Long> &lhs, const RValue<Long> &rhs);
+
+ // friend RValue<Long> RoundLong(const RValue<Float> &cast);
+
+ friend RValue<Long> AddAtomic(const RValue<Pointer<Long>> &x, const RValue<Long> &y);
+
+ Long *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Long1 : public Variable<qword>
+ {
+ public:
+ // explicit Long1(llvm::Argument *argument);
+
+ // explicit Long1(const RValue<Short> &cast);
+ // explicit Long1(const RValue<UShort> &cast);
+ // explicit Long1(const RValue<Int> &cast);
+ // explicit Long1(const RValue<UInt> &cast);
+ // explicit Long1(const RValue<Float> &cast);
+
+ explicit Long1(const Reference<UInt> &cast);
+
+ // Long1();
+ // Long1(qword x);
+ Long1(const RValue<Long1> &rhs);
+ // Long1(const RValue<ULong1> &rhs);
+ // Long1(const Long1 &rhs);
+ // Long1(const ULong1 &rhs);
+
+ // RValue<Long1> operator=(qword rhs) const;
+ // RValue<Long1> operator=(const RValue<Long1> &rhs) const;
+ // RValue<Long1> operator=(const RValue<ULong1> &rhs) const;
+ // RValue<Long1> operator=(const Long1 &rhs) const;
+ // RValue<Long1> operator=(const ULong1 &rhs) const;
+ // RValue<Pointer<Long1>> operator&();
+
+ // friend RValue<Long1> operator+(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator-(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator*(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator/(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator%(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator&(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator|(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator^(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator<<(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator>>(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator+=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator-=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator*=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator/=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator%=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator&=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator|=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator^=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator<<=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator>>=(const Long1 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long1> operator+(const RValue<Long1> &val);
+ // friend RValue<Long1> operator-(const RValue<Long1> &val);
+ // friend RValue<Long1> operator~(const RValue<Long1> &val);
+ // friend RValue<Long1> operator++(const Long1 &val, int); // Post-increment
+ // friend const Long1 &operator++(const Long1 &val); // Pre-increment
+ // friend RValue<Long1> operator--(const Long1 &val, int); // Post-decrement
+ // friend const Long1 &operator--(const Long1 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Long1> &lhs, const RValue<Long1> &rhs);
+
+ // friend RValue<Long1> RoundLong1(const RValue<Float> &cast);
+
+ Long1 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Long2 : public Variable<qword2>
+ {
+ public:
+ // explicit Long2(const RValue<Long> &cast);
+ // explicit Long2(const RValue<Long1> &cast);
+
+ // Long2();
+ // Long2(int x, int y);
+ // Long2(const RValue<Long2> &rhs);
+ // Long2(const Long2 &rhs);
+
+ // RValue<Long2> operator=(const RValue<Long2> &rhs) const;
+ // RValue<Long2> operator=(const Long2 &rhs) const;
+ // RValue<Pointer<Long2>> operator&();
+
+ // friend RValue<Long2> operator+(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator-(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator*(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator/(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator%(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator&(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator|(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator^(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator<<(const RValue<Long2> &lhs, unsigned char rhs);
+ // friend RValue<Long2> operator>>(const RValue<Long2> &lhs, unsigned char rhs);
+ // friend RValue<Long2> operator<<(const RValue<Long2> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long2> operator>>(const RValue<Long2> &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long2> operator+=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator-=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator*=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator/=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator%=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator&=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator|=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator^=(const Long2 &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Long2> operator<<=(const Long2 &lhs, unsigned char rhs);
+ // friend RValue<Long2> operator>>=(const Long2 &lhs, unsigned char rhs);
+ // friend RValue<Long2> operator<<=(const Long2 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long2> operator>>=(const Long2 &lhs, const RValue<Long1> &rhs);
+ // friend RValue<Long2> operator+(const RValue<Long2> &val);
+ // friend RValue<Long2> operator-(const RValue<Long2> &val);
+ // friend RValue<Long2> operator~(const RValue<Long2> &val);
+ // friend RValue<Long2> operator++(const Long2 &val, int); // Post-increment
+ // friend const Long2 &operator++(const Long2 &val); // Pre-increment
+ // friend RValue<Long2> operator--(const Long2 &val, int); // Post-decrement
+ // friend const Long2 &operator--(const Long2 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Long2> &lhs, const RValue<Long2> &rhs);
+
+ // friend RValue<Long2> RoundInt(const RValue<Float4> &cast);
+
+ // friend RValue<Long2> UnpackLow(const RValue<Long2> &x, const RValue<Long2> &y);
+ friend RValue<Long2> UnpackHigh(const RValue<Long2> &x, const RValue<Long2> &y);
+ // friend RValue<Int> Extract(const RValue<Long2> &val, int i);
+ // friend RValue<Long2> Insert(const RValue<Long2> &val, const RValue<Int> &element, int i);
+
+ Long2 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class UInt : public Variable<unsigned int>
+ {
+ public:
+ explicit UInt(llvm::Argument *argument);
+
+ explicit UInt(const RValue<UShort> &cast);
+ explicit UInt(const RValue<Long> &cast);
+ explicit UInt(const RValue<Float> &cast);
+
+ UInt();
+ UInt(int x);
+ UInt(unsigned int x);
+ UInt(const RValue<UInt> &rhs);
+ UInt(const RValue<Int> &rhs);
+ UInt(const UInt &rhs);
+ UInt(const Int &rhs);
+
+ RValue<UInt> operator=(unsigned int rhs) const;
+ RValue<UInt> operator=(const RValue<UInt> &rhs) const;
+ RValue<UInt> operator=(const RValue<Int> &rhs) const;
+ RValue<UInt> operator=(const UInt &rhs) const;
+ RValue<UInt> operator=(const Int &rhs) const;
+ RValue<Pointer<UInt>> operator&();
+
+ friend RValue<UInt> operator+(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator-(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator*(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator/(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator%(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator&(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator|(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator^(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator<<(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator>>(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator+=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator-=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator*=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator/=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator%=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator&=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator|=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator^=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator<<=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator>>=(const UInt &lhs, const RValue<UInt> &rhs);
+ friend RValue<UInt> operator+(const RValue<UInt> &val);
+ friend RValue<UInt> operator-(const RValue<UInt> &val);
+ friend RValue<UInt> operator~(const RValue<UInt> &val);
+ friend RValue<UInt> operator++(const UInt &val, int); // Post-increment
+ friend const UInt &operator++(const UInt &val); // Pre-increment
+ friend RValue<UInt> operator--(const UInt &val, int); // Post-decrement
+ friend const UInt &operator--(const UInt &val); // Pre-decrement
+ friend RValue<Bool> operator<(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<Bool> operator<=(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<Bool> operator>(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<Bool> operator>=(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<Bool> operator!=(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+ friend RValue<Bool> operator==(const RValue<UInt> &lhs, const RValue<UInt> &rhs);
+
+ // friend RValue<UInt> RoundUInt(const RValue<Float> &cast);
+
+ UInt *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Int2 : public Variable<int2>
+ {
+ public:
+ explicit Int2(const RValue<Int> &cast);
+ explicit Int2(const RValue<Int4> &cast);
+
+ Int2();
+ Int2(int x, int y);
+ Int2(const RValue<Int2> &rhs);
+ Int2(const Int2 &rhs);
+
+ RValue<Int2> operator=(const RValue<Int2> &rhs) const;
+ RValue<Int2> operator=(const Int2 &rhs) const;
+ // RValue<Pointer<Int2>> operator&();
+
+ friend RValue<Int2> operator+(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator-(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator*(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator/(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator%(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator&(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator|(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator^(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator<<(const RValue<Int2> &lhs, unsigned char rhs);
+ friend RValue<Int2> operator>>(const RValue<Int2> &lhs, unsigned char rhs);
+ friend RValue<Int2> operator<<(const RValue<Int2> &lhs, const RValue<Long1> &rhs);
+ friend RValue<Int2> operator>>(const RValue<Int2> &lhs, const RValue<Long1> &rhs);
+ friend RValue<Int2> operator+=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator-=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator*=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator/=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator%=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator&=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator|=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator^=(const Int2 &lhs, const RValue<Int2> &rhs);
+ friend RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs);
+ friend RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs);
+ friend RValue<Int2> operator<<=(const Int2 &lhs, const RValue<Long1> &rhs);
+ friend RValue<Int2> operator>>=(const Int2 &lhs, const RValue<Long1> &rhs);
+ friend RValue<Int2> operator+(const RValue<Int2> &val);
+ friend RValue<Int2> operator-(const RValue<Int2> &val);
+ friend RValue<Int2> operator~(const RValue<Int2> &val);
+ // friend RValue<Int2> operator++(const Int2 &val, int); // Post-increment
+ // friend const Int2 &operator++(const Int2 &val); // Pre-increment
+ // friend RValue<Int2> operator--(const Int2 &val, int); // Post-decrement
+ // friend const Int2 &operator--(const Int2 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Int2> &lhs, const RValue<Int2> &rhs);
+
+ // friend RValue<Int2> RoundInt(const RValue<Float4> &cast);
+
+ friend RValue<Long1> UnpackLow(const RValue<Int2> &x, const RValue<Int2> &y);
+ friend RValue<Long1> UnpackHigh(const RValue<Int2> &x, const RValue<Int2> &y);
+ friend RValue<Int> Extract(const RValue<Int2> &val, int i);
+ // friend RValue<Int2> Insert(const RValue<Int2> &val, const RValue<Int> &element, int i);
+
+ Int2 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class UInt2 : public Variable<uint2>
+ {
+ public:
+ UInt2();
+ UInt2(unsigned int x, unsigned int y);
+ UInt2(const RValue<UInt2> &rhs);
+ UInt2(const UInt2 &rhs);
+
+ RValue<UInt2> operator=(const RValue<UInt2> &rhs) const;
+ RValue<UInt2> operator=(const UInt2 &rhs) const;
+ // RValue<Pointer<UInt2>> operator&();
+
+ friend RValue<UInt2> operator+(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator-(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator*(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator/(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator%(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator&(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator|(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator^(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator<<(const RValue<UInt2> &lhs, unsigned char rhs);
+ friend RValue<UInt2> operator>>(const RValue<UInt2> &lhs, unsigned char rhs);
+ friend RValue<UInt2> operator<<(const RValue<UInt2> &lhs, const RValue<Long1> &rhs);
+ friend RValue<UInt2> operator>>(const RValue<UInt2> &lhs, const RValue<Long1> &rhs);
+ friend RValue<UInt2> operator+=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator-=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator*=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator/=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator%=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator&=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator|=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator^=(const UInt2 &lhs, const RValue<UInt2> &rhs);
+ friend RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs);
+ friend RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs);
+ friend RValue<UInt2> operator<<=(const UInt2 &lhs, const RValue<Long1> &rhs);
+ friend RValue<UInt2> operator>>=(const UInt2 &lhs, const RValue<Long1> &rhs);
+ friend RValue<UInt2> operator+(const RValue<UInt2> &val);
+ friend RValue<UInt2> operator-(const RValue<UInt2> &val);
+ friend RValue<UInt2> operator~(const RValue<UInt2> &val);
+ // friend RValue<UInt2> operator++(const UInt2 &val, int); // Post-increment
+ // friend const UInt2 &operator++(const UInt2 &val); // Pre-increment
+ // friend RValue<UInt2> operator--(const UInt2 &val, int); // Post-decrement
+ // friend const UInt2 &operator--(const UInt2 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ // friend RValue<Bool> operator>(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+ // friend RValue<Bool> operator==(const RValue<UInt2> &lhs, const RValue<UInt2> &rhs);
+
+ // friend RValue<UInt2> RoundInt(const RValue<Float4> &cast);
+
+ UInt2 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Int4 : public Variable<int4>
+ {
+ public:
+ explicit Int4(const RValue<Float4> &cast);
+
+ Int4();
+ Int4(int xyzw);
+ Int4(int x, int yzw);
+ Int4(int x, int y, int zw);
+ Int4(int x, int y, int z, int w);
+ Int4(const RValue<Int4> &rhs);
+ Int4(const Int4 &rhs);
+
+ RValue<Int4> operator=(const RValue<Int4> &rhs) const;
+ RValue<Int4> operator=(const Int4 &rhs) const;
+ // RValue<Pointer<Int4>> operator&();
+
+ friend RValue<Int4> operator+(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator-(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator*(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator/(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator%(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator&(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator|(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator^(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator<<(const RValue<Int4> &lhs, unsigned char rhs);
+ friend RValue<Int4> operator>>(const RValue<Int4> &lhs, unsigned char rhs);
+ friend RValue<Int4> operator+=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator-=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator*=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator/=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator%=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator&=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator|=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator^=(const Int4 &lhs, const RValue<Int4> &rhs);
+ friend RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs);
+ friend RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs);
+ friend RValue<Int4> operator+(const RValue<Int4> &val);
+ friend RValue<Int4> operator-(const RValue<Int4> &val);
+ friend RValue<Int4> operator~(const RValue<Int4> &val);
+ // friend RValue<Int4> operator++(const Int4 &val, int); // Post-increment
+ // friend const Int4 &operator++(const Int4 &val); // Pre-increment
+ // friend RValue<Int4> operator--(const Int4 &val, int); // Post-decrement
+ // friend const Int4 &operator--(const Int4 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ // friend RValue<Bool> operator>(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+ // friend RValue<Bool> operator==(const RValue<Int4> &lhs, const RValue<Int4> &rhs);
+
+ friend RValue<Int4> RoundInt(const RValue<Float4> &cast);
+ friend RValue<Short8> Pack(const RValue<Int4> &x, const RValue<Int4> &y);
+ friend RValue<Int4> Concatenate(const RValue<Int2> &lo, const RValue<Int2> &hi);
+ friend RValue<Int> Extract(const RValue<Int4> &x, int i);
+ friend RValue<Int4> Insert(const RValue<Int4> &val, const RValue<Int> &element, int i);
+ friend RValue<Int> SignMask(const RValue<Int4> &x);
+ friend RValue<Int4> Swizzle(const RValue<Int4> &x, unsigned char select);
+
+ Int4 *getThis();
+ static const llvm::Type *getType();
+
+ private:
+ void constant(int x, int y, int z, int w);
+ };
+
+ class UInt4 : public Variable<uint4>
+ {
+ public:
+ explicit UInt4(const RValue<Float4> &cast);
+
+ UInt4();
+ UInt4(unsigned int x, unsigned int y, unsigned int z, unsigned int w);
+ UInt4(const RValue<UInt4> &rhs);
+ UInt4(const UInt4 &rhs);
+
+ RValue<UInt4> operator=(const RValue<UInt4> &rhs) const;
+ RValue<UInt4> operator=(const UInt4 &rhs) const;
+ // RValue<Pointer<UInt4>> operator&();
+
+ friend RValue<UInt4> operator+(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator-(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator*(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator/(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator%(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator&(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator|(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator^(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator<<(const RValue<UInt4> &lhs, unsigned char rhs);
+ friend RValue<UInt4> operator>>(const RValue<UInt4> &lhs, unsigned char rhs);
+ friend RValue<UInt4> operator+=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator-=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator*=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator/=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator%=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator&=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator|=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator^=(const UInt4 &lhs, const RValue<UInt4> &rhs);
+ friend RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs);
+ friend RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs);
+ friend RValue<UInt4> operator+(const RValue<UInt4> &val);
+ friend RValue<UInt4> operator-(const RValue<UInt4> &val);
+ friend RValue<UInt4> operator~(const RValue<UInt4> &val);
+ // friend RValue<UInt4> operator++(const UInt4 &val, int); // Post-increment
+ // friend const UInt4 &operator++(const UInt4 &val); // Pre-increment
+ // friend RValue<UInt4> operator--(const UInt4 &val, int); // Post-decrement
+ // friend const UInt4 &operator--(const UInt4 &val); // Pre-decrement
+ // friend RValue<Bool> operator<(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ // friend RValue<Bool> operator<=(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ // friend RValue<Bool> operator>(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ // friend RValue<Bool> operator>=(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ // friend RValue<Bool> operator!=(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+ // friend RValue<Bool> operator==(const RValue<UInt4> &lhs, const RValue<UInt4> &rhs);
+
+ // friend RValue<UInt4> RoundInt(const RValue<Float4> &cast);
+ friend RValue<UShort8> Pack(const RValue<UInt4> &x, const RValue<UInt4> &y);
+ friend RValue<UInt4> Concatenate(const RValue<UInt2> &lo, const RValue<UInt2> &hi);
+
+ UInt4 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Float : public Variable<float>
+ {
+ public:
+ explicit Float(const RValue<Int> &cast);
+
+ Float();
+ Float(float x);
+ Float(const RValue<Float> &rhs);
+ Float(const Float &rhs);
+
+ // RValue<Float> operator=(float rhs) const; // FIXME: Implement
+ RValue<Float> operator=(const RValue<Float> &rhs) const;
+ RValue<Float> operator=(const Float &rhs) const;
+ RValue<Pointer<Float>> operator&();
+
+ friend RValue<Float> operator+(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator-(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator*(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator/(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator+=(const Float &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator-=(const Float &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator*=(const Float &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator/=(const Float &lhs, const RValue<Float> &rhs);
+ friend RValue<Float> operator+(const RValue<Float> &val);
+ friend RValue<Float> operator-(const RValue<Float> &val);
+ friend RValue<Bool> operator<(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Bool> operator<=(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Bool> operator>(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Bool> operator>=(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Bool> operator!=(const RValue<Float> &lhs, const RValue<Float> &rhs);
+ friend RValue<Bool> operator==(const RValue<Float> &lhs, const RValue<Float> &rhs);
+
+ friend RValue<Float> Abs(const RValue<Float> &x);
+ friend RValue<Float> Max(const RValue<Float> &x, const RValue<Float> &y);
+ friend RValue<Float> Min(const RValue<Float> &x, const RValue<Float> &y);
+
+ friend RValue<Float> Rcp_pp(const RValue<Float> &val);
+ friend RValue<Float> RcpSqrt_pp(const RValue<Float> &val);
+ friend RValue<Float> Sqrt(const RValue<Float> &x);
+
+ friend RValue<Float> Fraction(const RValue<Float> &val);
+ friend RValue<Float> Floor(const RValue<Float> &val);
+
+ Float *getThis();
+ static const llvm::Type *getType();
+ };
+
+ class Float2 : public Variable<float2>
+ {
+ public:
+ // explicit Float2(const RValue<Byte2> &cast);
+ // explicit Float2(const RValue<Short2> &cast);
+ // explicit Float2(const RValue<UShort2> &cast);
+ // explicit Float2(const RValue<Int2> &cast);
+ // explicit Float2(const RValue<UInt2> &cast);
+ explicit Float2(const RValue<Float4> &cast);
+
+ // Float2();
+ // Float2(float x, float y);
+ // Float2(const RValue<Float2> &rhs);
+ // Float2(const Float2 &rhs);
+ // Float2(const RValue<Float> &rhs);
+ // Float2(const Float &rhs);
+
+ // template<int T>
+ // Float2(const SwizzleMask1Float4<T> &rhs);
+
+ // RValue<Float2> operator=(float replicate) const;
+ // RValue<Float2> operator=(const RValue<Float2> &rhs) const;
+ // RValue<Float2> operator=(const Float2 &rhs) const;
+ // RValue<Float2> operator=(const RValue<Float> &rhs) const;
+ // RValue<Float2> operator=(const Float &rhs) const;
+
+ // template<int T>
+ // RValue<Float2> operator=(const SwizzleMask1Float4<T> &rhs);
+
+ // RValue<Pointer<Float2>> operator&();
+
+ // friend RValue<Float2> operator+(const RValue<Float2> &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator-(const RValue<Float2> &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator*(const RValue<Float2> &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator/(const RValue<Float2> &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator%(const RValue<Float2> &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator+=(const Float2 &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator-=(const Float2 &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator*=(const Float2 &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator/=(const Float2 &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator%=(const Float2 &lhs, const RValue<Float2> &rhs);
+ // friend RValue<Float2> operator+(const RValue<Float2> &val);
+ // friend RValue<Float2> operator-(const RValue<Float2> &val);
+
+ // friend RValue<Float2> Abs(const RValue<Float2> &x);
+ // friend RValue<Float2> Max(const RValue<Float2> &x, const RValue<Float2> &y);
+ // friend RValue<Float2> Min(const RValue<Float2> &x, const RValue<Float2> &y);
+
+ // friend RValue<Float2> Swizzle(const RValue<Float2> &x, unsigned char select);
+ // friend RValue<Float2> Mask(Float2 &lhs, const RValue<Float2> &rhs, unsigned char select);
+
+ Float2 *getThis();
+ static const llvm::Type *getType();
+ };
+
+ template<int T>
+ class Swizzle2Float4
+ {
+ friend Float4;
+
+ public:
+ operator RValue<Float4>() const;
+
+ private:
+ Float4 *parent;
+ };
+
+ template<int T>
+ class SwizzleFloat4
+ {
+ public:
+ operator RValue<Float4>() const;
+
+ private:
+ Float4 *parent;
+ };
+
+ template<int T>
+ class SwizzleMaskFloat4
+ {
+ friend Float4;
+
+ public:
+ operator RValue<Float4>() const;
+
+ RValue<Float4> operator=(const RValue<Float4> &rhs) const;
+ RValue<Float4> operator=(const RValue<Float> &rhs) const;
+
+ private:
+ Float4 *parent;
+ };
+
+ template<int T>
+ class SwizzleMask1Float4
+ {
+ public:
+ operator RValue<Float>() const;
+ operator RValue<Float4>() const;
+
+ RValue<Float4> operator=(float x) const;
+ RValue<Float4> operator=(const RValue<Float4> &rhs) const;
+ RValue<Float4> operator=(const RValue<Float> &rhs) const;
+
+ private:
+ Float4 *parent;
+ };
+
+ template<int T>
+ class SwizzleMask2Float4
+ {
+ friend Float4;
+
+ public:
+ operator RValue<Float4>() const;
+
+ RValue<Float4> operator=(const RValue<Float4> &rhs) const;
+
+ private:
+ Float4 *parent;
+ };
+
+ class Float4 : public Variable<float4>
+ {
+ public:
+ explicit Float4(const RValue<Byte4> &cast);
+ explicit Float4(const RValue<SByte4> &cast);
+ explicit Float4(const RValue<Short4> &cast);
+ explicit Float4(const RValue<UShort4> &cast);
+ explicit Float4(const RValue<Int4> &cast);
+ explicit Float4(const RValue<UInt4> &cast);
+
+ Float4();
+ Float4(float xyzw);
+ Float4(float x, float yzw);
+ Float4(float x, float y, float zw);
+ Float4(float x, float y, float z, float w);
+ Float4(const RValue<Float4> &rhs);
+ Float4(const Float4 &rhs);
+ Float4(const RValue<Float> &rhs);
+ Float4(const Float &rhs);
+
+ template<int T>
+ Float4(const SwizzleMask1Float4<T> &rhs);
+ template<int X, int Y>
+ Float4(const Swizzle2Float4<X> &x, const Swizzle2Float4<Y> &y);
+ template<int X, int Y>
+ Float4(const SwizzleMask2Float4<X> &x, const Swizzle2Float4<Y> &y);
+ template<int X, int Y>
+ Float4(const Swizzle2Float4<X> &x, const SwizzleMask2Float4<Y> &y);
+ template<int X, int Y>
+ Float4(const SwizzleMask2Float4<X> &x, const SwizzleMask2Float4<Y> &y);
+
+ RValue<Float4> operator=(float replicate) const;
+ RValue<Float4> operator=(const RValue<Float4> &rhs) const;
+ RValue<Float4> operator=(const Float4 &rhs) const;
+ RValue<Float4> operator=(const RValue<Float> &rhs) const;
+ RValue<Float4> operator=(const Float &rhs) const;
+
+ template<int T>
+ RValue<Float4> operator=(const SwizzleMask1Float4<T> &rhs);
+
+ RValue<Pointer<Float4>> operator&();
+
+ friend RValue<Float4> operator+(const RValue<Float4> &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator-(const RValue<Float4> &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator*(const RValue<Float4> &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator/(const RValue<Float4> &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator%(const RValue<Float4> &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator+=(const Float4 &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator-=(const Float4 &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator*=(const Float4 &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator/=(const Float4 &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator%=(const Float4 &lhs, const RValue<Float4> &rhs);
+ friend RValue<Float4> operator+(const RValue<Float4> &val);
+ friend RValue<Float4> operator-(const RValue<Float4> &val);
+
+ friend RValue<Float4> Abs(const RValue<Float4> &x);
+ friend RValue<Float4> Max(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Float4> Min(const RValue<Float4> &x, const RValue<Float4> &y);
+
+ friend RValue<Float4> Rcp_pp(const RValue<Float4> &val);
+ friend RValue<Float4> RcpSqrt_pp(const RValue<Float4> &val);
+ friend RValue<Float4> Sqrt(const RValue<Float4> &x);
+
+ friend RValue<Float4> Insert(const Float4 &val, const RValue<Float> &element, int i);
+ friend RValue<Float> Extract(const RValue<Float4> &x, int i);
+ friend RValue<Float4> Swizzle(const RValue<Float4> &x, unsigned char select);
+ friend RValue<Float4> ShuffleLowHigh(const RValue<Float4> &x, const RValue<Float4> &y, unsigned char imm);
+ friend RValue<Float4> UnpackLow(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Float4> UnpackHigh(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Float4> Mask(Float4 &lhs, const RValue<Float4> &rhs, unsigned char select);
+ friend RValue<Int> SignMask(const RValue<Float4> &x);
+
+ friend RValue<Int4> CmpEQ(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Int4> CmpLT(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Int4> CmpLE(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Int4> CmpNEQ(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Int4> CmpNLT(const RValue<Float4> &x, const RValue<Float4> &y);
+ friend RValue<Int4> CmpNLE(const RValue<Float4> &x, const RValue<Float4> &y);
+
+ friend RValue<Float4> Fraction(const RValue<Float4> &x);
+ friend RValue<Float4> Floor(const RValue<Float4> &x);
+
+ Float4 *getThis();
+ static const llvm::Type *getType();
+
+ union
+ {
+ SwizzleMask1Float4<0x00> x;
+ SwizzleMask1Float4<0x55> y;
+ SwizzleMask1Float4<0xAA> z;
+ SwizzleMask1Float4<0xFF> w;
+ Swizzle2Float4<0x00> xx;
+ Swizzle2Float4<0x01> yx;
+ Swizzle2Float4<0x02> zx;
+ Swizzle2Float4<0x03> wx;
+ SwizzleMask2Float4<0x54> xy;
+ Swizzle2Float4<0x55> yy;
+ Swizzle2Float4<0x56> zy;
+ Swizzle2Float4<0x57> wy;
+ SwizzleMask2Float4<0xA8> xz;
+ SwizzleMask2Float4<0xA9> yz;
+ Swizzle2Float4<0xAA> zz;
+ Swizzle2Float4<0xAB> wz;
+ SwizzleMask2Float4<0xFC> xw;
+ SwizzleMask2Float4<0xFD> yw;
+ SwizzleMask2Float4<0xFE> zw;
+ Swizzle2Float4<0xFF> ww;
+ SwizzleFloat4<0x00> xxx;
+ SwizzleFloat4<0x01> yxx;
+ SwizzleFloat4<0x02> zxx;
+ SwizzleFloat4<0x03> wxx;
+ SwizzleFloat4<0x04> xyx;
+ SwizzleFloat4<0x05> yyx;
+ SwizzleFloat4<0x06> zyx;
+ SwizzleFloat4<0x07> wyx;
+ SwizzleFloat4<0x08> xzx;
+ SwizzleFloat4<0x09> yzx;
+ SwizzleFloat4<0x0A> zzx;
+ SwizzleFloat4<0x0B> wzx;
+ SwizzleFloat4<0x0C> xwx;
+ SwizzleFloat4<0x0D> ywx;
+ SwizzleFloat4<0x0E> zwx;
+ SwizzleFloat4<0x0F> wwx;
+ SwizzleFloat4<0x50> xxy;
+ SwizzleFloat4<0x51> yxy;
+ SwizzleFloat4<0x52> zxy;
+ SwizzleFloat4<0x53> wxy;
+ SwizzleFloat4<0x54> xyy;
+ SwizzleFloat4<0x55> yyy;
+ SwizzleFloat4<0x56> zyy;
+ SwizzleFloat4<0x57> wyy;
+ SwizzleFloat4<0x58> xzy;
+ SwizzleFloat4<0x59> yzy;
+ SwizzleFloat4<0x5A> zzy;
+ SwizzleFloat4<0x5B> wzy;
+ SwizzleFloat4<0x5C> xwy;
+ SwizzleFloat4<0x5D> ywy;
+ SwizzleFloat4<0x5E> zwy;
+ SwizzleFloat4<0x5F> wwy;
+ SwizzleFloat4<0xA0> xxz;
+ SwizzleFloat4<0xA1> yxz;
+ SwizzleFloat4<0xA2> zxz;
+ SwizzleFloat4<0xA3> wxz;
+ SwizzleMaskFloat4<0xA4> xyz;
+ SwizzleFloat4<0xA5> yyz;
+ SwizzleFloat4<0xA6> zyz;
+ SwizzleFloat4<0xA7> wyz;
+ SwizzleFloat4<0xA8> xzz;
+ SwizzleFloat4<0xA9> yzz;
+ SwizzleFloat4<0xAA> zzz;
+ SwizzleFloat4<0xAB> wzz;
+ SwizzleFloat4<0xAC> xwz;
+ SwizzleFloat4<0xAD> ywz;
+ SwizzleFloat4<0xAE> zwz;
+ SwizzleFloat4<0xAF> wwz;
+ SwizzleFloat4<0xF0> xxw;
+ SwizzleFloat4<0xF1> yxw;
+ SwizzleFloat4<0xF2> zxw;
+ SwizzleFloat4<0xF3> wxw;
+ SwizzleMaskFloat4<0xF4> xyw;
+ SwizzleFloat4<0xF5> yyw;
+ SwizzleFloat4<0xF6> zyw;
+ SwizzleFloat4<0xF7> wyw;
+ SwizzleMaskFloat4<0xF8> xzw;
+ SwizzleMaskFloat4<0xF9> yzw;
+ SwizzleFloat4<0xFA> zzw;
+ SwizzleFloat4<0xFB> wzw;
+ SwizzleFloat4<0xFC> xww;
+ SwizzleFloat4<0xFD> yww;
+ SwizzleFloat4<0xFE> zww;
+ SwizzleFloat4<0xFF> www;
+ SwizzleFloat4<0x00> xxxx;
+ SwizzleFloat4<0x01> yxxx;
+ SwizzleFloat4<0x02> zxxx;
+ SwizzleFloat4<0x03> wxxx;
+ SwizzleFloat4<0x04> xyxx;
+ SwizzleFloat4<0x05> yyxx;
+ SwizzleFloat4<0x06> zyxx;
+ SwizzleFloat4<0x07> wyxx;
+ SwizzleFloat4<0x08> xzxx;
+ SwizzleFloat4<0x09> yzxx;
+ SwizzleFloat4<0x0A> zzxx;
+ SwizzleFloat4<0x0B> wzxx;
+ SwizzleFloat4<0x0C> xwxx;
+ SwizzleFloat4<0x0D> ywxx;
+ SwizzleFloat4<0x0E> zwxx;
+ SwizzleFloat4<0x0F> wwxx;
+ SwizzleFloat4<0x10> xxyx;
+ SwizzleFloat4<0x11> yxyx;
+ SwizzleFloat4<0x12> zxyx;
+ SwizzleFloat4<0x13> wxyx;
+ SwizzleFloat4<0x14> xyyx;
+ SwizzleFloat4<0x15> yyyx;
+ SwizzleFloat4<0x16> zyyx;
+ SwizzleFloat4<0x17> wyyx;
+ SwizzleFloat4<0x18> xzyx;
+ SwizzleFloat4<0x19> yzyx;
+ SwizzleFloat4<0x1A> zzyx;
+ SwizzleFloat4<0x1B> wzyx;
+ SwizzleFloat4<0x1C> xwyx;
+ SwizzleFloat4<0x1D> ywyx;
+ SwizzleFloat4<0x1E> zwyx;
+ SwizzleFloat4<0x1F> wwyx;
+ SwizzleFloat4<0x20> xxzx;
+ SwizzleFloat4<0x21> yxzx;
+ SwizzleFloat4<0x22> zxzx;
+ SwizzleFloat4<0x23> wxzx;
+ SwizzleFloat4<0x24> xyzx;
+ SwizzleFloat4<0x25> yyzx;
+ SwizzleFloat4<0x26> zyzx;
+ SwizzleFloat4<0x27> wyzx;
+ SwizzleFloat4<0x28> xzzx;
+ SwizzleFloat4<0x29> yzzx;
+ SwizzleFloat4<0x2A> zzzx;
+ SwizzleFloat4<0x2B> wzzx;
+ SwizzleFloat4<0x2C> xwzx;
+ SwizzleFloat4<0x2D> ywzx;
+ SwizzleFloat4<0x2E> zwzx;
+ SwizzleFloat4<0x2F> wwzx;
+ SwizzleFloat4<0x30> xxwx;
+ SwizzleFloat4<0x31> yxwx;
+ SwizzleFloat4<0x32> zxwx;
+ SwizzleFloat4<0x33> wxwx;
+ SwizzleFloat4<0x34> xywx;
+ SwizzleFloat4<0x35> yywx;
+ SwizzleFloat4<0x36> zywx;
+ SwizzleFloat4<0x37> wywx;
+ SwizzleFloat4<0x38> xzwx;
+ SwizzleFloat4<0x39> yzwx;
+ SwizzleFloat4<0x3A> zzwx;
+ SwizzleFloat4<0x3B> wzwx;
+ SwizzleFloat4<0x3C> xwwx;
+ SwizzleFloat4<0x3D> ywwx;
+ SwizzleFloat4<0x3E> zwwx;
+ SwizzleFloat4<0x3F> wwwx;
+ SwizzleFloat4<0x40> xxxy;
+ SwizzleFloat4<0x41> yxxy;
+ SwizzleFloat4<0x42> zxxy;
+ SwizzleFloat4<0x43> wxxy;
+ SwizzleFloat4<0x44> xyxy;
+ SwizzleFloat4<0x45> yyxy;
+ SwizzleFloat4<0x46> zyxy;
+ SwizzleFloat4<0x47> wyxy;
+ SwizzleFloat4<0x48> xzxy;
+ SwizzleFloat4<0x49> yzxy;
+ SwizzleFloat4<0x4A> zzxy;
+ SwizzleFloat4<0x4B> wzxy;
+ SwizzleFloat4<0x4C> xwxy;
+ SwizzleFloat4<0x4D> ywxy;
+ SwizzleFloat4<0x4E> zwxy;
+ SwizzleFloat4<0x4F> wwxy;
+ SwizzleFloat4<0x50> xxyy;
+ SwizzleFloat4<0x51> yxyy;
+ SwizzleFloat4<0x52> zxyy;
+ SwizzleFloat4<0x53> wxyy;
+ SwizzleFloat4<0x54> xyyy;
+ SwizzleFloat4<0x55> yyyy;
+ SwizzleFloat4<0x56> zyyy;
+ SwizzleFloat4<0x57> wyyy;
+ SwizzleFloat4<0x58> xzyy;
+ SwizzleFloat4<0x59> yzyy;
+ SwizzleFloat4<0x5A> zzyy;
+ SwizzleFloat4<0x5B> wzyy;
+ SwizzleFloat4<0x5C> xwyy;
+ SwizzleFloat4<0x5D> ywyy;
+ SwizzleFloat4<0x5E> zwyy;
+ SwizzleFloat4<0x5F> wwyy;
+ SwizzleFloat4<0x60> xxzy;
+ SwizzleFloat4<0x61> yxzy;
+ SwizzleFloat4<0x62> zxzy;
+ SwizzleFloat4<0x63> wxzy;
+ SwizzleFloat4<0x64> xyzy;
+ SwizzleFloat4<0x65> yyzy;
+ SwizzleFloat4<0x66> zyzy;
+ SwizzleFloat4<0x67> wyzy;
+ SwizzleFloat4<0x68> xzzy;
+ SwizzleFloat4<0x69> yzzy;
+ SwizzleFloat4<0x6A> zzzy;
+ SwizzleFloat4<0x6B> wzzy;
+ SwizzleFloat4<0x6C> xwzy;
+ SwizzleFloat4<0x6D> ywzy;
+ SwizzleFloat4<0x6E> zwzy;
+ SwizzleFloat4<0x6F> wwzy;
+ SwizzleFloat4<0x70> xxwy;
+ SwizzleFloat4<0x71> yxwy;
+ SwizzleFloat4<0x72> zxwy;
+ SwizzleFloat4<0x73> wxwy;
+ SwizzleFloat4<0x74> xywy;
+ SwizzleFloat4<0x75> yywy;
+ SwizzleFloat4<0x76> zywy;
+ SwizzleFloat4<0x77> wywy;
+ SwizzleFloat4<0x78> xzwy;
+ SwizzleFloat4<0x79> yzwy;
+ SwizzleFloat4<0x7A> zzwy;
+ SwizzleFloat4<0x7B> wzwy;
+ SwizzleFloat4<0x7C> xwwy;
+ SwizzleFloat4<0x7D> ywwy;
+ SwizzleFloat4<0x7E> zwwy;
+ SwizzleFloat4<0x7F> wwwy;
+ SwizzleFloat4<0x80> xxxz;
+ SwizzleFloat4<0x81> yxxz;
+ SwizzleFloat4<0x82> zxxz;
+ SwizzleFloat4<0x83> wxxz;
+ SwizzleFloat4<0x84> xyxz;
+ SwizzleFloat4<0x85> yyxz;
+ SwizzleFloat4<0x86> zyxz;
+ SwizzleFloat4<0x87> wyxz;
+ SwizzleFloat4<0x88> xzxz;
+ SwizzleFloat4<0x89> yzxz;
+ SwizzleFloat4<0x8A> zzxz;
+ SwizzleFloat4<0x8B> wzxz;
+ SwizzleFloat4<0x8C> xwxz;
+ SwizzleFloat4<0x8D> ywxz;
+ SwizzleFloat4<0x8E> zwxz;
+ SwizzleFloat4<0x8F> wwxz;
+ SwizzleFloat4<0x90> xxyz;
+ SwizzleFloat4<0x91> yxyz;
+ SwizzleFloat4<0x92> zxyz;
+ SwizzleFloat4<0x93> wxyz;
+ SwizzleFloat4<0x94> xyyz;
+ SwizzleFloat4<0x95> yyyz;
+ SwizzleFloat4<0x96> zyyz;
+ SwizzleFloat4<0x97> wyyz;
+ SwizzleFloat4<0x98> xzyz;
+ SwizzleFloat4<0x99> yzyz;
+ SwizzleFloat4<0x9A> zzyz;
+ SwizzleFloat4<0x9B> wzyz;
+ SwizzleFloat4<0x9C> xwyz;
+ SwizzleFloat4<0x9D> ywyz;
+ SwizzleFloat4<0x9E> zwyz;
+ SwizzleFloat4<0x9F> wwyz;
+ SwizzleFloat4<0xA0> xxzz;
+ SwizzleFloat4<0xA1> yxzz;
+ SwizzleFloat4<0xA2> zxzz;
+ SwizzleFloat4<0xA3> wxzz;
+ SwizzleFloat4<0xA4> xyzz;
+ SwizzleFloat4<0xA5> yyzz;
+ SwizzleFloat4<0xA6> zyzz;
+ SwizzleFloat4<0xA7> wyzz;
+ SwizzleFloat4<0xA8> xzzz;
+ SwizzleFloat4<0xA9> yzzz;
+ SwizzleFloat4<0xAA> zzzz;
+ SwizzleFloat4<0xAB> wzzz;
+ SwizzleFloat4<0xAC> xwzz;
+ SwizzleFloat4<0xAD> ywzz;
+ SwizzleFloat4<0xAE> zwzz;
+ SwizzleFloat4<0xAF> wwzz;
+ SwizzleFloat4<0xB0> xxwz;
+ SwizzleFloat4<0xB1> yxwz;
+ SwizzleFloat4<0xB2> zxwz;
+ SwizzleFloat4<0xB3> wxwz;
+ SwizzleFloat4<0xB4> xywz;
+ SwizzleFloat4<0xB5> yywz;
+ SwizzleFloat4<0xB6> zywz;
+ SwizzleFloat4<0xB7> wywz;
+ SwizzleFloat4<0xB8> xzwz;
+ SwizzleFloat4<0xB9> yzwz;
+ SwizzleFloat4<0xBA> zzwz;
+ SwizzleFloat4<0xBB> wzwz;
+ SwizzleFloat4<0xBC> xwwz;
+ SwizzleFloat4<0xBD> ywwz;
+ SwizzleFloat4<0xBE> zwwz;
+ SwizzleFloat4<0xBF> wwwz;
+ SwizzleFloat4<0xC0> xxxw;
+ SwizzleFloat4<0xC1> yxxw;
+ SwizzleFloat4<0xC2> zxxw;
+ SwizzleFloat4<0xC3> wxxw;
+ SwizzleFloat4<0xC4> xyxw;
+ SwizzleFloat4<0xC5> yyxw;
+ SwizzleFloat4<0xC6> zyxw;
+ SwizzleFloat4<0xC7> wyxw;
+ SwizzleFloat4<0xC8> xzxw;
+ SwizzleFloat4<0xC9> yzxw;
+ SwizzleFloat4<0xCA> zzxw;
+ SwizzleFloat4<0xCB> wzxw;
+ SwizzleFloat4<0xCC> xwxw;
+ SwizzleFloat4<0xCD> ywxw;
+ SwizzleFloat4<0xCE> zwxw;
+ SwizzleFloat4<0xCF> wwxw;
+ SwizzleFloat4<0xD0> xxyw;
+ SwizzleFloat4<0xD1> yxyw;
+ SwizzleFloat4<0xD2> zxyw;
+ SwizzleFloat4<0xD3> wxyw;
+ SwizzleFloat4<0xD4> xyyw;
+ SwizzleFloat4<0xD5> yyyw;
+ SwizzleFloat4<0xD6> zyyw;
+ SwizzleFloat4<0xD7> wyyw;
+ SwizzleFloat4<0xD8> xzyw;
+ SwizzleFloat4<0xD9> yzyw;
+ SwizzleFloat4<0xDA> zzyw;
+ SwizzleFloat4<0xDB> wzyw;
+ SwizzleFloat4<0xDC> xwyw;
+ SwizzleFloat4<0xDD> ywyw;
+ SwizzleFloat4<0xDE> zwyw;
+ SwizzleFloat4<0xDF> wwyw;
+ SwizzleFloat4<0xE0> xxzw;
+ SwizzleFloat4<0xE1> yxzw;
+ SwizzleFloat4<0xE2> zxzw;
+ SwizzleFloat4<0xE3> wxzw;
+ SwizzleMaskFloat4<0xE4> xyzw;
+ SwizzleFloat4<0xE5> yyzw;
+ SwizzleFloat4<0xE6> zyzw;
+ SwizzleFloat4<0xE7> wyzw;
+ SwizzleFloat4<0xE8> xzzw;
+ SwizzleFloat4<0xE9> yzzw;
+ SwizzleFloat4<0xEA> zzzw;
+ SwizzleFloat4<0xEB> wzzw;
+ SwizzleFloat4<0xEC> xwzw;
+ SwizzleFloat4<0xED> ywzw;
+ SwizzleFloat4<0xEE> zwzw;
+ SwizzleFloat4<0xEF> wwzw;
+ SwizzleFloat4<0xF0> xxww;
+ SwizzleFloat4<0xF1> yxww;
+ SwizzleFloat4<0xF2> zxww;
+ SwizzleFloat4<0xF3> wxww;
+ SwizzleFloat4<0xF4> xyww;
+ SwizzleFloat4<0xF5> yyww;
+ SwizzleFloat4<0xF6> zyww;
+ SwizzleFloat4<0xF7> wyww;
+ SwizzleFloat4<0xF8> xzww;
+ SwizzleFloat4<0xF9> yzww;
+ SwizzleFloat4<0xFA> zzww;
+ SwizzleFloat4<0xFB> wzww;
+ SwizzleFloat4<0xFC> xwww;
+ SwizzleFloat4<0xFD> ywww;
+ SwizzleFloat4<0xFE> zwww;
+ SwizzleFloat4<0xFF> wwww;
+ };
+
+ private:
+ void constant(float x, float y, float z, float w);
+ };
+
+ template<class T>
+ class Pointer : public Variable<T*>
+ {
+ public:
+ template<class S>
+ Pointer(const RValue<Pointer<S>> &pointerS, int alignment = 1) : alignment(alignment)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ llvm::Value *pointerT = Nucleus::createBitCast(pointerS.value, Nucleus::getPointerType(T::getType()));
+ Nucleus::createStore(pointerT, address);
+ }
+
+ template<class S>
+ Pointer(const Pointer<S> &pointer, int alignment = 1) : alignment(alignment)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ llvm::Value *pointerS = Nucleus::createLoad(pointer.address);
+ llvm::Value *pointerT = Nucleus::createBitCast(pointerS, Nucleus::getPointerType(T::getType()));
+ Nucleus::createStore(pointerT, address);
+ }
+
+ explicit Pointer(llvm::Value *pointer);
+ explicit Pointer(llvm::Argument *argument);
+ explicit Pointer(const void *external);
+
+ Pointer();
+ Pointer(const RValue<Pointer<T>> &rhs);
+ Pointer(const Pointer<T> &rhs);
+
+ RValue<Pointer<T>> operator=(const RValue<Pointer<T>> &rhs) const;
+ RValue<Pointer<T>> operator=(const Pointer<T> &rhs) const;
+
+ Reference<T> operator*();
+
+ friend RValue<Pointer<Byte>> operator+(const RValue<Pointer<Byte>> &lhs, int offset);
+ friend RValue<Pointer<Byte>> operator+(const RValue<Pointer<Byte>> &lhs, const RValue<Int> &offset);
+ friend RValue<Pointer<Byte>> operator+(const RValue<Pointer<Byte>> &lhs, const RValue<UInt> &offset);
+ friend RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset);
+ friend RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, const RValue<Int> &offset);
+ friend RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, const RValue<UInt> &offset);
+
+ friend RValue<Pointer<Byte>> operator-(const RValue<Pointer<Byte>> &lhs, int offset);
+ friend RValue<Pointer<Byte>> operator-(const RValue<Pointer<Byte>> &lhs, const RValue<Int> &offset);
+ friend RValue<Pointer<Byte>> operator-(const RValue<Pointer<Byte>> &lhs, const RValue<UInt> &offset);
+ friend RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset);
+ friend RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, const RValue<Int> &offset);
+ friend RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, const RValue<UInt> &offset);
+
+ static const llvm::Type *getType();
+
+ private:
+ const int alignment;
+ };
+
+ template<class T>
+ class Array : public Variable<T[]>
+ {
+ public:
+ Array(int size);
+
+ Reference<T> operator[](int index);
+ Reference<T> operator[](RValue<Int> index);
+ Reference<T> operator[](RValue<UInt> index);
+
+ // friend RValue<Array<T>> operator++(const Array<T> &val, int); // Post-increment
+ // friend const Array<T> &operator++(const Array<T> &val); // Pre-increment
+ // friend RValue<Array<T>> operator--(const Array<T> &val, int); // Post-decrement
+ // friend const Array<T> &operator--(const Array<T> &val); // Pre-decrement
+ };
+
+ llvm::BasicBlock *beginLoop();
+ bool branch(const RValue<Bool> &cmp, llvm::BasicBlock *bodyBB, llvm::BasicBlock *endBB);
+ bool elseBlock(llvm::BasicBlock *falseBB);
+
+ void Return();
+ void Return(const Int &ret);
+
+ template<class T>
+ void Return(const Pointer<T> &ret);
+
+ template<class T>
+ void Return(const RValue<Pointer<T>> &ret);
+
+ template<class R = Void, class A1 = Void, class A2 = Void, class A3 = Void, class A4 = Void>
+ class Function
+ {
+ public:
+ Function();
+
+ virtual ~Function();
+
+ llvm::Argument *arg(int index);
+
+ Routine *operator()(const wchar_t *name, ...);
+
+ private:
+ Nucleus *core;
+ llvm::Function *function;
+ std::vector<const llvm::Type*> arguments;
+ };
+
+ RValue<Long> Ticks();
+ void Emms();
+}
+
+namespace sw
+{
+ template<class T>
+ Reference<T>::Reference(llvm::Value *pointer, int alignment) : alignment(alignment)
+ {
+ address = pointer;
+ }
+
+ template<class T>
+ RValue<T> Reference<T>::operator=(const RValue<T> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address, false, alignment);
+
+ return rhs;
+ }
+
+ template<class T>
+ Reference<T>::operator RValue<T>() const
+ {
+ return RValue<T>(Nucleus::createLoad(address, false, alignment));
+ }
+
+ template<class T>
+ RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
+ {
+ llvm::Value *tmp = Nucleus::createLoad(ref.address, false, ref.alignment);
+ Nucleus::createStore(tmp, address, false, alignment);
+
+ return RValue<T>(tmp);
+ }
+
+ template<class T>
+ RValue<T> Reference<T>::operator+=(const RValue<T> &rhs) const
+ {
+ return *this = *this + rhs;
+ }
+
+ template<class T>
+ RValue<T>::RValue(llvm::Value *rvalue)
+ {
+ value = rvalue;
+ }
+
+ template<class T>
+ RValue<T>::RValue(const T &lvalue)
+ {
+ value = Nucleus::createLoad(lvalue.address);
+ }
+
+ template<class T>
+ RValue<T>::RValue(typename IntLiteral<T>::type i)
+ {
+ value = (llvm::Value*)Nucleus::createConstantInt(i);
+ }
+
+ template<int T>
+ Swizzle2Float4<T>::operator RValue<Float4>() const
+ {
+ llvm::Value *vector = Nucleus::createLoad(parent->address);
+
+ return RValue<Float4>(Nucleus::createSwizzle(vector, T));
+ }
+
+ template<int T>
+ SwizzleFloat4<T>::operator RValue<Float4>() const
+ {
+ llvm::Value *vector = Nucleus::createLoad(parent->address);
+
+ return RValue<Float4>(Nucleus::createSwizzle(vector, T));
+ }
+
+ template<int T>
+ SwizzleMaskFloat4<T>::operator RValue<Float4>() const
+ {
+ llvm::Value *vector = Nucleus::createLoad(parent->address);
+
+ return RValue<Float4>(Nucleus::createSwizzle(vector, T));
+ }
+
+ template<int T>
+ RValue<Float4> SwizzleMaskFloat4<T>::operator=(const RValue<Float4> &rhs) const
+ {
+ return Mask(*parent, rhs, T);
+ }
+
+ template<int T>
+ RValue<Float4> SwizzleMaskFloat4<T>::operator=(const RValue<Float> &rhs) const
+ {
+ return Mask(*parent, Float4(rhs), T);
+ }
+
+ template<int T>
+ SwizzleMask1Float4<T>::operator RValue<Float>() const // FIXME: Call a non-template function
+ {
+ return Extract(*parent, T & 0x3);
+ }
+
+ template<int T>
+ SwizzleMask1Float4<T>::operator RValue<Float4>() const
+ {
+ llvm::Value *vector = Nucleus::createLoad(parent->address);
+
+ return RValue<Float4>(Nucleus::createSwizzle(vector, T));
+ }
+
+ template<int T>
+ RValue<Float4> SwizzleMask1Float4<T>::operator=(float x) const
+ {
+ return Insert(*parent, Float(x), T & 0x3);
+ }
+
+ template<int T>
+ RValue<Float4> SwizzleMask1Float4<T>::operator=(const RValue<Float4> &rhs) const
+ {
+ return Mask(*parent, Float4(rhs), T);
+ }
+
+ template<int T>
+ RValue<Float4> SwizzleMask1Float4<T>::operator=(const RValue<Float> &rhs) const // FIXME: Call a non-template function
+ {
+ return Insert(*parent, rhs, T & 0x3);
+ }
+
+ template<int T>
+ SwizzleMask2Float4<T>::operator RValue<Float4>() const
+ {
+ llvm::Value *vector = Nucleus::createLoad(parent->address);
+
+ return RValue<Float4>(Nucleus::createSwizzle(vector, T));
+ }
+
+ template<int T>
+ RValue<Float4> SwizzleMask2Float4<T>::operator=(const RValue<Float4> &rhs) const
+ {
+ return Mask(*parent, Float4(rhs), T);
+ }
+
+ template<int T>
+ Float4::Float4(const SwizzleMask1Float4<T> &lhs)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = RValue<Float4>(lhs);
+ }
+
+ template<int X, int Y>
+ Float4::Float4(const Swizzle2Float4<X> &x, const Swizzle2Float4<Y> &y)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
+ }
+
+ template<int X, int Y>
+ Float4::Float4(const SwizzleMask2Float4<X> &x, const Swizzle2Float4<Y> &y)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
+ }
+
+ template<int X, int Y>
+ Float4::Float4(const Swizzle2Float4<X> &x, const SwizzleMask2Float4<Y> &y)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
+ }
+
+ template<int X, int Y>
+ Float4::Float4(const SwizzleMask2Float4<X> &x, const SwizzleMask2Float4<Y> &y)
+ {
+ xyzw.parent = this;
+ address = Nucleus::allocateStackVariable(getType());
+
+ *this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
+ }
+
+ template<int T>
+ RValue<Float4> Float4::operator=(const SwizzleMask1Float4<T> &lhs)
+ {
+ return *this = RValue<Float4>(lhs);
+ }
+
+ template<class T>
+ Pointer<T>::Pointer(llvm::Value *pointer) : alignment(1)
+ {
+ address = pointer;
+ }
+
+ template<class T>
+ Pointer<T>::Pointer(llvm::Argument *argument) : alignment(1)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ Nucleus::createStore((llvm::Value*)argument, address);
+ }
+
+ template<class T>
+ Pointer<T>::Pointer(const void *external) : alignment((size_t)external & 0x0000000F ? 1 : 16)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ llvm::Module *module = Nucleus::getModule();
+ const llvm::GlobalValue *globalPointer = Nucleus::getGlobalValueAtAddress(const_cast<void*>(external)); // FIXME: Const
+
+ if(!globalPointer)
+ {
+ globalPointer = Nucleus::createGlobalValue(T::getType(), false, alignment);
+
+ Nucleus::addGlobalMapping(globalPointer, const_cast<void*>(external)); // FIXME: Const
+ }
+
+ Nucleus::createStore((llvm::Value*)globalPointer, address); // FIXME: Const
+ }
+
+ template<class T>
+ Pointer<T>::Pointer() : alignment(1)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ Nucleus::createStore(Nucleus::createNullPointer(T::getType()), address);
+ }
+
+ template<class T>
+ Pointer<T>::Pointer(const RValue<Pointer<T>> &rhs) : alignment(1)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ Nucleus::createStore(rhs.value, address);
+ }
+
+ template<class T>
+ Pointer<T>::Pointer(const Pointer<T> &rhs) : alignment(rhs.alignment)
+ {
+ address = Nucleus::allocateStackVariable(Nucleus::getPointerType(T::getType()));
+
+ llvm::Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+ }
+
+ template<class T>
+ RValue<Pointer<T>> Pointer<T>::operator=(const RValue<Pointer<T>> &rhs) const
+ {
+ Nucleus::createStore(rhs.value, address);
+
+ return rhs;
+ }
+
+ template<class T>
+ RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs) const
+ {
+ llvm::Value *value = Nucleus::createLoad(rhs.address);
+ Nucleus::createStore(value, address);
+
+ return RValue<Pointer<T>>(value);
+ }
+
+ template<class T>
+ Reference<T> Pointer<T>::operator*()
+ {
+ return Reference<T>(Nucleus::createLoad(address), alignment);
+ }
+
+ template<class T>
+ const llvm::Type *Pointer<T>::getType()
+ {
+ return Nucleus::getPointerType(T::getType());
+ }
+
+ template<class T>
+ Array<T>::Array(int size)
+ {
+ address = Nucleus::allocateStackVariable(T::getType(), size);
+ }
+
+ template<class T>
+ Reference<T> Array<T>::operator[](int index)
+ {
+ llvm::Value *element = Nucleus::createGEP(address, (llvm::Value*)Nucleus::createConstantInt(index));
+
+ return Reference<T>(element);
+ }
+
+ template<class T>
+ Reference<T> Array<T>::operator[](RValue<Int> index)
+ {
+ llvm::Value *element = Nucleus::createGEP(address, index.value);
+
+ return Reference<T>(element);
+ }
+
+ template<class T>
+ Reference<T> Array<T>::operator[](RValue<UInt> index)
+ {
+ llvm::Value *element = Nucleus::createGEP(address, index.value);
+
+ return Reference<T>(element);
+ }
+
+// template<class T>
+// RValue<Array<T>> operator++(const Array<T> &val, int)
+// {
+// // FIXME: Requires storing the address of the array
+// }
+
+// template<class T>
+// const Array<T> &operator++(const Array<T> &val)
+// {
+// // FIXME: Requires storing the address of the array
+// }
+
+// template<class T>
+// RValue<Array<T>> operator--(const Array<T> &val, int)
+// {
+// // FIXME: Requires storing the address of the array
+// }
+
+// template<class T>
+// const Array<T> &operator--(const Array<T> &val)
+// {
+// // FIXME: Requires storing the address of the array
+// }
+
+ template<class T>
+ RValue<T> IfThenElse(const RValue<Bool> &condition, const RValue<T> &ifTrue, const RValue<T> &ifFalse)
+ {
+ return RValue<T>(Nucleus::createSelect(condition.value, ifTrue.value, ifFalse.value));
+ }
+
+ template<class T>
+ RValue<T> IfThenElse(const RValue<Bool> &condition, const T &ifTrue, const RValue<T> &ifFalse)
+ {
+ llvm::Value *trueValue = Nucleus::createLoad(ifTrue.address);
+
+ return RValue<T>(Nucleus::createSelect(condition.value, trueValue, ifFalse.value));
+ }
+
+ template<class T>
+ RValue<T> IfThenElse(const RValue<Bool> &condition, const RValue<T> &ifTrue, const T &ifFalse)
+ {
+ llvm::Value *falseValue = Nucleus::createLoad(ifFalse.address);
+
+ return RValue<T>(Nucleus::createSelect(condition.value, ifTrue.value, falseValue));
+ }
+
+ template<class T>
+ RValue<T> IfThenElse(const RValue<Bool> &condition, const T &ifTrue, const T &ifFalse)
+ {
+ llvm::Value *trueValue = Nucleus::createLoad(ifTrue.address);
+ llvm::Value *falseValue = Nucleus::createLoad(ifFalse.address);
+
+ return RValue<T>(Nucleus::createSelect(condition.value, trueValue, falseValue));
+ }
+
+ template<class T>
+ void Return(const Pointer<T> &ret)
+ {
+ Nucleus::createRet(Nucleus::createLoad(ret.address));
+ }
+
+ template<class T>
+ void Return(const RValue<Pointer<T>> &ret)
+ {
+ Nucleus::createRet(ret.value);
+ }
+
+ template<class R, class A1, class A2, class A3, class A4>
+ Function<R, A1, A2, A3, A4>::Function()
+ {
+ core = new Nucleus();
+
+ if(!A1::isVoid()) arguments.push_back(A1::getType());
+ if(!A2::isVoid()) arguments.push_back(A2::getType());
+ if(!A3::isVoid()) arguments.push_back(A3::getType());
+ if(!A4::isVoid()) arguments.push_back(A4::getType());
+
+ function = Nucleus::createFunction(R::getType(), arguments);
+ Nucleus::setFunction(function);
+ }
+
+ template<class R, class A1, class A2, class A3, class A4>
+ Function<R, A1, A2, A3, A4>::~Function()
+ {
+ delete core;
+ }
+
+ template<class R, class A1, class A2, class A3, class A4>
+ llvm::Argument *Function<R, A1, A2, A3, A4>::arg(int index)
+ {
+ return Nucleus::getArgument(function, index);
+ }
+
+ template<class R, class A1, class A2, class A3, class A4>
+ Routine *Function<R, A1, A2, A3, A4>::operator()(const wchar_t *name, ...)
+ {
+ wchar_t fullName[1024 + 1];
+
+ va_list vararg;
+ va_start(vararg, name);
+ vswprintf(fullName, 1024, name, vararg);
+ va_end(vararg);
+
+ return core->acquireRoutine(fullName, true);
+ }
+
+ template<class T, class S>
+ RValue<T> ReinterpretCast(const RValue<S> &val)
+ {
+ return RValue<T>(Nucleus::createBitCast(val.value, T::getType()));
+ }
+
+ template<class T, class S>
+ RValue<T> ReinterpretCast(const Variable<S> &var)
+ {
+ llvm::Value *val = Nucleus::createLoad(var.address);
+
+ return RValue<T>(Nucleus::createBitCast(val, T::getType()));
+ }
+
+ template<class T, class S>
+ RValue<T> ReinterpretCast(const Reference<S> &var)
+ {
+ return ReinterpretCast<T>(RValue<S>(var));
+ }
+
+ template<class T, class S>
+ RValue<T> As(const RValue<S> &val)
+ {
+ return ReinterpretCast<T>(val);
+ }
+
+ template<class T, class S>
+ RValue<T> As(const Variable<S> &var)
+ {
+ return ReinterpretCast<T>(var);
+ }
+
+ template<class T, class S>
+ RValue<T> As(const Reference<S> &val)
+ {
+ return ReinterpretCast<T>(val);
+ }
+}
+
+#endif // sw_Nucleus_hpp
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
new file mode 100644
index 0000000..314d7e6
--- /dev/null
+++ b/src/Reactor/Reactor.hpp
@@ -0,0 +1,13 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#include "Nucleus.hpp"
+#include "Shell.hpp"
\ No newline at end of file
diff --git a/src/Reactor/Reactor.vcxproj b/src/Reactor/Reactor.vcxproj
new file mode 100644
index 0000000..55285da
--- /dev/null
+++ b/src/Reactor/Reactor.vcxproj
@@ -0,0 +1,252 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Profile|Win32">
+ <Configuration>Profile</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Profile|x64">
+ <Configuration>Profile</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{28FD076D-10B5-4BD8-A4CF-F44C7002A803}</ProjectGuid>
+ <RootNamespace>Reactor</RootNamespace>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(Platform)\$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(Platform)\$(Configuration)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">$(Platform)\$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <AdditionalIncludeDirectories>..\;..\LLVM\include;..\LLVM\win32;..\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_LIB; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>true</MinimalRebuild>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <DisableSpecificWarnings>4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Midl>
+ <TargetEnvironment>X64</TargetEnvironment>
+ </Midl>
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <AdditionalIncludeDirectories>..\;..\LLVM\include;..\LLVM\win32;..\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_LIB; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>true</MinimalRebuild>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <DisableSpecificWarnings>4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>..\;..\LLVM\include;..\LLVM\win32;..\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_HAS_EXCEPTIONS=0; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>
+ </DebugInformationFormat>
+ <DisableSpecificWarnings>4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <StringPooling>true</StringPooling>
+ <FloatingPointExceptions>false</FloatingPointExceptions>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
+ <ClCompile>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>..\;..\LLVM\include;..\LLVM\win32;..\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_HAS_EXCEPTIONS=0; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <DisableSpecificWarnings>4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <StringPooling>true</StringPooling>
+ <FloatingPointExceptions>false</FloatingPointExceptions>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Midl>
+ <TargetEnvironment>X64</TargetEnvironment>
+ </Midl>
+ <ClCompile>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>..\;..\LLVM\include;..\LLVM\win32;..\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_HAS_EXCEPTIONS=0; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <DisableSpecificWarnings>4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <StringPooling>true</StringPooling>
+ <FloatingPointExceptions>false</FloatingPointExceptions>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">
+ <Midl>
+ <TargetEnvironment>X64</TargetEnvironment>
+ </Midl>
+ <ClCompile>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>..\;..\LLVM\include;..\LLVM\win32;..\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_HAS_EXCEPTIONS=0; _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Sync</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <DisableSpecificWarnings>4530;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <StringPooling>true</StringPooling>
+ <FloatingPointExceptions>false</FloatingPointExceptions>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="MemoryManager.cpp" />
+ <ClCompile Include="Nucleus.cpp" />
+ <ClCompile Include="Shell.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="MemoryManager.hpp" />
+ <ClInclude Include="Nucleus.hpp" />
+ <ClInclude Include="Reactor.hpp" />
+ <ClInclude Include="Shell.hpp" />
+ <ClInclude Include="x86.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/src/Reactor/Reactor.vcxproj.filters b/src/Reactor/Reactor.vcxproj.filters
new file mode 100644
index 0000000..772ce2d
--- /dev/null
+++ b/src/Reactor/Reactor.vcxproj.filters
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="MemoryManager.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Nucleus.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Shell.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="MemoryManager.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Nucleus.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Reactor.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Shell.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="x86.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/src/Reactor/Shell.cpp b/src/Reactor/Shell.cpp
new file mode 100644
index 0000000..a6f7829
--- /dev/null
+++ b/src/Reactor/Shell.cpp
@@ -0,0 +1,340 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#include "Shell.hpp"
+
+namespace sw
+{
+ TranscendentalPrecision logPrecision = ACCURATE;
+ TranscendentalPrecision expPrecision = ACCURATE;
+ TranscendentalPrecision rcpPrecision = ACCURATE;
+ TranscendentalPrecision rsqPrecision = ACCURATE;
+ bool perspectiveCorrection = true;
+
+ Color4i::Color4i() : x(r), y(g), z(b), w(a)
+ {
+ }
+
+ Color4i::Color4i(unsigned short red, unsigned short green, unsigned short blue, unsigned short alpha) : x(r), y(g), z(b), w(a)
+ {
+ r = Short4(red);
+ g = Short4(green);
+ b = Short4(blue);
+ a = Short4(alpha);
+ }
+
+ Color4i::Color4i(const Color4i &rhs) : x(r), y(g), z(b), w(a)
+ {
+ r = rhs.r;
+ g = rhs.g;
+ b = rhs.b;
+ a = rhs.a;
+ }
+
+ Color4i &Color4i::operator=(const Color4i &rhs)
+ {
+ r = rhs.r;
+ g = rhs.g;
+ b = rhs.b;
+ a = rhs.a;
+
+ return *this;
+ }
+
+ Short4 &Color4i::operator[](int i)
+ {
+ switch(i)
+ {
+ case 0: return x;
+ case 1: return y;
+ case 2: return z;
+ case 3: return w;
+ }
+
+ return x;
+ }
+
+ Color4f::Color4f() : x(r), y(g), z(b), w(a), u(r), v(g), s(b), t(a)
+ {
+ }
+
+ Color4f::Color4f(float red, float green, float blue, float alpha) : x(r), y(g), z(b), w(a), u(r), v(g), s(b), t(a)
+ {
+ r = Float4(red);
+ g = Float4(green);
+ b = Float4(blue);
+ a = Float4(alpha);
+ }
+
+ Color4f::Color4f(const Color4f &rhs) : x(r), y(g), z(b), w(a), u(r), v(g), s(b), t(a)
+ {
+ r = rhs.r;
+ g = rhs.g;
+ b = rhs.b;
+ a = rhs.a;
+ }
+
+ Color4f &Color4f::operator=(const Color4f &rhs)
+ {
+ r = rhs.r;
+ g = rhs.g;
+ b = rhs.b;
+ a = rhs.a;
+
+ return *this;
+ }
+
+ Float4 &Color4f::operator[](int i)
+ {
+ switch(i)
+ {
+ case 0: return x;
+ case 1: return y;
+ case 2: return z;
+ case 3: return w;
+ }
+
+ return x;
+ }
+
+ Float4 exponential(Float4 &src, bool pp)
+ {
+ Float4 x0;
+ Float4 x1;
+ Int4 x2;
+
+ x0 = src;
+
+ x0 = Min(x0, As<Float4>(Int4(0x43010000, 0x43010000, 0x43010000, 0x43010000))); // 129.00000e+0f
+ x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF, 0xC2FDFFFF, 0xC2FDFFFF, 0xC2FDFFFF))); // -126.99999e+0f
+ x1 = x0;
+ x1 -= Float4(0.5f, 0.5f, 0.5f, 0.5f);
+ x2 = RoundInt(x1);
+ x1 = Float4(x2);
+ x2 += Int4(0x0000007F, 0x0000007F, 0x0000007F, 0x0000007F); // 127
+ x2 = x2 << 23;
+ x0 -= x1;
+ x1 = As<Float4>(Int4(0x3AF61905, 0x3AF61905, 0x3AF61905, 0x3AF61905)); // 1.8775767e-3f
+ x1 *= x0;
+ x1 += As<Float4>(Int4(0x3C134806, 0x3C134806, 0x3C134806, 0x3C134806)); // 8.9893397e-3f
+ x1 *= x0;
+ x1 += As<Float4>(Int4(0x3D64AA23, 0x3D64AA23, 0x3D64AA23, 0x3D64AA23)); // 5.5826318e-2f
+ x1 *= x0;
+ x1 += As<Float4>(Int4(0x3E75EAD4, 0x3E75EAD4, 0x3E75EAD4, 0x3E75EAD4)); // 2.4015361e-1f
+ x1 *= x0;
+ x1 += As<Float4>(Int4(0x3F31727B, 0x3F31727B, 0x3F31727B, 0x3F31727B)); // 6.9315308e-1f
+ x1 *= x0;
+ x1 += As<Float4>(Int4(0x3F7FFFFF, 0x3F7FFFFF, 0x3F7FFFFF, 0x3F7FFFFF)); // 9.9999994e-1f
+ x1 *= As<Float4>(x2);
+
+ return x1;
+ }
+
+ Float4 logarithm(Float4 &src, bool absolute, bool pp)
+ {
+ Float4 x0;
+ Float4 x1;
+ Float4 x2;
+ Float4 x3;
+
+ x0 = src;
+
+ x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000));
+ x1 = As<Float4>(As<UInt4>(x1) >> 8);
+ x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f)));
+ x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f;
+ x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f)));
+
+ x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f);
+ x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f);
+ x2 /= x3;
+
+ x1 += (x0 - Float4(1.0f)) * x2;
+
+ return x1;
+ }
+
+ Float4 power(Float4 &src0, Float4 &src1, bool pp)
+ {
+ Float4 log = logarithm(src0, true, pp);
+ log *= src1;
+ return exponential(log, pp);
+ }
+
+ Float4 reciprocal(Float4 &src, bool pp, bool finite)
+ {
+ Float4 dst;
+
+ if(!pp && rcpPrecision >= WHQL)
+ {
+ dst = Float4(1, 1, 1, 1) / src;
+ }
+ else
+ {
+ dst = Rcp_pp(src);
+
+ if(!pp)
+ {
+ dst = (dst + dst) - (src * dst * dst);
+ }
+ }
+
+ if(finite)
+ {
+ int x = 0x7F7FFFFF;
+ dst = Min(dst, Float4((float&)x, (float&)x, (float&)x, (float&)x));
+ }
+
+ return dst;
+ }
+
+ Float4 reciprocalSquareRoot(Float4 &src, bool absolute, bool pp)
+ {
+ Float4 abs = src;
+
+ if(absolute)
+ {
+ abs = Abs(abs);
+ }
+
+ Float4 rsq;
+
+ if(!pp && rsqPrecision >= IEEE)
+ {
+ rsq = Float4(1.0f, 1.0f, 1.0f, 1.0f) / Sqrt(abs);
+ }
+ else
+ {
+ rsq = RcpSqrt_pp(abs);
+
+ if(!pp)
+ {
+ rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f);
+ }
+ }
+
+ int x = 0x7F7FFFFF;
+ rsq = Min(rsq, Float4((float&)x, (float&)x, (float&)x, (float&)x));
+
+ return rsq;
+ }
+
+ Float4 sine(Float4 &src, bool pp)
+ {
+ const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2
+ const Float4 B = Float4(1.27323954e+0f); // 4/pi
+ const Float4 C = Float4(7.75160950e-1f);
+ const Float4 D = Float4(2.24839049e-1f);
+
+ // Parabola approximating sine
+ Float4 sin = src * (Abs(src) * A + B);
+
+ // Improve precision from 0.06 to 0.001
+ if(true)
+ {
+ sin = sin * (Abs(sin) * D + C);
+ }
+
+ return sin;
+ }
+
+ Float4 dot3(Color4f &src0, Color4f &src1)
+ {
+ return src0.x * src1.x + src0.y * src1.y + src0.z * src1.z;
+ }
+
+ Float4 dot4(Color4f &src0, Color4f &src1)
+ {
+ return src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src0.w * src1.w;
+ }
+
+ void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3)
+ {
+ Int2 tmp0 = UnpackHigh(row0, row1);
+ Int2 tmp1 = UnpackHigh(row2, row3);
+ Int2 tmp2 = UnpackLow(row0, row1);
+ Int2 tmp3 = UnpackLow(row2, row3);
+
+ row0 = As<Short4>(UnpackLow(tmp2, tmp3));
+ row1 = As<Short4>(UnpackHigh(tmp2, tmp3));
+ row2 = As<Short4>(UnpackLow(tmp0, tmp1));
+ row3 = As<Short4>(UnpackHigh(tmp0, tmp1));
+ }
+
+ void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
+ {
+ Float4 tmp0 = UnpackLow(row0, row1);
+ Float4 tmp1 = UnpackLow(row2, row3);
+ Float4 tmp2 = UnpackHigh(row0, row1);
+ Float4 tmp3 = UnpackHigh(row2, row3);
+
+ row0 = Float4(tmp0.xy, tmp1.xy);
+ row1 = Float4(tmp0.zw, tmp1.zw);
+ row2 = Float4(tmp2.xy, tmp3.xy);
+ row3 = Float4(tmp2.zw, tmp3.zw);
+ }
+
+ void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
+ {
+ Float4 tmp0 = UnpackLow(row0, row1);
+ Float4 tmp1 = UnpackLow(row2, row3);
+ Float4 tmp2 = UnpackHigh(row0, row1);
+ Float4 tmp3 = UnpackHigh(row2, row3);
+
+ row0 = Float4(tmp0.xy, tmp1.xy);
+ row1 = Float4(tmp0.zw, tmp1.zw);
+ row2 = Float4(tmp2.xy, tmp3.xy);
+ }
+
+ void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
+ {
+ Float4 tmp0 = UnpackLow(row0, row1);
+ Float4 tmp1 = UnpackLow(row2, row3);
+
+ row0 = Float4(tmp0.xy, tmp1.xy);
+ row1 = Float4(tmp0.zw, tmp1.zw);
+ }
+
+ void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
+ {
+ Float4 tmp0 = UnpackLow(row0, row1);
+ Float4 tmp1 = UnpackLow(row2, row3);
+
+ row0 = Float4(tmp0.xy, tmp1.xy);
+ }
+
+ void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
+ {
+ row0 = UnpackLow(row0, row1);
+ row1 = Float4(row0.zw, row1.zw);
+ row2 = UnpackHigh(row0, row1);
+ row3 = Float4(row2.zw, row3.zw);
+ }
+
+ void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3)
+ {
+ row0 = UnpackLow(row2, row3);
+ row1 = Float4(row0.zw, row1.zw);
+ row2 = UnpackHigh(row2, row3);
+ row3 = Float4(row2.zw, row3.zw);
+ }
+
+ void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N)
+ {
+ switch(N)
+ {
+ case 1: transpose4x1(row0, row1, row2, row3); break;
+ case 2: transpose4x2(row0, row1, row2, row3); break;
+ case 3: transpose4x3(row0, row1, row2, row3); break;
+ case 4: transpose4x4(row0, row1, row2, row3); break;
+ }
+ }
+}
diff --git a/src/Reactor/Shell.hpp b/src/Reactor/Shell.hpp
new file mode 100644
index 0000000..f2d2b1b
--- /dev/null
+++ b/src/Reactor/Shell.hpp
@@ -0,0 +1,133 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#ifndef sw_Shell_hpp
+#define sw_Shell_hpp
+
+#include "Nucleus.hpp"
+
+namespace sw
+{
+ enum TranscendentalPrecision
+ {
+ APPROXIMATE,
+ PARTIAL, // 2^-10
+ ACCURATE,
+ WHQL, // 2^-21
+ IEEE // 2^-23
+ };
+
+ class Color4i
+ {
+ public:
+ Color4i();
+ Color4i(unsigned short red, unsigned short green, unsigned short blue, unsigned short alpha);
+ Color4i(const Color4i &rhs);
+
+ Short4 &operator[](int i);
+ Color4i &operator=(const Color4i &rhs);
+
+ Short4 r;
+ Short4 g;
+ Short4 b;
+ Short4 a;
+
+ Short4 &x;
+ Short4 &y;
+ Short4 &z;
+ Short4 &w;
+ };
+
+ class Color4f
+ {
+ public:
+ Color4f();
+ Color4f(float red, float green, float blue, float alpha);
+ Color4f(const Color4f &rhs);
+
+ Float4 &operator[](int i);
+ Color4f &operator=(const Color4f &rhs);
+
+ Float4 r;
+ Float4 g;
+ Float4 b;
+ Float4 a;
+
+ Float4 &x;
+ Float4 &y;
+ Float4 &z;
+ Float4 &w;
+
+ Float4 &u;
+ Float4 &v;
+ Float4 &s;
+ Float4 &t;
+ };
+
+ Float4 exponential(Float4 &src, bool pp = false);
+ Float4 logarithm(Float4 &src, bool abs, bool pp = false);
+ Float4 power(Float4 &src0, Float4 &src1, bool pp = false);
+ Float4 reciprocal(Float4 &src, bool pp = false, bool finite = false);
+ Float4 reciprocalSquareRoot(Float4 &src, bool abs, bool pp = false);
+ Float4 sine(Float4 &src, bool pp = false);
+
+ Float4 dot3(Color4f &src0, Color4f &src1);
+ Float4 dot4(Color4f &src0, Color4f &src1);
+
+ void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3);
+ void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N);
+
+ #define For(init, cond, inc) \
+ init; \
+ for(llvm::BasicBlock *loopBB__ = beginLoop(), \
+ *bodyBB__ = Nucleus::createBasicBlock(), \
+ *endBB__ = Nucleus::createBasicBlock(), \
+ *onceBB__ = endBB__; \
+ onceBB__ && branch(cond, bodyBB__, endBB__); \
+ inc, onceBB__ = 0, Nucleus::createBr(loopBB__), Nucleus::setInsertBlock(endBB__))
+
+ #define While(cond) For(((void*)0), cond, ((void*)0))
+
+ #define Do \
+ { \
+ llvm::BasicBlock *body = Nucleus::createBasicBlock(); \
+ Nucleus::createBr(body); \
+ Nucleus::setInsertBlock(body);
+
+ #define Until(cond) \
+ llvm::BasicBlock *end = Nucleus::createBasicBlock(); \
+ Nucleus::createCondBr((cond).value, end, body); \
+ Nucleus::setInsertBlock(end); \
+ }
+
+ #define If(cond) \
+ for(llvm::BasicBlock *trueBB__ = Nucleus::createBasicBlock(), \
+ *falseBB__ = Nucleus::createBasicBlock(), \
+ *endBB__ = Nucleus::createBasicBlock(), \
+ *onceBB__ = endBB__; \
+ onceBB__ && branch(cond, trueBB__, falseBB__); \
+ onceBB__ = 0, Nucleus::createBr(endBB__), Nucleus::setInsertBlock(falseBB__), Nucleus::createBr(endBB__), Nucleus::setInsertBlock(endBB__))
+
+ #define Else \
+ for(llvm::BasicBlock *endBB__ = Nucleus::getInsertBlock(), \
+ *falseBB__ = Nucleus::getPredecessor(endBB__), \
+ *onceBB__ = endBB__; \
+ onceBB__ && elseBlock(falseBB__); \
+ onceBB__ = 0, Nucleus::createBr(endBB__), Nucleus::setInsertBlock(endBB__))
+}
+
+#endif // sw_Shell_hpp
diff --git a/src/Reactor/x86.hpp b/src/Reactor/x86.hpp
new file mode 100644
index 0000000..290d5cb
--- /dev/null
+++ b/src/Reactor/x86.hpp
@@ -0,0 +1,131 @@
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2005-2011 TransGaming Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#include "Nucleus.hpp"
+
+namespace sw
+{
+ namespace x86
+ {
+ RValue<Int> cvtss2si(const RValue<Float> &val);
+ RValue<Int2> cvtps2pi(const RValue<Float4> &val);
+ RValue<Int2> cvttps2pi(const RValue<Float4> &val);
+ RValue<Int4> cvtps2dq(const RValue<Float4> &val);
+ RValue<Int4> cvttps2dq(const RValue<Float4> &val);
+
+ RValue<Float4> cvtpi2ps(const RValue<Float4> &x, const RValue<Int2> &y);
+ RValue<Float4> cvtdq2ps(const RValue<Int4> &val);
+
+ RValue<Float> rcpss(const RValue<Float> &val);
+ RValue<Float> sqrtss(const RValue<Float> &val);
+ RValue<Float> rsqrtss(const RValue<Float> &val);
+
+ RValue<Float4> rcpps(const RValue<Float4> &val);
+ RValue<Float4> sqrtps(const RValue<Float4> &val);
+ RValue<Float4> rsqrtps(const RValue<Float4> &val);
+ RValue<Float4> maxps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> minps(const RValue<Float4> &x, const RValue<Float4> &y);
+
+ RValue<Float> roundss(const RValue<Float> &val, unsigned char imm);
+ RValue<Float> floorss(const RValue<Float> &val);
+ RValue<Float> ceilss(const RValue<Float> &val);
+
+ RValue<Float4> roundps(const RValue<Float4> &val, unsigned char imm);
+ RValue<Float4> floorps(const RValue<Float4> &val);
+ RValue<Float4> ceilps(const RValue<Float4> &val);
+
+ RValue<Float4> cmpps(const RValue<Float4> &x, const RValue<Float4> &y, unsigned char imm);
+ RValue<Float4> cmpeqps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpltps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpleps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpunordps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpneqps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpnltps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpnleps(const RValue<Float4> &x, const RValue<Float4> &y);
+ RValue<Float4> cmpordps(const RValue<Float4> &x, const RValue<Float4> &y);
+
+ RValue<Float> cmpss(const RValue<Float> &x, const RValue<Float> &y, unsigned char imm);
+ RValue<Float> cmpeqss(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpltss(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpless(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpunordss(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpneqss(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpnltss(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpnless(const RValue<Float> &x, const RValue<Float> &y);
+ RValue<Float> cmpordss(const RValue<Float> &x, const RValue<Float> &y);
+
+ RValue<Int4> pabsd(const RValue<Int4> &x, const RValue<Int4> &y);
+
+ RValue<Short4> paddsw(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<Short4> psubsw(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<UShort4> paddusw(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ RValue<UShort4> psubusw(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ RValue<SByte8> paddsb(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ RValue<SByte8> psubsb(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ RValue<Byte8> paddusb(const RValue<Byte8> &x, const RValue<Byte8> &y);
+ RValue<Byte8> psubusb(const RValue<Byte8> &x, const RValue<Byte8> &y);
+
+ RValue<UShort4> pavgw(const RValue<UShort4> &x, const RValue<UShort4> &y);
+
+ RValue<Short4> pmaxsw(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<Short4> pminsw(const RValue<Short4> &x, const RValue<Short4> &y);
+
+ RValue<Short4> pcmpgtw(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<Short4> pcmpeqw(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<Byte8> pcmpgtb(const RValue<SByte8> &x, const RValue<SByte8> &y);
+ RValue<Byte8> pcmpeqb(const RValue<Byte8> &x, const RValue<Byte8> &y);
+
+ RValue<Short4> packssdw(const RValue<Int2> &x, const RValue<Int2> &y);
+ RValue<Short8> packssdw(const RValue<Int4> &x, const RValue<Int4> &y);
+ RValue<SByte8> packsswb(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<Byte8> packuswb(const RValue<UShort4> &x, const RValue<UShort4> &y);
+
+ RValue<UShort8> packusdw(const RValue<UInt4> &x, const RValue<UInt4> &y);
+
+ RValue<UShort4> psrlw(const RValue<UShort4> &x, unsigned char y);
+ RValue<UShort8> psrlw(const RValue<UShort8> &x, unsigned char y);
+ RValue<Short4> psraw(const RValue<Short4> &x, unsigned char y);
+ RValue<Short8> psraw(const RValue<Short8> &x, unsigned char y);
+ RValue<Short4> psllw(const RValue<Short4> &x, unsigned char y);
+ RValue<Short8> psllw(const RValue<Short8> &x, unsigned char y);
+ RValue<Int2> pslld(const RValue<Int2> &x, unsigned char y);
+ RValue<Int4> pslld(const RValue<Int4> &x, unsigned char y);
+ RValue<Int2> psrad(const RValue<Int2> &x, unsigned char y);
+ RValue<Int4> psrad(const RValue<Int4> &x, unsigned char y);
+ RValue<UInt2> psrld(const RValue<UInt2> &x, unsigned char y);
+ RValue<UInt4> psrld(const RValue<UInt4> &x, unsigned char y);
+
+ RValue<UShort4> psrlw(const RValue<UShort4> &x, const RValue<Long1> &y);
+ RValue<Short4> psraw(const RValue<Short4> &x, const RValue<Long1> &y);
+ RValue<Short4> psllw(const RValue<Short4> &x, const RValue<Long1> &y);
+ RValue<Int2> pslld(const RValue<Int2> &x, const RValue<Long1> &y);
+ RValue<UInt2> psrld(const RValue<UInt2> &x, const RValue<Long1> &y);
+ RValue<Int2> psrad(const RValue<Int2> &x, const RValue<Long1> &y);
+
+ RValue<Short4> pmulhw(const RValue<Short4> &x, const RValue<Short4> &y);
+ RValue<UShort4> pmulhuw(const RValue<UShort4> &x, const RValue<UShort4> &y);
+ RValue<Int2> pmaddwd(const RValue<Short4> &x, const RValue<Short4> &y);
+
+ RValue<Short8> pmulhw(const RValue<Short8> &x, const RValue<Short8> &y);
+ RValue<UShort8> pmulhuw(const RValue<UShort8> &x, const RValue<UShort8> &y);
+ RValue<Int4> pmaddwd(const RValue<Short8> &x, const RValue<Short8> &y);
+
+ RValue<Int> movmskps(const RValue<Float4> &x);
+ RValue<Int> pmovmskb(const RValue<Byte8> &x);
+
+ RValue<Int4> pmovzxbd(const RValue<Int4> &x);
+ RValue<Int4> pmovsxbd(const RValue<Int4> &x);
+ RValue<Int4> pmovzxwd(const RValue<Int4> &x);
+ RValue<Int4> pmovsxwd(const RValue<Int4> &x);
+
+ void emms();
+ }
+}