Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | #include "Nucleus.hpp" |
| 16 | |
| 17 | #include "llvm/Support/IRBuilder.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/GlobalVariable.h" |
| 20 | #include "llvm/Module.h" |
| 21 | #include "llvm/LLVMContext.h" |
| 22 | #include "llvm/Constants.h" |
| 23 | #include "llvm/Intrinsics.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 24 | #include "llvm/PassManager.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 25 | #include "llvm/Analysis/LoopPass.h" |
| 26 | #include "llvm/Transforms/Scalar.h" |
| 27 | #include "llvm/Target/TargetData.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 28 | #include "llvm/Target/TargetOptions.h" |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 29 | #include "llvm/Support/TargetSelect.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 30 | #include "../lib/ExecutionEngine/JIT/JIT.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 31 | |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 32 | #include "Routine.hpp" |
Nicolas Capens | 2fb4110 | 2014-06-26 10:11:50 -0400 | [diff] [blame] | 33 | #include "RoutineManager.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 34 | #include "x86.hpp" |
| 35 | #include "CPUID.hpp" |
| 36 | #include "Thread.hpp" |
| 37 | #include "Memory.hpp" |
| 38 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 39 | #include <xmmintrin.h> |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 40 | #include <fstream> |
| 41 | |
Nicolas Capens | cb12258 | 2014-05-06 23:34:44 -0400 | [diff] [blame] | 42 | #if defined(__x86_64__) && defined(_WIN32) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 43 | extern "C" void X86CompilationCallback() |
| 44 | { |
| 45 | assert(false); // UNIMPLEMENTED |
| 46 | } |
| 47 | #endif |
| 48 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 49 | extern "C" |
| 50 | { |
| 51 | bool (*CodeAnalystInitialize)() = 0; |
| 52 | void (*CodeAnalystCompleteJITLog)() = 0; |
| 53 | bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0; |
| 54 | } |
| 55 | |
| 56 | namespace llvm |
| 57 | { |
| 58 | extern bool JITEmitDebugInfo; |
| 59 | } |
| 60 | |
| 61 | namespace sw |
| 62 | { |
| 63 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 64 | |
| 65 | using namespace llvm; |
| 66 | |
Nicolas Capens | 2fb4110 | 2014-06-26 10:11:50 -0400 | [diff] [blame] | 67 | RoutineManager *Nucleus::routineManager = 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 68 | ExecutionEngine *Nucleus::executionEngine = 0; |
| 69 | Builder *Nucleus::builder = 0; |
| 70 | LLVMContext *Nucleus::context = 0; |
| 71 | Module *Nucleus::module = 0; |
| 72 | llvm::Function *Nucleus::function = 0; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 73 | BackoffLock Nucleus::codegenMutex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 74 | |
| 75 | class Builder : public IRBuilder<> |
| 76 | { |
| 77 | }; |
| 78 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 79 | Nucleus::Nucleus() |
| 80 | { |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 81 | codegenMutex.lock(); // Reactor and LLVM are currently not thread safe |
| 82 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 83 | InitializeNativeTarget(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 84 | JITEmitDebugInfo = false; |
| 85 | |
| 86 | if(!context) |
| 87 | { |
| 88 | context = new LLVMContext(); |
| 89 | } |
| 90 | |
| 91 | module = new Module("", *context); |
Nicolas Capens | 2fb4110 | 2014-06-26 10:11:50 -0400 | [diff] [blame] | 92 | routineManager = new RoutineManager(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 93 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 94 | #if defined(__x86_64__) |
| 95 | const char *architecture = "x86-64"; |
| 96 | #else |
| 97 | const char *architecture = "x86"; |
| 98 | #endif |
| 99 | |
| 100 | SmallVector<std::string, 1> MAttrs; |
| 101 | MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx"); |
| 102 | MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov"); |
| 103 | MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse"); |
| 104 | MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2"); |
| 105 | MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3"); |
| 106 | MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3"); |
| 107 | MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41"); |
| 108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 109 | std::string error; |
| 110 | TargetMachine *targetMachine = EngineBuilder::selectTarget(module, architecture, "", MAttrs, Reloc::Default, CodeModel::JITDefault, &error); |
Nicolas Capens | 2fb4110 | 2014-06-26 10:11:50 -0400 | [diff] [blame] | 111 | executionEngine = JIT::createJIT(module, 0, routineManager, CodeGenOpt::Aggressive, true, targetMachine); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 112 | |
| 113 | if(!builder) |
| 114 | { |
| 115 | builder = static_cast<Builder*>(new IRBuilder<>(*context)); |
| 116 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 117 | #if defined(_WIN32) |
| 118 | HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll"); |
| 119 | if(CodeAnalyst) |
| 120 | { |
| 121 | CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize"); |
| 122 | CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog"); |
| 123 | CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode"); |
| 124 | |
| 125 | CodeAnalystInitialize(); |
| 126 | } |
| 127 | #endif |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | Nucleus::~Nucleus() |
| 132 | { |
| 133 | delete executionEngine; |
| 134 | executionEngine = 0; |
| 135 | |
Nicolas Capens | 2fb4110 | 2014-06-26 10:11:50 -0400 | [diff] [blame] | 136 | routineManager = 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 137 | function = 0; |
| 138 | module = 0; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 139 | |
| 140 | codegenMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 144 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 145 | if(builder->GetInsertBlock()->empty() || !builder->GetInsertBlock()->back().isTerminator()) |
| 146 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 147 | Type *type = function->getReturnType(); |
| 148 | |
| 149 | if(type->isVoidTy()) |
| 150 | { |
| 151 | createRetVoid(); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | createRet(UndefValue::get(type)); |
| 156 | } |
| 157 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 158 | |
| 159 | if(false) |
| 160 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 161 | std::string error; |
| 162 | raw_fd_ostream file("llvm-dump-unopt.txt", error); |
| 163 | module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | if(runOptimizations) |
| 167 | { |
| 168 | optimize(); |
| 169 | } |
| 170 | |
| 171 | if(false) |
| 172 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 173 | std::string error; |
| 174 | raw_fd_ostream file("llvm-dump-opt.txt", error); |
| 175 | module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void *entry = executionEngine->getPointerToFunction(function); |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 179 | Routine *routine = routineManager->acquireRoutine(entry); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 180 | |
| 181 | if(CodeAnalystLogJITCode) |
| 182 | { |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 183 | CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | return routine; |
| 187 | } |
| 188 | |
| 189 | void Nucleus::optimize() |
| 190 | { |
| 191 | static PassManager *passManager = 0; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 192 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 193 | if(!passManager) |
| 194 | { |
| 195 | passManager = new PassManager(); |
| 196 | |
| 197 | UnsafeFPMath = true; |
| 198 | // NoInfsFPMath = true; |
| 199 | // NoNaNsFPMath = true; |
| 200 | |
| 201 | passManager->add(new TargetData(*executionEngine->getTargetData())); |
| 202 | passManager->add(createScalarReplAggregatesPass()); |
| 203 | |
| 204 | for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++) |
| 205 | { |
| 206 | switch(optimization[pass]) |
| 207 | { |
| 208 | case Disabled: break; |
| 209 | case CFGSimplification: passManager->add(createCFGSimplificationPass()); break; |
| 210 | case LICM: passManager->add(createLICMPass()); break; |
| 211 | case AggressiveDCE: passManager->add(createAggressiveDCEPass()); break; |
| 212 | case GVN: passManager->add(createGVNPass()); break; |
| 213 | case InstructionCombining: passManager->add(createInstructionCombiningPass()); break; |
| 214 | case Reassociate: passManager->add(createReassociatePass()); break; |
| 215 | case DeadStoreElimination: passManager->add(createDeadStoreEliminationPass()); break; |
| 216 | case SCCP: passManager->add(createSCCPPass()); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 217 | case ScalarReplAggregates: passManager->add(createScalarReplAggregatesPass()); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 218 | default: |
| 219 | assert(false); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | passManager->run(*module); |
| 225 | } |
| 226 | |
| 227 | void Nucleus::setFunction(llvm::Function *function) |
| 228 | { |
| 229 | Nucleus::function = function; |
| 230 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 231 | builder->SetInsertPoint(BasicBlock::Create(*context, "", function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | Module *Nucleus::getModule() |
| 235 | { |
| 236 | return module; |
| 237 | } |
| 238 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 239 | llvm::Function *Nucleus::getFunction() |
| 240 | { |
| 241 | return function; |
| 242 | } |
| 243 | |
| 244 | llvm::LLVMContext *Nucleus::getContext() |
| 245 | { |
| 246 | return context; |
| 247 | } |
| 248 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 249 | Value *Nucleus::allocateStackVariable(Type *type, int arraySize) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 250 | { |
| 251 | // Need to allocate it in the entry block for mem2reg to work |
| 252 | llvm::Function *function = getFunction(); |
| 253 | BasicBlock &entryBlock = function->getEntryBlock(); |
| 254 | |
| 255 | Instruction *declaration; |
| 256 | |
| 257 | if(arraySize) |
| 258 | { |
| 259 | declaration = new AllocaInst(type, Nucleus::createConstantInt(arraySize)); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | declaration = new AllocaInst(type, (Value*)0); |
| 264 | } |
| 265 | |
| 266 | entryBlock.getInstList().push_front(declaration); |
| 267 | |
| 268 | return declaration; |
| 269 | } |
| 270 | |
| 271 | BasicBlock *Nucleus::createBasicBlock() |
| 272 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 273 | return BasicBlock::Create(*context, "", Nucleus::getFunction()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | BasicBlock *Nucleus::getInsertBlock() |
| 277 | { |
| 278 | return builder->GetInsertBlock(); |
| 279 | } |
| 280 | |
| 281 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 282 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 283 | // assert(builder->GetInsertBlock()->back().isTerminator()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 284 | return builder->SetInsertPoint(basicBlock); |
| 285 | } |
| 286 | |
| 287 | BasicBlock *Nucleus::getPredecessor(BasicBlock *basicBlock) |
| 288 | { |
| 289 | return *pred_begin(basicBlock); |
| 290 | } |
| 291 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 292 | llvm::Function *Nucleus::createFunction(llvm::Type *ReturnType, std::vector<llvm::Type*> &Params) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 293 | { |
| 294 | llvm::FunctionType *functionType = llvm::FunctionType::get(ReturnType, Params, false); |
| 295 | llvm::Function *function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", Nucleus::getModule()); |
| 296 | function->setCallingConv(llvm::CallingConv::C); |
| 297 | |
| 298 | return function; |
| 299 | } |
| 300 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 301 | llvm::Value *Nucleus::getArgument(llvm::Function *function, unsigned int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 302 | { |
| 303 | llvm::Function::arg_iterator args = function->arg_begin(); |
| 304 | |
| 305 | while(index) |
| 306 | { |
| 307 | args++; |
| 308 | index--; |
| 309 | } |
| 310 | |
| 311 | return &*args; |
| 312 | } |
| 313 | |
| 314 | Value *Nucleus::createRetVoid() |
| 315 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 316 | x86::emms(); |
| 317 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 318 | return builder->CreateRetVoid(); |
| 319 | } |
| 320 | |
| 321 | Value *Nucleus::createRet(Value *V) |
| 322 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 323 | x86::emms(); |
| 324 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 325 | return builder->CreateRet(V); |
| 326 | } |
| 327 | |
| 328 | Value *Nucleus::createBr(BasicBlock *dest) |
| 329 | { |
| 330 | return builder->CreateBr(dest); |
| 331 | } |
| 332 | |
| 333 | Value *Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 334 | { |
| 335 | return builder->CreateCondBr(cond, ifTrue, ifFalse); |
| 336 | } |
| 337 | |
| 338 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 339 | { |
| 340 | return builder->CreateAdd(lhs, rhs); |
| 341 | } |
| 342 | |
| 343 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 344 | { |
| 345 | return builder->CreateSub(lhs, rhs); |
| 346 | } |
| 347 | |
| 348 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 349 | { |
| 350 | return builder->CreateMul(lhs, rhs); |
| 351 | } |
| 352 | |
| 353 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 354 | { |
| 355 | return builder->CreateUDiv(lhs, rhs); |
| 356 | } |
| 357 | |
| 358 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 359 | { |
| 360 | return builder->CreateSDiv(lhs, rhs); |
| 361 | } |
| 362 | |
| 363 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 364 | { |
| 365 | return builder->CreateFAdd(lhs, rhs); |
| 366 | } |
| 367 | |
| 368 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 369 | { |
| 370 | return builder->CreateFSub(lhs, rhs); |
| 371 | } |
| 372 | |
| 373 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 374 | { |
| 375 | return builder->CreateFMul(lhs, rhs); |
| 376 | } |
| 377 | |
| 378 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 379 | { |
| 380 | return builder->CreateFDiv(lhs, rhs); |
| 381 | } |
| 382 | |
| 383 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 384 | { |
| 385 | return builder->CreateURem(lhs, rhs); |
| 386 | } |
| 387 | |
| 388 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 389 | { |
| 390 | return builder->CreateSRem(lhs, rhs); |
| 391 | } |
| 392 | |
| 393 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 394 | { |
| 395 | return builder->CreateFRem(lhs, rhs); |
| 396 | } |
| 397 | |
| 398 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 399 | { |
| 400 | return builder->CreateShl(lhs, rhs); |
| 401 | } |
| 402 | |
| 403 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 404 | { |
| 405 | return builder->CreateLShr(lhs, rhs); |
| 406 | } |
| 407 | |
| 408 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 409 | { |
| 410 | return builder->CreateAShr(lhs, rhs); |
| 411 | } |
| 412 | |
| 413 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 414 | { |
| 415 | return builder->CreateAnd(lhs, rhs); |
| 416 | } |
| 417 | |
| 418 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 419 | { |
| 420 | return builder->CreateOr(lhs, rhs); |
| 421 | } |
| 422 | |
| 423 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 424 | { |
| 425 | return builder->CreateXor(lhs, rhs); |
| 426 | } |
| 427 | |
| 428 | Value *Nucleus::createNeg(Value *V) |
| 429 | { |
| 430 | return builder->CreateNeg(V); |
| 431 | } |
| 432 | |
| 433 | Value *Nucleus::createFNeg(Value *V) |
| 434 | { |
| 435 | return builder->CreateFNeg(V); |
| 436 | } |
| 437 | |
| 438 | Value *Nucleus::createNot(Value *V) |
| 439 | { |
| 440 | return builder->CreateNot(V); |
| 441 | } |
| 442 | |
| 443 | Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align) |
| 444 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 445 | return builder->Insert(new LoadInst(ptr, "", isVolatile, align)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align) |
| 449 | { |
| 450 | return builder->Insert(new StoreInst(value, ptr, isVolatile, align)); |
| 451 | } |
| 452 | |
| 453 | Value *Nucleus::createGEP(Value *ptr, Value *index) |
| 454 | { |
| 455 | return builder->CreateGEP(ptr, index); |
| 456 | } |
| 457 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 458 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 459 | { |
| 460 | return builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, value, SequentiallyConsistent); |
| 461 | } |
| 462 | |
| 463 | Value *Nucleus::createTrunc(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 464 | { |
| 465 | return builder->CreateTrunc(V, destType); |
| 466 | } |
| 467 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 468 | Value *Nucleus::createZExt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 469 | { |
| 470 | return builder->CreateZExt(V, destType); |
| 471 | } |
| 472 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 473 | Value *Nucleus::createSExt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 474 | { |
| 475 | return builder->CreateSExt(V, destType); |
| 476 | } |
| 477 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame^] | 478 | // Value *Nucleus::createFPToUI(Value *V, Type *destType) |
| 479 | // { |
| 480 | // return builder->CreateFPToUI(V, destType); |
| 481 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 482 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 483 | Value *Nucleus::createFPToSI(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 484 | { |
| 485 | return builder->CreateFPToSI(V, destType); |
| 486 | } |
| 487 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 488 | Value *Nucleus::createUIToFP(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 489 | { |
| 490 | return builder->CreateUIToFP(V, destType); |
| 491 | } |
| 492 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 493 | Value *Nucleus::createSIToFP(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 494 | { |
| 495 | return builder->CreateSIToFP(V, destType); |
| 496 | } |
| 497 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 498 | Value *Nucleus::createFPTrunc(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | { |
| 500 | return builder->CreateFPTrunc(V, destType); |
| 501 | } |
| 502 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 503 | Value *Nucleus::createFPExt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 504 | { |
| 505 | return builder->CreateFPExt(V, destType); |
| 506 | } |
| 507 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 508 | Value *Nucleus::createPtrToInt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 509 | { |
| 510 | return builder->CreatePtrToInt(V, destType); |
| 511 | } |
| 512 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 513 | Value *Nucleus::createIntToPtr(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 514 | { |
| 515 | return builder->CreateIntToPtr(V, destType); |
| 516 | } |
| 517 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 518 | Value *Nucleus::createBitCast(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 519 | { |
| 520 | return builder->CreateBitCast(V, destType); |
| 521 | } |
| 522 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 523 | Value *Nucleus::createIntCast(Value *V, Type *destType, bool isSigned) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 524 | { |
| 525 | return builder->CreateIntCast(V, destType, isSigned); |
| 526 | } |
| 527 | |
| 528 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 529 | { |
| 530 | return builder->CreateICmpEQ(lhs, rhs); |
| 531 | } |
| 532 | |
| 533 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 534 | { |
| 535 | return builder->CreateICmpNE(lhs, rhs); |
| 536 | } |
| 537 | |
| 538 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 539 | { |
| 540 | return builder->CreateICmpUGT(lhs, rhs); |
| 541 | } |
| 542 | |
| 543 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 544 | { |
| 545 | return builder->CreateICmpUGE(lhs, rhs); |
| 546 | } |
| 547 | |
| 548 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 549 | { |
| 550 | return builder->CreateICmpULT(lhs, rhs); |
| 551 | } |
| 552 | |
| 553 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 554 | { |
| 555 | return builder->CreateICmpULE(lhs, rhs); |
| 556 | } |
| 557 | |
| 558 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 559 | { |
| 560 | return builder->CreateICmpSGT(lhs, rhs); |
| 561 | } |
| 562 | |
| 563 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 564 | { |
| 565 | return builder->CreateICmpSGE(lhs, rhs); |
| 566 | } |
| 567 | |
| 568 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 569 | { |
| 570 | return builder->CreateICmpSLT(lhs, rhs); |
| 571 | } |
| 572 | |
| 573 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 574 | { |
| 575 | return builder->CreateICmpSLE(lhs, rhs); |
| 576 | } |
| 577 | |
| 578 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 579 | { |
| 580 | return builder->CreateFCmpOEQ(lhs, rhs); |
| 581 | } |
| 582 | |
| 583 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 584 | { |
| 585 | return builder->CreateFCmpOGT(lhs, rhs); |
| 586 | } |
| 587 | |
| 588 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 589 | { |
| 590 | return builder->CreateFCmpOGE(lhs, rhs); |
| 591 | } |
| 592 | |
| 593 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 594 | { |
| 595 | return builder->CreateFCmpOLT(lhs, rhs); |
| 596 | } |
| 597 | |
| 598 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 599 | { |
| 600 | return builder->CreateFCmpOLE(lhs, rhs); |
| 601 | } |
| 602 | |
| 603 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 604 | { |
| 605 | return builder->CreateFCmpONE(lhs, rhs); |
| 606 | } |
| 607 | |
| 608 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 609 | { |
| 610 | return builder->CreateFCmpORD(lhs, rhs); |
| 611 | } |
| 612 | |
| 613 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 614 | { |
| 615 | return builder->CreateFCmpUNO(lhs, rhs); |
| 616 | } |
| 617 | |
| 618 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 619 | { |
| 620 | return builder->CreateFCmpUEQ(lhs, rhs); |
| 621 | } |
| 622 | |
| 623 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 624 | { |
| 625 | return builder->CreateFCmpUGT(lhs, rhs); |
| 626 | } |
| 627 | |
| 628 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 629 | { |
| 630 | return builder->CreateFCmpUGE(lhs, rhs); |
| 631 | } |
| 632 | |
| 633 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 634 | { |
| 635 | return builder->CreateFCmpULT(lhs, rhs); |
| 636 | } |
| 637 | |
| 638 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 639 | { |
| 640 | return builder->CreateFCmpULE(lhs, rhs); |
| 641 | } |
| 642 | |
| 643 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 644 | { |
| 645 | return builder->CreateFCmpULE(lhs, rhs); |
| 646 | } |
| 647 | |
| 648 | Value *Nucleus::createCall(Value *callee) |
| 649 | { |
| 650 | return builder->CreateCall(callee); |
| 651 | } |
| 652 | |
| 653 | Value *Nucleus::createCall(Value *callee, Value *arg) |
| 654 | { |
| 655 | return builder->CreateCall(callee, arg); |
| 656 | } |
| 657 | |
| 658 | Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2) |
| 659 | { |
| 660 | return builder->CreateCall2(callee, arg1, arg2); |
| 661 | } |
| 662 | |
| 663 | Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3) |
| 664 | { |
| 665 | return builder->CreateCall3(callee, arg1, arg2, arg3); |
| 666 | } |
| 667 | |
| 668 | Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3, Value *arg4) |
| 669 | { |
| 670 | return builder->CreateCall4(callee, arg1, arg2, arg3, arg4); |
| 671 | } |
| 672 | |
| 673 | Value *Nucleus::createExtractElement(Value *vector, int index) |
| 674 | { |
| 675 | return builder->CreateExtractElement(vector, createConstantInt(index)); |
| 676 | } |
| 677 | |
| 678 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 679 | { |
| 680 | return builder->CreateInsertElement(vector, element, createConstantInt(index)); |
| 681 | } |
| 682 | |
| 683 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, Value *mask) |
| 684 | { |
| 685 | return builder->CreateShuffleVector(V1, V2, mask); |
| 686 | } |
| 687 | |
| 688 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 689 | { |
| 690 | return builder->CreateSelect(C, ifTrue, ifFalse); |
| 691 | } |
| 692 | |
| 693 | Value *Nucleus::createSwitch(llvm::Value *V, llvm::BasicBlock *Dest, unsigned NumCases) |
| 694 | { |
| 695 | return builder->CreateSwitch(V, Dest, NumCases); |
| 696 | } |
| 697 | |
| 698 | void Nucleus::addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch) |
| 699 | { |
| 700 | static_cast<SwitchInst*>(Switch)->addCase(Nucleus::createConstantInt(Case), Branch); |
| 701 | } |
| 702 | |
| 703 | Value *Nucleus::createUnreachable() |
| 704 | { |
| 705 | return builder->CreateUnreachable(); |
| 706 | } |
| 707 | |
| 708 | Value *Nucleus::createSwizzle(Value *val, unsigned char select) |
| 709 | { |
| 710 | Constant *swizzle[4]; |
| 711 | swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03); |
| 712 | swizzle[1] = Nucleus::createConstantInt((select >> 2) & 0x03); |
| 713 | swizzle[2] = Nucleus::createConstantInt((select >> 4) & 0x03); |
| 714 | swizzle[3] = Nucleus::createConstantInt((select >> 6) & 0x03); |
| 715 | |
| 716 | Value *shuffle = Nucleus::createShuffleVector(val, UndefValue::get(val->getType()), Nucleus::createConstantVector(swizzle, 4)); |
| 717 | |
| 718 | return shuffle; |
| 719 | } |
| 720 | |
| 721 | Value *Nucleus::createMask(Value *lhs, Value *rhs, unsigned char select) |
| 722 | { |
| 723 | bool mask[4] = {false, false, false, false}; |
| 724 | |
| 725 | mask[(select >> 0) & 0x03] = true; |
| 726 | mask[(select >> 2) & 0x03] = true; |
| 727 | mask[(select >> 4) & 0x03] = true; |
| 728 | mask[(select >> 6) & 0x03] = true; |
| 729 | |
| 730 | Constant *swizzle[4]; |
| 731 | swizzle[0] = Nucleus::createConstantInt(mask[0] ? 4 : 0); |
| 732 | swizzle[1] = Nucleus::createConstantInt(mask[1] ? 5 : 1); |
| 733 | swizzle[2] = Nucleus::createConstantInt(mask[2] ? 6 : 2); |
| 734 | swizzle[3] = Nucleus::createConstantInt(mask[3] ? 7 : 3); |
| 735 | |
| 736 | Value *shuffle = Nucleus::createShuffleVector(lhs, rhs, Nucleus::createConstantVector(swizzle, 4)); |
| 737 | |
| 738 | return shuffle; |
| 739 | } |
| 740 | |
| 741 | const llvm::GlobalValue *Nucleus::getGlobalValueAtAddress(void *Addr) |
| 742 | { |
| 743 | return executionEngine->getGlobalValueAtAddress(Addr); |
| 744 | } |
| 745 | |
| 746 | void Nucleus::addGlobalMapping(const llvm::GlobalValue *GV, void *Addr) |
| 747 | { |
| 748 | executionEngine->addGlobalMapping(GV, Addr); |
| 749 | } |
| 750 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 751 | llvm::GlobalValue *Nucleus::createGlobalValue(llvm::Type *Ty, bool isConstant, unsigned int Align) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 752 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 753 | llvm::GlobalValue *global = new llvm::GlobalVariable(*Nucleus::getModule(), Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, ""); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 754 | global->setAlignment(Align); |
| 755 | |
| 756 | return global; |
| 757 | } |
| 758 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 759 | llvm::Type *Nucleus::getPointerType(llvm::Type *ElementType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 760 | { |
| 761 | return llvm::PointerType::get(ElementType, 0); |
| 762 | } |
| 763 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 764 | llvm::Constant *Nucleus::createNullValue(llvm::Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 765 | { |
| 766 | return llvm::Constant::getNullValue(Ty); |
| 767 | } |
| 768 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 769 | llvm::ConstantInt *Nucleus::createConstantInt(int64_t i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 770 | { |
| 771 | return llvm::ConstantInt::get(Type::getInt64Ty(*context), i, true); |
| 772 | } |
| 773 | |
| 774 | llvm::ConstantInt *Nucleus::createConstantInt(int i) |
| 775 | { |
| 776 | return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, true); |
| 777 | } |
| 778 | |
| 779 | llvm::ConstantInt *Nucleus::createConstantInt(unsigned int i) |
| 780 | { |
| 781 | return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, false); |
| 782 | } |
| 783 | |
| 784 | llvm::ConstantInt *Nucleus::createConstantBool(bool b) |
| 785 | { |
| 786 | return llvm::ConstantInt::get(Type::getInt1Ty(*context), b); |
| 787 | } |
| 788 | |
| 789 | llvm::ConstantInt *Nucleus::createConstantByte(signed char i) |
| 790 | { |
| 791 | return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, true); |
| 792 | } |
| 793 | |
| 794 | llvm::ConstantInt *Nucleus::createConstantByte(unsigned char i) |
| 795 | { |
| 796 | return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, false); |
| 797 | } |
| 798 | |
| 799 | llvm::ConstantInt *Nucleus::createConstantShort(short i) |
| 800 | { |
| 801 | return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, true); |
| 802 | } |
| 803 | |
| 804 | llvm::ConstantInt *Nucleus::createConstantShort(unsigned short i) |
| 805 | { |
| 806 | return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, false); |
| 807 | } |
| 808 | |
| 809 | llvm::Constant *Nucleus::createConstantFloat(float x) |
| 810 | { |
| 811 | return ConstantFP::get(Float::getType(), x); |
| 812 | } |
| 813 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 814 | llvm::Value *Nucleus::createNullPointer(llvm::Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 815 | { |
| 816 | return llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0)); |
| 817 | } |
| 818 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 819 | llvm::Value *Nucleus::createConstantVector(llvm::Constant *const *Vals, unsigned NumVals) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 820 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 821 | return llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(Vals, NumVals)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 822 | } |
| 823 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 824 | Type *Void::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 825 | { |
| 826 | return Type::getVoidTy(*Nucleus::getContext()); |
| 827 | } |
| 828 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 829 | LValue::LValue(llvm::Type *type, int arraySize) |
| 830 | { |
| 831 | address = Nucleus::allocateStackVariable(type, arraySize); |
| 832 | } |
| 833 | |
| 834 | llvm::Value *LValue::loadValue(unsigned int alignment) const |
| 835 | { |
| 836 | return Nucleus::createLoad(address, false, alignment); |
| 837 | } |
| 838 | |
| 839 | llvm::Value *LValue::storeValue(llvm::Value *value, unsigned int alignment) const |
| 840 | { |
| 841 | return Nucleus::createStore(value, address, false, alignment); |
| 842 | } |
| 843 | |
| 844 | llvm::Value *LValue::getAddress(llvm::Value *index) const |
| 845 | { |
| 846 | return Nucleus::createGEP(address, index); |
| 847 | } |
| 848 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 849 | Type *MMX::getType() |
| 850 | { |
| 851 | return Type::getX86_MMXTy(*Nucleus::getContext()); |
| 852 | } |
| 853 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 854 | Bool::Bool(Argument<Bool> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 855 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 856 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | Bool::Bool() |
| 860 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | Bool::Bool(bool x) |
| 864 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 865 | storeValue(Nucleus::createConstantBool(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 866 | } |
| 867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 868 | Bool::Bool(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 869 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 870 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | Bool::Bool(const Bool &rhs) |
| 874 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 875 | Value *value = rhs.loadValue(); |
| 876 | storeValue(value); |
| 877 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 878 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 879 | Bool::Bool(const Reference<Bool> &rhs) |
| 880 | { |
| 881 | Value *value = rhs.loadValue(); |
| 882 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | } |
| 884 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 885 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 886 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 887 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 888 | |
| 889 | return rhs; |
| 890 | } |
| 891 | |
| 892 | RValue<Bool> Bool::operator=(const Bool &rhs) const |
| 893 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 894 | Value *value = rhs.loadValue(); |
| 895 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 896 | |
| 897 | return RValue<Bool>(value); |
| 898 | } |
| 899 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 900 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 901 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 902 | Value *value = rhs.loadValue(); |
| 903 | storeValue(value); |
| 904 | |
| 905 | return RValue<Bool>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 906 | } |
| 907 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 908 | RValue<Bool> operator!(RValue<Bool> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 909 | { |
| 910 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 911 | } |
| 912 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 913 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 914 | { |
| 915 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 916 | } |
| 917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 918 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 919 | { |
| 920 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 921 | } |
| 922 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 923 | Type *Bool::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 924 | { |
| 925 | return Type::getInt1Ty(*Nucleus::getContext()); |
| 926 | } |
| 927 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 928 | Byte::Byte(Argument<Byte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 929 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 930 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 931 | } |
| 932 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 933 | Byte::Byte(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 934 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 935 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 936 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 937 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 938 | } |
| 939 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 940 | Byte::Byte(RValue<UInt> cast) |
| 941 | { |
| 942 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 943 | |
| 944 | storeValue(integer); |
| 945 | } |
| 946 | |
| 947 | Byte::Byte(RValue<UShort> cast) |
| 948 | { |
| 949 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 950 | |
| 951 | storeValue(integer); |
| 952 | } |
| 953 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 954 | Byte::Byte() |
| 955 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | Byte::Byte(int x) |
| 959 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 960 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | Byte::Byte(unsigned char x) |
| 964 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 965 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 966 | } |
| 967 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 968 | Byte::Byte(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 969 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 970 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | Byte::Byte(const Byte &rhs) |
| 974 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 975 | Value *value = rhs.loadValue(); |
| 976 | storeValue(value); |
| 977 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 978 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 979 | Byte::Byte(const Reference<Byte> &rhs) |
| 980 | { |
| 981 | Value *value = rhs.loadValue(); |
| 982 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 983 | } |
| 984 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 985 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 986 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 987 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 988 | |
| 989 | return rhs; |
| 990 | } |
| 991 | |
| 992 | RValue<Byte> Byte::operator=(const Byte &rhs) const |
| 993 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 994 | Value *value = rhs.loadValue(); |
| 995 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 996 | |
| 997 | return RValue<Byte>(value); |
| 998 | } |
| 999 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1000 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1001 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1002 | Value *value = rhs.loadValue(); |
| 1003 | storeValue(value); |
| 1004 | |
| 1005 | return RValue<Byte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1006 | } |
| 1007 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1008 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1009 | { |
| 1010 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1011 | } |
| 1012 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1013 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1014 | { |
| 1015 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1016 | } |
| 1017 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1018 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1019 | { |
| 1020 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1021 | } |
| 1022 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1023 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1024 | { |
| 1025 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1026 | } |
| 1027 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1028 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1029 | { |
| 1030 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1031 | } |
| 1032 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1033 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1034 | { |
| 1035 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1036 | } |
| 1037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1038 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1039 | { |
| 1040 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1041 | } |
| 1042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1043 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1044 | { |
| 1045 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1046 | } |
| 1047 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1048 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1049 | { |
| 1050 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1051 | } |
| 1052 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1053 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1054 | { |
| 1055 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1056 | } |
| 1057 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1058 | RValue<Byte> operator+=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1059 | { |
| 1060 | return lhs = lhs + rhs; |
| 1061 | } |
| 1062 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1063 | RValue<Byte> operator-=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1064 | { |
| 1065 | return lhs = lhs - rhs; |
| 1066 | } |
| 1067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1068 | RValue<Byte> operator*=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1069 | { |
| 1070 | return lhs = lhs * rhs; |
| 1071 | } |
| 1072 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1073 | RValue<Byte> operator/=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1074 | { |
| 1075 | return lhs = lhs / rhs; |
| 1076 | } |
| 1077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1078 | RValue<Byte> operator%=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1079 | { |
| 1080 | return lhs = lhs % rhs; |
| 1081 | } |
| 1082 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1083 | RValue<Byte> operator&=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1084 | { |
| 1085 | return lhs = lhs & rhs; |
| 1086 | } |
| 1087 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1088 | RValue<Byte> operator|=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1089 | { |
| 1090 | return lhs = lhs | rhs; |
| 1091 | } |
| 1092 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1093 | RValue<Byte> operator^=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1094 | { |
| 1095 | return lhs = lhs ^ rhs; |
| 1096 | } |
| 1097 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1098 | RValue<Byte> operator<<=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1099 | { |
| 1100 | return lhs = lhs << rhs; |
| 1101 | } |
| 1102 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1103 | RValue<Byte> operator>>=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1104 | { |
| 1105 | return lhs = lhs >> rhs; |
| 1106 | } |
| 1107 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1108 | RValue<Byte> operator+(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1109 | { |
| 1110 | return val; |
| 1111 | } |
| 1112 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1113 | RValue<Byte> operator-(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1114 | { |
| 1115 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1116 | } |
| 1117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1118 | RValue<Byte> operator~(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1119 | { |
| 1120 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1121 | } |
| 1122 | |
| 1123 | RValue<Byte> operator++(const Byte &val, int) // Post-increment |
| 1124 | { |
| 1125 | RValue<Byte> res = val; |
| 1126 | |
| 1127 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1128 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1129 | |
| 1130 | return res; |
| 1131 | } |
| 1132 | |
| 1133 | const Byte &operator++(const Byte &val) // Pre-increment |
| 1134 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1135 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); |
| 1136 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1137 | |
| 1138 | return val; |
| 1139 | } |
| 1140 | |
| 1141 | RValue<Byte> operator--(const Byte &val, int) // Post-decrement |
| 1142 | { |
| 1143 | RValue<Byte> res = val; |
| 1144 | |
| 1145 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1146 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1147 | |
| 1148 | return res; |
| 1149 | } |
| 1150 | |
| 1151 | const Byte &operator--(const Byte &val) // Pre-decrement |
| 1152 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1153 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); |
| 1154 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1155 | |
| 1156 | return val; |
| 1157 | } |
| 1158 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1159 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1160 | { |
| 1161 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1162 | } |
| 1163 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1164 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1165 | { |
| 1166 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1167 | } |
| 1168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1169 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1170 | { |
| 1171 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1172 | } |
| 1173 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1174 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1175 | { |
| 1176 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1177 | } |
| 1178 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1179 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1180 | { |
| 1181 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1182 | } |
| 1183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1184 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1185 | { |
| 1186 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1187 | } |
| 1188 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1189 | Type *Byte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1190 | { |
| 1191 | return Type::getInt8Ty(*Nucleus::getContext()); |
| 1192 | } |
| 1193 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1194 | SByte::SByte(Argument<SByte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1195 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1196 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1199 | SByte::SByte(RValue<Int> cast) |
| 1200 | { |
| 1201 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1202 | |
| 1203 | storeValue(integer); |
| 1204 | } |
| 1205 | |
| 1206 | SByte::SByte(RValue<Short> cast) |
| 1207 | { |
| 1208 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1209 | |
| 1210 | storeValue(integer); |
| 1211 | } |
| 1212 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1213 | SByte::SByte() |
| 1214 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | SByte::SByte(signed char x) |
| 1218 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1219 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1220 | } |
| 1221 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1222 | SByte::SByte(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1223 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1224 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | SByte::SByte(const SByte &rhs) |
| 1228 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1229 | Value *value = rhs.loadValue(); |
| 1230 | storeValue(value); |
| 1231 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1232 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1233 | SByte::SByte(const Reference<SByte> &rhs) |
| 1234 | { |
| 1235 | Value *value = rhs.loadValue(); |
| 1236 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1237 | } |
| 1238 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1239 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1240 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1241 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1242 | |
| 1243 | return rhs; |
| 1244 | } |
| 1245 | |
| 1246 | RValue<SByte> SByte::operator=(const SByte &rhs) const |
| 1247 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1248 | Value *value = rhs.loadValue(); |
| 1249 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1250 | |
| 1251 | return RValue<SByte>(value); |
| 1252 | } |
| 1253 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1254 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1255 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1256 | Value *value = rhs.loadValue(); |
| 1257 | storeValue(value); |
| 1258 | |
| 1259 | return RValue<SByte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1262 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1263 | { |
| 1264 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1265 | } |
| 1266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1267 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1268 | { |
| 1269 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1270 | } |
| 1271 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1272 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1273 | { |
| 1274 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1275 | } |
| 1276 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1277 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1278 | { |
| 1279 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1280 | } |
| 1281 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1282 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1283 | { |
| 1284 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1285 | } |
| 1286 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1287 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1288 | { |
| 1289 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1290 | } |
| 1291 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1292 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1293 | { |
| 1294 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1295 | } |
| 1296 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1297 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1298 | { |
| 1299 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1300 | } |
| 1301 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1302 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1303 | { |
| 1304 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1305 | } |
| 1306 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1307 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1308 | { |
| 1309 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1310 | } |
| 1311 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1312 | RValue<SByte> operator+=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1313 | { |
| 1314 | return lhs = lhs + rhs; |
| 1315 | } |
| 1316 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1317 | RValue<SByte> operator-=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1318 | { |
| 1319 | return lhs = lhs - rhs; |
| 1320 | } |
| 1321 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1322 | RValue<SByte> operator*=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1323 | { |
| 1324 | return lhs = lhs * rhs; |
| 1325 | } |
| 1326 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1327 | RValue<SByte> operator/=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1328 | { |
| 1329 | return lhs = lhs / rhs; |
| 1330 | } |
| 1331 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1332 | RValue<SByte> operator%=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1333 | { |
| 1334 | return lhs = lhs % rhs; |
| 1335 | } |
| 1336 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1337 | RValue<SByte> operator&=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1338 | { |
| 1339 | return lhs = lhs & rhs; |
| 1340 | } |
| 1341 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1342 | RValue<SByte> operator|=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1343 | { |
| 1344 | return lhs = lhs | rhs; |
| 1345 | } |
| 1346 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1347 | RValue<SByte> operator^=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1348 | { |
| 1349 | return lhs = lhs ^ rhs; |
| 1350 | } |
| 1351 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1352 | RValue<SByte> operator<<=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1353 | { |
| 1354 | return lhs = lhs << rhs; |
| 1355 | } |
| 1356 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1357 | RValue<SByte> operator>>=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1358 | { |
| 1359 | return lhs = lhs >> rhs; |
| 1360 | } |
| 1361 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1362 | RValue<SByte> operator+(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1363 | { |
| 1364 | return val; |
| 1365 | } |
| 1366 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1367 | RValue<SByte> operator-(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1368 | { |
| 1369 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1370 | } |
| 1371 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1372 | RValue<SByte> operator~(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1373 | { |
| 1374 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1375 | } |
| 1376 | |
| 1377 | RValue<SByte> operator++(const SByte &val, int) // Post-increment |
| 1378 | { |
| 1379 | RValue<SByte> res = val; |
| 1380 | |
| 1381 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1382 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1383 | |
| 1384 | return res; |
| 1385 | } |
| 1386 | |
| 1387 | const SByte &operator++(const SByte &val) // Pre-increment |
| 1388 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1389 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1)); |
| 1390 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1391 | |
| 1392 | return val; |
| 1393 | } |
| 1394 | |
| 1395 | RValue<SByte> operator--(const SByte &val, int) // Post-decrement |
| 1396 | { |
| 1397 | RValue<SByte> res = val; |
| 1398 | |
| 1399 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1400 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1401 | |
| 1402 | return res; |
| 1403 | } |
| 1404 | |
| 1405 | const SByte &operator--(const SByte &val) // Pre-decrement |
| 1406 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1407 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1)); |
| 1408 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1409 | |
| 1410 | return val; |
| 1411 | } |
| 1412 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1413 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1414 | { |
| 1415 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1416 | } |
| 1417 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1418 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1419 | { |
| 1420 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1421 | } |
| 1422 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1423 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1424 | { |
| 1425 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1426 | } |
| 1427 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1428 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1429 | { |
| 1430 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1431 | } |
| 1432 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1433 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1434 | { |
| 1435 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1436 | } |
| 1437 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1438 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1439 | { |
| 1440 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1441 | } |
| 1442 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1443 | Type *SByte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1444 | { |
| 1445 | return Type::getInt8Ty(*Nucleus::getContext()); |
| 1446 | } |
| 1447 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1448 | Short::Short(Argument<Short> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1449 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1450 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1451 | } |
| 1452 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1453 | Short::Short(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1454 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1455 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1456 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1457 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | Short::Short() |
| 1461 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | Short::Short(short x) |
| 1465 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1466 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1467 | } |
| 1468 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1469 | Short::Short(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1470 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1471 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | Short::Short(const Short &rhs) |
| 1475 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1476 | Value *value = rhs.loadValue(); |
| 1477 | storeValue(value); |
| 1478 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1479 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1480 | Short::Short(const Reference<Short> &rhs) |
| 1481 | { |
| 1482 | Value *value = rhs.loadValue(); |
| 1483 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1484 | } |
| 1485 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1486 | RValue<Short> Short::operator=(RValue<Short> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1487 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1488 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1489 | |
| 1490 | return rhs; |
| 1491 | } |
| 1492 | |
| 1493 | RValue<Short> Short::operator=(const Short &rhs) const |
| 1494 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1495 | Value *value = rhs.loadValue(); |
| 1496 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1497 | |
| 1498 | return RValue<Short>(value); |
| 1499 | } |
| 1500 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1501 | RValue<Short> Short::operator=(const Reference<Short> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1502 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1503 | Value *value = rhs.loadValue(); |
| 1504 | storeValue(value); |
| 1505 | |
| 1506 | return RValue<Short>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1509 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1510 | { |
| 1511 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1512 | } |
| 1513 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1514 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1515 | { |
| 1516 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1517 | } |
| 1518 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1519 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1520 | { |
| 1521 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1522 | } |
| 1523 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1524 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1525 | { |
| 1526 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1527 | } |
| 1528 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1529 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1530 | { |
| 1531 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1532 | } |
| 1533 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1534 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1535 | { |
| 1536 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1537 | } |
| 1538 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1539 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1540 | { |
| 1541 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1542 | } |
| 1543 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1544 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1545 | { |
| 1546 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1547 | } |
| 1548 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1549 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1550 | { |
| 1551 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1552 | } |
| 1553 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1554 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1555 | { |
| 1556 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1557 | } |
| 1558 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1559 | RValue<Short> operator+=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1560 | { |
| 1561 | return lhs = lhs + rhs; |
| 1562 | } |
| 1563 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1564 | RValue<Short> operator-=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1565 | { |
| 1566 | return lhs = lhs - rhs; |
| 1567 | } |
| 1568 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1569 | RValue<Short> operator*=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1570 | { |
| 1571 | return lhs = lhs * rhs; |
| 1572 | } |
| 1573 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1574 | RValue<Short> operator/=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1575 | { |
| 1576 | return lhs = lhs / rhs; |
| 1577 | } |
| 1578 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1579 | RValue<Short> operator%=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1580 | { |
| 1581 | return lhs = lhs % rhs; |
| 1582 | } |
| 1583 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1584 | RValue<Short> operator&=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1585 | { |
| 1586 | return lhs = lhs & rhs; |
| 1587 | } |
| 1588 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1589 | RValue<Short> operator|=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1590 | { |
| 1591 | return lhs = lhs | rhs; |
| 1592 | } |
| 1593 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1594 | RValue<Short> operator^=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1595 | { |
| 1596 | return lhs = lhs ^ rhs; |
| 1597 | } |
| 1598 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1599 | RValue<Short> operator<<=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1600 | { |
| 1601 | return lhs = lhs << rhs; |
| 1602 | } |
| 1603 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1604 | RValue<Short> operator>>=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1605 | { |
| 1606 | return lhs = lhs >> rhs; |
| 1607 | } |
| 1608 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1609 | RValue<Short> operator+(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1610 | { |
| 1611 | return val; |
| 1612 | } |
| 1613 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1614 | RValue<Short> operator-(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1615 | { |
| 1616 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 1617 | } |
| 1618 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1619 | RValue<Short> operator~(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1620 | { |
| 1621 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 1622 | } |
| 1623 | |
| 1624 | RValue<Short> operator++(const Short &val, int) // Post-increment |
| 1625 | { |
| 1626 | RValue<Short> res = val; |
| 1627 | |
| 1628 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1629 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1630 | |
| 1631 | return res; |
| 1632 | } |
| 1633 | |
| 1634 | const Short &operator++(const Short &val) // Pre-increment |
| 1635 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1636 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1)); |
| 1637 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1638 | |
| 1639 | return val; |
| 1640 | } |
| 1641 | |
| 1642 | RValue<Short> operator--(const Short &val, int) // Post-decrement |
| 1643 | { |
| 1644 | RValue<Short> res = val; |
| 1645 | |
| 1646 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1647 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1648 | |
| 1649 | return res; |
| 1650 | } |
| 1651 | |
| 1652 | const Short &operator--(const Short &val) // Pre-decrement |
| 1653 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1654 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1)); |
| 1655 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1656 | |
| 1657 | return val; |
| 1658 | } |
| 1659 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1660 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1661 | { |
| 1662 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1663 | } |
| 1664 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1665 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1666 | { |
| 1667 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1668 | } |
| 1669 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1670 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1671 | { |
| 1672 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1673 | } |
| 1674 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1675 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1676 | { |
| 1677 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1678 | } |
| 1679 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1680 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1681 | { |
| 1682 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1683 | } |
| 1684 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1685 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1686 | { |
| 1687 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1688 | } |
| 1689 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1690 | Type *Short::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1691 | { |
| 1692 | return Type::getInt16Ty(*Nucleus::getContext()); |
| 1693 | } |
| 1694 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1695 | UShort::UShort(Argument<UShort> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1696 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1697 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1700 | UShort::UShort(RValue<UInt> cast) |
| 1701 | { |
| 1702 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1703 | |
| 1704 | storeValue(integer); |
| 1705 | } |
| 1706 | |
Alexis Hetu | 75b650f | 2015-11-19 17:40:15 -0500 | [diff] [blame] | 1707 | UShort::UShort(RValue<Int> cast) |
| 1708 | { |
| 1709 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1710 | |
| 1711 | storeValue(integer); |
| 1712 | } |
| 1713 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1714 | UShort::UShort() |
| 1715 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | UShort::UShort(unsigned short x) |
| 1719 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1720 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1723 | UShort::UShort(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1724 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1725 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | UShort::UShort(const UShort &rhs) |
| 1729 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1730 | Value *value = rhs.loadValue(); |
| 1731 | storeValue(value); |
| 1732 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1733 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1734 | UShort::UShort(const Reference<UShort> &rhs) |
| 1735 | { |
| 1736 | Value *value = rhs.loadValue(); |
| 1737 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1740 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1741 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1742 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1743 | |
| 1744 | return rhs; |
| 1745 | } |
| 1746 | |
| 1747 | RValue<UShort> UShort::operator=(const UShort &rhs) const |
| 1748 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1749 | Value *value = rhs.loadValue(); |
| 1750 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1751 | |
| 1752 | return RValue<UShort>(value); |
| 1753 | } |
| 1754 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1755 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1756 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1757 | Value *value = rhs.loadValue(); |
| 1758 | storeValue(value); |
| 1759 | |
| 1760 | return RValue<UShort>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1763 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1764 | { |
| 1765 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1766 | } |
| 1767 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1768 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1769 | { |
| 1770 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1771 | } |
| 1772 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1773 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1774 | { |
| 1775 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1776 | } |
| 1777 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1778 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1779 | { |
| 1780 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1781 | } |
| 1782 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1783 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1784 | { |
| 1785 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1786 | } |
| 1787 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1788 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1789 | { |
| 1790 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1791 | } |
| 1792 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1793 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1794 | { |
| 1795 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1796 | } |
| 1797 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1798 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1799 | { |
| 1800 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1801 | } |
| 1802 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1803 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1804 | { |
| 1805 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1806 | } |
| 1807 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1808 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1809 | { |
| 1810 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1811 | } |
| 1812 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1813 | RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1814 | { |
| 1815 | return lhs = lhs + rhs; |
| 1816 | } |
| 1817 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1818 | RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1819 | { |
| 1820 | return lhs = lhs - rhs; |
| 1821 | } |
| 1822 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1823 | RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1824 | { |
| 1825 | return lhs = lhs * rhs; |
| 1826 | } |
| 1827 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1828 | RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1829 | { |
| 1830 | return lhs = lhs / rhs; |
| 1831 | } |
| 1832 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1833 | RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1834 | { |
| 1835 | return lhs = lhs % rhs; |
| 1836 | } |
| 1837 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1838 | RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1839 | { |
| 1840 | return lhs = lhs & rhs; |
| 1841 | } |
| 1842 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1843 | RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1844 | { |
| 1845 | return lhs = lhs | rhs; |
| 1846 | } |
| 1847 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1848 | RValue<UShort> operator^=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1849 | { |
| 1850 | return lhs = lhs ^ rhs; |
| 1851 | } |
| 1852 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1853 | RValue<UShort> operator<<=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1854 | { |
| 1855 | return lhs = lhs << rhs; |
| 1856 | } |
| 1857 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1858 | RValue<UShort> operator>>=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1859 | { |
| 1860 | return lhs = lhs >> rhs; |
| 1861 | } |
| 1862 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1863 | RValue<UShort> operator+(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1864 | { |
| 1865 | return val; |
| 1866 | } |
| 1867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1868 | RValue<UShort> operator-(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1869 | { |
| 1870 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 1871 | } |
| 1872 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1873 | RValue<UShort> operator~(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1874 | { |
| 1875 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 1876 | } |
| 1877 | |
| 1878 | RValue<UShort> operator++(const UShort &val, int) // Post-increment |
| 1879 | { |
| 1880 | RValue<UShort> res = val; |
| 1881 | |
| 1882 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1883 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1884 | |
| 1885 | return res; |
| 1886 | } |
| 1887 | |
| 1888 | const UShort &operator++(const UShort &val) // Pre-increment |
| 1889 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1890 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1)); |
| 1891 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1892 | |
| 1893 | return val; |
| 1894 | } |
| 1895 | |
| 1896 | RValue<UShort> operator--(const UShort &val, int) // Post-decrement |
| 1897 | { |
| 1898 | RValue<UShort> res = val; |
| 1899 | |
| 1900 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1901 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1902 | |
| 1903 | return res; |
| 1904 | } |
| 1905 | |
| 1906 | const UShort &operator--(const UShort &val) // Pre-decrement |
| 1907 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1908 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1)); |
| 1909 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1910 | |
| 1911 | return val; |
| 1912 | } |
| 1913 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1914 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1915 | { |
| 1916 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1917 | } |
| 1918 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1919 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1920 | { |
| 1921 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1922 | } |
| 1923 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1924 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1925 | { |
| 1926 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1927 | } |
| 1928 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1929 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1930 | { |
| 1931 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1932 | } |
| 1933 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1934 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1935 | { |
| 1936 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1937 | } |
| 1938 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1939 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1940 | { |
| 1941 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1942 | } |
| 1943 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1944 | Type *UShort::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1945 | { |
| 1946 | return Type::getInt16Ty(*Nucleus::getContext()); |
| 1947 | } |
| 1948 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1949 | Type *Byte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1950 | { |
| 1951 | #if 0 |
| 1952 | return VectorType::get(Byte::getType(), 4); |
| 1953 | #else |
| 1954 | return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 1955 | #endif |
| 1956 | } |
| 1957 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1958 | Type *SByte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1959 | { |
| 1960 | #if 0 |
| 1961 | return VectorType::get(SByte::getType(), 4); |
| 1962 | #else |
| 1963 | return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 1964 | #endif |
| 1965 | } |
| 1966 | |
| 1967 | Byte8::Byte8() |
| 1968 | { |
| 1969 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | Byte8::Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7) |
| 1973 | { |
| 1974 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1975 | |
| 1976 | Constant *constantVector[8]; |
| 1977 | constantVector[0] = Nucleus::createConstantByte(x0); |
| 1978 | constantVector[1] = Nucleus::createConstantByte(x1); |
| 1979 | constantVector[2] = Nucleus::createConstantByte(x2); |
| 1980 | constantVector[3] = Nucleus::createConstantByte(x3); |
| 1981 | constantVector[4] = Nucleus::createConstantByte(x4); |
| 1982 | constantVector[5] = Nucleus::createConstantByte(x5); |
| 1983 | constantVector[6] = Nucleus::createConstantByte(x6); |
| 1984 | constantVector[7] = Nucleus::createConstantByte(x7); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1985 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1986 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1987 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | Byte8::Byte8(int64_t x) |
| 1991 | { |
| 1992 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1993 | |
| 1994 | Constant *constantVector[8]; |
| 1995 | constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0)); |
| 1996 | constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8)); |
| 1997 | constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16)); |
| 1998 | constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24)); |
| 1999 | constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32)); |
| 2000 | constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40)); |
| 2001 | constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48)); |
| 2002 | constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2003 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2004 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2005 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2006 | } |
| 2007 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2008 | Byte8::Byte8(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2009 | { |
| 2010 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2011 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2012 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | Byte8::Byte8(const Byte8 &rhs) |
| 2016 | { |
| 2017 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2018 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2019 | Value *value = rhs.loadValue(); |
| 2020 | storeValue(value); |
| 2021 | } |
| 2022 | |
| 2023 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2024 | { |
| 2025 | // xyzw.parent = this; |
| 2026 | |
| 2027 | Value *value = rhs.loadValue(); |
| 2028 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2029 | } |
| 2030 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2031 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2032 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2033 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2034 | |
| 2035 | return rhs; |
| 2036 | } |
| 2037 | |
| 2038 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const |
| 2039 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2040 | Value *value = rhs.loadValue(); |
| 2041 | storeValue(value); |
| 2042 | |
| 2043 | return RValue<Byte8>(value); |
| 2044 | } |
| 2045 | |
| 2046 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const |
| 2047 | { |
| 2048 | Value *value = rhs.loadValue(); |
| 2049 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2050 | |
| 2051 | return RValue<Byte8>(value); |
| 2052 | } |
| 2053 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2054 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2055 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2056 | if(CPUID::supportsMMX2()) |
| 2057 | { |
| 2058 | return x86::paddb(lhs, rhs); |
| 2059 | } |
| 2060 | else |
| 2061 | { |
| 2062 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2063 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2066 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2067 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2068 | if(CPUID::supportsMMX2()) |
| 2069 | { |
| 2070 | return x86::psubb(lhs, rhs); |
| 2071 | } |
| 2072 | else |
| 2073 | { |
| 2074 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2075 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2076 | } |
| 2077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2078 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2079 | // { |
| 2080 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2081 | // } |
| 2082 | |
| 2083 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2084 | // { |
| 2085 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2086 | // } |
| 2087 | |
| 2088 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2089 | // { |
| 2090 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2091 | // } |
| 2092 | |
| 2093 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2094 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2095 | if(CPUID::supportsMMX2()) |
| 2096 | { |
| 2097 | return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 2098 | } |
| 2099 | else |
| 2100 | { |
| 2101 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2102 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2103 | } |
| 2104 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2105 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2106 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2107 | if(CPUID::supportsMMX2()) |
| 2108 | { |
| 2109 | return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 2110 | } |
| 2111 | else |
| 2112 | { |
| 2113 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2114 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2115 | } |
| 2116 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2117 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2118 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2119 | if(CPUID::supportsMMX2()) |
| 2120 | { |
| 2121 | return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 2122 | } |
| 2123 | else |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2124 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2125 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2126 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2127 | } |
| 2128 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2129 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2130 | // { |
| 2131 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2132 | // } |
| 2133 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2134 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2135 | // { |
| 2136 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2137 | // } |
| 2138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2139 | RValue<Byte8> operator+=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2140 | { |
| 2141 | return lhs = lhs + rhs; |
| 2142 | } |
| 2143 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2144 | RValue<Byte8> operator-=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2145 | { |
| 2146 | return lhs = lhs - rhs; |
| 2147 | } |
| 2148 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2149 | // RValue<Byte8> operator*=(const Byte8 &lhs, RValue<Byte8> rhs) |
| 2150 | // { |
| 2151 | // return lhs = lhs * rhs; |
| 2152 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2154 | // RValue<Byte8> operator/=(const Byte8 &lhs, RValue<Byte8> rhs) |
| 2155 | // { |
| 2156 | // return lhs = lhs / rhs; |
| 2157 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2158 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2159 | // RValue<Byte8> operator%=(const Byte8 &lhs, RValue<Byte8> rhs) |
| 2160 | // { |
| 2161 | // return lhs = lhs % rhs; |
| 2162 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2163 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2164 | RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2165 | { |
| 2166 | return lhs = lhs & rhs; |
| 2167 | } |
| 2168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2169 | RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2170 | { |
| 2171 | return lhs = lhs | rhs; |
| 2172 | } |
| 2173 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2174 | RValue<Byte8> operator^=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2175 | { |
| 2176 | return lhs = lhs ^ rhs; |
| 2177 | } |
| 2178 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2179 | // RValue<Byte8> operator<<=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2180 | // { |
| 2181 | // return lhs = lhs << rhs; |
| 2182 | // } |
| 2183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2184 | // RValue<Byte8> operator>>=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2185 | // { |
| 2186 | // return lhs = lhs >> rhs; |
| 2187 | // } |
| 2188 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2189 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2190 | // { |
| 2191 | // return val; |
| 2192 | // } |
| 2193 | |
| 2194 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2195 | // { |
| 2196 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2197 | // } |
| 2198 | |
| 2199 | RValue<Byte8> operator~(RValue<Byte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2200 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2201 | if(CPUID::supportsMMX2()) |
| 2202 | { |
| 2203 | return val ^ Byte8(0xFFFFFFFFFFFFFFFF); |
| 2204 | } |
| 2205 | else |
| 2206 | { |
| 2207 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2208 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2209 | } |
| 2210 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2211 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2212 | { |
| 2213 | return x86::paddusb(x, y); |
| 2214 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2215 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2216 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2217 | { |
| 2218 | return x86::psubusb(x, y); |
| 2219 | } |
| 2220 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2221 | RValue<Short4> Unpack(RValue<Byte4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2222 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2223 | Value *int2 = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), x.value, 0); |
| 2224 | Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2225 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2226 | return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8)); |
| 2227 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2228 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2229 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2230 | { |
| 2231 | if(CPUID::supportsMMX2()) |
| 2232 | { |
| 2233 | return x86::punpcklbw(x, y); |
| 2234 | } |
| 2235 | else |
| 2236 | { |
| 2237 | Constant *shuffle[8]; |
| 2238 | shuffle[0] = Nucleus::createConstantInt(0); |
| 2239 | shuffle[1] = Nucleus::createConstantInt(8); |
| 2240 | shuffle[2] = Nucleus::createConstantInt(1); |
| 2241 | shuffle[3] = Nucleus::createConstantInt(9); |
| 2242 | shuffle[4] = Nucleus::createConstantInt(2); |
| 2243 | shuffle[5] = Nucleus::createConstantInt(10); |
| 2244 | shuffle[6] = Nucleus::createConstantInt(3); |
| 2245 | shuffle[7] = Nucleus::createConstantInt(11); |
| 2246 | |
| 2247 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
| 2248 | |
| 2249 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2250 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2251 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2253 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2254 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2255 | if(CPUID::supportsMMX2()) |
| 2256 | { |
| 2257 | return x86::punpckhbw(x, y); |
| 2258 | } |
| 2259 | else |
| 2260 | { |
| 2261 | Constant *shuffle[8]; |
| 2262 | shuffle[0] = Nucleus::createConstantInt(4); |
| 2263 | shuffle[1] = Nucleus::createConstantInt(12); |
| 2264 | shuffle[2] = Nucleus::createConstantInt(5); |
| 2265 | shuffle[3] = Nucleus::createConstantInt(13); |
| 2266 | shuffle[4] = Nucleus::createConstantInt(6); |
| 2267 | shuffle[5] = Nucleus::createConstantInt(14); |
| 2268 | shuffle[6] = Nucleus::createConstantInt(7); |
| 2269 | shuffle[7] = Nucleus::createConstantInt(15); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2270 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2271 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2273 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2274 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2275 | } |
| 2276 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2277 | RValue<Int> SignMask(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2278 | { |
| 2279 | return x86::pmovmskb(x); |
| 2280 | } |
| 2281 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2282 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2283 | // { |
| 2284 | // return x86::pcmpgtb(x, y); // FIXME: Signedness |
| 2285 | // } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2286 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2287 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2288 | { |
| 2289 | return x86::pcmpeqb(x, y); |
| 2290 | } |
| 2291 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2292 | Type *Byte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2293 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2294 | if(CPUID::supportsMMX2()) |
| 2295 | { |
| 2296 | return MMX::getType(); |
| 2297 | } |
| 2298 | else |
| 2299 | { |
| 2300 | return VectorType::get(Byte::getType(), 8); |
| 2301 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | SByte8::SByte8() |
| 2305 | { |
| 2306 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | SByte8::SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7) |
| 2310 | { |
| 2311 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2312 | |
| 2313 | Constant *constantVector[8]; |
| 2314 | constantVector[0] = Nucleus::createConstantByte(x0); |
| 2315 | constantVector[1] = Nucleus::createConstantByte(x1); |
| 2316 | constantVector[2] = Nucleus::createConstantByte(x2); |
| 2317 | constantVector[3] = Nucleus::createConstantByte(x3); |
| 2318 | constantVector[4] = Nucleus::createConstantByte(x4); |
| 2319 | constantVector[5] = Nucleus::createConstantByte(x5); |
| 2320 | constantVector[6] = Nucleus::createConstantByte(x6); |
| 2321 | constantVector[7] = Nucleus::createConstantByte(x7); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2322 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2323 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2324 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | SByte8::SByte8(int64_t x) |
| 2328 | { |
| 2329 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2330 | |
| 2331 | Constant *constantVector[8]; |
| 2332 | constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0)); |
| 2333 | constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8)); |
| 2334 | constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16)); |
| 2335 | constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24)); |
| 2336 | constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32)); |
| 2337 | constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40)); |
| 2338 | constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48)); |
| 2339 | constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2340 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2341 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2342 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2343 | } |
| 2344 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2345 | SByte8::SByte8(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2346 | { |
| 2347 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2348 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2349 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | SByte8::SByte8(const SByte8 &rhs) |
| 2353 | { |
| 2354 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2355 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2356 | Value *value = rhs.loadValue(); |
| 2357 | storeValue(value); |
| 2358 | } |
| 2359 | |
| 2360 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2361 | { |
| 2362 | // xyzw.parent = this; |
| 2363 | |
| 2364 | Value *value = rhs.loadValue(); |
| 2365 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2366 | } |
| 2367 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2368 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2369 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2370 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2371 | |
| 2372 | return rhs; |
| 2373 | } |
| 2374 | |
| 2375 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const |
| 2376 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2377 | Value *value = rhs.loadValue(); |
| 2378 | storeValue(value); |
| 2379 | |
| 2380 | return RValue<SByte8>(value); |
| 2381 | } |
| 2382 | |
| 2383 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const |
| 2384 | { |
| 2385 | Value *value = rhs.loadValue(); |
| 2386 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2387 | |
| 2388 | return RValue<SByte8>(value); |
| 2389 | } |
| 2390 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2391 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2392 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2393 | if(CPUID::supportsMMX2()) |
| 2394 | { |
| 2395 | return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2396 | } |
| 2397 | else |
| 2398 | { |
| 2399 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2400 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2401 | } |
| 2402 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2403 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2404 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2405 | if(CPUID::supportsMMX2()) |
| 2406 | { |
| 2407 | return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2408 | } |
| 2409 | else |
| 2410 | { |
| 2411 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2412 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2413 | } |
| 2414 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2415 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2416 | // { |
| 2417 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2418 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2419 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2420 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2421 | // { |
| 2422 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2423 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2424 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2425 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2426 | // { |
| 2427 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2428 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2430 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2431 | { |
| 2432 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2433 | } |
| 2434 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2435 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2436 | { |
| 2437 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2438 | } |
| 2439 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2440 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2441 | { |
| 2442 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2443 | } |
| 2444 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2445 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2446 | // { |
| 2447 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2448 | // } |
| 2449 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2450 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2451 | // { |
| 2452 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2453 | // } |
| 2454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2455 | RValue<SByte8> operator+=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2456 | { |
| 2457 | return lhs = lhs + rhs; |
| 2458 | } |
| 2459 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2460 | RValue<SByte8> operator-=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2461 | { |
| 2462 | return lhs = lhs - rhs; |
| 2463 | } |
| 2464 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2465 | // RValue<SByte8> operator*=(const SByte8 &lhs, RValue<SByte8> rhs) |
| 2466 | // { |
| 2467 | // return lhs = lhs * rhs; |
| 2468 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2469 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2470 | // RValue<SByte8> operator/=(const SByte8 &lhs, RValue<SByte8> rhs) |
| 2471 | // { |
| 2472 | // return lhs = lhs / rhs; |
| 2473 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2474 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2475 | // RValue<SByte8> operator%=(const SByte8 &lhs, RValue<SByte8> rhs) |
| 2476 | // { |
| 2477 | // return lhs = lhs % rhs; |
| 2478 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2479 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2480 | RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2481 | { |
| 2482 | return lhs = lhs & rhs; |
| 2483 | } |
| 2484 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2485 | RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2486 | { |
| 2487 | return lhs = lhs | rhs; |
| 2488 | } |
| 2489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2490 | RValue<SByte8> operator^=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2491 | { |
| 2492 | return lhs = lhs ^ rhs; |
| 2493 | } |
| 2494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2495 | // RValue<SByte8> operator<<=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2496 | // { |
| 2497 | // return lhs = lhs << rhs; |
| 2498 | // } |
| 2499 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2500 | // RValue<SByte8> operator>>=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2501 | // { |
| 2502 | // return lhs = lhs >> rhs; |
| 2503 | // } |
| 2504 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2505 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2506 | // { |
| 2507 | // return val; |
| 2508 | // } |
| 2509 | |
| 2510 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2511 | // { |
| 2512 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2513 | // } |
| 2514 | |
| 2515 | RValue<SByte8> operator~(RValue<SByte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2516 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2517 | if(CPUID::supportsMMX2()) |
| 2518 | { |
| 2519 | return val ^ SByte8(0xFFFFFFFFFFFFFFFF); |
| 2520 | } |
| 2521 | else |
| 2522 | { |
| 2523 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2524 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2525 | } |
| 2526 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2527 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2528 | { |
| 2529 | return x86::paddsb(x, y); |
| 2530 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2531 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2532 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2533 | { |
| 2534 | return x86::psubsb(x, y); |
| 2535 | } |
| 2536 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2537 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2538 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2539 | if(CPUID::supportsMMX2()) |
| 2540 | { |
| 2541 | return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y))); |
| 2542 | } |
| 2543 | else |
| 2544 | { |
| 2545 | Constant *shuffle[8]; |
| 2546 | shuffle[0] = Nucleus::createConstantInt(0); |
| 2547 | shuffle[1] = Nucleus::createConstantInt(8); |
| 2548 | shuffle[2] = Nucleus::createConstantInt(1); |
| 2549 | shuffle[3] = Nucleus::createConstantInt(9); |
| 2550 | shuffle[4] = Nucleus::createConstantInt(2); |
| 2551 | shuffle[5] = Nucleus::createConstantInt(10); |
| 2552 | shuffle[6] = Nucleus::createConstantInt(3); |
| 2553 | shuffle[7] = Nucleus::createConstantInt(11); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2554 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2555 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2556 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2557 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2558 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2559 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2560 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2561 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2562 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2563 | if(CPUID::supportsMMX2()) |
| 2564 | { |
| 2565 | return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y))); |
| 2566 | } |
| 2567 | else |
| 2568 | { |
| 2569 | Constant *shuffle[8]; |
| 2570 | shuffle[0] = Nucleus::createConstantInt(4); |
| 2571 | shuffle[1] = Nucleus::createConstantInt(12); |
| 2572 | shuffle[2] = Nucleus::createConstantInt(5); |
| 2573 | shuffle[3] = Nucleus::createConstantInt(13); |
| 2574 | shuffle[4] = Nucleus::createConstantInt(6); |
| 2575 | shuffle[5] = Nucleus::createConstantInt(14); |
| 2576 | shuffle[6] = Nucleus::createConstantInt(7); |
| 2577 | shuffle[7] = Nucleus::createConstantInt(15); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2578 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2579 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2580 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2581 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2582 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2583 | } |
| 2584 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2585 | RValue<Int> SignMask(RValue<SByte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2586 | { |
| 2587 | return x86::pmovmskb(As<Byte8>(x)); |
| 2588 | } |
| 2589 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2590 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2591 | { |
| 2592 | return x86::pcmpgtb(x, y); |
| 2593 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2594 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2595 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2596 | { |
| 2597 | return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y)); |
| 2598 | } |
| 2599 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2600 | Type *SByte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2601 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2602 | if(CPUID::supportsMMX2()) |
| 2603 | { |
| 2604 | return MMX::getType(); |
| 2605 | } |
| 2606 | else |
| 2607 | { |
| 2608 | return VectorType::get(SByte::getType(), 8); |
| 2609 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2610 | } |
| 2611 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2612 | Byte16::Byte16(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2613 | { |
| 2614 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2615 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2616 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | Byte16::Byte16(const Byte16 &rhs) |
| 2620 | { |
| 2621 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2622 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2623 | Value *value = rhs.loadValue(); |
| 2624 | storeValue(value); |
| 2625 | } |
| 2626 | |
| 2627 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2628 | { |
| 2629 | // xyzw.parent = this; |
| 2630 | |
| 2631 | Value *value = rhs.loadValue(); |
| 2632 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2633 | } |
| 2634 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2635 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2636 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2637 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2638 | |
| 2639 | return rhs; |
| 2640 | } |
| 2641 | |
| 2642 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const |
| 2643 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2644 | Value *value = rhs.loadValue(); |
| 2645 | storeValue(value); |
| 2646 | |
| 2647 | return RValue<Byte16>(value); |
| 2648 | } |
| 2649 | |
| 2650 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const |
| 2651 | { |
| 2652 | Value *value = rhs.loadValue(); |
| 2653 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2654 | |
| 2655 | return RValue<Byte16>(value); |
| 2656 | } |
| 2657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2658 | Type *Byte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2659 | { |
| 2660 | return VectorType::get(Byte::getType(), 16); |
| 2661 | } |
| 2662 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2663 | Type *SByte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2664 | { |
| 2665 | return VectorType::get(SByte::getType(), 16); |
| 2666 | } |
| 2667 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2668 | Short4::Short4(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2669 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2670 | Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2671 | Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2672 | |
| 2673 | storeValue(swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2674 | } |
| 2675 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2676 | Short4::Short4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2677 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2678 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 2679 | |
| 2680 | #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd) |
| 2681 | Constant *pack[8]; |
| 2682 | pack[0] = Nucleus::createConstantInt(0); |
| 2683 | pack[1] = Nucleus::createConstantInt(2); |
| 2684 | pack[2] = Nucleus::createConstantInt(4); |
| 2685 | pack[3] = Nucleus::createConstantInt(6); |
| 2686 | |
| 2687 | Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4)); |
| 2688 | #else |
| 2689 | Value *packed; |
| 2690 | |
| 2691 | // FIXME: Use Swizzle<Short8> |
| 2692 | if(!CPUID::supportsSSSE3()) |
| 2693 | { |
| 2694 | Constant *pshuflw[8]; |
| 2695 | pshuflw[0] = Nucleus::createConstantInt(0); |
| 2696 | pshuflw[1] = Nucleus::createConstantInt(2); |
| 2697 | pshuflw[2] = Nucleus::createConstantInt(0); |
| 2698 | pshuflw[3] = Nucleus::createConstantInt(2); |
| 2699 | pshuflw[4] = Nucleus::createConstantInt(4); |
| 2700 | pshuflw[5] = Nucleus::createConstantInt(5); |
| 2701 | pshuflw[6] = Nucleus::createConstantInt(6); |
| 2702 | pshuflw[7] = Nucleus::createConstantInt(7); |
| 2703 | |
| 2704 | Constant *pshufhw[8]; |
| 2705 | pshufhw[0] = Nucleus::createConstantInt(0); |
| 2706 | pshufhw[1] = Nucleus::createConstantInt(1); |
| 2707 | pshufhw[2] = Nucleus::createConstantInt(2); |
| 2708 | pshufhw[3] = Nucleus::createConstantInt(3); |
| 2709 | pshufhw[4] = Nucleus::createConstantInt(4); |
| 2710 | pshufhw[5] = Nucleus::createConstantInt(6); |
| 2711 | pshufhw[6] = Nucleus::createConstantInt(4); |
| 2712 | pshufhw[7] = Nucleus::createConstantInt(6); |
| 2713 | |
| 2714 | Value *shuffle1 = Nucleus::createShuffleVector(short8, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshuflw, 8)); |
| 2715 | Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshufhw, 8)); |
| 2716 | Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType()); |
| 2717 | packed = Nucleus::createSwizzle(int4, 0x88); |
| 2718 | } |
| 2719 | else |
| 2720 | { |
| 2721 | Constant *pshufb[16]; |
| 2722 | pshufb[0] = Nucleus::createConstantInt(0); |
| 2723 | pshufb[1] = Nucleus::createConstantInt(1); |
| 2724 | pshufb[2] = Nucleus::createConstantInt(4); |
| 2725 | pshufb[3] = Nucleus::createConstantInt(5); |
| 2726 | pshufb[4] = Nucleus::createConstantInt(8); |
| 2727 | pshufb[5] = Nucleus::createConstantInt(9); |
| 2728 | pshufb[6] = Nucleus::createConstantInt(12); |
| 2729 | pshufb[7] = Nucleus::createConstantInt(13); |
| 2730 | pshufb[8] = Nucleus::createConstantInt(0); |
| 2731 | pshufb[9] = Nucleus::createConstantInt(1); |
| 2732 | pshufb[10] = Nucleus::createConstantInt(4); |
| 2733 | pshufb[11] = Nucleus::createConstantInt(5); |
| 2734 | pshufb[12] = Nucleus::createConstantInt(8); |
| 2735 | pshufb[13] = Nucleus::createConstantInt(9); |
| 2736 | pshufb[14] = Nucleus::createConstantInt(12); |
| 2737 | pshufb[15] = Nucleus::createConstantInt(13); |
| 2738 | |
| 2739 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2740 | packed = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16)); |
| 2741 | } |
| 2742 | |
| 2743 | #if 0 // FIXME: No optimal instruction selection |
| 2744 | Value *qword2 = Nucleus::createBitCast(packed, Long2::getType()); |
| 2745 | Value *element = Nucleus::createExtractElement(qword2, 0); |
| 2746 | Value *short4 = Nucleus::createBitCast(element, Short4::getType()); |
| 2747 | #else // FIXME: Requires SSE |
| 2748 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2749 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2750 | #endif |
| 2751 | #endif |
| 2752 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2753 | storeValue(short4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2754 | } |
| 2755 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2756 | // Short4::Short4(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2757 | // { |
| 2758 | // } |
| 2759 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2760 | Short4::Short4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2761 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2762 | Int4 v4i32 = Int4(cast); |
| 2763 | v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2764 | |
| 2765 | storeValue(As<Short4>(Int2(v4i32)).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | Short4::Short4() |
| 2769 | { |
| 2770 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2771 | } |
| 2772 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2773 | Short4::Short4(short xyzw) |
| 2774 | { |
| 2775 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2776 | |
| 2777 | Constant *constantVector[4]; |
| 2778 | constantVector[0] = Nucleus::createConstantShort(xyzw); |
| 2779 | constantVector[1] = Nucleus::createConstantShort(xyzw); |
| 2780 | constantVector[2] = Nucleus::createConstantShort(xyzw); |
| 2781 | constantVector[3] = Nucleus::createConstantShort(xyzw); |
| 2782 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
| 2783 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2784 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2785 | } |
| 2786 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2787 | Short4::Short4(short x, short y, short z, short w) |
| 2788 | { |
| 2789 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2790 | |
| 2791 | Constant *constantVector[4]; |
| 2792 | constantVector[0] = Nucleus::createConstantShort(x); |
| 2793 | constantVector[1] = Nucleus::createConstantShort(y); |
| 2794 | constantVector[2] = Nucleus::createConstantShort(z); |
| 2795 | constantVector[3] = Nucleus::createConstantShort(w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2796 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
| 2797 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2798 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2799 | } |
| 2800 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2801 | Short4::Short4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2802 | { |
| 2803 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2804 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2805 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | Short4::Short4(const Short4 &rhs) |
| 2809 | { |
| 2810 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2811 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2812 | Value *value = rhs.loadValue(); |
| 2813 | storeValue(value); |
| 2814 | } |
| 2815 | |
| 2816 | Short4::Short4(const Reference<Short4> &rhs) |
| 2817 | { |
| 2818 | // xyzw.parent = this; |
| 2819 | |
| 2820 | Value *value = rhs.loadValue(); |
| 2821 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2822 | } |
| 2823 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2824 | Short4::Short4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2825 | { |
| 2826 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2827 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2828 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | Short4::Short4(const UShort4 &rhs) |
| 2832 | { |
| 2833 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2834 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2835 | storeValue(rhs.loadValue()); |
| 2836 | } |
| 2837 | |
| 2838 | Short4::Short4(const Reference<UShort4> &rhs) |
| 2839 | { |
| 2840 | // xyzw.parent = this; |
| 2841 | |
| 2842 | storeValue(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2843 | } |
| 2844 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2845 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2846 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2847 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2848 | |
| 2849 | return rhs; |
| 2850 | } |
| 2851 | |
| 2852 | RValue<Short4> Short4::operator=(const Short4 &rhs) const |
| 2853 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2854 | Value *value = rhs.loadValue(); |
| 2855 | storeValue(value); |
| 2856 | |
| 2857 | return RValue<Short4>(value); |
| 2858 | } |
| 2859 | |
| 2860 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const |
| 2861 | { |
| 2862 | Value *value = rhs.loadValue(); |
| 2863 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2864 | |
| 2865 | return RValue<Short4>(value); |
| 2866 | } |
| 2867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2868 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2869 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2870 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2871 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2872 | return RValue<Short4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | RValue<Short4> Short4::operator=(const UShort4 &rhs) const |
| 2876 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2877 | Value *value = rhs.loadValue(); |
| 2878 | storeValue(value); |
| 2879 | |
| 2880 | return RValue<Short4>(value); |
| 2881 | } |
| 2882 | |
| 2883 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const |
| 2884 | { |
| 2885 | Value *value = rhs.loadValue(); |
| 2886 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2887 | |
| 2888 | return RValue<Short4>(value); |
| 2889 | } |
| 2890 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2891 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2892 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2893 | if(CPUID::supportsMMX2()) |
| 2894 | { |
| 2895 | return x86::paddw(lhs, rhs); |
| 2896 | } |
| 2897 | else |
| 2898 | { |
| 2899 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2900 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2901 | } |
| 2902 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2903 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2904 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2905 | if(CPUID::supportsMMX2()) |
| 2906 | { |
| 2907 | return x86::psubw(lhs, rhs); |
| 2908 | } |
| 2909 | else |
| 2910 | { |
| 2911 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2912 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2915 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2916 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2917 | if(CPUID::supportsMMX2()) |
| 2918 | { |
| 2919 | return x86::pmullw(lhs, rhs); |
| 2920 | } |
| 2921 | else |
| 2922 | { |
| 2923 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2924 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2925 | } |
| 2926 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2927 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2928 | // { |
| 2929 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2930 | // } |
| 2931 | |
| 2932 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2933 | // { |
| 2934 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2935 | // } |
| 2936 | |
| 2937 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2938 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2939 | if(CPUID::supportsMMX2()) |
| 2940 | { |
| 2941 | return x86::pand(lhs, rhs); |
| 2942 | } |
| 2943 | else |
| 2944 | { |
| 2945 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2946 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2947 | } |
| 2948 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2949 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2950 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2951 | if(CPUID::supportsMMX2()) |
| 2952 | { |
| 2953 | return x86::por(lhs, rhs); |
| 2954 | } |
| 2955 | else |
| 2956 | { |
| 2957 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2958 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2959 | } |
| 2960 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2961 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2962 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2963 | if(CPUID::supportsMMX2()) |
| 2964 | { |
| 2965 | return x86::pxor(lhs, rhs); |
| 2966 | } |
| 2967 | else |
| 2968 | { |
| 2969 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2970 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2971 | } |
| 2972 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2973 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2974 | { |
| 2975 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2976 | |
| 2977 | return x86::psllw(lhs, rhs); |
| 2978 | } |
| 2979 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2980 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2981 | { |
| 2982 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2983 | |
| 2984 | return x86::psraw(lhs, rhs); |
| 2985 | } |
| 2986 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2987 | RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2988 | { |
| 2989 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2990 | |
| 2991 | return x86::psllw(lhs, rhs); |
| 2992 | } |
| 2993 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2994 | RValue<Short4> operator>>(RValue<Short4> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2995 | { |
| 2996 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2997 | |
| 2998 | return x86::psraw(lhs, rhs); |
| 2999 | } |
| 3000 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3001 | RValue<Short4> operator+=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3002 | { |
| 3003 | return lhs = lhs + rhs; |
| 3004 | } |
| 3005 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3006 | RValue<Short4> operator-=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3007 | { |
| 3008 | return lhs = lhs - rhs; |
| 3009 | } |
| 3010 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3011 | RValue<Short4> operator*=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3012 | { |
| 3013 | return lhs = lhs * rhs; |
| 3014 | } |
| 3015 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3016 | // RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs) |
| 3017 | // { |
| 3018 | // return lhs = lhs / rhs; |
| 3019 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3020 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3021 | // RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs) |
| 3022 | // { |
| 3023 | // return lhs = lhs % rhs; |
| 3024 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3025 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3026 | RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3027 | { |
| 3028 | return lhs = lhs & rhs; |
| 3029 | } |
| 3030 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3031 | RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3032 | { |
| 3033 | return lhs = lhs | rhs; |
| 3034 | } |
| 3035 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3036 | RValue<Short4> operator^=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3037 | { |
| 3038 | return lhs = lhs ^ rhs; |
| 3039 | } |
| 3040 | |
| 3041 | RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs) |
| 3042 | { |
| 3043 | return lhs = lhs << rhs; |
| 3044 | } |
| 3045 | |
| 3046 | RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs) |
| 3047 | { |
| 3048 | return lhs = lhs >> rhs; |
| 3049 | } |
| 3050 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3051 | RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3052 | { |
| 3053 | return lhs = lhs << rhs; |
| 3054 | } |
| 3055 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3056 | RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3057 | { |
| 3058 | return lhs = lhs >> rhs; |
| 3059 | } |
| 3060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3061 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3062 | // { |
| 3063 | // return val; |
| 3064 | // } |
| 3065 | |
| 3066 | RValue<Short4> operator-(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3067 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3068 | if(CPUID::supportsMMX2()) |
| 3069 | { |
| 3070 | return Short4(0, 0, 0, 0) - val; |
| 3071 | } |
| 3072 | else |
| 3073 | { |
| 3074 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
| 3075 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3076 | } |
| 3077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3078 | RValue<Short4> operator~(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3079 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3080 | if(CPUID::supportsMMX2()) |
| 3081 | { |
| 3082 | return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu); |
| 3083 | } |
| 3084 | else |
| 3085 | { |
| 3086 | return RValue<Short4>(Nucleus::createNot(val.value)); |
| 3087 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3088 | } |
| 3089 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3090 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3091 | { |
| 3092 | RValue<Int4> v4i32 = x86::cvtps2dq(cast); |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 3093 | RValue<Short8> v8i16 = x86::packssdw(v4i32, v4i32); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3094 | |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 3095 | return As<Short4>(Int2(As<Int4>(v8i16))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3096 | } |
| 3097 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3098 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3099 | { |
| 3100 | return x86::pmaxsw(x, y); |
| 3101 | } |
| 3102 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3103 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3104 | { |
| 3105 | return x86::pminsw(x, y); |
| 3106 | } |
| 3107 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3108 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3109 | { |
| 3110 | return x86::paddsw(x, y); |
| 3111 | } |
| 3112 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3113 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3114 | { |
| 3115 | return x86::psubsw(x, y); |
| 3116 | } |
| 3117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3118 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3119 | { |
| 3120 | return x86::pmulhw(x, y); |
| 3121 | } |
| 3122 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3123 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3124 | { |
| 3125 | return x86::pmaddwd(x, y); |
| 3126 | } |
| 3127 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3128 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3129 | { |
| 3130 | return x86::packsswb(x, y); |
| 3131 | } |
| 3132 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3133 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3134 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3135 | if(CPUID::supportsMMX2()) |
| 3136 | { |
| 3137 | return x86::punpcklwd(x, y); |
| 3138 | } |
| 3139 | else |
| 3140 | { |
| 3141 | Constant *shuffle[4]; |
| 3142 | shuffle[0] = Nucleus::createConstantInt(0); |
| 3143 | shuffle[1] = Nucleus::createConstantInt(4); |
| 3144 | shuffle[2] = Nucleus::createConstantInt(1); |
| 3145 | shuffle[3] = Nucleus::createConstantInt(5); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3146 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3147 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3148 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3149 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 3150 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3151 | } |
| 3152 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3153 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3154 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3155 | if(CPUID::supportsMMX2()) |
| 3156 | { |
| 3157 | return x86::punpckhwd(x, y); |
| 3158 | } |
| 3159 | else |
| 3160 | { |
| 3161 | Constant *shuffle[4]; |
| 3162 | shuffle[0] = Nucleus::createConstantInt(2); |
| 3163 | shuffle[1] = Nucleus::createConstantInt(6); |
| 3164 | shuffle[2] = Nucleus::createConstantInt(3); |
| 3165 | shuffle[3] = Nucleus::createConstantInt(7); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3166 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3167 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3169 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 3170 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3171 | } |
| 3172 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3173 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3174 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3175 | if(CPUID::supportsMMX2()) |
| 3176 | { |
| 3177 | return x86::pshufw(x, select); |
| 3178 | } |
| 3179 | else |
| 3180 | { |
| 3181 | return RValue<Short4>(Nucleus::createSwizzle(x.value, select)); |
| 3182 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3183 | } |
| 3184 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3185 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3186 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3187 | if(CPUID::supportsMMX2()) |
| 3188 | { |
| 3189 | return x86::pinsrw(val, Int(element), i); |
| 3190 | } |
| 3191 | else |
| 3192 | { |
| 3193 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 3194 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3195 | } |
| 3196 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3197 | RValue<Short> Extract(RValue<Short4> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3198 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3199 | if(CPUID::supportsMMX2()) |
| 3200 | { |
| 3201 | return Short(x86::pextrw(val, i)); |
| 3202 | } |
| 3203 | else |
| 3204 | { |
| 3205 | return RValue<Short>(Nucleus::createExtractElement(val.value, i)); |
| 3206 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3207 | } |
| 3208 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3209 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3210 | { |
| 3211 | return x86::pcmpgtw(x, y); |
| 3212 | } |
| 3213 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3214 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3215 | { |
| 3216 | return x86::pcmpeqw(x, y); |
| 3217 | } |
| 3218 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3219 | Type *Short4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3220 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3221 | if(CPUID::supportsMMX2()) |
| 3222 | { |
| 3223 | return MMX::getType(); |
| 3224 | } |
| 3225 | else |
| 3226 | { |
| 3227 | return VectorType::get(Short::getType(), 4); |
| 3228 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3229 | } |
| 3230 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3231 | UShort4::UShort4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3232 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3233 | *this = Short4(cast); |
| 3234 | } |
| 3235 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3236 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3237 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3238 | Float4 sat; |
| 3239 | |
| 3240 | if(saturate) |
| 3241 | { |
| 3242 | if(CPUID::supportsSSE4_1()) |
| 3243 | { |
| 3244 | sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation |
| 3245 | } |
| 3246 | else |
| 3247 | { |
| 3248 | sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)); |
| 3249 | } |
| 3250 | } |
| 3251 | else |
| 3252 | { |
| 3253 | sat = cast; |
| 3254 | } |
| 3255 | |
| 3256 | Int4 int4(sat); |
| 3257 | |
| 3258 | if(!saturate || !CPUID::supportsSSE4_1()) |
| 3259 | { |
| 3260 | *this = Short4(Int4(int4)); |
| 3261 | } |
| 3262 | else |
| 3263 | { |
| 3264 | *this = As<Short4>(Int2(As<Int4>(x86::packusdw(As<UInt4>(int4), As<UInt4>(int4))))); |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | UShort4::UShort4() |
| 3269 | { |
| 3270 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3271 | } |
| 3272 | |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 3273 | UShort4::UShort4(unsigned short xyzw) |
| 3274 | { |
| 3275 | // xyzw.parent = this; |
| 3276 | |
| 3277 | Constant *constantVector[4]; |
| 3278 | constantVector[0] = Nucleus::createConstantShort(xyzw); |
| 3279 | constantVector[1] = Nucleus::createConstantShort(xyzw); |
| 3280 | constantVector[2] = Nucleus::createConstantShort(xyzw); |
| 3281 | constantVector[3] = Nucleus::createConstantShort(xyzw); |
| 3282 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
| 3283 | |
| 3284 | storeValue(Nucleus::createBitCast(vector, getType())); |
| 3285 | } |
| 3286 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3287 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3288 | { |
| 3289 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3290 | |
| 3291 | Constant *constantVector[4]; |
| 3292 | constantVector[0] = Nucleus::createConstantShort(x); |
| 3293 | constantVector[1] = Nucleus::createConstantShort(y); |
| 3294 | constantVector[2] = Nucleus::createConstantShort(z); |
| 3295 | constantVector[3] = Nucleus::createConstantShort(w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3296 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3297 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3298 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3299 | } |
| 3300 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3301 | UShort4::UShort4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3302 | { |
| 3303 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3304 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3305 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | UShort4::UShort4(const UShort4 &rhs) |
| 3309 | { |
| 3310 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3311 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3312 | Value *value = rhs.loadValue(); |
| 3313 | storeValue(value); |
| 3314 | } |
| 3315 | |
| 3316 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3317 | { |
| 3318 | // xyzw.parent = this; |
| 3319 | |
| 3320 | Value *value = rhs.loadValue(); |
| 3321 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3322 | } |
| 3323 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3324 | UShort4::UShort4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3325 | { |
| 3326 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3327 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3328 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | UShort4::UShort4(const Short4 &rhs) |
| 3332 | { |
| 3333 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3334 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3335 | Value *value = rhs.loadValue(); |
| 3336 | storeValue(value); |
| 3337 | } |
| 3338 | |
| 3339 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3340 | { |
| 3341 | // xyzw.parent = this; |
| 3342 | |
| 3343 | Value *value = rhs.loadValue(); |
| 3344 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3345 | } |
| 3346 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3347 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3348 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3349 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3350 | |
| 3351 | return rhs; |
| 3352 | } |
| 3353 | |
| 3354 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const |
| 3355 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3356 | Value *value = rhs.loadValue(); |
| 3357 | storeValue(value); |
| 3358 | |
| 3359 | return RValue<UShort4>(value); |
| 3360 | } |
| 3361 | |
| 3362 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const |
| 3363 | { |
| 3364 | Value *value = rhs.loadValue(); |
| 3365 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3366 | |
| 3367 | return RValue<UShort4>(value); |
| 3368 | } |
| 3369 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3370 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3371 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3372 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3373 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3374 | return RValue<UShort4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) const |
| 3378 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3379 | Value *value = rhs.loadValue(); |
| 3380 | storeValue(value); |
| 3381 | |
| 3382 | return RValue<UShort4>(value); |
| 3383 | } |
| 3384 | |
| 3385 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const |
| 3386 | { |
| 3387 | Value *value = rhs.loadValue(); |
| 3388 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3389 | |
| 3390 | return RValue<UShort4>(value); |
| 3391 | } |
| 3392 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3393 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3394 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3395 | if(CPUID::supportsMMX2()) |
| 3396 | { |
| 3397 | return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3398 | } |
| 3399 | else |
| 3400 | { |
| 3401 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3402 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3403 | } |
| 3404 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3405 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3406 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3407 | if(CPUID::supportsMMX2()) |
| 3408 | { |
| 3409 | return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3410 | } |
| 3411 | else |
| 3412 | { |
| 3413 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3414 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3415 | } |
| 3416 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3417 | |
| 3418 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3419 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3420 | if(CPUID::supportsMMX2()) |
| 3421 | { |
| 3422 | return As<UShort4>(x86::pmullw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3423 | } |
| 3424 | else |
| 3425 | { |
| 3426 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3427 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3428 | } |
| 3429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3430 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3431 | { |
| 3432 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3433 | |
| 3434 | return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs)); |
| 3435 | } |
| 3436 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3437 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3438 | { |
| 3439 | // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 3440 | |
| 3441 | return x86::psrlw(lhs, rhs); |
| 3442 | } |
| 3443 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3444 | RValue<UShort4> operator<<(RValue<UShort4> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3445 | { |
| 3446 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3447 | |
| 3448 | return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs)); |
| 3449 | } |
| 3450 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3451 | RValue<UShort4> operator>>(RValue<UShort4> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3452 | { |
| 3453 | // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 3454 | |
| 3455 | return x86::psrlw(lhs, rhs); |
| 3456 | } |
| 3457 | |
| 3458 | RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs) |
| 3459 | { |
| 3460 | return lhs = lhs << rhs; |
| 3461 | } |
| 3462 | |
| 3463 | RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs) |
| 3464 | { |
| 3465 | return lhs = lhs >> rhs; |
| 3466 | } |
| 3467 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3468 | RValue<UShort4> operator<<=(const UShort4 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3469 | { |
| 3470 | return lhs = lhs << rhs; |
| 3471 | } |
| 3472 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3473 | RValue<UShort4> operator>>=(const UShort4 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3474 | { |
| 3475 | return lhs = lhs >> rhs; |
| 3476 | } |
| 3477 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3478 | RValue<UShort4> operator~(RValue<UShort4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3479 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3480 | if(CPUID::supportsMMX2()) |
| 3481 | { |
| 3482 | return As<UShort4>(As<Short4>(val) ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu)); |
| 3483 | } |
| 3484 | else |
| 3485 | { |
| 3486 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
| 3487 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3488 | } |
| 3489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3490 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3491 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3492 | 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 Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3493 | } |
| 3494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3495 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3496 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3497 | 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 Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3498 | } |
| 3499 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3500 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3501 | { |
| 3502 | return x86::paddusw(x, y); |
| 3503 | } |
| 3504 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3505 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3506 | { |
| 3507 | return x86::psubusw(x, y); |
| 3508 | } |
| 3509 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3510 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3511 | { |
| 3512 | return x86::pmulhuw(x, y); |
| 3513 | } |
| 3514 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3515 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3516 | { |
| 3517 | return x86::pavgw(x, y); |
| 3518 | } |
| 3519 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3520 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3521 | { |
| 3522 | return x86::packuswb(x, y); |
| 3523 | } |
| 3524 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3525 | Type *UShort4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3526 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3527 | if(CPUID::supportsMMX2()) |
| 3528 | { |
| 3529 | return MMX::getType(); |
| 3530 | } |
| 3531 | else |
| 3532 | { |
| 3533 | return VectorType::get(UShort::getType(), 4); |
| 3534 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3538 | { |
| 3539 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3540 | |
| 3541 | Constant *constantVector[8]; |
| 3542 | constantVector[0] = Nucleus::createConstantShort(c0); |
| 3543 | constantVector[1] = Nucleus::createConstantShort(c1); |
| 3544 | constantVector[2] = Nucleus::createConstantShort(c2); |
| 3545 | constantVector[3] = Nucleus::createConstantShort(c3); |
| 3546 | constantVector[4] = Nucleus::createConstantShort(c4); |
| 3547 | constantVector[5] = Nucleus::createConstantShort(c5); |
| 3548 | constantVector[6] = Nucleus::createConstantShort(c6); |
| 3549 | constantVector[7] = Nucleus::createConstantShort(c7); |
| 3550 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3551 | storeValue(Nucleus::createConstantVector(constantVector, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3552 | } |
| 3553 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3554 | Short8::Short8(RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3555 | { |
| 3556 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3557 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3558 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3559 | } |
| 3560 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3561 | Short8::Short8(const Reference<Short8> &rhs) |
| 3562 | { |
| 3563 | // xyzw.parent = this; |
| 3564 | |
| 3565 | Value *value = rhs.loadValue(); |
| 3566 | storeValue(value); |
| 3567 | } |
| 3568 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3569 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3570 | { |
| 3571 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 3572 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 3573 | |
| 3574 | Value *long2 = UndefValue::get(Long2::getType()); |
| 3575 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 3576 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 3577 | Value *short8 = Nucleus::createBitCast(long2, Short8::getType()); |
| 3578 | |
| 3579 | storeValue(short8); |
| 3580 | } |
| 3581 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3582 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3583 | { |
| 3584 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3585 | } |
| 3586 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3587 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3588 | { |
| 3589 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3590 | } |
| 3591 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3592 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3593 | { |
| 3594 | return x86::psllw(lhs, rhs); // FIXME: Fallback required |
| 3595 | } |
| 3596 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3597 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3598 | { |
| 3599 | return x86::psraw(lhs, rhs); // FIXME: Fallback required |
| 3600 | } |
| 3601 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3602 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3603 | { |
| 3604 | return x86::pmaddwd(x, y); // FIXME: Fallback required |
| 3605 | } |
| 3606 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 3607 | RValue<Int4> Abs(RValue<Int4> x) |
| 3608 | { |
| 3609 | if(CPUID::supportsSSSE3()) |
| 3610 | { |
| 3611 | return x86::pabsd(x); |
| 3612 | } |
| 3613 | else |
| 3614 | { |
| 3615 | Int4 mask = (x >> 31); |
| 3616 | return (mask ^ x) - mask; |
| 3617 | } |
| 3618 | } |
| 3619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3620 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3621 | { |
| 3622 | return x86::pmulhw(x, y); // FIXME: Fallback required |
| 3623 | } |
| 3624 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3625 | Type *Short8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3626 | { |
| 3627 | return VectorType::get(Short::getType(), 8); |
| 3628 | } |
| 3629 | |
| 3630 | 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) |
| 3631 | { |
| 3632 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3633 | |
| 3634 | Constant *constantVector[8]; |
| 3635 | constantVector[0] = Nucleus::createConstantShort(c0); |
| 3636 | constantVector[1] = Nucleus::createConstantShort(c1); |
| 3637 | constantVector[2] = Nucleus::createConstantShort(c2); |
| 3638 | constantVector[3] = Nucleus::createConstantShort(c3); |
| 3639 | constantVector[4] = Nucleus::createConstantShort(c4); |
| 3640 | constantVector[5] = Nucleus::createConstantShort(c5); |
| 3641 | constantVector[6] = Nucleus::createConstantShort(c6); |
| 3642 | constantVector[7] = Nucleus::createConstantShort(c7); |
| 3643 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3644 | storeValue(Nucleus::createConstantVector(constantVector, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3645 | } |
| 3646 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3647 | UShort8::UShort8(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3648 | { |
| 3649 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3650 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3651 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3652 | } |
| 3653 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3654 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3655 | { |
| 3656 | // xyzw.parent = this; |
| 3657 | |
| 3658 | Value *value = rhs.loadValue(); |
| 3659 | storeValue(value); |
| 3660 | } |
| 3661 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3662 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3663 | { |
| 3664 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 3665 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 3666 | |
| 3667 | Value *long2 = UndefValue::get(Long2::getType()); |
| 3668 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 3669 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 3670 | Value *short8 = Nucleus::createBitCast(long2, Short8::getType()); |
| 3671 | |
| 3672 | storeValue(short8); |
| 3673 | } |
| 3674 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3675 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3676 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3677 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3678 | |
| 3679 | return rhs; |
| 3680 | } |
| 3681 | |
| 3682 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const |
| 3683 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3684 | Value *value = rhs.loadValue(); |
| 3685 | storeValue(value); |
| 3686 | |
| 3687 | return RValue<UShort8>(value); |
| 3688 | } |
| 3689 | |
| 3690 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) const |
| 3691 | { |
| 3692 | Value *value = rhs.loadValue(); |
| 3693 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3694 | |
| 3695 | return RValue<UShort8>(value); |
| 3696 | } |
| 3697 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3698 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3699 | { |
| 3700 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3701 | } |
| 3702 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3703 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3704 | { |
| 3705 | return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required |
| 3706 | } |
| 3707 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3708 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3709 | { |
| 3710 | return x86::psrlw(lhs, rhs); // FIXME: Fallback required |
| 3711 | } |
| 3712 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3713 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3714 | { |
| 3715 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3716 | } |
| 3717 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3718 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3719 | { |
| 3720 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3721 | } |
| 3722 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3723 | RValue<UShort8> operator+=(const UShort8 &lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3724 | { |
| 3725 | return lhs = lhs + rhs; |
| 3726 | } |
| 3727 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3728 | RValue<UShort8> operator~(RValue<UShort8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3729 | { |
| 3730 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3731 | } |
| 3732 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3733 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3734 | { |
| 3735 | Constant *pshufb[16]; |
| 3736 | pshufb[0] = Nucleus::createConstantInt(select0 + 0); |
| 3737 | pshufb[1] = Nucleus::createConstantInt(select0 + 1); |
| 3738 | pshufb[2] = Nucleus::createConstantInt(select1 + 0); |
| 3739 | pshufb[3] = Nucleus::createConstantInt(select1 + 1); |
| 3740 | pshufb[4] = Nucleus::createConstantInt(select2 + 0); |
| 3741 | pshufb[5] = Nucleus::createConstantInt(select2 + 1); |
| 3742 | pshufb[6] = Nucleus::createConstantInt(select3 + 0); |
| 3743 | pshufb[7] = Nucleus::createConstantInt(select3 + 1); |
| 3744 | pshufb[8] = Nucleus::createConstantInt(select4 + 0); |
| 3745 | pshufb[9] = Nucleus::createConstantInt(select4 + 1); |
| 3746 | pshufb[10] = Nucleus::createConstantInt(select5 + 0); |
| 3747 | pshufb[11] = Nucleus::createConstantInt(select5 + 1); |
| 3748 | pshufb[12] = Nucleus::createConstantInt(select6 + 0); |
| 3749 | pshufb[13] = Nucleus::createConstantInt(select6 + 1); |
| 3750 | pshufb[14] = Nucleus::createConstantInt(select7 + 0); |
| 3751 | pshufb[15] = Nucleus::createConstantInt(select7 + 1); |
| 3752 | |
| 3753 | Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType()); |
| 3754 | Value *shuffle = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16)); |
| 3755 | Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType()); |
| 3756 | |
| 3757 | return RValue<UShort8>(short8); |
| 3758 | } |
| 3759 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3760 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3761 | { |
| 3762 | return x86::pmulhuw(x, y); // FIXME: Fallback required |
| 3763 | } |
| 3764 | |
| 3765 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3766 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3767 | // { |
| 3768 | // Constant *pshufb[16]; |
| 3769 | // pshufb[0] = Nucleus::createConstantInt(element + 0); |
| 3770 | // pshufb[1] = Nucleus::createConstantInt(element + 0); |
| 3771 | // pshufb[2] = Nucleus::createConstantInt(element + 4); |
| 3772 | // pshufb[3] = Nucleus::createConstantInt(element + 4); |
| 3773 | // pshufb[4] = Nucleus::createConstantInt(element + 8); |
| 3774 | // pshufb[5] = Nucleus::createConstantInt(element + 8); |
| 3775 | // pshufb[6] = Nucleus::createConstantInt(element + 12); |
| 3776 | // pshufb[7] = Nucleus::createConstantInt(element + 12); |
| 3777 | // pshufb[8] = Nucleus::createConstantInt(element + 16); |
| 3778 | // pshufb[9] = Nucleus::createConstantInt(element + 16); |
| 3779 | // pshufb[10] = Nucleus::createConstantInt(element + 20); |
| 3780 | // pshufb[11] = Nucleus::createConstantInt(element + 20); |
| 3781 | // pshufb[12] = Nucleus::createConstantInt(element + 24); |
| 3782 | // pshufb[13] = Nucleus::createConstantInt(element + 24); |
| 3783 | // pshufb[14] = Nucleus::createConstantInt(element + 28); |
| 3784 | // pshufb[15] = Nucleus::createConstantInt(element + 28); |
| 3785 | // |
| 3786 | // Value *shuffle = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(pshufb, 16)); |
| 3787 | // Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType()); |
| 3788 | // |
| 3789 | // return RValue<UShort8>(short8); |
| 3790 | // } |
| 3791 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3792 | Type *UShort8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3793 | { |
| 3794 | return VectorType::get(UShort::getType(), 8); |
| 3795 | } |
| 3796 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3797 | Int::Int(Argument<Int> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3798 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3799 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3800 | } |
| 3801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3802 | Int::Int(RValue<Byte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3803 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3804 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3805 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3806 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3807 | } |
| 3808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3809 | Int::Int(RValue<SByte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3810 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3811 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3812 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3813 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3814 | } |
| 3815 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3816 | Int::Int(RValue<Short> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3817 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3818 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3819 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3820 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3821 | } |
| 3822 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3823 | Int::Int(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3824 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3825 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3826 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3827 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3828 | } |
| 3829 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3830 | Int::Int(RValue<Int2> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3831 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3832 | *this = Extract(cast, 0); |
| 3833 | } |
| 3834 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3835 | Int::Int(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3836 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3837 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3838 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3839 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3840 | } |
| 3841 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3842 | Int::Int(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3843 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3844 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3845 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3846 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | Int::Int() |
| 3850 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | Int::Int(int x) |
| 3854 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3855 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3856 | } |
| 3857 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3858 | Int::Int(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3859 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3860 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3861 | } |
| 3862 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3863 | Int::Int(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3864 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3865 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | Int::Int(const Int &rhs) |
| 3869 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3870 | Value *value = rhs.loadValue(); |
| 3871 | storeValue(value); |
| 3872 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3873 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3874 | Int::Int(const Reference<Int> &rhs) |
| 3875 | { |
| 3876 | Value *value = rhs.loadValue(); |
| 3877 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | Int::Int(const UInt &rhs) |
| 3881 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3882 | Value *value = rhs.loadValue(); |
| 3883 | storeValue(value); |
| 3884 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3885 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3886 | Int::Int(const Reference<UInt> &rhs) |
| 3887 | { |
| 3888 | Value *value = rhs.loadValue(); |
| 3889 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | RValue<Int> Int::operator=(int rhs) const |
| 3893 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3894 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3895 | } |
| 3896 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3897 | RValue<Int> Int::operator=(RValue<Int> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3898 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3899 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3900 | |
| 3901 | return rhs; |
| 3902 | } |
| 3903 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3904 | RValue<Int> Int::operator=(RValue<UInt> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3905 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3906 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3907 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3908 | return RValue<Int>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | RValue<Int> Int::operator=(const Int &rhs) const |
| 3912 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3913 | Value *value = rhs.loadValue(); |
| 3914 | storeValue(value); |
| 3915 | |
| 3916 | return RValue<Int>(value); |
| 3917 | } |
| 3918 | |
| 3919 | RValue<Int> Int::operator=(const Reference<Int> &rhs) const |
| 3920 | { |
| 3921 | Value *value = rhs.loadValue(); |
| 3922 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3923 | |
| 3924 | return RValue<Int>(value); |
| 3925 | } |
| 3926 | |
| 3927 | RValue<Int> Int::operator=(const UInt &rhs) const |
| 3928 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3929 | Value *value = rhs.loadValue(); |
| 3930 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3931 | |
| 3932 | return RValue<Int>(value); |
| 3933 | } |
| 3934 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3935 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3936 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3937 | Value *value = rhs.loadValue(); |
| 3938 | storeValue(value); |
| 3939 | |
| 3940 | return RValue<Int>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3941 | } |
| 3942 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3943 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3944 | { |
| 3945 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3946 | } |
| 3947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3948 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3949 | { |
| 3950 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3951 | } |
| 3952 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3953 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3954 | { |
| 3955 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3956 | } |
| 3957 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3958 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3959 | { |
| 3960 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3961 | } |
| 3962 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3963 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3964 | { |
| 3965 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3966 | } |
| 3967 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3968 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3969 | { |
| 3970 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3971 | } |
| 3972 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3973 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3974 | { |
| 3975 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3976 | } |
| 3977 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3978 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3979 | { |
| 3980 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3981 | } |
| 3982 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3983 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3984 | { |
| 3985 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3986 | } |
| 3987 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3988 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3989 | { |
| 3990 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3991 | } |
| 3992 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3993 | RValue<Int> operator+=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3994 | { |
| 3995 | return lhs = lhs + rhs; |
| 3996 | } |
| 3997 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3998 | RValue<Int> operator-=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3999 | { |
| 4000 | return lhs = lhs - rhs; |
| 4001 | } |
| 4002 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4003 | RValue<Int> operator*=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4004 | { |
| 4005 | return lhs = lhs * rhs; |
| 4006 | } |
| 4007 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4008 | RValue<Int> operator/=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4009 | { |
| 4010 | return lhs = lhs / rhs; |
| 4011 | } |
| 4012 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4013 | RValue<Int> operator%=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4014 | { |
| 4015 | return lhs = lhs % rhs; |
| 4016 | } |
| 4017 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4018 | RValue<Int> operator&=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4019 | { |
| 4020 | return lhs = lhs & rhs; |
| 4021 | } |
| 4022 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4023 | RValue<Int> operator|=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4024 | { |
| 4025 | return lhs = lhs | rhs; |
| 4026 | } |
| 4027 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4028 | RValue<Int> operator^=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4029 | { |
| 4030 | return lhs = lhs ^ rhs; |
| 4031 | } |
| 4032 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4033 | RValue<Int> operator<<=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4034 | { |
| 4035 | return lhs = lhs << rhs; |
| 4036 | } |
| 4037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4038 | RValue<Int> operator>>=(const Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4039 | { |
| 4040 | return lhs = lhs >> rhs; |
| 4041 | } |
| 4042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4043 | RValue<Int> operator+(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4044 | { |
| 4045 | return val; |
| 4046 | } |
| 4047 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4048 | RValue<Int> operator-(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4049 | { |
| 4050 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4051 | } |
| 4052 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4053 | RValue<Int> operator~(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4054 | { |
| 4055 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4056 | } |
| 4057 | |
| 4058 | RValue<Int> operator++(const Int &val, int) // Post-increment |
| 4059 | { |
| 4060 | RValue<Int> res = val; |
| 4061 | |
| 4062 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4063 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4064 | |
| 4065 | return res; |
| 4066 | } |
| 4067 | |
| 4068 | const Int &operator++(const Int &val) // Pre-increment |
| 4069 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4070 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1)); |
| 4071 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4072 | |
| 4073 | return val; |
| 4074 | } |
| 4075 | |
| 4076 | RValue<Int> operator--(const Int &val, int) // Post-decrement |
| 4077 | { |
| 4078 | RValue<Int> res = val; |
| 4079 | |
| 4080 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4081 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4082 | |
| 4083 | return res; |
| 4084 | } |
| 4085 | |
| 4086 | const Int &operator--(const Int &val) // Pre-decrement |
| 4087 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4088 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1)); |
| 4089 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4090 | |
| 4091 | return val; |
| 4092 | } |
| 4093 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4094 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4095 | { |
| 4096 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4097 | } |
| 4098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4099 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4100 | { |
| 4101 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4102 | } |
| 4103 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4104 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4105 | { |
| 4106 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4107 | } |
| 4108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4109 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4110 | { |
| 4111 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4112 | } |
| 4113 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4114 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4115 | { |
| 4116 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4117 | } |
| 4118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4119 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4120 | { |
| 4121 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4122 | } |
| 4123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4124 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4125 | { |
| 4126 | return IfThenElse(x > y, x, y); |
| 4127 | } |
| 4128 | |
| 4129 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4130 | { |
| 4131 | return IfThenElse(x < y, x, y); |
| 4132 | } |
| 4133 | |
| 4134 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4135 | { |
| 4136 | return Min(Max(x, min), max); |
| 4137 | } |
| 4138 | |
| 4139 | RValue<Int> RoundInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4140 | { |
| 4141 | return x86::cvtss2si(cast); |
| 4142 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4143 | // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4144 | } |
| 4145 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4146 | Type *Int::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4147 | { |
| 4148 | return Type::getInt32Ty(*Nucleus::getContext()); |
| 4149 | } |
| 4150 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4151 | Long::Long(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4152 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4153 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4154 | |
| 4155 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4156 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4157 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4158 | } |
| 4159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4160 | Long::Long(RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4161 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4162 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4163 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4164 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | Long::Long() |
| 4168 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4169 | } |
| 4170 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4171 | Long::Long(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4172 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4173 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | RValue<Long> Long::operator=(int64_t rhs) const |
| 4177 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4178 | return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4179 | } |
| 4180 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4181 | RValue<Long> Long::operator=(RValue<Long> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4182 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4183 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4184 | |
| 4185 | return rhs; |
| 4186 | } |
| 4187 | |
| 4188 | RValue<Long> Long::operator=(const Long &rhs) const |
| 4189 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4190 | Value *value = rhs.loadValue(); |
| 4191 | storeValue(value); |
| 4192 | |
| 4193 | return RValue<Long>(value); |
| 4194 | } |
| 4195 | |
| 4196 | RValue<Long> Long::operator=(const Reference<Long> &rhs) const |
| 4197 | { |
| 4198 | Value *value = rhs.loadValue(); |
| 4199 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4200 | |
| 4201 | return RValue<Long>(value); |
| 4202 | } |
| 4203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4204 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4205 | { |
| 4206 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4207 | } |
| 4208 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4209 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4210 | { |
| 4211 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4212 | } |
| 4213 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4214 | RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4215 | { |
| 4216 | return lhs = lhs + rhs; |
| 4217 | } |
| 4218 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4219 | RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4220 | { |
| 4221 | return lhs = lhs - rhs; |
| 4222 | } |
| 4223 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4224 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4225 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4226 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4227 | } |
| 4228 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4229 | Type *Long::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4230 | { |
| 4231 | return Type::getInt64Ty(*Nucleus::getContext()); |
| 4232 | } |
| 4233 | |
Nicolas Capens | 50c9636 | 2016-01-04 23:03:59 -0500 | [diff] [blame] | 4234 | Long1::Long1(const RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4235 | { |
Nicolas Capens | 50c9636 | 2016-01-04 23:03:59 -0500 | [diff] [blame] | 4236 | Value *undefCast = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), cast.value, 0); |
| 4237 | Value *zeroCast = Nucleus::createInsertElement(undefCast, Nucleus::createConstantInt(0), 1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4238 | |
Nicolas Capens | 50c9636 | 2016-01-04 23:03:59 -0500 | [diff] [blame] | 4239 | storeValue(Nucleus::createBitCast(zeroCast, Long1::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4240 | } |
| 4241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4242 | Long1::Long1(RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4243 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4244 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4245 | } |
| 4246 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4247 | Type *Long1::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4248 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4249 | if(CPUID::supportsMMX2()) |
| 4250 | { |
| 4251 | return MMX::getType(); |
| 4252 | } |
| 4253 | else |
| 4254 | { |
| 4255 | return VectorType::get(Long::getType(), 1); |
| 4256 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4257 | } |
| 4258 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4259 | RValue<Long2> UnpackHigh(RValue<Long2> x, RValue<Long2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4260 | { |
| 4261 | Constant *shuffle[2]; |
| 4262 | shuffle[0] = Nucleus::createConstantInt(1); |
| 4263 | shuffle[1] = Nucleus::createConstantInt(3); |
| 4264 | |
| 4265 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2)); |
| 4266 | |
| 4267 | return RValue<Long2>(packed); |
| 4268 | } |
| 4269 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4270 | Type *Long2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4271 | { |
| 4272 | return VectorType::get(Long::getType(), 2); |
| 4273 | } |
| 4274 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 4275 | UInt::UInt(Argument<UInt> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4276 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 4277 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4278 | } |
| 4279 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4280 | UInt::UInt(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4281 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4282 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4283 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4284 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4285 | } |
| 4286 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4287 | UInt::UInt(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4288 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4289 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4290 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4291 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4292 | } |
| 4293 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4294 | UInt::UInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4295 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame^] | 4296 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 4297 | // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4298 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame^] | 4299 | // Smallest positive value representable in UInt, but not in Int |
| 4300 | const unsigned int ustart = 0x80000000u; |
| 4301 | const float ustartf = float(ustart); |
| 4302 | |
| 4303 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4304 | storeValue((~(As<Int>(cast) >> 31) & |
| 4305 | // Check if the value can be represented as an Int |
| 4306 | IfThenElse(cast >= ustartf, |
| 4307 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4308 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4309 | // Otherwise, just convert normally |
| 4310 | Int(cast))).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | UInt::UInt() |
| 4314 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | UInt::UInt(int x) |
| 4318 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4319 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | UInt::UInt(unsigned int x) |
| 4323 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4324 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4325 | } |
| 4326 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4327 | UInt::UInt(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4328 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4329 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4330 | } |
| 4331 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4332 | UInt::UInt(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4333 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4334 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | UInt::UInt(const UInt &rhs) |
| 4338 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4339 | Value *value = rhs.loadValue(); |
| 4340 | storeValue(value); |
| 4341 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4342 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4343 | UInt::UInt(const Reference<UInt> &rhs) |
| 4344 | { |
| 4345 | Value *value = rhs.loadValue(); |
| 4346 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | UInt::UInt(const Int &rhs) |
| 4350 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4351 | Value *value = rhs.loadValue(); |
| 4352 | storeValue(value); |
| 4353 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4354 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4355 | UInt::UInt(const Reference<Int> &rhs) |
| 4356 | { |
| 4357 | Value *value = rhs.loadValue(); |
| 4358 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | RValue<UInt> UInt::operator=(unsigned int rhs) const |
| 4362 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4363 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4364 | } |
| 4365 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4366 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4367 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4368 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4369 | |
| 4370 | return rhs; |
| 4371 | } |
| 4372 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4373 | RValue<UInt> UInt::operator=(RValue<Int> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4374 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4375 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4376 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4377 | return RValue<UInt>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | RValue<UInt> UInt::operator=(const UInt &rhs) const |
| 4381 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4382 | Value *value = rhs.loadValue(); |
| 4383 | storeValue(value); |
| 4384 | |
| 4385 | return RValue<UInt>(value); |
| 4386 | } |
| 4387 | |
| 4388 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const |
| 4389 | { |
| 4390 | Value *value = rhs.loadValue(); |
| 4391 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4392 | |
| 4393 | return RValue<UInt>(value); |
| 4394 | } |
| 4395 | |
| 4396 | RValue<UInt> UInt::operator=(const Int &rhs) const |
| 4397 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4398 | Value *value = rhs.loadValue(); |
| 4399 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4400 | |
| 4401 | return RValue<UInt>(value); |
| 4402 | } |
| 4403 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4404 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4405 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4406 | Value *value = rhs.loadValue(); |
| 4407 | storeValue(value); |
| 4408 | |
| 4409 | return RValue<UInt>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4410 | } |
| 4411 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4412 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4413 | { |
| 4414 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4415 | } |
| 4416 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4417 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4418 | { |
| 4419 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4420 | } |
| 4421 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4422 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4423 | { |
| 4424 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4425 | } |
| 4426 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4427 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4428 | { |
| 4429 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4430 | } |
| 4431 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4432 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4433 | { |
| 4434 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4435 | } |
| 4436 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4437 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4438 | { |
| 4439 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4440 | } |
| 4441 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4442 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4443 | { |
| 4444 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4445 | } |
| 4446 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4447 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4448 | { |
| 4449 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4450 | } |
| 4451 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4452 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4453 | { |
| 4454 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4455 | } |
| 4456 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4457 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4458 | { |
| 4459 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4460 | } |
| 4461 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4462 | RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4463 | { |
| 4464 | return lhs = lhs + rhs; |
| 4465 | } |
| 4466 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4467 | RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4468 | { |
| 4469 | return lhs = lhs - rhs; |
| 4470 | } |
| 4471 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4472 | RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4473 | { |
| 4474 | return lhs = lhs * rhs; |
| 4475 | } |
| 4476 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4477 | RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4478 | { |
| 4479 | return lhs = lhs / rhs; |
| 4480 | } |
| 4481 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4482 | RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4483 | { |
| 4484 | return lhs = lhs % rhs; |
| 4485 | } |
| 4486 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4487 | RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4488 | { |
| 4489 | return lhs = lhs & rhs; |
| 4490 | } |
| 4491 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4492 | RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4493 | { |
| 4494 | return lhs = lhs | rhs; |
| 4495 | } |
| 4496 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4497 | RValue<UInt> operator^=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4498 | { |
| 4499 | return lhs = lhs ^ rhs; |
| 4500 | } |
| 4501 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4502 | RValue<UInt> operator<<=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4503 | { |
| 4504 | return lhs = lhs << rhs; |
| 4505 | } |
| 4506 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4507 | RValue<UInt> operator>>=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4508 | { |
| 4509 | return lhs = lhs >> rhs; |
| 4510 | } |
| 4511 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4512 | RValue<UInt> operator+(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4513 | { |
| 4514 | return val; |
| 4515 | } |
| 4516 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4517 | RValue<UInt> operator-(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4518 | { |
| 4519 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4520 | } |
| 4521 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4522 | RValue<UInt> operator~(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4523 | { |
| 4524 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4525 | } |
| 4526 | |
| 4527 | RValue<UInt> operator++(const UInt &val, int) // Post-increment |
| 4528 | { |
| 4529 | RValue<UInt> res = val; |
| 4530 | |
| 4531 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4532 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4533 | |
| 4534 | return res; |
| 4535 | } |
| 4536 | |
| 4537 | const UInt &operator++(const UInt &val) // Pre-increment |
| 4538 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4539 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1)); |
| 4540 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4541 | |
| 4542 | return val; |
| 4543 | } |
| 4544 | |
| 4545 | RValue<UInt> operator--(const UInt &val, int) // Post-decrement |
| 4546 | { |
| 4547 | RValue<UInt> res = val; |
| 4548 | |
| 4549 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4550 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4551 | |
| 4552 | return res; |
| 4553 | } |
| 4554 | |
| 4555 | const UInt &operator--(const UInt &val) // Pre-decrement |
| 4556 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4557 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1)); |
| 4558 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4559 | |
| 4560 | return val; |
| 4561 | } |
| 4562 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4563 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4564 | { |
| 4565 | return IfThenElse(x > y, x, y); |
| 4566 | } |
| 4567 | |
| 4568 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4569 | { |
| 4570 | return IfThenElse(x < y, x, y); |
| 4571 | } |
| 4572 | |
| 4573 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4574 | { |
| 4575 | return Min(Max(x, min), max); |
| 4576 | } |
| 4577 | |
| 4578 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4579 | { |
| 4580 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4581 | } |
| 4582 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4583 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4584 | { |
| 4585 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4586 | } |
| 4587 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4588 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4589 | { |
| 4590 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4591 | } |
| 4592 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4593 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4594 | { |
| 4595 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4596 | } |
| 4597 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4598 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4599 | { |
| 4600 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4601 | } |
| 4602 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4603 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4604 | { |
| 4605 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4606 | } |
| 4607 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4608 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4609 | // { |
| 4610 | // return x86::cvtss2si(val); // FIXME: Unsigned |
| 4611 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4612 | // // return IfThenElse(val > 0.0f, Int(val + 0.5f), Int(val - 0.5f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4613 | // } |
| 4614 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4615 | Type *UInt::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4616 | { |
| 4617 | return Type::getInt32Ty(*Nucleus::getContext()); |
| 4618 | } |
| 4619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4620 | // Int2::Int2(RValue<Int> cast) |
| 4621 | // { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4622 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4623 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4624 | // |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4625 | // Constant *shuffle[2]; |
| 4626 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4627 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4628 | // |
| 4629 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4630 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4631 | // storeValue(replicate); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4632 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4633 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4634 | Int2::Int2(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4635 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4636 | Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType()); |
| 4637 | Value *element = Nucleus::createExtractElement(long2, 0); |
| 4638 | Value *int2 = Nucleus::createBitCast(element, Int2::getType()); |
| 4639 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4640 | storeValue(int2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | Int2::Int2() |
| 4644 | { |
| 4645 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | Int2::Int2(int x, int y) |
| 4649 | { |
| 4650 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4651 | |
| 4652 | Constant *constantVector[2]; |
| 4653 | constantVector[0] = Nucleus::createConstantInt(x); |
| 4654 | constantVector[1] = Nucleus::createConstantInt(y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4655 | Value *vector = Nucleus::createConstantVector(constantVector, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4656 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4657 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4658 | } |
| 4659 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4660 | Int2::Int2(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4661 | { |
| 4662 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4663 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4664 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | Int2::Int2(const Int2 &rhs) |
| 4668 | { |
| 4669 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4670 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4671 | Value *value = rhs.loadValue(); |
| 4672 | storeValue(value); |
| 4673 | } |
| 4674 | |
| 4675 | Int2::Int2(const Reference<Int2> &rhs) |
| 4676 | { |
| 4677 | // xy.parent = this; |
| 4678 | |
| 4679 | Value *value = rhs.loadValue(); |
| 4680 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4681 | } |
| 4682 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4683 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4684 | { |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4685 | if(CPUID::supportsMMX2()) |
| 4686 | { |
| 4687 | // movd mm0, lo |
| 4688 | // movd mm1, hi |
| 4689 | // punpckldq mm0, mm1 |
| 4690 | storeValue(As<Int2>(UnpackLow(As<Int2>(Long1(RValue<UInt>(lo))), As<Int2>(Long1(RValue<UInt>(hi))))).value); |
| 4691 | } |
| 4692 | else |
| 4693 | { |
| 4694 | Constant *shuffle[2]; |
| 4695 | shuffle[0] = Nucleus::createConstantInt(0); |
| 4696 | shuffle[1] = Nucleus::createConstantInt(1); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4697 | |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4698 | 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)); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4699 | |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4700 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
| 4701 | } |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4702 | } |
| 4703 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4704 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4705 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4706 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4707 | |
| 4708 | return rhs; |
| 4709 | } |
| 4710 | |
| 4711 | RValue<Int2> Int2::operator=(const Int2 &rhs) const |
| 4712 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4713 | Value *value = rhs.loadValue(); |
| 4714 | storeValue(value); |
| 4715 | |
| 4716 | return RValue<Int2>(value); |
| 4717 | } |
| 4718 | |
| 4719 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const |
| 4720 | { |
| 4721 | Value *value = rhs.loadValue(); |
| 4722 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4723 | |
| 4724 | return RValue<Int2>(value); |
| 4725 | } |
| 4726 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4727 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4728 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4729 | if(CPUID::supportsMMX2()) |
| 4730 | { |
| 4731 | return x86::paddd(lhs, rhs); |
| 4732 | } |
| 4733 | else |
| 4734 | { |
| 4735 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4736 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4737 | } |
| 4738 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4739 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4740 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4741 | if(CPUID::supportsMMX2()) |
| 4742 | { |
| 4743 | return x86::psubd(lhs, rhs); |
| 4744 | } |
| 4745 | else |
| 4746 | { |
| 4747 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4748 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4749 | } |
| 4750 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4751 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4752 | // { |
| 4753 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4754 | // } |
| 4755 | |
| 4756 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4757 | // { |
| 4758 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4759 | // } |
| 4760 | |
| 4761 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4762 | // { |
| 4763 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4764 | // } |
| 4765 | |
| 4766 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4767 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4768 | if(CPUID::supportsMMX2()) |
| 4769 | { |
| 4770 | return As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 4771 | } |
| 4772 | else |
| 4773 | { |
| 4774 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4775 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4776 | } |
| 4777 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4778 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4779 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4780 | if(CPUID::supportsMMX2()) |
| 4781 | { |
| 4782 | return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 4783 | } |
| 4784 | else |
| 4785 | { |
| 4786 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4787 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4788 | } |
| 4789 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4790 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4791 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4792 | if(CPUID::supportsMMX2()) |
| 4793 | { |
| 4794 | return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 4795 | } |
| 4796 | else |
| 4797 | { |
| 4798 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4799 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4800 | } |
| 4801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4802 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4803 | { |
| 4804 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4805 | |
| 4806 | return x86::pslld(lhs, rhs); |
| 4807 | } |
| 4808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4809 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4810 | { |
| 4811 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4812 | |
| 4813 | return x86::psrad(lhs, rhs); |
| 4814 | } |
| 4815 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4816 | RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4817 | { |
| 4818 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4819 | |
| 4820 | return x86::pslld(lhs, rhs); |
| 4821 | } |
| 4822 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4823 | RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4824 | { |
| 4825 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4826 | |
| 4827 | return x86::psrad(lhs, rhs); |
| 4828 | } |
| 4829 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4830 | RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4831 | { |
| 4832 | return lhs = lhs + rhs; |
| 4833 | } |
| 4834 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4835 | RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4836 | { |
| 4837 | return lhs = lhs - rhs; |
| 4838 | } |
| 4839 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4840 | // RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs) |
| 4841 | // { |
| 4842 | // return lhs = lhs * rhs; |
| 4843 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4844 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4845 | // RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs) |
| 4846 | // { |
| 4847 | // return lhs = lhs / rhs; |
| 4848 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4849 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4850 | // RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs) |
| 4851 | // { |
| 4852 | // return lhs = lhs % rhs; |
| 4853 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4854 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4855 | RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4856 | { |
| 4857 | return lhs = lhs & rhs; |
| 4858 | } |
| 4859 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4860 | RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4861 | { |
| 4862 | return lhs = lhs | rhs; |
| 4863 | } |
| 4864 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4865 | RValue<Int2> operator^=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4866 | { |
| 4867 | return lhs = lhs ^ rhs; |
| 4868 | } |
| 4869 | |
| 4870 | RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs) |
| 4871 | { |
| 4872 | return lhs = lhs << rhs; |
| 4873 | } |
| 4874 | |
| 4875 | RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs) |
| 4876 | { |
| 4877 | return lhs = lhs >> rhs; |
| 4878 | } |
| 4879 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4880 | RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4881 | { |
| 4882 | return lhs = lhs << rhs; |
| 4883 | } |
| 4884 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4885 | RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4886 | { |
| 4887 | return lhs = lhs >> rhs; |
| 4888 | } |
| 4889 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4890 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4891 | // { |
| 4892 | // return val; |
| 4893 | // } |
| 4894 | |
| 4895 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4896 | // { |
| 4897 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4898 | // } |
| 4899 | |
| 4900 | RValue<Int2> operator~(RValue<Int2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4901 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4902 | if(CPUID::supportsMMX2()) |
| 4903 | { |
| 4904 | return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF); |
| 4905 | } |
| 4906 | else |
| 4907 | { |
| 4908 | return RValue<Int2>(Nucleus::createNot(val.value)); |
| 4909 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4910 | } |
| 4911 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4912 | RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4913 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4914 | if(CPUID::supportsMMX2()) |
| 4915 | { |
| 4916 | return x86::punpckldq(x, y); |
| 4917 | } |
| 4918 | else |
| 4919 | { |
| 4920 | Constant *shuffle[2]; |
| 4921 | shuffle[0] = Nucleus::createConstantInt(0); |
| 4922 | shuffle[1] = Nucleus::createConstantInt(2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4923 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4924 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4925 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4926 | return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType())); |
| 4927 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4928 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4929 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4930 | RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4931 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4932 | if(CPUID::supportsMMX2()) |
| 4933 | { |
| 4934 | return x86::punpckhdq(x, y); |
| 4935 | } |
| 4936 | else |
| 4937 | { |
| 4938 | Constant *shuffle[2]; |
| 4939 | shuffle[0] = Nucleus::createConstantInt(1); |
| 4940 | shuffle[1] = Nucleus::createConstantInt(3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4941 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4942 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4943 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4944 | return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType())); |
| 4945 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4946 | } |
| 4947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4948 | RValue<Int> Extract(RValue<Int2> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4949 | { |
| 4950 | if(false) // FIXME: LLVM does not generate optimal code |
| 4951 | { |
| 4952 | return RValue<Int>(Nucleus::createExtractElement(val.value, i)); |
| 4953 | } |
| 4954 | else |
| 4955 | { |
| 4956 | if(i == 0) |
| 4957 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4958 | return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4959 | } |
| 4960 | else |
| 4961 | { |
| 4962 | Int2 val2 = As<Int2>(UnpackHigh(val, val)); |
| 4963 | |
| 4964 | return Extract(val2, 0); |
| 4965 | } |
| 4966 | } |
| 4967 | } |
| 4968 | |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4969 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4970 | { |
| 4971 | return RValue<Int2>(Nucleus::createBitCast(Nucleus::createInsertElement(Nucleus::createBitCast(val.value, VectorType::get(Int::getType(), 2)), element.value, i), Int2::getType())); |
| 4972 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4973 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4974 | Type *Int2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4975 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4976 | if(CPUID::supportsMMX2()) |
| 4977 | { |
| 4978 | return MMX::getType(); |
| 4979 | } |
| 4980 | else |
| 4981 | { |
| 4982 | return VectorType::get(Int::getType(), 2); |
| 4983 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | UInt2::UInt2() |
| 4987 | { |
| 4988 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4992 | { |
| 4993 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4994 | |
| 4995 | Constant *constantVector[2]; |
| 4996 | constantVector[0] = Nucleus::createConstantInt(x); |
| 4997 | constantVector[1] = Nucleus::createConstantInt(y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4998 | Value *vector = Nucleus::createConstantVector(constantVector, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4999 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5000 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5001 | } |
| 5002 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5003 | UInt2::UInt2(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5004 | { |
| 5005 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5006 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5007 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | UInt2::UInt2(const UInt2 &rhs) |
| 5011 | { |
| 5012 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5013 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5014 | Value *value = rhs.loadValue(); |
| 5015 | storeValue(value); |
| 5016 | } |
| 5017 | |
| 5018 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 5019 | { |
| 5020 | // xy.parent = this; |
| 5021 | |
| 5022 | Value *value = rhs.loadValue(); |
| 5023 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5024 | } |
| 5025 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5026 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5027 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5028 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5029 | |
| 5030 | return rhs; |
| 5031 | } |
| 5032 | |
| 5033 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const |
| 5034 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5035 | Value *value = rhs.loadValue(); |
| 5036 | storeValue(value); |
| 5037 | |
| 5038 | return RValue<UInt2>(value); |
| 5039 | } |
| 5040 | |
| 5041 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const |
| 5042 | { |
| 5043 | Value *value = rhs.loadValue(); |
| 5044 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5045 | |
| 5046 | return RValue<UInt2>(value); |
| 5047 | } |
| 5048 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5049 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5050 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5051 | if(CPUID::supportsMMX2()) |
| 5052 | { |
| 5053 | return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs))); |
| 5054 | } |
| 5055 | else |
| 5056 | { |
| 5057 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5058 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5059 | } |
| 5060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5061 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5062 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5063 | if(CPUID::supportsMMX2()) |
| 5064 | { |
| 5065 | return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs))); |
| 5066 | } |
| 5067 | else |
| 5068 | { |
| 5069 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5070 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5071 | } |
| 5072 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5073 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5074 | // { |
| 5075 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5076 | // } |
| 5077 | |
| 5078 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5079 | // { |
| 5080 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5081 | // } |
| 5082 | |
| 5083 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5084 | // { |
| 5085 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5086 | // } |
| 5087 | |
| 5088 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5089 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5090 | if(CPUID::supportsMMX2()) |
| 5091 | { |
| 5092 | return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 5093 | } |
| 5094 | else |
| 5095 | { |
| 5096 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5097 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5098 | } |
| 5099 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5100 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5101 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5102 | if(CPUID::supportsMMX2()) |
| 5103 | { |
| 5104 | return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 5105 | } |
| 5106 | else |
| 5107 | { |
| 5108 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5109 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5110 | } |
| 5111 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5112 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5113 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5114 | if(CPUID::supportsMMX2()) |
| 5115 | { |
| 5116 | return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 5117 | } |
| 5118 | else |
| 5119 | { |
| 5120 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5121 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5122 | } |
| 5123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5124 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5125 | { |
| 5126 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5127 | |
| 5128 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 5129 | } |
| 5130 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5131 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5132 | { |
| 5133 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5134 | |
| 5135 | return x86::psrld(lhs, rhs); |
| 5136 | } |
| 5137 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5138 | RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5139 | { |
| 5140 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5141 | |
| 5142 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 5143 | } |
| 5144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5145 | RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5146 | { |
| 5147 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5148 | |
| 5149 | return x86::psrld(lhs, rhs); |
| 5150 | } |
| 5151 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5152 | RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5153 | { |
| 5154 | return lhs = lhs + rhs; |
| 5155 | } |
| 5156 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5157 | RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5158 | { |
| 5159 | return lhs = lhs - rhs; |
| 5160 | } |
| 5161 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5162 | // RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs) |
| 5163 | // { |
| 5164 | // return lhs = lhs * rhs; |
| 5165 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5166 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5167 | // RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs) |
| 5168 | // { |
| 5169 | // return lhs = lhs / rhs; |
| 5170 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5171 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5172 | // RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs) |
| 5173 | // { |
| 5174 | // return lhs = lhs % rhs; |
| 5175 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5176 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5177 | RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5178 | { |
| 5179 | return lhs = lhs & rhs; |
| 5180 | } |
| 5181 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5182 | RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5183 | { |
| 5184 | return lhs = lhs | rhs; |
| 5185 | } |
| 5186 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5187 | RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5188 | { |
| 5189 | return lhs = lhs ^ rhs; |
| 5190 | } |
| 5191 | |
| 5192 | RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs) |
| 5193 | { |
| 5194 | return lhs = lhs << rhs; |
| 5195 | } |
| 5196 | |
| 5197 | RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs) |
| 5198 | { |
| 5199 | return lhs = lhs >> rhs; |
| 5200 | } |
| 5201 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5202 | RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5203 | { |
| 5204 | return lhs = lhs << rhs; |
| 5205 | } |
| 5206 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5207 | RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5208 | { |
| 5209 | return lhs = lhs >> rhs; |
| 5210 | } |
| 5211 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5212 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 5213 | // { |
| 5214 | // return val; |
| 5215 | // } |
| 5216 | |
| 5217 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 5218 | // { |
| 5219 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 5220 | // } |
| 5221 | |
| 5222 | RValue<UInt2> operator~(RValue<UInt2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5223 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5224 | if(CPUID::supportsMMX2()) |
| 5225 | { |
| 5226 | return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF); |
| 5227 | } |
| 5228 | else |
| 5229 | { |
| 5230 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 5231 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5232 | } |
| 5233 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5234 | Type *UInt2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5235 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5236 | if(CPUID::supportsMMX2()) |
| 5237 | { |
| 5238 | return MMX::getType(); |
| 5239 | } |
| 5240 | else |
| 5241 | { |
| 5242 | return VectorType::get(UInt::getType(), 2); |
| 5243 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5244 | } |
| 5245 | |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 5246 | Int4::Int4(RValue<Byte4> cast) |
| 5247 | { |
| 5248 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5249 | Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0); |
| 5250 | |
| 5251 | Value *e; |
| 5252 | |
| 5253 | if (CPUID::supportsSSE4_1()) |
| 5254 | { |
| 5255 | e = x86::pmovzxbd(RValue<Int4>(a)).value; |
| 5256 | } |
| 5257 | else |
| 5258 | { |
| 5259 | Constant *swizzle[16]; |
| 5260 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5261 | swizzle[1] = Nucleus::createConstantInt(16); |
| 5262 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5263 | swizzle[3] = Nucleus::createConstantInt(17); |
| 5264 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5265 | swizzle[5] = Nucleus::createConstantInt(18); |
| 5266 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5267 | swizzle[7] = Nucleus::createConstantInt(19); |
| 5268 | swizzle[8] = Nucleus::createConstantInt(4); |
| 5269 | swizzle[9] = Nucleus::createConstantInt(20); |
| 5270 | swizzle[10] = Nucleus::createConstantInt(5); |
| 5271 | swizzle[11] = Nucleus::createConstantInt(21); |
| 5272 | swizzle[12] = Nucleus::createConstantInt(6); |
| 5273 | swizzle[13] = Nucleus::createConstantInt(22); |
| 5274 | swizzle[14] = Nucleus::createConstantInt(7); |
| 5275 | swizzle[15] = Nucleus::createConstantInt(23); |
| 5276 | |
| 5277 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5278 | Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16)); |
| 5279 | |
| 5280 | Constant *swizzle2[8]; |
| 5281 | swizzle2[0] = Nucleus::createConstantInt(0); |
| 5282 | swizzle2[1] = Nucleus::createConstantInt(8); |
| 5283 | swizzle2[2] = Nucleus::createConstantInt(1); |
| 5284 | swizzle2[3] = Nucleus::createConstantInt(9); |
| 5285 | swizzle2[4] = Nucleus::createConstantInt(2); |
| 5286 | swizzle2[5] = Nucleus::createConstantInt(10); |
| 5287 | swizzle2[6] = Nucleus::createConstantInt(3); |
| 5288 | swizzle2[7] = Nucleus::createConstantInt(11); |
| 5289 | |
| 5290 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5291 | e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8)); |
| 5292 | } |
| 5293 | |
| 5294 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5295 | storeValue(f); |
| 5296 | } |
| 5297 | |
| 5298 | Int4::Int4(RValue<SByte4> cast) |
| 5299 | { |
| 5300 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5301 | Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0); |
| 5302 | |
| 5303 | Value *g; |
| 5304 | |
| 5305 | if (CPUID::supportsSSE4_1()) |
| 5306 | { |
| 5307 | g = x86::pmovsxbd(RValue<Int4>(a)).value; |
| 5308 | } |
| 5309 | else |
| 5310 | { |
| 5311 | Constant *swizzle[16]; |
| 5312 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5313 | swizzle[1] = Nucleus::createConstantInt(0); |
| 5314 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5315 | swizzle[3] = Nucleus::createConstantInt(1); |
| 5316 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5317 | swizzle[5] = Nucleus::createConstantInt(2); |
| 5318 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5319 | swizzle[7] = Nucleus::createConstantInt(3); |
| 5320 | swizzle[8] = Nucleus::createConstantInt(4); |
| 5321 | swizzle[9] = Nucleus::createConstantInt(4); |
| 5322 | swizzle[10] = Nucleus::createConstantInt(5); |
| 5323 | swizzle[11] = Nucleus::createConstantInt(5); |
| 5324 | swizzle[12] = Nucleus::createConstantInt(6); |
| 5325 | swizzle[13] = Nucleus::createConstantInt(6); |
| 5326 | swizzle[14] = Nucleus::createConstantInt(7); |
| 5327 | swizzle[15] = Nucleus::createConstantInt(7); |
| 5328 | |
| 5329 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5330 | Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16)); |
| 5331 | |
| 5332 | Constant *swizzle2[8]; |
| 5333 | swizzle2[0] = Nucleus::createConstantInt(0); |
| 5334 | swizzle2[1] = Nucleus::createConstantInt(0); |
| 5335 | swizzle2[2] = Nucleus::createConstantInt(1); |
| 5336 | swizzle2[3] = Nucleus::createConstantInt(1); |
| 5337 | swizzle2[4] = Nucleus::createConstantInt(2); |
| 5338 | swizzle2[5] = Nucleus::createConstantInt(2); |
| 5339 | swizzle2[6] = Nucleus::createConstantInt(3); |
| 5340 | swizzle2[7] = Nucleus::createConstantInt(3); |
| 5341 | |
| 5342 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5343 | Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8)); |
| 5344 | |
| 5345 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5346 | // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24)); |
| 5347 | g = x86::psrad(RValue<Int4>(f), 24).value; |
| 5348 | } |
| 5349 | |
| 5350 | storeValue(g); |
| 5351 | } |
| 5352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5353 | Int4::Int4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5354 | { |
| 5355 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5356 | |
| 5357 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5358 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5359 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5360 | } |
| 5361 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5362 | Int4::Int4(RValue<Short4> cast) |
| 5363 | { |
| 5364 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5365 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 5366 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 5367 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5368 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5369 | if(CPUID::supportsSSE4_1()) |
| 5370 | { |
| 5371 | storeValue(x86::pmovsxwd(vector).value); |
| 5372 | } |
| 5373 | else |
| 5374 | { |
| 5375 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 5376 | |
| 5377 | Constant *swizzle[8]; |
| 5378 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5379 | swizzle[1] = Nucleus::createConstantInt(0); |
| 5380 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5381 | swizzle[3] = Nucleus::createConstantInt(1); |
| 5382 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5383 | swizzle[5] = Nucleus::createConstantInt(2); |
| 5384 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5385 | swizzle[7] = Nucleus::createConstantInt(3); |
| 5386 | |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 5387 | Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8)); |
| 5388 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5389 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5390 | |
| 5391 | // Each Short is packed into each Int in the (Short | Short) format. |
| 5392 | // Shifting by 16 will retrieve the original Short value. |
| 5393 | // Shitfing an Int will propagate the sign bit, which will work |
| 5394 | // for both positive and negative values of a Short. |
| 5395 | *this >>= 16; |
| 5396 | } |
| 5397 | } |
| 5398 | |
| 5399 | Int4::Int4(RValue<UShort4> cast) |
| 5400 | { |
| 5401 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5402 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 5403 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 5404 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
| 5405 | |
| 5406 | if(CPUID::supportsSSE4_1()) |
| 5407 | { |
| 5408 | storeValue(x86::pmovzxwd(RValue<Int4>(vector)).value); |
| 5409 | } |
| 5410 | else |
| 5411 | { |
| 5412 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 5413 | |
| 5414 | Constant *swizzle[8]; |
| 5415 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5416 | swizzle[1] = Nucleus::createConstantInt(8); |
| 5417 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5418 | swizzle[3] = Nucleus::createConstantInt(9); |
| 5419 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5420 | swizzle[5] = Nucleus::createConstantInt(10); |
| 5421 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5422 | swizzle[7] = Nucleus::createConstantInt(11); |
| 5423 | |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 5424 | Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8)); |
| 5425 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5426 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5427 | } |
| 5428 | } |
| 5429 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5430 | Int4::Int4() |
| 5431 | { |
| 5432 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | Int4::Int4(int xyzw) |
| 5436 | { |
| 5437 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5438 | } |
| 5439 | |
| 5440 | Int4::Int4(int x, int yzw) |
| 5441 | { |
| 5442 | constant(x, yzw, yzw, yzw); |
| 5443 | } |
| 5444 | |
| 5445 | Int4::Int4(int x, int y, int zw) |
| 5446 | { |
| 5447 | constant(x, y, zw, zw); |
| 5448 | } |
| 5449 | |
| 5450 | Int4::Int4(int x, int y, int z, int w) |
| 5451 | { |
| 5452 | constant(x, y, z, w); |
| 5453 | } |
| 5454 | |
| 5455 | void Int4::constant(int x, int y, int z, int w) |
| 5456 | { |
| 5457 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5458 | |
| 5459 | Constant *constantVector[4]; |
| 5460 | constantVector[0] = Nucleus::createConstantInt(x); |
| 5461 | constantVector[1] = Nucleus::createConstantInt(y); |
| 5462 | constantVector[2] = Nucleus::createConstantInt(z); |
| 5463 | constantVector[3] = Nucleus::createConstantInt(w); |
| 5464 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5465 | storeValue(Nucleus::createConstantVector(constantVector, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5466 | } |
| 5467 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5468 | Int4::Int4(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5469 | { |
| 5470 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5471 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5472 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5473 | } |
| 5474 | |
| 5475 | Int4::Int4(const Int4 &rhs) |
| 5476 | { |
| 5477 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5478 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5479 | Value *value = rhs.loadValue(); |
| 5480 | storeValue(value); |
| 5481 | } |
| 5482 | |
| 5483 | Int4::Int4(const Reference<Int4> &rhs) |
| 5484 | { |
| 5485 | // xyzw.parent = this; |
| 5486 | |
| 5487 | Value *value = rhs.loadValue(); |
| 5488 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5489 | } |
| 5490 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5491 | Int4::Int4(RValue<UInt4> rhs) |
| 5492 | { |
| 5493 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5494 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5495 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | Int4::Int4(const UInt4 &rhs) |
| 5499 | { |
| 5500 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5501 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5502 | Value *value = rhs.loadValue(); |
| 5503 | storeValue(value); |
| 5504 | } |
| 5505 | |
| 5506 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5507 | { |
| 5508 | // xyzw.parent = this; |
| 5509 | |
| 5510 | Value *value = rhs.loadValue(); |
| 5511 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5512 | } |
| 5513 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5514 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5515 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 5516 | // xyzw.parent = this; |
| 5517 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5518 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 5519 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 5520 | |
| 5521 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5522 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 5523 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 5524 | Value *int4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 5525 | |
| 5526 | storeValue(int4); |
| 5527 | } |
| 5528 | |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 5529 | Int4::Int4(RValue<Int> rhs) |
| 5530 | { |
| 5531 | // xyzw.parent = this; |
| 5532 | |
| 5533 | Value *vector = loadValue(); |
| 5534 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5535 | |
| 5536 | Constant *swizzle[4]; |
| 5537 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5538 | swizzle[1] = Nucleus::createConstantInt(0); |
| 5539 | swizzle[2] = Nucleus::createConstantInt(0); |
| 5540 | swizzle[3] = Nucleus::createConstantInt(0); |
| 5541 | |
| 5542 | Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Int4::getType()), Nucleus::createConstantVector(swizzle, 4)); |
| 5543 | |
| 5544 | storeValue(replicate); |
| 5545 | } |
| 5546 | |
| 5547 | Int4::Int4(const Int &rhs) |
| 5548 | { |
| 5549 | // xyzw.parent = this; |
| 5550 | |
| 5551 | *this = RValue<Int>(rhs.loadValue()); |
| 5552 | } |
| 5553 | |
| 5554 | Int4::Int4(const Reference<Int> &rhs) |
| 5555 | { |
| 5556 | // xyzw.parent = this; |
| 5557 | |
| 5558 | *this = RValue<Int>(rhs.loadValue()); |
| 5559 | } |
| 5560 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5561 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5562 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5563 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5564 | |
| 5565 | return rhs; |
| 5566 | } |
| 5567 | |
| 5568 | RValue<Int4> Int4::operator=(const Int4 &rhs) const |
| 5569 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5570 | Value *value = rhs.loadValue(); |
| 5571 | storeValue(value); |
| 5572 | |
| 5573 | return RValue<Int4>(value); |
| 5574 | } |
| 5575 | |
| 5576 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const |
| 5577 | { |
| 5578 | Value *value = rhs.loadValue(); |
| 5579 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5580 | |
| 5581 | return RValue<Int4>(value); |
| 5582 | } |
| 5583 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5584 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5585 | { |
| 5586 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5587 | } |
| 5588 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5589 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5590 | { |
| 5591 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5592 | } |
| 5593 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5594 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5595 | { |
| 5596 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5597 | } |
| 5598 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5599 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5600 | { |
| 5601 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5602 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5603 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5604 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5605 | { |
| 5606 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5607 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5608 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5609 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5610 | { |
| 5611 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5612 | } |
| 5613 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5614 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5615 | { |
| 5616 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5617 | } |
| 5618 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5619 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5620 | { |
| 5621 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5622 | } |
| 5623 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5624 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5625 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5626 | return x86::pslld(lhs, rhs); |
| 5627 | } |
| 5628 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5629 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5630 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5631 | return x86::psrad(lhs, rhs); |
| 5632 | } |
| 5633 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5634 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5635 | { |
| 5636 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5637 | } |
| 5638 | |
| 5639 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5640 | { |
| 5641 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5642 | } |
| 5643 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5644 | RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5645 | { |
| 5646 | return lhs = lhs + rhs; |
| 5647 | } |
| 5648 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5649 | RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5650 | { |
| 5651 | return lhs = lhs - rhs; |
| 5652 | } |
| 5653 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5654 | RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5655 | { |
| 5656 | return lhs = lhs * rhs; |
| 5657 | } |
| 5658 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5659 | // RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs) |
| 5660 | // { |
| 5661 | // return lhs = lhs / rhs; |
| 5662 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5663 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5664 | // RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs) |
| 5665 | // { |
| 5666 | // return lhs = lhs % rhs; |
| 5667 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5668 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5669 | RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5670 | { |
| 5671 | return lhs = lhs & rhs; |
| 5672 | } |
| 5673 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5674 | RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5675 | { |
| 5676 | return lhs = lhs | rhs; |
| 5677 | } |
| 5678 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5679 | RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5680 | { |
| 5681 | return lhs = lhs ^ rhs; |
| 5682 | } |
| 5683 | |
| 5684 | RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs) |
| 5685 | { |
| 5686 | return lhs = lhs << rhs; |
| 5687 | } |
| 5688 | |
| 5689 | RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs) |
| 5690 | { |
| 5691 | return lhs = lhs >> rhs; |
| 5692 | } |
| 5693 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5694 | RValue<Int4> operator+(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5695 | { |
| 5696 | return val; |
| 5697 | } |
| 5698 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5699 | RValue<Int4> operator-(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5700 | { |
| 5701 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5702 | } |
| 5703 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5704 | RValue<Int4> operator~(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5705 | { |
| 5706 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5707 | } |
| 5708 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5709 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5710 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5711 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
Alexis Hetu | fb60399 | 2016-04-26 11:50:40 -0400 | [diff] [blame] | 5712 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5713 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5714 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5718 | { |
| 5719 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5720 | } |
| 5721 | |
| 5722 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5723 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5724 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5725 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5726 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5727 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5731 | { |
| 5732 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5733 | } |
| 5734 | |
| 5735 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5736 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5737 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5738 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5739 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5740 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5744 | { |
| 5745 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5746 | } |
| 5747 | |
| 5748 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5749 | { |
| 5750 | if(CPUID::supportsSSE4_1()) |
| 5751 | { |
| 5752 | return x86::pmaxsd(x, y); |
| 5753 | } |
| 5754 | else |
| 5755 | { |
| 5756 | RValue<Int4> greater = CmpNLE(x, y); |
| 5757 | return x & greater | y & ~greater; |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5762 | { |
| 5763 | if(CPUID::supportsSSE4_1()) |
| 5764 | { |
| 5765 | return x86::pminsd(x, y); |
| 5766 | } |
| 5767 | else |
| 5768 | { |
| 5769 | RValue<Int4> less = CmpLT(x, y); |
| 5770 | return x & less | y & ~less; |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | RValue<Int4> RoundInt(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5775 | { |
| 5776 | return x86::cvtps2dq(cast); |
| 5777 | } |
| 5778 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5779 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5780 | { |
| 5781 | return x86::packssdw(x, y); |
| 5782 | } |
| 5783 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5784 | RValue<Int> Extract(RValue<Int4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5785 | { |
| 5786 | return RValue<Int>(Nucleus::createExtractElement(x.value, i)); |
| 5787 | } |
| 5788 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5789 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5790 | { |
| 5791 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5792 | } |
| 5793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5794 | RValue<Int> SignMask(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5795 | { |
| 5796 | return x86::movmskps(As<Float4>(x)); |
| 5797 | } |
| 5798 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5799 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5800 | { |
| 5801 | return RValue<Int4>(Nucleus::createSwizzle(x.value, select)); |
| 5802 | } |
| 5803 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5804 | Type *Int4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5805 | { |
| 5806 | return VectorType::get(Int::getType(), 4); |
| 5807 | } |
| 5808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5809 | UInt4::UInt4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5810 | { |
| 5811 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5812 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame^] | 5813 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 5814 | // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5815 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame^] | 5816 | // Smallest positive value representable in UInt, but not in Int |
| 5817 | const unsigned int ustart = 0x80000000u; |
| 5818 | const float ustartf = float(ustart); |
| 5819 | |
| 5820 | // Check if the value can be represented as an Int |
| 5821 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5822 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5823 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5824 | // Otherwise, just convert normally |
| 5825 | (~uiValue & Int4(cast)); |
| 5826 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5827 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | UInt4::UInt4() |
| 5831 | { |
| 5832 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5833 | } |
| 5834 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5835 | UInt4::UInt4(int xyzw) |
| 5836 | { |
| 5837 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5838 | } |
| 5839 | |
| 5840 | UInt4::UInt4(int x, int yzw) |
| 5841 | { |
| 5842 | constant(x, yzw, yzw, yzw); |
| 5843 | } |
| 5844 | |
| 5845 | UInt4::UInt4(int x, int y, int zw) |
| 5846 | { |
| 5847 | constant(x, y, zw, zw); |
| 5848 | } |
| 5849 | |
| 5850 | UInt4::UInt4(int x, int y, int z, int w) |
| 5851 | { |
| 5852 | constant(x, y, z, w); |
| 5853 | } |
| 5854 | |
| 5855 | void UInt4::constant(int x, int y, int z, int w) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5856 | { |
| 5857 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5858 | |
| 5859 | Constant *constantVector[4]; |
| 5860 | constantVector[0] = Nucleus::createConstantInt(x); |
| 5861 | constantVector[1] = Nucleus::createConstantInt(y); |
| 5862 | constantVector[2] = Nucleus::createConstantInt(z); |
| 5863 | constantVector[3] = Nucleus::createConstantInt(w); |
| 5864 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5865 | storeValue(Nucleus::createConstantVector(constantVector, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5866 | } |
| 5867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5868 | UInt4::UInt4(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5869 | { |
| 5870 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5871 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5872 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | UInt4::UInt4(const UInt4 &rhs) |
| 5876 | { |
| 5877 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5878 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5879 | Value *value = rhs.loadValue(); |
| 5880 | storeValue(value); |
| 5881 | } |
| 5882 | |
| 5883 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5884 | { |
| 5885 | // xyzw.parent = this; |
| 5886 | |
| 5887 | Value *value = rhs.loadValue(); |
| 5888 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5889 | } |
| 5890 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5891 | UInt4::UInt4(RValue<Int4> rhs) |
| 5892 | { |
| 5893 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5894 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5895 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | UInt4::UInt4(const Int4 &rhs) |
| 5899 | { |
| 5900 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5901 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5902 | Value *value = rhs.loadValue(); |
| 5903 | storeValue(value); |
| 5904 | } |
| 5905 | |
| 5906 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5907 | { |
| 5908 | // xyzw.parent = this; |
| 5909 | |
| 5910 | Value *value = rhs.loadValue(); |
| 5911 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5912 | } |
| 5913 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5914 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5915 | { |
| 5916 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 5917 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 5918 | |
| 5919 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5920 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 5921 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 5922 | Value *uint4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 5923 | |
| 5924 | storeValue(uint4); |
| 5925 | } |
| 5926 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5927 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5928 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5929 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5930 | |
| 5931 | return rhs; |
| 5932 | } |
| 5933 | |
| 5934 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const |
| 5935 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5936 | Value *value = rhs.loadValue(); |
| 5937 | storeValue(value); |
| 5938 | |
| 5939 | return RValue<UInt4>(value); |
| 5940 | } |
| 5941 | |
| 5942 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const |
| 5943 | { |
| 5944 | Value *value = rhs.loadValue(); |
| 5945 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5946 | |
| 5947 | return RValue<UInt4>(value); |
| 5948 | } |
| 5949 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5950 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5951 | { |
| 5952 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5953 | } |
| 5954 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5955 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5956 | { |
| 5957 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5958 | } |
| 5959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5960 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5961 | { |
| 5962 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5963 | } |
| 5964 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5965 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5966 | { |
| 5967 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5968 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5969 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5970 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5971 | { |
| 5972 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5973 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5974 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5975 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5976 | { |
| 5977 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5978 | } |
| 5979 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5980 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5981 | { |
| 5982 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5983 | } |
| 5984 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5985 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5986 | { |
| 5987 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5988 | } |
| 5989 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5990 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5991 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5992 | return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs)); |
| 5993 | } |
| 5994 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5995 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5996 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5997 | return x86::psrld(lhs, rhs); |
| 5998 | } |
| 5999 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 6000 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6001 | { |
| 6002 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 6003 | } |
| 6004 | |
| 6005 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6006 | { |
| 6007 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 6008 | } |
| 6009 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6010 | RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6011 | { |
| 6012 | return lhs = lhs + rhs; |
| 6013 | } |
| 6014 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6015 | RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6016 | { |
| 6017 | return lhs = lhs - rhs; |
| 6018 | } |
| 6019 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6020 | RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6021 | { |
| 6022 | return lhs = lhs * rhs; |
| 6023 | } |
| 6024 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6025 | // RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs) |
| 6026 | // { |
| 6027 | // return lhs = lhs / rhs; |
| 6028 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6029 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6030 | // RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs) |
| 6031 | // { |
| 6032 | // return lhs = lhs % rhs; |
| 6033 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6034 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6035 | RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6036 | { |
| 6037 | return lhs = lhs & rhs; |
| 6038 | } |
| 6039 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6040 | RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6041 | { |
| 6042 | return lhs = lhs | rhs; |
| 6043 | } |
| 6044 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6045 | RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6046 | { |
| 6047 | return lhs = lhs ^ rhs; |
| 6048 | } |
| 6049 | |
| 6050 | RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs) |
| 6051 | { |
| 6052 | return lhs = lhs << rhs; |
| 6053 | } |
| 6054 | |
| 6055 | RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs) |
| 6056 | { |
| 6057 | return lhs = lhs >> rhs; |
| 6058 | } |
| 6059 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6060 | RValue<UInt4> operator+(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6061 | { |
| 6062 | return val; |
| 6063 | } |
| 6064 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6065 | RValue<UInt4> operator-(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6066 | { |
| 6067 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 6068 | } |
| 6069 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6070 | RValue<UInt4> operator~(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6071 | { |
| 6072 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 6073 | } |
| 6074 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6075 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6076 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 6077 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
Alexis Hetu | fb60399 | 2016-04-26 11:50:40 -0400 | [diff] [blame] | 6078 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 6079 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 6080 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6081 | } |
| 6082 | |
| 6083 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6084 | { |
| 6085 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 6086 | } |
| 6087 | |
| 6088 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6089 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 6090 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 6091 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 6092 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 6093 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6097 | { |
| 6098 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 6099 | } |
| 6100 | |
| 6101 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6102 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 6103 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 6104 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 6105 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 6106 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())) ^ UInt4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6110 | { |
| 6111 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 6112 | } |
| 6113 | |
| 6114 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 6115 | { |
| 6116 | if(CPUID::supportsSSE4_1()) |
| 6117 | { |
| 6118 | return x86::pmaxud(x, y); |
| 6119 | } |
| 6120 | else |
| 6121 | { |
| 6122 | RValue<UInt4> greater = CmpNLE(x, y); |
| 6123 | return x & greater | y & ~greater; |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 6128 | { |
| 6129 | if(CPUID::supportsSSE4_1()) |
| 6130 | { |
| 6131 | return x86::pminud(x, y); |
| 6132 | } |
| 6133 | else |
| 6134 | { |
| 6135 | RValue<UInt4> less = CmpLT(x, y); |
| 6136 | return x & less | y & ~less; |
| 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6141 | { |
| 6142 | return x86::packusdw(x, y); // FIXME: Fallback required |
| 6143 | } |
| 6144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6145 | Type *UInt4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6146 | { |
| 6147 | return VectorType::get(UInt::getType(), 4); |
| 6148 | } |
| 6149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6150 | Float::Float(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6151 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6152 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 6153 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6154 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | Float::Float() |
| 6158 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6159 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | Float::Float(float x) |
| 6163 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6164 | storeValue(Nucleus::createConstantFloat(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6165 | } |
| 6166 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6167 | Float::Float(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6168 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6169 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | Float::Float(const Float &rhs) |
| 6173 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6174 | Value *value = rhs.loadValue(); |
| 6175 | storeValue(value); |
| 6176 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6177 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6178 | Float::Float(const Reference<Float> &rhs) |
| 6179 | { |
| 6180 | Value *value = rhs.loadValue(); |
| 6181 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6182 | } |
| 6183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6184 | RValue<Float> Float::operator=(RValue<Float> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6185 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6186 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6187 | |
| 6188 | return rhs; |
| 6189 | } |
| 6190 | |
| 6191 | RValue<Float> Float::operator=(const Float &rhs) const |
| 6192 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6193 | Value *value = rhs.loadValue(); |
| 6194 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6195 | |
| 6196 | return RValue<Float>(value); |
| 6197 | } |
| 6198 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6199 | RValue<Float> Float::operator=(const Reference<Float> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6200 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6201 | Value *value = rhs.loadValue(); |
| 6202 | storeValue(value); |
| 6203 | |
| 6204 | return RValue<Float>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6205 | } |
| 6206 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6207 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6208 | { |
| 6209 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6210 | } |
| 6211 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6212 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6213 | { |
| 6214 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6215 | } |
| 6216 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6217 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6218 | { |
| 6219 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6220 | } |
| 6221 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6222 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6223 | { |
| 6224 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6225 | } |
| 6226 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6227 | RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6228 | { |
| 6229 | return lhs = lhs + rhs; |
| 6230 | } |
| 6231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6232 | RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6233 | { |
| 6234 | return lhs = lhs - rhs; |
| 6235 | } |
| 6236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6237 | RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6238 | { |
| 6239 | return lhs = lhs * rhs; |
| 6240 | } |
| 6241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6242 | RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6243 | { |
| 6244 | return lhs = lhs / rhs; |
| 6245 | } |
| 6246 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6247 | RValue<Float> operator+(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6248 | { |
| 6249 | return val; |
| 6250 | } |
| 6251 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6252 | RValue<Float> operator-(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6253 | { |
| 6254 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 6255 | } |
| 6256 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6257 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6258 | { |
| 6259 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 6260 | } |
| 6261 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6262 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6263 | { |
| 6264 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 6265 | } |
| 6266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6267 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6268 | { |
| 6269 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 6270 | } |
| 6271 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6272 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6273 | { |
| 6274 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 6275 | } |
| 6276 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6277 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6278 | { |
| 6279 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 6280 | } |
| 6281 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6282 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6283 | { |
| 6284 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 6285 | } |
| 6286 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6287 | RValue<Float> Abs(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6288 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6289 | return IfThenElse(x > 0.0f, x, -x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6290 | } |
| 6291 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6292 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6293 | { |
| 6294 | return IfThenElse(x > y, x, y); |
| 6295 | } |
| 6296 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6297 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6298 | { |
| 6299 | return IfThenElse(x < y, x, y); |
| 6300 | } |
| 6301 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6302 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6303 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6304 | if(exactAtPow2) |
| 6305 | { |
| 6306 | // rcpss uses a piecewise-linear approximation which minimizes the relative error |
| 6307 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 6308 | return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 6309 | } |
| 6310 | else |
| 6311 | { |
| 6312 | return x86::rcpss(x); |
| 6313 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6314 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6315 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6316 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6317 | { |
| 6318 | return x86::rsqrtss(x); |
| 6319 | } |
| 6320 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6321 | RValue<Float> Sqrt(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6322 | { |
| 6323 | return x86::sqrtss(x); |
| 6324 | } |
| 6325 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6326 | RValue<Float> Round(RValue<Float> x) |
| 6327 | { |
| 6328 | if(CPUID::supportsSSE4_1()) |
| 6329 | { |
| 6330 | return x86::roundss(x, 0); |
| 6331 | } |
| 6332 | else |
| 6333 | { |
| 6334 | return Float4(Round(Float4(x))).x; |
| 6335 | } |
| 6336 | } |
| 6337 | |
| 6338 | RValue<Float> Trunc(RValue<Float> x) |
| 6339 | { |
| 6340 | if(CPUID::supportsSSE4_1()) |
| 6341 | { |
| 6342 | return x86::roundss(x, 3); |
| 6343 | } |
| 6344 | else |
| 6345 | { |
| 6346 | return Float(Int(x)); // Rounded toward zero |
| 6347 | } |
| 6348 | } |
| 6349 | |
| 6350 | RValue<Float> Frac(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6351 | { |
| 6352 | if(CPUID::supportsSSE4_1()) |
| 6353 | { |
| 6354 | return x - x86::floorss(x); |
| 6355 | } |
| 6356 | else |
| 6357 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6358 | return Float4(Frac(Float4(x))).x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6359 | } |
| 6360 | } |
| 6361 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6362 | RValue<Float> Floor(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6363 | { |
| 6364 | if(CPUID::supportsSSE4_1()) |
| 6365 | { |
| 6366 | return x86::floorss(x); |
| 6367 | } |
| 6368 | else |
| 6369 | { |
| 6370 | return Float4(Floor(Float4(x))).x; |
| 6371 | } |
| 6372 | } |
| 6373 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6374 | RValue<Float> Ceil(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6375 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6376 | if(CPUID::supportsSSE4_1()) |
| 6377 | { |
| 6378 | return x86::ceilss(x); |
| 6379 | } |
| 6380 | else |
| 6381 | { |
| 6382 | return Float4(Ceil(Float4(x))).x; |
| 6383 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6384 | } |
| 6385 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6386 | Type *Float::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6387 | { |
| 6388 | return Type::getFloatTy(*Nucleus::getContext()); |
| 6389 | } |
| 6390 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6391 | Float2::Float2(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6392 | { |
| 6393 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6394 | |
| 6395 | Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType()); |
| 6396 | Value *int64 = Nucleus::createExtractElement(int64x2, 0); |
| 6397 | Value *float2 = Nucleus::createBitCast(int64, Float2::getType()); |
| 6398 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6399 | storeValue(float2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6400 | } |
| 6401 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6402 | Type *Float2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6403 | { |
| 6404 | return VectorType::get(Float::getType(), 2); |
| 6405 | } |
| 6406 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6407 | Float4::Float4(RValue<Byte4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6408 | { |
| 6409 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6410 | |
| 6411 | #if 0 |
| 6412 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes |
| 6413 | #elif 0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6414 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6415 | |
| 6416 | Value *i8x = Nucleus::createExtractElement(cast.value, 0); |
| 6417 | Value *f32x = Nucleus::createUIToFP(i8x, Float::getType()); |
| 6418 | Value *x = Nucleus::createInsertElement(vector, f32x, 0); |
| 6419 | |
| 6420 | Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1)); |
| 6421 | Value *f32y = Nucleus::createUIToFP(i8y, Float::getType()); |
| 6422 | Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1)); |
| 6423 | |
| 6424 | Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2)); |
| 6425 | Value *f32z = Nucleus::createUIToFP(i8z, Float::getType()); |
| 6426 | Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2)); |
| 6427 | |
| 6428 | Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3)); |
| 6429 | Value *f32w = Nucleus::createUIToFP(i8w, Float::getType()); |
| 6430 | Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3)); |
| 6431 | #else |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 6432 | Value *a = Int4(cast).loadValue(); |
| 6433 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6434 | #endif |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6435 | |
| 6436 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6437 | } |
| 6438 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6439 | Float4::Float4(RValue<SByte4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6440 | { |
| 6441 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6442 | |
| 6443 | #if 0 |
| 6444 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes |
| 6445 | #elif 0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6446 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6447 | |
| 6448 | Value *i8x = Nucleus::createExtractElement(cast.value, 0); |
| 6449 | Value *f32x = Nucleus::createSIToFP(i8x, Float::getType()); |
| 6450 | Value *x = Nucleus::createInsertElement(vector, f32x, 0); |
| 6451 | |
| 6452 | Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1)); |
| 6453 | Value *f32y = Nucleus::createSIToFP(i8y, Float::getType()); |
| 6454 | Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1)); |
| 6455 | |
| 6456 | Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2)); |
| 6457 | Value *f32z = Nucleus::createSIToFP(i8z, Float::getType()); |
| 6458 | Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2)); |
| 6459 | |
| 6460 | Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3)); |
| 6461 | Value *f32w = Nucleus::createSIToFP(i8w, Float::getType()); |
| 6462 | Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3)); |
| 6463 | #else |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 6464 | Value *a = Int4(cast).loadValue(); |
| 6465 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6466 | #endif |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6467 | |
| 6468 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6469 | } |
| 6470 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6471 | Float4::Float4(RValue<Short4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6472 | { |
| 6473 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6474 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 6475 | Int4 c(cast); |
| 6476 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6477 | } |
| 6478 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6479 | Float4::Float4(RValue<UShort4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6480 | { |
| 6481 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6482 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 6483 | Int4 c(cast); |
| 6484 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6485 | } |
| 6486 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6487 | Float4::Float4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6488 | { |
| 6489 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6490 | |
| 6491 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6492 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6493 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6494 | } |
| 6495 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6496 | Float4::Float4(RValue<UInt4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6497 | { |
| 6498 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6499 | |
| 6500 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); |
| 6501 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6502 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | Float4::Float4() |
| 6506 | { |
| 6507 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6508 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6509 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6510 | Float4::Float4(float xyzw) |
| 6511 | { |
| 6512 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6513 | } |
| 6514 | |
| 6515 | Float4::Float4(float x, float yzw) |
| 6516 | { |
| 6517 | constant(x, yzw, yzw, yzw); |
| 6518 | } |
| 6519 | |
| 6520 | Float4::Float4(float x, float y, float zw) |
| 6521 | { |
| 6522 | constant(x, y, zw, zw); |
| 6523 | } |
| 6524 | |
| 6525 | Float4::Float4(float x, float y, float z, float w) |
| 6526 | { |
| 6527 | constant(x, y, z, w); |
| 6528 | } |
| 6529 | |
| 6530 | void Float4::constant(float x, float y, float z, float w) |
| 6531 | { |
| 6532 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6533 | |
| 6534 | Constant *constantVector[4]; |
| 6535 | constantVector[0] = Nucleus::createConstantFloat(x); |
| 6536 | constantVector[1] = Nucleus::createConstantFloat(y); |
| 6537 | constantVector[2] = Nucleus::createConstantFloat(z); |
| 6538 | constantVector[3] = Nucleus::createConstantFloat(w); |
| 6539 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6540 | storeValue(Nucleus::createConstantVector(constantVector, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6541 | } |
| 6542 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6543 | Float4::Float4(RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6544 | { |
| 6545 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6546 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6547 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6548 | } |
| 6549 | |
| 6550 | Float4::Float4(const Float4 &rhs) |
| 6551 | { |
| 6552 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6553 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6554 | Value *value = rhs.loadValue(); |
| 6555 | storeValue(value); |
| 6556 | } |
| 6557 | |
| 6558 | Float4::Float4(const Reference<Float4> &rhs) |
| 6559 | { |
| 6560 | xyzw.parent = this; |
| 6561 | |
| 6562 | Value *value = rhs.loadValue(); |
| 6563 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6564 | } |
| 6565 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6566 | Float4::Float4(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6567 | { |
| 6568 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6569 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6570 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6571 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 6572 | |
| 6573 | Constant *swizzle[4]; |
| 6574 | swizzle[0] = Nucleus::createConstantInt(0); |
| 6575 | swizzle[1] = Nucleus::createConstantInt(0); |
| 6576 | swizzle[2] = Nucleus::createConstantInt(0); |
| 6577 | swizzle[3] = Nucleus::createConstantInt(0); |
| 6578 | |
| 6579 | Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4)); |
| 6580 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6581 | storeValue(replicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6582 | } |
| 6583 | |
| 6584 | Float4::Float4(const Float &rhs) |
| 6585 | { |
| 6586 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6587 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6588 | *this = RValue<Float>(rhs.loadValue()); |
| 6589 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6590 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6591 | Float4::Float4(const Reference<Float> &rhs) |
| 6592 | { |
| 6593 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6594 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6595 | *this = RValue<Float>(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | RValue<Float4> Float4::operator=(float x) const |
| 6599 | { |
| 6600 | return *this = Float4(x, x, x, x); |
| 6601 | } |
| 6602 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6603 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6604 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6605 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6606 | |
| 6607 | return rhs; |
| 6608 | } |
| 6609 | |
| 6610 | RValue<Float4> Float4::operator=(const Float4 &rhs) const |
| 6611 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6612 | Value *value = rhs.loadValue(); |
| 6613 | storeValue(value); |
| 6614 | |
| 6615 | return RValue<Float4>(value); |
| 6616 | } |
| 6617 | |
| 6618 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const |
| 6619 | { |
| 6620 | Value *value = rhs.loadValue(); |
| 6621 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6622 | |
| 6623 | return RValue<Float4>(value); |
| 6624 | } |
| 6625 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6626 | RValue<Float4> Float4::operator=(RValue<Float> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6627 | { |
| 6628 | return *this = Float4(rhs); |
| 6629 | } |
| 6630 | |
| 6631 | RValue<Float4> Float4::operator=(const Float &rhs) const |
| 6632 | { |
| 6633 | return *this = Float4(rhs); |
| 6634 | } |
| 6635 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6636 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6637 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6638 | return *this = Float4(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6639 | } |
| 6640 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6641 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6642 | { |
| 6643 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6644 | } |
| 6645 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6646 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6647 | { |
| 6648 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6649 | } |
| 6650 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6651 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6652 | { |
| 6653 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6654 | } |
| 6655 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6656 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6657 | { |
| 6658 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6659 | } |
| 6660 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6661 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6662 | { |
| 6663 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6664 | } |
| 6665 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6666 | RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6667 | { |
| 6668 | return lhs = lhs + rhs; |
| 6669 | } |
| 6670 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6671 | RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6672 | { |
| 6673 | return lhs = lhs - rhs; |
| 6674 | } |
| 6675 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6676 | RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6677 | { |
| 6678 | return lhs = lhs * rhs; |
| 6679 | } |
| 6680 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6681 | RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6682 | { |
| 6683 | return lhs = lhs / rhs; |
| 6684 | } |
| 6685 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6686 | RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6687 | { |
| 6688 | return lhs = lhs % rhs; |
| 6689 | } |
| 6690 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6691 | RValue<Float4> operator+(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6692 | { |
| 6693 | return val; |
| 6694 | } |
| 6695 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6696 | RValue<Float4> operator-(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6697 | { |
| 6698 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6699 | } |
| 6700 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6701 | RValue<Float4> Abs(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6702 | { |
| 6703 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6704 | |
| 6705 | Constant *constantVector[4]; |
| 6706 | constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6707 | constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6708 | constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6709 | constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6710 | |
| 6711 | Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4)); |
| 6712 | |
| 6713 | return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType())); |
| 6714 | } |
| 6715 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6716 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6717 | { |
| 6718 | return x86::maxps(x, y); |
| 6719 | } |
| 6720 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6721 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6722 | { |
| 6723 | return x86::minps(x, y); |
| 6724 | } |
| 6725 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6726 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6727 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6728 | if(exactAtPow2) |
| 6729 | { |
| 6730 | // rcpps uses a piecewise-linear approximation which minimizes the relative error |
| 6731 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 6732 | return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 6733 | } |
| 6734 | else |
| 6735 | { |
| 6736 | return x86::rcpps(x); |
| 6737 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6738 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6739 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6740 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6741 | { |
| 6742 | return x86::rsqrtps(x); |
| 6743 | } |
| 6744 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6745 | RValue<Float4> Sqrt(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6746 | { |
| 6747 | return x86::sqrtps(x); |
| 6748 | } |
| 6749 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6750 | RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6751 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6752 | llvm::Value *value = val.loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6753 | llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i); |
| 6754 | |
| 6755 | val = RValue<Float4>(insert); |
| 6756 | |
| 6757 | return val; |
| 6758 | } |
| 6759 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6760 | RValue<Float> Extract(RValue<Float4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6761 | { |
| 6762 | return RValue<Float>(Nucleus::createExtractElement(x.value, i)); |
| 6763 | } |
| 6764 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6765 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6766 | { |
| 6767 | return RValue<Float4>(Nucleus::createSwizzle(x.value, select)); |
| 6768 | } |
| 6769 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6770 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6771 | { |
| 6772 | Constant *shuffle[4]; |
| 6773 | shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0); |
| 6774 | shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0); |
| 6775 | shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4); |
| 6776 | shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4); |
| 6777 | |
| 6778 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4))); |
| 6779 | } |
| 6780 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6781 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6782 | { |
| 6783 | Constant *shuffle[4]; |
| 6784 | shuffle[0] = Nucleus::createConstantInt(0); |
| 6785 | shuffle[1] = Nucleus::createConstantInt(4); |
| 6786 | shuffle[2] = Nucleus::createConstantInt(1); |
| 6787 | shuffle[3] = Nucleus::createConstantInt(5); |
| 6788 | |
| 6789 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4))); |
| 6790 | } |
| 6791 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6792 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6793 | { |
| 6794 | Constant *shuffle[4]; |
| 6795 | shuffle[0] = Nucleus::createConstantInt(2); |
| 6796 | shuffle[1] = Nucleus::createConstantInt(6); |
| 6797 | shuffle[2] = Nucleus::createConstantInt(3); |
| 6798 | shuffle[3] = Nucleus::createConstantInt(7); |
| 6799 | |
| 6800 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4))); |
| 6801 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6802 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6803 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6804 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6805 | Value *vector = lhs.loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6806 | Value *shuffle = Nucleus::createMask(vector, rhs.value, select); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6807 | lhs.storeValue(shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6808 | |
| 6809 | return RValue<Float4>(shuffle); |
| 6810 | } |
| 6811 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6812 | RValue<Int> SignMask(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6813 | { |
| 6814 | return x86::movmskps(x); |
| 6815 | } |
| 6816 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6817 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6818 | { |
| 6819 | // return As<Int4>(x86::cmpeqps(x, y)); |
| 6820 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6821 | } |
| 6822 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6823 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6824 | { |
| 6825 | // return As<Int4>(x86::cmpltps(x, y)); |
| 6826 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6827 | } |
| 6828 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6829 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6830 | { |
| 6831 | // return As<Int4>(x86::cmpleps(x, y)); |
| 6832 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6833 | } |
| 6834 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6835 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6836 | { |
| 6837 | // return As<Int4>(x86::cmpneqps(x, y)); |
| 6838 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6839 | } |
| 6840 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6841 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6842 | { |
| 6843 | // return As<Int4>(x86::cmpnltps(x, y)); |
| 6844 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6845 | } |
| 6846 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6847 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6848 | { |
| 6849 | // return As<Int4>(x86::cmpnleps(x, y)); |
| 6850 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6851 | } |
| 6852 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6853 | RValue<Float4> Round(RValue<Float4> x) |
| 6854 | { |
| 6855 | if(CPUID::supportsSSE4_1()) |
| 6856 | { |
| 6857 | return x86::roundps(x, 0); |
| 6858 | } |
| 6859 | else |
| 6860 | { |
| 6861 | return Float4(RoundInt(x)); |
| 6862 | } |
| 6863 | } |
| 6864 | |
| 6865 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6866 | { |
| 6867 | if(CPUID::supportsSSE4_1()) |
| 6868 | { |
| 6869 | return x86::roundps(x, 3); |
| 6870 | } |
| 6871 | else |
| 6872 | { |
| 6873 | return Float4(Int4(x)); // Rounded toward zero |
| 6874 | } |
| 6875 | } |
| 6876 | |
| 6877 | RValue<Float4> Frac(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6878 | { |
| 6879 | if(CPUID::supportsSSE4_1()) |
| 6880 | { |
| 6881 | return x - x86::floorps(x); |
| 6882 | } |
| 6883 | else |
| 6884 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6885 | Float4 frc = x - Float4(Int4(x)); // Signed fractional part |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6886 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6887 | return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6888 | } |
| 6889 | } |
| 6890 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6891 | RValue<Float4> Floor(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6892 | { |
| 6893 | if(CPUID::supportsSSE4_1()) |
| 6894 | { |
| 6895 | return x86::floorps(x); |
| 6896 | } |
| 6897 | else |
| 6898 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6899 | return x - Frac(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6900 | } |
| 6901 | } |
| 6902 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6903 | RValue<Float4> Ceil(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6904 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6905 | if(CPUID::supportsSSE4_1()) |
| 6906 | { |
| 6907 | return x86::ceilps(x); |
| 6908 | } |
| 6909 | else |
| 6910 | { |
| 6911 | return -Floor(-x); |
| 6912 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6913 | } |
| 6914 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6915 | Type *Float4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6916 | { |
| 6917 | return VectorType::get(Float::getType(), 4); |
| 6918 | } |
| 6919 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6920 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6921 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6922 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6923 | } |
| 6924 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6925 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6926 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6927 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6928 | } |
| 6929 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6930 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6931 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6932 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6933 | } |
| 6934 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6935 | RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6936 | { |
| 6937 | return lhs = lhs + offset; |
| 6938 | } |
| 6939 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6940 | RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6941 | { |
| 6942 | return lhs = lhs + offset; |
| 6943 | } |
| 6944 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6945 | RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6946 | { |
| 6947 | return lhs = lhs + offset; |
| 6948 | } |
| 6949 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6950 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6951 | { |
| 6952 | return lhs + -offset; |
| 6953 | } |
| 6954 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6955 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6956 | { |
| 6957 | return lhs + -offset; |
| 6958 | } |
| 6959 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6960 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6961 | { |
| 6962 | return lhs + -offset; |
| 6963 | } |
| 6964 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6965 | RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6966 | { |
| 6967 | return lhs = lhs - offset; |
| 6968 | } |
| 6969 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6970 | RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6971 | { |
| 6972 | return lhs = lhs - offset; |
| 6973 | } |
| 6974 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6975 | RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6976 | { |
| 6977 | return lhs = lhs - offset; |
| 6978 | } |
| 6979 | |
| 6980 | void Return() |
| 6981 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6982 | Nucleus::createRetVoid(); |
| 6983 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6984 | Nucleus::createUnreachable(); |
| 6985 | } |
| 6986 | |
| 6987 | void Return(bool ret) |
| 6988 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6989 | Nucleus::createRet(Nucleus::createConstantBool(ret)); |
| 6990 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6991 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | void Return(const Int &ret) |
| 6995 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6996 | Nucleus::createRet(ret.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6997 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6998 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | BasicBlock *beginLoop() |
| 7002 | { |
| 7003 | BasicBlock *loopBB = Nucleus::createBasicBlock(); |
| 7004 | |
| 7005 | Nucleus::createBr(loopBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7006 | Nucleus::setInsertBlock(loopBB); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7007 | |
| 7008 | return loopBB; |
| 7009 | } |
| 7010 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7011 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7012 | { |
| 7013 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7014 | Nucleus::setInsertBlock(bodyBB); |
| 7015 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7016 | return true; |
| 7017 | } |
| 7018 | |
| 7019 | bool elseBlock(BasicBlock *falseBB) |
| 7020 | { |
| 7021 | falseBB->back().eraseFromParent(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7022 | Nucleus::setInsertBlock(falseBB); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7023 | |
| 7024 | return true; |
| 7025 | } |
| 7026 | |
| 7027 | RValue<Long> Ticks() |
| 7028 | { |
| 7029 | Module *module = Nucleus::getModule(); |
| 7030 | llvm::Function *rdtsc = Intrinsic::getDeclaration(module, Intrinsic::readcyclecounter); |
| 7031 | |
| 7032 | return RValue<Long>(Nucleus::createCall(rdtsc)); |
| 7033 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | namespace sw |
| 7037 | { |
| 7038 | namespace x86 |
| 7039 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7040 | RValue<Int> cvtss2si(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7041 | { |
| 7042 | Module *module = Nucleus::getModule(); |
| 7043 | llvm::Function *cvtss2si = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtss2si); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7044 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7045 | Float4 vector; |
| 7046 | vector.x = val; |
| 7047 | |
| 7048 | return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value)); |
| 7049 | } |
| 7050 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7051 | RValue<Int2> cvtps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7052 | { |
| 7053 | Module *module = Nucleus::getModule(); |
| 7054 | llvm::Function *cvtps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvtps2pi); |
| 7055 | |
| 7056 | return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value)); |
| 7057 | } |
| 7058 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7059 | RValue<Int2> cvttps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7060 | { |
| 7061 | Module *module = Nucleus::getModule(); |
| 7062 | llvm::Function *cvttps2pi = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cvttps2pi); |
| 7063 | |
| 7064 | return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value)); |
| 7065 | } |
| 7066 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7067 | RValue<Int4> cvtps2dq(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7068 | { |
| 7069 | if(CPUID::supportsSSE2()) |
| 7070 | { |
| 7071 | Module *module = Nucleus::getModule(); |
| 7072 | llvm::Function *cvtps2dq = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_cvtps2dq); |
| 7073 | |
| 7074 | return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value)); |
| 7075 | } |
| 7076 | else |
| 7077 | { |
| 7078 | Int2 lo = x86::cvtps2pi(val); |
| 7079 | Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7080 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7081 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7082 | } |
| 7083 | } |
| 7084 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7085 | RValue<Float> rcpss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7086 | { |
| 7087 | Module *module = Nucleus::getModule(); |
| 7088 | llvm::Function *rcpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ss); |
| 7089 | |
| 7090 | Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7091 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7092 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rcpss, vector), 0)); |
| 7093 | } |
| 7094 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7095 | RValue<Float> sqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7096 | { |
| 7097 | Module *module = Nucleus::getModule(); |
| 7098 | llvm::Function *sqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ss); |
| 7099 | |
| 7100 | Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7101 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7102 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0)); |
| 7103 | } |
| 7104 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7105 | RValue<Float> rsqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7106 | { |
| 7107 | Module *module = Nucleus::getModule(); |
| 7108 | llvm::Function *rsqrtss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ss); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7109 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7110 | Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0); |
| 7111 | |
| 7112 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0)); |
| 7113 | } |
| 7114 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7115 | RValue<Float4> rcpps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7116 | { |
| 7117 | Module *module = Nucleus::getModule(); |
| 7118 | llvm::Function *rcpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rcp_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7119 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7120 | return RValue<Float4>(Nucleus::createCall(rcpps, val.value)); |
| 7121 | } |
| 7122 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7123 | RValue<Float4> sqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7124 | { |
| 7125 | Module *module = Nucleus::getModule(); |
| 7126 | llvm::Function *sqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_sqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7127 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7128 | return RValue<Float4>(Nucleus::createCall(sqrtps, val.value)); |
| 7129 | } |
| 7130 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7131 | RValue<Float4> rsqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7132 | { |
| 7133 | Module *module = Nucleus::getModule(); |
| 7134 | llvm::Function *rsqrtps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_rsqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7135 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7136 | return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value)); |
| 7137 | } |
| 7138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7139 | RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7140 | { |
| 7141 | Module *module = Nucleus::getModule(); |
| 7142 | llvm::Function *maxps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_max_ps); |
| 7143 | |
| 7144 | return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value)); |
| 7145 | } |
| 7146 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7147 | RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7148 | { |
| 7149 | Module *module = Nucleus::getModule(); |
| 7150 | llvm::Function *minps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_min_ps); |
| 7151 | |
| 7152 | return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value)); |
| 7153 | } |
| 7154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7155 | RValue<Float> roundss(RValue<Float> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7156 | { |
| 7157 | Module *module = Nucleus::getModule(); |
| 7158 | llvm::Function *roundss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ss); |
| 7159 | |
| 7160 | Value *undef = UndefValue::get(Float4::getType()); |
| 7161 | Value *vector = Nucleus::createInsertElement(undef, val.value, 0); |
| 7162 | |
| 7163 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0)); |
| 7164 | } |
| 7165 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7166 | RValue<Float> floorss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7167 | { |
| 7168 | return roundss(val, 1); |
| 7169 | } |
| 7170 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7171 | RValue<Float> ceilss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7172 | { |
| 7173 | return roundss(val, 2); |
| 7174 | } |
| 7175 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7176 | RValue<Float4> roundps(RValue<Float4> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7177 | { |
| 7178 | Module *module = Nucleus::getModule(); |
| 7179 | llvm::Function *roundps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_round_ps); |
| 7180 | |
| 7181 | return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm))); |
| 7182 | } |
| 7183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7184 | RValue<Float4> floorps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7185 | { |
| 7186 | return roundps(val, 1); |
| 7187 | } |
| 7188 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7189 | RValue<Float4> ceilps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7190 | { |
| 7191 | return roundps(val, 2); |
| 7192 | } |
| 7193 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7194 | RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7195 | { |
| 7196 | Module *module = Nucleus::getModule(); |
| 7197 | llvm::Function *cmpps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ps); |
| 7198 | |
| 7199 | return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm))); |
| 7200 | } |
| 7201 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7202 | RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7203 | { |
| 7204 | return cmpps(x, y, 0); |
| 7205 | } |
| 7206 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7207 | RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7208 | { |
| 7209 | return cmpps(x, y, 1); |
| 7210 | } |
| 7211 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7212 | RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7213 | { |
| 7214 | return cmpps(x, y, 2); |
| 7215 | } |
| 7216 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7217 | RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7218 | { |
| 7219 | return cmpps(x, y, 3); |
| 7220 | } |
| 7221 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7222 | RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7223 | { |
| 7224 | return cmpps(x, y, 4); |
| 7225 | } |
| 7226 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7227 | RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7228 | { |
| 7229 | return cmpps(x, y, 5); |
| 7230 | } |
| 7231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7232 | RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7233 | { |
| 7234 | return cmpps(x, y, 6); |
| 7235 | } |
| 7236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7237 | RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7238 | { |
| 7239 | return cmpps(x, y, 7); |
| 7240 | } |
| 7241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7242 | RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7243 | { |
| 7244 | Module *module = Nucleus::getModule(); |
| 7245 | llvm::Function *cmpss = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_cmp_ss); |
| 7246 | |
| 7247 | Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0); |
| 7248 | Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0); |
| 7249 | |
| 7250 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0)); |
| 7251 | } |
| 7252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7253 | RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7254 | { |
| 7255 | return cmpss(x, y, 0); |
| 7256 | } |
| 7257 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7258 | RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7259 | { |
| 7260 | return cmpss(x, y, 1); |
| 7261 | } |
| 7262 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7263 | RValue<Float> cmpless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7264 | { |
| 7265 | return cmpss(x, y, 2); |
| 7266 | } |
| 7267 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7268 | RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7269 | { |
| 7270 | return cmpss(x, y, 3); |
| 7271 | } |
| 7272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7273 | RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7274 | { |
| 7275 | return cmpss(x, y, 4); |
| 7276 | } |
| 7277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7278 | RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7279 | { |
| 7280 | return cmpss(x, y, 5); |
| 7281 | } |
| 7282 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7283 | RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7284 | { |
| 7285 | return cmpss(x, y, 6); |
| 7286 | } |
| 7287 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7288 | RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7289 | { |
| 7290 | return cmpss(x, y, 7); |
| 7291 | } |
| 7292 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 7293 | RValue<Int4> pabsd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7294 | { |
| 7295 | Module *module = Nucleus::getModule(); |
| 7296 | llvm::Function *pabsd = Intrinsic::getDeclaration(module, Intrinsic::x86_ssse3_pabs_d_128); |
| 7297 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 7298 | return RValue<Int4>(Nucleus::createCall(pabsd, x.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7299 | } |
| 7300 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7301 | RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7302 | { |
| 7303 | Module *module = Nucleus::getModule(); |
| 7304 | llvm::Function *paddsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_w); |
| 7305 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7306 | return As<Short4>(RValue<MMX>(Nucleus::createCall(paddsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7307 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7308 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7309 | RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7310 | { |
| 7311 | Module *module = Nucleus::getModule(); |
| 7312 | llvm::Function *psubsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_w); |
| 7313 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7314 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psubsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7315 | } |
| 7316 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7317 | RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7318 | { |
| 7319 | Module *module = Nucleus::getModule(); |
| 7320 | llvm::Function *paddusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_w); |
| 7321 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7322 | return As<UShort4>(RValue<MMX>(Nucleus::createCall(paddusw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7323 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7324 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7325 | RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7326 | { |
| 7327 | Module *module = Nucleus::getModule(); |
| 7328 | llvm::Function *psubusw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_w); |
| 7329 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7330 | return As<UShort4>(RValue<MMX>(Nucleus::createCall(psubusw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7331 | } |
| 7332 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7333 | RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7334 | { |
| 7335 | Module *module = Nucleus::getModule(); |
| 7336 | llvm::Function *paddsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padds_b); |
| 7337 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7338 | return As<SByte8>(RValue<MMX>(Nucleus::createCall(paddsb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7339 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7340 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7341 | RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7342 | { |
| 7343 | Module *module = Nucleus::getModule(); |
| 7344 | llvm::Function *psubsb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubs_b); |
| 7345 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7346 | return As<SByte8>(RValue<MMX>(Nucleus::createCall(psubsb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7347 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7348 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7349 | RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7350 | { |
| 7351 | Module *module = Nucleus::getModule(); |
| 7352 | llvm::Function *paddusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_paddus_b); |
| 7353 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7354 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddusb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7355 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7356 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7357 | RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7358 | { |
| 7359 | Module *module = Nucleus::getModule(); |
| 7360 | llvm::Function *psubusb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psubus_b); |
| 7361 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7362 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubusb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7363 | } |
| 7364 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7365 | RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y) |
| 7366 | { |
| 7367 | Module *module = Nucleus::getModule(); |
| 7368 | llvm::Function *paddw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_w); |
| 7369 | |
| 7370 | return As<Short4>(RValue<MMX>(Nucleus::createCall(paddw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7371 | } |
| 7372 | |
| 7373 | RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y) |
| 7374 | { |
| 7375 | Module *module = Nucleus::getModule(); |
| 7376 | llvm::Function *psubw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_w); |
| 7377 | |
| 7378 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psubw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7379 | } |
| 7380 | |
| 7381 | RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y) |
| 7382 | { |
| 7383 | Module *module = Nucleus::getModule(); |
| 7384 | llvm::Function *pmullw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmull_w); |
| 7385 | |
| 7386 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pmullw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7387 | } |
| 7388 | |
| 7389 | RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y) |
| 7390 | { |
| 7391 | Module *module = Nucleus::getModule(); |
| 7392 | llvm::Function *pand = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pand); |
| 7393 | |
| 7394 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pand, As<MMX>(x).value, As<MMX>(y).value))); |
| 7395 | } |
| 7396 | |
| 7397 | RValue<Short4> por(RValue<Short4> x, RValue<Short4> y) |
| 7398 | { |
| 7399 | Module *module = Nucleus::getModule(); |
| 7400 | llvm::Function *por = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_por); |
| 7401 | |
| 7402 | return As<Short4>(RValue<MMX>(Nucleus::createCall(por, As<MMX>(x).value, As<MMX>(y).value))); |
| 7403 | } |
| 7404 | |
| 7405 | RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y) |
| 7406 | { |
| 7407 | Module *module = Nucleus::getModule(); |
| 7408 | llvm::Function *pxor = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pxor); |
| 7409 | |
| 7410 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pxor, As<MMX>(x).value, As<MMX>(y).value))); |
| 7411 | } |
| 7412 | |
| 7413 | RValue<Short4> pshufw(RValue<Short4> x, unsigned char y) |
| 7414 | { |
| 7415 | Module *module = Nucleus::getModule(); |
| 7416 | llvm::Function *pshufw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_pshuf_w); |
| 7417 | |
| 7418 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pshufw, As<MMX>(x).value, Nucleus::createConstantByte(y)))); |
| 7419 | } |
| 7420 | |
| 7421 | RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y) |
| 7422 | { |
| 7423 | Module *module = Nucleus::getModule(); |
| 7424 | llvm::Function *punpcklwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklwd); |
| 7425 | |
| 7426 | return As<Int2>(RValue<MMX>(Nucleus::createCall(punpcklwd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7427 | } |
| 7428 | |
| 7429 | RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y) |
| 7430 | { |
| 7431 | Module *module = Nucleus::getModule(); |
| 7432 | llvm::Function *punpckhwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhwd); |
| 7433 | |
| 7434 | return As<Int2>(RValue<MMX>(Nucleus::createCall(punpckhwd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7435 | } |
| 7436 | |
| 7437 | RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i) |
| 7438 | { |
| 7439 | Module *module = Nucleus::getModule(); |
| 7440 | llvm::Function *pinsrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pinsr_w); |
| 7441 | |
| 7442 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pinsrw, As<MMX>(x).value, y.value, Nucleus::createConstantInt(i)))); |
| 7443 | } |
| 7444 | |
| 7445 | RValue<Int> pextrw(RValue<Short4> x, unsigned int i) |
| 7446 | { |
| 7447 | Module *module = Nucleus::getModule(); |
| 7448 | llvm::Function *pextrw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pextr_w); |
| 7449 | |
| 7450 | return RValue<Int>(Nucleus::createCall(pextrw, As<MMX>(x).value, Nucleus::createConstantInt(i))); |
| 7451 | } |
| 7452 | |
| 7453 | RValue<Long1> punpckldq(RValue<Int2> x, RValue<Int2> y) |
| 7454 | { |
| 7455 | Module *module = Nucleus::getModule(); |
| 7456 | llvm::Function *punpckldq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckldq); |
| 7457 | |
| 7458 | return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckldq, As<MMX>(x).value, As<MMX>(y).value))); |
| 7459 | } |
| 7460 | |
| 7461 | RValue<Long1> punpckhdq(RValue<Int2> x, RValue<Int2> y) |
| 7462 | { |
| 7463 | Module *module = Nucleus::getModule(); |
| 7464 | llvm::Function *punpckhdq = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhdq); |
| 7465 | |
| 7466 | return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckhdq, As<MMX>(x).value, As<MMX>(y).value))); |
| 7467 | } |
| 7468 | |
| 7469 | RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y) |
| 7470 | { |
| 7471 | Module *module = Nucleus::getModule(); |
| 7472 | llvm::Function *punpcklbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpcklbw); |
| 7473 | |
| 7474 | return As<Short4>(RValue<MMX>(Nucleus::createCall(punpcklbw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7475 | } |
| 7476 | |
| 7477 | RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y) |
| 7478 | { |
| 7479 | Module *module = Nucleus::getModule(); |
| 7480 | llvm::Function *punpckhbw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_punpckhbw); |
| 7481 | |
| 7482 | return As<Short4>(RValue<MMX>(Nucleus::createCall(punpckhbw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7483 | } |
| 7484 | |
| 7485 | RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y) |
| 7486 | { |
| 7487 | Module *module = Nucleus::getModule(); |
| 7488 | llvm::Function *paddb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_b); |
| 7489 | |
| 7490 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddb, As<MMX>(x).value, As<MMX>(y).value))); |
| 7491 | } |
| 7492 | |
| 7493 | RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y) |
| 7494 | { |
| 7495 | Module *module = Nucleus::getModule(); |
| 7496 | llvm::Function *psubb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_b); |
| 7497 | |
| 7498 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubb, As<MMX>(x).value, As<MMX>(y).value))); |
| 7499 | } |
| 7500 | |
| 7501 | RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y) |
| 7502 | { |
| 7503 | Module *module = Nucleus::getModule(); |
| 7504 | llvm::Function *paddd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_padd_d); |
| 7505 | |
| 7506 | return As<Int2>(RValue<MMX>(Nucleus::createCall(paddd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7507 | } |
| 7508 | |
| 7509 | RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y) |
| 7510 | { |
| 7511 | Module *module = Nucleus::getModule(); |
| 7512 | llvm::Function *psubd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psub_d); |
| 7513 | |
| 7514 | return As<Int2>(RValue<MMX>(Nucleus::createCall(psubd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7515 | } |
| 7516 | |
| 7517 | RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7518 | { |
| 7519 | Module *module = Nucleus::getModule(); |
| 7520 | llvm::Function *pavgw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pavg_w); |
| 7521 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7522 | return As<UShort4>(RValue<MMX>(Nucleus::createCall(pavgw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7523 | } |
| 7524 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7525 | RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7526 | { |
| 7527 | Module *module = Nucleus::getModule(); |
| 7528 | llvm::Function *pmaxsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmaxs_w); |
| 7529 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7530 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pmaxsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7531 | } |
| 7532 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7533 | RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7534 | { |
| 7535 | Module *module = Nucleus::getModule(); |
| 7536 | llvm::Function *pminsw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmins_w); |
| 7537 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7538 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pminsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7539 | } |
| 7540 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7541 | RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7542 | { |
| 7543 | Module *module = Nucleus::getModule(); |
| 7544 | llvm::Function *pcmpgtw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_w); |
| 7545 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7546 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpgtw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7547 | } |
| 7548 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7549 | RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7550 | { |
| 7551 | Module *module = Nucleus::getModule(); |
| 7552 | llvm::Function *pcmpeqw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_w); |
| 7553 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7554 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pcmpeqw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7555 | } |
| 7556 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7557 | RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7558 | { |
| 7559 | Module *module = Nucleus::getModule(); |
| 7560 | llvm::Function *pcmpgtb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpgt_b); |
| 7561 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7562 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpgtb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7563 | } |
| 7564 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7565 | RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7566 | { |
| 7567 | Module *module = Nucleus::getModule(); |
| 7568 | llvm::Function *pcmpeqb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pcmpeq_b); |
| 7569 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7570 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(pcmpeqb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7571 | } |
| 7572 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7573 | RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7574 | { |
| 7575 | Module *module = Nucleus::getModule(); |
| 7576 | llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packssdw); |
| 7577 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7578 | return As<Short4>(RValue<MMX>(Nucleus::createCall(packssdw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7579 | } |
| 7580 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7581 | RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7582 | { |
| 7583 | if(CPUID::supportsSSE2()) |
| 7584 | { |
| 7585 | Module *module = Nucleus::getModule(); |
| 7586 | llvm::Function *packssdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_packssdw_128); |
| 7587 | |
| 7588 | return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value)); |
| 7589 | } |
| 7590 | else |
| 7591 | { |
| 7592 | Int2 loX = Int2(x); |
| 7593 | Int2 hiX = Int2(Swizzle(x, 0xEE)); |
| 7594 | |
| 7595 | Int2 loY = Int2(y); |
| 7596 | Int2 hiY = Int2(Swizzle(y, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7597 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7598 | Short4 lo = x86::packssdw(loX, hiX); |
| 7599 | Short4 hi = x86::packssdw(loY, hiY); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7600 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7601 | return Short8(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7602 | } |
| 7603 | } |
| 7604 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7605 | RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7606 | { |
| 7607 | Module *module = Nucleus::getModule(); |
| 7608 | llvm::Function *packsswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packsswb); |
| 7609 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7610 | return As<SByte8>(RValue<MMX>(Nucleus::createCall(packsswb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7611 | } |
| 7612 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7613 | RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7614 | { |
| 7615 | Module *module = Nucleus::getModule(); |
| 7616 | llvm::Function *packuswb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_packuswb); |
| 7617 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7618 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(packuswb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7619 | } |
| 7620 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7621 | RValue<UShort8> packusdw(RValue<UInt4> x, RValue<UInt4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7622 | { |
| 7623 | if(CPUID::supportsSSE4_1()) |
| 7624 | { |
| 7625 | Module *module = Nucleus::getModule(); |
| 7626 | llvm::Function *packusdw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_packusdw); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7627 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7628 | return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value)); |
| 7629 | } |
| 7630 | else |
| 7631 | { |
| 7632 | // FIXME: Not an exact replacement! |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7633 | 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 Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7634 | } |
| 7635 | } |
| 7636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7637 | RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7638 | { |
| 7639 | Module *module = Nucleus::getModule(); |
| 7640 | llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_w); |
| 7641 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7642 | return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, Nucleus::createConstantInt(y)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7643 | } |
| 7644 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7645 | RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7646 | { |
| 7647 | Module *module = Nucleus::getModule(); |
| 7648 | llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_w); |
| 7649 | |
| 7650 | return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y))); |
| 7651 | } |
| 7652 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7653 | RValue<Short4> psraw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7654 | { |
| 7655 | Module *module = Nucleus::getModule(); |
| 7656 | llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_w); |
| 7657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7658 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, Nucleus::createConstantInt(y)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7659 | } |
| 7660 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7661 | RValue<Short8> psraw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7662 | { |
| 7663 | Module *module = Nucleus::getModule(); |
| 7664 | llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_w); |
| 7665 | |
| 7666 | return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y))); |
| 7667 | } |
| 7668 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7669 | RValue<Short4> psllw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7670 | { |
| 7671 | Module *module = Nucleus::getModule(); |
| 7672 | llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_w); |
| 7673 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7674 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, Nucleus::createConstantInt(y)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7675 | } |
| 7676 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7677 | RValue<Short8> psllw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7678 | { |
| 7679 | Module *module = Nucleus::getModule(); |
| 7680 | llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_w); |
| 7681 | |
| 7682 | return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y))); |
| 7683 | } |
| 7684 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7685 | RValue<Int2> pslld(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7686 | { |
| 7687 | Module *module = Nucleus::getModule(); |
| 7688 | llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pslli_d); |
| 7689 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7690 | return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, Nucleus::createConstantInt(y)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7691 | } |
| 7692 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7693 | RValue<Int4> pslld(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7694 | { |
| 7695 | if(CPUID::supportsSSE2()) |
| 7696 | { |
| 7697 | Module *module = Nucleus::getModule(); |
| 7698 | llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pslli_d); |
| 7699 | |
| 7700 | return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y))); |
| 7701 | } |
| 7702 | else |
| 7703 | { |
| 7704 | Int2 lo = Int2(x); |
| 7705 | Int2 hi = Int2(Swizzle(x, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7706 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7707 | lo = x86::pslld(lo, y); |
| 7708 | hi = x86::pslld(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7709 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7710 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7711 | } |
| 7712 | } |
| 7713 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7714 | RValue<Int2> psrad(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7715 | { |
| 7716 | Module *module = Nucleus::getModule(); |
| 7717 | llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrai_d); |
| 7718 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7719 | return As<Int2>(RValue<MMX>(Nucleus::createCall(psrad, As<MMX>(x).value, Nucleus::createConstantInt(y)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7720 | } |
| 7721 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7722 | RValue<Int4> psrad(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7723 | { |
| 7724 | if(CPUID::supportsSSE2()) |
| 7725 | { |
| 7726 | Module *module = Nucleus::getModule(); |
| 7727 | llvm::Function *psrad = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrai_d); |
| 7728 | |
| 7729 | return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y))); |
| 7730 | } |
| 7731 | else |
| 7732 | { |
| 7733 | Int2 lo = Int2(x); |
| 7734 | Int2 hi = Int2(Swizzle(x, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7735 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7736 | lo = x86::psrad(lo, y); |
| 7737 | hi = x86::psrad(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7738 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7739 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7740 | } |
| 7741 | } |
| 7742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7743 | RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7744 | { |
| 7745 | Module *module = Nucleus::getModule(); |
| 7746 | llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrli_d); |
| 7747 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7748 | return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, Nucleus::createConstantInt(y)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7749 | } |
| 7750 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7751 | RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7752 | { |
| 7753 | if(CPUID::supportsSSE2()) |
| 7754 | { |
| 7755 | Module *module = Nucleus::getModule(); |
| 7756 | llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_psrli_d); |
| 7757 | |
| 7758 | return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y))); |
| 7759 | } |
| 7760 | else |
| 7761 | { |
| 7762 | UInt2 lo = As<UInt2>(Int2(As<Int4>(x))); |
| 7763 | UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7764 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7765 | lo = x86::psrld(lo, y); |
| 7766 | hi = x86::psrld(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7767 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7768 | return UInt4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7769 | } |
| 7770 | } |
| 7771 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7772 | RValue<UShort4> psrlw(RValue<UShort4> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7773 | { |
| 7774 | Module *module = Nucleus::getModule(); |
| 7775 | llvm::Function *psrlw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_w); |
| 7776 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7777 | return As<UShort4>(RValue<MMX>(Nucleus::createCall(psrlw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7778 | } |
| 7779 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7780 | RValue<Short4> psraw(RValue<Short4> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7781 | { |
| 7782 | Module *module = Nucleus::getModule(); |
| 7783 | llvm::Function *psraw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_w); |
| 7784 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7785 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psraw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7786 | } |
| 7787 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7788 | RValue<Short4> psllw(RValue<Short4> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7789 | { |
| 7790 | Module *module = Nucleus::getModule(); |
| 7791 | llvm::Function *psllw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_w); |
| 7792 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7793 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psllw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7794 | } |
| 7795 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7796 | RValue<Int2> pslld(RValue<Int2> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7797 | { |
| 7798 | Module *module = Nucleus::getModule(); |
| 7799 | llvm::Function *pslld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psll_d); |
| 7800 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7801 | return As<Int2>(RValue<MMX>(Nucleus::createCall(pslld, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7802 | } |
| 7803 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7804 | RValue<UInt2> psrld(RValue<UInt2> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7805 | { |
| 7806 | Module *module = Nucleus::getModule(); |
| 7807 | llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psrl_d); |
| 7808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7809 | return As<UInt2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7810 | } |
| 7811 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7812 | RValue<Int2> psrad(RValue<Int2> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7813 | { |
| 7814 | Module *module = Nucleus::getModule(); |
| 7815 | llvm::Function *psrld = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_psra_d); |
| 7816 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7817 | return As<Int2>(RValue<MMX>(Nucleus::createCall(psrld, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7818 | } |
| 7819 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7820 | RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y) |
| 7821 | { |
| 7822 | Module *module = Nucleus::getModule(); |
| 7823 | llvm::Function *pmaxsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxsd); |
| 7824 | |
| 7825 | return RValue<Int4>(Nucleus::createCall(pmaxsd, x.value, y.value)); |
| 7826 | } |
| 7827 | |
| 7828 | RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y) |
| 7829 | { |
| 7830 | Module *module = Nucleus::getModule(); |
| 7831 | llvm::Function *pminsd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminsd); |
| 7832 | |
| 7833 | return RValue<Int4>(Nucleus::createCall(pminsd, x.value, y.value)); |
| 7834 | } |
| 7835 | |
| 7836 | RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y) |
| 7837 | { |
| 7838 | Module *module = Nucleus::getModule(); |
| 7839 | llvm::Function *pmaxud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmaxud); |
| 7840 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7841 | return RValue<UInt4>(Nucleus::createCall(pmaxud, x.value, y.value)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7842 | } |
| 7843 | |
| 7844 | RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y) |
| 7845 | { |
| 7846 | Module *module = Nucleus::getModule(); |
| 7847 | llvm::Function *pminud = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pminud); |
| 7848 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7849 | return RValue<UInt4>(Nucleus::createCall(pminud, x.value, y.value)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7850 | } |
| 7851 | |
| 7852 | RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7853 | { |
| 7854 | Module *module = Nucleus::getModule(); |
| 7855 | llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulh_w); |
| 7856 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7857 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pmulhw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7858 | } |
| 7859 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7860 | RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7861 | { |
| 7862 | Module *module = Nucleus::getModule(); |
| 7863 | llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmulhu_w); |
| 7864 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7865 | return As<UShort4>(RValue<MMX>(Nucleus::createCall(pmulhuw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7866 | } |
| 7867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7868 | RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7869 | { |
| 7870 | Module *module = Nucleus::getModule(); |
| 7871 | llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmadd_wd); |
| 7872 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7873 | return As<Int2>(RValue<MMX>(Nucleus::createCall(pmaddwd, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7874 | } |
| 7875 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7876 | RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7877 | { |
| 7878 | Module *module = Nucleus::getModule(); |
| 7879 | llvm::Function *pmulhw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulh_w); |
| 7880 | |
| 7881 | return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value)); |
| 7882 | } |
| 7883 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7884 | RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7885 | { |
| 7886 | Module *module = Nucleus::getModule(); |
| 7887 | llvm::Function *pmulhuw = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmulhu_w); |
| 7888 | |
| 7889 | return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value)); |
| 7890 | } |
| 7891 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7892 | RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7893 | { |
| 7894 | Module *module = Nucleus::getModule(); |
| 7895 | llvm::Function *pmaddwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse2_pmadd_wd); |
| 7896 | |
| 7897 | return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value)); |
| 7898 | } |
| 7899 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7900 | RValue<Int> movmskps(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7901 | { |
| 7902 | Module *module = Nucleus::getModule(); |
| 7903 | llvm::Function *movmskps = Intrinsic::getDeclaration(module, Intrinsic::x86_sse_movmsk_ps); |
| 7904 | |
| 7905 | return RValue<Int>(Nucleus::createCall(movmskps, x.value)); |
| 7906 | } |
| 7907 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7908 | RValue<Int> pmovmskb(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7909 | { |
| 7910 | Module *module = Nucleus::getModule(); |
| 7911 | llvm::Function *pmovmskb = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_pmovmskb); |
| 7912 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7913 | return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7914 | } |
| 7915 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 7916 | //RValue<Int2> movd(RValue<Pointer<Int>> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7917 | //{ |
| 7918 | // Value *element = Nucleus::createLoad(x.value); |
| 7919 | |
| 7920 | //// Value *int2 = UndefValue::get(Int2::getType()); |
| 7921 | //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0)); |
| 7922 | |
| 7923 | // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType()); |
| 7924 | |
| 7925 | // return RValue<Int2>(int2); |
| 7926 | //} |
| 7927 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7928 | //RValue<Int2> movdq2q(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7929 | //{ |
| 7930 | // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType()); |
| 7931 | // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0)); |
| 7932 | |
| 7933 | // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType())); |
| 7934 | //} |
| 7935 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7936 | RValue<Int4> pmovzxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7937 | { |
| 7938 | Module *module = Nucleus::getModule(); |
| 7939 | llvm::Function *pmovzxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7940 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7941 | return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType()))); |
| 7942 | } |
| 7943 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7944 | RValue<Int4> pmovsxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7945 | { |
| 7946 | Module *module = Nucleus::getModule(); |
| 7947 | llvm::Function *pmovsxbd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7948 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7949 | return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType()))); |
| 7950 | } |
| 7951 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7952 | RValue<Int4> pmovzxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7953 | { |
| 7954 | Module *module = Nucleus::getModule(); |
| 7955 | llvm::Function *pmovzxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovzxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7956 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7957 | return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType()))); |
| 7958 | } |
| 7959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7960 | RValue<Int4> pmovsxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7961 | { |
| 7962 | Module *module = Nucleus::getModule(); |
| 7963 | llvm::Function *pmovsxwd = Intrinsic::getDeclaration(module, Intrinsic::x86_sse41_pmovsxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7964 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7965 | return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType()))); |
| 7966 | } |
| 7967 | |
| 7968 | void emms() |
| 7969 | { |
| 7970 | Module *module = Nucleus::getModule(); |
| 7971 | llvm::Function *emms = Intrinsic::getDeclaration(module, Intrinsic::x86_mmx_emms); |
| 7972 | |
| 7973 | Nucleus::createCall(emms); |
| 7974 | } |
| 7975 | } |
| 7976 | } |