blob: 3c19e3f8a10bded1308aa6e51e721e2d1e99dfdd [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
John Bauman89401822014-05-06 15:04:28 -04001703 UShort::UShort()
1704 {
John Bauman89401822014-05-06 15:04:28 -04001705 }
1706
1707 UShort::UShort(unsigned short x)
1708 {
John Bauman66b8ab22014-05-06 15:57:45 -04001709 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001710 }
1711
John Bauman19bac1e2014-05-06 15:23:49 -04001712 UShort::UShort(RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001713 {
John Bauman66b8ab22014-05-06 15:57:45 -04001714 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001715 }
1716
1717 UShort::UShort(const UShort &rhs)
1718 {
John Bauman66b8ab22014-05-06 15:57:45 -04001719 Value *value = rhs.loadValue();
1720 storeValue(value);
1721 }
John Bauman89401822014-05-06 15:04:28 -04001722
John Bauman66b8ab22014-05-06 15:57:45 -04001723 UShort::UShort(const Reference<UShort> &rhs)
1724 {
1725 Value *value = rhs.loadValue();
1726 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001727 }
1728
John Bauman19bac1e2014-05-06 15:23:49 -04001729 RValue<UShort> UShort::operator=(RValue<UShort> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001730 {
John Bauman66b8ab22014-05-06 15:57:45 -04001731 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001732
1733 return rhs;
1734 }
1735
1736 RValue<UShort> UShort::operator=(const UShort &rhs) const
1737 {
John Bauman66b8ab22014-05-06 15:57:45 -04001738 Value *value = rhs.loadValue();
1739 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001740
1741 return RValue<UShort>(value);
1742 }
1743
John Bauman66b8ab22014-05-06 15:57:45 -04001744 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001745 {
John Bauman66b8ab22014-05-06 15:57:45 -04001746 Value *value = rhs.loadValue();
1747 storeValue(value);
1748
1749 return RValue<UShort>(value);
John Bauman89401822014-05-06 15:04:28 -04001750 }
1751
John Bauman19bac1e2014-05-06 15:23:49 -04001752 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001753 {
1754 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
1755 }
1756
John Bauman19bac1e2014-05-06 15:23:49 -04001757 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001758 {
1759 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
1760 }
1761
John Bauman19bac1e2014-05-06 15:23:49 -04001762 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001763 {
1764 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
1765 }
1766
John Bauman19bac1e2014-05-06 15:23:49 -04001767 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001768 {
1769 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
1770 }
1771
John Bauman19bac1e2014-05-06 15:23:49 -04001772 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001773 {
1774 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
1775 }
1776
John Bauman19bac1e2014-05-06 15:23:49 -04001777 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001778 {
1779 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
1780 }
1781
John Bauman19bac1e2014-05-06 15:23:49 -04001782 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001783 {
1784 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
1785 }
1786
John Bauman19bac1e2014-05-06 15:23:49 -04001787 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001788 {
1789 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
1790 }
1791
John Bauman19bac1e2014-05-06 15:23:49 -04001792 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001793 {
1794 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
1795 }
1796
John Bauman19bac1e2014-05-06 15:23:49 -04001797 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001798 {
1799 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
1800 }
1801
John Bauman19bac1e2014-05-06 15:23:49 -04001802 RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001803 {
1804 return lhs = lhs + rhs;
1805 }
1806
John Bauman19bac1e2014-05-06 15:23:49 -04001807 RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001808 {
1809 return lhs = lhs - rhs;
1810 }
1811
John Bauman19bac1e2014-05-06 15:23:49 -04001812 RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001813 {
1814 return lhs = lhs * rhs;
1815 }
1816
John Bauman19bac1e2014-05-06 15:23:49 -04001817 RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001818 {
1819 return lhs = lhs / rhs;
1820 }
1821
John Bauman19bac1e2014-05-06 15:23:49 -04001822 RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001823 {
1824 return lhs = lhs % rhs;
1825 }
1826
John Bauman19bac1e2014-05-06 15:23:49 -04001827 RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001828 {
1829 return lhs = lhs & rhs;
1830 }
1831
John Bauman19bac1e2014-05-06 15:23:49 -04001832 RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001833 {
1834 return lhs = lhs | rhs;
1835 }
1836
John Bauman19bac1e2014-05-06 15:23:49 -04001837 RValue<UShort> operator^=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001838 {
1839 return lhs = lhs ^ rhs;
1840 }
1841
John Bauman19bac1e2014-05-06 15:23:49 -04001842 RValue<UShort> operator<<=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001843 {
1844 return lhs = lhs << rhs;
1845 }
1846
John Bauman19bac1e2014-05-06 15:23:49 -04001847 RValue<UShort> operator>>=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001848 {
1849 return lhs = lhs >> rhs;
1850 }
1851
John Bauman19bac1e2014-05-06 15:23:49 -04001852 RValue<UShort> operator+(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001853 {
1854 return val;
1855 }
1856
John Bauman19bac1e2014-05-06 15:23:49 -04001857 RValue<UShort> operator-(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001858 {
1859 return RValue<UShort>(Nucleus::createNeg(val.value));
1860 }
1861
John Bauman19bac1e2014-05-06 15:23:49 -04001862 RValue<UShort> operator~(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001863 {
1864 return RValue<UShort>(Nucleus::createNot(val.value));
1865 }
1866
1867 RValue<UShort> operator++(const UShort &val, int) // Post-increment
1868 {
1869 RValue<UShort> res = val;
1870
1871 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001872 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001873
1874 return res;
1875 }
1876
1877 const UShort &operator++(const UShort &val) // Pre-increment
1878 {
John Bauman66b8ab22014-05-06 15:57:45 -04001879 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
1880 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001881
1882 return val;
1883 }
1884
1885 RValue<UShort> operator--(const UShort &val, int) // Post-decrement
1886 {
1887 RValue<UShort> res = val;
1888
1889 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001890 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001891
1892 return res;
1893 }
1894
1895 const UShort &operator--(const UShort &val) // Pre-decrement
1896 {
John Bauman66b8ab22014-05-06 15:57:45 -04001897 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
1898 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001899
1900 return val;
1901 }
1902
John Bauman19bac1e2014-05-06 15:23:49 -04001903 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001904 {
1905 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1906 }
1907
John Bauman19bac1e2014-05-06 15:23:49 -04001908 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001909 {
1910 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1911 }
1912
John Bauman19bac1e2014-05-06 15:23:49 -04001913 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001914 {
1915 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1916 }
1917
John Bauman19bac1e2014-05-06 15:23:49 -04001918 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001919 {
1920 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1921 }
1922
John Bauman19bac1e2014-05-06 15:23:49 -04001923 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001924 {
1925 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1926 }
1927
John Bauman19bac1e2014-05-06 15:23:49 -04001928 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001929 {
1930 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1931 }
1932
John Bauman19bac1e2014-05-06 15:23:49 -04001933 Type *UShort::getType()
John Bauman89401822014-05-06 15:04:28 -04001934 {
1935 return Type::getInt16Ty(*Nucleus::getContext());
1936 }
1937
John Bauman19bac1e2014-05-06 15:23:49 -04001938 Type *Byte4::getType()
John Bauman89401822014-05-06 15:04:28 -04001939 {
1940 #if 0
1941 return VectorType::get(Byte::getType(), 4);
1942 #else
1943 return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
1944 #endif
1945 }
1946
John Bauman19bac1e2014-05-06 15:23:49 -04001947 Type *SByte4::getType()
John Bauman89401822014-05-06 15:04:28 -04001948 {
1949 #if 0
1950 return VectorType::get(SByte::getType(), 4);
1951 #else
1952 return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
1953 #endif
1954 }
1955
1956 Byte8::Byte8()
1957 {
1958 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001959 }
1960
1961 Byte8::Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
1962 {
1963 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001964
1965 Constant *constantVector[8];
1966 constantVector[0] = Nucleus::createConstantByte(x0);
1967 constantVector[1] = Nucleus::createConstantByte(x1);
1968 constantVector[2] = Nucleus::createConstantByte(x2);
1969 constantVector[3] = Nucleus::createConstantByte(x3);
1970 constantVector[4] = Nucleus::createConstantByte(x4);
1971 constantVector[5] = Nucleus::createConstantByte(x5);
1972 constantVector[6] = Nucleus::createConstantByte(x6);
1973 constantVector[7] = Nucleus::createConstantByte(x7);
John Bauman19bac1e2014-05-06 15:23:49 -04001974 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04001975
John Bauman66b8ab22014-05-06 15:57:45 -04001976 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04001977 }
1978
1979 Byte8::Byte8(int64_t x)
1980 {
1981 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001982
1983 Constant *constantVector[8];
1984 constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
1985 constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
1986 constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
1987 constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
1988 constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
1989 constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
1990 constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
1991 constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
John Bauman19bac1e2014-05-06 15:23:49 -04001992 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04001993
John Bauman66b8ab22014-05-06 15:57:45 -04001994 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04001995 }
1996
John Bauman19bac1e2014-05-06 15:23:49 -04001997 Byte8::Byte8(RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04001998 {
1999 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002000
John Bauman66b8ab22014-05-06 15:57:45 -04002001 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002002 }
2003
2004 Byte8::Byte8(const Byte8 &rhs)
2005 {
2006 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002007
John Bauman66b8ab22014-05-06 15:57:45 -04002008 Value *value = rhs.loadValue();
2009 storeValue(value);
2010 }
2011
2012 Byte8::Byte8(const Reference<Byte8> &rhs)
2013 {
2014 // xyzw.parent = this;
2015
2016 Value *value = rhs.loadValue();
2017 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002018 }
2019
John Bauman19bac1e2014-05-06 15:23:49 -04002020 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002021 {
John Bauman66b8ab22014-05-06 15:57:45 -04002022 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002023
2024 return rhs;
2025 }
2026
2027 RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const
2028 {
John Bauman66b8ab22014-05-06 15:57:45 -04002029 Value *value = rhs.loadValue();
2030 storeValue(value);
2031
2032 return RValue<Byte8>(value);
2033 }
2034
2035 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const
2036 {
2037 Value *value = rhs.loadValue();
2038 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002039
2040 return RValue<Byte8>(value);
2041 }
2042
John Bauman19bac1e2014-05-06 15:23:49 -04002043 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002044 {
John Bauman19bac1e2014-05-06 15:23:49 -04002045 if(CPUID::supportsMMX2())
2046 {
2047 return x86::paddb(lhs, rhs);
2048 }
2049 else
2050 {
2051 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
2052 }
John Bauman89401822014-05-06 15:04:28 -04002053 }
2054
John Bauman19bac1e2014-05-06 15:23:49 -04002055 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002056 {
John Bauman19bac1e2014-05-06 15:23:49 -04002057 if(CPUID::supportsMMX2())
2058 {
2059 return x86::psubb(lhs, rhs);
2060 }
2061 else
2062 {
2063 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
2064 }
John Bauman89401822014-05-06 15:04:28 -04002065 }
2066
John Bauman19bac1e2014-05-06 15:23:49 -04002067// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2068// {
2069// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2070// }
2071
2072// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2073// {
2074// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2075// }
2076
2077// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2078// {
2079// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2080// }
2081
2082 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002083 {
John Bauman19bac1e2014-05-06 15:23:49 -04002084 if(CPUID::supportsMMX2())
2085 {
2086 return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
2087 }
2088 else
2089 {
2090 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
2091 }
John Bauman89401822014-05-06 15:04:28 -04002092 }
2093
John Bauman19bac1e2014-05-06 15:23:49 -04002094 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002095 {
John Bauman19bac1e2014-05-06 15:23:49 -04002096 if(CPUID::supportsMMX2())
2097 {
2098 return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
2099 }
2100 else
2101 {
2102 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
2103 }
John Bauman89401822014-05-06 15:04:28 -04002104 }
2105
John Bauman19bac1e2014-05-06 15:23:49 -04002106 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002107 {
John Bauman19bac1e2014-05-06 15:23:49 -04002108 if(CPUID::supportsMMX2())
2109 {
2110 return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
2111 }
2112 else
John Bauman66b8ab22014-05-06 15:57:45 -04002113 {
John Bauman19bac1e2014-05-06 15:23:49 -04002114 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
2115 }
John Bauman89401822014-05-06 15:04:28 -04002116 }
2117
John Bauman19bac1e2014-05-06 15:23:49 -04002118// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002119// {
2120// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
2121// }
2122
John Bauman19bac1e2014-05-06 15:23:49 -04002123// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002124// {
2125// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
2126// }
2127
John Bauman19bac1e2014-05-06 15:23:49 -04002128 RValue<Byte8> operator+=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002129 {
2130 return lhs = lhs + rhs;
2131 }
2132
John Bauman19bac1e2014-05-06 15:23:49 -04002133 RValue<Byte8> operator-=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002134 {
2135 return lhs = lhs - rhs;
2136 }
2137
John Bauman19bac1e2014-05-06 15:23:49 -04002138// RValue<Byte8> operator*=(const Byte8 &lhs, RValue<Byte8> rhs)
2139// {
2140// return lhs = lhs * rhs;
2141// }
John Bauman89401822014-05-06 15:04:28 -04002142
John Bauman19bac1e2014-05-06 15:23:49 -04002143// RValue<Byte8> operator/=(const Byte8 &lhs, RValue<Byte8> rhs)
2144// {
2145// return lhs = lhs / rhs;
2146// }
John Bauman89401822014-05-06 15:04:28 -04002147
John Bauman19bac1e2014-05-06 15:23:49 -04002148// RValue<Byte8> operator%=(const Byte8 &lhs, RValue<Byte8> rhs)
2149// {
2150// return lhs = lhs % rhs;
2151// }
John Bauman89401822014-05-06 15:04:28 -04002152
John Bauman19bac1e2014-05-06 15:23:49 -04002153 RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002154 {
2155 return lhs = lhs & rhs;
2156 }
2157
John Bauman19bac1e2014-05-06 15:23:49 -04002158 RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002159 {
2160 return lhs = lhs | rhs;
2161 }
2162
John Bauman19bac1e2014-05-06 15:23:49 -04002163 RValue<Byte8> operator^=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002164 {
2165 return lhs = lhs ^ rhs;
2166 }
2167
John Bauman19bac1e2014-05-06 15:23:49 -04002168// RValue<Byte8> operator<<=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002169// {
2170// return lhs = lhs << rhs;
2171// }
2172
John Bauman19bac1e2014-05-06 15:23:49 -04002173// RValue<Byte8> operator>>=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002174// {
2175// return lhs = lhs >> rhs;
2176// }
2177
John Bauman19bac1e2014-05-06 15:23:49 -04002178// RValue<Byte8> operator+(RValue<Byte8> val)
2179// {
2180// return val;
2181// }
2182
2183// RValue<Byte8> operator-(RValue<Byte8> val)
2184// {
2185// return RValue<Byte8>(Nucleus::createNeg(val.value));
2186// }
2187
2188 RValue<Byte8> operator~(RValue<Byte8> val)
John Bauman89401822014-05-06 15:04:28 -04002189 {
John Bauman19bac1e2014-05-06 15:23:49 -04002190 if(CPUID::supportsMMX2())
2191 {
2192 return val ^ Byte8(0xFFFFFFFFFFFFFFFF);
2193 }
2194 else
2195 {
2196 return RValue<Byte8>(Nucleus::createNot(val.value));
2197 }
John Bauman89401822014-05-06 15:04:28 -04002198 }
2199
John Bauman19bac1e2014-05-06 15:23:49 -04002200 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002201 {
2202 return x86::paddusb(x, y);
2203 }
John Bauman66b8ab22014-05-06 15:57:45 -04002204
John Bauman19bac1e2014-05-06 15:23:49 -04002205 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002206 {
2207 return x86::psubusb(x, y);
2208 }
2209
John Bauman19bac1e2014-05-06 15:23:49 -04002210 RValue<Short4> Unpack(RValue<Byte4> x)
John Bauman89401822014-05-06 15:04:28 -04002211 {
John Bauman19bac1e2014-05-06 15:23:49 -04002212 Value *int2 = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), x.value, 0);
2213 Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType());
John Bauman89401822014-05-06 15:04:28 -04002214
John Bauman19bac1e2014-05-06 15:23:49 -04002215 return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8));
2216 }
John Bauman89401822014-05-06 15:04:28 -04002217
John Bauman19bac1e2014-05-06 15:23:49 -04002218 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2219 {
2220 if(CPUID::supportsMMX2())
2221 {
2222 return x86::punpcklbw(x, y);
2223 }
2224 else
2225 {
2226 Constant *shuffle[8];
2227 shuffle[0] = Nucleus::createConstantInt(0);
2228 shuffle[1] = Nucleus::createConstantInt(8);
2229 shuffle[2] = Nucleus::createConstantInt(1);
2230 shuffle[3] = Nucleus::createConstantInt(9);
2231 shuffle[4] = Nucleus::createConstantInt(2);
2232 shuffle[5] = Nucleus::createConstantInt(10);
2233 shuffle[6] = Nucleus::createConstantInt(3);
2234 shuffle[7] = Nucleus::createConstantInt(11);
2235
2236 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
2237
2238 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2239 }
John Bauman89401822014-05-06 15:04:28 -04002240 }
John Bauman66b8ab22014-05-06 15:57:45 -04002241
John Bauman19bac1e2014-05-06 15:23:49 -04002242 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002243 {
John Bauman19bac1e2014-05-06 15:23:49 -04002244 if(CPUID::supportsMMX2())
2245 {
2246 return x86::punpckhbw(x, y);
2247 }
2248 else
2249 {
2250 Constant *shuffle[8];
2251 shuffle[0] = Nucleus::createConstantInt(4);
2252 shuffle[1] = Nucleus::createConstantInt(12);
2253 shuffle[2] = Nucleus::createConstantInt(5);
2254 shuffle[3] = Nucleus::createConstantInt(13);
2255 shuffle[4] = Nucleus::createConstantInt(6);
2256 shuffle[5] = Nucleus::createConstantInt(14);
2257 shuffle[6] = Nucleus::createConstantInt(7);
2258 shuffle[7] = Nucleus::createConstantInt(15);
John Bauman89401822014-05-06 15:04:28 -04002259
John Bauman19bac1e2014-05-06 15:23:49 -04002260 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002261
John Bauman19bac1e2014-05-06 15:23:49 -04002262 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2263 }
John Bauman89401822014-05-06 15:04:28 -04002264 }
2265
John Bauman19bac1e2014-05-06 15:23:49 -04002266 RValue<Int> SignMask(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04002267 {
2268 return x86::pmovmskb(x);
2269 }
2270
John Bauman19bac1e2014-05-06 15:23:49 -04002271// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002272// {
2273// return x86::pcmpgtb(x, y); // FIXME: Signedness
2274// }
John Bauman66b8ab22014-05-06 15:57:45 -04002275
John Bauman19bac1e2014-05-06 15:23:49 -04002276 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002277 {
2278 return x86::pcmpeqb(x, y);
2279 }
2280
John Bauman19bac1e2014-05-06 15:23:49 -04002281 Type *Byte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002282 {
John Bauman19bac1e2014-05-06 15:23:49 -04002283 if(CPUID::supportsMMX2())
2284 {
2285 return MMX::getType();
2286 }
2287 else
2288 {
2289 return VectorType::get(Byte::getType(), 8);
2290 }
John Bauman89401822014-05-06 15:04:28 -04002291 }
2292
2293 SByte8::SByte8()
2294 {
2295 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002296 }
2297
2298 SByte8::SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
2299 {
2300 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002301
2302 Constant *constantVector[8];
2303 constantVector[0] = Nucleus::createConstantByte(x0);
2304 constantVector[1] = Nucleus::createConstantByte(x1);
2305 constantVector[2] = Nucleus::createConstantByte(x2);
2306 constantVector[3] = Nucleus::createConstantByte(x3);
2307 constantVector[4] = Nucleus::createConstantByte(x4);
2308 constantVector[5] = Nucleus::createConstantByte(x5);
2309 constantVector[6] = Nucleus::createConstantByte(x6);
2310 constantVector[7] = Nucleus::createConstantByte(x7);
John Bauman19bac1e2014-05-06 15:23:49 -04002311 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002312
John Bauman66b8ab22014-05-06 15:57:45 -04002313 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002314 }
2315
2316 SByte8::SByte8(int64_t x)
2317 {
2318 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002319
2320 Constant *constantVector[8];
2321 constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
2322 constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
2323 constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
2324 constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
2325 constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
2326 constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
2327 constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
2328 constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
John Bauman19bac1e2014-05-06 15:23:49 -04002329 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002330
John Bauman66b8ab22014-05-06 15:57:45 -04002331 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002332 }
2333
John Bauman19bac1e2014-05-06 15:23:49 -04002334 SByte8::SByte8(RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002335 {
2336 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002337
John Bauman66b8ab22014-05-06 15:57:45 -04002338 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002339 }
2340
2341 SByte8::SByte8(const SByte8 &rhs)
2342 {
2343 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002344
John Bauman66b8ab22014-05-06 15:57:45 -04002345 Value *value = rhs.loadValue();
2346 storeValue(value);
2347 }
2348
2349 SByte8::SByte8(const Reference<SByte8> &rhs)
2350 {
2351 // xyzw.parent = this;
2352
2353 Value *value = rhs.loadValue();
2354 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002355 }
2356
John Bauman19bac1e2014-05-06 15:23:49 -04002357 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002358 {
John Bauman66b8ab22014-05-06 15:57:45 -04002359 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002360
2361 return rhs;
2362 }
2363
2364 RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const
2365 {
John Bauman66b8ab22014-05-06 15:57:45 -04002366 Value *value = rhs.loadValue();
2367 storeValue(value);
2368
2369 return RValue<SByte8>(value);
2370 }
2371
2372 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const
2373 {
2374 Value *value = rhs.loadValue();
2375 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002376
2377 return RValue<SByte8>(value);
2378 }
2379
John Bauman19bac1e2014-05-06 15:23:49 -04002380 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002381 {
John Bauman19bac1e2014-05-06 15:23:49 -04002382 if(CPUID::supportsMMX2())
2383 {
2384 return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs)));
2385 }
2386 else
2387 {
2388 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
2389 }
John Bauman89401822014-05-06 15:04:28 -04002390 }
2391
John Bauman19bac1e2014-05-06 15:23:49 -04002392 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002393 {
John Bauman19bac1e2014-05-06 15:23:49 -04002394 if(CPUID::supportsMMX2())
2395 {
2396 return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs)));
2397 }
2398 else
2399 {
2400 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
2401 }
John Bauman89401822014-05-06 15:04:28 -04002402 }
2403
John Bauman19bac1e2014-05-06 15:23:49 -04002404// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2405// {
2406// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2407// }
John Bauman89401822014-05-06 15:04:28 -04002408
John Bauman19bac1e2014-05-06 15:23:49 -04002409// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2410// {
2411// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2412// }
John Bauman89401822014-05-06 15:04:28 -04002413
John Bauman19bac1e2014-05-06 15:23:49 -04002414// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2415// {
2416// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2417// }
John Bauman89401822014-05-06 15:04:28 -04002418
John Bauman19bac1e2014-05-06 15:23:49 -04002419 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002420 {
2421 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2422 }
2423
John Bauman19bac1e2014-05-06 15:23:49 -04002424 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002425 {
2426 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2427 }
2428
John Bauman19bac1e2014-05-06 15:23:49 -04002429 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002430 {
2431 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2432 }
2433
John Bauman19bac1e2014-05-06 15:23:49 -04002434// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002435// {
2436// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
2437// }
2438
John Bauman19bac1e2014-05-06 15:23:49 -04002439// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002440// {
2441// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
2442// }
2443
John Bauman19bac1e2014-05-06 15:23:49 -04002444 RValue<SByte8> operator+=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002445 {
2446 return lhs = lhs + rhs;
2447 }
2448
John Bauman19bac1e2014-05-06 15:23:49 -04002449 RValue<SByte8> operator-=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002450 {
2451 return lhs = lhs - rhs;
2452 }
2453
John Bauman19bac1e2014-05-06 15:23:49 -04002454// RValue<SByte8> operator*=(const SByte8 &lhs, RValue<SByte8> rhs)
2455// {
2456// return lhs = lhs * rhs;
2457// }
John Bauman89401822014-05-06 15:04:28 -04002458
John Bauman19bac1e2014-05-06 15:23:49 -04002459// RValue<SByte8> operator/=(const SByte8 &lhs, RValue<SByte8> rhs)
2460// {
2461// return lhs = lhs / rhs;
2462// }
John Bauman89401822014-05-06 15:04:28 -04002463
John Bauman19bac1e2014-05-06 15:23:49 -04002464// RValue<SByte8> operator%=(const SByte8 &lhs, RValue<SByte8> rhs)
2465// {
2466// return lhs = lhs % rhs;
2467// }
John Bauman89401822014-05-06 15:04:28 -04002468
John Bauman19bac1e2014-05-06 15:23:49 -04002469 RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002470 {
2471 return lhs = lhs & rhs;
2472 }
2473
John Bauman19bac1e2014-05-06 15:23:49 -04002474 RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002475 {
2476 return lhs = lhs | rhs;
2477 }
2478
John Bauman19bac1e2014-05-06 15:23:49 -04002479 RValue<SByte8> operator^=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002480 {
2481 return lhs = lhs ^ rhs;
2482 }
2483
John Bauman19bac1e2014-05-06 15:23:49 -04002484// RValue<SByte8> operator<<=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002485// {
2486// return lhs = lhs << rhs;
2487// }
2488
John Bauman19bac1e2014-05-06 15:23:49 -04002489// RValue<SByte8> operator>>=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002490// {
2491// return lhs = lhs >> rhs;
2492// }
2493
John Bauman19bac1e2014-05-06 15:23:49 -04002494// RValue<SByte8> operator+(RValue<SByte8> val)
2495// {
2496// return val;
2497// }
2498
2499// RValue<SByte8> operator-(RValue<SByte8> val)
2500// {
2501// return RValue<SByte8>(Nucleus::createNeg(val.value));
2502// }
2503
2504 RValue<SByte8> operator~(RValue<SByte8> val)
John Bauman89401822014-05-06 15:04:28 -04002505 {
John Bauman19bac1e2014-05-06 15:23:49 -04002506 if(CPUID::supportsMMX2())
2507 {
2508 return val ^ SByte8(0xFFFFFFFFFFFFFFFF);
2509 }
2510 else
2511 {
2512 return RValue<SByte8>(Nucleus::createNot(val.value));
2513 }
John Bauman89401822014-05-06 15:04:28 -04002514 }
2515
John Bauman19bac1e2014-05-06 15:23:49 -04002516 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002517 {
2518 return x86::paddsb(x, y);
2519 }
John Bauman66b8ab22014-05-06 15:57:45 -04002520
John Bauman19bac1e2014-05-06 15:23:49 -04002521 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002522 {
2523 return x86::psubsb(x, y);
2524 }
2525
John Bauman19bac1e2014-05-06 15:23:49 -04002526 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002527 {
John Bauman19bac1e2014-05-06 15:23:49 -04002528 if(CPUID::supportsMMX2())
2529 {
2530 return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y)));
2531 }
2532 else
2533 {
2534 Constant *shuffle[8];
2535 shuffle[0] = Nucleus::createConstantInt(0);
2536 shuffle[1] = Nucleus::createConstantInt(8);
2537 shuffle[2] = Nucleus::createConstantInt(1);
2538 shuffle[3] = Nucleus::createConstantInt(9);
2539 shuffle[4] = Nucleus::createConstantInt(2);
2540 shuffle[5] = Nucleus::createConstantInt(10);
2541 shuffle[6] = Nucleus::createConstantInt(3);
2542 shuffle[7] = Nucleus::createConstantInt(11);
John Bauman89401822014-05-06 15:04:28 -04002543
John Bauman19bac1e2014-05-06 15:23:49 -04002544 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002545
John Bauman19bac1e2014-05-06 15:23:49 -04002546 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2547 }
John Bauman89401822014-05-06 15:04:28 -04002548 }
John Bauman66b8ab22014-05-06 15:57:45 -04002549
John Bauman19bac1e2014-05-06 15:23:49 -04002550 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002551 {
John Bauman19bac1e2014-05-06 15:23:49 -04002552 if(CPUID::supportsMMX2())
2553 {
2554 return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y)));
2555 }
2556 else
2557 {
2558 Constant *shuffle[8];
2559 shuffle[0] = Nucleus::createConstantInt(4);
2560 shuffle[1] = Nucleus::createConstantInt(12);
2561 shuffle[2] = Nucleus::createConstantInt(5);
2562 shuffle[3] = Nucleus::createConstantInt(13);
2563 shuffle[4] = Nucleus::createConstantInt(6);
2564 shuffle[5] = Nucleus::createConstantInt(14);
2565 shuffle[6] = Nucleus::createConstantInt(7);
2566 shuffle[7] = Nucleus::createConstantInt(15);
John Bauman89401822014-05-06 15:04:28 -04002567
John Bauman19bac1e2014-05-06 15:23:49 -04002568 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002569
John Bauman19bac1e2014-05-06 15:23:49 -04002570 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2571 }
John Bauman89401822014-05-06 15:04:28 -04002572 }
2573
John Bauman19bac1e2014-05-06 15:23:49 -04002574 RValue<Int> SignMask(RValue<SByte8> x)
John Bauman89401822014-05-06 15:04:28 -04002575 {
2576 return x86::pmovmskb(As<Byte8>(x));
2577 }
2578
John Bauman19bac1e2014-05-06 15:23:49 -04002579 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002580 {
2581 return x86::pcmpgtb(x, y);
2582 }
John Bauman66b8ab22014-05-06 15:57:45 -04002583
John Bauman19bac1e2014-05-06 15:23:49 -04002584 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002585 {
2586 return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
2587 }
2588
John Bauman19bac1e2014-05-06 15:23:49 -04002589 Type *SByte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002590 {
John Bauman19bac1e2014-05-06 15:23:49 -04002591 if(CPUID::supportsMMX2())
2592 {
2593 return MMX::getType();
2594 }
2595 else
2596 {
2597 return VectorType::get(SByte::getType(), 8);
2598 }
John Bauman89401822014-05-06 15:04:28 -04002599 }
2600
John Bauman19bac1e2014-05-06 15:23:49 -04002601 Byte16::Byte16(RValue<Byte16> rhs)
John Bauman89401822014-05-06 15:04:28 -04002602 {
2603 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002604
John Bauman66b8ab22014-05-06 15:57:45 -04002605 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002606 }
2607
2608 Byte16::Byte16(const Byte16 &rhs)
2609 {
2610 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002611
John Bauman66b8ab22014-05-06 15:57:45 -04002612 Value *value = rhs.loadValue();
2613 storeValue(value);
2614 }
2615
2616 Byte16::Byte16(const Reference<Byte16> &rhs)
2617 {
2618 // xyzw.parent = this;
2619
2620 Value *value = rhs.loadValue();
2621 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002622 }
2623
John Bauman19bac1e2014-05-06 15:23:49 -04002624 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002625 {
John Bauman66b8ab22014-05-06 15:57:45 -04002626 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002627
2628 return rhs;
2629 }
2630
2631 RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const
2632 {
John Bauman66b8ab22014-05-06 15:57:45 -04002633 Value *value = rhs.loadValue();
2634 storeValue(value);
2635
2636 return RValue<Byte16>(value);
2637 }
2638
2639 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const
2640 {
2641 Value *value = rhs.loadValue();
2642 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002643
2644 return RValue<Byte16>(value);
2645 }
2646
John Bauman19bac1e2014-05-06 15:23:49 -04002647 Type *Byte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002648 {
2649 return VectorType::get(Byte::getType(), 16);
2650 }
2651
John Bauman19bac1e2014-05-06 15:23:49 -04002652 Type *SByte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002653 {
2654 return VectorType::get(SByte::getType(), 16);
2655 }
2656
John Bauman19bac1e2014-05-06 15:23:49 -04002657 Short4::Short4(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04002658 {
John Bauman89401822014-05-06 15:04:28 -04002659 Value *extend = Nucleus::createZExt(cast.value, Long::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04002660 Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value;
John Bauman66b8ab22014-05-06 15:57:45 -04002661
2662 storeValue(swizzle);
John Bauman89401822014-05-06 15:04:28 -04002663 }
2664
John Bauman19bac1e2014-05-06 15:23:49 -04002665 Short4::Short4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04002666 {
John Bauman89401822014-05-06 15:04:28 -04002667 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
2668
2669 #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd)
2670 Constant *pack[8];
2671 pack[0] = Nucleus::createConstantInt(0);
2672 pack[1] = Nucleus::createConstantInt(2);
2673 pack[2] = Nucleus::createConstantInt(4);
2674 pack[3] = Nucleus::createConstantInt(6);
2675
2676 Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4));
2677 #else
2678 Value *packed;
2679
2680 // FIXME: Use Swizzle<Short8>
2681 if(!CPUID::supportsSSSE3())
2682 {
2683 Constant *pshuflw[8];
2684 pshuflw[0] = Nucleus::createConstantInt(0);
2685 pshuflw[1] = Nucleus::createConstantInt(2);
2686 pshuflw[2] = Nucleus::createConstantInt(0);
2687 pshuflw[3] = Nucleus::createConstantInt(2);
2688 pshuflw[4] = Nucleus::createConstantInt(4);
2689 pshuflw[5] = Nucleus::createConstantInt(5);
2690 pshuflw[6] = Nucleus::createConstantInt(6);
2691 pshuflw[7] = Nucleus::createConstantInt(7);
2692
2693 Constant *pshufhw[8];
2694 pshufhw[0] = Nucleus::createConstantInt(0);
2695 pshufhw[1] = Nucleus::createConstantInt(1);
2696 pshufhw[2] = Nucleus::createConstantInt(2);
2697 pshufhw[3] = Nucleus::createConstantInt(3);
2698 pshufhw[4] = Nucleus::createConstantInt(4);
2699 pshufhw[5] = Nucleus::createConstantInt(6);
2700 pshufhw[6] = Nucleus::createConstantInt(4);
2701 pshufhw[7] = Nucleus::createConstantInt(6);
2702
2703 Value *shuffle1 = Nucleus::createShuffleVector(short8, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshuflw, 8));
2704 Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshufhw, 8));
2705 Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType());
2706 packed = Nucleus::createSwizzle(int4, 0x88);
2707 }
2708 else
2709 {
2710 Constant *pshufb[16];
2711 pshufb[0] = Nucleus::createConstantInt(0);
2712 pshufb[1] = Nucleus::createConstantInt(1);
2713 pshufb[2] = Nucleus::createConstantInt(4);
2714 pshufb[3] = Nucleus::createConstantInt(5);
2715 pshufb[4] = Nucleus::createConstantInt(8);
2716 pshufb[5] = Nucleus::createConstantInt(9);
2717 pshufb[6] = Nucleus::createConstantInt(12);
2718 pshufb[7] = Nucleus::createConstantInt(13);
2719 pshufb[8] = Nucleus::createConstantInt(0);
2720 pshufb[9] = Nucleus::createConstantInt(1);
2721 pshufb[10] = Nucleus::createConstantInt(4);
2722 pshufb[11] = Nucleus::createConstantInt(5);
2723 pshufb[12] = Nucleus::createConstantInt(8);
2724 pshufb[13] = Nucleus::createConstantInt(9);
2725 pshufb[14] = Nucleus::createConstantInt(12);
2726 pshufb[15] = Nucleus::createConstantInt(13);
2727
2728 Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType());
2729 packed = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
2730 }
2731
2732 #if 0 // FIXME: No optimal instruction selection
2733 Value *qword2 = Nucleus::createBitCast(packed, Long2::getType());
2734 Value *element = Nucleus::createExtractElement(qword2, 0);
2735 Value *short4 = Nucleus::createBitCast(element, Short4::getType());
2736 #else // FIXME: Requires SSE
2737 Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
2738 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
2739 #endif
2740 #endif
2741
John Bauman66b8ab22014-05-06 15:57:45 -04002742 storeValue(short4);
John Bauman89401822014-05-06 15:04:28 -04002743 }
2744
John Bauman19bac1e2014-05-06 15:23:49 -04002745// Short4::Short4(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04002746// {
2747// }
2748
John Bauman19bac1e2014-05-06 15:23:49 -04002749 Short4::Short4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04002750 {
John Bauman89401822014-05-06 15:04:28 -04002751 Int4 v4i32 = Int4(cast);
2752 v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
John Bauman66b8ab22014-05-06 15:57:45 -04002753
2754 storeValue(As<Short4>(Int2(v4i32)).value);
John Bauman89401822014-05-06 15:04:28 -04002755 }
2756
2757 Short4::Short4()
2758 {
2759 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002760 }
2761
John Bauman19bac1e2014-05-06 15:23:49 -04002762 Short4::Short4(short xyzw)
2763 {
2764 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04002765
2766 Constant *constantVector[4];
2767 constantVector[0] = Nucleus::createConstantShort(xyzw);
2768 constantVector[1] = Nucleus::createConstantShort(xyzw);
2769 constantVector[2] = Nucleus::createConstantShort(xyzw);
2770 constantVector[3] = Nucleus::createConstantShort(xyzw);
2771 Value *vector = Nucleus::createConstantVector(constantVector, 4);
2772
John Bauman66b8ab22014-05-06 15:57:45 -04002773 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman19bac1e2014-05-06 15:23:49 -04002774 }
2775
John Bauman89401822014-05-06 15:04:28 -04002776 Short4::Short4(short x, short y, short z, short w)
2777 {
2778 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002779
2780 Constant *constantVector[4];
2781 constantVector[0] = Nucleus::createConstantShort(x);
2782 constantVector[1] = Nucleus::createConstantShort(y);
2783 constantVector[2] = Nucleus::createConstantShort(z);
2784 constantVector[3] = Nucleus::createConstantShort(w);
John Bauman19bac1e2014-05-06 15:23:49 -04002785 Value *vector = Nucleus::createConstantVector(constantVector, 4);
2786
John Bauman66b8ab22014-05-06 15:57:45 -04002787 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002788 }
2789
John Bauman19bac1e2014-05-06 15:23:49 -04002790 Short4::Short4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002791 {
2792 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002793
John Bauman66b8ab22014-05-06 15:57:45 -04002794 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002795 }
2796
2797 Short4::Short4(const Short4 &rhs)
2798 {
2799 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002800
John Bauman66b8ab22014-05-06 15:57:45 -04002801 Value *value = rhs.loadValue();
2802 storeValue(value);
2803 }
2804
2805 Short4::Short4(const Reference<Short4> &rhs)
2806 {
2807 // xyzw.parent = this;
2808
2809 Value *value = rhs.loadValue();
2810 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002811 }
2812
John Bauman19bac1e2014-05-06 15:23:49 -04002813 Short4::Short4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002814 {
2815 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002816
John Bauman66b8ab22014-05-06 15:57:45 -04002817 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002818 }
2819
2820 Short4::Short4(const UShort4 &rhs)
2821 {
2822 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002823
John Bauman66b8ab22014-05-06 15:57:45 -04002824 storeValue(rhs.loadValue());
2825 }
2826
2827 Short4::Short4(const Reference<UShort4> &rhs)
2828 {
2829 // xyzw.parent = this;
2830
2831 storeValue(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04002832 }
2833
John Bauman19bac1e2014-05-06 15:23:49 -04002834 RValue<Short4> Short4::operator=(RValue<Short4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002835 {
John Bauman66b8ab22014-05-06 15:57:45 -04002836 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002837
2838 return rhs;
2839 }
2840
2841 RValue<Short4> Short4::operator=(const Short4 &rhs) const
2842 {
John Bauman66b8ab22014-05-06 15:57:45 -04002843 Value *value = rhs.loadValue();
2844 storeValue(value);
2845
2846 return RValue<Short4>(value);
2847 }
2848
2849 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const
2850 {
2851 Value *value = rhs.loadValue();
2852 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002853
2854 return RValue<Short4>(value);
2855 }
2856
John Bauman19bac1e2014-05-06 15:23:49 -04002857 RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002858 {
John Bauman66b8ab22014-05-06 15:57:45 -04002859 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002860
John Bauman66b8ab22014-05-06 15:57:45 -04002861 return RValue<Short4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04002862 }
2863
2864 RValue<Short4> Short4::operator=(const UShort4 &rhs) const
2865 {
John Bauman66b8ab22014-05-06 15:57:45 -04002866 Value *value = rhs.loadValue();
2867 storeValue(value);
2868
2869 return RValue<Short4>(value);
2870 }
2871
2872 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const
2873 {
2874 Value *value = rhs.loadValue();
2875 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002876
2877 return RValue<Short4>(value);
2878 }
2879
John Bauman19bac1e2014-05-06 15:23:49 -04002880 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002881 {
John Bauman19bac1e2014-05-06 15:23:49 -04002882 if(CPUID::supportsMMX2())
2883 {
2884 return x86::paddw(lhs, rhs);
2885 }
2886 else
2887 {
2888 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
2889 }
John Bauman89401822014-05-06 15:04:28 -04002890 }
2891
John Bauman19bac1e2014-05-06 15:23:49 -04002892 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002893 {
John Bauman19bac1e2014-05-06 15:23:49 -04002894 if(CPUID::supportsMMX2())
2895 {
2896 return x86::psubw(lhs, rhs);
2897 }
2898 else
2899 {
2900 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
2901 }
John Bauman89401822014-05-06 15:04:28 -04002902 }
2903
John Bauman19bac1e2014-05-06 15:23:49 -04002904 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002905 {
John Bauman19bac1e2014-05-06 15:23:49 -04002906 if(CPUID::supportsMMX2())
2907 {
2908 return x86::pmullw(lhs, rhs);
2909 }
2910 else
2911 {
2912 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
2913 }
John Bauman89401822014-05-06 15:04:28 -04002914 }
2915
John Bauman19bac1e2014-05-06 15:23:49 -04002916// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
2917// {
2918// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
2919// }
2920
2921// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
2922// {
2923// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
2924// }
2925
2926 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002927 {
John Bauman19bac1e2014-05-06 15:23:49 -04002928 if(CPUID::supportsMMX2())
2929 {
2930 return x86::pand(lhs, rhs);
2931 }
2932 else
2933 {
2934 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
2935 }
John Bauman89401822014-05-06 15:04:28 -04002936 }
2937
John Bauman19bac1e2014-05-06 15:23:49 -04002938 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002939 {
John Bauman19bac1e2014-05-06 15:23:49 -04002940 if(CPUID::supportsMMX2())
2941 {
2942 return x86::por(lhs, rhs);
2943 }
2944 else
2945 {
2946 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
2947 }
John Bauman89401822014-05-06 15:04:28 -04002948 }
2949
John Bauman19bac1e2014-05-06 15:23:49 -04002950 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002951 {
John Bauman19bac1e2014-05-06 15:23:49 -04002952 if(CPUID::supportsMMX2())
2953 {
2954 return x86::pxor(lhs, rhs);
2955 }
2956 else
2957 {
2958 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
2959 }
John Bauman89401822014-05-06 15:04:28 -04002960 }
2961
John Bauman19bac1e2014-05-06 15:23:49 -04002962 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002963 {
2964 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2965
2966 return x86::psllw(lhs, rhs);
2967 }
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::createAShr(lhs.value, rhs.value));
2972
2973 return x86::psraw(lhs, rhs);
2974 }
2975
John Bauman19bac1e2014-05-06 15:23:49 -04002976 RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04002977 {
2978 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2979
2980 return x86::psllw(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::createAShr(lhs.value, rhs.value));
2986
2987 return x86::psraw(lhs, rhs);
2988 }
2989
John Bauman19bac1e2014-05-06 15:23:49 -04002990 RValue<Short4> operator+=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002991 {
2992 return lhs = lhs + rhs;
2993 }
2994
John Bauman19bac1e2014-05-06 15:23:49 -04002995 RValue<Short4> operator-=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002996 {
2997 return lhs = lhs - rhs;
2998 }
2999
John Bauman19bac1e2014-05-06 15:23:49 -04003000 RValue<Short4> operator*=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003001 {
3002 return lhs = lhs * rhs;
3003 }
3004
John Bauman19bac1e2014-05-06 15:23:49 -04003005// RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs)
3006// {
3007// return lhs = lhs / rhs;
3008// }
John Bauman89401822014-05-06 15:04:28 -04003009
John Bauman19bac1e2014-05-06 15:23:49 -04003010// RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs)
3011// {
3012// return lhs = lhs % rhs;
3013// }
John Bauman89401822014-05-06 15:04:28 -04003014
John Bauman19bac1e2014-05-06 15:23:49 -04003015 RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003016 {
3017 return lhs = lhs & rhs;
3018 }
3019
John Bauman19bac1e2014-05-06 15:23:49 -04003020 RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003021 {
3022 return lhs = lhs | rhs;
3023 }
3024
John Bauman19bac1e2014-05-06 15:23:49 -04003025 RValue<Short4> operator^=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003026 {
3027 return lhs = lhs ^ rhs;
3028 }
3029
3030 RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs)
3031 {
3032 return lhs = lhs << rhs;
3033 }
3034
3035 RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs)
3036 {
3037 return lhs = lhs >> rhs;
3038 }
3039
John Bauman19bac1e2014-05-06 15:23:49 -04003040 RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003041 {
3042 return lhs = lhs << rhs;
3043 }
3044
John Bauman19bac1e2014-05-06 15:23:49 -04003045 RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003046 {
3047 return lhs = lhs >> rhs;
3048 }
3049
John Bauman19bac1e2014-05-06 15:23:49 -04003050// RValue<Short4> operator+(RValue<Short4> val)
3051// {
3052// return val;
3053// }
3054
3055 RValue<Short4> operator-(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04003056 {
John Bauman19bac1e2014-05-06 15:23:49 -04003057 if(CPUID::supportsMMX2())
3058 {
3059 return Short4(0, 0, 0, 0) - val;
3060 }
3061 else
3062 {
3063 return RValue<Short4>(Nucleus::createNeg(val.value));
3064 }
John Bauman89401822014-05-06 15:04:28 -04003065 }
3066
John Bauman19bac1e2014-05-06 15:23:49 -04003067 RValue<Short4> operator~(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04003068 {
John Bauman19bac1e2014-05-06 15:23:49 -04003069 if(CPUID::supportsMMX2())
3070 {
3071 return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu);
3072 }
3073 else
3074 {
3075 return RValue<Short4>(Nucleus::createNot(val.value));
3076 }
John Bauman89401822014-05-06 15:04:28 -04003077 }
3078
John Bauman19bac1e2014-05-06 15:23:49 -04003079 RValue<Short4> RoundShort4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04003080 {
3081 RValue<Int4> v4i32 = x86::cvtps2dq(cast);
3082 v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
John Bauman66b8ab22014-05-06 15:57:45 -04003083
John Bauman89401822014-05-06 15:04:28 -04003084 return As<Short4>(Int2(v4i32));
3085 }
3086
John Bauman19bac1e2014-05-06 15:23:49 -04003087 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003088 {
3089 return x86::pmaxsw(x, y);
3090 }
3091
John Bauman19bac1e2014-05-06 15:23:49 -04003092 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003093 {
3094 return x86::pminsw(x, y);
3095 }
3096
John Bauman19bac1e2014-05-06 15:23:49 -04003097 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003098 {
3099 return x86::paddsw(x, y);
3100 }
3101
John Bauman19bac1e2014-05-06 15:23:49 -04003102 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003103 {
3104 return x86::psubsw(x, y);
3105 }
3106
John Bauman19bac1e2014-05-06 15:23:49 -04003107 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003108 {
3109 return x86::pmulhw(x, y);
3110 }
3111
John Bauman19bac1e2014-05-06 15:23:49 -04003112 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003113 {
3114 return x86::pmaddwd(x, y);
3115 }
3116
John Bauman19bac1e2014-05-06 15:23:49 -04003117 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003118 {
3119 return x86::packsswb(x, y);
3120 }
3121
John Bauman19bac1e2014-05-06 15:23:49 -04003122 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003123 {
John Bauman19bac1e2014-05-06 15:23:49 -04003124 if(CPUID::supportsMMX2())
3125 {
3126 return x86::punpcklwd(x, y);
3127 }
3128 else
3129 {
3130 Constant *shuffle[4];
3131 shuffle[0] = Nucleus::createConstantInt(0);
3132 shuffle[1] = Nucleus::createConstantInt(4);
3133 shuffle[2] = Nucleus::createConstantInt(1);
3134 shuffle[3] = Nucleus::createConstantInt(5);
John Bauman89401822014-05-06 15:04:28 -04003135
John Bauman19bac1e2014-05-06 15:23:49 -04003136 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
John Bauman89401822014-05-06 15:04:28 -04003137
John Bauman19bac1e2014-05-06 15:23:49 -04003138 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
3139 }
John Bauman89401822014-05-06 15:04:28 -04003140 }
3141
John Bauman19bac1e2014-05-06 15:23:49 -04003142 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003143 {
John Bauman19bac1e2014-05-06 15:23:49 -04003144 if(CPUID::supportsMMX2())
3145 {
3146 return x86::punpckhwd(x, y);
3147 }
3148 else
3149 {
3150 Constant *shuffle[4];
3151 shuffle[0] = Nucleus::createConstantInt(2);
3152 shuffle[1] = Nucleus::createConstantInt(6);
3153 shuffle[2] = Nucleus::createConstantInt(3);
3154 shuffle[3] = Nucleus::createConstantInt(7);
John Bauman89401822014-05-06 15:04:28 -04003155
John Bauman19bac1e2014-05-06 15:23:49 -04003156 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
John Bauman89401822014-05-06 15:04:28 -04003157
John Bauman19bac1e2014-05-06 15:23:49 -04003158 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
3159 }
John Bauman89401822014-05-06 15:04:28 -04003160 }
3161
John Bauman19bac1e2014-05-06 15:23:49 -04003162 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04003163 {
John Bauman19bac1e2014-05-06 15:23:49 -04003164 if(CPUID::supportsMMX2())
3165 {
3166 return x86::pshufw(x, select);
3167 }
3168 else
3169 {
3170 return RValue<Short4>(Nucleus::createSwizzle(x.value, select));
3171 }
John Bauman89401822014-05-06 15:04:28 -04003172 }
3173
John Bauman19bac1e2014-05-06 15:23:49 -04003174 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
John Bauman89401822014-05-06 15:04:28 -04003175 {
John Bauman19bac1e2014-05-06 15:23:49 -04003176 if(CPUID::supportsMMX2())
3177 {
3178 return x86::pinsrw(val, Int(element), i);
3179 }
3180 else
3181 {
3182 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
3183 }
John Bauman89401822014-05-06 15:04:28 -04003184 }
3185
John Bauman19bac1e2014-05-06 15:23:49 -04003186 RValue<Short> Extract(RValue<Short4> val, int i)
John Bauman89401822014-05-06 15:04:28 -04003187 {
John Bauman19bac1e2014-05-06 15:23:49 -04003188 if(CPUID::supportsMMX2())
3189 {
3190 return Short(x86::pextrw(val, i));
3191 }
3192 else
3193 {
3194 return RValue<Short>(Nucleus::createExtractElement(val.value, i));
3195 }
John Bauman89401822014-05-06 15:04:28 -04003196 }
3197
John Bauman19bac1e2014-05-06 15:23:49 -04003198 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003199 {
3200 return x86::pcmpgtw(x, y);
3201 }
3202
John Bauman19bac1e2014-05-06 15:23:49 -04003203 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003204 {
3205 return x86::pcmpeqw(x, y);
3206 }
3207
John Bauman19bac1e2014-05-06 15:23:49 -04003208 Type *Short4::getType()
John Bauman89401822014-05-06 15:04:28 -04003209 {
John Bauman19bac1e2014-05-06 15:23:49 -04003210 if(CPUID::supportsMMX2())
3211 {
3212 return MMX::getType();
3213 }
3214 else
3215 {
3216 return VectorType::get(Short::getType(), 4);
3217 }
John Bauman89401822014-05-06 15:04:28 -04003218 }
3219
John Bauman19bac1e2014-05-06 15:23:49 -04003220 UShort4::UShort4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04003221 {
John Bauman89401822014-05-06 15:04:28 -04003222 *this = Short4(cast);
3223 }
3224
John Bauman19bac1e2014-05-06 15:23:49 -04003225 UShort4::UShort4(RValue<Float4> cast, bool saturate)
John Bauman89401822014-05-06 15:04:28 -04003226 {
John Bauman89401822014-05-06 15:04:28 -04003227 Float4 sat;
3228
3229 if(saturate)
3230 {
3231 if(CPUID::supportsSSE4_1())
3232 {
3233 sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation
3234 }
3235 else
3236 {
3237 sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000));
3238 }
3239 }
3240 else
3241 {
3242 sat = cast;
3243 }
3244
3245 Int4 int4(sat);
3246
3247 if(!saturate || !CPUID::supportsSSE4_1())
3248 {
3249 *this = Short4(Int4(int4));
3250 }
3251 else
3252 {
3253 *this = As<Short4>(Int2(As<Int4>(x86::packusdw(As<UInt4>(int4), As<UInt4>(int4)))));
3254 }
3255 }
3256
3257 UShort4::UShort4()
3258 {
3259 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003260 }
3261
3262 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3263 {
3264 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003265
3266 Constant *constantVector[4];
3267 constantVector[0] = Nucleus::createConstantShort(x);
3268 constantVector[1] = Nucleus::createConstantShort(y);
3269 constantVector[2] = Nucleus::createConstantShort(z);
3270 constantVector[3] = Nucleus::createConstantShort(w);
John Bauman19bac1e2014-05-06 15:23:49 -04003271 Value *vector = Nucleus::createConstantVector(constantVector, 4);
John Bauman89401822014-05-06 15:04:28 -04003272
John Bauman66b8ab22014-05-06 15:57:45 -04003273 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04003274 }
3275
John Bauman19bac1e2014-05-06 15:23:49 -04003276 UShort4::UShort4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003277 {
3278 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003279
John Bauman66b8ab22014-05-06 15:57:45 -04003280 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003281 }
3282
3283 UShort4::UShort4(const UShort4 &rhs)
3284 {
3285 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003286
John Bauman66b8ab22014-05-06 15:57:45 -04003287 Value *value = rhs.loadValue();
3288 storeValue(value);
3289 }
3290
3291 UShort4::UShort4(const Reference<UShort4> &rhs)
3292 {
3293 // xyzw.parent = this;
3294
3295 Value *value = rhs.loadValue();
3296 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003297 }
3298
John Bauman19bac1e2014-05-06 15:23:49 -04003299 UShort4::UShort4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003300 {
3301 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003302
John Bauman66b8ab22014-05-06 15:57:45 -04003303 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003304 }
3305
3306 UShort4::UShort4(const Short4 &rhs)
3307 {
3308 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003309
John Bauman66b8ab22014-05-06 15:57:45 -04003310 Value *value = rhs.loadValue();
3311 storeValue(value);
3312 }
3313
3314 UShort4::UShort4(const Reference<Short4> &rhs)
3315 {
3316 // xyzw.parent = this;
3317
3318 Value *value = rhs.loadValue();
3319 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003320 }
3321
John Bauman19bac1e2014-05-06 15:23:49 -04003322 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003323 {
John Bauman66b8ab22014-05-06 15:57:45 -04003324 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003325
3326 return rhs;
3327 }
3328
3329 RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const
3330 {
John Bauman66b8ab22014-05-06 15:57:45 -04003331 Value *value = rhs.loadValue();
3332 storeValue(value);
3333
3334 return RValue<UShort4>(value);
3335 }
3336
3337 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const
3338 {
3339 Value *value = rhs.loadValue();
3340 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003341
3342 return RValue<UShort4>(value);
3343 }
3344
John Bauman19bac1e2014-05-06 15:23:49 -04003345 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003346 {
John Bauman66b8ab22014-05-06 15:57:45 -04003347 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003348
John Bauman66b8ab22014-05-06 15:57:45 -04003349 return RValue<UShort4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003350 }
3351
3352 RValue<UShort4> UShort4::operator=(const Short4 &rhs) const
3353 {
John Bauman66b8ab22014-05-06 15:57:45 -04003354 Value *value = rhs.loadValue();
3355 storeValue(value);
3356
3357 return RValue<UShort4>(value);
3358 }
3359
3360 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const
3361 {
3362 Value *value = rhs.loadValue();
3363 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003364
3365 return RValue<UShort4>(value);
3366 }
3367
John Bauman19bac1e2014-05-06 15:23:49 -04003368 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003369 {
John Bauman19bac1e2014-05-06 15:23:49 -04003370 if(CPUID::supportsMMX2())
3371 {
3372 return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs)));
3373 }
3374 else
3375 {
3376 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
3377 }
John Bauman89401822014-05-06 15:04:28 -04003378 }
3379
John Bauman19bac1e2014-05-06 15:23:49 -04003380 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003381 {
John Bauman19bac1e2014-05-06 15:23:49 -04003382 if(CPUID::supportsMMX2())
3383 {
3384 return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs)));
3385 }
3386 else
3387 {
3388 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
3389 }
John Bauman89401822014-05-06 15:04:28 -04003390 }
3391
John Bauman19bac1e2014-05-06 15:23:49 -04003392
3393 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003394 {
John Bauman19bac1e2014-05-06 15:23:49 -04003395 if(CPUID::supportsMMX2())
3396 {
3397 return As<UShort4>(x86::pmullw(As<Short4>(lhs), As<Short4>(rhs)));
3398 }
3399 else
3400 {
3401 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
3402 }
John Bauman89401822014-05-06 15:04:28 -04003403 }
3404
John Bauman19bac1e2014-05-06 15:23:49 -04003405 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003406 {
3407 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3408
3409 return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
3410 }
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::createLShr(lhs.value, rhs.value));
3415
3416 return x86::psrlw(lhs, rhs);
3417 }
3418
John Bauman19bac1e2014-05-06 15:23:49 -04003419 RValue<UShort4> operator<<(RValue<UShort4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003420 {
3421 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3422
3423 return As<UShort4>(x86::psllw(As<Short4>(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::createLShr(lhs.value, rhs.value));
3429
3430 return x86::psrlw(lhs, rhs);
3431 }
3432
3433 RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs)
3434 {
3435 return lhs = lhs << rhs;
3436 }
3437
3438 RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs)
3439 {
3440 return lhs = lhs >> rhs;
3441 }
3442
John Bauman19bac1e2014-05-06 15:23:49 -04003443 RValue<UShort4> operator<<=(const UShort4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003444 {
3445 return lhs = lhs << rhs;
3446 }
3447
John Bauman19bac1e2014-05-06 15:23:49 -04003448 RValue<UShort4> operator>>=(const UShort4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003449 {
3450 return lhs = lhs >> rhs;
3451 }
3452
John Bauman19bac1e2014-05-06 15:23:49 -04003453 RValue<UShort4> operator~(RValue<UShort4> val)
John Bauman89401822014-05-06 15:04:28 -04003454 {
John Bauman19bac1e2014-05-06 15:23:49 -04003455 if(CPUID::supportsMMX2())
3456 {
3457 return As<UShort4>(As<Short4>(val) ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu));
3458 }
3459 else
3460 {
3461 return RValue<UShort4>(Nucleus::createNot(val.value));
3462 }
John Bauman89401822014-05-06 15:04:28 -04003463 }
3464
John Bauman19bac1e2014-05-06 15:23:49 -04003465 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003466 {
John Bauman66b8ab22014-05-06 15:57:45 -04003467 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 -04003468 }
3469
John Bauman19bac1e2014-05-06 15:23:49 -04003470 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003471 {
John Bauman66b8ab22014-05-06 15:57:45 -04003472 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 -04003473 }
3474
John Bauman19bac1e2014-05-06 15:23:49 -04003475 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003476 {
3477 return x86::paddusw(x, y);
3478 }
3479
John Bauman19bac1e2014-05-06 15:23:49 -04003480 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003481 {
3482 return x86::psubusw(x, y);
3483 }
3484
John Bauman19bac1e2014-05-06 15:23:49 -04003485 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003486 {
3487 return x86::pmulhuw(x, y);
3488 }
3489
John Bauman19bac1e2014-05-06 15:23:49 -04003490 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003491 {
3492 return x86::pavgw(x, y);
3493 }
3494
John Bauman19bac1e2014-05-06 15:23:49 -04003495 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003496 {
3497 return x86::packuswb(x, y);
3498 }
3499
John Bauman19bac1e2014-05-06 15:23:49 -04003500 Type *UShort4::getType()
John Bauman89401822014-05-06 15:04:28 -04003501 {
John Bauman19bac1e2014-05-06 15:23:49 -04003502 if(CPUID::supportsMMX2())
3503 {
3504 return MMX::getType();
3505 }
3506 else
3507 {
3508 return VectorType::get(UShort::getType(), 4);
3509 }
John Bauman89401822014-05-06 15:04:28 -04003510 }
3511
3512 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3513 {
3514 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003515
3516 Constant *constantVector[8];
3517 constantVector[0] = Nucleus::createConstantShort(c0);
3518 constantVector[1] = Nucleus::createConstantShort(c1);
3519 constantVector[2] = Nucleus::createConstantShort(c2);
3520 constantVector[3] = Nucleus::createConstantShort(c3);
3521 constantVector[4] = Nucleus::createConstantShort(c4);
3522 constantVector[5] = Nucleus::createConstantShort(c5);
3523 constantVector[6] = Nucleus::createConstantShort(c6);
3524 constantVector[7] = Nucleus::createConstantShort(c7);
3525
John Bauman66b8ab22014-05-06 15:57:45 -04003526 storeValue(Nucleus::createConstantVector(constantVector, 8));
John Bauman89401822014-05-06 15:04:28 -04003527 }
3528
John Bauman19bac1e2014-05-06 15:23:49 -04003529 Short8::Short8(RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003530 {
3531 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003532
John Bauman66b8ab22014-05-06 15:57:45 -04003533 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003534 }
3535
John Bauman19bac1e2014-05-06 15:23:49 -04003536 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003537 {
3538 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3539 }
3540
John Bauman19bac1e2014-05-06 15:23:49 -04003541 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003542 {
3543 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3544 }
3545
John Bauman19bac1e2014-05-06 15:23:49 -04003546 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003547 {
3548 return x86::psllw(lhs, rhs); // FIXME: Fallback required
3549 }
3550
John Bauman19bac1e2014-05-06 15:23:49 -04003551 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003552 {
3553 return x86::psraw(lhs, rhs); // FIXME: Fallback required
3554 }
3555
John Bauman19bac1e2014-05-06 15:23:49 -04003556 RValue<Short8> Concatenate(RValue<Short4> lo, RValue<Short4> hi)
John Bauman89401822014-05-06 15:04:28 -04003557 {
3558 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
3559 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
3560
3561 Value *long2 = UndefValue::get(Long2::getType());
3562 long2 = Nucleus::createInsertElement(long2, loLong, 0);
3563 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
3564 Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
3565
3566 return RValue<Short8>(short8);
3567 }
3568
John Bauman19bac1e2014-05-06 15:23:49 -04003569 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003570 {
3571 return x86::pmaddwd(x, y); // FIXME: Fallback required
3572 }
3573
John Bauman19bac1e2014-05-06 15:23:49 -04003574 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003575 {
3576 return x86::pmulhw(x, y); // FIXME: Fallback required
3577 }
3578
John Bauman19bac1e2014-05-06 15:23:49 -04003579 Type *Short8::getType()
John Bauman89401822014-05-06 15:04:28 -04003580 {
3581 return VectorType::get(Short::getType(), 8);
3582 }
3583
3584 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)
3585 {
3586 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003587
3588 Constant *constantVector[8];
3589 constantVector[0] = Nucleus::createConstantShort(c0);
3590 constantVector[1] = Nucleus::createConstantShort(c1);
3591 constantVector[2] = Nucleus::createConstantShort(c2);
3592 constantVector[3] = Nucleus::createConstantShort(c3);
3593 constantVector[4] = Nucleus::createConstantShort(c4);
3594 constantVector[5] = Nucleus::createConstantShort(c5);
3595 constantVector[6] = Nucleus::createConstantShort(c6);
3596 constantVector[7] = Nucleus::createConstantShort(c7);
3597
John Bauman66b8ab22014-05-06 15:57:45 -04003598 storeValue(Nucleus::createConstantVector(constantVector, 8));
John Bauman89401822014-05-06 15:04:28 -04003599 }
3600
John Bauman19bac1e2014-05-06 15:23:49 -04003601 UShort8::UShort8(RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003602 {
3603 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003604
John Bauman66b8ab22014-05-06 15:57:45 -04003605 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003606 }
3607
John Bauman19bac1e2014-05-06 15:23:49 -04003608 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003609 {
John Bauman66b8ab22014-05-06 15:57:45 -04003610 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003611
3612 return rhs;
3613 }
3614
3615 RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const
3616 {
John Bauman66b8ab22014-05-06 15:57:45 -04003617 Value *value = rhs.loadValue();
3618 storeValue(value);
3619
3620 return RValue<UShort8>(value);
3621 }
3622
3623 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) const
3624 {
3625 Value *value = rhs.loadValue();
3626 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003627
3628 return RValue<UShort8>(value);
3629 }
3630
John Bauman19bac1e2014-05-06 15:23:49 -04003631 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003632 {
3633 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3634 }
3635
John Bauman19bac1e2014-05-06 15:23:49 -04003636 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003637 {
3638 return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required
3639 }
3640
John Bauman19bac1e2014-05-06 15:23:49 -04003641 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003642 {
3643 return x86::psrlw(lhs, rhs); // FIXME: Fallback required
3644 }
3645
John Bauman19bac1e2014-05-06 15:23:49 -04003646 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003647 {
3648 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.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::createMul(lhs.value, rhs.value));
3654 }
3655
John Bauman19bac1e2014-05-06 15:23:49 -04003656 RValue<UShort8> operator+=(const UShort8 &lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003657 {
3658 return lhs = lhs + rhs;
3659 }
3660
John Bauman19bac1e2014-05-06 15:23:49 -04003661 RValue<UShort8> operator~(RValue<UShort8> val)
John Bauman89401822014-05-06 15:04:28 -04003662 {
3663 return RValue<UShort8>(Nucleus::createNot(val.value));
3664 }
3665
John Bauman19bac1e2014-05-06 15:23:49 -04003666 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 -04003667 {
3668 Constant *pshufb[16];
3669 pshufb[0] = Nucleus::createConstantInt(select0 + 0);
3670 pshufb[1] = Nucleus::createConstantInt(select0 + 1);
3671 pshufb[2] = Nucleus::createConstantInt(select1 + 0);
3672 pshufb[3] = Nucleus::createConstantInt(select1 + 1);
3673 pshufb[4] = Nucleus::createConstantInt(select2 + 0);
3674 pshufb[5] = Nucleus::createConstantInt(select2 + 1);
3675 pshufb[6] = Nucleus::createConstantInt(select3 + 0);
3676 pshufb[7] = Nucleus::createConstantInt(select3 + 1);
3677 pshufb[8] = Nucleus::createConstantInt(select4 + 0);
3678 pshufb[9] = Nucleus::createConstantInt(select4 + 1);
3679 pshufb[10] = Nucleus::createConstantInt(select5 + 0);
3680 pshufb[11] = Nucleus::createConstantInt(select5 + 1);
3681 pshufb[12] = Nucleus::createConstantInt(select6 + 0);
3682 pshufb[13] = Nucleus::createConstantInt(select6 + 1);
3683 pshufb[14] = Nucleus::createConstantInt(select7 + 0);
3684 pshufb[15] = Nucleus::createConstantInt(select7 + 1);
3685
3686 Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
3687 Value *shuffle = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
3688 Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3689
3690 return RValue<UShort8>(short8);
3691 }
3692
John Bauman19bac1e2014-05-06 15:23:49 -04003693 RValue<UShort8> Concatenate(RValue<UShort4> lo, RValue<UShort4> hi)
John Bauman89401822014-05-06 15:04:28 -04003694 {
3695 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
3696 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
3697
3698 Value *long2 = UndefValue::get(Long2::getType());
3699 long2 = Nucleus::createInsertElement(long2, loLong, 0);
3700 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
3701 Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
3702
3703 return RValue<UShort8>(short8);
3704 }
3705
John Bauman19bac1e2014-05-06 15:23:49 -04003706 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04003707 {
3708 return x86::pmulhuw(x, y); // FIXME: Fallback required
3709 }
3710
3711 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
John Bauman19bac1e2014-05-06 15:23:49 -04003712// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
John Bauman89401822014-05-06 15:04:28 -04003713// {
3714// Constant *pshufb[16];
3715// pshufb[0] = Nucleus::createConstantInt(element + 0);
3716// pshufb[1] = Nucleus::createConstantInt(element + 0);
3717// pshufb[2] = Nucleus::createConstantInt(element + 4);
3718// pshufb[3] = Nucleus::createConstantInt(element + 4);
3719// pshufb[4] = Nucleus::createConstantInt(element + 8);
3720// pshufb[5] = Nucleus::createConstantInt(element + 8);
3721// pshufb[6] = Nucleus::createConstantInt(element + 12);
3722// pshufb[7] = Nucleus::createConstantInt(element + 12);
3723// pshufb[8] = Nucleus::createConstantInt(element + 16);
3724// pshufb[9] = Nucleus::createConstantInt(element + 16);
3725// pshufb[10] = Nucleus::createConstantInt(element + 20);
3726// pshufb[11] = Nucleus::createConstantInt(element + 20);
3727// pshufb[12] = Nucleus::createConstantInt(element + 24);
3728// pshufb[13] = Nucleus::createConstantInt(element + 24);
3729// pshufb[14] = Nucleus::createConstantInt(element + 28);
3730// pshufb[15] = Nucleus::createConstantInt(element + 28);
3731//
3732// Value *shuffle = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(pshufb, 16));
3733// Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3734//
3735// return RValue<UShort8>(short8);
3736// }
3737
John Bauman19bac1e2014-05-06 15:23:49 -04003738 Type *UShort8::getType()
John Bauman89401822014-05-06 15:04:28 -04003739 {
3740 return VectorType::get(UShort::getType(), 8);
3741 }
3742
3743 Int::Int(Argument *argument)
3744 {
John Bauman66b8ab22014-05-06 15:57:45 -04003745 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04003746 }
3747
John Bauman19bac1e2014-05-06 15:23:49 -04003748 Int::Int(RValue<Byte> cast)
John Bauman89401822014-05-06 15:04:28 -04003749 {
John Bauman89401822014-05-06 15:04:28 -04003750 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3751
John Bauman66b8ab22014-05-06 15:57:45 -04003752 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003753 }
3754
John Bauman19bac1e2014-05-06 15:23:49 -04003755 Int::Int(RValue<SByte> cast)
John Bauman89401822014-05-06 15:04:28 -04003756 {
John Bauman89401822014-05-06 15:04:28 -04003757 Value *integer = Nucleus::createSExt(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<Short> 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<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04003770 {
John Bauman89401822014-05-06 15:04:28 -04003771 Value *integer = Nucleus::createZExt(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<Int2> cast)
John Bauman89401822014-05-06 15:04:28 -04003777 {
John Bauman89401822014-05-06 15:04:28 -04003778 *this = Extract(cast, 0);
3779 }
3780
John Bauman19bac1e2014-05-06 15:23:49 -04003781 Int::Int(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04003782 {
John Bauman89401822014-05-06 15:04:28 -04003783 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3784
John Bauman66b8ab22014-05-06 15:57:45 -04003785 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003786 }
3787
John Bauman19bac1e2014-05-06 15:23:49 -04003788 Int::Int(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04003789 {
John Bauman89401822014-05-06 15:04:28 -04003790 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3791
John Bauman66b8ab22014-05-06 15:57:45 -04003792 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003793 }
3794
3795 Int::Int()
3796 {
John Bauman89401822014-05-06 15:04:28 -04003797 }
3798
3799 Int::Int(int x)
3800 {
John Bauman66b8ab22014-05-06 15:57:45 -04003801 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04003802 }
3803
John Bauman19bac1e2014-05-06 15:23:49 -04003804 Int::Int(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003805 {
John Bauman66b8ab22014-05-06 15:57:45 -04003806 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003807 }
3808
John Bauman19bac1e2014-05-06 15:23:49 -04003809 Int::Int(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003810 {
John Bauman66b8ab22014-05-06 15:57:45 -04003811 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003812 }
3813
3814 Int::Int(const Int &rhs)
3815 {
John Bauman66b8ab22014-05-06 15:57:45 -04003816 Value *value = rhs.loadValue();
3817 storeValue(value);
3818 }
John Bauman89401822014-05-06 15:04:28 -04003819
John Bauman66b8ab22014-05-06 15:57:45 -04003820 Int::Int(const Reference<Int> &rhs)
3821 {
3822 Value *value = rhs.loadValue();
3823 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003824 }
3825
3826 Int::Int(const UInt &rhs)
3827 {
John Bauman66b8ab22014-05-06 15:57:45 -04003828 Value *value = rhs.loadValue();
3829 storeValue(value);
3830 }
John Bauman89401822014-05-06 15:04:28 -04003831
John Bauman66b8ab22014-05-06 15:57:45 -04003832 Int::Int(const Reference<UInt> &rhs)
3833 {
3834 Value *value = rhs.loadValue();
3835 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003836 }
3837
3838 RValue<Int> Int::operator=(int rhs) const
3839 {
John Bauman66b8ab22014-05-06 15:57:45 -04003840 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04003841 }
3842
John Bauman19bac1e2014-05-06 15:23:49 -04003843 RValue<Int> Int::operator=(RValue<Int> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003844 {
John Bauman66b8ab22014-05-06 15:57:45 -04003845 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003846
3847 return rhs;
3848 }
3849
John Bauman19bac1e2014-05-06 15:23:49 -04003850 RValue<Int> Int::operator=(RValue<UInt> 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
John Bauman66b8ab22014-05-06 15:57:45 -04003854 return RValue<Int>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003855 }
3856
3857 RValue<Int> Int::operator=(const Int &rhs) const
3858 {
John Bauman66b8ab22014-05-06 15:57:45 -04003859 Value *value = rhs.loadValue();
3860 storeValue(value);
3861
3862 return RValue<Int>(value);
3863 }
3864
3865 RValue<Int> Int::operator=(const Reference<Int> &rhs) const
3866 {
3867 Value *value = rhs.loadValue();
3868 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003869
3870 return RValue<Int>(value);
3871 }
3872
3873 RValue<Int> Int::operator=(const UInt &rhs) const
3874 {
John Bauman66b8ab22014-05-06 15:57:45 -04003875 Value *value = rhs.loadValue();
3876 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003877
3878 return RValue<Int>(value);
3879 }
3880
John Bauman66b8ab22014-05-06 15:57:45 -04003881 RValue<Int> Int::operator=(const Reference<UInt> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04003882 {
John Bauman66b8ab22014-05-06 15:57:45 -04003883 Value *value = rhs.loadValue();
3884 storeValue(value);
3885
3886 return RValue<Int>(value);
John Bauman89401822014-05-06 15:04:28 -04003887 }
3888
John Bauman19bac1e2014-05-06 15:23:49 -04003889 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003890 {
3891 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3892 }
3893
John Bauman19bac1e2014-05-06 15:23:49 -04003894 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003895 {
3896 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3897 }
3898
John Bauman19bac1e2014-05-06 15:23:49 -04003899 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003900 {
3901 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3902 }
3903
John Bauman19bac1e2014-05-06 15:23:49 -04003904 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003905 {
3906 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3907 }
3908
John Bauman19bac1e2014-05-06 15:23:49 -04003909 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003910 {
3911 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3912 }
3913
John Bauman19bac1e2014-05-06 15:23:49 -04003914 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003915 {
3916 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3917 }
3918
John Bauman19bac1e2014-05-06 15:23:49 -04003919 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003920 {
3921 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3922 }
3923
John Bauman19bac1e2014-05-06 15:23:49 -04003924 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003925 {
3926 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
3927 }
3928
John Bauman19bac1e2014-05-06 15:23:49 -04003929 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003930 {
3931 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
3932 }
3933
John Bauman19bac1e2014-05-06 15:23:49 -04003934 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003935 {
3936 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
3937 }
3938
John Bauman19bac1e2014-05-06 15:23:49 -04003939 RValue<Int> operator+=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003940 {
3941 return lhs = lhs + rhs;
3942 }
3943
John Bauman19bac1e2014-05-06 15:23:49 -04003944 RValue<Int> operator-=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003945 {
3946 return lhs = lhs - rhs;
3947 }
3948
John Bauman19bac1e2014-05-06 15:23:49 -04003949 RValue<Int> operator*=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003950 {
3951 return lhs = lhs * rhs;
3952 }
3953
John Bauman19bac1e2014-05-06 15:23:49 -04003954 RValue<Int> operator/=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003955 {
3956 return lhs = lhs / rhs;
3957 }
3958
John Bauman19bac1e2014-05-06 15:23:49 -04003959 RValue<Int> operator%=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003960 {
3961 return lhs = lhs % rhs;
3962 }
3963
John Bauman19bac1e2014-05-06 15:23:49 -04003964 RValue<Int> operator&=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003965 {
3966 return lhs = lhs & rhs;
3967 }
3968
John Bauman19bac1e2014-05-06 15:23:49 -04003969 RValue<Int> operator|=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003970 {
3971 return lhs = lhs | rhs;
3972 }
3973
John Bauman19bac1e2014-05-06 15:23:49 -04003974 RValue<Int> operator^=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003975 {
3976 return lhs = lhs ^ rhs;
3977 }
3978
John Bauman19bac1e2014-05-06 15:23:49 -04003979 RValue<Int> operator<<=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003980 {
3981 return lhs = lhs << rhs;
3982 }
3983
John Bauman19bac1e2014-05-06 15:23:49 -04003984 RValue<Int> operator>>=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003985 {
3986 return lhs = lhs >> rhs;
3987 }
3988
John Bauman19bac1e2014-05-06 15:23:49 -04003989 RValue<Int> operator+(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003990 {
3991 return val;
3992 }
3993
John Bauman19bac1e2014-05-06 15:23:49 -04003994 RValue<Int> operator-(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003995 {
3996 return RValue<Int>(Nucleus::createNeg(val.value));
3997 }
3998
John Bauman19bac1e2014-05-06 15:23:49 -04003999 RValue<Int> operator~(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04004000 {
4001 return RValue<Int>(Nucleus::createNot(val.value));
4002 }
4003
4004 RValue<Int> operator++(const Int &val, int) // Post-increment
4005 {
4006 RValue<Int> res = val;
4007
4008 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004009 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004010
4011 return res;
4012 }
4013
4014 const Int &operator++(const Int &val) // Pre-increment
4015 {
John Bauman66b8ab22014-05-06 15:57:45 -04004016 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
4017 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004018
4019 return val;
4020 }
4021
4022 RValue<Int> operator--(const Int &val, int) // Post-decrement
4023 {
4024 RValue<Int> res = val;
4025
4026 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004027 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004028
4029 return res;
4030 }
4031
4032 const Int &operator--(const Int &val) // Pre-decrement
4033 {
John Bauman66b8ab22014-05-06 15:57:45 -04004034 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
4035 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004036
4037 return val;
4038 }
4039
John Bauman19bac1e2014-05-06 15:23:49 -04004040 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004041 {
4042 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4043 }
4044
John Bauman19bac1e2014-05-06 15:23:49 -04004045 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004046 {
4047 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4048 }
4049
John Bauman19bac1e2014-05-06 15:23:49 -04004050 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004051 {
4052 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4053 }
4054
John Bauman19bac1e2014-05-06 15:23:49 -04004055 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004056 {
4057 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4058 }
4059
John Bauman19bac1e2014-05-06 15:23:49 -04004060 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004061 {
4062 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4063 }
4064
John Bauman19bac1e2014-05-06 15:23:49 -04004065 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004066 {
4067 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4068 }
4069
John Bauman19bac1e2014-05-06 15:23:49 -04004070 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4071 {
4072 return IfThenElse(x > y, x, y);
4073 }
4074
4075 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4076 {
4077 return IfThenElse(x < y, x, y);
4078 }
4079
4080 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4081 {
4082 return Min(Max(x, min), max);
4083 }
4084
4085 RValue<Int> RoundInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004086 {
4087 return x86::cvtss2si(cast);
4088
John Bauman66b8ab22014-05-06 15:57:45 -04004089 // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004090 }
4091
John Bauman19bac1e2014-05-06 15:23:49 -04004092 Type *Int::getType()
John Bauman89401822014-05-06 15:04:28 -04004093 {
4094 return Type::getInt32Ty(*Nucleus::getContext());
4095 }
4096
John Bauman19bac1e2014-05-06 15:23:49 -04004097 Long::Long(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04004098 {
John Bauman66b8ab22014-05-06 15:57:45 -04004099
John Bauman89401822014-05-06 15:04:28 -04004100
4101 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4102
John Bauman66b8ab22014-05-06 15:57:45 -04004103 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004104 }
4105
John Bauman19bac1e2014-05-06 15:23:49 -04004106 Long::Long(RValue<UInt> cast)
John Bauman89401822014-05-06 15:04:28 -04004107 {
John Bauman89401822014-05-06 15:04:28 -04004108 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4109
John Bauman66b8ab22014-05-06 15:57:45 -04004110 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004111 }
4112
4113 Long::Long()
4114 {
John Bauman89401822014-05-06 15:04:28 -04004115 }
4116
John Bauman19bac1e2014-05-06 15:23:49 -04004117 Long::Long(RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004118 {
John Bauman66b8ab22014-05-06 15:57:45 -04004119 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004120 }
4121
4122 RValue<Long> Long::operator=(int64_t rhs) const
4123 {
John Bauman66b8ab22014-05-06 15:57:45 -04004124 return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04004125 }
4126
John Bauman19bac1e2014-05-06 15:23:49 -04004127 RValue<Long> Long::operator=(RValue<Long> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004128 {
John Bauman66b8ab22014-05-06 15:57:45 -04004129 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004130
4131 return rhs;
4132 }
4133
4134 RValue<Long> Long::operator=(const Long &rhs) const
4135 {
John Bauman66b8ab22014-05-06 15:57:45 -04004136 Value *value = rhs.loadValue();
4137 storeValue(value);
4138
4139 return RValue<Long>(value);
4140 }
4141
4142 RValue<Long> Long::operator=(const Reference<Long> &rhs) const
4143 {
4144 Value *value = rhs.loadValue();
4145 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004146
4147 return RValue<Long>(value);
4148 }
4149
John Bauman19bac1e2014-05-06 15:23:49 -04004150 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004151 {
4152 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4153 }
4154
John Bauman19bac1e2014-05-06 15:23:49 -04004155 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004156 {
4157 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4158 }
4159
John Bauman19bac1e2014-05-06 15:23:49 -04004160 RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004161 {
4162 return lhs = lhs + rhs;
4163 }
4164
John Bauman19bac1e2014-05-06 15:23:49 -04004165 RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004166 {
4167 return lhs = lhs - rhs;
4168 }
4169
John Bauman66b8ab22014-05-06 15:57:45 -04004170 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
John Bauman89401822014-05-06 15:04:28 -04004171 {
John Bauman19bac1e2014-05-06 15:23:49 -04004172 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
John Bauman89401822014-05-06 15:04:28 -04004173 }
4174
John Bauman19bac1e2014-05-06 15:23:49 -04004175 Type *Long::getType()
John Bauman89401822014-05-06 15:04:28 -04004176 {
4177 return Type::getInt64Ty(*Nucleus::getContext());
4178 }
4179
4180 Long1::Long1(const Reference<UInt> &cast)
4181 {
John Bauman66b8ab22014-05-06 15:57:45 -04004182 Value *uint = cast.loadValue();
John Bauman89401822014-05-06 15:04:28 -04004183 Value *int64 = Nucleus::createZExt(uint, Long::getType());
4184 Value *long1 = Nucleus::createBitCast(int64, Long1::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04004185
4186 storeValue(long1);
John Bauman89401822014-05-06 15:04:28 -04004187 }
4188
John Bauman19bac1e2014-05-06 15:23:49 -04004189 Long1::Long1(RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004190 {
John Bauman66b8ab22014-05-06 15:57:45 -04004191 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004192 }
4193
John Bauman19bac1e2014-05-06 15:23:49 -04004194 Type *Long1::getType()
John Bauman89401822014-05-06 15:04:28 -04004195 {
John Bauman19bac1e2014-05-06 15:23:49 -04004196 if(CPUID::supportsMMX2())
4197 {
4198 return MMX::getType();
4199 }
4200 else
4201 {
4202 return VectorType::get(Long::getType(), 1);
4203 }
John Bauman89401822014-05-06 15:04:28 -04004204 }
4205
John Bauman19bac1e2014-05-06 15:23:49 -04004206 RValue<Long2> UnpackHigh(RValue<Long2> x, RValue<Long2> y)
John Bauman89401822014-05-06 15:04:28 -04004207 {
4208 Constant *shuffle[2];
4209 shuffle[0] = Nucleus::createConstantInt(1);
4210 shuffle[1] = Nucleus::createConstantInt(3);
4211
4212 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
4213
4214 return RValue<Long2>(packed);
4215 }
4216
John Bauman19bac1e2014-05-06 15:23:49 -04004217 Type *Long2::getType()
John Bauman89401822014-05-06 15:04:28 -04004218 {
4219 return VectorType::get(Long::getType(), 2);
4220 }
4221
4222 UInt::UInt(Argument *argument)
4223 {
John Bauman66b8ab22014-05-06 15:57:45 -04004224 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04004225 }
4226
John Bauman19bac1e2014-05-06 15:23:49 -04004227 UInt::UInt(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04004228 {
John Bauman89401822014-05-06 15:04:28 -04004229 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4230
John Bauman66b8ab22014-05-06 15:57:45 -04004231 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004232 }
4233
John Bauman19bac1e2014-05-06 15:23:49 -04004234 UInt::UInt(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04004235 {
John Bauman89401822014-05-06 15:04:28 -04004236 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4237
John Bauman66b8ab22014-05-06 15:57:45 -04004238 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004239 }
4240
John Bauman19bac1e2014-05-06 15:23:49 -04004241 UInt::UInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004242 {
Alexis Hetu77dfab42015-11-23 13:31:22 -05004243 Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType());
John Bauman89401822014-05-06 15:04:28 -04004244
John Bauman66b8ab22014-05-06 15:57:45 -04004245 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004246 }
4247
4248 UInt::UInt()
4249 {
John Bauman89401822014-05-06 15:04:28 -04004250 }
4251
4252 UInt::UInt(int x)
4253 {
John Bauman66b8ab22014-05-06 15:57:45 -04004254 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04004255 }
4256
4257 UInt::UInt(unsigned int x)
4258 {
John Bauman66b8ab22014-05-06 15:57:45 -04004259 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04004260 }
4261
John Bauman19bac1e2014-05-06 15:23:49 -04004262 UInt::UInt(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004263 {
John Bauman66b8ab22014-05-06 15:57:45 -04004264 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004265 }
4266
John Bauman19bac1e2014-05-06 15:23:49 -04004267 UInt::UInt(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004268 {
John Bauman66b8ab22014-05-06 15:57:45 -04004269 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004270 }
4271
4272 UInt::UInt(const UInt &rhs)
4273 {
John Bauman66b8ab22014-05-06 15:57:45 -04004274 Value *value = rhs.loadValue();
4275 storeValue(value);
4276 }
John Bauman89401822014-05-06 15:04:28 -04004277
John Bauman66b8ab22014-05-06 15:57:45 -04004278 UInt::UInt(const Reference<UInt> &rhs)
4279 {
4280 Value *value = rhs.loadValue();
4281 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004282 }
4283
4284 UInt::UInt(const Int &rhs)
4285 {
John Bauman66b8ab22014-05-06 15:57:45 -04004286 Value *value = rhs.loadValue();
4287 storeValue(value);
4288 }
John Bauman89401822014-05-06 15:04:28 -04004289
John Bauman66b8ab22014-05-06 15:57:45 -04004290 UInt::UInt(const Reference<Int> &rhs)
4291 {
4292 Value *value = rhs.loadValue();
4293 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004294 }
4295
4296 RValue<UInt> UInt::operator=(unsigned int rhs) const
4297 {
John Bauman66b8ab22014-05-06 15:57:45 -04004298 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04004299 }
4300
John Bauman19bac1e2014-05-06 15:23:49 -04004301 RValue<UInt> UInt::operator=(RValue<UInt> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004302 {
John Bauman66b8ab22014-05-06 15:57:45 -04004303 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004304
4305 return rhs;
4306 }
4307
John Bauman19bac1e2014-05-06 15:23:49 -04004308 RValue<UInt> UInt::operator=(RValue<Int> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004309 {
John Bauman66b8ab22014-05-06 15:57:45 -04004310 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004311
John Bauman66b8ab22014-05-06 15:57:45 -04004312 return RValue<UInt>(rhs);
John Bauman89401822014-05-06 15:04:28 -04004313 }
4314
4315 RValue<UInt> UInt::operator=(const UInt &rhs) const
4316 {
John Bauman66b8ab22014-05-06 15:57:45 -04004317 Value *value = rhs.loadValue();
4318 storeValue(value);
4319
4320 return RValue<UInt>(value);
4321 }
4322
4323 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const
4324 {
4325 Value *value = rhs.loadValue();
4326 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004327
4328 return RValue<UInt>(value);
4329 }
4330
4331 RValue<UInt> UInt::operator=(const Int &rhs) const
4332 {
John Bauman66b8ab22014-05-06 15:57:45 -04004333 Value *value = rhs.loadValue();
4334 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004335
4336 return RValue<UInt>(value);
4337 }
4338
John Bauman66b8ab22014-05-06 15:57:45 -04004339 RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04004340 {
John Bauman66b8ab22014-05-06 15:57:45 -04004341 Value *value = rhs.loadValue();
4342 storeValue(value);
4343
4344 return RValue<UInt>(value);
John Bauman89401822014-05-06 15:04:28 -04004345 }
4346
John Bauman19bac1e2014-05-06 15:23:49 -04004347 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004348 {
4349 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4350 }
4351
John Bauman19bac1e2014-05-06 15:23:49 -04004352 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004353 {
4354 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4355 }
4356
John Bauman19bac1e2014-05-06 15:23:49 -04004357 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004358 {
4359 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4360 }
4361
John Bauman19bac1e2014-05-06 15:23:49 -04004362 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004363 {
4364 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4365 }
4366
John Bauman19bac1e2014-05-06 15:23:49 -04004367 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004368 {
4369 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4370 }
4371
John Bauman19bac1e2014-05-06 15:23:49 -04004372 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004373 {
4374 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4375 }
4376
John Bauman19bac1e2014-05-06 15:23:49 -04004377 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004378 {
4379 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4380 }
4381
John Bauman19bac1e2014-05-06 15:23:49 -04004382 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004383 {
4384 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4385 }
4386
John Bauman19bac1e2014-05-06 15:23:49 -04004387 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004388 {
4389 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4390 }
4391
John Bauman19bac1e2014-05-06 15:23:49 -04004392 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004393 {
4394 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4395 }
4396
John Bauman19bac1e2014-05-06 15:23:49 -04004397 RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004398 {
4399 return lhs = lhs + rhs;
4400 }
4401
John Bauman19bac1e2014-05-06 15:23:49 -04004402 RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004403 {
4404 return lhs = lhs - rhs;
4405 }
4406
John Bauman19bac1e2014-05-06 15:23:49 -04004407 RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004408 {
4409 return lhs = lhs * rhs;
4410 }
4411
John Bauman19bac1e2014-05-06 15:23:49 -04004412 RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004413 {
4414 return lhs = lhs / rhs;
4415 }
4416
John Bauman19bac1e2014-05-06 15:23:49 -04004417 RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004418 {
4419 return lhs = lhs % rhs;
4420 }
4421
John Bauman19bac1e2014-05-06 15:23:49 -04004422 RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004423 {
4424 return lhs = lhs & rhs;
4425 }
4426
John Bauman19bac1e2014-05-06 15:23:49 -04004427 RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004428 {
4429 return lhs = lhs | rhs;
4430 }
4431
John Bauman19bac1e2014-05-06 15:23:49 -04004432 RValue<UInt> operator^=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004433 {
4434 return lhs = lhs ^ rhs;
4435 }
4436
John Bauman19bac1e2014-05-06 15:23:49 -04004437 RValue<UInt> operator<<=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004438 {
4439 return lhs = lhs << rhs;
4440 }
4441
John Bauman19bac1e2014-05-06 15:23:49 -04004442 RValue<UInt> operator>>=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004443 {
4444 return lhs = lhs >> rhs;
4445 }
4446
John Bauman19bac1e2014-05-06 15:23:49 -04004447 RValue<UInt> operator+(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004448 {
4449 return val;
4450 }
4451
John Bauman19bac1e2014-05-06 15:23:49 -04004452 RValue<UInt> operator-(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004453 {
4454 return RValue<UInt>(Nucleus::createNeg(val.value));
4455 }
4456
John Bauman19bac1e2014-05-06 15:23:49 -04004457 RValue<UInt> operator~(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004458 {
4459 return RValue<UInt>(Nucleus::createNot(val.value));
4460 }
4461
4462 RValue<UInt> operator++(const UInt &val, int) // Post-increment
4463 {
4464 RValue<UInt> res = val;
4465
4466 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004467 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004468
4469 return res;
4470 }
4471
4472 const UInt &operator++(const UInt &val) // Pre-increment
4473 {
John Bauman66b8ab22014-05-06 15:57:45 -04004474 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
4475 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004476
4477 return val;
4478 }
4479
4480 RValue<UInt> operator--(const UInt &val, int) // Post-decrement
4481 {
4482 RValue<UInt> res = val;
4483
4484 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004485 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004486
4487 return res;
4488 }
4489
4490 const UInt &operator--(const UInt &val) // Pre-decrement
4491 {
John Bauman66b8ab22014-05-06 15:57:45 -04004492 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
4493 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004494
4495 return val;
4496 }
4497
John Bauman19bac1e2014-05-06 15:23:49 -04004498 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4499 {
4500 return IfThenElse(x > y, x, y);
4501 }
4502
4503 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4504 {
4505 return IfThenElse(x < y, x, y);
4506 }
4507
4508 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4509 {
4510 return Min(Max(x, min), max);
4511 }
4512
4513 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004514 {
4515 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4516 }
4517
John Bauman19bac1e2014-05-06 15:23:49 -04004518 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004519 {
4520 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4521 }
4522
John Bauman19bac1e2014-05-06 15:23:49 -04004523 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004524 {
4525 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4526 }
4527
John Bauman19bac1e2014-05-06 15:23:49 -04004528 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004529 {
4530 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4531 }
4532
John Bauman19bac1e2014-05-06 15:23:49 -04004533 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004534 {
4535 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4536 }
4537
John Bauman19bac1e2014-05-06 15:23:49 -04004538 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004539 {
4540 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4541 }
4542
John Bauman19bac1e2014-05-06 15:23:49 -04004543// RValue<UInt> RoundUInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004544// {
4545// return x86::cvtss2si(val); // FIXME: Unsigned
4546//
John Bauman66b8ab22014-05-06 15:57:45 -04004547// // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004548// }
4549
John Bauman19bac1e2014-05-06 15:23:49 -04004550 Type *UInt::getType()
John Bauman89401822014-05-06 15:04:28 -04004551 {
4552 return Type::getInt32Ty(*Nucleus::getContext());
4553 }
4554
John Bauman19bac1e2014-05-06 15:23:49 -04004555// Int2::Int2(RValue<Int> cast)
4556// {
John Bauman19bac1e2014-05-06 15:23:49 -04004557// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4558// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04004559//
John Bauman19bac1e2014-05-06 15:23:49 -04004560// Constant *shuffle[2];
4561// shuffle[0] = Nucleus::createConstantInt(0);
4562// shuffle[1] = Nucleus::createConstantInt(0);
4563//
4564// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4565//
John Bauman66b8ab22014-05-06 15:57:45 -04004566// storeValue(replicate);
John Bauman19bac1e2014-05-06 15:23:49 -04004567// }
John Bauman89401822014-05-06 15:04:28 -04004568
John Bauman19bac1e2014-05-06 15:23:49 -04004569 Int2::Int2(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04004570 {
John Bauman89401822014-05-06 15:04:28 -04004571 Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType());
4572 Value *element = Nucleus::createExtractElement(long2, 0);
4573 Value *int2 = Nucleus::createBitCast(element, Int2::getType());
4574
John Bauman66b8ab22014-05-06 15:57:45 -04004575 storeValue(int2);
John Bauman89401822014-05-06 15:04:28 -04004576 }
4577
4578 Int2::Int2()
4579 {
4580 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004581 }
4582
4583 Int2::Int2(int x, int y)
4584 {
4585 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004586
4587 Constant *constantVector[2];
4588 constantVector[0] = Nucleus::createConstantInt(x);
4589 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004590 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004591
John Bauman66b8ab22014-05-06 15:57:45 -04004592 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004593 }
4594
John Bauman19bac1e2014-05-06 15:23:49 -04004595 Int2::Int2(RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004596 {
4597 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004598
John Bauman66b8ab22014-05-06 15:57:45 -04004599 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004600 }
4601
4602 Int2::Int2(const Int2 &rhs)
4603 {
4604 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004605
John Bauman66b8ab22014-05-06 15:57:45 -04004606 Value *value = rhs.loadValue();
4607 storeValue(value);
4608 }
4609
4610 Int2::Int2(const Reference<Int2> &rhs)
4611 {
4612 // xy.parent = this;
4613
4614 Value *value = rhs.loadValue();
4615 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004616 }
4617
John Bauman19bac1e2014-05-06 15:23:49 -04004618 RValue<Int2> Int2::operator=(RValue<Int2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004619 {
John Bauman66b8ab22014-05-06 15:57:45 -04004620 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004621
4622 return rhs;
4623 }
4624
4625 RValue<Int2> Int2::operator=(const Int2 &rhs) const
4626 {
John Bauman66b8ab22014-05-06 15:57:45 -04004627 Value *value = rhs.loadValue();
4628 storeValue(value);
4629
4630 return RValue<Int2>(value);
4631 }
4632
4633 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const
4634 {
4635 Value *value = rhs.loadValue();
4636 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004637
4638 return RValue<Int2>(value);
4639 }
4640
John Bauman19bac1e2014-05-06 15:23:49 -04004641 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004642 {
John Bauman19bac1e2014-05-06 15:23:49 -04004643 if(CPUID::supportsMMX2())
4644 {
4645 return x86::paddd(lhs, rhs);
4646 }
4647 else
4648 {
4649 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
4650 }
John Bauman89401822014-05-06 15:04:28 -04004651 }
4652
John Bauman19bac1e2014-05-06 15:23:49 -04004653 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004654 {
John Bauman19bac1e2014-05-06 15:23:49 -04004655 if(CPUID::supportsMMX2())
4656 {
4657 return x86::psubd(lhs, rhs);
4658 }
4659 else
4660 {
4661 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
4662 }
John Bauman89401822014-05-06 15:04:28 -04004663 }
4664
John Bauman19bac1e2014-05-06 15:23:49 -04004665// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4666// {
4667// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4668// }
4669
4670// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4671// {
4672// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4673// }
4674
4675// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4676// {
4677// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4678// }
4679
4680 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 As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
4685 }
4686 else
4687 {
4688 return RValue<Int2>(Nucleus::createAnd(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)
John Bauman89401822014-05-06 15:04:28 -04004693 {
John Bauman19bac1e2014-05-06 15:23:49 -04004694 if(CPUID::supportsMMX2())
4695 {
4696 return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
4697 }
4698 else
4699 {
4700 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
4701 }
John Bauman89401822014-05-06 15:04:28 -04004702 }
4703
John Bauman19bac1e2014-05-06 15:23:49 -04004704 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004705 {
John Bauman19bac1e2014-05-06 15:23:49 -04004706 if(CPUID::supportsMMX2())
4707 {
4708 return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
4709 }
4710 else
4711 {
4712 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
4713 }
John Bauman89401822014-05-06 15:04:28 -04004714 }
4715
John Bauman19bac1e2014-05-06 15:23:49 -04004716 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004717 {
4718 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4719
4720 return x86::pslld(lhs, rhs);
4721 }
4722
John Bauman19bac1e2014-05-06 15:23:49 -04004723 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004724 {
4725 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4726
4727 return x86::psrad(lhs, rhs);
4728 }
4729
John Bauman19bac1e2014-05-06 15:23:49 -04004730 RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004731 {
4732 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4733
4734 return x86::pslld(lhs, rhs);
4735 }
4736
John Bauman19bac1e2014-05-06 15:23:49 -04004737 RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004738 {
4739 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4740
4741 return x86::psrad(lhs, rhs);
4742 }
4743
John Bauman19bac1e2014-05-06 15:23:49 -04004744 RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004745 {
4746 return lhs = lhs + rhs;
4747 }
4748
John Bauman19bac1e2014-05-06 15:23:49 -04004749 RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004750 {
4751 return lhs = lhs - rhs;
4752 }
4753
John Bauman19bac1e2014-05-06 15:23:49 -04004754// RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs)
4755// {
4756// return lhs = lhs * rhs;
4757// }
John Bauman89401822014-05-06 15:04:28 -04004758
John Bauman19bac1e2014-05-06 15:23:49 -04004759// RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs)
4760// {
4761// return lhs = lhs / rhs;
4762// }
John Bauman89401822014-05-06 15:04:28 -04004763
John Bauman19bac1e2014-05-06 15:23:49 -04004764// RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs)
4765// {
4766// return lhs = lhs % rhs;
4767// }
John Bauman89401822014-05-06 15:04:28 -04004768
John Bauman19bac1e2014-05-06 15:23:49 -04004769 RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004770 {
4771 return lhs = lhs & rhs;
4772 }
4773
John Bauman19bac1e2014-05-06 15:23:49 -04004774 RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004775 {
4776 return lhs = lhs | rhs;
4777 }
4778
John Bauman19bac1e2014-05-06 15:23:49 -04004779 RValue<Int2> operator^=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004780 {
4781 return lhs = lhs ^ rhs;
4782 }
4783
4784 RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs)
4785 {
4786 return lhs = lhs << rhs;
4787 }
4788
4789 RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs)
4790 {
4791 return lhs = lhs >> rhs;
4792 }
4793
John Bauman19bac1e2014-05-06 15:23:49 -04004794 RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004795 {
4796 return lhs = lhs << rhs;
4797 }
4798
John Bauman19bac1e2014-05-06 15:23:49 -04004799 RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004800 {
4801 return lhs = lhs >> rhs;
4802 }
4803
John Bauman19bac1e2014-05-06 15:23:49 -04004804// RValue<Int2> operator+(RValue<Int2> val)
4805// {
4806// return val;
4807// }
4808
4809// RValue<Int2> operator-(RValue<Int2> val)
4810// {
4811// return RValue<Int2>(Nucleus::createNeg(val.value));
4812// }
4813
4814 RValue<Int2> operator~(RValue<Int2> val)
John Bauman89401822014-05-06 15:04:28 -04004815 {
John Bauman19bac1e2014-05-06 15:23:49 -04004816 if(CPUID::supportsMMX2())
4817 {
4818 return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF);
4819 }
4820 else
4821 {
4822 return RValue<Int2>(Nucleus::createNot(val.value));
4823 }
John Bauman89401822014-05-06 15:04:28 -04004824 }
4825
John Bauman19bac1e2014-05-06 15:23:49 -04004826 RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004827 {
John Bauman19bac1e2014-05-06 15:23:49 -04004828 if(CPUID::supportsMMX2())
4829 {
4830 return x86::punpckldq(x, y);
4831 }
4832 else
4833 {
4834 Constant *shuffle[2];
4835 shuffle[0] = Nucleus::createConstantInt(0);
4836 shuffle[1] = Nucleus::createConstantInt(2);
John Bauman89401822014-05-06 15:04:28 -04004837
John Bauman19bac1e2014-05-06 15:23:49 -04004838 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
John Bauman89401822014-05-06 15:04:28 -04004839
John Bauman19bac1e2014-05-06 15:23:49 -04004840 return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
4841 }
John Bauman89401822014-05-06 15:04:28 -04004842 }
John Bauman66b8ab22014-05-06 15:57:45 -04004843
John Bauman19bac1e2014-05-06 15:23:49 -04004844 RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004845 {
John Bauman19bac1e2014-05-06 15:23:49 -04004846 if(CPUID::supportsMMX2())
4847 {
4848 return x86::punpckhdq(x, y);
4849 }
4850 else
4851 {
4852 Constant *shuffle[2];
4853 shuffle[0] = Nucleus::createConstantInt(1);
4854 shuffle[1] = Nucleus::createConstantInt(3);
John Bauman89401822014-05-06 15:04:28 -04004855
John Bauman19bac1e2014-05-06 15:23:49 -04004856 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
John Bauman89401822014-05-06 15:04:28 -04004857
John Bauman19bac1e2014-05-06 15:23:49 -04004858 return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
4859 }
John Bauman89401822014-05-06 15:04:28 -04004860 }
4861
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004862 RValue<Int2> Concatenate(RValue<Int> lo, RValue<Int> hi)
4863 {
4864 Constant *shuffle[2];
4865 shuffle[0] = Nucleus::createConstantInt(0);
4866 shuffle[1] = Nucleus::createConstantInt(1);
4867
4868 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));
4869
4870 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
4871 }
4872
John Bauman19bac1e2014-05-06 15:23:49 -04004873 RValue<Int> Extract(RValue<Int2> val, int i)
John Bauman89401822014-05-06 15:04:28 -04004874 {
4875 if(false) // FIXME: LLVM does not generate optimal code
4876 {
4877 return RValue<Int>(Nucleus::createExtractElement(val.value, i));
4878 }
4879 else
4880 {
4881 if(i == 0)
4882 {
John Bauman19bac1e2014-05-06 15:23:49 -04004883 return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), 0));
John Bauman89401822014-05-06 15:04:28 -04004884 }
4885 else
4886 {
4887 Int2 val2 = As<Int2>(UnpackHigh(val, val));
4888
4889 return Extract(val2, 0);
4890 }
4891 }
4892 }
4893
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004894 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4895 {
4896 return RValue<Int2>(Nucleus::createBitCast(Nucleus::createInsertElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), element.value, i), Int2::getType()));
4897 }
John Bauman89401822014-05-06 15:04:28 -04004898
John Bauman19bac1e2014-05-06 15:23:49 -04004899 Type *Int2::getType()
John Bauman89401822014-05-06 15:04:28 -04004900 {
John Bauman19bac1e2014-05-06 15:23:49 -04004901 if(CPUID::supportsMMX2())
4902 {
4903 return MMX::getType();
4904 }
4905 else
4906 {
4907 return VectorType::get(Int::getType(), 2);
4908 }
John Bauman89401822014-05-06 15:04:28 -04004909 }
4910
4911 UInt2::UInt2()
4912 {
4913 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004914 }
4915
4916 UInt2::UInt2(unsigned int x, unsigned int y)
4917 {
4918 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004919
4920 Constant *constantVector[2];
4921 constantVector[0] = Nucleus::createConstantInt(x);
4922 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004923 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004924
John Bauman66b8ab22014-05-06 15:57:45 -04004925 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004926 }
4927
John Bauman19bac1e2014-05-06 15:23:49 -04004928 UInt2::UInt2(RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004929 {
4930 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004931
John Bauman66b8ab22014-05-06 15:57:45 -04004932 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004933 }
4934
4935 UInt2::UInt2(const UInt2 &rhs)
4936 {
4937 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004938
John Bauman66b8ab22014-05-06 15:57:45 -04004939 Value *value = rhs.loadValue();
4940 storeValue(value);
4941 }
4942
4943 UInt2::UInt2(const Reference<UInt2> &rhs)
4944 {
4945 // xy.parent = this;
4946
4947 Value *value = rhs.loadValue();
4948 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004949 }
4950
John Bauman19bac1e2014-05-06 15:23:49 -04004951 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004952 {
John Bauman66b8ab22014-05-06 15:57:45 -04004953 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004954
4955 return rhs;
4956 }
4957
4958 RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
4959 {
John Bauman66b8ab22014-05-06 15:57:45 -04004960 Value *value = rhs.loadValue();
4961 storeValue(value);
4962
4963 return RValue<UInt2>(value);
4964 }
4965
4966 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const
4967 {
4968 Value *value = rhs.loadValue();
4969 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004970
4971 return RValue<UInt2>(value);
4972 }
4973
John Bauman19bac1e2014-05-06 15:23:49 -04004974 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004975 {
John Bauman19bac1e2014-05-06 15:23:49 -04004976 if(CPUID::supportsMMX2())
4977 {
4978 return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs)));
4979 }
4980 else
4981 {
4982 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
4983 }
John Bauman89401822014-05-06 15:04:28 -04004984 }
4985
John Bauman19bac1e2014-05-06 15:23:49 -04004986 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004987 {
John Bauman19bac1e2014-05-06 15:23:49 -04004988 if(CPUID::supportsMMX2())
4989 {
4990 return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs)));
4991 }
4992 else
4993 {
4994 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
4995 }
John Bauman89401822014-05-06 15:04:28 -04004996 }
4997
John Bauman19bac1e2014-05-06 15:23:49 -04004998// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4999// {
5000// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
5001// }
5002
5003// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
5004// {
5005// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
5006// }
5007
5008// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
5009// {
5010// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
5011// }
5012
5013 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005014 {
John Bauman19bac1e2014-05-06 15:23:49 -04005015 if(CPUID::supportsMMX2())
5016 {
5017 return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
5018 }
5019 else
5020 {
5021 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
5022 }
John Bauman89401822014-05-06 15:04:28 -04005023 }
5024
John Bauman19bac1e2014-05-06 15:23:49 -04005025 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005026 {
John Bauman19bac1e2014-05-06 15:23:49 -04005027 if(CPUID::supportsMMX2())
5028 {
5029 return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
5030 }
5031 else
5032 {
5033 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
5034 }
John Bauman89401822014-05-06 15:04:28 -04005035 }
5036
John Bauman19bac1e2014-05-06 15:23:49 -04005037 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005038 {
John Bauman19bac1e2014-05-06 15:23:49 -04005039 if(CPUID::supportsMMX2())
5040 {
5041 return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
5042 }
5043 else
5044 {
5045 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
5046 }
John Bauman89401822014-05-06 15:04:28 -04005047 }
5048
John Bauman19bac1e2014-05-06 15:23:49 -04005049 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005050 {
5051 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5052
5053 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5054 }
5055
John Bauman19bac1e2014-05-06 15:23:49 -04005056 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005057 {
5058 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5059
5060 return x86::psrld(lhs, rhs);
5061 }
5062
John Bauman19bac1e2014-05-06 15:23:49 -04005063 RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005064 {
5065 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5066
5067 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5068 }
5069
John Bauman19bac1e2014-05-06 15:23:49 -04005070 RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005071 {
5072 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5073
5074 return x86::psrld(lhs, rhs);
5075 }
5076
John Bauman19bac1e2014-05-06 15:23:49 -04005077 RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005078 {
5079 return lhs = lhs + rhs;
5080 }
5081
John Bauman19bac1e2014-05-06 15:23:49 -04005082 RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005083 {
5084 return lhs = lhs - rhs;
5085 }
5086
John Bauman19bac1e2014-05-06 15:23:49 -04005087// RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs)
5088// {
5089// return lhs = lhs * rhs;
5090// }
John Bauman89401822014-05-06 15:04:28 -04005091
John Bauman19bac1e2014-05-06 15:23:49 -04005092// RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs)
5093// {
5094// return lhs = lhs / rhs;
5095// }
John Bauman89401822014-05-06 15:04:28 -04005096
John Bauman19bac1e2014-05-06 15:23:49 -04005097// RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs)
5098// {
5099// return lhs = lhs % rhs;
5100// }
John Bauman89401822014-05-06 15:04:28 -04005101
John Bauman19bac1e2014-05-06 15:23:49 -04005102 RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005103 {
5104 return lhs = lhs & rhs;
5105 }
5106
John Bauman19bac1e2014-05-06 15:23:49 -04005107 RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005108 {
5109 return lhs = lhs | rhs;
5110 }
5111
John Bauman19bac1e2014-05-06 15:23:49 -04005112 RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005113 {
5114 return lhs = lhs ^ rhs;
5115 }
5116
5117 RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
5118 {
5119 return lhs = lhs << rhs;
5120 }
5121
5122 RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
5123 {
5124 return lhs = lhs >> rhs;
5125 }
5126
John Bauman19bac1e2014-05-06 15:23:49 -04005127 RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005128 {
5129 return lhs = lhs << rhs;
5130 }
5131
John Bauman19bac1e2014-05-06 15:23:49 -04005132 RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005133 {
5134 return lhs = lhs >> rhs;
5135 }
5136
John Bauman19bac1e2014-05-06 15:23:49 -04005137// RValue<UInt2> operator+(RValue<UInt2> val)
5138// {
5139// return val;
5140// }
5141
5142// RValue<UInt2> operator-(RValue<UInt2> val)
5143// {
5144// return RValue<UInt2>(Nucleus::createNeg(val.value));
5145// }
5146
5147 RValue<UInt2> operator~(RValue<UInt2> val)
John Bauman89401822014-05-06 15:04:28 -04005148 {
John Bauman19bac1e2014-05-06 15:23:49 -04005149 if(CPUID::supportsMMX2())
5150 {
5151 return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF);
5152 }
5153 else
5154 {
5155 return RValue<UInt2>(Nucleus::createNot(val.value));
5156 }
John Bauman89401822014-05-06 15:04:28 -04005157 }
5158
John Bauman19bac1e2014-05-06 15:23:49 -04005159 Type *UInt2::getType()
John Bauman89401822014-05-06 15:04:28 -04005160 {
John Bauman19bac1e2014-05-06 15:23:49 -04005161 if(CPUID::supportsMMX2())
5162 {
5163 return MMX::getType();
5164 }
5165 else
5166 {
5167 return VectorType::get(UInt::getType(), 2);
5168 }
John Bauman89401822014-05-06 15:04:28 -04005169 }
5170
John Bauman19bac1e2014-05-06 15:23:49 -04005171 Int4::Int4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005172 {
5173 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005174
5175 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
John Bauman89401822014-05-06 15:04:28 -04005176
John Bauman66b8ab22014-05-06 15:57:45 -04005177 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005178 }
5179
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005180 Int4::Int4(RValue<Short4> cast)
5181 {
5182 Value *long2 = UndefValue::get(Long2::getType());
5183 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
5184 long2 = Nucleus::createInsertElement(long2, element, 0);
5185 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
5186
5187 if(CPUID::supportsSSE4_1())
5188 {
5189 storeValue(x86::pmovsxwd(vector).value);
5190 }
5191 else
5192 {
5193 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
5194
5195 Constant *swizzle[8];
5196 swizzle[0] = Nucleus::createConstantInt(0);
5197 swizzle[1] = Nucleus::createConstantInt(0);
5198 swizzle[2] = Nucleus::createConstantInt(1);
5199 swizzle[3] = Nucleus::createConstantInt(1);
5200 swizzle[4] = Nucleus::createConstantInt(2);
5201 swizzle[5] = Nucleus::createConstantInt(2);
5202 swizzle[6] = Nucleus::createConstantInt(3);
5203 swizzle[7] = Nucleus::createConstantInt(3);
5204
Nicolas Capens6ce5c332015-10-28 01:58:18 -04005205 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8));
5206 Value *d = Nucleus::createBitCast(c, Int4::getType());
5207 storeValue(d);
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005208
5209 // Each Short is packed into each Int in the (Short | Short) format.
5210 // Shifting by 16 will retrieve the original Short value.
5211 // Shitfing an Int will propagate the sign bit, which will work
5212 // for both positive and negative values of a Short.
5213 *this >>= 16;
5214 }
5215 }
5216
5217 Int4::Int4(RValue<UShort4> cast)
5218 {
5219 Value *long2 = UndefValue::get(Long2::getType());
5220 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
5221 long2 = Nucleus::createInsertElement(long2, element, 0);
5222 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
5223
5224 if(CPUID::supportsSSE4_1())
5225 {
5226 storeValue(x86::pmovzxwd(RValue<Int4>(vector)).value);
5227 }
5228 else
5229 {
5230 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
5231
5232 Constant *swizzle[8];
5233 swizzle[0] = Nucleus::createConstantInt(0);
5234 swizzle[1] = Nucleus::createConstantInt(8);
5235 swizzle[2] = Nucleus::createConstantInt(1);
5236 swizzle[3] = Nucleus::createConstantInt(9);
5237 swizzle[4] = Nucleus::createConstantInt(2);
5238 swizzle[5] = Nucleus::createConstantInt(10);
5239 swizzle[6] = Nucleus::createConstantInt(3);
5240 swizzle[7] = Nucleus::createConstantInt(11);
5241
Nicolas Capens6ce5c332015-10-28 01:58:18 -04005242 Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8));
5243 Value *d = Nucleus::createBitCast(c, Int4::getType());
5244 storeValue(d);
Alexis Hetu2aa852f2015-10-14 16:32:39 -04005245 }
5246 }
5247
John Bauman89401822014-05-06 15:04:28 -04005248 Int4::Int4()
5249 {
5250 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005251 }
5252
5253 Int4::Int4(int xyzw)
5254 {
5255 constant(xyzw, xyzw, xyzw, xyzw);
5256 }
5257
5258 Int4::Int4(int x, int yzw)
5259 {
5260 constant(x, yzw, yzw, yzw);
5261 }
5262
5263 Int4::Int4(int x, int y, int zw)
5264 {
5265 constant(x, y, zw, zw);
5266 }
5267
5268 Int4::Int4(int x, int y, int z, int w)
5269 {
5270 constant(x, y, z, w);
5271 }
5272
5273 void Int4::constant(int x, int y, int z, int w)
5274 {
5275 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005276
5277 Constant *constantVector[4];
5278 constantVector[0] = Nucleus::createConstantInt(x);
5279 constantVector[1] = Nucleus::createConstantInt(y);
5280 constantVector[2] = Nucleus::createConstantInt(z);
5281 constantVector[3] = Nucleus::createConstantInt(w);
5282
John Bauman66b8ab22014-05-06 15:57:45 -04005283 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005284 }
5285
John Bauman19bac1e2014-05-06 15:23:49 -04005286 Int4::Int4(RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005287 {
5288 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005289
John Bauman66b8ab22014-05-06 15:57:45 -04005290 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005291 }
5292
5293 Int4::Int4(const Int4 &rhs)
5294 {
5295 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005296
John Bauman66b8ab22014-05-06 15:57:45 -04005297 Value *value = rhs.loadValue();
5298 storeValue(value);
5299 }
5300
5301 Int4::Int4(const Reference<Int4> &rhs)
5302 {
5303 // xyzw.parent = this;
5304
5305 Value *value = rhs.loadValue();
5306 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005307 }
5308
John Bauman19bac1e2014-05-06 15:23:49 -04005309 Int4::Int4(RValue<UInt4> rhs)
5310 {
5311 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005312
John Bauman66b8ab22014-05-06 15:57:45 -04005313 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005314 }
5315
5316 Int4::Int4(const UInt4 &rhs)
5317 {
5318 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005319
John Bauman66b8ab22014-05-06 15:57:45 -04005320 Value *value = rhs.loadValue();
5321 storeValue(value);
5322 }
5323
5324 Int4::Int4(const Reference<UInt4> &rhs)
5325 {
5326 // xyzw.parent = this;
5327
5328 Value *value = rhs.loadValue();
5329 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005330 }
5331
5332 RValue<Int4> Int4::operator=(RValue<Int4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005333 {
John Bauman66b8ab22014-05-06 15:57:45 -04005334 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005335
5336 return rhs;
5337 }
5338
5339 RValue<Int4> Int4::operator=(const Int4 &rhs) const
5340 {
John Bauman66b8ab22014-05-06 15:57:45 -04005341 Value *value = rhs.loadValue();
5342 storeValue(value);
5343
5344 return RValue<Int4>(value);
5345 }
5346
5347 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const
5348 {
5349 Value *value = rhs.loadValue();
5350 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005351
5352 return RValue<Int4>(value);
5353 }
5354
John Bauman19bac1e2014-05-06 15:23:49 -04005355 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005356 {
5357 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5358 }
5359
John Bauman19bac1e2014-05-06 15:23:49 -04005360 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005361 {
5362 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5363 }
5364
John Bauman19bac1e2014-05-06 15:23:49 -04005365 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005366 {
5367 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5368 }
5369
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005370 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5371 {
5372 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5373 }
John Bauman89401822014-05-06 15:04:28 -04005374
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005375 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5376 {
5377 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5378 }
John Bauman89401822014-05-06 15:04:28 -04005379
John Bauman19bac1e2014-05-06 15:23:49 -04005380 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005381 {
5382 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5383 }
5384
John Bauman19bac1e2014-05-06 15:23:49 -04005385 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005386 {
5387 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5388 }
5389
John Bauman19bac1e2014-05-06 15:23:49 -04005390 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005391 {
5392 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5393 }
5394
John Bauman19bac1e2014-05-06 15:23:49 -04005395 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005396 {
John Bauman89401822014-05-06 15:04:28 -04005397 return x86::pslld(lhs, rhs);
5398 }
5399
John Bauman19bac1e2014-05-06 15:23:49 -04005400 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005401 {
John Bauman89401822014-05-06 15:04:28 -04005402 return x86::psrad(lhs, rhs);
5403 }
5404
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005405 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5406 {
5407 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5408 }
5409
5410 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5411 {
5412 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5413 }
5414
John Bauman19bac1e2014-05-06 15:23:49 -04005415 RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005416 {
5417 return lhs = lhs + rhs;
5418 }
5419
John Bauman19bac1e2014-05-06 15:23:49 -04005420 RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005421 {
5422 return lhs = lhs - rhs;
5423 }
5424
John Bauman19bac1e2014-05-06 15:23:49 -04005425 RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005426 {
5427 return lhs = lhs * rhs;
5428 }
5429
John Bauman19bac1e2014-05-06 15:23:49 -04005430// RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs)
5431// {
5432// return lhs = lhs / rhs;
5433// }
John Bauman89401822014-05-06 15:04:28 -04005434
John Bauman19bac1e2014-05-06 15:23:49 -04005435// RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs)
5436// {
5437// return lhs = lhs % rhs;
5438// }
John Bauman89401822014-05-06 15:04:28 -04005439
John Bauman19bac1e2014-05-06 15:23:49 -04005440 RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005441 {
5442 return lhs = lhs & rhs;
5443 }
5444
John Bauman19bac1e2014-05-06 15:23:49 -04005445 RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005446 {
5447 return lhs = lhs | rhs;
5448 }
5449
John Bauman19bac1e2014-05-06 15:23:49 -04005450 RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005451 {
5452 return lhs = lhs ^ rhs;
5453 }
5454
5455 RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
5456 {
5457 return lhs = lhs << rhs;
5458 }
5459
5460 RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
5461 {
5462 return lhs = lhs >> rhs;
5463 }
5464
John Bauman19bac1e2014-05-06 15:23:49 -04005465 RValue<Int4> operator+(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005466 {
5467 return val;
5468 }
5469
John Bauman19bac1e2014-05-06 15:23:49 -04005470 RValue<Int4> operator-(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005471 {
5472 return RValue<Int4>(Nucleus::createNeg(val.value));
5473 }
5474
John Bauman19bac1e2014-05-06 15:23:49 -04005475 RValue<Int4> operator~(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005476 {
5477 return RValue<Int4>(Nucleus::createNot(val.value));
5478 }
5479
John Bauman19bac1e2014-05-06 15:23:49 -04005480 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5481 {
5482 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5483 }
5484
5485 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5486 {
5487 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
5488 }
5489
5490 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5491 {
5492 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
5493 }
5494
5495 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5496 {
5497 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5498 }
5499
5500 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5501 {
5502 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
5503 }
5504
5505 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5506 {
5507 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
5508 }
5509
5510 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5511 {
5512 if(CPUID::supportsSSE4_1())
5513 {
5514 return x86::pmaxsd(x, y);
5515 }
5516 else
5517 {
5518 RValue<Int4> greater = CmpNLE(x, y);
5519 return x & greater | y & ~greater;
5520 }
5521 }
5522
5523 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5524 {
5525 if(CPUID::supportsSSE4_1())
5526 {
5527 return x86::pminsd(x, y);
5528 }
5529 else
5530 {
5531 RValue<Int4> less = CmpLT(x, y);
5532 return x & less | y & ~less;
5533 }
5534 }
5535
5536 RValue<Int4> RoundInt(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005537 {
5538 return x86::cvtps2dq(cast);
5539 }
5540
John Bauman19bac1e2014-05-06 15:23:49 -04005541 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04005542 {
5543 return x86::packssdw(x, y);
5544 }
5545
John Bauman19bac1e2014-05-06 15:23:49 -04005546 RValue<Int4> Concatenate(RValue<Int2> lo, RValue<Int2> hi)
John Bauman89401822014-05-06 15:04:28 -04005547 {
5548 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5549 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5550
5551 Value *long2 = UndefValue::get(Long2::getType());
5552 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5553 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5554 Value *int4 = Nucleus::createBitCast(long2, Int4::getType());
5555
5556 return RValue<Int4>(int4);
5557 }
5558
John Bauman19bac1e2014-05-06 15:23:49 -04005559 RValue<Int> Extract(RValue<Int4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04005560 {
5561 return RValue<Int>(Nucleus::createExtractElement(x.value, i));
5562 }
5563
John Bauman19bac1e2014-05-06 15:23:49 -04005564 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
John Bauman89401822014-05-06 15:04:28 -04005565 {
5566 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5567 }
5568
John Bauman19bac1e2014-05-06 15:23:49 -04005569 RValue<Int> SignMask(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04005570 {
5571 return x86::movmskps(As<Float4>(x));
5572 }
5573
John Bauman19bac1e2014-05-06 15:23:49 -04005574 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04005575 {
5576 return RValue<Int4>(Nucleus::createSwizzle(x.value, select));
5577 }
5578
John Bauman19bac1e2014-05-06 15:23:49 -04005579 Type *Int4::getType()
John Bauman89401822014-05-06 15:04:28 -04005580 {
5581 return VectorType::get(Int::getType(), 4);
5582 }
5583
John Bauman19bac1e2014-05-06 15:23:49 -04005584 UInt4::UInt4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005585 {
5586 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005587
5588 Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
5589
John Bauman66b8ab22014-05-06 15:57:45 -04005590 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005591 }
5592
5593 UInt4::UInt4()
5594 {
5595 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005596 }
5597
John Bauman19bac1e2014-05-06 15:23:49 -04005598 UInt4::UInt4(int xyzw)
5599 {
5600 constant(xyzw, xyzw, xyzw, xyzw);
5601 }
5602
5603 UInt4::UInt4(int x, int yzw)
5604 {
5605 constant(x, yzw, yzw, yzw);
5606 }
5607
5608 UInt4::UInt4(int x, int y, int zw)
5609 {
5610 constant(x, y, zw, zw);
5611 }
5612
5613 UInt4::UInt4(int x, int y, int z, int w)
5614 {
5615 constant(x, y, z, w);
5616 }
5617
5618 void UInt4::constant(int x, int y, int z, int w)
John Bauman89401822014-05-06 15:04:28 -04005619 {
5620 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005621
5622 Constant *constantVector[4];
5623 constantVector[0] = Nucleus::createConstantInt(x);
5624 constantVector[1] = Nucleus::createConstantInt(y);
5625 constantVector[2] = Nucleus::createConstantInt(z);
5626 constantVector[3] = Nucleus::createConstantInt(w);
5627
John Bauman66b8ab22014-05-06 15:57:45 -04005628 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005629 }
5630
John Bauman19bac1e2014-05-06 15:23:49 -04005631 UInt4::UInt4(RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005632 {
5633 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005634
John Bauman66b8ab22014-05-06 15:57:45 -04005635 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005636 }
5637
5638 UInt4::UInt4(const UInt4 &rhs)
5639 {
5640 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005641
John Bauman66b8ab22014-05-06 15:57:45 -04005642 Value *value = rhs.loadValue();
5643 storeValue(value);
5644 }
5645
5646 UInt4::UInt4(const Reference<UInt4> &rhs)
5647 {
5648 // xyzw.parent = this;
5649
5650 Value *value = rhs.loadValue();
5651 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005652 }
5653
John Bauman19bac1e2014-05-06 15:23:49 -04005654 UInt4::UInt4(RValue<Int4> rhs)
5655 {
5656 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005657
John Bauman66b8ab22014-05-06 15:57:45 -04005658 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005659 }
5660
5661 UInt4::UInt4(const Int4 &rhs)
5662 {
5663 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005664
John Bauman66b8ab22014-05-06 15:57:45 -04005665 Value *value = rhs.loadValue();
5666 storeValue(value);
5667 }
5668
5669 UInt4::UInt4(const Reference<Int4> &rhs)
5670 {
5671 // xyzw.parent = this;
5672
5673 Value *value = rhs.loadValue();
5674 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005675 }
5676
5677 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005678 {
John Bauman66b8ab22014-05-06 15:57:45 -04005679 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005680
5681 return rhs;
5682 }
5683
5684 RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
5685 {
John Bauman66b8ab22014-05-06 15:57:45 -04005686 Value *value = rhs.loadValue();
5687 storeValue(value);
5688
5689 return RValue<UInt4>(value);
5690 }
5691
5692 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const
5693 {
5694 Value *value = rhs.loadValue();
5695 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005696
5697 return RValue<UInt4>(value);
5698 }
5699
John Bauman19bac1e2014-05-06 15:23:49 -04005700 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005701 {
5702 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5703 }
5704
John Bauman19bac1e2014-05-06 15:23:49 -04005705 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005706 {
5707 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5708 }
5709
John Bauman19bac1e2014-05-06 15:23:49 -04005710 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005711 {
5712 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5713 }
5714
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005715 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5716 {
5717 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5718 }
John Bauman89401822014-05-06 15:04:28 -04005719
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005720 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5721 {
5722 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5723 }
John Bauman89401822014-05-06 15:04:28 -04005724
John Bauman19bac1e2014-05-06 15:23:49 -04005725 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005726 {
5727 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5728 }
5729
John Bauman19bac1e2014-05-06 15:23:49 -04005730 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005731 {
5732 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5733 }
5734
John Bauman19bac1e2014-05-06 15:23:49 -04005735 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005736 {
5737 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5738 }
5739
John Bauman19bac1e2014-05-06 15:23:49 -04005740 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005741 {
John Bauman89401822014-05-06 15:04:28 -04005742 return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
5743 }
5744
John Bauman19bac1e2014-05-06 15:23:49 -04005745 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005746 {
John Bauman89401822014-05-06 15:04:28 -04005747 return x86::psrld(lhs, rhs);
5748 }
5749
Alexis Hetud9d27bb2015-08-18 15:22:15 -04005750 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5751 {
5752 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5753 }
5754
5755 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5756 {
5757 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5758 }
5759
John Bauman19bac1e2014-05-06 15:23:49 -04005760 RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005761 {
5762 return lhs = lhs + rhs;
5763 }
5764
John Bauman19bac1e2014-05-06 15:23:49 -04005765 RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005766 {
5767 return lhs = lhs - rhs;
5768 }
5769
John Bauman19bac1e2014-05-06 15:23:49 -04005770 RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005771 {
5772 return lhs = lhs * rhs;
5773 }
5774
John Bauman19bac1e2014-05-06 15:23:49 -04005775// RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs)
5776// {
5777// return lhs = lhs / rhs;
5778// }
John Bauman89401822014-05-06 15:04:28 -04005779
John Bauman19bac1e2014-05-06 15:23:49 -04005780// RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs)
5781// {
5782// return lhs = lhs % rhs;
5783// }
John Bauman89401822014-05-06 15:04:28 -04005784
John Bauman19bac1e2014-05-06 15:23:49 -04005785 RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005786 {
5787 return lhs = lhs & rhs;
5788 }
5789
John Bauman19bac1e2014-05-06 15:23:49 -04005790 RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005791 {
5792 return lhs = lhs | rhs;
5793 }
5794
John Bauman19bac1e2014-05-06 15:23:49 -04005795 RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005796 {
5797 return lhs = lhs ^ rhs;
5798 }
5799
5800 RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
5801 {
5802 return lhs = lhs << rhs;
5803 }
5804
5805 RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
5806 {
5807 return lhs = lhs >> rhs;
5808 }
5809
John Bauman19bac1e2014-05-06 15:23:49 -04005810 RValue<UInt4> operator+(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005811 {
5812 return val;
5813 }
5814
John Bauman19bac1e2014-05-06 15:23:49 -04005815 RValue<UInt4> operator-(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005816 {
5817 return RValue<UInt4>(Nucleus::createNeg(val.value));
5818 }
5819
John Bauman19bac1e2014-05-06 15:23:49 -04005820 RValue<UInt4> operator~(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005821 {
5822 return RValue<UInt4>(Nucleus::createNot(val.value));
5823 }
5824
John Bauman19bac1e2014-05-06 15:23:49 -04005825 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5826 {
5827 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5828 }
5829
5830 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5831 {
5832 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5833 }
5834
5835 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5836 {
5837 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5838 }
5839
5840 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5841 {
5842 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5843 }
5844
5845 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5846 {
5847 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5848 }
5849
5850 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5851 {
5852 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5853 }
5854
5855 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5856 {
5857 if(CPUID::supportsSSE4_1())
5858 {
5859 return x86::pmaxud(x, y);
5860 }
5861 else
5862 {
5863 RValue<UInt4> greater = CmpNLE(x, y);
5864 return x & greater | y & ~greater;
5865 }
5866 }
5867
5868 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5869 {
5870 if(CPUID::supportsSSE4_1())
5871 {
5872 return x86::pminud(x, y);
5873 }
5874 else
5875 {
5876 RValue<UInt4> less = CmpLT(x, y);
5877 return x & less | y & ~less;
5878 }
5879 }
5880
5881 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04005882 {
5883 return x86::packusdw(x, y); // FIXME: Fallback required
5884 }
5885
John Bauman19bac1e2014-05-06 15:23:49 -04005886 RValue<UInt4> Concatenate(RValue<UInt2> lo, RValue<UInt2> hi)
John Bauman89401822014-05-06 15:04:28 -04005887 {
5888 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5889 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5890
5891 Value *long2 = UndefValue::get(Long2::getType());
5892 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5893 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5894 Value *uint4 = Nucleus::createBitCast(long2, Int4::getType());
5895
5896 return RValue<UInt4>(uint4);
5897 }
5898
John Bauman19bac1e2014-05-06 15:23:49 -04005899 Type *UInt4::getType()
John Bauman89401822014-05-06 15:04:28 -04005900 {
5901 return VectorType::get(UInt::getType(), 4);
5902 }
5903
John Bauman19bac1e2014-05-06 15:23:49 -04005904 Float::Float(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04005905 {
John Bauman89401822014-05-06 15:04:28 -04005906 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5907
John Bauman66b8ab22014-05-06 15:57:45 -04005908 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04005909 }
5910
5911 Float::Float()
5912 {
John Bauman66b8ab22014-05-06 15:57:45 -04005913
John Bauman89401822014-05-06 15:04:28 -04005914 }
5915
5916 Float::Float(float x)
5917 {
John Bauman66b8ab22014-05-06 15:57:45 -04005918 storeValue(Nucleus::createConstantFloat(x));
John Bauman89401822014-05-06 15:04:28 -04005919 }
5920
John Bauman19bac1e2014-05-06 15:23:49 -04005921 Float::Float(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005922 {
John Bauman66b8ab22014-05-06 15:57:45 -04005923 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005924 }
5925
5926 Float::Float(const Float &rhs)
5927 {
John Bauman66b8ab22014-05-06 15:57:45 -04005928 Value *value = rhs.loadValue();
5929 storeValue(value);
5930 }
John Bauman89401822014-05-06 15:04:28 -04005931
John Bauman66b8ab22014-05-06 15:57:45 -04005932 Float::Float(const Reference<Float> &rhs)
5933 {
5934 Value *value = rhs.loadValue();
5935 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005936 }
5937
John Bauman19bac1e2014-05-06 15:23:49 -04005938 RValue<Float> Float::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005939 {
John Bauman66b8ab22014-05-06 15:57:45 -04005940 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005941
5942 return rhs;
5943 }
5944
5945 RValue<Float> Float::operator=(const Float &rhs) const
5946 {
John Bauman66b8ab22014-05-06 15:57:45 -04005947 Value *value = rhs.loadValue();
5948 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005949
5950 return RValue<Float>(value);
5951 }
5952
John Bauman66b8ab22014-05-06 15:57:45 -04005953 RValue<Float> Float::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04005954 {
John Bauman66b8ab22014-05-06 15:57:45 -04005955 Value *value = rhs.loadValue();
5956 storeValue(value);
5957
5958 return RValue<Float>(value);
John Bauman89401822014-05-06 15:04:28 -04005959 }
5960
John Bauman19bac1e2014-05-06 15:23:49 -04005961 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005962 {
5963 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5964 }
5965
John Bauman19bac1e2014-05-06 15:23:49 -04005966 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005967 {
5968 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5969 }
5970
John Bauman19bac1e2014-05-06 15:23:49 -04005971 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005972 {
5973 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5974 }
5975
John Bauman19bac1e2014-05-06 15:23:49 -04005976 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005977 {
5978 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5979 }
5980
John Bauman19bac1e2014-05-06 15:23:49 -04005981 RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005982 {
5983 return lhs = lhs + rhs;
5984 }
5985
John Bauman19bac1e2014-05-06 15:23:49 -04005986 RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005987 {
5988 return lhs = lhs - rhs;
5989 }
5990
John Bauman19bac1e2014-05-06 15:23:49 -04005991 RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005992 {
5993 return lhs = lhs * rhs;
5994 }
5995
John Bauman19bac1e2014-05-06 15:23:49 -04005996 RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005997 {
5998 return lhs = lhs / rhs;
5999 }
6000
John Bauman19bac1e2014-05-06 15:23:49 -04006001 RValue<Float> operator+(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006002 {
6003 return val;
6004 }
6005
John Bauman19bac1e2014-05-06 15:23:49 -04006006 RValue<Float> operator-(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006007 {
6008 return RValue<Float>(Nucleus::createFNeg(val.value));
6009 }
6010
John Bauman19bac1e2014-05-06 15:23:49 -04006011 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006012 {
6013 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
6014 }
6015
John Bauman19bac1e2014-05-06 15:23:49 -04006016 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006017 {
6018 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
6019 }
6020
John Bauman19bac1e2014-05-06 15:23:49 -04006021 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006022 {
6023 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
6024 }
6025
John Bauman19bac1e2014-05-06 15:23:49 -04006026 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006027 {
6028 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
6029 }
6030
John Bauman19bac1e2014-05-06 15:23:49 -04006031 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006032 {
6033 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
6034 }
6035
John Bauman19bac1e2014-05-06 15:23:49 -04006036 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006037 {
6038 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
6039 }
6040
John Bauman19bac1e2014-05-06 15:23:49 -04006041 RValue<Float> Abs(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006042 {
John Bauman66b8ab22014-05-06 15:57:45 -04006043 return IfThenElse(x > 0.0f, x, -x);
John Bauman89401822014-05-06 15:04:28 -04006044 }
6045
John Bauman19bac1e2014-05-06 15:23:49 -04006046 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04006047 {
6048 return IfThenElse(x > y, x, y);
6049 }
6050
John Bauman19bac1e2014-05-06 15:23:49 -04006051 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04006052 {
6053 return IfThenElse(x < y, x, y);
6054 }
6055
John Bauman19bac1e2014-05-06 15:23:49 -04006056 RValue<Float> Rcp_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006057 {
6058 return x86::rcpss(x);
6059 }
John Bauman66b8ab22014-05-06 15:57:45 -04006060
John Bauman19bac1e2014-05-06 15:23:49 -04006061 RValue<Float> RcpSqrt_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006062 {
6063 return x86::rsqrtss(x);
6064 }
6065
John Bauman19bac1e2014-05-06 15:23:49 -04006066 RValue<Float> Sqrt(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006067 {
6068 return x86::sqrtss(x);
6069 }
6070
John Bauman19bac1e2014-05-06 15:23:49 -04006071 RValue<Float> Round(RValue<Float> x)
6072 {
6073 if(CPUID::supportsSSE4_1())
6074 {
6075 return x86::roundss(x, 0);
6076 }
6077 else
6078 {
6079 return Float4(Round(Float4(x))).x;
6080 }
6081 }
6082
6083 RValue<Float> Trunc(RValue<Float> x)
6084 {
6085 if(CPUID::supportsSSE4_1())
6086 {
6087 return x86::roundss(x, 3);
6088 }
6089 else
6090 {
6091 return Float(Int(x)); // Rounded toward zero
6092 }
6093 }
6094
6095 RValue<Float> Frac(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006096 {
6097 if(CPUID::supportsSSE4_1())
6098 {
6099 return x - x86::floorss(x);
6100 }
6101 else
6102 {
John Bauman19bac1e2014-05-06 15:23:49 -04006103 return Float4(Frac(Float4(x))).x;
John Bauman89401822014-05-06 15:04:28 -04006104 }
6105 }
6106
John Bauman19bac1e2014-05-06 15:23:49 -04006107 RValue<Float> Floor(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006108 {
6109 if(CPUID::supportsSSE4_1())
6110 {
6111 return x86::floorss(x);
6112 }
6113 else
6114 {
6115 return Float4(Floor(Float4(x))).x;
6116 }
6117 }
6118
John Bauman19bac1e2014-05-06 15:23:49 -04006119 RValue<Float> Ceil(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006120 {
John Bauman19bac1e2014-05-06 15:23:49 -04006121 if(CPUID::supportsSSE4_1())
6122 {
6123 return x86::ceilss(x);
6124 }
6125 else
6126 {
6127 return Float4(Ceil(Float4(x))).x;
6128 }
John Bauman89401822014-05-06 15:04:28 -04006129 }
6130
John Bauman19bac1e2014-05-06 15:23:49 -04006131 Type *Float::getType()
John Bauman89401822014-05-06 15:04:28 -04006132 {
6133 return Type::getFloatTy(*Nucleus::getContext());
6134 }
6135
John Bauman19bac1e2014-05-06 15:23:49 -04006136 Float2::Float2(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04006137 {
6138 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006139
6140 Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
6141 Value *int64 = Nucleus::createExtractElement(int64x2, 0);
6142 Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
6143
John Bauman66b8ab22014-05-06 15:57:45 -04006144 storeValue(float2);
John Bauman89401822014-05-06 15:04:28 -04006145 }
6146
John Bauman19bac1e2014-05-06 15:23:49 -04006147 Type *Float2::getType()
John Bauman89401822014-05-06 15:04:28 -04006148 {
6149 return VectorType::get(Float::getType(), 2);
6150 }
6151
John Bauman19bac1e2014-05-06 15:23:49 -04006152 Float4::Float4(RValue<Byte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006153 {
6154 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006155
6156 #if 0
6157 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6158 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006159 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006160
6161 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6162 Value *f32x = Nucleus::createUIToFP(i8x, Float::getType());
6163 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6164
6165 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6166 Value *f32y = Nucleus::createUIToFP(i8y, Float::getType());
6167 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6168
6169 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6170 Value *f32z = Nucleus::createUIToFP(i8z, Float::getType());
6171 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6172
6173 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6174 Value *f32w = Nucleus::createUIToFP(i8w, Float::getType());
6175 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6176 #else
6177 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6178 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6179
6180 Value *e;
6181
6182 if(CPUID::supportsSSE4_1())
6183 {
6184 e = x86::pmovzxbd(RValue<Int4>(a)).value;
6185 }
6186 else
6187 {
6188 Constant *swizzle[16];
6189 swizzle[0] = Nucleus::createConstantInt(0);
6190 swizzle[1] = Nucleus::createConstantInt(16);
6191 swizzle[2] = Nucleus::createConstantInt(1);
6192 swizzle[3] = Nucleus::createConstantInt(17);
6193 swizzle[4] = Nucleus::createConstantInt(2);
6194 swizzle[5] = Nucleus::createConstantInt(18);
6195 swizzle[6] = Nucleus::createConstantInt(3);
6196 swizzle[7] = Nucleus::createConstantInt(19);
6197 swizzle[8] = Nucleus::createConstantInt(4);
6198 swizzle[9] = Nucleus::createConstantInt(20);
6199 swizzle[10] = Nucleus::createConstantInt(5);
6200 swizzle[11] = Nucleus::createConstantInt(21);
6201 swizzle[12] = Nucleus::createConstantInt(6);
6202 swizzle[13] = Nucleus::createConstantInt(22);
6203 swizzle[14] = Nucleus::createConstantInt(7);
6204 swizzle[15] = Nucleus::createConstantInt(23);
6205
6206 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6207 Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16));
6208
6209 Constant *swizzle2[8];
6210 swizzle2[0] = Nucleus::createConstantInt(0);
6211 swizzle2[1] = Nucleus::createConstantInt(8);
6212 swizzle2[2] = Nucleus::createConstantInt(1);
6213 swizzle2[3] = Nucleus::createConstantInt(9);
6214 swizzle2[4] = Nucleus::createConstantInt(2);
6215 swizzle2[5] = Nucleus::createConstantInt(10);
6216 swizzle2[6] = Nucleus::createConstantInt(3);
6217 swizzle2[7] = Nucleus::createConstantInt(11);
6218
6219 Value *d = Nucleus::createBitCast(c, Short8::getType());
6220 e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8));
6221 }
6222
6223 Value *f = Nucleus::createBitCast(e, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006224 Value *g = Nucleus::createSIToFP(f, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006225 Value *xyzw = g;
6226 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006227
6228 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006229 }
6230
John Bauman19bac1e2014-05-06 15:23:49 -04006231 Float4::Float4(RValue<SByte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006232 {
6233 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006234
6235 #if 0
6236 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6237 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006238 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006239
6240 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6241 Value *f32x = Nucleus::createSIToFP(i8x, Float::getType());
6242 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6243
6244 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6245 Value *f32y = Nucleus::createSIToFP(i8y, Float::getType());
6246 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6247
6248 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6249 Value *f32z = Nucleus::createSIToFP(i8z, Float::getType());
6250 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6251
6252 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6253 Value *f32w = Nucleus::createSIToFP(i8w, Float::getType());
6254 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6255 #else
6256 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6257 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6258
6259 Value *g;
6260
6261 if(CPUID::supportsSSE4_1())
6262 {
6263 g = x86::pmovsxbd(RValue<Int4>(a)).value;
6264 }
6265 else
6266 {
6267 Constant *swizzle[16];
6268 swizzle[0] = Nucleus::createConstantInt(0);
6269 swizzle[1] = Nucleus::createConstantInt(0);
6270 swizzle[2] = Nucleus::createConstantInt(1);
6271 swizzle[3] = Nucleus::createConstantInt(1);
6272 swizzle[4] = Nucleus::createConstantInt(2);
6273 swizzle[5] = Nucleus::createConstantInt(2);
6274 swizzle[6] = Nucleus::createConstantInt(3);
6275 swizzle[7] = Nucleus::createConstantInt(3);
6276 swizzle[8] = Nucleus::createConstantInt(4);
6277 swizzle[9] = Nucleus::createConstantInt(4);
6278 swizzle[10] = Nucleus::createConstantInt(5);
6279 swizzle[11] = Nucleus::createConstantInt(5);
6280 swizzle[12] = Nucleus::createConstantInt(6);
6281 swizzle[13] = Nucleus::createConstantInt(6);
6282 swizzle[14] = Nucleus::createConstantInt(7);
6283 swizzle[15] = Nucleus::createConstantInt(7);
6284
6285 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6286 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16));
6287
6288 Constant *swizzle2[8];
6289 swizzle2[0] = Nucleus::createConstantInt(0);
6290 swizzle2[1] = Nucleus::createConstantInt(0);
6291 swizzle2[2] = Nucleus::createConstantInt(1);
6292 swizzle2[3] = Nucleus::createConstantInt(1);
6293 swizzle2[4] = Nucleus::createConstantInt(2);
6294 swizzle2[5] = Nucleus::createConstantInt(2);
6295 swizzle2[6] = Nucleus::createConstantInt(3);
6296 swizzle2[7] = Nucleus::createConstantInt(3);
6297
6298 Value *d = Nucleus::createBitCast(c, Short8::getType());
6299 Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8));
6300
6301 Value *f = Nucleus::createBitCast(e, Int4::getType());
6302 // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24));
6303 g = x86::psrad(RValue<Int4>(f), 24).value;
6304 }
6305
John Bauman19bac1e2014-05-06 15:23:49 -04006306 Value *xyzw = Nucleus::createSIToFP(g, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006307 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006308
6309 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006310 }
6311
John Bauman19bac1e2014-05-06 15:23:49 -04006312 Float4::Float4(RValue<Short4> cast)
John Bauman89401822014-05-06 15:04:28 -04006313 {
6314 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006315
Alexis Hetu2aa852f2015-10-14 16:32:39 -04006316 Int4 c(cast);
6317 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
John Bauman89401822014-05-06 15:04:28 -04006318 }
6319
John Bauman19bac1e2014-05-06 15:23:49 -04006320 Float4::Float4(RValue<UShort4> cast)
John Bauman89401822014-05-06 15:04:28 -04006321 {
6322 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006323
Alexis Hetu2aa852f2015-10-14 16:32:39 -04006324 Int4 c(cast);
6325 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
John Bauman89401822014-05-06 15:04:28 -04006326 }
6327
John Bauman19bac1e2014-05-06 15:23:49 -04006328 Float4::Float4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04006329 {
6330 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006331
6332 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006333
John Bauman66b8ab22014-05-06 15:57:45 -04006334 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006335 }
6336
John Bauman19bac1e2014-05-06 15:23:49 -04006337 Float4::Float4(RValue<UInt4> cast)
John Bauman89401822014-05-06 15:04:28 -04006338 {
6339 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006340
6341 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
6342
John Bauman66b8ab22014-05-06 15:57:45 -04006343 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006344 }
6345
6346 Float4::Float4()
6347 {
6348 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006349 }
John Bauman66b8ab22014-05-06 15:57:45 -04006350
John Bauman89401822014-05-06 15:04:28 -04006351 Float4::Float4(float xyzw)
6352 {
6353 constant(xyzw, xyzw, xyzw, xyzw);
6354 }
6355
6356 Float4::Float4(float x, float yzw)
6357 {
6358 constant(x, yzw, yzw, yzw);
6359 }
6360
6361 Float4::Float4(float x, float y, float zw)
6362 {
6363 constant(x, y, zw, zw);
6364 }
6365
6366 Float4::Float4(float x, float y, float z, float w)
6367 {
6368 constant(x, y, z, w);
6369 }
6370
6371 void Float4::constant(float x, float y, float z, float w)
6372 {
6373 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006374
6375 Constant *constantVector[4];
6376 constantVector[0] = Nucleus::createConstantFloat(x);
6377 constantVector[1] = Nucleus::createConstantFloat(y);
6378 constantVector[2] = Nucleus::createConstantFloat(z);
6379 constantVector[3] = Nucleus::createConstantFloat(w);
6380
John Bauman66b8ab22014-05-06 15:57:45 -04006381 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04006382 }
6383
John Bauman19bac1e2014-05-06 15:23:49 -04006384 Float4::Float4(RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006385 {
6386 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006387
John Bauman66b8ab22014-05-06 15:57:45 -04006388 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006389 }
6390
6391 Float4::Float4(const Float4 &rhs)
6392 {
6393 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006394
John Bauman66b8ab22014-05-06 15:57:45 -04006395 Value *value = rhs.loadValue();
6396 storeValue(value);
6397 }
6398
6399 Float4::Float4(const Reference<Float4> &rhs)
6400 {
6401 xyzw.parent = this;
6402
6403 Value *value = rhs.loadValue();
6404 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006405 }
6406
John Bauman19bac1e2014-05-06 15:23:49 -04006407 Float4::Float4(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006408 {
6409 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006410
John Bauman66b8ab22014-05-06 15:57:45 -04006411 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006412 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
6413
6414 Constant *swizzle[4];
6415 swizzle[0] = Nucleus::createConstantInt(0);
6416 swizzle[1] = Nucleus::createConstantInt(0);
6417 swizzle[2] = Nucleus::createConstantInt(0);
6418 swizzle[3] = Nucleus::createConstantInt(0);
6419
6420 Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4));
6421
John Bauman66b8ab22014-05-06 15:57:45 -04006422 storeValue(replicate);
John Bauman89401822014-05-06 15:04:28 -04006423 }
6424
6425 Float4::Float4(const Float &rhs)
6426 {
6427 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006428
John Bauman66b8ab22014-05-06 15:57:45 -04006429 *this = RValue<Float>(rhs.loadValue());
6430 }
John Bauman89401822014-05-06 15:04:28 -04006431
John Bauman66b8ab22014-05-06 15:57:45 -04006432 Float4::Float4(const Reference<Float> &rhs)
6433 {
6434 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006435
John Bauman66b8ab22014-05-06 15:57:45 -04006436 *this = RValue<Float>(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006437 }
6438
6439 RValue<Float4> Float4::operator=(float x) const
6440 {
6441 return *this = Float4(x, x, x, x);
6442 }
6443
John Bauman19bac1e2014-05-06 15:23:49 -04006444 RValue<Float4> Float4::operator=(RValue<Float4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006445 {
John Bauman66b8ab22014-05-06 15:57:45 -04006446 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006447
6448 return rhs;
6449 }
6450
6451 RValue<Float4> Float4::operator=(const Float4 &rhs) const
6452 {
John Bauman66b8ab22014-05-06 15:57:45 -04006453 Value *value = rhs.loadValue();
6454 storeValue(value);
6455
6456 return RValue<Float4>(value);
6457 }
6458
6459 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const
6460 {
6461 Value *value = rhs.loadValue();
6462 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006463
6464 return RValue<Float4>(value);
6465 }
6466
John Bauman19bac1e2014-05-06 15:23:49 -04006467 RValue<Float4> Float4::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006468 {
6469 return *this = Float4(rhs);
6470 }
6471
6472 RValue<Float4> Float4::operator=(const Float &rhs) const
6473 {
6474 return *this = Float4(rhs);
6475 }
6476
John Bauman66b8ab22014-05-06 15:57:45 -04006477 RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04006478 {
John Bauman66b8ab22014-05-06 15:57:45 -04006479 return *this = Float4(rhs);
John Bauman89401822014-05-06 15:04:28 -04006480 }
6481
John Bauman19bac1e2014-05-06 15:23:49 -04006482 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006483 {
6484 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
6485 }
6486
John Bauman19bac1e2014-05-06 15:23:49 -04006487 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006488 {
6489 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
6490 }
6491
John Bauman19bac1e2014-05-06 15:23:49 -04006492 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006493 {
6494 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
6495 }
6496
John Bauman19bac1e2014-05-06 15:23:49 -04006497 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006498 {
6499 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6500 }
6501
John Bauman19bac1e2014-05-06 15:23:49 -04006502 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006503 {
6504 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
6505 }
6506
John Bauman19bac1e2014-05-06 15:23:49 -04006507 RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006508 {
6509 return lhs = lhs + rhs;
6510 }
6511
John Bauman19bac1e2014-05-06 15:23:49 -04006512 RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006513 {
6514 return lhs = lhs - rhs;
6515 }
6516
John Bauman19bac1e2014-05-06 15:23:49 -04006517 RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006518 {
6519 return lhs = lhs * rhs;
6520 }
6521
John Bauman19bac1e2014-05-06 15:23:49 -04006522 RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006523 {
6524 return lhs = lhs / rhs;
6525 }
6526
John Bauman19bac1e2014-05-06 15:23:49 -04006527 RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006528 {
6529 return lhs = lhs % rhs;
6530 }
6531
John Bauman19bac1e2014-05-06 15:23:49 -04006532 RValue<Float4> operator+(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006533 {
6534 return val;
6535 }
6536
John Bauman19bac1e2014-05-06 15:23:49 -04006537 RValue<Float4> operator-(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006538 {
6539 return RValue<Float4>(Nucleus::createFNeg(val.value));
6540 }
6541
John Bauman19bac1e2014-05-06 15:23:49 -04006542 RValue<Float4> Abs(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006543 {
6544 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6545
6546 Constant *constantVector[4];
6547 constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF);
6548 constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF);
6549 constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF);
6550 constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF);
6551
6552 Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4));
6553
6554 return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType()));
6555 }
6556
John Bauman19bac1e2014-05-06 15:23:49 -04006557 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006558 {
6559 return x86::maxps(x, y);
6560 }
6561
John Bauman19bac1e2014-05-06 15:23:49 -04006562 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006563 {
6564 return x86::minps(x, y);
6565 }
6566
John Bauman19bac1e2014-05-06 15:23:49 -04006567 RValue<Float4> Rcp_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006568 {
6569 return x86::rcpps(x);
6570 }
John Bauman66b8ab22014-05-06 15:57:45 -04006571
John Bauman19bac1e2014-05-06 15:23:49 -04006572 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006573 {
6574 return x86::rsqrtps(x);
6575 }
6576
John Bauman19bac1e2014-05-06 15:23:49 -04006577 RValue<Float4> Sqrt(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006578 {
6579 return x86::sqrtps(x);
6580 }
6581
John Bauman19bac1e2014-05-06 15:23:49 -04006582 RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i)
John Bauman89401822014-05-06 15:04:28 -04006583 {
John Bauman66b8ab22014-05-06 15:57:45 -04006584 llvm::Value *value = val.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006585 llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i);
6586
6587 val = RValue<Float4>(insert);
6588
6589 return val;
6590 }
6591
John Bauman19bac1e2014-05-06 15:23:49 -04006592 RValue<Float> Extract(RValue<Float4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04006593 {
6594 return RValue<Float>(Nucleus::createExtractElement(x.value, i));
6595 }
6596
John Bauman19bac1e2014-05-06 15:23:49 -04006597 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006598 {
6599 return RValue<Float4>(Nucleus::createSwizzle(x.value, select));
6600 }
6601
John Bauman19bac1e2014-05-06 15:23:49 -04006602 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006603 {
6604 Constant *shuffle[4];
6605 shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0);
6606 shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0);
6607 shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4);
6608 shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4);
6609
6610 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6611 }
6612
John Bauman19bac1e2014-05-06 15:23:49 -04006613 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006614 {
6615 Constant *shuffle[4];
6616 shuffle[0] = Nucleus::createConstantInt(0);
6617 shuffle[1] = Nucleus::createConstantInt(4);
6618 shuffle[2] = Nucleus::createConstantInt(1);
6619 shuffle[3] = Nucleus::createConstantInt(5);
6620
6621 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6622 }
6623
John Bauman19bac1e2014-05-06 15:23:49 -04006624 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006625 {
6626 Constant *shuffle[4];
6627 shuffle[0] = Nucleus::createConstantInt(2);
6628 shuffle[1] = Nucleus::createConstantInt(6);
6629 shuffle[2] = Nucleus::createConstantInt(3);
6630 shuffle[3] = Nucleus::createConstantInt(7);
6631
6632 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6633 }
John Bauman66b8ab22014-05-06 15:57:45 -04006634
John Bauman19bac1e2014-05-06 15:23:49 -04006635 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006636 {
John Bauman66b8ab22014-05-06 15:57:45 -04006637 Value *vector = lhs.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006638 Value *shuffle = Nucleus::createMask(vector, rhs.value, select);
John Bauman66b8ab22014-05-06 15:57:45 -04006639 lhs.storeValue(shuffle);
John Bauman89401822014-05-06 15:04:28 -04006640
6641 return RValue<Float4>(shuffle);
6642 }
6643
John Bauman19bac1e2014-05-06 15:23:49 -04006644 RValue<Int> SignMask(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006645 {
6646 return x86::movmskps(x);
6647 }
6648
John Bauman19bac1e2014-05-06 15:23:49 -04006649 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006650 {
6651 // return As<Int4>(x86::cmpeqps(x, y));
6652 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
6653 }
6654
John Bauman19bac1e2014-05-06 15:23:49 -04006655 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006656 {
6657 // return As<Int4>(x86::cmpltps(x, y));
6658 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
6659 }
6660
John Bauman19bac1e2014-05-06 15:23:49 -04006661 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006662 {
6663 // return As<Int4>(x86::cmpleps(x, y));
6664 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
6665 }
6666
John Bauman19bac1e2014-05-06 15:23:49 -04006667 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006668 {
6669 // return As<Int4>(x86::cmpneqps(x, y));
6670 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
6671 }
6672
John Bauman19bac1e2014-05-06 15:23:49 -04006673 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006674 {
6675 // return As<Int4>(x86::cmpnltps(x, y));
6676 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
6677 }
6678
John Bauman19bac1e2014-05-06 15:23:49 -04006679 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006680 {
6681 // return As<Int4>(x86::cmpnleps(x, y));
6682 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
6683 }
6684
John Bauman19bac1e2014-05-06 15:23:49 -04006685 RValue<Float4> Round(RValue<Float4> x)
6686 {
6687 if(CPUID::supportsSSE4_1())
6688 {
6689 return x86::roundps(x, 0);
6690 }
6691 else
6692 {
6693 return Float4(RoundInt(x));
6694 }
6695 }
6696
6697 RValue<Float4> Trunc(RValue<Float4> x)
6698 {
6699 if(CPUID::supportsSSE4_1())
6700 {
6701 return x86::roundps(x, 3);
6702 }
6703 else
6704 {
6705 return Float4(Int4(x)); // Rounded toward zero
6706 }
6707 }
6708
6709 RValue<Float4> Frac(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006710 {
6711 if(CPUID::supportsSSE4_1())
6712 {
6713 return x - x86::floorps(x);
6714 }
6715 else
6716 {
John Bauman19bac1e2014-05-06 15:23:49 -04006717 Float4 frc = x - Float4(Int4(x)); // Signed fractional part
John Bauman89401822014-05-06 15:04:28 -04006718
John Bauman19bac1e2014-05-06 15:23:49 -04006719 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 -04006720 }
6721 }
6722
John Bauman19bac1e2014-05-06 15:23:49 -04006723 RValue<Float4> Floor(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006724 {
6725 if(CPUID::supportsSSE4_1())
6726 {
6727 return x86::floorps(x);
6728 }
6729 else
6730 {
John Bauman19bac1e2014-05-06 15:23:49 -04006731 return x - Frac(x);
John Bauman89401822014-05-06 15:04:28 -04006732 }
6733 }
6734
John Bauman19bac1e2014-05-06 15:23:49 -04006735 RValue<Float4> Ceil(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006736 {
John Bauman19bac1e2014-05-06 15:23:49 -04006737 if(CPUID::supportsSSE4_1())
6738 {
6739 return x86::ceilps(x);
6740 }
6741 else
6742 {
6743 return -Floor(-x);
6744 }
John Bauman89401822014-05-06 15:04:28 -04006745 }
6746
John Bauman19bac1e2014-05-06 15:23:49 -04006747 Type *Float4::getType()
John Bauman89401822014-05-06 15:04:28 -04006748 {
6749 return VectorType::get(Float::getType(), 4);
6750 }
6751
John Bauman66b8ab22014-05-06 15:57:45 -04006752 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006753 {
John Bauman66b8ab22014-05-06 15:57:45 -04006754 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
John Bauman89401822014-05-06 15:04:28 -04006755 }
6756
John Bauman66b8ab22014-05-06 15:57:45 -04006757 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006758 {
John Bauman66b8ab22014-05-06 15:57:45 -04006759 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006760 }
6761
John Bauman66b8ab22014-05-06 15:57:45 -04006762 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006763 {
John Bauman66b8ab22014-05-06 15:57:45 -04006764 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006765 }
6766
John Bauman66b8ab22014-05-06 15:57:45 -04006767 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006768 {
6769 return lhs = lhs + offset;
6770 }
6771
John Bauman66b8ab22014-05-06 15:57:45 -04006772 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006773 {
6774 return lhs = lhs + offset;
6775 }
6776
John Bauman66b8ab22014-05-06 15:57:45 -04006777 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006778 {
6779 return lhs = lhs + offset;
6780 }
6781
John Bauman66b8ab22014-05-06 15:57:45 -04006782 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006783 {
6784 return lhs + -offset;
6785 }
6786
John Bauman66b8ab22014-05-06 15:57:45 -04006787 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006788 {
6789 return lhs + -offset;
6790 }
6791
John Bauman66b8ab22014-05-06 15:57:45 -04006792 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006793 {
6794 return lhs + -offset;
6795 }
6796
John Bauman66b8ab22014-05-06 15:57:45 -04006797 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006798 {
6799 return lhs = lhs - offset;
6800 }
6801
John Bauman66b8ab22014-05-06 15:57:45 -04006802 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006803 {
6804 return lhs = lhs - offset;
6805 }
6806
John Bauman66b8ab22014-05-06 15:57:45 -04006807 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006808 {
6809 return lhs = lhs - offset;
6810 }
6811
6812 void Return()
6813 {
John Bauman89401822014-05-06 15:04:28 -04006814 Nucleus::createRetVoid();
6815 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006816 Nucleus::createUnreachable();
6817 }
6818
6819 void Return(bool ret)
6820 {
John Bauman19bac1e2014-05-06 15:23:49 -04006821 Nucleus::createRet(Nucleus::createConstantBool(ret));
6822 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6823 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006824 }
6825
6826 void Return(const Int &ret)
6827 {
John Bauman66b8ab22014-05-06 15:57:45 -04006828 Nucleus::createRet(ret.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006829 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006830 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006831 }
6832
6833 BasicBlock *beginLoop()
6834 {
6835 BasicBlock *loopBB = Nucleus::createBasicBlock();
6836
6837 Nucleus::createBr(loopBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006838 Nucleus::setInsertBlock(loopBB);
John Bauman89401822014-05-06 15:04:28 -04006839
6840 return loopBB;
6841 }
6842
John Bauman19bac1e2014-05-06 15:23:49 -04006843 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
John Bauman89401822014-05-06 15:04:28 -04006844 {
6845 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006846 Nucleus::setInsertBlock(bodyBB);
6847
John Bauman89401822014-05-06 15:04:28 -04006848 return true;
6849 }
6850
6851 bool elseBlock(BasicBlock *falseBB)
6852 {
6853 falseBB->back().eraseFromParent();
John Bauman66b8ab22014-05-06 15:57:45 -04006854 Nucleus::setInsertBlock(falseBB);
John Bauman89401822014-05-06 15:04:28 -04006855
6856 return true;
6857 }
6858
6859 RValue<Long> Ticks()
6860 {
6861 Module *module = Nucleus::getModule();
6862 llvm::Function *rdtsc = Intrinsic::getDeclaration(module, Intrinsic::readcyclecounter);
6863
6864 return RValue<Long>(Nucleus::createCall(rdtsc));
6865 }
John Bauman89401822014-05-06 15:04:28 -04006866}
6867
6868namespace sw
6869{
6870 namespace x86
6871 {
John Bauman19bac1e2014-05-06 15:23:49 -04006872 RValue<Int> cvtss2si(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006873 {
6874 Module *module = Nucleus::getModule();
6875 llvm::Function *cvtss2si = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtss2si);
John Bauman66b8ab22014-05-06 15:57:45 -04006876
John Bauman89401822014-05-06 15:04:28 -04006877 Float4 vector;
6878 vector.x = val;
6879
6880 return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value));
6881 }
6882
John Bauman19bac1e2014-05-06 15:23:49 -04006883 RValue<Int2> cvtps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006884 {
6885 Module *module = Nucleus::getModule();
6886 llvm::Function *cvtps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtps2pi);
6887
6888 return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value));
6889 }
6890
John Bauman19bac1e2014-05-06 15:23:49 -04006891 RValue<Int2> cvttps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006892 {
6893 Module *module = Nucleus::getModule();
6894 llvm::Function *cvttps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvttps2pi);
6895
6896 return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value));
6897 }
6898
John Bauman19bac1e2014-05-06 15:23:49 -04006899 RValue<Int4> cvtps2dq(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006900 {
6901 if(CPUID::supportsSSE2())
6902 {
6903 Module *module = Nucleus::getModule();
6904 llvm::Function *cvtps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtps2dq);
6905
6906 return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value));
6907 }
6908 else
6909 {
6910 Int2 lo = x86::cvtps2pi(val);
6911 Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04006912
John Bauman89401822014-05-06 15:04:28 -04006913 return Concatenate(lo, hi);
6914 }
6915 }
6916
John Bauman19bac1e2014-05-06 15:23:49 -04006917 RValue<Float> rcpss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006918 {
6919 Module *module = Nucleus::getModule();
6920 llvm::Function *rcpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ss);
6921
6922 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006923
John Bauman89401822014-05-06 15:04:28 -04006924 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rcpss, vector), 0));
6925 }
6926
John Bauman19bac1e2014-05-06 15:23:49 -04006927 RValue<Float> sqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006928 {
6929 Module *module = Nucleus::getModule();
6930 llvm::Function *sqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ss);
6931
6932 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006933
John Bauman89401822014-05-06 15:04:28 -04006934 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0));
6935 }
6936
John Bauman19bac1e2014-05-06 15:23:49 -04006937 RValue<Float> rsqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006938 {
6939 Module *module = Nucleus::getModule();
6940 llvm::Function *rsqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ss);
John Bauman66b8ab22014-05-06 15:57:45 -04006941
John Bauman89401822014-05-06 15:04:28 -04006942 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
6943
6944 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0));
6945 }
6946
John Bauman19bac1e2014-05-06 15:23:49 -04006947 RValue<Float4> rcpps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006948 {
6949 Module *module = Nucleus::getModule();
6950 llvm::Function *rcpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006951
John Bauman89401822014-05-06 15:04:28 -04006952 return RValue<Float4>(Nucleus::createCall(rcpps, val.value));
6953 }
6954
John Bauman19bac1e2014-05-06 15:23:49 -04006955 RValue<Float4> sqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006956 {
6957 Module *module = Nucleus::getModule();
6958 llvm::Function *sqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006959
John Bauman89401822014-05-06 15:04:28 -04006960 return RValue<Float4>(Nucleus::createCall(sqrtps, val.value));
6961 }
6962
John Bauman19bac1e2014-05-06 15:23:49 -04006963 RValue<Float4> rsqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006964 {
6965 Module *module = Nucleus::getModule();
6966 llvm::Function *rsqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006967
John Bauman89401822014-05-06 15:04:28 -04006968 return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value));
6969 }
6970
John Bauman19bac1e2014-05-06 15:23:49 -04006971 RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006972 {
6973 Module *module = Nucleus::getModule();
6974 llvm::Function *maxps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_max_ps);
6975
6976 return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value));
6977 }
6978
John Bauman19bac1e2014-05-06 15:23:49 -04006979 RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006980 {
6981 Module *module = Nucleus::getModule();
6982 llvm::Function *minps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_min_ps);
6983
6984 return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value));
6985 }
6986
John Bauman19bac1e2014-05-06 15:23:49 -04006987 RValue<Float> roundss(RValue<Float> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006988 {
6989 Module *module = Nucleus::getModule();
6990 llvm::Function *roundss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ss);
6991
6992 Value *undef = UndefValue::get(Float4::getType());
6993 Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
6994
6995 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0));
6996 }
6997
John Bauman19bac1e2014-05-06 15:23:49 -04006998 RValue<Float> floorss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006999 {
7000 return roundss(val, 1);
7001 }
7002
John Bauman19bac1e2014-05-06 15:23:49 -04007003 RValue<Float> ceilss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04007004 {
7005 return roundss(val, 2);
7006 }
7007
John Bauman19bac1e2014-05-06 15:23:49 -04007008 RValue<Float4> roundps(RValue<Float4> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007009 {
7010 Module *module = Nucleus::getModule();
7011 llvm::Function *roundps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ps);
7012
7013 return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm)));
7014 }
7015
John Bauman19bac1e2014-05-06 15:23:49 -04007016 RValue<Float4> floorps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007017 {
7018 return roundps(val, 1);
7019 }
7020
John Bauman19bac1e2014-05-06 15:23:49 -04007021 RValue<Float4> ceilps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007022 {
7023 return roundps(val, 2);
7024 }
7025
John Bauman19bac1e2014-05-06 15:23:49 -04007026 RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007027 {
7028 Module *module = Nucleus::getModule();
7029 llvm::Function *cmpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ps);
7030
7031 return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm)));
7032 }
7033
John Bauman19bac1e2014-05-06 15:23:49 -04007034 RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007035 {
7036 return cmpps(x, y, 0);
7037 }
7038
John Bauman19bac1e2014-05-06 15:23:49 -04007039 RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007040 {
7041 return cmpps(x, y, 1);
7042 }
7043
John Bauman19bac1e2014-05-06 15:23:49 -04007044 RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007045 {
7046 return cmpps(x, y, 2);
7047 }
7048
John Bauman19bac1e2014-05-06 15:23:49 -04007049 RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007050 {
7051 return cmpps(x, y, 3);
7052 }
7053
John Bauman19bac1e2014-05-06 15:23:49 -04007054 RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007055 {
7056 return cmpps(x, y, 4);
7057 }
7058
John Bauman19bac1e2014-05-06 15:23:49 -04007059 RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007060 {
7061 return cmpps(x, y, 5);
7062 }
7063
John Bauman19bac1e2014-05-06 15:23:49 -04007064 RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007065 {
7066 return cmpps(x, y, 6);
7067 }
7068
John Bauman19bac1e2014-05-06 15:23:49 -04007069 RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007070 {
7071 return cmpps(x, y, 7);
7072 }
7073
John Bauman19bac1e2014-05-06 15:23:49 -04007074 RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007075 {
7076 Module *module = Nucleus::getModule();
7077 llvm::Function *cmpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ss);
7078
7079 Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0);
7080 Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0);
7081
7082 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0));
7083 }
7084
John Bauman19bac1e2014-05-06 15:23:49 -04007085 RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007086 {
7087 return cmpss(x, y, 0);
7088 }
7089
John Bauman19bac1e2014-05-06 15:23:49 -04007090 RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007091 {
7092 return cmpss(x, y, 1);
7093 }
7094
John Bauman19bac1e2014-05-06 15:23:49 -04007095 RValue<Float> cmpless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007096 {
7097 return cmpss(x, y, 2);
7098 }
7099
John Bauman19bac1e2014-05-06 15:23:49 -04007100 RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007101 {
7102 return cmpss(x, y, 3);
7103 }
7104
John Bauman19bac1e2014-05-06 15:23:49 -04007105 RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007106 {
7107 return cmpss(x, y, 4);
7108 }
7109
John Bauman19bac1e2014-05-06 15:23:49 -04007110 RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007111 {
7112 return cmpss(x, y, 5);
7113 }
7114
John Bauman19bac1e2014-05-06 15:23:49 -04007115 RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007116 {
7117 return cmpss(x, y, 6);
7118 }
7119
John Bauman19bac1e2014-05-06 15:23:49 -04007120 RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007121 {
7122 return cmpss(x, y, 7);
7123 }
7124
John Bauman19bac1e2014-05-06 15:23:49 -04007125 RValue<Int4> pabsd(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007126 {
7127 Module *module = Nucleus::getModule();
7128 llvm::Function *pabsd = Intrinsic::getDeclaration(module, Intrinsic::x86_ssse3_pabs_d_128);
7129
7130 return RValue<Int4>(Nucleus::createCall(pabsd, x.value, y.value));
7131 }
7132
John Bauman19bac1e2014-05-06 15:23:49 -04007133 RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007134 {
7135 Module *module = Nucleus::getModule();
7136 llvm::Function *paddsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_w);
7137
John Bauman19bac1e2014-05-06 15:23:49 -04007138 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007139 }
John Bauman66b8ab22014-05-06 15:57:45 -04007140
John Bauman19bac1e2014-05-06 15:23:49 -04007141 RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007142 {
7143 Module *module = Nucleus::getModule();
7144 llvm::Function *psubsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_w);
7145
John Bauman19bac1e2014-05-06 15:23:49 -04007146 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007147 }
7148
John Bauman19bac1e2014-05-06 15:23:49 -04007149 RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007150 {
7151 Module *module = Nucleus::getModule();
7152 llvm::Function *paddusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_w);
7153
John Bauman19bac1e2014-05-06 15:23:49 -04007154 return As<UShort4>(RValue<MMX>(Nucleus::createCall(paddusw, 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<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007158 {
7159 Module *module = Nucleus::getModule();
7160 llvm::Function *psubusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_w);
7161
John Bauman19bac1e2014-05-06 15:23:49 -04007162 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psubusw, 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<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007166 {
7167 Module *module = Nucleus::getModule();
7168 llvm::Function *paddsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_b);
7169
John Bauman19bac1e2014-05-06 15:23:49 -04007170 return As<SByte8>(RValue<MMX>(Nucleus::createCall(paddsb, 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<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007174 {
7175 Module *module = Nucleus::getModule();
7176 llvm::Function *psubsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_b);
7177
John Bauman19bac1e2014-05-06 15:23:49 -04007178 return As<SByte8>(RValue<MMX>(Nucleus::createCall(psubsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007179 }
John Bauman66b8ab22014-05-06 15:57:45 -04007180
John Bauman19bac1e2014-05-06 15:23:49 -04007181 RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007182 {
7183 Module *module = Nucleus::getModule();
7184 llvm::Function *paddusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_b);
7185
John Bauman19bac1e2014-05-06 15:23:49 -04007186 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddusb, 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<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007190 {
7191 Module *module = Nucleus::getModule();
7192 llvm::Function *psubusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_b);
7193
John Bauman19bac1e2014-05-06 15:23:49 -04007194 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007195 }
7196
John Bauman19bac1e2014-05-06 15:23:49 -04007197 RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y)
7198 {
7199 Module *module = Nucleus::getModule();
7200 llvm::Function *paddw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_w);
7201
7202 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddw, As<MMX>(x).value, As<MMX>(y).value)));
7203 }
7204
7205 RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y)
7206 {
7207 Module *module = Nucleus::getModule();
7208 llvm::Function *psubw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_w);
7209
7210 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubw, As<MMX>(x).value, As<MMX>(y).value)));
7211 }
7212
7213 RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y)
7214 {
7215 Module *module = Nucleus::getModule();
7216 llvm::Function *pmullw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmull_w);
7217
7218 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmullw, As<MMX>(x).value, As<MMX>(y).value)));
7219 }
7220
7221 RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y)
7222 {
7223 Module *module = Nucleus::getModule();
7224 llvm::Function *pand = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pand);
7225
7226 return As<Short4>(RValue<MMX>(Nucleus::createCall(pand, As<MMX>(x).value, As<MMX>(y).value)));
7227 }
7228
7229 RValue<Short4> por(RValue<Short4> x, RValue<Short4> y)
7230 {
7231 Module *module = Nucleus::getModule();
7232 llvm::Function *por = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_por);
7233
7234 return As<Short4>(RValue<MMX>(Nucleus::createCall(por, As<MMX>(x).value, As<MMX>(y).value)));
7235 }
7236
7237 RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y)
7238 {
7239 Module *module = Nucleus::getModule();
7240 llvm::Function *pxor = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pxor);
7241
7242 return As<Short4>(RValue<MMX>(Nucleus::createCall(pxor, As<MMX>(x).value, As<MMX>(y).value)));
7243 }
7244
7245 RValue<Short4> pshufw(RValue<Short4> x, unsigned char y)
7246 {
7247 Module *module = Nucleus::getModule();
7248 llvm::Function *pshufw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_pshuf_w);
7249
7250 return As<Short4>(RValue<MMX>(Nucleus::createCall(pshufw, As<MMX>(x).value, Nucleus::createConstantByte(y))));
7251 }
7252
7253 RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y)
7254 {
7255 Module *module = Nucleus::getModule();
7256 llvm::Function *punpcklwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklwd);
7257
7258 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpcklwd, As<MMX>(x).value, As<MMX>(y).value)));
7259 }
7260
7261 RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y)
7262 {
7263 Module *module = Nucleus::getModule();
7264 llvm::Function *punpckhwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhwd);
7265
7266 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpckhwd, As<MMX>(x).value, As<MMX>(y).value)));
7267 }
7268
7269 RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i)
7270 {
7271 Module *module = Nucleus::getModule();
7272 llvm::Function *pinsrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pinsr_w);
7273
7274 return As<Short4>(RValue<MMX>(Nucleus::createCall(pinsrw, As<MMX>(x).value, y.value, Nucleus::createConstantInt(i))));
7275 }
7276
7277 RValue<Int> pextrw(RValue<Short4> x, unsigned int i)
7278 {
7279 Module *module = Nucleus::getModule();
7280 llvm::Function *pextrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pextr_w);
7281
7282 return RValue<Int>(Nucleus::createCall(pextrw, As<MMX>(x).value, Nucleus::createConstantInt(i)));
7283 }
7284
7285 RValue<Long1> punpckldq(RValue<Int2> x, RValue<Int2> y)
7286 {
7287 Module *module = Nucleus::getModule();
7288 llvm::Function *punpckldq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckldq);
7289
7290 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckldq, As<MMX>(x).value, As<MMX>(y).value)));
7291 }
7292
7293 RValue<Long1> punpckhdq(RValue<Int2> x, RValue<Int2> y)
7294 {
7295 Module *module = Nucleus::getModule();
7296 llvm::Function *punpckhdq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhdq);
7297
7298 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckhdq, As<MMX>(x).value, As<MMX>(y).value)));
7299 }
7300
7301 RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y)
7302 {
7303 Module *module = Nucleus::getModule();
7304 llvm::Function *punpcklbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklbw);
7305
7306 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpcklbw, As<MMX>(x).value, As<MMX>(y).value)));
7307 }
7308
7309 RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y)
7310 {
7311 Module *module = Nucleus::getModule();
7312 llvm::Function *punpckhbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhbw);
7313
7314 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpckhbw, As<MMX>(x).value, As<MMX>(y).value)));
7315 }
7316
7317 RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y)
7318 {
7319 Module *module = Nucleus::getModule();
7320 llvm::Function *paddb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_b);
7321
7322 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddb, As<MMX>(x).value, As<MMX>(y).value)));
7323 }
7324
7325 RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y)
7326 {
7327 Module *module = Nucleus::getModule();
7328 llvm::Function *psubb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_b);
7329
7330 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubb, As<MMX>(x).value, As<MMX>(y).value)));
7331 }
7332
7333 RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y)
7334 {
7335 Module *module = Nucleus::getModule();
7336 llvm::Function *paddd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_d);
7337
7338 return As<Int2>(RValue<MMX>(Nucleus::createCall(paddd, As<MMX>(x).value, As<MMX>(y).value)));
7339 }
7340
7341 RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y)
7342 {
7343 Module *module = Nucleus::getModule();
7344 llvm::Function *psubd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_d);
7345
7346 return As<Int2>(RValue<MMX>(Nucleus::createCall(psubd, As<MMX>(x).value, As<MMX>(y).value)));
7347 }
7348
7349 RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007350 {
7351 Module *module = Nucleus::getModule();
7352 llvm::Function *pavgw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pavg_w);
7353
John Bauman19bac1e2014-05-06 15:23:49 -04007354 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pavgw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007355 }
7356
John Bauman19bac1e2014-05-06 15:23:49 -04007357 RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007358 {
7359 Module *module = Nucleus::getModule();
7360 llvm::Function *pmaxsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmaxs_w);
7361
John Bauman19bac1e2014-05-06 15:23:49 -04007362 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmaxsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007363 }
7364
John Bauman19bac1e2014-05-06 15:23:49 -04007365 RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007366 {
7367 Module *module = Nucleus::getModule();
7368 llvm::Function *pminsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmins_w);
7369
John Bauman19bac1e2014-05-06 15:23:49 -04007370 return As<Short4>(RValue<MMX>(Nucleus::createCall(pminsw, 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> pcmpgtw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007374 {
7375 Module *module = Nucleus::getModule();
7376 llvm::Function *pcmpgtw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_w);
7377
John Bauman19bac1e2014-05-06 15:23:49 -04007378 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpgtw, 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> pcmpeqw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007382 {
7383 Module *module = Nucleus::getModule();
7384 llvm::Function *pcmpeqw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_w);
7385
John Bauman19bac1e2014-05-06 15:23:49 -04007386 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpeqw, 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<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007390 {
7391 Module *module = Nucleus::getModule();
7392 llvm::Function *pcmpgtb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_b);
7393
John Bauman19bac1e2014-05-06 15:23:49 -04007394 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpgtb, 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<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007398 {
7399 Module *module = Nucleus::getModule();
7400 llvm::Function *pcmpeqb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_b);
7401
John Bauman19bac1e2014-05-06 15:23:49 -04007402 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpeqb, 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<Short4> packssdw(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04007406 {
7407 Module *module = Nucleus::getModule();
7408 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packssdw);
7409
John Bauman19bac1e2014-05-06 15:23:49 -04007410 return As<Short4>(RValue<MMX>(Nucleus::createCall(packssdw, 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<Short8> packssdw(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007414 {
7415 if(CPUID::supportsSSE2())
7416 {
7417 Module *module = Nucleus::getModule();
7418 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_packssdw_128);
7419
7420 return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value));
7421 }
7422 else
7423 {
7424 Int2 loX = Int2(x);
7425 Int2 hiX = Int2(Swizzle(x, 0xEE));
7426
7427 Int2 loY = Int2(y);
7428 Int2 hiY = Int2(Swizzle(y, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007429
John Bauman89401822014-05-06 15:04:28 -04007430 Short4 lo = x86::packssdw(loX, hiX);
7431 Short4 hi = x86::packssdw(loY, hiY);
John Bauman66b8ab22014-05-06 15:57:45 -04007432
John Bauman89401822014-05-06 15:04:28 -04007433 return Concatenate(lo, hi);
7434 }
7435 }
7436
John Bauman19bac1e2014-05-06 15:23:49 -04007437 RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007438 {
7439 Module *module = Nucleus::getModule();
7440 llvm::Function *packsswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packsswb);
7441
John Bauman19bac1e2014-05-06 15:23:49 -04007442 return As<SByte8>(RValue<MMX>(Nucleus::createCall(packsswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007443 }
7444
John Bauman19bac1e2014-05-06 15:23:49 -04007445 RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007446 {
7447 Module *module = Nucleus::getModule();
7448 llvm::Function *packuswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packuswb);
7449
John Bauman19bac1e2014-05-06 15:23:49 -04007450 return As<Byte8>(RValue<MMX>(Nucleus::createCall(packuswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007451 }
7452
John Bauman19bac1e2014-05-06 15:23:49 -04007453 RValue<UShort8> packusdw(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04007454 {
7455 if(CPUID::supportsSSE4_1())
7456 {
7457 Module *module = Nucleus::getModule();
7458 llvm::Function *packusdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_packusdw);
John Bauman66b8ab22014-05-06 15:57:45 -04007459
John Bauman89401822014-05-06 15:04:28 -04007460 return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value));
7461 }
7462 else
7463 {
7464 // FIXME: Not an exact replacement!
John Bauman19bac1e2014-05-06 15:23:49 -04007465 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 -04007466 }
7467 }
7468
John Bauman19bac1e2014-05-06 15:23:49 -04007469 RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007470 {
7471 Module *module = Nucleus::getModule();
7472 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_w);
7473
John Bauman19bac1e2014-05-06 15:23:49 -04007474 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007475 }
7476
John Bauman19bac1e2014-05-06 15:23:49 -04007477 RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007478 {
7479 Module *module = Nucleus::getModule();
7480 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_w);
7481
7482 return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y)));
7483 }
7484
John Bauman19bac1e2014-05-06 15:23:49 -04007485 RValue<Short4> psraw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007486 {
7487 Module *module = Nucleus::getModule();
7488 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_w);
7489
John Bauman19bac1e2014-05-06 15:23:49 -04007490 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, 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<Short8> psraw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007494 {
7495 Module *module = Nucleus::getModule();
7496 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_w);
7497
7498 return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y)));
7499 }
7500
John Bauman19bac1e2014-05-06 15:23:49 -04007501 RValue<Short4> psllw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007502 {
7503 Module *module = Nucleus::getModule();
7504 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_w);
7505
John Bauman19bac1e2014-05-06 15:23:49 -04007506 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, 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> psllw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007510 {
7511 Module *module = Nucleus::getModule();
7512 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_w);
7513
7514 return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y)));
7515 }
7516
John Bauman19bac1e2014-05-06 15:23:49 -04007517 RValue<Int2> pslld(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007518 {
7519 Module *module = Nucleus::getModule();
7520 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_d);
7521
John Bauman19bac1e2014-05-06 15:23:49 -04007522 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, 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<Int4> pslld(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007526 {
7527 if(CPUID::supportsSSE2())
7528 {
7529 Module *module = Nucleus::getModule();
7530 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_d);
7531
7532 return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y)));
7533 }
7534 else
7535 {
7536 Int2 lo = Int2(x);
7537 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007538
John Bauman89401822014-05-06 15:04:28 -04007539 lo = x86::pslld(lo, y);
7540 hi = x86::pslld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007541
John Bauman89401822014-05-06 15:04:28 -04007542 return Concatenate(lo, hi);
7543 }
7544 }
7545
John Bauman19bac1e2014-05-06 15:23:49 -04007546 RValue<Int2> psrad(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007547 {
7548 Module *module = Nucleus::getModule();
7549 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_d);
7550
John Bauman19bac1e2014-05-06 15:23:49 -04007551 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrad, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007552 }
7553
John Bauman19bac1e2014-05-06 15:23:49 -04007554 RValue<Int4> psrad(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007555 {
7556 if(CPUID::supportsSSE2())
7557 {
7558 Module *module = Nucleus::getModule();
7559 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_d);
7560
7561 return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y)));
7562 }
7563 else
7564 {
7565 Int2 lo = Int2(x);
7566 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007567
John Bauman89401822014-05-06 15:04:28 -04007568 lo = x86::psrad(lo, y);
7569 hi = x86::psrad(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007570
John Bauman89401822014-05-06 15:04:28 -04007571 return Concatenate(lo, hi);
7572 }
7573 }
7574
John Bauman19bac1e2014-05-06 15:23:49 -04007575 RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007576 {
7577 Module *module = Nucleus::getModule();
7578 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_d);
7579
John Bauman19bac1e2014-05-06 15:23:49 -04007580 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007581 }
7582
John Bauman19bac1e2014-05-06 15:23:49 -04007583 RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007584 {
7585 if(CPUID::supportsSSE2())
7586 {
7587 Module *module = Nucleus::getModule();
7588 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_d);
7589
7590 return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y)));
7591 }
7592 else
7593 {
7594 UInt2 lo = As<UInt2>(Int2(As<Int4>(x)));
7595 UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE)));
John Bauman66b8ab22014-05-06 15:57:45 -04007596
John Bauman89401822014-05-06 15:04:28 -04007597 lo = x86::psrld(lo, y);
7598 hi = x86::psrld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007599
John Bauman89401822014-05-06 15:04:28 -04007600 return Concatenate(lo, hi);
7601 }
7602 }
7603
John Bauman19bac1e2014-05-06 15:23:49 -04007604 RValue<UShort4> psrlw(RValue<UShort4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007605 {
7606 Module *module = Nucleus::getModule();
7607 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_w);
7608
John Bauman19bac1e2014-05-06 15:23:49 -04007609 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007610 }
7611
John Bauman19bac1e2014-05-06 15:23:49 -04007612 RValue<Short4> psraw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007613 {
7614 Module *module = Nucleus::getModule();
7615 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_w);
7616
John Bauman19bac1e2014-05-06 15:23:49 -04007617 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007618 }
7619
John Bauman19bac1e2014-05-06 15:23:49 -04007620 RValue<Short4> psllw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007621 {
7622 Module *module = Nucleus::getModule();
7623 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_w);
7624
John Bauman19bac1e2014-05-06 15:23:49 -04007625 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, 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<Int2> pslld(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007629 {
7630 Module *module = Nucleus::getModule();
7631 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_d);
7632
John Bauman19bac1e2014-05-06 15:23:49 -04007633 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, 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<UInt2> psrld(RValue<UInt2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007637 {
7638 Module *module = Nucleus::getModule();
7639 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_d);
7640
John Bauman19bac1e2014-05-06 15:23:49 -04007641 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, 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> psrad(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007645 {
7646 Module *module = Nucleus::getModule();
7647 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_d);
7648
John Bauman19bac1e2014-05-06 15:23:49 -04007649 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrld, 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<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y)
7653 {
7654 Module *module = Nucleus::getModule();
7655 llvm::Function *pmaxsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxsd);
7656
7657 return RValue<Int4>(Nucleus::createCall(pmaxsd, x.value, y.value));
7658 }
7659
7660 RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y)
7661 {
7662 Module *module = Nucleus::getModule();
7663 llvm::Function *pminsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminsd);
7664
7665 return RValue<Int4>(Nucleus::createCall(pminsd, x.value, y.value));
7666 }
7667
7668 RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y)
7669 {
7670 Module *module = Nucleus::getModule();
7671 llvm::Function *pmaxud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxud);
7672
John Bauman66b8ab22014-05-06 15:57:45 -04007673 return RValue<UInt4>(Nucleus::createCall(pmaxud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007674 }
7675
7676 RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y)
7677 {
7678 Module *module = Nucleus::getModule();
7679 llvm::Function *pminud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminud);
7680
John Bauman66b8ab22014-05-06 15:57:45 -04007681 return RValue<UInt4>(Nucleus::createCall(pminud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007682 }
7683
7684 RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007685 {
7686 Module *module = Nucleus::getModule();
7687 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulh_w);
7688
John Bauman19bac1e2014-05-06 15:23:49 -04007689 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmulhw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007690 }
7691
John Bauman19bac1e2014-05-06 15:23:49 -04007692 RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007693 {
7694 Module *module = Nucleus::getModule();
7695 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulhu_w);
7696
John Bauman19bac1e2014-05-06 15:23:49 -04007697 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pmulhuw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007698 }
7699
John Bauman19bac1e2014-05-06 15:23:49 -04007700 RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007701 {
7702 Module *module = Nucleus::getModule();
7703 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmadd_wd);
7704
John Bauman19bac1e2014-05-06 15:23:49 -04007705 return As<Int2>(RValue<MMX>(Nucleus::createCall(pmaddwd, 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<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007709 {
7710 Module *module = Nucleus::getModule();
7711 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulh_w);
7712
7713 return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value));
7714 }
7715
John Bauman19bac1e2014-05-06 15:23:49 -04007716 RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04007717 {
7718 Module *module = Nucleus::getModule();
7719 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulhu_w);
7720
7721 return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value));
7722 }
7723
John Bauman19bac1e2014-05-06 15:23:49 -04007724 RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007725 {
7726 Module *module = Nucleus::getModule();
7727 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmadd_wd);
7728
7729 return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value));
7730 }
7731
John Bauman19bac1e2014-05-06 15:23:49 -04007732 RValue<Int> movmskps(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04007733 {
7734 Module *module = Nucleus::getModule();
7735 llvm::Function *movmskps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_movmsk_ps);
7736
7737 return RValue<Int>(Nucleus::createCall(movmskps, x.value));
7738 }
7739
John Bauman19bac1e2014-05-06 15:23:49 -04007740 RValue<Int> pmovmskb(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04007741 {
7742 Module *module = Nucleus::getModule();
7743 llvm::Function *pmovmskb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmovmskb);
7744
John Bauman19bac1e2014-05-06 15:23:49 -04007745 return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value));
John Bauman89401822014-05-06 15:04:28 -04007746 }
7747
John Bauman66b8ab22014-05-06 15:57:45 -04007748 //RValue<Int2> movd(RValue<Pointer<Int> > x)
John Bauman89401822014-05-06 15:04:28 -04007749 //{
7750 // Value *element = Nucleus::createLoad(x.value);
7751
7752 //// Value *int2 = UndefValue::get(Int2::getType());
7753 //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0));
7754
7755 // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType());
7756
7757 // return RValue<Int2>(int2);
7758 //}
7759
John Bauman19bac1e2014-05-06 15:23:49 -04007760 //RValue<Int2> movdq2q(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007761 //{
7762 // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType());
7763 // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0));
7764
7765 // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType()));
7766 //}
7767
John Bauman19bac1e2014-05-06 15:23:49 -04007768 RValue<Int4> pmovzxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007769 {
7770 Module *module = Nucleus::getModule();
7771 llvm::Function *pmovzxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007772
John Bauman89401822014-05-06 15:04:28 -04007773 return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType())));
7774 }
7775
John Bauman19bac1e2014-05-06 15:23:49 -04007776 RValue<Int4> pmovsxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007777 {
7778 Module *module = Nucleus::getModule();
7779 llvm::Function *pmovsxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007780
John Bauman89401822014-05-06 15:04:28 -04007781 return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType())));
7782 }
7783
John Bauman19bac1e2014-05-06 15:23:49 -04007784 RValue<Int4> pmovzxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007785 {
7786 Module *module = Nucleus::getModule();
7787 llvm::Function *pmovzxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007788
John Bauman89401822014-05-06 15:04:28 -04007789 return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType())));
7790 }
7791
John Bauman19bac1e2014-05-06 15:23:49 -04007792 RValue<Int4> pmovsxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007793 {
7794 Module *module = Nucleus::getModule();
7795 llvm::Function *pmovsxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007796
John Bauman89401822014-05-06 15:04:28 -04007797 return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType())));
7798 }
7799
7800 void emms()
7801 {
7802 Module *module = Nucleus::getModule();
7803 llvm::Function *emms = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_emms);
7804
7805 Nucleus::createCall(emms);
7806 }
7807 }
7808}