blob: ee082e65dc9ddfe3fb456eaf8386c910a60c2458 [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
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004827 RValue<Int2> Concatenate(RValue<Int> lo, RValue<Int> hi)
4828 {
4829 Constant *shuffle[2];
4830 shuffle[0] = Nucleus::createConstantInt(0);
4831 shuffle[1] = Nucleus::createConstantInt(1);
4832
4833 Value *packed = Nucleus::createShuffleVector(Nucleus::createBitCast(lo.value, VectorType::get(Int::getType(), 1)), Nucleus::createBitCast(hi.value, VectorType::get(Int::getType(), 1)), Nucleus::createConstantVector(shuffle, 2));
4834
4835 return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType()));
4836 }
4837
John Bauman19bac1e2014-05-06 15:23:49 -04004838 RValue<Int> Extract(RValue<Int2> val, int i)
John Bauman89401822014-05-06 15:04:28 -04004839 {
4840 if(false) // FIXME: LLVM does not generate optimal code
4841 {
4842 return RValue<Int>(Nucleus::createExtractElement(val.value, i));
4843 }
4844 else
4845 {
4846 if(i == 0)
4847 {
John Bauman19bac1e2014-05-06 15:23:49 -04004848 return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), 0));
John Bauman89401822014-05-06 15:04:28 -04004849 }
4850 else
4851 {
4852 Int2 val2 = As<Int2>(UnpackHigh(val, val));
4853
4854 return Extract(val2, 0);
4855 }
4856 }
4857 }
4858
Nicolas Capensfff3c9b2015-05-13 23:40:44 -04004859 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4860 {
4861 return RValue<Int2>(Nucleus::createBitCast(Nucleus::createInsertElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), element.value, i), Int2::getType()));
4862 }
John Bauman89401822014-05-06 15:04:28 -04004863
John Bauman19bac1e2014-05-06 15:23:49 -04004864 Type *Int2::getType()
John Bauman89401822014-05-06 15:04:28 -04004865 {
John Bauman19bac1e2014-05-06 15:23:49 -04004866 if(CPUID::supportsMMX2())
4867 {
4868 return MMX::getType();
4869 }
4870 else
4871 {
4872 return VectorType::get(Int::getType(), 2);
4873 }
John Bauman89401822014-05-06 15:04:28 -04004874 }
4875
4876 UInt2::UInt2()
4877 {
4878 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004879 }
4880
4881 UInt2::UInt2(unsigned int x, unsigned int y)
4882 {
4883 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004884
4885 Constant *constantVector[2];
4886 constantVector[0] = Nucleus::createConstantInt(x);
4887 constantVector[1] = Nucleus::createConstantInt(y);
John Bauman19bac1e2014-05-06 15:23:49 -04004888 Value *vector = Nucleus::createConstantVector(constantVector, 2);
John Bauman89401822014-05-06 15:04:28 -04004889
John Bauman66b8ab22014-05-06 15:57:45 -04004890 storeValue(Nucleus::createBitCast(vector, getType()));
John Bauman89401822014-05-06 15:04:28 -04004891 }
4892
John Bauman19bac1e2014-05-06 15:23:49 -04004893 UInt2::UInt2(RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004894 {
4895 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004896
John Bauman66b8ab22014-05-06 15:57:45 -04004897 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004898 }
4899
4900 UInt2::UInt2(const UInt2 &rhs)
4901 {
4902 // xy.parent = this;
John Bauman89401822014-05-06 15:04:28 -04004903
John Bauman66b8ab22014-05-06 15:57:45 -04004904 Value *value = rhs.loadValue();
4905 storeValue(value);
4906 }
4907
4908 UInt2::UInt2(const Reference<UInt2> &rhs)
4909 {
4910 // xy.parent = this;
4911
4912 Value *value = rhs.loadValue();
4913 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004914 }
4915
John Bauman19bac1e2014-05-06 15:23:49 -04004916 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const
John Bauman89401822014-05-06 15:04:28 -04004917 {
John Bauman66b8ab22014-05-06 15:57:45 -04004918 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04004919
4920 return rhs;
4921 }
4922
4923 RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
4924 {
John Bauman66b8ab22014-05-06 15:57:45 -04004925 Value *value = rhs.loadValue();
4926 storeValue(value);
4927
4928 return RValue<UInt2>(value);
4929 }
4930
4931 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const
4932 {
4933 Value *value = rhs.loadValue();
4934 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04004935
4936 return RValue<UInt2>(value);
4937 }
4938
John Bauman19bac1e2014-05-06 15:23:49 -04004939 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004940 {
John Bauman19bac1e2014-05-06 15:23:49 -04004941 if(CPUID::supportsMMX2())
4942 {
4943 return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs)));
4944 }
4945 else
4946 {
4947 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
4948 }
John Bauman89401822014-05-06 15:04:28 -04004949 }
4950
John Bauman19bac1e2014-05-06 15:23:49 -04004951 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004952 {
John Bauman19bac1e2014-05-06 15:23:49 -04004953 if(CPUID::supportsMMX2())
4954 {
4955 return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs)));
4956 }
4957 else
4958 {
4959 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
4960 }
John Bauman89401822014-05-06 15:04:28 -04004961 }
4962
John Bauman19bac1e2014-05-06 15:23:49 -04004963// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4964// {
4965// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4966// }
4967
4968// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4969// {
4970// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4971// }
4972
4973// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4974// {
4975// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4976// }
4977
4978 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004979 {
John Bauman19bac1e2014-05-06 15:23:49 -04004980 if(CPUID::supportsMMX2())
4981 {
4982 return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs)));
4983 }
4984 else
4985 {
4986 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
4987 }
John Bauman89401822014-05-06 15:04:28 -04004988 }
4989
John Bauman19bac1e2014-05-06 15:23:49 -04004990 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04004991 {
John Bauman19bac1e2014-05-06 15:23:49 -04004992 if(CPUID::supportsMMX2())
4993 {
4994 return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs)));
4995 }
4996 else
4997 {
4998 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
4999 }
John Bauman89401822014-05-06 15:04:28 -04005000 }
5001
John Bauman19bac1e2014-05-06 15:23:49 -04005002 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005003 {
John Bauman19bac1e2014-05-06 15:23:49 -04005004 if(CPUID::supportsMMX2())
5005 {
5006 return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs)));
5007 }
5008 else
5009 {
5010 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
5011 }
John Bauman89401822014-05-06 15:04:28 -04005012 }
5013
John Bauman19bac1e2014-05-06 15:23:49 -04005014 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005015 {
5016 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5017
5018 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5019 }
5020
John Bauman19bac1e2014-05-06 15:23:49 -04005021 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005022 {
5023 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5024
5025 return x86::psrld(lhs, rhs);
5026 }
5027
John Bauman19bac1e2014-05-06 15:23:49 -04005028 RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005029 {
5030 // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value));
5031
5032 return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs));
5033 }
5034
John Bauman19bac1e2014-05-06 15:23:49 -04005035 RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005036 {
5037 // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value));
5038
5039 return x86::psrld(lhs, rhs);
5040 }
5041
John Bauman19bac1e2014-05-06 15:23:49 -04005042 RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005043 {
5044 return lhs = lhs + rhs;
5045 }
5046
John Bauman19bac1e2014-05-06 15:23:49 -04005047 RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005048 {
5049 return lhs = lhs - rhs;
5050 }
5051
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)
5058// {
5059// return lhs = lhs / rhs;
5060// }
John Bauman89401822014-05-06 15:04:28 -04005061
John Bauman19bac1e2014-05-06 15:23:49 -04005062// RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs)
5063// {
5064// return lhs = lhs % rhs;
5065// }
John Bauman89401822014-05-06 15:04:28 -04005066
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
John Bauman19bac1e2014-05-06 15:23:49 -04005072 RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005073 {
5074 return lhs = lhs | rhs;
5075 }
5076
John Bauman19bac1e2014-05-06 15:23:49 -04005077 RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs)
John Bauman89401822014-05-06 15:04:28 -04005078 {
5079 return lhs = lhs ^ rhs;
5080 }
5081
5082 RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
5083 {
5084 return lhs = lhs << rhs;
5085 }
5086
5087 RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
5088 {
5089 return lhs = lhs >> rhs;
5090 }
5091
John Bauman19bac1e2014-05-06 15:23:49 -04005092 RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005093 {
5094 return lhs = lhs << rhs;
5095 }
5096
John Bauman19bac1e2014-05-06 15:23:49 -04005097 RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs)
John Bauman89401822014-05-06 15:04:28 -04005098 {
5099 return lhs = lhs >> rhs;
5100 }
5101
John Bauman19bac1e2014-05-06 15:23:49 -04005102// RValue<UInt2> operator+(RValue<UInt2> val)
5103// {
5104// return val;
5105// }
5106
5107// RValue<UInt2> operator-(RValue<UInt2> val)
5108// {
5109// return RValue<UInt2>(Nucleus::createNeg(val.value));
5110// }
5111
5112 RValue<UInt2> operator~(RValue<UInt2> val)
John Bauman89401822014-05-06 15:04:28 -04005113 {
John Bauman19bac1e2014-05-06 15:23:49 -04005114 if(CPUID::supportsMMX2())
5115 {
5116 return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF);
5117 }
5118 else
5119 {
5120 return RValue<UInt2>(Nucleus::createNot(val.value));
5121 }
John Bauman89401822014-05-06 15:04:28 -04005122 }
5123
John Bauman19bac1e2014-05-06 15:23:49 -04005124 Type *UInt2::getType()
John Bauman89401822014-05-06 15:04:28 -04005125 {
John Bauman19bac1e2014-05-06 15:23:49 -04005126 if(CPUID::supportsMMX2())
5127 {
5128 return MMX::getType();
5129 }
5130 else
5131 {
5132 return VectorType::get(UInt::getType(), 2);
5133 }
John Bauman89401822014-05-06 15:04:28 -04005134 }
5135
John Bauman19bac1e2014-05-06 15:23:49 -04005136 Int4::Int4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005137 {
5138 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005139
5140 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
John Bauman89401822014-05-06 15:04:28 -04005141
John Bauman66b8ab22014-05-06 15:57:45 -04005142 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005143 }
5144
5145 Int4::Int4()
5146 {
5147 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005148 }
5149
5150 Int4::Int4(int xyzw)
5151 {
5152 constant(xyzw, xyzw, xyzw, xyzw);
5153 }
5154
5155 Int4::Int4(int x, int yzw)
5156 {
5157 constant(x, yzw, yzw, yzw);
5158 }
5159
5160 Int4::Int4(int x, int y, int zw)
5161 {
5162 constant(x, y, zw, zw);
5163 }
5164
5165 Int4::Int4(int x, int y, int z, int w)
5166 {
5167 constant(x, y, z, w);
5168 }
5169
5170 void Int4::constant(int x, int y, int z, int w)
5171 {
5172 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005173
5174 Constant *constantVector[4];
5175 constantVector[0] = Nucleus::createConstantInt(x);
5176 constantVector[1] = Nucleus::createConstantInt(y);
5177 constantVector[2] = Nucleus::createConstantInt(z);
5178 constantVector[3] = Nucleus::createConstantInt(w);
5179
John Bauman66b8ab22014-05-06 15:57:45 -04005180 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005181 }
5182
John Bauman19bac1e2014-05-06 15:23:49 -04005183 Int4::Int4(RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005184 {
5185 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005186
John Bauman66b8ab22014-05-06 15:57:45 -04005187 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005188 }
5189
5190 Int4::Int4(const Int4 &rhs)
5191 {
5192 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005193
John Bauman66b8ab22014-05-06 15:57:45 -04005194 Value *value = rhs.loadValue();
5195 storeValue(value);
5196 }
5197
5198 Int4::Int4(const Reference<Int4> &rhs)
5199 {
5200 // xyzw.parent = this;
5201
5202 Value *value = rhs.loadValue();
5203 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005204 }
5205
John Bauman19bac1e2014-05-06 15:23:49 -04005206 Int4::Int4(RValue<UInt4> rhs)
5207 {
5208 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005209
John Bauman66b8ab22014-05-06 15:57:45 -04005210 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005211 }
5212
5213 Int4::Int4(const UInt4 &rhs)
5214 {
5215 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005216
John Bauman66b8ab22014-05-06 15:57:45 -04005217 Value *value = rhs.loadValue();
5218 storeValue(value);
5219 }
5220
5221 Int4::Int4(const Reference<UInt4> &rhs)
5222 {
5223 // xyzw.parent = this;
5224
5225 Value *value = rhs.loadValue();
5226 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005227 }
5228
5229 RValue<Int4> Int4::operator=(RValue<Int4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005230 {
John Bauman66b8ab22014-05-06 15:57:45 -04005231 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005232
5233 return rhs;
5234 }
5235
5236 RValue<Int4> Int4::operator=(const Int4 &rhs) const
5237 {
John Bauman66b8ab22014-05-06 15:57:45 -04005238 Value *value = rhs.loadValue();
5239 storeValue(value);
5240
5241 return RValue<Int4>(value);
5242 }
5243
5244 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const
5245 {
5246 Value *value = rhs.loadValue();
5247 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005248
5249 return RValue<Int4>(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::createAdd(lhs.value, rhs.value));
5255 }
5256
John Bauman19bac1e2014-05-06 15:23:49 -04005257 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005258 {
5259 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5260 }
5261
John Bauman19bac1e2014-05-06 15:23:49 -04005262 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005263 {
5264 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5265 }
5266
John Bauman19bac1e2014-05-06 15:23:49 -04005267// RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5268// {
5269// return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5270// }
John Bauman89401822014-05-06 15:04:28 -04005271
John Bauman19bac1e2014-05-06 15:23:49 -04005272// RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5273// {
5274// return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5275// }
John Bauman89401822014-05-06 15:04:28 -04005276
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::createAnd(lhs.value, rhs.value));
5280 }
5281
John Bauman19bac1e2014-05-06 15:23:49 -04005282 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005283 {
5284 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5285 }
5286
John Bauman19bac1e2014-05-06 15:23:49 -04005287 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005288 {
5289 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5290 }
5291
John Bauman19bac1e2014-05-06 15:23:49 -04005292 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005293 {
5294 // return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5295
5296 return x86::pslld(lhs, rhs);
5297 }
5298
John Bauman19bac1e2014-05-06 15:23:49 -04005299 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005300 {
5301 // return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5302
5303 return x86::psrad(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)
John Bauman89401822014-05-06 15:04:28 -04005312 {
5313 return lhs = lhs - rhs;
5314 }
5315
John Bauman19bac1e2014-05-06 15:23:49 -04005316 RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005317 {
5318 return lhs = lhs * rhs;
5319 }
5320
John Bauman19bac1e2014-05-06 15:23:49 -04005321// RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs)
5322// {
5323// return lhs = lhs / rhs;
5324// }
John Bauman89401822014-05-06 15:04:28 -04005325
John Bauman19bac1e2014-05-06 15:23:49 -04005326// RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs)
5327// {
5328// return lhs = lhs % rhs;
5329// }
John Bauman89401822014-05-06 15:04:28 -04005330
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
John Bauman19bac1e2014-05-06 15:23:49 -04005336 RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005337 {
5338 return lhs = lhs | rhs;
5339 }
5340
John Bauman19bac1e2014-05-06 15:23:49 -04005341 RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005342 {
5343 return lhs = lhs ^ rhs;
5344 }
5345
5346 RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
5347 {
5348 return lhs = lhs << rhs;
5349 }
5350
5351 RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
5352 {
5353 return lhs = lhs >> rhs;
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 val;
5359 }
5360
John Bauman19bac1e2014-05-06 15:23:49 -04005361 RValue<Int4> operator-(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005362 {
5363 return RValue<Int4>(Nucleus::createNeg(val.value));
5364 }
5365
John Bauman19bac1e2014-05-06 15:23:49 -04005366 RValue<Int4> operator~(RValue<Int4> val)
John Bauman89401822014-05-06 15:04:28 -04005367 {
5368 return RValue<Int4>(Nucleus::createNot(val.value));
5369 }
5370
John Bauman19bac1e2014-05-06 15:23:49 -04005371 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5372 {
5373 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5374 }
5375
5376 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5377 {
5378 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
5379 }
5380
5381 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5382 {
5383 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
5384 }
5385
5386 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5387 {
5388 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5389 }
5390
5391 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5392 {
5393 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
5394 }
5395
5396 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5397 {
5398 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
5399 }
5400
5401 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5402 {
5403 if(CPUID::supportsSSE4_1())
5404 {
5405 return x86::pmaxsd(x, y);
5406 }
5407 else
5408 {
5409 RValue<Int4> greater = CmpNLE(x, y);
5410 return x & greater | y & ~greater;
5411 }
5412 }
5413
5414 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5415 {
5416 if(CPUID::supportsSSE4_1())
5417 {
5418 return x86::pminsd(x, y);
5419 }
5420 else
5421 {
5422 RValue<Int4> less = CmpLT(x, y);
5423 return x & less | y & ~less;
5424 }
5425 }
5426
5427 RValue<Int4> RoundInt(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005428 {
5429 return x86::cvtps2dq(cast);
5430 }
5431
John Bauman19bac1e2014-05-06 15:23:49 -04005432 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04005433 {
5434 return x86::packssdw(x, y);
5435 }
5436
John Bauman19bac1e2014-05-06 15:23:49 -04005437 RValue<Int4> Concatenate(RValue<Int2> lo, RValue<Int2> hi)
John Bauman89401822014-05-06 15:04:28 -04005438 {
5439 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5440 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5441
5442 Value *long2 = UndefValue::get(Long2::getType());
5443 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5444 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5445 Value *int4 = Nucleus::createBitCast(long2, Int4::getType());
5446
5447 return RValue<Int4>(int4);
5448 }
5449
John Bauman19bac1e2014-05-06 15:23:49 -04005450 RValue<Int> Extract(RValue<Int4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04005451 {
5452 return RValue<Int>(Nucleus::createExtractElement(x.value, i));
5453 }
5454
John Bauman19bac1e2014-05-06 15:23:49 -04005455 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
John Bauman89401822014-05-06 15:04:28 -04005456 {
5457 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5458 }
5459
John Bauman19bac1e2014-05-06 15:23:49 -04005460 RValue<Int> SignMask(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04005461 {
5462 return x86::movmskps(As<Float4>(x));
5463 }
5464
John Bauman19bac1e2014-05-06 15:23:49 -04005465 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04005466 {
5467 return RValue<Int4>(Nucleus::createSwizzle(x.value, select));
5468 }
5469
John Bauman19bac1e2014-05-06 15:23:49 -04005470 Type *Int4::getType()
John Bauman89401822014-05-06 15:04:28 -04005471 {
5472 return VectorType::get(Int::getType(), 4);
5473 }
5474
John Bauman19bac1e2014-05-06 15:23:49 -04005475 UInt4::UInt4(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04005476 {
5477 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005478
5479 Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
5480
John Bauman66b8ab22014-05-06 15:57:45 -04005481 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04005482 }
5483
5484 UInt4::UInt4()
5485 {
5486 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005487 }
5488
John Bauman19bac1e2014-05-06 15:23:49 -04005489 UInt4::UInt4(int xyzw)
5490 {
5491 constant(xyzw, xyzw, xyzw, xyzw);
5492 }
5493
5494 UInt4::UInt4(int x, int yzw)
5495 {
5496 constant(x, yzw, yzw, yzw);
5497 }
5498
5499 UInt4::UInt4(int x, int y, int zw)
5500 {
5501 constant(x, y, zw, zw);
5502 }
5503
5504 UInt4::UInt4(int x, int y, int z, int w)
5505 {
5506 constant(x, y, z, w);
5507 }
5508
5509 void UInt4::constant(int x, int y, int z, int w)
John Bauman89401822014-05-06 15:04:28 -04005510 {
5511 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005512
5513 Constant *constantVector[4];
5514 constantVector[0] = Nucleus::createConstantInt(x);
5515 constantVector[1] = Nucleus::createConstantInt(y);
5516 constantVector[2] = Nucleus::createConstantInt(z);
5517 constantVector[3] = Nucleus::createConstantInt(w);
5518
John Bauman66b8ab22014-05-06 15:57:45 -04005519 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04005520 }
5521
John Bauman19bac1e2014-05-06 15:23:49 -04005522 UInt4::UInt4(RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005523 {
5524 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005525
John Bauman66b8ab22014-05-06 15:57:45 -04005526 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005527 }
5528
5529 UInt4::UInt4(const UInt4 &rhs)
5530 {
5531 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04005532
John Bauman66b8ab22014-05-06 15:57:45 -04005533 Value *value = rhs.loadValue();
5534 storeValue(value);
5535 }
5536
5537 UInt4::UInt4(const Reference<UInt4> &rhs)
5538 {
5539 // xyzw.parent = this;
5540
5541 Value *value = rhs.loadValue();
5542 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005543 }
5544
John Bauman19bac1e2014-05-06 15:23:49 -04005545 UInt4::UInt4(RValue<Int4> rhs)
5546 {
5547 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005548
John Bauman66b8ab22014-05-06 15:57:45 -04005549 storeValue(rhs.value);
John Bauman19bac1e2014-05-06 15:23:49 -04005550 }
5551
5552 UInt4::UInt4(const Int4 &rhs)
5553 {
5554 // xyzw.parent = this;
John Bauman19bac1e2014-05-06 15:23:49 -04005555
John Bauman66b8ab22014-05-06 15:57:45 -04005556 Value *value = rhs.loadValue();
5557 storeValue(value);
5558 }
5559
5560 UInt4::UInt4(const Reference<Int4> &rhs)
5561 {
5562 // xyzw.parent = this;
5563
5564 Value *value = rhs.loadValue();
5565 storeValue(value);
John Bauman19bac1e2014-05-06 15:23:49 -04005566 }
5567
5568 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005569 {
John Bauman66b8ab22014-05-06 15:57:45 -04005570 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005571
5572 return rhs;
5573 }
5574
5575 RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
5576 {
John Bauman66b8ab22014-05-06 15:57:45 -04005577 Value *value = rhs.loadValue();
5578 storeValue(value);
5579
5580 return RValue<UInt4>(value);
5581 }
5582
5583 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const
5584 {
5585 Value *value = rhs.loadValue();
5586 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005587
5588 return RValue<UInt4>(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::createAdd(lhs.value, rhs.value));
5594 }
5595
John Bauman19bac1e2014-05-06 15:23:49 -04005596 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005597 {
5598 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5599 }
5600
John Bauman19bac1e2014-05-06 15:23:49 -04005601 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005602 {
5603 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5604 }
5605
John Bauman19bac1e2014-05-06 15:23:49 -04005606// RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5607// {
5608// return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5609// }
John Bauman89401822014-05-06 15:04:28 -04005610
John Bauman19bac1e2014-05-06 15:23:49 -04005611// RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5612// {
5613// return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5614// }
John Bauman89401822014-05-06 15:04:28 -04005615
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::createAnd(lhs.value, rhs.value));
5619 }
5620
John Bauman19bac1e2014-05-06 15:23:49 -04005621 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005622 {
5623 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5624 }
5625
John Bauman19bac1e2014-05-06 15:23:49 -04005626 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005627 {
5628 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5629 }
5630
John Bauman19bac1e2014-05-06 15:23:49 -04005631 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005632 {
5633 // return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5634
5635 return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs));
5636 }
5637
John Bauman19bac1e2014-05-06 15:23:49 -04005638 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
John Bauman89401822014-05-06 15:04:28 -04005639 {
5640 // return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5641
5642 return x86::psrld(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)
John Bauman89401822014-05-06 15:04:28 -04005651 {
5652 return lhs = lhs - rhs;
5653 }
5654
John Bauman19bac1e2014-05-06 15:23:49 -04005655 RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005656 {
5657 return lhs = lhs * rhs;
5658 }
5659
John Bauman19bac1e2014-05-06 15:23:49 -04005660// RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs)
5661// {
5662// return lhs = lhs / rhs;
5663// }
John Bauman89401822014-05-06 15:04:28 -04005664
John Bauman19bac1e2014-05-06 15:23:49 -04005665// RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs)
5666// {
5667// return lhs = lhs % rhs;
5668// }
John Bauman89401822014-05-06 15:04:28 -04005669
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
John Bauman19bac1e2014-05-06 15:23:49 -04005675 RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005676 {
5677 return lhs = lhs | rhs;
5678 }
5679
John Bauman19bac1e2014-05-06 15:23:49 -04005680 RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs)
John Bauman89401822014-05-06 15:04:28 -04005681 {
5682 return lhs = lhs ^ rhs;
5683 }
5684
5685 RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
5686 {
5687 return lhs = lhs << rhs;
5688 }
5689
5690 RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
5691 {
5692 return lhs = lhs >> rhs;
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 val;
5698 }
5699
John Bauman19bac1e2014-05-06 15:23:49 -04005700 RValue<UInt4> operator-(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005701 {
5702 return RValue<UInt4>(Nucleus::createNeg(val.value));
5703 }
5704
John Bauman19bac1e2014-05-06 15:23:49 -04005705 RValue<UInt4> operator~(RValue<UInt4> val)
John Bauman89401822014-05-06 15:04:28 -04005706 {
5707 return RValue<UInt4>(Nucleus::createNot(val.value));
5708 }
5709
John Bauman19bac1e2014-05-06 15:23:49 -04005710 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5711 {
5712 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5713 }
5714
5715 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5716 {
5717 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5718 }
5719
5720 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5721 {
5722 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5723 }
5724
5725 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5726 {
5727 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5728 }
5729
5730 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5731 {
5732 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5733 }
5734
5735 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5736 {
5737 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5738 }
5739
5740 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5741 {
5742 if(CPUID::supportsSSE4_1())
5743 {
5744 return x86::pmaxud(x, y);
5745 }
5746 else
5747 {
5748 RValue<UInt4> greater = CmpNLE(x, y);
5749 return x & greater | y & ~greater;
5750 }
5751 }
5752
5753 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5754 {
5755 if(CPUID::supportsSSE4_1())
5756 {
5757 return x86::pminud(x, y);
5758 }
5759 else
5760 {
5761 RValue<UInt4> less = CmpLT(x, y);
5762 return x & less | y & ~less;
5763 }
5764 }
5765
5766 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04005767 {
5768 return x86::packusdw(x, y); // FIXME: Fallback required
5769 }
5770
John Bauman19bac1e2014-05-06 15:23:49 -04005771 RValue<UInt4> Concatenate(RValue<UInt2> lo, RValue<UInt2> hi)
John Bauman89401822014-05-06 15:04:28 -04005772 {
5773 Value *loLong = Nucleus::createBitCast(lo.value, Long::getType());
5774 Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType());
5775
5776 Value *long2 = UndefValue::get(Long2::getType());
5777 long2 = Nucleus::createInsertElement(long2, loLong, 0);
5778 long2 = Nucleus::createInsertElement(long2, hiLong, 1);
5779 Value *uint4 = Nucleus::createBitCast(long2, Int4::getType());
5780
5781 return RValue<UInt4>(uint4);
5782 }
5783
John Bauman19bac1e2014-05-06 15:23:49 -04005784 Type *UInt4::getType()
John Bauman89401822014-05-06 15:04:28 -04005785 {
5786 return VectorType::get(UInt::getType(), 4);
5787 }
5788
John Bauman19bac1e2014-05-06 15:23:49 -04005789 Float::Float(RValue<Int> cast)
John Bauman89401822014-05-06 15:04:28 -04005790 {
John Bauman89401822014-05-06 15:04:28 -04005791 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5792
John Bauman66b8ab22014-05-06 15:57:45 -04005793 storeValue(integer);
John Bauman89401822014-05-06 15:04:28 -04005794 }
5795
5796 Float::Float()
5797 {
John Bauman66b8ab22014-05-06 15:57:45 -04005798
John Bauman89401822014-05-06 15:04:28 -04005799 }
5800
5801 Float::Float(float x)
5802 {
John Bauman66b8ab22014-05-06 15:57:45 -04005803 storeValue(Nucleus::createConstantFloat(x));
John Bauman89401822014-05-06 15:04:28 -04005804 }
5805
John Bauman19bac1e2014-05-06 15:23:49 -04005806 Float::Float(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005807 {
John Bauman66b8ab22014-05-06 15:57:45 -04005808 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005809 }
5810
5811 Float::Float(const Float &rhs)
5812 {
John Bauman66b8ab22014-05-06 15:57:45 -04005813 Value *value = rhs.loadValue();
5814 storeValue(value);
5815 }
John Bauman89401822014-05-06 15:04:28 -04005816
John Bauman66b8ab22014-05-06 15:57:45 -04005817 Float::Float(const Reference<Float> &rhs)
5818 {
5819 Value *value = rhs.loadValue();
5820 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005821 }
5822
John Bauman19bac1e2014-05-06 15:23:49 -04005823 RValue<Float> Float::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04005824 {
John Bauman66b8ab22014-05-06 15:57:45 -04005825 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04005826
5827 return rhs;
5828 }
5829
5830 RValue<Float> Float::operator=(const Float &rhs) const
5831 {
John Bauman66b8ab22014-05-06 15:57:45 -04005832 Value *value = rhs.loadValue();
5833 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04005834
5835 return RValue<Float>(value);
5836 }
5837
John Bauman66b8ab22014-05-06 15:57:45 -04005838 RValue<Float> Float::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04005839 {
John Bauman66b8ab22014-05-06 15:57:45 -04005840 Value *value = rhs.loadValue();
5841 storeValue(value);
5842
5843 return RValue<Float>(value);
John Bauman89401822014-05-06 15:04:28 -04005844 }
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::createFAdd(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::createFSub(lhs.value, rhs.value));
5854 }
5855
John Bauman19bac1e2014-05-06 15:23:49 -04005856 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005857 {
5858 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5859 }
5860
John Bauman19bac1e2014-05-06 15:23:49 -04005861 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005862 {
5863 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
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*=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005877 {
5878 return lhs = lhs * rhs;
5879 }
5880
John Bauman19bac1e2014-05-06 15:23:49 -04005881 RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005882 {
5883 return lhs = lhs / rhs;
5884 }
5885
John Bauman19bac1e2014-05-06 15:23:49 -04005886 RValue<Float> operator+(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005887 {
5888 return val;
5889 }
5890
John Bauman19bac1e2014-05-06 15:23:49 -04005891 RValue<Float> operator-(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04005892 {
5893 return RValue<Float>(Nucleus::createFNeg(val.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::createFCmpOLT(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::createFCmpOLE(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::createFCmpOGT(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::createFCmpOGE(lhs.value, rhs.value));
5914 }
5915
John Bauman19bac1e2014-05-06 15:23:49 -04005916 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005917 {
5918 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5919 }
5920
John Bauman19bac1e2014-05-06 15:23:49 -04005921 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04005922 {
5923 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5924 }
5925
John Bauman19bac1e2014-05-06 15:23:49 -04005926 RValue<Float> Abs(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005927 {
John Bauman66b8ab22014-05-06 15:57:45 -04005928 return IfThenElse(x > 0.0f, x, -x);
John Bauman89401822014-05-06 15:04:28 -04005929 }
5930
John Bauman19bac1e2014-05-06 15:23:49 -04005931 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04005932 {
5933 return IfThenElse(x > y, x, y);
5934 }
5935
John Bauman19bac1e2014-05-06 15:23:49 -04005936 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04005937 {
5938 return IfThenElse(x < y, x, y);
5939 }
5940
John Bauman19bac1e2014-05-06 15:23:49 -04005941 RValue<Float> Rcp_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005942 {
5943 return x86::rcpss(x);
5944 }
John Bauman66b8ab22014-05-06 15:57:45 -04005945
John Bauman19bac1e2014-05-06 15:23:49 -04005946 RValue<Float> RcpSqrt_pp(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005947 {
5948 return x86::rsqrtss(x);
5949 }
5950
John Bauman19bac1e2014-05-06 15:23:49 -04005951 RValue<Float> Sqrt(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005952 {
5953 return x86::sqrtss(x);
5954 }
5955
John Bauman19bac1e2014-05-06 15:23:49 -04005956 RValue<Float> Round(RValue<Float> x)
5957 {
5958 if(CPUID::supportsSSE4_1())
5959 {
5960 return x86::roundss(x, 0);
5961 }
5962 else
5963 {
5964 return Float4(Round(Float4(x))).x;
5965 }
5966 }
5967
5968 RValue<Float> Trunc(RValue<Float> x)
5969 {
5970 if(CPUID::supportsSSE4_1())
5971 {
5972 return x86::roundss(x, 3);
5973 }
5974 else
5975 {
5976 return Float(Int(x)); // Rounded toward zero
5977 }
5978 }
5979
5980 RValue<Float> Frac(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005981 {
5982 if(CPUID::supportsSSE4_1())
5983 {
5984 return x - x86::floorss(x);
5985 }
5986 else
5987 {
John Bauman19bac1e2014-05-06 15:23:49 -04005988 return Float4(Frac(Float4(x))).x;
John Bauman89401822014-05-06 15:04:28 -04005989 }
5990 }
5991
John Bauman19bac1e2014-05-06 15:23:49 -04005992 RValue<Float> Floor(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04005993 {
5994 if(CPUID::supportsSSE4_1())
5995 {
5996 return x86::floorss(x);
5997 }
5998 else
5999 {
6000 return Float4(Floor(Float4(x))).x;
6001 }
6002 }
6003
John Bauman19bac1e2014-05-06 15:23:49 -04006004 RValue<Float> Ceil(RValue<Float> x)
John Bauman89401822014-05-06 15:04:28 -04006005 {
John Bauman19bac1e2014-05-06 15:23:49 -04006006 if(CPUID::supportsSSE4_1())
6007 {
6008 return x86::ceilss(x);
6009 }
6010 else
6011 {
6012 return Float4(Ceil(Float4(x))).x;
6013 }
John Bauman89401822014-05-06 15:04:28 -04006014 }
6015
John Bauman19bac1e2014-05-06 15:23:49 -04006016 Type *Float::getType()
John Bauman89401822014-05-06 15:04:28 -04006017 {
6018 return Type::getFloatTy(*Nucleus::getContext());
6019 }
6020
John Bauman19bac1e2014-05-06 15:23:49 -04006021 Float2::Float2(RValue<Float4> cast)
John Bauman89401822014-05-06 15:04:28 -04006022 {
6023 // xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006024
6025 Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
6026 Value *int64 = Nucleus::createExtractElement(int64x2, 0);
6027 Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
6028
John Bauman66b8ab22014-05-06 15:57:45 -04006029 storeValue(float2);
John Bauman89401822014-05-06 15:04:28 -04006030 }
6031
John Bauman19bac1e2014-05-06 15:23:49 -04006032 Type *Float2::getType()
John Bauman89401822014-05-06 15:04:28 -04006033 {
6034 return VectorType::get(Float::getType(), 2);
6035 }
6036
John Bauman19bac1e2014-05-06 15:23:49 -04006037 Float4::Float4(RValue<Byte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006038 {
6039 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006040
6041 #if 0
6042 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6043 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006044 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006045
6046 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6047 Value *f32x = Nucleus::createUIToFP(i8x, Float::getType());
6048 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6049
6050 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6051 Value *f32y = Nucleus::createUIToFP(i8y, Float::getType());
6052 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6053
6054 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6055 Value *f32z = Nucleus::createUIToFP(i8z, Float::getType());
6056 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6057
6058 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6059 Value *f32w = Nucleus::createUIToFP(i8w, Float::getType());
6060 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6061 #else
6062 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6063 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6064
6065 Value *e;
6066
6067 if(CPUID::supportsSSE4_1())
6068 {
6069 e = x86::pmovzxbd(RValue<Int4>(a)).value;
6070 }
6071 else
6072 {
6073 Constant *swizzle[16];
6074 swizzle[0] = Nucleus::createConstantInt(0);
6075 swizzle[1] = Nucleus::createConstantInt(16);
6076 swizzle[2] = Nucleus::createConstantInt(1);
6077 swizzle[3] = Nucleus::createConstantInt(17);
6078 swizzle[4] = Nucleus::createConstantInt(2);
6079 swizzle[5] = Nucleus::createConstantInt(18);
6080 swizzle[6] = Nucleus::createConstantInt(3);
6081 swizzle[7] = Nucleus::createConstantInt(19);
6082 swizzle[8] = Nucleus::createConstantInt(4);
6083 swizzle[9] = Nucleus::createConstantInt(20);
6084 swizzle[10] = Nucleus::createConstantInt(5);
6085 swizzle[11] = Nucleus::createConstantInt(21);
6086 swizzle[12] = Nucleus::createConstantInt(6);
6087 swizzle[13] = Nucleus::createConstantInt(22);
6088 swizzle[14] = Nucleus::createConstantInt(7);
6089 swizzle[15] = Nucleus::createConstantInt(23);
6090
6091 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6092 Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16));
6093
6094 Constant *swizzle2[8];
6095 swizzle2[0] = Nucleus::createConstantInt(0);
6096 swizzle2[1] = Nucleus::createConstantInt(8);
6097 swizzle2[2] = Nucleus::createConstantInt(1);
6098 swizzle2[3] = Nucleus::createConstantInt(9);
6099 swizzle2[4] = Nucleus::createConstantInt(2);
6100 swizzle2[5] = Nucleus::createConstantInt(10);
6101 swizzle2[6] = Nucleus::createConstantInt(3);
6102 swizzle2[7] = Nucleus::createConstantInt(11);
6103
6104 Value *d = Nucleus::createBitCast(c, Short8::getType());
6105 e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8));
6106 }
6107
6108 Value *f = Nucleus::createBitCast(e, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006109 Value *g = Nucleus::createSIToFP(f, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006110 Value *xyzw = g;
6111 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006112
6113 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006114 }
6115
John Bauman19bac1e2014-05-06 15:23:49 -04006116 Float4::Float4(RValue<SByte4> cast)
John Bauman89401822014-05-06 15:04:28 -04006117 {
6118 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006119
6120 #if 0
6121 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6122 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006123 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006124
6125 Value *i8x = Nucleus::createExtractElement(cast.value, 0);
6126 Value *f32x = Nucleus::createSIToFP(i8x, Float::getType());
6127 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6128
6129 Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6130 Value *f32y = Nucleus::createSIToFP(i8y, Float::getType());
6131 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6132
6133 Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6134 Value *f32z = Nucleus::createSIToFP(i8z, Float::getType());
6135 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6136
6137 Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6138 Value *f32w = Nucleus::createSIToFP(i8w, Float::getType());
6139 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6140 #else
6141 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
6142 Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0);
6143
6144 Value *g;
6145
6146 if(CPUID::supportsSSE4_1())
6147 {
6148 g = x86::pmovsxbd(RValue<Int4>(a)).value;
6149 }
6150 else
6151 {
6152 Constant *swizzle[16];
6153 swizzle[0] = Nucleus::createConstantInt(0);
6154 swizzle[1] = Nucleus::createConstantInt(0);
6155 swizzle[2] = Nucleus::createConstantInt(1);
6156 swizzle[3] = Nucleus::createConstantInt(1);
6157 swizzle[4] = Nucleus::createConstantInt(2);
6158 swizzle[5] = Nucleus::createConstantInt(2);
6159 swizzle[6] = Nucleus::createConstantInt(3);
6160 swizzle[7] = Nucleus::createConstantInt(3);
6161 swizzle[8] = Nucleus::createConstantInt(4);
6162 swizzle[9] = Nucleus::createConstantInt(4);
6163 swizzle[10] = Nucleus::createConstantInt(5);
6164 swizzle[11] = Nucleus::createConstantInt(5);
6165 swizzle[12] = Nucleus::createConstantInt(6);
6166 swizzle[13] = Nucleus::createConstantInt(6);
6167 swizzle[14] = Nucleus::createConstantInt(7);
6168 swizzle[15] = Nucleus::createConstantInt(7);
6169
6170 Value *b = Nucleus::createBitCast(a, Byte16::getType());
6171 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16));
6172
6173 Constant *swizzle2[8];
6174 swizzle2[0] = Nucleus::createConstantInt(0);
6175 swizzle2[1] = Nucleus::createConstantInt(0);
6176 swizzle2[2] = Nucleus::createConstantInt(1);
6177 swizzle2[3] = Nucleus::createConstantInt(1);
6178 swizzle2[4] = Nucleus::createConstantInt(2);
6179 swizzle2[5] = Nucleus::createConstantInt(2);
6180 swizzle2[6] = Nucleus::createConstantInt(3);
6181 swizzle2[7] = Nucleus::createConstantInt(3);
6182
6183 Value *d = Nucleus::createBitCast(c, Short8::getType());
6184 Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8));
6185
6186 Value *f = Nucleus::createBitCast(e, Int4::getType());
6187 // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24));
6188 g = x86::psrad(RValue<Int4>(f), 24).value;
6189 }
6190
John Bauman19bac1e2014-05-06 15:23:49 -04006191 Value *xyzw = Nucleus::createSIToFP(g, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006192 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006193
6194 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006195 }
6196
John Bauman19bac1e2014-05-06 15:23:49 -04006197 Float4::Float4(RValue<Short4> cast)
John Bauman89401822014-05-06 15:04:28 -04006198 {
6199 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006200
6201 #if 0
6202 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6203 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006204 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006205
6206 Value *i16x = Nucleus::createExtractElement(cast.value, 0);
6207 Value *f32x = Nucleus::createSIToFP(i16x, Float::getType());
6208 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6209
6210 Value *i16y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6211 Value *f32y = Nucleus::createSIToFP(i16y, Float::getType());
6212 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6213
6214 Value *i16z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6215 Value *f32z = Nucleus::createSIToFP(i16z, Float::getType());
6216 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6217
6218 Value *i16w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6219 Value *f32w = Nucleus::createSIToFP(i16w, Float::getType());
6220 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6221 #else
6222 Value *long2 = UndefValue::get(Long2::getType());
6223 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
6224 long2 = Nucleus::createInsertElement(long2, element, 0);
6225 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
6226
6227 Value *xyzw;
6228
6229 if(CPUID::supportsSSE4_1())
6230 {
6231 Value *c = x86::pmovsxwd(vector).value;
6232
John Bauman19bac1e2014-05-06 15:23:49 -04006233 xyzw = Nucleus::createSIToFP(c, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006234 }
6235 else
6236 {
6237 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
6238
6239 Constant *swizzle[8];
6240 swizzle[0] = Nucleus::createConstantInt(0);
6241 swizzle[1] = Nucleus::createConstantInt(0);
6242 swizzle[2] = Nucleus::createConstantInt(1);
6243 swizzle[3] = Nucleus::createConstantInt(1);
6244 swizzle[4] = Nucleus::createConstantInt(2);
6245 swizzle[5] = Nucleus::createConstantInt(2);
6246 swizzle[6] = Nucleus::createConstantInt(3);
6247 swizzle[7] = Nucleus::createConstantInt(3);
John Bauman66b8ab22014-05-06 15:57:45 -04006248
John Bauman89401822014-05-06 15:04:28 -04006249 Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8));
6250 Value *d = Nucleus::createBitCast(c, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006251 Value *e = Nucleus::createSIToFP(d, Float4::getType());
John Bauman66b8ab22014-05-06 15:57:45 -04006252
John Bauman89401822014-05-06 15:04:28 -04006253 Constant *constantVector[4];
6254 constantVector[0] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6255 constantVector[1] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6256 constantVector[2] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6257 constantVector[3] = Nucleus::createConstantFloat(1.0f / (1 << 16));
6258
6259 xyzw = Nucleus::createFMul(e, Nucleus::createConstantVector(constantVector, 4));
6260 }
6261 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006262
6263 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006264 }
6265
John Bauman19bac1e2014-05-06 15:23:49 -04006266 Float4::Float4(RValue<UShort4> cast)
John Bauman89401822014-05-06 15:04:28 -04006267 {
6268 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006269
6270 #if 0
6271 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes
6272 #elif 0
John Bauman66b8ab22014-05-06 15:57:45 -04006273 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006274
6275 Value *i16x = Nucleus::createExtractElement(cast.value, 0);
6276 Value *f32x = Nucleus::createUIToFP(i16x, Float::getType());
6277 Value *x = Nucleus::createInsertElement(vector, f32x, 0);
6278
6279 Value *i16y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1));
6280 Value *f32y = Nucleus::createUIToFP(i16y, Float::getType());
6281 Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1));
6282
6283 Value *i16z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2));
6284 Value *f32z = Nucleus::createUIToFP(i16z, Float::getType());
6285 Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2));
6286
6287 Value *i16w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3));
6288 Value *f32w = Nucleus::createUIToFP(i16w, Float::getType());
6289 Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3));
6290 #else
6291 Value *long2 = UndefValue::get(Long2::getType());
6292 Value *element = Nucleus::createBitCast(cast.value, Long::getType());
6293 long2 = Nucleus::createInsertElement(long2, element, 0);
6294 RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType()));
6295
6296 Value *c;
John Bauman66b8ab22014-05-06 15:57:45 -04006297
John Bauman89401822014-05-06 15:04:28 -04006298 if(CPUID::supportsSSE4_1())
6299 {
6300 c = x86::pmovzxwd(RValue<Int4>(vector)).value;
6301 }
6302 else
6303 {
6304 Value *b = Nucleus::createBitCast(vector.value, Short8::getType());
6305
6306 Constant *swizzle[8];
6307 swizzle[0] = Nucleus::createConstantInt(0);
6308 swizzle[1] = Nucleus::createConstantInt(8);
6309 swizzle[2] = Nucleus::createConstantInt(1);
6310 swizzle[3] = Nucleus::createConstantInt(9);
6311 swizzle[4] = Nucleus::createConstantInt(2);
6312 swizzle[5] = Nucleus::createConstantInt(10);
6313 swizzle[6] = Nucleus::createConstantInt(3);
6314 swizzle[7] = Nucleus::createConstantInt(11);
6315
6316 c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8));
6317 }
6318
6319 Value *d = Nucleus::createBitCast(c, Int4::getType());
John Bauman19bac1e2014-05-06 15:23:49 -04006320 Value *e = Nucleus::createSIToFP(d, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006321 Value *xyzw = e;
6322 #endif
John Bauman66b8ab22014-05-06 15:57:45 -04006323
6324 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006325 }
6326
John Bauman19bac1e2014-05-06 15:23:49 -04006327 Float4::Float4(RValue<Int4> cast)
John Bauman89401822014-05-06 15:04:28 -04006328 {
6329 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006330
6331 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
John Bauman89401822014-05-06 15:04:28 -04006332
John Bauman66b8ab22014-05-06 15:57:45 -04006333 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006334 }
6335
John Bauman19bac1e2014-05-06 15:23:49 -04006336 Float4::Float4(RValue<UInt4> cast)
John Bauman89401822014-05-06 15:04:28 -04006337 {
6338 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006339
6340 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
6341
John Bauman66b8ab22014-05-06 15:57:45 -04006342 storeValue(xyzw);
John Bauman89401822014-05-06 15:04:28 -04006343 }
6344
6345 Float4::Float4()
6346 {
6347 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006348 }
John Bauman66b8ab22014-05-06 15:57:45 -04006349
John Bauman89401822014-05-06 15:04:28 -04006350 Float4::Float4(float xyzw)
6351 {
6352 constant(xyzw, xyzw, xyzw, xyzw);
6353 }
6354
6355 Float4::Float4(float x, float yzw)
6356 {
6357 constant(x, yzw, yzw, yzw);
6358 }
6359
6360 Float4::Float4(float x, float y, float zw)
6361 {
6362 constant(x, y, zw, zw);
6363 }
6364
6365 Float4::Float4(float x, float y, float z, float w)
6366 {
6367 constant(x, y, z, w);
6368 }
6369
6370 void Float4::constant(float x, float y, float z, float w)
6371 {
6372 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006373
6374 Constant *constantVector[4];
6375 constantVector[0] = Nucleus::createConstantFloat(x);
6376 constantVector[1] = Nucleus::createConstantFloat(y);
6377 constantVector[2] = Nucleus::createConstantFloat(z);
6378 constantVector[3] = Nucleus::createConstantFloat(w);
6379
John Bauman66b8ab22014-05-06 15:57:45 -04006380 storeValue(Nucleus::createConstantVector(constantVector, 4));
John Bauman89401822014-05-06 15:04:28 -04006381 }
6382
John Bauman19bac1e2014-05-06 15:23:49 -04006383 Float4::Float4(RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006384 {
6385 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006386
John Bauman66b8ab22014-05-06 15:57:45 -04006387 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006388 }
6389
6390 Float4::Float4(const Float4 &rhs)
6391 {
6392 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006393
John Bauman66b8ab22014-05-06 15:57:45 -04006394 Value *value = rhs.loadValue();
6395 storeValue(value);
6396 }
6397
6398 Float4::Float4(const Reference<Float4> &rhs)
6399 {
6400 xyzw.parent = this;
6401
6402 Value *value = rhs.loadValue();
6403 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006404 }
6405
John Bauman19bac1e2014-05-06 15:23:49 -04006406 Float4::Float4(RValue<Float> rhs)
John Bauman89401822014-05-06 15:04:28 -04006407 {
6408 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006409
John Bauman66b8ab22014-05-06 15:57:45 -04006410 Value *vector = loadValue();
John Bauman89401822014-05-06 15:04:28 -04006411 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
6412
6413 Constant *swizzle[4];
6414 swizzle[0] = Nucleus::createConstantInt(0);
6415 swizzle[1] = Nucleus::createConstantInt(0);
6416 swizzle[2] = Nucleus::createConstantInt(0);
6417 swizzle[3] = Nucleus::createConstantInt(0);
6418
6419 Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4));
6420
John Bauman66b8ab22014-05-06 15:57:45 -04006421 storeValue(replicate);
John Bauman89401822014-05-06 15:04:28 -04006422 }
6423
6424 Float4::Float4(const Float &rhs)
6425 {
6426 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006427
John Bauman66b8ab22014-05-06 15:57:45 -04006428 *this = RValue<Float>(rhs.loadValue());
6429 }
John Bauman89401822014-05-06 15:04:28 -04006430
John Bauman66b8ab22014-05-06 15:57:45 -04006431 Float4::Float4(const Reference<Float> &rhs)
6432 {
6433 xyzw.parent = this;
John Bauman89401822014-05-06 15:04:28 -04006434
John Bauman66b8ab22014-05-06 15:57:45 -04006435 *this = RValue<Float>(rhs.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006436 }
6437
6438 RValue<Float4> Float4::operator=(float x) const
6439 {
6440 return *this = Float4(x, x, x, x);
6441 }
6442
John Bauman19bac1e2014-05-06 15:23:49 -04006443 RValue<Float4> Float4::operator=(RValue<Float4> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006444 {
John Bauman66b8ab22014-05-06 15:57:45 -04006445 storeValue(rhs.value);
John Bauman89401822014-05-06 15:04:28 -04006446
6447 return rhs;
6448 }
6449
6450 RValue<Float4> Float4::operator=(const Float4 &rhs) const
6451 {
John Bauman66b8ab22014-05-06 15:57:45 -04006452 Value *value = rhs.loadValue();
6453 storeValue(value);
6454
6455 return RValue<Float4>(value);
6456 }
6457
6458 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const
6459 {
6460 Value *value = rhs.loadValue();
6461 storeValue(value);
John Bauman89401822014-05-06 15:04:28 -04006462
6463 return RValue<Float4>(value);
6464 }
6465
John Bauman19bac1e2014-05-06 15:23:49 -04006466 RValue<Float4> Float4::operator=(RValue<Float> rhs) const
John Bauman89401822014-05-06 15:04:28 -04006467 {
6468 return *this = Float4(rhs);
6469 }
6470
6471 RValue<Float4> Float4::operator=(const Float &rhs) const
6472 {
6473 return *this = Float4(rhs);
6474 }
6475
John Bauman66b8ab22014-05-06 15:57:45 -04006476 RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const
John Bauman89401822014-05-06 15:04:28 -04006477 {
John Bauman66b8ab22014-05-06 15:57:45 -04006478 return *this = Float4(rhs);
John Bauman89401822014-05-06 15:04:28 -04006479 }
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::createFAdd(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::createFSub(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::createFMul(lhs.value, rhs.value));
6494 }
6495
John Bauman19bac1e2014-05-06 15:23:49 -04006496 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006497 {
6498 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6499 }
6500
John Bauman19bac1e2014-05-06 15:23:49 -04006501 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006502 {
6503 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
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/=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006522 {
6523 return lhs = lhs / rhs;
6524 }
6525
John Bauman19bac1e2014-05-06 15:23:49 -04006526 RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs)
John Bauman89401822014-05-06 15:04:28 -04006527 {
6528 return lhs = lhs % rhs;
6529 }
6530
John Bauman19bac1e2014-05-06 15:23:49 -04006531 RValue<Float4> operator+(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006532 {
6533 return val;
6534 }
6535
John Bauman19bac1e2014-05-06 15:23:49 -04006536 RValue<Float4> operator-(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006537 {
6538 return RValue<Float4>(Nucleus::createFNeg(val.value));
6539 }
6540
John Bauman19bac1e2014-05-06 15:23:49 -04006541 RValue<Float4> Abs(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006542 {
6543 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6544
6545 Constant *constantVector[4];
6546 constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF);
6547 constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF);
6548 constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF);
6549 constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF);
6550
6551 Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4));
6552
6553 return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType()));
6554 }
6555
John Bauman19bac1e2014-05-06 15:23:49 -04006556 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006557 {
6558 return x86::maxps(x, y);
6559 }
6560
John Bauman19bac1e2014-05-06 15:23:49 -04006561 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006562 {
6563 return x86::minps(x, y);
6564 }
6565
John Bauman19bac1e2014-05-06 15:23:49 -04006566 RValue<Float4> Rcp_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006567 {
6568 return x86::rcpps(x);
6569 }
John Bauman66b8ab22014-05-06 15:57:45 -04006570
John Bauman19bac1e2014-05-06 15:23:49 -04006571 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006572 {
6573 return x86::rsqrtps(x);
6574 }
6575
John Bauman19bac1e2014-05-06 15:23:49 -04006576 RValue<Float4> Sqrt(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006577 {
6578 return x86::sqrtps(x);
6579 }
6580
John Bauman19bac1e2014-05-06 15:23:49 -04006581 RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i)
John Bauman89401822014-05-06 15:04:28 -04006582 {
John Bauman66b8ab22014-05-06 15:57:45 -04006583 llvm::Value *value = val.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006584 llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i);
6585
6586 val = RValue<Float4>(insert);
6587
6588 return val;
6589 }
6590
John Bauman19bac1e2014-05-06 15:23:49 -04006591 RValue<Float> Extract(RValue<Float4> x, int i)
John Bauman89401822014-05-06 15:04:28 -04006592 {
6593 return RValue<Float>(Nucleus::createExtractElement(x.value, i));
6594 }
6595
John Bauman19bac1e2014-05-06 15:23:49 -04006596 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006597 {
6598 return RValue<Float4>(Nucleus::createSwizzle(x.value, select));
6599 }
6600
John Bauman19bac1e2014-05-06 15:23:49 -04006601 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006602 {
6603 Constant *shuffle[4];
6604 shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0);
6605 shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0);
6606 shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4);
6607 shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4);
6608
6609 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6610 }
6611
John Bauman19bac1e2014-05-06 15:23:49 -04006612 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006613 {
6614 Constant *shuffle[4];
6615 shuffle[0] = Nucleus::createConstantInt(0);
6616 shuffle[1] = Nucleus::createConstantInt(4);
6617 shuffle[2] = Nucleus::createConstantInt(1);
6618 shuffle[3] = Nucleus::createConstantInt(5);
6619
6620 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6621 }
6622
John Bauman19bac1e2014-05-06 15:23:49 -04006623 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006624 {
6625 Constant *shuffle[4];
6626 shuffle[0] = Nucleus::createConstantInt(2);
6627 shuffle[1] = Nucleus::createConstantInt(6);
6628 shuffle[2] = Nucleus::createConstantInt(3);
6629 shuffle[3] = Nucleus::createConstantInt(7);
6630
6631 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)));
6632 }
John Bauman66b8ab22014-05-06 15:57:45 -04006633
John Bauman19bac1e2014-05-06 15:23:49 -04006634 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
John Bauman89401822014-05-06 15:04:28 -04006635 {
John Bauman66b8ab22014-05-06 15:57:45 -04006636 Value *vector = lhs.loadValue();
John Bauman89401822014-05-06 15:04:28 -04006637 Value *shuffle = Nucleus::createMask(vector, rhs.value, select);
John Bauman66b8ab22014-05-06 15:57:45 -04006638 lhs.storeValue(shuffle);
John Bauman89401822014-05-06 15:04:28 -04006639
6640 return RValue<Float4>(shuffle);
6641 }
6642
John Bauman19bac1e2014-05-06 15:23:49 -04006643 RValue<Int> SignMask(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006644 {
6645 return x86::movmskps(x);
6646 }
6647
John Bauman19bac1e2014-05-06 15:23:49 -04006648 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006649 {
6650 // return As<Int4>(x86::cmpeqps(x, y));
6651 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
6652 }
6653
John Bauman19bac1e2014-05-06 15:23:49 -04006654 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006655 {
6656 // return As<Int4>(x86::cmpltps(x, y));
6657 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
6658 }
6659
John Bauman19bac1e2014-05-06 15:23:49 -04006660 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006661 {
6662 // return As<Int4>(x86::cmpleps(x, y));
6663 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
6664 }
6665
John Bauman19bac1e2014-05-06 15:23:49 -04006666 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006667 {
6668 // return As<Int4>(x86::cmpneqps(x, y));
6669 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
6670 }
6671
John Bauman19bac1e2014-05-06 15:23:49 -04006672 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006673 {
6674 // return As<Int4>(x86::cmpnltps(x, y));
6675 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
6676 }
6677
John Bauman19bac1e2014-05-06 15:23:49 -04006678 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006679 {
6680 // return As<Int4>(x86::cmpnleps(x, y));
6681 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
6682 }
6683
John Bauman19bac1e2014-05-06 15:23:49 -04006684 RValue<Float4> Round(RValue<Float4> x)
6685 {
6686 if(CPUID::supportsSSE4_1())
6687 {
6688 return x86::roundps(x, 0);
6689 }
6690 else
6691 {
6692 return Float4(RoundInt(x));
6693 }
6694 }
6695
6696 RValue<Float4> Trunc(RValue<Float4> x)
6697 {
6698 if(CPUID::supportsSSE4_1())
6699 {
6700 return x86::roundps(x, 3);
6701 }
6702 else
6703 {
6704 return Float4(Int4(x)); // Rounded toward zero
6705 }
6706 }
6707
6708 RValue<Float4> Frac(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006709 {
6710 if(CPUID::supportsSSE4_1())
6711 {
6712 return x - x86::floorps(x);
6713 }
6714 else
6715 {
John Bauman19bac1e2014-05-06 15:23:49 -04006716 Float4 frc = x - Float4(Int4(x)); // Signed fractional part
John Bauman89401822014-05-06 15:04:28 -04006717
John Bauman19bac1e2014-05-06 15:23:49 -04006718 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 -04006719 }
6720 }
6721
John Bauman19bac1e2014-05-06 15:23:49 -04006722 RValue<Float4> Floor(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006723 {
6724 if(CPUID::supportsSSE4_1())
6725 {
6726 return x86::floorps(x);
6727 }
6728 else
6729 {
John Bauman19bac1e2014-05-06 15:23:49 -04006730 return x - Frac(x);
John Bauman89401822014-05-06 15:04:28 -04006731 }
6732 }
6733
John Bauman19bac1e2014-05-06 15:23:49 -04006734 RValue<Float4> Ceil(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04006735 {
John Bauman19bac1e2014-05-06 15:23:49 -04006736 if(CPUID::supportsSSE4_1())
6737 {
6738 return x86::ceilps(x);
6739 }
6740 else
6741 {
6742 return -Floor(-x);
6743 }
John Bauman89401822014-05-06 15:04:28 -04006744 }
6745
John Bauman19bac1e2014-05-06 15:23:49 -04006746 Type *Float4::getType()
John Bauman89401822014-05-06 15:04:28 -04006747 {
6748 return VectorType::get(Float::getType(), 4);
6749 }
6750
John Bauman66b8ab22014-05-06 15:57:45 -04006751 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int 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, Nucleus::createConstantInt(offset)));
John Bauman89401822014-05-06 15:04:28 -04006754 }
6755
John Bauman66b8ab22014-05-06 15:57:45 -04006756 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006757 {
John Bauman66b8ab22014-05-06 15:57:45 -04006758 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006759 }
6760
John Bauman66b8ab22014-05-06 15:57:45 -04006761 RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006762 {
John Bauman66b8ab22014-05-06 15:57:45 -04006763 return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
John Bauman89401822014-05-06 15:04:28 -04006764 }
6765
John Bauman66b8ab22014-05-06 15:57:45 -04006766 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int 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+=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006772 {
6773 return lhs = lhs + offset;
6774 }
6775
John Bauman66b8ab22014-05-06 15:57:45 -04006776 RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006777 {
6778 return lhs = lhs + offset;
6779 }
6780
John Bauman66b8ab22014-05-06 15:57:45 -04006781 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int 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-(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006787 {
6788 return lhs + -offset;
6789 }
6790
John Bauman66b8ab22014-05-06 15:57:45 -04006791 RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006792 {
6793 return lhs + -offset;
6794 }
6795
John Bauman66b8ab22014-05-06 15:57:45 -04006796 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset)
John Bauman89401822014-05-06 15:04:28 -04006797 {
6798 return lhs = lhs - offset;
6799 }
6800
John Bauman66b8ab22014-05-06 15:57:45 -04006801 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
John Bauman89401822014-05-06 15:04:28 -04006802 {
6803 return lhs = lhs - offset;
6804 }
6805
John Bauman66b8ab22014-05-06 15:57:45 -04006806 RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
John Bauman89401822014-05-06 15:04:28 -04006807 {
6808 return lhs = lhs - offset;
6809 }
6810
6811 void Return()
6812 {
John Bauman89401822014-05-06 15:04:28 -04006813 Nucleus::createRetVoid();
6814 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006815 Nucleus::createUnreachable();
6816 }
6817
6818 void Return(bool ret)
6819 {
John Bauman19bac1e2014-05-06 15:23:49 -04006820 Nucleus::createRet(Nucleus::createConstantBool(ret));
6821 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6822 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006823 }
6824
6825 void Return(const Int &ret)
6826 {
John Bauman66b8ab22014-05-06 15:57:45 -04006827 Nucleus::createRet(ret.loadValue());
John Bauman89401822014-05-06 15:04:28 -04006828 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
John Bauman19bac1e2014-05-06 15:23:49 -04006829 Nucleus::createUnreachable();
John Bauman89401822014-05-06 15:04:28 -04006830 }
6831
6832 BasicBlock *beginLoop()
6833 {
6834 BasicBlock *loopBB = Nucleus::createBasicBlock();
6835
6836 Nucleus::createBr(loopBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006837 Nucleus::setInsertBlock(loopBB);
John Bauman89401822014-05-06 15:04:28 -04006838
6839 return loopBB;
6840 }
6841
John Bauman19bac1e2014-05-06 15:23:49 -04006842 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
John Bauman89401822014-05-06 15:04:28 -04006843 {
6844 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
John Bauman66b8ab22014-05-06 15:57:45 -04006845 Nucleus::setInsertBlock(bodyBB);
6846
John Bauman89401822014-05-06 15:04:28 -04006847 return true;
6848 }
6849
6850 bool elseBlock(BasicBlock *falseBB)
6851 {
6852 falseBB->back().eraseFromParent();
John Bauman66b8ab22014-05-06 15:57:45 -04006853 Nucleus::setInsertBlock(falseBB);
John Bauman89401822014-05-06 15:04:28 -04006854
6855 return true;
6856 }
6857
6858 RValue<Long> Ticks()
6859 {
6860 Module *module = Nucleus::getModule();
6861 llvm::Function *rdtsc = Intrinsic::getDeclaration(module, Intrinsic::readcyclecounter);
6862
6863 return RValue<Long>(Nucleus::createCall(rdtsc));
6864 }
John Bauman89401822014-05-06 15:04:28 -04006865}
6866
6867namespace sw
6868{
6869 namespace x86
6870 {
John Bauman19bac1e2014-05-06 15:23:49 -04006871 RValue<Int> cvtss2si(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006872 {
6873 Module *module = Nucleus::getModule();
6874 llvm::Function *cvtss2si = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtss2si);
John Bauman66b8ab22014-05-06 15:57:45 -04006875
John Bauman89401822014-05-06 15:04:28 -04006876 Float4 vector;
6877 vector.x = val;
6878
6879 return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value));
6880 }
6881
John Bauman19bac1e2014-05-06 15:23:49 -04006882 RValue<Int2> cvtps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006883 {
6884 Module *module = Nucleus::getModule();
6885 llvm::Function *cvtps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtps2pi);
6886
6887 return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value));
6888 }
6889
John Bauman19bac1e2014-05-06 15:23:49 -04006890 RValue<Int2> cvttps2pi(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006891 {
6892 Module *module = Nucleus::getModule();
6893 llvm::Function *cvttps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvttps2pi);
6894
6895 return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value));
6896 }
6897
John Bauman19bac1e2014-05-06 15:23:49 -04006898 RValue<Int4> cvtps2dq(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006899 {
6900 if(CPUID::supportsSSE2())
6901 {
6902 Module *module = Nucleus::getModule();
6903 llvm::Function *cvtps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtps2dq);
6904
6905 return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value));
6906 }
6907 else
6908 {
6909 Int2 lo = x86::cvtps2pi(val);
6910 Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04006911
John Bauman89401822014-05-06 15:04:28 -04006912 return Concatenate(lo, hi);
6913 }
6914 }
6915
John Bauman19bac1e2014-05-06 15:23:49 -04006916 RValue<Float> rcpss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006917 {
6918 Module *module = Nucleus::getModule();
6919 llvm::Function *rcpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_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(rcpss, vector), 0));
6924 }
6925
John Bauman19bac1e2014-05-06 15:23:49 -04006926 RValue<Float> sqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006927 {
6928 Module *module = Nucleus::getModule();
6929 llvm::Function *sqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ss);
6930
6931 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
John Bauman66b8ab22014-05-06 15:57:45 -04006932
John Bauman89401822014-05-06 15:04:28 -04006933 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0));
6934 }
6935
John Bauman19bac1e2014-05-06 15:23:49 -04006936 RValue<Float> rsqrtss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006937 {
6938 Module *module = Nucleus::getModule();
6939 llvm::Function *rsqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ss);
John Bauman66b8ab22014-05-06 15:57:45 -04006940
John Bauman89401822014-05-06 15:04:28 -04006941 Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0);
6942
6943 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0));
6944 }
6945
John Bauman19bac1e2014-05-06 15:23:49 -04006946 RValue<Float4> rcpps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006947 {
6948 Module *module = Nucleus::getModule();
6949 llvm::Function *rcpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006950
John Bauman89401822014-05-06 15:04:28 -04006951 return RValue<Float4>(Nucleus::createCall(rcpps, val.value));
6952 }
6953
John Bauman19bac1e2014-05-06 15:23:49 -04006954 RValue<Float4> sqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006955 {
6956 Module *module = Nucleus::getModule();
6957 llvm::Function *sqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006958
John Bauman89401822014-05-06 15:04:28 -04006959 return RValue<Float4>(Nucleus::createCall(sqrtps, val.value));
6960 }
6961
John Bauman19bac1e2014-05-06 15:23:49 -04006962 RValue<Float4> rsqrtps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04006963 {
6964 Module *module = Nucleus::getModule();
6965 llvm::Function *rsqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ps);
John Bauman66b8ab22014-05-06 15:57:45 -04006966
John Bauman89401822014-05-06 15:04:28 -04006967 return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value));
6968 }
6969
John Bauman19bac1e2014-05-06 15:23:49 -04006970 RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006971 {
6972 Module *module = Nucleus::getModule();
6973 llvm::Function *maxps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_max_ps);
6974
6975 return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value));
6976 }
6977
John Bauman19bac1e2014-05-06 15:23:49 -04006978 RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04006979 {
6980 Module *module = Nucleus::getModule();
6981 llvm::Function *minps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_min_ps);
6982
6983 return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value));
6984 }
6985
John Bauman19bac1e2014-05-06 15:23:49 -04006986 RValue<Float> roundss(RValue<Float> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04006987 {
6988 Module *module = Nucleus::getModule();
6989 llvm::Function *roundss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ss);
6990
6991 Value *undef = UndefValue::get(Float4::getType());
6992 Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
6993
6994 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0));
6995 }
6996
John Bauman19bac1e2014-05-06 15:23:49 -04006997 RValue<Float> floorss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04006998 {
6999 return roundss(val, 1);
7000 }
7001
John Bauman19bac1e2014-05-06 15:23:49 -04007002 RValue<Float> ceilss(RValue<Float> val)
John Bauman89401822014-05-06 15:04:28 -04007003 {
7004 return roundss(val, 2);
7005 }
7006
John Bauman19bac1e2014-05-06 15:23:49 -04007007 RValue<Float4> roundps(RValue<Float4> val, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007008 {
7009 Module *module = Nucleus::getModule();
7010 llvm::Function *roundps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ps);
7011
7012 return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm)));
7013 }
7014
John Bauman19bac1e2014-05-06 15:23:49 -04007015 RValue<Float4> floorps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007016 {
7017 return roundps(val, 1);
7018 }
7019
John Bauman19bac1e2014-05-06 15:23:49 -04007020 RValue<Float4> ceilps(RValue<Float4> val)
John Bauman89401822014-05-06 15:04:28 -04007021 {
7022 return roundps(val, 2);
7023 }
7024
John Bauman19bac1e2014-05-06 15:23:49 -04007025 RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007026 {
7027 Module *module = Nucleus::getModule();
7028 llvm::Function *cmpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ps);
7029
7030 return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm)));
7031 }
7032
John Bauman19bac1e2014-05-06 15:23:49 -04007033 RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007034 {
7035 return cmpps(x, y, 0);
7036 }
7037
John Bauman19bac1e2014-05-06 15:23:49 -04007038 RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007039 {
7040 return cmpps(x, y, 1);
7041 }
7042
John Bauman19bac1e2014-05-06 15:23:49 -04007043 RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007044 {
7045 return cmpps(x, y, 2);
7046 }
7047
John Bauman19bac1e2014-05-06 15:23:49 -04007048 RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007049 {
7050 return cmpps(x, y, 3);
7051 }
7052
John Bauman19bac1e2014-05-06 15:23:49 -04007053 RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007054 {
7055 return cmpps(x, y, 4);
7056 }
7057
John Bauman19bac1e2014-05-06 15:23:49 -04007058 RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007059 {
7060 return cmpps(x, y, 5);
7061 }
7062
John Bauman19bac1e2014-05-06 15:23:49 -04007063 RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007064 {
7065 return cmpps(x, y, 6);
7066 }
7067
John Bauman19bac1e2014-05-06 15:23:49 -04007068 RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y)
John Bauman89401822014-05-06 15:04:28 -04007069 {
7070 return cmpps(x, y, 7);
7071 }
7072
John Bauman19bac1e2014-05-06 15:23:49 -04007073 RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm)
John Bauman89401822014-05-06 15:04:28 -04007074 {
7075 Module *module = Nucleus::getModule();
7076 llvm::Function *cmpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ss);
7077
7078 Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0);
7079 Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0);
7080
7081 return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0));
7082 }
7083
John Bauman19bac1e2014-05-06 15:23:49 -04007084 RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007085 {
7086 return cmpss(x, y, 0);
7087 }
7088
John Bauman19bac1e2014-05-06 15:23:49 -04007089 RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007090 {
7091 return cmpss(x, y, 1);
7092 }
7093
John Bauman19bac1e2014-05-06 15:23:49 -04007094 RValue<Float> cmpless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007095 {
7096 return cmpss(x, y, 2);
7097 }
7098
John Bauman19bac1e2014-05-06 15:23:49 -04007099 RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007100 {
7101 return cmpss(x, y, 3);
7102 }
7103
John Bauman19bac1e2014-05-06 15:23:49 -04007104 RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007105 {
7106 return cmpss(x, y, 4);
7107 }
7108
John Bauman19bac1e2014-05-06 15:23:49 -04007109 RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007110 {
7111 return cmpss(x, y, 5);
7112 }
7113
John Bauman19bac1e2014-05-06 15:23:49 -04007114 RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007115 {
7116 return cmpss(x, y, 6);
7117 }
7118
John Bauman19bac1e2014-05-06 15:23:49 -04007119 RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y)
John Bauman89401822014-05-06 15:04:28 -04007120 {
7121 return cmpss(x, y, 7);
7122 }
7123
John Bauman19bac1e2014-05-06 15:23:49 -04007124 RValue<Int4> pabsd(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007125 {
7126 Module *module = Nucleus::getModule();
7127 llvm::Function *pabsd = Intrinsic::getDeclaration(module, Intrinsic::x86_ssse3_pabs_d_128);
7128
7129 return RValue<Int4>(Nucleus::createCall(pabsd, x.value, y.value));
7130 }
7131
John Bauman19bac1e2014-05-06 15:23:49 -04007132 RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007133 {
7134 Module *module = Nucleus::getModule();
7135 llvm::Function *paddsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_w);
7136
John Bauman19bac1e2014-05-06 15:23:49 -04007137 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007138 }
John Bauman66b8ab22014-05-06 15:57:45 -04007139
John Bauman19bac1e2014-05-06 15:23:49 -04007140 RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007141 {
7142 Module *module = Nucleus::getModule();
7143 llvm::Function *psubsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_w);
7144
John Bauman19bac1e2014-05-06 15:23:49 -04007145 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007146 }
7147
John Bauman19bac1e2014-05-06 15:23:49 -04007148 RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007149 {
7150 Module *module = Nucleus::getModule();
7151 llvm::Function *paddusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_w);
7152
John Bauman19bac1e2014-05-06 15:23:49 -04007153 return As<UShort4>(RValue<MMX>(Nucleus::createCall(paddusw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007154 }
John Bauman66b8ab22014-05-06 15:57:45 -04007155
John Bauman19bac1e2014-05-06 15:23:49 -04007156 RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007157 {
7158 Module *module = Nucleus::getModule();
7159 llvm::Function *psubusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_w);
7160
John Bauman19bac1e2014-05-06 15:23:49 -04007161 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psubusw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007162 }
7163
John Bauman19bac1e2014-05-06 15:23:49 -04007164 RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007165 {
7166 Module *module = Nucleus::getModule();
7167 llvm::Function *paddsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_b);
7168
John Bauman19bac1e2014-05-06 15:23:49 -04007169 return As<SByte8>(RValue<MMX>(Nucleus::createCall(paddsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007170 }
John Bauman66b8ab22014-05-06 15:57:45 -04007171
John Bauman19bac1e2014-05-06 15:23:49 -04007172 RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007173 {
7174 Module *module = Nucleus::getModule();
7175 llvm::Function *psubsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_b);
7176
John Bauman19bac1e2014-05-06 15:23:49 -04007177 return As<SByte8>(RValue<MMX>(Nucleus::createCall(psubsb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007178 }
John Bauman66b8ab22014-05-06 15:57:45 -04007179
John Bauman19bac1e2014-05-06 15:23:49 -04007180 RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007181 {
7182 Module *module = Nucleus::getModule();
7183 llvm::Function *paddusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_b);
7184
John Bauman19bac1e2014-05-06 15:23:49 -04007185 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007186 }
John Bauman66b8ab22014-05-06 15:57:45 -04007187
John Bauman19bac1e2014-05-06 15:23:49 -04007188 RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007189 {
7190 Module *module = Nucleus::getModule();
7191 llvm::Function *psubusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_b);
7192
John Bauman19bac1e2014-05-06 15:23:49 -04007193 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubusb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007194 }
7195
John Bauman19bac1e2014-05-06 15:23:49 -04007196 RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y)
7197 {
7198 Module *module = Nucleus::getModule();
7199 llvm::Function *paddw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_w);
7200
7201 return As<Short4>(RValue<MMX>(Nucleus::createCall(paddw, As<MMX>(x).value, As<MMX>(y).value)));
7202 }
7203
7204 RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y)
7205 {
7206 Module *module = Nucleus::getModule();
7207 llvm::Function *psubw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_w);
7208
7209 return As<Short4>(RValue<MMX>(Nucleus::createCall(psubw, As<MMX>(x).value, As<MMX>(y).value)));
7210 }
7211
7212 RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y)
7213 {
7214 Module *module = Nucleus::getModule();
7215 llvm::Function *pmullw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmull_w);
7216
7217 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmullw, As<MMX>(x).value, As<MMX>(y).value)));
7218 }
7219
7220 RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y)
7221 {
7222 Module *module = Nucleus::getModule();
7223 llvm::Function *pand = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pand);
7224
7225 return As<Short4>(RValue<MMX>(Nucleus::createCall(pand, As<MMX>(x).value, As<MMX>(y).value)));
7226 }
7227
7228 RValue<Short4> por(RValue<Short4> x, RValue<Short4> y)
7229 {
7230 Module *module = Nucleus::getModule();
7231 llvm::Function *por = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_por);
7232
7233 return As<Short4>(RValue<MMX>(Nucleus::createCall(por, As<MMX>(x).value, As<MMX>(y).value)));
7234 }
7235
7236 RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y)
7237 {
7238 Module *module = Nucleus::getModule();
7239 llvm::Function *pxor = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pxor);
7240
7241 return As<Short4>(RValue<MMX>(Nucleus::createCall(pxor, As<MMX>(x).value, As<MMX>(y).value)));
7242 }
7243
7244 RValue<Short4> pshufw(RValue<Short4> x, unsigned char y)
7245 {
7246 Module *module = Nucleus::getModule();
7247 llvm::Function *pshufw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_pshuf_w);
7248
7249 return As<Short4>(RValue<MMX>(Nucleus::createCall(pshufw, As<MMX>(x).value, Nucleus::createConstantByte(y))));
7250 }
7251
7252 RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y)
7253 {
7254 Module *module = Nucleus::getModule();
7255 llvm::Function *punpcklwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklwd);
7256
7257 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpcklwd, As<MMX>(x).value, As<MMX>(y).value)));
7258 }
7259
7260 RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y)
7261 {
7262 Module *module = Nucleus::getModule();
7263 llvm::Function *punpckhwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhwd);
7264
7265 return As<Int2>(RValue<MMX>(Nucleus::createCall(punpckhwd, As<MMX>(x).value, As<MMX>(y).value)));
7266 }
7267
7268 RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i)
7269 {
7270 Module *module = Nucleus::getModule();
7271 llvm::Function *pinsrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pinsr_w);
7272
7273 return As<Short4>(RValue<MMX>(Nucleus::createCall(pinsrw, As<MMX>(x).value, y.value, Nucleus::createConstantInt(i))));
7274 }
7275
7276 RValue<Int> pextrw(RValue<Short4> x, unsigned int i)
7277 {
7278 Module *module = Nucleus::getModule();
7279 llvm::Function *pextrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pextr_w);
7280
7281 return RValue<Int>(Nucleus::createCall(pextrw, As<MMX>(x).value, Nucleus::createConstantInt(i)));
7282 }
7283
7284 RValue<Long1> punpckldq(RValue<Int2> x, RValue<Int2> y)
7285 {
7286 Module *module = Nucleus::getModule();
7287 llvm::Function *punpckldq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckldq);
7288
7289 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckldq, As<MMX>(x).value, As<MMX>(y).value)));
7290 }
7291
7292 RValue<Long1> punpckhdq(RValue<Int2> x, RValue<Int2> y)
7293 {
7294 Module *module = Nucleus::getModule();
7295 llvm::Function *punpckhdq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhdq);
7296
7297 return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckhdq, As<MMX>(x).value, As<MMX>(y).value)));
7298 }
7299
7300 RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y)
7301 {
7302 Module *module = Nucleus::getModule();
7303 llvm::Function *punpcklbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklbw);
7304
7305 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpcklbw, As<MMX>(x).value, As<MMX>(y).value)));
7306 }
7307
7308 RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y)
7309 {
7310 Module *module = Nucleus::getModule();
7311 llvm::Function *punpckhbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhbw);
7312
7313 return As<Short4>(RValue<MMX>(Nucleus::createCall(punpckhbw, As<MMX>(x).value, As<MMX>(y).value)));
7314 }
7315
7316 RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y)
7317 {
7318 Module *module = Nucleus::getModule();
7319 llvm::Function *paddb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_b);
7320
7321 return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddb, As<MMX>(x).value, As<MMX>(y).value)));
7322 }
7323
7324 RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y)
7325 {
7326 Module *module = Nucleus::getModule();
7327 llvm::Function *psubb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_b);
7328
7329 return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubb, As<MMX>(x).value, As<MMX>(y).value)));
7330 }
7331
7332 RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y)
7333 {
7334 Module *module = Nucleus::getModule();
7335 llvm::Function *paddd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_d);
7336
7337 return As<Int2>(RValue<MMX>(Nucleus::createCall(paddd, As<MMX>(x).value, As<MMX>(y).value)));
7338 }
7339
7340 RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y)
7341 {
7342 Module *module = Nucleus::getModule();
7343 llvm::Function *psubd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_d);
7344
7345 return As<Int2>(RValue<MMX>(Nucleus::createCall(psubd, As<MMX>(x).value, As<MMX>(y).value)));
7346 }
7347
7348 RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007349 {
7350 Module *module = Nucleus::getModule();
7351 llvm::Function *pavgw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pavg_w);
7352
John Bauman19bac1e2014-05-06 15:23:49 -04007353 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pavgw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007354 }
7355
John Bauman19bac1e2014-05-06 15:23:49 -04007356 RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007357 {
7358 Module *module = Nucleus::getModule();
7359 llvm::Function *pmaxsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmaxs_w);
7360
John Bauman19bac1e2014-05-06 15:23:49 -04007361 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmaxsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007362 }
7363
John Bauman19bac1e2014-05-06 15:23:49 -04007364 RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007365 {
7366 Module *module = Nucleus::getModule();
7367 llvm::Function *pminsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmins_w);
7368
John Bauman19bac1e2014-05-06 15:23:49 -04007369 return As<Short4>(RValue<MMX>(Nucleus::createCall(pminsw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007370 }
7371
John Bauman19bac1e2014-05-06 15:23:49 -04007372 RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007373 {
7374 Module *module = Nucleus::getModule();
7375 llvm::Function *pcmpgtw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_w);
7376
John Bauman19bac1e2014-05-06 15:23:49 -04007377 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpgtw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007378 }
7379
John Bauman19bac1e2014-05-06 15:23:49 -04007380 RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007381 {
7382 Module *module = Nucleus::getModule();
7383 llvm::Function *pcmpeqw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_w);
7384
John Bauman19bac1e2014-05-06 15:23:49 -04007385 return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpeqw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007386 }
7387
John Bauman19bac1e2014-05-06 15:23:49 -04007388 RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y)
John Bauman89401822014-05-06 15:04:28 -04007389 {
7390 Module *module = Nucleus::getModule();
7391 llvm::Function *pcmpgtb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_b);
7392
John Bauman19bac1e2014-05-06 15:23:49 -04007393 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpgtb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007394 }
7395
John Bauman19bac1e2014-05-06 15:23:49 -04007396 RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y)
John Bauman89401822014-05-06 15:04:28 -04007397 {
7398 Module *module = Nucleus::getModule();
7399 llvm::Function *pcmpeqb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_b);
7400
John Bauman19bac1e2014-05-06 15:23:49 -04007401 return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpeqb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007402 }
7403
John Bauman19bac1e2014-05-06 15:23:49 -04007404 RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y)
John Bauman89401822014-05-06 15:04:28 -04007405 {
7406 Module *module = Nucleus::getModule();
7407 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packssdw);
7408
John Bauman19bac1e2014-05-06 15:23:49 -04007409 return As<Short4>(RValue<MMX>(Nucleus::createCall(packssdw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007410 }
7411
John Bauman19bac1e2014-05-06 15:23:49 -04007412 RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y)
John Bauman89401822014-05-06 15:04:28 -04007413 {
7414 if(CPUID::supportsSSE2())
7415 {
7416 Module *module = Nucleus::getModule();
7417 llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_packssdw_128);
7418
7419 return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value));
7420 }
7421 else
7422 {
7423 Int2 loX = Int2(x);
7424 Int2 hiX = Int2(Swizzle(x, 0xEE));
7425
7426 Int2 loY = Int2(y);
7427 Int2 hiY = Int2(Swizzle(y, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007428
John Bauman89401822014-05-06 15:04:28 -04007429 Short4 lo = x86::packssdw(loX, hiX);
7430 Short4 hi = x86::packssdw(loY, hiY);
John Bauman66b8ab22014-05-06 15:57:45 -04007431
John Bauman89401822014-05-06 15:04:28 -04007432 return Concatenate(lo, hi);
7433 }
7434 }
7435
John Bauman19bac1e2014-05-06 15:23:49 -04007436 RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007437 {
7438 Module *module = Nucleus::getModule();
7439 llvm::Function *packsswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packsswb);
7440
John Bauman19bac1e2014-05-06 15:23:49 -04007441 return As<SByte8>(RValue<MMX>(Nucleus::createCall(packsswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007442 }
7443
John Bauman19bac1e2014-05-06 15:23:49 -04007444 RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007445 {
7446 Module *module = Nucleus::getModule();
7447 llvm::Function *packuswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packuswb);
7448
John Bauman19bac1e2014-05-06 15:23:49 -04007449 return As<Byte8>(RValue<MMX>(Nucleus::createCall(packuswb, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007450 }
7451
John Bauman19bac1e2014-05-06 15:23:49 -04007452 RValue<UShort8> packusdw(RValue<UInt4> x, RValue<UInt4> y)
John Bauman89401822014-05-06 15:04:28 -04007453 {
7454 if(CPUID::supportsSSE4_1())
7455 {
7456 Module *module = Nucleus::getModule();
7457 llvm::Function *packusdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_packusdw);
John Bauman66b8ab22014-05-06 15:57:45 -04007458
John Bauman89401822014-05-06 15:04:28 -04007459 return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value));
7460 }
7461 else
7462 {
7463 // FIXME: Not an exact replacement!
John Bauman19bac1e2014-05-06 15:23:49 -04007464 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 -04007465 }
7466 }
7467
John Bauman19bac1e2014-05-06 15:23:49 -04007468 RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007469 {
7470 Module *module = Nucleus::getModule();
7471 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_w);
7472
John Bauman19bac1e2014-05-06 15:23:49 -04007473 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007474 }
7475
John Bauman19bac1e2014-05-06 15:23:49 -04007476 RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007477 {
7478 Module *module = Nucleus::getModule();
7479 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_w);
7480
7481 return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y)));
7482 }
7483
John Bauman19bac1e2014-05-06 15:23:49 -04007484 RValue<Short4> psraw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007485 {
7486 Module *module = Nucleus::getModule();
7487 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_w);
7488
John Bauman19bac1e2014-05-06 15:23:49 -04007489 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007490 }
7491
John Bauman19bac1e2014-05-06 15:23:49 -04007492 RValue<Short8> psraw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007493 {
7494 Module *module = Nucleus::getModule();
7495 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_w);
7496
7497 return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y)));
7498 }
7499
John Bauman19bac1e2014-05-06 15:23:49 -04007500 RValue<Short4> psllw(RValue<Short4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007501 {
7502 Module *module = Nucleus::getModule();
7503 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_w);
7504
John Bauman19bac1e2014-05-06 15:23:49 -04007505 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007506 }
7507
John Bauman19bac1e2014-05-06 15:23:49 -04007508 RValue<Short8> psllw(RValue<Short8> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007509 {
7510 Module *module = Nucleus::getModule();
7511 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_w);
7512
7513 return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y)));
7514 }
7515
John Bauman19bac1e2014-05-06 15:23:49 -04007516 RValue<Int2> pslld(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007517 {
7518 Module *module = Nucleus::getModule();
7519 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_d);
7520
John Bauman19bac1e2014-05-06 15:23:49 -04007521 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007522 }
7523
John Bauman19bac1e2014-05-06 15:23:49 -04007524 RValue<Int4> pslld(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007525 {
7526 if(CPUID::supportsSSE2())
7527 {
7528 Module *module = Nucleus::getModule();
7529 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_d);
7530
7531 return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y)));
7532 }
7533 else
7534 {
7535 Int2 lo = Int2(x);
7536 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007537
John Bauman89401822014-05-06 15:04:28 -04007538 lo = x86::pslld(lo, y);
7539 hi = x86::pslld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007540
John Bauman89401822014-05-06 15:04:28 -04007541 return Concatenate(lo, hi);
7542 }
7543 }
7544
John Bauman19bac1e2014-05-06 15:23:49 -04007545 RValue<Int2> psrad(RValue<Int2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007546 {
7547 Module *module = Nucleus::getModule();
7548 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_d);
7549
John Bauman19bac1e2014-05-06 15:23:49 -04007550 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrad, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007551 }
7552
John Bauman19bac1e2014-05-06 15:23:49 -04007553 RValue<Int4> psrad(RValue<Int4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007554 {
7555 if(CPUID::supportsSSE2())
7556 {
7557 Module *module = Nucleus::getModule();
7558 llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_d);
7559
7560 return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y)));
7561 }
7562 else
7563 {
7564 Int2 lo = Int2(x);
7565 Int2 hi = Int2(Swizzle(x, 0xEE));
John Bauman66b8ab22014-05-06 15:57:45 -04007566
John Bauman89401822014-05-06 15:04:28 -04007567 lo = x86::psrad(lo, y);
7568 hi = x86::psrad(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007569
John Bauman89401822014-05-06 15:04:28 -04007570 return Concatenate(lo, hi);
7571 }
7572 }
7573
John Bauman19bac1e2014-05-06 15:23:49 -04007574 RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007575 {
7576 Module *module = Nucleus::getModule();
7577 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_d);
7578
John Bauman19bac1e2014-05-06 15:23:49 -04007579 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, Nucleus::createConstantInt(y))));
John Bauman89401822014-05-06 15:04:28 -04007580 }
7581
John Bauman19bac1e2014-05-06 15:23:49 -04007582 RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y)
John Bauman89401822014-05-06 15:04:28 -04007583 {
7584 if(CPUID::supportsSSE2())
7585 {
7586 Module *module = Nucleus::getModule();
7587 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_d);
7588
7589 return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y)));
7590 }
7591 else
7592 {
7593 UInt2 lo = As<UInt2>(Int2(As<Int4>(x)));
7594 UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE)));
John Bauman66b8ab22014-05-06 15:57:45 -04007595
John Bauman89401822014-05-06 15:04:28 -04007596 lo = x86::psrld(lo, y);
7597 hi = x86::psrld(hi, y);
John Bauman66b8ab22014-05-06 15:57:45 -04007598
John Bauman89401822014-05-06 15:04:28 -04007599 return Concatenate(lo, hi);
7600 }
7601 }
7602
John Bauman19bac1e2014-05-06 15:23:49 -04007603 RValue<UShort4> psrlw(RValue<UShort4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007604 {
7605 Module *module = Nucleus::getModule();
7606 llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_w);
7607
John Bauman19bac1e2014-05-06 15:23:49 -04007608 return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007609 }
7610
John Bauman19bac1e2014-05-06 15:23:49 -04007611 RValue<Short4> psraw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007612 {
7613 Module *module = Nucleus::getModule();
7614 llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_w);
7615
John Bauman19bac1e2014-05-06 15:23:49 -04007616 return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007617 }
7618
John Bauman19bac1e2014-05-06 15:23:49 -04007619 RValue<Short4> psllw(RValue<Short4> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007620 {
7621 Module *module = Nucleus::getModule();
7622 llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_w);
7623
John Bauman19bac1e2014-05-06 15:23:49 -04007624 return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007625 }
7626
John Bauman19bac1e2014-05-06 15:23:49 -04007627 RValue<Int2> pslld(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007628 {
7629 Module *module = Nucleus::getModule();
7630 llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_d);
7631
John Bauman19bac1e2014-05-06 15:23:49 -04007632 return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007633 }
7634
John Bauman19bac1e2014-05-06 15:23:49 -04007635 RValue<UInt2> psrld(RValue<UInt2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007636 {
7637 Module *module = Nucleus::getModule();
7638 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_d);
7639
John Bauman19bac1e2014-05-06 15:23:49 -04007640 return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007641 }
7642
John Bauman19bac1e2014-05-06 15:23:49 -04007643 RValue<Int2> psrad(RValue<Int2> x, RValue<Long1> y)
John Bauman89401822014-05-06 15:04:28 -04007644 {
7645 Module *module = Nucleus::getModule();
7646 llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_d);
7647
John Bauman19bac1e2014-05-06 15:23:49 -04007648 return As<Int2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007649 }
7650
John Bauman19bac1e2014-05-06 15:23:49 -04007651 RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y)
7652 {
7653 Module *module = Nucleus::getModule();
7654 llvm::Function *pmaxsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxsd);
7655
7656 return RValue<Int4>(Nucleus::createCall(pmaxsd, x.value, y.value));
7657 }
7658
7659 RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y)
7660 {
7661 Module *module = Nucleus::getModule();
7662 llvm::Function *pminsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminsd);
7663
7664 return RValue<Int4>(Nucleus::createCall(pminsd, x.value, y.value));
7665 }
7666
7667 RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y)
7668 {
7669 Module *module = Nucleus::getModule();
7670 llvm::Function *pmaxud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxud);
7671
John Bauman66b8ab22014-05-06 15:57:45 -04007672 return RValue<UInt4>(Nucleus::createCall(pmaxud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007673 }
7674
7675 RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y)
7676 {
7677 Module *module = Nucleus::getModule();
7678 llvm::Function *pminud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminud);
7679
John Bauman66b8ab22014-05-06 15:57:45 -04007680 return RValue<UInt4>(Nucleus::createCall(pminud, x.value, y.value));
John Bauman19bac1e2014-05-06 15:23:49 -04007681 }
7682
7683 RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007684 {
7685 Module *module = Nucleus::getModule();
7686 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulh_w);
7687
John Bauman19bac1e2014-05-06 15:23:49 -04007688 return As<Short4>(RValue<MMX>(Nucleus::createCall(pmulhw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007689 }
7690
John Bauman19bac1e2014-05-06 15:23:49 -04007691 RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y)
John Bauman89401822014-05-06 15:04:28 -04007692 {
7693 Module *module = Nucleus::getModule();
7694 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulhu_w);
7695
John Bauman19bac1e2014-05-06 15:23:49 -04007696 return As<UShort4>(RValue<MMX>(Nucleus::createCall(pmulhuw, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007697 }
7698
John Bauman19bac1e2014-05-06 15:23:49 -04007699 RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y)
John Bauman89401822014-05-06 15:04:28 -04007700 {
7701 Module *module = Nucleus::getModule();
7702 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmadd_wd);
7703
John Bauman19bac1e2014-05-06 15:23:49 -04007704 return As<Int2>(RValue<MMX>(Nucleus::createCall(pmaddwd, As<MMX>(x).value, As<MMX>(y).value)));
John Bauman89401822014-05-06 15:04:28 -04007705 }
7706
John Bauman19bac1e2014-05-06 15:23:49 -04007707 RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007708 {
7709 Module *module = Nucleus::getModule();
7710 llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulh_w);
7711
7712 return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value));
7713 }
7714
John Bauman19bac1e2014-05-06 15:23:49 -04007715 RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y)
John Bauman89401822014-05-06 15:04:28 -04007716 {
7717 Module *module = Nucleus::getModule();
7718 llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulhu_w);
7719
7720 return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value));
7721 }
7722
John Bauman19bac1e2014-05-06 15:23:49 -04007723 RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y)
John Bauman89401822014-05-06 15:04:28 -04007724 {
7725 Module *module = Nucleus::getModule();
7726 llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmadd_wd);
7727
7728 return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value));
7729 }
7730
John Bauman19bac1e2014-05-06 15:23:49 -04007731 RValue<Int> movmskps(RValue<Float4> x)
John Bauman89401822014-05-06 15:04:28 -04007732 {
7733 Module *module = Nucleus::getModule();
7734 llvm::Function *movmskps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_movmsk_ps);
7735
7736 return RValue<Int>(Nucleus::createCall(movmskps, x.value));
7737 }
7738
John Bauman19bac1e2014-05-06 15:23:49 -04007739 RValue<Int> pmovmskb(RValue<Byte8> x)
John Bauman89401822014-05-06 15:04:28 -04007740 {
7741 Module *module = Nucleus::getModule();
7742 llvm::Function *pmovmskb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmovmskb);
7743
John Bauman19bac1e2014-05-06 15:23:49 -04007744 return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value));
John Bauman89401822014-05-06 15:04:28 -04007745 }
7746
John Bauman66b8ab22014-05-06 15:57:45 -04007747 //RValue<Int2> movd(RValue<Pointer<Int> > x)
John Bauman89401822014-05-06 15:04:28 -04007748 //{
7749 // Value *element = Nucleus::createLoad(x.value);
7750
7751 //// Value *int2 = UndefValue::get(Int2::getType());
7752 //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0));
7753
7754 // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType());
7755
7756 // return RValue<Int2>(int2);
7757 //}
7758
John Bauman19bac1e2014-05-06 15:23:49 -04007759 //RValue<Int2> movdq2q(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007760 //{
7761 // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType());
7762 // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0));
7763
7764 // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType()));
7765 //}
7766
John Bauman19bac1e2014-05-06 15:23:49 -04007767 RValue<Int4> pmovzxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007768 {
7769 Module *module = Nucleus::getModule();
7770 llvm::Function *pmovzxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007771
John Bauman89401822014-05-06 15:04:28 -04007772 return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType())));
7773 }
7774
John Bauman19bac1e2014-05-06 15:23:49 -04007775 RValue<Int4> pmovsxbd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007776 {
7777 Module *module = Nucleus::getModule();
7778 llvm::Function *pmovsxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxbd);
John Bauman66b8ab22014-05-06 15:57:45 -04007779
John Bauman89401822014-05-06 15:04:28 -04007780 return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType())));
7781 }
7782
John Bauman19bac1e2014-05-06 15:23:49 -04007783 RValue<Int4> pmovzxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007784 {
7785 Module *module = Nucleus::getModule();
7786 llvm::Function *pmovzxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007787
John Bauman89401822014-05-06 15:04:28 -04007788 return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType())));
7789 }
7790
John Bauman19bac1e2014-05-06 15:23:49 -04007791 RValue<Int4> pmovsxwd(RValue<Int4> x)
John Bauman89401822014-05-06 15:04:28 -04007792 {
7793 Module *module = Nucleus::getModule();
7794 llvm::Function *pmovsxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxwd);
John Bauman66b8ab22014-05-06 15:57:45 -04007795
John Bauman89401822014-05-06 15:04:28 -04007796 return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType())));
7797 }
7798
7799 void emms()
7800 {
7801 Module *module = Nucleus::getModule();
7802 llvm::Function *emms = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_emms);
7803
7804 Nucleus::createCall(emms);
7805 }
7806 }
7807}