blob: 49ec8597c89c8032721d785860b92884b9283106 [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
936 Byte::Byte()
937 {
John Bauman89401822014-05-06 15:04:28 -0400938 }
939
940 Byte::Byte(int x)
941 {
John Bauman66b8ab22014-05-06 15:57:45 -0400942 storeValue(Nucleus::createConstantByte((unsigned char)x));
John Bauman89401822014-05-06 15:04:28 -0400943 }
944
945 Byte::Byte(unsigned char x)
946 {
John Bauman66b8ab22014-05-06 15:57:45 -0400947 storeValue(Nucleus::createConstantByte(x));
John Bauman89401822014-05-06 15:04:28 -0400948 }
949
John Bauman19bac1e2014-05-06 15:23:49 -0400950 Byte::Byte(RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -0400951 {
John Bauman66b8ab22014-05-06 15:57:45 -0400952 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400953 }
954
955 Byte::Byte(const Byte &rhs)
956 {
John Bauman66b8ab22014-05-06 15:57:45 -0400957 Value *value = rhs.loadValue();
958 storeValue(value);
959 }
John Bauman89401822014-05-06 15:04:28 -0400960
John Bauman66b8ab22014-05-06 15:57:45 -0400961 Byte::Byte(const Reference<Byte> &rhs)
962 {
963 Value *value = rhs.loadValue();
964 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400965 }
966
John Bauman19bac1e2014-05-06 15:23:49 -0400967 RValue<Byte> Byte::operator=(RValue<Byte> rhs) const
John Bauman89401822014-05-06 15:04:28 -0400968 {
John Bauman66b8ab22014-05-06 15:57:45 -0400969 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -0400970
971 return rhs;
972 }
973
974 RValue<Byte> Byte::operator=(const Byte &rhs) const
975 {
John Bauman66b8ab22014-05-06 15:57:45 -0400976 Value *value = rhs.loadValue();
977 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -0400978
979 return RValue<Byte>(value);
980 }
981
John Bauman66b8ab22014-05-06 15:57:45 -0400982 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) const
John Bauman89401822014-05-06 15:04:28 -0400983 {
John Bauman66b8ab22014-05-06 15:57:45 -0400984 Value *value = rhs.loadValue();
985 storeValue(value);
986
987 return RValue<Byte>(value);
John Bauman89401822014-05-06 15:04:28 -0400988 }
989
John Bauman19bac1e2014-05-06 15:23:49 -0400990 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -0400991 {
992 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
993 }
994
John Bauman19bac1e2014-05-06 15:23:49 -0400995 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -0400996 {
997 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
998 }
999
John Bauman19bac1e2014-05-06 15:23:49 -04001000 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001001 {
1002 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1003 }
1004
John Bauman19bac1e2014-05-06 15:23:49 -04001005 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001006 {
1007 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1008 }
1009
John Bauman19bac1e2014-05-06 15:23:49 -04001010 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001011 {
1012 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1013 }
1014
John Bauman19bac1e2014-05-06 15:23:49 -04001015 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001016 {
1017 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1018 }
1019
John Bauman19bac1e2014-05-06 15:23:49 -04001020 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001021 {
1022 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1023 }
1024
John Bauman19bac1e2014-05-06 15:23:49 -04001025 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001026 {
1027 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1028 }
1029
John Bauman19bac1e2014-05-06 15:23:49 -04001030 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001031 {
1032 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1033 }
1034
John Bauman19bac1e2014-05-06 15:23:49 -04001035 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001036 {
1037 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1038 }
1039
John Bauman19bac1e2014-05-06 15:23:49 -04001040 RValue<Byte> operator+=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001041 {
1042 return lhs = lhs + rhs;
1043 }
1044
John Bauman19bac1e2014-05-06 15:23:49 -04001045 RValue<Byte> operator-=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001046 {
1047 return lhs = lhs - rhs;
1048 }
1049
John Bauman19bac1e2014-05-06 15:23:49 -04001050 RValue<Byte> operator*=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001051 {
1052 return lhs = lhs * rhs;
1053 }
1054
John Bauman19bac1e2014-05-06 15:23:49 -04001055 RValue<Byte> operator/=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001056 {
1057 return lhs = lhs / rhs;
1058 }
1059
John Bauman19bac1e2014-05-06 15:23:49 -04001060 RValue<Byte> operator%=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001061 {
1062 return lhs = lhs % rhs;
1063 }
1064
John Bauman19bac1e2014-05-06 15:23:49 -04001065 RValue<Byte> operator&=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001066 {
1067 return lhs = lhs & rhs;
1068 }
1069
John Bauman19bac1e2014-05-06 15:23:49 -04001070 RValue<Byte> operator|=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001071 {
1072 return lhs = lhs | rhs;
1073 }
1074
John Bauman19bac1e2014-05-06 15:23:49 -04001075 RValue<Byte> operator^=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001076 {
1077 return lhs = lhs ^ rhs;
1078 }
1079
John Bauman19bac1e2014-05-06 15:23:49 -04001080 RValue<Byte> operator<<=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001081 {
1082 return lhs = lhs << rhs;
1083 }
1084
John Bauman19bac1e2014-05-06 15:23:49 -04001085 RValue<Byte> operator>>=(const Byte &lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001086 {
1087 return lhs = lhs >> rhs;
1088 }
1089
John Bauman19bac1e2014-05-06 15:23:49 -04001090 RValue<Byte> operator+(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001091 {
1092 return val;
1093 }
1094
John Bauman19bac1e2014-05-06 15:23:49 -04001095 RValue<Byte> operator-(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001096 {
1097 return RValue<Byte>(Nucleus::createNeg(val.value));
1098 }
1099
John Bauman19bac1e2014-05-06 15:23:49 -04001100 RValue<Byte> operator~(RValue<Byte> val)
John Bauman89401822014-05-06 15:04:28 -04001101 {
1102 return RValue<Byte>(Nucleus::createNot(val.value));
1103 }
1104
1105 RValue<Byte> operator++(const Byte &val, int) // Post-increment
1106 {
1107 RValue<Byte> res = val;
1108
1109 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001110 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001111
1112 return res;
1113 }
1114
1115 const Byte &operator++(const Byte &val) // Pre-increment
1116 {
John Bauman66b8ab22014-05-06 15:57:45 -04001117 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
1118 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001119
1120 return val;
1121 }
1122
1123 RValue<Byte> operator--(const Byte &val, int) // Post-decrement
1124 {
1125 RValue<Byte> res = val;
1126
1127 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001128 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001129
1130 return res;
1131 }
1132
1133 const Byte &operator--(const Byte &val) // Pre-decrement
1134 {
John Bauman66b8ab22014-05-06 15:57:45 -04001135 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1));
1136 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001137
1138 return val;
1139 }
1140
John Bauman19bac1e2014-05-06 15:23:49 -04001141 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001142 {
1143 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1144 }
1145
John Bauman19bac1e2014-05-06 15:23:49 -04001146 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001147 {
1148 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1149 }
1150
John Bauman19bac1e2014-05-06 15:23:49 -04001151 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001152 {
1153 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1154 }
1155
John Bauman19bac1e2014-05-06 15:23:49 -04001156 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001157 {
1158 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1159 }
1160
John Bauman19bac1e2014-05-06 15:23:49 -04001161 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001162 {
1163 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1164 }
1165
John Bauman19bac1e2014-05-06 15:23:49 -04001166 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001167 {
1168 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1169 }
1170
John Bauman19bac1e2014-05-06 15:23:49 -04001171 Type *Byte::getType()
John Bauman89401822014-05-06 15:04:28 -04001172 {
1173 return Type::getInt8Ty(*Nucleus::getContext());
1174 }
1175
1176 SByte::SByte(Argument *argument)
1177 {
John Bauman66b8ab22014-05-06 15:57:45 -04001178 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04001179 }
1180
1181 SByte::SByte()
1182 {
John Bauman89401822014-05-06 15:04:28 -04001183 }
1184
1185 SByte::SByte(signed char x)
1186 {
John Bauman66b8ab22014-05-06 15:57:45 -04001187 storeValue(Nucleus::createConstantByte(x));
John Bauman89401822014-05-06 15:04:28 -04001188 }
1189
John Bauman19bac1e2014-05-06 15:23:49 -04001190 SByte::SByte(RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001191 {
John Bauman66b8ab22014-05-06 15:57:45 -04001192 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001193 }
1194
1195 SByte::SByte(const SByte &rhs)
1196 {
John Bauman66b8ab22014-05-06 15:57:45 -04001197 Value *value = rhs.loadValue();
1198 storeValue(value);
1199 }
John Bauman89401822014-05-06 15:04:28 -04001200
John Bauman66b8ab22014-05-06 15:57:45 -04001201 SByte::SByte(const Reference<SByte> &rhs)
1202 {
1203 Value *value = rhs.loadValue();
1204 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001205 }
1206
John Bauman19bac1e2014-05-06 15:23:49 -04001207 RValue<SByte> SByte::operator=(RValue<SByte> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001208 {
John Bauman66b8ab22014-05-06 15:57:45 -04001209 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001210
1211 return rhs;
1212 }
1213
1214 RValue<SByte> SByte::operator=(const SByte &rhs) const
1215 {
John Bauman66b8ab22014-05-06 15:57:45 -04001216 Value *value = rhs.loadValue();
1217 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001218
1219 return RValue<SByte>(value);
1220 }
1221
John Bauman66b8ab22014-05-06 15:57:45 -04001222 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001223 {
John Bauman66b8ab22014-05-06 15:57:45 -04001224 Value *value = rhs.loadValue();
1225 storeValue(value);
1226
1227 return RValue<SByte>(value);
John Bauman89401822014-05-06 15:04:28 -04001228 }
1229
John Bauman19bac1e2014-05-06 15:23:49 -04001230 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001231 {
1232 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1233 }
1234
John Bauman19bac1e2014-05-06 15:23:49 -04001235 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001236 {
1237 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1238 }
1239
John Bauman19bac1e2014-05-06 15:23:49 -04001240 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001241 {
1242 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1243 }
1244
John Bauman19bac1e2014-05-06 15:23:49 -04001245 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001246 {
1247 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1248 }
1249
John Bauman19bac1e2014-05-06 15:23:49 -04001250 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001251 {
1252 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1253 }
1254
John Bauman19bac1e2014-05-06 15:23:49 -04001255 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001256 {
1257 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1258 }
1259
John Bauman19bac1e2014-05-06 15:23:49 -04001260 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001261 {
1262 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1263 }
1264
John Bauman19bac1e2014-05-06 15:23:49 -04001265 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001266 {
1267 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1268 }
1269
John Bauman19bac1e2014-05-06 15:23:49 -04001270 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001271 {
1272 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1273 }
1274
John Bauman19bac1e2014-05-06 15:23:49 -04001275 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001276 {
1277 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1278 }
1279
John Bauman19bac1e2014-05-06 15:23:49 -04001280 RValue<SByte> operator+=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001281 {
1282 return lhs = lhs + rhs;
1283 }
1284
John Bauman19bac1e2014-05-06 15:23:49 -04001285 RValue<SByte> operator-=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001286 {
1287 return lhs = lhs - rhs;
1288 }
1289
John Bauman19bac1e2014-05-06 15:23:49 -04001290 RValue<SByte> operator*=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001291 {
1292 return lhs = lhs * rhs;
1293 }
1294
John Bauman19bac1e2014-05-06 15:23:49 -04001295 RValue<SByte> operator/=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001296 {
1297 return lhs = lhs / rhs;
1298 }
1299
John Bauman19bac1e2014-05-06 15:23:49 -04001300 RValue<SByte> operator%=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001301 {
1302 return lhs = lhs % rhs;
1303 }
1304
John Bauman19bac1e2014-05-06 15:23:49 -04001305 RValue<SByte> operator&=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001306 {
1307 return lhs = lhs & rhs;
1308 }
1309
John Bauman19bac1e2014-05-06 15:23:49 -04001310 RValue<SByte> operator|=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001311 {
1312 return lhs = lhs | rhs;
1313 }
1314
John Bauman19bac1e2014-05-06 15:23:49 -04001315 RValue<SByte> operator^=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001316 {
1317 return lhs = lhs ^ rhs;
1318 }
1319
John Bauman19bac1e2014-05-06 15:23:49 -04001320 RValue<SByte> operator<<=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001321 {
1322 return lhs = lhs << rhs;
1323 }
1324
John Bauman19bac1e2014-05-06 15:23:49 -04001325 RValue<SByte> operator>>=(const SByte &lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001326 {
1327 return lhs = lhs >> rhs;
1328 }
1329
John Bauman19bac1e2014-05-06 15:23:49 -04001330 RValue<SByte> operator+(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001331 {
1332 return val;
1333 }
1334
John Bauman19bac1e2014-05-06 15:23:49 -04001335 RValue<SByte> operator-(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001336 {
1337 return RValue<SByte>(Nucleus::createNeg(val.value));
1338 }
1339
John Bauman19bac1e2014-05-06 15:23:49 -04001340 RValue<SByte> operator~(RValue<SByte> val)
John Bauman89401822014-05-06 15:04:28 -04001341 {
1342 return RValue<SByte>(Nucleus::createNot(val.value));
1343 }
1344
1345 RValue<SByte> operator++(const SByte &val, int) // Post-increment
1346 {
1347 RValue<SByte> res = val;
1348
1349 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001350 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001351
1352 return res;
1353 }
1354
1355 const SByte &operator++(const SByte &val) // Pre-increment
1356 {
John Bauman66b8ab22014-05-06 15:57:45 -04001357 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1));
1358 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001359
1360 return val;
1361 }
1362
1363 RValue<SByte> operator--(const SByte &val, int) // Post-decrement
1364 {
1365 RValue<SByte> res = val;
1366
1367 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001368 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001369
1370 return res;
1371 }
1372
1373 const SByte &operator--(const SByte &val) // Pre-decrement
1374 {
John Bauman66b8ab22014-05-06 15:57:45 -04001375 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1));
1376 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001377
1378 return val;
1379 }
1380
John Bauman19bac1e2014-05-06 15:23:49 -04001381 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001382 {
1383 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1384 }
1385
John Bauman19bac1e2014-05-06 15:23:49 -04001386 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001387 {
1388 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1389 }
1390
John Bauman19bac1e2014-05-06 15:23:49 -04001391 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001392 {
1393 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1394 }
1395
John Bauman19bac1e2014-05-06 15:23:49 -04001396 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001397 {
1398 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1399 }
1400
John Bauman19bac1e2014-05-06 15:23:49 -04001401 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001402 {
1403 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1404 }
1405
John Bauman19bac1e2014-05-06 15:23:49 -04001406 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
John Bauman89401822014-05-06 15:04:28 -04001407 {
1408 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1409 }
1410
John Bauman19bac1e2014-05-06 15:23:49 -04001411 Type *SByte::getType()
John Bauman89401822014-05-06 15:04:28 -04001412 {
1413 return Type::getInt8Ty(*Nucleus::getContext());
1414 }
1415
1416 Short::Short(Argument *argument)
1417 {
John Bauman66b8ab22014-05-06 15:57:45 -04001418 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04001419 }
1420
John Bauman19bac1e2014-05-06 15:23:49 -04001421 Short::Short(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04001422 {
John Bauman89401822014-05-06 15:04:28 -04001423 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1424
John Bauman66b8ab22014-05-06 15:57:45 -04001425 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04001426 }
1427
1428 Short::Short()
1429 {
John Bauman89401822014-05-06 15:04:28 -04001430 }
1431
1432 Short::Short(short x)
1433 {
John Bauman66b8ab22014-05-06 15:57:45 -04001434 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001435 }
1436
John Bauman19bac1e2014-05-06 15:23:49 -04001437 Short::Short(RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001438 {
John Bauman66b8ab22014-05-06 15:57:45 -04001439 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001440 }
1441
1442 Short::Short(const Short &rhs)
1443 {
John Bauman66b8ab22014-05-06 15:57:45 -04001444 Value *value = rhs.loadValue();
1445 storeValue(value);
1446 }
John Bauman89401822014-05-06 15:04:28 -04001447
John Bauman66b8ab22014-05-06 15:57:45 -04001448 Short::Short(const Reference<Short> &rhs)
1449 {
1450 Value *value = rhs.loadValue();
1451 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001452 }
1453
John Bauman19bac1e2014-05-06 15:23:49 -04001454 RValue<Short> Short::operator=(RValue<Short> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001455 {
John Bauman66b8ab22014-05-06 15:57:45 -04001456 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001457
1458 return rhs;
1459 }
1460
1461 RValue<Short> Short::operator=(const Short &rhs) const
1462 {
John Bauman66b8ab22014-05-06 15:57:45 -04001463 Value *value = rhs.loadValue();
1464 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001465
1466 return RValue<Short>(value);
1467 }
1468
John Bauman66b8ab22014-05-06 15:57:45 -04001469 RValue<Short> Short::operator=(const Reference<Short> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001470 {
John Bauman66b8ab22014-05-06 15:57:45 -04001471 Value *value = rhs.loadValue();
1472 storeValue(value);
1473
1474 return RValue<Short>(value);
John Bauman89401822014-05-06 15:04:28 -04001475 }
1476
John Bauman19bac1e2014-05-06 15:23:49 -04001477 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001478 {
1479 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
1480 }
1481
John Bauman19bac1e2014-05-06 15:23:49 -04001482 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001483 {
1484 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
1485 }
1486
John Bauman19bac1e2014-05-06 15:23:49 -04001487 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001488 {
1489 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
1490 }
1491
John Bauman19bac1e2014-05-06 15:23:49 -04001492 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001493 {
1494 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
1495 }
1496
John Bauman19bac1e2014-05-06 15:23:49 -04001497 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001498 {
1499 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
1500 }
1501
John Bauman19bac1e2014-05-06 15:23:49 -04001502 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001503 {
1504 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
1505 }
1506
John Bauman19bac1e2014-05-06 15:23:49 -04001507 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001508 {
1509 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
1510 }
1511
John Bauman19bac1e2014-05-06 15:23:49 -04001512 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001513 {
1514 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
1515 }
1516
John Bauman19bac1e2014-05-06 15:23:49 -04001517 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001518 {
1519 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
1520 }
1521
John Bauman19bac1e2014-05-06 15:23:49 -04001522 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001523 {
1524 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
1525 }
1526
John Bauman19bac1e2014-05-06 15:23:49 -04001527 RValue<Short> operator+=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001528 {
1529 return lhs = lhs + rhs;
1530 }
1531
John Bauman19bac1e2014-05-06 15:23:49 -04001532 RValue<Short> operator-=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001533 {
1534 return lhs = lhs - rhs;
1535 }
1536
John Bauman19bac1e2014-05-06 15:23:49 -04001537 RValue<Short> operator*=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001538 {
1539 return lhs = lhs * rhs;
1540 }
1541
John Bauman19bac1e2014-05-06 15:23:49 -04001542 RValue<Short> operator/=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001543 {
1544 return lhs = lhs / rhs;
1545 }
1546
John Bauman19bac1e2014-05-06 15:23:49 -04001547 RValue<Short> operator%=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001548 {
1549 return lhs = lhs % rhs;
1550 }
1551
John Bauman19bac1e2014-05-06 15:23:49 -04001552 RValue<Short> operator&=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001553 {
1554 return lhs = lhs & rhs;
1555 }
1556
John Bauman19bac1e2014-05-06 15:23:49 -04001557 RValue<Short> operator|=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001558 {
1559 return lhs = lhs | rhs;
1560 }
1561
John Bauman19bac1e2014-05-06 15:23:49 -04001562 RValue<Short> operator^=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001563 {
1564 return lhs = lhs ^ rhs;
1565 }
1566
John Bauman19bac1e2014-05-06 15:23:49 -04001567 RValue<Short> operator<<=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001568 {
1569 return lhs = lhs << rhs;
1570 }
1571
John Bauman19bac1e2014-05-06 15:23:49 -04001572 RValue<Short> operator>>=(const Short &lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001573 {
1574 return lhs = lhs >> rhs;
1575 }
1576
John Bauman19bac1e2014-05-06 15:23:49 -04001577 RValue<Short> operator+(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001578 {
1579 return val;
1580 }
1581
John Bauman19bac1e2014-05-06 15:23:49 -04001582 RValue<Short> operator-(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001583 {
1584 return RValue<Short>(Nucleus::createNeg(val.value));
1585 }
1586
John Bauman19bac1e2014-05-06 15:23:49 -04001587 RValue<Short> operator~(RValue<Short> val)
John Bauman89401822014-05-06 15:04:28 -04001588 {
1589 return RValue<Short>(Nucleus::createNot(val.value));
1590 }
1591
1592 RValue<Short> operator++(const Short &val, int) // Post-increment
1593 {
1594 RValue<Short> res = val;
1595
1596 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001597 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001598
1599 return res;
1600 }
1601
1602 const Short &operator++(const Short &val) // Pre-increment
1603 {
John Bauman66b8ab22014-05-06 15:57:45 -04001604 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1));
1605 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001606
1607 return val;
1608 }
1609
1610 RValue<Short> operator--(const Short &val, int) // Post-decrement
1611 {
1612 RValue<Short> res = val;
1613
1614 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001615 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001616
1617 return res;
1618 }
1619
1620 const Short &operator--(const Short &val) // Pre-decrement
1621 {
John Bauman66b8ab22014-05-06 15:57:45 -04001622 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1));
1623 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001624
1625 return val;
1626 }
1627
John Bauman19bac1e2014-05-06 15:23:49 -04001628 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001629 {
1630 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1631 }
1632
John Bauman19bac1e2014-05-06 15:23:49 -04001633 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001634 {
1635 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1636 }
1637
John Bauman19bac1e2014-05-06 15:23:49 -04001638 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001639 {
1640 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1641 }
1642
John Bauman19bac1e2014-05-06 15:23:49 -04001643 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001644 {
1645 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1646 }
1647
John Bauman19bac1e2014-05-06 15:23:49 -04001648 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001649 {
1650 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1651 }
1652
John Bauman19bac1e2014-05-06 15:23:49 -04001653 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
John Bauman89401822014-05-06 15:04:28 -04001654 {
1655 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1656 }
1657
John Bauman19bac1e2014-05-06 15:23:49 -04001658 Type *Short::getType()
John Bauman89401822014-05-06 15:04:28 -04001659 {
1660 return Type::getInt16Ty(*Nucleus::getContext());
1661 }
1662
1663 UShort::UShort(Argument *argument)
1664 {
John Bauman66b8ab22014-05-06 15:57:45 -04001665 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04001666 }
1667
1668 UShort::UShort()
1669 {
John Bauman89401822014-05-06 15:04:28 -04001670 }
1671
1672 UShort::UShort(unsigned short x)
1673 {
John Bauman66b8ab22014-05-06 15:57:45 -04001674 storeValue(Nucleus::createConstantShort(x));
John Bauman89401822014-05-06 15:04:28 -04001675 }
1676
John Bauman19bac1e2014-05-06 15:23:49 -04001677 UShort::UShort(RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001678 {
John Bauman66b8ab22014-05-06 15:57:45 -04001679 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001680 }
1681
1682 UShort::UShort(const UShort &rhs)
1683 {
John Bauman66b8ab22014-05-06 15:57:45 -04001684 Value *value = rhs.loadValue();
1685 storeValue(value);
1686 }
John Bauman89401822014-05-06 15:04:28 -04001687
John Bauman66b8ab22014-05-06 15:57:45 -04001688 UShort::UShort(const Reference<UShort> &rhs)
1689 {
1690 Value *value = rhs.loadValue();
1691 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001692 }
1693
John Bauman19bac1e2014-05-06 15:23:49 -04001694 RValue<UShort> UShort::operator=(RValue<UShort> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001695 {
John Bauman66b8ab22014-05-06 15:57:45 -04001696 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001697
1698 return rhs;
1699 }
1700
1701 RValue<UShort> UShort::operator=(const UShort &rhs) const
1702 {
John Bauman66b8ab22014-05-06 15:57:45 -04001703 Value *value = rhs.loadValue();
1704 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001705
1706 return RValue<UShort>(value);
1707 }
1708
John Bauman66b8ab22014-05-06 15:57:45 -04001709 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04001710 {
John Bauman66b8ab22014-05-06 15:57:45 -04001711 Value *value = rhs.loadValue();
1712 storeValue(value);
1713
1714 return RValue<UShort>(value);
John Bauman89401822014-05-06 15:04:28 -04001715 }
1716
John Bauman19bac1e2014-05-06 15:23:49 -04001717 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001718 {
1719 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
1720 }
1721
John Bauman19bac1e2014-05-06 15:23:49 -04001722 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001723 {
1724 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
1725 }
1726
John Bauman19bac1e2014-05-06 15:23:49 -04001727 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001728 {
1729 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
1730 }
1731
John Bauman19bac1e2014-05-06 15:23:49 -04001732 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001733 {
1734 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
1735 }
1736
John Bauman19bac1e2014-05-06 15:23:49 -04001737 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001738 {
1739 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
1740 }
1741
John Bauman19bac1e2014-05-06 15:23:49 -04001742 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001743 {
1744 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
1745 }
1746
John Bauman19bac1e2014-05-06 15:23:49 -04001747 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001748 {
1749 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
1750 }
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::createXor(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::createShl(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::createLShr(lhs.value, rhs.value));
1765 }
1766
John Bauman19bac1e2014-05-06 15:23:49 -04001767 RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001768 {
1769 return lhs = lhs + rhs;
1770 }
1771
John Bauman19bac1e2014-05-06 15:23:49 -04001772 RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001773 {
1774 return lhs = lhs - rhs;
1775 }
1776
John Bauman19bac1e2014-05-06 15:23:49 -04001777 RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001778 {
1779 return lhs = lhs * rhs;
1780 }
1781
John Bauman19bac1e2014-05-06 15:23:49 -04001782 RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001783 {
1784 return lhs = lhs / rhs;
1785 }
1786
John Bauman19bac1e2014-05-06 15:23:49 -04001787 RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001788 {
1789 return lhs = lhs % rhs;
1790 }
1791
John Bauman19bac1e2014-05-06 15:23:49 -04001792 RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001793 {
1794 return lhs = lhs & rhs;
1795 }
1796
John Bauman19bac1e2014-05-06 15:23:49 -04001797 RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001798 {
1799 return lhs = lhs | rhs;
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+(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001818 {
1819 return val;
1820 }
1821
John Bauman19bac1e2014-05-06 15:23:49 -04001822 RValue<UShort> operator-(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001823 {
1824 return RValue<UShort>(Nucleus::createNeg(val.value));
1825 }
1826
John Bauman19bac1e2014-05-06 15:23:49 -04001827 RValue<UShort> operator~(RValue<UShort> val)
John Bauman89401822014-05-06 15:04:28 -04001828 {
1829 return RValue<UShort>(Nucleus::createNot(val.value));
1830 }
1831
1832 RValue<UShort> operator++(const UShort &val, int) // Post-increment
1833 {
1834 RValue<UShort> res = val;
1835
1836 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001837 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001838
1839 return res;
1840 }
1841
1842 const UShort &operator++(const UShort &val) // Pre-increment
1843 {
John Bauman66b8ab22014-05-06 15:57:45 -04001844 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
1845 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001846
1847 return val;
1848 }
1849
1850 RValue<UShort> operator--(const UShort &val, int) // Post-decrement
1851 {
1852 RValue<UShort> res = val;
1853
1854 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1));
John Bauman66b8ab22014-05-06 15:57:45 -04001855 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001856
1857 return res;
1858 }
1859
1860 const UShort &operator--(const UShort &val) // Pre-decrement
1861 {
John Bauman66b8ab22014-05-06 15:57:45 -04001862 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1));
1863 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04001864
1865 return val;
1866 }
1867
John Bauman19bac1e2014-05-06 15:23:49 -04001868 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001869 {
1870 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1871 }
1872
John Bauman19bac1e2014-05-06 15:23:49 -04001873 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001874 {
1875 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1876 }
1877
John Bauman19bac1e2014-05-06 15:23:49 -04001878 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001879 {
1880 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1881 }
1882
John Bauman19bac1e2014-05-06 15:23:49 -04001883 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001884 {
1885 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1886 }
1887
John Bauman19bac1e2014-05-06 15:23:49 -04001888 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001889 {
1890 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1891 }
1892
John Bauman19bac1e2014-05-06 15:23:49 -04001893 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
John Bauman89401822014-05-06 15:04:28 -04001894 {
1895 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1896 }
1897
John Bauman19bac1e2014-05-06 15:23:49 -04001898 Type *UShort::getType()
John Bauman89401822014-05-06 15:04:28 -04001899 {
1900 return Type::getInt16Ty(*Nucleus::getContext());
1901 }
1902
John Bauman19bac1e2014-05-06 15:23:49 -04001903 Type *Byte4::getType()
John Bauman89401822014-05-06 15:04:28 -04001904 {
1905 #if 0
1906 return VectorType::get(Byte::getType(), 4);
1907 #else
1908 return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
1909 #endif
1910 }
1911
John Bauman19bac1e2014-05-06 15:23:49 -04001912 Type *SByte4::getType()
John Bauman89401822014-05-06 15:04:28 -04001913 {
1914 #if 0
1915 return VectorType::get(SByte::getType(), 4);
1916 #else
1917 return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block
1918 #endif
1919 }
1920
1921 Byte8::Byte8()
1922 {
1923 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001924 }
1925
1926 Byte8::Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
1927 {
1928 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001929
1930 Constant *constantVector[8];
1931 constantVector[0] = Nucleus::createConstantByte(x0);
1932 constantVector[1] = Nucleus::createConstantByte(x1);
1933 constantVector[2] = Nucleus::createConstantByte(x2);
1934 constantVector[3] = Nucleus::createConstantByte(x3);
1935 constantVector[4] = Nucleus::createConstantByte(x4);
1936 constantVector[5] = Nucleus::createConstantByte(x5);
1937 constantVector[6] = Nucleus::createConstantByte(x6);
1938 constantVector[7] = Nucleus::createConstantByte(x7);
John Bauman19bac1e2014-05-06 15:23:49 -04001939 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04001940
John Bauman66b8ab22014-05-06 15:57:45 -04001941 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04001942 }
1943
1944 Byte8::Byte8(int64_t x)
1945 {
1946 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001947
1948 Constant *constantVector[8];
1949 constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
1950 constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
1951 constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
1952 constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
1953 constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
1954 constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
1955 constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
1956 constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
John Bauman19bac1e2014-05-06 15:23:49 -04001957 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04001958
John Bauman66b8ab22014-05-06 15:57:45 -04001959 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04001960 }
1961
John Bauman19bac1e2014-05-06 15:23:49 -04001962 Byte8::Byte8(RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04001963 {
1964 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001965
John Bauman66b8ab22014-05-06 15:57:45 -04001966 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001967 }
1968
1969 Byte8::Byte8(const Byte8 &rhs)
1970 {
1971 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04001972
John Bauman66b8ab22014-05-06 15:57:45 -04001973 Value *value = rhs.loadValue();
1974 storeValue(value);
1975 }
1976
1977 Byte8::Byte8(const Reference<Byte8> &rhs)
1978 {
1979 // xyzw.parent = this;
1980
1981 Value *value = rhs.loadValue();
1982 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04001983 }
1984
John Bauman19bac1e2014-05-06 15:23:49 -04001985 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04001986 {
John Bauman66b8ab22014-05-06 15:57:45 -04001987 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04001988
1989 return rhs;
1990 }
1991
1992 RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const
1993 {
John Bauman66b8ab22014-05-06 15:57:45 -04001994 Value *value = rhs.loadValue();
1995 storeValue(value);
1996
1997 return RValue<Byte8>(value);
1998 }
1999
2000 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const
2001 {
2002 Value *value = rhs.loadValue();
2003 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002004
2005 return RValue<Byte8>(value);
2006 }
2007
John Bauman19bac1e2014-05-06 15:23:49 -04002008 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002009 {
John Bauman19bac1e2014-05-06 15:23:49 -04002010 if(CPUID::supportsMMX2())
2011 {
2012 return x86::paddb(lhs, rhs);
2013 }
2014 else
2015 {
2016 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
2017 }
John Bauman89401822014-05-06 15:04:28 -04002018 }
2019
John Bauman19bac1e2014-05-06 15:23:49 -04002020 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002021 {
John Bauman19bac1e2014-05-06 15:23:49 -04002022 if(CPUID::supportsMMX2())
2023 {
2024 return x86::psubb(lhs, rhs);
2025 }
2026 else
2027 {
2028 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
2029 }
John Bauman89401822014-05-06 15:04:28 -04002030 }
2031
John Bauman19bac1e2014-05-06 15:23:49 -04002032// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2033// {
2034// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2035// }
2036
2037// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2038// {
2039// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2040// }
2041
2042// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2043// {
2044// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2045// }
2046
2047 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002048 {
John Bauman19bac1e2014-05-06 15:23:49 -04002049 if(CPUID::supportsMMX2())
2050 {
2051 return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
2052 }
2053 else
2054 {
2055 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
2056 }
John Bauman89401822014-05-06 15:04:28 -04002057 }
2058
John Bauman19bac1e2014-05-06 15:23:49 -04002059 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002060 {
John Bauman19bac1e2014-05-06 15:23:49 -04002061 if(CPUID::supportsMMX2())
2062 {
2063 return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
2064 }
2065 else
2066 {
2067 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
2068 }
John Bauman89401822014-05-06 15:04:28 -04002069 }
2070
John Bauman19bac1e2014-05-06 15:23:49 -04002071 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002072 {
John Bauman19bac1e2014-05-06 15:23:49 -04002073 if(CPUID::supportsMMX2())
2074 {
2075 return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
2076 }
2077 else
John Bauman66b8ab22014-05-06 15:57:45 -04002078 {
John Bauman19bac1e2014-05-06 15:23:49 -04002079 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
2080 }
John Bauman89401822014-05-06 15:04:28 -04002081 }
2082
John Bauman19bac1e2014-05-06 15:23:49 -04002083// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002084// {
2085// return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value));
2086// }
2087
John Bauman19bac1e2014-05-06 15:23:49 -04002088// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002089// {
2090// return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value));
2091// }
2092
John Bauman19bac1e2014-05-06 15:23:49 -04002093 RValue<Byte8> operator+=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002094 {
2095 return lhs = lhs + rhs;
2096 }
2097
John Bauman19bac1e2014-05-06 15:23:49 -04002098 RValue<Byte8> operator-=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002099 {
2100 return lhs = lhs - rhs;
2101 }
2102
John Bauman19bac1e2014-05-06 15:23:49 -04002103// RValue<Byte8> operator*=(const Byte8 &lhs, RValue<Byte8> rhs)
2104// {
2105// return lhs = lhs * rhs;
2106// }
John Bauman89401822014-05-06 15:04:28 -04002107
John Bauman19bac1e2014-05-06 15:23:49 -04002108// RValue<Byte8> operator/=(const Byte8 &lhs, RValue<Byte8> rhs)
2109// {
2110// return lhs = lhs / rhs;
2111// }
John Bauman89401822014-05-06 15:04:28 -04002112
John Bauman19bac1e2014-05-06 15:23:49 -04002113// RValue<Byte8> operator%=(const Byte8 &lhs, RValue<Byte8> rhs)
2114// {
2115// return lhs = lhs % rhs;
2116// }
John Bauman89401822014-05-06 15:04:28 -04002117
John Bauman19bac1e2014-05-06 15:23:49 -04002118 RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002119 {
2120 return lhs = lhs & rhs;
2121 }
2122
John Bauman19bac1e2014-05-06 15:23:49 -04002123 RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002124 {
2125 return lhs = lhs | rhs;
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)
John Bauman89401822014-05-06 15:04:28 -04002139// {
2140// return lhs = lhs >> rhs;
2141// }
2142
John Bauman19bac1e2014-05-06 15:23:49 -04002143// RValue<Byte8> operator+(RValue<Byte8> val)
2144// {
2145// return val;
2146// }
2147
2148// RValue<Byte8> operator-(RValue<Byte8> val)
2149// {
2150// return RValue<Byte8>(Nucleus::createNeg(val.value));
2151// }
2152
2153 RValue<Byte8> operator~(RValue<Byte8> val)
John Bauman89401822014-05-06 15:04:28 -04002154 {
John Bauman19bac1e2014-05-06 15:23:49 -04002155 if(CPUID::supportsMMX2())
2156 {
2157 return val ^ Byte8(0xFFFFFFFFFFFFFFFF);
2158 }
2159 else
2160 {
2161 return RValue<Byte8>(Nucleus::createNot(val.value));
2162 }
John Bauman89401822014-05-06 15:04:28 -04002163 }
2164
John Bauman19bac1e2014-05-06 15:23:49 -04002165 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002166 {
2167 return x86::paddusb(x, y);
2168 }
John Bauman66b8ab22014-05-06 15:57:45 -04002169
John Bauman19bac1e2014-05-06 15:23:49 -04002170 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002171 {
2172 return x86::psubusb(x, y);
2173 }
2174
John Bauman19bac1e2014-05-06 15:23:49 -04002175 RValue<Short4> Unpack(RValue<Byte4> x)
John Bauman89401822014-05-06 15:04:28 -04002176 {
John Bauman19bac1e2014-05-06 15:23:49 -04002177 Value *int2 = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), x.value, 0);
2178 Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType());
John Bauman89401822014-05-06 15:04:28 -04002179
John Bauman19bac1e2014-05-06 15:23:49 -04002180 return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8));
2181 }
John Bauman89401822014-05-06 15:04:28 -04002182
John Bauman19bac1e2014-05-06 15:23:49 -04002183 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2184 {
2185 if(CPUID::supportsMMX2())
2186 {
2187 return x86::punpcklbw(x, y);
2188 }
2189 else
2190 {
2191 Constant *shuffle[8];
2192 shuffle[0] = Nucleus::createConstantInt(0);
2193 shuffle[1] = Nucleus::createConstantInt(8);
2194 shuffle[2] = Nucleus::createConstantInt(1);
2195 shuffle[3] = Nucleus::createConstantInt(9);
2196 shuffle[4] = Nucleus::createConstantInt(2);
2197 shuffle[5] = Nucleus::createConstantInt(10);
2198 shuffle[6] = Nucleus::createConstantInt(3);
2199 shuffle[7] = Nucleus::createConstantInt(11);
2200
2201 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
2202
2203 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2204 }
John Bauman89401822014-05-06 15:04:28 -04002205 }
John Bauman66b8ab22014-05-06 15:57:45 -04002206
John Bauman19bac1e2014-05-06 15:23:49 -04002207 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002208 {
John Bauman19bac1e2014-05-06 15:23:49 -04002209 if(CPUID::supportsMMX2())
2210 {
2211 return x86::punpckhbw(x, y);
2212 }
2213 else
2214 {
2215 Constant *shuffle[8];
2216 shuffle[0] = Nucleus::createConstantInt(4);
2217 shuffle[1] = Nucleus::createConstantInt(12);
2218 shuffle[2] = Nucleus::createConstantInt(5);
2219 shuffle[3] = Nucleus::createConstantInt(13);
2220 shuffle[4] = Nucleus::createConstantInt(6);
2221 shuffle[5] = Nucleus::createConstantInt(14);
2222 shuffle[6] = Nucleus::createConstantInt(7);
2223 shuffle[7] = Nucleus::createConstantInt(15);
John Bauman89401822014-05-06 15:04:28 -04002224
John Bauman19bac1e2014-05-06 15:23:49 -04002225 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002226
John Bauman19bac1e2014-05-06 15:23:49 -04002227 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2228 }
John Bauman89401822014-05-06 15:04:28 -04002229 }
2230
John Bauman19bac1e2014-05-06 15:23:49 -04002231 RValue<Int> SignMask(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04002232 {
2233 return x86::pmovmskb(x);
2234 }
2235
John Bauman19bac1e2014-05-06 15:23:49 -04002236// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002237// {
2238// return x86::pcmpgtb(x, y); // FIXME: Signedness
2239// }
John Bauman66b8ab22014-05-06 15:57:45 -04002240
John Bauman19bac1e2014-05-06 15:23:49 -04002241 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04002242 {
2243 return x86::pcmpeqb(x, y);
2244 }
2245
John Bauman19bac1e2014-05-06 15:23:49 -04002246 Type *Byte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002247 {
John Bauman19bac1e2014-05-06 15:23:49 -04002248 if(CPUID::supportsMMX2())
2249 {
2250 return MMX::getType();
2251 }
2252 else
2253 {
2254 return VectorType::get(Byte::getType(), 8);
2255 }
John Bauman89401822014-05-06 15:04:28 -04002256 }
2257
2258 SByte8::SByte8()
2259 {
2260 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002261 }
2262
2263 SByte8::SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7)
2264 {
2265 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002266
2267 Constant *constantVector[8];
2268 constantVector[0] = Nucleus::createConstantByte(x0);
2269 constantVector[1] = Nucleus::createConstantByte(x1);
2270 constantVector[2] = Nucleus::createConstantByte(x2);
2271 constantVector[3] = Nucleus::createConstantByte(x3);
2272 constantVector[4] = Nucleus::createConstantByte(x4);
2273 constantVector[5] = Nucleus::createConstantByte(x5);
2274 constantVector[6] = Nucleus::createConstantByte(x6);
2275 constantVector[7] = Nucleus::createConstantByte(x7);
John Bauman19bac1e2014-05-06 15:23:49 -04002276 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002277
John Bauman66b8ab22014-05-06 15:57:45 -04002278 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002279 }
2280
2281 SByte8::SByte8(int64_t x)
2282 {
2283 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002284
2285 Constant *constantVector[8];
2286 constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0));
2287 constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8));
2288 constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16));
2289 constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24));
2290 constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32));
2291 constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40));
2292 constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48));
2293 constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56));
John Bauman19bac1e2014-05-06 15:23:49 -04002294 Value *vector = Nucleus::createConstantVector(constantVector, 8);
John Bauman89401822014-05-06 15:04:28 -04002295
John Bauman66b8ab22014-05-06 15:57:45 -04002296 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002297 }
2298
John Bauman19bac1e2014-05-06 15:23:49 -04002299 SByte8::SByte8(RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002300 {
2301 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002302
John Bauman66b8ab22014-05-06 15:57:45 -04002303 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002304 }
2305
2306 SByte8::SByte8(const SByte8 &rhs)
2307 {
2308 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002309
John Bauman66b8ab22014-05-06 15:57:45 -04002310 Value *value = rhs.loadValue();
2311 storeValue(value);
2312 }
2313
2314 SByte8::SByte8(const Reference<SByte8> &rhs)
2315 {
2316 // xyzw.parent = this;
2317
2318 Value *value = rhs.loadValue();
2319 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002320 }
2321
John Bauman19bac1e2014-05-06 15:23:49 -04002322 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002323 {
John Bauman66b8ab22014-05-06 15:57:45 -04002324 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002325
2326 return rhs;
2327 }
2328
2329 RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const
2330 {
John Bauman66b8ab22014-05-06 15:57:45 -04002331 Value *value = rhs.loadValue();
2332 storeValue(value);
2333
2334 return RValue<SByte8>(value);
2335 }
2336
2337 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const
2338 {
2339 Value *value = rhs.loadValue();
2340 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002341
2342 return RValue<SByte8>(value);
2343 }
2344
John Bauman19bac1e2014-05-06 15:23:49 -04002345 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002346 {
John Bauman19bac1e2014-05-06 15:23:49 -04002347 if(CPUID::supportsMMX2())
2348 {
2349 return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs)));
2350 }
2351 else
2352 {
2353 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
2354 }
John Bauman89401822014-05-06 15:04:28 -04002355 }
2356
John Bauman19bac1e2014-05-06 15:23:49 -04002357 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002358 {
John Bauman19bac1e2014-05-06 15:23:49 -04002359 if(CPUID::supportsMMX2())
2360 {
2361 return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs)));
2362 }
2363 else
2364 {
2365 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
2366 }
John Bauman89401822014-05-06 15:04:28 -04002367 }
2368
John Bauman19bac1e2014-05-06 15:23:49 -04002369// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2370// {
2371// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2372// }
John Bauman89401822014-05-06 15:04:28 -04002373
John Bauman19bac1e2014-05-06 15:23:49 -04002374// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2375// {
2376// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2377// }
John Bauman89401822014-05-06 15:04:28 -04002378
John Bauman19bac1e2014-05-06 15:23:49 -04002379// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2380// {
2381// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2382// }
John Bauman89401822014-05-06 15:04:28 -04002383
John Bauman19bac1e2014-05-06 15:23:49 -04002384 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002385 {
2386 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2387 }
2388
John Bauman19bac1e2014-05-06 15:23:49 -04002389 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002390 {
2391 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2392 }
2393
John Bauman19bac1e2014-05-06 15:23:49 -04002394 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002395 {
2396 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2397 }
2398
John Bauman19bac1e2014-05-06 15:23:49 -04002399// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002400// {
2401// return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value));
2402// }
2403
John Bauman19bac1e2014-05-06 15:23:49 -04002404// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002405// {
2406// return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value));
2407// }
2408
John Bauman19bac1e2014-05-06 15:23:49 -04002409 RValue<SByte8> operator+=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002410 {
2411 return lhs = lhs + rhs;
2412 }
2413
John Bauman19bac1e2014-05-06 15:23:49 -04002414 RValue<SByte8> operator-=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002415 {
2416 return lhs = lhs - rhs;
2417 }
2418
John Bauman19bac1e2014-05-06 15:23:49 -04002419// RValue<SByte8> operator*=(const SByte8 &lhs, RValue<SByte8> rhs)
2420// {
2421// return lhs = lhs * rhs;
2422// }
John Bauman89401822014-05-06 15:04:28 -04002423
John Bauman19bac1e2014-05-06 15:23:49 -04002424// RValue<SByte8> operator/=(const SByte8 &lhs, RValue<SByte8> rhs)
2425// {
2426// return lhs = lhs / rhs;
2427// }
John Bauman89401822014-05-06 15:04:28 -04002428
John Bauman19bac1e2014-05-06 15:23:49 -04002429// RValue<SByte8> operator%=(const SByte8 &lhs, RValue<SByte8> rhs)
2430// {
2431// return lhs = lhs % rhs;
2432// }
John Bauman89401822014-05-06 15:04:28 -04002433
John Bauman19bac1e2014-05-06 15:23:49 -04002434 RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002435 {
2436 return lhs = lhs & rhs;
2437 }
2438
John Bauman19bac1e2014-05-06 15:23:49 -04002439 RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs)
John Bauman89401822014-05-06 15:04:28 -04002440 {
2441 return lhs = lhs | rhs;
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)
John Bauman89401822014-05-06 15:04:28 -04002455// {
2456// return lhs = lhs >> rhs;
2457// }
2458
John Bauman19bac1e2014-05-06 15:23:49 -04002459// RValue<SByte8> operator+(RValue<SByte8> val)
2460// {
2461// return val;
2462// }
2463
2464// RValue<SByte8> operator-(RValue<SByte8> val)
2465// {
2466// return RValue<SByte8>(Nucleus::createNeg(val.value));
2467// }
2468
2469 RValue<SByte8> operator~(RValue<SByte8> val)
John Bauman89401822014-05-06 15:04:28 -04002470 {
John Bauman19bac1e2014-05-06 15:23:49 -04002471 if(CPUID::supportsMMX2())
2472 {
2473 return val ^ SByte8(0xFFFFFFFFFFFFFFFF);
2474 }
2475 else
2476 {
2477 return RValue<SByte8>(Nucleus::createNot(val.value));
2478 }
John Bauman89401822014-05-06 15:04:28 -04002479 }
2480
John Bauman19bac1e2014-05-06 15:23:49 -04002481 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002482 {
2483 return x86::paddsb(x, y);
2484 }
John Bauman66b8ab22014-05-06 15:57:45 -04002485
John Bauman19bac1e2014-05-06 15:23:49 -04002486 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002487 {
2488 return x86::psubsb(x, y);
2489 }
2490
John Bauman19bac1e2014-05-06 15:23:49 -04002491 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002492 {
John Bauman19bac1e2014-05-06 15:23:49 -04002493 if(CPUID::supportsMMX2())
2494 {
2495 return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y)));
2496 }
2497 else
2498 {
2499 Constant *shuffle[8];
2500 shuffle[0] = Nucleus::createConstantInt(0);
2501 shuffle[1] = Nucleus::createConstantInt(8);
2502 shuffle[2] = Nucleus::createConstantInt(1);
2503 shuffle[3] = Nucleus::createConstantInt(9);
2504 shuffle[4] = Nucleus::createConstantInt(2);
2505 shuffle[5] = Nucleus::createConstantInt(10);
2506 shuffle[6] = Nucleus::createConstantInt(3);
2507 shuffle[7] = Nucleus::createConstantInt(11);
John Bauman89401822014-05-06 15:04:28 -04002508
John Bauman19bac1e2014-05-06 15:23:49 -04002509 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002510
John Bauman19bac1e2014-05-06 15:23:49 -04002511 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2512 }
John Bauman89401822014-05-06 15:04:28 -04002513 }
John Bauman66b8ab22014-05-06 15:57:45 -04002514
John Bauman19bac1e2014-05-06 15:23:49 -04002515 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002516 {
John Bauman19bac1e2014-05-06 15:23:49 -04002517 if(CPUID::supportsMMX2())
2518 {
2519 return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y)));
2520 }
2521 else
2522 {
2523 Constant *shuffle[8];
2524 shuffle[0] = Nucleus::createConstantInt(4);
2525 shuffle[1] = Nucleus::createConstantInt(12);
2526 shuffle[2] = Nucleus::createConstantInt(5);
2527 shuffle[3] = Nucleus::createConstantInt(13);
2528 shuffle[4] = Nucleus::createConstantInt(6);
2529 shuffle[5] = Nucleus::createConstantInt(14);
2530 shuffle[6] = Nucleus::createConstantInt(7);
2531 shuffle[7] = Nucleus::createConstantInt(15);
John Bauman89401822014-05-06 15:04:28 -04002532
John Bauman19bac1e2014-05-06 15:23:49 -04002533 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8));
John Bauman89401822014-05-06 15:04:28 -04002534
John Bauman19bac1e2014-05-06 15:23:49 -04002535 return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType()));
2536 }
John Bauman89401822014-05-06 15:04:28 -04002537 }
2538
John Bauman19bac1e2014-05-06 15:23:49 -04002539 RValue<Int> SignMask(RValue<SByte8> x)
John Bauman89401822014-05-06 15:04:28 -04002540 {
2541 return x86::pmovmskb(As<Byte8>(x));
2542 }
2543
John Bauman19bac1e2014-05-06 15:23:49 -04002544 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002545 {
2546 return x86::pcmpgtb(x, y);
2547 }
John Bauman66b8ab22014-05-06 15:57:45 -04002548
John Bauman19bac1e2014-05-06 15:23:49 -04002549 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04002550 {
2551 return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y));
2552 }
2553
John Bauman19bac1e2014-05-06 15:23:49 -04002554 Type *SByte8::getType()
John Bauman89401822014-05-06 15:04:28 -04002555 {
John Bauman19bac1e2014-05-06 15:23:49 -04002556 if(CPUID::supportsMMX2())
2557 {
2558 return MMX::getType();
2559 }
2560 else
2561 {
2562 return VectorType::get(SByte::getType(), 8);
2563 }
John Bauman89401822014-05-06 15:04:28 -04002564 }
2565
John Bauman19bac1e2014-05-06 15:23:49 -04002566 Byte16::Byte16(RValue<Byte16> rhs)
John Bauman89401822014-05-06 15:04:28 -04002567 {
2568 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002569
John Bauman66b8ab22014-05-06 15:57:45 -04002570 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002571 }
2572
2573 Byte16::Byte16(const Byte16 &rhs)
2574 {
2575 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002576
John Bauman66b8ab22014-05-06 15:57:45 -04002577 Value *value = rhs.loadValue();
2578 storeValue(value);
2579 }
2580
2581 Byte16::Byte16(const Reference<Byte16> &rhs)
2582 {
2583 // xyzw.parent = this;
2584
2585 Value *value = rhs.loadValue();
2586 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002587 }
2588
John Bauman19bac1e2014-05-06 15:23:49 -04002589 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002590 {
John Bauman66b8ab22014-05-06 15:57:45 -04002591 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002592
2593 return rhs;
2594 }
2595
2596 RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const
2597 {
John Bauman66b8ab22014-05-06 15:57:45 -04002598 Value *value = rhs.loadValue();
2599 storeValue(value);
2600
2601 return RValue<Byte16>(value);
2602 }
2603
2604 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const
2605 {
2606 Value *value = rhs.loadValue();
2607 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002608
2609 return RValue<Byte16>(value);
2610 }
2611
John Bauman19bac1e2014-05-06 15:23:49 -04002612 Type *Byte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002613 {
2614 return VectorType::get(Byte::getType(), 16);
2615 }
2616
John Bauman19bac1e2014-05-06 15:23:49 -04002617 Type *SByte16::getType()
John Bauman89401822014-05-06 15:04:28 -04002618 {
2619 return VectorType::get(SByte::getType(), 16);
2620 }
2621
John Bauman19bac1e2014-05-06 15:23:49 -04002622 Short4::Short4(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04002623 {
John Bauman89401822014-05-06 15:04:28 -04002624 Value *extend = Nucleus::createZExt(cast.value, Long::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04002625 Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value;
John Bauman66b8ab22014-05-06 15:57:45 -04002626
2627 storeValue(swizzle);
John Bauman89401822014-05-06 15:04:28 -04002628 }
2629
John Bauman19bac1e2014-05-06 15:23:49 -04002630 Short4::Short4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04002631 {
John Bauman89401822014-05-06 15:04:28 -04002632 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
2633
2634 #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd)
2635 Constant *pack[8];
2636 pack[0] = Nucleus::createConstantInt(0);
2637 pack[1] = Nucleus::createConstantInt(2);
2638 pack[2] = Nucleus::createConstantInt(4);
2639 pack[3] = Nucleus::createConstantInt(6);
2640
2641 Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4));
2642 #else
2643 Value *packed;
2644
2645 // FIXME: Use Swizzle<Short8>
2646 if(!CPUID::supportsSSSE3())
2647 {
2648 Constant *pshuflw[8];
2649 pshuflw[0] = Nucleus::createConstantInt(0);
2650 pshuflw[1] = Nucleus::createConstantInt(2);
2651 pshuflw[2] = Nucleus::createConstantInt(0);
2652 pshuflw[3] = Nucleus::createConstantInt(2);
2653 pshuflw[4] = Nucleus::createConstantInt(4);
2654 pshuflw[5] = Nucleus::createConstantInt(5);
2655 pshuflw[6] = Nucleus::createConstantInt(6);
2656 pshuflw[7] = Nucleus::createConstantInt(7);
2657
2658 Constant *pshufhw[8];
2659 pshufhw[0] = Nucleus::createConstantInt(0);
2660 pshufhw[1] = Nucleus::createConstantInt(1);
2661 pshufhw[2] = Nucleus::createConstantInt(2);
2662 pshufhw[3] = Nucleus::createConstantInt(3);
2663 pshufhw[4] = Nucleus::createConstantInt(4);
2664 pshufhw[5] = Nucleus::createConstantInt(6);
2665 pshufhw[6] = Nucleus::createConstantInt(4);
2666 pshufhw[7] = Nucleus::createConstantInt(6);
2667
2668 Value *shuffle1 = Nucleus::createShuffleVector(short8, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshuflw, 8));
2669 Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshufhw, 8));
2670 Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType());
2671 packed = Nucleus::createSwizzle(int4, 0x88);
2672 }
2673 else
2674 {
2675 Constant *pshufb[16];
2676 pshufb[0] = Nucleus::createConstantInt(0);
2677 pshufb[1] = Nucleus::createConstantInt(1);
2678 pshufb[2] = Nucleus::createConstantInt(4);
2679 pshufb[3] = Nucleus::createConstantInt(5);
2680 pshufb[4] = Nucleus::createConstantInt(8);
2681 pshufb[5] = Nucleus::createConstantInt(9);
2682 pshufb[6] = Nucleus::createConstantInt(12);
2683 pshufb[7] = Nucleus::createConstantInt(13);
2684 pshufb[8] = Nucleus::createConstantInt(0);
2685 pshufb[9] = Nucleus::createConstantInt(1);
2686 pshufb[10] = Nucleus::createConstantInt(4);
2687 pshufb[11] = Nucleus::createConstantInt(5);
2688 pshufb[12] = Nucleus::createConstantInt(8);
2689 pshufb[13] = Nucleus::createConstantInt(9);
2690 pshufb[14] = Nucleus::createConstantInt(12);
2691 pshufb[15] = Nucleus::createConstantInt(13);
2692
2693 Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType());
2694 packed = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
2695 }
2696
2697 #if 0 // FIXME: No optimal instruction selection
2698 Value *qword2 = Nucleus::createBitCast(packed, Long2::getType());
2699 Value *element = Nucleus::createExtractElement(qword2, 0);
2700 Value *short4 = Nucleus::createBitCast(element, Short4::getType());
2701 #else // FIXME: Requires SSE
2702 Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
2703 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
2704 #endif
2705 #endif
2706
John Bauman66b8ab22014-05-06 15:57:45 -04002707 storeValue(short4);
John Bauman89401822014-05-06 15:04:28 -04002708 }
2709
John Bauman19bac1e2014-05-06 15:23:49 -04002710// Short4::Short4(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04002711// {
2712// }
2713
John Bauman19bac1e2014-05-06 15:23:49 -04002714 Short4::Short4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04002715 {
John Bauman89401822014-05-06 15:04:28 -04002716 Int4 v4i32 = Int4(cast);
2717 v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
John Bauman66b8ab22014-05-06 15:57:45 -04002718
2719 storeValue(As<Short4>(Int2(v4i32)).value);
John Bauman89401822014-05-06 15:04:28 -04002720 }
2721
2722 Short4::Short4()
2723 {
2724 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002725 }
2726
John Bauman19bac1e2014-05-06 15:23:49 -04002727 Short4::Short4(short xyzw)
2728 {
2729 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04002730
2731 Constant *constantVector[4];
2732 constantVector[0] = Nucleus::createConstantShort(xyzw);
2733 constantVector[1] = Nucleus::createConstantShort(xyzw);
2734 constantVector[2] = Nucleus::createConstantShort(xyzw);
2735 constantVector[3] = Nucleus::createConstantShort(xyzw);
2736 Value *vector = Nucleus::createConstantVector(constantVector, 4);
2737
John Bauman66b8ab22014-05-06 15:57:45 -04002738 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman19bac1e2014-05-06 15:23:49 -04002739 }
2740
John Bauman89401822014-05-06 15:04:28 -04002741 Short4::Short4(short x, short y, short z, short w)
2742 {
2743 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002744
2745 Constant *constantVector[4];
2746 constantVector[0] = Nucleus::createConstantShort(x);
2747 constantVector[1] = Nucleus::createConstantShort(y);
2748 constantVector[2] = Nucleus::createConstantShort(z);
2749 constantVector[3] = Nucleus::createConstantShort(w);
John Bauman19bac1e2014-05-06 15:23:49 -04002750 Value *vector = Nucleus::createConstantVector(constantVector, 4);
2751
John Bauman66b8ab22014-05-06 15:57:45 -04002752 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04002753 }
2754
John Bauman19bac1e2014-05-06 15:23:49 -04002755 Short4::Short4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002756 {
2757 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002758
John Bauman66b8ab22014-05-06 15:57:45 -04002759 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002760 }
2761
2762 Short4::Short4(const Short4 &rhs)
2763 {
2764 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002765
John Bauman66b8ab22014-05-06 15:57:45 -04002766 Value *value = rhs.loadValue();
2767 storeValue(value);
2768 }
2769
2770 Short4::Short4(const Reference<Short4> &rhs)
2771 {
2772 // xyzw.parent = this;
2773
2774 Value *value = rhs.loadValue();
2775 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002776 }
2777
John Bauman19bac1e2014-05-06 15:23:49 -04002778 Short4::Short4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002779 {
2780 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002781
John Bauman66b8ab22014-05-06 15:57:45 -04002782 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002783 }
2784
2785 Short4::Short4(const UShort4 &rhs)
2786 {
2787 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04002788
John Bauman66b8ab22014-05-06 15:57:45 -04002789 storeValue(rhs.loadValue());
2790 }
2791
2792 Short4::Short4(const Reference<UShort4> &rhs)
2793 {
2794 // xyzw.parent = this;
2795
2796 storeValue(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04002797 }
2798
John Bauman19bac1e2014-05-06 15:23:49 -04002799 RValue<Short4> Short4::operator=(RValue<Short4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002800 {
John Bauman66b8ab22014-05-06 15:57:45 -04002801 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002802
2803 return rhs;
2804 }
2805
2806 RValue<Short4> Short4::operator=(const Short4 &rhs) const
2807 {
John Bauman66b8ab22014-05-06 15:57:45 -04002808 Value *value = rhs.loadValue();
2809 storeValue(value);
2810
2811 return RValue<Short4>(value);
2812 }
2813
2814 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const
2815 {
2816 Value *value = rhs.loadValue();
2817 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002818
2819 return RValue<Short4>(value);
2820 }
2821
John Bauman19bac1e2014-05-06 15:23:49 -04002822 RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04002823 {
John Bauman66b8ab22014-05-06 15:57:45 -04002824 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04002825
John Bauman66b8ab22014-05-06 15:57:45 -04002826 return RValue<Short4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04002827 }
2828
2829 RValue<Short4> Short4::operator=(const UShort4 &rhs) const
2830 {
John Bauman66b8ab22014-05-06 15:57:45 -04002831 Value *value = rhs.loadValue();
2832 storeValue(value);
2833
2834 return RValue<Short4>(value);
2835 }
2836
2837 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const
2838 {
2839 Value *value = rhs.loadValue();
2840 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04002841
2842 return RValue<Short4>(value);
2843 }
2844
John Bauman19bac1e2014-05-06 15:23:49 -04002845 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002846 {
John Bauman19bac1e2014-05-06 15:23:49 -04002847 if(CPUID::supportsMMX2())
2848 {
2849 return x86::paddw(lhs, rhs);
2850 }
2851 else
2852 {
2853 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
2854 }
John Bauman89401822014-05-06 15:04:28 -04002855 }
2856
John Bauman19bac1e2014-05-06 15:23:49 -04002857 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002858 {
John Bauman19bac1e2014-05-06 15:23:49 -04002859 if(CPUID::supportsMMX2())
2860 {
2861 return x86::psubw(lhs, rhs);
2862 }
2863 else
2864 {
2865 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
2866 }
John Bauman89401822014-05-06 15:04:28 -04002867 }
2868
John Bauman19bac1e2014-05-06 15:23:49 -04002869 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002870 {
John Bauman19bac1e2014-05-06 15:23:49 -04002871 if(CPUID::supportsMMX2())
2872 {
2873 return x86::pmullw(lhs, rhs);
2874 }
2875 else
2876 {
2877 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
2878 }
John Bauman89401822014-05-06 15:04:28 -04002879 }
2880
John Bauman19bac1e2014-05-06 15:23:49 -04002881// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
2882// {
2883// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
2884// }
2885
2886// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
2887// {
2888// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
2889// }
2890
2891 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002892 {
John Bauman19bac1e2014-05-06 15:23:49 -04002893 if(CPUID::supportsMMX2())
2894 {
2895 return x86::pand(lhs, rhs);
2896 }
2897 else
2898 {
2899 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
2900 }
John Bauman89401822014-05-06 15:04:28 -04002901 }
2902
John Bauman19bac1e2014-05-06 15:23:49 -04002903 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002904 {
John Bauman19bac1e2014-05-06 15:23:49 -04002905 if(CPUID::supportsMMX2())
2906 {
2907 return x86::por(lhs, rhs);
2908 }
2909 else
2910 {
2911 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
2912 }
John Bauman89401822014-05-06 15:04:28 -04002913 }
2914
John Bauman19bac1e2014-05-06 15:23:49 -04002915 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002916 {
John Bauman19bac1e2014-05-06 15:23:49 -04002917 if(CPUID::supportsMMX2())
2918 {
2919 return x86::pxor(lhs, rhs);
2920 }
2921 else
2922 {
2923 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
2924 }
John Bauman89401822014-05-06 15:04:28 -04002925 }
2926
John Bauman19bac1e2014-05-06 15:23:49 -04002927 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002928 {
2929 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2930
2931 return x86::psllw(lhs, rhs);
2932 }
2933
John Bauman19bac1e2014-05-06 15:23:49 -04002934 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04002935 {
2936 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
2937
2938 return x86::psraw(lhs, rhs);
2939 }
2940
John Bauman19bac1e2014-05-06 15:23:49 -04002941 RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04002942 {
2943 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
2944
2945 return x86::psllw(lhs, rhs);
2946 }
2947
John Bauman19bac1e2014-05-06 15:23:49 -04002948 RValue<Short4> operator>>(RValue<Short4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04002949 {
2950 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
2951
2952 return x86::psraw(lhs, rhs);
2953 }
2954
John Bauman19bac1e2014-05-06 15:23:49 -04002955 RValue<Short4> operator+=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002956 {
2957 return lhs = lhs + rhs;
2958 }
2959
John Bauman19bac1e2014-05-06 15:23:49 -04002960 RValue<Short4> operator-=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002961 {
2962 return lhs = lhs - rhs;
2963 }
2964
John Bauman19bac1e2014-05-06 15:23:49 -04002965 RValue<Short4> operator*=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002966 {
2967 return lhs = lhs * rhs;
2968 }
2969
John Bauman19bac1e2014-05-06 15:23:49 -04002970// RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs)
2971// {
2972// return lhs = lhs / rhs;
2973// }
John Bauman89401822014-05-06 15:04:28 -04002974
John Bauman19bac1e2014-05-06 15:23:49 -04002975// RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs)
2976// {
2977// return lhs = lhs % rhs;
2978// }
John Bauman89401822014-05-06 15:04:28 -04002979
John Bauman19bac1e2014-05-06 15:23:49 -04002980 RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002981 {
2982 return lhs = lhs & rhs;
2983 }
2984
John Bauman19bac1e2014-05-06 15:23:49 -04002985 RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04002986 {
2987 return lhs = 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
2995 RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs)
2996 {
2997 return lhs = lhs << rhs;
2998 }
2999
3000 RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs)
3001 {
3002 return lhs = lhs >> rhs;
3003 }
3004
John Bauman19bac1e2014-05-06 15:23:49 -04003005 RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003006 {
3007 return lhs = lhs << rhs;
3008 }
3009
John Bauman19bac1e2014-05-06 15:23:49 -04003010 RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003011 {
3012 return lhs = lhs >> rhs;
3013 }
3014
John Bauman19bac1e2014-05-06 15:23:49 -04003015// RValue<Short4> operator+(RValue<Short4> val)
3016// {
3017// return val;
3018// }
3019
3020 RValue<Short4> operator-(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04003021 {
John Bauman19bac1e2014-05-06 15:23:49 -04003022 if(CPUID::supportsMMX2())
3023 {
3024 return Short4(0, 0, 0, 0) - val;
3025 }
3026 else
3027 {
3028 return RValue<Short4>(Nucleus::createNeg(val.value));
3029 }
John Bauman89401822014-05-06 15:04:28 -04003030 }
3031
John Bauman19bac1e2014-05-06 15:23:49 -04003032 RValue<Short4> operator~(RValue<Short4> val)
John Bauman89401822014-05-06 15:04:28 -04003033 {
John Bauman19bac1e2014-05-06 15:23:49 -04003034 if(CPUID::supportsMMX2())
3035 {
3036 return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu);
3037 }
3038 else
3039 {
3040 return RValue<Short4>(Nucleus::createNot(val.value));
3041 }
John Bauman89401822014-05-06 15:04:28 -04003042 }
3043
John Bauman19bac1e2014-05-06 15:23:49 -04003044 RValue<Short4> RoundShort4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04003045 {
3046 RValue<Int4> v4i32 = x86::cvtps2dq(cast);
3047 v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32));
John Bauman66b8ab22014-05-06 15:57:45 -04003048
John Bauman89401822014-05-06 15:04:28 -04003049 return As<Short4>(Int2(v4i32));
3050 }
3051
John Bauman19bac1e2014-05-06 15:23:49 -04003052 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003053 {
3054 return x86::pmaxsw(x, y);
3055 }
3056
John Bauman19bac1e2014-05-06 15:23:49 -04003057 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003058 {
3059 return x86::pminsw(x, y);
3060 }
3061
John Bauman19bac1e2014-05-06 15:23:49 -04003062 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003063 {
3064 return x86::paddsw(x, y);
3065 }
3066
John Bauman19bac1e2014-05-06 15:23:49 -04003067 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003068 {
3069 return x86::psubsw(x, y);
3070 }
3071
John Bauman19bac1e2014-05-06 15:23:49 -04003072 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003073 {
3074 return x86::pmulhw(x, y);
3075 }
3076
John Bauman19bac1e2014-05-06 15:23:49 -04003077 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003078 {
3079 return x86::pmaddwd(x, y);
3080 }
3081
John Bauman19bac1e2014-05-06 15:23:49 -04003082 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003083 {
3084 return x86::packsswb(x, y);
3085 }
3086
John Bauman19bac1e2014-05-06 15:23:49 -04003087 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003088 {
John Bauman19bac1e2014-05-06 15:23:49 -04003089 if(CPUID::supportsMMX2())
3090 {
3091 return x86::punpcklwd(x, y);
3092 }
3093 else
3094 {
3095 Constant *shuffle[4];
3096 shuffle[0] = Nucleus::createConstantInt(0);
3097 shuffle[1] = Nucleus::createConstantInt(4);
3098 shuffle[2] = Nucleus::createConstantInt(1);
3099 shuffle[3] = Nucleus::createConstantInt(5);
John Bauman89401822014-05-06 15:04:28 -04003100
John Bauman19bac1e2014-05-06 15:23:49 -04003101 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
John Bauman89401822014-05-06 15:04:28 -04003102
John Bauman19bac1e2014-05-06 15:23:49 -04003103 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
3104 }
John Bauman89401822014-05-06 15:04:28 -04003105 }
3106
John Bauman19bac1e2014-05-06 15:23:49 -04003107 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003108 {
John Bauman19bac1e2014-05-06 15:23:49 -04003109 if(CPUID::supportsMMX2())
3110 {
3111 return x86::punpckhwd(x, y);
3112 }
3113 else
3114 {
3115 Constant *shuffle[4];
3116 shuffle[0] = Nucleus::createConstantInt(2);
3117 shuffle[1] = Nucleus::createConstantInt(6);
3118 shuffle[2] = Nucleus::createConstantInt(3);
3119 shuffle[3] = Nucleus::createConstantInt(7);
John Bauman89401822014-05-06 15:04:28 -04003120
John Bauman19bac1e2014-05-06 15:23:49 -04003121 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4));
John Bauman89401822014-05-06 15:04:28 -04003122
John Bauman19bac1e2014-05-06 15:23:49 -04003123 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
3124 }
John Bauman89401822014-05-06 15:04:28 -04003125 }
3126
John Bauman19bac1e2014-05-06 15:23:49 -04003127 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04003128 {
John Bauman19bac1e2014-05-06 15:23:49 -04003129 if(CPUID::supportsMMX2())
3130 {
3131 return x86::pshufw(x, select);
3132 }
3133 else
3134 {
3135 return RValue<Short4>(Nucleus::createSwizzle(x.value, select));
3136 }
John Bauman89401822014-05-06 15:04:28 -04003137 }
3138
John Bauman19bac1e2014-05-06 15:23:49 -04003139 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
John Bauman89401822014-05-06 15:04:28 -04003140 {
John Bauman19bac1e2014-05-06 15:23:49 -04003141 if(CPUID::supportsMMX2())
3142 {
3143 return x86::pinsrw(val, Int(element), i);
3144 }
3145 else
3146 {
3147 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
3148 }
John Bauman89401822014-05-06 15:04:28 -04003149 }
3150
John Bauman19bac1e2014-05-06 15:23:49 -04003151 RValue<Short> Extract(RValue<Short4> val, int i)
John Bauman89401822014-05-06 15:04:28 -04003152 {
John Bauman19bac1e2014-05-06 15:23:49 -04003153 if(CPUID::supportsMMX2())
3154 {
3155 return Short(x86::pextrw(val, i));
3156 }
3157 else
3158 {
3159 return RValue<Short>(Nucleus::createExtractElement(val.value, i));
3160 }
John Bauman89401822014-05-06 15:04:28 -04003161 }
3162
John Bauman19bac1e2014-05-06 15:23:49 -04003163 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003164 {
3165 return x86::pcmpgtw(x, y);
3166 }
3167
John Bauman19bac1e2014-05-06 15:23:49 -04003168 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04003169 {
3170 return x86::pcmpeqw(x, y);
3171 }
3172
John Bauman19bac1e2014-05-06 15:23:49 -04003173 Type *Short4::getType()
John Bauman89401822014-05-06 15:04:28 -04003174 {
John Bauman19bac1e2014-05-06 15:23:49 -04003175 if(CPUID::supportsMMX2())
3176 {
3177 return MMX::getType();
3178 }
3179 else
3180 {
3181 return VectorType::get(Short::getType(), 4);
3182 }
John Bauman89401822014-05-06 15:04:28 -04003183 }
3184
John Bauman19bac1e2014-05-06 15:23:49 -04003185 UShort4::UShort4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04003186 {
John Bauman89401822014-05-06 15:04:28 -04003187 *this = Short4(cast);
3188 }
3189
John Bauman19bac1e2014-05-06 15:23:49 -04003190 UShort4::UShort4(RValue<Float4> cast, bool saturate)
John Bauman89401822014-05-06 15:04:28 -04003191 {
John Bauman89401822014-05-06 15:04:28 -04003192 Float4 sat;
3193
3194 if(saturate)
3195 {
3196 if(CPUID::supportsSSE4_1())
3197 {
3198 sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation
3199 }
3200 else
3201 {
3202 sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000));
3203 }
3204 }
3205 else
3206 {
3207 sat = cast;
3208 }
3209
3210 Int4 int4(sat);
3211
3212 if(!saturate || !CPUID::supportsSSE4_1())
3213 {
3214 *this = Short4(Int4(int4));
3215 }
3216 else
3217 {
3218 *this = As<Short4>(Int2(As<Int4>(x86::packusdw(As<UInt4>(int4), As<UInt4>(int4)))));
3219 }
3220 }
3221
3222 UShort4::UShort4()
3223 {
3224 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003225 }
3226
3227 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3228 {
3229 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003230
3231 Constant *constantVector[4];
3232 constantVector[0] = Nucleus::createConstantShort(x);
3233 constantVector[1] = Nucleus::createConstantShort(y);
3234 constantVector[2] = Nucleus::createConstantShort(z);
3235 constantVector[3] = Nucleus::createConstantShort(w);
John Bauman19bac1e2014-05-06 15:23:49 -04003236 Value *vector = Nucleus::createConstantVector(constantVector, 4);
John Bauman89401822014-05-06 15:04:28 -04003237
John Bauman66b8ab22014-05-06 15:57:45 -04003238 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04003239 }
3240
John Bauman19bac1e2014-05-06 15:23:49 -04003241 UShort4::UShort4(RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003242 {
3243 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003244
John Bauman66b8ab22014-05-06 15:57:45 -04003245 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003246 }
3247
3248 UShort4::UShort4(const UShort4 &rhs)
3249 {
3250 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003251
John Bauman66b8ab22014-05-06 15:57:45 -04003252 Value *value = rhs.loadValue();
3253 storeValue(value);
3254 }
3255
3256 UShort4::UShort4(const Reference<UShort4> &rhs)
3257 {
3258 // xyzw.parent = this;
3259
3260 Value *value = rhs.loadValue();
3261 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003262 }
3263
John Bauman19bac1e2014-05-06 15:23:49 -04003264 UShort4::UShort4(RValue<Short4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003265 {
3266 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003267
John Bauman66b8ab22014-05-06 15:57:45 -04003268 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003269 }
3270
3271 UShort4::UShort4(const Short4 &rhs)
3272 {
3273 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003274
John Bauman66b8ab22014-05-06 15:57:45 -04003275 Value *value = rhs.loadValue();
3276 storeValue(value);
3277 }
3278
3279 UShort4::UShort4(const Reference<Short4> &rhs)
3280 {
3281 // xyzw.parent = this;
3282
3283 Value *value = rhs.loadValue();
3284 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003285 }
3286
John Bauman19bac1e2014-05-06 15:23:49 -04003287 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003288 {
John Bauman66b8ab22014-05-06 15:57:45 -04003289 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003290
3291 return rhs;
3292 }
3293
3294 RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const
3295 {
John Bauman66b8ab22014-05-06 15:57:45 -04003296 Value *value = rhs.loadValue();
3297 storeValue(value);
3298
3299 return RValue<UShort4>(value);
3300 }
3301
3302 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const
3303 {
3304 Value *value = rhs.loadValue();
3305 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003306
3307 return RValue<UShort4>(value);
3308 }
3309
John Bauman19bac1e2014-05-06 15:23:49 -04003310 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003311 {
John Bauman66b8ab22014-05-06 15:57:45 -04003312 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003313
John Bauman66b8ab22014-05-06 15:57:45 -04003314 return RValue<UShort4>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003315 }
3316
3317 RValue<UShort4> UShort4::operator=(const Short4 &rhs) const
3318 {
John Bauman66b8ab22014-05-06 15:57:45 -04003319 Value *value = rhs.loadValue();
3320 storeValue(value);
3321
3322 return RValue<UShort4>(value);
3323 }
3324
3325 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const
3326 {
3327 Value *value = rhs.loadValue();
3328 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003329
3330 return RValue<UShort4>(value);
3331 }
3332
John Bauman19bac1e2014-05-06 15:23:49 -04003333 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003334 {
John Bauman19bac1e2014-05-06 15:23:49 -04003335 if(CPUID::supportsMMX2())
3336 {
3337 return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs)));
3338 }
3339 else
3340 {
3341 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
3342 }
John Bauman89401822014-05-06 15:04:28 -04003343 }
3344
John Bauman19bac1e2014-05-06 15:23:49 -04003345 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003346 {
John Bauman19bac1e2014-05-06 15:23:49 -04003347 if(CPUID::supportsMMX2())
3348 {
3349 return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs)));
3350 }
3351 else
3352 {
3353 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
3354 }
John Bauman89401822014-05-06 15:04:28 -04003355 }
3356
John Bauman19bac1e2014-05-06 15:23:49 -04003357
3358 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
John Bauman89401822014-05-06 15:04:28 -04003359 {
John Bauman19bac1e2014-05-06 15:23:49 -04003360 if(CPUID::supportsMMX2())
3361 {
3362 return As<UShort4>(x86::pmullw(As<Short4>(lhs), As<Short4>(rhs)));
3363 }
3364 else
3365 {
3366 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
3367 }
John Bauman89401822014-05-06 15:04:28 -04003368 }
3369
John Bauman19bac1e2014-05-06 15:23:49 -04003370 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003371 {
3372 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3373
3374 return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
3375 }
3376
John Bauman19bac1e2014-05-06 15:23:49 -04003377 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003378 {
3379 // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
3380
3381 return x86::psrlw(lhs, rhs);
3382 }
3383
John Bauman19bac1e2014-05-06 15:23:49 -04003384 RValue<UShort4> operator<<(RValue<UShort4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003385 {
3386 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3387
3388 return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs));
3389 }
3390
John Bauman19bac1e2014-05-06 15:23:49 -04003391 RValue<UShort4> operator>>(RValue<UShort4> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003392 {
3393 // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value));
3394
3395 return x86::psrlw(lhs, rhs);
3396 }
3397
3398 RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs)
3399 {
3400 return lhs = lhs << rhs;
3401 }
3402
3403 RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs)
3404 {
3405 return lhs = lhs >> rhs;
3406 }
3407
John Bauman19bac1e2014-05-06 15:23:49 -04003408 RValue<UShort4> operator<<=(const UShort4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003409 {
3410 return lhs = lhs << rhs;
3411 }
3412
John Bauman19bac1e2014-05-06 15:23:49 -04003413 RValue<UShort4> operator>>=(const UShort4 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04003414 {
3415 return lhs = lhs >> rhs;
3416 }
3417
John Bauman19bac1e2014-05-06 15:23:49 -04003418 RValue<UShort4> operator~(RValue<UShort4> val)
John Bauman89401822014-05-06 15:04:28 -04003419 {
John Bauman19bac1e2014-05-06 15:23:49 -04003420 if(CPUID::supportsMMX2())
3421 {
3422 return As<UShort4>(As<Short4>(val) ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu));
3423 }
3424 else
3425 {
3426 return RValue<UShort4>(Nucleus::createNot(val.value));
3427 }
John Bauman89401822014-05-06 15:04:28 -04003428 }
3429
John Bauman19bac1e2014-05-06 15:23:49 -04003430 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003431 {
John Bauman66b8ab22014-05-06 15:57:45 -04003432 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 -04003433 }
3434
John Bauman19bac1e2014-05-06 15:23:49 -04003435 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003436 {
John Bauman66b8ab22014-05-06 15:57:45 -04003437 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 -04003438 }
3439
John Bauman19bac1e2014-05-06 15:23:49 -04003440 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003441 {
3442 return x86::paddusw(x, y);
3443 }
3444
John Bauman19bac1e2014-05-06 15:23:49 -04003445 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003446 {
3447 return x86::psubusw(x, y);
3448 }
3449
John Bauman19bac1e2014-05-06 15:23:49 -04003450 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003451 {
3452 return x86::pmulhuw(x, y);
3453 }
3454
John Bauman19bac1e2014-05-06 15:23:49 -04003455 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003456 {
3457 return x86::pavgw(x, y);
3458 }
3459
John Bauman19bac1e2014-05-06 15:23:49 -04003460 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04003461 {
3462 return x86::packuswb(x, y);
3463 }
3464
John Bauman19bac1e2014-05-06 15:23:49 -04003465 Type *UShort4::getType()
John Bauman89401822014-05-06 15:04:28 -04003466 {
John Bauman19bac1e2014-05-06 15:23:49 -04003467 if(CPUID::supportsMMX2())
3468 {
3469 return MMX::getType();
3470 }
3471 else
3472 {
3473 return VectorType::get(UShort::getType(), 4);
3474 }
John Bauman89401822014-05-06 15:04:28 -04003475 }
3476
3477 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3478 {
3479 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003480
3481 Constant *constantVector[8];
3482 constantVector[0] = Nucleus::createConstantShort(c0);
3483 constantVector[1] = Nucleus::createConstantShort(c1);
3484 constantVector[2] = Nucleus::createConstantShort(c2);
3485 constantVector[3] = Nucleus::createConstantShort(c3);
3486 constantVector[4] = Nucleus::createConstantShort(c4);
3487 constantVector[5] = Nucleus::createConstantShort(c5);
3488 constantVector[6] = Nucleus::createConstantShort(c6);
3489 constantVector[7] = Nucleus::createConstantShort(c7);
3490
John Bauman66b8ab22014-05-06 15:57:45 -04003491 storeValue(Nucleus::createConstantVector(constantVector, 8));
John Bauman89401822014-05-06 15:04:28 -04003492 }
3493
John Bauman19bac1e2014-05-06 15:23:49 -04003494 Short8::Short8(RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003495 {
3496 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003497
John Bauman66b8ab22014-05-06 15:57:45 -04003498 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003499 }
3500
John Bauman19bac1e2014-05-06 15:23:49 -04003501 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003502 {
3503 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3504 }
3505
John Bauman19bac1e2014-05-06 15:23:49 -04003506 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003507 {
3508 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3509 }
3510
John Bauman19bac1e2014-05-06 15:23:49 -04003511 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003512 {
3513 return x86::psllw(lhs, rhs); // FIXME: Fallback required
3514 }
3515
John Bauman19bac1e2014-05-06 15:23:49 -04003516 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003517 {
3518 return x86::psraw(lhs, rhs); // FIXME: Fallback required
3519 }
3520
John Bauman19bac1e2014-05-06 15:23:49 -04003521 RValue<Short8> Concatenate(RValue<Short4> lo, RValue<Short4> hi)
John Bauman89401822014-05-06 15:04:28 -04003522 {
3523 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
3524 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
3525
3526 Value *long2 = UndefValue::get(Long2::getType());
3527 long2 = Nucleus::createInsertElement(long2, loLong, 0);
3528 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
3529 Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
3530
3531 return RValue<Short8>(short8);
3532 }
3533
John Bauman19bac1e2014-05-06 15:23:49 -04003534 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003535 {
3536 return x86::pmaddwd(x, y); // FIXME: Fallback required
3537 }
3538
John Bauman19bac1e2014-05-06 15:23:49 -04003539 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04003540 {
3541 return x86::pmulhw(x, y); // FIXME: Fallback required
3542 }
3543
John Bauman19bac1e2014-05-06 15:23:49 -04003544 Type *Short8::getType()
John Bauman89401822014-05-06 15:04:28 -04003545 {
3546 return VectorType::get(Short::getType(), 8);
3547 }
3548
3549 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)
3550 {
3551 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003552
3553 Constant *constantVector[8];
3554 constantVector[0] = Nucleus::createConstantShort(c0);
3555 constantVector[1] = Nucleus::createConstantShort(c1);
3556 constantVector[2] = Nucleus::createConstantShort(c2);
3557 constantVector[3] = Nucleus::createConstantShort(c3);
3558 constantVector[4] = Nucleus::createConstantShort(c4);
3559 constantVector[5] = Nucleus::createConstantShort(c5);
3560 constantVector[6] = Nucleus::createConstantShort(c6);
3561 constantVector[7] = Nucleus::createConstantShort(c7);
3562
John Bauman66b8ab22014-05-06 15:57:45 -04003563 storeValue(Nucleus::createConstantVector(constantVector, 8));
John Bauman89401822014-05-06 15:04:28 -04003564 }
3565
John Bauman19bac1e2014-05-06 15:23:49 -04003566 UShort8::UShort8(RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003567 {
3568 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04003569
John Bauman66b8ab22014-05-06 15:57:45 -04003570 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003571 }
3572
John Bauman19bac1e2014-05-06 15:23:49 -04003573 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003574 {
John Bauman66b8ab22014-05-06 15:57:45 -04003575 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003576
3577 return rhs;
3578 }
3579
3580 RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const
3581 {
John Bauman66b8ab22014-05-06 15:57:45 -04003582 Value *value = rhs.loadValue();
3583 storeValue(value);
3584
3585 return RValue<UShort8>(value);
3586 }
3587
3588 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) const
3589 {
3590 Value *value = rhs.loadValue();
3591 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003592
3593 return RValue<UShort8>(value);
3594 }
3595
John Bauman19bac1e2014-05-06 15:23:49 -04003596 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003597 {
3598 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3599 }
3600
John Bauman19bac1e2014-05-06 15:23:49 -04003601 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003602 {
3603 return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required
3604 }
3605
John Bauman19bac1e2014-05-06 15:23:49 -04003606 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04003607 {
3608 return x86::psrlw(lhs, rhs); // FIXME: Fallback required
3609 }
3610
John Bauman19bac1e2014-05-06 15:23:49 -04003611 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003612 {
3613 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3614 }
3615
John Bauman19bac1e2014-05-06 15:23:49 -04003616 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003617 {
3618 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3619 }
3620
John Bauman19bac1e2014-05-06 15:23:49 -04003621 RValue<UShort8> operator+=(const UShort8 &lhs, RValue<UShort8> rhs)
John Bauman89401822014-05-06 15:04:28 -04003622 {
3623 return lhs = lhs + rhs;
3624 }
3625
John Bauman19bac1e2014-05-06 15:23:49 -04003626 RValue<UShort8> operator~(RValue<UShort8> val)
John Bauman89401822014-05-06 15:04:28 -04003627 {
3628 return RValue<UShort8>(Nucleus::createNot(val.value));
3629 }
3630
John Bauman19bac1e2014-05-06 15:23:49 -04003631 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 -04003632 {
3633 Constant *pshufb[16];
3634 pshufb[0] = Nucleus::createConstantInt(select0 + 0);
3635 pshufb[1] = Nucleus::createConstantInt(select0 + 1);
3636 pshufb[2] = Nucleus::createConstantInt(select1 + 0);
3637 pshufb[3] = Nucleus::createConstantInt(select1 + 1);
3638 pshufb[4] = Nucleus::createConstantInt(select2 + 0);
3639 pshufb[5] = Nucleus::createConstantInt(select2 + 1);
3640 pshufb[6] = Nucleus::createConstantInt(select3 + 0);
3641 pshufb[7] = Nucleus::createConstantInt(select3 + 1);
3642 pshufb[8] = Nucleus::createConstantInt(select4 + 0);
3643 pshufb[9] = Nucleus::createConstantInt(select4 + 1);
3644 pshufb[10] = Nucleus::createConstantInt(select5 + 0);
3645 pshufb[11] = Nucleus::createConstantInt(select5 + 1);
3646 pshufb[12] = Nucleus::createConstantInt(select6 + 0);
3647 pshufb[13] = Nucleus::createConstantInt(select6 + 1);
3648 pshufb[14] = Nucleus::createConstantInt(select7 + 0);
3649 pshufb[15] = Nucleus::createConstantInt(select7 + 1);
3650
3651 Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType());
3652 Value *shuffle = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16));
3653 Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3654
3655 return RValue<UShort8>(short8);
3656 }
3657
John Bauman19bac1e2014-05-06 15:23:49 -04003658 RValue<UShort8> Concatenate(RValue<UShort4> lo, RValue<UShort4> hi)
John Bauman89401822014-05-06 15:04:28 -04003659 {
3660 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
3661 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
3662
3663 Value *long2 = UndefValue::get(Long2::getType());
3664 long2 = Nucleus::createInsertElement(long2, loLong, 0);
3665 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
3666 Value *short8 = Nucleus::createBitCast(long2, Short8::getType());
3667
3668 return RValue<UShort8>(short8);
3669 }
3670
John Bauman19bac1e2014-05-06 15:23:49 -04003671 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04003672 {
3673 return x86::pmulhuw(x, y); // FIXME: Fallback required
3674 }
3675
3676 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
John Bauman19bac1e2014-05-06 15:23:49 -04003677// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
John Bauman89401822014-05-06 15:04:28 -04003678// {
3679// Constant *pshufb[16];
3680// pshufb[0] = Nucleus::createConstantInt(element + 0);
3681// pshufb[1] = Nucleus::createConstantInt(element + 0);
3682// pshufb[2] = Nucleus::createConstantInt(element + 4);
3683// pshufb[3] = Nucleus::createConstantInt(element + 4);
3684// pshufb[4] = Nucleus::createConstantInt(element + 8);
3685// pshufb[5] = Nucleus::createConstantInt(element + 8);
3686// pshufb[6] = Nucleus::createConstantInt(element + 12);
3687// pshufb[7] = Nucleus::createConstantInt(element + 12);
3688// pshufb[8] = Nucleus::createConstantInt(element + 16);
3689// pshufb[9] = Nucleus::createConstantInt(element + 16);
3690// pshufb[10] = Nucleus::createConstantInt(element + 20);
3691// pshufb[11] = Nucleus::createConstantInt(element + 20);
3692// pshufb[12] = Nucleus::createConstantInt(element + 24);
3693// pshufb[13] = Nucleus::createConstantInt(element + 24);
3694// pshufb[14] = Nucleus::createConstantInt(element + 28);
3695// pshufb[15] = Nucleus::createConstantInt(element + 28);
3696//
3697// Value *shuffle = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(pshufb, 16));
3698// Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType());
3699//
3700// return RValue<UShort8>(short8);
3701// }
3702
John Bauman19bac1e2014-05-06 15:23:49 -04003703 Type *UShort8::getType()
John Bauman89401822014-05-06 15:04:28 -04003704 {
3705 return VectorType::get(UShort::getType(), 8);
3706 }
3707
3708 Int::Int(Argument *argument)
3709 {
John Bauman66b8ab22014-05-06 15:57:45 -04003710 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04003711 }
3712
John Bauman19bac1e2014-05-06 15:23:49 -04003713 Int::Int(RValue<Byte> cast)
John Bauman89401822014-05-06 15:04:28 -04003714 {
John Bauman89401822014-05-06 15:04:28 -04003715 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3716
John Bauman66b8ab22014-05-06 15:57:45 -04003717 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003718 }
3719
John Bauman19bac1e2014-05-06 15:23:49 -04003720 Int::Int(RValue<SByte> cast)
John Bauman89401822014-05-06 15:04:28 -04003721 {
John Bauman89401822014-05-06 15:04:28 -04003722 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3723
John Bauman66b8ab22014-05-06 15:57:45 -04003724 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003725 }
3726
John Bauman19bac1e2014-05-06 15:23:49 -04003727 Int::Int(RValue<Short> cast)
John Bauman89401822014-05-06 15:04:28 -04003728 {
John Bauman89401822014-05-06 15:04:28 -04003729 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3730
John Bauman66b8ab22014-05-06 15:57:45 -04003731 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003732 }
3733
John Bauman19bac1e2014-05-06 15:23:49 -04003734 Int::Int(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04003735 {
John Bauman89401822014-05-06 15:04:28 -04003736 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3737
John Bauman66b8ab22014-05-06 15:57:45 -04003738 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003739 }
3740
John Bauman19bac1e2014-05-06 15:23:49 -04003741 Int::Int(RValue<Int2> cast)
John Bauman89401822014-05-06 15:04:28 -04003742 {
John Bauman89401822014-05-06 15:04:28 -04003743 *this = Extract(cast, 0);
3744 }
3745
John Bauman19bac1e2014-05-06 15:23:49 -04003746 Int::Int(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04003747 {
John Bauman89401822014-05-06 15:04:28 -04003748 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3749
John Bauman66b8ab22014-05-06 15:57:45 -04003750 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003751 }
3752
John Bauman19bac1e2014-05-06 15:23:49 -04003753 Int::Int(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04003754 {
John Bauman89401822014-05-06 15:04:28 -04003755 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3756
John Bauman66b8ab22014-05-06 15:57:45 -04003757 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04003758 }
3759
3760 Int::Int()
3761 {
John Bauman89401822014-05-06 15:04:28 -04003762 }
3763
3764 Int::Int(int x)
3765 {
John Bauman66b8ab22014-05-06 15:57:45 -04003766 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04003767 }
3768
John Bauman19bac1e2014-05-06 15:23:49 -04003769 Int::Int(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003770 {
John Bauman66b8ab22014-05-06 15:57:45 -04003771 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003772 }
3773
John Bauman19bac1e2014-05-06 15:23:49 -04003774 Int::Int(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04003775 {
John Bauman66b8ab22014-05-06 15:57:45 -04003776 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003777 }
3778
3779 Int::Int(const Int &rhs)
3780 {
John Bauman66b8ab22014-05-06 15:57:45 -04003781 Value *value = rhs.loadValue();
3782 storeValue(value);
3783 }
John Bauman89401822014-05-06 15:04:28 -04003784
John Bauman66b8ab22014-05-06 15:57:45 -04003785 Int::Int(const Reference<Int> &rhs)
3786 {
3787 Value *value = rhs.loadValue();
3788 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003789 }
3790
3791 Int::Int(const UInt &rhs)
3792 {
John Bauman66b8ab22014-05-06 15:57:45 -04003793 Value *value = rhs.loadValue();
3794 storeValue(value);
3795 }
John Bauman89401822014-05-06 15:04:28 -04003796
John Bauman66b8ab22014-05-06 15:57:45 -04003797 Int::Int(const Reference<UInt> &rhs)
3798 {
3799 Value *value = rhs.loadValue();
3800 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003801 }
3802
3803 RValue<Int> Int::operator=(int rhs) const
3804 {
John Bauman66b8ab22014-05-06 15:57:45 -04003805 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04003806 }
3807
John Bauman19bac1e2014-05-06 15:23:49 -04003808 RValue<Int> Int::operator=(RValue<Int> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003809 {
John Bauman66b8ab22014-05-06 15:57:45 -04003810 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003811
3812 return rhs;
3813 }
3814
John Bauman19bac1e2014-05-06 15:23:49 -04003815 RValue<Int> Int::operator=(RValue<UInt> rhs) const
John Bauman89401822014-05-06 15:04:28 -04003816 {
John Bauman66b8ab22014-05-06 15:57:45 -04003817 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04003818
John Bauman66b8ab22014-05-06 15:57:45 -04003819 return RValue<Int>(rhs);
John Bauman89401822014-05-06 15:04:28 -04003820 }
3821
3822 RValue<Int> Int::operator=(const Int &rhs) const
3823 {
John Bauman66b8ab22014-05-06 15:57:45 -04003824 Value *value = rhs.loadValue();
3825 storeValue(value);
3826
3827 return RValue<Int>(value);
3828 }
3829
3830 RValue<Int> Int::operator=(const Reference<Int> &rhs) const
3831 {
3832 Value *value = rhs.loadValue();
3833 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003834
3835 return RValue<Int>(value);
3836 }
3837
3838 RValue<Int> Int::operator=(const UInt &rhs) const
3839 {
John Bauman66b8ab22014-05-06 15:57:45 -04003840 Value *value = rhs.loadValue();
3841 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04003842
3843 return RValue<Int>(value);
3844 }
3845
John Bauman66b8ab22014-05-06 15:57:45 -04003846 RValue<Int> Int::operator=(const Reference<UInt> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04003847 {
John Bauman66b8ab22014-05-06 15:57:45 -04003848 Value *value = rhs.loadValue();
3849 storeValue(value);
3850
3851 return RValue<Int>(value);
John Bauman89401822014-05-06 15:04:28 -04003852 }
3853
John Bauman19bac1e2014-05-06 15:23:49 -04003854 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003855 {
3856 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3857 }
3858
John Bauman19bac1e2014-05-06 15:23:49 -04003859 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003860 {
3861 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3862 }
3863
John Bauman19bac1e2014-05-06 15:23:49 -04003864 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003865 {
3866 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3867 }
3868
John Bauman19bac1e2014-05-06 15:23:49 -04003869 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003870 {
3871 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3872 }
3873
John Bauman19bac1e2014-05-06 15:23:49 -04003874 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003875 {
3876 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3877 }
3878
John Bauman19bac1e2014-05-06 15:23:49 -04003879 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003880 {
3881 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3882 }
3883
John Bauman19bac1e2014-05-06 15:23:49 -04003884 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003885 {
3886 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3887 }
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::createXor(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::createShl(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::createAShr(lhs.value, rhs.value));
3902 }
3903
John Bauman19bac1e2014-05-06 15:23:49 -04003904 RValue<Int> operator+=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003905 {
3906 return lhs = lhs + rhs;
3907 }
3908
John Bauman19bac1e2014-05-06 15:23:49 -04003909 RValue<Int> operator-=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003910 {
3911 return lhs = lhs - rhs;
3912 }
3913
John Bauman19bac1e2014-05-06 15:23:49 -04003914 RValue<Int> operator*=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003915 {
3916 return lhs = lhs * rhs;
3917 }
3918
John Bauman19bac1e2014-05-06 15:23:49 -04003919 RValue<Int> operator/=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003920 {
3921 return lhs = lhs / rhs;
3922 }
3923
John Bauman19bac1e2014-05-06 15:23:49 -04003924 RValue<Int> operator%=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003925 {
3926 return lhs = lhs % rhs;
3927 }
3928
John Bauman19bac1e2014-05-06 15:23:49 -04003929 RValue<Int> operator&=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003930 {
3931 return lhs = lhs & rhs;
3932 }
3933
John Bauman19bac1e2014-05-06 15:23:49 -04003934 RValue<Int> operator|=(const Int &lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04003935 {
3936 return lhs = lhs | rhs;
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+(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003955 {
3956 return val;
3957 }
3958
John Bauman19bac1e2014-05-06 15:23:49 -04003959 RValue<Int> operator-(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003960 {
3961 return RValue<Int>(Nucleus::createNeg(val.value));
3962 }
3963
John Bauman19bac1e2014-05-06 15:23:49 -04003964 RValue<Int> operator~(RValue<Int> val)
John Bauman89401822014-05-06 15:04:28 -04003965 {
3966 return RValue<Int>(Nucleus::createNot(val.value));
3967 }
3968
3969 RValue<Int> operator++(const Int &val, int) // Post-increment
3970 {
3971 RValue<Int> res = val;
3972
3973 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04003974 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003975
3976 return res;
3977 }
3978
3979 const Int &operator++(const Int &val) // Pre-increment
3980 {
John Bauman66b8ab22014-05-06 15:57:45 -04003981 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
3982 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003983
3984 return val;
3985 }
3986
3987 RValue<Int> operator--(const Int &val, int) // Post-decrement
3988 {
3989 RValue<Int> res = val;
3990
3991 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04003992 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04003993
3994 return res;
3995 }
3996
3997 const Int &operator--(const Int &val) // Pre-decrement
3998 {
John Bauman66b8ab22014-05-06 15:57:45 -04003999 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
4000 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004001
4002 return val;
4003 }
4004
John Bauman19bac1e2014-05-06 15:23:49 -04004005 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004006 {
4007 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4008 }
4009
John Bauman19bac1e2014-05-06 15:23:49 -04004010 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004011 {
4012 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4013 }
4014
John Bauman19bac1e2014-05-06 15:23:49 -04004015 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004016 {
4017 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4018 }
4019
John Bauman19bac1e2014-05-06 15:23:49 -04004020 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004021 {
4022 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4023 }
4024
John Bauman19bac1e2014-05-06 15:23:49 -04004025 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004026 {
4027 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4028 }
4029
John Bauman19bac1e2014-05-06 15:23:49 -04004030 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004031 {
4032 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4033 }
4034
John Bauman19bac1e2014-05-06 15:23:49 -04004035 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4036 {
4037 return IfThenElse(x > y, x, y);
4038 }
4039
4040 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4041 {
4042 return IfThenElse(x < y, x, y);
4043 }
4044
4045 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4046 {
4047 return Min(Max(x, min), max);
4048 }
4049
4050 RValue<Int> RoundInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004051 {
4052 return x86::cvtss2si(cast);
4053
John Bauman66b8ab22014-05-06 15:57:45 -04004054 // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004055 }
4056
John Bauman19bac1e2014-05-06 15:23:49 -04004057 Type *Int::getType()
John Bauman89401822014-05-06 15:04:28 -04004058 {
4059 return Type::getInt32Ty(*Nucleus::getContext());
4060 }
4061
John Bauman19bac1e2014-05-06 15:23:49 -04004062 Long::Long(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04004063 {
John Bauman66b8ab22014-05-06 15:57:45 -04004064
John Bauman89401822014-05-06 15:04:28 -04004065
4066 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4067
John Bauman66b8ab22014-05-06 15:57:45 -04004068 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004069 }
4070
John Bauman19bac1e2014-05-06 15:23:49 -04004071 Long::Long(RValue<UInt> cast)
John Bauman89401822014-05-06 15:04:28 -04004072 {
John Bauman89401822014-05-06 15:04:28 -04004073 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4074
John Bauman66b8ab22014-05-06 15:57:45 -04004075 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004076 }
4077
4078 Long::Long()
4079 {
John Bauman89401822014-05-06 15:04:28 -04004080 }
4081
John Bauman19bac1e2014-05-06 15:23:49 -04004082 Long::Long(RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004083 {
John Bauman66b8ab22014-05-06 15:57:45 -04004084 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004085 }
4086
4087 RValue<Long> Long::operator=(int64_t rhs) const
4088 {
John Bauman66b8ab22014-05-06 15:57:45 -04004089 return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04004090 }
4091
John Bauman19bac1e2014-05-06 15:23:49 -04004092 RValue<Long> Long::operator=(RValue<Long> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004093 {
John Bauman66b8ab22014-05-06 15:57:45 -04004094 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004095
4096 return rhs;
4097 }
4098
4099 RValue<Long> Long::operator=(const Long &rhs) const
4100 {
John Bauman66b8ab22014-05-06 15:57:45 -04004101 Value *value = rhs.loadValue();
4102 storeValue(value);
4103
4104 return RValue<Long>(value);
4105 }
4106
4107 RValue<Long> Long::operator=(const Reference<Long> &rhs) const
4108 {
4109 Value *value = rhs.loadValue();
4110 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004111
4112 return RValue<Long>(value);
4113 }
4114
John Bauman19bac1e2014-05-06 15:23:49 -04004115 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004116 {
4117 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4118 }
4119
John Bauman19bac1e2014-05-06 15:23:49 -04004120 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004121 {
4122 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4123 }
4124
John Bauman19bac1e2014-05-06 15:23:49 -04004125 RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004126 {
4127 return lhs = lhs + rhs;
4128 }
4129
John Bauman19bac1e2014-05-06 15:23:49 -04004130 RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs)
John Bauman89401822014-05-06 15:04:28 -04004131 {
4132 return lhs = lhs - rhs;
4133 }
4134
John Bauman66b8ab22014-05-06 15:57:45 -04004135 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
John Bauman89401822014-05-06 15:04:28 -04004136 {
John Bauman19bac1e2014-05-06 15:23:49 -04004137 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
John Bauman89401822014-05-06 15:04:28 -04004138 }
4139
John Bauman19bac1e2014-05-06 15:23:49 -04004140 Type *Long::getType()
John Bauman89401822014-05-06 15:04:28 -04004141 {
4142 return Type::getInt64Ty(*Nucleus::getContext());
4143 }
4144
4145 Long1::Long1(const Reference<UInt> &cast)
4146 {
John Bauman66b8ab22014-05-06 15:57:45 -04004147 Value *uint = cast.loadValue();
John Bauman89401822014-05-06 15:04:28 -04004148 Value *int64 = Nucleus::createZExt(uint, Long::getType());
4149 Value *long1 = Nucleus::createBitCast(int64, Long1::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04004150
4151 storeValue(long1);
John Bauman89401822014-05-06 15:04:28 -04004152 }
4153
John Bauman19bac1e2014-05-06 15:23:49 -04004154 Long1::Long1(RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004155 {
John Bauman66b8ab22014-05-06 15:57:45 -04004156 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004157 }
4158
John Bauman19bac1e2014-05-06 15:23:49 -04004159 Type *Long1::getType()
John Bauman89401822014-05-06 15:04:28 -04004160 {
John Bauman19bac1e2014-05-06 15:23:49 -04004161 if(CPUID::supportsMMX2())
4162 {
4163 return MMX::getType();
4164 }
4165 else
4166 {
4167 return VectorType::get(Long::getType(), 1);
4168 }
John Bauman89401822014-05-06 15:04:28 -04004169 }
4170
John Bauman19bac1e2014-05-06 15:23:49 -04004171 RValue<Long2> UnpackHigh(RValue<Long2> x, RValue<Long2> y)
John Bauman89401822014-05-06 15:04:28 -04004172 {
4173 Constant *shuffle[2];
4174 shuffle[0] = Nucleus::createConstantInt(1);
4175 shuffle[1] = Nucleus::createConstantInt(3);
4176
4177 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
4178
4179 return RValue<Long2>(packed);
4180 }
4181
John Bauman19bac1e2014-05-06 15:23:49 -04004182 Type *Long2::getType()
John Bauman89401822014-05-06 15:04:28 -04004183 {
4184 return VectorType::get(Long::getType(), 2);
4185 }
4186
4187 UInt::UInt(Argument *argument)
4188 {
John Bauman66b8ab22014-05-06 15:57:45 -04004189 storeValue(argument);
John Bauman89401822014-05-06 15:04:28 -04004190 }
4191
John Bauman19bac1e2014-05-06 15:23:49 -04004192 UInt::UInt(RValue<UShort> cast)
John Bauman89401822014-05-06 15:04:28 -04004193 {
John Bauman89401822014-05-06 15:04:28 -04004194 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4195
John Bauman66b8ab22014-05-06 15:57:45 -04004196 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004197 }
4198
John Bauman19bac1e2014-05-06 15:23:49 -04004199 UInt::UInt(RValue<Long> cast)
John Bauman89401822014-05-06 15:04:28 -04004200 {
John Bauman89401822014-05-06 15:04:28 -04004201 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4202
John Bauman66b8ab22014-05-06 15:57:45 -04004203 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004204 }
4205
John Bauman19bac1e2014-05-06 15:23:49 -04004206 UInt::UInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004207 {
John Bauman89401822014-05-06 15:04:28 -04004208 Value *integer = Nucleus::createFPToSI(cast.value, UInt::getType());
4209
John Bauman66b8ab22014-05-06 15:57:45 -04004210 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04004211 }
4212
4213 UInt::UInt()
4214 {
John Bauman89401822014-05-06 15:04:28 -04004215 }
4216
4217 UInt::UInt(int x)
4218 {
John Bauman66b8ab22014-05-06 15:57:45 -04004219 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04004220 }
4221
4222 UInt::UInt(unsigned int x)
4223 {
John Bauman66b8ab22014-05-06 15:57:45 -04004224 storeValue(Nucleus::createConstantInt(x));
John Bauman89401822014-05-06 15:04:28 -04004225 }
4226
John Bauman19bac1e2014-05-06 15:23:49 -04004227 UInt::UInt(RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004228 {
John Bauman66b8ab22014-05-06 15:57:45 -04004229 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004230 }
4231
John Bauman19bac1e2014-05-06 15:23:49 -04004232 UInt::UInt(RValue<Int> rhs)
John Bauman89401822014-05-06 15:04:28 -04004233 {
John Bauman66b8ab22014-05-06 15:57:45 -04004234 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004235 }
4236
4237 UInt::UInt(const UInt &rhs)
4238 {
John Bauman66b8ab22014-05-06 15:57:45 -04004239 Value *value = rhs.loadValue();
4240 storeValue(value);
4241 }
John Bauman89401822014-05-06 15:04:28 -04004242
John Bauman66b8ab22014-05-06 15:57:45 -04004243 UInt::UInt(const Reference<UInt> &rhs)
4244 {
4245 Value *value = rhs.loadValue();
4246 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004247 }
4248
4249 UInt::UInt(const Int &rhs)
4250 {
John Bauman66b8ab22014-05-06 15:57:45 -04004251 Value *value = rhs.loadValue();
4252 storeValue(value);
4253 }
John Bauman89401822014-05-06 15:04:28 -04004254
John Bauman66b8ab22014-05-06 15:57:45 -04004255 UInt::UInt(const Reference<Int> &rhs)
4256 {
4257 Value *value = rhs.loadValue();
4258 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004259 }
4260
4261 RValue<UInt> UInt::operator=(unsigned int rhs) const
4262 {
John Bauman66b8ab22014-05-06 15:57:45 -04004263 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
John Bauman89401822014-05-06 15:04:28 -04004264 }
4265
John Bauman19bac1e2014-05-06 15:23:49 -04004266 RValue<UInt> UInt::operator=(RValue<UInt> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004267 {
John Bauman66b8ab22014-05-06 15:57:45 -04004268 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004269
4270 return rhs;
4271 }
4272
John Bauman19bac1e2014-05-06 15:23:49 -04004273 RValue<UInt> UInt::operator=(RValue<Int> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004274 {
John Bauman66b8ab22014-05-06 15:57:45 -04004275 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004276
John Bauman66b8ab22014-05-06 15:57:45 -04004277 return RValue<UInt>(rhs);
John Bauman89401822014-05-06 15:04:28 -04004278 }
4279
4280 RValue<UInt> UInt::operator=(const UInt &rhs) const
4281 {
John Bauman66b8ab22014-05-06 15:57:45 -04004282 Value *value = rhs.loadValue();
4283 storeValue(value);
4284
4285 return RValue<UInt>(value);
4286 }
4287
4288 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const
4289 {
4290 Value *value = rhs.loadValue();
4291 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004292
4293 return RValue<UInt>(value);
4294 }
4295
4296 RValue<UInt> UInt::operator=(const Int &rhs) const
4297 {
John Bauman66b8ab22014-05-06 15:57:45 -04004298 Value *value = rhs.loadValue();
4299 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004300
4301 return RValue<UInt>(value);
4302 }
4303
John Bauman66b8ab22014-05-06 15:57:45 -04004304 RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04004305 {
John Bauman66b8ab22014-05-06 15:57:45 -04004306 Value *value = rhs.loadValue();
4307 storeValue(value);
4308
4309 return RValue<UInt>(value);
John Bauman89401822014-05-06 15:04:28 -04004310 }
4311
John Bauman19bac1e2014-05-06 15:23:49 -04004312 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004313 {
4314 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4315 }
4316
John Bauman19bac1e2014-05-06 15:23:49 -04004317 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004318 {
4319 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4320 }
4321
John Bauman19bac1e2014-05-06 15:23:49 -04004322 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004323 {
4324 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4325 }
4326
John Bauman19bac1e2014-05-06 15:23:49 -04004327 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004328 {
4329 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4330 }
4331
John Bauman19bac1e2014-05-06 15:23:49 -04004332 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004333 {
4334 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4335 }
4336
John Bauman19bac1e2014-05-06 15:23:49 -04004337 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004338 {
4339 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4340 }
4341
John Bauman19bac1e2014-05-06 15:23:49 -04004342 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004343 {
4344 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4345 }
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::createXor(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::createShl(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::createLShr(lhs.value, rhs.value));
4360 }
4361
John Bauman19bac1e2014-05-06 15:23:49 -04004362 RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004363 {
4364 return lhs = lhs + rhs;
4365 }
4366
John Bauman19bac1e2014-05-06 15:23:49 -04004367 RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004368 {
4369 return lhs = lhs - rhs;
4370 }
4371
John Bauman19bac1e2014-05-06 15:23:49 -04004372 RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004373 {
4374 return lhs = lhs * rhs;
4375 }
4376
John Bauman19bac1e2014-05-06 15:23:49 -04004377 RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004378 {
4379 return lhs = lhs / rhs;
4380 }
4381
John Bauman19bac1e2014-05-06 15:23:49 -04004382 RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004383 {
4384 return lhs = lhs % rhs;
4385 }
4386
John Bauman19bac1e2014-05-06 15:23:49 -04004387 RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004388 {
4389 return lhs = lhs & rhs;
4390 }
4391
John Bauman19bac1e2014-05-06 15:23:49 -04004392 RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004393 {
4394 return lhs = lhs | rhs;
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+(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004413 {
4414 return val;
4415 }
4416
John Bauman19bac1e2014-05-06 15:23:49 -04004417 RValue<UInt> operator-(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004418 {
4419 return RValue<UInt>(Nucleus::createNeg(val.value));
4420 }
4421
John Bauman19bac1e2014-05-06 15:23:49 -04004422 RValue<UInt> operator~(RValue<UInt> val)
John Bauman89401822014-05-06 15:04:28 -04004423 {
4424 return RValue<UInt>(Nucleus::createNot(val.value));
4425 }
4426
4427 RValue<UInt> operator++(const UInt &val, int) // Post-increment
4428 {
4429 RValue<UInt> res = val;
4430
4431 Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004432 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004433
4434 return res;
4435 }
4436
4437 const UInt &operator++(const UInt &val) // Pre-increment
4438 {
John Bauman66b8ab22014-05-06 15:57:45 -04004439 Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1));
4440 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004441
4442 return val;
4443 }
4444
4445 RValue<UInt> operator--(const UInt &val, int) // Post-decrement
4446 {
4447 RValue<UInt> res = val;
4448
4449 Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1));
John Bauman66b8ab22014-05-06 15:57:45 -04004450 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004451
4452 return res;
4453 }
4454
4455 const UInt &operator--(const UInt &val) // Pre-decrement
4456 {
John Bauman66b8ab22014-05-06 15:57:45 -04004457 Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1));
4458 val.storeValue(inc);
John Bauman89401822014-05-06 15:04:28 -04004459
4460 return val;
4461 }
4462
John Bauman19bac1e2014-05-06 15:23:49 -04004463 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4464 {
4465 return IfThenElse(x > y, x, y);
4466 }
4467
4468 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4469 {
4470 return IfThenElse(x < y, x, y);
4471 }
4472
4473 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4474 {
4475 return Min(Max(x, min), max);
4476 }
4477
4478 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004479 {
4480 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4481 }
4482
John Bauman19bac1e2014-05-06 15:23:49 -04004483 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004484 {
4485 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4486 }
4487
John Bauman19bac1e2014-05-06 15:23:49 -04004488 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004489 {
4490 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4491 }
4492
John Bauman19bac1e2014-05-06 15:23:49 -04004493 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004494 {
4495 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4496 }
4497
John Bauman19bac1e2014-05-06 15:23:49 -04004498 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004499 {
4500 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4501 }
4502
John Bauman19bac1e2014-05-06 15:23:49 -04004503 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
John Bauman89401822014-05-06 15:04:28 -04004504 {
4505 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4506 }
4507
John Bauman19bac1e2014-05-06 15:23:49 -04004508// RValue<UInt> RoundUInt(RValue<Float> cast)
John Bauman89401822014-05-06 15:04:28 -04004509// {
4510// return x86::cvtss2si(val); // FIXME: Unsigned
4511//
John Bauman66b8ab22014-05-06 15:57:45 -04004512// // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f));
John Bauman89401822014-05-06 15:04:28 -04004513// }
4514
John Bauman19bac1e2014-05-06 15:23:49 -04004515 Type *UInt::getType()
John Bauman89401822014-05-06 15:04:28 -04004516 {
4517 return Type::getInt32Ty(*Nucleus::getContext());
4518 }
4519
John Bauman19bac1e2014-05-06 15:23:49 -04004520// Int2::Int2(RValue<Int> cast)
4521// {
John Bauman19bac1e2014-05-06 15:23:49 -04004522// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4523// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04004524//
John Bauman19bac1e2014-05-06 15:23:49 -04004525// Constant *shuffle[2];
4526// shuffle[0] = Nucleus::createConstantInt(0);
4527// shuffle[1] = Nucleus::createConstantInt(0);
4528//
4529// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4530//
John Bauman66b8ab22014-05-06 15:57:45 -04004531// storeValue(replicate);
John Bauman19bac1e2014-05-06 15:23:49 -04004532// }
John Bauman89401822014-05-06 15:04:28 -04004533
John Bauman19bac1e2014-05-06 15:23:49 -04004534 Int2::Int2(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04004535 {
John Bauman89401822014-05-06 15:04:28 -04004536 Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType());
4537 Value *element = Nucleus::createExtractElement(long2, 0);
4538 Value *int2 = Nucleus::createBitCast(element, Int2::getType());
4539
John Bauman66b8ab22014-05-06 15:57:45 -04004540 storeValue(int2);
John Bauman89401822014-05-06 15:04:28 -04004541 }
4542
4543 Int2::Int2()
4544 {
4545 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004546 }
4547
4548 Int2::Int2(int x, int y)
4549 {
4550 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004551
4552 Constant *constantVector[2];
4553 constantVector[0] = Nucleus::createConstantInt(x);
4554 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004555 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004556
John Bauman66b8ab22014-05-06 15:57:45 -04004557 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004558 }
4559
John Bauman19bac1e2014-05-06 15:23:49 -04004560 Int2::Int2(RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004561 {
4562 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004563
John Bauman66b8ab22014-05-06 15:57:45 -04004564 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004565 }
4566
4567 Int2::Int2(const Int2 &rhs)
4568 {
4569 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004570
John Bauman66b8ab22014-05-06 15:57:45 -04004571 Value *value = rhs.loadValue();
4572 storeValue(value);
4573 }
4574
4575 Int2::Int2(const Reference<Int2> &rhs)
4576 {
4577 // xy.parent = this;
4578
4579 Value *value = rhs.loadValue();
4580 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004581 }
4582
John Bauman19bac1e2014-05-06 15:23:49 -04004583 RValue<Int2> Int2::operator=(RValue<Int2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004584 {
John Bauman66b8ab22014-05-06 15:57:45 -04004585 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004586
4587 return rhs;
4588 }
4589
4590 RValue<Int2> Int2::operator=(const Int2 &rhs) const
4591 {
John Bauman66b8ab22014-05-06 15:57:45 -04004592 Value *value = rhs.loadValue();
4593 storeValue(value);
4594
4595 return RValue<Int2>(value);
4596 }
4597
4598 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const
4599 {
4600 Value *value = rhs.loadValue();
4601 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004602
4603 return RValue<Int2>(value);
4604 }
4605
John Bauman19bac1e2014-05-06 15:23:49 -04004606 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004607 {
John Bauman19bac1e2014-05-06 15:23:49 -04004608 if(CPUID::supportsMMX2())
4609 {
4610 return x86::paddd(lhs, rhs);
4611 }
4612 else
4613 {
4614 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
4615 }
John Bauman89401822014-05-06 15:04:28 -04004616 }
4617
John Bauman19bac1e2014-05-06 15:23:49 -04004618 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004619 {
John Bauman19bac1e2014-05-06 15:23:49 -04004620 if(CPUID::supportsMMX2())
4621 {
4622 return x86::psubd(lhs, rhs);
4623 }
4624 else
4625 {
4626 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
4627 }
John Bauman89401822014-05-06 15:04:28 -04004628 }
4629
John Bauman19bac1e2014-05-06 15:23:49 -04004630// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4631// {
4632// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4633// }
4634
4635// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4636// {
4637// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4638// }
4639
4640// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4641// {
4642// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4643// }
4644
4645 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004646 {
John Bauman19bac1e2014-05-06 15:23:49 -04004647 if(CPUID::supportsMMX2())
4648 {
4649 return As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
4650 }
4651 else
4652 {
4653 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
4654 }
John Bauman89401822014-05-06 15:04:28 -04004655 }
4656
John Bauman19bac1e2014-05-06 15:23:49 -04004657 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004658 {
John Bauman19bac1e2014-05-06 15:23:49 -04004659 if(CPUID::supportsMMX2())
4660 {
4661 return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
4662 }
4663 else
4664 {
4665 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
4666 }
John Bauman89401822014-05-06 15:04:28 -04004667 }
4668
John Bauman19bac1e2014-05-06 15:23:49 -04004669 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004670 {
John Bauman19bac1e2014-05-06 15:23:49 -04004671 if(CPUID::supportsMMX2())
4672 {
4673 return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
4674 }
4675 else
4676 {
4677 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
4678 }
John Bauman89401822014-05-06 15:04:28 -04004679 }
4680
John Bauman19bac1e2014-05-06 15:23:49 -04004681 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004682 {
4683 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4684
4685 return x86::pslld(lhs, rhs);
4686 }
4687
John Bauman19bac1e2014-05-06 15:23:49 -04004688 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04004689 {
4690 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4691
4692 return x86::psrad(lhs, rhs);
4693 }
4694
John Bauman19bac1e2014-05-06 15:23:49 -04004695 RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004696 {
4697 // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value));
4698
4699 return x86::pslld(lhs, rhs);
4700 }
4701
John Bauman19bac1e2014-05-06 15:23:49 -04004702 RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004703 {
4704 // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value));
4705
4706 return x86::psrad(lhs, rhs);
4707 }
4708
John Bauman19bac1e2014-05-06 15:23:49 -04004709 RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004710 {
4711 return lhs = lhs + rhs;
4712 }
4713
John Bauman19bac1e2014-05-06 15:23:49 -04004714 RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004715 {
4716 return lhs = lhs - rhs;
4717 }
4718
John Bauman19bac1e2014-05-06 15:23:49 -04004719// RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs)
4720// {
4721// return lhs = lhs * rhs;
4722// }
John Bauman89401822014-05-06 15:04:28 -04004723
John Bauman19bac1e2014-05-06 15:23:49 -04004724// RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs)
4725// {
4726// return lhs = lhs / rhs;
4727// }
John Bauman89401822014-05-06 15:04:28 -04004728
John Bauman19bac1e2014-05-06 15:23:49 -04004729// RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs)
4730// {
4731// return lhs = lhs % rhs;
4732// }
John Bauman89401822014-05-06 15:04:28 -04004733
John Bauman19bac1e2014-05-06 15:23:49 -04004734 RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004735 {
4736 return lhs = lhs & rhs;
4737 }
4738
John Bauman19bac1e2014-05-06 15:23:49 -04004739 RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004740 {
4741 return lhs = 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
4749 RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs)
4750 {
4751 return lhs = lhs << rhs;
4752 }
4753
4754 RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs)
4755 {
4756 return lhs = lhs >> rhs;
4757 }
4758
John Bauman19bac1e2014-05-06 15:23:49 -04004759 RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004760 {
4761 return lhs = lhs << rhs;
4762 }
4763
John Bauman19bac1e2014-05-06 15:23:49 -04004764 RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04004765 {
4766 return lhs = lhs >> rhs;
4767 }
4768
John Bauman19bac1e2014-05-06 15:23:49 -04004769// RValue<Int2> operator+(RValue<Int2> val)
4770// {
4771// return val;
4772// }
4773
4774// RValue<Int2> operator-(RValue<Int2> val)
4775// {
4776// return RValue<Int2>(Nucleus::createNeg(val.value));
4777// }
4778
4779 RValue<Int2> operator~(RValue<Int2> val)
John Bauman89401822014-05-06 15:04:28 -04004780 {
John Bauman19bac1e2014-05-06 15:23:49 -04004781 if(CPUID::supportsMMX2())
4782 {
4783 return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF);
4784 }
4785 else
4786 {
4787 return RValue<Int2>(Nucleus::createNot(val.value));
4788 }
John Bauman89401822014-05-06 15:04:28 -04004789 }
4790
John Bauman19bac1e2014-05-06 15:23:49 -04004791 RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004792 {
John Bauman19bac1e2014-05-06 15:23:49 -04004793 if(CPUID::supportsMMX2())
4794 {
4795 return x86::punpckldq(x, y);
4796 }
4797 else
4798 {
4799 Constant *shuffle[2];
4800 shuffle[0] = Nucleus::createConstantInt(0);
4801 shuffle[1] = Nucleus::createConstantInt(2);
John Bauman89401822014-05-06 15:04:28 -04004802
John Bauman19bac1e2014-05-06 15:23:49 -04004803 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
John Bauman89401822014-05-06 15:04:28 -04004804
John Bauman19bac1e2014-05-06 15:23:49 -04004805 return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
4806 }
John Bauman89401822014-05-06 15:04:28 -04004807 }
John Bauman66b8ab22014-05-06 15:57:45 -04004808
John Bauman19bac1e2014-05-06 15:23:49 -04004809 RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04004810 {
John Bauman19bac1e2014-05-06 15:23:49 -04004811 if(CPUID::supportsMMX2())
4812 {
4813 return x86::punpckhdq(x, y);
4814 }
4815 else
4816 {
4817 Constant *shuffle[2];
4818 shuffle[0] = Nucleus::createConstantInt(1);
4819 shuffle[1] = Nucleus::createConstantInt(3);
John Bauman89401822014-05-06 15:04:28 -04004820
John Bauman19bac1e2014-05-06 15:23:49 -04004821 Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2));
John Bauman89401822014-05-06 15:04:28 -04004822
John Bauman19bac1e2014-05-06 15:23:49 -04004823 return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType()));
4824 }
John Bauman89401822014-05-06 15:04:28 -04004825 }
4826
John Bauman19bac1e2014-05-06 15:23:49 -04004827 RValue<Int> Extract(RValue<Int2> val, int i)
John Bauman89401822014-05-06 15:04:28 -04004828 {
4829 if(false) // FIXME: LLVM does not generate optimal code
4830 {
4831 return RValue<Int>(Nucleus::createExtractElement(val.value, i));
4832 }
4833 else
4834 {
4835 if(i == 0)
4836 {
John Bauman19bac1e2014-05-06 15:23:49 -04004837 return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), 0));
John Bauman89401822014-05-06 15:04:28 -04004838 }
4839 else
4840 {
4841 Int2 val2 = As<Int2>(UnpackHigh(val, val));
4842
4843 return Extract(val2, 0);
4844 }
4845 }
4846 }
4847
4848 // FIXME: Crashes LLVM
John Bauman19bac1e2014-05-06 15:23:49 -04004849// RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
John Bauman89401822014-05-06 15:04:28 -04004850// {
4851// return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, Nucleus::createConstantInt(i)));
4852// }
4853
John Bauman19bac1e2014-05-06 15:23:49 -04004854 Type *Int2::getType()
John Bauman89401822014-05-06 15:04:28 -04004855 {
John Bauman19bac1e2014-05-06 15:23:49 -04004856 if(CPUID::supportsMMX2())
4857 {
4858 return MMX::getType();
4859 }
4860 else
4861 {
4862 return VectorType::get(Int::getType(), 2);
4863 }
John Bauman89401822014-05-06 15:04:28 -04004864 }
4865
4866 UInt2::UInt2()
4867 {
4868 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004869 }
4870
4871 UInt2::UInt2(unsigned int x, unsigned int y)
4872 {
4873 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004874
4875 Constant *constantVector[2];
4876 constantVector[0] = Nucleus::createConstantInt(x);
4877 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004878 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004879
John Bauman66b8ab22014-05-06 15:57:45 -04004880 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004881 }
4882
John Bauman19bac1e2014-05-06 15:23:49 -04004883 UInt2::UInt2(RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004884 {
4885 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004886
John Bauman66b8ab22014-05-06 15:57:45 -04004887 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004888 }
4889
4890 UInt2::UInt2(const UInt2 &rhs)
4891 {
4892 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004893
John Bauman66b8ab22014-05-06 15:57:45 -04004894 Value *value = rhs.loadValue();
4895 storeValue(value);
4896 }
4897
4898 UInt2::UInt2(const Reference<UInt2> &rhs)
4899 {
4900 // xy.parent = this;
4901
4902 Value *value = rhs.loadValue();
4903 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004904 }
4905
John Bauman19bac1e2014-05-06 15:23:49 -04004906 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004907 {
John Bauman66b8ab22014-05-06 15:57:45 -04004908 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004909
4910 return rhs;
4911 }
4912
4913 RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
4914 {
John Bauman66b8ab22014-05-06 15:57:45 -04004915 Value *value = rhs.loadValue();
4916 storeValue(value);
4917
4918 return RValue<UInt2>(value);
4919 }
4920
4921 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const
4922 {
4923 Value *value = rhs.loadValue();
4924 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004925
4926 return RValue<UInt2>(value);
4927 }
4928
John Bauman19bac1e2014-05-06 15:23:49 -04004929 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004930 {
John Bauman19bac1e2014-05-06 15:23:49 -04004931 if(CPUID::supportsMMX2())
4932 {
4933 return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs)));
4934 }
4935 else
4936 {
4937 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
4938 }
John Bauman89401822014-05-06 15:04:28 -04004939 }
4940
John Bauman19bac1e2014-05-06 15:23:49 -04004941 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004942 {
John Bauman19bac1e2014-05-06 15:23:49 -04004943 if(CPUID::supportsMMX2())
4944 {
4945 return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs)));
4946 }
4947 else
4948 {
4949 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
4950 }
John Bauman89401822014-05-06 15:04:28 -04004951 }
4952
John Bauman19bac1e2014-05-06 15:23:49 -04004953// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4954// {
4955// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4956// }
4957
4958// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4959// {
4960// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4961// }
4962
4963// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4964// {
4965// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4966// }
4967
4968 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004969 {
John Bauman19bac1e2014-05-06 15:23:49 -04004970 if(CPUID::supportsMMX2())
4971 {
4972 return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
4973 }
4974 else
4975 {
4976 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
4977 }
John Bauman89401822014-05-06 15:04:28 -04004978 }
4979
John Bauman19bac1e2014-05-06 15:23:49 -04004980 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004981 {
John Bauman19bac1e2014-05-06 15:23:49 -04004982 if(CPUID::supportsMMX2())
4983 {
4984 return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
4985 }
4986 else
4987 {
4988 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
4989 }
John Bauman89401822014-05-06 15:04:28 -04004990 }
4991
John Bauman19bac1e2014-05-06 15:23:49 -04004992 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004993 {
John Bauman19bac1e2014-05-06 15:23:49 -04004994 if(CPUID::supportsMMX2())
4995 {
4996 return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
4997 }
4998 else
4999 {
5000 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
5001 }
John Bauman89401822014-05-06 15:04:28 -04005002 }
5003
John Bauman19bac1e2014-05-06 15:23:49 -04005004 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005005 {
5006 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5007
5008 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5009 }
5010
John Bauman19bac1e2014-05-06 15:23:49 -04005011 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005012 {
5013 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5014
5015 return x86::psrld(lhs, rhs);
5016 }
5017
John Bauman19bac1e2014-05-06 15:23:49 -04005018 RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005019 {
5020 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5021
5022 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5023 }
5024
John Bauman19bac1e2014-05-06 15:23:49 -04005025 RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005026 {
5027 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5028
5029 return x86::psrld(lhs, rhs);
5030 }
5031
John Bauman19bac1e2014-05-06 15:23:49 -04005032 RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005033 {
5034 return lhs = lhs + rhs;
5035 }
5036
John Bauman19bac1e2014-05-06 15:23:49 -04005037 RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005038 {
5039 return lhs = lhs - rhs;
5040 }
5041
John Bauman19bac1e2014-05-06 15:23:49 -04005042// RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs)
5043// {
5044// return lhs = lhs * rhs;
5045// }
John Bauman89401822014-05-06 15:04:28 -04005046
John Bauman19bac1e2014-05-06 15:23:49 -04005047// RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs)
5048// {
5049// return lhs = lhs / rhs;
5050// }
John Bauman89401822014-05-06 15:04:28 -04005051
John Bauman19bac1e2014-05-06 15:23:49 -04005052// RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs)
5053// {
5054// return lhs = lhs % rhs;
5055// }
John Bauman89401822014-05-06 15:04:28 -04005056
John Bauman19bac1e2014-05-06 15:23:49 -04005057 RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005058 {
5059 return lhs = lhs & rhs;
5060 }
5061
John Bauman19bac1e2014-05-06 15:23:49 -04005062 RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005063 {
5064 return lhs = lhs | rhs;
5065 }
5066
John Bauman19bac1e2014-05-06 15:23:49 -04005067 RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005068 {
5069 return lhs = lhs ^ rhs;
5070 }
5071
5072 RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
5073 {
5074 return lhs = lhs << rhs;
5075 }
5076
5077 RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
5078 {
5079 return lhs = lhs >> rhs;
5080 }
5081
John Bauman19bac1e2014-05-06 15:23:49 -04005082 RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> 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<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005088 {
5089 return lhs = lhs >> rhs;
5090 }
5091
John Bauman19bac1e2014-05-06 15:23:49 -04005092// RValue<UInt2> operator+(RValue<UInt2> val)
5093// {
5094// return val;
5095// }
5096
5097// RValue<UInt2> operator-(RValue<UInt2> val)
5098// {
5099// return RValue<UInt2>(Nucleus::createNeg(val.value));
5100// }
5101
5102 RValue<UInt2> operator~(RValue<UInt2> val)
John Bauman89401822014-05-06 15:04:28 -04005103 {
John Bauman19bac1e2014-05-06 15:23:49 -04005104 if(CPUID::supportsMMX2())
5105 {
5106 return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF);
5107 }
5108 else
5109 {
5110 return RValue<UInt2>(Nucleus::createNot(val.value));
5111 }
John Bauman89401822014-05-06 15:04:28 -04005112 }
5113
John Bauman19bac1e2014-05-06 15:23:49 -04005114 Type *UInt2::getType()
John Bauman89401822014-05-06 15:04:28 -04005115 {
John Bauman19bac1e2014-05-06 15:23:49 -04005116 if(CPUID::supportsMMX2())
5117 {
5118 return MMX::getType();
5119 }
5120 else
5121 {
5122 return VectorType::get(UInt::getType(), 2);
5123 }
John Bauman89401822014-05-06 15:04:28 -04005124 }
5125
John Bauman19bac1e2014-05-06 15:23:49 -04005126 Int4::Int4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005127 {
5128 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005129
5130 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
John Bauman89401822014-05-06 15:04:28 -04005131
John Bauman66b8ab22014-05-06 15:57:45 -04005132 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005133 }
5134
5135 Int4::Int4()
5136 {
5137 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005138 }
5139
5140 Int4::Int4(int xyzw)
5141 {
5142 constant(xyzw, xyzw, xyzw, xyzw);
5143 }
5144
5145 Int4::Int4(int x, int yzw)
5146 {
5147 constant(x, yzw, yzw, yzw);
5148 }
5149
5150 Int4::Int4(int x, int y, int zw)
5151 {
5152 constant(x, y, zw, zw);
5153 }
5154
5155 Int4::Int4(int x, int y, int z, int w)
5156 {
5157 constant(x, y, z, w);
5158 }
5159
5160 void Int4::constant(int x, int y, int z, int w)
5161 {
5162 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005163
5164 Constant *constantVector[4];
5165 constantVector[0] = Nucleus::createConstantInt(x);
5166 constantVector[1] = Nucleus::createConstantInt(y);
5167 constantVector[2] = Nucleus::createConstantInt(z);
5168 constantVector[3] = Nucleus::createConstantInt(w);
5169
John Bauman66b8ab22014-05-06 15:57:45 -04005170 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005171 }
5172
John Bauman19bac1e2014-05-06 15:23:49 -04005173 Int4::Int4(RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005174 {
5175 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005176
John Bauman66b8ab22014-05-06 15:57:45 -04005177 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005178 }
5179
5180 Int4::Int4(const Int4 &rhs)
5181 {
5182 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005183
John Bauman66b8ab22014-05-06 15:57:45 -04005184 Value *value = rhs.loadValue();
5185 storeValue(value);
5186 }
5187
5188 Int4::Int4(const Reference<Int4> &rhs)
5189 {
5190 // xyzw.parent = this;
5191
5192 Value *value = rhs.loadValue();
5193 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005194 }
5195
John Bauman19bac1e2014-05-06 15:23:49 -04005196 Int4::Int4(RValue<UInt4> rhs)
5197 {
5198 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005199
John Bauman66b8ab22014-05-06 15:57:45 -04005200 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005201 }
5202
5203 Int4::Int4(const UInt4 &rhs)
5204 {
5205 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005206
John Bauman66b8ab22014-05-06 15:57:45 -04005207 Value *value = rhs.loadValue();
5208 storeValue(value);
5209 }
5210
5211 Int4::Int4(const Reference<UInt4> &rhs)
5212 {
5213 // xyzw.parent = this;
5214
5215 Value *value = rhs.loadValue();
5216 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005217 }
5218
5219 RValue<Int4> Int4::operator=(RValue<Int4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005220 {
John Bauman66b8ab22014-05-06 15:57:45 -04005221 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005222
5223 return rhs;
5224 }
5225
5226 RValue<Int4> Int4::operator=(const Int4 &rhs) const
5227 {
John Bauman66b8ab22014-05-06 15:57:45 -04005228 Value *value = rhs.loadValue();
5229 storeValue(value);
5230
5231 return RValue<Int4>(value);
5232 }
5233
5234 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const
5235 {
5236 Value *value = rhs.loadValue();
5237 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005238
5239 return RValue<Int4>(value);
5240 }
5241
John Bauman19bac1e2014-05-06 15:23:49 -04005242 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005243 {
5244 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5245 }
5246
John Bauman19bac1e2014-05-06 15:23:49 -04005247 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005248 {
5249 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5250 }
5251
John Bauman19bac1e2014-05-06 15:23:49 -04005252 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005253 {
5254 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5255 }
5256
John Bauman19bac1e2014-05-06 15:23:49 -04005257// RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5258// {
5259// return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5260// }
John Bauman89401822014-05-06 15:04:28 -04005261
John Bauman19bac1e2014-05-06 15:23:49 -04005262// RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5263// {
5264// return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5265// }
John Bauman89401822014-05-06 15:04:28 -04005266
John Bauman19bac1e2014-05-06 15:23:49 -04005267 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005268 {
5269 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5270 }
5271
John Bauman19bac1e2014-05-06 15:23:49 -04005272 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005273 {
5274 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5275 }
5276
John Bauman19bac1e2014-05-06 15:23:49 -04005277 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005278 {
5279 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5280 }
5281
John Bauman19bac1e2014-05-06 15:23:49 -04005282 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005283 {
5284 // return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5285
5286 return x86::pslld(lhs, rhs);
5287 }
5288
John Bauman19bac1e2014-05-06 15:23:49 -04005289 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005290 {
5291 // return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5292
5293 return x86::psrad(lhs, rhs);
5294 }
5295
John Bauman19bac1e2014-05-06 15:23:49 -04005296 RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005297 {
5298 return lhs = lhs + rhs;
5299 }
5300
John Bauman19bac1e2014-05-06 15:23:49 -04005301 RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005302 {
5303 return lhs = lhs - rhs;
5304 }
5305
John Bauman19bac1e2014-05-06 15:23:49 -04005306 RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005307 {
5308 return lhs = lhs * rhs;
5309 }
5310
John Bauman19bac1e2014-05-06 15:23:49 -04005311// RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs)
5312// {
5313// return lhs = lhs / rhs;
5314// }
John Bauman89401822014-05-06 15:04:28 -04005315
John Bauman19bac1e2014-05-06 15:23:49 -04005316// RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs)
5317// {
5318// return lhs = lhs % rhs;
5319// }
John Bauman89401822014-05-06 15:04:28 -04005320
John Bauman19bac1e2014-05-06 15:23:49 -04005321 RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005322 {
5323 return lhs = lhs & rhs;
5324 }
5325
John Bauman19bac1e2014-05-06 15:23:49 -04005326 RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005327 {
5328 return lhs = lhs | rhs;
5329 }
5330
John Bauman19bac1e2014-05-06 15:23:49 -04005331 RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005332 {
5333 return lhs = lhs ^ rhs;
5334 }
5335
5336 RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
5337 {
5338 return lhs = lhs << rhs;
5339 }
5340
5341 RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
5342 {
5343 return lhs = lhs >> rhs;
5344 }
5345
John Bauman19bac1e2014-05-06 15:23:49 -04005346 RValue<Int4> operator+(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005347 {
5348 return val;
5349 }
5350
John Bauman19bac1e2014-05-06 15:23:49 -04005351 RValue<Int4> operator-(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005352 {
5353 return RValue<Int4>(Nucleus::createNeg(val.value));
5354 }
5355
John Bauman19bac1e2014-05-06 15:23:49 -04005356 RValue<Int4> operator~(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005357 {
5358 return RValue<Int4>(Nucleus::createNot(val.value));
5359 }
5360
John Bauman19bac1e2014-05-06 15:23:49 -04005361 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5362 {
5363 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5364 }
5365
5366 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5367 {
5368 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
5369 }
5370
5371 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5372 {
5373 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
5374 }
5375
5376 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5377 {
5378 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5379 }
5380
5381 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5382 {
5383 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
5384 }
5385
5386 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5387 {
5388 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
5389 }
5390
5391 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5392 {
5393 if(CPUID::supportsSSE4_1())
5394 {
5395 return x86::pmaxsd(x, y);
5396 }
5397 else
5398 {
5399 RValue<Int4> greater = CmpNLE(x, y);
5400 return x & greater | y & ~greater;
5401 }
5402 }
5403
5404 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5405 {
5406 if(CPUID::supportsSSE4_1())
5407 {
5408 return x86::pminsd(x, y);
5409 }
5410 else
5411 {
5412 RValue<Int4> less = CmpLT(x, y);
5413 return x & less | y & ~less;
5414 }
5415 }
5416
5417 RValue<Int4> RoundInt(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005418 {
5419 return x86::cvtps2dq(cast);
5420 }
5421
John Bauman19bac1e2014-05-06 15:23:49 -04005422 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04005423 {
5424 return x86::packssdw(x, y);
5425 }
5426
John Bauman19bac1e2014-05-06 15:23:49 -04005427 RValue<Int4> Concatenate(RValue<Int2> lo, RValue<Int2> hi)
John Bauman89401822014-05-06 15:04:28 -04005428 {
5429 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5430 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5431
5432 Value *long2 = UndefValue::get(Long2::getType());
5433 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5434 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5435 Value *int4 = Nucleus::createBitCast(long2, Int4::getType());
5436
5437 return RValue<Int4>(int4);
5438 }
5439
John Bauman19bac1e2014-05-06 15:23:49 -04005440 RValue<Int> Extract(RValue<Int4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04005441 {
5442 return RValue<Int>(Nucleus::createExtractElement(x.value, i));
5443 }
5444
John Bauman19bac1e2014-05-06 15:23:49 -04005445 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
John Bauman89401822014-05-06 15:04:28 -04005446 {
5447 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5448 }
5449
John Bauman19bac1e2014-05-06 15:23:49 -04005450 RValue<Int> SignMask(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04005451 {
5452 return x86::movmskps(As<Float4>(x));
5453 }
5454
John Bauman19bac1e2014-05-06 15:23:49 -04005455 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04005456 {
5457 return RValue<Int4>(Nucleus::createSwizzle(x.value, select));
5458 }
5459
John Bauman19bac1e2014-05-06 15:23:49 -04005460 Type *Int4::getType()
John Bauman89401822014-05-06 15:04:28 -04005461 {
5462 return VectorType::get(Int::getType(), 4);
5463 }
5464
John Bauman19bac1e2014-05-06 15:23:49 -04005465 UInt4::UInt4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005466 {
5467 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005468
5469 Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
5470
John Bauman66b8ab22014-05-06 15:57:45 -04005471 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005472 }
5473
5474 UInt4::UInt4()
5475 {
5476 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005477 }
5478
John Bauman19bac1e2014-05-06 15:23:49 -04005479 UInt4::UInt4(int xyzw)
5480 {
5481 constant(xyzw, xyzw, xyzw, xyzw);
5482 }
5483
5484 UInt4::UInt4(int x, int yzw)
5485 {
5486 constant(x, yzw, yzw, yzw);
5487 }
5488
5489 UInt4::UInt4(int x, int y, int zw)
5490 {
5491 constant(x, y, zw, zw);
5492 }
5493
5494 UInt4::UInt4(int x, int y, int z, int w)
5495 {
5496 constant(x, y, z, w);
5497 }
5498
5499 void UInt4::constant(int x, int y, int z, int w)
John Bauman89401822014-05-06 15:04:28 -04005500 {
5501 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005502
5503 Constant *constantVector[4];
5504 constantVector[0] = Nucleus::createConstantInt(x);
5505 constantVector[1] = Nucleus::createConstantInt(y);
5506 constantVector[2] = Nucleus::createConstantInt(z);
5507 constantVector[3] = Nucleus::createConstantInt(w);
5508
John Bauman66b8ab22014-05-06 15:57:45 -04005509 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005510 }
5511
John Bauman19bac1e2014-05-06 15:23:49 -04005512 UInt4::UInt4(RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005513 {
5514 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005515
John Bauman66b8ab22014-05-06 15:57:45 -04005516 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005517 }
5518
5519 UInt4::UInt4(const UInt4 &rhs)
5520 {
5521 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005522
John Bauman66b8ab22014-05-06 15:57:45 -04005523 Value *value = rhs.loadValue();
5524 storeValue(value);
5525 }
5526
5527 UInt4::UInt4(const Reference<UInt4> &rhs)
5528 {
5529 // xyzw.parent = this;
5530
5531 Value *value = rhs.loadValue();
5532 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005533 }
5534
John Bauman19bac1e2014-05-06 15:23:49 -04005535 UInt4::UInt4(RValue<Int4> rhs)
5536 {
5537 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005538
John Bauman66b8ab22014-05-06 15:57:45 -04005539 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005540 }
5541
5542 UInt4::UInt4(const Int4 &rhs)
5543 {
5544 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005545
John Bauman66b8ab22014-05-06 15:57:45 -04005546 Value *value = rhs.loadValue();
5547 storeValue(value);
5548 }
5549
5550 UInt4::UInt4(const Reference<Int4> &rhs)
5551 {
5552 // xyzw.parent = this;
5553
5554 Value *value = rhs.loadValue();
5555 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005556 }
5557
5558 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005559 {
John Bauman66b8ab22014-05-06 15:57:45 -04005560 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005561
5562 return rhs;
5563 }
5564
5565 RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
5566 {
John Bauman66b8ab22014-05-06 15:57:45 -04005567 Value *value = rhs.loadValue();
5568 storeValue(value);
5569
5570 return RValue<UInt4>(value);
5571 }
5572
5573 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const
5574 {
5575 Value *value = rhs.loadValue();
5576 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005577
5578 return RValue<UInt4>(value);
5579 }
5580
John Bauman19bac1e2014-05-06 15:23:49 -04005581 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005582 {
5583 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5584 }
5585
John Bauman19bac1e2014-05-06 15:23:49 -04005586 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005587 {
5588 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5589 }
5590
John Bauman19bac1e2014-05-06 15:23:49 -04005591 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005592 {
5593 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5594 }
5595
John Bauman19bac1e2014-05-06 15:23:49 -04005596// RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5597// {
5598// return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5599// }
John Bauman89401822014-05-06 15:04:28 -04005600
John Bauman19bac1e2014-05-06 15:23:49 -04005601// RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5602// {
5603// return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5604// }
John Bauman89401822014-05-06 15:04:28 -04005605
John Bauman19bac1e2014-05-06 15:23:49 -04005606 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005607 {
5608 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5609 }
5610
John Bauman19bac1e2014-05-06 15:23:49 -04005611 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005612 {
5613 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5614 }
5615
John Bauman19bac1e2014-05-06 15:23:49 -04005616 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005617 {
5618 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5619 }
5620
John Bauman19bac1e2014-05-06 15:23:49 -04005621 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005622 {
5623 // return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5624
5625 return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
5626 }
5627
John Bauman19bac1e2014-05-06 15:23:49 -04005628 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005629 {
5630 // return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5631
5632 return x86::psrld(lhs, rhs);
5633 }
5634
John Bauman19bac1e2014-05-06 15:23:49 -04005635 RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005636 {
5637 return lhs = lhs + rhs;
5638 }
5639
John Bauman19bac1e2014-05-06 15:23:49 -04005640 RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005641 {
5642 return lhs = lhs - rhs;
5643 }
5644
John Bauman19bac1e2014-05-06 15:23:49 -04005645 RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005646 {
5647 return lhs = lhs * rhs;
5648 }
5649
John Bauman19bac1e2014-05-06 15:23:49 -04005650// RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs)
5651// {
5652// return lhs = lhs / rhs;
5653// }
John Bauman89401822014-05-06 15:04:28 -04005654
John Bauman19bac1e2014-05-06 15:23:49 -04005655// RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs)
5656// {
5657// return lhs = lhs % rhs;
5658// }
John Bauman89401822014-05-06 15:04:28 -04005659
John Bauman19bac1e2014-05-06 15:23:49 -04005660 RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005661 {
5662 return lhs = lhs & rhs;
5663 }
5664
John Bauman19bac1e2014-05-06 15:23:49 -04005665 RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005666 {
5667 return lhs = lhs | rhs;
5668 }
5669
John Bauman19bac1e2014-05-06 15:23:49 -04005670 RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005671 {
5672 return lhs = lhs ^ rhs;
5673 }
5674
5675 RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
5676 {
5677 return lhs = lhs << rhs;
5678 }
5679
5680 RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
5681 {
5682 return lhs = lhs >> rhs;
5683 }
5684
John Bauman19bac1e2014-05-06 15:23:49 -04005685 RValue<UInt4> operator+(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005686 {
5687 return val;
5688 }
5689
John Bauman19bac1e2014-05-06 15:23:49 -04005690 RValue<UInt4> operator-(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005691 {
5692 return RValue<UInt4>(Nucleus::createNeg(val.value));
5693 }
5694
John Bauman19bac1e2014-05-06 15:23:49 -04005695 RValue<UInt4> operator~(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005696 {
5697 return RValue<UInt4>(Nucleus::createNot(val.value));
5698 }
5699
John Bauman19bac1e2014-05-06 15:23:49 -04005700 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5701 {
5702 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5703 }
5704
5705 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5706 {
5707 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5708 }
5709
5710 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5711 {
5712 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5713 }
5714
5715 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5716 {
5717 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5718 }
5719
5720 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5721 {
5722 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5723 }
5724
5725 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5726 {
5727 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5728 }
5729
5730 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5731 {
5732 if(CPUID::supportsSSE4_1())
5733 {
5734 return x86::pmaxud(x, y);
5735 }
5736 else
5737 {
5738 RValue<UInt4> greater = CmpNLE(x, y);
5739 return x & greater | y & ~greater;
5740 }
5741 }
5742
5743 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5744 {
5745 if(CPUID::supportsSSE4_1())
5746 {
5747 return x86::pminud(x, y);
5748 }
5749 else
5750 {
5751 RValue<UInt4> less = CmpLT(x, y);
5752 return x & less | y & ~less;
5753 }
5754 }
5755
5756 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04005757 {
5758 return x86::packusdw(x, y); // FIXME: Fallback required
5759 }
5760
John Bauman19bac1e2014-05-06 15:23:49 -04005761 RValue<UInt4> Concatenate(RValue<UInt2> lo, RValue<UInt2> hi)
John Bauman89401822014-05-06 15:04:28 -04005762 {
5763 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5764 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5765
5766 Value *long2 = UndefValue::get(Long2::getType());
5767 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5768 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5769 Value *uint4 = Nucleus::createBitCast(long2, Int4::getType());
5770
5771 return RValue<UInt4>(uint4);
5772 }
5773
John Bauman19bac1e2014-05-06 15:23:49 -04005774 Type *UInt4::getType()
John Bauman89401822014-05-06 15:04:28 -04005775 {
5776 return VectorType::get(UInt::getType(), 4);
5777 }
5778
John Bauman19bac1e2014-05-06 15:23:49 -04005779 Float::Float(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04005780 {
John Bauman89401822014-05-06 15:04:28 -04005781 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5782
John Bauman66b8ab22014-05-06 15:57:45 -04005783 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04005784 }
5785
5786 Float::Float()
5787 {
John Bauman66b8ab22014-05-06 15:57:45 -04005788
John Bauman89401822014-05-06 15:04:28 -04005789 }
5790
5791 Float::Float(float x)
5792 {
John Bauman66b8ab22014-05-06 15:57:45 -04005793 storeValue(Nucleus::createConstantFloat(x));
John Bauman89401822014-05-06 15:04:28 -04005794 }
5795
John Bauman19bac1e2014-05-06 15:23:49 -04005796 Float::Float(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005797 {
John Bauman66b8ab22014-05-06 15:57:45 -04005798 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005799 }
5800
5801 Float::Float(const Float &rhs)
5802 {
John Bauman66b8ab22014-05-06 15:57:45 -04005803 Value *value = rhs.loadValue();
5804 storeValue(value);
5805 }
John Bauman89401822014-05-06 15:04:28 -04005806
John Bauman66b8ab22014-05-06 15:57:45 -04005807 Float::Float(const Reference<Float> &rhs)
5808 {
5809 Value *value = rhs.loadValue();
5810 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005811 }
5812
John Bauman19bac1e2014-05-06 15:23:49 -04005813 RValue<Float> Float::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005814 {
John Bauman66b8ab22014-05-06 15:57:45 -04005815 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005816
5817 return rhs;
5818 }
5819
5820 RValue<Float> Float::operator=(const Float &rhs) const
5821 {
John Bauman66b8ab22014-05-06 15:57:45 -04005822 Value *value = rhs.loadValue();
5823 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005824
5825 return RValue<Float>(value);
5826 }
5827
John Bauman66b8ab22014-05-06 15:57:45 -04005828 RValue<Float> Float::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04005829 {
John Bauman66b8ab22014-05-06 15:57:45 -04005830 Value *value = rhs.loadValue();
5831 storeValue(value);
5832
5833 return RValue<Float>(value);
John Bauman89401822014-05-06 15:04:28 -04005834 }
5835
John Bauman19bac1e2014-05-06 15:23:49 -04005836 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005837 {
5838 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5839 }
5840
John Bauman19bac1e2014-05-06 15:23:49 -04005841 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005842 {
5843 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5844 }
5845
John Bauman19bac1e2014-05-06 15:23:49 -04005846 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005847 {
5848 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5849 }
5850
John Bauman19bac1e2014-05-06 15:23:49 -04005851 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005852 {
5853 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5854 }
5855
John Bauman19bac1e2014-05-06 15:23:49 -04005856 RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005857 {
5858 return lhs = lhs + rhs;
5859 }
5860
John Bauman19bac1e2014-05-06 15:23:49 -04005861 RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005862 {
5863 return lhs = lhs - rhs;
5864 }
5865
John Bauman19bac1e2014-05-06 15:23:49 -04005866 RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005867 {
5868 return lhs = lhs * rhs;
5869 }
5870
John Bauman19bac1e2014-05-06 15:23:49 -04005871 RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005872 {
5873 return lhs = lhs / rhs;
5874 }
5875
John Bauman19bac1e2014-05-06 15:23:49 -04005876 RValue<Float> operator+(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005877 {
5878 return val;
5879 }
5880
John Bauman19bac1e2014-05-06 15:23:49 -04005881 RValue<Float> operator-(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005882 {
5883 return RValue<Float>(Nucleus::createFNeg(val.value));
5884 }
5885
John Bauman19bac1e2014-05-06 15:23:49 -04005886 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005887 {
5888 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5889 }
5890
John Bauman19bac1e2014-05-06 15:23:49 -04005891 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005892 {
5893 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5894 }
5895
John Bauman19bac1e2014-05-06 15:23:49 -04005896 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005897 {
5898 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5899 }
5900
John Bauman19bac1e2014-05-06 15:23:49 -04005901 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005902 {
5903 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5904 }
5905
John Bauman19bac1e2014-05-06 15:23:49 -04005906 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005907 {
5908 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5909 }
5910
John Bauman19bac1e2014-05-06 15:23:49 -04005911 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005912 {
5913 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5914 }
5915
John Bauman19bac1e2014-05-06 15:23:49 -04005916 RValue<Float> Abs(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005917 {
John Bauman66b8ab22014-05-06 15:57:45 -04005918 return IfThenElse(x > 0.0f, x, -x);
John Bauman89401822014-05-06 15:04:28 -04005919 }
5920
John Bauman19bac1e2014-05-06 15:23:49 -04005921 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04005922 {
5923 return IfThenElse(x > y, x, y);
5924 }
5925
John Bauman19bac1e2014-05-06 15:23:49 -04005926 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04005927 {
5928 return IfThenElse(x < y, x, y);
5929 }
5930
John Bauman19bac1e2014-05-06 15:23:49 -04005931 RValue<Float> Rcp_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005932 {
5933 return x86::rcpss(x);
5934 }
John Bauman66b8ab22014-05-06 15:57:45 -04005935
John Bauman19bac1e2014-05-06 15:23:49 -04005936 RValue<Float> RcpSqrt_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005937 {
5938 return x86::rsqrtss(x);
5939 }
5940
John Bauman19bac1e2014-05-06 15:23:49 -04005941 RValue<Float> Sqrt(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005942 {
5943 return x86::sqrtss(x);
5944 }
5945
John Bauman19bac1e2014-05-06 15:23:49 -04005946 RValue<Float> Round(RValue<Float> x)
5947 {
5948 if(CPUID::supportsSSE4_1())
5949 {
5950 return x86::roundss(x, 0);
5951 }
5952 else
5953 {
5954 return Float4(Round(Float4(x))).x;
5955 }
5956 }
5957
5958 RValue<Float> Trunc(RValue<Float> x)
5959 {
5960 if(CPUID::supportsSSE4_1())
5961 {
5962 return x86::roundss(x, 3);
5963 }
5964 else
5965 {
5966 return Float(Int(x)); // Rounded toward zero
5967 }
5968 }
5969
5970 RValue<Float> Frac(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005971 {
5972 if(CPUID::supportsSSE4_1())
5973 {
5974 return x - x86::floorss(x);
5975 }
5976 else
5977 {
John Bauman19bac1e2014-05-06 15:23:49 -04005978 return Float4(Frac(Float4(x))).x;
John Bauman89401822014-05-06 15:04:28 -04005979 }
5980 }
5981
John Bauman19bac1e2014-05-06 15:23:49 -04005982 RValue<Float> Floor(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005983 {
5984 if(CPUID::supportsSSE4_1())
5985 {
5986 return x86::floorss(x);
5987 }
5988 else
5989 {
5990 return Float4(Floor(Float4(x))).x;
5991 }
5992 }
5993
John Bauman19bac1e2014-05-06 15:23:49 -04005994 RValue<Float> Ceil(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005995 {
John Bauman19bac1e2014-05-06 15:23:49 -04005996 if(CPUID::supportsSSE4_1())
5997 {
5998 return x86::ceilss(x);
5999 }
6000 else
6001 {
6002 return Float4(Ceil(Float4(x))).x;
6003 }
John Bauman89401822014-05-06 15:04:28 -04006004 }
6005
John Bauman19bac1e2014-05-06 15:23:49 -04006006 Type *Float::getType()
John Bauman89401822014-05-06 15:04:28 -04006007 {
6008 return Type::getFloatTy(*Nucleus::getContext());
6009 }
6010
John Bauman19bac1e2014-05-06 15:23:49 -04006011 Float2::Float2(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04006012 {
6013 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006014
6015 Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
6016 Value *int64 = Nucleus::createExtractElement(int64x2, 0);
6017 Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
6018
John Bauman66b8ab22014-05-06 15:57:45 -04006019 storeValue(float2);
John Bauman89401822014-05-06 15:04:28 -04006020 }
6021
John Bauman19bac1e2014-05-06 15:23:49 -04006022 Type *Float2::getType()
John Bauman89401822014-05-06 15:04:28 -04006023 {
6024 return VectorType::get(Float::getType(), 2);
6025 }
6026
John Bauman19bac1e2014-05-06 15:23:49 -04006027 Float4::Float4(RValue<Byte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006028 {
6029 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006030
6031 #if 0
6032 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6033 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006034 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006035
6036 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6037 Value *f32x = Nucleus::createUIToFP(i8x, Float::getType());
6038 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6039
6040 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6041 Value *f32y = Nucleus::createUIToFP(i8y, Float::getType());
6042 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6043
6044 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6045 Value *f32z = Nucleus::createUIToFP(i8z, Float::getType());
6046 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6047
6048 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6049 Value *f32w = Nucleus::createUIToFP(i8w, Float::getType());
6050 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6051 #else
6052 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6053 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6054
6055 Value *e;
6056
6057 if(CPUID::supportsSSE4_1())
6058 {
6059 e = x86::pmovzxbd(RValue<Int4>(a)).value;
6060 }
6061 else
6062 {
6063 Constant *swizzle[16];
6064 swizzle[0] = Nucleus::createConstantInt(0);
6065 swizzle[1] = Nucleus::createConstantInt(16);
6066 swizzle[2] = Nucleus::createConstantInt(1);
6067 swizzle[3] = Nucleus::createConstantInt(17);
6068 swizzle[4] = Nucleus::createConstantInt(2);
6069 swizzle[5] = Nucleus::createConstantInt(18);
6070 swizzle[6] = Nucleus::createConstantInt(3);
6071 swizzle[7] = Nucleus::createConstantInt(19);
6072 swizzle[8] = Nucleus::createConstantInt(4);
6073 swizzle[9] = Nucleus::createConstantInt(20);
6074 swizzle[10] = Nucleus::createConstantInt(5);
6075 swizzle[11] = Nucleus::createConstantInt(21);
6076 swizzle[12] = Nucleus::createConstantInt(6);
6077 swizzle[13] = Nucleus::createConstantInt(22);
6078 swizzle[14] = Nucleus::createConstantInt(7);
6079 swizzle[15] = Nucleus::createConstantInt(23);
6080
6081 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6082 Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16));
6083
6084 Constant *swizzle2[8];
6085 swizzle2[0] = Nucleus::createConstantInt(0);
6086 swizzle2[1] = Nucleus::createConstantInt(8);
6087 swizzle2[2] = Nucleus::createConstantInt(1);
6088 swizzle2[3] = Nucleus::createConstantInt(9);
6089 swizzle2[4] = Nucleus::createConstantInt(2);
6090 swizzle2[5] = Nucleus::createConstantInt(10);
6091 swizzle2[6] = Nucleus::createConstantInt(3);
6092 swizzle2[7] = Nucleus::createConstantInt(11);
6093
6094 Value *d = Nucleus::createBitCast(c, Short8::getType());
6095 e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8));
6096 }
6097
6098 Value *f = Nucleus::createBitCast(e, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006099 Value *g = Nucleus::createSIToFP(f, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006100 Value *xyzw = g;
6101 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006102
6103 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006104 }
6105
John Bauman19bac1e2014-05-06 15:23:49 -04006106 Float4::Float4(RValue<SByte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006107 {
6108 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006109
6110 #if 0
6111 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6112 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006113 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006114
6115 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6116 Value *f32x = Nucleus::createSIToFP(i8x, Float::getType());
6117 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6118
6119 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6120 Value *f32y = Nucleus::createSIToFP(i8y, Float::getType());
6121 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6122
6123 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6124 Value *f32z = Nucleus::createSIToFP(i8z, Float::getType());
6125 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6126
6127 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6128 Value *f32w = Nucleus::createSIToFP(i8w, Float::getType());
6129 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6130 #else
6131 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6132 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6133
6134 Value *g;
6135
6136 if(CPUID::supportsSSE4_1())
6137 {
6138 g = x86::pmovsxbd(RValue<Int4>(a)).value;
6139 }
6140 else
6141 {
6142 Constant *swizzle[16];
6143 swizzle[0] = Nucleus::createConstantInt(0);
6144 swizzle[1] = Nucleus::createConstantInt(0);
6145 swizzle[2] = Nucleus::createConstantInt(1);
6146 swizzle[3] = Nucleus::createConstantInt(1);
6147 swizzle[4] = Nucleus::createConstantInt(2);
6148 swizzle[5] = Nucleus::createConstantInt(2);
6149 swizzle[6] = Nucleus::createConstantInt(3);
6150 swizzle[7] = Nucleus::createConstantInt(3);
6151 swizzle[8] = Nucleus::createConstantInt(4);
6152 swizzle[9] = Nucleus::createConstantInt(4);
6153 swizzle[10] = Nucleus::createConstantInt(5);
6154 swizzle[11] = Nucleus::createConstantInt(5);
6155 swizzle[12] = Nucleus::createConstantInt(6);
6156 swizzle[13] = Nucleus::createConstantInt(6);
6157 swizzle[14] = Nucleus::createConstantInt(7);
6158 swizzle[15] = Nucleus::createConstantInt(7);
6159
6160 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6161 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16));
6162
6163 Constant *swizzle2[8];
6164 swizzle2[0] = Nucleus::createConstantInt(0);
6165 swizzle2[1] = Nucleus::createConstantInt(0);
6166 swizzle2[2] = Nucleus::createConstantInt(1);
6167 swizzle2[3] = Nucleus::createConstantInt(1);
6168 swizzle2[4] = Nucleus::createConstantInt(2);
6169 swizzle2[5] = Nucleus::createConstantInt(2);
6170 swizzle2[6] = Nucleus::createConstantInt(3);
6171 swizzle2[7] = Nucleus::createConstantInt(3);
6172
6173 Value *d = Nucleus::createBitCast(c, Short8::getType());
6174 Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8));
6175
6176 Value *f = Nucleus::createBitCast(e, Int4::getType());
6177 // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24));
6178 g = x86::psrad(RValue<Int4>(f), 24).value;
6179 }
6180
John Bauman19bac1e2014-05-06 15:23:49 -04006181 Value *xyzw = Nucleus::createSIToFP(g, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006182 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006183
6184 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006185 }
6186
John Bauman19bac1e2014-05-06 15:23:49 -04006187 Float4::Float4(RValue<Short4> cast)
John Bauman89401822014-05-06 15:04:28 -04006188 {
6189 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006190
6191 #if 0
6192 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6193 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006194 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006195
6196 Value *i16x = Nucleus::createExtractElement(cast.value, 0);
6197 Value *f32x = Nucleus::createSIToFP(i16x, Float::getType());
6198 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6199
6200 Value *i16y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6201 Value *f32y = Nucleus::createSIToFP(i16y, Float::getType());
6202 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6203
6204 Value *i16z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6205 Value *f32z = Nucleus::createSIToFP(i16z, Float::getType());
6206 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6207
6208 Value *i16w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6209 Value *f32w = Nucleus::createSIToFP(i16w, Float::getType());
6210 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6211 #else
6212 Value *long2 = UndefValue::get(Long2::getType());
6213 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
6214 long2 = Nucleus::createInsertElement(long2, element, 0);
6215 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
6216
6217 Value *xyzw;
6218
6219 if(CPUID::supportsSSE4_1())
6220 {
6221 Value *c = x86::pmovsxwd(vector).value;
6222
John Bauman19bac1e2014-05-06 15:23:49 -04006223 xyzw = Nucleus::createSIToFP(c, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006224 }
6225 else
6226 {
6227 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
6228
6229 Constant *swizzle[8];
6230 swizzle[0] = Nucleus::createConstantInt(0);
6231 swizzle[1] = Nucleus::createConstantInt(0);
6232 swizzle[2] = Nucleus::createConstantInt(1);
6233 swizzle[3] = Nucleus::createConstantInt(1);
6234 swizzle[4] = Nucleus::createConstantInt(2);
6235 swizzle[5] = Nucleus::createConstantInt(2);
6236 swizzle[6] = Nucleus::createConstantInt(3);
6237 swizzle[7] = Nucleus::createConstantInt(3);
John Bauman66b8ab22014-05-06 15:57:45 -04006238
John Bauman89401822014-05-06 15:04:28 -04006239 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8));
6240 Value *d = Nucleus::createBitCast(c, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006241 Value *e = Nucleus::createSIToFP(d, Float4::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04006242
John Bauman89401822014-05-06 15:04:28 -04006243 Constant *constantVector[4];
6244 constantVector[0] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6245 constantVector[1] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6246 constantVector[2] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6247 constantVector[3] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6248
6249 xyzw = Nucleus::createFMul(e, Nucleus::createConstantVector(constantVector, 4));
6250 }
6251 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006252
6253 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006254 }
6255
John Bauman19bac1e2014-05-06 15:23:49 -04006256 Float4::Float4(RValue<UShort4> cast)
John Bauman89401822014-05-06 15:04:28 -04006257 {
6258 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006259
6260 #if 0
6261 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6262 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006263 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006264
6265 Value *i16x = Nucleus::createExtractElement(cast.value, 0);
6266 Value *f32x = Nucleus::createUIToFP(i16x, Float::getType());
6267 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6268
6269 Value *i16y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6270 Value *f32y = Nucleus::createUIToFP(i16y, Float::getType());
6271 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6272
6273 Value *i16z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6274 Value *f32z = Nucleus::createUIToFP(i16z, Float::getType());
6275 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6276
6277 Value *i16w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6278 Value *f32w = Nucleus::createUIToFP(i16w, Float::getType());
6279 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6280 #else
6281 Value *long2 = UndefValue::get(Long2::getType());
6282 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
6283 long2 = Nucleus::createInsertElement(long2, element, 0);
6284 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
6285
6286 Value *c;
John Bauman66b8ab22014-05-06 15:57:45 -04006287
John Bauman89401822014-05-06 15:04:28 -04006288 if(CPUID::supportsSSE4_1())
6289 {
6290 c = x86::pmovzxwd(RValue<Int4>(vector)).value;
6291 }
6292 else
6293 {
6294 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
6295
6296 Constant *swizzle[8];
6297 swizzle[0] = Nucleus::createConstantInt(0);
6298 swizzle[1] = Nucleus::createConstantInt(8);
6299 swizzle[2] = Nucleus::createConstantInt(1);
6300 swizzle[3] = Nucleus::createConstantInt(9);
6301 swizzle[4] = Nucleus::createConstantInt(2);
6302 swizzle[5] = Nucleus::createConstantInt(10);
6303 swizzle[6] = Nucleus::createConstantInt(3);
6304 swizzle[7] = Nucleus::createConstantInt(11);
6305
6306 c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8));
6307 }
6308
6309 Value *d = Nucleus::createBitCast(c, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006310 Value *e = Nucleus::createSIToFP(d, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006311 Value *xyzw = e;
6312 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006313
6314 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006315 }
6316
John Bauman19bac1e2014-05-06 15:23:49 -04006317 Float4::Float4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04006318 {
6319 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006320
6321 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006322
John Bauman66b8ab22014-05-06 15:57:45 -04006323 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006324 }
6325
John Bauman19bac1e2014-05-06 15:23:49 -04006326 Float4::Float4(RValue<UInt4> cast)
John Bauman89401822014-05-06 15:04:28 -04006327 {
6328 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006329
6330 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
6331
John Bauman66b8ab22014-05-06 15:57:45 -04006332 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006333 }
6334
6335 Float4::Float4()
6336 {
6337 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006338 }
John Bauman66b8ab22014-05-06 15:57:45 -04006339
John Bauman89401822014-05-06 15:04:28 -04006340 Float4::Float4(float xyzw)
6341 {
6342 constant(xyzw, xyzw, xyzw, xyzw);
6343 }
6344
6345 Float4::Float4(float x, float yzw)
6346 {
6347 constant(x, yzw, yzw, yzw);
6348 }
6349
6350 Float4::Float4(float x, float y, float zw)
6351 {
6352 constant(x, y, zw, zw);
6353 }
6354
6355 Float4::Float4(float x, float y, float z, float w)
6356 {
6357 constant(x, y, z, w);
6358 }
6359
6360 void Float4::constant(float x, float y, float z, float w)
6361 {
6362 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006363
6364 Constant *constantVector[4];
6365 constantVector[0] = Nucleus::createConstantFloat(x);
6366 constantVector[1] = Nucleus::createConstantFloat(y);
6367 constantVector[2] = Nucleus::createConstantFloat(z);
6368 constantVector[3] = Nucleus::createConstantFloat(w);
6369
John Bauman66b8ab22014-05-06 15:57:45 -04006370 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04006371 }
6372
John Bauman19bac1e2014-05-06 15:23:49 -04006373 Float4::Float4(RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006374 {
6375 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006376
John Bauman66b8ab22014-05-06 15:57:45 -04006377 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006378 }
6379
6380 Float4::Float4(const Float4 &rhs)
6381 {
6382 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006383
John Bauman66b8ab22014-05-06 15:57:45 -04006384 Value *value = rhs.loadValue();
6385 storeValue(value);
6386 }
6387
6388 Float4::Float4(const Reference<Float4> &rhs)
6389 {
6390 xyzw.parent = this;
6391
6392 Value *value = rhs.loadValue();
6393 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006394 }
6395
John Bauman19bac1e2014-05-06 15:23:49 -04006396 Float4::Float4(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006397 {
6398 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006399
John Bauman66b8ab22014-05-06 15:57:45 -04006400 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006401 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
6402
6403 Constant *swizzle[4];
6404 swizzle[0] = Nucleus::createConstantInt(0);
6405 swizzle[1] = Nucleus::createConstantInt(0);
6406 swizzle[2] = Nucleus::createConstantInt(0);
6407 swizzle[3] = Nucleus::createConstantInt(0);
6408
6409 Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4));
6410
John Bauman66b8ab22014-05-06 15:57:45 -04006411 storeValue(replicate);
John Bauman89401822014-05-06 15:04:28 -04006412 }
6413
6414 Float4::Float4(const Float &rhs)
6415 {
6416 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006417
John Bauman66b8ab22014-05-06 15:57:45 -04006418 *this = RValue<Float>(rhs.loadValue());
6419 }
John Bauman89401822014-05-06 15:04:28 -04006420
John Bauman66b8ab22014-05-06 15:57:45 -04006421 Float4::Float4(const Reference<Float> &rhs)
6422 {
6423 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006424
John Bauman66b8ab22014-05-06 15:57:45 -04006425 *this = RValue<Float>(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006426 }
6427
6428 RValue<Float4> Float4::operator=(float x) const
6429 {
6430 return *this = Float4(x, x, x, x);
6431 }
6432
John Bauman19bac1e2014-05-06 15:23:49 -04006433 RValue<Float4> Float4::operator=(RValue<Float4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006434 {
John Bauman66b8ab22014-05-06 15:57:45 -04006435 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006436
6437 return rhs;
6438 }
6439
6440 RValue<Float4> Float4::operator=(const Float4 &rhs) const
6441 {
John Bauman66b8ab22014-05-06 15:57:45 -04006442 Value *value = rhs.loadValue();
6443 storeValue(value);
6444
6445 return RValue<Float4>(value);
6446 }
6447
6448 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const
6449 {
6450 Value *value = rhs.loadValue();
6451 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006452
6453 return RValue<Float4>(value);
6454 }
6455
John Bauman19bac1e2014-05-06 15:23:49 -04006456 RValue<Float4> Float4::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006457 {
6458 return *this = Float4(rhs);
6459 }
6460
6461 RValue<Float4> Float4::operator=(const Float &rhs) const
6462 {
6463 return *this = Float4(rhs);
6464 }
6465
John Bauman66b8ab22014-05-06 15:57:45 -04006466 RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04006467 {
John Bauman66b8ab22014-05-06 15:57:45 -04006468 return *this = Float4(rhs);
John Bauman89401822014-05-06 15:04:28 -04006469 }
6470
John Bauman19bac1e2014-05-06 15:23:49 -04006471 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006472 {
6473 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
6474 }
6475
John Bauman19bac1e2014-05-06 15:23:49 -04006476 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006477 {
6478 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
6479 }
6480
John Bauman19bac1e2014-05-06 15:23:49 -04006481 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006482 {
6483 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
6484 }
6485
John Bauman19bac1e2014-05-06 15:23:49 -04006486 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006487 {
6488 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6489 }
6490
John Bauman19bac1e2014-05-06 15:23:49 -04006491 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006492 {
6493 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
6494 }
6495
John Bauman19bac1e2014-05-06 15:23:49 -04006496 RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006497 {
6498 return lhs = lhs + rhs;
6499 }
6500
John Bauman19bac1e2014-05-06 15:23:49 -04006501 RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006502 {
6503 return lhs = lhs - rhs;
6504 }
6505
John Bauman19bac1e2014-05-06 15:23:49 -04006506 RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006507 {
6508 return lhs = lhs * rhs;
6509 }
6510
John Bauman19bac1e2014-05-06 15:23:49 -04006511 RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006512 {
6513 return lhs = lhs / rhs;
6514 }
6515
John Bauman19bac1e2014-05-06 15:23:49 -04006516 RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006517 {
6518 return lhs = lhs % rhs;
6519 }
6520
John Bauman19bac1e2014-05-06 15:23:49 -04006521 RValue<Float4> operator+(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006522 {
6523 return val;
6524 }
6525
John Bauman19bac1e2014-05-06 15:23:49 -04006526 RValue<Float4> operator-(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006527 {
6528 return RValue<Float4>(Nucleus::createFNeg(val.value));
6529 }
6530
John Bauman19bac1e2014-05-06 15:23:49 -04006531 RValue<Float4> Abs(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006532 {
6533 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6534
6535 Constant *constantVector[4];
6536 constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF);
6537 constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF);
6538 constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF);
6539 constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF);
6540
6541 Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4));
6542
6543 return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType()));
6544 }
6545
John Bauman19bac1e2014-05-06 15:23:49 -04006546 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006547 {
6548 return x86::maxps(x, y);
6549 }
6550
John Bauman19bac1e2014-05-06 15:23:49 -04006551 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006552 {
6553 return x86::minps(x, y);
6554 }
6555
John Bauman19bac1e2014-05-06 15:23:49 -04006556 RValue<Float4> Rcp_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006557 {
6558 return x86::rcpps(x);
6559 }
John Bauman66b8ab22014-05-06 15:57:45 -04006560
John Bauman19bac1e2014-05-06 15:23:49 -04006561 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006562 {
6563 return x86::rsqrtps(x);
6564 }
6565
John Bauman19bac1e2014-05-06 15:23:49 -04006566 RValue<Float4> Sqrt(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006567 {
6568 return x86::sqrtps(x);
6569 }
6570
John Bauman19bac1e2014-05-06 15:23:49 -04006571 RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i)
John Bauman89401822014-05-06 15:04:28 -04006572 {
John Bauman66b8ab22014-05-06 15:57:45 -04006573 llvm::Value *value = val.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006574 llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i);
6575
6576 val = RValue<Float4>(insert);
6577
6578 return val;
6579 }
6580
John Bauman19bac1e2014-05-06 15:23:49 -04006581 RValue<Float> Extract(RValue<Float4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04006582 {
6583 return RValue<Float>(Nucleus::createExtractElement(x.value, i));
6584 }
6585
John Bauman19bac1e2014-05-06 15:23:49 -04006586 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006587 {
6588 return RValue<Float4>(Nucleus::createSwizzle(x.value, select));
6589 }
6590
John Bauman19bac1e2014-05-06 15:23:49 -04006591 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006592 {
6593 Constant *shuffle[4];
6594 shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0);
6595 shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0);
6596 shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4);
6597 shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4);
6598
6599 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6600 }
6601
John Bauman19bac1e2014-05-06 15:23:49 -04006602 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006603 {
6604 Constant *shuffle[4];
6605 shuffle[0] = Nucleus::createConstantInt(0);
6606 shuffle[1] = Nucleus::createConstantInt(4);
6607 shuffle[2] = Nucleus::createConstantInt(1);
6608 shuffle[3] = Nucleus::createConstantInt(5);
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> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006614 {
6615 Constant *shuffle[4];
6616 shuffle[0] = Nucleus::createConstantInt(2);
6617 shuffle[1] = Nucleus::createConstantInt(6);
6618 shuffle[2] = Nucleus::createConstantInt(3);
6619 shuffle[3] = Nucleus::createConstantInt(7);
6620
6621 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6622 }
John Bauman66b8ab22014-05-06 15:57:45 -04006623
John Bauman19bac1e2014-05-06 15:23:49 -04006624 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006625 {
John Bauman66b8ab22014-05-06 15:57:45 -04006626 Value *vector = lhs.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006627 Value *shuffle = Nucleus::createMask(vector, rhs.value, select);
John Bauman66b8ab22014-05-06 15:57:45 -04006628 lhs.storeValue(shuffle);
John Bauman89401822014-05-06 15:04:28 -04006629
6630 return RValue<Float4>(shuffle);
6631 }
6632
John Bauman19bac1e2014-05-06 15:23:49 -04006633 RValue<Int> SignMask(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006634 {
6635 return x86::movmskps(x);
6636 }
6637
John Bauman19bac1e2014-05-06 15:23:49 -04006638 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006639 {
6640 // return As<Int4>(x86::cmpeqps(x, y));
6641 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
6642 }
6643
John Bauman19bac1e2014-05-06 15:23:49 -04006644 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006645 {
6646 // return As<Int4>(x86::cmpltps(x, y));
6647 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
6648 }
6649
John Bauman19bac1e2014-05-06 15:23:49 -04006650 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006651 {
6652 // return As<Int4>(x86::cmpleps(x, y));
6653 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
6654 }
6655
John Bauman19bac1e2014-05-06 15:23:49 -04006656 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006657 {
6658 // return As<Int4>(x86::cmpneqps(x, y));
6659 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
6660 }
6661
John Bauman19bac1e2014-05-06 15:23:49 -04006662 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006663 {
6664 // return As<Int4>(x86::cmpnltps(x, y));
6665 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
6666 }
6667
John Bauman19bac1e2014-05-06 15:23:49 -04006668 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006669 {
6670 // return As<Int4>(x86::cmpnleps(x, y));
6671 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
6672 }
6673
John Bauman19bac1e2014-05-06 15:23:49 -04006674 RValue<Float4> Round(RValue<Float4> x)
6675 {
6676 if(CPUID::supportsSSE4_1())
6677 {
6678 return x86::roundps(x, 0);
6679 }
6680 else
6681 {
6682 return Float4(RoundInt(x));
6683 }
6684 }
6685
6686 RValue<Float4> Trunc(RValue<Float4> x)
6687 {
6688 if(CPUID::supportsSSE4_1())
6689 {
6690 return x86::roundps(x, 3);
6691 }
6692 else
6693 {
6694 return Float4(Int4(x)); // Rounded toward zero
6695 }
6696 }
6697
6698 RValue<Float4> Frac(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006699 {
6700 if(CPUID::supportsSSE4_1())
6701 {
6702 return x - x86::floorps(x);
6703 }
6704 else
6705 {
John Bauman19bac1e2014-05-06 15:23:49 -04006706 Float4 frc = x - Float4(Int4(x)); // Signed fractional part
John Bauman89401822014-05-06 15:04:28 -04006707
John Bauman19bac1e2014-05-06 15:23:49 -04006708 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 -04006709 }
6710 }
6711
John Bauman19bac1e2014-05-06 15:23:49 -04006712 RValue<Float4> Floor(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006713 {
6714 if(CPUID::supportsSSE4_1())
6715 {
6716 return x86::floorps(x);
6717 }
6718 else
6719 {
John Bauman19bac1e2014-05-06 15:23:49 -04006720 return x - Frac(x);
John Bauman89401822014-05-06 15:04:28 -04006721 }
6722 }
6723
John Bauman19bac1e2014-05-06 15:23:49 -04006724 RValue<Float4> Ceil(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006725 {
John Bauman19bac1e2014-05-06 15:23:49 -04006726 if(CPUID::supportsSSE4_1())
6727 {
6728 return x86::ceilps(x);
6729 }
6730 else
6731 {
6732 return -Floor(-x);
6733 }
John Bauman89401822014-05-06 15:04:28 -04006734 }
6735
John Bauman19bac1e2014-05-06 15:23:49 -04006736 Type *Float4::getType()
John Bauman89401822014-05-06 15:04:28 -04006737 {
6738 return VectorType::get(Float::getType(), 4);
6739 }
6740
John Bauman66b8ab22014-05-06 15:57:45 -04006741 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006742 {
John Bauman66b8ab22014-05-06 15:57:45 -04006743 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
John Bauman89401822014-05-06 15:04:28 -04006744 }
6745
John Bauman66b8ab22014-05-06 15:57:45 -04006746 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006747 {
John Bauman66b8ab22014-05-06 15:57:45 -04006748 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006749 }
6750
John Bauman66b8ab22014-05-06 15:57:45 -04006751 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006752 {
John Bauman66b8ab22014-05-06 15:57:45 -04006753 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006754 }
6755
John Bauman66b8ab22014-05-06 15:57:45 -04006756 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006757 {
6758 return lhs = lhs + offset;
6759 }
6760
John Bauman66b8ab22014-05-06 15:57:45 -04006761 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006762 {
6763 return lhs = lhs + offset;
6764 }
6765
John Bauman66b8ab22014-05-06 15:57:45 -04006766 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006767 {
6768 return lhs = lhs + offset;
6769 }
6770
John Bauman66b8ab22014-05-06 15:57:45 -04006771 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006772 {
6773 return lhs + -offset;
6774 }
6775
John Bauman66b8ab22014-05-06 15:57:45 -04006776 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006777 {
6778 return lhs + -offset;
6779 }
6780
John Bauman66b8ab22014-05-06 15:57:45 -04006781 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006782 {
6783 return lhs + -offset;
6784 }
6785
John Bauman66b8ab22014-05-06 15:57:45 -04006786 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006787 {
6788 return lhs = lhs - offset;
6789 }
6790
John Bauman66b8ab22014-05-06 15:57:45 -04006791 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006792 {
6793 return lhs = lhs - offset;
6794 }
6795
John Bauman66b8ab22014-05-06 15:57:45 -04006796 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006797 {
6798 return lhs = lhs - offset;
6799 }
6800
6801 void Return()
6802 {
John Bauman89401822014-05-06 15:04:28 -04006803 Nucleus::createRetVoid();
6804 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006805 Nucleus::createUnreachable();
6806 }
6807
6808 void Return(bool ret)
6809 {
John Bauman19bac1e2014-05-06 15:23:49 -04006810 Nucleus::createRet(Nucleus::createConstantBool(ret));
6811 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6812 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006813 }
6814
6815 void Return(const Int &ret)
6816 {
John Bauman66b8ab22014-05-06 15:57:45 -04006817 Nucleus::createRet(ret.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006818 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006819 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006820 }
6821
6822 BasicBlock *beginLoop()
6823 {
6824 BasicBlock *loopBB = Nucleus::createBasicBlock();
6825
6826 Nucleus::createBr(loopBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006827 Nucleus::setInsertBlock(loopBB);
John Bauman89401822014-05-06 15:04:28 -04006828
6829 return loopBB;
6830 }
6831
John Bauman19bac1e2014-05-06 15:23:49 -04006832 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
John Bauman89401822014-05-06 15:04:28 -04006833 {
6834 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006835 Nucleus::setInsertBlock(bodyBB);
6836
John Bauman89401822014-05-06 15:04:28 -04006837 return true;
6838 }
6839
6840 bool elseBlock(BasicBlock *falseBB)
6841 {
6842 falseBB->back().eraseFromParent();
John Bauman66b8ab22014-05-06 15:57:45 -04006843 Nucleus::setInsertBlock(falseBB);
John Bauman89401822014-05-06 15:04:28 -04006844
6845 return true;
6846 }
6847
6848 RValue<Long> Ticks()
6849 {
6850 Module *module = Nucleus::getModule();
6851 llvm::Function *rdtsc = Intrinsic::getDeclaration(module, Intrinsic::readcyclecounter);
6852
6853 return RValue<Long>(Nucleus::createCall(rdtsc));
6854 }
John Bauman89401822014-05-06 15:04:28 -04006855}
6856
6857namespace sw
6858{
6859 namespace x86
6860 {
John Bauman19bac1e2014-05-06 15:23:49 -04006861 RValue<Int> cvtss2si(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006862 {
6863 Module *module = Nucleus::getModule();
6864 llvm::Function *cvtss2si = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtss2si);
John Bauman66b8ab22014-05-06 15:57:45 -04006865
John Bauman89401822014-05-06 15:04:28 -04006866 Float4 vector;
6867 vector.x = val;
6868
6869 return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value));
6870 }
6871
John Bauman19bac1e2014-05-06 15:23:49 -04006872 RValue<Int2> cvtps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006873 {
6874 Module *module = Nucleus::getModule();
6875 llvm::Function *cvtps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtps2pi);
6876
6877 return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value));
6878 }
6879
John Bauman19bac1e2014-05-06 15:23:49 -04006880 RValue<Int2> cvttps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006881 {
6882 Module *module = Nucleus::getModule();
6883 llvm::Function *cvttps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvttps2pi);
6884
6885 return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value));
6886 }
6887
John Bauman19bac1e2014-05-06 15:23:49 -04006888 RValue<Int4> cvtps2dq(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006889 {
6890 if(CPUID::supportsSSE2())
6891 {
6892 Module *module = Nucleus::getModule();
6893 llvm::Function *cvtps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtps2dq);
6894
6895 return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value));
6896 }
6897 else
6898 {
6899 Int2 lo = x86::cvtps2pi(val);
6900 Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04006901
John Bauman89401822014-05-06 15:04:28 -04006902 return Concatenate(lo, hi);
6903 }
6904 }
6905
John Bauman19bac1e2014-05-06 15:23:49 -04006906 RValue<Float> rcpss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006907 {
6908 Module *module = Nucleus::getModule();
6909 llvm::Function *rcpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ss);
6910
6911 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006912
John Bauman89401822014-05-06 15:04:28 -04006913 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rcpss, vector), 0));
6914 }
6915
John Bauman19bac1e2014-05-06 15:23:49 -04006916 RValue<Float> sqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006917 {
6918 Module *module = Nucleus::getModule();
6919 llvm::Function *sqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ss);
6920
6921 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006922
John Bauman89401822014-05-06 15:04:28 -04006923 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0));
6924 }
6925
John Bauman19bac1e2014-05-06 15:23:49 -04006926 RValue<Float> rsqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006927 {
6928 Module *module = Nucleus::getModule();
6929 llvm::Function *rsqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ss);
John Bauman66b8ab22014-05-06 15:57:45 -04006930
John Bauman89401822014-05-06 15:04:28 -04006931 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
6932
6933 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0));
6934 }
6935
John Bauman19bac1e2014-05-06 15:23:49 -04006936 RValue<Float4> rcpps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006937 {
6938 Module *module = Nucleus::getModule();
6939 llvm::Function *rcpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006940
John Bauman89401822014-05-06 15:04:28 -04006941 return RValue<Float4>(Nucleus::createCall(rcpps, val.value));
6942 }
6943
John Bauman19bac1e2014-05-06 15:23:49 -04006944 RValue<Float4> sqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006945 {
6946 Module *module = Nucleus::getModule();
6947 llvm::Function *sqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006948
John Bauman89401822014-05-06 15:04:28 -04006949 return RValue<Float4>(Nucleus::createCall(sqrtps, val.value));
6950 }
6951
John Bauman19bac1e2014-05-06 15:23:49 -04006952 RValue<Float4> rsqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006953 {
6954 Module *module = Nucleus::getModule();
6955 llvm::Function *rsqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006956
John Bauman89401822014-05-06 15:04:28 -04006957 return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value));
6958 }
6959
John Bauman19bac1e2014-05-06 15:23:49 -04006960 RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006961 {
6962 Module *module = Nucleus::getModule();
6963 llvm::Function *maxps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_max_ps);
6964
6965 return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value));
6966 }
6967
John Bauman19bac1e2014-05-06 15:23:49 -04006968 RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006969 {
6970 Module *module = Nucleus::getModule();
6971 llvm::Function *minps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_min_ps);
6972
6973 return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value));
6974 }
6975
John Bauman19bac1e2014-05-06 15:23:49 -04006976 RValue<Float> roundss(RValue<Float> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006977 {
6978 Module *module = Nucleus::getModule();
6979 llvm::Function *roundss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ss);
6980
6981 Value *undef = UndefValue::get(Float4::getType());
6982 Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
6983
6984 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0));
6985 }
6986
John Bauman19bac1e2014-05-06 15:23:49 -04006987 RValue<Float> floorss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006988 {
6989 return roundss(val, 1);
6990 }
6991
John Bauman19bac1e2014-05-06 15:23:49 -04006992 RValue<Float> ceilss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006993 {
6994 return roundss(val, 2);
6995 }
6996
John Bauman19bac1e2014-05-06 15:23:49 -04006997 RValue<Float4> roundps(RValue<Float4> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006998 {
6999 Module *module = Nucleus::getModule();
7000 llvm::Function *roundps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ps);
7001
7002 return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm)));
7003 }
7004
John Bauman19bac1e2014-05-06 15:23:49 -04007005 RValue<Float4> floorps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007006 {
7007 return roundps(val, 1);
7008 }
7009
John Bauman19bac1e2014-05-06 15:23:49 -04007010 RValue<Float4> ceilps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007011 {
7012 return roundps(val, 2);
7013 }
7014
John Bauman19bac1e2014-05-06 15:23:49 -04007015 RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007016 {
7017 Module *module = Nucleus::getModule();
7018 llvm::Function *cmpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ps);
7019
7020 return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm)));
7021 }
7022
John Bauman19bac1e2014-05-06 15:23:49 -04007023 RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007024 {
7025 return cmpps(x, y, 0);
7026 }
7027
John Bauman19bac1e2014-05-06 15:23:49 -04007028 RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007029 {
7030 return cmpps(x, y, 1);
7031 }
7032
John Bauman19bac1e2014-05-06 15:23:49 -04007033 RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007034 {
7035 return cmpps(x, y, 2);
7036 }
7037
John Bauman19bac1e2014-05-06 15:23:49 -04007038 RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007039 {
7040 return cmpps(x, y, 3);
7041 }
7042
John Bauman19bac1e2014-05-06 15:23:49 -04007043 RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007044 {
7045 return cmpps(x, y, 4);
7046 }
7047
John Bauman19bac1e2014-05-06 15:23:49 -04007048 RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007049 {
7050 return cmpps(x, y, 5);
7051 }
7052
John Bauman19bac1e2014-05-06 15:23:49 -04007053 RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007054 {
7055 return cmpps(x, y, 6);
7056 }
7057
John Bauman19bac1e2014-05-06 15:23:49 -04007058 RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007059 {
7060 return cmpps(x, y, 7);
7061 }
7062
John Bauman19bac1e2014-05-06 15:23:49 -04007063 RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007064 {
7065 Module *module = Nucleus::getModule();
7066 llvm::Function *cmpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ss);
7067
7068 Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0);
7069 Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0);
7070
7071 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0));
7072 }
7073
John Bauman19bac1e2014-05-06 15:23:49 -04007074 RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007075 {
7076 return cmpss(x, y, 0);
7077 }
7078
John Bauman19bac1e2014-05-06 15:23:49 -04007079 RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007080 {
7081 return cmpss(x, y, 1);
7082 }
7083
John Bauman19bac1e2014-05-06 15:23:49 -04007084 RValue<Float> cmpless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007085 {
7086 return cmpss(x, y, 2);
7087 }
7088
John Bauman19bac1e2014-05-06 15:23:49 -04007089 RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007090 {
7091 return cmpss(x, y, 3);
7092 }
7093
John Bauman19bac1e2014-05-06 15:23:49 -04007094 RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007095 {
7096 return cmpss(x, y, 4);
7097 }
7098
John Bauman19bac1e2014-05-06 15:23:49 -04007099 RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007100 {
7101 return cmpss(x, y, 5);
7102 }
7103
John Bauman19bac1e2014-05-06 15:23:49 -04007104 RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007105 {
7106 return cmpss(x, y, 6);
7107 }
7108
John Bauman19bac1e2014-05-06 15:23:49 -04007109 RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007110 {
7111 return cmpss(x, y, 7);
7112 }
7113
John Bauman19bac1e2014-05-06 15:23:49 -04007114 RValue<Int4> pabsd(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007115 {
7116 Module *module = Nucleus::getModule();
7117 llvm::Function *pabsd = Intrinsic::getDeclaration(module, Intrinsic::x86_ssse3_pabs_d_128);
7118
7119 return RValue<Int4>(Nucleus::createCall(pabsd, x.value, y.value));
7120 }
7121
John Bauman19bac1e2014-05-06 15:23:49 -04007122 RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007123 {
7124 Module *module = Nucleus::getModule();
7125 llvm::Function *paddsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_w);
7126
John Bauman19bac1e2014-05-06 15:23:49 -04007127 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007128 }
John Bauman66b8ab22014-05-06 15:57:45 -04007129
John Bauman19bac1e2014-05-06 15:23:49 -04007130 RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007131 {
7132 Module *module = Nucleus::getModule();
7133 llvm::Function *psubsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_w);
7134
John Bauman19bac1e2014-05-06 15:23:49 -04007135 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007136 }
7137
John Bauman19bac1e2014-05-06 15:23:49 -04007138 RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007139 {
7140 Module *module = Nucleus::getModule();
7141 llvm::Function *paddusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_w);
7142
John Bauman19bac1e2014-05-06 15:23:49 -04007143 return As<UShort4>(RValue<MMX>(Nucleus::createCall(paddusw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007144 }
John Bauman66b8ab22014-05-06 15:57:45 -04007145
John Bauman19bac1e2014-05-06 15:23:49 -04007146 RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007147 {
7148 Module *module = Nucleus::getModule();
7149 llvm::Function *psubusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_w);
7150
John Bauman19bac1e2014-05-06 15:23:49 -04007151 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psubusw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007152 }
7153
John Bauman19bac1e2014-05-06 15:23:49 -04007154 RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007155 {
7156 Module *module = Nucleus::getModule();
7157 llvm::Function *paddsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_b);
7158
John Bauman19bac1e2014-05-06 15:23:49 -04007159 return As<SByte8>(RValue<MMX>(Nucleus::createCall(paddsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007160 }
John Bauman66b8ab22014-05-06 15:57:45 -04007161
John Bauman19bac1e2014-05-06 15:23:49 -04007162 RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007163 {
7164 Module *module = Nucleus::getModule();
7165 llvm::Function *psubsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_b);
7166
John Bauman19bac1e2014-05-06 15:23:49 -04007167 return As<SByte8>(RValue<MMX>(Nucleus::createCall(psubsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007168 }
John Bauman66b8ab22014-05-06 15:57:45 -04007169
John Bauman19bac1e2014-05-06 15:23:49 -04007170 RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007171 {
7172 Module *module = Nucleus::getModule();
7173 llvm::Function *paddusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_b);
7174
John Bauman19bac1e2014-05-06 15:23:49 -04007175 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007176 }
John Bauman66b8ab22014-05-06 15:57:45 -04007177
John Bauman19bac1e2014-05-06 15:23:49 -04007178 RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007179 {
7180 Module *module = Nucleus::getModule();
7181 llvm::Function *psubusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_b);
7182
John Bauman19bac1e2014-05-06 15:23:49 -04007183 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007184 }
7185
John Bauman19bac1e2014-05-06 15:23:49 -04007186 RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y)
7187 {
7188 Module *module = Nucleus::getModule();
7189 llvm::Function *paddw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_w);
7190
7191 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddw, As<MMX>(x).value, As<MMX>(y).value)));
7192 }
7193
7194 RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y)
7195 {
7196 Module *module = Nucleus::getModule();
7197 llvm::Function *psubw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_w);
7198
7199 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubw, As<MMX>(x).value, As<MMX>(y).value)));
7200 }
7201
7202 RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y)
7203 {
7204 Module *module = Nucleus::getModule();
7205 llvm::Function *pmullw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmull_w);
7206
7207 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmullw, As<MMX>(x).value, As<MMX>(y).value)));
7208 }
7209
7210 RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y)
7211 {
7212 Module *module = Nucleus::getModule();
7213 llvm::Function *pand = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pand);
7214
7215 return As<Short4>(RValue<MMX>(Nucleus::createCall(pand, As<MMX>(x).value, As<MMX>(y).value)));
7216 }
7217
7218 RValue<Short4> por(RValue<Short4> x, RValue<Short4> y)
7219 {
7220 Module *module = Nucleus::getModule();
7221 llvm::Function *por = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_por);
7222
7223 return As<Short4>(RValue<MMX>(Nucleus::createCall(por, As<MMX>(x).value, As<MMX>(y).value)));
7224 }
7225
7226 RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y)
7227 {
7228 Module *module = Nucleus::getModule();
7229 llvm::Function *pxor = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pxor);
7230
7231 return As<Short4>(RValue<MMX>(Nucleus::createCall(pxor, As<MMX>(x).value, As<MMX>(y).value)));
7232 }
7233
7234 RValue<Short4> pshufw(RValue<Short4> x, unsigned char y)
7235 {
7236 Module *module = Nucleus::getModule();
7237 llvm::Function *pshufw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_pshuf_w);
7238
7239 return As<Short4>(RValue<MMX>(Nucleus::createCall(pshufw, As<MMX>(x).value, Nucleus::createConstantByte(y))));
7240 }
7241
7242 RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y)
7243 {
7244 Module *module = Nucleus::getModule();
7245 llvm::Function *punpcklwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklwd);
7246
7247 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpcklwd, As<MMX>(x).value, As<MMX>(y).value)));
7248 }
7249
7250 RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y)
7251 {
7252 Module *module = Nucleus::getModule();
7253 llvm::Function *punpckhwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhwd);
7254
7255 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpckhwd, As<MMX>(x).value, As<MMX>(y).value)));
7256 }
7257
7258 RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i)
7259 {
7260 Module *module = Nucleus::getModule();
7261 llvm::Function *pinsrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pinsr_w);
7262
7263 return As<Short4>(RValue<MMX>(Nucleus::createCall(pinsrw, As<MMX>(x).value, y.value, Nucleus::createConstantInt(i))));
7264 }
7265
7266 RValue<Int> pextrw(RValue<Short4> x, unsigned int i)
7267 {
7268 Module *module = Nucleus::getModule();
7269 llvm::Function *pextrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pextr_w);
7270
7271 return RValue<Int>(Nucleus::createCall(pextrw, As<MMX>(x).value, Nucleus::createConstantInt(i)));
7272 }
7273
7274 RValue<Long1> punpckldq(RValue<Int2> x, RValue<Int2> y)
7275 {
7276 Module *module = Nucleus::getModule();
7277 llvm::Function *punpckldq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckldq);
7278
7279 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckldq, As<MMX>(x).value, As<MMX>(y).value)));
7280 }
7281
7282 RValue<Long1> punpckhdq(RValue<Int2> x, RValue<Int2> y)
7283 {
7284 Module *module = Nucleus::getModule();
7285 llvm::Function *punpckhdq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhdq);
7286
7287 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckhdq, As<MMX>(x).value, As<MMX>(y).value)));
7288 }
7289
7290 RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y)
7291 {
7292 Module *module = Nucleus::getModule();
7293 llvm::Function *punpcklbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklbw);
7294
7295 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpcklbw, As<MMX>(x).value, As<MMX>(y).value)));
7296 }
7297
7298 RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y)
7299 {
7300 Module *module = Nucleus::getModule();
7301 llvm::Function *punpckhbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhbw);
7302
7303 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpckhbw, As<MMX>(x).value, As<MMX>(y).value)));
7304 }
7305
7306 RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y)
7307 {
7308 Module *module = Nucleus::getModule();
7309 llvm::Function *paddb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_b);
7310
7311 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddb, As<MMX>(x).value, As<MMX>(y).value)));
7312 }
7313
7314 RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y)
7315 {
7316 Module *module = Nucleus::getModule();
7317 llvm::Function *psubb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_b);
7318
7319 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubb, As<MMX>(x).value, As<MMX>(y).value)));
7320 }
7321
7322 RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y)
7323 {
7324 Module *module = Nucleus::getModule();
7325 llvm::Function *paddd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_d);
7326
7327 return As<Int2>(RValue<MMX>(Nucleus::createCall(paddd, As<MMX>(x).value, As<MMX>(y).value)));
7328 }
7329
7330 RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y)
7331 {
7332 Module *module = Nucleus::getModule();
7333 llvm::Function *psubd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_d);
7334
7335 return As<Int2>(RValue<MMX>(Nucleus::createCall(psubd, As<MMX>(x).value, As<MMX>(y).value)));
7336 }
7337
7338 RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007339 {
7340 Module *module = Nucleus::getModule();
7341 llvm::Function *pavgw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pavg_w);
7342
John Bauman19bac1e2014-05-06 15:23:49 -04007343 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pavgw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007344 }
7345
John Bauman19bac1e2014-05-06 15:23:49 -04007346 RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007347 {
7348 Module *module = Nucleus::getModule();
7349 llvm::Function *pmaxsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmaxs_w);
7350
John Bauman19bac1e2014-05-06 15:23:49 -04007351 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmaxsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007352 }
7353
John Bauman19bac1e2014-05-06 15:23:49 -04007354 RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007355 {
7356 Module *module = Nucleus::getModule();
7357 llvm::Function *pminsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmins_w);
7358
John Bauman19bac1e2014-05-06 15:23:49 -04007359 return As<Short4>(RValue<MMX>(Nucleus::createCall(pminsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007360 }
7361
John Bauman19bac1e2014-05-06 15:23:49 -04007362 RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007363 {
7364 Module *module = Nucleus::getModule();
7365 llvm::Function *pcmpgtw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_w);
7366
John Bauman19bac1e2014-05-06 15:23:49 -04007367 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpgtw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007368 }
7369
John Bauman19bac1e2014-05-06 15:23:49 -04007370 RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007371 {
7372 Module *module = Nucleus::getModule();
7373 llvm::Function *pcmpeqw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_w);
7374
John Bauman19bac1e2014-05-06 15:23:49 -04007375 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpeqw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007376 }
7377
John Bauman19bac1e2014-05-06 15:23:49 -04007378 RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007379 {
7380 Module *module = Nucleus::getModule();
7381 llvm::Function *pcmpgtb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_b);
7382
John Bauman19bac1e2014-05-06 15:23:49 -04007383 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpgtb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007384 }
7385
John Bauman19bac1e2014-05-06 15:23:49 -04007386 RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007387 {
7388 Module *module = Nucleus::getModule();
7389 llvm::Function *pcmpeqb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_b);
7390
John Bauman19bac1e2014-05-06 15:23:49 -04007391 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpeqb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007392 }
7393
John Bauman19bac1e2014-05-06 15:23:49 -04007394 RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04007395 {
7396 Module *module = Nucleus::getModule();
7397 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packssdw);
7398
John Bauman19bac1e2014-05-06 15:23:49 -04007399 return As<Short4>(RValue<MMX>(Nucleus::createCall(packssdw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007400 }
7401
John Bauman19bac1e2014-05-06 15:23:49 -04007402 RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007403 {
7404 if(CPUID::supportsSSE2())
7405 {
7406 Module *module = Nucleus::getModule();
7407 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_packssdw_128);
7408
7409 return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value));
7410 }
7411 else
7412 {
7413 Int2 loX = Int2(x);
7414 Int2 hiX = Int2(Swizzle(x, 0xEE));
7415
7416 Int2 loY = Int2(y);
7417 Int2 hiY = Int2(Swizzle(y, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007418
John Bauman89401822014-05-06 15:04:28 -04007419 Short4 lo = x86::packssdw(loX, hiX);
7420 Short4 hi = x86::packssdw(loY, hiY);
John Bauman66b8ab22014-05-06 15:57:45 -04007421
John Bauman89401822014-05-06 15:04:28 -04007422 return Concatenate(lo, hi);
7423 }
7424 }
7425
John Bauman19bac1e2014-05-06 15:23:49 -04007426 RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007427 {
7428 Module *module = Nucleus::getModule();
7429 llvm::Function *packsswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packsswb);
7430
John Bauman19bac1e2014-05-06 15:23:49 -04007431 return As<SByte8>(RValue<MMX>(Nucleus::createCall(packsswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007432 }
7433
John Bauman19bac1e2014-05-06 15:23:49 -04007434 RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007435 {
7436 Module *module = Nucleus::getModule();
7437 llvm::Function *packuswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packuswb);
7438
John Bauman19bac1e2014-05-06 15:23:49 -04007439 return As<Byte8>(RValue<MMX>(Nucleus::createCall(packuswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007440 }
7441
John Bauman19bac1e2014-05-06 15:23:49 -04007442 RValue<UShort8> packusdw(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04007443 {
7444 if(CPUID::supportsSSE4_1())
7445 {
7446 Module *module = Nucleus::getModule();
7447 llvm::Function *packusdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_packusdw);
John Bauman66b8ab22014-05-06 15:57:45 -04007448
John Bauman89401822014-05-06 15:04:28 -04007449 return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value));
7450 }
7451 else
7452 {
7453 // FIXME: Not an exact replacement!
John Bauman19bac1e2014-05-06 15:23:49 -04007454 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 -04007455 }
7456 }
7457
John Bauman19bac1e2014-05-06 15:23:49 -04007458 RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007459 {
7460 Module *module = Nucleus::getModule();
7461 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_w);
7462
John Bauman19bac1e2014-05-06 15:23:49 -04007463 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007464 }
7465
John Bauman19bac1e2014-05-06 15:23:49 -04007466 RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007467 {
7468 Module *module = Nucleus::getModule();
7469 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_w);
7470
7471 return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y)));
7472 }
7473
John Bauman19bac1e2014-05-06 15:23:49 -04007474 RValue<Short4> psraw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007475 {
7476 Module *module = Nucleus::getModule();
7477 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_w);
7478
John Bauman19bac1e2014-05-06 15:23:49 -04007479 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007480 }
7481
John Bauman19bac1e2014-05-06 15:23:49 -04007482 RValue<Short8> psraw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007483 {
7484 Module *module = Nucleus::getModule();
7485 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_w);
7486
7487 return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y)));
7488 }
7489
John Bauman19bac1e2014-05-06 15:23:49 -04007490 RValue<Short4> psllw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007491 {
7492 Module *module = Nucleus::getModule();
7493 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_w);
7494
John Bauman19bac1e2014-05-06 15:23:49 -04007495 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007496 }
7497
John Bauman19bac1e2014-05-06 15:23:49 -04007498 RValue<Short8> psllw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007499 {
7500 Module *module = Nucleus::getModule();
7501 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_w);
7502
7503 return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y)));
7504 }
7505
John Bauman19bac1e2014-05-06 15:23:49 -04007506 RValue<Int2> pslld(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007507 {
7508 Module *module = Nucleus::getModule();
7509 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_d);
7510
John Bauman19bac1e2014-05-06 15:23:49 -04007511 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007512 }
7513
John Bauman19bac1e2014-05-06 15:23:49 -04007514 RValue<Int4> pslld(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007515 {
7516 if(CPUID::supportsSSE2())
7517 {
7518 Module *module = Nucleus::getModule();
7519 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_d);
7520
7521 return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y)));
7522 }
7523 else
7524 {
7525 Int2 lo = Int2(x);
7526 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007527
John Bauman89401822014-05-06 15:04:28 -04007528 lo = x86::pslld(lo, y);
7529 hi = x86::pslld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007530
John Bauman89401822014-05-06 15:04:28 -04007531 return Concatenate(lo, hi);
7532 }
7533 }
7534
John Bauman19bac1e2014-05-06 15:23:49 -04007535 RValue<Int2> psrad(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007536 {
7537 Module *module = Nucleus::getModule();
7538 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_d);
7539
John Bauman19bac1e2014-05-06 15:23:49 -04007540 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrad, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007541 }
7542
John Bauman19bac1e2014-05-06 15:23:49 -04007543 RValue<Int4> psrad(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007544 {
7545 if(CPUID::supportsSSE2())
7546 {
7547 Module *module = Nucleus::getModule();
7548 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_d);
7549
7550 return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y)));
7551 }
7552 else
7553 {
7554 Int2 lo = Int2(x);
7555 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007556
John Bauman89401822014-05-06 15:04:28 -04007557 lo = x86::psrad(lo, y);
7558 hi = x86::psrad(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007559
John Bauman89401822014-05-06 15:04:28 -04007560 return Concatenate(lo, hi);
7561 }
7562 }
7563
John Bauman19bac1e2014-05-06 15:23:49 -04007564 RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007565 {
7566 Module *module = Nucleus::getModule();
7567 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_d);
7568
John Bauman19bac1e2014-05-06 15:23:49 -04007569 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007570 }
7571
John Bauman19bac1e2014-05-06 15:23:49 -04007572 RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007573 {
7574 if(CPUID::supportsSSE2())
7575 {
7576 Module *module = Nucleus::getModule();
7577 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_d);
7578
7579 return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y)));
7580 }
7581 else
7582 {
7583 UInt2 lo = As<UInt2>(Int2(As<Int4>(x)));
7584 UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE)));
John Bauman66b8ab22014-05-06 15:57:45 -04007585
John Bauman89401822014-05-06 15:04:28 -04007586 lo = x86::psrld(lo, y);
7587 hi = x86::psrld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007588
John Bauman89401822014-05-06 15:04:28 -04007589 return Concatenate(lo, hi);
7590 }
7591 }
7592
John Bauman19bac1e2014-05-06 15:23:49 -04007593 RValue<UShort4> psrlw(RValue<UShort4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007594 {
7595 Module *module = Nucleus::getModule();
7596 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_w);
7597
John Bauman19bac1e2014-05-06 15:23:49 -04007598 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007599 }
7600
John Bauman19bac1e2014-05-06 15:23:49 -04007601 RValue<Short4> psraw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007602 {
7603 Module *module = Nucleus::getModule();
7604 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_w);
7605
John Bauman19bac1e2014-05-06 15:23:49 -04007606 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007607 }
7608
John Bauman19bac1e2014-05-06 15:23:49 -04007609 RValue<Short4> psllw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007610 {
7611 Module *module = Nucleus::getModule();
7612 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_w);
7613
John Bauman19bac1e2014-05-06 15:23:49 -04007614 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007615 }
7616
John Bauman19bac1e2014-05-06 15:23:49 -04007617 RValue<Int2> pslld(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007618 {
7619 Module *module = Nucleus::getModule();
7620 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_d);
7621
John Bauman19bac1e2014-05-06 15:23:49 -04007622 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007623 }
7624
John Bauman19bac1e2014-05-06 15:23:49 -04007625 RValue<UInt2> psrld(RValue<UInt2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007626 {
7627 Module *module = Nucleus::getModule();
7628 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_d);
7629
John Bauman19bac1e2014-05-06 15:23:49 -04007630 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007631 }
7632
John Bauman19bac1e2014-05-06 15:23:49 -04007633 RValue<Int2> psrad(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007634 {
7635 Module *module = Nucleus::getModule();
7636 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_d);
7637
John Bauman19bac1e2014-05-06 15:23:49 -04007638 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007639 }
7640
John Bauman19bac1e2014-05-06 15:23:49 -04007641 RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y)
7642 {
7643 Module *module = Nucleus::getModule();
7644 llvm::Function *pmaxsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxsd);
7645
7646 return RValue<Int4>(Nucleus::createCall(pmaxsd, x.value, y.value));
7647 }
7648
7649 RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y)
7650 {
7651 Module *module = Nucleus::getModule();
7652 llvm::Function *pminsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminsd);
7653
7654 return RValue<Int4>(Nucleus::createCall(pminsd, x.value, y.value));
7655 }
7656
7657 RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y)
7658 {
7659 Module *module = Nucleus::getModule();
7660 llvm::Function *pmaxud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxud);
7661
John Bauman66b8ab22014-05-06 15:57:45 -04007662 return RValue<UInt4>(Nucleus::createCall(pmaxud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007663 }
7664
7665 RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y)
7666 {
7667 Module *module = Nucleus::getModule();
7668 llvm::Function *pminud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminud);
7669
John Bauman66b8ab22014-05-06 15:57:45 -04007670 return RValue<UInt4>(Nucleus::createCall(pminud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007671 }
7672
7673 RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007674 {
7675 Module *module = Nucleus::getModule();
7676 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulh_w);
7677
John Bauman19bac1e2014-05-06 15:23:49 -04007678 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmulhw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007679 }
7680
John Bauman19bac1e2014-05-06 15:23:49 -04007681 RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007682 {
7683 Module *module = Nucleus::getModule();
7684 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulhu_w);
7685
John Bauman19bac1e2014-05-06 15:23:49 -04007686 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pmulhuw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007687 }
7688
John Bauman19bac1e2014-05-06 15:23:49 -04007689 RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007690 {
7691 Module *module = Nucleus::getModule();
7692 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmadd_wd);
7693
John Bauman19bac1e2014-05-06 15:23:49 -04007694 return As<Int2>(RValue<MMX>(Nucleus::createCall(pmaddwd, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007695 }
7696
John Bauman19bac1e2014-05-06 15:23:49 -04007697 RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007698 {
7699 Module *module = Nucleus::getModule();
7700 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulh_w);
7701
7702 return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value));
7703 }
7704
John Bauman19bac1e2014-05-06 15:23:49 -04007705 RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04007706 {
7707 Module *module = Nucleus::getModule();
7708 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulhu_w);
7709
7710 return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value));
7711 }
7712
John Bauman19bac1e2014-05-06 15:23:49 -04007713 RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007714 {
7715 Module *module = Nucleus::getModule();
7716 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmadd_wd);
7717
7718 return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value));
7719 }
7720
John Bauman19bac1e2014-05-06 15:23:49 -04007721 RValue<Int> movmskps(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04007722 {
7723 Module *module = Nucleus::getModule();
7724 llvm::Function *movmskps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_movmsk_ps);
7725
7726 return RValue<Int>(Nucleus::createCall(movmskps, x.value));
7727 }
7728
John Bauman19bac1e2014-05-06 15:23:49 -04007729 RValue<Int> pmovmskb(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04007730 {
7731 Module *module = Nucleus::getModule();
7732 llvm::Function *pmovmskb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmovmskb);
7733
John Bauman19bac1e2014-05-06 15:23:49 -04007734 return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value));
John Bauman89401822014-05-06 15:04:28 -04007735 }
7736
John Bauman66b8ab22014-05-06 15:57:45 -04007737 //RValue<Int2> movd(RValue<Pointer<Int> > x)
John Bauman89401822014-05-06 15:04:28 -04007738 //{
7739 // Value *element = Nucleus::createLoad(x.value);
7740
7741 //// Value *int2 = UndefValue::get(Int2::getType());
7742 //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0));
7743
7744 // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType());
7745
7746 // return RValue<Int2>(int2);
7747 //}
7748
John Bauman19bac1e2014-05-06 15:23:49 -04007749 //RValue<Int2> movdq2q(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007750 //{
7751 // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType());
7752 // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0));
7753
7754 // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType()));
7755 //}
7756
John Bauman19bac1e2014-05-06 15:23:49 -04007757 RValue<Int4> pmovzxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007758 {
7759 Module *module = Nucleus::getModule();
7760 llvm::Function *pmovzxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007761
John Bauman89401822014-05-06 15:04:28 -04007762 return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType())));
7763 }
7764
John Bauman19bac1e2014-05-06 15:23:49 -04007765 RValue<Int4> pmovsxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007766 {
7767 Module *module = Nucleus::getModule();
7768 llvm::Function *pmovsxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007769
John Bauman89401822014-05-06 15:04:28 -04007770 return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType())));
7771 }
7772
John Bauman19bac1e2014-05-06 15:23:49 -04007773 RValue<Int4> pmovzxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007774 {
7775 Module *module = Nucleus::getModule();
7776 llvm::Function *pmovzxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007777
John Bauman89401822014-05-06 15:04:28 -04007778 return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType())));
7779 }
7780
John Bauman19bac1e2014-05-06 15:23:49 -04007781 RValue<Int4> pmovsxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007782 {
7783 Module *module = Nucleus::getModule();
7784 llvm::Function *pmovsxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007785
John Bauman89401822014-05-06 15:04:28 -04007786 return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType())));
7787 }
7788
7789 void emms()
7790 {
7791 Module *module = Nucleus::getModule();
7792 llvm::Function *emms = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_emms);
7793
7794 Nucleus::createCall(emms);
7795 }
7796 }
7797}