blob: 4db16e0f3562cede7bca5e2098abf163073890b0 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman89401822014-05-06 15:04:28 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman89401822014-05-06 15:04:28 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman89401822014-05-06 15:04:28 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman89401822014-05-06 15:04:28 -040014
Nicolas Capenscb986762017-01-20 11:34:37 -050015#include "Reactor.hpp"
John Bauman89401822014-05-06 15:04:28 -040016
17#include "llvm/Support/IRBuilder.h"
18#include "llvm/Function.h"
19#include "llvm/GlobalVariable.h"
20#include "llvm/Module.h"
21#include "llvm/LLVMContext.h"
22#include "llvm/Constants.h"
23#include "llvm/Intrinsics.h"
John Bauman66b8ab22014-05-06 15:57:45 -040024#include "llvm/PassManager.h"
John Bauman89401822014-05-06 15:04:28 -040025#include "llvm/Analysis/LoopPass.h"
26#include "llvm/Transforms/Scalar.h"
27#include "llvm/Target/TargetData.h"
John Bauman89401822014-05-06 15:04:28 -040028#include "llvm/Target/TargetOptions.h"
John Bauman19bac1e2014-05-06 15:23:49 -040029#include "llvm/Support/TargetSelect.h"
John Bauman89401822014-05-06 15:04:28 -040030#include "../lib/ExecutionEngine/JIT/JIT.h"
John Bauman89401822014-05-06 15:04:28 -040031
Nicolas Capensdaa5d912016-09-28 16:56:36 -040032#include "LLVMRoutine.hpp"
33#include "LLVMRoutineManager.hpp"
John Bauman89401822014-05-06 15:04:28 -040034#include "x86.hpp"
Nicolas Capens708c24b2017-10-26 13:07:10 -040035#include "Common/CPUID.hpp"
36#include "Common/Thread.hpp"
37#include "Common/Memory.hpp"
38#include "Common/MutexLock.hpp"
John Bauman89401822014-05-06 15:04:28 -040039
40#include <fstream>
41
Nicolas Capens47dc8672017-04-25 12:54:39 -040042#if defined(__i386__) || defined(__x86_64__)
43#include <xmmintrin.h>
44#endif
45
Nicolas Capenscb122582014-05-06 23:34:44 -040046#if defined(__x86_64__) && defined(_WIN32)
John Bauman66b8ab22014-05-06 15:57:45 -040047extern "C" void X86CompilationCallback()
48{
49 assert(false); // UNIMPLEMENTED
50}
51#endif
52
John Bauman89401822014-05-06 15:04:28 -040053extern "C"
54{
55 bool (*CodeAnalystInitialize)() = 0;
56 void (*CodeAnalystCompleteJITLog)() = 0;
57 bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0;
58}
59
60namespace llvm
61{
62 extern bool JITEmitDebugInfo;
63}
64
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -040065namespace
66{
Nicolas Capensdaa5d912016-09-28 16:56:36 -040067 sw::LLVMRoutineManager *routineManager = nullptr;
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -040068 llvm::ExecutionEngine *executionEngine = nullptr;
69 llvm::IRBuilder<> *builder = nullptr;
70 llvm::LLVMContext *context = nullptr;
71 llvm::Module *module = nullptr;
72 llvm::Function *function = nullptr;
Nicolas Capens3bbc5e12016-09-27 10:49:52 -040073
Jorge E. Moreiraf8faed62016-12-02 17:03:54 -080074 sw::MutexLock codegenMutex;
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -040075}
76
John Bauman89401822014-05-06 15:04:28 -040077namespace sw
78{
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -040079 Optimization optimization[10] = {InstructionCombining, Disabled};
John Bauman89401822014-05-06 15:04:28 -040080
Nicolas Capensfbf2bc52017-07-26 17:26:17 -040081 enum EmulatedType
82 {
83 Type_v2i32,
84 Type_v4i16,
85 Type_v2i16,
86 Type_v8i8,
87 Type_v4i8,
88 Type_v2f32,
89 EmulatedTypeCount
90 };
91
Nicolas Capens19336542016-09-26 10:32:29 -040092 class Value : public llvm::Value {};
Nicolas Capensb98fe5c2016-11-09 12:24:06 -050093 class SwitchCases : public llvm::SwitchInst {};
Nicolas Capensc8b67a42016-09-25 15:02:52 -040094 class BasicBlock : public llvm::BasicBlock {};
Nicolas Capensac230122016-09-20 14:30:06 -040095
Nicolas Capensfbf2bc52017-07-26 17:26:17 -040096 llvm::Type *T(Type *t)
97 {
Nicolas Capens01a97962017-07-28 17:30:51 -040098 uintptr_t type = reinterpret_cast<uintptr_t>(t);
Nicolas Capensfbf2bc52017-07-26 17:26:17 -040099 if(type < EmulatedTypeCount)
100 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400101 // Use 128-bit vectors to implement logically shorter ones.
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400102 switch(type)
103 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400104 case Type_v2i32: return T(Int4::getType());
105 case Type_v4i16: return T(Short8::getType());
106 case Type_v2i16: return T(Short8::getType());
107 case Type_v8i8: return T(Byte16::getType());
108 case Type_v4i8: return T(Byte16::getType());
109 case Type_v2f32: return T(Float4::getType());
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400110 default: assert(false);
111 }
112 }
113
114 return reinterpret_cast<llvm::Type*>(t);
115 }
116
Nicolas Capensac230122016-09-20 14:30:06 -0400117 inline Type *T(llvm::Type *t)
118 {
119 return reinterpret_cast<Type*>(t);
120 }
121
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400122 Type *T(EmulatedType t)
123 {
124 return reinterpret_cast<Type*>(t);
125 }
126
Nicolas Capens19336542016-09-26 10:32:29 -0400127 inline Value *V(llvm::Value *t)
128 {
129 return reinterpret_cast<Value*>(t);
130 }
131
Nicolas Capensac230122016-09-20 14:30:06 -0400132 inline std::vector<llvm::Type*> &T(std::vector<Type*> &t)
133 {
134 return reinterpret_cast<std::vector<llvm::Type*>&>(t);
135 }
136
Nicolas Capensc8b67a42016-09-25 15:02:52 -0400137 inline BasicBlock *B(llvm::BasicBlock *t)
138 {
139 return reinterpret_cast<BasicBlock*>(t);
140 }
141
Nicolas Capens01a97962017-07-28 17:30:51 -0400142 static size_t typeSize(Type *type)
143 {
144 uintptr_t t = reinterpret_cast<uintptr_t>(type);
145 if(t < EmulatedTypeCount)
146 {
147 switch(t)
148 {
149 case Type_v2i32: return 8;
150 case Type_v4i16: return 8;
151 case Type_v2i16: return 4;
152 case Type_v8i8: return 8;
153 case Type_v4i8: return 4;
154 case Type_v2f32: return 8;
155 default: assert(false);
156 }
157 }
158
159 return T(type)->getPrimitiveSizeInBits() / 8;
160 }
161
Nicolas Capens69674fb2017-09-01 11:08:44 -0400162 static unsigned int elementCount(Type *type)
163 {
164 uintptr_t t = reinterpret_cast<uintptr_t>(type);
165 if(t < EmulatedTypeCount)
166 {
167 switch(t)
168 {
169 case Type_v2i32: return 2;
170 case Type_v4i16: return 4;
171 case Type_v2i16: return 2;
172 case Type_v8i8: return 8;
173 case Type_v4i8: return 4;
174 case Type_v2f32: return 2;
175 default: assert(false);
176 }
177 }
178
179 return llvm::cast<llvm::VectorType>(T(type))->getNumElements();
180 }
181
John Bauman89401822014-05-06 15:04:28 -0400182 Nucleus::Nucleus()
183 {
Nicolas Capens3bbc5e12016-09-27 10:49:52 -0400184 ::codegenMutex.lock(); // Reactor and LLVM are currently not thread safe
Nicolas Capensb7ea9842015-04-01 10:54:59 -0400185
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400186 llvm::InitializeNativeTarget();
187 llvm::JITEmitDebugInfo = false;
John Bauman89401822014-05-06 15:04:28 -0400188
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400189 if(!::context)
John Bauman89401822014-05-06 15:04:28 -0400190 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400191 ::context = new llvm::LLVMContext();
John Bauman89401822014-05-06 15:04:28 -0400192 }
193
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400194 ::module = new llvm::Module("", *::context);
Nicolas Capensdaa5d912016-09-28 16:56:36 -0400195 ::routineManager = new LLVMRoutineManager();
John Bauman66b8ab22014-05-06 15:57:45 -0400196
John Bauman89401822014-05-06 15:04:28 -0400197 #if defined(__x86_64__)
198 const char *architecture = "x86-64";
199 #else
200 const char *architecture = "x86";
201 #endif
202
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400203 llvm::SmallVector<std::string, 1> MAttrs;
John Bauman89401822014-05-06 15:04:28 -0400204 MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx");
205 MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov");
206 MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse");
207 MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2");
208 MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3");
209 MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3");
210 MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41");
211
John Bauman19bac1e2014-05-06 15:23:49 -0400212 std::string error;
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400213 llvm::TargetMachine *targetMachine = llvm::EngineBuilder::selectTarget(::module, architecture, "", MAttrs, llvm::Reloc::Default, llvm::CodeModel::JITDefault, &error);
214 ::executionEngine = llvm::JIT::createJIT(::module, 0, ::routineManager, llvm::CodeGenOpt::Aggressive, true, targetMachine);
John Bauman89401822014-05-06 15:04:28 -0400215
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400216 if(!::builder)
John Bauman89401822014-05-06 15:04:28 -0400217 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400218 ::builder = new llvm::IRBuilder<>(*::context);
John Bauman89401822014-05-06 15:04:28 -0400219
John Bauman66b8ab22014-05-06 15:57:45 -0400220 #if defined(_WIN32)
221 HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll");
222 if(CodeAnalyst)
223 {
224 CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize");
225 CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog");
226 CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode");
227
228 CodeAnalystInitialize();
229 }
230 #endif
John Bauman89401822014-05-06 15:04:28 -0400231 }
232 }
233
234 Nucleus::~Nucleus()
235 {
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400236 delete ::executionEngine;
237 ::executionEngine = nullptr;
John Bauman89401822014-05-06 15:04:28 -0400238
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400239 ::routineManager = nullptr;
240 ::function = nullptr;
241 ::module = nullptr;
Nicolas Capensb7ea9842015-04-01 10:54:59 -0400242
Nicolas Capens3bbc5e12016-09-27 10:49:52 -0400243 ::codegenMutex.unlock();
John Bauman89401822014-05-06 15:04:28 -0400244 }
245
246 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
247 {
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400248 if(::builder->GetInsertBlock()->empty() || !::builder->GetInsertBlock()->back().isTerminator())
John Bauman19bac1e2014-05-06 15:23:49 -0400249 {
Nicolas Capensac230122016-09-20 14:30:06 -0400250 llvm::Type *type = ::function->getReturnType();
John Bauman19bac1e2014-05-06 15:23:49 -0400251
252 if(type->isVoidTy())
253 {
254 createRetVoid();
255 }
256 else
257 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400258 createRet(V(llvm::UndefValue::get(type)));
John Bauman19bac1e2014-05-06 15:23:49 -0400259 }
260 }
John Bauman89401822014-05-06 15:04:28 -0400261
262 if(false)
263 {
John Bauman66b8ab22014-05-06 15:57:45 -0400264 std::string error;
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400265 llvm::raw_fd_ostream file("llvm-dump-unopt.txt", error);
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400266 ::module->print(file, 0);
John Bauman89401822014-05-06 15:04:28 -0400267 }
268
269 if(runOptimizations)
270 {
271 optimize();
272 }
273
274 if(false)
275 {
John Bauman66b8ab22014-05-06 15:57:45 -0400276 std::string error;
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400277 llvm::raw_fd_ostream file("llvm-dump-opt.txt", error);
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400278 ::module->print(file, 0);
John Bauman89401822014-05-06 15:04:28 -0400279 }
280
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400281 void *entry = ::executionEngine->getPointerToFunction(::function);
Nicolas Capensdaa5d912016-09-28 16:56:36 -0400282 LLVMRoutine *routine = ::routineManager->acquireRoutine(entry);
John Bauman89401822014-05-06 15:04:28 -0400283
284 if(CodeAnalystLogJITCode)
285 {
Nicolas Capensd946e0a2014-06-26 11:31:08 -0400286 CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name);
John Bauman89401822014-05-06 15:04:28 -0400287 }
288
289 return routine;
290 }
291
292 void Nucleus::optimize()
293 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400294 static llvm::PassManager *passManager = nullptr;
John Bauman66b8ab22014-05-06 15:57:45 -0400295
John Bauman89401822014-05-06 15:04:28 -0400296 if(!passManager)
297 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400298 passManager = new llvm::PassManager();
John Bauman89401822014-05-06 15:04:28 -0400299
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400300 llvm::UnsafeFPMath = true;
301 // llvm::NoInfsFPMath = true;
302 // llvm::NoNaNsFPMath = true;
John Bauman89401822014-05-06 15:04:28 -0400303
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400304 passManager->add(new llvm::TargetData(*::executionEngine->getTargetData()));
305 passManager->add(llvm::createScalarReplAggregatesPass());
John Bauman89401822014-05-06 15:04:28 -0400306
307 for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++)
308 {
309 switch(optimization[pass])
310 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400311 case Disabled: break;
312 case CFGSimplification: passManager->add(llvm::createCFGSimplificationPass()); break;
313 case LICM: passManager->add(llvm::createLICMPass()); break;
314 case AggressiveDCE: passManager->add(llvm::createAggressiveDCEPass()); break;
315 case GVN: passManager->add(llvm::createGVNPass()); break;
316 case InstructionCombining: passManager->add(llvm::createInstructionCombiningPass()); break;
317 case Reassociate: passManager->add(llvm::createReassociatePass()); break;
318 case DeadStoreElimination: passManager->add(llvm::createDeadStoreEliminationPass()); break;
319 case SCCP: passManager->add(llvm::createSCCPPass()); break;
320 case ScalarReplAggregates: passManager->add(llvm::createScalarReplAggregatesPass()); break;
John Bauman89401822014-05-06 15:04:28 -0400321 default:
322 assert(false);
323 }
324 }
325 }
326
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400327 passManager->run(*::module);
John Bauman89401822014-05-06 15:04:28 -0400328 }
329
John Bauman19bac1e2014-05-06 15:23:49 -0400330 Value *Nucleus::allocateStackVariable(Type *type, int arraySize)
John Bauman89401822014-05-06 15:04:28 -0400331 {
332 // Need to allocate it in the entry block for mem2reg to work
Nicolas Capensc8b67a42016-09-25 15:02:52 -0400333 llvm::BasicBlock &entryBlock = ::function->getEntryBlock();
John Bauman89401822014-05-06 15:04:28 -0400334
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400335 llvm::Instruction *declaration;
John Bauman89401822014-05-06 15:04:28 -0400336
337 if(arraySize)
338 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400339 declaration = new llvm::AllocaInst(T(type), Nucleus::createConstantInt(arraySize));
John Bauman89401822014-05-06 15:04:28 -0400340 }
341 else
342 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400343 declaration = new llvm::AllocaInst(T(type), (Value*)nullptr);
John Bauman89401822014-05-06 15:04:28 -0400344 }
345
346 entryBlock.getInstList().push_front(declaration);
347
Nicolas Capens19336542016-09-26 10:32:29 -0400348 return V(declaration);
John Bauman89401822014-05-06 15:04:28 -0400349 }
350
351 BasicBlock *Nucleus::createBasicBlock()
352 {
Nicolas Capensc8b67a42016-09-25 15:02:52 -0400353 return B(BasicBlock::Create(*::context, "", ::function));
John Bauman89401822014-05-06 15:04:28 -0400354 }
355
356 BasicBlock *Nucleus::getInsertBlock()
357 {
Nicolas Capensc8b67a42016-09-25 15:02:52 -0400358 return B(::builder->GetInsertBlock());
John Bauman89401822014-05-06 15:04:28 -0400359 }
360
361 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
362 {
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400363 // assert(::builder->GetInsertBlock()->back().isTerminator());
364 return ::builder->SetInsertPoint(basicBlock);
John Bauman89401822014-05-06 15:04:28 -0400365 }
366
Nicolas Capensac230122016-09-20 14:30:06 -0400367 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
John Bauman89401822014-05-06 15:04:28 -0400368 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400369 llvm::FunctionType *functionType = llvm::FunctionType::get(T(ReturnType), T(Params), false);
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400370 ::function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", ::module);
371 ::function->setCallingConv(llvm::CallingConv::C);
John Bauman89401822014-05-06 15:04:28 -0400372
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400373 ::builder->SetInsertPoint(BasicBlock::Create(*::context, "", ::function));
John Bauman89401822014-05-06 15:04:28 -0400374 }
375
Nicolas Capens19336542016-09-26 10:32:29 -0400376 Value *Nucleus::getArgument(unsigned int index)
John Bauman89401822014-05-06 15:04:28 -0400377 {
Nicolas Capens5c1f5cc2016-09-23 16:45:13 -0400378 llvm::Function::arg_iterator args = ::function->arg_begin();
John Bauman89401822014-05-06 15:04:28 -0400379
380 while(index)
381 {
382 args++;
383 index--;
384 }
385
Nicolas Capens19336542016-09-26 10:32:29 -0400386 return V(&*args);
John Bauman89401822014-05-06 15:04:28 -0400387 }
388
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400389 void Nucleus::createRetVoid()
John Bauman89401822014-05-06 15:04:28 -0400390 {
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400391 ::builder->CreateRetVoid();
John Bauman89401822014-05-06 15:04:28 -0400392 }
393
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400394 void Nucleus::createRet(Value *v)
John Bauman89401822014-05-06 15:04:28 -0400395 {
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400396 ::builder->CreateRet(v);
John Bauman89401822014-05-06 15:04:28 -0400397 }
398
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400399 void Nucleus::createBr(BasicBlock *dest)
John Bauman89401822014-05-06 15:04:28 -0400400 {
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400401 ::builder->CreateBr(dest);
John Bauman89401822014-05-06 15:04:28 -0400402 }
403
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400404 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
John Bauman89401822014-05-06 15:04:28 -0400405 {
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400406 ::builder->CreateCondBr(cond, ifTrue, ifFalse);
John Bauman89401822014-05-06 15:04:28 -0400407 }
408
409 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
410 {
Nicolas Capens19336542016-09-26 10:32:29 -0400411 return V(::builder->CreateAdd(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400412 }
413
414 Value *Nucleus::createSub(Value *lhs, Value *rhs)
415 {
Nicolas Capens19336542016-09-26 10:32:29 -0400416 return V(::builder->CreateSub(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400417 }
418
419 Value *Nucleus::createMul(Value *lhs, Value *rhs)
420 {
Nicolas Capens19336542016-09-26 10:32:29 -0400421 return V(::builder->CreateMul(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400422 }
423
424 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
425 {
Nicolas Capens19336542016-09-26 10:32:29 -0400426 return V(::builder->CreateUDiv(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400427 }
428
429 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
430 {
Nicolas Capens19336542016-09-26 10:32:29 -0400431 return V(::builder->CreateSDiv(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400432 }
433
434 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
435 {
Nicolas Capens19336542016-09-26 10:32:29 -0400436 return V(::builder->CreateFAdd(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400437 }
438
439 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
440 {
Nicolas Capens19336542016-09-26 10:32:29 -0400441 return V(::builder->CreateFSub(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400442 }
443
444 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
445 {
Nicolas Capens19336542016-09-26 10:32:29 -0400446 return V(::builder->CreateFMul(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400447 }
448
449 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
450 {
Nicolas Capens19336542016-09-26 10:32:29 -0400451 return V(::builder->CreateFDiv(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400452 }
453
454 Value *Nucleus::createURem(Value *lhs, Value *rhs)
455 {
Nicolas Capens19336542016-09-26 10:32:29 -0400456 return V(::builder->CreateURem(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400457 }
458
459 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
460 {
Nicolas Capens19336542016-09-26 10:32:29 -0400461 return V(::builder->CreateSRem(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400462 }
463
464 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
465 {
Nicolas Capens19336542016-09-26 10:32:29 -0400466 return V(::builder->CreateFRem(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400467 }
468
469 Value *Nucleus::createShl(Value *lhs, Value *rhs)
470 {
Nicolas Capens19336542016-09-26 10:32:29 -0400471 return V(::builder->CreateShl(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400472 }
473
474 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
475 {
Nicolas Capens19336542016-09-26 10:32:29 -0400476 return V(::builder->CreateLShr(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400477 }
478
479 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
480 {
Nicolas Capens19336542016-09-26 10:32:29 -0400481 return V(::builder->CreateAShr(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400482 }
483
484 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
485 {
Nicolas Capens19336542016-09-26 10:32:29 -0400486 return V(::builder->CreateAnd(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400487 }
488
489 Value *Nucleus::createOr(Value *lhs, Value *rhs)
490 {
Nicolas Capens19336542016-09-26 10:32:29 -0400491 return V(::builder->CreateOr(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400492 }
493
494 Value *Nucleus::createXor(Value *lhs, Value *rhs)
495 {
Nicolas Capens19336542016-09-26 10:32:29 -0400496 return V(::builder->CreateXor(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400497 }
498
Nicolas Capens19336542016-09-26 10:32:29 -0400499 Value *Nucleus::createNeg(Value *v)
John Bauman89401822014-05-06 15:04:28 -0400500 {
Nicolas Capens19336542016-09-26 10:32:29 -0400501 return V(::builder->CreateNeg(v));
John Bauman89401822014-05-06 15:04:28 -0400502 }
503
Nicolas Capens19336542016-09-26 10:32:29 -0400504 Value *Nucleus::createFNeg(Value *v)
John Bauman89401822014-05-06 15:04:28 -0400505 {
Nicolas Capens19336542016-09-26 10:32:29 -0400506 return V(::builder->CreateFNeg(v));
John Bauman89401822014-05-06 15:04:28 -0400507 }
508
Nicolas Capens19336542016-09-26 10:32:29 -0400509 Value *Nucleus::createNot(Value *v)
John Bauman89401822014-05-06 15:04:28 -0400510 {
Nicolas Capens19336542016-09-26 10:32:29 -0400511 return V(::builder->CreateNot(v));
John Bauman89401822014-05-06 15:04:28 -0400512 }
513
Nicolas Capens01a97962017-07-28 17:30:51 -0400514 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int alignment)
John Bauman89401822014-05-06 15:04:28 -0400515 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400516 uintptr_t t = reinterpret_cast<uintptr_t>(type);
517 if(t < EmulatedTypeCount)
518 {
519 switch(t)
520 {
521 case Type_v2i32:
522 case Type_v4i16:
523 case Type_v8i8:
524 case Type_v2f32:
525 return createBitCast(createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))), createLoad(createBitCast(ptr, Pointer<Long>::getType()), Long::getType(), isVolatile, alignment), 0), T(T(type)));
526 case Type_v2i16:
527 case Type_v4i8:
528 if(alignment != 0) // Not a local variable (all vectors are 128-bit).
529 {
530 Value *u = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2)));
531 Value *i = V(createLoad(createBitCast(ptr, Pointer<Int>::getType()), Int::getType(), isVolatile, alignment));
532 i = createZExt(i, Long::getType());
533 Value *v = V(createInsertElement(u, i, 0));
534 return createBitCast(v, T(T(type)));
535 }
536 break;
537 default:
538 assert(false);
539 }
540 }
541
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400542 assert(ptr->getType()->getContainedType(0) == T(type));
Nicolas Capens01a97962017-07-28 17:30:51 -0400543 return V(::builder->Insert(new llvm::LoadInst(ptr, "", isVolatile, alignment)));
John Bauman89401822014-05-06 15:04:28 -0400544 }
545
Nicolas Capens01a97962017-07-28 17:30:51 -0400546 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int alignment)
John Bauman89401822014-05-06 15:04:28 -0400547 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400548 uintptr_t t = reinterpret_cast<uintptr_t>(type);
549 if(t < EmulatedTypeCount)
550 {
551 switch(t)
552 {
553 case Type_v2i32:
554 case Type_v4i16:
555 case Type_v8i8:
556 case Type_v2f32:
557 createStore(createExtractElement(createBitCast(value, T(llvm::VectorType::get(T(Long::getType()), 2))), Long::getType(), 0), createBitCast(ptr, Pointer<Long>::getType()), Long::getType(), isVolatile, alignment);
558 return value;
559 case Type_v2i16:
560 case Type_v4i8:
561 if(alignment != 0) // Not a local variable (all vectors are 128-bit).
562 {
563 createStore(createExtractElement(createBitCast(value, Int4::getType()), Int::getType(), 0), createBitCast(ptr, Pointer<Int>::getType()), Int::getType(), isVolatile, alignment);
564 return value;
565 }
566 break;
567 default:
568 assert(false);
569 }
570 }
571
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400572 assert(ptr->getType()->getContainedType(0) == T(type));
Nicolas Capens01a97962017-07-28 17:30:51 -0400573 ::builder->Insert(new llvm::StoreInst(value, ptr, isVolatile, alignment));
Nicolas Capensb955d5b2016-09-28 22:36:28 -0400574 return value;
John Bauman89401822014-05-06 15:04:28 -0400575 }
576
Nicolas Capensd294def2017-01-26 17:44:37 -0800577 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex)
John Bauman89401822014-05-06 15:04:28 -0400578 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400579 if(sizeof(void*) == 8)
Nicolas Capensd294def2017-01-26 17:44:37 -0800580 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400581 if(unsignedIndex)
582 {
583 index = createZExt(index, Long::getType());
584 }
585 else
586 {
587 index = createSExt(index, Long::getType());
588 }
589
590 index = createMul(index, createConstantLong((int64_t)typeSize(type)));
591 }
592 else
593 {
594 index = createMul(index, createConstantInt((int)typeSize(type)));
Nicolas Capensd294def2017-01-26 17:44:37 -0800595 }
596
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400597 assert(ptr->getType()->getContainedType(0) == T(type));
Nicolas Capens01a97962017-07-28 17:30:51 -0400598 return createBitCast(V(::builder->CreateGEP(createBitCast(ptr, T(llvm::PointerType::get(T(Byte::getType()), 0))), index)), T(llvm::PointerType::get(T(type), 0)));
John Bauman89401822014-05-06 15:04:28 -0400599 }
600
John Bauman19bac1e2014-05-06 15:23:49 -0400601 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
602 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400603 return V(::builder->CreateAtomicRMW(llvm::AtomicRMWInst::Add, ptr, value, llvm::SequentiallyConsistent));
John Bauman19bac1e2014-05-06 15:23:49 -0400604 }
605
Nicolas Capens19336542016-09-26 10:32:29 -0400606 Value *Nucleus::createTrunc(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400607 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400608 return V(::builder->CreateTrunc(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400609 }
610
Nicolas Capens19336542016-09-26 10:32:29 -0400611 Value *Nucleus::createZExt(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400612 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400613 return V(::builder->CreateZExt(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400614 }
615
Nicolas Capens19336542016-09-26 10:32:29 -0400616 Value *Nucleus::createSExt(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400617 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400618 return V(::builder->CreateSExt(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400619 }
620
Nicolas Capens19336542016-09-26 10:32:29 -0400621 Value *Nucleus::createFPToSI(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400622 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400623 return V(::builder->CreateFPToSI(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400624 }
625
Nicolas Capens19336542016-09-26 10:32:29 -0400626 Value *Nucleus::createSIToFP(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400627 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400628 return V(::builder->CreateSIToFP(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400629 }
630
Nicolas Capens19336542016-09-26 10:32:29 -0400631 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400632 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400633 return V(::builder->CreateFPTrunc(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400634 }
635
Nicolas Capens19336542016-09-26 10:32:29 -0400636 Value *Nucleus::createFPExt(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400637 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400638 return V(::builder->CreateFPExt(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400639 }
640
Nicolas Capens19336542016-09-26 10:32:29 -0400641 Value *Nucleus::createBitCast(Value *v, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400642 {
Nicolas Capens01a97962017-07-28 17:30:51 -0400643 // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need
644 // support for casting between scalars and wide vectors. Emulate them by writing to the stack and
645 // reading back as the destination type.
646 if(!v->getType()->isVectorTy() && T(destType)->isVectorTy())
647 {
648 Value *readAddress = allocateStackVariable(destType);
649 Value *writeAddress = createBitCast(readAddress, T(llvm::PointerType::get(v->getType(), 0)));
650 createStore(v, writeAddress, T(v->getType()));
651 return createLoad(readAddress, destType);
652 }
653 else if(v->getType()->isVectorTy() && !T(destType)->isVectorTy())
654 {
655 Value *writeAddress = allocateStackVariable(T(v->getType()));
656 createStore(v, writeAddress, T(v->getType()));
657 Value *readAddress = createBitCast(writeAddress, T(llvm::PointerType::get(T(destType), 0)));
658 return createLoad(readAddress, destType);
659 }
660
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400661 return V(::builder->CreateBitCast(v, T(destType)));
John Bauman89401822014-05-06 15:04:28 -0400662 }
663
John Bauman89401822014-05-06 15:04:28 -0400664 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
665 {
Nicolas Capens19336542016-09-26 10:32:29 -0400666 return V(::builder->CreateICmpEQ(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400667 }
668
669 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
670 {
Nicolas Capens19336542016-09-26 10:32:29 -0400671 return V(::builder->CreateICmpNE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400672 }
673
674 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
675 {
Nicolas Capens19336542016-09-26 10:32:29 -0400676 return V(::builder->CreateICmpUGT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400677 }
678
679 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
680 {
Nicolas Capens19336542016-09-26 10:32:29 -0400681 return V(::builder->CreateICmpUGE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400682 }
683
684 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
685 {
Nicolas Capens19336542016-09-26 10:32:29 -0400686 return V(::builder->CreateICmpULT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400687 }
688
689 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
690 {
Nicolas Capens19336542016-09-26 10:32:29 -0400691 return V(::builder->CreateICmpULE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400692 }
693
694 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
695 {
Nicolas Capens19336542016-09-26 10:32:29 -0400696 return V(::builder->CreateICmpSGT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400697 }
698
699 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
700 {
Nicolas Capens19336542016-09-26 10:32:29 -0400701 return V(::builder->CreateICmpSGE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400702 }
703
704 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
705 {
Nicolas Capens19336542016-09-26 10:32:29 -0400706 return V(::builder->CreateICmpSLT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400707 }
708
709 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
710 {
Nicolas Capens19336542016-09-26 10:32:29 -0400711 return V(::builder->CreateICmpSLE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400712 }
713
714 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
715 {
Nicolas Capens19336542016-09-26 10:32:29 -0400716 return V(::builder->CreateFCmpOEQ(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400717 }
718
719 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
720 {
Nicolas Capens19336542016-09-26 10:32:29 -0400721 return V(::builder->CreateFCmpOGT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400722 }
723
724 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
725 {
Nicolas Capens19336542016-09-26 10:32:29 -0400726 return V(::builder->CreateFCmpOGE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400727 }
728
729 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
730 {
Nicolas Capens19336542016-09-26 10:32:29 -0400731 return V(::builder->CreateFCmpOLT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400732 }
733
734 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
735 {
Nicolas Capens19336542016-09-26 10:32:29 -0400736 return V(::builder->CreateFCmpOLE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400737 }
738
739 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
740 {
Nicolas Capens19336542016-09-26 10:32:29 -0400741 return V(::builder->CreateFCmpONE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400742 }
743
744 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
745 {
Nicolas Capens19336542016-09-26 10:32:29 -0400746 return V(::builder->CreateFCmpORD(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400747 }
748
749 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
750 {
Nicolas Capens19336542016-09-26 10:32:29 -0400751 return V(::builder->CreateFCmpUNO(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400752 }
753
754 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
755 {
Nicolas Capens19336542016-09-26 10:32:29 -0400756 return V(::builder->CreateFCmpUEQ(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400757 }
758
759 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
760 {
Nicolas Capens19336542016-09-26 10:32:29 -0400761 return V(::builder->CreateFCmpUGT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400762 }
763
764 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
765 {
Nicolas Capens19336542016-09-26 10:32:29 -0400766 return V(::builder->CreateFCmpUGE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400767 }
768
769 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
770 {
Nicolas Capens19336542016-09-26 10:32:29 -0400771 return V(::builder->CreateFCmpULT(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400772 }
773
774 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
775 {
Nicolas Capens19336542016-09-26 10:32:29 -0400776 return V(::builder->CreateFCmpULE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400777 }
778
779 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
780 {
Nicolas Capens19336542016-09-26 10:32:29 -0400781 return V(::builder->CreateFCmpULE(lhs, rhs));
John Bauman89401822014-05-06 15:04:28 -0400782 }
783
Nicolas Capense95d5342016-09-30 11:37:28 -0400784 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
John Bauman89401822014-05-06 15:04:28 -0400785 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400786 assert(vector->getType()->getContainedType(0) == T(type));
Nicolas Capens19336542016-09-26 10:32:29 -0400787 return V(::builder->CreateExtractElement(vector, createConstantInt(index)));
John Bauman89401822014-05-06 15:04:28 -0400788 }
789
790 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
791 {
Nicolas Capens19336542016-09-26 10:32:29 -0400792 return V(::builder->CreateInsertElement(vector, element, createConstantInt(index)));
John Bauman89401822014-05-06 15:04:28 -0400793 }
794
Nicolas Capense89cd582016-09-30 14:23:47 -0400795 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
John Bauman89401822014-05-06 15:04:28 -0400796 {
Nicolas Capense89cd582016-09-30 14:23:47 -0400797 int size = llvm::cast<llvm::VectorType>(V1->getType())->getNumElements();
798 const int maxSize = 16;
799 llvm::Constant *swizzle[maxSize];
800 assert(size <= maxSize);
801
802 for(int i = 0; i < size; i++)
803 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400804 swizzle[i] = llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), select[i]);
Nicolas Capense89cd582016-09-30 14:23:47 -0400805 }
806
807 llvm::Value *shuffle = llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(swizzle, size));
808
809 return V(::builder->CreateShuffleVector(V1, V2, shuffle));
John Bauman89401822014-05-06 15:04:28 -0400810 }
811
812 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
813 {
Nicolas Capens19336542016-09-26 10:32:29 -0400814 return V(::builder->CreateSelect(C, ifTrue, ifFalse));
John Bauman89401822014-05-06 15:04:28 -0400815 }
816
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500817 SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases)
John Bauman89401822014-05-06 15:04:28 -0400818 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500819 return reinterpret_cast<SwitchCases*>(::builder->CreateSwitch(control, defaultBranch, numCases));
John Bauman89401822014-05-06 15:04:28 -0400820 }
821
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500822 void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch)
John Bauman89401822014-05-06 15:04:28 -0400823 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400824 switchCases->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), label, true), branch);
John Bauman89401822014-05-06 15:04:28 -0400825 }
826
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400827 void Nucleus::createUnreachable()
John Bauman89401822014-05-06 15:04:28 -0400828 {
Nicolas Capens3d7c35f2016-09-28 10:36:57 -0400829 ::builder->CreateUnreachable();
John Bauman89401822014-05-06 15:04:28 -0400830 }
831
Nicolas Capense95d5342016-09-30 11:37:28 -0400832 static Value *createSwizzle4(Value *val, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -0400833 {
Nicolas Capense89cd582016-09-30 14:23:47 -0400834 int swizzle[4] =
835 {
836 (select >> 0) & 0x03,
837 (select >> 2) & 0x03,
838 (select >> 4) & 0x03,
839 (select >> 6) & 0x03,
840 };
John Bauman89401822014-05-06 15:04:28 -0400841
Nicolas Capense89cd582016-09-30 14:23:47 -0400842 return Nucleus::createShuffleVector(val, val, swizzle);
John Bauman89401822014-05-06 15:04:28 -0400843 }
844
Nicolas Capense95d5342016-09-30 11:37:28 -0400845 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -0400846 {
847 bool mask[4] = {false, false, false, false};
848
849 mask[(select >> 0) & 0x03] = true;
850 mask[(select >> 2) & 0x03] = true;
851 mask[(select >> 4) & 0x03] = true;
852 mask[(select >> 6) & 0x03] = true;
853
Nicolas Capense89cd582016-09-30 14:23:47 -0400854 int swizzle[4] =
855 {
856 mask[0] ? 4 : 0,
857 mask[1] ? 5 : 1,
858 mask[2] ? 6 : 2,
859 mask[3] ? 7 : 3,
860 };
John Bauman89401822014-05-06 15:04:28 -0400861
Nicolas Capensa29d6532016-12-05 21:38:09 -0500862 return Nucleus::createShuffleVector(lhs, rhs, swizzle);
John Bauman89401822014-05-06 15:04:28 -0400863 }
864
Nicolas Capensac230122016-09-20 14:30:06 -0400865 Type *Nucleus::getPointerType(Type *ElementType)
John Bauman89401822014-05-06 15:04:28 -0400866 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400867 return T(llvm::PointerType::get(T(ElementType), 0));
John Bauman89401822014-05-06 15:04:28 -0400868 }
869
Nicolas Capens13ac2322016-10-13 14:52:12 -0400870 Value *Nucleus::createNullValue(Type *Ty)
John Bauman89401822014-05-06 15:04:28 -0400871 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400872 return V(llvm::Constant::getNullValue(T(Ty)));
John Bauman89401822014-05-06 15:04:28 -0400873 }
874
Nicolas Capens13ac2322016-10-13 14:52:12 -0400875 Value *Nucleus::createConstantLong(int64_t i)
John Bauman89401822014-05-06 15:04:28 -0400876 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400877 return V(llvm::ConstantInt::get(llvm::Type::getInt64Ty(*::context), i, true));
John Bauman89401822014-05-06 15:04:28 -0400878 }
879
Nicolas Capens13ac2322016-10-13 14:52:12 -0400880 Value *Nucleus::createConstantInt(int i)
John Bauman89401822014-05-06 15:04:28 -0400881 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400882 return V(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), i, true));
John Bauman89401822014-05-06 15:04:28 -0400883 }
884
Nicolas Capens13ac2322016-10-13 14:52:12 -0400885 Value *Nucleus::createConstantInt(unsigned int i)
John Bauman89401822014-05-06 15:04:28 -0400886 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400887 return V(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), i, false));
John Bauman89401822014-05-06 15:04:28 -0400888 }
889
Nicolas Capens13ac2322016-10-13 14:52:12 -0400890 Value *Nucleus::createConstantBool(bool b)
John Bauman89401822014-05-06 15:04:28 -0400891 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400892 return V(llvm::ConstantInt::get(llvm::Type::getInt1Ty(*::context), b));
John Bauman89401822014-05-06 15:04:28 -0400893 }
894
Nicolas Capens13ac2322016-10-13 14:52:12 -0400895 Value *Nucleus::createConstantByte(signed char i)
John Bauman89401822014-05-06 15:04:28 -0400896 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400897 return V(llvm::ConstantInt::get(llvm::Type::getInt8Ty(*::context), i, true));
John Bauman89401822014-05-06 15:04:28 -0400898 }
899
Nicolas Capens13ac2322016-10-13 14:52:12 -0400900 Value *Nucleus::createConstantByte(unsigned char i)
John Bauman89401822014-05-06 15:04:28 -0400901 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400902 return V(llvm::ConstantInt::get(llvm::Type::getInt8Ty(*::context), i, false));
John Bauman89401822014-05-06 15:04:28 -0400903 }
904
Nicolas Capens13ac2322016-10-13 14:52:12 -0400905 Value *Nucleus::createConstantShort(short i)
John Bauman89401822014-05-06 15:04:28 -0400906 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400907 return V(llvm::ConstantInt::get(llvm::Type::getInt16Ty(*::context), i, true));
John Bauman89401822014-05-06 15:04:28 -0400908 }
909
Nicolas Capens13ac2322016-10-13 14:52:12 -0400910 Value *Nucleus::createConstantShort(unsigned short i)
John Bauman89401822014-05-06 15:04:28 -0400911 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400912 return V(llvm::ConstantInt::get(llvm::Type::getInt16Ty(*::context), i, false));
John Bauman89401822014-05-06 15:04:28 -0400913 }
914
Nicolas Capens13ac2322016-10-13 14:52:12 -0400915 Value *Nucleus::createConstantFloat(float x)
John Bauman89401822014-05-06 15:04:28 -0400916 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400917 return V(llvm::ConstantFP::get(T(Float::getType()), x));
John Bauman89401822014-05-06 15:04:28 -0400918 }
919
Nicolas Capens13ac2322016-10-13 14:52:12 -0400920 Value *Nucleus::createNullPointer(Type *Ty)
John Bauman89401822014-05-06 15:04:28 -0400921 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400922 return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(T(Ty), 0)));
John Bauman89401822014-05-06 15:04:28 -0400923 }
924
Nicolas Capens13ac2322016-10-13 14:52:12 -0400925 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
John Bauman89401822014-05-06 15:04:28 -0400926 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400927 assert(llvm::isa<llvm::VectorType>(T(type)));
Nicolas Capens69674fb2017-09-01 11:08:44 -0400928 const int numConstants = elementCount(type); // Number of provided constants for the (emulated) type.
929 const int numElements = llvm::cast<llvm::VectorType>(T(type))->getNumElements(); // Number of elements of the underlying vector type.
930 assert(numElements <= 16 && numConstants <= numElements);
Nicolas Capens13ac2322016-10-13 14:52:12 -0400931 llvm::Constant *constantVector[16];
932
Nicolas Capens69674fb2017-09-01 11:08:44 -0400933 for(int i = 0; i < numElements; i++)
Nicolas Capens13ac2322016-10-13 14:52:12 -0400934 {
Nicolas Capens69674fb2017-09-01 11:08:44 -0400935 constantVector[i] = llvm::ConstantInt::get(T(type)->getContainedType(0), constants[i % numConstants]);
Nicolas Capens13ac2322016-10-13 14:52:12 -0400936 }
937
Nicolas Capens69674fb2017-09-01 11:08:44 -0400938 return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numElements)));
Nicolas Capens13ac2322016-10-13 14:52:12 -0400939 }
940
941 Value *Nucleus::createConstantVector(const double *constants, Type *type)
942 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -0400943 assert(llvm::isa<llvm::VectorType>(T(type)));
Nicolas Capens69674fb2017-09-01 11:08:44 -0400944 const int numConstants = elementCount(type); // Number of provided constants for the (emulated) type.
945 const int numElements = llvm::cast<llvm::VectorType>(T(type))->getNumElements(); // Number of elements of the underlying vector type.
946 assert(numElements <= 8 && numConstants <= numElements);
Nicolas Capens13ac2322016-10-13 14:52:12 -0400947 llvm::Constant *constantVector[8];
948
Nicolas Capens69674fb2017-09-01 11:08:44 -0400949 for(int i = 0; i < numElements; i++)
Nicolas Capens13ac2322016-10-13 14:52:12 -0400950 {
Nicolas Capens69674fb2017-09-01 11:08:44 -0400951 constantVector[i] = llvm::ConstantFP::get(T(type)->getContainedType(0), constants[i % numConstants]);
Nicolas Capens13ac2322016-10-13 14:52:12 -0400952 }
953
Nicolas Capens69674fb2017-09-01 11:08:44 -0400954 return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numElements)));
John Bauman89401822014-05-06 15:04:28 -0400955 }
956
John Bauman19bac1e2014-05-06 15:23:49 -0400957 Type *Void::getType()
John Bauman89401822014-05-06 15:04:28 -0400958 {
Nicolas Capensac230122016-09-20 14:30:06 -0400959 return T(llvm::Type::getVoidTy(*::context));
John Bauman89401822014-05-06 15:04:28 -0400960 }
961
Nicolas Capens81f18302016-01-14 09:32:35 -0500962 Bool::Bool(Argument<Bool> argument)
John Bauman89401822014-05-06 15:04:28 -0400963 {
Nicolas Capens81f18302016-01-14 09:32:35 -0500964 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -0400965 }
966
John Bauman89401822014-05-06 15:04:28 -0400967 Bool::Bool(bool x)
968 {
John Bauman66b8ab22014-05-06 15:57:45 -0400969 storeValue(Nucleus::createConstantBool(x));
John Bauman89401822014-05-06 15:04:28 -0400970 }
971
John Bauman19bac1e2014-05-06 15:23:49 -0400972 Bool::Bool(RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -0400973 {
John Bauman66b8ab22014-05-06 15:57:45 -0400974 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400975 }
976
977 Bool::Bool(const Bool &rhs)
978 {
John Bauman66b8ab22014-05-06 15:57:45 -0400979 Value *value = rhs.loadValue();
980 storeValue(value);
981 }
John Bauman89401822014-05-06 15:04:28 -0400982
John Bauman66b8ab22014-05-06 15:57:45 -0400983 Bool::Bool(const Reference<Bool> &rhs)
984 {
985 Value *value = rhs.loadValue();
986 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400987 }
988
Nicolas Capens96d4e092016-11-18 14:22:38 -0500989 RValue<Bool> Bool::operator=(RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -0400990 {
John Bauman66b8ab22014-05-06 15:57:45 -0400991 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400992
993 return rhs;
994 }
995
Nicolas Capens96d4e092016-11-18 14:22:38 -0500996 RValue<Bool> Bool::operator=(const Bool &rhs)
John Bauman89401822014-05-06 15:04:28 -0400997 {
John Bauman66b8ab22014-05-06 15:57:45 -0400998 Value *value = rhs.loadValue();
999 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001000
1001 return RValue<Bool>(value);
1002 }
1003
Nicolas Capens96d4e092016-11-18 14:22:38 -05001004 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
John Bauman89401822014-05-06 15:04:28 -04001005 {
John Bauman66b8ab22014-05-06 15:57:45 -04001006 Value *value = rhs.loadValue();
1007 storeValue(value);
1008
1009 return RValue<Bool>(value);
John Bauman89401822014-05-06 15:04:28 -04001010 }
1011
John Bauman19bac1e2014-05-06 15:23:49 -04001012 RValue<Bool> operator!(RValue<Bool> val)
John Bauman89401822014-05-06 15:04:28 -04001013 {
1014 return RValue<Bool>(Nucleus::createNot(val.value));
1015 }
1016
John Bauman19bac1e2014-05-06 15:23:49 -04001017 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -04001018 {
1019 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1020 }
1021
John Bauman19bac1e2014-05-06 15:23:49 -04001022 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -04001023 {
1024 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1025 }
1026
John Bauman19bac1e2014-05-06 15:23:49 -04001027 Type *Bool::getType()
John Bauman89401822014-05-06 15:04:28 -04001028 {
Nicolas Capensac230122016-09-20 14:30:06 -04001029 return T(llvm::Type::getInt1Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04001030 }
1031
Nicolas Capens81f18302016-01-14 09:32:35 -05001032 Byte::Byte(Argument<Byte> argument)
John Bauman89401822014-05-06 15:04:28 -04001033 {
Nicolas Capens81f18302016-01-14 09:32:35 -05001034 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -04001035 }
1036
John Bauman19bac1e2014-05-06 15:23:49 -04001037 Byte::Byte(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04001038 {
John Bauman89401822014-05-06 15:04:28 -04001039 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1040
John Bauman66b8ab22014-05-06 15:57:45 -04001041 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04001042 }
1043
Alexis Hetu77dfab42015-11-23 13:31:22 -05001044 Byte::Byte(RValue<UInt> cast)
1045 {
1046 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1047
1048 storeValue(integer);
1049 }
1050
1051 Byte::Byte(RValue<UShort> cast)
1052 {
1053 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1054
1055 storeValue(integer);
1056 }
1057
John Bauman89401822014-05-06 15:04:28 -04001058 Byte::Byte(int x)
1059 {
John Bauman66b8ab22014-05-06 15:57:45 -04001060 storeValue(Nucleus::createConstantByte((unsigned char)x));
John Bauman89401822014-05-06 15:04:28 -04001061 }
1062
1063 Byte::Byte(unsigned char x)
1064 {
John Bauman66b8ab22014-05-06 15:57:45 -04001065 storeValue(Nucleus::createConstantByte(x));
John Bauman89401822014-05-06 15:04:28 -04001066 }
1067
John Bauman19bac1e2014-05-06 15:23:49 -04001068 Byte::Byte(RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001069 {
John Bauman66b8ab22014-05-06 15:57:45 -04001070 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001071 }
1072
1073 Byte::Byte(const Byte &rhs)
1074 {
John Bauman66b8ab22014-05-06 15:57:45 -04001075 Value *value = rhs.loadValue();
1076 storeValue(value);
1077 }
John Bauman89401822014-05-06 15:04:28 -04001078
John Bauman66b8ab22014-05-06 15:57:45 -04001079 Byte::Byte(const Reference<Byte> &rhs)
1080 {
1081 Value *value = rhs.loadValue();
1082 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001083 }
1084
Nicolas Capens96d4e092016-11-18 14:22:38 -05001085 RValue<Byte> Byte::operator=(RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001086 {
John Bauman66b8ab22014-05-06 15:57:45 -04001087 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001088
1089 return rhs;
1090 }
1091
Nicolas Capens96445fe2016-12-15 14:45:13 -05001092 RValue<Byte> Byte::operator=(const Byte &rhs)
John Bauman89401822014-05-06 15:04:28 -04001093 {
John Bauman66b8ab22014-05-06 15:57:45 -04001094 Value *value = rhs.loadValue();
1095 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001096
1097 return RValue<Byte>(value);
1098 }
1099
Nicolas Capens96d4e092016-11-18 14:22:38 -05001100 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
John Bauman89401822014-05-06 15:04:28 -04001101 {
John Bauman66b8ab22014-05-06 15:57:45 -04001102 Value *value = rhs.loadValue();
1103 storeValue(value);
1104
1105 return RValue<Byte>(value);
John Bauman89401822014-05-06 15:04:28 -04001106 }
1107
John Bauman19bac1e2014-05-06 15:23:49 -04001108 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001109 {
1110 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1111 }
1112
John Bauman19bac1e2014-05-06 15:23:49 -04001113 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001114 {
1115 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1116 }
1117
John Bauman19bac1e2014-05-06 15:23:49 -04001118 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001119 {
1120 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1121 }
1122
John Bauman19bac1e2014-05-06 15:23:49 -04001123 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001124 {
1125 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1126 }
1127
John Bauman19bac1e2014-05-06 15:23:49 -04001128 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001129 {
1130 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1131 }
1132
John Bauman19bac1e2014-05-06 15:23:49 -04001133 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001134 {
1135 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1136 }
1137
John Bauman19bac1e2014-05-06 15:23:49 -04001138 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001139 {
1140 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1141 }
1142
John Bauman19bac1e2014-05-06 15:23:49 -04001143 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001144 {
1145 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1146 }
1147
John Bauman19bac1e2014-05-06 15:23:49 -04001148 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001149 {
1150 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1151 }
1152
John Bauman19bac1e2014-05-06 15:23:49 -04001153 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001154 {
1155 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1156 }
1157
Nicolas Capens96d4e092016-11-18 14:22:38 -05001158 RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001159 {
1160 return lhs = lhs + rhs;
1161 }
1162
Nicolas Capens96d4e092016-11-18 14:22:38 -05001163 RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001164 {
1165 return lhs = lhs - rhs;
1166 }
1167
Nicolas Capens96d4e092016-11-18 14:22:38 -05001168 RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001169 {
1170 return lhs = lhs * rhs;
1171 }
1172
Nicolas Capens96d4e092016-11-18 14:22:38 -05001173 RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001174 {
1175 return lhs = lhs / rhs;
1176 }
1177
Nicolas Capens96d4e092016-11-18 14:22:38 -05001178 RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001179 {
1180 return lhs = lhs % rhs;
1181 }
1182
Nicolas Capens96d4e092016-11-18 14:22:38 -05001183 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001184 {
1185 return lhs = lhs & rhs;
1186 }
1187
Nicolas Capens96d4e092016-11-18 14:22:38 -05001188 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001189 {
1190 return lhs = lhs | rhs;
1191 }
1192
Nicolas Capens96d4e092016-11-18 14:22:38 -05001193 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001194 {
1195 return lhs = lhs ^ rhs;
1196 }
1197
Nicolas Capens96d4e092016-11-18 14:22:38 -05001198 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001199 {
1200 return lhs = lhs << rhs;
1201 }
1202
Nicolas Capens96d4e092016-11-18 14:22:38 -05001203 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001204 {
1205 return lhs = lhs >> rhs;
1206 }
1207
John Bauman19bac1e2014-05-06 15:23:49 -04001208 RValue<Byte> operator+(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001209 {
1210 return val;
1211 }
1212
John Bauman19bac1e2014-05-06 15:23:49 -04001213 RValue<Byte> operator-(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001214 {
1215 return RValue<Byte>(Nucleus::createNeg(val.value));
1216 }
1217
John Bauman19bac1e2014-05-06 15:23:49 -04001218 RValue<Byte> operator~(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001219 {
1220 return RValue<Byte>(Nucleus::createNot(val.value));
1221 }
1222
Nicolas Capens96d4e092016-11-18 14:22:38 -05001223 RValue<Byte> operator++(Byte &val, int) // Post-increment
John Bauman89401822014-05-06 15:04:28 -04001224 {
1225 RValue<Byte> res = val;
1226
Nicolas Capens19336542016-09-26 10:32:29 -04001227 Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((unsigned char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001228 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001229
1230 return res;
1231 }
1232
Nicolas Capens96d4e092016-11-18 14:22:38 -05001233 const Byte &operator++(Byte &val) // Pre-increment
John Bauman89401822014-05-06 15:04:28 -04001234 {
Nicolas Capens19336542016-09-26 10:32:29 -04001235 Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001236 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001237
1238 return val;
1239 }
1240
Nicolas Capens96d4e092016-11-18 14:22:38 -05001241 RValue<Byte> operator--(Byte &val, int) // Post-decrement
John Bauman89401822014-05-06 15:04:28 -04001242 {
1243 RValue<Byte> res = val;
1244
Nicolas Capens19336542016-09-26 10:32:29 -04001245 Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((unsigned char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001246 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001247
1248 return res;
1249 }
1250
Nicolas Capens96d4e092016-11-18 14:22:38 -05001251 const Byte &operator--(Byte &val) // Pre-decrement
John Bauman89401822014-05-06 15:04:28 -04001252 {
Nicolas Capens19336542016-09-26 10:32:29 -04001253 Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001254 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001255
1256 return val;
1257 }
1258
John Bauman19bac1e2014-05-06 15:23:49 -04001259 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001260 {
1261 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1262 }
1263
John Bauman19bac1e2014-05-06 15:23:49 -04001264 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001265 {
1266 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1267 }
1268
John Bauman19bac1e2014-05-06 15:23:49 -04001269 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001270 {
1271 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1272 }
1273
John Bauman19bac1e2014-05-06 15:23:49 -04001274 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001275 {
1276 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1277 }
1278
John Bauman19bac1e2014-05-06 15:23:49 -04001279 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001280 {
1281 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1282 }
1283
John Bauman19bac1e2014-05-06 15:23:49 -04001284 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001285 {
1286 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1287 }
1288
John Bauman19bac1e2014-05-06 15:23:49 -04001289 Type *Byte::getType()
John Bauman89401822014-05-06 15:04:28 -04001290 {
Nicolas Capensac230122016-09-20 14:30:06 -04001291 return T(llvm::Type::getInt8Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04001292 }
1293
Nicolas Capens81f18302016-01-14 09:32:35 -05001294 SByte::SByte(Argument<SByte> argument)
John Bauman89401822014-05-06 15:04:28 -04001295 {
Nicolas Capens81f18302016-01-14 09:32:35 -05001296 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -04001297 }
1298
Alexis Hetu77dfab42015-11-23 13:31:22 -05001299 SByte::SByte(RValue<Int> cast)
1300 {
1301 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1302
1303 storeValue(integer);
1304 }
1305
1306 SByte::SByte(RValue<Short> cast)
1307 {
1308 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1309
1310 storeValue(integer);
1311 }
1312
John Bauman89401822014-05-06 15:04:28 -04001313 SByte::SByte(signed char x)
1314 {
John Bauman66b8ab22014-05-06 15:57:45 -04001315 storeValue(Nucleus::createConstantByte(x));
John Bauman89401822014-05-06 15:04:28 -04001316 }
1317
John Bauman19bac1e2014-05-06 15:23:49 -04001318 SByte::SByte(RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001319 {
John Bauman66b8ab22014-05-06 15:57:45 -04001320 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001321 }
1322
1323 SByte::SByte(const SByte &rhs)
1324 {
John Bauman66b8ab22014-05-06 15:57:45 -04001325 Value *value = rhs.loadValue();
1326 storeValue(value);
1327 }
John Bauman89401822014-05-06 15:04:28 -04001328
John Bauman66b8ab22014-05-06 15:57:45 -04001329 SByte::SByte(const Reference<SByte> &rhs)
1330 {
1331 Value *value = rhs.loadValue();
1332 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001333 }
1334
Nicolas Capens96d4e092016-11-18 14:22:38 -05001335 RValue<SByte> SByte::operator=(RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001336 {
John Bauman66b8ab22014-05-06 15:57:45 -04001337 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001338
1339 return rhs;
1340 }
1341
Nicolas Capens96d4e092016-11-18 14:22:38 -05001342 RValue<SByte> SByte::operator=(const SByte &rhs)
John Bauman89401822014-05-06 15:04:28 -04001343 {
John Bauman66b8ab22014-05-06 15:57:45 -04001344 Value *value = rhs.loadValue();
1345 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001346
1347 return RValue<SByte>(value);
1348 }
1349
Nicolas Capens96d4e092016-11-18 14:22:38 -05001350 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
John Bauman89401822014-05-06 15:04:28 -04001351 {
John Bauman66b8ab22014-05-06 15:57:45 -04001352 Value *value = rhs.loadValue();
1353 storeValue(value);
1354
1355 return RValue<SByte>(value);
John Bauman89401822014-05-06 15:04:28 -04001356 }
1357
John Bauman19bac1e2014-05-06 15:23:49 -04001358 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001359 {
1360 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1361 }
1362
John Bauman19bac1e2014-05-06 15:23:49 -04001363 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001364 {
1365 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1366 }
1367
John Bauman19bac1e2014-05-06 15:23:49 -04001368 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001369 {
1370 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1371 }
1372
John Bauman19bac1e2014-05-06 15:23:49 -04001373 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001374 {
1375 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1376 }
1377
John Bauman19bac1e2014-05-06 15:23:49 -04001378 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001379 {
1380 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1381 }
1382
John Bauman19bac1e2014-05-06 15:23:49 -04001383 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001384 {
1385 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1386 }
1387
John Bauman19bac1e2014-05-06 15:23:49 -04001388 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001389 {
1390 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1391 }
1392
John Bauman19bac1e2014-05-06 15:23:49 -04001393 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001394 {
1395 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1396 }
1397
John Bauman19bac1e2014-05-06 15:23:49 -04001398 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001399 {
1400 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1401 }
1402
John Bauman19bac1e2014-05-06 15:23:49 -04001403 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001404 {
1405 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1406 }
1407
Nicolas Capens96d4e092016-11-18 14:22:38 -05001408 RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001409 {
1410 return lhs = lhs + rhs;
1411 }
1412
Nicolas Capens96d4e092016-11-18 14:22:38 -05001413 RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001414 {
1415 return lhs = lhs - rhs;
1416 }
1417
Nicolas Capens96d4e092016-11-18 14:22:38 -05001418 RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001419 {
1420 return lhs = lhs * rhs;
1421 }
1422
Nicolas Capens96d4e092016-11-18 14:22:38 -05001423 RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001424 {
1425 return lhs = lhs / rhs;
1426 }
1427
Nicolas Capens96d4e092016-11-18 14:22:38 -05001428 RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001429 {
1430 return lhs = lhs % rhs;
1431 }
1432
Nicolas Capens96d4e092016-11-18 14:22:38 -05001433 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001434 {
1435 return lhs = lhs & rhs;
1436 }
1437
Nicolas Capens96d4e092016-11-18 14:22:38 -05001438 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001439 {
1440 return lhs = lhs | rhs;
1441 }
1442
Nicolas Capens96d4e092016-11-18 14:22:38 -05001443 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001444 {
1445 return lhs = lhs ^ rhs;
1446 }
1447
Nicolas Capens96d4e092016-11-18 14:22:38 -05001448 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001449 {
1450 return lhs = lhs << rhs;
1451 }
1452
Nicolas Capens96d4e092016-11-18 14:22:38 -05001453 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001454 {
1455 return lhs = lhs >> rhs;
1456 }
1457
John Bauman19bac1e2014-05-06 15:23:49 -04001458 RValue<SByte> operator+(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001459 {
1460 return val;
1461 }
1462
John Bauman19bac1e2014-05-06 15:23:49 -04001463 RValue<SByte> operator-(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001464 {
1465 return RValue<SByte>(Nucleus::createNeg(val.value));
1466 }
1467
John Bauman19bac1e2014-05-06 15:23:49 -04001468 RValue<SByte> operator~(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001469 {
1470 return RValue<SByte>(Nucleus::createNot(val.value));
1471 }
1472
Nicolas Capens96d4e092016-11-18 14:22:38 -05001473 RValue<SByte> operator++(SByte &val, int) // Post-increment
John Bauman89401822014-05-06 15:04:28 -04001474 {
1475 RValue<SByte> res = val;
1476
Nicolas Capens19336542016-09-26 10:32:29 -04001477 Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((signed char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001478 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001479
1480 return res;
1481 }
1482
Nicolas Capens96d4e092016-11-18 14:22:38 -05001483 const SByte &operator++(SByte &val) // Pre-increment
John Bauman89401822014-05-06 15:04:28 -04001484 {
Nicolas Capens19336542016-09-26 10:32:29 -04001485 Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((signed char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001486 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001487
1488 return val;
1489 }
1490
Nicolas Capens96d4e092016-11-18 14:22:38 -05001491 RValue<SByte> operator--(SByte &val, int) // Post-decrement
John Bauman89401822014-05-06 15:04:28 -04001492 {
1493 RValue<SByte> res = val;
1494
Nicolas Capens19336542016-09-26 10:32:29 -04001495 Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((signed char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001496 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001497
1498 return res;
1499 }
1500
Nicolas Capens96d4e092016-11-18 14:22:38 -05001501 const SByte &operator--(SByte &val) // Pre-decrement
John Bauman89401822014-05-06 15:04:28 -04001502 {
Nicolas Capens19336542016-09-26 10:32:29 -04001503 Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((signed char)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001504 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001505
1506 return val;
1507 }
1508
John Bauman19bac1e2014-05-06 15:23:49 -04001509 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001510 {
1511 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1512 }
1513
John Bauman19bac1e2014-05-06 15:23:49 -04001514 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001515 {
1516 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1517 }
1518
John Bauman19bac1e2014-05-06 15:23:49 -04001519 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001520 {
1521 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1522 }
1523
John Bauman19bac1e2014-05-06 15:23:49 -04001524 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001525 {
1526 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1527 }
1528
John Bauman19bac1e2014-05-06 15:23:49 -04001529 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001530 {
1531 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1532 }
1533
John Bauman19bac1e2014-05-06 15:23:49 -04001534 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001535 {
1536 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1537 }
1538
John Bauman19bac1e2014-05-06 15:23:49 -04001539 Type *SByte::getType()
John Bauman89401822014-05-06 15:04:28 -04001540 {
Nicolas Capensac230122016-09-20 14:30:06 -04001541 return T(llvm::Type::getInt8Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04001542 }
1543
Nicolas Capens81f18302016-01-14 09:32:35 -05001544 Short::Short(Argument<Short> argument)
John Bauman89401822014-05-06 15:04:28 -04001545 {
Nicolas Capens81f18302016-01-14 09:32:35 -05001546 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -04001547 }
1548
John Bauman19bac1e2014-05-06 15:23:49 -04001549 Short::Short(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04001550 {
John Bauman89401822014-05-06 15:04:28 -04001551 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1552
John Bauman66b8ab22014-05-06 15:57:45 -04001553 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04001554 }
1555
John Bauman89401822014-05-06 15:04:28 -04001556 Short::Short(short x)
1557 {
John Bauman66b8ab22014-05-06 15:57:45 -04001558 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001559 }
1560
John Bauman19bac1e2014-05-06 15:23:49 -04001561 Short::Short(RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001562 {
John Bauman66b8ab22014-05-06 15:57:45 -04001563 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001564 }
1565
1566 Short::Short(const Short &rhs)
1567 {
John Bauman66b8ab22014-05-06 15:57:45 -04001568 Value *value = rhs.loadValue();
1569 storeValue(value);
1570 }
John Bauman89401822014-05-06 15:04:28 -04001571
John Bauman66b8ab22014-05-06 15:57:45 -04001572 Short::Short(const Reference<Short> &rhs)
1573 {
1574 Value *value = rhs.loadValue();
1575 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001576 }
1577
Nicolas Capens96d4e092016-11-18 14:22:38 -05001578 RValue<Short> Short::operator=(RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001579 {
John Bauman66b8ab22014-05-06 15:57:45 -04001580 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001581
1582 return rhs;
1583 }
1584
Nicolas Capens96d4e092016-11-18 14:22:38 -05001585 RValue<Short> Short::operator=(const Short &rhs)
John Bauman89401822014-05-06 15:04:28 -04001586 {
John Bauman66b8ab22014-05-06 15:57:45 -04001587 Value *value = rhs.loadValue();
1588 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001589
1590 return RValue<Short>(value);
1591 }
1592
Nicolas Capens96d4e092016-11-18 14:22:38 -05001593 RValue<Short> Short::operator=(const Reference<Short> &rhs)
John Bauman89401822014-05-06 15:04:28 -04001594 {
John Bauman66b8ab22014-05-06 15:57:45 -04001595 Value *value = rhs.loadValue();
1596 storeValue(value);
1597
1598 return RValue<Short>(value);
John Bauman89401822014-05-06 15:04:28 -04001599 }
1600
John Bauman19bac1e2014-05-06 15:23:49 -04001601 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001602 {
1603 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
1604 }
1605
John Bauman19bac1e2014-05-06 15:23:49 -04001606 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001607 {
1608 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
1609 }
1610
John Bauman19bac1e2014-05-06 15:23:49 -04001611 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001612 {
1613 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
1614 }
1615
John Bauman19bac1e2014-05-06 15:23:49 -04001616 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001617 {
1618 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
1619 }
1620
John Bauman19bac1e2014-05-06 15:23:49 -04001621 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001622 {
1623 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
1624 }
1625
John Bauman19bac1e2014-05-06 15:23:49 -04001626 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001627 {
1628 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
1629 }
1630
John Bauman19bac1e2014-05-06 15:23:49 -04001631 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001632 {
1633 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
1634 }
1635
John Bauman19bac1e2014-05-06 15:23:49 -04001636 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001637 {
1638 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
1639 }
1640
John Bauman19bac1e2014-05-06 15:23:49 -04001641 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001642 {
1643 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
1644 }
1645
John Bauman19bac1e2014-05-06 15:23:49 -04001646 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001647 {
1648 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
1649 }
1650
Nicolas Capens96d4e092016-11-18 14:22:38 -05001651 RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001652 {
1653 return lhs = lhs + rhs;
1654 }
1655
Nicolas Capens96d4e092016-11-18 14:22:38 -05001656 RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001657 {
1658 return lhs = lhs - rhs;
1659 }
1660
Nicolas Capens96d4e092016-11-18 14:22:38 -05001661 RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001662 {
1663 return lhs = lhs * rhs;
1664 }
1665
Nicolas Capens96d4e092016-11-18 14:22:38 -05001666 RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001667 {
1668 return lhs = lhs / rhs;
1669 }
1670
Nicolas Capens96d4e092016-11-18 14:22:38 -05001671 RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001672 {
1673 return lhs = lhs % rhs;
1674 }
1675
Nicolas Capens96d4e092016-11-18 14:22:38 -05001676 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001677 {
1678 return lhs = lhs & rhs;
1679 }
1680
Nicolas Capens96d4e092016-11-18 14:22:38 -05001681 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001682 {
1683 return lhs = lhs | rhs;
1684 }
1685
Nicolas Capens96d4e092016-11-18 14:22:38 -05001686 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001687 {
1688 return lhs = lhs ^ rhs;
1689 }
1690
Nicolas Capens96d4e092016-11-18 14:22:38 -05001691 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001692 {
1693 return lhs = lhs << rhs;
1694 }
1695
Nicolas Capens96d4e092016-11-18 14:22:38 -05001696 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001697 {
1698 return lhs = lhs >> rhs;
1699 }
1700
John Bauman19bac1e2014-05-06 15:23:49 -04001701 RValue<Short> operator+(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001702 {
1703 return val;
1704 }
1705
John Bauman19bac1e2014-05-06 15:23:49 -04001706 RValue<Short> operator-(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001707 {
1708 return RValue<Short>(Nucleus::createNeg(val.value));
1709 }
1710
John Bauman19bac1e2014-05-06 15:23:49 -04001711 RValue<Short> operator~(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001712 {
1713 return RValue<Short>(Nucleus::createNot(val.value));
1714 }
1715
Nicolas Capens96d4e092016-11-18 14:22:38 -05001716 RValue<Short> operator++(Short &val, int) // Post-increment
John Bauman89401822014-05-06 15:04:28 -04001717 {
1718 RValue<Short> res = val;
1719
Nicolas Capens19336542016-09-26 10:32:29 -04001720 Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001721 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001722
1723 return res;
1724 }
1725
Nicolas Capens96d4e092016-11-18 14:22:38 -05001726 const Short &operator++(Short &val) // Pre-increment
John Bauman89401822014-05-06 15:04:28 -04001727 {
Nicolas Capens19336542016-09-26 10:32:29 -04001728 Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001729 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001730
1731 return val;
1732 }
1733
Nicolas Capens96d4e092016-11-18 14:22:38 -05001734 RValue<Short> operator--(Short &val, int) // Post-decrement
John Bauman89401822014-05-06 15:04:28 -04001735 {
1736 RValue<Short> res = val;
1737
Nicolas Capens19336542016-09-26 10:32:29 -04001738 Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001739 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001740
1741 return res;
1742 }
1743
Nicolas Capens96d4e092016-11-18 14:22:38 -05001744 const Short &operator--(Short &val) // Pre-decrement
John Bauman89401822014-05-06 15:04:28 -04001745 {
Nicolas Capens19336542016-09-26 10:32:29 -04001746 Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001747 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001748
1749 return val;
1750 }
1751
John Bauman19bac1e2014-05-06 15:23:49 -04001752 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001753 {
1754 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1755 }
1756
John Bauman19bac1e2014-05-06 15:23:49 -04001757 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001758 {
1759 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1760 }
1761
John Bauman19bac1e2014-05-06 15:23:49 -04001762 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001763 {
1764 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1765 }
1766
John Bauman19bac1e2014-05-06 15:23:49 -04001767 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001768 {
1769 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1770 }
1771
John Bauman19bac1e2014-05-06 15:23:49 -04001772 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001773 {
1774 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1775 }
1776
John Bauman19bac1e2014-05-06 15:23:49 -04001777 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001778 {
1779 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1780 }
1781
John Bauman19bac1e2014-05-06 15:23:49 -04001782 Type *Short::getType()
John Bauman89401822014-05-06 15:04:28 -04001783 {
Nicolas Capensac230122016-09-20 14:30:06 -04001784 return T(llvm::Type::getInt16Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04001785 }
1786
Nicolas Capens81f18302016-01-14 09:32:35 -05001787 UShort::UShort(Argument<UShort> argument)
John Bauman89401822014-05-06 15:04:28 -04001788 {
Nicolas Capens81f18302016-01-14 09:32:35 -05001789 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -04001790 }
1791
Alexis Hetu77dfab42015-11-23 13:31:22 -05001792 UShort::UShort(RValue<UInt> cast)
1793 {
1794 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
1795
1796 storeValue(integer);
1797 }
1798
Alexis Hetu75b650f2015-11-19 17:40:15 -05001799 UShort::UShort(RValue<Int> cast)
1800 {
1801 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
1802
1803 storeValue(integer);
1804 }
1805
John Bauman89401822014-05-06 15:04:28 -04001806 UShort::UShort(unsigned short x)
1807 {
John Bauman66b8ab22014-05-06 15:57:45 -04001808 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001809 }
1810
John Bauman19bac1e2014-05-06 15:23:49 -04001811 UShort::UShort(RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001812 {
John Bauman66b8ab22014-05-06 15:57:45 -04001813 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001814 }
1815
1816 UShort::UShort(const UShort &rhs)
1817 {
John Bauman66b8ab22014-05-06 15:57:45 -04001818 Value *value = rhs.loadValue();
1819 storeValue(value);
1820 }
John Bauman89401822014-05-06 15:04:28 -04001821
John Bauman66b8ab22014-05-06 15:57:45 -04001822 UShort::UShort(const Reference<UShort> &rhs)
1823 {
1824 Value *value = rhs.loadValue();
1825 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001826 }
1827
Nicolas Capens96d4e092016-11-18 14:22:38 -05001828 RValue<UShort> UShort::operator=(RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001829 {
John Bauman66b8ab22014-05-06 15:57:45 -04001830 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001831
1832 return rhs;
1833 }
1834
Nicolas Capens96d4e092016-11-18 14:22:38 -05001835 RValue<UShort> UShort::operator=(const UShort &rhs)
John Bauman89401822014-05-06 15:04:28 -04001836 {
John Bauman66b8ab22014-05-06 15:57:45 -04001837 Value *value = rhs.loadValue();
1838 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001839
1840 return RValue<UShort>(value);
1841 }
1842
Nicolas Capens96d4e092016-11-18 14:22:38 -05001843 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
John Bauman89401822014-05-06 15:04:28 -04001844 {
John Bauman66b8ab22014-05-06 15:57:45 -04001845 Value *value = rhs.loadValue();
1846 storeValue(value);
1847
1848 return RValue<UShort>(value);
John Bauman89401822014-05-06 15:04:28 -04001849 }
1850
John Bauman19bac1e2014-05-06 15:23:49 -04001851 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001852 {
1853 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
1854 }
1855
John Bauman19bac1e2014-05-06 15:23:49 -04001856 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001857 {
1858 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
1859 }
1860
John Bauman19bac1e2014-05-06 15:23:49 -04001861 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001862 {
1863 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
1864 }
1865
John Bauman19bac1e2014-05-06 15:23:49 -04001866 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001867 {
1868 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
1869 }
1870
John Bauman19bac1e2014-05-06 15:23:49 -04001871 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001872 {
1873 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
1874 }
1875
John Bauman19bac1e2014-05-06 15:23:49 -04001876 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001877 {
1878 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
1879 }
1880
John Bauman19bac1e2014-05-06 15:23:49 -04001881 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001882 {
1883 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
1884 }
1885
John Bauman19bac1e2014-05-06 15:23:49 -04001886 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001887 {
1888 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
1889 }
1890
John Bauman19bac1e2014-05-06 15:23:49 -04001891 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001892 {
1893 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
1894 }
1895
John Bauman19bac1e2014-05-06 15:23:49 -04001896 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001897 {
1898 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
1899 }
1900
Nicolas Capens96d4e092016-11-18 14:22:38 -05001901 RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001902 {
1903 return lhs = lhs + rhs;
1904 }
1905
Nicolas Capens96d4e092016-11-18 14:22:38 -05001906 RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001907 {
1908 return lhs = lhs - rhs;
1909 }
1910
Nicolas Capens96d4e092016-11-18 14:22:38 -05001911 RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001912 {
1913 return lhs = lhs * rhs;
1914 }
1915
Nicolas Capens96d4e092016-11-18 14:22:38 -05001916 RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001917 {
1918 return lhs = lhs / rhs;
1919 }
1920
Nicolas Capens96d4e092016-11-18 14:22:38 -05001921 RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001922 {
1923 return lhs = lhs % rhs;
1924 }
1925
Nicolas Capens96d4e092016-11-18 14:22:38 -05001926 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001927 {
1928 return lhs = lhs & rhs;
1929 }
1930
Nicolas Capens96d4e092016-11-18 14:22:38 -05001931 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001932 {
1933 return lhs = lhs | rhs;
1934 }
1935
Nicolas Capens96d4e092016-11-18 14:22:38 -05001936 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001937 {
1938 return lhs = lhs ^ rhs;
1939 }
1940
Nicolas Capens96d4e092016-11-18 14:22:38 -05001941 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001942 {
1943 return lhs = lhs << rhs;
1944 }
1945
Nicolas Capens96d4e092016-11-18 14:22:38 -05001946 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001947 {
1948 return lhs = lhs >> rhs;
1949 }
1950
John Bauman19bac1e2014-05-06 15:23:49 -04001951 RValue<UShort> operator+(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001952 {
1953 return val;
1954 }
1955
John Bauman19bac1e2014-05-06 15:23:49 -04001956 RValue<UShort> operator-(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001957 {
1958 return RValue<UShort>(Nucleus::createNeg(val.value));
1959 }
1960
John Bauman19bac1e2014-05-06 15:23:49 -04001961 RValue<UShort> operator~(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001962 {
1963 return RValue<UShort>(Nucleus::createNot(val.value));
1964 }
1965
Nicolas Capens96d4e092016-11-18 14:22:38 -05001966 RValue<UShort> operator++(UShort &val, int) // Post-increment
John Bauman89401822014-05-06 15:04:28 -04001967 {
1968 RValue<UShort> res = val;
1969
Nicolas Capens19336542016-09-26 10:32:29 -04001970 Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((unsigned short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001971 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001972
1973 return res;
1974 }
1975
Nicolas Capens96d4e092016-11-18 14:22:38 -05001976 const UShort &operator++(UShort &val) // Pre-increment
John Bauman89401822014-05-06 15:04:28 -04001977 {
Nicolas Capens19336542016-09-26 10:32:29 -04001978 Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001979 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001980
1981 return val;
1982 }
1983
Nicolas Capens96d4e092016-11-18 14:22:38 -05001984 RValue<UShort> operator--(UShort &val, int) // Post-decrement
John Bauman89401822014-05-06 15:04:28 -04001985 {
1986 RValue<UShort> res = val;
1987
Nicolas Capens19336542016-09-26 10:32:29 -04001988 Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((unsigned short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001989 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001990
1991 return res;
1992 }
1993
Nicolas Capens96d4e092016-11-18 14:22:38 -05001994 const UShort &operator--(UShort &val) // Pre-decrement
John Bauman89401822014-05-06 15:04:28 -04001995 {
Nicolas Capens19336542016-09-26 10:32:29 -04001996 Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1)));
John Bauman66b8ab22014-05-06 15:57:45 -04001997 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001998
1999 return val;
2000 }
2001
John Bauman19bac1e2014-05-06 15:23:49 -04002002 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04002003 {
2004 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2005 }
2006
John Bauman19bac1e2014-05-06 15:23:49 -04002007 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04002008 {
2009 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2010 }
2011
John Bauman19bac1e2014-05-06 15:23:49 -04002012 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04002013 {
2014 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2015 }
2016
John Bauman19bac1e2014-05-06 15:23:49 -04002017 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04002018 {
2019 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2020 }
2021
John Bauman19bac1e2014-05-06 15:23:49 -04002022 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04002023 {
2024 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2025 }
2026
John Bauman19bac1e2014-05-06 15:23:49 -04002027 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04002028 {
2029 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2030 }
2031
John Bauman19bac1e2014-05-06 15:23:49 -04002032 Type *UShort::getType()
John Bauman89401822014-05-06 15:04:28 -04002033 {
Nicolas Capensac230122016-09-20 14:30:06 -04002034 return T(llvm::Type::getInt16Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04002035 }
2036
Nicolas Capens16b5f152016-10-13 13:39:01 -04002037 Byte4::Byte4(RValue<Byte8> cast)
2038 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002039 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002040 }
2041
2042 Byte4::Byte4(const Reference<Byte4> &rhs)
2043 {
Nicolas Capens16b5f152016-10-13 13:39:01 -04002044 Value *value = rhs.loadValue();
2045 storeValue(value);
2046 }
2047
John Bauman19bac1e2014-05-06 15:23:49 -04002048 Type *Byte4::getType()
John Bauman89401822014-05-06 15:04:28 -04002049 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002050 return T(Type_v4i8);
John Bauman89401822014-05-06 15:04:28 -04002051 }
2052
John Bauman19bac1e2014-05-06 15:23:49 -04002053 Type *SByte4::getType()
John Bauman89401822014-05-06 15:04:28 -04002054 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002055 return T(Type_v4i8);
John Bauman89401822014-05-06 15:04:28 -04002056 }
2057
Nicolas Capens3bbc5e12016-09-27 10:49:52 -04002058 Byte8::Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
John Bauman89401822014-05-06 15:04:28 -04002059 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04002060 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
Nicolas Capens01a97962017-07-28 17:30:51 -04002061 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002062 }
2063
John Bauman19bac1e2014-05-06 15:23:49 -04002064 Byte8::Byte8(RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002065 {
John Bauman66b8ab22014-05-06 15:57:45 -04002066 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002067 }
2068
2069 Byte8::Byte8(const Byte8 &rhs)
2070 {
John Bauman66b8ab22014-05-06 15:57:45 -04002071 Value *value = rhs.loadValue();
2072 storeValue(value);
2073 }
2074
2075 Byte8::Byte8(const Reference<Byte8> &rhs)
2076 {
John Bauman66b8ab22014-05-06 15:57:45 -04002077 Value *value = rhs.loadValue();
2078 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002079 }
2080
Nicolas Capens96d4e092016-11-18 14:22:38 -05002081 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002082 {
John Bauman66b8ab22014-05-06 15:57:45 -04002083 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002084
2085 return rhs;
2086 }
2087
Nicolas Capens96d4e092016-11-18 14:22:38 -05002088 RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002089 {
John Bauman66b8ab22014-05-06 15:57:45 -04002090 Value *value = rhs.loadValue();
2091 storeValue(value);
2092
2093 return RValue<Byte8>(value);
2094 }
2095
Nicolas Capens96d4e092016-11-18 14:22:38 -05002096 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04002097 {
2098 Value *value = rhs.loadValue();
2099 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002100
2101 return RValue<Byte8>(value);
2102 }
2103
John Bauman19bac1e2014-05-06 15:23:49 -04002104 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002105 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002106 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002107 }
2108
John Bauman19bac1e2014-05-06 15:23:49 -04002109 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002110 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002111 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002112 }
2113
John Bauman19bac1e2014-05-06 15:23:49 -04002114// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2115// {
2116// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2117// }
2118
2119// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2120// {
2121// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2122// }
2123
2124// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2125// {
2126// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2127// }
2128
2129 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002130 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002131 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002132 }
2133
John Bauman19bac1e2014-05-06 15:23:49 -04002134 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002135 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002136 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002137 }
2138
John Bauman19bac1e2014-05-06 15:23:49 -04002139 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002140 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002141 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002142 }
2143
John Bauman19bac1e2014-05-06 15:23:49 -04002144// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002145// {
2146// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
2147// }
2148
John Bauman19bac1e2014-05-06 15:23:49 -04002149// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002150// {
2151// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
2152// }
2153
Nicolas Capens96d4e092016-11-18 14:22:38 -05002154 RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002155 {
2156 return lhs = lhs + rhs;
2157 }
2158
Nicolas Capens96d4e092016-11-18 14:22:38 -05002159 RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002160 {
2161 return lhs = lhs - rhs;
2162 }
2163
Nicolas Capens96d4e092016-11-18 14:22:38 -05002164// RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002165// {
2166// return lhs = lhs * rhs;
2167// }
John Bauman89401822014-05-06 15:04:28 -04002168
Nicolas Capens96d4e092016-11-18 14:22:38 -05002169// RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002170// {
2171// return lhs = lhs / rhs;
2172// }
John Bauman89401822014-05-06 15:04:28 -04002173
Nicolas Capens96d4e092016-11-18 14:22:38 -05002174// RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002175// {
2176// return lhs = lhs % rhs;
2177// }
John Bauman89401822014-05-06 15:04:28 -04002178
Nicolas Capens96d4e092016-11-18 14:22:38 -05002179 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002180 {
2181 return lhs = lhs & rhs;
2182 }
2183
Nicolas Capens96d4e092016-11-18 14:22:38 -05002184 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002185 {
2186 return lhs = lhs | rhs;
2187 }
2188
Nicolas Capens96d4e092016-11-18 14:22:38 -05002189 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002190 {
2191 return lhs = lhs ^ rhs;
2192 }
2193
Nicolas Capens96d4e092016-11-18 14:22:38 -05002194// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002195// {
2196// return lhs = lhs << rhs;
2197// }
2198
Nicolas Capens96d4e092016-11-18 14:22:38 -05002199// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002200// {
2201// return lhs = lhs >> rhs;
2202// }
2203
John Bauman19bac1e2014-05-06 15:23:49 -04002204// RValue<Byte8> operator+(RValue<Byte8> val)
2205// {
2206// return val;
2207// }
2208
2209// RValue<Byte8> operator-(RValue<Byte8> val)
2210// {
2211// return RValue<Byte8>(Nucleus::createNeg(val.value));
2212// }
2213
2214 RValue<Byte8> operator~(RValue<Byte8> val)
John Bauman89401822014-05-06 15:04:28 -04002215 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002216 return RValue<Byte8>(Nucleus::createNot(val.value));
John Bauman89401822014-05-06 15:04:28 -04002217 }
2218
John Bauman19bac1e2014-05-06 15:23:49 -04002219 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002220 {
2221 return x86::paddusb(x, y);
2222 }
John Bauman66b8ab22014-05-06 15:57:45 -04002223
John Bauman19bac1e2014-05-06 15:23:49 -04002224 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002225 {
2226 return x86::psubusb(x, y);
2227 }
2228
John Bauman19bac1e2014-05-06 15:23:49 -04002229 RValue<Short4> Unpack(RValue<Byte4> x)
John Bauman89401822014-05-06 15:04:28 -04002230 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002231 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2232 return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
John Bauman19bac1e2014-05-06 15:23:49 -04002233 }
John Bauman89401822014-05-06 15:04:28 -04002234
Nicolas Capens411273e2017-01-26 15:13:36 -08002235 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
2236 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002237 return UnpackLow(As<Byte8>(x), As<Byte8>(y));
Nicolas Capens411273e2017-01-26 15:13:36 -08002238 }
2239
John Bauman19bac1e2014-05-06 15:23:49 -04002240 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2241 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002242 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2243 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04002244 }
John Bauman66b8ab22014-05-06 15:57:45 -04002245
John Bauman19bac1e2014-05-06 15:23:49 -04002246 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002247 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002248 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2249 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2250 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
John Bauman89401822014-05-06 15:04:28 -04002251 }
2252
John Bauman19bac1e2014-05-06 15:23:49 -04002253 RValue<Int> SignMask(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04002254 {
2255 return x86::pmovmskb(x);
2256 }
2257
John Bauman19bac1e2014-05-06 15:23:49 -04002258// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002259// {
2260// return x86::pcmpgtb(x, y); // FIXME: Signedness
2261// }
John Bauman66b8ab22014-05-06 15:57:45 -04002262
John Bauman19bac1e2014-05-06 15:23:49 -04002263 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002264 {
2265 return x86::pcmpeqb(x, y);
2266 }
2267
John Bauman19bac1e2014-05-06 15:23:49 -04002268 Type *Byte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002269 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002270 return T(Type_v8i8);
John Bauman89401822014-05-06 15:04:28 -04002271 }
2272
Nicolas Capens3bbc5e12016-09-27 10:49:52 -04002273 SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
John Bauman89401822014-05-06 15:04:28 -04002274 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04002275 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
Nicolas Capens01a97962017-07-28 17:30:51 -04002276 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002277
John Bauman66b8ab22014-05-06 15:57:45 -04002278 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002279 }
2280
John Bauman19bac1e2014-05-06 15:23:49 -04002281 SByte8::SByte8(RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002282 {
John Bauman66b8ab22014-05-06 15:57:45 -04002283 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002284 }
2285
2286 SByte8::SByte8(const SByte8 &rhs)
2287 {
John Bauman66b8ab22014-05-06 15:57:45 -04002288 Value *value = rhs.loadValue();
2289 storeValue(value);
2290 }
2291
2292 SByte8::SByte8(const Reference<SByte8> &rhs)
2293 {
John Bauman66b8ab22014-05-06 15:57:45 -04002294 Value *value = rhs.loadValue();
2295 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002296 }
2297
Nicolas Capens96d4e092016-11-18 14:22:38 -05002298 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002299 {
John Bauman66b8ab22014-05-06 15:57:45 -04002300 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002301
2302 return rhs;
2303 }
2304
Nicolas Capens96d4e092016-11-18 14:22:38 -05002305 RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002306 {
John Bauman66b8ab22014-05-06 15:57:45 -04002307 Value *value = rhs.loadValue();
2308 storeValue(value);
2309
2310 return RValue<SByte8>(value);
2311 }
2312
Nicolas Capens96d4e092016-11-18 14:22:38 -05002313 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04002314 {
2315 Value *value = rhs.loadValue();
2316 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002317
2318 return RValue<SByte8>(value);
2319 }
2320
John Bauman19bac1e2014-05-06 15:23:49 -04002321 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002322 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002323 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002324 }
2325
John Bauman19bac1e2014-05-06 15:23:49 -04002326 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002327 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002328 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002329 }
2330
John Bauman19bac1e2014-05-06 15:23:49 -04002331// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2332// {
2333// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2334// }
John Bauman89401822014-05-06 15:04:28 -04002335
John Bauman19bac1e2014-05-06 15:23:49 -04002336// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2337// {
2338// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2339// }
John Bauman89401822014-05-06 15:04:28 -04002340
John Bauman19bac1e2014-05-06 15:23:49 -04002341// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2342// {
2343// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2344// }
John Bauman89401822014-05-06 15:04:28 -04002345
John Bauman19bac1e2014-05-06 15:23:49 -04002346 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002347 {
2348 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2349 }
2350
John Bauman19bac1e2014-05-06 15:23:49 -04002351 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002352 {
2353 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2354 }
2355
John Bauman19bac1e2014-05-06 15:23:49 -04002356 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002357 {
2358 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2359 }
2360
John Bauman19bac1e2014-05-06 15:23:49 -04002361// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002362// {
2363// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
2364// }
2365
John Bauman19bac1e2014-05-06 15:23:49 -04002366// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002367// {
2368// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
2369// }
2370
Nicolas Capens96d4e092016-11-18 14:22:38 -05002371 RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002372 {
2373 return lhs = lhs + rhs;
2374 }
2375
Nicolas Capens96d4e092016-11-18 14:22:38 -05002376 RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002377 {
2378 return lhs = lhs - rhs;
2379 }
2380
Nicolas Capens96d4e092016-11-18 14:22:38 -05002381// RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002382// {
2383// return lhs = lhs * rhs;
2384// }
John Bauman89401822014-05-06 15:04:28 -04002385
Nicolas Capens96d4e092016-11-18 14:22:38 -05002386// RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002387// {
2388// return lhs = lhs / rhs;
2389// }
John Bauman89401822014-05-06 15:04:28 -04002390
Nicolas Capens96d4e092016-11-18 14:22:38 -05002391// RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002392// {
2393// return lhs = lhs % rhs;
2394// }
John Bauman89401822014-05-06 15:04:28 -04002395
Nicolas Capens96d4e092016-11-18 14:22:38 -05002396 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002397 {
2398 return lhs = lhs & rhs;
2399 }
2400
Nicolas Capens96d4e092016-11-18 14:22:38 -05002401 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002402 {
2403 return lhs = lhs | rhs;
2404 }
2405
Nicolas Capens96d4e092016-11-18 14:22:38 -05002406 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002407 {
2408 return lhs = lhs ^ rhs;
2409 }
2410
Nicolas Capens96d4e092016-11-18 14:22:38 -05002411// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002412// {
2413// return lhs = lhs << rhs;
2414// }
2415
Nicolas Capens96d4e092016-11-18 14:22:38 -05002416// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002417// {
2418// return lhs = lhs >> rhs;
2419// }
2420
John Bauman19bac1e2014-05-06 15:23:49 -04002421// RValue<SByte8> operator+(RValue<SByte8> val)
2422// {
2423// return val;
2424// }
2425
2426// RValue<SByte8> operator-(RValue<SByte8> val)
2427// {
2428// return RValue<SByte8>(Nucleus::createNeg(val.value));
2429// }
2430
2431 RValue<SByte8> operator~(RValue<SByte8> val)
John Bauman89401822014-05-06 15:04:28 -04002432 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002433 return RValue<SByte8>(Nucleus::createNot(val.value));
John Bauman89401822014-05-06 15:04:28 -04002434 }
2435
John Bauman19bac1e2014-05-06 15:23:49 -04002436 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002437 {
2438 return x86::paddsb(x, y);
2439 }
John Bauman66b8ab22014-05-06 15:57:45 -04002440
John Bauman19bac1e2014-05-06 15:23:49 -04002441 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002442 {
2443 return x86::psubsb(x, y);
2444 }
2445
John Bauman19bac1e2014-05-06 15:23:49 -04002446 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002447 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002448 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2449 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04002450 }
John Bauman66b8ab22014-05-06 15:57:45 -04002451
John Bauman19bac1e2014-05-06 15:23:49 -04002452 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002453 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002454 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2455 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2456 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
John Bauman89401822014-05-06 15:04:28 -04002457 }
2458
John Bauman19bac1e2014-05-06 15:23:49 -04002459 RValue<Int> SignMask(RValue<SByte8> x)
John Bauman89401822014-05-06 15:04:28 -04002460 {
2461 return x86::pmovmskb(As<Byte8>(x));
2462 }
2463
John Bauman19bac1e2014-05-06 15:23:49 -04002464 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002465 {
2466 return x86::pcmpgtb(x, y);
2467 }
John Bauman66b8ab22014-05-06 15:57:45 -04002468
John Bauman19bac1e2014-05-06 15:23:49 -04002469 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002470 {
2471 return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
2472 }
2473
John Bauman19bac1e2014-05-06 15:23:49 -04002474 Type *SByte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002475 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002476 return T(Type_v8i8);
John Bauman89401822014-05-06 15:04:28 -04002477 }
2478
John Bauman19bac1e2014-05-06 15:23:49 -04002479 Byte16::Byte16(RValue<Byte16> rhs)
John Bauman89401822014-05-06 15:04:28 -04002480 {
John Bauman66b8ab22014-05-06 15:57:45 -04002481 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002482 }
2483
2484 Byte16::Byte16(const Byte16 &rhs)
2485 {
John Bauman66b8ab22014-05-06 15:57:45 -04002486 Value *value = rhs.loadValue();
2487 storeValue(value);
2488 }
2489
2490 Byte16::Byte16(const Reference<Byte16> &rhs)
2491 {
John Bauman66b8ab22014-05-06 15:57:45 -04002492 Value *value = rhs.loadValue();
2493 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002494 }
2495
Nicolas Capens96d4e092016-11-18 14:22:38 -05002496 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
John Bauman89401822014-05-06 15:04:28 -04002497 {
John Bauman66b8ab22014-05-06 15:57:45 -04002498 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002499
2500 return rhs;
2501 }
2502
Nicolas Capens96d4e092016-11-18 14:22:38 -05002503 RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002504 {
John Bauman66b8ab22014-05-06 15:57:45 -04002505 Value *value = rhs.loadValue();
2506 storeValue(value);
2507
2508 return RValue<Byte16>(value);
2509 }
2510
Nicolas Capens96d4e092016-11-18 14:22:38 -05002511 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04002512 {
2513 Value *value = rhs.loadValue();
2514 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002515
2516 return RValue<Byte16>(value);
2517 }
2518
John Bauman19bac1e2014-05-06 15:23:49 -04002519 Type *Byte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002520 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002521 return T(llvm::VectorType::get(T(Byte::getType()), 16));
John Bauman89401822014-05-06 15:04:28 -04002522 }
2523
John Bauman19bac1e2014-05-06 15:23:49 -04002524 Type *SByte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002525 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002526 return T(llvm::VectorType::get(T(SByte::getType()), 16));
John Bauman89401822014-05-06 15:04:28 -04002527 }
2528
Nicolas Capens16b5f152016-10-13 13:39:01 -04002529 Short2::Short2(RValue<Short4> cast)
2530 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002531 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002532 }
2533
2534 Type *Short2::getType()
2535 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002536 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002537 }
2538
2539 UShort2::UShort2(RValue<UShort4> cast)
2540 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002541 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002542 }
2543
2544 Type *UShort2::getType()
2545 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002546 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002547 }
2548
John Bauman19bac1e2014-05-06 15:23:49 -04002549 Short4::Short4(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04002550 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002551 Value *vector = loadValue();
2552 Value *element = Nucleus::createTrunc(cast.value, Short::getType());
2553 Value *insert = Nucleus::createInsertElement(vector, element, 0);
2554 Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
John Bauman66b8ab22014-05-06 15:57:45 -04002555
2556 storeValue(swizzle);
John Bauman89401822014-05-06 15:04:28 -04002557 }
2558
John Bauman19bac1e2014-05-06 15:23:49 -04002559 Short4::Short4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04002560 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002561 int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
John Bauman89401822014-05-06 15:04:28 -04002562 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
2563
Nicolas Capens01a97962017-07-28 17:30:51 -04002564 Value *packed = Nucleus::createShuffleVector(short8, short8, select);
2565 Value *short4 = As<Short4>(Int2(As<Int4>(packed))).value;
John Bauman89401822014-05-06 15:04:28 -04002566
John Bauman66b8ab22014-05-06 15:57:45 -04002567 storeValue(short4);
John Bauman89401822014-05-06 15:04:28 -04002568 }
2569
John Bauman19bac1e2014-05-06 15:23:49 -04002570// Short4::Short4(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04002571// {
2572// }
2573
John Bauman19bac1e2014-05-06 15:23:49 -04002574 Short4::Short4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04002575 {
John Bauman89401822014-05-06 15:04:28 -04002576 Int4 v4i32 = Int4(cast);
2577 v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
John Bauman66b8ab22014-05-06 15:57:45 -04002578
2579 storeValue(As<Short4>(Int2(v4i32)).value);
John Bauman89401822014-05-06 15:04:28 -04002580 }
2581
John Bauman19bac1e2014-05-06 15:23:49 -04002582 Short4::Short4(short xyzw)
2583 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04002584 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
Nicolas Capens01a97962017-07-28 17:30:51 -04002585 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman19bac1e2014-05-06 15:23:49 -04002586 }
2587
John Bauman89401822014-05-06 15:04:28 -04002588 Short4::Short4(short x, short y, short z, short w)
2589 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04002590 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens01a97962017-07-28 17:30:51 -04002591 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002592 }
2593
John Bauman19bac1e2014-05-06 15:23:49 -04002594 Short4::Short4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002595 {
John Bauman66b8ab22014-05-06 15:57:45 -04002596 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002597 }
2598
2599 Short4::Short4(const Short4 &rhs)
2600 {
John Bauman66b8ab22014-05-06 15:57:45 -04002601 Value *value = rhs.loadValue();
2602 storeValue(value);
2603 }
2604
2605 Short4::Short4(const Reference<Short4> &rhs)
2606 {
John Bauman66b8ab22014-05-06 15:57:45 -04002607 Value *value = rhs.loadValue();
2608 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002609 }
2610
John Bauman19bac1e2014-05-06 15:23:49 -04002611 Short4::Short4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002612 {
John Bauman66b8ab22014-05-06 15:57:45 -04002613 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002614 }
2615
2616 Short4::Short4(const UShort4 &rhs)
2617 {
John Bauman66b8ab22014-05-06 15:57:45 -04002618 storeValue(rhs.loadValue());
2619 }
2620
2621 Short4::Short4(const Reference<UShort4> &rhs)
2622 {
John Bauman66b8ab22014-05-06 15:57:45 -04002623 storeValue(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04002624 }
2625
Nicolas Capens96d4e092016-11-18 14:22:38 -05002626 RValue<Short4> Short4::operator=(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002627 {
John Bauman66b8ab22014-05-06 15:57:45 -04002628 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002629
2630 return rhs;
2631 }
2632
Nicolas Capens96d4e092016-11-18 14:22:38 -05002633 RValue<Short4> Short4::operator=(const Short4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002634 {
John Bauman66b8ab22014-05-06 15:57:45 -04002635 Value *value = rhs.loadValue();
2636 storeValue(value);
2637
2638 return RValue<Short4>(value);
2639 }
2640
Nicolas Capens96d4e092016-11-18 14:22:38 -05002641 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04002642 {
2643 Value *value = rhs.loadValue();
2644 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002645
2646 return RValue<Short4>(value);
2647 }
2648
Nicolas Capens96d4e092016-11-18 14:22:38 -05002649 RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002650 {
John Bauman66b8ab22014-05-06 15:57:45 -04002651 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002652
John Bauman66b8ab22014-05-06 15:57:45 -04002653 return RValue<Short4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04002654 }
2655
Nicolas Capens96d4e092016-11-18 14:22:38 -05002656 RValue<Short4> Short4::operator=(const UShort4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002657 {
John Bauman66b8ab22014-05-06 15:57:45 -04002658 Value *value = rhs.loadValue();
2659 storeValue(value);
2660
2661 return RValue<Short4>(value);
2662 }
2663
Nicolas Capens96d4e092016-11-18 14:22:38 -05002664 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04002665 {
2666 Value *value = rhs.loadValue();
2667 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002668
2669 return RValue<Short4>(value);
2670 }
2671
John Bauman19bac1e2014-05-06 15:23:49 -04002672 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002673 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002674 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002675 }
2676
John Bauman19bac1e2014-05-06 15:23:49 -04002677 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002678 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002679 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002680 }
2681
John Bauman19bac1e2014-05-06 15:23:49 -04002682 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002683 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002684 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002685 }
2686
John Bauman19bac1e2014-05-06 15:23:49 -04002687// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
2688// {
2689// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
2690// }
2691
2692// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
2693// {
2694// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
2695// }
2696
2697 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002698 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002699 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002700 }
2701
John Bauman19bac1e2014-05-06 15:23:49 -04002702 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002703 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002704 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002705 }
2706
John Bauman19bac1e2014-05-06 15:23:49 -04002707 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002708 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002709 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04002710 }
2711
John Bauman19bac1e2014-05-06 15:23:49 -04002712 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002713 {
2714 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2715
2716 return x86::psllw(lhs, rhs);
2717 }
2718
John Bauman19bac1e2014-05-06 15:23:49 -04002719 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002720 {
2721 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
2722
2723 return x86::psraw(lhs, rhs);
2724 }
2725
Nicolas Capens96d4e092016-11-18 14:22:38 -05002726 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002727 {
2728 return lhs = lhs + rhs;
2729 }
2730
Nicolas Capens96d4e092016-11-18 14:22:38 -05002731 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002732 {
2733 return lhs = lhs - rhs;
2734 }
2735
Nicolas Capens96d4e092016-11-18 14:22:38 -05002736 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002737 {
2738 return lhs = lhs * rhs;
2739 }
2740
Nicolas Capens96d4e092016-11-18 14:22:38 -05002741// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002742// {
2743// return lhs = lhs / rhs;
2744// }
John Bauman89401822014-05-06 15:04:28 -04002745
Nicolas Capens96d4e092016-11-18 14:22:38 -05002746// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04002747// {
2748// return lhs = lhs % rhs;
2749// }
John Bauman89401822014-05-06 15:04:28 -04002750
Nicolas Capens96d4e092016-11-18 14:22:38 -05002751 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002752 {
2753 return lhs = lhs & rhs;
2754 }
2755
Nicolas Capens96d4e092016-11-18 14:22:38 -05002756 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002757 {
2758 return lhs = lhs | rhs;
2759 }
2760
Nicolas Capens96d4e092016-11-18 14:22:38 -05002761 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002762 {
2763 return lhs = lhs ^ rhs;
2764 }
2765
Nicolas Capens96d4e092016-11-18 14:22:38 -05002766 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002767 {
2768 return lhs = lhs << rhs;
2769 }
2770
Nicolas Capens96d4e092016-11-18 14:22:38 -05002771 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002772 {
2773 return lhs = lhs >> rhs;
2774 }
2775
John Bauman19bac1e2014-05-06 15:23:49 -04002776// RValue<Short4> operator+(RValue<Short4> val)
2777// {
2778// return val;
2779// }
2780
2781 RValue<Short4> operator-(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04002782 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002783 return RValue<Short4>(Nucleus::createNeg(val.value));
John Bauman89401822014-05-06 15:04:28 -04002784 }
2785
John Bauman19bac1e2014-05-06 15:23:49 -04002786 RValue<Short4> operator~(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04002787 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002788 return RValue<Short4>(Nucleus::createNot(val.value));
John Bauman89401822014-05-06 15:04:28 -04002789 }
2790
John Bauman19bac1e2014-05-06 15:23:49 -04002791 RValue<Short4> RoundShort4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04002792 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002793 RValue<Int4> int4 = RoundInt(cast);
Nicolas Capens33438a62017-09-27 11:47:35 -04002794 return As<Short4>(PackSigned(int4, int4));
John Bauman89401822014-05-06 15:04:28 -04002795 }
2796
John Bauman19bac1e2014-05-06 15:23:49 -04002797 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002798 {
2799 return x86::pmaxsw(x, y);
2800 }
2801
John Bauman19bac1e2014-05-06 15:23:49 -04002802 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002803 {
2804 return x86::pminsw(x, y);
2805 }
2806
John Bauman19bac1e2014-05-06 15:23:49 -04002807 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002808 {
2809 return x86::paddsw(x, y);
2810 }
2811
John Bauman19bac1e2014-05-06 15:23:49 -04002812 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002813 {
2814 return x86::psubsw(x, y);
2815 }
2816
John Bauman19bac1e2014-05-06 15:23:49 -04002817 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002818 {
2819 return x86::pmulhw(x, y);
2820 }
2821
John Bauman19bac1e2014-05-06 15:23:49 -04002822 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002823 {
2824 return x86::pmaddwd(x, y);
2825 }
2826
Nicolas Capens33438a62017-09-27 11:47:35 -04002827 RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002828 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002829 auto result = x86::packsswb(x, y);
2830
2831 return As<SByte8>(Swizzle(As<Int4>(result), 0x88));
John Bauman89401822014-05-06 15:04:28 -04002832 }
2833
Nicolas Capens33438a62017-09-27 11:47:35 -04002834 RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y)
2835 {
2836 auto result = x86::packuswb(x, y);
2837
2838 return As<Byte8>(Swizzle(As<Int4>(result), 0x88));
2839 }
2840
John Bauman19bac1e2014-05-06 15:23:49 -04002841 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002842 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002843 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
2844 return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04002845 }
2846
John Bauman19bac1e2014-05-06 15:23:49 -04002847 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002848 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002849 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
2850 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2851 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
John Bauman89401822014-05-06 15:04:28 -04002852 }
2853
John Bauman19bac1e2014-05-06 15:23:49 -04002854 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04002855 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002856 // Real type is v8i16
2857 int shuffle[8] =
John Bauman19bac1e2014-05-06 15:23:49 -04002858 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002859 (select >> 0) & 0x03,
2860 (select >> 2) & 0x03,
2861 (select >> 4) & 0x03,
2862 (select >> 6) & 0x03,
2863 (select >> 0) & 0x03,
2864 (select >> 2) & 0x03,
2865 (select >> 4) & 0x03,
2866 (select >> 6) & 0x03,
2867 };
2868
2869 return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04002870 }
2871
John Bauman19bac1e2014-05-06 15:23:49 -04002872 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
John Bauman89401822014-05-06 15:04:28 -04002873 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002874 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
John Bauman89401822014-05-06 15:04:28 -04002875 }
2876
John Bauman19bac1e2014-05-06 15:23:49 -04002877 RValue<Short> Extract(RValue<Short4> val, int i)
John Bauman89401822014-05-06 15:04:28 -04002878 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002879 return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
John Bauman89401822014-05-06 15:04:28 -04002880 }
2881
John Bauman19bac1e2014-05-06 15:23:49 -04002882 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002883 {
2884 return x86::pcmpgtw(x, y);
2885 }
2886
John Bauman19bac1e2014-05-06 15:23:49 -04002887 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04002888 {
2889 return x86::pcmpeqw(x, y);
2890 }
2891
John Bauman19bac1e2014-05-06 15:23:49 -04002892 Type *Short4::getType()
John Bauman89401822014-05-06 15:04:28 -04002893 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04002894 return T(Type_v4i16);
John Bauman89401822014-05-06 15:04:28 -04002895 }
2896
John Bauman19bac1e2014-05-06 15:23:49 -04002897 UShort4::UShort4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04002898 {
John Bauman89401822014-05-06 15:04:28 -04002899 *this = Short4(cast);
2900 }
2901
John Bauman19bac1e2014-05-06 15:23:49 -04002902 UShort4::UShort4(RValue<Float4> cast, bool saturate)
John Bauman89401822014-05-06 15:04:28 -04002903 {
John Bauman89401822014-05-06 15:04:28 -04002904 if(saturate)
2905 {
2906 if(CPUID::supportsSSE4_1())
2907 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002908 Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
Nicolas Capens33438a62017-09-27 11:47:35 -04002909 *this = As<Short4>(PackUnsigned(int4, int4));
John Bauman89401822014-05-06 15:04:28 -04002910 }
2911 else
2912 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002913 *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
John Bauman89401822014-05-06 15:04:28 -04002914 }
2915 }
2916 else
2917 {
Nicolas Capens01a97962017-07-28 17:30:51 -04002918 *this = Short4(Int4(cast));
John Bauman89401822014-05-06 15:04:28 -04002919 }
2920 }
2921
Alexis Hetu90c7ad62016-06-27 11:50:40 -04002922 UShort4::UShort4(unsigned short xyzw)
2923 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04002924 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
Nicolas Capens01a97962017-07-28 17:30:51 -04002925 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Alexis Hetu90c7ad62016-06-27 11:50:40 -04002926 }
2927
John Bauman89401822014-05-06 15:04:28 -04002928 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
2929 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04002930 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens01a97962017-07-28 17:30:51 -04002931 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002932 }
2933
John Bauman19bac1e2014-05-06 15:23:49 -04002934 UShort4::UShort4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002935 {
John Bauman66b8ab22014-05-06 15:57:45 -04002936 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002937 }
2938
2939 UShort4::UShort4(const UShort4 &rhs)
2940 {
John Bauman66b8ab22014-05-06 15:57:45 -04002941 Value *value = rhs.loadValue();
2942 storeValue(value);
2943 }
2944
2945 UShort4::UShort4(const Reference<UShort4> &rhs)
2946 {
John Bauman66b8ab22014-05-06 15:57:45 -04002947 Value *value = rhs.loadValue();
2948 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002949 }
2950
John Bauman19bac1e2014-05-06 15:23:49 -04002951 UShort4::UShort4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002952 {
John Bauman66b8ab22014-05-06 15:57:45 -04002953 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002954 }
2955
2956 UShort4::UShort4(const Short4 &rhs)
2957 {
John Bauman66b8ab22014-05-06 15:57:45 -04002958 Value *value = rhs.loadValue();
2959 storeValue(value);
2960 }
2961
2962 UShort4::UShort4(const Reference<Short4> &rhs)
2963 {
John Bauman66b8ab22014-05-06 15:57:45 -04002964 Value *value = rhs.loadValue();
2965 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002966 }
2967
Nicolas Capens96d4e092016-11-18 14:22:38 -05002968 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002969 {
John Bauman66b8ab22014-05-06 15:57:45 -04002970 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002971
2972 return rhs;
2973 }
2974
Nicolas Capens96d4e092016-11-18 14:22:38 -05002975 RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002976 {
John Bauman66b8ab22014-05-06 15:57:45 -04002977 Value *value = rhs.loadValue();
2978 storeValue(value);
2979
2980 return RValue<UShort4>(value);
2981 }
2982
Nicolas Capens96d4e092016-11-18 14:22:38 -05002983 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04002984 {
2985 Value *value = rhs.loadValue();
2986 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002987
2988 return RValue<UShort4>(value);
2989 }
2990
Nicolas Capens96d4e092016-11-18 14:22:38 -05002991 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002992 {
John Bauman66b8ab22014-05-06 15:57:45 -04002993 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002994
John Bauman66b8ab22014-05-06 15:57:45 -04002995 return RValue<UShort4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04002996 }
2997
Nicolas Capens96d4e092016-11-18 14:22:38 -05002998 RValue<UShort4> UShort4::operator=(const Short4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04002999 {
John Bauman66b8ab22014-05-06 15:57:45 -04003000 Value *value = rhs.loadValue();
3001 storeValue(value);
3002
3003 return RValue<UShort4>(value);
3004 }
3005
Nicolas Capens96d4e092016-11-18 14:22:38 -05003006 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04003007 {
3008 Value *value = rhs.loadValue();
3009 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003010
3011 return RValue<UShort4>(value);
3012 }
3013
John Bauman19bac1e2014-05-06 15:23:49 -04003014 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003015 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003016 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04003017 }
3018
John Bauman19bac1e2014-05-06 15:23:49 -04003019 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003020 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003021 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04003022 }
3023
John Bauman19bac1e2014-05-06 15:23:49 -04003024 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003025 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003026 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04003027 }
3028
Nicolas Capens16b5f152016-10-13 13:39:01 -04003029 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3030 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003031 return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003032 }
3033
3034 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
3035 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003036 return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003037 }
3038
3039 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3040 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003041 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003042 }
3043
John Bauman19bac1e2014-05-06 15:23:49 -04003044 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003045 {
3046 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3047
3048 return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
3049 }
3050
John Bauman19bac1e2014-05-06 15:23:49 -04003051 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003052 {
3053 // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
3054
3055 return x86::psrlw(lhs, rhs);
3056 }
3057
Nicolas Capens96d4e092016-11-18 14:22:38 -05003058 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003059 {
3060 return lhs = lhs << rhs;
3061 }
3062
Nicolas Capens96d4e092016-11-18 14:22:38 -05003063 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003064 {
3065 return lhs = lhs >> rhs;
3066 }
3067
John Bauman19bac1e2014-05-06 15:23:49 -04003068 RValue<UShort4> operator~(RValue<UShort4> val)
John Bauman89401822014-05-06 15:04:28 -04003069 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003070 return RValue<UShort4>(Nucleus::createNot(val.value));
John Bauman89401822014-05-06 15:04:28 -04003071 }
3072
John Bauman19bac1e2014-05-06 15:23:49 -04003073 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003074 {
John Bauman66b8ab22014-05-06 15:57:45 -04003075 return RValue<UShort4>(Max(As<Short4>(x) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u), As<Short4>(y) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u)) + Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u));
John Bauman89401822014-05-06 15:04:28 -04003076 }
3077
John Bauman19bac1e2014-05-06 15:23:49 -04003078 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003079 {
John Bauman66b8ab22014-05-06 15:57:45 -04003080 return RValue<UShort4>(Min(As<Short4>(x) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u), As<Short4>(y) - Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u)) + Short4(0x8000u, 0x8000u, 0x8000u, 0x8000u));
John Bauman89401822014-05-06 15:04:28 -04003081 }
3082
John Bauman19bac1e2014-05-06 15:23:49 -04003083 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003084 {
3085 return x86::paddusw(x, y);
3086 }
3087
John Bauman19bac1e2014-05-06 15:23:49 -04003088 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003089 {
3090 return x86::psubusw(x, y);
3091 }
3092
John Bauman19bac1e2014-05-06 15:23:49 -04003093 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003094 {
3095 return x86::pmulhuw(x, y);
3096 }
3097
John Bauman19bac1e2014-05-06 15:23:49 -04003098 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003099 {
3100 return x86::pavgw(x, y);
3101 }
3102
John Bauman19bac1e2014-05-06 15:23:49 -04003103 Type *UShort4::getType()
John Bauman89401822014-05-06 15:04:28 -04003104 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04003105 return T(Type_v4i16);
John Bauman89401822014-05-06 15:04:28 -04003106 }
3107
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003108 Short8::Short8(short c)
3109 {
3110 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3111 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3112 }
3113
John Bauman89401822014-05-06 15:04:28 -04003114 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3115 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04003116 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3117 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04003118 }
3119
John Bauman19bac1e2014-05-06 15:23:49 -04003120 Short8::Short8(RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003121 {
John Bauman66b8ab22014-05-06 15:57:45 -04003122 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003123 }
3124
Nicolas Capensef8cd662016-06-30 15:34:40 -04003125 Short8::Short8(const Reference<Short8> &rhs)
3126 {
Nicolas Capensef8cd662016-06-30 15:34:40 -04003127 Value *value = rhs.loadValue();
3128 storeValue(value);
3129 }
3130
Nicolas Capens62abb552016-01-05 12:03:47 -05003131 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3132 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003133 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3134 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
Nicolas Capens62abb552016-01-05 12:03:47 -05003135
Nicolas Capens01a97962017-07-28 17:30:51 -04003136 storeValue(packed);
Nicolas Capens62abb552016-01-05 12:03:47 -05003137 }
3138
John Bauman19bac1e2014-05-06 15:23:49 -04003139 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003140 {
3141 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3142 }
3143
John Bauman19bac1e2014-05-06 15:23:49 -04003144 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003145 {
3146 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3147 }
3148
John Bauman19bac1e2014-05-06 15:23:49 -04003149 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003150 {
3151 return x86::psllw(lhs, rhs); // FIXME: Fallback required
3152 }
3153
John Bauman19bac1e2014-05-06 15:23:49 -04003154 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003155 {
3156 return x86::psraw(lhs, rhs); // FIXME: Fallback required
3157 }
3158
John Bauman19bac1e2014-05-06 15:23:49 -04003159 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003160 {
3161 return x86::pmaddwd(x, y); // FIXME: Fallback required
3162 }
3163
Alexis Hetu0f448072016-03-18 10:56:08 -04003164 RValue<Int4> Abs(RValue<Int4> x)
3165 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003166 auto negative = x >> 31;
3167 return (x ^ negative) - negative;
Alexis Hetu0f448072016-03-18 10:56:08 -04003168 }
3169
John Bauman19bac1e2014-05-06 15:23:49 -04003170 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003171 {
3172 return x86::pmulhw(x, y); // FIXME: Fallback required
3173 }
3174
John Bauman19bac1e2014-05-06 15:23:49 -04003175 Type *Short8::getType()
John Bauman89401822014-05-06 15:04:28 -04003176 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04003177 return T(llvm::VectorType::get(T(Short::getType()), 8));
John Bauman89401822014-05-06 15:04:28 -04003178 }
3179
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003180 UShort8::UShort8(unsigned short c)
3181 {
3182 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3183 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3184 }
3185
John Bauman89401822014-05-06 15:04:28 -04003186 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)
3187 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04003188 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3189 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04003190 }
3191
John Bauman19bac1e2014-05-06 15:23:49 -04003192 UShort8::UShort8(RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003193 {
John Bauman66b8ab22014-05-06 15:57:45 -04003194 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003195 }
3196
Nicolas Capensef8cd662016-06-30 15:34:40 -04003197 UShort8::UShort8(const Reference<UShort8> &rhs)
3198 {
Nicolas Capensef8cd662016-06-30 15:34:40 -04003199 Value *value = rhs.loadValue();
3200 storeValue(value);
3201 }
3202
Nicolas Capens62abb552016-01-05 12:03:47 -05003203 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3204 {
Nicolas Capens01a97962017-07-28 17:30:51 -04003205 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3206 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
Nicolas Capens62abb552016-01-05 12:03:47 -05003207
Nicolas Capens01a97962017-07-28 17:30:51 -04003208 storeValue(packed);
Nicolas Capens62abb552016-01-05 12:03:47 -05003209 }
3210
Nicolas Capens96d4e092016-11-18 14:22:38 -05003211 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003212 {
John Bauman66b8ab22014-05-06 15:57:45 -04003213 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003214
3215 return rhs;
3216 }
3217
Nicolas Capens96d4e092016-11-18 14:22:38 -05003218 RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
John Bauman89401822014-05-06 15:04:28 -04003219 {
John Bauman66b8ab22014-05-06 15:57:45 -04003220 Value *value = rhs.loadValue();
3221 storeValue(value);
3222
3223 return RValue<UShort8>(value);
3224 }
3225
Nicolas Capens96d4e092016-11-18 14:22:38 -05003226 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04003227 {
3228 Value *value = rhs.loadValue();
3229 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003230
3231 return RValue<UShort8>(value);
3232 }
3233
John Bauman19bac1e2014-05-06 15:23:49 -04003234 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003235 {
3236 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3237 }
3238
John Bauman19bac1e2014-05-06 15:23:49 -04003239 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003240 {
3241 return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required
3242 }
3243
John Bauman19bac1e2014-05-06 15:23:49 -04003244 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003245 {
3246 return x86::psrlw(lhs, rhs); // FIXME: Fallback required
3247 }
3248
John Bauman19bac1e2014-05-06 15:23:49 -04003249 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003250 {
3251 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3252 }
3253
John Bauman19bac1e2014-05-06 15:23:49 -04003254 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003255 {
3256 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3257 }
3258
Nicolas Capens96d4e092016-11-18 14:22:38 -05003259 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003260 {
3261 return lhs = lhs + rhs;
3262 }
3263
John Bauman19bac1e2014-05-06 15:23:49 -04003264 RValue<UShort8> operator~(RValue<UShort8> val)
John Bauman89401822014-05-06 15:04:28 -04003265 {
3266 return RValue<UShort8>(Nucleus::createNot(val.value));
3267 }
3268
John Bauman19bac1e2014-05-06 15:23:49 -04003269 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
John Bauman89401822014-05-06 15:04:28 -04003270 {
Nicolas Capense89cd582016-09-30 14:23:47 -04003271 int pshufb[16] =
3272 {
3273 select0 + 0,
3274 select0 + 1,
3275 select1 + 0,
3276 select1 + 1,
3277 select2 + 0,
3278 select2 + 1,
3279 select3 + 0,
3280 select3 + 1,
3281 select4 + 0,
3282 select4 + 1,
3283 select5 + 0,
3284 select5 + 1,
3285 select6 + 0,
3286 select6 + 1,
3287 select7 + 0,
3288 select7 + 1,
3289 };
John Bauman89401822014-05-06 15:04:28 -04003290
3291 Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
Nicolas Capense89cd582016-09-30 14:23:47 -04003292 Value *shuffle = Nucleus::createShuffleVector(byte16, byte16, pshufb);
John Bauman89401822014-05-06 15:04:28 -04003293 Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3294
3295 return RValue<UShort8>(short8);
3296 }
3297
John Bauman19bac1e2014-05-06 15:23:49 -04003298 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04003299 {
3300 return x86::pmulhuw(x, y); // FIXME: Fallback required
3301 }
3302
John Bauman19bac1e2014-05-06 15:23:49 -04003303 Type *UShort8::getType()
John Bauman89401822014-05-06 15:04:28 -04003304 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04003305 return T(llvm::VectorType::get(T(UShort::getType()), 8));
John Bauman89401822014-05-06 15:04:28 -04003306 }
3307
Nicolas Capens81f18302016-01-14 09:32:35 -05003308 Int::Int(Argument<Int> argument)
John Bauman89401822014-05-06 15:04:28 -04003309 {
Nicolas Capens81f18302016-01-14 09:32:35 -05003310 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -04003311 }
3312
John Bauman19bac1e2014-05-06 15:23:49 -04003313 Int::Int(RValue<Byte> cast)
John Bauman89401822014-05-06 15:04:28 -04003314 {
John Bauman89401822014-05-06 15:04:28 -04003315 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3316
John Bauman66b8ab22014-05-06 15:57:45 -04003317 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003318 }
3319
John Bauman19bac1e2014-05-06 15:23:49 -04003320 Int::Int(RValue<SByte> cast)
John Bauman89401822014-05-06 15:04:28 -04003321 {
John Bauman89401822014-05-06 15:04:28 -04003322 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3323
John Bauman66b8ab22014-05-06 15:57:45 -04003324 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003325 }
3326
John Bauman19bac1e2014-05-06 15:23:49 -04003327 Int::Int(RValue<Short> cast)
John Bauman89401822014-05-06 15:04:28 -04003328 {
John Bauman89401822014-05-06 15:04:28 -04003329 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3330
John Bauman66b8ab22014-05-06 15:57:45 -04003331 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003332 }
3333
John Bauman19bac1e2014-05-06 15:23:49 -04003334 Int::Int(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04003335 {
John Bauman89401822014-05-06 15:04:28 -04003336 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3337
John Bauman66b8ab22014-05-06 15:57:45 -04003338 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003339 }
3340
John Bauman19bac1e2014-05-06 15:23:49 -04003341 Int::Int(RValue<Int2> cast)
John Bauman89401822014-05-06 15:04:28 -04003342 {
John Bauman89401822014-05-06 15:04:28 -04003343 *this = Extract(cast, 0);
3344 }
3345
John Bauman19bac1e2014-05-06 15:23:49 -04003346 Int::Int(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04003347 {
John Bauman89401822014-05-06 15:04:28 -04003348 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3349
John Bauman66b8ab22014-05-06 15:57:45 -04003350 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003351 }
3352
John Bauman19bac1e2014-05-06 15:23:49 -04003353 Int::Int(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04003354 {
John Bauman89401822014-05-06 15:04:28 -04003355 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3356
John Bauman66b8ab22014-05-06 15:57:45 -04003357 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003358 }
3359
John Bauman89401822014-05-06 15:04:28 -04003360 Int::Int(int x)
3361 {
John Bauman66b8ab22014-05-06 15:57:45 -04003362 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04003363 }
3364
John Bauman19bac1e2014-05-06 15:23:49 -04003365 Int::Int(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003366 {
John Bauman66b8ab22014-05-06 15:57:45 -04003367 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003368 }
3369
John Bauman19bac1e2014-05-06 15:23:49 -04003370 Int::Int(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003371 {
John Bauman66b8ab22014-05-06 15:57:45 -04003372 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003373 }
3374
3375 Int::Int(const Int &rhs)
3376 {
John Bauman66b8ab22014-05-06 15:57:45 -04003377 Value *value = rhs.loadValue();
3378 storeValue(value);
3379 }
John Bauman89401822014-05-06 15:04:28 -04003380
John Bauman66b8ab22014-05-06 15:57:45 -04003381 Int::Int(const Reference<Int> &rhs)
3382 {
3383 Value *value = rhs.loadValue();
3384 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003385 }
3386
3387 Int::Int(const UInt &rhs)
3388 {
John Bauman66b8ab22014-05-06 15:57:45 -04003389 Value *value = rhs.loadValue();
3390 storeValue(value);
3391 }
John Bauman89401822014-05-06 15:04:28 -04003392
John Bauman66b8ab22014-05-06 15:57:45 -04003393 Int::Int(const Reference<UInt> &rhs)
3394 {
3395 Value *value = rhs.loadValue();
3396 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003397 }
3398
Nicolas Capens96d4e092016-11-18 14:22:38 -05003399 RValue<Int> Int::operator=(int rhs)
John Bauman89401822014-05-06 15:04:28 -04003400 {
John Bauman66b8ab22014-05-06 15:57:45 -04003401 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04003402 }
3403
Nicolas Capens96d4e092016-11-18 14:22:38 -05003404 RValue<Int> Int::operator=(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003405 {
John Bauman66b8ab22014-05-06 15:57:45 -04003406 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003407
3408 return rhs;
3409 }
3410
Nicolas Capens96d4e092016-11-18 14:22:38 -05003411 RValue<Int> Int::operator=(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003412 {
John Bauman66b8ab22014-05-06 15:57:45 -04003413 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003414
John Bauman66b8ab22014-05-06 15:57:45 -04003415 return RValue<Int>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003416 }
3417
Nicolas Capens96d4e092016-11-18 14:22:38 -05003418 RValue<Int> Int::operator=(const Int &rhs)
John Bauman89401822014-05-06 15:04:28 -04003419 {
John Bauman66b8ab22014-05-06 15:57:45 -04003420 Value *value = rhs.loadValue();
3421 storeValue(value);
3422
3423 return RValue<Int>(value);
3424 }
3425
Nicolas Capens96d4e092016-11-18 14:22:38 -05003426 RValue<Int> Int::operator=(const Reference<Int> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04003427 {
3428 Value *value = rhs.loadValue();
3429 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003430
3431 return RValue<Int>(value);
3432 }
3433
Nicolas Capens96d4e092016-11-18 14:22:38 -05003434 RValue<Int> Int::operator=(const UInt &rhs)
John Bauman89401822014-05-06 15:04:28 -04003435 {
John Bauman66b8ab22014-05-06 15:57:45 -04003436 Value *value = rhs.loadValue();
3437 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003438
3439 return RValue<Int>(value);
3440 }
3441
Nicolas Capens96d4e092016-11-18 14:22:38 -05003442 RValue<Int> Int::operator=(const Reference<UInt> &rhs)
John Bauman89401822014-05-06 15:04:28 -04003443 {
John Bauman66b8ab22014-05-06 15:57:45 -04003444 Value *value = rhs.loadValue();
3445 storeValue(value);
3446
3447 return RValue<Int>(value);
John Bauman89401822014-05-06 15:04:28 -04003448 }
3449
John Bauman19bac1e2014-05-06 15:23:49 -04003450 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003451 {
3452 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3453 }
3454
John Bauman19bac1e2014-05-06 15:23:49 -04003455 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003456 {
3457 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3458 }
3459
John Bauman19bac1e2014-05-06 15:23:49 -04003460 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003461 {
3462 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3463 }
3464
John Bauman19bac1e2014-05-06 15:23:49 -04003465 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003466 {
3467 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3468 }
3469
John Bauman19bac1e2014-05-06 15:23:49 -04003470 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003471 {
3472 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3473 }
3474
John Bauman19bac1e2014-05-06 15:23:49 -04003475 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003476 {
3477 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3478 }
3479
John Bauman19bac1e2014-05-06 15:23:49 -04003480 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003481 {
3482 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3483 }
3484
John Bauman19bac1e2014-05-06 15:23:49 -04003485 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003486 {
3487 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
3488 }
3489
John Bauman19bac1e2014-05-06 15:23:49 -04003490 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003491 {
3492 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
3493 }
3494
John Bauman19bac1e2014-05-06 15:23:49 -04003495 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003496 {
3497 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
3498 }
3499
Nicolas Capens96d4e092016-11-18 14:22:38 -05003500 RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003501 {
3502 return lhs = lhs + rhs;
3503 }
3504
Nicolas Capens96d4e092016-11-18 14:22:38 -05003505 RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003506 {
3507 return lhs = lhs - rhs;
3508 }
3509
Nicolas Capens96d4e092016-11-18 14:22:38 -05003510 RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003511 {
3512 return lhs = lhs * rhs;
3513 }
3514
Nicolas Capens96d4e092016-11-18 14:22:38 -05003515 RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003516 {
3517 return lhs = lhs / rhs;
3518 }
3519
Nicolas Capens96d4e092016-11-18 14:22:38 -05003520 RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003521 {
3522 return lhs = lhs % rhs;
3523 }
3524
Nicolas Capens96d4e092016-11-18 14:22:38 -05003525 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003526 {
3527 return lhs = lhs & rhs;
3528 }
3529
Nicolas Capens96d4e092016-11-18 14:22:38 -05003530 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003531 {
3532 return lhs = lhs | rhs;
3533 }
3534
Nicolas Capens96d4e092016-11-18 14:22:38 -05003535 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003536 {
3537 return lhs = lhs ^ rhs;
3538 }
3539
Nicolas Capens96d4e092016-11-18 14:22:38 -05003540 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003541 {
3542 return lhs = lhs << rhs;
3543 }
3544
Nicolas Capens96d4e092016-11-18 14:22:38 -05003545 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003546 {
3547 return lhs = lhs >> rhs;
3548 }
3549
John Bauman19bac1e2014-05-06 15:23:49 -04003550 RValue<Int> operator+(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003551 {
3552 return val;
3553 }
3554
John Bauman19bac1e2014-05-06 15:23:49 -04003555 RValue<Int> operator-(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003556 {
3557 return RValue<Int>(Nucleus::createNeg(val.value));
3558 }
3559
John Bauman19bac1e2014-05-06 15:23:49 -04003560 RValue<Int> operator~(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003561 {
3562 return RValue<Int>(Nucleus::createNot(val.value));
3563 }
3564
Nicolas Capens96d4e092016-11-18 14:22:38 -05003565 RValue<Int> operator++(Int &val, int) // Post-increment
John Bauman89401822014-05-06 15:04:28 -04003566 {
3567 RValue<Int> res = val;
3568
Nicolas Capens19336542016-09-26 10:32:29 -04003569 Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04003570 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003571
3572 return res;
3573 }
3574
Nicolas Capens96d4e092016-11-18 14:22:38 -05003575 const Int &operator++(Int &val) // Pre-increment
John Bauman89401822014-05-06 15:04:28 -04003576 {
Nicolas Capens19336542016-09-26 10:32:29 -04003577 Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04003578 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003579
3580 return val;
3581 }
3582
Nicolas Capens96d4e092016-11-18 14:22:38 -05003583 RValue<Int> operator--(Int &val, int) // Post-decrement
John Bauman89401822014-05-06 15:04:28 -04003584 {
3585 RValue<Int> res = val;
3586
Nicolas Capens19336542016-09-26 10:32:29 -04003587 Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04003588 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003589
3590 return res;
3591 }
3592
Nicolas Capens96d4e092016-11-18 14:22:38 -05003593 const Int &operator--(Int &val) // Pre-decrement
John Bauman89401822014-05-06 15:04:28 -04003594 {
Nicolas Capens19336542016-09-26 10:32:29 -04003595 Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04003596 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003597
3598 return val;
3599 }
3600
John Bauman19bac1e2014-05-06 15:23:49 -04003601 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003602 {
3603 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
3604 }
3605
John Bauman19bac1e2014-05-06 15:23:49 -04003606 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003607 {
3608 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
3609 }
3610
John Bauman19bac1e2014-05-06 15:23:49 -04003611 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003612 {
3613 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
3614 }
3615
John Bauman19bac1e2014-05-06 15:23:49 -04003616 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003617 {
3618 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
3619 }
3620
John Bauman19bac1e2014-05-06 15:23:49 -04003621 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003622 {
3623 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
3624 }
3625
John Bauman19bac1e2014-05-06 15:23:49 -04003626 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003627 {
3628 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
3629 }
3630
John Bauman19bac1e2014-05-06 15:23:49 -04003631 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
3632 {
3633 return IfThenElse(x > y, x, y);
3634 }
3635
3636 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
3637 {
3638 return IfThenElse(x < y, x, y);
3639 }
3640
3641 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
3642 {
3643 return Min(Max(x, min), max);
3644 }
3645
3646 RValue<Int> RoundInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04003647 {
3648 return x86::cvtss2si(cast);
3649
John Bauman66b8ab22014-05-06 15:57:45 -04003650 // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04003651 }
3652
John Bauman19bac1e2014-05-06 15:23:49 -04003653 Type *Int::getType()
John Bauman89401822014-05-06 15:04:28 -04003654 {
Nicolas Capensac230122016-09-20 14:30:06 -04003655 return T(llvm::Type::getInt32Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04003656 }
3657
John Bauman19bac1e2014-05-06 15:23:49 -04003658 Long::Long(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04003659 {
John Bauman89401822014-05-06 15:04:28 -04003660 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
3661
John Bauman66b8ab22014-05-06 15:57:45 -04003662 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003663 }
3664
John Bauman19bac1e2014-05-06 15:23:49 -04003665 Long::Long(RValue<UInt> cast)
John Bauman89401822014-05-06 15:04:28 -04003666 {
John Bauman89401822014-05-06 15:04:28 -04003667 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
3668
John Bauman66b8ab22014-05-06 15:57:45 -04003669 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003670 }
3671
John Bauman19bac1e2014-05-06 15:23:49 -04003672 Long::Long(RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04003673 {
John Bauman66b8ab22014-05-06 15:57:45 -04003674 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003675 }
3676
Nicolas Capens96d4e092016-11-18 14:22:38 -05003677 RValue<Long> Long::operator=(int64_t rhs)
John Bauman89401822014-05-06 15:04:28 -04003678 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04003679 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
John Bauman89401822014-05-06 15:04:28 -04003680 }
3681
Nicolas Capens96d4e092016-11-18 14:22:38 -05003682 RValue<Long> Long::operator=(RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04003683 {
John Bauman66b8ab22014-05-06 15:57:45 -04003684 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003685
3686 return rhs;
3687 }
3688
Nicolas Capens96d4e092016-11-18 14:22:38 -05003689 RValue<Long> Long::operator=(const Long &rhs)
John Bauman89401822014-05-06 15:04:28 -04003690 {
John Bauman66b8ab22014-05-06 15:57:45 -04003691 Value *value = rhs.loadValue();
3692 storeValue(value);
3693
3694 return RValue<Long>(value);
3695 }
3696
Nicolas Capens96d4e092016-11-18 14:22:38 -05003697 RValue<Long> Long::operator=(const Reference<Long> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04003698 {
3699 Value *value = rhs.loadValue();
3700 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003701
3702 return RValue<Long>(value);
3703 }
3704
John Bauman19bac1e2014-05-06 15:23:49 -04003705 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04003706 {
3707 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
3708 }
3709
John Bauman19bac1e2014-05-06 15:23:49 -04003710 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04003711 {
3712 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
3713 }
3714
Nicolas Capens96d4e092016-11-18 14:22:38 -05003715 RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04003716 {
3717 return lhs = lhs + rhs;
3718 }
3719
Nicolas Capens96d4e092016-11-18 14:22:38 -05003720 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04003721 {
3722 return lhs = lhs - rhs;
3723 }
3724
John Bauman66b8ab22014-05-06 15:57:45 -04003725 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
John Bauman89401822014-05-06 15:04:28 -04003726 {
John Bauman19bac1e2014-05-06 15:23:49 -04003727 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
John Bauman89401822014-05-06 15:04:28 -04003728 }
3729
John Bauman19bac1e2014-05-06 15:23:49 -04003730 Type *Long::getType()
John Bauman89401822014-05-06 15:04:28 -04003731 {
Nicolas Capensac230122016-09-20 14:30:06 -04003732 return T(llvm::Type::getInt64Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04003733 }
3734
Nicolas Capens81f18302016-01-14 09:32:35 -05003735 UInt::UInt(Argument<UInt> argument)
John Bauman89401822014-05-06 15:04:28 -04003736 {
Nicolas Capens81f18302016-01-14 09:32:35 -05003737 storeValue(argument.value);
John Bauman89401822014-05-06 15:04:28 -04003738 }
3739
John Bauman19bac1e2014-05-06 15:23:49 -04003740 UInt::UInt(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04003741 {
John Bauman89401822014-05-06 15:04:28 -04003742 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
3743
John Bauman66b8ab22014-05-06 15:57:45 -04003744 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003745 }
3746
John Bauman19bac1e2014-05-06 15:23:49 -04003747 UInt::UInt(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04003748 {
John Bauman89401822014-05-06 15:04:28 -04003749 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
3750
John Bauman66b8ab22014-05-06 15:57:45 -04003751 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003752 }
3753
John Bauman19bac1e2014-05-06 15:23:49 -04003754 UInt::UInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04003755 {
Alexis Hetu764d1422016-09-28 08:44:22 -04003756 // Note: createFPToUI is broken, must perform conversion using createFPtoSI
3757 // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType());
John Bauman89401822014-05-06 15:04:28 -04003758
Alexis Hetu764d1422016-09-28 08:44:22 -04003759 // Smallest positive value representable in UInt, but not in Int
3760 const unsigned int ustart = 0x80000000u;
3761 const float ustartf = float(ustart);
3762
3763 // If the value is negative, store 0, otherwise store the result of the conversion
3764 storeValue((~(As<Int>(cast) >> 31) &
3765 // Check if the value can be represented as an Int
3766 IfThenElse(cast >= ustartf,
3767 // If the value is too large, subtract ustart and re-add it after conversion.
3768 As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
3769 // Otherwise, just convert normally
3770 Int(cast))).value);
John Bauman89401822014-05-06 15:04:28 -04003771 }
3772
John Bauman89401822014-05-06 15:04:28 -04003773 UInt::UInt(int x)
3774 {
John Bauman66b8ab22014-05-06 15:57:45 -04003775 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04003776 }
3777
3778 UInt::UInt(unsigned int x)
3779 {
John Bauman66b8ab22014-05-06 15:57:45 -04003780 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04003781 }
3782
John Bauman19bac1e2014-05-06 15:23:49 -04003783 UInt::UInt(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003784 {
John Bauman66b8ab22014-05-06 15:57:45 -04003785 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003786 }
3787
John Bauman19bac1e2014-05-06 15:23:49 -04003788 UInt::UInt(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003789 {
John Bauman66b8ab22014-05-06 15:57:45 -04003790 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003791 }
3792
3793 UInt::UInt(const UInt &rhs)
3794 {
John Bauman66b8ab22014-05-06 15:57:45 -04003795 Value *value = rhs.loadValue();
3796 storeValue(value);
3797 }
John Bauman89401822014-05-06 15:04:28 -04003798
John Bauman66b8ab22014-05-06 15:57:45 -04003799 UInt::UInt(const Reference<UInt> &rhs)
3800 {
3801 Value *value = rhs.loadValue();
3802 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003803 }
3804
3805 UInt::UInt(const Int &rhs)
3806 {
John Bauman66b8ab22014-05-06 15:57:45 -04003807 Value *value = rhs.loadValue();
3808 storeValue(value);
3809 }
John Bauman89401822014-05-06 15:04:28 -04003810
John Bauman66b8ab22014-05-06 15:57:45 -04003811 UInt::UInt(const Reference<Int> &rhs)
3812 {
3813 Value *value = rhs.loadValue();
3814 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003815 }
3816
Nicolas Capens96d4e092016-11-18 14:22:38 -05003817 RValue<UInt> UInt::operator=(unsigned int rhs)
John Bauman89401822014-05-06 15:04:28 -04003818 {
John Bauman66b8ab22014-05-06 15:57:45 -04003819 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04003820 }
3821
Nicolas Capens96d4e092016-11-18 14:22:38 -05003822 RValue<UInt> UInt::operator=(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003823 {
John Bauman66b8ab22014-05-06 15:57:45 -04003824 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003825
3826 return rhs;
3827 }
3828
Nicolas Capens96d4e092016-11-18 14:22:38 -05003829 RValue<UInt> UInt::operator=(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003830 {
John Bauman66b8ab22014-05-06 15:57:45 -04003831 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003832
John Bauman66b8ab22014-05-06 15:57:45 -04003833 return RValue<UInt>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003834 }
3835
Nicolas Capens96d4e092016-11-18 14:22:38 -05003836 RValue<UInt> UInt::operator=(const UInt &rhs)
John Bauman89401822014-05-06 15:04:28 -04003837 {
John Bauman66b8ab22014-05-06 15:57:45 -04003838 Value *value = rhs.loadValue();
3839 storeValue(value);
3840
3841 return RValue<UInt>(value);
3842 }
3843
Nicolas Capens96d4e092016-11-18 14:22:38 -05003844 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04003845 {
3846 Value *value = rhs.loadValue();
3847 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003848
3849 return RValue<UInt>(value);
3850 }
3851
Nicolas Capens96d4e092016-11-18 14:22:38 -05003852 RValue<UInt> UInt::operator=(const Int &rhs)
John Bauman89401822014-05-06 15:04:28 -04003853 {
John Bauman66b8ab22014-05-06 15:57:45 -04003854 Value *value = rhs.loadValue();
3855 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003856
3857 return RValue<UInt>(value);
3858 }
3859
Nicolas Capens96d4e092016-11-18 14:22:38 -05003860 RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
John Bauman89401822014-05-06 15:04:28 -04003861 {
John Bauman66b8ab22014-05-06 15:57:45 -04003862 Value *value = rhs.loadValue();
3863 storeValue(value);
3864
3865 return RValue<UInt>(value);
John Bauman89401822014-05-06 15:04:28 -04003866 }
3867
John Bauman19bac1e2014-05-06 15:23:49 -04003868 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003869 {
3870 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
3871 }
3872
John Bauman19bac1e2014-05-06 15:23:49 -04003873 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003874 {
3875 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
3876 }
3877
John Bauman19bac1e2014-05-06 15:23:49 -04003878 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003879 {
3880 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
3881 }
3882
John Bauman19bac1e2014-05-06 15:23:49 -04003883 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003884 {
3885 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
3886 }
3887
John Bauman19bac1e2014-05-06 15:23:49 -04003888 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003889 {
3890 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
3891 }
3892
John Bauman19bac1e2014-05-06 15:23:49 -04003893 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003894 {
3895 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
3896 }
3897
John Bauman19bac1e2014-05-06 15:23:49 -04003898 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003899 {
3900 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
3901 }
3902
John Bauman19bac1e2014-05-06 15:23:49 -04003903 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003904 {
3905 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
3906 }
3907
John Bauman19bac1e2014-05-06 15:23:49 -04003908 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003909 {
3910 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
3911 }
3912
John Bauman19bac1e2014-05-06 15:23:49 -04003913 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003914 {
3915 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
3916 }
3917
Nicolas Capens96d4e092016-11-18 14:22:38 -05003918 RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003919 {
3920 return lhs = lhs + rhs;
3921 }
3922
Nicolas Capens96d4e092016-11-18 14:22:38 -05003923 RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003924 {
3925 return lhs = lhs - rhs;
3926 }
3927
Nicolas Capens96d4e092016-11-18 14:22:38 -05003928 RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003929 {
3930 return lhs = lhs * rhs;
3931 }
3932
Nicolas Capens96d4e092016-11-18 14:22:38 -05003933 RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003934 {
3935 return lhs = lhs / rhs;
3936 }
3937
Nicolas Capens96d4e092016-11-18 14:22:38 -05003938 RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003939 {
3940 return lhs = lhs % rhs;
3941 }
3942
Nicolas Capens96d4e092016-11-18 14:22:38 -05003943 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003944 {
3945 return lhs = lhs & rhs;
3946 }
3947
Nicolas Capens96d4e092016-11-18 14:22:38 -05003948 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003949 {
3950 return lhs = lhs | rhs;
3951 }
3952
Nicolas Capens96d4e092016-11-18 14:22:38 -05003953 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003954 {
3955 return lhs = lhs ^ rhs;
3956 }
3957
Nicolas Capens96d4e092016-11-18 14:22:38 -05003958 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003959 {
3960 return lhs = lhs << rhs;
3961 }
3962
Nicolas Capens96d4e092016-11-18 14:22:38 -05003963 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003964 {
3965 return lhs = lhs >> rhs;
3966 }
3967
John Bauman19bac1e2014-05-06 15:23:49 -04003968 RValue<UInt> operator+(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04003969 {
3970 return val;
3971 }
3972
John Bauman19bac1e2014-05-06 15:23:49 -04003973 RValue<UInt> operator-(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04003974 {
3975 return RValue<UInt>(Nucleus::createNeg(val.value));
3976 }
3977
John Bauman19bac1e2014-05-06 15:23:49 -04003978 RValue<UInt> operator~(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04003979 {
3980 return RValue<UInt>(Nucleus::createNot(val.value));
3981 }
3982
Nicolas Capens96d4e092016-11-18 14:22:38 -05003983 RValue<UInt> operator++(UInt &val, int) // Post-increment
John Bauman89401822014-05-06 15:04:28 -04003984 {
3985 RValue<UInt> res = val;
3986
Nicolas Capens19336542016-09-26 10:32:29 -04003987 Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04003988 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003989
3990 return res;
3991 }
3992
Nicolas Capens96d4e092016-11-18 14:22:38 -05003993 const UInt &operator++(UInt &val) // Pre-increment
John Bauman89401822014-05-06 15:04:28 -04003994 {
Nicolas Capens19336542016-09-26 10:32:29 -04003995 Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04003996 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003997
3998 return val;
3999 }
4000
Nicolas Capens96d4e092016-11-18 14:22:38 -05004001 RValue<UInt> operator--(UInt &val, int) // Post-decrement
John Bauman89401822014-05-06 15:04:28 -04004002 {
4003 RValue<UInt> res = val;
4004
Nicolas Capens19336542016-09-26 10:32:29 -04004005 Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04004006 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004007
4008 return res;
4009 }
4010
Nicolas Capens96d4e092016-11-18 14:22:38 -05004011 const UInt &operator--(UInt &val) // Pre-decrement
John Bauman89401822014-05-06 15:04:28 -04004012 {
Nicolas Capens19336542016-09-26 10:32:29 -04004013 Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1)));
John Bauman66b8ab22014-05-06 15:57:45 -04004014 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004015
4016 return val;
4017 }
4018
John Bauman19bac1e2014-05-06 15:23:49 -04004019 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4020 {
4021 return IfThenElse(x > y, x, y);
4022 }
4023
4024 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4025 {
4026 return IfThenElse(x < y, x, y);
4027 }
4028
4029 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4030 {
4031 return Min(Max(x, min), max);
4032 }
4033
4034 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004035 {
4036 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4037 }
4038
John Bauman19bac1e2014-05-06 15:23:49 -04004039 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004040 {
4041 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4042 }
4043
John Bauman19bac1e2014-05-06 15:23:49 -04004044 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004045 {
4046 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4047 }
4048
John Bauman19bac1e2014-05-06 15:23:49 -04004049 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004050 {
4051 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4052 }
4053
John Bauman19bac1e2014-05-06 15:23:49 -04004054 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004055 {
4056 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4057 }
4058
John Bauman19bac1e2014-05-06 15:23:49 -04004059 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004060 {
4061 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4062 }
4063
John Bauman19bac1e2014-05-06 15:23:49 -04004064// RValue<UInt> RoundUInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004065// {
4066// return x86::cvtss2si(val); // FIXME: Unsigned
4067//
John Bauman66b8ab22014-05-06 15:57:45 -04004068// // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004069// }
4070
John Bauman19bac1e2014-05-06 15:23:49 -04004071 Type *UInt::getType()
John Bauman89401822014-05-06 15:04:28 -04004072 {
Nicolas Capensac230122016-09-20 14:30:06 -04004073 return T(llvm::Type::getInt32Ty(*::context));
John Bauman89401822014-05-06 15:04:28 -04004074 }
4075
John Bauman19bac1e2014-05-06 15:23:49 -04004076// Int2::Int2(RValue<Int> cast)
4077// {
John Bauman19bac1e2014-05-06 15:23:49 -04004078// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4079// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04004080//
Nicolas Capense89cd582016-09-30 14:23:47 -04004081// int shuffle[2] = {0, 0};
4082// Value *replicate = Nucleus::createShuffleVector(vector, vector, shuffle);
John Bauman19bac1e2014-05-06 15:23:49 -04004083//
John Bauman66b8ab22014-05-06 15:57:45 -04004084// storeValue(replicate);
John Bauman19bac1e2014-05-06 15:23:49 -04004085// }
John Bauman89401822014-05-06 15:04:28 -04004086
John Bauman19bac1e2014-05-06 15:23:49 -04004087 Int2::Int2(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04004088 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004089 storeValue(Nucleus::createBitCast(cast.value, getType()));
John Bauman89401822014-05-06 15:04:28 -04004090 }
4091
John Bauman89401822014-05-06 15:04:28 -04004092 Int2::Int2(int x, int y)
4093 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004094 int64_t constantVector[2] = {x, y};
Nicolas Capens01a97962017-07-28 17:30:51 -04004095 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004096 }
4097
John Bauman19bac1e2014-05-06 15:23:49 -04004098 Int2::Int2(RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004099 {
John Bauman66b8ab22014-05-06 15:57:45 -04004100 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004101 }
4102
4103 Int2::Int2(const Int2 &rhs)
4104 {
John Bauman66b8ab22014-05-06 15:57:45 -04004105 Value *value = rhs.loadValue();
4106 storeValue(value);
4107 }
4108
4109 Int2::Int2(const Reference<Int2> &rhs)
4110 {
John Bauman66b8ab22014-05-06 15:57:45 -04004111 Value *value = rhs.loadValue();
4112 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004113 }
4114
Nicolas Capens62abb552016-01-05 12:03:47 -05004115 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4116 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004117 int shuffle[4] = {0, 4, 1, 5};
4118 Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
Nicolas Capens45f187a2016-12-02 15:30:56 -05004119
Nicolas Capens01a97962017-07-28 17:30:51 -04004120 storeValue(Nucleus::createBitCast(packed, Int2::getType()));
Nicolas Capens62abb552016-01-05 12:03:47 -05004121 }
4122
Nicolas Capens96d4e092016-11-18 14:22:38 -05004123 RValue<Int2> Int2::operator=(RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004124 {
John Bauman66b8ab22014-05-06 15:57:45 -04004125 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004126
4127 return rhs;
4128 }
4129
Nicolas Capens96d4e092016-11-18 14:22:38 -05004130 RValue<Int2> Int2::operator=(const Int2 &rhs)
John Bauman89401822014-05-06 15:04:28 -04004131 {
John Bauman66b8ab22014-05-06 15:57:45 -04004132 Value *value = rhs.loadValue();
4133 storeValue(value);
4134
4135 return RValue<Int2>(value);
4136 }
4137
Nicolas Capens96d4e092016-11-18 14:22:38 -05004138 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04004139 {
4140 Value *value = rhs.loadValue();
4141 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004142
4143 return RValue<Int2>(value);
4144 }
4145
John Bauman19bac1e2014-05-06 15:23:49 -04004146 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004147 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004148 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004149 }
4150
John Bauman19bac1e2014-05-06 15:23:49 -04004151 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004152 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004153 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004154 }
4155
John Bauman19bac1e2014-05-06 15:23:49 -04004156// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4157// {
4158// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4159// }
4160
4161// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4162// {
4163// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4164// }
4165
4166// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4167// {
4168// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4169// }
4170
4171 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004172 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004173 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004174 }
4175
John Bauman19bac1e2014-05-06 15:23:49 -04004176 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004177 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004178 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004179 }
4180
John Bauman19bac1e2014-05-06 15:23:49 -04004181 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004182 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004183 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004184 }
4185
John Bauman19bac1e2014-05-06 15:23:49 -04004186 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004187 {
4188 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4189
4190 return x86::pslld(lhs, rhs);
4191 }
4192
John Bauman19bac1e2014-05-06 15:23:49 -04004193 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004194 {
4195 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4196
4197 return x86::psrad(lhs, rhs);
4198 }
4199
Nicolas Capens96d4e092016-11-18 14:22:38 -05004200 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004201 {
4202 return lhs = lhs + rhs;
4203 }
4204
Nicolas Capens96d4e092016-11-18 14:22:38 -05004205 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004206 {
4207 return lhs = lhs - rhs;
4208 }
4209
Nicolas Capens96d4e092016-11-18 14:22:38 -05004210// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004211// {
4212// return lhs = lhs * rhs;
4213// }
John Bauman89401822014-05-06 15:04:28 -04004214
Nicolas Capens96d4e092016-11-18 14:22:38 -05004215// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004216// {
4217// return lhs = lhs / rhs;
4218// }
John Bauman89401822014-05-06 15:04:28 -04004219
Nicolas Capens96d4e092016-11-18 14:22:38 -05004220// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004221// {
4222// return lhs = lhs % rhs;
4223// }
John Bauman89401822014-05-06 15:04:28 -04004224
Nicolas Capens96d4e092016-11-18 14:22:38 -05004225 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004226 {
4227 return lhs = lhs & rhs;
4228 }
4229
Nicolas Capens96d4e092016-11-18 14:22:38 -05004230 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004231 {
4232 return lhs = lhs | rhs;
4233 }
4234
Nicolas Capens96d4e092016-11-18 14:22:38 -05004235 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004236 {
4237 return lhs = lhs ^ rhs;
4238 }
4239
Nicolas Capens96d4e092016-11-18 14:22:38 -05004240 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004241 {
4242 return lhs = lhs << rhs;
4243 }
4244
Nicolas Capens96d4e092016-11-18 14:22:38 -05004245 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004246 {
4247 return lhs = lhs >> rhs;
4248 }
4249
John Bauman19bac1e2014-05-06 15:23:49 -04004250// RValue<Int2> operator+(RValue<Int2> val)
4251// {
4252// return val;
4253// }
4254
4255// RValue<Int2> operator-(RValue<Int2> val)
4256// {
4257// return RValue<Int2>(Nucleus::createNeg(val.value));
4258// }
4259
4260 RValue<Int2> operator~(RValue<Int2> val)
John Bauman89401822014-05-06 15:04:28 -04004261 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004262 return RValue<Int2>(Nucleus::createNot(val.value));
John Bauman89401822014-05-06 15:04:28 -04004263 }
4264
Nicolas Capens45f187a2016-12-02 15:30:56 -05004265 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004266 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004267 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
4268 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04004269 }
John Bauman66b8ab22014-05-06 15:57:45 -04004270
Nicolas Capens45f187a2016-12-02 15:30:56 -05004271 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004272 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004273 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
4274 auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
4275 return As<Short4>(Swizzle(lowHigh, 0xEE));
John Bauman89401822014-05-06 15:04:28 -04004276 }
4277
John Bauman19bac1e2014-05-06 15:23:49 -04004278 RValue<Int> Extract(RValue<Int2> val, int i)
John Bauman89401822014-05-06 15:04:28 -04004279 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004280 return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
John Bauman89401822014-05-06 15:04:28 -04004281 }
4282
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004283 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4284 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004285 return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004286 }
John Bauman89401822014-05-06 15:04:28 -04004287
John Bauman19bac1e2014-05-06 15:23:49 -04004288 Type *Int2::getType()
John Bauman89401822014-05-06 15:04:28 -04004289 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04004290 return T(Type_v2i32);
John Bauman89401822014-05-06 15:04:28 -04004291 }
4292
John Bauman89401822014-05-06 15:04:28 -04004293 UInt2::UInt2(unsigned int x, unsigned int y)
4294 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004295 int64_t constantVector[2] = {x, y};
Nicolas Capens01a97962017-07-28 17:30:51 -04004296 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004297 }
4298
John Bauman19bac1e2014-05-06 15:23:49 -04004299 UInt2::UInt2(RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004300 {
John Bauman66b8ab22014-05-06 15:57:45 -04004301 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004302 }
4303
4304 UInt2::UInt2(const UInt2 &rhs)
4305 {
John Bauman66b8ab22014-05-06 15:57:45 -04004306 Value *value = rhs.loadValue();
4307 storeValue(value);
4308 }
4309
4310 UInt2::UInt2(const Reference<UInt2> &rhs)
4311 {
John Bauman66b8ab22014-05-06 15:57:45 -04004312 Value *value = rhs.loadValue();
4313 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004314 }
4315
Nicolas Capens96d4e092016-11-18 14:22:38 -05004316 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004317 {
John Bauman66b8ab22014-05-06 15:57:45 -04004318 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004319
4320 return rhs;
4321 }
4322
Nicolas Capens96d4e092016-11-18 14:22:38 -05004323 RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
John Bauman89401822014-05-06 15:04:28 -04004324 {
John Bauman66b8ab22014-05-06 15:57:45 -04004325 Value *value = rhs.loadValue();
4326 storeValue(value);
4327
4328 return RValue<UInt2>(value);
4329 }
4330
Nicolas Capens96d4e092016-11-18 14:22:38 -05004331 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04004332 {
4333 Value *value = rhs.loadValue();
4334 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004335
4336 return RValue<UInt2>(value);
4337 }
4338
John Bauman19bac1e2014-05-06 15:23:49 -04004339 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004340 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004341 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004342 }
4343
John Bauman19bac1e2014-05-06 15:23:49 -04004344 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004345 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004346 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004347 }
4348
John Bauman19bac1e2014-05-06 15:23:49 -04004349// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4350// {
4351// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4352// }
4353
4354// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4355// {
4356// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4357// }
4358
4359// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4360// {
4361// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4362// }
4363
4364 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004365 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004366 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004367 }
4368
John Bauman19bac1e2014-05-06 15:23:49 -04004369 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004370 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004371 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004372 }
4373
John Bauman19bac1e2014-05-06 15:23:49 -04004374 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004375 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004376 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
John Bauman89401822014-05-06 15:04:28 -04004377 }
4378
John Bauman19bac1e2014-05-06 15:23:49 -04004379 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004380 {
4381 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
4382
4383 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
4384 }
4385
John Bauman19bac1e2014-05-06 15:23:49 -04004386 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004387 {
4388 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
4389
4390 return x86::psrld(lhs, rhs);
4391 }
4392
Nicolas Capens96d4e092016-11-18 14:22:38 -05004393 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004394 {
4395 return lhs = lhs + rhs;
4396 }
4397
Nicolas Capens96d4e092016-11-18 14:22:38 -05004398 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004399 {
4400 return lhs = lhs - rhs;
4401 }
4402
Nicolas Capens96d4e092016-11-18 14:22:38 -05004403// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004404// {
4405// return lhs = lhs * rhs;
4406// }
John Bauman89401822014-05-06 15:04:28 -04004407
Nicolas Capens96d4e092016-11-18 14:22:38 -05004408// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004409// {
4410// return lhs = lhs / rhs;
4411// }
John Bauman89401822014-05-06 15:04:28 -04004412
Nicolas Capens96d4e092016-11-18 14:22:38 -05004413// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004414// {
4415// return lhs = lhs % rhs;
4416// }
John Bauman89401822014-05-06 15:04:28 -04004417
Nicolas Capens96d4e092016-11-18 14:22:38 -05004418 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004419 {
4420 return lhs = lhs & rhs;
4421 }
4422
Nicolas Capens96d4e092016-11-18 14:22:38 -05004423 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004424 {
4425 return lhs = lhs | rhs;
4426 }
4427
Nicolas Capens96d4e092016-11-18 14:22:38 -05004428 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004429 {
4430 return lhs = lhs ^ rhs;
4431 }
4432
Nicolas Capens96d4e092016-11-18 14:22:38 -05004433 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004434 {
4435 return lhs = lhs << rhs;
4436 }
4437
Nicolas Capens96d4e092016-11-18 14:22:38 -05004438 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004439 {
4440 return lhs = lhs >> rhs;
4441 }
4442
John Bauman19bac1e2014-05-06 15:23:49 -04004443// RValue<UInt2> operator+(RValue<UInt2> val)
4444// {
4445// return val;
4446// }
4447
4448// RValue<UInt2> operator-(RValue<UInt2> val)
4449// {
4450// return RValue<UInt2>(Nucleus::createNeg(val.value));
4451// }
4452
4453 RValue<UInt2> operator~(RValue<UInt2> val)
John Bauman89401822014-05-06 15:04:28 -04004454 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004455 return RValue<UInt2>(Nucleus::createNot(val.value));
John Bauman89401822014-05-06 15:04:28 -04004456 }
4457
John Bauman19bac1e2014-05-06 15:23:49 -04004458 Type *UInt2::getType()
John Bauman89401822014-05-06 15:04:28 -04004459 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04004460 return T(Type_v2i32);
John Bauman89401822014-05-06 15:04:28 -04004461 }
4462
Nicolas Capenscb986762017-01-20 11:34:37 -05004463 Int4::Int4() : XYZW(this)
4464 {
4465 }
4466
4467 Int4::Int4(RValue<Byte4> cast) : XYZW(this)
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004468 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004469 if(CPUID::supportsSSE4_1())
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004470 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004471 *this = x86::pmovzxbd(As<Byte16>(cast));
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004472 }
4473 else
4474 {
Nicolas Capense89cd582016-09-30 14:23:47 -04004475 int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
Nicolas Capens01a97962017-07-28 17:30:51 -04004476 Value *a = Nucleus::createBitCast(cast.value, Byte16::getType());
4477 Value *b = Nucleus::createShuffleVector(a, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004478
Nicolas Capense89cd582016-09-30 14:23:47 -04004479 int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
Nicolas Capens01a97962017-07-28 17:30:51 -04004480 Value *c = Nucleus::createBitCast(b, Short8::getType());
4481 Value *d = Nucleus::createShuffleVector(c, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004482
Nicolas Capens01a97962017-07-28 17:30:51 -04004483 *this = As<Int4>(d);
4484 }
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004485 }
4486
Nicolas Capenscb986762017-01-20 11:34:37 -05004487 Int4::Int4(RValue<SByte4> cast) : XYZW(this)
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004488 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004489 if(CPUID::supportsSSE4_1())
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004490 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004491 *this = x86::pmovsxbd(As<SByte16>(cast));
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004492 }
4493 else
4494 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004495 int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
4496 Value *a = Nucleus::createBitCast(cast.value, Byte16::getType());
4497 Value *b = Nucleus::createShuffleVector(a, a, swizzle);
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004498
Nicolas Capense89cd582016-09-30 14:23:47 -04004499 int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
Nicolas Capens01a97962017-07-28 17:30:51 -04004500 Value *c = Nucleus::createBitCast(b, Short8::getType());
4501 Value *d = Nucleus::createShuffleVector(c, c, swizzle2);
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004502
Nicolas Capens01a97962017-07-28 17:30:51 -04004503 *this = As<Int4>(d) >> 24;
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004504 }
Meng-Lin Wu601d0052016-06-10 14:18:41 -04004505 }
4506
Nicolas Capenscb986762017-01-20 11:34:37 -05004507 Int4::Int4(RValue<Float4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004508 {
John Bauman89401822014-05-06 15:04:28 -04004509 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
John Bauman89401822014-05-06 15:04:28 -04004510
John Bauman66b8ab22014-05-06 15:57:45 -04004511 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04004512 }
4513
Nicolas Capenscb986762017-01-20 11:34:37 -05004514 Int4::Int4(RValue<Short4> cast) : XYZW(this)
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004515 {
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004516 if(CPUID::supportsSSE4_1())
4517 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004518 *this = x86::pmovsxwd(As<Short8>(cast));
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004519 }
4520 else
4521 {
Nicolas Capense89cd582016-09-30 14:23:47 -04004522 int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
Nicolas Capens01a97962017-07-28 17:30:51 -04004523 Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
4524 *this = As<Int4>(c) >> 16;
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004525 }
4526 }
4527
Nicolas Capenscb986762017-01-20 11:34:37 -05004528 Int4::Int4(RValue<UShort4> cast) : XYZW(this)
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004529 {
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004530 if(CPUID::supportsSSE4_1())
4531 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004532 *this = x86::pmovzxwd(As<UShort8>(cast));
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004533 }
4534 else
4535 {
Nicolas Capense89cd582016-09-30 14:23:47 -04004536 int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
Nicolas Capens01a97962017-07-28 17:30:51 -04004537 Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
4538 *this = As<Int4>(c);
Alexis Hetu2aa852f2015-10-14 16:32:39 -04004539 }
4540 }
4541
Nicolas Capenscb986762017-01-20 11:34:37 -05004542 Int4::Int4(int xyzw) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004543 {
4544 constant(xyzw, xyzw, xyzw, xyzw);
4545 }
4546
Nicolas Capenscb986762017-01-20 11:34:37 -05004547 Int4::Int4(int x, int yzw) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004548 {
4549 constant(x, yzw, yzw, yzw);
4550 }
4551
Nicolas Capenscb986762017-01-20 11:34:37 -05004552 Int4::Int4(int x, int y, int zw) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004553 {
4554 constant(x, y, zw, zw);
4555 }
4556
Nicolas Capenscb986762017-01-20 11:34:37 -05004557 Int4::Int4(int x, int y, int z, int w) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004558 {
4559 constant(x, y, z, w);
4560 }
4561
4562 void Int4::constant(int x, int y, int z, int w)
4563 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004564 int64_t constantVector[4] = {x, y, z, w};
4565 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004566 }
4567
Nicolas Capenscb986762017-01-20 11:34:37 -05004568 Int4::Int4(RValue<Int4> rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004569 {
John Bauman66b8ab22014-05-06 15:57:45 -04004570 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004571 }
4572
Nicolas Capenscb986762017-01-20 11:34:37 -05004573 Int4::Int4(const Int4 &rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004574 {
John Bauman66b8ab22014-05-06 15:57:45 -04004575 Value *value = rhs.loadValue();
4576 storeValue(value);
4577 }
4578
Nicolas Capenscb986762017-01-20 11:34:37 -05004579 Int4::Int4(const Reference<Int4> &rhs) : XYZW(this)
John Bauman66b8ab22014-05-06 15:57:45 -04004580 {
John Bauman66b8ab22014-05-06 15:57:45 -04004581 Value *value = rhs.loadValue();
4582 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004583 }
4584
Nicolas Capenscb986762017-01-20 11:34:37 -05004585 Int4::Int4(RValue<UInt4> rhs) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004586 {
John Bauman66b8ab22014-05-06 15:57:45 -04004587 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04004588 }
4589
Nicolas Capenscb986762017-01-20 11:34:37 -05004590 Int4::Int4(const UInt4 &rhs) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004591 {
John Bauman66b8ab22014-05-06 15:57:45 -04004592 Value *value = rhs.loadValue();
4593 storeValue(value);
4594 }
4595
Nicolas Capenscb986762017-01-20 11:34:37 -05004596 Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this)
John Bauman66b8ab22014-05-06 15:57:45 -04004597 {
John Bauman66b8ab22014-05-06 15:57:45 -04004598 Value *value = rhs.loadValue();
4599 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04004600 }
4601
Nicolas Capenscb986762017-01-20 11:34:37 -05004602 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this)
Nicolas Capens62abb552016-01-05 12:03:47 -05004603 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004604 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
4605 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
Nicolas Capens62abb552016-01-05 12:03:47 -05004606
Nicolas Capens01a97962017-07-28 17:30:51 -04004607 storeValue(packed);
Nicolas Capens62abb552016-01-05 12:03:47 -05004608 }
4609
Nicolas Capenscb986762017-01-20 11:34:37 -05004610 Int4::Int4(RValue<Int> rhs) : XYZW(this)
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004611 {
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004612 Value *vector = loadValue();
4613 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
4614
Nicolas Capense89cd582016-09-30 14:23:47 -04004615 int swizzle[4] = {0, 0, 0, 0};
4616 Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle);
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004617
4618 storeValue(replicate);
4619 }
4620
Nicolas Capenscb986762017-01-20 11:34:37 -05004621 Int4::Int4(const Int &rhs) : XYZW(this)
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004622 {
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004623 *this = RValue<Int>(rhs.loadValue());
4624 }
4625
Nicolas Capenscb986762017-01-20 11:34:37 -05004626 Int4::Int4(const Reference<Int> &rhs) : XYZW(this)
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004627 {
Nicolas Capens24c8cf02016-08-15 15:33:14 -04004628 *this = RValue<Int>(rhs.loadValue());
4629 }
4630
Nicolas Capens96d4e092016-11-18 14:22:38 -05004631 RValue<Int4> Int4::operator=(RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004632 {
John Bauman66b8ab22014-05-06 15:57:45 -04004633 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004634
4635 return rhs;
4636 }
4637
Nicolas Capens96d4e092016-11-18 14:22:38 -05004638 RValue<Int4> Int4::operator=(const Int4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04004639 {
John Bauman66b8ab22014-05-06 15:57:45 -04004640 Value *value = rhs.loadValue();
4641 storeValue(value);
4642
4643 return RValue<Int4>(value);
4644 }
4645
Nicolas Capens96d4e092016-11-18 14:22:38 -05004646 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04004647 {
4648 Value *value = rhs.loadValue();
4649 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004650
4651 return RValue<Int4>(value);
4652 }
4653
John Bauman19bac1e2014-05-06 15:23:49 -04004654 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004655 {
4656 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
4657 }
4658
John Bauman19bac1e2014-05-06 15:23:49 -04004659 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004660 {
4661 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
4662 }
4663
John Bauman19bac1e2014-05-06 15:23:49 -04004664 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004665 {
4666 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
4667 }
4668
Alexis Hetud9d27bb2015-08-18 15:22:15 -04004669 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
4670 {
4671 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
4672 }
John Bauman89401822014-05-06 15:04:28 -04004673
Alexis Hetud9d27bb2015-08-18 15:22:15 -04004674 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
4675 {
4676 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
4677 }
John Bauman89401822014-05-06 15:04:28 -04004678
John Bauman19bac1e2014-05-06 15:23:49 -04004679 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004680 {
4681 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
4682 }
4683
John Bauman19bac1e2014-05-06 15:23:49 -04004684 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004685 {
4686 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
4687 }
4688
John Bauman19bac1e2014-05-06 15:23:49 -04004689 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004690 {
4691 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
4692 }
4693
John Bauman19bac1e2014-05-06 15:23:49 -04004694 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004695 {
John Bauman89401822014-05-06 15:04:28 -04004696 return x86::pslld(lhs, rhs);
4697 }
4698
John Bauman19bac1e2014-05-06 15:23:49 -04004699 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004700 {
John Bauman89401822014-05-06 15:04:28 -04004701 return x86::psrad(lhs, rhs);
4702 }
4703
Alexis Hetud9d27bb2015-08-18 15:22:15 -04004704 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
4705 {
4706 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
4707 }
4708
4709 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
4710 {
4711 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
4712 }
4713
Nicolas Capens96d4e092016-11-18 14:22:38 -05004714 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004715 {
4716 return lhs = lhs + rhs;
4717 }
4718
Nicolas Capens96d4e092016-11-18 14:22:38 -05004719 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004720 {
4721 return lhs = lhs - rhs;
4722 }
4723
Nicolas Capens96d4e092016-11-18 14:22:38 -05004724 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004725 {
4726 return lhs = lhs * rhs;
4727 }
4728
Nicolas Capens96d4e092016-11-18 14:22:38 -05004729// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004730// {
4731// return lhs = lhs / rhs;
4732// }
John Bauman89401822014-05-06 15:04:28 -04004733
Nicolas Capens96d4e092016-11-18 14:22:38 -05004734// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04004735// {
4736// return lhs = lhs % rhs;
4737// }
John Bauman89401822014-05-06 15:04:28 -04004738
Nicolas Capens96d4e092016-11-18 14:22:38 -05004739 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004740 {
4741 return lhs = lhs & rhs;
4742 }
4743
Nicolas Capens96d4e092016-11-18 14:22:38 -05004744 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004745 {
4746 return lhs = lhs | rhs;
4747 }
4748
Nicolas Capens96d4e092016-11-18 14:22:38 -05004749 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004750 {
4751 return lhs = lhs ^ rhs;
4752 }
4753
Nicolas Capens96d4e092016-11-18 14:22:38 -05004754 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004755 {
4756 return lhs = lhs << rhs;
4757 }
4758
Nicolas Capens96d4e092016-11-18 14:22:38 -05004759 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004760 {
4761 return lhs = lhs >> rhs;
4762 }
4763
John Bauman19bac1e2014-05-06 15:23:49 -04004764 RValue<Int4> operator+(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04004765 {
4766 return val;
4767 }
4768
John Bauman19bac1e2014-05-06 15:23:49 -04004769 RValue<Int4> operator-(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04004770 {
4771 return RValue<Int4>(Nucleus::createNeg(val.value));
4772 }
4773
John Bauman19bac1e2014-05-06 15:23:49 -04004774 RValue<Int4> operator~(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04004775 {
4776 return RValue<Int4>(Nucleus::createNot(val.value));
4777 }
4778
John Bauman19bac1e2014-05-06 15:23:49 -04004779 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
4780 {
Nicolas Capens197226a2016-04-27 23:08:50 -04004781 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
Alexis Hetufb603992016-04-26 11:50:40 -04004782 // Restore the following line when LLVM is updated to a version where this issue is fixed.
4783 // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
4784 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04004785 }
4786
4787 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
4788 {
Nicolas Capens9ae6cfd2017-11-27 14:58:53 -05004789 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
4790 // Restore the following line when LLVM is updated to a version where this issue is fixed.
4791 // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
4792 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04004793 }
4794
4795 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
4796 {
Nicolas Capens197226a2016-04-27 23:08:50 -04004797 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
4798 // Restore the following line when LLVM is updated to a version where this issue is fixed.
4799 // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
4800 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04004801 }
4802
4803 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
4804 {
Nicolas Capens9ae6cfd2017-11-27 14:58:53 -05004805 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
4806 // Restore the following line when LLVM is updated to a version where this issue is fixed.
4807 // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
4808 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04004809 }
4810
4811 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
4812 {
Nicolas Capens197226a2016-04-27 23:08:50 -04004813 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
4814 // Restore the following line when LLVM is updated to a version where this issue is fixed.
4815 // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
4816 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04004817 }
4818
4819 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
4820 {
Nicolas Capens9ae6cfd2017-11-27 14:58:53 -05004821 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
4822 // Restore the following line when LLVM is updated to a version where this issue is fixed.
4823 // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
4824 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04004825 }
4826
4827 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
4828 {
4829 if(CPUID::supportsSSE4_1())
4830 {
4831 return x86::pmaxsd(x, y);
4832 }
4833 else
4834 {
4835 RValue<Int4> greater = CmpNLE(x, y);
Tom Anderson69bc6e82017-03-20 11:54:29 -07004836 return (x & greater) | (y & ~greater);
John Bauman19bac1e2014-05-06 15:23:49 -04004837 }
4838 }
4839
4840 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
4841 {
4842 if(CPUID::supportsSSE4_1())
4843 {
4844 return x86::pminsd(x, y);
4845 }
4846 else
4847 {
4848 RValue<Int4> less = CmpLT(x, y);
Tom Anderson69bc6e82017-03-20 11:54:29 -07004849 return (x & less) | (y & ~less);
John Bauman19bac1e2014-05-06 15:23:49 -04004850 }
4851 }
4852
4853 RValue<Int4> RoundInt(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04004854 {
4855 return x86::cvtps2dq(cast);
4856 }
4857
Nicolas Capens33438a62017-09-27 11:47:35 -04004858 RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04004859 {
4860 return x86::packssdw(x, y);
4861 }
4862
Nicolas Capens33438a62017-09-27 11:47:35 -04004863 RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y)
4864 {
4865 return x86::packusdw(x, y);
4866 }
4867
John Bauman19bac1e2014-05-06 15:23:49 -04004868 RValue<Int> Extract(RValue<Int4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04004869 {
Nicolas Capense95d5342016-09-30 11:37:28 -04004870 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
John Bauman89401822014-05-06 15:04:28 -04004871 }
4872
John Bauman19bac1e2014-05-06 15:23:49 -04004873 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
John Bauman89401822014-05-06 15:04:28 -04004874 {
4875 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
4876 }
4877
John Bauman19bac1e2014-05-06 15:23:49 -04004878 RValue<Int> SignMask(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04004879 {
4880 return x86::movmskps(As<Float4>(x));
4881 }
4882
John Bauman19bac1e2014-05-06 15:23:49 -04004883 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04004884 {
Nicolas Capense95d5342016-09-30 11:37:28 -04004885 return RValue<Int4>(createSwizzle4(x.value, select));
John Bauman89401822014-05-06 15:04:28 -04004886 }
4887
John Bauman19bac1e2014-05-06 15:23:49 -04004888 Type *Int4::getType()
John Bauman89401822014-05-06 15:04:28 -04004889 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04004890 return T(llvm::VectorType::get(T(Int::getType()), 4));
John Bauman89401822014-05-06 15:04:28 -04004891 }
4892
Nicolas Capenscb986762017-01-20 11:34:37 -05004893 UInt4::UInt4() : XYZW(this)
4894 {
4895 }
4896
4897 UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004898 {
Alexis Hetu764d1422016-09-28 08:44:22 -04004899 // Note: createFPToUI is broken, must perform conversion using createFPtoSI
4900 // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
John Bauman89401822014-05-06 15:04:28 -04004901
Alexis Hetu764d1422016-09-28 08:44:22 -04004902 // Smallest positive value representable in UInt, but not in Int
4903 const unsigned int ustart = 0x80000000u;
4904 const float ustartf = float(ustart);
4905
4906 // Check if the value can be represented as an Int
4907 Int4 uiValue = CmpNLT(cast, Float4(ustartf));
4908 // If the value is too large, subtract ustart and re-add it after conversion.
4909 uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
4910 // Otherwise, just convert normally
4911 (~uiValue & Int4(cast));
4912 // If the value is negative, store 0, otherwise store the result of the conversion
4913 storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
John Bauman89401822014-05-06 15:04:28 -04004914 }
4915
Nicolas Capenscb986762017-01-20 11:34:37 -05004916 UInt4::UInt4(int xyzw) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004917 {
4918 constant(xyzw, xyzw, xyzw, xyzw);
4919 }
4920
Nicolas Capenscb986762017-01-20 11:34:37 -05004921 UInt4::UInt4(int x, int yzw) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004922 {
4923 constant(x, yzw, yzw, yzw);
4924 }
4925
Nicolas Capenscb986762017-01-20 11:34:37 -05004926 UInt4::UInt4(int x, int y, int zw) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004927 {
4928 constant(x, y, zw, zw);
4929 }
4930
Nicolas Capenscb986762017-01-20 11:34:37 -05004931 UInt4::UInt4(int x, int y, int z, int w) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004932 {
4933 constant(x, y, z, w);
4934 }
4935
4936 void UInt4::constant(int x, int y, int z, int w)
John Bauman89401822014-05-06 15:04:28 -04004937 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004938 int64_t constantVector[4] = {x, y, z, w};
4939 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004940 }
4941
Nicolas Capenscb986762017-01-20 11:34:37 -05004942 UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004943 {
John Bauman66b8ab22014-05-06 15:57:45 -04004944 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004945 }
4946
Nicolas Capenscb986762017-01-20 11:34:37 -05004947 UInt4::UInt4(const UInt4 &rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04004948 {
John Bauman66b8ab22014-05-06 15:57:45 -04004949 Value *value = rhs.loadValue();
4950 storeValue(value);
4951 }
4952
Nicolas Capenscb986762017-01-20 11:34:37 -05004953 UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this)
John Bauman66b8ab22014-05-06 15:57:45 -04004954 {
John Bauman66b8ab22014-05-06 15:57:45 -04004955 Value *value = rhs.loadValue();
4956 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004957 }
4958
Nicolas Capenscb986762017-01-20 11:34:37 -05004959 UInt4::UInt4(RValue<Int4> rhs) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004960 {
John Bauman66b8ab22014-05-06 15:57:45 -04004961 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04004962 }
4963
Nicolas Capenscb986762017-01-20 11:34:37 -05004964 UInt4::UInt4(const Int4 &rhs) : XYZW(this)
John Bauman19bac1e2014-05-06 15:23:49 -04004965 {
John Bauman66b8ab22014-05-06 15:57:45 -04004966 Value *value = rhs.loadValue();
4967 storeValue(value);
4968 }
4969
Nicolas Capenscb986762017-01-20 11:34:37 -05004970 UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this)
John Bauman66b8ab22014-05-06 15:57:45 -04004971 {
John Bauman66b8ab22014-05-06 15:57:45 -04004972 Value *value = rhs.loadValue();
4973 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04004974 }
4975
Nicolas Capenscb986762017-01-20 11:34:37 -05004976 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this)
Nicolas Capens62abb552016-01-05 12:03:47 -05004977 {
Nicolas Capens01a97962017-07-28 17:30:51 -04004978 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
4979 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
Nicolas Capens62abb552016-01-05 12:03:47 -05004980
Nicolas Capens01a97962017-07-28 17:30:51 -04004981 storeValue(packed);
Nicolas Capens62abb552016-01-05 12:03:47 -05004982 }
4983
Nicolas Capens96d4e092016-11-18 14:22:38 -05004984 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04004985 {
John Bauman66b8ab22014-05-06 15:57:45 -04004986 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004987
4988 return rhs;
4989 }
4990
Nicolas Capens96d4e092016-11-18 14:22:38 -05004991 RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04004992 {
John Bauman66b8ab22014-05-06 15:57:45 -04004993 Value *value = rhs.loadValue();
4994 storeValue(value);
4995
4996 return RValue<UInt4>(value);
4997 }
4998
Nicolas Capens96d4e092016-11-18 14:22:38 -05004999 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04005000 {
5001 Value *value = rhs.loadValue();
5002 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005003
5004 return RValue<UInt4>(value);
5005 }
5006
John Bauman19bac1e2014-05-06 15:23:49 -04005007 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005008 {
5009 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5010 }
5011
John Bauman19bac1e2014-05-06 15:23:49 -04005012 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005013 {
5014 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5015 }
5016
John Bauman19bac1e2014-05-06 15:23:49 -04005017 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005018 {
5019 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5020 }
5021
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005022 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5023 {
5024 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5025 }
John Bauman89401822014-05-06 15:04:28 -04005026
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005027 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5028 {
5029 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5030 }
John Bauman89401822014-05-06 15:04:28 -04005031
John Bauman19bac1e2014-05-06 15:23:49 -04005032 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005033 {
5034 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5035 }
5036
John Bauman19bac1e2014-05-06 15:23:49 -04005037 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005038 {
5039 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5040 }
5041
John Bauman19bac1e2014-05-06 15:23:49 -04005042 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005043 {
5044 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5045 }
5046
John Bauman19bac1e2014-05-06 15:23:49 -04005047 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005048 {
John Bauman89401822014-05-06 15:04:28 -04005049 return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
5050 }
5051
John Bauman19bac1e2014-05-06 15:23:49 -04005052 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005053 {
John Bauman89401822014-05-06 15:04:28 -04005054 return x86::psrld(lhs, rhs);
5055 }
5056
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005057 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5058 {
5059 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5060 }
5061
5062 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5063 {
5064 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5065 }
5066
Nicolas Capens96d4e092016-11-18 14:22:38 -05005067 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005068 {
5069 return lhs = lhs + rhs;
5070 }
5071
Nicolas Capens96d4e092016-11-18 14:22:38 -05005072 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005073 {
5074 return lhs = lhs - rhs;
5075 }
5076
Nicolas Capens96d4e092016-11-18 14:22:38 -05005077 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005078 {
5079 return lhs = lhs * rhs;
5080 }
5081
Nicolas Capens96d4e092016-11-18 14:22:38 -05005082// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04005083// {
5084// return lhs = lhs / rhs;
5085// }
John Bauman89401822014-05-06 15:04:28 -04005086
Nicolas Capens96d4e092016-11-18 14:22:38 -05005087// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman19bac1e2014-05-06 15:23:49 -04005088// {
5089// return lhs = lhs % rhs;
5090// }
John Bauman89401822014-05-06 15:04:28 -04005091
Nicolas Capens96d4e092016-11-18 14:22:38 -05005092 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005093 {
5094 return lhs = lhs & rhs;
5095 }
5096
Nicolas Capens96d4e092016-11-18 14:22:38 -05005097 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005098 {
5099 return lhs = lhs | rhs;
5100 }
5101
Nicolas Capens96d4e092016-11-18 14:22:38 -05005102 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005103 {
5104 return lhs = lhs ^ rhs;
5105 }
5106
Nicolas Capens96d4e092016-11-18 14:22:38 -05005107 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005108 {
5109 return lhs = lhs << rhs;
5110 }
5111
Nicolas Capens96d4e092016-11-18 14:22:38 -05005112 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005113 {
5114 return lhs = lhs >> rhs;
5115 }
5116
John Bauman19bac1e2014-05-06 15:23:49 -04005117 RValue<UInt4> operator+(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005118 {
5119 return val;
5120 }
5121
John Bauman19bac1e2014-05-06 15:23:49 -04005122 RValue<UInt4> operator-(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005123 {
5124 return RValue<UInt4>(Nucleus::createNeg(val.value));
5125 }
5126
John Bauman19bac1e2014-05-06 15:23:49 -04005127 RValue<UInt4> operator~(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005128 {
5129 return RValue<UInt4>(Nucleus::createNot(val.value));
5130 }
5131
John Bauman19bac1e2014-05-06 15:23:49 -04005132 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5133 {
Nicolas Capens197226a2016-04-27 23:08:50 -04005134 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
Alexis Hetufb603992016-04-26 11:50:40 -04005135 // Restore the following line when LLVM is updated to a version where this issue is fixed.
5136 // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5137 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04005138 }
5139
5140 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5141 {
5142 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5143 }
5144
5145 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5146 {
Nicolas Capens197226a2016-04-27 23:08:50 -04005147 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
5148 // Restore the following line when LLVM is updated to a version where this issue is fixed.
5149 // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5150 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04005151 }
5152
5153 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5154 {
5155 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5156 }
5157
5158 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5159 {
Nicolas Capens197226a2016-04-27 23:08:50 -04005160 // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0
5161 // Restore the following line when LLVM is updated to a version where this issue is fixed.
5162 // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5163 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF);
John Bauman19bac1e2014-05-06 15:23:49 -04005164 }
5165
5166 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5167 {
5168 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5169 }
5170
5171 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5172 {
5173 if(CPUID::supportsSSE4_1())
5174 {
5175 return x86::pmaxud(x, y);
5176 }
5177 else
5178 {
5179 RValue<UInt4> greater = CmpNLE(x, y);
Tom Anderson69bc6e82017-03-20 11:54:29 -07005180 return (x & greater) | (y & ~greater);
John Bauman19bac1e2014-05-06 15:23:49 -04005181 }
5182 }
5183
5184 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5185 {
5186 if(CPUID::supportsSSE4_1())
5187 {
5188 return x86::pminud(x, y);
5189 }
5190 else
5191 {
5192 RValue<UInt4> less = CmpLT(x, y);
Tom Anderson69bc6e82017-03-20 11:54:29 -07005193 return (x & less) | (y & ~less);
John Bauman19bac1e2014-05-06 15:23:49 -04005194 }
5195 }
5196
John Bauman19bac1e2014-05-06 15:23:49 -04005197 Type *UInt4::getType()
John Bauman89401822014-05-06 15:04:28 -04005198 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005199 return T(llvm::VectorType::get(T(UInt::getType()), 4));
John Bauman89401822014-05-06 15:04:28 -04005200 }
5201
John Bauman19bac1e2014-05-06 15:23:49 -04005202 Float::Float(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04005203 {
John Bauman89401822014-05-06 15:04:28 -04005204 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5205
John Bauman66b8ab22014-05-06 15:57:45 -04005206 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04005207 }
5208
Alexis Hetucfd96322017-07-24 14:44:33 -04005209 Float::Float(RValue<UInt> cast)
5210 {
5211 RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) +
5212 As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u)));
5213
5214 storeValue(result.value);
5215 }
5216
John Bauman89401822014-05-06 15:04:28 -04005217 Float::Float(float x)
5218 {
John Bauman66b8ab22014-05-06 15:57:45 -04005219 storeValue(Nucleus::createConstantFloat(x));
John Bauman89401822014-05-06 15:04:28 -04005220 }
5221
John Bauman19bac1e2014-05-06 15:23:49 -04005222 Float::Float(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005223 {
John Bauman66b8ab22014-05-06 15:57:45 -04005224 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005225 }
5226
5227 Float::Float(const Float &rhs)
5228 {
John Bauman66b8ab22014-05-06 15:57:45 -04005229 Value *value = rhs.loadValue();
5230 storeValue(value);
5231 }
John Bauman89401822014-05-06 15:04:28 -04005232
John Bauman66b8ab22014-05-06 15:57:45 -04005233 Float::Float(const Reference<Float> &rhs)
5234 {
5235 Value *value = rhs.loadValue();
5236 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005237 }
5238
Nicolas Capens96d4e092016-11-18 14:22:38 -05005239 RValue<Float> Float::operator=(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005240 {
John Bauman66b8ab22014-05-06 15:57:45 -04005241 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005242
5243 return rhs;
5244 }
5245
Nicolas Capens96d4e092016-11-18 14:22:38 -05005246 RValue<Float> Float::operator=(const Float &rhs)
John Bauman89401822014-05-06 15:04:28 -04005247 {
John Bauman66b8ab22014-05-06 15:57:45 -04005248 Value *value = rhs.loadValue();
5249 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005250
5251 return RValue<Float>(value);
5252 }
5253
Nicolas Capens96d4e092016-11-18 14:22:38 -05005254 RValue<Float> Float::operator=(const Reference<Float> &rhs)
John Bauman89401822014-05-06 15:04:28 -04005255 {
John Bauman66b8ab22014-05-06 15:57:45 -04005256 Value *value = rhs.loadValue();
5257 storeValue(value);
5258
5259 return RValue<Float>(value);
John Bauman89401822014-05-06 15:04:28 -04005260 }
5261
John Bauman19bac1e2014-05-06 15:23:49 -04005262 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005263 {
5264 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5265 }
5266
John Bauman19bac1e2014-05-06 15:23:49 -04005267 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005268 {
5269 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5270 }
5271
John Bauman19bac1e2014-05-06 15:23:49 -04005272 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005273 {
5274 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5275 }
5276
John Bauman19bac1e2014-05-06 15:23:49 -04005277 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005278 {
5279 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5280 }
5281
Nicolas Capens96d4e092016-11-18 14:22:38 -05005282 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005283 {
5284 return lhs = lhs + rhs;
5285 }
5286
Nicolas Capens96d4e092016-11-18 14:22:38 -05005287 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005288 {
5289 return lhs = lhs - rhs;
5290 }
5291
Nicolas Capens96d4e092016-11-18 14:22:38 -05005292 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005293 {
5294 return lhs = lhs * rhs;
5295 }
5296
Nicolas Capens96d4e092016-11-18 14:22:38 -05005297 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005298 {
5299 return lhs = lhs / rhs;
5300 }
5301
John Bauman19bac1e2014-05-06 15:23:49 -04005302 RValue<Float> operator+(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005303 {
5304 return val;
5305 }
5306
John Bauman19bac1e2014-05-06 15:23:49 -04005307 RValue<Float> operator-(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005308 {
5309 return RValue<Float>(Nucleus::createFNeg(val.value));
5310 }
5311
John Bauman19bac1e2014-05-06 15:23:49 -04005312 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005313 {
5314 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5315 }
5316
John Bauman19bac1e2014-05-06 15:23:49 -04005317 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005318 {
5319 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5320 }
5321
John Bauman19bac1e2014-05-06 15:23:49 -04005322 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005323 {
5324 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5325 }
5326
John Bauman19bac1e2014-05-06 15:23:49 -04005327 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005328 {
5329 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5330 }
5331
John Bauman19bac1e2014-05-06 15:23:49 -04005332 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005333 {
5334 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5335 }
5336
John Bauman19bac1e2014-05-06 15:23:49 -04005337 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005338 {
5339 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5340 }
5341
John Bauman19bac1e2014-05-06 15:23:49 -04005342 RValue<Float> Abs(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005343 {
John Bauman66b8ab22014-05-06 15:57:45 -04005344 return IfThenElse(x > 0.0f, x, -x);
John Bauman89401822014-05-06 15:04:28 -04005345 }
5346
John Bauman19bac1e2014-05-06 15:23:49 -04005347 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04005348 {
5349 return IfThenElse(x > y, x, y);
5350 }
5351
John Bauman19bac1e2014-05-06 15:23:49 -04005352 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04005353 {
5354 return IfThenElse(x < y, x, y);
5355 }
5356
Nicolas Capens05b3d662016-02-25 23:58:33 -05005357 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
John Bauman89401822014-05-06 15:04:28 -04005358 {
Nicolas Capens47dc8672017-04-25 12:54:39 -04005359 #if defined(__i386__) || defined(__x86_64__)
5360 if(exactAtPow2)
5361 {
5362 // rcpss uses a piecewise-linear approximation which minimizes the relative error
5363 // but is not exact at power-of-two values. Rectify by multiplying by the inverse.
5364 return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f))));
5365 }
5366 #endif
5367
5368 return x86::rcpss(x);
John Bauman89401822014-05-06 15:04:28 -04005369 }
John Bauman66b8ab22014-05-06 15:57:45 -04005370
John Bauman19bac1e2014-05-06 15:23:49 -04005371 RValue<Float> RcpSqrt_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005372 {
5373 return x86::rsqrtss(x);
5374 }
5375
John Bauman19bac1e2014-05-06 15:23:49 -04005376 RValue<Float> Sqrt(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005377 {
5378 return x86::sqrtss(x);
5379 }
5380
John Bauman19bac1e2014-05-06 15:23:49 -04005381 RValue<Float> Round(RValue<Float> x)
5382 {
5383 if(CPUID::supportsSSE4_1())
5384 {
5385 return x86::roundss(x, 0);
5386 }
5387 else
5388 {
5389 return Float4(Round(Float4(x))).x;
5390 }
5391 }
5392
5393 RValue<Float> Trunc(RValue<Float> x)
5394 {
5395 if(CPUID::supportsSSE4_1())
5396 {
5397 return x86::roundss(x, 3);
5398 }
5399 else
5400 {
5401 return Float(Int(x)); // Rounded toward zero
5402 }
5403 }
5404
5405 RValue<Float> Frac(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005406 {
5407 if(CPUID::supportsSSE4_1())
5408 {
5409 return x - x86::floorss(x);
5410 }
5411 else
5412 {
John Bauman19bac1e2014-05-06 15:23:49 -04005413 return Float4(Frac(Float4(x))).x;
John Bauman89401822014-05-06 15:04:28 -04005414 }
5415 }
5416
John Bauman19bac1e2014-05-06 15:23:49 -04005417 RValue<Float> Floor(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005418 {
5419 if(CPUID::supportsSSE4_1())
5420 {
5421 return x86::floorss(x);
5422 }
5423 else
5424 {
5425 return Float4(Floor(Float4(x))).x;
5426 }
5427 }
5428
John Bauman19bac1e2014-05-06 15:23:49 -04005429 RValue<Float> Ceil(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005430 {
John Bauman19bac1e2014-05-06 15:23:49 -04005431 if(CPUID::supportsSSE4_1())
5432 {
5433 return x86::ceilss(x);
5434 }
5435 else
5436 {
5437 return Float4(Ceil(Float4(x))).x;
5438 }
John Bauman89401822014-05-06 15:04:28 -04005439 }
5440
John Bauman19bac1e2014-05-06 15:23:49 -04005441 Type *Float::getType()
John Bauman89401822014-05-06 15:04:28 -04005442 {
Nicolas Capensac230122016-09-20 14:30:06 -04005443 return T(llvm::Type::getFloatTy(*::context));
John Bauman89401822014-05-06 15:04:28 -04005444 }
5445
John Bauman19bac1e2014-05-06 15:23:49 -04005446 Float2::Float2(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005447 {
Nicolas Capens01a97962017-07-28 17:30:51 -04005448 storeValue(Nucleus::createBitCast(cast.value, getType()));
John Bauman89401822014-05-06 15:04:28 -04005449 }
5450
John Bauman19bac1e2014-05-06 15:23:49 -04005451 Type *Float2::getType()
John Bauman89401822014-05-06 15:04:28 -04005452 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005453 return T(Type_v2f32);
John Bauman89401822014-05-06 15:04:28 -04005454 }
5455
Nicolas Capenscb986762017-01-20 11:34:37 -05005456 Float4::Float4(RValue<Byte4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005457 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04005458 Value *a = Int4(cast).loadValue();
5459 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04005460
5461 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005462 }
5463
Nicolas Capenscb986762017-01-20 11:34:37 -05005464 Float4::Float4(RValue<SByte4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005465 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04005466 Value *a = Int4(cast).loadValue();
5467 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04005468
5469 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005470 }
5471
Nicolas Capenscb986762017-01-20 11:34:37 -05005472 Float4::Float4(RValue<Short4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005473 {
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005474 Int4 c(cast);
5475 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
John Bauman89401822014-05-06 15:04:28 -04005476 }
5477
Nicolas Capenscb986762017-01-20 11:34:37 -05005478 Float4::Float4(RValue<UShort4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005479 {
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005480 Int4 c(cast);
5481 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
John Bauman89401822014-05-06 15:04:28 -04005482 }
5483
Nicolas Capenscb986762017-01-20 11:34:37 -05005484 Float4::Float4(RValue<Int4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005485 {
John Bauman89401822014-05-06 15:04:28 -04005486 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04005487
John Bauman66b8ab22014-05-06 15:57:45 -04005488 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005489 }
5490
Nicolas Capenscb986762017-01-20 11:34:37 -05005491 Float4::Float4(RValue<UInt4> cast) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005492 {
Nicolas Capens96445fe2016-12-15 14:45:13 -05005493 RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
5494 As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
John Bauman89401822014-05-06 15:04:28 -04005495
Nicolas Capens96445fe2016-12-15 14:45:13 -05005496 storeValue(result.value);
John Bauman89401822014-05-06 15:04:28 -04005497 }
5498
Nicolas Capenscb986762017-01-20 11:34:37 -05005499 Float4::Float4() : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005500 {
John Bauman89401822014-05-06 15:04:28 -04005501 }
John Bauman66b8ab22014-05-06 15:57:45 -04005502
Nicolas Capenscb986762017-01-20 11:34:37 -05005503 Float4::Float4(float xyzw) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005504 {
5505 constant(xyzw, xyzw, xyzw, xyzw);
5506 }
5507
Nicolas Capenscb986762017-01-20 11:34:37 -05005508 Float4::Float4(float x, float yzw) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005509 {
5510 constant(x, yzw, yzw, yzw);
5511 }
5512
Nicolas Capenscb986762017-01-20 11:34:37 -05005513 Float4::Float4(float x, float y, float zw) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005514 {
5515 constant(x, y, zw, zw);
5516 }
5517
Nicolas Capenscb986762017-01-20 11:34:37 -05005518 Float4::Float4(float x, float y, float z, float w) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005519 {
5520 constant(x, y, z, w);
5521 }
5522
5523 void Float4::constant(float x, float y, float z, float w)
5524 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005525 double constantVector[4] = {x, y, z, w};
5526 storeValue(Nucleus::createConstantVector(constantVector, getType()));
John Bauman89401822014-05-06 15:04:28 -04005527 }
5528
Nicolas Capenscb986762017-01-20 11:34:37 -05005529 Float4::Float4(RValue<Float4> rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005530 {
John Bauman66b8ab22014-05-06 15:57:45 -04005531 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005532 }
5533
Nicolas Capenscb986762017-01-20 11:34:37 -05005534 Float4::Float4(const Float4 &rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005535 {
John Bauman66b8ab22014-05-06 15:57:45 -04005536 Value *value = rhs.loadValue();
5537 storeValue(value);
5538 }
5539
Nicolas Capenscb986762017-01-20 11:34:37 -05005540 Float4::Float4(const Reference<Float4> &rhs) : XYZW(this)
John Bauman66b8ab22014-05-06 15:57:45 -04005541 {
John Bauman66b8ab22014-05-06 15:57:45 -04005542 Value *value = rhs.loadValue();
5543 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005544 }
5545
Nicolas Capenscb986762017-01-20 11:34:37 -05005546 Float4::Float4(RValue<Float> rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005547 {
John Bauman66b8ab22014-05-06 15:57:45 -04005548 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04005549 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
5550
Nicolas Capense89cd582016-09-30 14:23:47 -04005551 int swizzle[4] = {0, 0, 0, 0};
5552 Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle);
John Bauman89401822014-05-06 15:04:28 -04005553
John Bauman66b8ab22014-05-06 15:57:45 -04005554 storeValue(replicate);
John Bauman89401822014-05-06 15:04:28 -04005555 }
5556
Nicolas Capenscb986762017-01-20 11:34:37 -05005557 Float4::Float4(const Float &rhs) : XYZW(this)
John Bauman89401822014-05-06 15:04:28 -04005558 {
John Bauman66b8ab22014-05-06 15:57:45 -04005559 *this = RValue<Float>(rhs.loadValue());
5560 }
John Bauman89401822014-05-06 15:04:28 -04005561
Nicolas Capenscb986762017-01-20 11:34:37 -05005562 Float4::Float4(const Reference<Float> &rhs) : XYZW(this)
John Bauman66b8ab22014-05-06 15:57:45 -04005563 {
John Bauman66b8ab22014-05-06 15:57:45 -04005564 *this = RValue<Float>(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04005565 }
5566
Nicolas Capens96d4e092016-11-18 14:22:38 -05005567 RValue<Float4> Float4::operator=(float x)
John Bauman89401822014-05-06 15:04:28 -04005568 {
5569 return *this = Float4(x, x, x, x);
5570 }
5571
Nicolas Capens96d4e092016-11-18 14:22:38 -05005572 RValue<Float4> Float4::operator=(RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005573 {
John Bauman66b8ab22014-05-06 15:57:45 -04005574 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005575
5576 return rhs;
5577 }
5578
Nicolas Capens96d4e092016-11-18 14:22:38 -05005579 RValue<Float4> Float4::operator=(const Float4 &rhs)
John Bauman89401822014-05-06 15:04:28 -04005580 {
John Bauman66b8ab22014-05-06 15:57:45 -04005581 Value *value = rhs.loadValue();
5582 storeValue(value);
5583
5584 return RValue<Float4>(value);
5585 }
5586
Nicolas Capens96d4e092016-11-18 14:22:38 -05005587 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
John Bauman66b8ab22014-05-06 15:57:45 -04005588 {
5589 Value *value = rhs.loadValue();
5590 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005591
5592 return RValue<Float4>(value);
5593 }
5594
Nicolas Capens96d4e092016-11-18 14:22:38 -05005595 RValue<Float4> Float4::operator=(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005596 {
5597 return *this = Float4(rhs);
5598 }
5599
Nicolas Capens96d4e092016-11-18 14:22:38 -05005600 RValue<Float4> Float4::operator=(const Float &rhs)
John Bauman89401822014-05-06 15:04:28 -04005601 {
5602 return *this = Float4(rhs);
5603 }
5604
Nicolas Capens96d4e092016-11-18 14:22:38 -05005605 RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
John Bauman89401822014-05-06 15:04:28 -04005606 {
John Bauman66b8ab22014-05-06 15:57:45 -04005607 return *this = Float4(rhs);
John Bauman89401822014-05-06 15:04:28 -04005608 }
5609
John Bauman19bac1e2014-05-06 15:23:49 -04005610 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005611 {
5612 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
5613 }
5614
John Bauman19bac1e2014-05-06 15:23:49 -04005615 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005616 {
5617 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
5618 }
5619
John Bauman19bac1e2014-05-06 15:23:49 -04005620 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005621 {
5622 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
5623 }
5624
John Bauman19bac1e2014-05-06 15:23:49 -04005625 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005626 {
5627 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
5628 }
5629
John Bauman19bac1e2014-05-06 15:23:49 -04005630 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005631 {
5632 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
5633 }
5634
Nicolas Capens96d4e092016-11-18 14:22:38 -05005635 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005636 {
5637 return lhs = lhs + rhs;
5638 }
5639
Nicolas Capens96d4e092016-11-18 14:22:38 -05005640 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005641 {
5642 return lhs = lhs - rhs;
5643 }
5644
Nicolas Capens96d4e092016-11-18 14:22:38 -05005645 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005646 {
5647 return lhs = lhs * rhs;
5648 }
5649
Nicolas Capens96d4e092016-11-18 14:22:38 -05005650 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005651 {
5652 return lhs = lhs / rhs;
5653 }
5654
Nicolas Capens96d4e092016-11-18 14:22:38 -05005655 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005656 {
5657 return lhs = lhs % rhs;
5658 }
5659
John Bauman19bac1e2014-05-06 15:23:49 -04005660 RValue<Float4> operator+(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04005661 {
5662 return val;
5663 }
5664
John Bauman19bac1e2014-05-06 15:23:49 -04005665 RValue<Float4> operator-(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04005666 {
5667 return RValue<Float4>(Nucleus::createFNeg(val.value));
5668 }
5669
John Bauman19bac1e2014-05-06 15:23:49 -04005670 RValue<Float4> Abs(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005671 {
5672 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
Nicolas Capens13ac2322016-10-13 14:52:12 -04005673 int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
5674 Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
John Bauman89401822014-05-06 15:04:28 -04005675
Nicolas Capens01a97962017-07-28 17:30:51 -04005676 return As<Float4>(result);
John Bauman89401822014-05-06 15:04:28 -04005677 }
5678
John Bauman19bac1e2014-05-06 15:23:49 -04005679 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005680 {
5681 return x86::maxps(x, y);
5682 }
5683
John Bauman19bac1e2014-05-06 15:23:49 -04005684 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005685 {
5686 return x86::minps(x, y);
5687 }
5688
Nicolas Capens05b3d662016-02-25 23:58:33 -05005689 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
John Bauman89401822014-05-06 15:04:28 -04005690 {
Nicolas Capens47dc8672017-04-25 12:54:39 -04005691 #if defined(__i386__) || defined(__x86_64__)
5692 if(exactAtPow2)
5693 {
5694 // rcpps uses a piecewise-linear approximation which minimizes the relative error
5695 // but is not exact at power-of-two values. Rectify by multiplying by the inverse.
5696 return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f))));
5697 }
5698 #endif
5699
5700 return x86::rcpps(x);
John Bauman89401822014-05-06 15:04:28 -04005701 }
John Bauman66b8ab22014-05-06 15:57:45 -04005702
John Bauman19bac1e2014-05-06 15:23:49 -04005703 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005704 {
5705 return x86::rsqrtps(x);
5706 }
5707
John Bauman19bac1e2014-05-06 15:23:49 -04005708 RValue<Float4> Sqrt(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005709 {
5710 return x86::sqrtps(x);
5711 }
5712
Nicolas Capens01a97962017-07-28 17:30:51 -04005713 RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
John Bauman89401822014-05-06 15:04:28 -04005714 {
Nicolas Capens01a97962017-07-28 17:30:51 -04005715 return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
John Bauman89401822014-05-06 15:04:28 -04005716 }
5717
John Bauman19bac1e2014-05-06 15:23:49 -04005718 RValue<Float> Extract(RValue<Float4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04005719 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005720 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
John Bauman89401822014-05-06 15:04:28 -04005721 }
5722
John Bauman19bac1e2014-05-06 15:23:49 -04005723 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04005724 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005725 return RValue<Float4>(createSwizzle4(x.value, select));
John Bauman89401822014-05-06 15:04:28 -04005726 }
5727
John Bauman19bac1e2014-05-06 15:23:49 -04005728 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04005729 {
Nicolas Capense89cd582016-09-30 14:23:47 -04005730 int shuffle[4] =
5731 {
5732 ((imm >> 0) & 0x03) + 0,
5733 ((imm >> 2) & 0x03) + 0,
5734 ((imm >> 4) & 0x03) + 4,
5735 ((imm >> 6) & 0x03) + 4,
5736 };
John Bauman89401822014-05-06 15:04:28 -04005737
Nicolas Capense89cd582016-09-30 14:23:47 -04005738 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04005739 }
5740
John Bauman19bac1e2014-05-06 15:23:49 -04005741 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005742 {
Nicolas Capense89cd582016-09-30 14:23:47 -04005743 int shuffle[4] = {0, 4, 1, 5};
5744 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04005745 }
5746
John Bauman19bac1e2014-05-06 15:23:49 -04005747 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005748 {
Nicolas Capense89cd582016-09-30 14:23:47 -04005749 int shuffle[4] = {2, 6, 3, 7};
5750 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
John Bauman89401822014-05-06 15:04:28 -04005751 }
John Bauman66b8ab22014-05-06 15:57:45 -04005752
John Bauman19bac1e2014-05-06 15:23:49 -04005753 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04005754 {
John Bauman66b8ab22014-05-06 15:57:45 -04005755 Value *vector = lhs.loadValue();
Nicolas Capens01a97962017-07-28 17:30:51 -04005756 Value *result = createMask4(vector, rhs.value, select);
5757 lhs.storeValue(result);
John Bauman89401822014-05-06 15:04:28 -04005758
Nicolas Capens01a97962017-07-28 17:30:51 -04005759 return RValue<Float4>(result);
John Bauman89401822014-05-06 15:04:28 -04005760 }
5761
John Bauman19bac1e2014-05-06 15:23:49 -04005762 RValue<Int> SignMask(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005763 {
5764 return x86::movmskps(x);
5765 }
5766
John Bauman19bac1e2014-05-06 15:23:49 -04005767 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005768 {
5769 // return As<Int4>(x86::cmpeqps(x, y));
5770 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
5771 }
5772
John Bauman19bac1e2014-05-06 15:23:49 -04005773 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005774 {
5775 // return As<Int4>(x86::cmpltps(x, y));
5776 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
5777 }
5778
John Bauman19bac1e2014-05-06 15:23:49 -04005779 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005780 {
5781 // return As<Int4>(x86::cmpleps(x, y));
5782 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
5783 }
5784
John Bauman19bac1e2014-05-06 15:23:49 -04005785 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005786 {
5787 // return As<Int4>(x86::cmpneqps(x, y));
5788 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
5789 }
5790
John Bauman19bac1e2014-05-06 15:23:49 -04005791 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005792 {
5793 // return As<Int4>(x86::cmpnltps(x, y));
5794 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
5795 }
5796
John Bauman19bac1e2014-05-06 15:23:49 -04005797 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04005798 {
5799 // return As<Int4>(x86::cmpnleps(x, y));
5800 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
5801 }
5802
Alexis Hetu8ef6d102017-11-09 15:49:09 -05005803 RValue<Int4> IsInf(RValue<Float4> x)
5804 {
5805 return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000));
5806 }
5807
5808 RValue<Int4> IsNan(RValue<Float4> x)
5809 {
5810 return ~CmpEQ(x, x);
5811 }
5812
John Bauman19bac1e2014-05-06 15:23:49 -04005813 RValue<Float4> Round(RValue<Float4> x)
5814 {
5815 if(CPUID::supportsSSE4_1())
5816 {
5817 return x86::roundps(x, 0);
5818 }
5819 else
5820 {
5821 return Float4(RoundInt(x));
5822 }
5823 }
5824
5825 RValue<Float4> Trunc(RValue<Float4> x)
5826 {
5827 if(CPUID::supportsSSE4_1())
5828 {
5829 return x86::roundps(x, 3);
5830 }
5831 else
5832 {
Nicolas Capens01a97962017-07-28 17:30:51 -04005833 return Float4(Int4(x));
John Bauman19bac1e2014-05-06 15:23:49 -04005834 }
5835 }
5836
5837 RValue<Float4> Frac(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005838 {
Nicolas Capensb9230422017-07-17 10:27:33 -04005839 Float4 frc;
5840
John Bauman89401822014-05-06 15:04:28 -04005841 if(CPUID::supportsSSE4_1())
5842 {
Nicolas Capens01a97962017-07-28 17:30:51 -04005843 frc = x - Floor(x);
John Bauman89401822014-05-06 15:04:28 -04005844 }
5845 else
5846 {
Nicolas Capensb9230422017-07-17 10:27:33 -04005847 frc = x - Float4(Int4(x)); // Signed fractional part.
John Bauman89401822014-05-06 15:04:28 -04005848
Nicolas Capensb9230422017-07-17 10:27:33 -04005849 frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1.0f))); // Add 1.0 if negative.
John Bauman89401822014-05-06 15:04:28 -04005850 }
Nicolas Capensb9230422017-07-17 10:27:33 -04005851
5852 // x - floor(x) can be 1.0 for very small negative x.
5853 // Clamp against the value just below 1.0.
5854 return Min(frc, As<Float4>(Int4(0x3F7FFFFF)));
John Bauman89401822014-05-06 15:04:28 -04005855 }
5856
John Bauman19bac1e2014-05-06 15:23:49 -04005857 RValue<Float4> Floor(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005858 {
5859 if(CPUID::supportsSSE4_1())
5860 {
5861 return x86::floorps(x);
5862 }
5863 else
5864 {
John Bauman19bac1e2014-05-06 15:23:49 -04005865 return x - Frac(x);
John Bauman89401822014-05-06 15:04:28 -04005866 }
5867 }
5868
John Bauman19bac1e2014-05-06 15:23:49 -04005869 RValue<Float4> Ceil(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04005870 {
John Bauman19bac1e2014-05-06 15:23:49 -04005871 if(CPUID::supportsSSE4_1())
5872 {
5873 return x86::ceilps(x);
5874 }
5875 else
5876 {
5877 return -Floor(-x);
5878 }
John Bauman89401822014-05-06 15:04:28 -04005879 }
5880
John Bauman19bac1e2014-05-06 15:23:49 -04005881 Type *Float4::getType()
John Bauman89401822014-05-06 15:04:28 -04005882 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005883 return T(llvm::VectorType::get(T(Float::getType()), 4));
John Bauman89401822014-05-06 15:04:28 -04005884 }
5885
Nicolas Capens81f18302016-01-14 09:32:35 -05005886 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04005887 {
Nicolas Capens01a97962017-07-28 17:30:51 -04005888 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
John Bauman89401822014-05-06 15:04:28 -04005889 }
5890
Nicolas Capens81f18302016-01-14 09:32:35 -05005891 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04005892 {
Nicolas Capensd294def2017-01-26 17:44:37 -08005893 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
John Bauman89401822014-05-06 15:04:28 -04005894 }
5895
Nicolas Capens81f18302016-01-14 09:32:35 -05005896 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04005897 {
Nicolas Capensd294def2017-01-26 17:44:37 -08005898 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
John Bauman89401822014-05-06 15:04:28 -04005899 }
5900
Nicolas Capens96d4e092016-11-18 14:22:38 -05005901 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04005902 {
5903 return lhs = lhs + offset;
5904 }
5905
Nicolas Capens96d4e092016-11-18 14:22:38 -05005906 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04005907 {
5908 return lhs = lhs + offset;
5909 }
5910
Nicolas Capens96d4e092016-11-18 14:22:38 -05005911 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04005912 {
5913 return lhs = lhs + offset;
5914 }
5915
Nicolas Capens81f18302016-01-14 09:32:35 -05005916 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04005917 {
5918 return lhs + -offset;
5919 }
5920
Nicolas Capens81f18302016-01-14 09:32:35 -05005921 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04005922 {
5923 return lhs + -offset;
5924 }
5925
Nicolas Capens81f18302016-01-14 09:32:35 -05005926 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04005927 {
5928 return lhs + -offset;
5929 }
5930
Nicolas Capens96d4e092016-11-18 14:22:38 -05005931 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04005932 {
5933 return lhs = lhs - offset;
5934 }
5935
Nicolas Capens96d4e092016-11-18 14:22:38 -05005936 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04005937 {
5938 return lhs = lhs - offset;
5939 }
5940
Nicolas Capens96d4e092016-11-18 14:22:38 -05005941 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04005942 {
5943 return lhs = lhs - offset;
5944 }
5945
5946 void Return()
5947 {
John Bauman89401822014-05-06 15:04:28 -04005948 Nucleus::createRetVoid();
5949 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04005950 Nucleus::createUnreachable();
5951 }
5952
Nicolas Capenseb253d02016-11-18 14:40:40 -05005953 void Return(RValue<Int> ret)
John Bauman19bac1e2014-05-06 15:23:49 -04005954 {
Nicolas Capenseb253d02016-11-18 14:40:40 -05005955 Nucleus::createRet(ret.value);
John Bauman89401822014-05-06 15:04:28 -04005956 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04005957 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04005958 }
5959
Nicolas Capensf4eec2f2017-05-24 15:46:48 -04005960 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
John Bauman89401822014-05-06 15:04:28 -04005961 {
5962 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
John Bauman66b8ab22014-05-06 15:57:45 -04005963 Nucleus::setInsertBlock(bodyBB);
John Bauman89401822014-05-06 15:04:28 -04005964 }
5965
John Bauman89401822014-05-06 15:04:28 -04005966 RValue<Long> Ticks()
5967 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005968 llvm::Function *rdtsc = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::readcyclecounter);
John Bauman89401822014-05-06 15:04:28 -04005969
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04005970 return RValue<Long>(V(::builder->CreateCall(rdtsc)));
John Bauman89401822014-05-06 15:04:28 -04005971 }
John Bauman89401822014-05-06 15:04:28 -04005972}
5973
5974namespace sw
5975{
5976 namespace x86
5977 {
John Bauman19bac1e2014-05-06 15:23:49 -04005978 RValue<Int> cvtss2si(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005979 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005980 llvm::Function *cvtss2si = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cvtss2si);
John Bauman66b8ab22014-05-06 15:57:45 -04005981
John Bauman89401822014-05-06 15:04:28 -04005982 Float4 vector;
5983 vector.x = val;
5984
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04005985 return RValue<Int>(V(::builder->CreateCall(cvtss2si, RValue<Float4>(vector).value)));
John Bauman89401822014-05-06 15:04:28 -04005986 }
5987
John Bauman19bac1e2014-05-06 15:23:49 -04005988 RValue<Int4> cvtps2dq(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04005989 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04005990 llvm::Function *cvtps2dq = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_cvtps2dq);
John Bauman89401822014-05-06 15:04:28 -04005991
Nicolas Capens9e013d42017-07-28 17:26:14 -04005992 return RValue<Int4>(V(::builder->CreateCall(cvtps2dq, val.value)));
John Bauman89401822014-05-06 15:04:28 -04005993 }
5994
John Bauman19bac1e2014-05-06 15:23:49 -04005995 RValue<Float> rcpss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005996 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005997 llvm::Function *rcpss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rcp_ss);
John Bauman89401822014-05-06 15:04:28 -04005998
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04005999 Value *vector = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006000
Nicolas Capense95d5342016-09-30 11:37:28 -04006001 return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rcpss, vector)), Float::getType(), 0));
John Bauman89401822014-05-06 15:04:28 -04006002 }
6003
John Bauman19bac1e2014-05-06 15:23:49 -04006004 RValue<Float> sqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006005 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006006 llvm::Function *sqrtss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_sqrt_ss);
John Bauman89401822014-05-06 15:04:28 -04006007
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006008 Value *vector = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006009
Nicolas Capense95d5342016-09-30 11:37:28 -04006010 return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(sqrtss, vector)), Float::getType(), 0));
John Bauman89401822014-05-06 15:04:28 -04006011 }
6012
John Bauman19bac1e2014-05-06 15:23:49 -04006013 RValue<Float> rsqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006014 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006015 llvm::Function *rsqrtss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rsqrt_ss);
John Bauman66b8ab22014-05-06 15:57:45 -04006016
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006017 Value *vector = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), val.value, 0);
John Bauman89401822014-05-06 15:04:28 -04006018
Nicolas Capense95d5342016-09-30 11:37:28 -04006019 return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rsqrtss, vector)), Float::getType(), 0));
John Bauman89401822014-05-06 15:04:28 -04006020 }
6021
John Bauman19bac1e2014-05-06 15:23:49 -04006022 RValue<Float4> rcpps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006023 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006024 llvm::Function *rcpps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rcp_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006025
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006026 return RValue<Float4>(V(::builder->CreateCall(rcpps, val.value)));
John Bauman89401822014-05-06 15:04:28 -04006027 }
6028
John Bauman19bac1e2014-05-06 15:23:49 -04006029 RValue<Float4> sqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006030 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006031 llvm::Function *sqrtps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_sqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006032
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006033 return RValue<Float4>(V(::builder->CreateCall(sqrtps, val.value)));
John Bauman89401822014-05-06 15:04:28 -04006034 }
6035
John Bauman19bac1e2014-05-06 15:23:49 -04006036 RValue<Float4> rsqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006037 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006038 llvm::Function *rsqrtps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rsqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006039
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006040 return RValue<Float4>(V(::builder->CreateCall(rsqrtps, val.value)));
John Bauman89401822014-05-06 15:04:28 -04006041 }
6042
John Bauman19bac1e2014-05-06 15:23:49 -04006043 RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006044 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006045 llvm::Function *maxps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_max_ps);
John Bauman89401822014-05-06 15:04:28 -04006046
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006047 return RValue<Float4>(V(::builder->CreateCall2(maxps, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006048 }
6049
John Bauman19bac1e2014-05-06 15:23:49 -04006050 RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006051 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006052 llvm::Function *minps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_min_ps);
John Bauman89401822014-05-06 15:04:28 -04006053
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006054 return RValue<Float4>(V(::builder->CreateCall2(minps, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006055 }
6056
John Bauman19bac1e2014-05-06 15:23:49 -04006057 RValue<Float> roundss(RValue<Float> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006058 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006059 llvm::Function *roundss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_round_ss);
John Bauman89401822014-05-06 15:04:28 -04006060
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006061 Value *undef = V(llvm::UndefValue::get(T(Float4::getType())));
John Bauman89401822014-05-06 15:04:28 -04006062 Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
6063
Nicolas Capense95d5342016-09-30 11:37:28 -04006064 return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(roundss, undef, vector, V(Nucleus::createConstantInt(imm)))), Float::getType(), 0));
John Bauman89401822014-05-06 15:04:28 -04006065 }
6066
John Bauman19bac1e2014-05-06 15:23:49 -04006067 RValue<Float> floorss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006068 {
6069 return roundss(val, 1);
6070 }
6071
John Bauman19bac1e2014-05-06 15:23:49 -04006072 RValue<Float> ceilss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006073 {
6074 return roundss(val, 2);
6075 }
6076
John Bauman19bac1e2014-05-06 15:23:49 -04006077 RValue<Float4> roundps(RValue<Float4> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006078 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006079 llvm::Function *roundps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_round_ps);
John Bauman89401822014-05-06 15:04:28 -04006080
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006081 return RValue<Float4>(V(::builder->CreateCall2(roundps, val.value, V(Nucleus::createConstantInt(imm)))));
John Bauman89401822014-05-06 15:04:28 -04006082 }
6083
John Bauman19bac1e2014-05-06 15:23:49 -04006084 RValue<Float4> floorps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006085 {
6086 return roundps(val, 1);
6087 }
6088
John Bauman19bac1e2014-05-06 15:23:49 -04006089 RValue<Float4> ceilps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006090 {
6091 return roundps(val, 2);
6092 }
6093
Alexis Hetu0f448072016-03-18 10:56:08 -04006094 RValue<Int4> pabsd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04006095 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006096 llvm::Function *pabsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_ssse3_pabs_d_128);
John Bauman89401822014-05-06 15:04:28 -04006097
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006098 return RValue<Int4>(V(::builder->CreateCall(pabsd, x.value)));
John Bauman89401822014-05-06 15:04:28 -04006099 }
6100
John Bauman19bac1e2014-05-06 15:23:49 -04006101 RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006102 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006103 llvm::Function *paddsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_padds_w);
John Bauman89401822014-05-06 15:04:28 -04006104
Nicolas Capens01a97962017-07-28 17:30:51 -04006105 return As<Short4>(V(::builder->CreateCall2(paddsw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006106 }
John Bauman66b8ab22014-05-06 15:57:45 -04006107
John Bauman19bac1e2014-05-06 15:23:49 -04006108 RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006109 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006110 llvm::Function *psubsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubs_w);
John Bauman89401822014-05-06 15:04:28 -04006111
Nicolas Capens01a97962017-07-28 17:30:51 -04006112 return As<Short4>(V(::builder->CreateCall2(psubsw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006113 }
6114
John Bauman19bac1e2014-05-06 15:23:49 -04006115 RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04006116 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006117 llvm::Function *paddusw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_paddus_w);
John Bauman89401822014-05-06 15:04:28 -04006118
Nicolas Capens01a97962017-07-28 17:30:51 -04006119 return As<UShort4>(V(::builder->CreateCall2(paddusw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006120 }
John Bauman66b8ab22014-05-06 15:57:45 -04006121
John Bauman19bac1e2014-05-06 15:23:49 -04006122 RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04006123 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006124 llvm::Function *psubusw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubus_w);
John Bauman89401822014-05-06 15:04:28 -04006125
Nicolas Capens01a97962017-07-28 17:30:51 -04006126 return As<UShort4>(V(::builder->CreateCall2(psubusw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006127 }
6128
John Bauman19bac1e2014-05-06 15:23:49 -04006129 RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04006130 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006131 llvm::Function *paddsb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_padds_b);
John Bauman89401822014-05-06 15:04:28 -04006132
Nicolas Capens01a97962017-07-28 17:30:51 -04006133 return As<SByte8>(V(::builder->CreateCall2(paddsb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006134 }
John Bauman66b8ab22014-05-06 15:57:45 -04006135
John Bauman19bac1e2014-05-06 15:23:49 -04006136 RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04006137 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006138 llvm::Function *psubsb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubs_b);
John Bauman89401822014-05-06 15:04:28 -04006139
Nicolas Capens01a97962017-07-28 17:30:51 -04006140 return As<SByte8>(V(::builder->CreateCall2(psubsb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006141 }
John Bauman66b8ab22014-05-06 15:57:45 -04006142
John Bauman19bac1e2014-05-06 15:23:49 -04006143 RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04006144 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006145 llvm::Function *paddusb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_paddus_b);
John Bauman89401822014-05-06 15:04:28 -04006146
Nicolas Capens01a97962017-07-28 17:30:51 -04006147 return As<Byte8>(V(::builder->CreateCall2(paddusb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006148 }
John Bauman66b8ab22014-05-06 15:57:45 -04006149
John Bauman19bac1e2014-05-06 15:23:49 -04006150 RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04006151 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006152 llvm::Function *psubusb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubus_b);
John Bauman89401822014-05-06 15:04:28 -04006153
Nicolas Capens01a97962017-07-28 17:30:51 -04006154 return As<Byte8>(V(::builder->CreateCall2(psubusb, x.value, y.value)));
John Bauman19bac1e2014-05-06 15:23:49 -04006155 }
6156
6157 RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04006158 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006159 llvm::Function *pavgw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pavg_w);
John Bauman89401822014-05-06 15:04:28 -04006160
Nicolas Capens01a97962017-07-28 17:30:51 -04006161 return As<UShort4>(V(::builder->CreateCall2(pavgw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006162 }
6163
John Bauman19bac1e2014-05-06 15:23:49 -04006164 RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006165 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006166 llvm::Function *pmaxsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmaxs_w);
John Bauman89401822014-05-06 15:04:28 -04006167
Nicolas Capens01a97962017-07-28 17:30:51 -04006168 return As<Short4>(V(::builder->CreateCall2(pmaxsw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006169 }
6170
John Bauman19bac1e2014-05-06 15:23:49 -04006171 RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006172 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006173 llvm::Function *pminsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmins_w);
John Bauman89401822014-05-06 15:04:28 -04006174
Nicolas Capens01a97962017-07-28 17:30:51 -04006175 return As<Short4>(V(::builder->CreateCall2(pminsw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006176 }
6177
John Bauman19bac1e2014-05-06 15:23:49 -04006178 RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006179 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006180 llvm::Function *pcmpgtw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpgt_w);
John Bauman89401822014-05-06 15:04:28 -04006181
Nicolas Capens01a97962017-07-28 17:30:51 -04006182 return As<Short4>(V(::builder->CreateCall2(pcmpgtw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006183 }
6184
John Bauman19bac1e2014-05-06 15:23:49 -04006185 RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006186 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006187 llvm::Function *pcmpeqw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpeq_w);
John Bauman89401822014-05-06 15:04:28 -04006188
Nicolas Capens01a97962017-07-28 17:30:51 -04006189 return As<Short4>(V(::builder->CreateCall2(pcmpeqw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006190 }
6191
John Bauman19bac1e2014-05-06 15:23:49 -04006192 RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04006193 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006194 llvm::Function *pcmpgtb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpgt_b);
John Bauman89401822014-05-06 15:04:28 -04006195
Nicolas Capens01a97962017-07-28 17:30:51 -04006196 return As<Byte8>(V(::builder->CreateCall2(pcmpgtb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006197 }
6198
John Bauman19bac1e2014-05-06 15:23:49 -04006199 RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04006200 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006201 llvm::Function *pcmpeqb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpeq_b);
John Bauman89401822014-05-06 15:04:28 -04006202
Nicolas Capens01a97962017-07-28 17:30:51 -04006203 return As<Byte8>(V(::builder->CreateCall2(pcmpeqb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006204 }
6205
John Bauman19bac1e2014-05-06 15:23:49 -04006206 RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04006207 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006208 llvm::Function *packssdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packssdw_128);
John Bauman89401822014-05-06 15:04:28 -04006209
Nicolas Capens01a97962017-07-28 17:30:51 -04006210 return As<Short4>(V(::builder->CreateCall2(packssdw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006211 }
6212
John Bauman19bac1e2014-05-06 15:23:49 -04006213 RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04006214 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04006215 llvm::Function *packssdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packssdw_128);
John Bauman89401822014-05-06 15:04:28 -04006216
Nicolas Capens9e013d42017-07-28 17:26:14 -04006217 return RValue<Short8>(V(::builder->CreateCall2(packssdw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006218 }
6219
John Bauman19bac1e2014-05-06 15:23:49 -04006220 RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006221 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006222 llvm::Function *packsswb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packsswb_128);
John Bauman89401822014-05-06 15:04:28 -04006223
Nicolas Capens01a97962017-07-28 17:30:51 -04006224 return As<SByte8>(V(::builder->CreateCall2(packsswb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006225 }
6226
Nicolas Capens33438a62017-09-27 11:47:35 -04006227 RValue<Byte8> packuswb(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006228 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006229 llvm::Function *packuswb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packuswb_128);
John Bauman89401822014-05-06 15:04:28 -04006230
Nicolas Capens01a97962017-07-28 17:30:51 -04006231 return As<Byte8>(V(::builder->CreateCall2(packuswb, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006232 }
6233
Nicolas Capens3e7062b2017-01-17 14:01:33 -05006234 RValue<UShort8> packusdw(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04006235 {
6236 if(CPUID::supportsSSE4_1())
6237 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006238 llvm::Function *packusdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_packusdw);
John Bauman66b8ab22014-05-06 15:57:45 -04006239
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006240 return RValue<UShort8>(V(::builder->CreateCall2(packusdw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006241 }
6242 else
6243 {
Nicolas Capens3e7062b2017-01-17 14:01:33 -05006244 RValue<Int4> bx = (x & ~(x >> 31)) - Int4(0x8000);
6245 RValue<Int4> by = (y & ~(y >> 31)) - Int4(0x8000);
6246
6247 return As<UShort8>(packssdw(bx, by) + Short8(0x8000u));
John Bauman89401822014-05-06 15:04:28 -04006248 }
6249 }
6250
John Bauman19bac1e2014-05-06 15:23:49 -04006251 RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006252 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006253 llvm::Function *psrlw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrli_w);
John Bauman89401822014-05-06 15:04:28 -04006254
Nicolas Capens01a97962017-07-28 17:30:51 -04006255 return As<UShort4>(V(::builder->CreateCall2(psrlw, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006256 }
6257
John Bauman19bac1e2014-05-06 15:23:49 -04006258 RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006259 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006260 llvm::Function *psrlw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrli_w);
John Bauman89401822014-05-06 15:04:28 -04006261
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006262 return RValue<UShort8>(V(::builder->CreateCall2(psrlw, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006263 }
6264
John Bauman19bac1e2014-05-06 15:23:49 -04006265 RValue<Short4> psraw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006266 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006267 llvm::Function *psraw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrai_w);
John Bauman89401822014-05-06 15:04:28 -04006268
Nicolas Capens01a97962017-07-28 17:30:51 -04006269 return As<Short4>(V(::builder->CreateCall2(psraw, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006270 }
6271
John Bauman19bac1e2014-05-06 15:23:49 -04006272 RValue<Short8> psraw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006273 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006274 llvm::Function *psraw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrai_w);
John Bauman89401822014-05-06 15:04:28 -04006275
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006276 return RValue<Short8>(V(::builder->CreateCall2(psraw, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006277 }
6278
John Bauman19bac1e2014-05-06 15:23:49 -04006279 RValue<Short4> psllw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006280 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006281 llvm::Function *psllw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pslli_w);
John Bauman89401822014-05-06 15:04:28 -04006282
Nicolas Capens01a97962017-07-28 17:30:51 -04006283 return As<Short4>(V(::builder->CreateCall2(psllw, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006284 }
6285
John Bauman19bac1e2014-05-06 15:23:49 -04006286 RValue<Short8> psllw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006287 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006288 llvm::Function *psllw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pslli_w);
John Bauman89401822014-05-06 15:04:28 -04006289
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006290 return RValue<Short8>(V(::builder->CreateCall2(psllw, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006291 }
6292
John Bauman19bac1e2014-05-06 15:23:49 -04006293 RValue<Int2> pslld(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006294 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006295 llvm::Function *pslld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pslli_d);
John Bauman89401822014-05-06 15:04:28 -04006296
Nicolas Capens01a97962017-07-28 17:30:51 -04006297 return As<Int2>(V(::builder->CreateCall2(pslld, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006298 }
6299
John Bauman19bac1e2014-05-06 15:23:49 -04006300 RValue<Int4> pslld(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006301 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04006302 llvm::Function *pslld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pslli_d);
John Bauman89401822014-05-06 15:04:28 -04006303
Nicolas Capens9e013d42017-07-28 17:26:14 -04006304 return RValue<Int4>(V(::builder->CreateCall2(pslld, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006305 }
6306
John Bauman19bac1e2014-05-06 15:23:49 -04006307 RValue<Int2> psrad(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006308 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006309 llvm::Function *psrad = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrai_d);
John Bauman89401822014-05-06 15:04:28 -04006310
Nicolas Capens01a97962017-07-28 17:30:51 -04006311 return As<Int2>(V(::builder->CreateCall2(psrad, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006312 }
6313
John Bauman19bac1e2014-05-06 15:23:49 -04006314 RValue<Int4> psrad(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006315 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04006316 llvm::Function *psrad = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrai_d);
John Bauman89401822014-05-06 15:04:28 -04006317
Nicolas Capens9e013d42017-07-28 17:26:14 -04006318 return RValue<Int4>(V(::builder->CreateCall2(psrad, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006319 }
6320
John Bauman19bac1e2014-05-06 15:23:49 -04006321 RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006322 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006323 llvm::Function *psrld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrli_d);
John Bauman89401822014-05-06 15:04:28 -04006324
Nicolas Capens01a97962017-07-28 17:30:51 -04006325 return As<UInt2>(V(::builder->CreateCall2(psrld, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006326 }
6327
John Bauman19bac1e2014-05-06 15:23:49 -04006328 RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04006329 {
Nicolas Capens9e013d42017-07-28 17:26:14 -04006330 llvm::Function *psrld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrli_d);
John Bauman89401822014-05-06 15:04:28 -04006331
Nicolas Capens9e013d42017-07-28 17:26:14 -04006332 return RValue<UInt4>(V(::builder->CreateCall2(psrld, x.value, V(Nucleus::createConstantInt(y)))));
John Bauman89401822014-05-06 15:04:28 -04006333 }
6334
John Bauman19bac1e2014-05-06 15:23:49 -04006335 RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y)
6336 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006337 llvm::Function *pmaxsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmaxsd);
John Bauman19bac1e2014-05-06 15:23:49 -04006338
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006339 return RValue<Int4>(V(::builder->CreateCall2(pmaxsd, x.value, y.value)));
John Bauman19bac1e2014-05-06 15:23:49 -04006340 }
6341
6342 RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y)
6343 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006344 llvm::Function *pminsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pminsd);
John Bauman19bac1e2014-05-06 15:23:49 -04006345
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006346 return RValue<Int4>(V(::builder->CreateCall2(pminsd, x.value, y.value)));
John Bauman19bac1e2014-05-06 15:23:49 -04006347 }
6348
6349 RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y)
6350 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006351 llvm::Function *pmaxud = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmaxud);
John Bauman19bac1e2014-05-06 15:23:49 -04006352
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006353 return RValue<UInt4>(V(::builder->CreateCall2(pmaxud, x.value, y.value)));
John Bauman19bac1e2014-05-06 15:23:49 -04006354 }
6355
6356 RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y)
6357 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006358 llvm::Function *pminud = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pminud);
John Bauman19bac1e2014-05-06 15:23:49 -04006359
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006360 return RValue<UInt4>(V(::builder->CreateCall2(pminud, x.value, y.value)));
John Bauman19bac1e2014-05-06 15:23:49 -04006361 }
6362
6363 RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006364 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006365 llvm::Function *pmulhw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmulh_w);
John Bauman89401822014-05-06 15:04:28 -04006366
Nicolas Capens01a97962017-07-28 17:30:51 -04006367 return As<Short4>(V(::builder->CreateCall2(pmulhw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006368 }
6369
John Bauman19bac1e2014-05-06 15:23:49 -04006370 RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04006371 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006372 llvm::Function *pmulhuw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmulhu_w);
John Bauman89401822014-05-06 15:04:28 -04006373
Nicolas Capens01a97962017-07-28 17:30:51 -04006374 return As<UShort4>(V(::builder->CreateCall2(pmulhuw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006375 }
6376
John Bauman19bac1e2014-05-06 15:23:49 -04006377 RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04006378 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006379 llvm::Function *pmaddwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmadd_wd);
John Bauman89401822014-05-06 15:04:28 -04006380
Nicolas Capens01a97962017-07-28 17:30:51 -04006381 return As<Int2>(V(::builder->CreateCall2(pmaddwd, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006382 }
6383
John Bauman19bac1e2014-05-06 15:23:49 -04006384 RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04006385 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006386 llvm::Function *pmulhw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmulh_w);
John Bauman89401822014-05-06 15:04:28 -04006387
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006388 return RValue<Short8>(V(::builder->CreateCall2(pmulhw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006389 }
6390
John Bauman19bac1e2014-05-06 15:23:49 -04006391 RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04006392 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006393 llvm::Function *pmulhuw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmulhu_w);
John Bauman89401822014-05-06 15:04:28 -04006394
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006395 return RValue<UShort8>(V(::builder->CreateCall2(pmulhuw, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006396 }
6397
John Bauman19bac1e2014-05-06 15:23:49 -04006398 RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04006399 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006400 llvm::Function *pmaddwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmadd_wd);
John Bauman89401822014-05-06 15:04:28 -04006401
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006402 return RValue<Int4>(V(::builder->CreateCall2(pmaddwd, x.value, y.value)));
John Bauman89401822014-05-06 15:04:28 -04006403 }
6404
John Bauman19bac1e2014-05-06 15:23:49 -04006405 RValue<Int> movmskps(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006406 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006407 llvm::Function *movmskps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_movmsk_ps);
John Bauman89401822014-05-06 15:04:28 -04006408
Nicolas Capens2ab69ee2016-09-26 11:45:17 -04006409 return RValue<Int>(V(::builder->CreateCall(movmskps, x.value)));
John Bauman89401822014-05-06 15:04:28 -04006410 }
6411
John Bauman19bac1e2014-05-06 15:23:49 -04006412 RValue<Int> pmovmskb(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04006413 {
Nicolas Capens01a97962017-07-28 17:30:51 -04006414 llvm::Function *pmovmskb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmovmskb_128);
John Bauman89401822014-05-06 15:04:28 -04006415
Nicolas Capens01a97962017-07-28 17:30:51 -04006416 return RValue<Int>(V(::builder->CreateCall(pmovmskb, x.value))) & 0xFF;
John Bauman89401822014-05-06 15:04:28 -04006417 }
6418
Nicolas Capens01a97962017-07-28 17:30:51 -04006419 RValue<Int4> pmovzxbd(RValue<Byte16> x)
John Bauman89401822014-05-06 15:04:28 -04006420 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006421 llvm::Function *pmovzxbd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovzxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04006422
Nicolas Capens01a97962017-07-28 17:30:51 -04006423 return RValue<Int4>(V(::builder->CreateCall(pmovzxbd, x.value)));
John Bauman89401822014-05-06 15:04:28 -04006424 }
6425
Nicolas Capens01a97962017-07-28 17:30:51 -04006426 RValue<Int4> pmovsxbd(RValue<SByte16> x)
John Bauman89401822014-05-06 15:04:28 -04006427 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006428 llvm::Function *pmovsxbd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovsxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04006429
Nicolas Capens01a97962017-07-28 17:30:51 -04006430 return RValue<Int4>(V(::builder->CreateCall(pmovsxbd, x.value)));
John Bauman89401822014-05-06 15:04:28 -04006431 }
6432
Nicolas Capens01a97962017-07-28 17:30:51 -04006433 RValue<Int4> pmovzxwd(RValue<UShort8> x)
John Bauman89401822014-05-06 15:04:28 -04006434 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006435 llvm::Function *pmovzxwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovzxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04006436
Nicolas Capens01a97962017-07-28 17:30:51 -04006437 return RValue<Int4>(V(::builder->CreateCall(pmovzxwd, x.value)));
John Bauman89401822014-05-06 15:04:28 -04006438 }
6439
Nicolas Capens01a97962017-07-28 17:30:51 -04006440 RValue<Int4> pmovsxwd(RValue<Short8> x)
John Bauman89401822014-05-06 15:04:28 -04006441 {
Nicolas Capensfbf2bc52017-07-26 17:26:17 -04006442 llvm::Function *pmovsxwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovsxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04006443
Nicolas Capens01a97962017-07-28 17:30:51 -04006444 return RValue<Int4>(V(::builder->CreateCall(pmovsxwd, x.value)));
John Bauman89401822014-05-06 15:04:28 -04006445 }
6446 }
6447}