blob: 094481b2097e34bf1fc9a7264d73af80090c31cc [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001// SwiftShader Software Renderer
2//
John Bauman19bac1e2014-05-06 15:23:49 -04003// Copyright(c) 2005-2012 TransGaming Inc.
John Bauman89401822014-05-06 15:04:28 -04004//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#include "Nucleus.hpp"
13
14#include "llvm/Support/IRBuilder.h"
15#include "llvm/Function.h"
16#include "llvm/GlobalVariable.h"
17#include "llvm/Module.h"
18#include "llvm/LLVMContext.h"
19#include "llvm/Constants.h"
20#include "llvm/Intrinsics.h"
John Bauman66b8ab22014-05-06 15:57:45 -040021#include "llvm/PassManager.h"
John Bauman89401822014-05-06 15:04:28 -040022#include "llvm/Analysis/LoopPass.h"
23#include "llvm/Transforms/Scalar.h"
24#include "llvm/Target/TargetData.h"
John Bauman89401822014-05-06 15:04:28 -040025#include "llvm/Target/TargetOptions.h"
John Bauman19bac1e2014-05-06 15:23:49 -040026#include "llvm/Support/TargetSelect.h"
John Bauman89401822014-05-06 15:04:28 -040027#include "../lib/ExecutionEngine/JIT/JIT.h"
John Bauman89401822014-05-06 15:04:28 -040028
Nicolas Capensd946e0a2014-06-26 11:31:08 -040029#include "Routine.hpp"
Nicolas Capens2fb41102014-06-26 10:11:50 -040030#include "RoutineManager.hpp"
John Bauman89401822014-05-06 15:04:28 -040031#include "x86.hpp"
32#include "CPUID.hpp"
33#include "Thread.hpp"
34#include "Memory.hpp"
35
36#include <fstream>
37
Nicolas Capenscb122582014-05-06 23:34:44 -040038#if defined(__x86_64__) && defined(_WIN32)
John Bauman66b8ab22014-05-06 15:57:45 -040039extern "C" void X86CompilationCallback()
40{
41 assert(false); // UNIMPLEMENTED
42}
43#endif
44
John Bauman89401822014-05-06 15:04:28 -040045extern "C"
46{
47 bool (*CodeAnalystInitialize)() = 0;
48 void (*CodeAnalystCompleteJITLog)() = 0;
49 bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0;
50}
51
52namespace llvm
53{
54 extern bool JITEmitDebugInfo;
55}
56
57namespace sw
58{
59 Optimization optimization[10] = {InstructionCombining, Disabled};
60
61 using namespace llvm;
62
Nicolas Capens2fb41102014-06-26 10:11:50 -040063 RoutineManager *Nucleus::routineManager = 0;
John Bauman89401822014-05-06 15:04:28 -040064 ExecutionEngine *Nucleus::executionEngine = 0;
65 Builder *Nucleus::builder = 0;
66 LLVMContext *Nucleus::context = 0;
67 Module *Nucleus::module = 0;
68 llvm::Function *Nucleus::function = 0;
Nicolas Capensb7ea9842015-04-01 10:54:59 -040069 BackoffLock Nucleus::codegenMutex;
John Bauman89401822014-05-06 15:04:28 -040070
71 class Builder : public IRBuilder<>
72 {
73 };
74
John Bauman89401822014-05-06 15:04:28 -040075 Nucleus::Nucleus()
76 {
Nicolas Capensb7ea9842015-04-01 10:54:59 -040077 codegenMutex.lock(); // Reactor and LLVM are currently not thread safe
78
John Bauman19bac1e2014-05-06 15:23:49 -040079 InitializeNativeTarget();
John Bauman89401822014-05-06 15:04:28 -040080 JITEmitDebugInfo = false;
81
82 if(!context)
83 {
84 context = new LLVMContext();
85 }
86
87 module = new Module("", *context);
Nicolas Capens2fb41102014-06-26 10:11:50 -040088 routineManager = new RoutineManager();
John Bauman66b8ab22014-05-06 15:57:45 -040089
John Bauman89401822014-05-06 15:04:28 -040090 #if defined(__x86_64__)
91 const char *architecture = "x86-64";
92 #else
93 const char *architecture = "x86";
94 #endif
95
96 SmallVector<std::string, 1> MAttrs;
97 MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx");
98 MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov");
99 MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse");
100 MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2");
101 MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3");
102 MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3");
103 MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41");
104
John Bauman19bac1e2014-05-06 15:23:49 -0400105 std::string error;
106 TargetMachine *targetMachine = EngineBuilder::selectTarget(module, architecture, "", MAttrs, Reloc::Default, CodeModel::JITDefault, &error);
Nicolas Capens2fb41102014-06-26 10:11:50 -0400107 executionEngine = JIT::createJIT(module, 0, routineManager, CodeGenOpt::Aggressive, true, targetMachine);
John Bauman89401822014-05-06 15:04:28 -0400108
109 if(!builder)
110 {
111 builder = static_cast<Builder*>(new IRBuilder<>(*context));
112
John Bauman66b8ab22014-05-06 15:57:45 -0400113 #if defined(_WIN32)
114 HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll");
115 if(CodeAnalyst)
116 {
117 CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize");
118 CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog");
119 CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode");
120
121 CodeAnalystInitialize();
122 }
123 #endif
John Bauman89401822014-05-06 15:04:28 -0400124 }
125 }
126
127 Nucleus::~Nucleus()
128 {
129 delete executionEngine;
130 executionEngine = 0;
131
Nicolas Capens2fb41102014-06-26 10:11:50 -0400132 routineManager = 0;
John Bauman89401822014-05-06 15:04:28 -0400133 function = 0;
134 module = 0;
Nicolas Capensb7ea9842015-04-01 10:54:59 -0400135
136 codegenMutex.unlock();
John Bauman89401822014-05-06 15:04:28 -0400137 }
138
139 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
140 {
John Bauman19bac1e2014-05-06 15:23:49 -0400141 if(builder->GetInsertBlock()->empty() || !builder->GetInsertBlock()->back().isTerminator())
142 {
John Bauman19bac1e2014-05-06 15:23:49 -0400143 Type *type = function->getReturnType();
144
145 if(type->isVoidTy())
146 {
147 createRetVoid();
148 }
149 else
150 {
151 createRet(UndefValue::get(type));
152 }
153 }
John Bauman89401822014-05-06 15:04:28 -0400154
155 if(false)
156 {
John Bauman66b8ab22014-05-06 15:57:45 -0400157 std::string error;
158 raw_fd_ostream file("llvm-dump-unopt.txt", error);
159 module->print(file, 0);
John Bauman89401822014-05-06 15:04:28 -0400160 }
161
162 if(runOptimizations)
163 {
164 optimize();
165 }
166
167 if(false)
168 {
John Bauman66b8ab22014-05-06 15:57:45 -0400169 std::string error;
170 raw_fd_ostream file("llvm-dump-opt.txt", error);
171 module->print(file, 0);
John Bauman89401822014-05-06 15:04:28 -0400172 }
173
174 void *entry = executionEngine->getPointerToFunction(function);
Nicolas Capensd946e0a2014-06-26 11:31:08 -0400175 Routine *routine = routineManager->acquireRoutine(entry);
John Bauman89401822014-05-06 15:04:28 -0400176
177 if(CodeAnalystLogJITCode)
178 {
Nicolas Capensd946e0a2014-06-26 11:31:08 -0400179 CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name);
John Bauman89401822014-05-06 15:04:28 -0400180 }
181
182 return routine;
183 }
184
185 void Nucleus::optimize()
186 {
187 static PassManager *passManager = 0;
John Bauman66b8ab22014-05-06 15:57:45 -0400188
John Bauman89401822014-05-06 15:04:28 -0400189 if(!passManager)
190 {
191 passManager = new PassManager();
192
193 UnsafeFPMath = true;
194 // NoInfsFPMath = true;
195 // NoNaNsFPMath = true;
196
197 passManager->add(new TargetData(*executionEngine->getTargetData()));
198 passManager->add(createScalarReplAggregatesPass());
199
200 for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++)
201 {
202 switch(optimization[pass])
203 {
204 case Disabled: break;
205 case CFGSimplification: passManager->add(createCFGSimplificationPass()); break;
206 case LICM: passManager->add(createLICMPass()); break;
207 case AggressiveDCE: passManager->add(createAggressiveDCEPass()); break;
208 case GVN: passManager->add(createGVNPass()); break;
209 case InstructionCombining: passManager->add(createInstructionCombiningPass()); break;
210 case Reassociate: passManager->add(createReassociatePass()); break;
211 case DeadStoreElimination: passManager->add(createDeadStoreEliminationPass()); break;
212 case SCCP: passManager->add(createSCCPPass()); break;
John Bauman19bac1e2014-05-06 15:23:49 -0400213 case ScalarReplAggregates: passManager->add(createScalarReplAggregatesPass()); break;
John Bauman89401822014-05-06 15:04:28 -0400214 default:
215 assert(false);
216 }
217 }
218 }
219
220 passManager->run(*module);
221 }
222
223 void Nucleus::setFunction(llvm::Function *function)
224 {
225 Nucleus::function = function;
226
John Bauman19bac1e2014-05-06 15:23:49 -0400227 builder->SetInsertPoint(BasicBlock::Create(*context, "", function));
John Bauman89401822014-05-06 15:04:28 -0400228 }
229
230 Module *Nucleus::getModule()
231 {
232 return module;
233 }
234
John Bauman89401822014-05-06 15:04:28 -0400235 llvm::Function *Nucleus::getFunction()
236 {
237 return function;
238 }
239
240 llvm::LLVMContext *Nucleus::getContext()
241 {
242 return context;
243 }
244
John Bauman19bac1e2014-05-06 15:23:49 -0400245 Value *Nucleus::allocateStackVariable(Type *type, int arraySize)
John Bauman89401822014-05-06 15:04:28 -0400246 {
247 // Need to allocate it in the entry block for mem2reg to work
248 llvm::Function *function = getFunction();
249 BasicBlock &entryBlock = function->getEntryBlock();
250
251 Instruction *declaration;
252
253 if(arraySize)
254 {
255 declaration = new AllocaInst(type, Nucleus::createConstantInt(arraySize));
256 }
257 else
258 {
259 declaration = new AllocaInst(type, (Value*)0);
260 }
261
262 entryBlock.getInstList().push_front(declaration);
263
264 return declaration;
265 }
266
267 BasicBlock *Nucleus::createBasicBlock()
268 {
John Bauman19bac1e2014-05-06 15:23:49 -0400269 return BasicBlock::Create(*context, "", Nucleus::getFunction());
John Bauman89401822014-05-06 15:04:28 -0400270 }
271
272 BasicBlock *Nucleus::getInsertBlock()
273 {
274 return builder->GetInsertBlock();
275 }
276
277 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
278 {
John Bauman19bac1e2014-05-06 15:23:49 -0400279 // assert(builder->GetInsertBlock()->back().isTerminator());
John Bauman89401822014-05-06 15:04:28 -0400280 return builder->SetInsertPoint(basicBlock);
281 }
282
283 BasicBlock *Nucleus::getPredecessor(BasicBlock *basicBlock)
284 {
285 return *pred_begin(basicBlock);
286 }
287
John Bauman19bac1e2014-05-06 15:23:49 -0400288 llvm::Function *Nucleus::createFunction(llvm::Type *ReturnType, std::vector<llvm::Type*> &Params)
John Bauman89401822014-05-06 15:04:28 -0400289 {
290 llvm::FunctionType *functionType = llvm::FunctionType::get(ReturnType, Params, false);
291 llvm::Function *function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", Nucleus::getModule());
292 function->setCallingConv(llvm::CallingConv::C);
293
294 return function;
295 }
296
297 llvm::Argument *Nucleus::getArgument(llvm::Function *function, unsigned int index)
298 {
299 llvm::Function::arg_iterator args = function->arg_begin();
300
301 while(index)
302 {
303 args++;
304 index--;
305 }
306
307 return &*args;
308 }
309
310 Value *Nucleus::createRetVoid()
311 {
John Bauman66b8ab22014-05-06 15:57:45 -0400312 x86::emms();
313
John Bauman89401822014-05-06 15:04:28 -0400314 return builder->CreateRetVoid();
315 }
316
317 Value *Nucleus::createRet(Value *V)
318 {
John Bauman66b8ab22014-05-06 15:57:45 -0400319 x86::emms();
320
John Bauman89401822014-05-06 15:04:28 -0400321 return builder->CreateRet(V);
322 }
323
324 Value *Nucleus::createBr(BasicBlock *dest)
325 {
326 return builder->CreateBr(dest);
327 }
328
329 Value *Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
330 {
331 return builder->CreateCondBr(cond, ifTrue, ifFalse);
332 }
333
334 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
335 {
336 return builder->CreateAdd(lhs, rhs);
337 }
338
339 Value *Nucleus::createSub(Value *lhs, Value *rhs)
340 {
341 return builder->CreateSub(lhs, rhs);
342 }
343
344 Value *Nucleus::createMul(Value *lhs, Value *rhs)
345 {
346 return builder->CreateMul(lhs, rhs);
347 }
348
349 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
350 {
351 return builder->CreateUDiv(lhs, rhs);
352 }
353
354 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
355 {
356 return builder->CreateSDiv(lhs, rhs);
357 }
358
359 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
360 {
361 return builder->CreateFAdd(lhs, rhs);
362 }
363
364 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
365 {
366 return builder->CreateFSub(lhs, rhs);
367 }
368
369 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
370 {
371 return builder->CreateFMul(lhs, rhs);
372 }
373
374 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
375 {
376 return builder->CreateFDiv(lhs, rhs);
377 }
378
379 Value *Nucleus::createURem(Value *lhs, Value *rhs)
380 {
381 return builder->CreateURem(lhs, rhs);
382 }
383
384 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
385 {
386 return builder->CreateSRem(lhs, rhs);
387 }
388
389 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
390 {
391 return builder->CreateFRem(lhs, rhs);
392 }
393
394 Value *Nucleus::createShl(Value *lhs, Value *rhs)
395 {
396 return builder->CreateShl(lhs, rhs);
397 }
398
399 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
400 {
401 return builder->CreateLShr(lhs, rhs);
402 }
403
404 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
405 {
406 return builder->CreateAShr(lhs, rhs);
407 }
408
409 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
410 {
411 return builder->CreateAnd(lhs, rhs);
412 }
413
414 Value *Nucleus::createOr(Value *lhs, Value *rhs)
415 {
416 return builder->CreateOr(lhs, rhs);
417 }
418
419 Value *Nucleus::createXor(Value *lhs, Value *rhs)
420 {
421 return builder->CreateXor(lhs, rhs);
422 }
423
424 Value *Nucleus::createNeg(Value *V)
425 {
426 return builder->CreateNeg(V);
427 }
428
429 Value *Nucleus::createFNeg(Value *V)
430 {
431 return builder->CreateFNeg(V);
432 }
433
434 Value *Nucleus::createNot(Value *V)
435 {
436 return builder->CreateNot(V);
437 }
438
439 Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align)
440 {
John Bauman19bac1e2014-05-06 15:23:49 -0400441 return builder->Insert(new LoadInst(ptr, "", isVolatile, align));
John Bauman89401822014-05-06 15:04:28 -0400442 }
443
444 Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align)
445 {
446 return builder->Insert(new StoreInst(value, ptr, isVolatile, align));
447 }
448
449 Value *Nucleus::createGEP(Value *ptr, Value *index)
450 {
451 return builder->CreateGEP(ptr, index);
452 }
453
John Bauman19bac1e2014-05-06 15:23:49 -0400454 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
455 {
456 return builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, value, SequentiallyConsistent);
457 }
458
459 Value *Nucleus::createTrunc(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400460 {
461 return builder->CreateTrunc(V, destType);
462 }
463
John Bauman19bac1e2014-05-06 15:23:49 -0400464 Value *Nucleus::createZExt(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400465 {
466 return builder->CreateZExt(V, destType);
467 }
468
John Bauman19bac1e2014-05-06 15:23:49 -0400469 Value *Nucleus::createSExt(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400470 {
471 return builder->CreateSExt(V, destType);
472 }
473
John Bauman19bac1e2014-05-06 15:23:49 -0400474 Value *Nucleus::createFPToUI(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400475 {
476 return builder->CreateFPToUI(V, destType);
477 }
478
John Bauman19bac1e2014-05-06 15:23:49 -0400479 Value *Nucleus::createFPToSI(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400480 {
481 return builder->CreateFPToSI(V, destType);
482 }
483
John Bauman19bac1e2014-05-06 15:23:49 -0400484 Value *Nucleus::createUIToFP(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400485 {
486 return builder->CreateUIToFP(V, destType);
487 }
488
John Bauman19bac1e2014-05-06 15:23:49 -0400489 Value *Nucleus::createSIToFP(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400490 {
491 return builder->CreateSIToFP(V, destType);
492 }
493
John Bauman19bac1e2014-05-06 15:23:49 -0400494 Value *Nucleus::createFPTrunc(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400495 {
496 return builder->CreateFPTrunc(V, destType);
497 }
498
John Bauman19bac1e2014-05-06 15:23:49 -0400499 Value *Nucleus::createFPExt(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400500 {
501 return builder->CreateFPExt(V, destType);
502 }
503
John Bauman19bac1e2014-05-06 15:23:49 -0400504 Value *Nucleus::createPtrToInt(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400505 {
506 return builder->CreatePtrToInt(V, destType);
507 }
508
John Bauman19bac1e2014-05-06 15:23:49 -0400509 Value *Nucleus::createIntToPtr(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400510 {
511 return builder->CreateIntToPtr(V, destType);
512 }
513
John Bauman19bac1e2014-05-06 15:23:49 -0400514 Value *Nucleus::createBitCast(Value *V, Type *destType)
John Bauman89401822014-05-06 15:04:28 -0400515 {
516 return builder->CreateBitCast(V, destType);
517 }
518
John Bauman19bac1e2014-05-06 15:23:49 -0400519 Value *Nucleus::createIntCast(Value *V, Type *destType, bool isSigned)
John Bauman89401822014-05-06 15:04:28 -0400520 {
521 return builder->CreateIntCast(V, destType, isSigned);
522 }
523
524 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
525 {
526 return builder->CreateICmpEQ(lhs, rhs);
527 }
528
529 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
530 {
531 return builder->CreateICmpNE(lhs, rhs);
532 }
533
534 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
535 {
536 return builder->CreateICmpUGT(lhs, rhs);
537 }
538
539 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
540 {
541 return builder->CreateICmpUGE(lhs, rhs);
542 }
543
544 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
545 {
546 return builder->CreateICmpULT(lhs, rhs);
547 }
548
549 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
550 {
551 return builder->CreateICmpULE(lhs, rhs);
552 }
553
554 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
555 {
556 return builder->CreateICmpSGT(lhs, rhs);
557 }
558
559 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
560 {
561 return builder->CreateICmpSGE(lhs, rhs);
562 }
563
564 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
565 {
566 return builder->CreateICmpSLT(lhs, rhs);
567 }
568
569 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
570 {
571 return builder->CreateICmpSLE(lhs, rhs);
572 }
573
574 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
575 {
576 return builder->CreateFCmpOEQ(lhs, rhs);
577 }
578
579 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
580 {
581 return builder->CreateFCmpOGT(lhs, rhs);
582 }
583
584 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
585 {
586 return builder->CreateFCmpOGE(lhs, rhs);
587 }
588
589 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
590 {
591 return builder->CreateFCmpOLT(lhs, rhs);
592 }
593
594 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
595 {
596 return builder->CreateFCmpOLE(lhs, rhs);
597 }
598
599 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
600 {
601 return builder->CreateFCmpONE(lhs, rhs);
602 }
603
604 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
605 {
606 return builder->CreateFCmpORD(lhs, rhs);
607 }
608
609 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
610 {
611 return builder->CreateFCmpUNO(lhs, rhs);
612 }
613
614 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
615 {
616 return builder->CreateFCmpUEQ(lhs, rhs);
617 }
618
619 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
620 {
621 return builder->CreateFCmpUGT(lhs, rhs);
622 }
623
624 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
625 {
626 return builder->CreateFCmpUGE(lhs, rhs);
627 }
628
629 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
630 {
631 return builder->CreateFCmpULT(lhs, rhs);
632 }
633
634 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
635 {
636 return builder->CreateFCmpULE(lhs, rhs);
637 }
638
639 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
640 {
641 return builder->CreateFCmpULE(lhs, rhs);
642 }
643
644 Value *Nucleus::createCall(Value *callee)
645 {
646 return builder->CreateCall(callee);
647 }
648
649 Value *Nucleus::createCall(Value *callee, Value *arg)
650 {
651 return builder->CreateCall(callee, arg);
652 }
653
654 Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2)
655 {
656 return builder->CreateCall2(callee, arg1, arg2);
657 }
658
659 Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3)
660 {
661 return builder->CreateCall3(callee, arg1, arg2, arg3);
662 }
663
664 Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3, Value *arg4)
665 {
666 return builder->CreateCall4(callee, arg1, arg2, arg3, arg4);
667 }
668
669 Value *Nucleus::createExtractElement(Value *vector, int index)
670 {
671 return builder->CreateExtractElement(vector, createConstantInt(index));
672 }
673
674 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
675 {
676 return builder->CreateInsertElement(vector, element, createConstantInt(index));
677 }
678
679 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, Value *mask)
680 {
681 return builder->CreateShuffleVector(V1, V2, mask);
682 }
683
684 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
685 {
686 return builder->CreateSelect(C, ifTrue, ifFalse);
687 }
688
689 Value *Nucleus::createSwitch(llvm::Value *V, llvm::BasicBlock *Dest, unsigned NumCases)
690 {
691 return builder->CreateSwitch(V, Dest, NumCases);
692 }
693
694 void Nucleus::addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch)
695 {
696 static_cast<SwitchInst*>(Switch)->addCase(Nucleus::createConstantInt(Case), Branch);
697 }
698
699 Value *Nucleus::createUnreachable()
700 {
701 return builder->CreateUnreachable();
702 }
703
704 Value *Nucleus::createSwizzle(Value *val, unsigned char select)
705 {
706 Constant *swizzle[4];
707 swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03);
708 swizzle[1] = Nucleus::createConstantInt((select >> 2) & 0x03);
709 swizzle[2] = Nucleus::createConstantInt((select >> 4) & 0x03);
710 swizzle[3] = Nucleus::createConstantInt((select >> 6) & 0x03);
711
712 Value *shuffle = Nucleus::createShuffleVector(val, UndefValue::get(val->getType()), Nucleus::createConstantVector(swizzle, 4));
713
714 return shuffle;
715 }
716
717 Value *Nucleus::createMask(Value *lhs, Value *rhs, unsigned char select)
718 {
719 bool mask[4] = {false, false, false, false};
720
721 mask[(select >> 0) & 0x03] = true;
722 mask[(select >> 2) & 0x03] = true;
723 mask[(select >> 4) & 0x03] = true;
724 mask[(select >> 6) & 0x03] = true;
725
726 Constant *swizzle[4];
727 swizzle[0] = Nucleus::createConstantInt(mask[0] ? 4 : 0);
728 swizzle[1] = Nucleus::createConstantInt(mask[1] ? 5 : 1);
729 swizzle[2] = Nucleus::createConstantInt(mask[2] ? 6 : 2);
730 swizzle[3] = Nucleus::createConstantInt(mask[3] ? 7 : 3);
731
732 Value *shuffle = Nucleus::createShuffleVector(lhs, rhs, Nucleus::createConstantVector(swizzle, 4));
733
734 return shuffle;
735 }
736
737 const llvm::GlobalValue *Nucleus::getGlobalValueAtAddress(void *Addr)
738 {
739 return executionEngine->getGlobalValueAtAddress(Addr);
740 }
741
742 void Nucleus::addGlobalMapping(const llvm::GlobalValue *GV, void *Addr)
743 {
744 executionEngine->addGlobalMapping(GV, Addr);
745 }
746
John Bauman19bac1e2014-05-06 15:23:49 -0400747 llvm::GlobalValue *Nucleus::createGlobalValue(llvm::Type *Ty, bool isConstant, unsigned int Align)
John Bauman89401822014-05-06 15:04:28 -0400748 {
John Bauman19bac1e2014-05-06 15:23:49 -0400749 llvm::GlobalValue *global = new llvm::GlobalVariable(*Nucleus::getModule(), Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, "");
John Bauman89401822014-05-06 15:04:28 -0400750 global->setAlignment(Align);
751
752 return global;
753 }
754
John Bauman19bac1e2014-05-06 15:23:49 -0400755 llvm::Type *Nucleus::getPointerType(llvm::Type *ElementType)
John Bauman89401822014-05-06 15:04:28 -0400756 {
757 return llvm::PointerType::get(ElementType, 0);
758 }
759
John Bauman19bac1e2014-05-06 15:23:49 -0400760 llvm::Constant *Nucleus::createNullValue(llvm::Type *Ty)
John Bauman89401822014-05-06 15:04:28 -0400761 {
762 return llvm::Constant::getNullValue(Ty);
763 }
764
John Bauman66b8ab22014-05-06 15:57:45 -0400765 llvm::ConstantInt *Nucleus::createConstantInt(int64_t i)
John Bauman89401822014-05-06 15:04:28 -0400766 {
767 return llvm::ConstantInt::get(Type::getInt64Ty(*context), i, true);
768 }
769
770 llvm::ConstantInt *Nucleus::createConstantInt(int i)
771 {
772 return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, true);
773 }
774
775 llvm::ConstantInt *Nucleus::createConstantInt(unsigned int i)
776 {
777 return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, false);
778 }
779
780 llvm::ConstantInt *Nucleus::createConstantBool(bool b)
781 {
782 return llvm::ConstantInt::get(Type::getInt1Ty(*context), b);
783 }
784
785 llvm::ConstantInt *Nucleus::createConstantByte(signed char i)
786 {
787 return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, true);
788 }
789
790 llvm::ConstantInt *Nucleus::createConstantByte(unsigned char i)
791 {
792 return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, false);
793 }
794
795 llvm::ConstantInt *Nucleus::createConstantShort(short i)
796 {
797 return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, true);
798 }
799
800 llvm::ConstantInt *Nucleus::createConstantShort(unsigned short i)
801 {
802 return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, false);
803 }
804
805 llvm::Constant *Nucleus::createConstantFloat(float x)
806 {
807 return ConstantFP::get(Float::getType(), x);
808 }
809
John Bauman19bac1e2014-05-06 15:23:49 -0400810 llvm::Value *Nucleus::createNullPointer(llvm::Type *Ty)
John Bauman89401822014-05-06 15:04:28 -0400811 {
812 return llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0));
813 }
814
John Bauman19bac1e2014-05-06 15:23:49 -0400815 llvm::Value *Nucleus::createConstantVector(llvm::Constant *const *Vals, unsigned NumVals)
John Bauman89401822014-05-06 15:04:28 -0400816 {
John Bauman19bac1e2014-05-06 15:23:49 -0400817 return llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(Vals, NumVals));
John Bauman89401822014-05-06 15:04:28 -0400818 }
819
John Bauman19bac1e2014-05-06 15:23:49 -0400820 Type *Void::getType()
John Bauman89401822014-05-06 15:04:28 -0400821 {
822 return Type::getVoidTy(*Nucleus::getContext());
823 }
824
John Bauman66b8ab22014-05-06 15:57:45 -0400825 LValue::LValue(llvm::Type *type, int arraySize)
826 {
827 address = Nucleus::allocateStackVariable(type, arraySize);
828 }
829
830 llvm::Value *LValue::loadValue(unsigned int alignment) const
831 {
832 return Nucleus::createLoad(address, false, alignment);
833 }
834
835 llvm::Value *LValue::storeValue(llvm::Value *value, unsigned int alignment) const
836 {
837 return Nucleus::createStore(value, address, false, alignment);
838 }
839
840 llvm::Value *LValue::getAddress(llvm::Value *index) const
841 {
842 return Nucleus::createGEP(address, index);
843 }
844
John Bauman19bac1e2014-05-06 15:23:49 -0400845 Type *MMX::getType()
846 {
847 return Type::getX86_MMXTy(*Nucleus::getContext());
848 }
849
John Bauman89401822014-05-06 15:04:28 -0400850 Bool::Bool(Argument *argument)
851 {
John Bauman66b8ab22014-05-06 15:57:45 -0400852 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -0400853 }
854
855 Bool::Bool()
856 {
John Bauman89401822014-05-06 15:04:28 -0400857 }
858
859 Bool::Bool(bool x)
860 {
John Bauman66b8ab22014-05-06 15:57:45 -0400861 storeValue(Nucleus::createConstantBool(x));
John Bauman89401822014-05-06 15:04:28 -0400862 }
863
John Bauman19bac1e2014-05-06 15:23:49 -0400864 Bool::Bool(RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -0400865 {
John Bauman66b8ab22014-05-06 15:57:45 -0400866 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400867 }
868
869 Bool::Bool(const Bool &rhs)
870 {
John Bauman66b8ab22014-05-06 15:57:45 -0400871 Value *value = rhs.loadValue();
872 storeValue(value);
873 }
John Bauman89401822014-05-06 15:04:28 -0400874
John Bauman66b8ab22014-05-06 15:57:45 -0400875 Bool::Bool(const Reference<Bool> &rhs)
876 {
877 Value *value = rhs.loadValue();
878 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400879 }
880
John Bauman19bac1e2014-05-06 15:23:49 -0400881 RValue<Bool> Bool::operator=(RValue<Bool> rhs) const
John Bauman89401822014-05-06 15:04:28 -0400882 {
John Bauman66b8ab22014-05-06 15:57:45 -0400883 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400884
885 return rhs;
886 }
887
888 RValue<Bool> Bool::operator=(const Bool &rhs) const
889 {
John Bauman66b8ab22014-05-06 15:57:45 -0400890 Value *value = rhs.loadValue();
891 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400892
893 return RValue<Bool>(value);
894 }
895
John Bauman66b8ab22014-05-06 15:57:45 -0400896 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) const
John Bauman89401822014-05-06 15:04:28 -0400897 {
John Bauman66b8ab22014-05-06 15:57:45 -0400898 Value *value = rhs.loadValue();
899 storeValue(value);
900
901 return RValue<Bool>(value);
John Bauman89401822014-05-06 15:04:28 -0400902 }
903
John Bauman19bac1e2014-05-06 15:23:49 -0400904 RValue<Bool> operator!(RValue<Bool> val)
John Bauman89401822014-05-06 15:04:28 -0400905 {
906 return RValue<Bool>(Nucleus::createNot(val.value));
907 }
908
John Bauman19bac1e2014-05-06 15:23:49 -0400909 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -0400910 {
911 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
912 }
913
John Bauman19bac1e2014-05-06 15:23:49 -0400914 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
John Bauman89401822014-05-06 15:04:28 -0400915 {
916 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
917 }
918
John Bauman19bac1e2014-05-06 15:23:49 -0400919 Type *Bool::getType()
John Bauman89401822014-05-06 15:04:28 -0400920 {
921 return Type::getInt1Ty(*Nucleus::getContext());
922 }
923
924 Byte::Byte(Argument *argument)
925 {
John Bauman66b8ab22014-05-06 15:57:45 -0400926 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -0400927 }
928
John Bauman19bac1e2014-05-06 15:23:49 -0400929 Byte::Byte(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -0400930 {
John Bauman89401822014-05-06 15:04:28 -0400931 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
932
John Bauman66b8ab22014-05-06 15:57:45 -0400933 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -0400934 }
935
Alexis Hetu77dfab42015-11-23 13:31:22 -0500936 Byte::Byte(RValue<UInt> cast)
937 {
938 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
939
940 storeValue(integer);
941 }
942
943 Byte::Byte(RValue<UShort> cast)
944 {
945 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
946
947 storeValue(integer);
948 }
949
John Bauman89401822014-05-06 15:04:28 -0400950 Byte::Byte()
951 {
John Bauman89401822014-05-06 15:04:28 -0400952 }
953
954 Byte::Byte(int x)
955 {
John Bauman66b8ab22014-05-06 15:57:45 -0400956 storeValue(Nucleus::createConstantByte((unsigned char)x));
John Bauman89401822014-05-06 15:04:28 -0400957 }
958
959 Byte::Byte(unsigned char x)
960 {
John Bauman66b8ab22014-05-06 15:57:45 -0400961 storeValue(Nucleus::createConstantByte(x));
John Bauman89401822014-05-06 15:04:28 -0400962 }
963
John Bauman19bac1e2014-05-06 15:23:49 -0400964 Byte::Byte(RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -0400965 {
John Bauman66b8ab22014-05-06 15:57:45 -0400966 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400967 }
968
969 Byte::Byte(const Byte &rhs)
970 {
John Bauman66b8ab22014-05-06 15:57:45 -0400971 Value *value = rhs.loadValue();
972 storeValue(value);
973 }
John Bauman89401822014-05-06 15:04:28 -0400974
John Bauman66b8ab22014-05-06 15:57:45 -0400975 Byte::Byte(const Reference<Byte> &rhs)
976 {
977 Value *value = rhs.loadValue();
978 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400979 }
980
John Bauman19bac1e2014-05-06 15:23:49 -0400981 RValue<Byte> Byte::operator=(RValue<Byte> rhs) const
John Bauman89401822014-05-06 15:04:28 -0400982 {
John Bauman66b8ab22014-05-06 15:57:45 -0400983 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400984
985 return rhs;
986 }
987
988 RValue<Byte> Byte::operator=(const Byte &rhs) const
989 {
John Bauman66b8ab22014-05-06 15:57:45 -0400990 Value *value = rhs.loadValue();
991 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400992
993 return RValue<Byte>(value);
994 }
995
John Bauman66b8ab22014-05-06 15:57:45 -0400996 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) const
John Bauman89401822014-05-06 15:04:28 -0400997 {
John Bauman66b8ab22014-05-06 15:57:45 -0400998 Value *value = rhs.loadValue();
999 storeValue(value);
1000
1001 return RValue<Byte>(value);
John Bauman89401822014-05-06 15:04:28 -04001002 }
1003
John Bauman19bac1e2014-05-06 15:23:49 -04001004 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001005 {
1006 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1007 }
1008
John Bauman19bac1e2014-05-06 15:23:49 -04001009 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001010 {
1011 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1012 }
1013
John Bauman19bac1e2014-05-06 15:23:49 -04001014 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001015 {
1016 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1017 }
1018
John Bauman19bac1e2014-05-06 15:23:49 -04001019 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001020 {
1021 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1022 }
1023
John Bauman19bac1e2014-05-06 15:23:49 -04001024 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001025 {
1026 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1027 }
1028
John Bauman19bac1e2014-05-06 15:23:49 -04001029 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001030 {
1031 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1032 }
1033
John Bauman19bac1e2014-05-06 15:23:49 -04001034 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001035 {
1036 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1037 }
1038
John Bauman19bac1e2014-05-06 15:23:49 -04001039 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001040 {
1041 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1042 }
1043
John Bauman19bac1e2014-05-06 15:23:49 -04001044 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001045 {
1046 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1047 }
1048
John Bauman19bac1e2014-05-06 15:23:49 -04001049 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001050 {
1051 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1052 }
1053
John Bauman19bac1e2014-05-06 15:23:49 -04001054 RValue<Byte> operator+=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001055 {
1056 return lhs = lhs + rhs;
1057 }
1058
John Bauman19bac1e2014-05-06 15:23:49 -04001059 RValue<Byte> operator-=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001060 {
1061 return lhs = lhs - rhs;
1062 }
1063
John Bauman19bac1e2014-05-06 15:23:49 -04001064 RValue<Byte> operator*=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001065 {
1066 return lhs = lhs * rhs;
1067 }
1068
John Bauman19bac1e2014-05-06 15:23:49 -04001069 RValue<Byte> operator/=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001070 {
1071 return lhs = lhs / rhs;
1072 }
1073
John Bauman19bac1e2014-05-06 15:23:49 -04001074 RValue<Byte> operator%=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001075 {
1076 return lhs = lhs % rhs;
1077 }
1078
John Bauman19bac1e2014-05-06 15:23:49 -04001079 RValue<Byte> operator&=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001080 {
1081 return lhs = lhs & rhs;
1082 }
1083
John Bauman19bac1e2014-05-06 15:23:49 -04001084 RValue<Byte> operator|=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001085 {
1086 return lhs = lhs | rhs;
1087 }
1088
John Bauman19bac1e2014-05-06 15:23:49 -04001089 RValue<Byte> operator^=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001090 {
1091 return lhs = lhs ^ rhs;
1092 }
1093
John Bauman19bac1e2014-05-06 15:23:49 -04001094 RValue<Byte> operator<<=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001095 {
1096 return lhs = lhs << rhs;
1097 }
1098
John Bauman19bac1e2014-05-06 15:23:49 -04001099 RValue<Byte> operator>>=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001100 {
1101 return lhs = lhs >> rhs;
1102 }
1103
John Bauman19bac1e2014-05-06 15:23:49 -04001104 RValue<Byte> operator+(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001105 {
1106 return val;
1107 }
1108
John Bauman19bac1e2014-05-06 15:23:49 -04001109 RValue<Byte> operator-(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001110 {
1111 return RValue<Byte>(Nucleus::createNeg(val.value));
1112 }
1113
John Bauman19bac1e2014-05-06 15:23:49 -04001114 RValue<Byte> operator~(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001115 {
1116 return RValue<Byte>(Nucleus::createNot(val.value));
1117 }
1118
1119 RValue<Byte> operator++(const Byte &val, int) // Post-increment
1120 {
1121 RValue<Byte> res = val;
1122
1123 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001124 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001125
1126 return res;
1127 }
1128
1129 const Byte &operator++(const Byte &val) // Pre-increment
1130 {
John Bauman66b8ab22014-05-06 15:57:45 -04001131 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
1132 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001133
1134 return val;
1135 }
1136
1137 RValue<Byte> operator--(const Byte &val, int) // Post-decrement
1138 {
1139 RValue<Byte> res = val;
1140
1141 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001142 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001143
1144 return res;
1145 }
1146
1147 const Byte &operator--(const Byte &val) // Pre-decrement
1148 {
John Bauman66b8ab22014-05-06 15:57:45 -04001149 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
1150 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001151
1152 return val;
1153 }
1154
John Bauman19bac1e2014-05-06 15:23:49 -04001155 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001156 {
1157 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1158 }
1159
John Bauman19bac1e2014-05-06 15:23:49 -04001160 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001161 {
1162 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1163 }
1164
John Bauman19bac1e2014-05-06 15:23:49 -04001165 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001166 {
1167 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1168 }
1169
John Bauman19bac1e2014-05-06 15:23:49 -04001170 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001171 {
1172 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1173 }
1174
John Bauman19bac1e2014-05-06 15:23:49 -04001175 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001176 {
1177 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1178 }
1179
John Bauman19bac1e2014-05-06 15:23:49 -04001180 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001181 {
1182 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1183 }
1184
John Bauman19bac1e2014-05-06 15:23:49 -04001185 Type *Byte::getType()
John Bauman89401822014-05-06 15:04:28 -04001186 {
1187 return Type::getInt8Ty(*Nucleus::getContext());
1188 }
1189
1190 SByte::SByte(Argument *argument)
1191 {
John Bauman66b8ab22014-05-06 15:57:45 -04001192 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04001193 }
1194
Alexis Hetu77dfab42015-11-23 13:31:22 -05001195 SByte::SByte(RValue<Int> cast)
1196 {
1197 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1198
1199 storeValue(integer);
1200 }
1201
1202 SByte::SByte(RValue<Short> cast)
1203 {
1204 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1205
1206 storeValue(integer);
1207 }
1208
John Bauman89401822014-05-06 15:04:28 -04001209 SByte::SByte()
1210 {
John Bauman89401822014-05-06 15:04:28 -04001211 }
1212
1213 SByte::SByte(signed char x)
1214 {
John Bauman66b8ab22014-05-06 15:57:45 -04001215 storeValue(Nucleus::createConstantByte(x));
John Bauman89401822014-05-06 15:04:28 -04001216 }
1217
John Bauman19bac1e2014-05-06 15:23:49 -04001218 SByte::SByte(RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001219 {
John Bauman66b8ab22014-05-06 15:57:45 -04001220 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001221 }
1222
1223 SByte::SByte(const SByte &rhs)
1224 {
John Bauman66b8ab22014-05-06 15:57:45 -04001225 Value *value = rhs.loadValue();
1226 storeValue(value);
1227 }
John Bauman89401822014-05-06 15:04:28 -04001228
John Bauman66b8ab22014-05-06 15:57:45 -04001229 SByte::SByte(const Reference<SByte> &rhs)
1230 {
1231 Value *value = rhs.loadValue();
1232 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001233 }
1234
John Bauman19bac1e2014-05-06 15:23:49 -04001235 RValue<SByte> SByte::operator=(RValue<SByte> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001236 {
John Bauman66b8ab22014-05-06 15:57:45 -04001237 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001238
1239 return rhs;
1240 }
1241
1242 RValue<SByte> SByte::operator=(const SByte &rhs) const
1243 {
John Bauman66b8ab22014-05-06 15:57:45 -04001244 Value *value = rhs.loadValue();
1245 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001246
1247 return RValue<SByte>(value);
1248 }
1249
John Bauman66b8ab22014-05-06 15:57:45 -04001250 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001251 {
John Bauman66b8ab22014-05-06 15:57:45 -04001252 Value *value = rhs.loadValue();
1253 storeValue(value);
1254
1255 return RValue<SByte>(value);
John Bauman89401822014-05-06 15:04:28 -04001256 }
1257
John Bauman19bac1e2014-05-06 15:23:49 -04001258 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001259 {
1260 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1261 }
1262
John Bauman19bac1e2014-05-06 15:23:49 -04001263 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001264 {
1265 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1266 }
1267
John Bauman19bac1e2014-05-06 15:23:49 -04001268 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001269 {
1270 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1271 }
1272
John Bauman19bac1e2014-05-06 15:23:49 -04001273 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001274 {
1275 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1276 }
1277
John Bauman19bac1e2014-05-06 15:23:49 -04001278 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001279 {
1280 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1281 }
1282
John Bauman19bac1e2014-05-06 15:23:49 -04001283 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001284 {
1285 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1286 }
1287
John Bauman19bac1e2014-05-06 15:23:49 -04001288 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001289 {
1290 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1291 }
1292
John Bauman19bac1e2014-05-06 15:23:49 -04001293 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001294 {
1295 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1296 }
1297
John Bauman19bac1e2014-05-06 15:23:49 -04001298 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001299 {
1300 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1301 }
1302
John Bauman19bac1e2014-05-06 15:23:49 -04001303 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001304 {
1305 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1306 }
1307
John Bauman19bac1e2014-05-06 15:23:49 -04001308 RValue<SByte> operator+=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001309 {
1310 return lhs = lhs + rhs;
1311 }
1312
John Bauman19bac1e2014-05-06 15:23:49 -04001313 RValue<SByte> operator-=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001314 {
1315 return lhs = lhs - rhs;
1316 }
1317
John Bauman19bac1e2014-05-06 15:23:49 -04001318 RValue<SByte> operator*=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001319 {
1320 return lhs = lhs * rhs;
1321 }
1322
John Bauman19bac1e2014-05-06 15:23:49 -04001323 RValue<SByte> operator/=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001324 {
1325 return lhs = lhs / rhs;
1326 }
1327
John Bauman19bac1e2014-05-06 15:23:49 -04001328 RValue<SByte> operator%=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001329 {
1330 return lhs = lhs % rhs;
1331 }
1332
John Bauman19bac1e2014-05-06 15:23:49 -04001333 RValue<SByte> operator&=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001334 {
1335 return lhs = lhs & rhs;
1336 }
1337
John Bauman19bac1e2014-05-06 15:23:49 -04001338 RValue<SByte> operator|=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001339 {
1340 return lhs = lhs | rhs;
1341 }
1342
John Bauman19bac1e2014-05-06 15:23:49 -04001343 RValue<SByte> operator^=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001344 {
1345 return lhs = lhs ^ rhs;
1346 }
1347
John Bauman19bac1e2014-05-06 15:23:49 -04001348 RValue<SByte> operator<<=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001349 {
1350 return lhs = lhs << rhs;
1351 }
1352
John Bauman19bac1e2014-05-06 15:23:49 -04001353 RValue<SByte> operator>>=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001354 {
1355 return lhs = lhs >> rhs;
1356 }
1357
John Bauman19bac1e2014-05-06 15:23:49 -04001358 RValue<SByte> operator+(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001359 {
1360 return val;
1361 }
1362
John Bauman19bac1e2014-05-06 15:23:49 -04001363 RValue<SByte> operator-(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001364 {
1365 return RValue<SByte>(Nucleus::createNeg(val.value));
1366 }
1367
John Bauman19bac1e2014-05-06 15:23:49 -04001368 RValue<SByte> operator~(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001369 {
1370 return RValue<SByte>(Nucleus::createNot(val.value));
1371 }
1372
1373 RValue<SByte> operator++(const SByte &val, int) // Post-increment
1374 {
1375 RValue<SByte> res = val;
1376
1377 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001378 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001379
1380 return res;
1381 }
1382
1383 const SByte &operator++(const SByte &val) // Pre-increment
1384 {
John Bauman66b8ab22014-05-06 15:57:45 -04001385 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1));
1386 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001387
1388 return val;
1389 }
1390
1391 RValue<SByte> operator--(const SByte &val, int) // Post-decrement
1392 {
1393 RValue<SByte> res = val;
1394
1395 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001396 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001397
1398 return res;
1399 }
1400
1401 const SByte &operator--(const SByte &val) // Pre-decrement
1402 {
John Bauman66b8ab22014-05-06 15:57:45 -04001403 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1));
1404 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001405
1406 return val;
1407 }
1408
John Bauman19bac1e2014-05-06 15:23:49 -04001409 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001410 {
1411 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1412 }
1413
John Bauman19bac1e2014-05-06 15:23:49 -04001414 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001415 {
1416 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1417 }
1418
John Bauman19bac1e2014-05-06 15:23:49 -04001419 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001420 {
1421 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1422 }
1423
John Bauman19bac1e2014-05-06 15:23:49 -04001424 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001425 {
1426 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1427 }
1428
John Bauman19bac1e2014-05-06 15:23:49 -04001429 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001430 {
1431 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1432 }
1433
John Bauman19bac1e2014-05-06 15:23:49 -04001434 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001435 {
1436 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1437 }
1438
John Bauman19bac1e2014-05-06 15:23:49 -04001439 Type *SByte::getType()
John Bauman89401822014-05-06 15:04:28 -04001440 {
1441 return Type::getInt8Ty(*Nucleus::getContext());
1442 }
1443
1444 Short::Short(Argument *argument)
1445 {
John Bauman66b8ab22014-05-06 15:57:45 -04001446 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04001447 }
1448
John Bauman19bac1e2014-05-06 15:23:49 -04001449 Short::Short(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04001450 {
John Bauman89401822014-05-06 15:04:28 -04001451 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1452
John Bauman66b8ab22014-05-06 15:57:45 -04001453 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04001454 }
1455
1456 Short::Short()
1457 {
John Bauman89401822014-05-06 15:04:28 -04001458 }
1459
1460 Short::Short(short x)
1461 {
John Bauman66b8ab22014-05-06 15:57:45 -04001462 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001463 }
1464
John Bauman19bac1e2014-05-06 15:23:49 -04001465 Short::Short(RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001466 {
John Bauman66b8ab22014-05-06 15:57:45 -04001467 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001468 }
1469
1470 Short::Short(const Short &rhs)
1471 {
John Bauman66b8ab22014-05-06 15:57:45 -04001472 Value *value = rhs.loadValue();
1473 storeValue(value);
1474 }
John Bauman89401822014-05-06 15:04:28 -04001475
John Bauman66b8ab22014-05-06 15:57:45 -04001476 Short::Short(const Reference<Short> &rhs)
1477 {
1478 Value *value = rhs.loadValue();
1479 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001480 }
1481
John Bauman19bac1e2014-05-06 15:23:49 -04001482 RValue<Short> Short::operator=(RValue<Short> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001483 {
John Bauman66b8ab22014-05-06 15:57:45 -04001484 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001485
1486 return rhs;
1487 }
1488
1489 RValue<Short> Short::operator=(const Short &rhs) const
1490 {
John Bauman66b8ab22014-05-06 15:57:45 -04001491 Value *value = rhs.loadValue();
1492 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001493
1494 return RValue<Short>(value);
1495 }
1496
John Bauman66b8ab22014-05-06 15:57:45 -04001497 RValue<Short> Short::operator=(const Reference<Short> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001498 {
John Bauman66b8ab22014-05-06 15:57:45 -04001499 Value *value = rhs.loadValue();
1500 storeValue(value);
1501
1502 return RValue<Short>(value);
John Bauman89401822014-05-06 15:04:28 -04001503 }
1504
John Bauman19bac1e2014-05-06 15:23:49 -04001505 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001506 {
1507 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
1508 }
1509
John Bauman19bac1e2014-05-06 15:23:49 -04001510 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001511 {
1512 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
1513 }
1514
John Bauman19bac1e2014-05-06 15:23:49 -04001515 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001516 {
1517 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
1518 }
1519
John Bauman19bac1e2014-05-06 15:23:49 -04001520 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001521 {
1522 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
1523 }
1524
John Bauman19bac1e2014-05-06 15:23:49 -04001525 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001526 {
1527 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
1528 }
1529
John Bauman19bac1e2014-05-06 15:23:49 -04001530 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001531 {
1532 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
1533 }
1534
John Bauman19bac1e2014-05-06 15:23:49 -04001535 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001536 {
1537 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
1538 }
1539
John Bauman19bac1e2014-05-06 15:23:49 -04001540 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001541 {
1542 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
1543 }
1544
John Bauman19bac1e2014-05-06 15:23:49 -04001545 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001546 {
1547 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
1548 }
1549
John Bauman19bac1e2014-05-06 15:23:49 -04001550 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001551 {
1552 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
1553 }
1554
John Bauman19bac1e2014-05-06 15:23:49 -04001555 RValue<Short> operator+=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001556 {
1557 return lhs = lhs + rhs;
1558 }
1559
John Bauman19bac1e2014-05-06 15:23:49 -04001560 RValue<Short> operator-=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001561 {
1562 return lhs = lhs - rhs;
1563 }
1564
John Bauman19bac1e2014-05-06 15:23:49 -04001565 RValue<Short> operator*=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001566 {
1567 return lhs = lhs * rhs;
1568 }
1569
John Bauman19bac1e2014-05-06 15:23:49 -04001570 RValue<Short> operator/=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001571 {
1572 return lhs = lhs / rhs;
1573 }
1574
John Bauman19bac1e2014-05-06 15:23:49 -04001575 RValue<Short> operator%=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001576 {
1577 return lhs = lhs % rhs;
1578 }
1579
John Bauman19bac1e2014-05-06 15:23:49 -04001580 RValue<Short> operator&=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001581 {
1582 return lhs = lhs & rhs;
1583 }
1584
John Bauman19bac1e2014-05-06 15:23:49 -04001585 RValue<Short> operator|=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001586 {
1587 return lhs = lhs | rhs;
1588 }
1589
John Bauman19bac1e2014-05-06 15:23:49 -04001590 RValue<Short> operator^=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001591 {
1592 return lhs = lhs ^ rhs;
1593 }
1594
John Bauman19bac1e2014-05-06 15:23:49 -04001595 RValue<Short> operator<<=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001596 {
1597 return lhs = lhs << rhs;
1598 }
1599
John Bauman19bac1e2014-05-06 15:23:49 -04001600 RValue<Short> operator>>=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001601 {
1602 return lhs = lhs >> rhs;
1603 }
1604
John Bauman19bac1e2014-05-06 15:23:49 -04001605 RValue<Short> operator+(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001606 {
1607 return val;
1608 }
1609
John Bauman19bac1e2014-05-06 15:23:49 -04001610 RValue<Short> operator-(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001611 {
1612 return RValue<Short>(Nucleus::createNeg(val.value));
1613 }
1614
John Bauman19bac1e2014-05-06 15:23:49 -04001615 RValue<Short> operator~(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001616 {
1617 return RValue<Short>(Nucleus::createNot(val.value));
1618 }
1619
1620 RValue<Short> operator++(const Short &val, int) // Post-increment
1621 {
1622 RValue<Short> res = val;
1623
1624 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001625 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001626
1627 return res;
1628 }
1629
1630 const Short &operator++(const Short &val) // Pre-increment
1631 {
John Bauman66b8ab22014-05-06 15:57:45 -04001632 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1));
1633 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001634
1635 return val;
1636 }
1637
1638 RValue<Short> operator--(const Short &val, int) // Post-decrement
1639 {
1640 RValue<Short> res = val;
1641
1642 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001643 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001644
1645 return res;
1646 }
1647
1648 const Short &operator--(const Short &val) // Pre-decrement
1649 {
John Bauman66b8ab22014-05-06 15:57:45 -04001650 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1));
1651 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001652
1653 return val;
1654 }
1655
John Bauman19bac1e2014-05-06 15:23:49 -04001656 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001657 {
1658 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1659 }
1660
John Bauman19bac1e2014-05-06 15:23:49 -04001661 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001662 {
1663 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1664 }
1665
John Bauman19bac1e2014-05-06 15:23:49 -04001666 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001667 {
1668 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1669 }
1670
John Bauman19bac1e2014-05-06 15:23:49 -04001671 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001672 {
1673 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1674 }
1675
John Bauman19bac1e2014-05-06 15:23:49 -04001676 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001677 {
1678 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1679 }
1680
John Bauman19bac1e2014-05-06 15:23:49 -04001681 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001682 {
1683 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1684 }
1685
John Bauman19bac1e2014-05-06 15:23:49 -04001686 Type *Short::getType()
John Bauman89401822014-05-06 15:04:28 -04001687 {
1688 return Type::getInt16Ty(*Nucleus::getContext());
1689 }
1690
1691 UShort::UShort(Argument *argument)
1692 {
John Bauman66b8ab22014-05-06 15:57:45 -04001693 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04001694 }
1695
Alexis Hetu77dfab42015-11-23 13:31:22 -05001696 UShort::UShort(RValue<UInt> cast)
1697 {
1698 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
1699
1700 storeValue(integer);
1701 }
1702
Alexis Hetu75b650f2015-11-19 17:40:15 -05001703 UShort::UShort(RValue<Int> cast)
1704 {
1705 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
1706
1707 storeValue(integer);
1708 }
1709
John Bauman89401822014-05-06 15:04:28 -04001710 UShort::UShort()
1711 {
John Bauman89401822014-05-06 15:04:28 -04001712 }
1713
1714 UShort::UShort(unsigned short x)
1715 {
John Bauman66b8ab22014-05-06 15:57:45 -04001716 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001717 }
1718
John Bauman19bac1e2014-05-06 15:23:49 -04001719 UShort::UShort(RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001720 {
John Bauman66b8ab22014-05-06 15:57:45 -04001721 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001722 }
1723
1724 UShort::UShort(const UShort &rhs)
1725 {
John Bauman66b8ab22014-05-06 15:57:45 -04001726 Value *value = rhs.loadValue();
1727 storeValue(value);
1728 }
John Bauman89401822014-05-06 15:04:28 -04001729
John Bauman66b8ab22014-05-06 15:57:45 -04001730 UShort::UShort(const Reference<UShort> &rhs)
1731 {
1732 Value *value = rhs.loadValue();
1733 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001734 }
1735
John Bauman19bac1e2014-05-06 15:23:49 -04001736 RValue<UShort> UShort::operator=(RValue<UShort> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001737 {
John Bauman66b8ab22014-05-06 15:57:45 -04001738 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001739
1740 return rhs;
1741 }
1742
1743 RValue<UShort> UShort::operator=(const UShort &rhs) const
1744 {
John Bauman66b8ab22014-05-06 15:57:45 -04001745 Value *value = rhs.loadValue();
1746 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001747
1748 return RValue<UShort>(value);
1749 }
1750
John Bauman66b8ab22014-05-06 15:57:45 -04001751 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001752 {
John Bauman66b8ab22014-05-06 15:57:45 -04001753 Value *value = rhs.loadValue();
1754 storeValue(value);
1755
1756 return RValue<UShort>(value);
John Bauman89401822014-05-06 15:04:28 -04001757 }
1758
John Bauman19bac1e2014-05-06 15:23:49 -04001759 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001760 {
1761 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
1762 }
1763
John Bauman19bac1e2014-05-06 15:23:49 -04001764 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001765 {
1766 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
1767 }
1768
John Bauman19bac1e2014-05-06 15:23:49 -04001769 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001770 {
1771 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
1772 }
1773
John Bauman19bac1e2014-05-06 15:23:49 -04001774 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001775 {
1776 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
1777 }
1778
John Bauman19bac1e2014-05-06 15:23:49 -04001779 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001780 {
1781 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
1782 }
1783
John Bauman19bac1e2014-05-06 15:23:49 -04001784 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001785 {
1786 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
1787 }
1788
John Bauman19bac1e2014-05-06 15:23:49 -04001789 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001790 {
1791 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
1792 }
1793
John Bauman19bac1e2014-05-06 15:23:49 -04001794 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001795 {
1796 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
1797 }
1798
John Bauman19bac1e2014-05-06 15:23:49 -04001799 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001800 {
1801 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
1802 }
1803
John Bauman19bac1e2014-05-06 15:23:49 -04001804 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001805 {
1806 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
1807 }
1808
John Bauman19bac1e2014-05-06 15:23:49 -04001809 RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001810 {
1811 return lhs = lhs + rhs;
1812 }
1813
John Bauman19bac1e2014-05-06 15:23:49 -04001814 RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001815 {
1816 return lhs = lhs - rhs;
1817 }
1818
John Bauman19bac1e2014-05-06 15:23:49 -04001819 RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001820 {
1821 return lhs = lhs * rhs;
1822 }
1823
John Bauman19bac1e2014-05-06 15:23:49 -04001824 RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001825 {
1826 return lhs = lhs / rhs;
1827 }
1828
John Bauman19bac1e2014-05-06 15:23:49 -04001829 RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001830 {
1831 return lhs = lhs % rhs;
1832 }
1833
John Bauman19bac1e2014-05-06 15:23:49 -04001834 RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001835 {
1836 return lhs = lhs & rhs;
1837 }
1838
John Bauman19bac1e2014-05-06 15:23:49 -04001839 RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001840 {
1841 return lhs = lhs | rhs;
1842 }
1843
John Bauman19bac1e2014-05-06 15:23:49 -04001844 RValue<UShort> operator^=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001845 {
1846 return lhs = lhs ^ rhs;
1847 }
1848
John Bauman19bac1e2014-05-06 15:23:49 -04001849 RValue<UShort> operator<<=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001850 {
1851 return lhs = lhs << rhs;
1852 }
1853
John Bauman19bac1e2014-05-06 15:23:49 -04001854 RValue<UShort> operator>>=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001855 {
1856 return lhs = lhs >> rhs;
1857 }
1858
John Bauman19bac1e2014-05-06 15:23:49 -04001859 RValue<UShort> operator+(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001860 {
1861 return val;
1862 }
1863
John Bauman19bac1e2014-05-06 15:23:49 -04001864 RValue<UShort> operator-(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001865 {
1866 return RValue<UShort>(Nucleus::createNeg(val.value));
1867 }
1868
John Bauman19bac1e2014-05-06 15:23:49 -04001869 RValue<UShort> operator~(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001870 {
1871 return RValue<UShort>(Nucleus::createNot(val.value));
1872 }
1873
1874 RValue<UShort> operator++(const UShort &val, int) // Post-increment
1875 {
1876 RValue<UShort> res = val;
1877
1878 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001879 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001880
1881 return res;
1882 }
1883
1884 const UShort &operator++(const UShort &val) // Pre-increment
1885 {
John Bauman66b8ab22014-05-06 15:57:45 -04001886 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
1887 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001888
1889 return val;
1890 }
1891
1892 RValue<UShort> operator--(const UShort &val, int) // Post-decrement
1893 {
1894 RValue<UShort> res = val;
1895
1896 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001897 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001898
1899 return res;
1900 }
1901
1902 const UShort &operator--(const UShort &val) // Pre-decrement
1903 {
John Bauman66b8ab22014-05-06 15:57:45 -04001904 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
1905 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001906
1907 return val;
1908 }
1909
John Bauman19bac1e2014-05-06 15:23:49 -04001910 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001911 {
1912 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1913 }
1914
John Bauman19bac1e2014-05-06 15:23:49 -04001915 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001916 {
1917 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1918 }
1919
John Bauman19bac1e2014-05-06 15:23:49 -04001920 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001921 {
1922 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1923 }
1924
John Bauman19bac1e2014-05-06 15:23:49 -04001925 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001926 {
1927 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1928 }
1929
John Bauman19bac1e2014-05-06 15:23:49 -04001930 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001931 {
1932 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1933 }
1934
John Bauman19bac1e2014-05-06 15:23:49 -04001935 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001936 {
1937 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1938 }
1939
John Bauman19bac1e2014-05-06 15:23:49 -04001940 Type *UShort::getType()
John Bauman89401822014-05-06 15:04:28 -04001941 {
1942 return Type::getInt16Ty(*Nucleus::getContext());
1943 }
1944
John Bauman19bac1e2014-05-06 15:23:49 -04001945 Type *Byte4::getType()
John Bauman89401822014-05-06 15:04:28 -04001946 {
1947 #if 0
1948 return VectorType::get(Byte::getType(), 4);
1949 #else
1950 return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
1951 #endif
1952 }
1953
John Bauman19bac1e2014-05-06 15:23:49 -04001954 Type *SByte4::getType()
John Bauman89401822014-05-06 15:04:28 -04001955 {
1956 #if 0
1957 return VectorType::get(SByte::getType(), 4);
1958 #else
1959 return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
1960 #endif
1961 }
1962
1963 Byte8::Byte8()
1964 {
1965 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001966 }
1967
1968 Byte8::Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
1969 {
1970 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001971
1972 Constant *constantVector[8];
1973 constantVector[0] = Nucleus::createConstantByte(x0);
1974 constantVector[1] = Nucleus::createConstantByte(x1);
1975 constantVector[2] = Nucleus::createConstantByte(x2);
1976 constantVector[3] = Nucleus::createConstantByte(x3);
1977 constantVector[4] = Nucleus::createConstantByte(x4);
1978 constantVector[5] = Nucleus::createConstantByte(x5);
1979 constantVector[6] = Nucleus::createConstantByte(x6);
1980 constantVector[7] = Nucleus::createConstantByte(x7);
John Bauman19bac1e2014-05-06 15:23:49 -04001981 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04001982
John Bauman66b8ab22014-05-06 15:57:45 -04001983 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04001984 }
1985
1986 Byte8::Byte8(int64_t x)
1987 {
1988 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001989
1990 Constant *constantVector[8];
1991 constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
1992 constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
1993 constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
1994 constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
1995 constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
1996 constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
1997 constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
1998 constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
John Bauman19bac1e2014-05-06 15:23:49 -04001999 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002000
John Bauman66b8ab22014-05-06 15:57:45 -04002001 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002002 }
2003
John Bauman19bac1e2014-05-06 15:23:49 -04002004 Byte8::Byte8(RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002005 {
2006 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002007
John Bauman66b8ab22014-05-06 15:57:45 -04002008 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002009 }
2010
2011 Byte8::Byte8(const Byte8 &rhs)
2012 {
2013 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002014
John Bauman66b8ab22014-05-06 15:57:45 -04002015 Value *value = rhs.loadValue();
2016 storeValue(value);
2017 }
2018
2019 Byte8::Byte8(const Reference<Byte8> &rhs)
2020 {
2021 // xyzw.parent = this;
2022
2023 Value *value = rhs.loadValue();
2024 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002025 }
2026
John Bauman19bac1e2014-05-06 15:23:49 -04002027 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002028 {
John Bauman66b8ab22014-05-06 15:57:45 -04002029 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002030
2031 return rhs;
2032 }
2033
2034 RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const
2035 {
John Bauman66b8ab22014-05-06 15:57:45 -04002036 Value *value = rhs.loadValue();
2037 storeValue(value);
2038
2039 return RValue<Byte8>(value);
2040 }
2041
2042 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const
2043 {
2044 Value *value = rhs.loadValue();
2045 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002046
2047 return RValue<Byte8>(value);
2048 }
2049
John Bauman19bac1e2014-05-06 15:23:49 -04002050 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002051 {
John Bauman19bac1e2014-05-06 15:23:49 -04002052 if(CPUID::supportsMMX2())
2053 {
2054 return x86::paddb(lhs, rhs);
2055 }
2056 else
2057 {
2058 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
2059 }
John Bauman89401822014-05-06 15:04:28 -04002060 }
2061
John Bauman19bac1e2014-05-06 15:23:49 -04002062 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002063 {
John Bauman19bac1e2014-05-06 15:23:49 -04002064 if(CPUID::supportsMMX2())
2065 {
2066 return x86::psubb(lhs, rhs);
2067 }
2068 else
2069 {
2070 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
2071 }
John Bauman89401822014-05-06 15:04:28 -04002072 }
2073
John Bauman19bac1e2014-05-06 15:23:49 -04002074// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2075// {
2076// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2077// }
2078
2079// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2080// {
2081// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2082// }
2083
2084// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2085// {
2086// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2087// }
2088
2089 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002090 {
John Bauman19bac1e2014-05-06 15:23:49 -04002091 if(CPUID::supportsMMX2())
2092 {
2093 return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
2094 }
2095 else
2096 {
2097 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
2098 }
John Bauman89401822014-05-06 15:04:28 -04002099 }
2100
John Bauman19bac1e2014-05-06 15:23:49 -04002101 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002102 {
John Bauman19bac1e2014-05-06 15:23:49 -04002103 if(CPUID::supportsMMX2())
2104 {
2105 return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
2106 }
2107 else
2108 {
2109 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
2110 }
John Bauman89401822014-05-06 15:04:28 -04002111 }
2112
John Bauman19bac1e2014-05-06 15:23:49 -04002113 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002114 {
John Bauman19bac1e2014-05-06 15:23:49 -04002115 if(CPUID::supportsMMX2())
2116 {
2117 return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
2118 }
2119 else
John Bauman66b8ab22014-05-06 15:57:45 -04002120 {
John Bauman19bac1e2014-05-06 15:23:49 -04002121 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
2122 }
John Bauman89401822014-05-06 15:04:28 -04002123 }
2124
John Bauman19bac1e2014-05-06 15:23:49 -04002125// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002126// {
2127// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
2128// }
2129
John Bauman19bac1e2014-05-06 15:23:49 -04002130// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002131// {
2132// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
2133// }
2134
John Bauman19bac1e2014-05-06 15:23:49 -04002135 RValue<Byte8> operator+=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002136 {
2137 return lhs = lhs + rhs;
2138 }
2139
John Bauman19bac1e2014-05-06 15:23:49 -04002140 RValue<Byte8> operator-=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002141 {
2142 return lhs = lhs - rhs;
2143 }
2144
John Bauman19bac1e2014-05-06 15:23:49 -04002145// RValue<Byte8> operator*=(const Byte8 &lhs, RValue<Byte8> rhs)
2146// {
2147// return lhs = lhs * rhs;
2148// }
John Bauman89401822014-05-06 15:04:28 -04002149
John Bauman19bac1e2014-05-06 15:23:49 -04002150// RValue<Byte8> operator/=(const Byte8 &lhs, RValue<Byte8> rhs)
2151// {
2152// return lhs = lhs / rhs;
2153// }
John Bauman89401822014-05-06 15:04:28 -04002154
John Bauman19bac1e2014-05-06 15:23:49 -04002155// RValue<Byte8> operator%=(const Byte8 &lhs, RValue<Byte8> rhs)
2156// {
2157// return lhs = lhs % rhs;
2158// }
John Bauman89401822014-05-06 15:04:28 -04002159
John Bauman19bac1e2014-05-06 15:23:49 -04002160 RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002161 {
2162 return lhs = lhs & rhs;
2163 }
2164
John Bauman19bac1e2014-05-06 15:23:49 -04002165 RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002166 {
2167 return lhs = lhs | rhs;
2168 }
2169
John Bauman19bac1e2014-05-06 15:23:49 -04002170 RValue<Byte8> operator^=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002171 {
2172 return lhs = lhs ^ rhs;
2173 }
2174
John Bauman19bac1e2014-05-06 15:23:49 -04002175// RValue<Byte8> operator<<=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002176// {
2177// return lhs = lhs << rhs;
2178// }
2179
John Bauman19bac1e2014-05-06 15:23:49 -04002180// RValue<Byte8> operator>>=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002181// {
2182// return lhs = lhs >> rhs;
2183// }
2184
John Bauman19bac1e2014-05-06 15:23:49 -04002185// RValue<Byte8> operator+(RValue<Byte8> val)
2186// {
2187// return val;
2188// }
2189
2190// RValue<Byte8> operator-(RValue<Byte8> val)
2191// {
2192// return RValue<Byte8>(Nucleus::createNeg(val.value));
2193// }
2194
2195 RValue<Byte8> operator~(RValue<Byte8> val)
John Bauman89401822014-05-06 15:04:28 -04002196 {
John Bauman19bac1e2014-05-06 15:23:49 -04002197 if(CPUID::supportsMMX2())
2198 {
2199 return val ^ Byte8(0xFFFFFFFFFFFFFFFF);
2200 }
2201 else
2202 {
2203 return RValue<Byte8>(Nucleus::createNot(val.value));
2204 }
John Bauman89401822014-05-06 15:04:28 -04002205 }
2206
John Bauman19bac1e2014-05-06 15:23:49 -04002207 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002208 {
2209 return x86::paddusb(x, y);
2210 }
John Bauman66b8ab22014-05-06 15:57:45 -04002211
John Bauman19bac1e2014-05-06 15:23:49 -04002212 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002213 {
2214 return x86::psubusb(x, y);
2215 }
2216
John Bauman19bac1e2014-05-06 15:23:49 -04002217 RValue<Short4> Unpack(RValue<Byte4> x)
John Bauman89401822014-05-06 15:04:28 -04002218 {
John Bauman19bac1e2014-05-06 15:23:49 -04002219 Value *int2 = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), x.value, 0);
2220 Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType());
John Bauman89401822014-05-06 15:04:28 -04002221
John Bauman19bac1e2014-05-06 15:23:49 -04002222 return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8));
2223 }
John Bauman89401822014-05-06 15:04:28 -04002224
John Bauman19bac1e2014-05-06 15:23:49 -04002225 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2226 {
2227 if(CPUID::supportsMMX2())
2228 {
2229 return x86::punpcklbw(x, y);
2230 }
2231 else
2232 {
2233 Constant *shuffle[8];
2234 shuffle[0] = Nucleus::createConstantInt(0);
2235 shuffle[1] = Nucleus::createConstantInt(8);
2236 shuffle[2] = Nucleus::createConstantInt(1);
2237 shuffle[3] = Nucleus::createConstantInt(9);
2238 shuffle[4] = Nucleus::createConstantInt(2);
2239 shuffle[5] = Nucleus::createConstantInt(10);
2240 shuffle[6] = Nucleus::createConstantInt(3);
2241 shuffle[7] = Nucleus::createConstantInt(11);
2242
2243 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
2244
2245 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2246 }
John Bauman89401822014-05-06 15:04:28 -04002247 }
John Bauman66b8ab22014-05-06 15:57:45 -04002248
John Bauman19bac1e2014-05-06 15:23:49 -04002249 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002250 {
John Bauman19bac1e2014-05-06 15:23:49 -04002251 if(CPUID::supportsMMX2())
2252 {
2253 return x86::punpckhbw(x, y);
2254 }
2255 else
2256 {
2257 Constant *shuffle[8];
2258 shuffle[0] = Nucleus::createConstantInt(4);
2259 shuffle[1] = Nucleus::createConstantInt(12);
2260 shuffle[2] = Nucleus::createConstantInt(5);
2261 shuffle[3] = Nucleus::createConstantInt(13);
2262 shuffle[4] = Nucleus::createConstantInt(6);
2263 shuffle[5] = Nucleus::createConstantInt(14);
2264 shuffle[6] = Nucleus::createConstantInt(7);
2265 shuffle[7] = Nucleus::createConstantInt(15);
John Bauman89401822014-05-06 15:04:28 -04002266
John Bauman19bac1e2014-05-06 15:23:49 -04002267 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002268
John Bauman19bac1e2014-05-06 15:23:49 -04002269 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2270 }
John Bauman89401822014-05-06 15:04:28 -04002271 }
2272
John Bauman19bac1e2014-05-06 15:23:49 -04002273 RValue<Int> SignMask(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04002274 {
2275 return x86::pmovmskb(x);
2276 }
2277
John Bauman19bac1e2014-05-06 15:23:49 -04002278// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002279// {
2280// return x86::pcmpgtb(x, y); // FIXME: Signedness
2281// }
John Bauman66b8ab22014-05-06 15:57:45 -04002282
John Bauman19bac1e2014-05-06 15:23:49 -04002283 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002284 {
2285 return x86::pcmpeqb(x, y);
2286 }
2287
John Bauman19bac1e2014-05-06 15:23:49 -04002288 Type *Byte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002289 {
John Bauman19bac1e2014-05-06 15:23:49 -04002290 if(CPUID::supportsMMX2())
2291 {
2292 return MMX::getType();
2293 }
2294 else
2295 {
2296 return VectorType::get(Byte::getType(), 8);
2297 }
John Bauman89401822014-05-06 15:04:28 -04002298 }
2299
2300 SByte8::SByte8()
2301 {
2302 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002303 }
2304
2305 SByte8::SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
2306 {
2307 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002308
2309 Constant *constantVector[8];
2310 constantVector[0] = Nucleus::createConstantByte(x0);
2311 constantVector[1] = Nucleus::createConstantByte(x1);
2312 constantVector[2] = Nucleus::createConstantByte(x2);
2313 constantVector[3] = Nucleus::createConstantByte(x3);
2314 constantVector[4] = Nucleus::createConstantByte(x4);
2315 constantVector[5] = Nucleus::createConstantByte(x5);
2316 constantVector[6] = Nucleus::createConstantByte(x6);
2317 constantVector[7] = Nucleus::createConstantByte(x7);
John Bauman19bac1e2014-05-06 15:23:49 -04002318 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002319
John Bauman66b8ab22014-05-06 15:57:45 -04002320 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002321 }
2322
2323 SByte8::SByte8(int64_t x)
2324 {
2325 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002326
2327 Constant *constantVector[8];
2328 constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
2329 constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
2330 constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
2331 constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
2332 constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
2333 constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
2334 constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
2335 constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
John Bauman19bac1e2014-05-06 15:23:49 -04002336 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002337
John Bauman66b8ab22014-05-06 15:57:45 -04002338 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002339 }
2340
John Bauman19bac1e2014-05-06 15:23:49 -04002341 SByte8::SByte8(RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002342 {
2343 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002344
John Bauman66b8ab22014-05-06 15:57:45 -04002345 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002346 }
2347
2348 SByte8::SByte8(const SByte8 &rhs)
2349 {
2350 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002351
John Bauman66b8ab22014-05-06 15:57:45 -04002352 Value *value = rhs.loadValue();
2353 storeValue(value);
2354 }
2355
2356 SByte8::SByte8(const Reference<SByte8> &rhs)
2357 {
2358 // xyzw.parent = this;
2359
2360 Value *value = rhs.loadValue();
2361 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002362 }
2363
John Bauman19bac1e2014-05-06 15:23:49 -04002364 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002365 {
John Bauman66b8ab22014-05-06 15:57:45 -04002366 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002367
2368 return rhs;
2369 }
2370
2371 RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const
2372 {
John Bauman66b8ab22014-05-06 15:57:45 -04002373 Value *value = rhs.loadValue();
2374 storeValue(value);
2375
2376 return RValue<SByte8>(value);
2377 }
2378
2379 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const
2380 {
2381 Value *value = rhs.loadValue();
2382 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002383
2384 return RValue<SByte8>(value);
2385 }
2386
John Bauman19bac1e2014-05-06 15:23:49 -04002387 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002388 {
John Bauman19bac1e2014-05-06 15:23:49 -04002389 if(CPUID::supportsMMX2())
2390 {
2391 return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs)));
2392 }
2393 else
2394 {
2395 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
2396 }
John Bauman89401822014-05-06 15:04:28 -04002397 }
2398
John Bauman19bac1e2014-05-06 15:23:49 -04002399 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002400 {
John Bauman19bac1e2014-05-06 15:23:49 -04002401 if(CPUID::supportsMMX2())
2402 {
2403 return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs)));
2404 }
2405 else
2406 {
2407 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
2408 }
John Bauman89401822014-05-06 15:04:28 -04002409 }
2410
John Bauman19bac1e2014-05-06 15:23:49 -04002411// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2412// {
2413// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2414// }
John Bauman89401822014-05-06 15:04:28 -04002415
John Bauman19bac1e2014-05-06 15:23:49 -04002416// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2417// {
2418// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2419// }
John Bauman89401822014-05-06 15:04:28 -04002420
John Bauman19bac1e2014-05-06 15:23:49 -04002421// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2422// {
2423// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2424// }
John Bauman89401822014-05-06 15:04:28 -04002425
John Bauman19bac1e2014-05-06 15:23:49 -04002426 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002427 {
2428 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2429 }
2430
John Bauman19bac1e2014-05-06 15:23:49 -04002431 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002432 {
2433 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2434 }
2435
John Bauman19bac1e2014-05-06 15:23:49 -04002436 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002437 {
2438 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2439 }
2440
John Bauman19bac1e2014-05-06 15:23:49 -04002441// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002442// {
2443// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
2444// }
2445
John Bauman19bac1e2014-05-06 15:23:49 -04002446// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002447// {
2448// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
2449// }
2450
John Bauman19bac1e2014-05-06 15:23:49 -04002451 RValue<SByte8> operator+=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002452 {
2453 return lhs = lhs + rhs;
2454 }
2455
John Bauman19bac1e2014-05-06 15:23:49 -04002456 RValue<SByte8> operator-=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002457 {
2458 return lhs = lhs - rhs;
2459 }
2460
John Bauman19bac1e2014-05-06 15:23:49 -04002461// RValue<SByte8> operator*=(const SByte8 &lhs, RValue<SByte8> rhs)
2462// {
2463// return lhs = lhs * rhs;
2464// }
John Bauman89401822014-05-06 15:04:28 -04002465
John Bauman19bac1e2014-05-06 15:23:49 -04002466// RValue<SByte8> operator/=(const SByte8 &lhs, RValue<SByte8> rhs)
2467// {
2468// return lhs = lhs / rhs;
2469// }
John Bauman89401822014-05-06 15:04:28 -04002470
John Bauman19bac1e2014-05-06 15:23:49 -04002471// RValue<SByte8> operator%=(const SByte8 &lhs, RValue<SByte8> rhs)
2472// {
2473// return lhs = lhs % rhs;
2474// }
John Bauman89401822014-05-06 15:04:28 -04002475
John Bauman19bac1e2014-05-06 15:23:49 -04002476 RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002477 {
2478 return lhs = lhs & rhs;
2479 }
2480
John Bauman19bac1e2014-05-06 15:23:49 -04002481 RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002482 {
2483 return lhs = lhs | rhs;
2484 }
2485
John Bauman19bac1e2014-05-06 15:23:49 -04002486 RValue<SByte8> operator^=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002487 {
2488 return lhs = lhs ^ rhs;
2489 }
2490
John Bauman19bac1e2014-05-06 15:23:49 -04002491// RValue<SByte8> operator<<=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002492// {
2493// return lhs = lhs << rhs;
2494// }
2495
John Bauman19bac1e2014-05-06 15:23:49 -04002496// RValue<SByte8> operator>>=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002497// {
2498// return lhs = lhs >> rhs;
2499// }
2500
John Bauman19bac1e2014-05-06 15:23:49 -04002501// RValue<SByte8> operator+(RValue<SByte8> val)
2502// {
2503// return val;
2504// }
2505
2506// RValue<SByte8> operator-(RValue<SByte8> val)
2507// {
2508// return RValue<SByte8>(Nucleus::createNeg(val.value));
2509// }
2510
2511 RValue<SByte8> operator~(RValue<SByte8> val)
John Bauman89401822014-05-06 15:04:28 -04002512 {
John Bauman19bac1e2014-05-06 15:23:49 -04002513 if(CPUID::supportsMMX2())
2514 {
2515 return val ^ SByte8(0xFFFFFFFFFFFFFFFF);
2516 }
2517 else
2518 {
2519 return RValue<SByte8>(Nucleus::createNot(val.value));
2520 }
John Bauman89401822014-05-06 15:04:28 -04002521 }
2522
John Bauman19bac1e2014-05-06 15:23:49 -04002523 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002524 {
2525 return x86::paddsb(x, y);
2526 }
John Bauman66b8ab22014-05-06 15:57:45 -04002527
John Bauman19bac1e2014-05-06 15:23:49 -04002528 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002529 {
2530 return x86::psubsb(x, y);
2531 }
2532
John Bauman19bac1e2014-05-06 15:23:49 -04002533 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002534 {
John Bauman19bac1e2014-05-06 15:23:49 -04002535 if(CPUID::supportsMMX2())
2536 {
2537 return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y)));
2538 }
2539 else
2540 {
2541 Constant *shuffle[8];
2542 shuffle[0] = Nucleus::createConstantInt(0);
2543 shuffle[1] = Nucleus::createConstantInt(8);
2544 shuffle[2] = Nucleus::createConstantInt(1);
2545 shuffle[3] = Nucleus::createConstantInt(9);
2546 shuffle[4] = Nucleus::createConstantInt(2);
2547 shuffle[5] = Nucleus::createConstantInt(10);
2548 shuffle[6] = Nucleus::createConstantInt(3);
2549 shuffle[7] = Nucleus::createConstantInt(11);
John Bauman89401822014-05-06 15:04:28 -04002550
John Bauman19bac1e2014-05-06 15:23:49 -04002551 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002552
John Bauman19bac1e2014-05-06 15:23:49 -04002553 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2554 }
John Bauman89401822014-05-06 15:04:28 -04002555 }
John Bauman66b8ab22014-05-06 15:57:45 -04002556
John Bauman19bac1e2014-05-06 15:23:49 -04002557 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002558 {
John Bauman19bac1e2014-05-06 15:23:49 -04002559 if(CPUID::supportsMMX2())
2560 {
2561 return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y)));
2562 }
2563 else
2564 {
2565 Constant *shuffle[8];
2566 shuffle[0] = Nucleus::createConstantInt(4);
2567 shuffle[1] = Nucleus::createConstantInt(12);
2568 shuffle[2] = Nucleus::createConstantInt(5);
2569 shuffle[3] = Nucleus::createConstantInt(13);
2570 shuffle[4] = Nucleus::createConstantInt(6);
2571 shuffle[5] = Nucleus::createConstantInt(14);
2572 shuffle[6] = Nucleus::createConstantInt(7);
2573 shuffle[7] = Nucleus::createConstantInt(15);
John Bauman89401822014-05-06 15:04:28 -04002574
John Bauman19bac1e2014-05-06 15:23:49 -04002575 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002576
John Bauman19bac1e2014-05-06 15:23:49 -04002577 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2578 }
John Bauman89401822014-05-06 15:04:28 -04002579 }
2580
John Bauman19bac1e2014-05-06 15:23:49 -04002581 RValue<Int> SignMask(RValue<SByte8> x)
John Bauman89401822014-05-06 15:04:28 -04002582 {
2583 return x86::pmovmskb(As<Byte8>(x));
2584 }
2585
John Bauman19bac1e2014-05-06 15:23:49 -04002586 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002587 {
2588 return x86::pcmpgtb(x, y);
2589 }
John Bauman66b8ab22014-05-06 15:57:45 -04002590
John Bauman19bac1e2014-05-06 15:23:49 -04002591 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002592 {
2593 return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
2594 }
2595
John Bauman19bac1e2014-05-06 15:23:49 -04002596 Type *SByte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002597 {
John Bauman19bac1e2014-05-06 15:23:49 -04002598 if(CPUID::supportsMMX2())
2599 {
2600 return MMX::getType();
2601 }
2602 else
2603 {
2604 return VectorType::get(SByte::getType(), 8);
2605 }
John Bauman89401822014-05-06 15:04:28 -04002606 }
2607
John Bauman19bac1e2014-05-06 15:23:49 -04002608 Byte16::Byte16(RValue<Byte16> rhs)
John Bauman89401822014-05-06 15:04:28 -04002609 {
2610 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002611
John Bauman66b8ab22014-05-06 15:57:45 -04002612 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002613 }
2614
2615 Byte16::Byte16(const Byte16 &rhs)
2616 {
2617 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002618
John Bauman66b8ab22014-05-06 15:57:45 -04002619 Value *value = rhs.loadValue();
2620 storeValue(value);
2621 }
2622
2623 Byte16::Byte16(const Reference<Byte16> &rhs)
2624 {
2625 // xyzw.parent = this;
2626
2627 Value *value = rhs.loadValue();
2628 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002629 }
2630
John Bauman19bac1e2014-05-06 15:23:49 -04002631 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002632 {
John Bauman66b8ab22014-05-06 15:57:45 -04002633 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002634
2635 return rhs;
2636 }
2637
2638 RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const
2639 {
John Bauman66b8ab22014-05-06 15:57:45 -04002640 Value *value = rhs.loadValue();
2641 storeValue(value);
2642
2643 return RValue<Byte16>(value);
2644 }
2645
2646 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const
2647 {
2648 Value *value = rhs.loadValue();
2649 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002650
2651 return RValue<Byte16>(value);
2652 }
2653
John Bauman19bac1e2014-05-06 15:23:49 -04002654 Type *Byte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002655 {
2656 return VectorType::get(Byte::getType(), 16);
2657 }
2658
John Bauman19bac1e2014-05-06 15:23:49 -04002659 Type *SByte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002660 {
2661 return VectorType::get(SByte::getType(), 16);
2662 }
2663
John Bauman19bac1e2014-05-06 15:23:49 -04002664 Short4::Short4(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04002665 {
John Bauman89401822014-05-06 15:04:28 -04002666 Value *extend = Nucleus::createZExt(cast.value, Long::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04002667 Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value;
John Bauman66b8ab22014-05-06 15:57:45 -04002668
2669 storeValue(swizzle);
John Bauman89401822014-05-06 15:04:28 -04002670 }
2671
John Bauman19bac1e2014-05-06 15:23:49 -04002672 Short4::Short4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04002673 {
John Bauman89401822014-05-06 15:04:28 -04002674 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
2675
2676 #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd)
2677 Constant *pack[8];
2678 pack[0] = Nucleus::createConstantInt(0);
2679 pack[1] = Nucleus::createConstantInt(2);
2680 pack[2] = Nucleus::createConstantInt(4);
2681 pack[3] = Nucleus::createConstantInt(6);
2682
2683 Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4));
2684 #else
2685 Value *packed;
2686
2687 // FIXME: Use Swizzle<Short8>
2688 if(!CPUID::supportsSSSE3())
2689 {
2690 Constant *pshuflw[8];
2691 pshuflw[0] = Nucleus::createConstantInt(0);
2692 pshuflw[1] = Nucleus::createConstantInt(2);
2693 pshuflw[2] = Nucleus::createConstantInt(0);
2694 pshuflw[3] = Nucleus::createConstantInt(2);
2695 pshuflw[4] = Nucleus::createConstantInt(4);
2696 pshuflw[5] = Nucleus::createConstantInt(5);
2697 pshuflw[6] = Nucleus::createConstantInt(6);
2698 pshuflw[7] = Nucleus::createConstantInt(7);
2699
2700 Constant *pshufhw[8];
2701 pshufhw[0] = Nucleus::createConstantInt(0);
2702 pshufhw[1] = Nucleus::createConstantInt(1);
2703 pshufhw[2] = Nucleus::createConstantInt(2);
2704 pshufhw[3] = Nucleus::createConstantInt(3);
2705 pshufhw[4] = Nucleus::createConstantInt(4);
2706 pshufhw[5] = Nucleus::createConstantInt(6);
2707 pshufhw[6] = Nucleus::createConstantInt(4);
2708 pshufhw[7] = Nucleus::createConstantInt(6);
2709
2710 Value *shuffle1 = Nucleus::createShuffleVector(short8, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshuflw, 8));
2711 Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshufhw, 8));
2712 Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType());
2713 packed = Nucleus::createSwizzle(int4, 0x88);
2714 }
2715 else
2716 {
2717 Constant *pshufb[16];
2718 pshufb[0] = Nucleus::createConstantInt(0);
2719 pshufb[1] = Nucleus::createConstantInt(1);
2720 pshufb[2] = Nucleus::createConstantInt(4);
2721 pshufb[3] = Nucleus::createConstantInt(5);
2722 pshufb[4] = Nucleus::createConstantInt(8);
2723 pshufb[5] = Nucleus::createConstantInt(9);
2724 pshufb[6] = Nucleus::createConstantInt(12);
2725 pshufb[7] = Nucleus::createConstantInt(13);
2726 pshufb[8] = Nucleus::createConstantInt(0);
2727 pshufb[9] = Nucleus::createConstantInt(1);
2728 pshufb[10] = Nucleus::createConstantInt(4);
2729 pshufb[11] = Nucleus::createConstantInt(5);
2730 pshufb[12] = Nucleus::createConstantInt(8);
2731 pshufb[13] = Nucleus::createConstantInt(9);
2732 pshufb[14] = Nucleus::createConstantInt(12);
2733 pshufb[15] = Nucleus::createConstantInt(13);
2734
2735 Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType());
2736 packed = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
2737 }
2738
2739 #if 0 // FIXME: No optimal instruction selection
2740 Value *qword2 = Nucleus::createBitCast(packed, Long2::getType());
2741 Value *element = Nucleus::createExtractElement(qword2, 0);
2742 Value *short4 = Nucleus::createBitCast(element, Short4::getType());
2743 #else // FIXME: Requires SSE
2744 Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
2745 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
2746 #endif
2747 #endif
2748
John Bauman66b8ab22014-05-06 15:57:45 -04002749 storeValue(short4);
John Bauman89401822014-05-06 15:04:28 -04002750 }
2751
John Bauman19bac1e2014-05-06 15:23:49 -04002752// Short4::Short4(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04002753// {
2754// }
2755
John Bauman19bac1e2014-05-06 15:23:49 -04002756 Short4::Short4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04002757 {
John Bauman89401822014-05-06 15:04:28 -04002758 Int4 v4i32 = Int4(cast);
2759 v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
John Bauman66b8ab22014-05-06 15:57:45 -04002760
2761 storeValue(As<Short4>(Int2(v4i32)).value);
John Bauman89401822014-05-06 15:04:28 -04002762 }
2763
2764 Short4::Short4()
2765 {
2766 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002767 }
2768
John Bauman19bac1e2014-05-06 15:23:49 -04002769 Short4::Short4(short xyzw)
2770 {
2771 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04002772
2773 Constant *constantVector[4];
2774 constantVector[0] = Nucleus::createConstantShort(xyzw);
2775 constantVector[1] = Nucleus::createConstantShort(xyzw);
2776 constantVector[2] = Nucleus::createConstantShort(xyzw);
2777 constantVector[3] = Nucleus::createConstantShort(xyzw);
2778 Value *vector = Nucleus::createConstantVector(constantVector, 4);
2779
John Bauman66b8ab22014-05-06 15:57:45 -04002780 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman19bac1e2014-05-06 15:23:49 -04002781 }
2782
John Bauman89401822014-05-06 15:04:28 -04002783 Short4::Short4(short x, short y, short z, short w)
2784 {
2785 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002786
2787 Constant *constantVector[4];
2788 constantVector[0] = Nucleus::createConstantShort(x);
2789 constantVector[1] = Nucleus::createConstantShort(y);
2790 constantVector[2] = Nucleus::createConstantShort(z);
2791 constantVector[3] = Nucleus::createConstantShort(w);
John Bauman19bac1e2014-05-06 15:23:49 -04002792 Value *vector = Nucleus::createConstantVector(constantVector, 4);
2793
John Bauman66b8ab22014-05-06 15:57:45 -04002794 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002795 }
2796
John Bauman19bac1e2014-05-06 15:23:49 -04002797 Short4::Short4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002798 {
2799 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002800
John Bauman66b8ab22014-05-06 15:57:45 -04002801 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002802 }
2803
2804 Short4::Short4(const Short4 &rhs)
2805 {
2806 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002807
John Bauman66b8ab22014-05-06 15:57:45 -04002808 Value *value = rhs.loadValue();
2809 storeValue(value);
2810 }
2811
2812 Short4::Short4(const Reference<Short4> &rhs)
2813 {
2814 // xyzw.parent = this;
2815
2816 Value *value = rhs.loadValue();
2817 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002818 }
2819
John Bauman19bac1e2014-05-06 15:23:49 -04002820 Short4::Short4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002821 {
2822 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002823
John Bauman66b8ab22014-05-06 15:57:45 -04002824 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002825 }
2826
2827 Short4::Short4(const UShort4 &rhs)
2828 {
2829 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002830
John Bauman66b8ab22014-05-06 15:57:45 -04002831 storeValue(rhs.loadValue());
2832 }
2833
2834 Short4::Short4(const Reference<UShort4> &rhs)
2835 {
2836 // xyzw.parent = this;
2837
2838 storeValue(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04002839 }
2840
John Bauman19bac1e2014-05-06 15:23:49 -04002841 RValue<Short4> Short4::operator=(RValue<Short4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002842 {
John Bauman66b8ab22014-05-06 15:57:45 -04002843 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002844
2845 return rhs;
2846 }
2847
2848 RValue<Short4> Short4::operator=(const Short4 &rhs) const
2849 {
John Bauman66b8ab22014-05-06 15:57:45 -04002850 Value *value = rhs.loadValue();
2851 storeValue(value);
2852
2853 return RValue<Short4>(value);
2854 }
2855
2856 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const
2857 {
2858 Value *value = rhs.loadValue();
2859 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002860
2861 return RValue<Short4>(value);
2862 }
2863
John Bauman19bac1e2014-05-06 15:23:49 -04002864 RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002865 {
John Bauman66b8ab22014-05-06 15:57:45 -04002866 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002867
John Bauman66b8ab22014-05-06 15:57:45 -04002868 return RValue<Short4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04002869 }
2870
2871 RValue<Short4> Short4::operator=(const UShort4 &rhs) const
2872 {
John Bauman66b8ab22014-05-06 15:57:45 -04002873 Value *value = rhs.loadValue();
2874 storeValue(value);
2875
2876 return RValue<Short4>(value);
2877 }
2878
2879 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const
2880 {
2881 Value *value = rhs.loadValue();
2882 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002883
2884 return RValue<Short4>(value);
2885 }
2886
John Bauman19bac1e2014-05-06 15:23:49 -04002887 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002888 {
John Bauman19bac1e2014-05-06 15:23:49 -04002889 if(CPUID::supportsMMX2())
2890 {
2891 return x86::paddw(lhs, rhs);
2892 }
2893 else
2894 {
2895 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
2896 }
John Bauman89401822014-05-06 15:04:28 -04002897 }
2898
John Bauman19bac1e2014-05-06 15:23:49 -04002899 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002900 {
John Bauman19bac1e2014-05-06 15:23:49 -04002901 if(CPUID::supportsMMX2())
2902 {
2903 return x86::psubw(lhs, rhs);
2904 }
2905 else
2906 {
2907 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
2908 }
John Bauman89401822014-05-06 15:04:28 -04002909 }
2910
John Bauman19bac1e2014-05-06 15:23:49 -04002911 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002912 {
John Bauman19bac1e2014-05-06 15:23:49 -04002913 if(CPUID::supportsMMX2())
2914 {
2915 return x86::pmullw(lhs, rhs);
2916 }
2917 else
2918 {
2919 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
2920 }
John Bauman89401822014-05-06 15:04:28 -04002921 }
2922
John Bauman19bac1e2014-05-06 15:23:49 -04002923// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
2924// {
2925// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
2926// }
2927
2928// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
2929// {
2930// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
2931// }
2932
2933 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002934 {
John Bauman19bac1e2014-05-06 15:23:49 -04002935 if(CPUID::supportsMMX2())
2936 {
2937 return x86::pand(lhs, rhs);
2938 }
2939 else
2940 {
2941 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
2942 }
John Bauman89401822014-05-06 15:04:28 -04002943 }
2944
John Bauman19bac1e2014-05-06 15:23:49 -04002945 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002946 {
John Bauman19bac1e2014-05-06 15:23:49 -04002947 if(CPUID::supportsMMX2())
2948 {
2949 return x86::por(lhs, rhs);
2950 }
2951 else
2952 {
2953 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
2954 }
John Bauman89401822014-05-06 15:04:28 -04002955 }
2956
John Bauman19bac1e2014-05-06 15:23:49 -04002957 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002958 {
John Bauman19bac1e2014-05-06 15:23:49 -04002959 if(CPUID::supportsMMX2())
2960 {
2961 return x86::pxor(lhs, rhs);
2962 }
2963 else
2964 {
2965 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
2966 }
John Bauman89401822014-05-06 15:04:28 -04002967 }
2968
John Bauman19bac1e2014-05-06 15:23:49 -04002969 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002970 {
2971 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2972
2973 return x86::psllw(lhs, rhs);
2974 }
2975
John Bauman19bac1e2014-05-06 15:23:49 -04002976 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002977 {
2978 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
2979
2980 return x86::psraw(lhs, rhs);
2981 }
2982
John Bauman19bac1e2014-05-06 15:23:49 -04002983 RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04002984 {
2985 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2986
2987 return x86::psllw(lhs, rhs);
2988 }
2989
John Bauman19bac1e2014-05-06 15:23:49 -04002990 RValue<Short4> operator>>(RValue<Short4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04002991 {
2992 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
2993
2994 return x86::psraw(lhs, rhs);
2995 }
2996
John Bauman19bac1e2014-05-06 15:23:49 -04002997 RValue<Short4> operator+=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002998 {
2999 return lhs = lhs + rhs;
3000 }
3001
John Bauman19bac1e2014-05-06 15:23:49 -04003002 RValue<Short4> operator-=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003003 {
3004 return lhs = lhs - rhs;
3005 }
3006
John Bauman19bac1e2014-05-06 15:23:49 -04003007 RValue<Short4> operator*=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003008 {
3009 return lhs = lhs * rhs;
3010 }
3011
John Bauman19bac1e2014-05-06 15:23:49 -04003012// RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs)
3013// {
3014// return lhs = lhs / rhs;
3015// }
John Bauman89401822014-05-06 15:04:28 -04003016
John Bauman19bac1e2014-05-06 15:23:49 -04003017// RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs)
3018// {
3019// return lhs = lhs % rhs;
3020// }
John Bauman89401822014-05-06 15:04:28 -04003021
John Bauman19bac1e2014-05-06 15:23:49 -04003022 RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003023 {
3024 return lhs = lhs & rhs;
3025 }
3026
John Bauman19bac1e2014-05-06 15:23:49 -04003027 RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003028 {
3029 return lhs = lhs | rhs;
3030 }
3031
John Bauman19bac1e2014-05-06 15:23:49 -04003032 RValue<Short4> operator^=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003033 {
3034 return lhs = lhs ^ rhs;
3035 }
3036
3037 RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs)
3038 {
3039 return lhs = lhs << rhs;
3040 }
3041
3042 RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs)
3043 {
3044 return lhs = lhs >> rhs;
3045 }
3046
John Bauman19bac1e2014-05-06 15:23:49 -04003047 RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003048 {
3049 return lhs = lhs << rhs;
3050 }
3051
John Bauman19bac1e2014-05-06 15:23:49 -04003052 RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003053 {
3054 return lhs = lhs >> rhs;
3055 }
3056
John Bauman19bac1e2014-05-06 15:23:49 -04003057// RValue<Short4> operator+(RValue<Short4> val)
3058// {
3059// return val;
3060// }
3061
3062 RValue<Short4> operator-(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04003063 {
John Bauman19bac1e2014-05-06 15:23:49 -04003064 if(CPUID::supportsMMX2())
3065 {
3066 return Short4(0, 0, 0, 0) - val;
3067 }
3068 else
3069 {
3070 return RValue<Short4>(Nucleus::createNeg(val.value));
3071 }
John Bauman89401822014-05-06 15:04:28 -04003072 }
3073
John Bauman19bac1e2014-05-06 15:23:49 -04003074 RValue<Short4> operator~(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04003075 {
John Bauman19bac1e2014-05-06 15:23:49 -04003076 if(CPUID::supportsMMX2())
3077 {
3078 return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu);
3079 }
3080 else
3081 {
3082 return RValue<Short4>(Nucleus::createNot(val.value));
3083 }
John Bauman89401822014-05-06 15:04:28 -04003084 }
3085
John Bauman19bac1e2014-05-06 15:23:49 -04003086 RValue<Short4> RoundShort4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04003087 {
3088 RValue<Int4> v4i32 = x86::cvtps2dq(cast);
Nicolas Capens698633a2015-02-04 00:16:13 -05003089 RValue<Short8> v8i16 = x86::packssdw(v4i32, v4i32);
John Bauman66b8ab22014-05-06 15:57:45 -04003090
Nicolas Capens698633a2015-02-04 00:16:13 -05003091 return As<Short4>(Int2(As<Int4>(v8i16)));
John Bauman89401822014-05-06 15:04:28 -04003092 }
3093
John Bauman19bac1e2014-05-06 15:23:49 -04003094 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003095 {
3096 return x86::pmaxsw(x, y);
3097 }
3098
John Bauman19bac1e2014-05-06 15:23:49 -04003099 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003100 {
3101 return x86::pminsw(x, y);
3102 }
3103
John Bauman19bac1e2014-05-06 15:23:49 -04003104 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003105 {
3106 return x86::paddsw(x, y);
3107 }
3108
John Bauman19bac1e2014-05-06 15:23:49 -04003109 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003110 {
3111 return x86::psubsw(x, y);
3112 }
3113
John Bauman19bac1e2014-05-06 15:23:49 -04003114 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003115 {
3116 return x86::pmulhw(x, y);
3117 }
3118
John Bauman19bac1e2014-05-06 15:23:49 -04003119 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003120 {
3121 return x86::pmaddwd(x, y);
3122 }
3123
John Bauman19bac1e2014-05-06 15:23:49 -04003124 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003125 {
3126 return x86::packsswb(x, y);
3127 }
3128
John Bauman19bac1e2014-05-06 15:23:49 -04003129 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003130 {
John Bauman19bac1e2014-05-06 15:23:49 -04003131 if(CPUID::supportsMMX2())
3132 {
3133 return x86::punpcklwd(x, y);
3134 }
3135 else
3136 {
3137 Constant *shuffle[4];
3138 shuffle[0] = Nucleus::createConstantInt(0);
3139 shuffle[1] = Nucleus::createConstantInt(4);
3140 shuffle[2] = Nucleus::createConstantInt(1);
3141 shuffle[3] = Nucleus::createConstantInt(5);
John Bauman89401822014-05-06 15:04:28 -04003142
John Bauman19bac1e2014-05-06 15:23:49 -04003143 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
John Bauman89401822014-05-06 15:04:28 -04003144
John Bauman19bac1e2014-05-06 15:23:49 -04003145 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
3146 }
John Bauman89401822014-05-06 15:04:28 -04003147 }
3148
John Bauman19bac1e2014-05-06 15:23:49 -04003149 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003150 {
John Bauman19bac1e2014-05-06 15:23:49 -04003151 if(CPUID::supportsMMX2())
3152 {
3153 return x86::punpckhwd(x, y);
3154 }
3155 else
3156 {
3157 Constant *shuffle[4];
3158 shuffle[0] = Nucleus::createConstantInt(2);
3159 shuffle[1] = Nucleus::createConstantInt(6);
3160 shuffle[2] = Nucleus::createConstantInt(3);
3161 shuffle[3] = Nucleus::createConstantInt(7);
John Bauman89401822014-05-06 15:04:28 -04003162
John Bauman19bac1e2014-05-06 15:23:49 -04003163 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
John Bauman89401822014-05-06 15:04:28 -04003164
John Bauman19bac1e2014-05-06 15:23:49 -04003165 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
3166 }
John Bauman89401822014-05-06 15:04:28 -04003167 }
3168
John Bauman19bac1e2014-05-06 15:23:49 -04003169 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04003170 {
John Bauman19bac1e2014-05-06 15:23:49 -04003171 if(CPUID::supportsMMX2())
3172 {
3173 return x86::pshufw(x, select);
3174 }
3175 else
3176 {
3177 return RValue<Short4>(Nucleus::createSwizzle(x.value, select));
3178 }
John Bauman89401822014-05-06 15:04:28 -04003179 }
3180
John Bauman19bac1e2014-05-06 15:23:49 -04003181 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
John Bauman89401822014-05-06 15:04:28 -04003182 {
John Bauman19bac1e2014-05-06 15:23:49 -04003183 if(CPUID::supportsMMX2())
3184 {
3185 return x86::pinsrw(val, Int(element), i);
3186 }
3187 else
3188 {
3189 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
3190 }
John Bauman89401822014-05-06 15:04:28 -04003191 }
3192
John Bauman19bac1e2014-05-06 15:23:49 -04003193 RValue<Short> Extract(RValue<Short4> val, int i)
John Bauman89401822014-05-06 15:04:28 -04003194 {
John Bauman19bac1e2014-05-06 15:23:49 -04003195 if(CPUID::supportsMMX2())
3196 {
3197 return Short(x86::pextrw(val, i));
3198 }
3199 else
3200 {
3201 return RValue<Short>(Nucleus::createExtractElement(val.value, i));
3202 }
John Bauman89401822014-05-06 15:04:28 -04003203 }
3204
John Bauman19bac1e2014-05-06 15:23:49 -04003205 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003206 {
3207 return x86::pcmpgtw(x, y);
3208 }
3209
John Bauman19bac1e2014-05-06 15:23:49 -04003210 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003211 {
3212 return x86::pcmpeqw(x, y);
3213 }
3214
John Bauman19bac1e2014-05-06 15:23:49 -04003215 Type *Short4::getType()
John Bauman89401822014-05-06 15:04:28 -04003216 {
John Bauman19bac1e2014-05-06 15:23:49 -04003217 if(CPUID::supportsMMX2())
3218 {
3219 return MMX::getType();
3220 }
3221 else
3222 {
3223 return VectorType::get(Short::getType(), 4);
3224 }
John Bauman89401822014-05-06 15:04:28 -04003225 }
3226
John Bauman19bac1e2014-05-06 15:23:49 -04003227 UShort4::UShort4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04003228 {
John Bauman89401822014-05-06 15:04:28 -04003229 *this = Short4(cast);
3230 }
3231
John Bauman19bac1e2014-05-06 15:23:49 -04003232 UShort4::UShort4(RValue<Float4> cast, bool saturate)
John Bauman89401822014-05-06 15:04:28 -04003233 {
John Bauman89401822014-05-06 15:04:28 -04003234 Float4 sat;
3235
3236 if(saturate)
3237 {
3238 if(CPUID::supportsSSE4_1())
3239 {
3240 sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation
3241 }
3242 else
3243 {
3244 sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000));
3245 }
3246 }
3247 else
3248 {
3249 sat = cast;
3250 }
3251
3252 Int4 int4(sat);
3253
3254 if(!saturate || !CPUID::supportsSSE4_1())
3255 {
3256 *this = Short4(Int4(int4));
3257 }
3258 else
3259 {
3260 *this = As<Short4>(Int2(As<Int4>(x86::packusdw(As<UInt4>(int4), As<UInt4>(int4)))));
3261 }
3262 }
3263
3264 UShort4::UShort4()
3265 {
3266 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003267 }
3268
3269 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3270 {
3271 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003272
3273 Constant *constantVector[4];
3274 constantVector[0] = Nucleus::createConstantShort(x);
3275 constantVector[1] = Nucleus::createConstantShort(y);
3276 constantVector[2] = Nucleus::createConstantShort(z);
3277 constantVector[3] = Nucleus::createConstantShort(w);
John Bauman19bac1e2014-05-06 15:23:49 -04003278 Value *vector = Nucleus::createConstantVector(constantVector, 4);
John Bauman89401822014-05-06 15:04:28 -04003279
John Bauman66b8ab22014-05-06 15:57:45 -04003280 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04003281 }
3282
John Bauman19bac1e2014-05-06 15:23:49 -04003283 UShort4::UShort4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003284 {
3285 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003286
John Bauman66b8ab22014-05-06 15:57:45 -04003287 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003288 }
3289
3290 UShort4::UShort4(const UShort4 &rhs)
3291 {
3292 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003293
John Bauman66b8ab22014-05-06 15:57:45 -04003294 Value *value = rhs.loadValue();
3295 storeValue(value);
3296 }
3297
3298 UShort4::UShort4(const Reference<UShort4> &rhs)
3299 {
3300 // xyzw.parent = this;
3301
3302 Value *value = rhs.loadValue();
3303 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003304 }
3305
John Bauman19bac1e2014-05-06 15:23:49 -04003306 UShort4::UShort4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003307 {
3308 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003309
John Bauman66b8ab22014-05-06 15:57:45 -04003310 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003311 }
3312
3313 UShort4::UShort4(const Short4 &rhs)
3314 {
3315 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003316
John Bauman66b8ab22014-05-06 15:57:45 -04003317 Value *value = rhs.loadValue();
3318 storeValue(value);
3319 }
3320
3321 UShort4::UShort4(const Reference<Short4> &rhs)
3322 {
3323 // xyzw.parent = this;
3324
3325 Value *value = rhs.loadValue();
3326 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003327 }
3328
John Bauman19bac1e2014-05-06 15:23:49 -04003329 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003330 {
John Bauman66b8ab22014-05-06 15:57:45 -04003331 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003332
3333 return rhs;
3334 }
3335
3336 RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const
3337 {
John Bauman66b8ab22014-05-06 15:57:45 -04003338 Value *value = rhs.loadValue();
3339 storeValue(value);
3340
3341 return RValue<UShort4>(value);
3342 }
3343
3344 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const
3345 {
3346 Value *value = rhs.loadValue();
3347 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003348
3349 return RValue<UShort4>(value);
3350 }
3351
John Bauman19bac1e2014-05-06 15:23:49 -04003352 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003353 {
John Bauman66b8ab22014-05-06 15:57:45 -04003354 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003355
John Bauman66b8ab22014-05-06 15:57:45 -04003356 return RValue<UShort4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003357 }
3358
3359 RValue<UShort4> UShort4::operator=(const Short4 &rhs) const
3360 {
John Bauman66b8ab22014-05-06 15:57:45 -04003361 Value *value = rhs.loadValue();
3362 storeValue(value);
3363
3364 return RValue<UShort4>(value);
3365 }
3366
3367 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const
3368 {
3369 Value *value = rhs.loadValue();
3370 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003371
3372 return RValue<UShort4>(value);
3373 }
3374
John Bauman19bac1e2014-05-06 15:23:49 -04003375 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003376 {
John Bauman19bac1e2014-05-06 15:23:49 -04003377 if(CPUID::supportsMMX2())
3378 {
3379 return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs)));
3380 }
3381 else
3382 {
3383 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
3384 }
John Bauman89401822014-05-06 15:04:28 -04003385 }
3386
John Bauman19bac1e2014-05-06 15:23:49 -04003387 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003388 {
John Bauman19bac1e2014-05-06 15:23:49 -04003389 if(CPUID::supportsMMX2())
3390 {
3391 return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs)));
3392 }
3393 else
3394 {
3395 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
3396 }
John Bauman89401822014-05-06 15:04:28 -04003397 }
3398
John Bauman19bac1e2014-05-06 15:23:49 -04003399
3400 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003401 {
John Bauman19bac1e2014-05-06 15:23:49 -04003402 if(CPUID::supportsMMX2())
3403 {
3404 return As<UShort4>(x86::pmullw(As<Short4>(lhs), As<Short4>(rhs)));
3405 }
3406 else
3407 {
3408 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
3409 }
John Bauman89401822014-05-06 15:04:28 -04003410 }
3411
John Bauman19bac1e2014-05-06 15:23:49 -04003412 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003413 {
3414 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3415
3416 return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
3417 }
3418
John Bauman19bac1e2014-05-06 15:23:49 -04003419 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003420 {
3421 // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
3422
3423 return x86::psrlw(lhs, rhs);
3424 }
3425
John Bauman19bac1e2014-05-06 15:23:49 -04003426 RValue<UShort4> operator<<(RValue<UShort4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003427 {
3428 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3429
3430 return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
3431 }
3432
John Bauman19bac1e2014-05-06 15:23:49 -04003433 RValue<UShort4> operator>>(RValue<UShort4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003434 {
3435 // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
3436
3437 return x86::psrlw(lhs, rhs);
3438 }
3439
3440 RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs)
3441 {
3442 return lhs = lhs << rhs;
3443 }
3444
3445 RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs)
3446 {
3447 return lhs = lhs >> rhs;
3448 }
3449
John Bauman19bac1e2014-05-06 15:23:49 -04003450 RValue<UShort4> operator<<=(const UShort4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003451 {
3452 return lhs = lhs << rhs;
3453 }
3454
John Bauman19bac1e2014-05-06 15:23:49 -04003455 RValue<UShort4> operator>>=(const UShort4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003456 {
3457 return lhs = lhs >> rhs;
3458 }
3459
John Bauman19bac1e2014-05-06 15:23:49 -04003460 RValue<UShort4> operator~(RValue<UShort4> val)
John Bauman89401822014-05-06 15:04:28 -04003461 {
John Bauman19bac1e2014-05-06 15:23:49 -04003462 if(CPUID::supportsMMX2())
3463 {
3464 return As<UShort4>(As<Short4>(val) ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu));
3465 }
3466 else
3467 {
3468 return RValue<UShort4>(Nucleus::createNot(val.value));
3469 }
John Bauman89401822014-05-06 15:04:28 -04003470 }
3471
John Bauman19bac1e2014-05-06 15:23:49 -04003472 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003473 {
John Bauman66b8ab22014-05-06 15:57:45 -04003474 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 -04003475 }
3476
John Bauman19bac1e2014-05-06 15:23:49 -04003477 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003478 {
John Bauman66b8ab22014-05-06 15:57:45 -04003479 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 -04003480 }
3481
John Bauman19bac1e2014-05-06 15:23:49 -04003482 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003483 {
3484 return x86::paddusw(x, y);
3485 }
3486
John Bauman19bac1e2014-05-06 15:23:49 -04003487 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003488 {
3489 return x86::psubusw(x, y);
3490 }
3491
John Bauman19bac1e2014-05-06 15:23:49 -04003492 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003493 {
3494 return x86::pmulhuw(x, y);
3495 }
3496
John Bauman19bac1e2014-05-06 15:23:49 -04003497 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003498 {
3499 return x86::pavgw(x, y);
3500 }
3501
John Bauman19bac1e2014-05-06 15:23:49 -04003502 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003503 {
3504 return x86::packuswb(x, y);
3505 }
3506
John Bauman19bac1e2014-05-06 15:23:49 -04003507 Type *UShort4::getType()
John Bauman89401822014-05-06 15:04:28 -04003508 {
John Bauman19bac1e2014-05-06 15:23:49 -04003509 if(CPUID::supportsMMX2())
3510 {
3511 return MMX::getType();
3512 }
3513 else
3514 {
3515 return VectorType::get(UShort::getType(), 4);
3516 }
John Bauman89401822014-05-06 15:04:28 -04003517 }
3518
3519 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3520 {
3521 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003522
3523 Constant *constantVector[8];
3524 constantVector[0] = Nucleus::createConstantShort(c0);
3525 constantVector[1] = Nucleus::createConstantShort(c1);
3526 constantVector[2] = Nucleus::createConstantShort(c2);
3527 constantVector[3] = Nucleus::createConstantShort(c3);
3528 constantVector[4] = Nucleus::createConstantShort(c4);
3529 constantVector[5] = Nucleus::createConstantShort(c5);
3530 constantVector[6] = Nucleus::createConstantShort(c6);
3531 constantVector[7] = Nucleus::createConstantShort(c7);
3532
John Bauman66b8ab22014-05-06 15:57:45 -04003533 storeValue(Nucleus::createConstantVector(constantVector, 8));
John Bauman89401822014-05-06 15:04:28 -04003534 }
3535
John Bauman19bac1e2014-05-06 15:23:49 -04003536 Short8::Short8(RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003537 {
3538 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003539
John Bauman66b8ab22014-05-06 15:57:45 -04003540 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003541 }
3542
Nicolas Capens62abb552016-01-05 12:03:47 -05003543 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3544 {
3545 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
3546 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
3547
3548 Value *long2 = UndefValue::get(Long2::getType());
3549 long2 = Nucleus::createInsertElement(long2, loLong, 0);
3550 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
3551 Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
3552
3553 storeValue(short8);
3554 }
3555
John Bauman19bac1e2014-05-06 15:23:49 -04003556 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003557 {
3558 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3559 }
3560
John Bauman19bac1e2014-05-06 15:23:49 -04003561 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003562 {
3563 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3564 }
3565
John Bauman19bac1e2014-05-06 15:23:49 -04003566 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003567 {
3568 return x86::psllw(lhs, rhs); // FIXME: Fallback required
3569 }
3570
John Bauman19bac1e2014-05-06 15:23:49 -04003571 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003572 {
3573 return x86::psraw(lhs, rhs); // FIXME: Fallback required
3574 }
3575
John Bauman19bac1e2014-05-06 15:23:49 -04003576 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003577 {
3578 return x86::pmaddwd(x, y); // FIXME: Fallback required
3579 }
3580
John Bauman19bac1e2014-05-06 15:23:49 -04003581 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003582 {
3583 return x86::pmulhw(x, y); // FIXME: Fallback required
3584 }
3585
John Bauman19bac1e2014-05-06 15:23:49 -04003586 Type *Short8::getType()
John Bauman89401822014-05-06 15:04:28 -04003587 {
3588 return VectorType::get(Short::getType(), 8);
3589 }
3590
3591 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)
3592 {
3593 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003594
3595 Constant *constantVector[8];
3596 constantVector[0] = Nucleus::createConstantShort(c0);
3597 constantVector[1] = Nucleus::createConstantShort(c1);
3598 constantVector[2] = Nucleus::createConstantShort(c2);
3599 constantVector[3] = Nucleus::createConstantShort(c3);
3600 constantVector[4] = Nucleus::createConstantShort(c4);
3601 constantVector[5] = Nucleus::createConstantShort(c5);
3602 constantVector[6] = Nucleus::createConstantShort(c6);
3603 constantVector[7] = Nucleus::createConstantShort(c7);
3604
John Bauman66b8ab22014-05-06 15:57:45 -04003605 storeValue(Nucleus::createConstantVector(constantVector, 8));
John Bauman89401822014-05-06 15:04:28 -04003606 }
3607
John Bauman19bac1e2014-05-06 15:23:49 -04003608 UShort8::UShort8(RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003609 {
3610 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003611
John Bauman66b8ab22014-05-06 15:57:45 -04003612 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003613 }
3614
Nicolas Capens62abb552016-01-05 12:03:47 -05003615 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3616 {
3617 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
3618 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
3619
3620 Value *long2 = UndefValue::get(Long2::getType());
3621 long2 = Nucleus::createInsertElement(long2, loLong, 0);
3622 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
3623 Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
3624
3625 storeValue(short8);
3626 }
3627
John Bauman19bac1e2014-05-06 15:23:49 -04003628 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003629 {
John Bauman66b8ab22014-05-06 15:57:45 -04003630 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003631
3632 return rhs;
3633 }
3634
3635 RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const
3636 {
John Bauman66b8ab22014-05-06 15:57:45 -04003637 Value *value = rhs.loadValue();
3638 storeValue(value);
3639
3640 return RValue<UShort8>(value);
3641 }
3642
3643 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) const
3644 {
3645 Value *value = rhs.loadValue();
3646 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003647
3648 return RValue<UShort8>(value);
3649 }
3650
John Bauman19bac1e2014-05-06 15:23:49 -04003651 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003652 {
3653 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3654 }
3655
John Bauman19bac1e2014-05-06 15:23:49 -04003656 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003657 {
3658 return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required
3659 }
3660
John Bauman19bac1e2014-05-06 15:23:49 -04003661 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003662 {
3663 return x86::psrlw(lhs, rhs); // FIXME: Fallback required
3664 }
3665
John Bauman19bac1e2014-05-06 15:23:49 -04003666 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003667 {
3668 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3669 }
3670
John Bauman19bac1e2014-05-06 15:23:49 -04003671 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003672 {
3673 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3674 }
3675
John Bauman19bac1e2014-05-06 15:23:49 -04003676 RValue<UShort8> operator+=(const UShort8 &lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003677 {
3678 return lhs = lhs + rhs;
3679 }
3680
John Bauman19bac1e2014-05-06 15:23:49 -04003681 RValue<UShort8> operator~(RValue<UShort8> val)
John Bauman89401822014-05-06 15:04:28 -04003682 {
3683 return RValue<UShort8>(Nucleus::createNot(val.value));
3684 }
3685
John Bauman19bac1e2014-05-06 15:23:49 -04003686 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 -04003687 {
3688 Constant *pshufb[16];
3689 pshufb[0] = Nucleus::createConstantInt(select0 + 0);
3690 pshufb[1] = Nucleus::createConstantInt(select0 + 1);
3691 pshufb[2] = Nucleus::createConstantInt(select1 + 0);
3692 pshufb[3] = Nucleus::createConstantInt(select1 + 1);
3693 pshufb[4] = Nucleus::createConstantInt(select2 + 0);
3694 pshufb[5] = Nucleus::createConstantInt(select2 + 1);
3695 pshufb[6] = Nucleus::createConstantInt(select3 + 0);
3696 pshufb[7] = Nucleus::createConstantInt(select3 + 1);
3697 pshufb[8] = Nucleus::createConstantInt(select4 + 0);
3698 pshufb[9] = Nucleus::createConstantInt(select4 + 1);
3699 pshufb[10] = Nucleus::createConstantInt(select5 + 0);
3700 pshufb[11] = Nucleus::createConstantInt(select5 + 1);
3701 pshufb[12] = Nucleus::createConstantInt(select6 + 0);
3702 pshufb[13] = Nucleus::createConstantInt(select6 + 1);
3703 pshufb[14] = Nucleus::createConstantInt(select7 + 0);
3704 pshufb[15] = Nucleus::createConstantInt(select7 + 1);
3705
3706 Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
3707 Value *shuffle = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
3708 Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3709
3710 return RValue<UShort8>(short8);
3711 }
3712
John Bauman19bac1e2014-05-06 15:23:49 -04003713 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04003714 {
3715 return x86::pmulhuw(x, y); // FIXME: Fallback required
3716 }
3717
3718 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
John Bauman19bac1e2014-05-06 15:23:49 -04003719// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
John Bauman89401822014-05-06 15:04:28 -04003720// {
3721// Constant *pshufb[16];
3722// pshufb[0] = Nucleus::createConstantInt(element + 0);
3723// pshufb[1] = Nucleus::createConstantInt(element + 0);
3724// pshufb[2] = Nucleus::createConstantInt(element + 4);
3725// pshufb[3] = Nucleus::createConstantInt(element + 4);
3726// pshufb[4] = Nucleus::createConstantInt(element + 8);
3727// pshufb[5] = Nucleus::createConstantInt(element + 8);
3728// pshufb[6] = Nucleus::createConstantInt(element + 12);
3729// pshufb[7] = Nucleus::createConstantInt(element + 12);
3730// pshufb[8] = Nucleus::createConstantInt(element + 16);
3731// pshufb[9] = Nucleus::createConstantInt(element + 16);
3732// pshufb[10] = Nucleus::createConstantInt(element + 20);
3733// pshufb[11] = Nucleus::createConstantInt(element + 20);
3734// pshufb[12] = Nucleus::createConstantInt(element + 24);
3735// pshufb[13] = Nucleus::createConstantInt(element + 24);
3736// pshufb[14] = Nucleus::createConstantInt(element + 28);
3737// pshufb[15] = Nucleus::createConstantInt(element + 28);
3738//
3739// Value *shuffle = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(pshufb, 16));
3740// Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3741//
3742// return RValue<UShort8>(short8);
3743// }
3744
John Bauman19bac1e2014-05-06 15:23:49 -04003745 Type *UShort8::getType()
John Bauman89401822014-05-06 15:04:28 -04003746 {
3747 return VectorType::get(UShort::getType(), 8);
3748 }
3749
3750 Int::Int(Argument *argument)
3751 {
John Bauman66b8ab22014-05-06 15:57:45 -04003752 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04003753 }
3754
John Bauman19bac1e2014-05-06 15:23:49 -04003755 Int::Int(RValue<Byte> cast)
John Bauman89401822014-05-06 15:04:28 -04003756 {
John Bauman89401822014-05-06 15:04:28 -04003757 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3758
John Bauman66b8ab22014-05-06 15:57:45 -04003759 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003760 }
3761
John Bauman19bac1e2014-05-06 15:23:49 -04003762 Int::Int(RValue<SByte> cast)
John Bauman89401822014-05-06 15:04:28 -04003763 {
John Bauman89401822014-05-06 15:04:28 -04003764 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3765
John Bauman66b8ab22014-05-06 15:57:45 -04003766 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003767 }
3768
John Bauman19bac1e2014-05-06 15:23:49 -04003769 Int::Int(RValue<Short> cast)
John Bauman89401822014-05-06 15:04:28 -04003770 {
John Bauman89401822014-05-06 15:04:28 -04003771 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3772
John Bauman66b8ab22014-05-06 15:57:45 -04003773 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003774 }
3775
John Bauman19bac1e2014-05-06 15:23:49 -04003776 Int::Int(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04003777 {
John Bauman89401822014-05-06 15:04:28 -04003778 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3779
John Bauman66b8ab22014-05-06 15:57:45 -04003780 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003781 }
3782
John Bauman19bac1e2014-05-06 15:23:49 -04003783 Int::Int(RValue<Int2> cast)
John Bauman89401822014-05-06 15:04:28 -04003784 {
John Bauman89401822014-05-06 15:04:28 -04003785 *this = Extract(cast, 0);
3786 }
3787
John Bauman19bac1e2014-05-06 15:23:49 -04003788 Int::Int(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04003789 {
John Bauman89401822014-05-06 15:04:28 -04003790 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3791
John Bauman66b8ab22014-05-06 15:57:45 -04003792 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003793 }
3794
John Bauman19bac1e2014-05-06 15:23:49 -04003795 Int::Int(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04003796 {
John Bauman89401822014-05-06 15:04:28 -04003797 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3798
John Bauman66b8ab22014-05-06 15:57:45 -04003799 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003800 }
3801
3802 Int::Int()
3803 {
John Bauman89401822014-05-06 15:04:28 -04003804 }
3805
3806 Int::Int(int x)
3807 {
John Bauman66b8ab22014-05-06 15:57:45 -04003808 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04003809 }
3810
John Bauman19bac1e2014-05-06 15:23:49 -04003811 Int::Int(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003812 {
John Bauman66b8ab22014-05-06 15:57:45 -04003813 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003814 }
3815
John Bauman19bac1e2014-05-06 15:23:49 -04003816 Int::Int(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003817 {
John Bauman66b8ab22014-05-06 15:57:45 -04003818 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003819 }
3820
3821 Int::Int(const Int &rhs)
3822 {
John Bauman66b8ab22014-05-06 15:57:45 -04003823 Value *value = rhs.loadValue();
3824 storeValue(value);
3825 }
John Bauman89401822014-05-06 15:04:28 -04003826
John Bauman66b8ab22014-05-06 15:57:45 -04003827 Int::Int(const Reference<Int> &rhs)
3828 {
3829 Value *value = rhs.loadValue();
3830 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003831 }
3832
3833 Int::Int(const UInt &rhs)
3834 {
John Bauman66b8ab22014-05-06 15:57:45 -04003835 Value *value = rhs.loadValue();
3836 storeValue(value);
3837 }
John Bauman89401822014-05-06 15:04:28 -04003838
John Bauman66b8ab22014-05-06 15:57:45 -04003839 Int::Int(const Reference<UInt> &rhs)
3840 {
3841 Value *value = rhs.loadValue();
3842 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003843 }
3844
3845 RValue<Int> Int::operator=(int rhs) const
3846 {
John Bauman66b8ab22014-05-06 15:57:45 -04003847 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04003848 }
3849
John Bauman19bac1e2014-05-06 15:23:49 -04003850 RValue<Int> Int::operator=(RValue<Int> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003851 {
John Bauman66b8ab22014-05-06 15:57:45 -04003852 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003853
3854 return rhs;
3855 }
3856
John Bauman19bac1e2014-05-06 15:23:49 -04003857 RValue<Int> Int::operator=(RValue<UInt> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003858 {
John Bauman66b8ab22014-05-06 15:57:45 -04003859 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003860
John Bauman66b8ab22014-05-06 15:57:45 -04003861 return RValue<Int>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003862 }
3863
3864 RValue<Int> Int::operator=(const Int &rhs) const
3865 {
John Bauman66b8ab22014-05-06 15:57:45 -04003866 Value *value = rhs.loadValue();
3867 storeValue(value);
3868
3869 return RValue<Int>(value);
3870 }
3871
3872 RValue<Int> Int::operator=(const Reference<Int> &rhs) const
3873 {
3874 Value *value = rhs.loadValue();
3875 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003876
3877 return RValue<Int>(value);
3878 }
3879
3880 RValue<Int> Int::operator=(const UInt &rhs) const
3881 {
John Bauman66b8ab22014-05-06 15:57:45 -04003882 Value *value = rhs.loadValue();
3883 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003884
3885 return RValue<Int>(value);
3886 }
3887
John Bauman66b8ab22014-05-06 15:57:45 -04003888 RValue<Int> Int::operator=(const Reference<UInt> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04003889 {
John Bauman66b8ab22014-05-06 15:57:45 -04003890 Value *value = rhs.loadValue();
3891 storeValue(value);
3892
3893 return RValue<Int>(value);
John Bauman89401822014-05-06 15:04:28 -04003894 }
3895
John Bauman19bac1e2014-05-06 15:23:49 -04003896 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003897 {
3898 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3899 }
3900
John Bauman19bac1e2014-05-06 15:23:49 -04003901 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003902 {
3903 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3904 }
3905
John Bauman19bac1e2014-05-06 15:23:49 -04003906 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003907 {
3908 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3909 }
3910
John Bauman19bac1e2014-05-06 15:23:49 -04003911 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003912 {
3913 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3914 }
3915
John Bauman19bac1e2014-05-06 15:23:49 -04003916 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003917 {
3918 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3919 }
3920
John Bauman19bac1e2014-05-06 15:23:49 -04003921 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003922 {
3923 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3924 }
3925
John Bauman19bac1e2014-05-06 15:23:49 -04003926 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003927 {
3928 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3929 }
3930
John Bauman19bac1e2014-05-06 15:23:49 -04003931 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003932 {
3933 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
3934 }
3935
John Bauman19bac1e2014-05-06 15:23:49 -04003936 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003937 {
3938 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
3939 }
3940
John Bauman19bac1e2014-05-06 15:23:49 -04003941 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003942 {
3943 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
3944 }
3945
John Bauman19bac1e2014-05-06 15:23:49 -04003946 RValue<Int> operator+=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003947 {
3948 return lhs = lhs + rhs;
3949 }
3950
John Bauman19bac1e2014-05-06 15:23:49 -04003951 RValue<Int> operator-=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003952 {
3953 return lhs = lhs - rhs;
3954 }
3955
John Bauman19bac1e2014-05-06 15:23:49 -04003956 RValue<Int> operator*=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003957 {
3958 return lhs = lhs * rhs;
3959 }
3960
John Bauman19bac1e2014-05-06 15:23:49 -04003961 RValue<Int> operator/=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003962 {
3963 return lhs = lhs / rhs;
3964 }
3965
John Bauman19bac1e2014-05-06 15:23:49 -04003966 RValue<Int> operator%=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003967 {
3968 return lhs = lhs % rhs;
3969 }
3970
John Bauman19bac1e2014-05-06 15:23:49 -04003971 RValue<Int> operator&=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003972 {
3973 return lhs = lhs & rhs;
3974 }
3975
John Bauman19bac1e2014-05-06 15:23:49 -04003976 RValue<Int> operator|=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003977 {
3978 return lhs = lhs | rhs;
3979 }
3980
John Bauman19bac1e2014-05-06 15:23:49 -04003981 RValue<Int> operator^=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003982 {
3983 return lhs = lhs ^ rhs;
3984 }
3985
John Bauman19bac1e2014-05-06 15:23:49 -04003986 RValue<Int> operator<<=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003987 {
3988 return lhs = lhs << rhs;
3989 }
3990
John Bauman19bac1e2014-05-06 15:23:49 -04003991 RValue<Int> operator>>=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003992 {
3993 return lhs = lhs >> rhs;
3994 }
3995
John Bauman19bac1e2014-05-06 15:23:49 -04003996 RValue<Int> operator+(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003997 {
3998 return val;
3999 }
4000
John Bauman19bac1e2014-05-06 15:23:49 -04004001 RValue<Int> operator-(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04004002 {
4003 return RValue<Int>(Nucleus::createNeg(val.value));
4004 }
4005
John Bauman19bac1e2014-05-06 15:23:49 -04004006 RValue<Int> operator~(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04004007 {
4008 return RValue<Int>(Nucleus::createNot(val.value));
4009 }
4010
4011 RValue<Int> operator++(const Int &val, int) // Post-increment
4012 {
4013 RValue<Int> res = val;
4014
4015 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004016 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004017
4018 return res;
4019 }
4020
4021 const Int &operator++(const Int &val) // Pre-increment
4022 {
John Bauman66b8ab22014-05-06 15:57:45 -04004023 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
4024 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004025
4026 return val;
4027 }
4028
4029 RValue<Int> operator--(const Int &val, int) // Post-decrement
4030 {
4031 RValue<Int> res = val;
4032
4033 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004034 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004035
4036 return res;
4037 }
4038
4039 const Int &operator--(const Int &val) // Pre-decrement
4040 {
John Bauman66b8ab22014-05-06 15:57:45 -04004041 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
4042 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004043
4044 return val;
4045 }
4046
John Bauman19bac1e2014-05-06 15:23:49 -04004047 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004048 {
4049 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4050 }
4051
John Bauman19bac1e2014-05-06 15:23:49 -04004052 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004053 {
4054 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4055 }
4056
John Bauman19bac1e2014-05-06 15:23:49 -04004057 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004058 {
4059 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4060 }
4061
John Bauman19bac1e2014-05-06 15:23:49 -04004062 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004063 {
4064 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4065 }
4066
John Bauman19bac1e2014-05-06 15:23:49 -04004067 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004068 {
4069 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4070 }
4071
John Bauman19bac1e2014-05-06 15:23:49 -04004072 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004073 {
4074 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4075 }
4076
John Bauman19bac1e2014-05-06 15:23:49 -04004077 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4078 {
4079 return IfThenElse(x > y, x, y);
4080 }
4081
4082 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4083 {
4084 return IfThenElse(x < y, x, y);
4085 }
4086
4087 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4088 {
4089 return Min(Max(x, min), max);
4090 }
4091
4092 RValue<Int> RoundInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004093 {
4094 return x86::cvtss2si(cast);
4095
John Bauman66b8ab22014-05-06 15:57:45 -04004096 // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004097 }
4098
John Bauman19bac1e2014-05-06 15:23:49 -04004099 Type *Int::getType()
John Bauman89401822014-05-06 15:04:28 -04004100 {
4101 return Type::getInt32Ty(*Nucleus::getContext());
4102 }
4103
John Bauman19bac1e2014-05-06 15:23:49 -04004104 Long::Long(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04004105 {
John Bauman66b8ab22014-05-06 15:57:45 -04004106
John Bauman89401822014-05-06 15:04:28 -04004107
4108 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4109
John Bauman66b8ab22014-05-06 15:57:45 -04004110 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004111 }
4112
John Bauman19bac1e2014-05-06 15:23:49 -04004113 Long::Long(RValue<UInt> cast)
John Bauman89401822014-05-06 15:04:28 -04004114 {
John Bauman89401822014-05-06 15:04:28 -04004115 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4116
John Bauman66b8ab22014-05-06 15:57:45 -04004117 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004118 }
4119
4120 Long::Long()
4121 {
John Bauman89401822014-05-06 15:04:28 -04004122 }
4123
John Bauman19bac1e2014-05-06 15:23:49 -04004124 Long::Long(RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004125 {
John Bauman66b8ab22014-05-06 15:57:45 -04004126 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004127 }
4128
4129 RValue<Long> Long::operator=(int64_t rhs) const
4130 {
John Bauman66b8ab22014-05-06 15:57:45 -04004131 return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04004132 }
4133
John Bauman19bac1e2014-05-06 15:23:49 -04004134 RValue<Long> Long::operator=(RValue<Long> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004135 {
John Bauman66b8ab22014-05-06 15:57:45 -04004136 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004137
4138 return rhs;
4139 }
4140
4141 RValue<Long> Long::operator=(const Long &rhs) const
4142 {
John Bauman66b8ab22014-05-06 15:57:45 -04004143 Value *value = rhs.loadValue();
4144 storeValue(value);
4145
4146 return RValue<Long>(value);
4147 }
4148
4149 RValue<Long> Long::operator=(const Reference<Long> &rhs) const
4150 {
4151 Value *value = rhs.loadValue();
4152 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004153
4154 return RValue<Long>(value);
4155 }
4156
John Bauman19bac1e2014-05-06 15:23:49 -04004157 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004158 {
4159 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4160 }
4161
John Bauman19bac1e2014-05-06 15:23:49 -04004162 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004163 {
4164 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4165 }
4166
John Bauman19bac1e2014-05-06 15:23:49 -04004167 RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004168 {
4169 return lhs = lhs + rhs;
4170 }
4171
John Bauman19bac1e2014-05-06 15:23:49 -04004172 RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004173 {
4174 return lhs = lhs - rhs;
4175 }
4176
John Bauman66b8ab22014-05-06 15:57:45 -04004177 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
John Bauman89401822014-05-06 15:04:28 -04004178 {
John Bauman19bac1e2014-05-06 15:23:49 -04004179 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
John Bauman89401822014-05-06 15:04:28 -04004180 }
4181
John Bauman19bac1e2014-05-06 15:23:49 -04004182 Type *Long::getType()
John Bauman89401822014-05-06 15:04:28 -04004183 {
4184 return Type::getInt64Ty(*Nucleus::getContext());
4185 }
4186
Nicolas Capens50c96362016-01-04 23:03:59 -05004187 Long1::Long1(const RValue<UInt> cast)
John Bauman89401822014-05-06 15:04:28 -04004188 {
Nicolas Capens50c96362016-01-04 23:03:59 -05004189 Value *undefCast = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), cast.value, 0);
4190 Value *zeroCast = Nucleus::createInsertElement(undefCast, Nucleus::createConstantInt(0), 1);
John Bauman66b8ab22014-05-06 15:57:45 -04004191
Nicolas Capens50c96362016-01-04 23:03:59 -05004192 storeValue(Nucleus::createBitCast(zeroCast, Long1::getType()));
John Bauman89401822014-05-06 15:04:28 -04004193 }
4194
John Bauman19bac1e2014-05-06 15:23:49 -04004195 Long1::Long1(RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004196 {
John Bauman66b8ab22014-05-06 15:57:45 -04004197 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004198 }
4199
John Bauman19bac1e2014-05-06 15:23:49 -04004200 Type *Long1::getType()
John Bauman89401822014-05-06 15:04:28 -04004201 {
John Bauman19bac1e2014-05-06 15:23:49 -04004202 if(CPUID::supportsMMX2())
4203 {
4204 return MMX::getType();
4205 }
4206 else
4207 {
4208 return VectorType::get(Long::getType(), 1);
4209 }
John Bauman89401822014-05-06 15:04:28 -04004210 }
4211
John Bauman19bac1e2014-05-06 15:23:49 -04004212 RValue<Long2> UnpackHigh(RValue<Long2> x, RValue<Long2> y)
John Bauman89401822014-05-06 15:04:28 -04004213 {
4214 Constant *shuffle[2];
4215 shuffle[0] = Nucleus::createConstantInt(1);
4216 shuffle[1] = Nucleus::createConstantInt(3);
4217
4218 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
4219
4220 return RValue<Long2>(packed);
4221 }
4222
John Bauman19bac1e2014-05-06 15:23:49 -04004223 Type *Long2::getType()
John Bauman89401822014-05-06 15:04:28 -04004224 {
4225 return VectorType::get(Long::getType(), 2);
4226 }
4227
4228 UInt::UInt(Argument *argument)
4229 {
John Bauman66b8ab22014-05-06 15:57:45 -04004230 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04004231 }
4232
John Bauman19bac1e2014-05-06 15:23:49 -04004233 UInt::UInt(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04004234 {
John Bauman89401822014-05-06 15:04:28 -04004235 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4236
John Bauman66b8ab22014-05-06 15:57:45 -04004237 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004238 }
4239
John Bauman19bac1e2014-05-06 15:23:49 -04004240 UInt::UInt(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04004241 {
John Bauman89401822014-05-06 15:04:28 -04004242 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4243
John Bauman66b8ab22014-05-06 15:57:45 -04004244 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004245 }
4246
John Bauman19bac1e2014-05-06 15:23:49 -04004247 UInt::UInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004248 {
Alexis Hetu77dfab42015-11-23 13:31:22 -05004249 Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType());
John Bauman89401822014-05-06 15:04:28 -04004250
John Bauman66b8ab22014-05-06 15:57:45 -04004251 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004252 }
4253
4254 UInt::UInt()
4255 {
John Bauman89401822014-05-06 15:04:28 -04004256 }
4257
4258 UInt::UInt(int x)
4259 {
John Bauman66b8ab22014-05-06 15:57:45 -04004260 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04004261 }
4262
4263 UInt::UInt(unsigned int x)
4264 {
John Bauman66b8ab22014-05-06 15:57:45 -04004265 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04004266 }
4267
John Bauman19bac1e2014-05-06 15:23:49 -04004268 UInt::UInt(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004269 {
John Bauman66b8ab22014-05-06 15:57:45 -04004270 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004271 }
4272
John Bauman19bac1e2014-05-06 15:23:49 -04004273 UInt::UInt(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004274 {
John Bauman66b8ab22014-05-06 15:57:45 -04004275 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004276 }
4277
4278 UInt::UInt(const UInt &rhs)
4279 {
John Bauman66b8ab22014-05-06 15:57:45 -04004280 Value *value = rhs.loadValue();
4281 storeValue(value);
4282 }
John Bauman89401822014-05-06 15:04:28 -04004283
John Bauman66b8ab22014-05-06 15:57:45 -04004284 UInt::UInt(const Reference<UInt> &rhs)
4285 {
4286 Value *value = rhs.loadValue();
4287 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004288 }
4289
4290 UInt::UInt(const Int &rhs)
4291 {
John Bauman66b8ab22014-05-06 15:57:45 -04004292 Value *value = rhs.loadValue();
4293 storeValue(value);
4294 }
John Bauman89401822014-05-06 15:04:28 -04004295
John Bauman66b8ab22014-05-06 15:57:45 -04004296 UInt::UInt(const Reference<Int> &rhs)
4297 {
4298 Value *value = rhs.loadValue();
4299 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004300 }
4301
4302 RValue<UInt> UInt::operator=(unsigned int rhs) const
4303 {
John Bauman66b8ab22014-05-06 15:57:45 -04004304 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04004305 }
4306
John Bauman19bac1e2014-05-06 15:23:49 -04004307 RValue<UInt> UInt::operator=(RValue<UInt> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004308 {
John Bauman66b8ab22014-05-06 15:57:45 -04004309 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004310
4311 return rhs;
4312 }
4313
John Bauman19bac1e2014-05-06 15:23:49 -04004314 RValue<UInt> UInt::operator=(RValue<Int> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004315 {
John Bauman66b8ab22014-05-06 15:57:45 -04004316 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004317
John Bauman66b8ab22014-05-06 15:57:45 -04004318 return RValue<UInt>(rhs);
John Bauman89401822014-05-06 15:04:28 -04004319 }
4320
4321 RValue<UInt> UInt::operator=(const UInt &rhs) const
4322 {
John Bauman66b8ab22014-05-06 15:57:45 -04004323 Value *value = rhs.loadValue();
4324 storeValue(value);
4325
4326 return RValue<UInt>(value);
4327 }
4328
4329 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const
4330 {
4331 Value *value = rhs.loadValue();
4332 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004333
4334 return RValue<UInt>(value);
4335 }
4336
4337 RValue<UInt> UInt::operator=(const Int &rhs) const
4338 {
John Bauman66b8ab22014-05-06 15:57:45 -04004339 Value *value = rhs.loadValue();
4340 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004341
4342 return RValue<UInt>(value);
4343 }
4344
John Bauman66b8ab22014-05-06 15:57:45 -04004345 RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04004346 {
John Bauman66b8ab22014-05-06 15:57:45 -04004347 Value *value = rhs.loadValue();
4348 storeValue(value);
4349
4350 return RValue<UInt>(value);
John Bauman89401822014-05-06 15:04:28 -04004351 }
4352
John Bauman19bac1e2014-05-06 15:23:49 -04004353 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004354 {
4355 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4356 }
4357
John Bauman19bac1e2014-05-06 15:23:49 -04004358 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004359 {
4360 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4361 }
4362
John Bauman19bac1e2014-05-06 15:23:49 -04004363 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004364 {
4365 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4366 }
4367
John Bauman19bac1e2014-05-06 15:23:49 -04004368 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004369 {
4370 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4371 }
4372
John Bauman19bac1e2014-05-06 15:23:49 -04004373 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004374 {
4375 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4376 }
4377
John Bauman19bac1e2014-05-06 15:23:49 -04004378 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004379 {
4380 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4381 }
4382
John Bauman19bac1e2014-05-06 15:23:49 -04004383 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004384 {
4385 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4386 }
4387
John Bauman19bac1e2014-05-06 15:23:49 -04004388 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004389 {
4390 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4391 }
4392
John Bauman19bac1e2014-05-06 15:23:49 -04004393 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004394 {
4395 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4396 }
4397
John Bauman19bac1e2014-05-06 15:23:49 -04004398 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004399 {
4400 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4401 }
4402
John Bauman19bac1e2014-05-06 15:23:49 -04004403 RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004404 {
4405 return lhs = lhs + rhs;
4406 }
4407
John Bauman19bac1e2014-05-06 15:23:49 -04004408 RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004409 {
4410 return lhs = lhs - rhs;
4411 }
4412
John Bauman19bac1e2014-05-06 15:23:49 -04004413 RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004414 {
4415 return lhs = lhs * rhs;
4416 }
4417
John Bauman19bac1e2014-05-06 15:23:49 -04004418 RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004419 {
4420 return lhs = lhs / rhs;
4421 }
4422
John Bauman19bac1e2014-05-06 15:23:49 -04004423 RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004424 {
4425 return lhs = lhs % rhs;
4426 }
4427
John Bauman19bac1e2014-05-06 15:23:49 -04004428 RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004429 {
4430 return lhs = lhs & rhs;
4431 }
4432
John Bauman19bac1e2014-05-06 15:23:49 -04004433 RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004434 {
4435 return lhs = lhs | rhs;
4436 }
4437
John Bauman19bac1e2014-05-06 15:23:49 -04004438 RValue<UInt> operator^=(const UInt &lhs, RValue<UInt> 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<UInt> operator<<=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004444 {
4445 return lhs = lhs << rhs;
4446 }
4447
John Bauman19bac1e2014-05-06 15:23:49 -04004448 RValue<UInt> operator>>=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004449 {
4450 return lhs = lhs >> rhs;
4451 }
4452
John Bauman19bac1e2014-05-06 15:23:49 -04004453 RValue<UInt> operator+(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004454 {
4455 return val;
4456 }
4457
John Bauman19bac1e2014-05-06 15:23:49 -04004458 RValue<UInt> operator-(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004459 {
4460 return RValue<UInt>(Nucleus::createNeg(val.value));
4461 }
4462
John Bauman19bac1e2014-05-06 15:23:49 -04004463 RValue<UInt> operator~(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004464 {
4465 return RValue<UInt>(Nucleus::createNot(val.value));
4466 }
4467
4468 RValue<UInt> operator++(const UInt &val, int) // Post-increment
4469 {
4470 RValue<UInt> res = val;
4471
4472 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004473 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004474
4475 return res;
4476 }
4477
4478 const UInt &operator++(const UInt &val) // Pre-increment
4479 {
John Bauman66b8ab22014-05-06 15:57:45 -04004480 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
4481 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004482
4483 return val;
4484 }
4485
4486 RValue<UInt> operator--(const UInt &val, int) // Post-decrement
4487 {
4488 RValue<UInt> res = val;
4489
4490 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004491 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004492
4493 return res;
4494 }
4495
4496 const UInt &operator--(const UInt &val) // Pre-decrement
4497 {
John Bauman66b8ab22014-05-06 15:57:45 -04004498 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
4499 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004500
4501 return val;
4502 }
4503
John Bauman19bac1e2014-05-06 15:23:49 -04004504 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4505 {
4506 return IfThenElse(x > y, x, y);
4507 }
4508
4509 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4510 {
4511 return IfThenElse(x < y, x, y);
4512 }
4513
4514 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4515 {
4516 return Min(Max(x, min), max);
4517 }
4518
4519 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004520 {
4521 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4522 }
4523
John Bauman19bac1e2014-05-06 15:23:49 -04004524 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004525 {
4526 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4527 }
4528
John Bauman19bac1e2014-05-06 15:23:49 -04004529 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004530 {
4531 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4532 }
4533
John Bauman19bac1e2014-05-06 15:23:49 -04004534 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004535 {
4536 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4537 }
4538
John Bauman19bac1e2014-05-06 15:23:49 -04004539 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004540 {
4541 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4542 }
4543
John Bauman19bac1e2014-05-06 15:23:49 -04004544 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004545 {
4546 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4547 }
4548
John Bauman19bac1e2014-05-06 15:23:49 -04004549// RValue<UInt> RoundUInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004550// {
4551// return x86::cvtss2si(val); // FIXME: Unsigned
4552//
John Bauman66b8ab22014-05-06 15:57:45 -04004553// // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004554// }
4555
John Bauman19bac1e2014-05-06 15:23:49 -04004556 Type *UInt::getType()
John Bauman89401822014-05-06 15:04:28 -04004557 {
4558 return Type::getInt32Ty(*Nucleus::getContext());
4559 }
4560
John Bauman19bac1e2014-05-06 15:23:49 -04004561// Int2::Int2(RValue<Int> cast)
4562// {
John Bauman19bac1e2014-05-06 15:23:49 -04004563// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4564// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04004565//
John Bauman19bac1e2014-05-06 15:23:49 -04004566// Constant *shuffle[2];
4567// shuffle[0] = Nucleus::createConstantInt(0);
4568// shuffle[1] = Nucleus::createConstantInt(0);
4569//
4570// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4571//
John Bauman66b8ab22014-05-06 15:57:45 -04004572// storeValue(replicate);
John Bauman19bac1e2014-05-06 15:23:49 -04004573// }
John Bauman89401822014-05-06 15:04:28 -04004574
John Bauman19bac1e2014-05-06 15:23:49 -04004575 Int2::Int2(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04004576 {
John Bauman89401822014-05-06 15:04:28 -04004577 Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType());
4578 Value *element = Nucleus::createExtractElement(long2, 0);
4579 Value *int2 = Nucleus::createBitCast(element, Int2::getType());
4580
John Bauman66b8ab22014-05-06 15:57:45 -04004581 storeValue(int2);
John Bauman89401822014-05-06 15:04:28 -04004582 }
4583
4584 Int2::Int2()
4585 {
4586 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004587 }
4588
4589 Int2::Int2(int x, int y)
4590 {
4591 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004592
4593 Constant *constantVector[2];
4594 constantVector[0] = Nucleus::createConstantInt(x);
4595 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004596 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004597
John Bauman66b8ab22014-05-06 15:57:45 -04004598 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004599 }
4600
John Bauman19bac1e2014-05-06 15:23:49 -04004601 Int2::Int2(RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004602 {
4603 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004604
John Bauman66b8ab22014-05-06 15:57:45 -04004605 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004606 }
4607
4608 Int2::Int2(const Int2 &rhs)
4609 {
4610 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004611
John Bauman66b8ab22014-05-06 15:57:45 -04004612 Value *value = rhs.loadValue();
4613 storeValue(value);
4614 }
4615
4616 Int2::Int2(const Reference<Int2> &rhs)
4617 {
4618 // xy.parent = this;
4619
4620 Value *value = rhs.loadValue();
4621 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004622 }
4623
Nicolas Capens62abb552016-01-05 12:03:47 -05004624 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4625 {
Nicolas Capensb40a2562016-01-05 00:08:45 -05004626 if(CPUID::supportsMMX2())
4627 {
4628 // movd mm0, lo
4629 // movd mm1, hi
4630 // punpckldq mm0, mm1
4631 storeValue(As<Int2>(UnpackLow(As<Int2>(Long1(RValue<UInt>(lo))), As<Int2>(Long1(RValue<UInt>(hi))))).value);
4632 }
4633 else
4634 {
4635 Constant *shuffle[2];
4636 shuffle[0] = Nucleus::createConstantInt(0);
4637 shuffle[1] = Nucleus::createConstantInt(1);
4638
4639 Value *packed = Nucleus::createShuffleVector(Nucleus::createBitCast(lo.value, VectorType::get(Int::getType(), 1)), Nucleus::createBitCast(hi.value, VectorType::get(Int::getType(), 1)), Nucleus::createConstantVector(shuffle, 2));
4640
4641 storeValue(Nucleus::createBitCast(packed, Int2::getType()));
4642 }
Nicolas Capens62abb552016-01-05 12:03:47 -05004643 }
4644
John Bauman19bac1e2014-05-06 15:23:49 -04004645 RValue<Int2> Int2::operator=(RValue<Int2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004646 {
John Bauman66b8ab22014-05-06 15:57:45 -04004647 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004648
4649 return rhs;
4650 }
4651
4652 RValue<Int2> Int2::operator=(const Int2 &rhs) const
4653 {
John Bauman66b8ab22014-05-06 15:57:45 -04004654 Value *value = rhs.loadValue();
4655 storeValue(value);
4656
4657 return RValue<Int2>(value);
4658 }
4659
4660 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const
4661 {
4662 Value *value = rhs.loadValue();
4663 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004664
4665 return RValue<Int2>(value);
4666 }
4667
John Bauman19bac1e2014-05-06 15:23:49 -04004668 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004669 {
John Bauman19bac1e2014-05-06 15:23:49 -04004670 if(CPUID::supportsMMX2())
4671 {
4672 return x86::paddd(lhs, rhs);
4673 }
4674 else
4675 {
4676 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
4677 }
John Bauman89401822014-05-06 15:04:28 -04004678 }
4679
John Bauman19bac1e2014-05-06 15:23:49 -04004680 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004681 {
John Bauman19bac1e2014-05-06 15:23:49 -04004682 if(CPUID::supportsMMX2())
4683 {
4684 return x86::psubd(lhs, rhs);
4685 }
4686 else
4687 {
4688 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
4689 }
John Bauman89401822014-05-06 15:04:28 -04004690 }
4691
John Bauman19bac1e2014-05-06 15:23:49 -04004692// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4693// {
4694// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4695// }
4696
4697// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4698// {
4699// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4700// }
4701
4702// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4703// {
4704// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4705// }
4706
4707 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004708 {
John Bauman19bac1e2014-05-06 15:23:49 -04004709 if(CPUID::supportsMMX2())
4710 {
4711 return As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
4712 }
4713 else
4714 {
4715 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
4716 }
John Bauman89401822014-05-06 15:04:28 -04004717 }
4718
John Bauman19bac1e2014-05-06 15:23:49 -04004719 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004720 {
John Bauman19bac1e2014-05-06 15:23:49 -04004721 if(CPUID::supportsMMX2())
4722 {
4723 return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
4724 }
4725 else
4726 {
4727 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
4728 }
John Bauman89401822014-05-06 15:04:28 -04004729 }
4730
John Bauman19bac1e2014-05-06 15:23:49 -04004731 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004732 {
John Bauman19bac1e2014-05-06 15:23:49 -04004733 if(CPUID::supportsMMX2())
4734 {
4735 return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
4736 }
4737 else
4738 {
4739 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
4740 }
John Bauman89401822014-05-06 15:04:28 -04004741 }
4742
John Bauman19bac1e2014-05-06 15:23:49 -04004743 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004744 {
4745 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4746
4747 return x86::pslld(lhs, rhs);
4748 }
4749
John Bauman19bac1e2014-05-06 15:23:49 -04004750 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004751 {
4752 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4753
4754 return x86::psrad(lhs, rhs);
4755 }
4756
John Bauman19bac1e2014-05-06 15:23:49 -04004757 RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004758 {
4759 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4760
4761 return x86::pslld(lhs, rhs);
4762 }
4763
John Bauman19bac1e2014-05-06 15:23:49 -04004764 RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004765 {
4766 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4767
4768 return x86::psrad(lhs, rhs);
4769 }
4770
John Bauman19bac1e2014-05-06 15:23:49 -04004771 RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004772 {
4773 return lhs = lhs + rhs;
4774 }
4775
John Bauman19bac1e2014-05-06 15:23:49 -04004776 RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004777 {
4778 return lhs = lhs - rhs;
4779 }
4780
John Bauman19bac1e2014-05-06 15:23:49 -04004781// RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs)
4782// {
4783// return lhs = lhs * rhs;
4784// }
John Bauman89401822014-05-06 15:04:28 -04004785
John Bauman19bac1e2014-05-06 15:23:49 -04004786// RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs)
4787// {
4788// return lhs = lhs / rhs;
4789// }
John Bauman89401822014-05-06 15:04:28 -04004790
John Bauman19bac1e2014-05-06 15:23:49 -04004791// RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs)
4792// {
4793// return lhs = lhs % rhs;
4794// }
John Bauman89401822014-05-06 15:04:28 -04004795
John Bauman19bac1e2014-05-06 15:23:49 -04004796 RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004797 {
4798 return lhs = lhs & rhs;
4799 }
4800
John Bauman19bac1e2014-05-06 15:23:49 -04004801 RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004802 {
4803 return lhs = lhs | rhs;
4804 }
4805
John Bauman19bac1e2014-05-06 15:23:49 -04004806 RValue<Int2> operator^=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004807 {
4808 return lhs = lhs ^ rhs;
4809 }
4810
4811 RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs)
4812 {
4813 return lhs = lhs << rhs;
4814 }
4815
4816 RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs)
4817 {
4818 return lhs = lhs >> rhs;
4819 }
4820
John Bauman19bac1e2014-05-06 15:23:49 -04004821 RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004822 {
4823 return lhs = lhs << rhs;
4824 }
4825
John Bauman19bac1e2014-05-06 15:23:49 -04004826 RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004827 {
4828 return lhs = lhs >> rhs;
4829 }
4830
John Bauman19bac1e2014-05-06 15:23:49 -04004831// RValue<Int2> operator+(RValue<Int2> val)
4832// {
4833// return val;
4834// }
4835
4836// RValue<Int2> operator-(RValue<Int2> val)
4837// {
4838// return RValue<Int2>(Nucleus::createNeg(val.value));
4839// }
4840
4841 RValue<Int2> operator~(RValue<Int2> val)
John Bauman89401822014-05-06 15:04:28 -04004842 {
John Bauman19bac1e2014-05-06 15:23:49 -04004843 if(CPUID::supportsMMX2())
4844 {
4845 return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF);
4846 }
4847 else
4848 {
4849 return RValue<Int2>(Nucleus::createNot(val.value));
4850 }
John Bauman89401822014-05-06 15:04:28 -04004851 }
4852
John Bauman19bac1e2014-05-06 15:23:49 -04004853 RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004854 {
John Bauman19bac1e2014-05-06 15:23:49 -04004855 if(CPUID::supportsMMX2())
4856 {
4857 return x86::punpckldq(x, y);
4858 }
4859 else
4860 {
4861 Constant *shuffle[2];
4862 shuffle[0] = Nucleus::createConstantInt(0);
4863 shuffle[1] = Nucleus::createConstantInt(2);
John Bauman89401822014-05-06 15:04:28 -04004864
John Bauman19bac1e2014-05-06 15:23:49 -04004865 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
John Bauman89401822014-05-06 15:04:28 -04004866
John Bauman19bac1e2014-05-06 15:23:49 -04004867 return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
4868 }
John Bauman89401822014-05-06 15:04:28 -04004869 }
John Bauman66b8ab22014-05-06 15:57:45 -04004870
John Bauman19bac1e2014-05-06 15:23:49 -04004871 RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004872 {
John Bauman19bac1e2014-05-06 15:23:49 -04004873 if(CPUID::supportsMMX2())
4874 {
4875 return x86::punpckhdq(x, y);
4876 }
4877 else
4878 {
4879 Constant *shuffle[2];
4880 shuffle[0] = Nucleus::createConstantInt(1);
4881 shuffle[1] = Nucleus::createConstantInt(3);
John Bauman89401822014-05-06 15:04:28 -04004882
John Bauman19bac1e2014-05-06 15:23:49 -04004883 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
John Bauman89401822014-05-06 15:04:28 -04004884
John Bauman19bac1e2014-05-06 15:23:49 -04004885 return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
4886 }
John Bauman89401822014-05-06 15:04:28 -04004887 }
4888
John Bauman19bac1e2014-05-06 15:23:49 -04004889 RValue<Int> Extract(RValue<Int2> val, int i)
John Bauman89401822014-05-06 15:04:28 -04004890 {
4891 if(false) // FIXME: LLVM does not generate optimal code
4892 {
4893 return RValue<Int>(Nucleus::createExtractElement(val.value, i));
4894 }
4895 else
4896 {
4897 if(i == 0)
4898 {
John Bauman19bac1e2014-05-06 15:23:49 -04004899 return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), 0));
John Bauman89401822014-05-06 15:04:28 -04004900 }
4901 else
4902 {
4903 Int2 val2 = As<Int2>(UnpackHigh(val, val));
4904
4905 return Extract(val2, 0);
4906 }
4907 }
4908 }
4909
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004910 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4911 {
4912 return RValue<Int2>(Nucleus::createBitCast(Nucleus::createInsertElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), element.value, i), Int2::getType()));
4913 }
John Bauman89401822014-05-06 15:04:28 -04004914
John Bauman19bac1e2014-05-06 15:23:49 -04004915 Type *Int2::getType()
John Bauman89401822014-05-06 15:04:28 -04004916 {
John Bauman19bac1e2014-05-06 15:23:49 -04004917 if(CPUID::supportsMMX2())
4918 {
4919 return MMX::getType();
4920 }
4921 else
4922 {
4923 return VectorType::get(Int::getType(), 2);
4924 }
John Bauman89401822014-05-06 15:04:28 -04004925 }
4926
4927 UInt2::UInt2()
4928 {
4929 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004930 }
4931
4932 UInt2::UInt2(unsigned int x, unsigned int y)
4933 {
4934 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004935
4936 Constant *constantVector[2];
4937 constantVector[0] = Nucleus::createConstantInt(x);
4938 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004939 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004940
John Bauman66b8ab22014-05-06 15:57:45 -04004941 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004942 }
4943
John Bauman19bac1e2014-05-06 15:23:49 -04004944 UInt2::UInt2(RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004945 {
4946 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004947
John Bauman66b8ab22014-05-06 15:57:45 -04004948 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004949 }
4950
4951 UInt2::UInt2(const UInt2 &rhs)
4952 {
4953 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004954
John Bauman66b8ab22014-05-06 15:57:45 -04004955 Value *value = rhs.loadValue();
4956 storeValue(value);
4957 }
4958
4959 UInt2::UInt2(const Reference<UInt2> &rhs)
4960 {
4961 // xy.parent = this;
4962
4963 Value *value = rhs.loadValue();
4964 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004965 }
4966
John Bauman19bac1e2014-05-06 15:23:49 -04004967 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004968 {
John Bauman66b8ab22014-05-06 15:57:45 -04004969 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004970
4971 return rhs;
4972 }
4973
4974 RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
4975 {
John Bauman66b8ab22014-05-06 15:57:45 -04004976 Value *value = rhs.loadValue();
4977 storeValue(value);
4978
4979 return RValue<UInt2>(value);
4980 }
4981
4982 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const
4983 {
4984 Value *value = rhs.loadValue();
4985 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004986
4987 return RValue<UInt2>(value);
4988 }
4989
John Bauman19bac1e2014-05-06 15:23:49 -04004990 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004991 {
John Bauman19bac1e2014-05-06 15:23:49 -04004992 if(CPUID::supportsMMX2())
4993 {
4994 return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs)));
4995 }
4996 else
4997 {
4998 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
4999 }
John Bauman89401822014-05-06 15:04:28 -04005000 }
5001
John Bauman19bac1e2014-05-06 15:23:49 -04005002 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005003 {
John Bauman19bac1e2014-05-06 15:23:49 -04005004 if(CPUID::supportsMMX2())
5005 {
5006 return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs)));
5007 }
5008 else
5009 {
5010 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
5011 }
John Bauman89401822014-05-06 15:04:28 -04005012 }
5013
John Bauman19bac1e2014-05-06 15:23:49 -04005014// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
5015// {
5016// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
5017// }
5018
5019// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
5020// {
5021// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
5022// }
5023
5024// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
5025// {
5026// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
5027// }
5028
5029 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005030 {
John Bauman19bac1e2014-05-06 15:23:49 -04005031 if(CPUID::supportsMMX2())
5032 {
5033 return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
5034 }
5035 else
5036 {
5037 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
5038 }
John Bauman89401822014-05-06 15:04:28 -04005039 }
5040
John Bauman19bac1e2014-05-06 15:23:49 -04005041 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005042 {
John Bauman19bac1e2014-05-06 15:23:49 -04005043 if(CPUID::supportsMMX2())
5044 {
5045 return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
5046 }
5047 else
5048 {
5049 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
5050 }
John Bauman89401822014-05-06 15:04:28 -04005051 }
5052
John Bauman19bac1e2014-05-06 15:23:49 -04005053 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005054 {
John Bauman19bac1e2014-05-06 15:23:49 -04005055 if(CPUID::supportsMMX2())
5056 {
5057 return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
5058 }
5059 else
5060 {
5061 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
5062 }
John Bauman89401822014-05-06 15:04:28 -04005063 }
5064
John Bauman19bac1e2014-05-06 15:23:49 -04005065 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005066 {
5067 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5068
5069 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5070 }
5071
John Bauman19bac1e2014-05-06 15:23:49 -04005072 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005073 {
5074 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5075
5076 return x86::psrld(lhs, rhs);
5077 }
5078
John Bauman19bac1e2014-05-06 15:23:49 -04005079 RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005080 {
5081 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5082
5083 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5084 }
5085
John Bauman19bac1e2014-05-06 15:23:49 -04005086 RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005087 {
5088 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5089
5090 return x86::psrld(lhs, rhs);
5091 }
5092
John Bauman19bac1e2014-05-06 15:23:49 -04005093 RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005094 {
5095 return lhs = lhs + rhs;
5096 }
5097
John Bauman19bac1e2014-05-06 15:23:49 -04005098 RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005099 {
5100 return lhs = lhs - rhs;
5101 }
5102
John Bauman19bac1e2014-05-06 15:23:49 -04005103// RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs)
5104// {
5105// return lhs = lhs * rhs;
5106// }
John Bauman89401822014-05-06 15:04:28 -04005107
John Bauman19bac1e2014-05-06 15:23:49 -04005108// RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs)
5109// {
5110// return lhs = lhs / rhs;
5111// }
John Bauman89401822014-05-06 15:04:28 -04005112
John Bauman19bac1e2014-05-06 15:23:49 -04005113// RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs)
5114// {
5115// return lhs = lhs % rhs;
5116// }
John Bauman89401822014-05-06 15:04:28 -04005117
John Bauman19bac1e2014-05-06 15:23:49 -04005118 RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005119 {
5120 return lhs = lhs & rhs;
5121 }
5122
John Bauman19bac1e2014-05-06 15:23:49 -04005123 RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005124 {
5125 return lhs = lhs | rhs;
5126 }
5127
John Bauman19bac1e2014-05-06 15:23:49 -04005128 RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005129 {
5130 return lhs = lhs ^ rhs;
5131 }
5132
5133 RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
5134 {
5135 return lhs = lhs << rhs;
5136 }
5137
5138 RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
5139 {
5140 return lhs = lhs >> rhs;
5141 }
5142
John Bauman19bac1e2014-05-06 15:23:49 -04005143 RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005144 {
5145 return lhs = lhs << rhs;
5146 }
5147
John Bauman19bac1e2014-05-06 15:23:49 -04005148 RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005149 {
5150 return lhs = lhs >> rhs;
5151 }
5152
John Bauman19bac1e2014-05-06 15:23:49 -04005153// RValue<UInt2> operator+(RValue<UInt2> val)
5154// {
5155// return val;
5156// }
5157
5158// RValue<UInt2> operator-(RValue<UInt2> val)
5159// {
5160// return RValue<UInt2>(Nucleus::createNeg(val.value));
5161// }
5162
5163 RValue<UInt2> operator~(RValue<UInt2> val)
John Bauman89401822014-05-06 15:04:28 -04005164 {
John Bauman19bac1e2014-05-06 15:23:49 -04005165 if(CPUID::supportsMMX2())
5166 {
5167 return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF);
5168 }
5169 else
5170 {
5171 return RValue<UInt2>(Nucleus::createNot(val.value));
5172 }
John Bauman89401822014-05-06 15:04:28 -04005173 }
5174
John Bauman19bac1e2014-05-06 15:23:49 -04005175 Type *UInt2::getType()
John Bauman89401822014-05-06 15:04:28 -04005176 {
John Bauman19bac1e2014-05-06 15:23:49 -04005177 if(CPUID::supportsMMX2())
5178 {
5179 return MMX::getType();
5180 }
5181 else
5182 {
5183 return VectorType::get(UInt::getType(), 2);
5184 }
John Bauman89401822014-05-06 15:04:28 -04005185 }
5186
John Bauman19bac1e2014-05-06 15:23:49 -04005187 Int4::Int4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005188 {
5189 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005190
5191 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
John Bauman89401822014-05-06 15:04:28 -04005192
John Bauman66b8ab22014-05-06 15:57:45 -04005193 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005194 }
5195
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005196 Int4::Int4(RValue<Short4> cast)
5197 {
5198 Value *long2 = UndefValue::get(Long2::getType());
5199 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
5200 long2 = Nucleus::createInsertElement(long2, element, 0);
5201 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
5202
5203 if(CPUID::supportsSSE4_1())
5204 {
5205 storeValue(x86::pmovsxwd(vector).value);
5206 }
5207 else
5208 {
5209 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
5210
5211 Constant *swizzle[8];
5212 swizzle[0] = Nucleus::createConstantInt(0);
5213 swizzle[1] = Nucleus::createConstantInt(0);
5214 swizzle[2] = Nucleus::createConstantInt(1);
5215 swizzle[3] = Nucleus::createConstantInt(1);
5216 swizzle[4] = Nucleus::createConstantInt(2);
5217 swizzle[5] = Nucleus::createConstantInt(2);
5218 swizzle[6] = Nucleus::createConstantInt(3);
5219 swizzle[7] = Nucleus::createConstantInt(3);
5220
Nicolas Capens6ce5c332015-10-28 01:58:18 -04005221 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8));
5222 Value *d = Nucleus::createBitCast(c, Int4::getType());
5223 storeValue(d);
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005224
5225 // Each Short is packed into each Int in the (Short | Short) format.
5226 // Shifting by 16 will retrieve the original Short value.
5227 // Shitfing an Int will propagate the sign bit, which will work
5228 // for both positive and negative values of a Short.
5229 *this >>= 16;
5230 }
5231 }
5232
5233 Int4::Int4(RValue<UShort4> cast)
5234 {
5235 Value *long2 = UndefValue::get(Long2::getType());
5236 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
5237 long2 = Nucleus::createInsertElement(long2, element, 0);
5238 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
5239
5240 if(CPUID::supportsSSE4_1())
5241 {
5242 storeValue(x86::pmovzxwd(RValue<Int4>(vector)).value);
5243 }
5244 else
5245 {
5246 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
5247
5248 Constant *swizzle[8];
5249 swizzle[0] = Nucleus::createConstantInt(0);
5250 swizzle[1] = Nucleus::createConstantInt(8);
5251 swizzle[2] = Nucleus::createConstantInt(1);
5252 swizzle[3] = Nucleus::createConstantInt(9);
5253 swizzle[4] = Nucleus::createConstantInt(2);
5254 swizzle[5] = Nucleus::createConstantInt(10);
5255 swizzle[6] = Nucleus::createConstantInt(3);
5256 swizzle[7] = Nucleus::createConstantInt(11);
5257
Nicolas Capens6ce5c332015-10-28 01:58:18 -04005258 Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8));
5259 Value *d = Nucleus::createBitCast(c, Int4::getType());
5260 storeValue(d);
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005261 }
5262 }
5263
John Bauman89401822014-05-06 15:04:28 -04005264 Int4::Int4()
5265 {
5266 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005267 }
5268
5269 Int4::Int4(int xyzw)
5270 {
5271 constant(xyzw, xyzw, xyzw, xyzw);
5272 }
5273
5274 Int4::Int4(int x, int yzw)
5275 {
5276 constant(x, yzw, yzw, yzw);
5277 }
5278
5279 Int4::Int4(int x, int y, int zw)
5280 {
5281 constant(x, y, zw, zw);
5282 }
5283
5284 Int4::Int4(int x, int y, int z, int w)
5285 {
5286 constant(x, y, z, w);
5287 }
5288
5289 void Int4::constant(int x, int y, int z, int w)
5290 {
5291 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005292
5293 Constant *constantVector[4];
5294 constantVector[0] = Nucleus::createConstantInt(x);
5295 constantVector[1] = Nucleus::createConstantInt(y);
5296 constantVector[2] = Nucleus::createConstantInt(z);
5297 constantVector[3] = Nucleus::createConstantInt(w);
5298
John Bauman66b8ab22014-05-06 15:57:45 -04005299 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005300 }
5301
John Bauman19bac1e2014-05-06 15:23:49 -04005302 Int4::Int4(RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005303 {
5304 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005305
John Bauman66b8ab22014-05-06 15:57:45 -04005306 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005307 }
5308
5309 Int4::Int4(const Int4 &rhs)
5310 {
5311 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005312
John Bauman66b8ab22014-05-06 15:57:45 -04005313 Value *value = rhs.loadValue();
5314 storeValue(value);
5315 }
5316
5317 Int4::Int4(const Reference<Int4> &rhs)
5318 {
5319 // xyzw.parent = this;
5320
5321 Value *value = rhs.loadValue();
5322 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005323 }
5324
John Bauman19bac1e2014-05-06 15:23:49 -04005325 Int4::Int4(RValue<UInt4> rhs)
5326 {
5327 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005328
John Bauman66b8ab22014-05-06 15:57:45 -04005329 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005330 }
5331
5332 Int4::Int4(const UInt4 &rhs)
5333 {
5334 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005335
John Bauman66b8ab22014-05-06 15:57:45 -04005336 Value *value = rhs.loadValue();
5337 storeValue(value);
5338 }
5339
5340 Int4::Int4(const Reference<UInt4> &rhs)
5341 {
5342 // xyzw.parent = this;
5343
5344 Value *value = rhs.loadValue();
5345 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005346 }
5347
Nicolas Capens62abb552016-01-05 12:03:47 -05005348 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
5349 {
5350 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5351 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5352
5353 Value *long2 = UndefValue::get(Long2::getType());
5354 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5355 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5356 Value *int4 = Nucleus::createBitCast(long2, Int4::getType());
5357
5358 storeValue(int4);
5359 }
5360
John Bauman19bac1e2014-05-06 15:23:49 -04005361 RValue<Int4> Int4::operator=(RValue<Int4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005362 {
John Bauman66b8ab22014-05-06 15:57:45 -04005363 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005364
5365 return rhs;
5366 }
5367
5368 RValue<Int4> Int4::operator=(const Int4 &rhs) const
5369 {
John Bauman66b8ab22014-05-06 15:57:45 -04005370 Value *value = rhs.loadValue();
5371 storeValue(value);
5372
5373 return RValue<Int4>(value);
5374 }
5375
5376 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const
5377 {
5378 Value *value = rhs.loadValue();
5379 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005380
5381 return RValue<Int4>(value);
5382 }
5383
John Bauman19bac1e2014-05-06 15:23:49 -04005384 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005385 {
5386 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5387 }
5388
John Bauman19bac1e2014-05-06 15:23:49 -04005389 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005390 {
5391 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5392 }
5393
John Bauman19bac1e2014-05-06 15:23:49 -04005394 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005395 {
5396 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5397 }
5398
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005399 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5400 {
5401 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5402 }
John Bauman89401822014-05-06 15:04:28 -04005403
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005404 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5405 {
5406 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5407 }
John Bauman89401822014-05-06 15:04:28 -04005408
John Bauman19bac1e2014-05-06 15:23:49 -04005409 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005410 {
5411 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5412 }
5413
John Bauman19bac1e2014-05-06 15:23:49 -04005414 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005415 {
5416 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5417 }
5418
John Bauman19bac1e2014-05-06 15:23:49 -04005419 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005420 {
5421 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5422 }
5423
John Bauman19bac1e2014-05-06 15:23:49 -04005424 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005425 {
John Bauman89401822014-05-06 15:04:28 -04005426 return x86::pslld(lhs, rhs);
5427 }
5428
John Bauman19bac1e2014-05-06 15:23:49 -04005429 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005430 {
John Bauman89401822014-05-06 15:04:28 -04005431 return x86::psrad(lhs, rhs);
5432 }
5433
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005434 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5435 {
5436 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5437 }
5438
5439 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5440 {
5441 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5442 }
5443
John Bauman19bac1e2014-05-06 15:23:49 -04005444 RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005445 {
5446 return lhs = lhs + rhs;
5447 }
5448
John Bauman19bac1e2014-05-06 15:23:49 -04005449 RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005450 {
5451 return lhs = lhs - rhs;
5452 }
5453
John Bauman19bac1e2014-05-06 15:23:49 -04005454 RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005455 {
5456 return lhs = lhs * rhs;
5457 }
5458
John Bauman19bac1e2014-05-06 15:23:49 -04005459// RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs)
5460// {
5461// return lhs = lhs / rhs;
5462// }
John Bauman89401822014-05-06 15:04:28 -04005463
John Bauman19bac1e2014-05-06 15:23:49 -04005464// RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs)
5465// {
5466// return lhs = lhs % rhs;
5467// }
John Bauman89401822014-05-06 15:04:28 -04005468
John Bauman19bac1e2014-05-06 15:23:49 -04005469 RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005470 {
5471 return lhs = lhs & rhs;
5472 }
5473
John Bauman19bac1e2014-05-06 15:23:49 -04005474 RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005475 {
5476 return lhs = lhs | rhs;
5477 }
5478
John Bauman19bac1e2014-05-06 15:23:49 -04005479 RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005480 {
5481 return lhs = lhs ^ rhs;
5482 }
5483
5484 RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
5485 {
5486 return lhs = lhs << rhs;
5487 }
5488
5489 RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
5490 {
5491 return lhs = lhs >> rhs;
5492 }
5493
John Bauman19bac1e2014-05-06 15:23:49 -04005494 RValue<Int4> operator+(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005495 {
5496 return val;
5497 }
5498
John Bauman19bac1e2014-05-06 15:23:49 -04005499 RValue<Int4> operator-(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005500 {
5501 return RValue<Int4>(Nucleus::createNeg(val.value));
5502 }
5503
John Bauman19bac1e2014-05-06 15:23:49 -04005504 RValue<Int4> operator~(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005505 {
5506 return RValue<Int4>(Nucleus::createNot(val.value));
5507 }
5508
John Bauman19bac1e2014-05-06 15:23:49 -04005509 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5510 {
5511 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5512 }
5513
5514 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5515 {
5516 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
5517 }
5518
5519 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5520 {
5521 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
5522 }
5523
5524 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5525 {
5526 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5527 }
5528
5529 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5530 {
5531 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
5532 }
5533
5534 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5535 {
5536 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
5537 }
5538
5539 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5540 {
5541 if(CPUID::supportsSSE4_1())
5542 {
5543 return x86::pmaxsd(x, y);
5544 }
5545 else
5546 {
5547 RValue<Int4> greater = CmpNLE(x, y);
5548 return x & greater | y & ~greater;
5549 }
5550 }
5551
5552 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5553 {
5554 if(CPUID::supportsSSE4_1())
5555 {
5556 return x86::pminsd(x, y);
5557 }
5558 else
5559 {
5560 RValue<Int4> less = CmpLT(x, y);
5561 return x & less | y & ~less;
5562 }
5563 }
5564
5565 RValue<Int4> RoundInt(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005566 {
5567 return x86::cvtps2dq(cast);
5568 }
5569
John Bauman19bac1e2014-05-06 15:23:49 -04005570 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04005571 {
5572 return x86::packssdw(x, y);
5573 }
5574
John Bauman19bac1e2014-05-06 15:23:49 -04005575 RValue<Int> Extract(RValue<Int4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04005576 {
5577 return RValue<Int>(Nucleus::createExtractElement(x.value, i));
5578 }
5579
John Bauman19bac1e2014-05-06 15:23:49 -04005580 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
John Bauman89401822014-05-06 15:04:28 -04005581 {
5582 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5583 }
5584
John Bauman19bac1e2014-05-06 15:23:49 -04005585 RValue<Int> SignMask(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04005586 {
5587 return x86::movmskps(As<Float4>(x));
5588 }
5589
John Bauman19bac1e2014-05-06 15:23:49 -04005590 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04005591 {
5592 return RValue<Int4>(Nucleus::createSwizzle(x.value, select));
5593 }
5594
John Bauman19bac1e2014-05-06 15:23:49 -04005595 Type *Int4::getType()
John Bauman89401822014-05-06 15:04:28 -04005596 {
5597 return VectorType::get(Int::getType(), 4);
5598 }
5599
John Bauman19bac1e2014-05-06 15:23:49 -04005600 UInt4::UInt4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005601 {
5602 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005603
5604 Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
5605
John Bauman66b8ab22014-05-06 15:57:45 -04005606 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005607 }
5608
5609 UInt4::UInt4()
5610 {
5611 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005612 }
5613
John Bauman19bac1e2014-05-06 15:23:49 -04005614 UInt4::UInt4(int xyzw)
5615 {
5616 constant(xyzw, xyzw, xyzw, xyzw);
5617 }
5618
5619 UInt4::UInt4(int x, int yzw)
5620 {
5621 constant(x, yzw, yzw, yzw);
5622 }
5623
5624 UInt4::UInt4(int x, int y, int zw)
5625 {
5626 constant(x, y, zw, zw);
5627 }
5628
5629 UInt4::UInt4(int x, int y, int z, int w)
5630 {
5631 constant(x, y, z, w);
5632 }
5633
5634 void UInt4::constant(int x, int y, int z, int w)
John Bauman89401822014-05-06 15:04:28 -04005635 {
5636 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005637
5638 Constant *constantVector[4];
5639 constantVector[0] = Nucleus::createConstantInt(x);
5640 constantVector[1] = Nucleus::createConstantInt(y);
5641 constantVector[2] = Nucleus::createConstantInt(z);
5642 constantVector[3] = Nucleus::createConstantInt(w);
5643
John Bauman66b8ab22014-05-06 15:57:45 -04005644 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005645 }
5646
John Bauman19bac1e2014-05-06 15:23:49 -04005647 UInt4::UInt4(RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005648 {
5649 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005650
John Bauman66b8ab22014-05-06 15:57:45 -04005651 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005652 }
5653
5654 UInt4::UInt4(const UInt4 &rhs)
5655 {
5656 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005657
John Bauman66b8ab22014-05-06 15:57:45 -04005658 Value *value = rhs.loadValue();
5659 storeValue(value);
5660 }
5661
5662 UInt4::UInt4(const Reference<UInt4> &rhs)
5663 {
5664 // xyzw.parent = this;
5665
5666 Value *value = rhs.loadValue();
5667 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005668 }
5669
John Bauman19bac1e2014-05-06 15:23:49 -04005670 UInt4::UInt4(RValue<Int4> rhs)
5671 {
5672 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005673
John Bauman66b8ab22014-05-06 15:57:45 -04005674 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005675 }
5676
5677 UInt4::UInt4(const Int4 &rhs)
5678 {
5679 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005680
John Bauman66b8ab22014-05-06 15:57:45 -04005681 Value *value = rhs.loadValue();
5682 storeValue(value);
5683 }
5684
5685 UInt4::UInt4(const Reference<Int4> &rhs)
5686 {
5687 // xyzw.parent = this;
5688
5689 Value *value = rhs.loadValue();
5690 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005691 }
5692
Nicolas Capens62abb552016-01-05 12:03:47 -05005693 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5694 {
5695 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5696 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5697
5698 Value *long2 = UndefValue::get(Long2::getType());
5699 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5700 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5701 Value *uint4 = Nucleus::createBitCast(long2, Int4::getType());
5702
5703 storeValue(uint4);
5704 }
5705
John Bauman19bac1e2014-05-06 15:23:49 -04005706 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005707 {
John Bauman66b8ab22014-05-06 15:57:45 -04005708 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005709
5710 return rhs;
5711 }
5712
5713 RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
5714 {
John Bauman66b8ab22014-05-06 15:57:45 -04005715 Value *value = rhs.loadValue();
5716 storeValue(value);
5717
5718 return RValue<UInt4>(value);
5719 }
5720
5721 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const
5722 {
5723 Value *value = rhs.loadValue();
5724 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005725
5726 return RValue<UInt4>(value);
5727 }
5728
John Bauman19bac1e2014-05-06 15:23:49 -04005729 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005730 {
5731 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5732 }
5733
John Bauman19bac1e2014-05-06 15:23:49 -04005734 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005735 {
5736 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5737 }
5738
John Bauman19bac1e2014-05-06 15:23:49 -04005739 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005740 {
5741 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5742 }
5743
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005744 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5745 {
5746 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5747 }
John Bauman89401822014-05-06 15:04:28 -04005748
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005749 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5750 {
5751 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5752 }
John Bauman89401822014-05-06 15:04:28 -04005753
John Bauman19bac1e2014-05-06 15:23:49 -04005754 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005755 {
5756 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5757 }
5758
John Bauman19bac1e2014-05-06 15:23:49 -04005759 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005760 {
5761 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5762 }
5763
John Bauman19bac1e2014-05-06 15:23:49 -04005764 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005765 {
5766 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5767 }
5768
John Bauman19bac1e2014-05-06 15:23:49 -04005769 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005770 {
John Bauman89401822014-05-06 15:04:28 -04005771 return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
5772 }
5773
John Bauman19bac1e2014-05-06 15:23:49 -04005774 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005775 {
John Bauman89401822014-05-06 15:04:28 -04005776 return x86::psrld(lhs, rhs);
5777 }
5778
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005779 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5780 {
5781 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5782 }
5783
5784 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5785 {
5786 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5787 }
5788
John Bauman19bac1e2014-05-06 15:23:49 -04005789 RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005790 {
5791 return lhs = lhs + rhs;
5792 }
5793
John Bauman19bac1e2014-05-06 15:23:49 -04005794 RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005795 {
5796 return lhs = lhs - rhs;
5797 }
5798
John Bauman19bac1e2014-05-06 15:23:49 -04005799 RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005800 {
5801 return lhs = lhs * rhs;
5802 }
5803
John Bauman19bac1e2014-05-06 15:23:49 -04005804// RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs)
5805// {
5806// return lhs = lhs / rhs;
5807// }
John Bauman89401822014-05-06 15:04:28 -04005808
John Bauman19bac1e2014-05-06 15:23:49 -04005809// RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs)
5810// {
5811// return lhs = lhs % rhs;
5812// }
John Bauman89401822014-05-06 15:04:28 -04005813
John Bauman19bac1e2014-05-06 15:23:49 -04005814 RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005815 {
5816 return lhs = lhs & rhs;
5817 }
5818
John Bauman19bac1e2014-05-06 15:23:49 -04005819 RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005820 {
5821 return lhs = lhs | rhs;
5822 }
5823
John Bauman19bac1e2014-05-06 15:23:49 -04005824 RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005825 {
5826 return lhs = lhs ^ rhs;
5827 }
5828
5829 RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
5830 {
5831 return lhs = lhs << rhs;
5832 }
5833
5834 RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
5835 {
5836 return lhs = lhs >> rhs;
5837 }
5838
John Bauman19bac1e2014-05-06 15:23:49 -04005839 RValue<UInt4> operator+(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005840 {
5841 return val;
5842 }
5843
John Bauman19bac1e2014-05-06 15:23:49 -04005844 RValue<UInt4> operator-(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005845 {
5846 return RValue<UInt4>(Nucleus::createNeg(val.value));
5847 }
5848
John Bauman19bac1e2014-05-06 15:23:49 -04005849 RValue<UInt4> operator~(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005850 {
5851 return RValue<UInt4>(Nucleus::createNot(val.value));
5852 }
5853
John Bauman19bac1e2014-05-06 15:23:49 -04005854 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5855 {
5856 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5857 }
5858
5859 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5860 {
5861 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5862 }
5863
5864 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5865 {
5866 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5867 }
5868
5869 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5870 {
5871 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5872 }
5873
5874 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5875 {
5876 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5877 }
5878
5879 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5880 {
5881 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5882 }
5883
5884 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5885 {
5886 if(CPUID::supportsSSE4_1())
5887 {
5888 return x86::pmaxud(x, y);
5889 }
5890 else
5891 {
5892 RValue<UInt4> greater = CmpNLE(x, y);
5893 return x & greater | y & ~greater;
5894 }
5895 }
5896
5897 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5898 {
5899 if(CPUID::supportsSSE4_1())
5900 {
5901 return x86::pminud(x, y);
5902 }
5903 else
5904 {
5905 RValue<UInt4> less = CmpLT(x, y);
5906 return x & less | y & ~less;
5907 }
5908 }
5909
5910 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04005911 {
5912 return x86::packusdw(x, y); // FIXME: Fallback required
5913 }
5914
John Bauman19bac1e2014-05-06 15:23:49 -04005915 Type *UInt4::getType()
John Bauman89401822014-05-06 15:04:28 -04005916 {
5917 return VectorType::get(UInt::getType(), 4);
5918 }
5919
John Bauman19bac1e2014-05-06 15:23:49 -04005920 Float::Float(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04005921 {
John Bauman89401822014-05-06 15:04:28 -04005922 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5923
John Bauman66b8ab22014-05-06 15:57:45 -04005924 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04005925 }
5926
5927 Float::Float()
5928 {
John Bauman66b8ab22014-05-06 15:57:45 -04005929
John Bauman89401822014-05-06 15:04:28 -04005930 }
5931
5932 Float::Float(float x)
5933 {
John Bauman66b8ab22014-05-06 15:57:45 -04005934 storeValue(Nucleus::createConstantFloat(x));
John Bauman89401822014-05-06 15:04:28 -04005935 }
5936
John Bauman19bac1e2014-05-06 15:23:49 -04005937 Float::Float(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005938 {
John Bauman66b8ab22014-05-06 15:57:45 -04005939 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005940 }
5941
5942 Float::Float(const Float &rhs)
5943 {
John Bauman66b8ab22014-05-06 15:57:45 -04005944 Value *value = rhs.loadValue();
5945 storeValue(value);
5946 }
John Bauman89401822014-05-06 15:04:28 -04005947
John Bauman66b8ab22014-05-06 15:57:45 -04005948 Float::Float(const Reference<Float> &rhs)
5949 {
5950 Value *value = rhs.loadValue();
5951 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005952 }
5953
John Bauman19bac1e2014-05-06 15:23:49 -04005954 RValue<Float> Float::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005955 {
John Bauman66b8ab22014-05-06 15:57:45 -04005956 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005957
5958 return rhs;
5959 }
5960
5961 RValue<Float> Float::operator=(const Float &rhs) const
5962 {
John Bauman66b8ab22014-05-06 15:57:45 -04005963 Value *value = rhs.loadValue();
5964 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005965
5966 return RValue<Float>(value);
5967 }
5968
John Bauman66b8ab22014-05-06 15:57:45 -04005969 RValue<Float> Float::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04005970 {
John Bauman66b8ab22014-05-06 15:57:45 -04005971 Value *value = rhs.loadValue();
5972 storeValue(value);
5973
5974 return RValue<Float>(value);
John Bauman89401822014-05-06 15:04:28 -04005975 }
5976
John Bauman19bac1e2014-05-06 15:23:49 -04005977 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005978 {
5979 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5980 }
5981
John Bauman19bac1e2014-05-06 15:23:49 -04005982 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005983 {
5984 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5985 }
5986
John Bauman19bac1e2014-05-06 15:23:49 -04005987 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005988 {
5989 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5990 }
5991
John Bauman19bac1e2014-05-06 15:23:49 -04005992 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005993 {
5994 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5995 }
5996
John Bauman19bac1e2014-05-06 15:23:49 -04005997 RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005998 {
5999 return lhs = lhs + rhs;
6000 }
6001
John Bauman19bac1e2014-05-06 15:23:49 -04006002 RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006003 {
6004 return lhs = lhs - rhs;
6005 }
6006
John Bauman19bac1e2014-05-06 15:23:49 -04006007 RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006008 {
6009 return lhs = lhs * rhs;
6010 }
6011
John Bauman19bac1e2014-05-06 15:23:49 -04006012 RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006013 {
6014 return lhs = lhs / rhs;
6015 }
6016
John Bauman19bac1e2014-05-06 15:23:49 -04006017 RValue<Float> operator+(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006018 {
6019 return val;
6020 }
6021
John Bauman19bac1e2014-05-06 15:23:49 -04006022 RValue<Float> operator-(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006023 {
6024 return RValue<Float>(Nucleus::createFNeg(val.value));
6025 }
6026
John Bauman19bac1e2014-05-06 15:23:49 -04006027 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006028 {
6029 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
6030 }
6031
John Bauman19bac1e2014-05-06 15:23:49 -04006032 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006033 {
6034 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
6035 }
6036
John Bauman19bac1e2014-05-06 15:23:49 -04006037 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006038 {
6039 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
6040 }
6041
John Bauman19bac1e2014-05-06 15:23:49 -04006042 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006043 {
6044 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
6045 }
6046
John Bauman19bac1e2014-05-06 15:23:49 -04006047 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006048 {
6049 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
6050 }
6051
John Bauman19bac1e2014-05-06 15:23:49 -04006052 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006053 {
6054 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
6055 }
6056
John Bauman19bac1e2014-05-06 15:23:49 -04006057 RValue<Float> Abs(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006058 {
John Bauman66b8ab22014-05-06 15:57:45 -04006059 return IfThenElse(x > 0.0f, x, -x);
John Bauman89401822014-05-06 15:04:28 -04006060 }
6061
John Bauman19bac1e2014-05-06 15:23:49 -04006062 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04006063 {
6064 return IfThenElse(x > y, x, y);
6065 }
6066
John Bauman19bac1e2014-05-06 15:23:49 -04006067 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04006068 {
6069 return IfThenElse(x < y, x, y);
6070 }
6071
John Bauman19bac1e2014-05-06 15:23:49 -04006072 RValue<Float> Rcp_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006073 {
6074 return x86::rcpss(x);
6075 }
John Bauman66b8ab22014-05-06 15:57:45 -04006076
John Bauman19bac1e2014-05-06 15:23:49 -04006077 RValue<Float> RcpSqrt_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006078 {
6079 return x86::rsqrtss(x);
6080 }
6081
John Bauman19bac1e2014-05-06 15:23:49 -04006082 RValue<Float> Sqrt(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006083 {
6084 return x86::sqrtss(x);
6085 }
6086
John Bauman19bac1e2014-05-06 15:23:49 -04006087 RValue<Float> Round(RValue<Float> x)
6088 {
6089 if(CPUID::supportsSSE4_1())
6090 {
6091 return x86::roundss(x, 0);
6092 }
6093 else
6094 {
6095 return Float4(Round(Float4(x))).x;
6096 }
6097 }
6098
6099 RValue<Float> Trunc(RValue<Float> x)
6100 {
6101 if(CPUID::supportsSSE4_1())
6102 {
6103 return x86::roundss(x, 3);
6104 }
6105 else
6106 {
6107 return Float(Int(x)); // Rounded toward zero
6108 }
6109 }
6110
6111 RValue<Float> Frac(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006112 {
6113 if(CPUID::supportsSSE4_1())
6114 {
6115 return x - x86::floorss(x);
6116 }
6117 else
6118 {
John Bauman19bac1e2014-05-06 15:23:49 -04006119 return Float4(Frac(Float4(x))).x;
John Bauman89401822014-05-06 15:04:28 -04006120 }
6121 }
6122
John Bauman19bac1e2014-05-06 15:23:49 -04006123 RValue<Float> Floor(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006124 {
6125 if(CPUID::supportsSSE4_1())
6126 {
6127 return x86::floorss(x);
6128 }
6129 else
6130 {
6131 return Float4(Floor(Float4(x))).x;
6132 }
6133 }
6134
John Bauman19bac1e2014-05-06 15:23:49 -04006135 RValue<Float> Ceil(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006136 {
John Bauman19bac1e2014-05-06 15:23:49 -04006137 if(CPUID::supportsSSE4_1())
6138 {
6139 return x86::ceilss(x);
6140 }
6141 else
6142 {
6143 return Float4(Ceil(Float4(x))).x;
6144 }
John Bauman89401822014-05-06 15:04:28 -04006145 }
6146
John Bauman19bac1e2014-05-06 15:23:49 -04006147 Type *Float::getType()
John Bauman89401822014-05-06 15:04:28 -04006148 {
6149 return Type::getFloatTy(*Nucleus::getContext());
6150 }
6151
John Bauman19bac1e2014-05-06 15:23:49 -04006152 Float2::Float2(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04006153 {
6154 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006155
6156 Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
6157 Value *int64 = Nucleus::createExtractElement(int64x2, 0);
6158 Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
6159
John Bauman66b8ab22014-05-06 15:57:45 -04006160 storeValue(float2);
John Bauman89401822014-05-06 15:04:28 -04006161 }
6162
John Bauman19bac1e2014-05-06 15:23:49 -04006163 Type *Float2::getType()
John Bauman89401822014-05-06 15:04:28 -04006164 {
6165 return VectorType::get(Float::getType(), 2);
6166 }
6167
John Bauman19bac1e2014-05-06 15:23:49 -04006168 Float4::Float4(RValue<Byte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006169 {
6170 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006171
6172 #if 0
6173 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6174 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006175 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006176
6177 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6178 Value *f32x = Nucleus::createUIToFP(i8x, Float::getType());
6179 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6180
6181 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6182 Value *f32y = Nucleus::createUIToFP(i8y, Float::getType());
6183 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6184
6185 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6186 Value *f32z = Nucleus::createUIToFP(i8z, Float::getType());
6187 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6188
6189 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6190 Value *f32w = Nucleus::createUIToFP(i8w, Float::getType());
6191 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6192 #else
6193 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6194 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6195
6196 Value *e;
6197
6198 if(CPUID::supportsSSE4_1())
6199 {
6200 e = x86::pmovzxbd(RValue<Int4>(a)).value;
6201 }
6202 else
6203 {
6204 Constant *swizzle[16];
6205 swizzle[0] = Nucleus::createConstantInt(0);
6206 swizzle[1] = Nucleus::createConstantInt(16);
6207 swizzle[2] = Nucleus::createConstantInt(1);
6208 swizzle[3] = Nucleus::createConstantInt(17);
6209 swizzle[4] = Nucleus::createConstantInt(2);
6210 swizzle[5] = Nucleus::createConstantInt(18);
6211 swizzle[6] = Nucleus::createConstantInt(3);
6212 swizzle[7] = Nucleus::createConstantInt(19);
6213 swizzle[8] = Nucleus::createConstantInt(4);
6214 swizzle[9] = Nucleus::createConstantInt(20);
6215 swizzle[10] = Nucleus::createConstantInt(5);
6216 swizzle[11] = Nucleus::createConstantInt(21);
6217 swizzle[12] = Nucleus::createConstantInt(6);
6218 swizzle[13] = Nucleus::createConstantInt(22);
6219 swizzle[14] = Nucleus::createConstantInt(7);
6220 swizzle[15] = Nucleus::createConstantInt(23);
6221
6222 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6223 Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16));
6224
6225 Constant *swizzle2[8];
6226 swizzle2[0] = Nucleus::createConstantInt(0);
6227 swizzle2[1] = Nucleus::createConstantInt(8);
6228 swizzle2[2] = Nucleus::createConstantInt(1);
6229 swizzle2[3] = Nucleus::createConstantInt(9);
6230 swizzle2[4] = Nucleus::createConstantInt(2);
6231 swizzle2[5] = Nucleus::createConstantInt(10);
6232 swizzle2[6] = Nucleus::createConstantInt(3);
6233 swizzle2[7] = Nucleus::createConstantInt(11);
6234
6235 Value *d = Nucleus::createBitCast(c, Short8::getType());
6236 e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8));
6237 }
6238
6239 Value *f = Nucleus::createBitCast(e, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006240 Value *g = Nucleus::createSIToFP(f, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006241 Value *xyzw = g;
6242 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006243
6244 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006245 }
6246
John Bauman19bac1e2014-05-06 15:23:49 -04006247 Float4::Float4(RValue<SByte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006248 {
6249 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006250
6251 #if 0
6252 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6253 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006254 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006255
6256 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6257 Value *f32x = Nucleus::createSIToFP(i8x, Float::getType());
6258 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6259
6260 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6261 Value *f32y = Nucleus::createSIToFP(i8y, Float::getType());
6262 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6263
6264 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6265 Value *f32z = Nucleus::createSIToFP(i8z, Float::getType());
6266 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6267
6268 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6269 Value *f32w = Nucleus::createSIToFP(i8w, Float::getType());
6270 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6271 #else
6272 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6273 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6274
6275 Value *g;
6276
6277 if(CPUID::supportsSSE4_1())
6278 {
6279 g = x86::pmovsxbd(RValue<Int4>(a)).value;
6280 }
6281 else
6282 {
6283 Constant *swizzle[16];
6284 swizzle[0] = Nucleus::createConstantInt(0);
6285 swizzle[1] = Nucleus::createConstantInt(0);
6286 swizzle[2] = Nucleus::createConstantInt(1);
6287 swizzle[3] = Nucleus::createConstantInt(1);
6288 swizzle[4] = Nucleus::createConstantInt(2);
6289 swizzle[5] = Nucleus::createConstantInt(2);
6290 swizzle[6] = Nucleus::createConstantInt(3);
6291 swizzle[7] = Nucleus::createConstantInt(3);
6292 swizzle[8] = Nucleus::createConstantInt(4);
6293 swizzle[9] = Nucleus::createConstantInt(4);
6294 swizzle[10] = Nucleus::createConstantInt(5);
6295 swizzle[11] = Nucleus::createConstantInt(5);
6296 swizzle[12] = Nucleus::createConstantInt(6);
6297 swizzle[13] = Nucleus::createConstantInt(6);
6298 swizzle[14] = Nucleus::createConstantInt(7);
6299 swizzle[15] = Nucleus::createConstantInt(7);
6300
6301 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6302 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16));
6303
6304 Constant *swizzle2[8];
6305 swizzle2[0] = Nucleus::createConstantInt(0);
6306 swizzle2[1] = Nucleus::createConstantInt(0);
6307 swizzle2[2] = Nucleus::createConstantInt(1);
6308 swizzle2[3] = Nucleus::createConstantInt(1);
6309 swizzle2[4] = Nucleus::createConstantInt(2);
6310 swizzle2[5] = Nucleus::createConstantInt(2);
6311 swizzle2[6] = Nucleus::createConstantInt(3);
6312 swizzle2[7] = Nucleus::createConstantInt(3);
6313
6314 Value *d = Nucleus::createBitCast(c, Short8::getType());
6315 Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8));
6316
6317 Value *f = Nucleus::createBitCast(e, Int4::getType());
6318 // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24));
6319 g = x86::psrad(RValue<Int4>(f), 24).value;
6320 }
6321
John Bauman19bac1e2014-05-06 15:23:49 -04006322 Value *xyzw = Nucleus::createSIToFP(g, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006323 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006324
6325 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006326 }
6327
John Bauman19bac1e2014-05-06 15:23:49 -04006328 Float4::Float4(RValue<Short4> cast)
John Bauman89401822014-05-06 15:04:28 -04006329 {
6330 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006331
Alexis Hetu2aa852f2015-10-14 16:32:39 -04006332 Int4 c(cast);
6333 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
John Bauman89401822014-05-06 15:04:28 -04006334 }
6335
John Bauman19bac1e2014-05-06 15:23:49 -04006336 Float4::Float4(RValue<UShort4> cast)
John Bauman89401822014-05-06 15:04:28 -04006337 {
6338 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006339
Alexis Hetu2aa852f2015-10-14 16:32:39 -04006340 Int4 c(cast);
6341 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
John Bauman89401822014-05-06 15:04:28 -04006342 }
6343
John Bauman19bac1e2014-05-06 15:23:49 -04006344 Float4::Float4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04006345 {
6346 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006347
6348 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006349
John Bauman66b8ab22014-05-06 15:57:45 -04006350 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006351 }
6352
John Bauman19bac1e2014-05-06 15:23:49 -04006353 Float4::Float4(RValue<UInt4> cast)
John Bauman89401822014-05-06 15:04:28 -04006354 {
6355 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006356
6357 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
6358
John Bauman66b8ab22014-05-06 15:57:45 -04006359 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006360 }
6361
6362 Float4::Float4()
6363 {
6364 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006365 }
John Bauman66b8ab22014-05-06 15:57:45 -04006366
John Bauman89401822014-05-06 15:04:28 -04006367 Float4::Float4(float xyzw)
6368 {
6369 constant(xyzw, xyzw, xyzw, xyzw);
6370 }
6371
6372 Float4::Float4(float x, float yzw)
6373 {
6374 constant(x, yzw, yzw, yzw);
6375 }
6376
6377 Float4::Float4(float x, float y, float zw)
6378 {
6379 constant(x, y, zw, zw);
6380 }
6381
6382 Float4::Float4(float x, float y, float z, float w)
6383 {
6384 constant(x, y, z, w);
6385 }
6386
6387 void Float4::constant(float x, float y, float z, float w)
6388 {
6389 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006390
6391 Constant *constantVector[4];
6392 constantVector[0] = Nucleus::createConstantFloat(x);
6393 constantVector[1] = Nucleus::createConstantFloat(y);
6394 constantVector[2] = Nucleus::createConstantFloat(z);
6395 constantVector[3] = Nucleus::createConstantFloat(w);
6396
John Bauman66b8ab22014-05-06 15:57:45 -04006397 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04006398 }
6399
John Bauman19bac1e2014-05-06 15:23:49 -04006400 Float4::Float4(RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006401 {
6402 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006403
John Bauman66b8ab22014-05-06 15:57:45 -04006404 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006405 }
6406
6407 Float4::Float4(const Float4 &rhs)
6408 {
6409 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006410
John Bauman66b8ab22014-05-06 15:57:45 -04006411 Value *value = rhs.loadValue();
6412 storeValue(value);
6413 }
6414
6415 Float4::Float4(const Reference<Float4> &rhs)
6416 {
6417 xyzw.parent = this;
6418
6419 Value *value = rhs.loadValue();
6420 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006421 }
6422
John Bauman19bac1e2014-05-06 15:23:49 -04006423 Float4::Float4(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006424 {
6425 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006426
John Bauman66b8ab22014-05-06 15:57:45 -04006427 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006428 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
6429
6430 Constant *swizzle[4];
6431 swizzle[0] = Nucleus::createConstantInt(0);
6432 swizzle[1] = Nucleus::createConstantInt(0);
6433 swizzle[2] = Nucleus::createConstantInt(0);
6434 swizzle[3] = Nucleus::createConstantInt(0);
6435
6436 Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4));
6437
John Bauman66b8ab22014-05-06 15:57:45 -04006438 storeValue(replicate);
John Bauman89401822014-05-06 15:04:28 -04006439 }
6440
6441 Float4::Float4(const Float &rhs)
6442 {
6443 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006444
John Bauman66b8ab22014-05-06 15:57:45 -04006445 *this = RValue<Float>(rhs.loadValue());
6446 }
John Bauman89401822014-05-06 15:04:28 -04006447
John Bauman66b8ab22014-05-06 15:57:45 -04006448 Float4::Float4(const Reference<Float> &rhs)
6449 {
6450 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006451
John Bauman66b8ab22014-05-06 15:57:45 -04006452 *this = RValue<Float>(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006453 }
6454
6455 RValue<Float4> Float4::operator=(float x) const
6456 {
6457 return *this = Float4(x, x, x, x);
6458 }
6459
John Bauman19bac1e2014-05-06 15:23:49 -04006460 RValue<Float4> Float4::operator=(RValue<Float4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006461 {
John Bauman66b8ab22014-05-06 15:57:45 -04006462 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006463
6464 return rhs;
6465 }
6466
6467 RValue<Float4> Float4::operator=(const Float4 &rhs) const
6468 {
John Bauman66b8ab22014-05-06 15:57:45 -04006469 Value *value = rhs.loadValue();
6470 storeValue(value);
6471
6472 return RValue<Float4>(value);
6473 }
6474
6475 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const
6476 {
6477 Value *value = rhs.loadValue();
6478 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006479
6480 return RValue<Float4>(value);
6481 }
6482
John Bauman19bac1e2014-05-06 15:23:49 -04006483 RValue<Float4> Float4::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006484 {
6485 return *this = Float4(rhs);
6486 }
6487
6488 RValue<Float4> Float4::operator=(const Float &rhs) const
6489 {
6490 return *this = Float4(rhs);
6491 }
6492
John Bauman66b8ab22014-05-06 15:57:45 -04006493 RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04006494 {
John Bauman66b8ab22014-05-06 15:57:45 -04006495 return *this = Float4(rhs);
John Bauman89401822014-05-06 15:04:28 -04006496 }
6497
John Bauman19bac1e2014-05-06 15:23:49 -04006498 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006499 {
6500 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
6501 }
6502
John Bauman19bac1e2014-05-06 15:23:49 -04006503 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006504 {
6505 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
6506 }
6507
John Bauman19bac1e2014-05-06 15:23:49 -04006508 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006509 {
6510 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
6511 }
6512
John Bauman19bac1e2014-05-06 15:23:49 -04006513 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006514 {
6515 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6516 }
6517
John Bauman19bac1e2014-05-06 15:23:49 -04006518 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006519 {
6520 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
6521 }
6522
John Bauman19bac1e2014-05-06 15:23:49 -04006523 RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006524 {
6525 return lhs = lhs + rhs;
6526 }
6527
John Bauman19bac1e2014-05-06 15:23:49 -04006528 RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006529 {
6530 return lhs = lhs - rhs;
6531 }
6532
John Bauman19bac1e2014-05-06 15:23:49 -04006533 RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006534 {
6535 return lhs = lhs * rhs;
6536 }
6537
John Bauman19bac1e2014-05-06 15:23:49 -04006538 RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006539 {
6540 return lhs = lhs / rhs;
6541 }
6542
John Bauman19bac1e2014-05-06 15:23:49 -04006543 RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006544 {
6545 return lhs = lhs % rhs;
6546 }
6547
John Bauman19bac1e2014-05-06 15:23:49 -04006548 RValue<Float4> operator+(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006549 {
6550 return val;
6551 }
6552
John Bauman19bac1e2014-05-06 15:23:49 -04006553 RValue<Float4> operator-(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006554 {
6555 return RValue<Float4>(Nucleus::createFNeg(val.value));
6556 }
6557
John Bauman19bac1e2014-05-06 15:23:49 -04006558 RValue<Float4> Abs(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006559 {
6560 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6561
6562 Constant *constantVector[4];
6563 constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF);
6564 constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF);
6565 constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF);
6566 constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF);
6567
6568 Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4));
6569
6570 return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType()));
6571 }
6572
John Bauman19bac1e2014-05-06 15:23:49 -04006573 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006574 {
6575 return x86::maxps(x, y);
6576 }
6577
John Bauman19bac1e2014-05-06 15:23:49 -04006578 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006579 {
6580 return x86::minps(x, y);
6581 }
6582
John Bauman19bac1e2014-05-06 15:23:49 -04006583 RValue<Float4> Rcp_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006584 {
6585 return x86::rcpps(x);
6586 }
John Bauman66b8ab22014-05-06 15:57:45 -04006587
John Bauman19bac1e2014-05-06 15:23:49 -04006588 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006589 {
6590 return x86::rsqrtps(x);
6591 }
6592
John Bauman19bac1e2014-05-06 15:23:49 -04006593 RValue<Float4> Sqrt(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006594 {
6595 return x86::sqrtps(x);
6596 }
6597
John Bauman19bac1e2014-05-06 15:23:49 -04006598 RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i)
John Bauman89401822014-05-06 15:04:28 -04006599 {
John Bauman66b8ab22014-05-06 15:57:45 -04006600 llvm::Value *value = val.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006601 llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i);
6602
6603 val = RValue<Float4>(insert);
6604
6605 return val;
6606 }
6607
John Bauman19bac1e2014-05-06 15:23:49 -04006608 RValue<Float> Extract(RValue<Float4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04006609 {
6610 return RValue<Float>(Nucleus::createExtractElement(x.value, i));
6611 }
6612
John Bauman19bac1e2014-05-06 15:23:49 -04006613 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006614 {
6615 return RValue<Float4>(Nucleus::createSwizzle(x.value, select));
6616 }
6617
John Bauman19bac1e2014-05-06 15:23:49 -04006618 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006619 {
6620 Constant *shuffle[4];
6621 shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0);
6622 shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0);
6623 shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4);
6624 shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4);
6625
6626 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6627 }
6628
John Bauman19bac1e2014-05-06 15:23:49 -04006629 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006630 {
6631 Constant *shuffle[4];
6632 shuffle[0] = Nucleus::createConstantInt(0);
6633 shuffle[1] = Nucleus::createConstantInt(4);
6634 shuffle[2] = Nucleus::createConstantInt(1);
6635 shuffle[3] = Nucleus::createConstantInt(5);
6636
6637 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6638 }
6639
John Bauman19bac1e2014-05-06 15:23:49 -04006640 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006641 {
6642 Constant *shuffle[4];
6643 shuffle[0] = Nucleus::createConstantInt(2);
6644 shuffle[1] = Nucleus::createConstantInt(6);
6645 shuffle[2] = Nucleus::createConstantInt(3);
6646 shuffle[3] = Nucleus::createConstantInt(7);
6647
6648 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6649 }
John Bauman66b8ab22014-05-06 15:57:45 -04006650
John Bauman19bac1e2014-05-06 15:23:49 -04006651 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006652 {
John Bauman66b8ab22014-05-06 15:57:45 -04006653 Value *vector = lhs.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006654 Value *shuffle = Nucleus::createMask(vector, rhs.value, select);
John Bauman66b8ab22014-05-06 15:57:45 -04006655 lhs.storeValue(shuffle);
John Bauman89401822014-05-06 15:04:28 -04006656
6657 return RValue<Float4>(shuffle);
6658 }
6659
John Bauman19bac1e2014-05-06 15:23:49 -04006660 RValue<Int> SignMask(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006661 {
6662 return x86::movmskps(x);
6663 }
6664
John Bauman19bac1e2014-05-06 15:23:49 -04006665 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006666 {
6667 // return As<Int4>(x86::cmpeqps(x, y));
6668 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
6669 }
6670
John Bauman19bac1e2014-05-06 15:23:49 -04006671 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006672 {
6673 // return As<Int4>(x86::cmpltps(x, y));
6674 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
6675 }
6676
John Bauman19bac1e2014-05-06 15:23:49 -04006677 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006678 {
6679 // return As<Int4>(x86::cmpleps(x, y));
6680 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
6681 }
6682
John Bauman19bac1e2014-05-06 15:23:49 -04006683 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006684 {
6685 // return As<Int4>(x86::cmpneqps(x, y));
6686 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
6687 }
6688
John Bauman19bac1e2014-05-06 15:23:49 -04006689 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006690 {
6691 // return As<Int4>(x86::cmpnltps(x, y));
6692 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
6693 }
6694
John Bauman19bac1e2014-05-06 15:23:49 -04006695 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006696 {
6697 // return As<Int4>(x86::cmpnleps(x, y));
6698 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
6699 }
6700
John Bauman19bac1e2014-05-06 15:23:49 -04006701 RValue<Float4> Round(RValue<Float4> x)
6702 {
6703 if(CPUID::supportsSSE4_1())
6704 {
6705 return x86::roundps(x, 0);
6706 }
6707 else
6708 {
6709 return Float4(RoundInt(x));
6710 }
6711 }
6712
6713 RValue<Float4> Trunc(RValue<Float4> x)
6714 {
6715 if(CPUID::supportsSSE4_1())
6716 {
6717 return x86::roundps(x, 3);
6718 }
6719 else
6720 {
6721 return Float4(Int4(x)); // Rounded toward zero
6722 }
6723 }
6724
6725 RValue<Float4> Frac(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006726 {
6727 if(CPUID::supportsSSE4_1())
6728 {
6729 return x - x86::floorps(x);
6730 }
6731 else
6732 {
John Bauman19bac1e2014-05-06 15:23:49 -04006733 Float4 frc = x - Float4(Int4(x)); // Signed fractional part
John Bauman89401822014-05-06 15:04:28 -04006734
John Bauman19bac1e2014-05-06 15:23:49 -04006735 return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1)));
John Bauman89401822014-05-06 15:04:28 -04006736 }
6737 }
6738
John Bauman19bac1e2014-05-06 15:23:49 -04006739 RValue<Float4> Floor(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006740 {
6741 if(CPUID::supportsSSE4_1())
6742 {
6743 return x86::floorps(x);
6744 }
6745 else
6746 {
John Bauman19bac1e2014-05-06 15:23:49 -04006747 return x - Frac(x);
John Bauman89401822014-05-06 15:04:28 -04006748 }
6749 }
6750
John Bauman19bac1e2014-05-06 15:23:49 -04006751 RValue<Float4> Ceil(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006752 {
John Bauman19bac1e2014-05-06 15:23:49 -04006753 if(CPUID::supportsSSE4_1())
6754 {
6755 return x86::ceilps(x);
6756 }
6757 else
6758 {
6759 return -Floor(-x);
6760 }
John Bauman89401822014-05-06 15:04:28 -04006761 }
6762
John Bauman19bac1e2014-05-06 15:23:49 -04006763 Type *Float4::getType()
John Bauman89401822014-05-06 15:04:28 -04006764 {
6765 return VectorType::get(Float::getType(), 4);
6766 }
6767
John Bauman66b8ab22014-05-06 15:57:45 -04006768 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006769 {
John Bauman66b8ab22014-05-06 15:57:45 -04006770 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
John Bauman89401822014-05-06 15:04:28 -04006771 }
6772
John Bauman66b8ab22014-05-06 15:57:45 -04006773 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006774 {
John Bauman66b8ab22014-05-06 15:57:45 -04006775 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006776 }
6777
John Bauman66b8ab22014-05-06 15:57:45 -04006778 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006779 {
John Bauman66b8ab22014-05-06 15:57:45 -04006780 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006781 }
6782
John Bauman66b8ab22014-05-06 15:57:45 -04006783 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006784 {
6785 return lhs = lhs + offset;
6786 }
6787
John Bauman66b8ab22014-05-06 15:57:45 -04006788 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006789 {
6790 return lhs = lhs + offset;
6791 }
6792
John Bauman66b8ab22014-05-06 15:57:45 -04006793 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006794 {
6795 return lhs = lhs + offset;
6796 }
6797
John Bauman66b8ab22014-05-06 15:57:45 -04006798 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006799 {
6800 return lhs + -offset;
6801 }
6802
John Bauman66b8ab22014-05-06 15:57:45 -04006803 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006804 {
6805 return lhs + -offset;
6806 }
6807
John Bauman66b8ab22014-05-06 15:57:45 -04006808 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006809 {
6810 return lhs + -offset;
6811 }
6812
John Bauman66b8ab22014-05-06 15:57:45 -04006813 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006814 {
6815 return lhs = lhs - offset;
6816 }
6817
John Bauman66b8ab22014-05-06 15:57:45 -04006818 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006819 {
6820 return lhs = lhs - offset;
6821 }
6822
John Bauman66b8ab22014-05-06 15:57:45 -04006823 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006824 {
6825 return lhs = lhs - offset;
6826 }
6827
6828 void Return()
6829 {
John Bauman89401822014-05-06 15:04:28 -04006830 Nucleus::createRetVoid();
6831 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006832 Nucleus::createUnreachable();
6833 }
6834
6835 void Return(bool ret)
6836 {
John Bauman19bac1e2014-05-06 15:23:49 -04006837 Nucleus::createRet(Nucleus::createConstantBool(ret));
6838 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6839 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006840 }
6841
6842 void Return(const Int &ret)
6843 {
John Bauman66b8ab22014-05-06 15:57:45 -04006844 Nucleus::createRet(ret.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006845 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006846 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006847 }
6848
6849 BasicBlock *beginLoop()
6850 {
6851 BasicBlock *loopBB = Nucleus::createBasicBlock();
6852
6853 Nucleus::createBr(loopBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006854 Nucleus::setInsertBlock(loopBB);
John Bauman89401822014-05-06 15:04:28 -04006855
6856 return loopBB;
6857 }
6858
John Bauman19bac1e2014-05-06 15:23:49 -04006859 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
John Bauman89401822014-05-06 15:04:28 -04006860 {
6861 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006862 Nucleus::setInsertBlock(bodyBB);
6863
John Bauman89401822014-05-06 15:04:28 -04006864 return true;
6865 }
6866
6867 bool elseBlock(BasicBlock *falseBB)
6868 {
6869 falseBB->back().eraseFromParent();
John Bauman66b8ab22014-05-06 15:57:45 -04006870 Nucleus::setInsertBlock(falseBB);
John Bauman89401822014-05-06 15:04:28 -04006871
6872 return true;
6873 }
6874
6875 RValue<Long> Ticks()
6876 {
6877 Module *module = Nucleus::getModule();
6878 llvm::Function *rdtsc = Intrinsic::getDeclaration(module, Intrinsic::readcyclecounter);
6879
6880 return RValue<Long>(Nucleus::createCall(rdtsc));
6881 }
John Bauman89401822014-05-06 15:04:28 -04006882}
6883
6884namespace sw
6885{
6886 namespace x86
6887 {
John Bauman19bac1e2014-05-06 15:23:49 -04006888 RValue<Int> cvtss2si(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006889 {
6890 Module *module = Nucleus::getModule();
6891 llvm::Function *cvtss2si = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtss2si);
John Bauman66b8ab22014-05-06 15:57:45 -04006892
John Bauman89401822014-05-06 15:04:28 -04006893 Float4 vector;
6894 vector.x = val;
6895
6896 return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value));
6897 }
6898
John Bauman19bac1e2014-05-06 15:23:49 -04006899 RValue<Int2> cvtps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006900 {
6901 Module *module = Nucleus::getModule();
6902 llvm::Function *cvtps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtps2pi);
6903
6904 return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value));
6905 }
6906
John Bauman19bac1e2014-05-06 15:23:49 -04006907 RValue<Int2> cvttps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006908 {
6909 Module *module = Nucleus::getModule();
6910 llvm::Function *cvttps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvttps2pi);
6911
6912 return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value));
6913 }
6914
John Bauman19bac1e2014-05-06 15:23:49 -04006915 RValue<Int4> cvtps2dq(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006916 {
6917 if(CPUID::supportsSSE2())
6918 {
6919 Module *module = Nucleus::getModule();
6920 llvm::Function *cvtps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtps2dq);
6921
6922 return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value));
6923 }
6924 else
6925 {
6926 Int2 lo = x86::cvtps2pi(val);
6927 Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04006928
Nicolas Capens62abb552016-01-05 12:03:47 -05006929 return Int4(lo, hi);
John Bauman89401822014-05-06 15:04:28 -04006930 }
6931 }
6932
John Bauman19bac1e2014-05-06 15:23:49 -04006933 RValue<Float> rcpss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006934 {
6935 Module *module = Nucleus::getModule();
6936 llvm::Function *rcpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ss);
6937
6938 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006939
John Bauman89401822014-05-06 15:04:28 -04006940 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rcpss, vector), 0));
6941 }
6942
John Bauman19bac1e2014-05-06 15:23:49 -04006943 RValue<Float> sqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006944 {
6945 Module *module = Nucleus::getModule();
6946 llvm::Function *sqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ss);
6947
6948 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006949
John Bauman89401822014-05-06 15:04:28 -04006950 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0));
6951 }
6952
John Bauman19bac1e2014-05-06 15:23:49 -04006953 RValue<Float> rsqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006954 {
6955 Module *module = Nucleus::getModule();
6956 llvm::Function *rsqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ss);
John Bauman66b8ab22014-05-06 15:57:45 -04006957
John Bauman89401822014-05-06 15:04:28 -04006958 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
6959
6960 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0));
6961 }
6962
John Bauman19bac1e2014-05-06 15:23:49 -04006963 RValue<Float4> rcpps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006964 {
6965 Module *module = Nucleus::getModule();
6966 llvm::Function *rcpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006967
John Bauman89401822014-05-06 15:04:28 -04006968 return RValue<Float4>(Nucleus::createCall(rcpps, val.value));
6969 }
6970
John Bauman19bac1e2014-05-06 15:23:49 -04006971 RValue<Float4> sqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006972 {
6973 Module *module = Nucleus::getModule();
6974 llvm::Function *sqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006975
John Bauman89401822014-05-06 15:04:28 -04006976 return RValue<Float4>(Nucleus::createCall(sqrtps, val.value));
6977 }
6978
John Bauman19bac1e2014-05-06 15:23:49 -04006979 RValue<Float4> rsqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006980 {
6981 Module *module = Nucleus::getModule();
6982 llvm::Function *rsqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006983
John Bauman89401822014-05-06 15:04:28 -04006984 return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value));
6985 }
6986
John Bauman19bac1e2014-05-06 15:23:49 -04006987 RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006988 {
6989 Module *module = Nucleus::getModule();
6990 llvm::Function *maxps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_max_ps);
6991
6992 return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value));
6993 }
6994
John Bauman19bac1e2014-05-06 15:23:49 -04006995 RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006996 {
6997 Module *module = Nucleus::getModule();
6998 llvm::Function *minps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_min_ps);
6999
7000 return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value));
7001 }
7002
John Bauman19bac1e2014-05-06 15:23:49 -04007003 RValue<Float> roundss(RValue<Float> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007004 {
7005 Module *module = Nucleus::getModule();
7006 llvm::Function *roundss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ss);
7007
7008 Value *undef = UndefValue::get(Float4::getType());
7009 Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
7010
7011 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0));
7012 }
7013
John Bauman19bac1e2014-05-06 15:23:49 -04007014 RValue<Float> floorss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04007015 {
7016 return roundss(val, 1);
7017 }
7018
John Bauman19bac1e2014-05-06 15:23:49 -04007019 RValue<Float> ceilss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04007020 {
7021 return roundss(val, 2);
7022 }
7023
John Bauman19bac1e2014-05-06 15:23:49 -04007024 RValue<Float4> roundps(RValue<Float4> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007025 {
7026 Module *module = Nucleus::getModule();
7027 llvm::Function *roundps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ps);
7028
7029 return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm)));
7030 }
7031
John Bauman19bac1e2014-05-06 15:23:49 -04007032 RValue<Float4> floorps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007033 {
7034 return roundps(val, 1);
7035 }
7036
John Bauman19bac1e2014-05-06 15:23:49 -04007037 RValue<Float4> ceilps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007038 {
7039 return roundps(val, 2);
7040 }
7041
John Bauman19bac1e2014-05-06 15:23:49 -04007042 RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007043 {
7044 Module *module = Nucleus::getModule();
7045 llvm::Function *cmpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ps);
7046
7047 return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm)));
7048 }
7049
John Bauman19bac1e2014-05-06 15:23:49 -04007050 RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007051 {
7052 return cmpps(x, y, 0);
7053 }
7054
John Bauman19bac1e2014-05-06 15:23:49 -04007055 RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007056 {
7057 return cmpps(x, y, 1);
7058 }
7059
John Bauman19bac1e2014-05-06 15:23:49 -04007060 RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007061 {
7062 return cmpps(x, y, 2);
7063 }
7064
John Bauman19bac1e2014-05-06 15:23:49 -04007065 RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007066 {
7067 return cmpps(x, y, 3);
7068 }
7069
John Bauman19bac1e2014-05-06 15:23:49 -04007070 RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007071 {
7072 return cmpps(x, y, 4);
7073 }
7074
John Bauman19bac1e2014-05-06 15:23:49 -04007075 RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007076 {
7077 return cmpps(x, y, 5);
7078 }
7079
John Bauman19bac1e2014-05-06 15:23:49 -04007080 RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007081 {
7082 return cmpps(x, y, 6);
7083 }
7084
John Bauman19bac1e2014-05-06 15:23:49 -04007085 RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007086 {
7087 return cmpps(x, y, 7);
7088 }
7089
John Bauman19bac1e2014-05-06 15:23:49 -04007090 RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007091 {
7092 Module *module = Nucleus::getModule();
7093 llvm::Function *cmpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ss);
7094
7095 Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0);
7096 Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0);
7097
7098 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0));
7099 }
7100
John Bauman19bac1e2014-05-06 15:23:49 -04007101 RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007102 {
7103 return cmpss(x, y, 0);
7104 }
7105
John Bauman19bac1e2014-05-06 15:23:49 -04007106 RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007107 {
7108 return cmpss(x, y, 1);
7109 }
7110
John Bauman19bac1e2014-05-06 15:23:49 -04007111 RValue<Float> cmpless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007112 {
7113 return cmpss(x, y, 2);
7114 }
7115
John Bauman19bac1e2014-05-06 15:23:49 -04007116 RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007117 {
7118 return cmpss(x, y, 3);
7119 }
7120
John Bauman19bac1e2014-05-06 15:23:49 -04007121 RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007122 {
7123 return cmpss(x, y, 4);
7124 }
7125
John Bauman19bac1e2014-05-06 15:23:49 -04007126 RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007127 {
7128 return cmpss(x, y, 5);
7129 }
7130
John Bauman19bac1e2014-05-06 15:23:49 -04007131 RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007132 {
7133 return cmpss(x, y, 6);
7134 }
7135
John Bauman19bac1e2014-05-06 15:23:49 -04007136 RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007137 {
7138 return cmpss(x, y, 7);
7139 }
7140
John Bauman19bac1e2014-05-06 15:23:49 -04007141 RValue<Int4> pabsd(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007142 {
7143 Module *module = Nucleus::getModule();
7144 llvm::Function *pabsd = Intrinsic::getDeclaration(module, Intrinsic::x86_ssse3_pabs_d_128);
7145
7146 return RValue<Int4>(Nucleus::createCall(pabsd, x.value, y.value));
7147 }
7148
John Bauman19bac1e2014-05-06 15:23:49 -04007149 RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007150 {
7151 Module *module = Nucleus::getModule();
7152 llvm::Function *paddsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_w);
7153
John Bauman19bac1e2014-05-06 15:23:49 -04007154 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007155 }
John Bauman66b8ab22014-05-06 15:57:45 -04007156
John Bauman19bac1e2014-05-06 15:23:49 -04007157 RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007158 {
7159 Module *module = Nucleus::getModule();
7160 llvm::Function *psubsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_w);
7161
John Bauman19bac1e2014-05-06 15:23:49 -04007162 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007163 }
7164
John Bauman19bac1e2014-05-06 15:23:49 -04007165 RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007166 {
7167 Module *module = Nucleus::getModule();
7168 llvm::Function *paddusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_w);
7169
John Bauman19bac1e2014-05-06 15:23:49 -04007170 return As<UShort4>(RValue<MMX>(Nucleus::createCall(paddusw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007171 }
John Bauman66b8ab22014-05-06 15:57:45 -04007172
John Bauman19bac1e2014-05-06 15:23:49 -04007173 RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007174 {
7175 Module *module = Nucleus::getModule();
7176 llvm::Function *psubusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_w);
7177
John Bauman19bac1e2014-05-06 15:23:49 -04007178 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psubusw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007179 }
7180
John Bauman19bac1e2014-05-06 15:23:49 -04007181 RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007182 {
7183 Module *module = Nucleus::getModule();
7184 llvm::Function *paddsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_b);
7185
John Bauman19bac1e2014-05-06 15:23:49 -04007186 return As<SByte8>(RValue<MMX>(Nucleus::createCall(paddsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007187 }
John Bauman66b8ab22014-05-06 15:57:45 -04007188
John Bauman19bac1e2014-05-06 15:23:49 -04007189 RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007190 {
7191 Module *module = Nucleus::getModule();
7192 llvm::Function *psubsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_b);
7193
John Bauman19bac1e2014-05-06 15:23:49 -04007194 return As<SByte8>(RValue<MMX>(Nucleus::createCall(psubsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007195 }
John Bauman66b8ab22014-05-06 15:57:45 -04007196
John Bauman19bac1e2014-05-06 15:23:49 -04007197 RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007198 {
7199 Module *module = Nucleus::getModule();
7200 llvm::Function *paddusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_b);
7201
John Bauman19bac1e2014-05-06 15:23:49 -04007202 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007203 }
John Bauman66b8ab22014-05-06 15:57:45 -04007204
John Bauman19bac1e2014-05-06 15:23:49 -04007205 RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007206 {
7207 Module *module = Nucleus::getModule();
7208 llvm::Function *psubusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_b);
7209
John Bauman19bac1e2014-05-06 15:23:49 -04007210 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007211 }
7212
John Bauman19bac1e2014-05-06 15:23:49 -04007213 RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y)
7214 {
7215 Module *module = Nucleus::getModule();
7216 llvm::Function *paddw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_w);
7217
7218 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddw, As<MMX>(x).value, As<MMX>(y).value)));
7219 }
7220
7221 RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y)
7222 {
7223 Module *module = Nucleus::getModule();
7224 llvm::Function *psubw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_w);
7225
7226 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubw, As<MMX>(x).value, As<MMX>(y).value)));
7227 }
7228
7229 RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y)
7230 {
7231 Module *module = Nucleus::getModule();
7232 llvm::Function *pmullw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmull_w);
7233
7234 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmullw, As<MMX>(x).value, As<MMX>(y).value)));
7235 }
7236
7237 RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y)
7238 {
7239 Module *module = Nucleus::getModule();
7240 llvm::Function *pand = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pand);
7241
7242 return As<Short4>(RValue<MMX>(Nucleus::createCall(pand, As<MMX>(x).value, As<MMX>(y).value)));
7243 }
7244
7245 RValue<Short4> por(RValue<Short4> x, RValue<Short4> y)
7246 {
7247 Module *module = Nucleus::getModule();
7248 llvm::Function *por = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_por);
7249
7250 return As<Short4>(RValue<MMX>(Nucleus::createCall(por, As<MMX>(x).value, As<MMX>(y).value)));
7251 }
7252
7253 RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y)
7254 {
7255 Module *module = Nucleus::getModule();
7256 llvm::Function *pxor = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pxor);
7257
7258 return As<Short4>(RValue<MMX>(Nucleus::createCall(pxor, As<MMX>(x).value, As<MMX>(y).value)));
7259 }
7260
7261 RValue<Short4> pshufw(RValue<Short4> x, unsigned char y)
7262 {
7263 Module *module = Nucleus::getModule();
7264 llvm::Function *pshufw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_pshuf_w);
7265
7266 return As<Short4>(RValue<MMX>(Nucleus::createCall(pshufw, As<MMX>(x).value, Nucleus::createConstantByte(y))));
7267 }
7268
7269 RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y)
7270 {
7271 Module *module = Nucleus::getModule();
7272 llvm::Function *punpcklwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklwd);
7273
7274 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpcklwd, As<MMX>(x).value, As<MMX>(y).value)));
7275 }
7276
7277 RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y)
7278 {
7279 Module *module = Nucleus::getModule();
7280 llvm::Function *punpckhwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhwd);
7281
7282 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpckhwd, As<MMX>(x).value, As<MMX>(y).value)));
7283 }
7284
7285 RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i)
7286 {
7287 Module *module = Nucleus::getModule();
7288 llvm::Function *pinsrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pinsr_w);
7289
7290 return As<Short4>(RValue<MMX>(Nucleus::createCall(pinsrw, As<MMX>(x).value, y.value, Nucleus::createConstantInt(i))));
7291 }
7292
7293 RValue<Int> pextrw(RValue<Short4> x, unsigned int i)
7294 {
7295 Module *module = Nucleus::getModule();
7296 llvm::Function *pextrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pextr_w);
7297
7298 return RValue<Int>(Nucleus::createCall(pextrw, As<MMX>(x).value, Nucleus::createConstantInt(i)));
7299 }
7300
7301 RValue<Long1> punpckldq(RValue<Int2> x, RValue<Int2> y)
7302 {
7303 Module *module = Nucleus::getModule();
7304 llvm::Function *punpckldq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckldq);
7305
7306 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckldq, As<MMX>(x).value, As<MMX>(y).value)));
7307 }
7308
7309 RValue<Long1> punpckhdq(RValue<Int2> x, RValue<Int2> y)
7310 {
7311 Module *module = Nucleus::getModule();
7312 llvm::Function *punpckhdq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhdq);
7313
7314 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckhdq, As<MMX>(x).value, As<MMX>(y).value)));
7315 }
7316
7317 RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y)
7318 {
7319 Module *module = Nucleus::getModule();
7320 llvm::Function *punpcklbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklbw);
7321
7322 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpcklbw, As<MMX>(x).value, As<MMX>(y).value)));
7323 }
7324
7325 RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y)
7326 {
7327 Module *module = Nucleus::getModule();
7328 llvm::Function *punpckhbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhbw);
7329
7330 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpckhbw, As<MMX>(x).value, As<MMX>(y).value)));
7331 }
7332
7333 RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y)
7334 {
7335 Module *module = Nucleus::getModule();
7336 llvm::Function *paddb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_b);
7337
7338 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddb, As<MMX>(x).value, As<MMX>(y).value)));
7339 }
7340
7341 RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y)
7342 {
7343 Module *module = Nucleus::getModule();
7344 llvm::Function *psubb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_b);
7345
7346 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubb, As<MMX>(x).value, As<MMX>(y).value)));
7347 }
7348
7349 RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y)
7350 {
7351 Module *module = Nucleus::getModule();
7352 llvm::Function *paddd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_d);
7353
7354 return As<Int2>(RValue<MMX>(Nucleus::createCall(paddd, As<MMX>(x).value, As<MMX>(y).value)));
7355 }
7356
7357 RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y)
7358 {
7359 Module *module = Nucleus::getModule();
7360 llvm::Function *psubd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_d);
7361
7362 return As<Int2>(RValue<MMX>(Nucleus::createCall(psubd, As<MMX>(x).value, As<MMX>(y).value)));
7363 }
7364
7365 RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007366 {
7367 Module *module = Nucleus::getModule();
7368 llvm::Function *pavgw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pavg_w);
7369
John Bauman19bac1e2014-05-06 15:23:49 -04007370 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pavgw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007371 }
7372
John Bauman19bac1e2014-05-06 15:23:49 -04007373 RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007374 {
7375 Module *module = Nucleus::getModule();
7376 llvm::Function *pmaxsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmaxs_w);
7377
John Bauman19bac1e2014-05-06 15:23:49 -04007378 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmaxsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007379 }
7380
John Bauman19bac1e2014-05-06 15:23:49 -04007381 RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007382 {
7383 Module *module = Nucleus::getModule();
7384 llvm::Function *pminsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmins_w);
7385
John Bauman19bac1e2014-05-06 15:23:49 -04007386 return As<Short4>(RValue<MMX>(Nucleus::createCall(pminsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007387 }
7388
John Bauman19bac1e2014-05-06 15:23:49 -04007389 RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007390 {
7391 Module *module = Nucleus::getModule();
7392 llvm::Function *pcmpgtw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_w);
7393
John Bauman19bac1e2014-05-06 15:23:49 -04007394 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpgtw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007395 }
7396
John Bauman19bac1e2014-05-06 15:23:49 -04007397 RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007398 {
7399 Module *module = Nucleus::getModule();
7400 llvm::Function *pcmpeqw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_w);
7401
John Bauman19bac1e2014-05-06 15:23:49 -04007402 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpeqw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007403 }
7404
John Bauman19bac1e2014-05-06 15:23:49 -04007405 RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007406 {
7407 Module *module = Nucleus::getModule();
7408 llvm::Function *pcmpgtb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_b);
7409
John Bauman19bac1e2014-05-06 15:23:49 -04007410 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpgtb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007411 }
7412
John Bauman19bac1e2014-05-06 15:23:49 -04007413 RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007414 {
7415 Module *module = Nucleus::getModule();
7416 llvm::Function *pcmpeqb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_b);
7417
John Bauman19bac1e2014-05-06 15:23:49 -04007418 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpeqb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007419 }
7420
John Bauman19bac1e2014-05-06 15:23:49 -04007421 RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04007422 {
7423 Module *module = Nucleus::getModule();
7424 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packssdw);
7425
John Bauman19bac1e2014-05-06 15:23:49 -04007426 return As<Short4>(RValue<MMX>(Nucleus::createCall(packssdw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007427 }
7428
John Bauman19bac1e2014-05-06 15:23:49 -04007429 RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007430 {
7431 if(CPUID::supportsSSE2())
7432 {
7433 Module *module = Nucleus::getModule();
7434 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_packssdw_128);
7435
7436 return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value));
7437 }
7438 else
7439 {
7440 Int2 loX = Int2(x);
7441 Int2 hiX = Int2(Swizzle(x, 0xEE));
7442
7443 Int2 loY = Int2(y);
7444 Int2 hiY = Int2(Swizzle(y, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007445
John Bauman89401822014-05-06 15:04:28 -04007446 Short4 lo = x86::packssdw(loX, hiX);
7447 Short4 hi = x86::packssdw(loY, hiY);
John Bauman66b8ab22014-05-06 15:57:45 -04007448
Nicolas Capens62abb552016-01-05 12:03:47 -05007449 return Short8(lo, hi);
John Bauman89401822014-05-06 15:04:28 -04007450 }
7451 }
7452
John Bauman19bac1e2014-05-06 15:23:49 -04007453 RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007454 {
7455 Module *module = Nucleus::getModule();
7456 llvm::Function *packsswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packsswb);
7457
John Bauman19bac1e2014-05-06 15:23:49 -04007458 return As<SByte8>(RValue<MMX>(Nucleus::createCall(packsswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007459 }
7460
John Bauman19bac1e2014-05-06 15:23:49 -04007461 RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007462 {
7463 Module *module = Nucleus::getModule();
7464 llvm::Function *packuswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packuswb);
7465
John Bauman19bac1e2014-05-06 15:23:49 -04007466 return As<Byte8>(RValue<MMX>(Nucleus::createCall(packuswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007467 }
7468
John Bauman19bac1e2014-05-06 15:23:49 -04007469 RValue<UShort8> packusdw(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04007470 {
7471 if(CPUID::supportsSSE4_1())
7472 {
7473 Module *module = Nucleus::getModule();
7474 llvm::Function *packusdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_packusdw);
John Bauman66b8ab22014-05-06 15:57:45 -04007475
John Bauman89401822014-05-06 15:04:28 -04007476 return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value));
7477 }
7478 else
7479 {
7480 // FIXME: Not an exact replacement!
John Bauman19bac1e2014-05-06 15:23:49 -04007481 return As<UShort8>(packssdw(As<Int4>(x - UInt4(0x00008000, 0x00008000, 0x00008000, 0x00008000)), As<Int4>(y - UInt4(0x00008000, 0x00008000, 0x00008000, 0x00008000))) + Short8(0x8000u, 0x8000u, 0x8000u, 0x8000u, 0x8000u, 0x8000u, 0x8000u, 0x8000u));
John Bauman89401822014-05-06 15:04:28 -04007482 }
7483 }
7484
John Bauman19bac1e2014-05-06 15:23:49 -04007485 RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007486 {
7487 Module *module = Nucleus::getModule();
7488 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_w);
7489
John Bauman19bac1e2014-05-06 15:23:49 -04007490 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007491 }
7492
John Bauman19bac1e2014-05-06 15:23:49 -04007493 RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007494 {
7495 Module *module = Nucleus::getModule();
7496 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_w);
7497
7498 return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y)));
7499 }
7500
John Bauman19bac1e2014-05-06 15:23:49 -04007501 RValue<Short4> psraw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007502 {
7503 Module *module = Nucleus::getModule();
7504 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_w);
7505
John Bauman19bac1e2014-05-06 15:23:49 -04007506 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007507 }
7508
John Bauman19bac1e2014-05-06 15:23:49 -04007509 RValue<Short8> psraw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007510 {
7511 Module *module = Nucleus::getModule();
7512 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_w);
7513
7514 return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y)));
7515 }
7516
John Bauman19bac1e2014-05-06 15:23:49 -04007517 RValue<Short4> psllw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007518 {
7519 Module *module = Nucleus::getModule();
7520 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_w);
7521
John Bauman19bac1e2014-05-06 15:23:49 -04007522 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007523 }
7524
John Bauman19bac1e2014-05-06 15:23:49 -04007525 RValue<Short8> psllw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007526 {
7527 Module *module = Nucleus::getModule();
7528 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_w);
7529
7530 return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y)));
7531 }
7532
John Bauman19bac1e2014-05-06 15:23:49 -04007533 RValue<Int2> pslld(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007534 {
7535 Module *module = Nucleus::getModule();
7536 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_d);
7537
John Bauman19bac1e2014-05-06 15:23:49 -04007538 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007539 }
7540
John Bauman19bac1e2014-05-06 15:23:49 -04007541 RValue<Int4> pslld(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007542 {
7543 if(CPUID::supportsSSE2())
7544 {
7545 Module *module = Nucleus::getModule();
7546 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_d);
7547
7548 return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y)));
7549 }
7550 else
7551 {
7552 Int2 lo = Int2(x);
7553 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007554
John Bauman89401822014-05-06 15:04:28 -04007555 lo = x86::pslld(lo, y);
7556 hi = x86::pslld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007557
Nicolas Capens62abb552016-01-05 12:03:47 -05007558 return Int4(lo, hi);
John Bauman89401822014-05-06 15:04:28 -04007559 }
7560 }
7561
John Bauman19bac1e2014-05-06 15:23:49 -04007562 RValue<Int2> psrad(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007563 {
7564 Module *module = Nucleus::getModule();
7565 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_d);
7566
John Bauman19bac1e2014-05-06 15:23:49 -04007567 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrad, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007568 }
7569
John Bauman19bac1e2014-05-06 15:23:49 -04007570 RValue<Int4> psrad(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007571 {
7572 if(CPUID::supportsSSE2())
7573 {
7574 Module *module = Nucleus::getModule();
7575 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_d);
7576
7577 return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y)));
7578 }
7579 else
7580 {
7581 Int2 lo = Int2(x);
7582 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007583
John Bauman89401822014-05-06 15:04:28 -04007584 lo = x86::psrad(lo, y);
7585 hi = x86::psrad(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007586
Nicolas Capens62abb552016-01-05 12:03:47 -05007587 return Int4(lo, hi);
John Bauman89401822014-05-06 15:04:28 -04007588 }
7589 }
7590
John Bauman19bac1e2014-05-06 15:23:49 -04007591 RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007592 {
7593 Module *module = Nucleus::getModule();
7594 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_d);
7595
John Bauman19bac1e2014-05-06 15:23:49 -04007596 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007597 }
7598
John Bauman19bac1e2014-05-06 15:23:49 -04007599 RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007600 {
7601 if(CPUID::supportsSSE2())
7602 {
7603 Module *module = Nucleus::getModule();
7604 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_d);
7605
7606 return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y)));
7607 }
7608 else
7609 {
7610 UInt2 lo = As<UInt2>(Int2(As<Int4>(x)));
7611 UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE)));
John Bauman66b8ab22014-05-06 15:57:45 -04007612
John Bauman89401822014-05-06 15:04:28 -04007613 lo = x86::psrld(lo, y);
7614 hi = x86::psrld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007615
Nicolas Capens62abb552016-01-05 12:03:47 -05007616 return UInt4(lo, hi);
John Bauman89401822014-05-06 15:04:28 -04007617 }
7618 }
7619
John Bauman19bac1e2014-05-06 15:23:49 -04007620 RValue<UShort4> psrlw(RValue<UShort4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007621 {
7622 Module *module = Nucleus::getModule();
7623 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_w);
7624
John Bauman19bac1e2014-05-06 15:23:49 -04007625 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007626 }
7627
John Bauman19bac1e2014-05-06 15:23:49 -04007628 RValue<Short4> psraw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007629 {
7630 Module *module = Nucleus::getModule();
7631 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_w);
7632
John Bauman19bac1e2014-05-06 15:23:49 -04007633 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007634 }
7635
John Bauman19bac1e2014-05-06 15:23:49 -04007636 RValue<Short4> psllw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007637 {
7638 Module *module = Nucleus::getModule();
7639 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_w);
7640
John Bauman19bac1e2014-05-06 15:23:49 -04007641 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007642 }
7643
John Bauman19bac1e2014-05-06 15:23:49 -04007644 RValue<Int2> pslld(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007645 {
7646 Module *module = Nucleus::getModule();
7647 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_d);
7648
John Bauman19bac1e2014-05-06 15:23:49 -04007649 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007650 }
7651
John Bauman19bac1e2014-05-06 15:23:49 -04007652 RValue<UInt2> psrld(RValue<UInt2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007653 {
7654 Module *module = Nucleus::getModule();
7655 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_d);
7656
John Bauman19bac1e2014-05-06 15:23:49 -04007657 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007658 }
7659
John Bauman19bac1e2014-05-06 15:23:49 -04007660 RValue<Int2> psrad(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007661 {
7662 Module *module = Nucleus::getModule();
7663 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_d);
7664
John Bauman19bac1e2014-05-06 15:23:49 -04007665 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007666 }
7667
John Bauman19bac1e2014-05-06 15:23:49 -04007668 RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y)
7669 {
7670 Module *module = Nucleus::getModule();
7671 llvm::Function *pmaxsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxsd);
7672
7673 return RValue<Int4>(Nucleus::createCall(pmaxsd, x.value, y.value));
7674 }
7675
7676 RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y)
7677 {
7678 Module *module = Nucleus::getModule();
7679 llvm::Function *pminsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminsd);
7680
7681 return RValue<Int4>(Nucleus::createCall(pminsd, x.value, y.value));
7682 }
7683
7684 RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y)
7685 {
7686 Module *module = Nucleus::getModule();
7687 llvm::Function *pmaxud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxud);
7688
John Bauman66b8ab22014-05-06 15:57:45 -04007689 return RValue<UInt4>(Nucleus::createCall(pmaxud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007690 }
7691
7692 RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y)
7693 {
7694 Module *module = Nucleus::getModule();
7695 llvm::Function *pminud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminud);
7696
John Bauman66b8ab22014-05-06 15:57:45 -04007697 return RValue<UInt4>(Nucleus::createCall(pminud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007698 }
7699
7700 RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007701 {
7702 Module *module = Nucleus::getModule();
7703 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulh_w);
7704
John Bauman19bac1e2014-05-06 15:23:49 -04007705 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmulhw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007706 }
7707
John Bauman19bac1e2014-05-06 15:23:49 -04007708 RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007709 {
7710 Module *module = Nucleus::getModule();
7711 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulhu_w);
7712
John Bauman19bac1e2014-05-06 15:23:49 -04007713 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pmulhuw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007714 }
7715
John Bauman19bac1e2014-05-06 15:23:49 -04007716 RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007717 {
7718 Module *module = Nucleus::getModule();
7719 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmadd_wd);
7720
John Bauman19bac1e2014-05-06 15:23:49 -04007721 return As<Int2>(RValue<MMX>(Nucleus::createCall(pmaddwd, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007722 }
7723
John Bauman19bac1e2014-05-06 15:23:49 -04007724 RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007725 {
7726 Module *module = Nucleus::getModule();
7727 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulh_w);
7728
7729 return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value));
7730 }
7731
John Bauman19bac1e2014-05-06 15:23:49 -04007732 RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04007733 {
7734 Module *module = Nucleus::getModule();
7735 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulhu_w);
7736
7737 return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value));
7738 }
7739
John Bauman19bac1e2014-05-06 15:23:49 -04007740 RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007741 {
7742 Module *module = Nucleus::getModule();
7743 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmadd_wd);
7744
7745 return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value));
7746 }
7747
John Bauman19bac1e2014-05-06 15:23:49 -04007748 RValue<Int> movmskps(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04007749 {
7750 Module *module = Nucleus::getModule();
7751 llvm::Function *movmskps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_movmsk_ps);
7752
7753 return RValue<Int>(Nucleus::createCall(movmskps, x.value));
7754 }
7755
John Bauman19bac1e2014-05-06 15:23:49 -04007756 RValue<Int> pmovmskb(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04007757 {
7758 Module *module = Nucleus::getModule();
7759 llvm::Function *pmovmskb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmovmskb);
7760
John Bauman19bac1e2014-05-06 15:23:49 -04007761 return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value));
John Bauman89401822014-05-06 15:04:28 -04007762 }
7763
John Bauman66b8ab22014-05-06 15:57:45 -04007764 //RValue<Int2> movd(RValue<Pointer<Int> > x)
John Bauman89401822014-05-06 15:04:28 -04007765 //{
7766 // Value *element = Nucleus::createLoad(x.value);
7767
7768 //// Value *int2 = UndefValue::get(Int2::getType());
7769 //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0));
7770
7771 // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType());
7772
7773 // return RValue<Int2>(int2);
7774 //}
7775
John Bauman19bac1e2014-05-06 15:23:49 -04007776 //RValue<Int2> movdq2q(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007777 //{
7778 // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType());
7779 // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0));
7780
7781 // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType()));
7782 //}
7783
John Bauman19bac1e2014-05-06 15:23:49 -04007784 RValue<Int4> pmovzxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007785 {
7786 Module *module = Nucleus::getModule();
7787 llvm::Function *pmovzxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007788
John Bauman89401822014-05-06 15:04:28 -04007789 return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType())));
7790 }
7791
John Bauman19bac1e2014-05-06 15:23:49 -04007792 RValue<Int4> pmovsxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007793 {
7794 Module *module = Nucleus::getModule();
7795 llvm::Function *pmovsxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007796
John Bauman89401822014-05-06 15:04:28 -04007797 return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType())));
7798 }
7799
John Bauman19bac1e2014-05-06 15:23:49 -04007800 RValue<Int4> pmovzxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007801 {
7802 Module *module = Nucleus::getModule();
7803 llvm::Function *pmovzxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007804
John Bauman89401822014-05-06 15:04:28 -04007805 return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType())));
7806 }
7807
John Bauman19bac1e2014-05-06 15:23:49 -04007808 RValue<Int4> pmovsxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007809 {
7810 Module *module = Nucleus::getModule();
7811 llvm::Function *pmovsxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007812
John Bauman89401822014-05-06 15:04:28 -04007813 return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType())));
7814 }
7815
7816 void emms()
7817 {
7818 Module *module = Nucleus::getModule();
7819 llvm::Function *emms = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_emms);
7820
7821 Nucleus::createCall(emms);
7822 }
7823 }
7824}