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 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 61 | namespace |
| 62 | { |
| 63 | sw::RoutineManager *routineManager = nullptr; |
| 64 | llvm::ExecutionEngine *executionEngine = nullptr; |
| 65 | llvm::IRBuilder<> *builder = nullptr; |
| 66 | llvm::LLVMContext *context = nullptr; |
| 67 | llvm::Module *module = nullptr; |
| 68 | llvm::Function *function = nullptr; |
| 69 | } |
| 70 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 71 | namespace sw |
| 72 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 73 | using namespace llvm; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 74 | BackoffLock Nucleus::codegenMutex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 75 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 76 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 77 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 78 | class Type : public llvm::Type |
| 79 | { |
| 80 | }; |
| 81 | |
| 82 | inline Type *T(llvm::Type *t) |
| 83 | { |
| 84 | return reinterpret_cast<Type*>(t); |
| 85 | } |
| 86 | |
| 87 | inline std::vector<llvm::Type*> &T(std::vector<Type*> &t) |
| 88 | { |
| 89 | return reinterpret_cast<std::vector<llvm::Type*>&>(t); |
| 90 | } |
| 91 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 92 | Nucleus::Nucleus() |
| 93 | { |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 94 | codegenMutex.lock(); // Reactor and LLVM are currently not thread safe |
| 95 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 96 | InitializeNativeTarget(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 97 | JITEmitDebugInfo = false; |
| 98 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 99 | if(!::context) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 100 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 101 | ::context = new LLVMContext(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 104 | ::module = new Module("", *::context); |
| 105 | ::routineManager = new RoutineManager(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 106 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 107 | #if defined(__x86_64__) |
| 108 | const char *architecture = "x86-64"; |
| 109 | #else |
| 110 | const char *architecture = "x86"; |
| 111 | #endif |
| 112 | |
| 113 | SmallVector<std::string, 1> MAttrs; |
| 114 | MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx"); |
| 115 | MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov"); |
| 116 | MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse"); |
| 117 | MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2"); |
| 118 | MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3"); |
| 119 | MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3"); |
| 120 | MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41"); |
| 121 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 122 | std::string error; |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 123 | TargetMachine *targetMachine = EngineBuilder::selectTarget(::module, architecture, "", MAttrs, Reloc::Default, CodeModel::JITDefault, &error); |
| 124 | ::executionEngine = JIT::createJIT(::module, 0, ::routineManager, CodeGenOpt::Aggressive, true, targetMachine); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 125 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 126 | if(!::builder) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 127 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 128 | ::builder = new IRBuilder<>(*::context); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 129 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 130 | #if defined(_WIN32) |
| 131 | HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll"); |
| 132 | if(CodeAnalyst) |
| 133 | { |
| 134 | CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize"); |
| 135 | CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog"); |
| 136 | CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode"); |
| 137 | |
| 138 | CodeAnalystInitialize(); |
| 139 | } |
| 140 | #endif |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
| 144 | Nucleus::~Nucleus() |
| 145 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 146 | delete ::executionEngine; |
| 147 | ::executionEngine = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 148 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 149 | ::routineManager = nullptr; |
| 150 | ::function = nullptr; |
| 151 | ::module = nullptr; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 152 | |
| 153 | codegenMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 157 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 158 | if(::builder->GetInsertBlock()->empty() || !::builder->GetInsertBlock()->back().isTerminator()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 159 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 160 | llvm::Type *type = ::function->getReturnType(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 161 | |
| 162 | if(type->isVoidTy()) |
| 163 | { |
| 164 | createRetVoid(); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | createRet(UndefValue::get(type)); |
| 169 | } |
| 170 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 171 | |
| 172 | if(false) |
| 173 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 174 | std::string error; |
| 175 | raw_fd_ostream file("llvm-dump-unopt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 176 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | if(runOptimizations) |
| 180 | { |
| 181 | optimize(); |
| 182 | } |
| 183 | |
| 184 | if(false) |
| 185 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 186 | std::string error; |
| 187 | raw_fd_ostream file("llvm-dump-opt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 188 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 191 | void *entry = ::executionEngine->getPointerToFunction(::function); |
| 192 | Routine *routine = ::routineManager->acquireRoutine(entry); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 193 | |
| 194 | if(CodeAnalystLogJITCode) |
| 195 | { |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 196 | CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | return routine; |
| 200 | } |
| 201 | |
| 202 | void Nucleus::optimize() |
| 203 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 204 | static PassManager *passManager = nullptr; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 205 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 206 | if(!passManager) |
| 207 | { |
| 208 | passManager = new PassManager(); |
| 209 | |
| 210 | UnsafeFPMath = true; |
| 211 | // NoInfsFPMath = true; |
| 212 | // NoNaNsFPMath = true; |
| 213 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 214 | passManager->add(new TargetData(*::executionEngine->getTargetData())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 215 | passManager->add(createScalarReplAggregatesPass()); |
| 216 | |
| 217 | for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++) |
| 218 | { |
| 219 | switch(optimization[pass]) |
| 220 | { |
| 221 | case Disabled: break; |
| 222 | case CFGSimplification: passManager->add(createCFGSimplificationPass()); break; |
| 223 | case LICM: passManager->add(createLICMPass()); break; |
| 224 | case AggressiveDCE: passManager->add(createAggressiveDCEPass()); break; |
| 225 | case GVN: passManager->add(createGVNPass()); break; |
| 226 | case InstructionCombining: passManager->add(createInstructionCombiningPass()); break; |
| 227 | case Reassociate: passManager->add(createReassociatePass()); break; |
| 228 | case DeadStoreElimination: passManager->add(createDeadStoreEliminationPass()); break; |
| 229 | case SCCP: passManager->add(createSCCPPass()); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 230 | case ScalarReplAggregates: passManager->add(createScalarReplAggregatesPass()); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 231 | default: |
| 232 | assert(false); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 237 | passManager->run(*::module); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 238 | } |
| 239 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 240 | Value *Nucleus::allocateStackVariable(Type *type, int arraySize) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 241 | { |
| 242 | // Need to allocate it in the entry block for mem2reg to work |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 243 | BasicBlock &entryBlock = ::function->getEntryBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 244 | |
| 245 | Instruction *declaration; |
| 246 | |
| 247 | if(arraySize) |
| 248 | { |
| 249 | declaration = new AllocaInst(type, Nucleus::createConstantInt(arraySize)); |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | declaration = new AllocaInst(type, (Value*)0); |
| 254 | } |
| 255 | |
| 256 | entryBlock.getInstList().push_front(declaration); |
| 257 | |
| 258 | return declaration; |
| 259 | } |
| 260 | |
| 261 | BasicBlock *Nucleus::createBasicBlock() |
| 262 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 263 | return BasicBlock::Create(*::context, "", ::function); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | BasicBlock *Nucleus::getInsertBlock() |
| 267 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 268 | return ::builder->GetInsertBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 272 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 273 | // assert(::builder->GetInsertBlock()->back().isTerminator()); |
| 274 | return ::builder->SetInsertPoint(basicBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | BasicBlock *Nucleus::getPredecessor(BasicBlock *basicBlock) |
| 278 | { |
| 279 | return *pred_begin(basicBlock); |
| 280 | } |
| 281 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 282 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 283 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 284 | llvm::FunctionType *functionType = llvm::FunctionType::get(ReturnType, T(Params), false); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 285 | ::function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", ::module); |
| 286 | ::function->setCallingConv(llvm::CallingConv::C); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 287 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 288 | ::builder->SetInsertPoint(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 291 | llvm::Value *Nucleus::getArgument(unsigned int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 292 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 293 | llvm::Function::arg_iterator args = ::function->arg_begin(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 294 | |
| 295 | while(index) |
| 296 | { |
| 297 | args++; |
| 298 | index--; |
| 299 | } |
| 300 | |
| 301 | return &*args; |
| 302 | } |
| 303 | |
| 304 | Value *Nucleus::createRetVoid() |
| 305 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 306 | x86::emms(); |
| 307 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 308 | return ::builder->CreateRetVoid(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | Value *Nucleus::createRet(Value *V) |
| 312 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 313 | x86::emms(); |
| 314 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 315 | return ::builder->CreateRet(V); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | Value *Nucleus::createBr(BasicBlock *dest) |
| 319 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 320 | return ::builder->CreateBr(dest); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | Value *Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 324 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 325 | return ::builder->CreateCondBr(cond, ifTrue, ifFalse); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 329 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 330 | return ::builder->CreateAdd(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 334 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 335 | return ::builder->CreateSub(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 339 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 340 | return ::builder->CreateMul(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 344 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 345 | return ::builder->CreateUDiv(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 349 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 350 | return ::builder->CreateSDiv(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 354 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 355 | return ::builder->CreateFAdd(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 359 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 360 | return ::builder->CreateFSub(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 364 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 365 | return ::builder->CreateFMul(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 369 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 370 | return ::builder->CreateFDiv(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 374 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 375 | return ::builder->CreateURem(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 379 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 380 | return ::builder->CreateSRem(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 384 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 385 | return ::builder->CreateFRem(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 389 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 390 | return ::builder->CreateShl(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 394 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 395 | return ::builder->CreateLShr(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 399 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 400 | return ::builder->CreateAShr(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 404 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 405 | return ::builder->CreateAnd(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 409 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 410 | return ::builder->CreateOr(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 414 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 415 | return ::builder->CreateXor(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | Value *Nucleus::createNeg(Value *V) |
| 419 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 420 | return ::builder->CreateNeg(V); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | Value *Nucleus::createFNeg(Value *V) |
| 424 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 425 | return ::builder->CreateFNeg(V); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | Value *Nucleus::createNot(Value *V) |
| 429 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 430 | return ::builder->CreateNot(V); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align) |
| 434 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 435 | return ::builder->Insert(new LoadInst(ptr, "", isVolatile, align)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align) |
| 439 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 440 | return ::builder->Insert(new StoreInst(value, ptr, isVolatile, align)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 441 | } |
| 442 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 443 | Value *Nucleus::createStore(Constant *constant, Value *ptr, bool isVolatile, unsigned int align) |
| 444 | { |
| 445 | return ::builder->Insert(new StoreInst(constant, ptr, isVolatile, align)); |
| 446 | } |
| 447 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 448 | Value *Nucleus::createGEP(Value *ptr, Value *index) |
| 449 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 450 | return ::builder->CreateGEP(ptr, index); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 451 | } |
| 452 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 453 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 454 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 455 | return ::builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, value, SequentiallyConsistent); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | Value *Nucleus::createTrunc(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 459 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 460 | return ::builder->CreateTrunc(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 461 | } |
| 462 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 463 | Value *Nucleus::createZExt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 464 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 465 | return ::builder->CreateZExt(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 466 | } |
| 467 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 468 | Value *Nucleus::createSExt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 469 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 470 | return ::builder->CreateSExt(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 471 | } |
| 472 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 473 | Value *Nucleus::createFPToSI(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 474 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 475 | return ::builder->CreateFPToSI(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 476 | } |
| 477 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 478 | Value *Nucleus::createUIToFP(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 479 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 480 | return ::builder->CreateUIToFP(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 481 | } |
| 482 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 483 | Value *Nucleus::createSIToFP(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 484 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 485 | return ::builder->CreateSIToFP(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 486 | } |
| 487 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 488 | Value *Nucleus::createFPTrunc(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 489 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 490 | return ::builder->CreateFPTrunc(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 491 | } |
| 492 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 493 | Value *Nucleus::createFPExt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 494 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 495 | return ::builder->CreateFPExt(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 496 | } |
| 497 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 498 | Value *Nucleus::createPtrToInt(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 500 | return ::builder->CreatePtrToInt(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 501 | } |
| 502 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 503 | Value *Nucleus::createIntToPtr(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 504 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 505 | return ::builder->CreateIntToPtr(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 506 | } |
| 507 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 508 | Value *Nucleus::createBitCast(Value *V, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 509 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 510 | return ::builder->CreateBitCast(V, destType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 511 | } |
| 512 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 513 | Value *Nucleus::createIntCast(Value *V, Type *destType, bool isSigned) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 514 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 515 | return ::builder->CreateIntCast(V, destType, isSigned); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 519 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 520 | return ::builder->CreateICmpEQ(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 524 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 525 | return ::builder->CreateICmpNE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 529 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 530 | return ::builder->CreateICmpUGT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 534 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 535 | return ::builder->CreateICmpUGE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 539 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 540 | return ::builder->CreateICmpULT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 544 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 545 | return ::builder->CreateICmpULE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 549 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 550 | return ::builder->CreateICmpSGT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 554 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 555 | return ::builder->CreateICmpSGE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 559 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 560 | return ::builder->CreateICmpSLT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 564 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 565 | return ::builder->CreateICmpSLE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 569 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 570 | return ::builder->CreateFCmpOEQ(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 574 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 575 | return ::builder->CreateFCmpOGT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 579 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 580 | return ::builder->CreateFCmpOGE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 584 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 585 | return ::builder->CreateFCmpOLT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 589 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 590 | return ::builder->CreateFCmpOLE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 594 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 595 | return ::builder->CreateFCmpONE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 599 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 600 | return ::builder->CreateFCmpORD(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 604 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 605 | return ::builder->CreateFCmpUNO(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 609 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 610 | return ::builder->CreateFCmpUEQ(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 614 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 615 | return ::builder->CreateFCmpUGT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 619 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 620 | return ::builder->CreateFCmpUGE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 624 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 625 | return ::builder->CreateFCmpULT(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 629 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 630 | return ::builder->CreateFCmpULE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 634 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 635 | return ::builder->CreateFCmpULE(lhs, rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | Value *Nucleus::createCall(Value *callee) |
| 639 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 640 | return ::builder->CreateCall(callee); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | Value *Nucleus::createCall(Value *callee, Value *arg) |
| 644 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 645 | return ::builder->CreateCall(callee, arg); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2) |
| 649 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 650 | return ::builder->CreateCall2(callee, arg1, arg2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3) |
| 654 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 655 | return ::builder->CreateCall3(callee, arg1, arg2, arg3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3, Value *arg4) |
| 659 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 660 | return ::builder->CreateCall4(callee, arg1, arg2, arg3, arg4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | Value *Nucleus::createExtractElement(Value *vector, int index) |
| 664 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 665 | return ::builder->CreateExtractElement(vector, createConstantInt(index)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 669 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 670 | return ::builder->CreateInsertElement(vector, element, createConstantInt(index)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, Value *mask) |
| 674 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 675 | return ::builder->CreateShuffleVector(V1, V2, mask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 679 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 680 | return ::builder->CreateSelect(C, ifTrue, ifFalse); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | Value *Nucleus::createSwitch(llvm::Value *V, llvm::BasicBlock *Dest, unsigned NumCases) |
| 684 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 685 | return ::builder->CreateSwitch(V, Dest, NumCases); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | void Nucleus::addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch) |
| 689 | { |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 690 | static_cast<SwitchInst*>(Switch)->addCase(llvm::ConstantInt::get(Type::getInt32Ty(*::context), Case, true), Branch); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | Value *Nucleus::createUnreachable() |
| 694 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 695 | return ::builder->CreateUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | Value *Nucleus::createSwizzle(Value *val, unsigned char select) |
| 699 | { |
| 700 | Constant *swizzle[4]; |
| 701 | swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03); |
| 702 | swizzle[1] = Nucleus::createConstantInt((select >> 2) & 0x03); |
| 703 | swizzle[2] = Nucleus::createConstantInt((select >> 4) & 0x03); |
| 704 | swizzle[3] = Nucleus::createConstantInt((select >> 6) & 0x03); |
| 705 | |
| 706 | Value *shuffle = Nucleus::createShuffleVector(val, UndefValue::get(val->getType()), Nucleus::createConstantVector(swizzle, 4)); |
| 707 | |
| 708 | return shuffle; |
| 709 | } |
| 710 | |
| 711 | Value *Nucleus::createMask(Value *lhs, Value *rhs, unsigned char select) |
| 712 | { |
| 713 | bool mask[4] = {false, false, false, false}; |
| 714 | |
| 715 | mask[(select >> 0) & 0x03] = true; |
| 716 | mask[(select >> 2) & 0x03] = true; |
| 717 | mask[(select >> 4) & 0x03] = true; |
| 718 | mask[(select >> 6) & 0x03] = true; |
| 719 | |
| 720 | Constant *swizzle[4]; |
| 721 | swizzle[0] = Nucleus::createConstantInt(mask[0] ? 4 : 0); |
| 722 | swizzle[1] = Nucleus::createConstantInt(mask[1] ? 5 : 1); |
| 723 | swizzle[2] = Nucleus::createConstantInt(mask[2] ? 6 : 2); |
| 724 | swizzle[3] = Nucleus::createConstantInt(mask[3] ? 7 : 3); |
| 725 | |
| 726 | Value *shuffle = Nucleus::createShuffleVector(lhs, rhs, Nucleus::createConstantVector(swizzle, 4)); |
| 727 | |
| 728 | return shuffle; |
| 729 | } |
| 730 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 731 | llvm::Constant *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 732 | { |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 733 | const GlobalValue *existingGlobal = ::executionEngine->getGlobalValueAtAddress(const_cast<void*>(address)); // FIXME: Const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 734 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 735 | if(existingGlobal) |
| 736 | { |
| 737 | return (llvm::Constant*)existingGlobal; |
| 738 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 739 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 740 | llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, ""); |
| 741 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 742 | global->setAlignment(Align); |
| 743 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 744 | ::executionEngine->addGlobalMapping(global, const_cast<void*>(address)); |
| 745 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 746 | return global; |
| 747 | } |
| 748 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 749 | Type *Nucleus::getPointerType(Type *ElementType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 750 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 751 | return T(llvm::PointerType::get(ElementType, 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 752 | } |
| 753 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 754 | llvm::Constant *Nucleus::createNullValue(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 755 | { |
| 756 | return llvm::Constant::getNullValue(Ty); |
| 757 | } |
| 758 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 759 | llvm::Constant *Nucleus::createConstantInt(int64_t i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 760 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 761 | return llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 762 | } |
| 763 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 764 | llvm::Constant *Nucleus::createConstantInt(int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 765 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 766 | return llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 769 | llvm::Constant *Nucleus::createConstantInt(unsigned int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 770 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 771 | return llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 772 | } |
| 773 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 774 | llvm::Constant *Nucleus::createConstantBool(bool b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 775 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 776 | return llvm::ConstantInt::get(Type::getInt1Ty(*::context), b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 777 | } |
| 778 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 779 | llvm::Constant *Nucleus::createConstantByte(signed char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 780 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 781 | return llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 784 | llvm::Constant *Nucleus::createConstantByte(unsigned char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 785 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 786 | return llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 789 | llvm::Constant *Nucleus::createConstantShort(short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 790 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 791 | return llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 794 | llvm::Constant *Nucleus::createConstantShort(unsigned short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 795 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 796 | return llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | llvm::Constant *Nucleus::createConstantFloat(float x) |
| 800 | { |
| 801 | return ConstantFP::get(Float::getType(), x); |
| 802 | } |
| 803 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 804 | llvm::Value *Nucleus::createNullPointer(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 805 | { |
| 806 | return llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0)); |
| 807 | } |
| 808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 809 | llvm::Value *Nucleus::createConstantVector(llvm::Constant *const *Vals, unsigned NumVals) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 810 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 811 | return llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(Vals, NumVals)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 812 | } |
| 813 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 814 | Type *Void::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 815 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 816 | return T(llvm::Type::getVoidTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 819 | LValue::LValue(Type *type, int arraySize) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 820 | { |
| 821 | address = Nucleus::allocateStackVariable(type, arraySize); |
| 822 | } |
| 823 | |
| 824 | llvm::Value *LValue::loadValue(unsigned int alignment) const |
| 825 | { |
| 826 | return Nucleus::createLoad(address, false, alignment); |
| 827 | } |
| 828 | |
| 829 | llvm::Value *LValue::storeValue(llvm::Value *value, unsigned int alignment) const |
| 830 | { |
| 831 | return Nucleus::createStore(value, address, false, alignment); |
| 832 | } |
| 833 | |
Nicolas Capens | 0e33ae3 | 2016-09-23 17:37:27 -0400 | [diff] [blame] | 834 | llvm::Value *LValue::storeValue(llvm::Constant *constant, unsigned int alignment) const |
| 835 | { |
| 836 | return Nucleus::createStore(constant, address, false, alignment); |
| 837 | } |
| 838 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 839 | llvm::Value *LValue::getAddress(llvm::Value *index) const |
| 840 | { |
| 841 | return Nucleus::createGEP(address, index); |
| 842 | } |
| 843 | |
Nicolas Capens | 4f738a1 | 2016-09-20 15:46:16 -0400 | [diff] [blame] | 844 | class MMX : public Variable<MMX> |
| 845 | { |
| 846 | public: |
| 847 | static Type *getType(); |
| 848 | }; |
| 849 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 850 | Type *MMX::getType() |
| 851 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 852 | return T(llvm::Type::getX86_MMXTy(*::context)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 855 | Bool::Bool(Argument<Bool> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 856 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 857 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | Bool::Bool() |
| 861 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | Bool::Bool(bool x) |
| 865 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 866 | storeValue(Nucleus::createConstantBool(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 867 | } |
| 868 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 869 | Bool::Bool(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 870 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 871 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | Bool::Bool(const Bool &rhs) |
| 875 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 876 | Value *value = rhs.loadValue(); |
| 877 | storeValue(value); |
| 878 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 879 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 880 | Bool::Bool(const Reference<Bool> &rhs) |
| 881 | { |
| 882 | Value *value = rhs.loadValue(); |
| 883 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 884 | } |
| 885 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 886 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 887 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 888 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 889 | |
| 890 | return rhs; |
| 891 | } |
| 892 | |
| 893 | RValue<Bool> Bool::operator=(const Bool &rhs) const |
| 894 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 895 | Value *value = rhs.loadValue(); |
| 896 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 897 | |
| 898 | return RValue<Bool>(value); |
| 899 | } |
| 900 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 901 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 902 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 903 | Value *value = rhs.loadValue(); |
| 904 | storeValue(value); |
| 905 | |
| 906 | return RValue<Bool>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 907 | } |
| 908 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 909 | RValue<Bool> operator!(RValue<Bool> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 910 | { |
| 911 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 912 | } |
| 913 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 914 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 915 | { |
| 916 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 917 | } |
| 918 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 919 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 920 | { |
| 921 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 922 | } |
| 923 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 924 | Type *Bool::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 925 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 926 | return T(llvm::Type::getInt1Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 929 | Byte::Byte(Argument<Byte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 930 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 931 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 932 | } |
| 933 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 934 | Byte::Byte(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 935 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 936 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 937 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 938 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 941 | Byte::Byte(RValue<UInt> cast) |
| 942 | { |
| 943 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 944 | |
| 945 | storeValue(integer); |
| 946 | } |
| 947 | |
| 948 | Byte::Byte(RValue<UShort> cast) |
| 949 | { |
| 950 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 951 | |
| 952 | storeValue(integer); |
| 953 | } |
| 954 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 955 | Byte::Byte() |
| 956 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | Byte::Byte(int x) |
| 960 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 961 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | Byte::Byte(unsigned char x) |
| 965 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 966 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 967 | } |
| 968 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 969 | Byte::Byte(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 970 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 971 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | Byte::Byte(const Byte &rhs) |
| 975 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 976 | Value *value = rhs.loadValue(); |
| 977 | storeValue(value); |
| 978 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 979 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 980 | Byte::Byte(const Reference<Byte> &rhs) |
| 981 | { |
| 982 | Value *value = rhs.loadValue(); |
| 983 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 984 | } |
| 985 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 986 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 987 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 988 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 989 | |
| 990 | return rhs; |
| 991 | } |
| 992 | |
| 993 | RValue<Byte> Byte::operator=(const Byte &rhs) const |
| 994 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 995 | Value *value = rhs.loadValue(); |
| 996 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 997 | |
| 998 | return RValue<Byte>(value); |
| 999 | } |
| 1000 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1001 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1002 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1003 | Value *value = rhs.loadValue(); |
| 1004 | storeValue(value); |
| 1005 | |
| 1006 | return RValue<Byte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1009 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | { |
| 1011 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1012 | } |
| 1013 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1014 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1015 | { |
| 1016 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1017 | } |
| 1018 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1019 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1020 | { |
| 1021 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1022 | } |
| 1023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1024 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1025 | { |
| 1026 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1027 | } |
| 1028 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1029 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1030 | { |
| 1031 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1032 | } |
| 1033 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1034 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1035 | { |
| 1036 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1037 | } |
| 1038 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1039 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1040 | { |
| 1041 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1042 | } |
| 1043 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1044 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1045 | { |
| 1046 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1047 | } |
| 1048 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1049 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1050 | { |
| 1051 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1052 | } |
| 1053 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1054 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1055 | { |
| 1056 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1057 | } |
| 1058 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1059 | RValue<Byte> operator+=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1060 | { |
| 1061 | return lhs = lhs + rhs; |
| 1062 | } |
| 1063 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1064 | RValue<Byte> operator-=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1065 | { |
| 1066 | return lhs = lhs - rhs; |
| 1067 | } |
| 1068 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1069 | RValue<Byte> operator*=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1070 | { |
| 1071 | return lhs = lhs * rhs; |
| 1072 | } |
| 1073 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1074 | RValue<Byte> operator/=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1075 | { |
| 1076 | return lhs = lhs / rhs; |
| 1077 | } |
| 1078 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1079 | RValue<Byte> operator%=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1080 | { |
| 1081 | return lhs = lhs % rhs; |
| 1082 | } |
| 1083 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1084 | RValue<Byte> operator&=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1085 | { |
| 1086 | return lhs = lhs & rhs; |
| 1087 | } |
| 1088 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1089 | RValue<Byte> operator|=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1090 | { |
| 1091 | return lhs = lhs | rhs; |
| 1092 | } |
| 1093 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1094 | RValue<Byte> operator^=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1095 | { |
| 1096 | return lhs = lhs ^ rhs; |
| 1097 | } |
| 1098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1099 | RValue<Byte> operator<<=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1100 | { |
| 1101 | return lhs = lhs << rhs; |
| 1102 | } |
| 1103 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1104 | RValue<Byte> operator>>=(const Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1105 | { |
| 1106 | return lhs = lhs >> rhs; |
| 1107 | } |
| 1108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1109 | RValue<Byte> operator+(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1110 | { |
| 1111 | return val; |
| 1112 | } |
| 1113 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1114 | RValue<Byte> operator-(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1115 | { |
| 1116 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1117 | } |
| 1118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1119 | RValue<Byte> operator~(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1120 | { |
| 1121 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1122 | } |
| 1123 | |
| 1124 | RValue<Byte> operator++(const Byte &val, int) // Post-increment |
| 1125 | { |
| 1126 | RValue<Byte> res = val; |
| 1127 | |
| 1128 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1129 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1130 | |
| 1131 | return res; |
| 1132 | } |
| 1133 | |
| 1134 | const Byte &operator++(const Byte &val) // Pre-increment |
| 1135 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1136 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); |
| 1137 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1138 | |
| 1139 | return val; |
| 1140 | } |
| 1141 | |
| 1142 | RValue<Byte> operator--(const Byte &val, int) // Post-decrement |
| 1143 | { |
| 1144 | RValue<Byte> res = val; |
| 1145 | |
| 1146 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1147 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1148 | |
| 1149 | return res; |
| 1150 | } |
| 1151 | |
| 1152 | const Byte &operator--(const Byte &val) // Pre-decrement |
| 1153 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1154 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); |
| 1155 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1156 | |
| 1157 | return val; |
| 1158 | } |
| 1159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1160 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1161 | { |
| 1162 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1163 | } |
| 1164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1165 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1166 | { |
| 1167 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1168 | } |
| 1169 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1170 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1171 | { |
| 1172 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1173 | } |
| 1174 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1175 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1176 | { |
| 1177 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1178 | } |
| 1179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1180 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1181 | { |
| 1182 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1183 | } |
| 1184 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1185 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1186 | { |
| 1187 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1188 | } |
| 1189 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1190 | Type *Byte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1191 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 1192 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1195 | SByte::SByte(Argument<SByte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1196 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1197 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1200 | SByte::SByte(RValue<Int> cast) |
| 1201 | { |
| 1202 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1203 | |
| 1204 | storeValue(integer); |
| 1205 | } |
| 1206 | |
| 1207 | SByte::SByte(RValue<Short> cast) |
| 1208 | { |
| 1209 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1210 | |
| 1211 | storeValue(integer); |
| 1212 | } |
| 1213 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1214 | SByte::SByte() |
| 1215 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | SByte::SByte(signed char x) |
| 1219 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1220 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1221 | } |
| 1222 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1223 | SByte::SByte(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1224 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1225 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | SByte::SByte(const SByte &rhs) |
| 1229 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1230 | Value *value = rhs.loadValue(); |
| 1231 | storeValue(value); |
| 1232 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1233 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1234 | SByte::SByte(const Reference<SByte> &rhs) |
| 1235 | { |
| 1236 | Value *value = rhs.loadValue(); |
| 1237 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1240 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1241 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1242 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1243 | |
| 1244 | return rhs; |
| 1245 | } |
| 1246 | |
| 1247 | RValue<SByte> SByte::operator=(const SByte &rhs) const |
| 1248 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1249 | Value *value = rhs.loadValue(); |
| 1250 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1251 | |
| 1252 | return RValue<SByte>(value); |
| 1253 | } |
| 1254 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1255 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1256 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1257 | Value *value = rhs.loadValue(); |
| 1258 | storeValue(value); |
| 1259 | |
| 1260 | return RValue<SByte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1261 | } |
| 1262 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1263 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1264 | { |
| 1265 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1266 | } |
| 1267 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1268 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1269 | { |
| 1270 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1271 | } |
| 1272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1273 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1274 | { |
| 1275 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1276 | } |
| 1277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1278 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1279 | { |
| 1280 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1281 | } |
| 1282 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1283 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1284 | { |
| 1285 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1286 | } |
| 1287 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1288 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1289 | { |
| 1290 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1291 | } |
| 1292 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1293 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1294 | { |
| 1295 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1296 | } |
| 1297 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1298 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1299 | { |
| 1300 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1301 | } |
| 1302 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1303 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1304 | { |
| 1305 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1306 | } |
| 1307 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1308 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1309 | { |
| 1310 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1311 | } |
| 1312 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1313 | RValue<SByte> operator+=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1314 | { |
| 1315 | return lhs = lhs + rhs; |
| 1316 | } |
| 1317 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1318 | RValue<SByte> operator-=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1319 | { |
| 1320 | return lhs = lhs - rhs; |
| 1321 | } |
| 1322 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1323 | RValue<SByte> operator*=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1324 | { |
| 1325 | return lhs = lhs * rhs; |
| 1326 | } |
| 1327 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1328 | RValue<SByte> operator/=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1329 | { |
| 1330 | return lhs = lhs / rhs; |
| 1331 | } |
| 1332 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1333 | RValue<SByte> operator%=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1334 | { |
| 1335 | return lhs = lhs % rhs; |
| 1336 | } |
| 1337 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1338 | RValue<SByte> operator&=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1339 | { |
| 1340 | return lhs = lhs & rhs; |
| 1341 | } |
| 1342 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1343 | RValue<SByte> operator|=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1344 | { |
| 1345 | return lhs = lhs | rhs; |
| 1346 | } |
| 1347 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1348 | RValue<SByte> operator^=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1349 | { |
| 1350 | return lhs = lhs ^ rhs; |
| 1351 | } |
| 1352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1353 | RValue<SByte> operator<<=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1354 | { |
| 1355 | return lhs = lhs << rhs; |
| 1356 | } |
| 1357 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1358 | RValue<SByte> operator>>=(const SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1359 | { |
| 1360 | return lhs = lhs >> rhs; |
| 1361 | } |
| 1362 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1363 | RValue<SByte> operator+(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1364 | { |
| 1365 | return val; |
| 1366 | } |
| 1367 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1368 | RValue<SByte> operator-(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1369 | { |
| 1370 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1371 | } |
| 1372 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1373 | RValue<SByte> operator~(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1374 | { |
| 1375 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1376 | } |
| 1377 | |
| 1378 | RValue<SByte> operator++(const SByte &val, int) // Post-increment |
| 1379 | { |
| 1380 | RValue<SByte> res = val; |
| 1381 | |
| 1382 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1383 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1384 | |
| 1385 | return res; |
| 1386 | } |
| 1387 | |
| 1388 | const SByte &operator++(const SByte &val) // Pre-increment |
| 1389 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1390 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1)); |
| 1391 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1392 | |
| 1393 | return val; |
| 1394 | } |
| 1395 | |
| 1396 | RValue<SByte> operator--(const SByte &val, int) // Post-decrement |
| 1397 | { |
| 1398 | RValue<SByte> res = val; |
| 1399 | |
| 1400 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1401 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1402 | |
| 1403 | return res; |
| 1404 | } |
| 1405 | |
| 1406 | const SByte &operator--(const SByte &val) // Pre-decrement |
| 1407 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1408 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1)); |
| 1409 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1410 | |
| 1411 | return val; |
| 1412 | } |
| 1413 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1414 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1415 | { |
| 1416 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1417 | } |
| 1418 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1419 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1420 | { |
| 1421 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1422 | } |
| 1423 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1424 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1425 | { |
| 1426 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1427 | } |
| 1428 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1429 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1430 | { |
| 1431 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1432 | } |
| 1433 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1434 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1435 | { |
| 1436 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1437 | } |
| 1438 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1439 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1440 | { |
| 1441 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1442 | } |
| 1443 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1444 | Type *SByte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1445 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 1446 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1447 | } |
| 1448 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1449 | Short::Short(Argument<Short> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1450 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1451 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1454 | Short::Short(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1455 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1456 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1457 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1458 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | Short::Short() |
| 1462 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | Short::Short(short x) |
| 1466 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1467 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1470 | Short::Short(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1471 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1472 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | Short::Short(const Short &rhs) |
| 1476 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1477 | Value *value = rhs.loadValue(); |
| 1478 | storeValue(value); |
| 1479 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1480 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1481 | Short::Short(const Reference<Short> &rhs) |
| 1482 | { |
| 1483 | Value *value = rhs.loadValue(); |
| 1484 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1485 | } |
| 1486 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1487 | RValue<Short> Short::operator=(RValue<Short> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1488 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1489 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1490 | |
| 1491 | return rhs; |
| 1492 | } |
| 1493 | |
| 1494 | RValue<Short> Short::operator=(const Short &rhs) const |
| 1495 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1496 | Value *value = rhs.loadValue(); |
| 1497 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1498 | |
| 1499 | return RValue<Short>(value); |
| 1500 | } |
| 1501 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1502 | RValue<Short> Short::operator=(const Reference<Short> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1503 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1504 | Value *value = rhs.loadValue(); |
| 1505 | storeValue(value); |
| 1506 | |
| 1507 | return RValue<Short>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1508 | } |
| 1509 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1510 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1511 | { |
| 1512 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1513 | } |
| 1514 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1515 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1516 | { |
| 1517 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1518 | } |
| 1519 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1520 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1521 | { |
| 1522 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1523 | } |
| 1524 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1525 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1526 | { |
| 1527 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1528 | } |
| 1529 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1530 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1531 | { |
| 1532 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1533 | } |
| 1534 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1535 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1536 | { |
| 1537 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1538 | } |
| 1539 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1540 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1541 | { |
| 1542 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1543 | } |
| 1544 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1545 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1546 | { |
| 1547 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1548 | } |
| 1549 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1550 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1551 | { |
| 1552 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1553 | } |
| 1554 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1555 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1556 | { |
| 1557 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1558 | } |
| 1559 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1560 | RValue<Short> operator+=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1561 | { |
| 1562 | return lhs = lhs + rhs; |
| 1563 | } |
| 1564 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1565 | RValue<Short> operator-=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1566 | { |
| 1567 | return lhs = lhs - rhs; |
| 1568 | } |
| 1569 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1570 | RValue<Short> operator*=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1571 | { |
| 1572 | return lhs = lhs * rhs; |
| 1573 | } |
| 1574 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1575 | RValue<Short> operator/=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1576 | { |
| 1577 | return lhs = lhs / rhs; |
| 1578 | } |
| 1579 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1580 | RValue<Short> operator%=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1581 | { |
| 1582 | return lhs = lhs % rhs; |
| 1583 | } |
| 1584 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1585 | RValue<Short> operator&=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1586 | { |
| 1587 | return lhs = lhs & rhs; |
| 1588 | } |
| 1589 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1590 | RValue<Short> operator|=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1591 | { |
| 1592 | return lhs = lhs | rhs; |
| 1593 | } |
| 1594 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1595 | RValue<Short> operator^=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1596 | { |
| 1597 | return lhs = lhs ^ rhs; |
| 1598 | } |
| 1599 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1600 | RValue<Short> operator<<=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1601 | { |
| 1602 | return lhs = lhs << rhs; |
| 1603 | } |
| 1604 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1605 | RValue<Short> operator>>=(const Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1606 | { |
| 1607 | return lhs = lhs >> rhs; |
| 1608 | } |
| 1609 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1610 | RValue<Short> operator+(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1611 | { |
| 1612 | return val; |
| 1613 | } |
| 1614 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1615 | RValue<Short> operator-(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1616 | { |
| 1617 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 1618 | } |
| 1619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1620 | RValue<Short> operator~(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1621 | { |
| 1622 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 1623 | } |
| 1624 | |
| 1625 | RValue<Short> operator++(const Short &val, int) // Post-increment |
| 1626 | { |
| 1627 | RValue<Short> res = val; |
| 1628 | |
| 1629 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1630 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1631 | |
| 1632 | return res; |
| 1633 | } |
| 1634 | |
| 1635 | const Short &operator++(const Short &val) // Pre-increment |
| 1636 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1637 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1)); |
| 1638 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1639 | |
| 1640 | return val; |
| 1641 | } |
| 1642 | |
| 1643 | RValue<Short> operator--(const Short &val, int) // Post-decrement |
| 1644 | { |
| 1645 | RValue<Short> res = val; |
| 1646 | |
| 1647 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1648 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1649 | |
| 1650 | return res; |
| 1651 | } |
| 1652 | |
| 1653 | const Short &operator--(const Short &val) // Pre-decrement |
| 1654 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1655 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1)); |
| 1656 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1657 | |
| 1658 | return val; |
| 1659 | } |
| 1660 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1661 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1662 | { |
| 1663 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1664 | } |
| 1665 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1666 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1667 | { |
| 1668 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1669 | } |
| 1670 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1671 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1672 | { |
| 1673 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1674 | } |
| 1675 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1676 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1677 | { |
| 1678 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1679 | } |
| 1680 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1681 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1682 | { |
| 1683 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1684 | } |
| 1685 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1686 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1687 | { |
| 1688 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1689 | } |
| 1690 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1691 | Type *Short::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1692 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 1693 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1694 | } |
| 1695 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1696 | UShort::UShort(Argument<UShort> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1697 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1698 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1699 | } |
| 1700 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1701 | UShort::UShort(RValue<UInt> cast) |
| 1702 | { |
| 1703 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1704 | |
| 1705 | storeValue(integer); |
| 1706 | } |
| 1707 | |
Alexis Hetu | 75b650f | 2015-11-19 17:40:15 -0500 | [diff] [blame] | 1708 | UShort::UShort(RValue<Int> cast) |
| 1709 | { |
| 1710 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1711 | |
| 1712 | storeValue(integer); |
| 1713 | } |
| 1714 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1715 | UShort::UShort() |
| 1716 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | UShort::UShort(unsigned short x) |
| 1720 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1721 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1724 | UShort::UShort(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1725 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1726 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | UShort::UShort(const UShort &rhs) |
| 1730 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1731 | Value *value = rhs.loadValue(); |
| 1732 | storeValue(value); |
| 1733 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1734 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1735 | UShort::UShort(const Reference<UShort> &rhs) |
| 1736 | { |
| 1737 | Value *value = rhs.loadValue(); |
| 1738 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1741 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1742 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1743 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1744 | |
| 1745 | return rhs; |
| 1746 | } |
| 1747 | |
| 1748 | RValue<UShort> UShort::operator=(const UShort &rhs) const |
| 1749 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1750 | Value *value = rhs.loadValue(); |
| 1751 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1752 | |
| 1753 | return RValue<UShort>(value); |
| 1754 | } |
| 1755 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1756 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1757 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1758 | Value *value = rhs.loadValue(); |
| 1759 | storeValue(value); |
| 1760 | |
| 1761 | return RValue<UShort>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1762 | } |
| 1763 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1764 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1765 | { |
| 1766 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1767 | } |
| 1768 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1769 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1770 | { |
| 1771 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1772 | } |
| 1773 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1774 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1775 | { |
| 1776 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1777 | } |
| 1778 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1779 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1780 | { |
| 1781 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1782 | } |
| 1783 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1784 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1785 | { |
| 1786 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1787 | } |
| 1788 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1789 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1790 | { |
| 1791 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1792 | } |
| 1793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1794 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1795 | { |
| 1796 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1797 | } |
| 1798 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1799 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1800 | { |
| 1801 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1802 | } |
| 1803 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1804 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1805 | { |
| 1806 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1807 | } |
| 1808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1809 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1810 | { |
| 1811 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1812 | } |
| 1813 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1814 | RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1815 | { |
| 1816 | return lhs = lhs + rhs; |
| 1817 | } |
| 1818 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1819 | RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1820 | { |
| 1821 | return lhs = lhs - rhs; |
| 1822 | } |
| 1823 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1824 | RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1825 | { |
| 1826 | return lhs = lhs * rhs; |
| 1827 | } |
| 1828 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1829 | RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1830 | { |
| 1831 | return lhs = lhs / rhs; |
| 1832 | } |
| 1833 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1834 | RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1835 | { |
| 1836 | return lhs = lhs % rhs; |
| 1837 | } |
| 1838 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1839 | RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1840 | { |
| 1841 | return lhs = lhs & rhs; |
| 1842 | } |
| 1843 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1844 | RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1845 | { |
| 1846 | return lhs = lhs | rhs; |
| 1847 | } |
| 1848 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1849 | RValue<UShort> operator^=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1850 | { |
| 1851 | return lhs = lhs ^ rhs; |
| 1852 | } |
| 1853 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1854 | RValue<UShort> operator<<=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1855 | { |
| 1856 | return lhs = lhs << rhs; |
| 1857 | } |
| 1858 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1859 | RValue<UShort> operator>>=(const UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1860 | { |
| 1861 | return lhs = lhs >> rhs; |
| 1862 | } |
| 1863 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1864 | RValue<UShort> operator+(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1865 | { |
| 1866 | return val; |
| 1867 | } |
| 1868 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1869 | RValue<UShort> operator-(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1870 | { |
| 1871 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 1872 | } |
| 1873 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1874 | RValue<UShort> operator~(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1875 | { |
| 1876 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 1877 | } |
| 1878 | |
| 1879 | RValue<UShort> operator++(const UShort &val, int) // Post-increment |
| 1880 | { |
| 1881 | RValue<UShort> res = val; |
| 1882 | |
| 1883 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantShort((unsigned short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1884 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1885 | |
| 1886 | return res; |
| 1887 | } |
| 1888 | |
| 1889 | const UShort &operator++(const UShort &val) // Pre-increment |
| 1890 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1891 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1)); |
| 1892 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1893 | |
| 1894 | return val; |
| 1895 | } |
| 1896 | |
| 1897 | RValue<UShort> operator--(const UShort &val, int) // Post-decrement |
| 1898 | { |
| 1899 | RValue<UShort> res = val; |
| 1900 | |
| 1901 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantShort((unsigned short)1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1902 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1903 | |
| 1904 | return res; |
| 1905 | } |
| 1906 | |
| 1907 | const UShort &operator--(const UShort &val) // Pre-decrement |
| 1908 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1909 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1)); |
| 1910 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1911 | |
| 1912 | return val; |
| 1913 | } |
| 1914 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1915 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1916 | { |
| 1917 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1918 | } |
| 1919 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1920 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1921 | { |
| 1922 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1923 | } |
| 1924 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1925 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1926 | { |
| 1927 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1928 | } |
| 1929 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1930 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1931 | { |
| 1932 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1933 | } |
| 1934 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1935 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1936 | { |
| 1937 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1938 | } |
| 1939 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1940 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1941 | { |
| 1942 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1943 | } |
| 1944 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1945 | Type *UShort::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1946 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 1947 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1948 | } |
| 1949 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1950 | Type *Byte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1951 | { |
| 1952 | #if 0 |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 1953 | return T(VectorType::get(Byte::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1954 | #else |
| 1955 | return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 1956 | #endif |
| 1957 | } |
| 1958 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1959 | Type *SByte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1960 | { |
| 1961 | #if 0 |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 1962 | return T(VectorType::get(SByte::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1963 | #else |
| 1964 | return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 1965 | #endif |
| 1966 | } |
| 1967 | |
| 1968 | Byte8::Byte8() |
| 1969 | { |
| 1970 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | Byte8::Byte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7) |
| 1974 | { |
| 1975 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1976 | |
| 1977 | Constant *constantVector[8]; |
| 1978 | constantVector[0] = Nucleus::createConstantByte(x0); |
| 1979 | constantVector[1] = Nucleus::createConstantByte(x1); |
| 1980 | constantVector[2] = Nucleus::createConstantByte(x2); |
| 1981 | constantVector[3] = Nucleus::createConstantByte(x3); |
| 1982 | constantVector[4] = Nucleus::createConstantByte(x4); |
| 1983 | constantVector[5] = Nucleus::createConstantByte(x5); |
| 1984 | constantVector[6] = Nucleus::createConstantByte(x6); |
| 1985 | constantVector[7] = Nucleus::createConstantByte(x7); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1986 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1987 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1988 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | Byte8::Byte8(int64_t x) |
| 1992 | { |
| 1993 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1994 | |
| 1995 | Constant *constantVector[8]; |
| 1996 | constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0)); |
| 1997 | constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8)); |
| 1998 | constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16)); |
| 1999 | constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24)); |
| 2000 | constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32)); |
| 2001 | constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40)); |
| 2002 | constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48)); |
| 2003 | constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2004 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2005 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2006 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2007 | } |
| 2008 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2009 | Byte8::Byte8(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2010 | { |
| 2011 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2012 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2013 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | Byte8::Byte8(const Byte8 &rhs) |
| 2017 | { |
| 2018 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2019 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2020 | Value *value = rhs.loadValue(); |
| 2021 | storeValue(value); |
| 2022 | } |
| 2023 | |
| 2024 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2025 | { |
| 2026 | // xyzw.parent = this; |
| 2027 | |
| 2028 | Value *value = rhs.loadValue(); |
| 2029 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2030 | } |
| 2031 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2032 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2033 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2034 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2035 | |
| 2036 | return rhs; |
| 2037 | } |
| 2038 | |
| 2039 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const |
| 2040 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2041 | Value *value = rhs.loadValue(); |
| 2042 | storeValue(value); |
| 2043 | |
| 2044 | return RValue<Byte8>(value); |
| 2045 | } |
| 2046 | |
| 2047 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const |
| 2048 | { |
| 2049 | Value *value = rhs.loadValue(); |
| 2050 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2051 | |
| 2052 | return RValue<Byte8>(value); |
| 2053 | } |
| 2054 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2055 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2056 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2057 | if(CPUID::supportsMMX2()) |
| 2058 | { |
| 2059 | return x86::paddb(lhs, rhs); |
| 2060 | } |
| 2061 | else |
| 2062 | { |
| 2063 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2064 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2065 | } |
| 2066 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2067 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2068 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2069 | if(CPUID::supportsMMX2()) |
| 2070 | { |
| 2071 | return x86::psubb(lhs, rhs); |
| 2072 | } |
| 2073 | else |
| 2074 | { |
| 2075 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2076 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2077 | } |
| 2078 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2079 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2080 | // { |
| 2081 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2082 | // } |
| 2083 | |
| 2084 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2085 | // { |
| 2086 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2087 | // } |
| 2088 | |
| 2089 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2090 | // { |
| 2091 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2092 | // } |
| 2093 | |
| 2094 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2095 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2096 | if(CPUID::supportsMMX2()) |
| 2097 | { |
| 2098 | return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 2099 | } |
| 2100 | else |
| 2101 | { |
| 2102 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2103 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2104 | } |
| 2105 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2106 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2107 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2108 | if(CPUID::supportsMMX2()) |
| 2109 | { |
| 2110 | return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 2111 | } |
| 2112 | else |
| 2113 | { |
| 2114 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2115 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2116 | } |
| 2117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2118 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2119 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2120 | if(CPUID::supportsMMX2()) |
| 2121 | { |
| 2122 | return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 2123 | } |
| 2124 | else |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2125 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2126 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2127 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2128 | } |
| 2129 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2130 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2131 | // { |
| 2132 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2133 | // } |
| 2134 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2135 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2136 | // { |
| 2137 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2138 | // } |
| 2139 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2140 | RValue<Byte8> operator+=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2141 | { |
| 2142 | return lhs = lhs + rhs; |
| 2143 | } |
| 2144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2145 | RValue<Byte8> operator-=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2146 | { |
| 2147 | return lhs = lhs - rhs; |
| 2148 | } |
| 2149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2150 | // RValue<Byte8> operator*=(const Byte8 &lhs, RValue<Byte8> rhs) |
| 2151 | // { |
| 2152 | // return lhs = lhs * rhs; |
| 2153 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2155 | // RValue<Byte8> operator/=(const Byte8 &lhs, RValue<Byte8> rhs) |
| 2156 | // { |
| 2157 | // return lhs = lhs / rhs; |
| 2158 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2160 | // RValue<Byte8> operator%=(const Byte8 &lhs, RValue<Byte8> rhs) |
| 2161 | // { |
| 2162 | // return lhs = lhs % rhs; |
| 2163 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2165 | RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2166 | { |
| 2167 | return lhs = lhs & rhs; |
| 2168 | } |
| 2169 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2170 | RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2171 | { |
| 2172 | return lhs = lhs | rhs; |
| 2173 | } |
| 2174 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2175 | RValue<Byte8> operator^=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2176 | { |
| 2177 | return lhs = lhs ^ rhs; |
| 2178 | } |
| 2179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2180 | // RValue<Byte8> operator<<=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2181 | // { |
| 2182 | // return lhs = lhs << rhs; |
| 2183 | // } |
| 2184 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2185 | // RValue<Byte8> operator>>=(const Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2186 | // { |
| 2187 | // return lhs = lhs >> rhs; |
| 2188 | // } |
| 2189 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2190 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2191 | // { |
| 2192 | // return val; |
| 2193 | // } |
| 2194 | |
| 2195 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2196 | // { |
| 2197 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2198 | // } |
| 2199 | |
| 2200 | RValue<Byte8> operator~(RValue<Byte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2201 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2202 | if(CPUID::supportsMMX2()) |
| 2203 | { |
| 2204 | return val ^ Byte8(0xFFFFFFFFFFFFFFFF); |
| 2205 | } |
| 2206 | else |
| 2207 | { |
| 2208 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2209 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2210 | } |
| 2211 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2212 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2213 | { |
| 2214 | return x86::paddusb(x, y); |
| 2215 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2216 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2217 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2218 | { |
| 2219 | return x86::psubusb(x, y); |
| 2220 | } |
| 2221 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2222 | RValue<Short4> Unpack(RValue<Byte4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2223 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2224 | Value *int2 = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), x.value, 0); |
| 2225 | Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2226 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2227 | return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8)); |
| 2228 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2229 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2230 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2231 | { |
| 2232 | if(CPUID::supportsMMX2()) |
| 2233 | { |
| 2234 | return x86::punpcklbw(x, y); |
| 2235 | } |
| 2236 | else |
| 2237 | { |
| 2238 | Constant *shuffle[8]; |
| 2239 | shuffle[0] = Nucleus::createConstantInt(0); |
| 2240 | shuffle[1] = Nucleus::createConstantInt(8); |
| 2241 | shuffle[2] = Nucleus::createConstantInt(1); |
| 2242 | shuffle[3] = Nucleus::createConstantInt(9); |
| 2243 | shuffle[4] = Nucleus::createConstantInt(2); |
| 2244 | shuffle[5] = Nucleus::createConstantInt(10); |
| 2245 | shuffle[6] = Nucleus::createConstantInt(3); |
| 2246 | shuffle[7] = Nucleus::createConstantInt(11); |
| 2247 | |
| 2248 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
| 2249 | |
| 2250 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2251 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2252 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2253 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2254 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2255 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2256 | if(CPUID::supportsMMX2()) |
| 2257 | { |
| 2258 | return x86::punpckhbw(x, y); |
| 2259 | } |
| 2260 | else |
| 2261 | { |
| 2262 | Constant *shuffle[8]; |
| 2263 | shuffle[0] = Nucleus::createConstantInt(4); |
| 2264 | shuffle[1] = Nucleus::createConstantInt(12); |
| 2265 | shuffle[2] = Nucleus::createConstantInt(5); |
| 2266 | shuffle[3] = Nucleus::createConstantInt(13); |
| 2267 | shuffle[4] = Nucleus::createConstantInt(6); |
| 2268 | shuffle[5] = Nucleus::createConstantInt(14); |
| 2269 | shuffle[6] = Nucleus::createConstantInt(7); |
| 2270 | shuffle[7] = Nucleus::createConstantInt(15); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2271 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2272 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2273 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2274 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2275 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2276 | } |
| 2277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2278 | RValue<Int> SignMask(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2279 | { |
| 2280 | return x86::pmovmskb(x); |
| 2281 | } |
| 2282 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2283 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2284 | // { |
| 2285 | // return x86::pcmpgtb(x, y); // FIXME: Signedness |
| 2286 | // } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2287 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2288 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2289 | { |
| 2290 | return x86::pcmpeqb(x, y); |
| 2291 | } |
| 2292 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2293 | Type *Byte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2294 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2295 | if(CPUID::supportsMMX2()) |
| 2296 | { |
| 2297 | return MMX::getType(); |
| 2298 | } |
| 2299 | else |
| 2300 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 2301 | return T(VectorType::get(Byte::getType(), 8)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2302 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | SByte8::SByte8() |
| 2306 | { |
| 2307 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | SByte8::SByte8(byte x0, byte x1, byte x2, byte x3, byte x4, byte x5, byte x6, byte x7) |
| 2311 | { |
| 2312 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2313 | |
| 2314 | Constant *constantVector[8]; |
| 2315 | constantVector[0] = Nucleus::createConstantByte(x0); |
| 2316 | constantVector[1] = Nucleus::createConstantByte(x1); |
| 2317 | constantVector[2] = Nucleus::createConstantByte(x2); |
| 2318 | constantVector[3] = Nucleus::createConstantByte(x3); |
| 2319 | constantVector[4] = Nucleus::createConstantByte(x4); |
| 2320 | constantVector[5] = Nucleus::createConstantByte(x5); |
| 2321 | constantVector[6] = Nucleus::createConstantByte(x6); |
| 2322 | constantVector[7] = Nucleus::createConstantByte(x7); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2323 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2324 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2325 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | SByte8::SByte8(int64_t x) |
| 2329 | { |
| 2330 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2331 | |
| 2332 | Constant *constantVector[8]; |
| 2333 | constantVector[0] = Nucleus::createConstantByte((unsigned char)(x >> 0)); |
| 2334 | constantVector[1] = Nucleus::createConstantByte((unsigned char)(x >> 8)); |
| 2335 | constantVector[2] = Nucleus::createConstantByte((unsigned char)(x >> 16)); |
| 2336 | constantVector[3] = Nucleus::createConstantByte((unsigned char)(x >> 24)); |
| 2337 | constantVector[4] = Nucleus::createConstantByte((unsigned char)(x >> 32)); |
| 2338 | constantVector[5] = Nucleus::createConstantByte((unsigned char)(x >> 40)); |
| 2339 | constantVector[6] = Nucleus::createConstantByte((unsigned char)(x >> 48)); |
| 2340 | constantVector[7] = Nucleus::createConstantByte((unsigned char)(x >> 56)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2341 | Value *vector = Nucleus::createConstantVector(constantVector, 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2342 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2343 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2344 | } |
| 2345 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2346 | SByte8::SByte8(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2347 | { |
| 2348 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2349 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2350 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | SByte8::SByte8(const SByte8 &rhs) |
| 2354 | { |
| 2355 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2356 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2357 | Value *value = rhs.loadValue(); |
| 2358 | storeValue(value); |
| 2359 | } |
| 2360 | |
| 2361 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2362 | { |
| 2363 | // xyzw.parent = this; |
| 2364 | |
| 2365 | Value *value = rhs.loadValue(); |
| 2366 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2367 | } |
| 2368 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2369 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2370 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2371 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2372 | |
| 2373 | return rhs; |
| 2374 | } |
| 2375 | |
| 2376 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const |
| 2377 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2378 | Value *value = rhs.loadValue(); |
| 2379 | storeValue(value); |
| 2380 | |
| 2381 | return RValue<SByte8>(value); |
| 2382 | } |
| 2383 | |
| 2384 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const |
| 2385 | { |
| 2386 | Value *value = rhs.loadValue(); |
| 2387 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2388 | |
| 2389 | return RValue<SByte8>(value); |
| 2390 | } |
| 2391 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2392 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2393 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2394 | if(CPUID::supportsMMX2()) |
| 2395 | { |
| 2396 | return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2397 | } |
| 2398 | else |
| 2399 | { |
| 2400 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2401 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2402 | } |
| 2403 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2404 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2405 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2406 | if(CPUID::supportsMMX2()) |
| 2407 | { |
| 2408 | return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2409 | } |
| 2410 | else |
| 2411 | { |
| 2412 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2413 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2414 | } |
| 2415 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2416 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2417 | // { |
| 2418 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2419 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2420 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2421 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2422 | // { |
| 2423 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2424 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2425 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2426 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2427 | // { |
| 2428 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2429 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2430 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2431 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2432 | { |
| 2433 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2434 | } |
| 2435 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2436 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2437 | { |
| 2438 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2439 | } |
| 2440 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2441 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2442 | { |
| 2443 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2444 | } |
| 2445 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2446 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2447 | // { |
| 2448 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2449 | // } |
| 2450 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2451 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2452 | // { |
| 2453 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2454 | // } |
| 2455 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2456 | RValue<SByte8> operator+=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2457 | { |
| 2458 | return lhs = lhs + rhs; |
| 2459 | } |
| 2460 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2461 | RValue<SByte8> operator-=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2462 | { |
| 2463 | return lhs = lhs - rhs; |
| 2464 | } |
| 2465 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2466 | // RValue<SByte8> operator*=(const SByte8 &lhs, RValue<SByte8> rhs) |
| 2467 | // { |
| 2468 | // return lhs = lhs * rhs; |
| 2469 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2470 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2471 | // RValue<SByte8> operator/=(const SByte8 &lhs, RValue<SByte8> rhs) |
| 2472 | // { |
| 2473 | // return lhs = lhs / rhs; |
| 2474 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2475 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2476 | // RValue<SByte8> operator%=(const SByte8 &lhs, RValue<SByte8> rhs) |
| 2477 | // { |
| 2478 | // return lhs = lhs % rhs; |
| 2479 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2480 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2481 | RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2482 | { |
| 2483 | return lhs = lhs & rhs; |
| 2484 | } |
| 2485 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2486 | RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2487 | { |
| 2488 | return lhs = lhs | rhs; |
| 2489 | } |
| 2490 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2491 | RValue<SByte8> operator^=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2492 | { |
| 2493 | return lhs = lhs ^ rhs; |
| 2494 | } |
| 2495 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2496 | // RValue<SByte8> operator<<=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2497 | // { |
| 2498 | // return lhs = lhs << rhs; |
| 2499 | // } |
| 2500 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2501 | // RValue<SByte8> operator>>=(const SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2502 | // { |
| 2503 | // return lhs = lhs >> rhs; |
| 2504 | // } |
| 2505 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2506 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2507 | // { |
| 2508 | // return val; |
| 2509 | // } |
| 2510 | |
| 2511 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2512 | // { |
| 2513 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2514 | // } |
| 2515 | |
| 2516 | RValue<SByte8> operator~(RValue<SByte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2517 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2518 | if(CPUID::supportsMMX2()) |
| 2519 | { |
| 2520 | return val ^ SByte8(0xFFFFFFFFFFFFFFFF); |
| 2521 | } |
| 2522 | else |
| 2523 | { |
| 2524 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2525 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2526 | } |
| 2527 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2528 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2529 | { |
| 2530 | return x86::paddsb(x, y); |
| 2531 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2532 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2533 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2534 | { |
| 2535 | return x86::psubsb(x, y); |
| 2536 | } |
| 2537 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2538 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2539 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2540 | if(CPUID::supportsMMX2()) |
| 2541 | { |
| 2542 | return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y))); |
| 2543 | } |
| 2544 | else |
| 2545 | { |
| 2546 | Constant *shuffle[8]; |
| 2547 | shuffle[0] = Nucleus::createConstantInt(0); |
| 2548 | shuffle[1] = Nucleus::createConstantInt(8); |
| 2549 | shuffle[2] = Nucleus::createConstantInt(1); |
| 2550 | shuffle[3] = Nucleus::createConstantInt(9); |
| 2551 | shuffle[4] = Nucleus::createConstantInt(2); |
| 2552 | shuffle[5] = Nucleus::createConstantInt(10); |
| 2553 | shuffle[6] = Nucleus::createConstantInt(3); |
| 2554 | shuffle[7] = Nucleus::createConstantInt(11); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2555 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2556 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2557 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2558 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2559 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2560 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2561 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2562 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2563 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2564 | if(CPUID::supportsMMX2()) |
| 2565 | { |
| 2566 | return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y))); |
| 2567 | } |
| 2568 | else |
| 2569 | { |
| 2570 | Constant *shuffle[8]; |
| 2571 | shuffle[0] = Nucleus::createConstantInt(4); |
| 2572 | shuffle[1] = Nucleus::createConstantInt(12); |
| 2573 | shuffle[2] = Nucleus::createConstantInt(5); |
| 2574 | shuffle[3] = Nucleus::createConstantInt(13); |
| 2575 | shuffle[4] = Nucleus::createConstantInt(6); |
| 2576 | shuffle[5] = Nucleus::createConstantInt(14); |
| 2577 | shuffle[6] = Nucleus::createConstantInt(7); |
| 2578 | shuffle[7] = Nucleus::createConstantInt(15); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2579 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2580 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2581 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2582 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2583 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2584 | } |
| 2585 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2586 | RValue<Int> SignMask(RValue<SByte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2587 | { |
| 2588 | return x86::pmovmskb(As<Byte8>(x)); |
| 2589 | } |
| 2590 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2591 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2592 | { |
| 2593 | return x86::pcmpgtb(x, y); |
| 2594 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2595 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2596 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2597 | { |
| 2598 | return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y)); |
| 2599 | } |
| 2600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2601 | Type *SByte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2602 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2603 | if(CPUID::supportsMMX2()) |
| 2604 | { |
| 2605 | return MMX::getType(); |
| 2606 | } |
| 2607 | else |
| 2608 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 2609 | return T(VectorType::get(SByte::getType(), 8)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2610 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2611 | } |
| 2612 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2613 | Byte16::Byte16(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2614 | { |
| 2615 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2616 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2617 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | Byte16::Byte16(const Byte16 &rhs) |
| 2621 | { |
| 2622 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2623 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2624 | Value *value = rhs.loadValue(); |
| 2625 | storeValue(value); |
| 2626 | } |
| 2627 | |
| 2628 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2629 | { |
| 2630 | // xyzw.parent = this; |
| 2631 | |
| 2632 | Value *value = rhs.loadValue(); |
| 2633 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2634 | } |
| 2635 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2636 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2637 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2638 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2639 | |
| 2640 | return rhs; |
| 2641 | } |
| 2642 | |
| 2643 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const |
| 2644 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2645 | Value *value = rhs.loadValue(); |
| 2646 | storeValue(value); |
| 2647 | |
| 2648 | return RValue<Byte16>(value); |
| 2649 | } |
| 2650 | |
| 2651 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const |
| 2652 | { |
| 2653 | Value *value = rhs.loadValue(); |
| 2654 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2655 | |
| 2656 | return RValue<Byte16>(value); |
| 2657 | } |
| 2658 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2659 | Type *Byte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2660 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 2661 | return T(VectorType::get(Byte::getType(), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2662 | } |
| 2663 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2664 | Type *SByte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2665 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 2666 | return T( VectorType::get(SByte::getType(), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2667 | } |
| 2668 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2669 | Short4::Short4(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2670 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2671 | Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2672 | Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2673 | |
| 2674 | storeValue(swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2675 | } |
| 2676 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2677 | Short4::Short4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2678 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2679 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 2680 | |
| 2681 | #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd) |
| 2682 | Constant *pack[8]; |
| 2683 | pack[0] = Nucleus::createConstantInt(0); |
| 2684 | pack[1] = Nucleus::createConstantInt(2); |
| 2685 | pack[2] = Nucleus::createConstantInt(4); |
| 2686 | pack[3] = Nucleus::createConstantInt(6); |
| 2687 | |
| 2688 | Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4)); |
| 2689 | #else |
| 2690 | Value *packed; |
| 2691 | |
| 2692 | // FIXME: Use Swizzle<Short8> |
| 2693 | if(!CPUID::supportsSSSE3()) |
| 2694 | { |
| 2695 | Constant *pshuflw[8]; |
| 2696 | pshuflw[0] = Nucleus::createConstantInt(0); |
| 2697 | pshuflw[1] = Nucleus::createConstantInt(2); |
| 2698 | pshuflw[2] = Nucleus::createConstantInt(0); |
| 2699 | pshuflw[3] = Nucleus::createConstantInt(2); |
| 2700 | pshuflw[4] = Nucleus::createConstantInt(4); |
| 2701 | pshuflw[5] = Nucleus::createConstantInt(5); |
| 2702 | pshuflw[6] = Nucleus::createConstantInt(6); |
| 2703 | pshuflw[7] = Nucleus::createConstantInt(7); |
| 2704 | |
| 2705 | Constant *pshufhw[8]; |
| 2706 | pshufhw[0] = Nucleus::createConstantInt(0); |
| 2707 | pshufhw[1] = Nucleus::createConstantInt(1); |
| 2708 | pshufhw[2] = Nucleus::createConstantInt(2); |
| 2709 | pshufhw[3] = Nucleus::createConstantInt(3); |
| 2710 | pshufhw[4] = Nucleus::createConstantInt(4); |
| 2711 | pshufhw[5] = Nucleus::createConstantInt(6); |
| 2712 | pshufhw[6] = Nucleus::createConstantInt(4); |
| 2713 | pshufhw[7] = Nucleus::createConstantInt(6); |
| 2714 | |
| 2715 | Value *shuffle1 = Nucleus::createShuffleVector(short8, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshuflw, 8)); |
| 2716 | Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, UndefValue::get(Short8::getType()), Nucleus::createConstantVector(pshufhw, 8)); |
| 2717 | Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType()); |
| 2718 | packed = Nucleus::createSwizzle(int4, 0x88); |
| 2719 | } |
| 2720 | else |
| 2721 | { |
| 2722 | Constant *pshufb[16]; |
| 2723 | pshufb[0] = Nucleus::createConstantInt(0); |
| 2724 | pshufb[1] = Nucleus::createConstantInt(1); |
| 2725 | pshufb[2] = Nucleus::createConstantInt(4); |
| 2726 | pshufb[3] = Nucleus::createConstantInt(5); |
| 2727 | pshufb[4] = Nucleus::createConstantInt(8); |
| 2728 | pshufb[5] = Nucleus::createConstantInt(9); |
| 2729 | pshufb[6] = Nucleus::createConstantInt(12); |
| 2730 | pshufb[7] = Nucleus::createConstantInt(13); |
| 2731 | pshufb[8] = Nucleus::createConstantInt(0); |
| 2732 | pshufb[9] = Nucleus::createConstantInt(1); |
| 2733 | pshufb[10] = Nucleus::createConstantInt(4); |
| 2734 | pshufb[11] = Nucleus::createConstantInt(5); |
| 2735 | pshufb[12] = Nucleus::createConstantInt(8); |
| 2736 | pshufb[13] = Nucleus::createConstantInt(9); |
| 2737 | pshufb[14] = Nucleus::createConstantInt(12); |
| 2738 | pshufb[15] = Nucleus::createConstantInt(13); |
| 2739 | |
| 2740 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2741 | packed = Nucleus::createShuffleVector(byte16, UndefValue::get(Byte16::getType()), Nucleus::createConstantVector(pshufb, 16)); |
| 2742 | } |
| 2743 | |
| 2744 | #if 0 // FIXME: No optimal instruction selection |
| 2745 | Value *qword2 = Nucleus::createBitCast(packed, Long2::getType()); |
| 2746 | Value *element = Nucleus::createExtractElement(qword2, 0); |
| 2747 | Value *short4 = Nucleus::createBitCast(element, Short4::getType()); |
| 2748 | #else // FIXME: Requires SSE |
| 2749 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2750 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2751 | #endif |
| 2752 | #endif |
| 2753 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2754 | storeValue(short4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2755 | } |
| 2756 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2757 | // Short4::Short4(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2758 | // { |
| 2759 | // } |
| 2760 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2761 | Short4::Short4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2762 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2763 | Int4 v4i32 = Int4(cast); |
| 2764 | v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2765 | |
| 2766 | storeValue(As<Short4>(Int2(v4i32)).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | Short4::Short4() |
| 2770 | { |
| 2771 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2772 | } |
| 2773 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2774 | Short4::Short4(short xyzw) |
| 2775 | { |
| 2776 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2777 | |
| 2778 | Constant *constantVector[4]; |
| 2779 | constantVector[0] = Nucleus::createConstantShort(xyzw); |
| 2780 | constantVector[1] = Nucleus::createConstantShort(xyzw); |
| 2781 | constantVector[2] = Nucleus::createConstantShort(xyzw); |
| 2782 | constantVector[3] = Nucleus::createConstantShort(xyzw); |
| 2783 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
| 2784 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2785 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2786 | } |
| 2787 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2788 | Short4::Short4(short x, short y, short z, short w) |
| 2789 | { |
| 2790 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2791 | |
| 2792 | Constant *constantVector[4]; |
| 2793 | constantVector[0] = Nucleus::createConstantShort(x); |
| 2794 | constantVector[1] = Nucleus::createConstantShort(y); |
| 2795 | constantVector[2] = Nucleus::createConstantShort(z); |
| 2796 | constantVector[3] = Nucleus::createConstantShort(w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2797 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
| 2798 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2799 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2802 | Short4::Short4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2803 | { |
| 2804 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2805 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2806 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | Short4::Short4(const Short4 &rhs) |
| 2810 | { |
| 2811 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2812 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2813 | Value *value = rhs.loadValue(); |
| 2814 | storeValue(value); |
| 2815 | } |
| 2816 | |
| 2817 | Short4::Short4(const Reference<Short4> &rhs) |
| 2818 | { |
| 2819 | // xyzw.parent = this; |
| 2820 | |
| 2821 | Value *value = rhs.loadValue(); |
| 2822 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2823 | } |
| 2824 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2825 | Short4::Short4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2826 | { |
| 2827 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2828 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2829 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | Short4::Short4(const UShort4 &rhs) |
| 2833 | { |
| 2834 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2835 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2836 | storeValue(rhs.loadValue()); |
| 2837 | } |
| 2838 | |
| 2839 | Short4::Short4(const Reference<UShort4> &rhs) |
| 2840 | { |
| 2841 | // xyzw.parent = this; |
| 2842 | |
| 2843 | storeValue(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2844 | } |
| 2845 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2846 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2847 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2848 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2849 | |
| 2850 | return rhs; |
| 2851 | } |
| 2852 | |
| 2853 | RValue<Short4> Short4::operator=(const Short4 &rhs) const |
| 2854 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2855 | Value *value = rhs.loadValue(); |
| 2856 | storeValue(value); |
| 2857 | |
| 2858 | return RValue<Short4>(value); |
| 2859 | } |
| 2860 | |
| 2861 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const |
| 2862 | { |
| 2863 | Value *value = rhs.loadValue(); |
| 2864 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2865 | |
| 2866 | return RValue<Short4>(value); |
| 2867 | } |
| 2868 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2869 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2870 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2871 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2872 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2873 | return RValue<Short4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | RValue<Short4> Short4::operator=(const UShort4 &rhs) const |
| 2877 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2878 | Value *value = rhs.loadValue(); |
| 2879 | storeValue(value); |
| 2880 | |
| 2881 | return RValue<Short4>(value); |
| 2882 | } |
| 2883 | |
| 2884 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const |
| 2885 | { |
| 2886 | Value *value = rhs.loadValue(); |
| 2887 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2888 | |
| 2889 | return RValue<Short4>(value); |
| 2890 | } |
| 2891 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2892 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2893 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2894 | if(CPUID::supportsMMX2()) |
| 2895 | { |
| 2896 | return x86::paddw(lhs, rhs); |
| 2897 | } |
| 2898 | else |
| 2899 | { |
| 2900 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2901 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2902 | } |
| 2903 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2904 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2905 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2906 | if(CPUID::supportsMMX2()) |
| 2907 | { |
| 2908 | return x86::psubw(lhs, rhs); |
| 2909 | } |
| 2910 | else |
| 2911 | { |
| 2912 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2913 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2914 | } |
| 2915 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2916 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2917 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2918 | if(CPUID::supportsMMX2()) |
| 2919 | { |
| 2920 | return x86::pmullw(lhs, rhs); |
| 2921 | } |
| 2922 | else |
| 2923 | { |
| 2924 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2925 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2928 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2929 | // { |
| 2930 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2931 | // } |
| 2932 | |
| 2933 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2934 | // { |
| 2935 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2936 | // } |
| 2937 | |
| 2938 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2939 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2940 | if(CPUID::supportsMMX2()) |
| 2941 | { |
| 2942 | return x86::pand(lhs, rhs); |
| 2943 | } |
| 2944 | else |
| 2945 | { |
| 2946 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2947 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2948 | } |
| 2949 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2950 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2951 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2952 | if(CPUID::supportsMMX2()) |
| 2953 | { |
| 2954 | return x86::por(lhs, rhs); |
| 2955 | } |
| 2956 | else |
| 2957 | { |
| 2958 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2959 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2960 | } |
| 2961 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2962 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2963 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2964 | if(CPUID::supportsMMX2()) |
| 2965 | { |
| 2966 | return x86::pxor(lhs, rhs); |
| 2967 | } |
| 2968 | else |
| 2969 | { |
| 2970 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2971 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2972 | } |
| 2973 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2974 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2975 | { |
| 2976 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2977 | |
| 2978 | return x86::psllw(lhs, rhs); |
| 2979 | } |
| 2980 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2981 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2982 | { |
| 2983 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2984 | |
| 2985 | return x86::psraw(lhs, rhs); |
| 2986 | } |
| 2987 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2988 | RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2989 | { |
| 2990 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2991 | |
| 2992 | return x86::psllw(lhs, rhs); |
| 2993 | } |
| 2994 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2995 | RValue<Short4> operator>>(RValue<Short4> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2996 | { |
| 2997 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2998 | |
| 2999 | return x86::psraw(lhs, rhs); |
| 3000 | } |
| 3001 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3002 | RValue<Short4> operator+=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3003 | { |
| 3004 | return lhs = lhs + rhs; |
| 3005 | } |
| 3006 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3007 | RValue<Short4> operator-=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3008 | { |
| 3009 | return lhs = lhs - rhs; |
| 3010 | } |
| 3011 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3012 | RValue<Short4> operator*=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3013 | { |
| 3014 | return lhs = lhs * rhs; |
| 3015 | } |
| 3016 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3017 | // RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs) |
| 3018 | // { |
| 3019 | // return lhs = lhs / rhs; |
| 3020 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3021 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3022 | // RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs) |
| 3023 | // { |
| 3024 | // return lhs = lhs % rhs; |
| 3025 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3026 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3027 | RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3028 | { |
| 3029 | return lhs = lhs & rhs; |
| 3030 | } |
| 3031 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3032 | RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3033 | { |
| 3034 | return lhs = lhs | rhs; |
| 3035 | } |
| 3036 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3037 | RValue<Short4> operator^=(const Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3038 | { |
| 3039 | return lhs = lhs ^ rhs; |
| 3040 | } |
| 3041 | |
| 3042 | RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs) |
| 3043 | { |
| 3044 | return lhs = lhs << rhs; |
| 3045 | } |
| 3046 | |
| 3047 | RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs) |
| 3048 | { |
| 3049 | return lhs = lhs >> rhs; |
| 3050 | } |
| 3051 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3052 | RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3053 | { |
| 3054 | return lhs = lhs << rhs; |
| 3055 | } |
| 3056 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3057 | RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3058 | { |
| 3059 | return lhs = lhs >> rhs; |
| 3060 | } |
| 3061 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3062 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3063 | // { |
| 3064 | // return val; |
| 3065 | // } |
| 3066 | |
| 3067 | RValue<Short4> operator-(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3068 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3069 | if(CPUID::supportsMMX2()) |
| 3070 | { |
| 3071 | return Short4(0, 0, 0, 0) - val; |
| 3072 | } |
| 3073 | else |
| 3074 | { |
| 3075 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
| 3076 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3077 | } |
| 3078 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3079 | RValue<Short4> operator~(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3080 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3081 | if(CPUID::supportsMMX2()) |
| 3082 | { |
| 3083 | return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu); |
| 3084 | } |
| 3085 | else |
| 3086 | { |
| 3087 | return RValue<Short4>(Nucleus::createNot(val.value)); |
| 3088 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3089 | } |
| 3090 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3091 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3092 | { |
| 3093 | RValue<Int4> v4i32 = x86::cvtps2dq(cast); |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 3094 | RValue<Short8> v8i16 = x86::packssdw(v4i32, v4i32); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3095 | |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 3096 | return As<Short4>(Int2(As<Int4>(v8i16))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3097 | } |
| 3098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3099 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3100 | { |
| 3101 | return x86::pmaxsw(x, y); |
| 3102 | } |
| 3103 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3104 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3105 | { |
| 3106 | return x86::pminsw(x, y); |
| 3107 | } |
| 3108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3109 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3110 | { |
| 3111 | return x86::paddsw(x, y); |
| 3112 | } |
| 3113 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3114 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3115 | { |
| 3116 | return x86::psubsw(x, y); |
| 3117 | } |
| 3118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3119 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3120 | { |
| 3121 | return x86::pmulhw(x, y); |
| 3122 | } |
| 3123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3124 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3125 | { |
| 3126 | return x86::pmaddwd(x, y); |
| 3127 | } |
| 3128 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3129 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3130 | { |
| 3131 | return x86::packsswb(x, y); |
| 3132 | } |
| 3133 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3134 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3135 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3136 | if(CPUID::supportsMMX2()) |
| 3137 | { |
| 3138 | return x86::punpcklwd(x, y); |
| 3139 | } |
| 3140 | else |
| 3141 | { |
| 3142 | Constant *shuffle[4]; |
| 3143 | shuffle[0] = Nucleus::createConstantInt(0); |
| 3144 | shuffle[1] = Nucleus::createConstantInt(4); |
| 3145 | shuffle[2] = Nucleus::createConstantInt(1); |
| 3146 | shuffle[3] = Nucleus::createConstantInt(5); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3147 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3148 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3150 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 3151 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3152 | } |
| 3153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3154 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3155 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3156 | if(CPUID::supportsMMX2()) |
| 3157 | { |
| 3158 | return x86::punpckhwd(x, y); |
| 3159 | } |
| 3160 | else |
| 3161 | { |
| 3162 | Constant *shuffle[4]; |
| 3163 | shuffle[0] = Nucleus::createConstantInt(2); |
| 3164 | shuffle[1] = Nucleus::createConstantInt(6); |
| 3165 | shuffle[2] = Nucleus::createConstantInt(3); |
| 3166 | shuffle[3] = Nucleus::createConstantInt(7); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3167 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3168 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3169 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3170 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 3171 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3172 | } |
| 3173 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3174 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3175 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3176 | if(CPUID::supportsMMX2()) |
| 3177 | { |
| 3178 | return x86::pshufw(x, select); |
| 3179 | } |
| 3180 | else |
| 3181 | { |
| 3182 | return RValue<Short4>(Nucleus::createSwizzle(x.value, select)); |
| 3183 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3184 | } |
| 3185 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3186 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3187 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3188 | if(CPUID::supportsMMX2()) |
| 3189 | { |
| 3190 | return x86::pinsrw(val, Int(element), i); |
| 3191 | } |
| 3192 | else |
| 3193 | { |
| 3194 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 3195 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3196 | } |
| 3197 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3198 | RValue<Short> Extract(RValue<Short4> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3199 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3200 | if(CPUID::supportsMMX2()) |
| 3201 | { |
| 3202 | return Short(x86::pextrw(val, i)); |
| 3203 | } |
| 3204 | else |
| 3205 | { |
| 3206 | return RValue<Short>(Nucleus::createExtractElement(val.value, i)); |
| 3207 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3208 | } |
| 3209 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3210 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3211 | { |
| 3212 | return x86::pcmpgtw(x, y); |
| 3213 | } |
| 3214 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3215 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3216 | { |
| 3217 | return x86::pcmpeqw(x, y); |
| 3218 | } |
| 3219 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3220 | Type *Short4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3221 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3222 | if(CPUID::supportsMMX2()) |
| 3223 | { |
| 3224 | return MMX::getType(); |
| 3225 | } |
| 3226 | else |
| 3227 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 3228 | return T(VectorType::get(Short::getType(), 4)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3229 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3232 | UShort4::UShort4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3233 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3234 | *this = Short4(cast); |
| 3235 | } |
| 3236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3237 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3238 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3239 | Float4 sat; |
| 3240 | |
| 3241 | if(saturate) |
| 3242 | { |
| 3243 | if(CPUID::supportsSSE4_1()) |
| 3244 | { |
| 3245 | sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation |
| 3246 | } |
| 3247 | else |
| 3248 | { |
| 3249 | sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)); |
| 3250 | } |
| 3251 | } |
| 3252 | else |
| 3253 | { |
| 3254 | sat = cast; |
| 3255 | } |
| 3256 | |
| 3257 | Int4 int4(sat); |
| 3258 | |
| 3259 | if(!saturate || !CPUID::supportsSSE4_1()) |
| 3260 | { |
| 3261 | *this = Short4(Int4(int4)); |
| 3262 | } |
| 3263 | else |
| 3264 | { |
| 3265 | *this = As<Short4>(Int2(As<Int4>(x86::packusdw(As<UInt4>(int4), As<UInt4>(int4))))); |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | UShort4::UShort4() |
| 3270 | { |
| 3271 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3272 | } |
| 3273 | |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 3274 | UShort4::UShort4(unsigned short xyzw) |
| 3275 | { |
| 3276 | // xyzw.parent = this; |
| 3277 | |
| 3278 | Constant *constantVector[4]; |
| 3279 | constantVector[0] = Nucleus::createConstantShort(xyzw); |
| 3280 | constantVector[1] = Nucleus::createConstantShort(xyzw); |
| 3281 | constantVector[2] = Nucleus::createConstantShort(xyzw); |
| 3282 | constantVector[3] = Nucleus::createConstantShort(xyzw); |
| 3283 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
| 3284 | |
| 3285 | storeValue(Nucleus::createBitCast(vector, getType())); |
| 3286 | } |
| 3287 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3288 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3289 | { |
| 3290 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3291 | |
| 3292 | Constant *constantVector[4]; |
| 3293 | constantVector[0] = Nucleus::createConstantShort(x); |
| 3294 | constantVector[1] = Nucleus::createConstantShort(y); |
| 3295 | constantVector[2] = Nucleus::createConstantShort(z); |
| 3296 | constantVector[3] = Nucleus::createConstantShort(w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3297 | Value *vector = Nucleus::createConstantVector(constantVector, 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3298 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3299 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3300 | } |
| 3301 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3302 | UShort4::UShort4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3303 | { |
| 3304 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3305 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3306 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | UShort4::UShort4(const UShort4 &rhs) |
| 3310 | { |
| 3311 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3312 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3313 | Value *value = rhs.loadValue(); |
| 3314 | storeValue(value); |
| 3315 | } |
| 3316 | |
| 3317 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3318 | { |
| 3319 | // xyzw.parent = this; |
| 3320 | |
| 3321 | Value *value = rhs.loadValue(); |
| 3322 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3323 | } |
| 3324 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3325 | UShort4::UShort4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3326 | { |
| 3327 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3328 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3329 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | UShort4::UShort4(const Short4 &rhs) |
| 3333 | { |
| 3334 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3335 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3336 | Value *value = rhs.loadValue(); |
| 3337 | storeValue(value); |
| 3338 | } |
| 3339 | |
| 3340 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3341 | { |
| 3342 | // xyzw.parent = this; |
| 3343 | |
| 3344 | Value *value = rhs.loadValue(); |
| 3345 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3346 | } |
| 3347 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3348 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3349 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3350 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3351 | |
| 3352 | return rhs; |
| 3353 | } |
| 3354 | |
| 3355 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const |
| 3356 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3357 | Value *value = rhs.loadValue(); |
| 3358 | storeValue(value); |
| 3359 | |
| 3360 | return RValue<UShort4>(value); |
| 3361 | } |
| 3362 | |
| 3363 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const |
| 3364 | { |
| 3365 | Value *value = rhs.loadValue(); |
| 3366 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3367 | |
| 3368 | return RValue<UShort4>(value); |
| 3369 | } |
| 3370 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3371 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3372 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3373 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3374 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3375 | return RValue<UShort4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) const |
| 3379 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3380 | Value *value = rhs.loadValue(); |
| 3381 | storeValue(value); |
| 3382 | |
| 3383 | return RValue<UShort4>(value); |
| 3384 | } |
| 3385 | |
| 3386 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const |
| 3387 | { |
| 3388 | Value *value = rhs.loadValue(); |
| 3389 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3390 | |
| 3391 | return RValue<UShort4>(value); |
| 3392 | } |
| 3393 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3394 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3395 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3396 | if(CPUID::supportsMMX2()) |
| 3397 | { |
| 3398 | return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3399 | } |
| 3400 | else |
| 3401 | { |
| 3402 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3403 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3404 | } |
| 3405 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3406 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3407 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3408 | if(CPUID::supportsMMX2()) |
| 3409 | { |
| 3410 | return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3411 | } |
| 3412 | else |
| 3413 | { |
| 3414 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3415 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3416 | } |
| 3417 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 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 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 3533 | return T(VectorType::get(UShort::getType(), 4)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 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 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 3627 | return T(VectorType::get(Short::getType(), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 3794 | return T(VectorType::get(UShort::getType(), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4148 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4153 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4154 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4155 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4156 | } |
| 4157 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4158 | Long::Long(RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4159 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4160 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4161 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4162 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | Long::Long() |
| 4166 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4167 | } |
| 4168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4169 | Long::Long(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4170 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4171 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | RValue<Long> Long::operator=(int64_t rhs) const |
| 4175 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4176 | return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4177 | } |
| 4178 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4179 | RValue<Long> Long::operator=(RValue<Long> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4180 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4181 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4182 | |
| 4183 | return rhs; |
| 4184 | } |
| 4185 | |
| 4186 | RValue<Long> Long::operator=(const Long &rhs) const |
| 4187 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4188 | Value *value = rhs.loadValue(); |
| 4189 | storeValue(value); |
| 4190 | |
| 4191 | return RValue<Long>(value); |
| 4192 | } |
| 4193 | |
| 4194 | RValue<Long> Long::operator=(const Reference<Long> &rhs) const |
| 4195 | { |
| 4196 | Value *value = rhs.loadValue(); |
| 4197 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4198 | |
| 4199 | return RValue<Long>(value); |
| 4200 | } |
| 4201 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4202 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4203 | { |
| 4204 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4205 | } |
| 4206 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4207 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4208 | { |
| 4209 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4210 | } |
| 4211 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4212 | RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4213 | { |
| 4214 | return lhs = lhs + rhs; |
| 4215 | } |
| 4216 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4217 | RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4218 | { |
| 4219 | return lhs = lhs - rhs; |
| 4220 | } |
| 4221 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4222 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4223 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4224 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4225 | } |
| 4226 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4227 | Type *Long::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4228 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4229 | return T(llvm::Type::getInt64Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4230 | } |
| 4231 | |
Nicolas Capens | 50c9636 | 2016-01-04 23:03:59 -0500 | [diff] [blame] | 4232 | Long1::Long1(const RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4233 | { |
Nicolas Capens | 50c9636 | 2016-01-04 23:03:59 -0500 | [diff] [blame] | 4234 | Value *undefCast = Nucleus::createInsertElement(UndefValue::get(VectorType::get(Int::getType(), 2)), cast.value, 0); |
| 4235 | Value *zeroCast = Nucleus::createInsertElement(undefCast, Nucleus::createConstantInt(0), 1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4236 | |
Nicolas Capens | 50c9636 | 2016-01-04 23:03:59 -0500 | [diff] [blame] | 4237 | storeValue(Nucleus::createBitCast(zeroCast, Long1::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4238 | } |
| 4239 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4240 | Long1::Long1(RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4241 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4242 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4243 | } |
| 4244 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4245 | Type *Long1::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4246 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4247 | if(CPUID::supportsMMX2()) |
| 4248 | { |
| 4249 | return MMX::getType(); |
| 4250 | } |
| 4251 | else |
| 4252 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4253 | return T(VectorType::get(Long::getType(), 1)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4254 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4255 | } |
| 4256 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4257 | RValue<Long2> UnpackHigh(RValue<Long2> x, RValue<Long2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4258 | { |
| 4259 | Constant *shuffle[2]; |
| 4260 | shuffle[0] = Nucleus::createConstantInt(1); |
| 4261 | shuffle[1] = Nucleus::createConstantInt(3); |
| 4262 | |
| 4263 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2)); |
| 4264 | |
| 4265 | return RValue<Long2>(packed); |
| 4266 | } |
| 4267 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4268 | Type *Long2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4269 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4270 | return T(VectorType::get(Long::getType(), 2)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4271 | } |
| 4272 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 4273 | UInt::UInt(Argument<UInt> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4274 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 4275 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4276 | } |
| 4277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4278 | UInt::UInt(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4279 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4280 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4281 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4282 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4283 | } |
| 4284 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4285 | UInt::UInt(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4286 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4287 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4288 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4289 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4290 | } |
| 4291 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4292 | UInt::UInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4293 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 4294 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 4295 | // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4296 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 4297 | // Smallest positive value representable in UInt, but not in Int |
| 4298 | const unsigned int ustart = 0x80000000u; |
| 4299 | const float ustartf = float(ustart); |
| 4300 | |
| 4301 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4302 | storeValue((~(As<Int>(cast) >> 31) & |
| 4303 | // Check if the value can be represented as an Int |
| 4304 | IfThenElse(cast >= ustartf, |
| 4305 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4306 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4307 | // Otherwise, just convert normally |
| 4308 | Int(cast))).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | UInt::UInt() |
| 4312 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | UInt::UInt(int x) |
| 4316 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4317 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | UInt::UInt(unsigned int x) |
| 4321 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4322 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4323 | } |
| 4324 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4325 | UInt::UInt(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4326 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4327 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4328 | } |
| 4329 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4330 | UInt::UInt(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4331 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4332 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | UInt::UInt(const UInt &rhs) |
| 4336 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4337 | Value *value = rhs.loadValue(); |
| 4338 | storeValue(value); |
| 4339 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4340 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4341 | UInt::UInt(const Reference<UInt> &rhs) |
| 4342 | { |
| 4343 | Value *value = rhs.loadValue(); |
| 4344 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | UInt::UInt(const Int &rhs) |
| 4348 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4349 | Value *value = rhs.loadValue(); |
| 4350 | storeValue(value); |
| 4351 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4352 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4353 | UInt::UInt(const Reference<Int> &rhs) |
| 4354 | { |
| 4355 | Value *value = rhs.loadValue(); |
| 4356 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | RValue<UInt> UInt::operator=(unsigned int rhs) const |
| 4360 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4361 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4362 | } |
| 4363 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4364 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4365 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4366 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4367 | |
| 4368 | return rhs; |
| 4369 | } |
| 4370 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4371 | RValue<UInt> UInt::operator=(RValue<Int> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4372 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4373 | storeValue(rhs.value); |
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 | return RValue<UInt>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | RValue<UInt> UInt::operator=(const UInt &rhs) const |
| 4379 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4380 | Value *value = rhs.loadValue(); |
| 4381 | storeValue(value); |
| 4382 | |
| 4383 | return RValue<UInt>(value); |
| 4384 | } |
| 4385 | |
| 4386 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const |
| 4387 | { |
| 4388 | Value *value = rhs.loadValue(); |
| 4389 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4390 | |
| 4391 | return RValue<UInt>(value); |
| 4392 | } |
| 4393 | |
| 4394 | RValue<UInt> UInt::operator=(const Int &rhs) const |
| 4395 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4396 | Value *value = rhs.loadValue(); |
| 4397 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4398 | |
| 4399 | return RValue<UInt>(value); |
| 4400 | } |
| 4401 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4402 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4403 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4404 | Value *value = rhs.loadValue(); |
| 4405 | storeValue(value); |
| 4406 | |
| 4407 | return RValue<UInt>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4408 | } |
| 4409 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4410 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4411 | { |
| 4412 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4413 | } |
| 4414 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4415 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4416 | { |
| 4417 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4418 | } |
| 4419 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4420 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4421 | { |
| 4422 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4423 | } |
| 4424 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4425 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4426 | { |
| 4427 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4428 | } |
| 4429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4430 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4431 | { |
| 4432 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4433 | } |
| 4434 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4435 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4436 | { |
| 4437 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4438 | } |
| 4439 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4440 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4441 | { |
| 4442 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4443 | } |
| 4444 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4445 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4446 | { |
| 4447 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4448 | } |
| 4449 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4450 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4451 | { |
| 4452 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4453 | } |
| 4454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4455 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4456 | { |
| 4457 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4458 | } |
| 4459 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4460 | RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4461 | { |
| 4462 | return lhs = lhs + rhs; |
| 4463 | } |
| 4464 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4465 | RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4466 | { |
| 4467 | return lhs = lhs - rhs; |
| 4468 | } |
| 4469 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4470 | RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4471 | { |
| 4472 | return lhs = lhs * rhs; |
| 4473 | } |
| 4474 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4475 | RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4476 | { |
| 4477 | return lhs = lhs / rhs; |
| 4478 | } |
| 4479 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4480 | RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4481 | { |
| 4482 | return lhs = lhs % rhs; |
| 4483 | } |
| 4484 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4485 | RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4486 | { |
| 4487 | return lhs = lhs & rhs; |
| 4488 | } |
| 4489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4490 | RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4491 | { |
| 4492 | return lhs = lhs | rhs; |
| 4493 | } |
| 4494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4495 | RValue<UInt> operator^=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4496 | { |
| 4497 | return lhs = lhs ^ rhs; |
| 4498 | } |
| 4499 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4500 | RValue<UInt> operator<<=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4501 | { |
| 4502 | return lhs = lhs << rhs; |
| 4503 | } |
| 4504 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4505 | RValue<UInt> operator>>=(const UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4506 | { |
| 4507 | return lhs = lhs >> rhs; |
| 4508 | } |
| 4509 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4510 | RValue<UInt> operator+(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4511 | { |
| 4512 | return val; |
| 4513 | } |
| 4514 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4515 | RValue<UInt> operator-(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4516 | { |
| 4517 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4518 | } |
| 4519 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4520 | RValue<UInt> operator~(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4521 | { |
| 4522 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4523 | } |
| 4524 | |
| 4525 | RValue<UInt> operator++(const UInt &val, int) // Post-increment |
| 4526 | { |
| 4527 | RValue<UInt> res = val; |
| 4528 | |
| 4529 | Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantInt(1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4530 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4531 | |
| 4532 | return res; |
| 4533 | } |
| 4534 | |
| 4535 | const UInt &operator++(const UInt &val) // Pre-increment |
| 4536 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4537 | Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantInt(1)); |
| 4538 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4539 | |
| 4540 | return val; |
| 4541 | } |
| 4542 | |
| 4543 | RValue<UInt> operator--(const UInt &val, int) // Post-decrement |
| 4544 | { |
| 4545 | RValue<UInt> res = val; |
| 4546 | |
| 4547 | Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantInt(1)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4548 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4549 | |
| 4550 | return res; |
| 4551 | } |
| 4552 | |
| 4553 | const UInt &operator--(const UInt &val) // Pre-decrement |
| 4554 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4555 | Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantInt(1)); |
| 4556 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4557 | |
| 4558 | return val; |
| 4559 | } |
| 4560 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4561 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4562 | { |
| 4563 | return IfThenElse(x > y, x, y); |
| 4564 | } |
| 4565 | |
| 4566 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4567 | { |
| 4568 | return IfThenElse(x < y, x, y); |
| 4569 | } |
| 4570 | |
| 4571 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4572 | { |
| 4573 | return Min(Max(x, min), max); |
| 4574 | } |
| 4575 | |
| 4576 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4577 | { |
| 4578 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4579 | } |
| 4580 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4581 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4582 | { |
| 4583 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4584 | } |
| 4585 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4586 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4587 | { |
| 4588 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4589 | } |
| 4590 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4591 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4592 | { |
| 4593 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4594 | } |
| 4595 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4596 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4597 | { |
| 4598 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4599 | } |
| 4600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4601 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4602 | { |
| 4603 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4604 | } |
| 4605 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4606 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4607 | // { |
| 4608 | // return x86::cvtss2si(val); // FIXME: Unsigned |
| 4609 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4610 | // // 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] | 4611 | // } |
| 4612 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4613 | Type *UInt::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4614 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4615 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4616 | } |
| 4617 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4618 | // Int2::Int2(RValue<Int> cast) |
| 4619 | // { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4620 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4621 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4622 | // |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4623 | // Constant *shuffle[2]; |
| 4624 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4625 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4626 | // |
| 4627 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4628 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4629 | // storeValue(replicate); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4630 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4631 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4632 | Int2::Int2(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4633 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4634 | Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType()); |
| 4635 | Value *element = Nucleus::createExtractElement(long2, 0); |
| 4636 | Value *int2 = Nucleus::createBitCast(element, Int2::getType()); |
| 4637 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4638 | storeValue(int2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | Int2::Int2() |
| 4642 | { |
| 4643 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | Int2::Int2(int x, int y) |
| 4647 | { |
| 4648 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4649 | |
| 4650 | Constant *constantVector[2]; |
| 4651 | constantVector[0] = Nucleus::createConstantInt(x); |
| 4652 | constantVector[1] = Nucleus::createConstantInt(y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4653 | Value *vector = Nucleus::createConstantVector(constantVector, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4654 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4655 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4656 | } |
| 4657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4658 | Int2::Int2(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4659 | { |
| 4660 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4661 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4662 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | Int2::Int2(const Int2 &rhs) |
| 4666 | { |
| 4667 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4668 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4669 | Value *value = rhs.loadValue(); |
| 4670 | storeValue(value); |
| 4671 | } |
| 4672 | |
| 4673 | Int2::Int2(const Reference<Int2> &rhs) |
| 4674 | { |
| 4675 | // xy.parent = this; |
| 4676 | |
| 4677 | Value *value = rhs.loadValue(); |
| 4678 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4679 | } |
| 4680 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4681 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4682 | { |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4683 | if(CPUID::supportsMMX2()) |
| 4684 | { |
| 4685 | // movd mm0, lo |
| 4686 | // movd mm1, hi |
| 4687 | // punpckldq mm0, mm1 |
| 4688 | storeValue(As<Int2>(UnpackLow(As<Int2>(Long1(RValue<UInt>(lo))), As<Int2>(Long1(RValue<UInt>(hi))))).value); |
| 4689 | } |
| 4690 | else |
| 4691 | { |
| 4692 | Constant *shuffle[2]; |
| 4693 | shuffle[0] = Nucleus::createConstantInt(0); |
| 4694 | shuffle[1] = Nucleus::createConstantInt(1); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4695 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4696 | Value *packed = Nucleus::createShuffleVector(Nucleus::createBitCast(lo.value, T(VectorType::get(Int::getType(), 1))), Nucleus::createBitCast(hi.value, T(VectorType::get(Int::getType(), 1))), Nucleus::createConstantVector(shuffle, 2)); |
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 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
| 4699 | } |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4700 | } |
| 4701 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4702 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4703 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4704 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4705 | |
| 4706 | return rhs; |
| 4707 | } |
| 4708 | |
| 4709 | RValue<Int2> Int2::operator=(const Int2 &rhs) const |
| 4710 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4711 | Value *value = rhs.loadValue(); |
| 4712 | storeValue(value); |
| 4713 | |
| 4714 | return RValue<Int2>(value); |
| 4715 | } |
| 4716 | |
| 4717 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const |
| 4718 | { |
| 4719 | Value *value = rhs.loadValue(); |
| 4720 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4721 | |
| 4722 | return RValue<Int2>(value); |
| 4723 | } |
| 4724 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4725 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4726 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4727 | if(CPUID::supportsMMX2()) |
| 4728 | { |
| 4729 | return x86::paddd(lhs, rhs); |
| 4730 | } |
| 4731 | else |
| 4732 | { |
| 4733 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4734 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4735 | } |
| 4736 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4737 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4738 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4739 | if(CPUID::supportsMMX2()) |
| 4740 | { |
| 4741 | return x86::psubd(lhs, rhs); |
| 4742 | } |
| 4743 | else |
| 4744 | { |
| 4745 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4746 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4747 | } |
| 4748 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4749 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4750 | // { |
| 4751 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4752 | // } |
| 4753 | |
| 4754 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4755 | // { |
| 4756 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4757 | // } |
| 4758 | |
| 4759 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4760 | // { |
| 4761 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4762 | // } |
| 4763 | |
| 4764 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4765 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4766 | if(CPUID::supportsMMX2()) |
| 4767 | { |
| 4768 | return As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 4769 | } |
| 4770 | else |
| 4771 | { |
| 4772 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4773 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4774 | } |
| 4775 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4776 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4777 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4778 | if(CPUID::supportsMMX2()) |
| 4779 | { |
| 4780 | return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 4781 | } |
| 4782 | else |
| 4783 | { |
| 4784 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4785 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4786 | } |
| 4787 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4788 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4789 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4790 | if(CPUID::supportsMMX2()) |
| 4791 | { |
| 4792 | return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 4793 | } |
| 4794 | else |
| 4795 | { |
| 4796 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4797 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4798 | } |
| 4799 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4800 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4801 | { |
| 4802 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4803 | |
| 4804 | return x86::pslld(lhs, rhs); |
| 4805 | } |
| 4806 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4807 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4808 | { |
| 4809 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4810 | |
| 4811 | return x86::psrad(lhs, rhs); |
| 4812 | } |
| 4813 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4814 | RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4815 | { |
| 4816 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4817 | |
| 4818 | return x86::pslld(lhs, rhs); |
| 4819 | } |
| 4820 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4821 | RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4822 | { |
| 4823 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4824 | |
| 4825 | return x86::psrad(lhs, rhs); |
| 4826 | } |
| 4827 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4828 | RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4829 | { |
| 4830 | return lhs = lhs + rhs; |
| 4831 | } |
| 4832 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4833 | RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4834 | { |
| 4835 | return lhs = lhs - rhs; |
| 4836 | } |
| 4837 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4838 | // RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs) |
| 4839 | // { |
| 4840 | // return lhs = lhs * rhs; |
| 4841 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4842 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4843 | // RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs) |
| 4844 | // { |
| 4845 | // return lhs = lhs / rhs; |
| 4846 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4847 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4848 | // RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs) |
| 4849 | // { |
| 4850 | // return lhs = lhs % rhs; |
| 4851 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4852 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4853 | RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4854 | { |
| 4855 | return lhs = lhs & rhs; |
| 4856 | } |
| 4857 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4858 | RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4859 | { |
| 4860 | return lhs = lhs | rhs; |
| 4861 | } |
| 4862 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4863 | RValue<Int2> operator^=(const Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4864 | { |
| 4865 | return lhs = lhs ^ rhs; |
| 4866 | } |
| 4867 | |
| 4868 | RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs) |
| 4869 | { |
| 4870 | return lhs = lhs << rhs; |
| 4871 | } |
| 4872 | |
| 4873 | RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs) |
| 4874 | { |
| 4875 | return lhs = lhs >> rhs; |
| 4876 | } |
| 4877 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4878 | RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4879 | { |
| 4880 | return lhs = lhs << rhs; |
| 4881 | } |
| 4882 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4883 | RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4884 | { |
| 4885 | return lhs = lhs >> rhs; |
| 4886 | } |
| 4887 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4888 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4889 | // { |
| 4890 | // return val; |
| 4891 | // } |
| 4892 | |
| 4893 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4894 | // { |
| 4895 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4896 | // } |
| 4897 | |
| 4898 | RValue<Int2> operator~(RValue<Int2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4899 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4900 | if(CPUID::supportsMMX2()) |
| 4901 | { |
| 4902 | return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF); |
| 4903 | } |
| 4904 | else |
| 4905 | { |
| 4906 | return RValue<Int2>(Nucleus::createNot(val.value)); |
| 4907 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4908 | } |
| 4909 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4910 | RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4911 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4912 | if(CPUID::supportsMMX2()) |
| 4913 | { |
| 4914 | return x86::punpckldq(x, y); |
| 4915 | } |
| 4916 | else |
| 4917 | { |
| 4918 | Constant *shuffle[2]; |
| 4919 | shuffle[0] = Nucleus::createConstantInt(0); |
| 4920 | shuffle[1] = Nucleus::createConstantInt(2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4921 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4922 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 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 | return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType())); |
| 4925 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4926 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4927 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4928 | RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4929 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4930 | if(CPUID::supportsMMX2()) |
| 4931 | { |
| 4932 | return x86::punpckhdq(x, y); |
| 4933 | } |
| 4934 | else |
| 4935 | { |
| 4936 | Constant *shuffle[2]; |
| 4937 | shuffle[0] = Nucleus::createConstantInt(1); |
| 4938 | shuffle[1] = Nucleus::createConstantInt(3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4939 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4940 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 2)); |
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 | return RValue<Long1>(Nucleus::createBitCast(packed, Long1::getType())); |
| 4943 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4944 | } |
| 4945 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4946 | RValue<Int> Extract(RValue<Int2> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4947 | { |
| 4948 | if(false) // FIXME: LLVM does not generate optimal code |
| 4949 | { |
| 4950 | return RValue<Int>(Nucleus::createExtractElement(val.value, i)); |
| 4951 | } |
| 4952 | else |
| 4953 | { |
| 4954 | if(i == 0) |
| 4955 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4956 | return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, T(VectorType::get(Int::getType(), 2))), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4957 | } |
| 4958 | else |
| 4959 | { |
| 4960 | Int2 val2 = As<Int2>(UnpackHigh(val, val)); |
| 4961 | |
| 4962 | return Extract(val2, 0); |
| 4963 | } |
| 4964 | } |
| 4965 | } |
| 4966 | |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4967 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4968 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4969 | return RValue<Int2>(Nucleus::createBitCast(Nucleus::createInsertElement(Nucleus::createBitCast(val.value, T(VectorType::get(Int::getType(), 2))), element.value, i), Int2::getType())); |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4970 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4971 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4972 | Type *Int2::getType() |
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 | if(CPUID::supportsMMX2()) |
| 4975 | { |
| 4976 | return MMX::getType(); |
| 4977 | } |
| 4978 | else |
| 4979 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 4980 | return T(VectorType::get(Int::getType(), 2)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4981 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | UInt2::UInt2() |
| 4985 | { |
| 4986 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4990 | { |
| 4991 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4992 | |
| 4993 | Constant *constantVector[2]; |
| 4994 | constantVector[0] = Nucleus::createConstantInt(x); |
| 4995 | constantVector[1] = Nucleus::createConstantInt(y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4996 | Value *vector = Nucleus::createConstantVector(constantVector, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4997 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4998 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4999 | } |
| 5000 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5001 | UInt2::UInt2(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5002 | { |
| 5003 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5004 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5005 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | UInt2::UInt2(const UInt2 &rhs) |
| 5009 | { |
| 5010 | // xy.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5011 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5012 | Value *value = rhs.loadValue(); |
| 5013 | storeValue(value); |
| 5014 | } |
| 5015 | |
| 5016 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 5017 | { |
| 5018 | // xy.parent = this; |
| 5019 | |
| 5020 | Value *value = rhs.loadValue(); |
| 5021 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5022 | } |
| 5023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5024 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5025 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5026 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5027 | |
| 5028 | return rhs; |
| 5029 | } |
| 5030 | |
| 5031 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const |
| 5032 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5033 | Value *value = rhs.loadValue(); |
| 5034 | storeValue(value); |
| 5035 | |
| 5036 | return RValue<UInt2>(value); |
| 5037 | } |
| 5038 | |
| 5039 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const |
| 5040 | { |
| 5041 | Value *value = rhs.loadValue(); |
| 5042 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5043 | |
| 5044 | return RValue<UInt2>(value); |
| 5045 | } |
| 5046 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5047 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5048 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5049 | if(CPUID::supportsMMX2()) |
| 5050 | { |
| 5051 | return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs))); |
| 5052 | } |
| 5053 | else |
| 5054 | { |
| 5055 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5056 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5057 | } |
| 5058 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5059 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5060 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5061 | if(CPUID::supportsMMX2()) |
| 5062 | { |
| 5063 | return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs))); |
| 5064 | } |
| 5065 | else |
| 5066 | { |
| 5067 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5068 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5069 | } |
| 5070 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5071 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5072 | // { |
| 5073 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5074 | // } |
| 5075 | |
| 5076 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5077 | // { |
| 5078 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5079 | // } |
| 5080 | |
| 5081 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5082 | // { |
| 5083 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5084 | // } |
| 5085 | |
| 5086 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5087 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5088 | if(CPUID::supportsMMX2()) |
| 5089 | { |
| 5090 | return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 5091 | } |
| 5092 | else |
| 5093 | { |
| 5094 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5095 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5096 | } |
| 5097 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5098 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5099 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5100 | if(CPUID::supportsMMX2()) |
| 5101 | { |
| 5102 | return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 5103 | } |
| 5104 | else |
| 5105 | { |
| 5106 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5107 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5108 | } |
| 5109 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5110 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5111 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5112 | if(CPUID::supportsMMX2()) |
| 5113 | { |
| 5114 | return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 5115 | } |
| 5116 | else |
| 5117 | { |
| 5118 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5119 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5120 | } |
| 5121 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5122 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5123 | { |
| 5124 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5125 | |
| 5126 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 5127 | } |
| 5128 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5129 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5130 | { |
| 5131 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5132 | |
| 5133 | return x86::psrld(lhs, rhs); |
| 5134 | } |
| 5135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5136 | RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5137 | { |
| 5138 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5139 | |
| 5140 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 5141 | } |
| 5142 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5143 | RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5144 | { |
| 5145 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5146 | |
| 5147 | return x86::psrld(lhs, rhs); |
| 5148 | } |
| 5149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5150 | RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5151 | { |
| 5152 | return lhs = lhs + rhs; |
| 5153 | } |
| 5154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5155 | RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5156 | { |
| 5157 | return lhs = lhs - rhs; |
| 5158 | } |
| 5159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5160 | // RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs) |
| 5161 | // { |
| 5162 | // return lhs = lhs * rhs; |
| 5163 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5165 | // RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs) |
| 5166 | // { |
| 5167 | // return lhs = lhs / rhs; |
| 5168 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5169 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5170 | // RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs) |
| 5171 | // { |
| 5172 | // return lhs = lhs % rhs; |
| 5173 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5174 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5175 | RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5176 | { |
| 5177 | return lhs = lhs & rhs; |
| 5178 | } |
| 5179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5180 | RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5181 | { |
| 5182 | return lhs = lhs | rhs; |
| 5183 | } |
| 5184 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5185 | RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5186 | { |
| 5187 | return lhs = lhs ^ rhs; |
| 5188 | } |
| 5189 | |
| 5190 | RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs) |
| 5191 | { |
| 5192 | return lhs = lhs << rhs; |
| 5193 | } |
| 5194 | |
| 5195 | RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs) |
| 5196 | { |
| 5197 | return lhs = lhs >> rhs; |
| 5198 | } |
| 5199 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5200 | RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5201 | { |
| 5202 | return lhs = lhs << rhs; |
| 5203 | } |
| 5204 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5205 | RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5206 | { |
| 5207 | return lhs = lhs >> rhs; |
| 5208 | } |
| 5209 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5210 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 5211 | // { |
| 5212 | // return val; |
| 5213 | // } |
| 5214 | |
| 5215 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 5216 | // { |
| 5217 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 5218 | // } |
| 5219 | |
| 5220 | RValue<UInt2> operator~(RValue<UInt2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5221 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5222 | if(CPUID::supportsMMX2()) |
| 5223 | { |
| 5224 | return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF); |
| 5225 | } |
| 5226 | else |
| 5227 | { |
| 5228 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 5229 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5230 | } |
| 5231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5232 | Type *UInt2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5233 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5234 | if(CPUID::supportsMMX2()) |
| 5235 | { |
| 5236 | return MMX::getType(); |
| 5237 | } |
| 5238 | else |
| 5239 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 5240 | return T(VectorType::get(UInt::getType(), 2)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5241 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5242 | } |
| 5243 | |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 5244 | Int4::Int4(RValue<Byte4> cast) |
| 5245 | { |
| 5246 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5247 | Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0); |
| 5248 | |
| 5249 | Value *e; |
| 5250 | |
| 5251 | if (CPUID::supportsSSE4_1()) |
| 5252 | { |
| 5253 | e = x86::pmovzxbd(RValue<Int4>(a)).value; |
| 5254 | } |
| 5255 | else |
| 5256 | { |
| 5257 | Constant *swizzle[16]; |
| 5258 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5259 | swizzle[1] = Nucleus::createConstantInt(16); |
| 5260 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5261 | swizzle[3] = Nucleus::createConstantInt(17); |
| 5262 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5263 | swizzle[5] = Nucleus::createConstantInt(18); |
| 5264 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5265 | swizzle[7] = Nucleus::createConstantInt(19); |
| 5266 | swizzle[8] = Nucleus::createConstantInt(4); |
| 5267 | swizzle[9] = Nucleus::createConstantInt(20); |
| 5268 | swizzle[10] = Nucleus::createConstantInt(5); |
| 5269 | swizzle[11] = Nucleus::createConstantInt(21); |
| 5270 | swizzle[12] = Nucleus::createConstantInt(6); |
| 5271 | swizzle[13] = Nucleus::createConstantInt(22); |
| 5272 | swizzle[14] = Nucleus::createConstantInt(7); |
| 5273 | swizzle[15] = Nucleus::createConstantInt(23); |
| 5274 | |
| 5275 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5276 | Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Byte16::getType()), Nucleus::createConstantVector(swizzle, 16)); |
| 5277 | |
| 5278 | Constant *swizzle2[8]; |
| 5279 | swizzle2[0] = Nucleus::createConstantInt(0); |
| 5280 | swizzle2[1] = Nucleus::createConstantInt(8); |
| 5281 | swizzle2[2] = Nucleus::createConstantInt(1); |
| 5282 | swizzle2[3] = Nucleus::createConstantInt(9); |
| 5283 | swizzle2[4] = Nucleus::createConstantInt(2); |
| 5284 | swizzle2[5] = Nucleus::createConstantInt(10); |
| 5285 | swizzle2[6] = Nucleus::createConstantInt(3); |
| 5286 | swizzle2[7] = Nucleus::createConstantInt(11); |
| 5287 | |
| 5288 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5289 | e = Nucleus::createShuffleVector(d, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle2, 8)); |
| 5290 | } |
| 5291 | |
| 5292 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5293 | storeValue(f); |
| 5294 | } |
| 5295 | |
| 5296 | Int4::Int4(RValue<SByte4> cast) |
| 5297 | { |
| 5298 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5299 | Value *a = Nucleus::createInsertElement(UndefValue::get(Int4::getType()), x, 0); |
| 5300 | |
| 5301 | Value *g; |
| 5302 | |
| 5303 | if (CPUID::supportsSSE4_1()) |
| 5304 | { |
| 5305 | g = x86::pmovsxbd(RValue<Int4>(a)).value; |
| 5306 | } |
| 5307 | else |
| 5308 | { |
| 5309 | Constant *swizzle[16]; |
| 5310 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5311 | swizzle[1] = Nucleus::createConstantInt(0); |
| 5312 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5313 | swizzle[3] = Nucleus::createConstantInt(1); |
| 5314 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5315 | swizzle[5] = Nucleus::createConstantInt(2); |
| 5316 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5317 | swizzle[7] = Nucleus::createConstantInt(3); |
| 5318 | swizzle[8] = Nucleus::createConstantInt(4); |
| 5319 | swizzle[9] = Nucleus::createConstantInt(4); |
| 5320 | swizzle[10] = Nucleus::createConstantInt(5); |
| 5321 | swizzle[11] = Nucleus::createConstantInt(5); |
| 5322 | swizzle[12] = Nucleus::createConstantInt(6); |
| 5323 | swizzle[13] = Nucleus::createConstantInt(6); |
| 5324 | swizzle[14] = Nucleus::createConstantInt(7); |
| 5325 | swizzle[15] = Nucleus::createConstantInt(7); |
| 5326 | |
| 5327 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5328 | Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 16)); |
| 5329 | |
| 5330 | Constant *swizzle2[8]; |
| 5331 | swizzle2[0] = Nucleus::createConstantInt(0); |
| 5332 | swizzle2[1] = Nucleus::createConstantInt(0); |
| 5333 | swizzle2[2] = Nucleus::createConstantInt(1); |
| 5334 | swizzle2[3] = Nucleus::createConstantInt(1); |
| 5335 | swizzle2[4] = Nucleus::createConstantInt(2); |
| 5336 | swizzle2[5] = Nucleus::createConstantInt(2); |
| 5337 | swizzle2[6] = Nucleus::createConstantInt(3); |
| 5338 | swizzle2[7] = Nucleus::createConstantInt(3); |
| 5339 | |
| 5340 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5341 | Value *e = Nucleus::createShuffleVector(d, d, Nucleus::createConstantVector(swizzle2, 8)); |
| 5342 | |
| 5343 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5344 | // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24)); |
| 5345 | g = x86::psrad(RValue<Int4>(f), 24).value; |
| 5346 | } |
| 5347 | |
| 5348 | storeValue(g); |
| 5349 | } |
| 5350 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5351 | Int4::Int4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5352 | { |
| 5353 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5354 | |
| 5355 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5356 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5357 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5358 | } |
| 5359 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5360 | Int4::Int4(RValue<Short4> cast) |
| 5361 | { |
| 5362 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5363 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 5364 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 5365 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5366 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5367 | if(CPUID::supportsSSE4_1()) |
| 5368 | { |
| 5369 | storeValue(x86::pmovsxwd(vector).value); |
| 5370 | } |
| 5371 | else |
| 5372 | { |
| 5373 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 5374 | |
| 5375 | Constant *swizzle[8]; |
| 5376 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5377 | swizzle[1] = Nucleus::createConstantInt(0); |
| 5378 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5379 | swizzle[3] = Nucleus::createConstantInt(1); |
| 5380 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5381 | swizzle[5] = Nucleus::createConstantInt(2); |
| 5382 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5383 | swizzle[7] = Nucleus::createConstantInt(3); |
| 5384 | |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 5385 | Value *c = Nucleus::createShuffleVector(b, b, Nucleus::createConstantVector(swizzle, 8)); |
| 5386 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5387 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5388 | |
| 5389 | // Each Short is packed into each Int in the (Short | Short) format. |
| 5390 | // Shifting by 16 will retrieve the original Short value. |
| 5391 | // Shitfing an Int will propagate the sign bit, which will work |
| 5392 | // for both positive and negative values of a Short. |
| 5393 | *this >>= 16; |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | Int4::Int4(RValue<UShort4> cast) |
| 5398 | { |
| 5399 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5400 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 5401 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 5402 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
| 5403 | |
| 5404 | if(CPUID::supportsSSE4_1()) |
| 5405 | { |
| 5406 | storeValue(x86::pmovzxwd(RValue<Int4>(vector)).value); |
| 5407 | } |
| 5408 | else |
| 5409 | { |
| 5410 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 5411 | |
| 5412 | Constant *swizzle[8]; |
| 5413 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5414 | swizzle[1] = Nucleus::createConstantInt(8); |
| 5415 | swizzle[2] = Nucleus::createConstantInt(1); |
| 5416 | swizzle[3] = Nucleus::createConstantInt(9); |
| 5417 | swizzle[4] = Nucleus::createConstantInt(2); |
| 5418 | swizzle[5] = Nucleus::createConstantInt(10); |
| 5419 | swizzle[6] = Nucleus::createConstantInt(3); |
| 5420 | swizzle[7] = Nucleus::createConstantInt(11); |
| 5421 | |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 5422 | Value *c = Nucleus::createShuffleVector(b, Nucleus::createNullValue(Short8::getType()), Nucleus::createConstantVector(swizzle, 8)); |
| 5423 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5424 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5428 | Int4::Int4() |
| 5429 | { |
| 5430 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | Int4::Int4(int xyzw) |
| 5434 | { |
| 5435 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5436 | } |
| 5437 | |
| 5438 | Int4::Int4(int x, int yzw) |
| 5439 | { |
| 5440 | constant(x, yzw, yzw, yzw); |
| 5441 | } |
| 5442 | |
| 5443 | Int4::Int4(int x, int y, int zw) |
| 5444 | { |
| 5445 | constant(x, y, zw, zw); |
| 5446 | } |
| 5447 | |
| 5448 | Int4::Int4(int x, int y, int z, int w) |
| 5449 | { |
| 5450 | constant(x, y, z, w); |
| 5451 | } |
| 5452 | |
| 5453 | void Int4::constant(int x, int y, int z, int w) |
| 5454 | { |
| 5455 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5456 | |
| 5457 | Constant *constantVector[4]; |
| 5458 | constantVector[0] = Nucleus::createConstantInt(x); |
| 5459 | constantVector[1] = Nucleus::createConstantInt(y); |
| 5460 | constantVector[2] = Nucleus::createConstantInt(z); |
| 5461 | constantVector[3] = Nucleus::createConstantInt(w); |
| 5462 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5463 | storeValue(Nucleus::createConstantVector(constantVector, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5464 | } |
| 5465 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5466 | Int4::Int4(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5467 | { |
| 5468 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5469 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5470 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | Int4::Int4(const Int4 &rhs) |
| 5474 | { |
| 5475 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5476 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5477 | Value *value = rhs.loadValue(); |
| 5478 | storeValue(value); |
| 5479 | } |
| 5480 | |
| 5481 | Int4::Int4(const Reference<Int4> &rhs) |
| 5482 | { |
| 5483 | // xyzw.parent = this; |
| 5484 | |
| 5485 | Value *value = rhs.loadValue(); |
| 5486 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5487 | } |
| 5488 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5489 | Int4::Int4(RValue<UInt4> rhs) |
| 5490 | { |
| 5491 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5492 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5493 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | Int4::Int4(const UInt4 &rhs) |
| 5497 | { |
| 5498 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5499 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5500 | Value *value = rhs.loadValue(); |
| 5501 | storeValue(value); |
| 5502 | } |
| 5503 | |
| 5504 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5505 | { |
| 5506 | // xyzw.parent = this; |
| 5507 | |
| 5508 | Value *value = rhs.loadValue(); |
| 5509 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5510 | } |
| 5511 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5512 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5513 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 5514 | // xyzw.parent = this; |
| 5515 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5516 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 5517 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 5518 | |
| 5519 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5520 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 5521 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 5522 | Value *int4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 5523 | |
| 5524 | storeValue(int4); |
| 5525 | } |
| 5526 | |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 5527 | Int4::Int4(RValue<Int> rhs) |
| 5528 | { |
| 5529 | // xyzw.parent = this; |
| 5530 | |
| 5531 | Value *vector = loadValue(); |
| 5532 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5533 | |
| 5534 | Constant *swizzle[4]; |
| 5535 | swizzle[0] = Nucleus::createConstantInt(0); |
| 5536 | swizzle[1] = Nucleus::createConstantInt(0); |
| 5537 | swizzle[2] = Nucleus::createConstantInt(0); |
| 5538 | swizzle[3] = Nucleus::createConstantInt(0); |
| 5539 | |
| 5540 | Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Int4::getType()), Nucleus::createConstantVector(swizzle, 4)); |
| 5541 | |
| 5542 | storeValue(replicate); |
| 5543 | } |
| 5544 | |
| 5545 | Int4::Int4(const Int &rhs) |
| 5546 | { |
| 5547 | // xyzw.parent = this; |
| 5548 | |
| 5549 | *this = RValue<Int>(rhs.loadValue()); |
| 5550 | } |
| 5551 | |
| 5552 | Int4::Int4(const Reference<Int> &rhs) |
| 5553 | { |
| 5554 | // xyzw.parent = this; |
| 5555 | |
| 5556 | *this = RValue<Int>(rhs.loadValue()); |
| 5557 | } |
| 5558 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5559 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5560 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5561 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5562 | |
| 5563 | return rhs; |
| 5564 | } |
| 5565 | |
| 5566 | RValue<Int4> Int4::operator=(const Int4 &rhs) const |
| 5567 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5568 | Value *value = rhs.loadValue(); |
| 5569 | storeValue(value); |
| 5570 | |
| 5571 | return RValue<Int4>(value); |
| 5572 | } |
| 5573 | |
| 5574 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const |
| 5575 | { |
| 5576 | Value *value = rhs.loadValue(); |
| 5577 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5578 | |
| 5579 | return RValue<Int4>(value); |
| 5580 | } |
| 5581 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5582 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5583 | { |
| 5584 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5585 | } |
| 5586 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5587 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5588 | { |
| 5589 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5590 | } |
| 5591 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5592 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5593 | { |
| 5594 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5595 | } |
| 5596 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5597 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5598 | { |
| 5599 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5600 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5601 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5602 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5603 | { |
| 5604 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5605 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5606 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5607 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5608 | { |
| 5609 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5610 | } |
| 5611 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5612 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5613 | { |
| 5614 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5615 | } |
| 5616 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5617 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5618 | { |
| 5619 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5620 | } |
| 5621 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5622 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5623 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5624 | return x86::pslld(lhs, rhs); |
| 5625 | } |
| 5626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5627 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5628 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5629 | return x86::psrad(lhs, rhs); |
| 5630 | } |
| 5631 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5632 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5633 | { |
| 5634 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5635 | } |
| 5636 | |
| 5637 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5638 | { |
| 5639 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5640 | } |
| 5641 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5642 | RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5643 | { |
| 5644 | return lhs = lhs + rhs; |
| 5645 | } |
| 5646 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5647 | RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5648 | { |
| 5649 | return lhs = lhs - rhs; |
| 5650 | } |
| 5651 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5652 | RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5653 | { |
| 5654 | return lhs = lhs * rhs; |
| 5655 | } |
| 5656 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5657 | // RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs) |
| 5658 | // { |
| 5659 | // return lhs = lhs / rhs; |
| 5660 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5661 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5662 | // RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs) |
| 5663 | // { |
| 5664 | // return lhs = lhs % rhs; |
| 5665 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5666 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5667 | RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5668 | { |
| 5669 | return lhs = lhs & rhs; |
| 5670 | } |
| 5671 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5672 | RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5673 | { |
| 5674 | return lhs = lhs | rhs; |
| 5675 | } |
| 5676 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5677 | RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5678 | { |
| 5679 | return lhs = lhs ^ rhs; |
| 5680 | } |
| 5681 | |
| 5682 | RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs) |
| 5683 | { |
| 5684 | return lhs = lhs << rhs; |
| 5685 | } |
| 5686 | |
| 5687 | RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs) |
| 5688 | { |
| 5689 | return lhs = lhs >> rhs; |
| 5690 | } |
| 5691 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5692 | RValue<Int4> operator+(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5693 | { |
| 5694 | return val; |
| 5695 | } |
| 5696 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5697 | RValue<Int4> operator-(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5698 | { |
| 5699 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5700 | } |
| 5701 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5702 | RValue<Int4> operator~(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5703 | { |
| 5704 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5705 | } |
| 5706 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5707 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5708 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5709 | // 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] | 5710 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5711 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5712 | 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] | 5713 | } |
| 5714 | |
| 5715 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5716 | { |
| 5717 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5718 | } |
| 5719 | |
| 5720 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5721 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5722 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5723 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5724 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5725 | 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] | 5726 | } |
| 5727 | |
| 5728 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5729 | { |
| 5730 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5731 | } |
| 5732 | |
| 5733 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5734 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5735 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5736 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5737 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5738 | 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] | 5739 | } |
| 5740 | |
| 5741 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5742 | { |
| 5743 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5744 | } |
| 5745 | |
| 5746 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5747 | { |
| 5748 | if(CPUID::supportsSSE4_1()) |
| 5749 | { |
| 5750 | return x86::pmaxsd(x, y); |
| 5751 | } |
| 5752 | else |
| 5753 | { |
| 5754 | RValue<Int4> greater = CmpNLE(x, y); |
| 5755 | return x & greater | y & ~greater; |
| 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5760 | { |
| 5761 | if(CPUID::supportsSSE4_1()) |
| 5762 | { |
| 5763 | return x86::pminsd(x, y); |
| 5764 | } |
| 5765 | else |
| 5766 | { |
| 5767 | RValue<Int4> less = CmpLT(x, y); |
| 5768 | return x & less | y & ~less; |
| 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | RValue<Int4> RoundInt(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5773 | { |
| 5774 | return x86::cvtps2dq(cast); |
| 5775 | } |
| 5776 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5777 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5778 | { |
| 5779 | return x86::packssdw(x, y); |
| 5780 | } |
| 5781 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5782 | RValue<Int> Extract(RValue<Int4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5783 | { |
| 5784 | return RValue<Int>(Nucleus::createExtractElement(x.value, i)); |
| 5785 | } |
| 5786 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5787 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5788 | { |
| 5789 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5790 | } |
| 5791 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5792 | RValue<Int> SignMask(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5793 | { |
| 5794 | return x86::movmskps(As<Float4>(x)); |
| 5795 | } |
| 5796 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5797 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5798 | { |
| 5799 | return RValue<Int4>(Nucleus::createSwizzle(x.value, select)); |
| 5800 | } |
| 5801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5802 | Type *Int4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5803 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 5804 | return T(VectorType::get(Int::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5805 | } |
| 5806 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5807 | UInt4::UInt4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5808 | { |
| 5809 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5810 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 5811 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 5812 | // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5813 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 5814 | // Smallest positive value representable in UInt, but not in Int |
| 5815 | const unsigned int ustart = 0x80000000u; |
| 5816 | const float ustartf = float(ustart); |
| 5817 | |
| 5818 | // Check if the value can be represented as an Int |
| 5819 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5820 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5821 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5822 | // Otherwise, just convert normally |
| 5823 | (~uiValue & Int4(cast)); |
| 5824 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5825 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | UInt4::UInt4() |
| 5829 | { |
| 5830 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5831 | } |
| 5832 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5833 | UInt4::UInt4(int xyzw) |
| 5834 | { |
| 5835 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5836 | } |
| 5837 | |
| 5838 | UInt4::UInt4(int x, int yzw) |
| 5839 | { |
| 5840 | constant(x, yzw, yzw, yzw); |
| 5841 | } |
| 5842 | |
| 5843 | UInt4::UInt4(int x, int y, int zw) |
| 5844 | { |
| 5845 | constant(x, y, zw, zw); |
| 5846 | } |
| 5847 | |
| 5848 | UInt4::UInt4(int x, int y, int z, int w) |
| 5849 | { |
| 5850 | constant(x, y, z, w); |
| 5851 | } |
| 5852 | |
| 5853 | void UInt4::constant(int x, int y, int z, int w) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5854 | { |
| 5855 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5856 | |
| 5857 | Constant *constantVector[4]; |
| 5858 | constantVector[0] = Nucleus::createConstantInt(x); |
| 5859 | constantVector[1] = Nucleus::createConstantInt(y); |
| 5860 | constantVector[2] = Nucleus::createConstantInt(z); |
| 5861 | constantVector[3] = Nucleus::createConstantInt(w); |
| 5862 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5863 | storeValue(Nucleus::createConstantVector(constantVector, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5864 | } |
| 5865 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5866 | UInt4::UInt4(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5867 | { |
| 5868 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5869 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5870 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | UInt4::UInt4(const UInt4 &rhs) |
| 5874 | { |
| 5875 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5876 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5877 | Value *value = rhs.loadValue(); |
| 5878 | storeValue(value); |
| 5879 | } |
| 5880 | |
| 5881 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5882 | { |
| 5883 | // xyzw.parent = this; |
| 5884 | |
| 5885 | Value *value = rhs.loadValue(); |
| 5886 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5887 | } |
| 5888 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5889 | UInt4::UInt4(RValue<Int4> rhs) |
| 5890 | { |
| 5891 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5892 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5893 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | UInt4::UInt4(const Int4 &rhs) |
| 5897 | { |
| 5898 | // xyzw.parent = this; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5899 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5900 | Value *value = rhs.loadValue(); |
| 5901 | storeValue(value); |
| 5902 | } |
| 5903 | |
| 5904 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5905 | { |
| 5906 | // xyzw.parent = this; |
| 5907 | |
| 5908 | Value *value = rhs.loadValue(); |
| 5909 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5910 | } |
| 5911 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5912 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5913 | { |
| 5914 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 5915 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 5916 | |
| 5917 | Value *long2 = UndefValue::get(Long2::getType()); |
| 5918 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 5919 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 5920 | Value *uint4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 5921 | |
| 5922 | storeValue(uint4); |
| 5923 | } |
| 5924 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5925 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5926 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5927 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5928 | |
| 5929 | return rhs; |
| 5930 | } |
| 5931 | |
| 5932 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const |
| 5933 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5934 | Value *value = rhs.loadValue(); |
| 5935 | storeValue(value); |
| 5936 | |
| 5937 | return RValue<UInt4>(value); |
| 5938 | } |
| 5939 | |
| 5940 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const |
| 5941 | { |
| 5942 | Value *value = rhs.loadValue(); |
| 5943 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5944 | |
| 5945 | return RValue<UInt4>(value); |
| 5946 | } |
| 5947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5948 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5949 | { |
| 5950 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5951 | } |
| 5952 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5953 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5954 | { |
| 5955 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5956 | } |
| 5957 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5958 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5959 | { |
| 5960 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5961 | } |
| 5962 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5963 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5964 | { |
| 5965 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5966 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5967 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5968 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5969 | { |
| 5970 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5971 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5972 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5973 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5974 | { |
| 5975 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5976 | } |
| 5977 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5978 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5979 | { |
| 5980 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5981 | } |
| 5982 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5983 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5984 | { |
| 5985 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5986 | } |
| 5987 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5988 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5989 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5990 | return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs)); |
| 5991 | } |
| 5992 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5993 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5994 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5995 | return x86::psrld(lhs, rhs); |
| 5996 | } |
| 5997 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5998 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5999 | { |
| 6000 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 6001 | } |
| 6002 | |
| 6003 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6004 | { |
| 6005 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 6006 | } |
| 6007 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6008 | RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6009 | { |
| 6010 | return lhs = lhs + rhs; |
| 6011 | } |
| 6012 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6013 | RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6014 | { |
| 6015 | return lhs = lhs - rhs; |
| 6016 | } |
| 6017 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6018 | RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6019 | { |
| 6020 | return lhs = lhs * rhs; |
| 6021 | } |
| 6022 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6023 | // RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs) |
| 6024 | // { |
| 6025 | // return lhs = lhs / rhs; |
| 6026 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6027 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6028 | // RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs) |
| 6029 | // { |
| 6030 | // return lhs = lhs % rhs; |
| 6031 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6032 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6033 | RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6034 | { |
| 6035 | return lhs = lhs & rhs; |
| 6036 | } |
| 6037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6038 | RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6039 | { |
| 6040 | return lhs = lhs | rhs; |
| 6041 | } |
| 6042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6043 | RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6044 | { |
| 6045 | return lhs = lhs ^ rhs; |
| 6046 | } |
| 6047 | |
| 6048 | RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs) |
| 6049 | { |
| 6050 | return lhs = lhs << rhs; |
| 6051 | } |
| 6052 | |
| 6053 | RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs) |
| 6054 | { |
| 6055 | return lhs = lhs >> rhs; |
| 6056 | } |
| 6057 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6058 | RValue<UInt4> operator+(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6059 | { |
| 6060 | return val; |
| 6061 | } |
| 6062 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6063 | RValue<UInt4> operator-(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6064 | { |
| 6065 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 6066 | } |
| 6067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6068 | RValue<UInt4> operator~(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6069 | { |
| 6070 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 6071 | } |
| 6072 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6073 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6074 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 6075 | // 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] | 6076 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 6077 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 6078 | 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] | 6079 | } |
| 6080 | |
| 6081 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6082 | { |
| 6083 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 6084 | } |
| 6085 | |
| 6086 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6087 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 6088 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 6089 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 6090 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 6091 | 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] | 6092 | } |
| 6093 | |
| 6094 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6095 | { |
| 6096 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 6097 | } |
| 6098 | |
| 6099 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6100 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 6101 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 6102 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 6103 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 6104 | 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] | 6105 | } |
| 6106 | |
| 6107 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6108 | { |
| 6109 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 6110 | } |
| 6111 | |
| 6112 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 6113 | { |
| 6114 | if(CPUID::supportsSSE4_1()) |
| 6115 | { |
| 6116 | return x86::pmaxud(x, y); |
| 6117 | } |
| 6118 | else |
| 6119 | { |
| 6120 | RValue<UInt4> greater = CmpNLE(x, y); |
| 6121 | return x & greater | y & ~greater; |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 6126 | { |
| 6127 | if(CPUID::supportsSSE4_1()) |
| 6128 | { |
| 6129 | return x86::pminud(x, y); |
| 6130 | } |
| 6131 | else |
| 6132 | { |
| 6133 | RValue<UInt4> less = CmpLT(x, y); |
| 6134 | return x & less | y & ~less; |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6139 | { |
| 6140 | return x86::packusdw(x, y); // FIXME: Fallback required |
| 6141 | } |
| 6142 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6143 | Type *UInt4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6144 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 6145 | return T(VectorType::get(UInt::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6146 | } |
| 6147 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6148 | Float::Float(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6149 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6150 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 6151 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6152 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | Float::Float() |
| 6156 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6157 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | Float::Float(float x) |
| 6161 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6162 | storeValue(Nucleus::createConstantFloat(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6163 | } |
| 6164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6165 | Float::Float(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6166 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6167 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | Float::Float(const Float &rhs) |
| 6171 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6172 | Value *value = rhs.loadValue(); |
| 6173 | storeValue(value); |
| 6174 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6175 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6176 | Float::Float(const Reference<Float> &rhs) |
| 6177 | { |
| 6178 | Value *value = rhs.loadValue(); |
| 6179 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6180 | } |
| 6181 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6182 | RValue<Float> Float::operator=(RValue<Float> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6183 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6184 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6185 | |
| 6186 | return rhs; |
| 6187 | } |
| 6188 | |
| 6189 | RValue<Float> Float::operator=(const Float &rhs) const |
| 6190 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6191 | Value *value = rhs.loadValue(); |
| 6192 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6193 | |
| 6194 | return RValue<Float>(value); |
| 6195 | } |
| 6196 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6197 | RValue<Float> Float::operator=(const Reference<Float> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6198 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6199 | Value *value = rhs.loadValue(); |
| 6200 | storeValue(value); |
| 6201 | |
| 6202 | return RValue<Float>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6203 | } |
| 6204 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6205 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6206 | { |
| 6207 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6208 | } |
| 6209 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6210 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6211 | { |
| 6212 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6213 | } |
| 6214 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6215 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6216 | { |
| 6217 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6218 | } |
| 6219 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6220 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6221 | { |
| 6222 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6223 | } |
| 6224 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6225 | RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6226 | { |
| 6227 | return lhs = lhs + rhs; |
| 6228 | } |
| 6229 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6230 | RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6231 | { |
| 6232 | return lhs = lhs - rhs; |
| 6233 | } |
| 6234 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6235 | RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6236 | { |
| 6237 | return lhs = lhs * rhs; |
| 6238 | } |
| 6239 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6240 | RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6241 | { |
| 6242 | return lhs = lhs / rhs; |
| 6243 | } |
| 6244 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6245 | RValue<Float> operator+(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6246 | { |
| 6247 | return val; |
| 6248 | } |
| 6249 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6250 | RValue<Float> operator-(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6251 | { |
| 6252 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 6253 | } |
| 6254 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6255 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6256 | { |
| 6257 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 6258 | } |
| 6259 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6260 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6261 | { |
| 6262 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 6263 | } |
| 6264 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6265 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6266 | { |
| 6267 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 6268 | } |
| 6269 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6270 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6271 | { |
| 6272 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 6273 | } |
| 6274 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6275 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6276 | { |
| 6277 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 6278 | } |
| 6279 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6280 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6281 | { |
| 6282 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 6283 | } |
| 6284 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6285 | RValue<Float> Abs(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6286 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6287 | return IfThenElse(x > 0.0f, x, -x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6288 | } |
| 6289 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6290 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6291 | { |
| 6292 | return IfThenElse(x > y, x, y); |
| 6293 | } |
| 6294 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6295 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6296 | { |
| 6297 | return IfThenElse(x < y, x, y); |
| 6298 | } |
| 6299 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6300 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6301 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6302 | if(exactAtPow2) |
| 6303 | { |
| 6304 | // rcpss uses a piecewise-linear approximation which minimizes the relative error |
| 6305 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 6306 | return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 6307 | } |
| 6308 | else |
| 6309 | { |
| 6310 | return x86::rcpss(x); |
| 6311 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6312 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6313 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6314 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6315 | { |
| 6316 | return x86::rsqrtss(x); |
| 6317 | } |
| 6318 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6319 | RValue<Float> Sqrt(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6320 | { |
| 6321 | return x86::sqrtss(x); |
| 6322 | } |
| 6323 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6324 | RValue<Float> Round(RValue<Float> x) |
| 6325 | { |
| 6326 | if(CPUID::supportsSSE4_1()) |
| 6327 | { |
| 6328 | return x86::roundss(x, 0); |
| 6329 | } |
| 6330 | else |
| 6331 | { |
| 6332 | return Float4(Round(Float4(x))).x; |
| 6333 | } |
| 6334 | } |
| 6335 | |
| 6336 | RValue<Float> Trunc(RValue<Float> x) |
| 6337 | { |
| 6338 | if(CPUID::supportsSSE4_1()) |
| 6339 | { |
| 6340 | return x86::roundss(x, 3); |
| 6341 | } |
| 6342 | else |
| 6343 | { |
| 6344 | return Float(Int(x)); // Rounded toward zero |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | RValue<Float> Frac(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6349 | { |
| 6350 | if(CPUID::supportsSSE4_1()) |
| 6351 | { |
| 6352 | return x - x86::floorss(x); |
| 6353 | } |
| 6354 | else |
| 6355 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6356 | return Float4(Frac(Float4(x))).x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6360 | RValue<Float> Floor(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6361 | { |
| 6362 | if(CPUID::supportsSSE4_1()) |
| 6363 | { |
| 6364 | return x86::floorss(x); |
| 6365 | } |
| 6366 | else |
| 6367 | { |
| 6368 | return Float4(Floor(Float4(x))).x; |
| 6369 | } |
| 6370 | } |
| 6371 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6372 | RValue<Float> Ceil(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6373 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6374 | if(CPUID::supportsSSE4_1()) |
| 6375 | { |
| 6376 | return x86::ceilss(x); |
| 6377 | } |
| 6378 | else |
| 6379 | { |
| 6380 | return Float4(Ceil(Float4(x))).x; |
| 6381 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6382 | } |
| 6383 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6384 | Type *Float::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6385 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 6386 | return T(llvm::Type::getFloatTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6387 | } |
| 6388 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6389 | Float2::Float2(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6390 | { |
| 6391 | // xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6392 | |
| 6393 | Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType()); |
| 6394 | Value *int64 = Nucleus::createExtractElement(int64x2, 0); |
| 6395 | Value *float2 = Nucleus::createBitCast(int64, Float2::getType()); |
| 6396 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6397 | storeValue(float2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6398 | } |
| 6399 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6400 | Type *Float2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6401 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 6402 | return T(VectorType::get(Float::getType(), 2)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6403 | } |
| 6404 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6405 | Float4::Float4(RValue<Byte4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6406 | { |
| 6407 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6408 | |
| 6409 | #if 0 |
| 6410 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes |
| 6411 | #elif 0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6412 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6413 | |
| 6414 | Value *i8x = Nucleus::createExtractElement(cast.value, 0); |
| 6415 | Value *f32x = Nucleus::createUIToFP(i8x, Float::getType()); |
| 6416 | Value *x = Nucleus::createInsertElement(vector, f32x, 0); |
| 6417 | |
| 6418 | Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1)); |
| 6419 | Value *f32y = Nucleus::createUIToFP(i8y, Float::getType()); |
| 6420 | Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1)); |
| 6421 | |
| 6422 | Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2)); |
| 6423 | Value *f32z = Nucleus::createUIToFP(i8z, Float::getType()); |
| 6424 | Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2)); |
| 6425 | |
| 6426 | Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3)); |
| 6427 | Value *f32w = Nucleus::createUIToFP(i8w, Float::getType()); |
| 6428 | Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3)); |
| 6429 | #else |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 6430 | Value *a = Int4(cast).loadValue(); |
| 6431 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6432 | #endif |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6433 | |
| 6434 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6435 | } |
| 6436 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6437 | Float4::Float4(RValue<SByte4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6438 | { |
| 6439 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6440 | |
| 6441 | #if 0 |
| 6442 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes |
| 6443 | #elif 0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6444 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6445 | |
| 6446 | Value *i8x = Nucleus::createExtractElement(cast.value, 0); |
| 6447 | Value *f32x = Nucleus::createSIToFP(i8x, Float::getType()); |
| 6448 | Value *x = Nucleus::createInsertElement(vector, f32x, 0); |
| 6449 | |
| 6450 | Value *i8y = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(1)); |
| 6451 | Value *f32y = Nucleus::createSIToFP(i8y, Float::getType()); |
| 6452 | Value *xy = Nucleus::createInsertElement(x, f32y, Nucleus::createConstantInt(1)); |
| 6453 | |
| 6454 | Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2)); |
| 6455 | Value *f32z = Nucleus::createSIToFP(i8z, Float::getType()); |
| 6456 | Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2)); |
| 6457 | |
| 6458 | Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3)); |
| 6459 | Value *f32w = Nucleus::createSIToFP(i8w, Float::getType()); |
| 6460 | Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3)); |
| 6461 | #else |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 6462 | Value *a = Int4(cast).loadValue(); |
| 6463 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6464 | #endif |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6465 | |
| 6466 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6467 | } |
| 6468 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6469 | Float4::Float4(RValue<Short4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6470 | { |
| 6471 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6472 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 6473 | Int4 c(cast); |
| 6474 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6475 | } |
| 6476 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6477 | Float4::Float4(RValue<UShort4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6478 | { |
| 6479 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6480 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 6481 | Int4 c(cast); |
| 6482 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6483 | } |
| 6484 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6485 | Float4::Float4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6486 | { |
| 6487 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6488 | |
| 6489 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6490 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6491 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6492 | } |
| 6493 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6494 | Float4::Float4(RValue<UInt4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6495 | { |
| 6496 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6497 | |
| 6498 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); |
| 6499 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6500 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | Float4::Float4() |
| 6504 | { |
| 6505 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6506 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6507 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6508 | Float4::Float4(float xyzw) |
| 6509 | { |
| 6510 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6511 | } |
| 6512 | |
| 6513 | Float4::Float4(float x, float yzw) |
| 6514 | { |
| 6515 | constant(x, yzw, yzw, yzw); |
| 6516 | } |
| 6517 | |
| 6518 | Float4::Float4(float x, float y, float zw) |
| 6519 | { |
| 6520 | constant(x, y, zw, zw); |
| 6521 | } |
| 6522 | |
| 6523 | Float4::Float4(float x, float y, float z, float w) |
| 6524 | { |
| 6525 | constant(x, y, z, w); |
| 6526 | } |
| 6527 | |
| 6528 | void Float4::constant(float x, float y, float z, float w) |
| 6529 | { |
| 6530 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6531 | |
| 6532 | Constant *constantVector[4]; |
| 6533 | constantVector[0] = Nucleus::createConstantFloat(x); |
| 6534 | constantVector[1] = Nucleus::createConstantFloat(y); |
| 6535 | constantVector[2] = Nucleus::createConstantFloat(z); |
| 6536 | constantVector[3] = Nucleus::createConstantFloat(w); |
| 6537 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6538 | storeValue(Nucleus::createConstantVector(constantVector, 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6539 | } |
| 6540 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6541 | Float4::Float4(RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6542 | { |
| 6543 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6544 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6545 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | Float4::Float4(const Float4 &rhs) |
| 6549 | { |
| 6550 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6551 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6552 | Value *value = rhs.loadValue(); |
| 6553 | storeValue(value); |
| 6554 | } |
| 6555 | |
| 6556 | Float4::Float4(const Reference<Float4> &rhs) |
| 6557 | { |
| 6558 | xyzw.parent = this; |
| 6559 | |
| 6560 | Value *value = rhs.loadValue(); |
| 6561 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6562 | } |
| 6563 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6564 | Float4::Float4(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6565 | { |
| 6566 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6567 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6568 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6569 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 6570 | |
| 6571 | Constant *swizzle[4]; |
| 6572 | swizzle[0] = Nucleus::createConstantInt(0); |
| 6573 | swizzle[1] = Nucleus::createConstantInt(0); |
| 6574 | swizzle[2] = Nucleus::createConstantInt(0); |
| 6575 | swizzle[3] = Nucleus::createConstantInt(0); |
| 6576 | |
| 6577 | Value *replicate = Nucleus::createShuffleVector(insert, UndefValue::get(Float4::getType()), Nucleus::createConstantVector(swizzle, 4)); |
| 6578 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6579 | storeValue(replicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6580 | } |
| 6581 | |
| 6582 | Float4::Float4(const Float &rhs) |
| 6583 | { |
| 6584 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6585 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6586 | *this = RValue<Float>(rhs.loadValue()); |
| 6587 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6588 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6589 | Float4::Float4(const Reference<Float> &rhs) |
| 6590 | { |
| 6591 | xyzw.parent = this; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6592 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6593 | *this = RValue<Float>(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | RValue<Float4> Float4::operator=(float x) const |
| 6597 | { |
| 6598 | return *this = Float4(x, x, x, x); |
| 6599 | } |
| 6600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6601 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6602 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6603 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6604 | |
| 6605 | return rhs; |
| 6606 | } |
| 6607 | |
| 6608 | RValue<Float4> Float4::operator=(const Float4 &rhs) const |
| 6609 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6610 | Value *value = rhs.loadValue(); |
| 6611 | storeValue(value); |
| 6612 | |
| 6613 | return RValue<Float4>(value); |
| 6614 | } |
| 6615 | |
| 6616 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const |
| 6617 | { |
| 6618 | Value *value = rhs.loadValue(); |
| 6619 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6620 | |
| 6621 | return RValue<Float4>(value); |
| 6622 | } |
| 6623 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6624 | RValue<Float4> Float4::operator=(RValue<Float> rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6625 | { |
| 6626 | return *this = Float4(rhs); |
| 6627 | } |
| 6628 | |
| 6629 | RValue<Float4> Float4::operator=(const Float &rhs) const |
| 6630 | { |
| 6631 | return *this = Float4(rhs); |
| 6632 | } |
| 6633 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6634 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6635 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6636 | return *this = Float4(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6637 | } |
| 6638 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6639 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6640 | { |
| 6641 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6642 | } |
| 6643 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6644 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6645 | { |
| 6646 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6647 | } |
| 6648 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6649 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6650 | { |
| 6651 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6652 | } |
| 6653 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6654 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6655 | { |
| 6656 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6657 | } |
| 6658 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6659 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6660 | { |
| 6661 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6662 | } |
| 6663 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6664 | RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6665 | { |
| 6666 | return lhs = lhs + rhs; |
| 6667 | } |
| 6668 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6669 | RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6670 | { |
| 6671 | return lhs = lhs - rhs; |
| 6672 | } |
| 6673 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6674 | RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6675 | { |
| 6676 | return lhs = lhs * rhs; |
| 6677 | } |
| 6678 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6679 | RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6680 | { |
| 6681 | return lhs = lhs / rhs; |
| 6682 | } |
| 6683 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6684 | RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6685 | { |
| 6686 | return lhs = lhs % rhs; |
| 6687 | } |
| 6688 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6689 | RValue<Float4> operator+(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6690 | { |
| 6691 | return val; |
| 6692 | } |
| 6693 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6694 | RValue<Float4> operator-(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6695 | { |
| 6696 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6697 | } |
| 6698 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6699 | RValue<Float4> Abs(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6700 | { |
| 6701 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6702 | |
| 6703 | Constant *constantVector[4]; |
| 6704 | constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6705 | constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6706 | constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6707 | constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF); |
| 6708 | |
| 6709 | Value *result = Nucleus::createAnd(vector, Nucleus::createConstantVector(constantVector, 4)); |
| 6710 | |
| 6711 | return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType())); |
| 6712 | } |
| 6713 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6714 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6715 | { |
| 6716 | return x86::maxps(x, y); |
| 6717 | } |
| 6718 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6719 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6720 | { |
| 6721 | return x86::minps(x, y); |
| 6722 | } |
| 6723 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6724 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6725 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6726 | if(exactAtPow2) |
| 6727 | { |
| 6728 | // rcpps uses a piecewise-linear approximation which minimizes the relative error |
| 6729 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 6730 | return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 6731 | } |
| 6732 | else |
| 6733 | { |
| 6734 | return x86::rcpps(x); |
| 6735 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6736 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6737 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6738 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6739 | { |
| 6740 | return x86::rsqrtps(x); |
| 6741 | } |
| 6742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6743 | RValue<Float4> Sqrt(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6744 | { |
| 6745 | return x86::sqrtps(x); |
| 6746 | } |
| 6747 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6748 | RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6749 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6750 | llvm::Value *value = val.loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6751 | llvm::Value *insert = Nucleus::createInsertElement(value, element.value, i); |
| 6752 | |
| 6753 | val = RValue<Float4>(insert); |
| 6754 | |
| 6755 | return val; |
| 6756 | } |
| 6757 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6758 | RValue<Float> Extract(RValue<Float4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6759 | { |
| 6760 | return RValue<Float>(Nucleus::createExtractElement(x.value, i)); |
| 6761 | } |
| 6762 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6763 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6764 | { |
| 6765 | return RValue<Float4>(Nucleus::createSwizzle(x.value, select)); |
| 6766 | } |
| 6767 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6768 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6769 | { |
| 6770 | Constant *shuffle[4]; |
| 6771 | shuffle[0] = Nucleus::createConstantInt(((imm >> 0) & 0x03) + 0); |
| 6772 | shuffle[1] = Nucleus::createConstantInt(((imm >> 2) & 0x03) + 0); |
| 6773 | shuffle[2] = Nucleus::createConstantInt(((imm >> 4) & 0x03) + 4); |
| 6774 | shuffle[3] = Nucleus::createConstantInt(((imm >> 6) & 0x03) + 4); |
| 6775 | |
| 6776 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4))); |
| 6777 | } |
| 6778 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6779 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6780 | { |
| 6781 | Constant *shuffle[4]; |
| 6782 | shuffle[0] = Nucleus::createConstantInt(0); |
| 6783 | shuffle[1] = Nucleus::createConstantInt(4); |
| 6784 | shuffle[2] = Nucleus::createConstantInt(1); |
| 6785 | shuffle[3] = Nucleus::createConstantInt(5); |
| 6786 | |
| 6787 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4))); |
| 6788 | } |
| 6789 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6790 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6791 | { |
| 6792 | Constant *shuffle[4]; |
| 6793 | shuffle[0] = Nucleus::createConstantInt(2); |
| 6794 | shuffle[1] = Nucleus::createConstantInt(6); |
| 6795 | shuffle[2] = Nucleus::createConstantInt(3); |
| 6796 | shuffle[3] = Nucleus::createConstantInt(7); |
| 6797 | |
| 6798 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, Nucleus::createConstantVector(shuffle, 4))); |
| 6799 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6800 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6801 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6802 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6803 | Value *vector = lhs.loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6804 | Value *shuffle = Nucleus::createMask(vector, rhs.value, select); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6805 | lhs.storeValue(shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6806 | |
| 6807 | return RValue<Float4>(shuffle); |
| 6808 | } |
| 6809 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6810 | RValue<Int> SignMask(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6811 | { |
| 6812 | return x86::movmskps(x); |
| 6813 | } |
| 6814 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6815 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6816 | { |
| 6817 | // return As<Int4>(x86::cmpeqps(x, y)); |
| 6818 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6819 | } |
| 6820 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6821 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6822 | { |
| 6823 | // return As<Int4>(x86::cmpltps(x, y)); |
| 6824 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6825 | } |
| 6826 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6827 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6828 | { |
| 6829 | // return As<Int4>(x86::cmpleps(x, y)); |
| 6830 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6831 | } |
| 6832 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6833 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6834 | { |
| 6835 | // return As<Int4>(x86::cmpneqps(x, y)); |
| 6836 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6837 | } |
| 6838 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6839 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6840 | { |
| 6841 | // return As<Int4>(x86::cmpnltps(x, y)); |
| 6842 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6843 | } |
| 6844 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6845 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6846 | { |
| 6847 | // return As<Int4>(x86::cmpnleps(x, y)); |
| 6848 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6849 | } |
| 6850 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6851 | RValue<Float4> Round(RValue<Float4> x) |
| 6852 | { |
| 6853 | if(CPUID::supportsSSE4_1()) |
| 6854 | { |
| 6855 | return x86::roundps(x, 0); |
| 6856 | } |
| 6857 | else |
| 6858 | { |
| 6859 | return Float4(RoundInt(x)); |
| 6860 | } |
| 6861 | } |
| 6862 | |
| 6863 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6864 | { |
| 6865 | if(CPUID::supportsSSE4_1()) |
| 6866 | { |
| 6867 | return x86::roundps(x, 3); |
| 6868 | } |
| 6869 | else |
| 6870 | { |
| 6871 | return Float4(Int4(x)); // Rounded toward zero |
| 6872 | } |
| 6873 | } |
| 6874 | |
| 6875 | RValue<Float4> Frac(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6876 | { |
| 6877 | if(CPUID::supportsSSE4_1()) |
| 6878 | { |
| 6879 | return x - x86::floorps(x); |
| 6880 | } |
| 6881 | else |
| 6882 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6883 | Float4 frc = x - Float4(Int4(x)); // Signed fractional part |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6884 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6885 | 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] | 6886 | } |
| 6887 | } |
| 6888 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6889 | RValue<Float4> Floor(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6890 | { |
| 6891 | if(CPUID::supportsSSE4_1()) |
| 6892 | { |
| 6893 | return x86::floorps(x); |
| 6894 | } |
| 6895 | else |
| 6896 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6897 | return x - Frac(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6898 | } |
| 6899 | } |
| 6900 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6901 | RValue<Float4> Ceil(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6902 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6903 | if(CPUID::supportsSSE4_1()) |
| 6904 | { |
| 6905 | return x86::ceilps(x); |
| 6906 | } |
| 6907 | else |
| 6908 | { |
| 6909 | return -Floor(-x); |
| 6910 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6911 | } |
| 6912 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6913 | Type *Float4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6914 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame^] | 6915 | return T(VectorType::get(Float::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6916 | } |
| 6917 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6918 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6919 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6920 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6921 | } |
| 6922 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6923 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6924 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6925 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6926 | } |
| 6927 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6928 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6929 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6930 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6931 | } |
| 6932 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6933 | RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6934 | { |
| 6935 | return lhs = lhs + offset; |
| 6936 | } |
| 6937 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6938 | RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6939 | { |
| 6940 | return lhs = lhs + offset; |
| 6941 | } |
| 6942 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6943 | RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6944 | { |
| 6945 | return lhs = lhs + offset; |
| 6946 | } |
| 6947 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6948 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6949 | { |
| 6950 | return lhs + -offset; |
| 6951 | } |
| 6952 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6953 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6954 | { |
| 6955 | return lhs + -offset; |
| 6956 | } |
| 6957 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6958 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6959 | { |
| 6960 | return lhs + -offset; |
| 6961 | } |
| 6962 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6963 | RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6964 | { |
| 6965 | return lhs = lhs - offset; |
| 6966 | } |
| 6967 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6968 | RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6969 | { |
| 6970 | return lhs = lhs - offset; |
| 6971 | } |
| 6972 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6973 | RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6974 | { |
| 6975 | return lhs = lhs - offset; |
| 6976 | } |
| 6977 | |
| 6978 | void Return() |
| 6979 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6980 | Nucleus::createRetVoid(); |
| 6981 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6982 | Nucleus::createUnreachable(); |
| 6983 | } |
| 6984 | |
| 6985 | void Return(bool ret) |
| 6986 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6987 | Nucleus::createRet(Nucleus::createConstantBool(ret)); |
| 6988 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6989 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | void Return(const Int &ret) |
| 6993 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6994 | Nucleus::createRet(ret.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6995 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6996 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6997 | } |
| 6998 | |
| 6999 | BasicBlock *beginLoop() |
| 7000 | { |
| 7001 | BasicBlock *loopBB = Nucleus::createBasicBlock(); |
| 7002 | |
| 7003 | Nucleus::createBr(loopBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7004 | Nucleus::setInsertBlock(loopBB); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7005 | |
| 7006 | return loopBB; |
| 7007 | } |
| 7008 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7009 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7010 | { |
| 7011 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7012 | Nucleus::setInsertBlock(bodyBB); |
| 7013 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7014 | return true; |
| 7015 | } |
| 7016 | |
| 7017 | bool elseBlock(BasicBlock *falseBB) |
| 7018 | { |
| 7019 | falseBB->back().eraseFromParent(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7020 | Nucleus::setInsertBlock(falseBB); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7021 | |
| 7022 | return true; |
| 7023 | } |
| 7024 | |
| 7025 | RValue<Long> Ticks() |
| 7026 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7027 | llvm::Function *rdtsc = Intrinsic::getDeclaration(::module, Intrinsic::readcyclecounter); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7028 | |
| 7029 | return RValue<Long>(Nucleus::createCall(rdtsc)); |
| 7030 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | namespace sw |
| 7034 | { |
| 7035 | namespace x86 |
| 7036 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7037 | RValue<Int> cvtss2si(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7038 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7039 | llvm::Function *cvtss2si = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cvtss2si); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7040 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7041 | Float4 vector; |
| 7042 | vector.x = val; |
| 7043 | |
| 7044 | return RValue<Int>(Nucleus::createCall(cvtss2si, RValue<Float4>(vector).value)); |
| 7045 | } |
| 7046 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7047 | RValue<Int2> cvtps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7048 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7049 | llvm::Function *cvtps2pi = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cvtps2pi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7050 | |
| 7051 | return RValue<Int2>(Nucleus::createCall(cvtps2pi, val.value)); |
| 7052 | } |
| 7053 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7054 | RValue<Int2> cvttps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7055 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7056 | llvm::Function *cvttps2pi = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cvttps2pi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7057 | |
| 7058 | return RValue<Int2>(Nucleus::createCall(cvttps2pi, val.value)); |
| 7059 | } |
| 7060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7061 | RValue<Int4> cvtps2dq(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7062 | { |
| 7063 | if(CPUID::supportsSSE2()) |
| 7064 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7065 | llvm::Function *cvtps2dq = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_cvtps2dq); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7066 | |
| 7067 | return RValue<Int4>(Nucleus::createCall(cvtps2dq, val.value)); |
| 7068 | } |
| 7069 | else |
| 7070 | { |
| 7071 | Int2 lo = x86::cvtps2pi(val); |
| 7072 | Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7073 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7074 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7075 | } |
| 7076 | } |
| 7077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7078 | RValue<Float> rcpss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7079 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7080 | llvm::Function *rcpss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rcp_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7081 | |
| 7082 | Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7083 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7084 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rcpss, vector), 0)); |
| 7085 | } |
| 7086 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7087 | RValue<Float> sqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7088 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7089 | llvm::Function *sqrtss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_sqrt_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7090 | |
| 7091 | Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7092 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7093 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(sqrtss, vector), 0)); |
| 7094 | } |
| 7095 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7096 | RValue<Float> rsqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7097 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7098 | llvm::Function *rsqrtss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rsqrt_ss); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7099 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7100 | Value *vector = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), val.value, 0); |
| 7101 | |
| 7102 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(rsqrtss, vector), 0)); |
| 7103 | } |
| 7104 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7105 | RValue<Float4> rcpps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7106 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7107 | llvm::Function *rcpps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rcp_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7108 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7109 | return RValue<Float4>(Nucleus::createCall(rcpps, val.value)); |
| 7110 | } |
| 7111 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7112 | RValue<Float4> sqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7113 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7114 | llvm::Function *sqrtps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_sqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7115 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7116 | return RValue<Float4>(Nucleus::createCall(sqrtps, val.value)); |
| 7117 | } |
| 7118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7119 | RValue<Float4> rsqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7120 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7121 | llvm::Function *rsqrtps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rsqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7122 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7123 | return RValue<Float4>(Nucleus::createCall(rsqrtps, val.value)); |
| 7124 | } |
| 7125 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7126 | RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7127 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7128 | llvm::Function *maxps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_max_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7129 | |
| 7130 | return RValue<Float4>(Nucleus::createCall(maxps, x.value, y.value)); |
| 7131 | } |
| 7132 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7133 | RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7134 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7135 | llvm::Function *minps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_min_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7136 | |
| 7137 | return RValue<Float4>(Nucleus::createCall(minps, x.value, y.value)); |
| 7138 | } |
| 7139 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7140 | RValue<Float> roundss(RValue<Float> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7141 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7142 | llvm::Function *roundss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_round_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7143 | |
| 7144 | Value *undef = UndefValue::get(Float4::getType()); |
| 7145 | Value *vector = Nucleus::createInsertElement(undef, val.value, 0); |
| 7146 | |
| 7147 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(roundss, undef, vector, Nucleus::createConstantInt(imm)), 0)); |
| 7148 | } |
| 7149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7150 | RValue<Float> floorss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7151 | { |
| 7152 | return roundss(val, 1); |
| 7153 | } |
| 7154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7155 | RValue<Float> ceilss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7156 | { |
| 7157 | return roundss(val, 2); |
| 7158 | } |
| 7159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7160 | RValue<Float4> roundps(RValue<Float4> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7161 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7162 | llvm::Function *roundps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_round_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7163 | |
| 7164 | return RValue<Float4>(Nucleus::createCall(roundps, val.value, Nucleus::createConstantInt(imm))); |
| 7165 | } |
| 7166 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7167 | RValue<Float4> floorps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7168 | { |
| 7169 | return roundps(val, 1); |
| 7170 | } |
| 7171 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7172 | RValue<Float4> ceilps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7173 | { |
| 7174 | return roundps(val, 2); |
| 7175 | } |
| 7176 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7177 | RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7178 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7179 | llvm::Function *cmpps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cmp_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7180 | |
| 7181 | return RValue<Float4>(Nucleus::createCall(cmpps, x.value, y.value, Nucleus::createConstantByte(imm))); |
| 7182 | } |
| 7183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7184 | RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7185 | { |
| 7186 | return cmpps(x, y, 0); |
| 7187 | } |
| 7188 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7189 | RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7190 | { |
| 7191 | return cmpps(x, y, 1); |
| 7192 | } |
| 7193 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7194 | RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7195 | { |
| 7196 | return cmpps(x, y, 2); |
| 7197 | } |
| 7198 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7199 | RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7200 | { |
| 7201 | return cmpps(x, y, 3); |
| 7202 | } |
| 7203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7204 | RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7205 | { |
| 7206 | return cmpps(x, y, 4); |
| 7207 | } |
| 7208 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7209 | RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7210 | { |
| 7211 | return cmpps(x, y, 5); |
| 7212 | } |
| 7213 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7214 | RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7215 | { |
| 7216 | return cmpps(x, y, 6); |
| 7217 | } |
| 7218 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7219 | RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7220 | { |
| 7221 | return cmpps(x, y, 7); |
| 7222 | } |
| 7223 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7224 | RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7225 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7226 | llvm::Function *cmpss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cmp_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7227 | |
| 7228 | Value *vector1 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), x.value, 0); |
| 7229 | Value *vector2 = Nucleus::createInsertElement(UndefValue::get(Float4::getType()), y.value, 0); |
| 7230 | |
| 7231 | return RValue<Float>(Nucleus::createExtractElement(Nucleus::createCall(cmpss, vector1, vector2, Nucleus::createConstantByte(imm)), 0)); |
| 7232 | } |
| 7233 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7234 | RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7235 | { |
| 7236 | return cmpss(x, y, 0); |
| 7237 | } |
| 7238 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7239 | RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7240 | { |
| 7241 | return cmpss(x, y, 1); |
| 7242 | } |
| 7243 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7244 | RValue<Float> cmpless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7245 | { |
| 7246 | return cmpss(x, y, 2); |
| 7247 | } |
| 7248 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7249 | RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7250 | { |
| 7251 | return cmpss(x, y, 3); |
| 7252 | } |
| 7253 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7254 | RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7255 | { |
| 7256 | return cmpss(x, y, 4); |
| 7257 | } |
| 7258 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7259 | RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7260 | { |
| 7261 | return cmpss(x, y, 5); |
| 7262 | } |
| 7263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7264 | RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7265 | { |
| 7266 | return cmpss(x, y, 6); |
| 7267 | } |
| 7268 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7269 | RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7270 | { |
| 7271 | return cmpss(x, y, 7); |
| 7272 | } |
| 7273 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 7274 | RValue<Int4> pabsd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7275 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7276 | llvm::Function *pabsd = Intrinsic::getDeclaration(::module, Intrinsic::x86_ssse3_pabs_d_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7277 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 7278 | return RValue<Int4>(Nucleus::createCall(pabsd, x.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7279 | } |
| 7280 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7281 | RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7282 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7283 | llvm::Function *paddsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padds_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7284 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7285 | 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] | 7286 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7287 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7288 | RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7289 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7290 | llvm::Function *psubsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7291 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7292 | 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] | 7293 | } |
| 7294 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7295 | RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7296 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7297 | llvm::Function *paddusw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_paddus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7298 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7299 | 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] | 7300 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7301 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7302 | RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7303 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7304 | llvm::Function *psubusw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7305 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7306 | 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] | 7307 | } |
| 7308 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7309 | RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7310 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7311 | llvm::Function *paddsb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padds_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7312 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7313 | 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] | 7314 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7315 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7316 | RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7317 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7318 | llvm::Function *psubsb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubs_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7319 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7320 | 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] | 7321 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7322 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7323 | RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7324 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7325 | llvm::Function *paddusb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_paddus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7326 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7327 | 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] | 7328 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7329 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7330 | RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7331 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7332 | llvm::Function *psubusb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7333 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7334 | 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] | 7335 | } |
| 7336 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7337 | RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y) |
| 7338 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7339 | llvm::Function *paddw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padd_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7340 | |
| 7341 | return As<Short4>(RValue<MMX>(Nucleus::createCall(paddw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7342 | } |
| 7343 | |
| 7344 | RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y) |
| 7345 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7346 | llvm::Function *psubw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psub_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7347 | |
| 7348 | return As<Short4>(RValue<MMX>(Nucleus::createCall(psubw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7349 | } |
| 7350 | |
| 7351 | RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y) |
| 7352 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7353 | llvm::Function *pmullw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmull_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7354 | |
| 7355 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pmullw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7356 | } |
| 7357 | |
| 7358 | RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y) |
| 7359 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7360 | llvm::Function *pand = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pand); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7361 | |
| 7362 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pand, As<MMX>(x).value, As<MMX>(y).value))); |
| 7363 | } |
| 7364 | |
| 7365 | RValue<Short4> por(RValue<Short4> x, RValue<Short4> y) |
| 7366 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7367 | llvm::Function *por = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_por); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7368 | |
| 7369 | return As<Short4>(RValue<MMX>(Nucleus::createCall(por, As<MMX>(x).value, As<MMX>(y).value))); |
| 7370 | } |
| 7371 | |
| 7372 | RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y) |
| 7373 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7374 | llvm::Function *pxor = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pxor); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7375 | |
| 7376 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pxor, As<MMX>(x).value, As<MMX>(y).value))); |
| 7377 | } |
| 7378 | |
| 7379 | RValue<Short4> pshufw(RValue<Short4> x, unsigned char y) |
| 7380 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7381 | llvm::Function *pshufw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_pshuf_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7382 | |
| 7383 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pshufw, As<MMX>(x).value, Nucleus::createConstantByte(y)))); |
| 7384 | } |
| 7385 | |
| 7386 | RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y) |
| 7387 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7388 | llvm::Function *punpcklwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpcklwd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7389 | |
| 7390 | return As<Int2>(RValue<MMX>(Nucleus::createCall(punpcklwd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7391 | } |
| 7392 | |
| 7393 | RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y) |
| 7394 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7395 | llvm::Function *punpckhwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckhwd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7396 | |
| 7397 | return As<Int2>(RValue<MMX>(Nucleus::createCall(punpckhwd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7398 | } |
| 7399 | |
| 7400 | RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i) |
| 7401 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7402 | llvm::Function *pinsrw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pinsr_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7403 | |
| 7404 | return As<Short4>(RValue<MMX>(Nucleus::createCall(pinsrw, As<MMX>(x).value, y.value, Nucleus::createConstantInt(i)))); |
| 7405 | } |
| 7406 | |
| 7407 | RValue<Int> pextrw(RValue<Short4> x, unsigned int i) |
| 7408 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7409 | llvm::Function *pextrw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pextr_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7410 | |
| 7411 | return RValue<Int>(Nucleus::createCall(pextrw, As<MMX>(x).value, Nucleus::createConstantInt(i))); |
| 7412 | } |
| 7413 | |
| 7414 | RValue<Long1> punpckldq(RValue<Int2> x, RValue<Int2> y) |
| 7415 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7416 | llvm::Function *punpckldq = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckldq); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7417 | |
| 7418 | return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckldq, As<MMX>(x).value, As<MMX>(y).value))); |
| 7419 | } |
| 7420 | |
| 7421 | RValue<Long1> punpckhdq(RValue<Int2> x, RValue<Int2> y) |
| 7422 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7423 | llvm::Function *punpckhdq = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckhdq); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7424 | |
| 7425 | return As<Long1>(RValue<MMX>(Nucleus::createCall(punpckhdq, As<MMX>(x).value, As<MMX>(y).value))); |
| 7426 | } |
| 7427 | |
| 7428 | RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y) |
| 7429 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7430 | llvm::Function *punpcklbw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpcklbw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7431 | |
| 7432 | return As<Short4>(RValue<MMX>(Nucleus::createCall(punpcklbw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7433 | } |
| 7434 | |
| 7435 | RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y) |
| 7436 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7437 | llvm::Function *punpckhbw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckhbw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7438 | |
| 7439 | return As<Short4>(RValue<MMX>(Nucleus::createCall(punpckhbw, As<MMX>(x).value, As<MMX>(y).value))); |
| 7440 | } |
| 7441 | |
| 7442 | RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y) |
| 7443 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7444 | llvm::Function *paddb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padd_b); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7445 | |
| 7446 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(paddb, As<MMX>(x).value, As<MMX>(y).value))); |
| 7447 | } |
| 7448 | |
| 7449 | RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y) |
| 7450 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7451 | llvm::Function *psubb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psub_b); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7452 | |
| 7453 | return As<Byte8>(RValue<MMX>(Nucleus::createCall(psubb, As<MMX>(x).value, As<MMX>(y).value))); |
| 7454 | } |
| 7455 | |
| 7456 | RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y) |
| 7457 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7458 | llvm::Function *paddd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padd_d); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7459 | |
| 7460 | return As<Int2>(RValue<MMX>(Nucleus::createCall(paddd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7461 | } |
| 7462 | |
| 7463 | RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y) |
| 7464 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7465 | llvm::Function *psubd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psub_d); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7466 | |
| 7467 | return As<Int2>(RValue<MMX>(Nucleus::createCall(psubd, As<MMX>(x).value, As<MMX>(y).value))); |
| 7468 | } |
| 7469 | |
| 7470 | RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7471 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7472 | llvm::Function *pavgw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pavg_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7473 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7474 | 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] | 7475 | } |
| 7476 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7477 | RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7478 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7479 | llvm::Function *pmaxsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmaxs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7480 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7481 | 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] | 7482 | } |
| 7483 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7484 | RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7485 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7486 | llvm::Function *pminsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmins_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7487 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7488 | 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] | 7489 | } |
| 7490 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7491 | RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7492 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7493 | llvm::Function *pcmpgtw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpgt_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7495 | 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] | 7496 | } |
| 7497 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7498 | RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7499 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7500 | llvm::Function *pcmpeqw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpeq_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7501 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7502 | 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] | 7503 | } |
| 7504 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7505 | RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7506 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7507 | llvm::Function *pcmpgtb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpgt_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7508 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7509 | 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] | 7510 | } |
| 7511 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7512 | RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7513 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7514 | llvm::Function *pcmpeqb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpeq_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7515 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7516 | 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] | 7517 | } |
| 7518 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7519 | RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7520 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7521 | llvm::Function *packssdw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_packssdw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7522 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7523 | 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] | 7524 | } |
| 7525 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7526 | RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7527 | { |
| 7528 | if(CPUID::supportsSSE2()) |
| 7529 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7530 | llvm::Function *packssdw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_packssdw_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7531 | |
| 7532 | return RValue<Short8>(Nucleus::createCall(packssdw, x.value, y.value)); |
| 7533 | } |
| 7534 | else |
| 7535 | { |
| 7536 | Int2 loX = Int2(x); |
| 7537 | Int2 hiX = Int2(Swizzle(x, 0xEE)); |
| 7538 | |
| 7539 | Int2 loY = Int2(y); |
| 7540 | Int2 hiY = Int2(Swizzle(y, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7541 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7542 | Short4 lo = x86::packssdw(loX, hiX); |
| 7543 | Short4 hi = x86::packssdw(loY, hiY); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7544 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7545 | return Short8(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7546 | } |
| 7547 | } |
| 7548 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7549 | RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7550 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7551 | llvm::Function *packsswb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_packsswb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7552 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7553 | 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] | 7554 | } |
| 7555 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7556 | RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7557 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7558 | llvm::Function *packuswb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_packuswb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7559 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7560 | 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] | 7561 | } |
| 7562 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7563 | RValue<UShort8> packusdw(RValue<UInt4> x, RValue<UInt4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7564 | { |
| 7565 | if(CPUID::supportsSSE4_1()) |
| 7566 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7567 | llvm::Function *packusdw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_packusdw); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7568 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7569 | return RValue<UShort8>(Nucleus::createCall(packusdw, x.value, y.value)); |
| 7570 | } |
| 7571 | else |
| 7572 | { |
| 7573 | // FIXME: Not an exact replacement! |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7574 | 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] | 7575 | } |
| 7576 | } |
| 7577 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7578 | RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7579 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7580 | llvm::Function *psrlw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7581 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7582 | 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] | 7583 | } |
| 7584 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7585 | RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7586 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7587 | llvm::Function *psrlw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7588 | |
| 7589 | return RValue<UShort8>(Nucleus::createCall(psrlw, x.value, Nucleus::createConstantInt(y))); |
| 7590 | } |
| 7591 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7592 | RValue<Short4> psraw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7593 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7594 | llvm::Function *psraw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrai_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7595 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7596 | 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] | 7597 | } |
| 7598 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7599 | RValue<Short8> psraw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7600 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7601 | llvm::Function *psraw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrai_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7602 | |
| 7603 | return RValue<Short8>(Nucleus::createCall(psraw, x.value, Nucleus::createConstantInt(y))); |
| 7604 | } |
| 7605 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7606 | RValue<Short4> psllw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7607 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7608 | llvm::Function *psllw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pslli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7609 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7610 | 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] | 7611 | } |
| 7612 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7613 | RValue<Short8> psllw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7614 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7615 | llvm::Function *psllw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pslli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7616 | |
| 7617 | return RValue<Short8>(Nucleus::createCall(psllw, x.value, Nucleus::createConstantInt(y))); |
| 7618 | } |
| 7619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7620 | RValue<Int2> pslld(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7621 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7622 | llvm::Function *pslld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pslli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7623 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7624 | 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] | 7625 | } |
| 7626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7627 | RValue<Int4> pslld(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7628 | { |
| 7629 | if(CPUID::supportsSSE2()) |
| 7630 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7631 | llvm::Function *pslld = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pslli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7632 | |
| 7633 | return RValue<Int4>(Nucleus::createCall(pslld, x.value, Nucleus::createConstantInt(y))); |
| 7634 | } |
| 7635 | else |
| 7636 | { |
| 7637 | Int2 lo = Int2(x); |
| 7638 | Int2 hi = Int2(Swizzle(x, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7639 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7640 | lo = x86::pslld(lo, y); |
| 7641 | hi = x86::pslld(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7642 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7643 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7644 | } |
| 7645 | } |
| 7646 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7647 | RValue<Int2> psrad(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7648 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7649 | llvm::Function *psrad = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrai_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7650 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7651 | 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] | 7652 | } |
| 7653 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7654 | RValue<Int4> psrad(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7655 | { |
| 7656 | if(CPUID::supportsSSE2()) |
| 7657 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7658 | llvm::Function *psrad = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrai_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7659 | |
| 7660 | return RValue<Int4>(Nucleus::createCall(psrad, x.value, Nucleus::createConstantInt(y))); |
| 7661 | } |
| 7662 | else |
| 7663 | { |
| 7664 | Int2 lo = Int2(x); |
| 7665 | Int2 hi = Int2(Swizzle(x, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7666 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7667 | lo = x86::psrad(lo, y); |
| 7668 | hi = x86::psrad(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7669 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7670 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7671 | } |
| 7672 | } |
| 7673 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7674 | RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7675 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7676 | llvm::Function *psrld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7677 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7678 | 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] | 7679 | } |
| 7680 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7681 | RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7682 | { |
| 7683 | if(CPUID::supportsSSE2()) |
| 7684 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7685 | llvm::Function *psrld = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7686 | |
| 7687 | return RValue<UInt4>(Nucleus::createCall(psrld, x.value, Nucleus::createConstantInt(y))); |
| 7688 | } |
| 7689 | else |
| 7690 | { |
| 7691 | UInt2 lo = As<UInt2>(Int2(As<Int4>(x))); |
| 7692 | UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7693 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7694 | lo = x86::psrld(lo, y); |
| 7695 | hi = x86::psrld(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7696 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7697 | return UInt4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7698 | } |
| 7699 | } |
| 7700 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7701 | RValue<UShort4> psrlw(RValue<UShort4> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7702 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7703 | llvm::Function *psrlw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrl_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7704 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7705 | 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] | 7706 | } |
| 7707 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7708 | RValue<Short4> psraw(RValue<Short4> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7709 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7710 | llvm::Function *psraw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psra_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7711 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7712 | 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] | 7713 | } |
| 7714 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7715 | RValue<Short4> psllw(RValue<Short4> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7716 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7717 | llvm::Function *psllw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psll_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7718 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7719 | 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] | 7720 | } |
| 7721 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7722 | RValue<Int2> pslld(RValue<Int2> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7723 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7724 | llvm::Function *pslld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psll_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7725 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7726 | 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] | 7727 | } |
| 7728 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7729 | RValue<UInt2> psrld(RValue<UInt2> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7730 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7731 | llvm::Function *psrld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrl_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7732 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7733 | 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] | 7734 | } |
| 7735 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7736 | RValue<Int2> psrad(RValue<Int2> x, RValue<Long1> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7737 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7738 | llvm::Function *psrld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psra_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7739 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7740 | 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] | 7741 | } |
| 7742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7743 | RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y) |
| 7744 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7745 | llvm::Function *pmaxsd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmaxsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7746 | |
| 7747 | return RValue<Int4>(Nucleus::createCall(pmaxsd, x.value, y.value)); |
| 7748 | } |
| 7749 | |
| 7750 | RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y) |
| 7751 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7752 | llvm::Function *pminsd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pminsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7753 | |
| 7754 | return RValue<Int4>(Nucleus::createCall(pminsd, x.value, y.value)); |
| 7755 | } |
| 7756 | |
| 7757 | RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y) |
| 7758 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7759 | llvm::Function *pmaxud = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmaxud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7760 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7761 | return RValue<UInt4>(Nucleus::createCall(pmaxud, x.value, y.value)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7762 | } |
| 7763 | |
| 7764 | RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y) |
| 7765 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7766 | llvm::Function *pminud = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pminud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7767 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7768 | return RValue<UInt4>(Nucleus::createCall(pminud, x.value, y.value)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7769 | } |
| 7770 | |
| 7771 | RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7772 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7773 | llvm::Function *pmulhw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmulh_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7774 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7775 | 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] | 7776 | } |
| 7777 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7778 | RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7779 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7780 | llvm::Function *pmulhuw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmulhu_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7781 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7782 | 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] | 7783 | } |
| 7784 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7785 | RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7786 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7787 | llvm::Function *pmaddwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmadd_wd); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7788 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7789 | 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] | 7790 | } |
| 7791 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7792 | RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7793 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7794 | llvm::Function *pmulhw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pmulh_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7795 | |
| 7796 | return RValue<Short8>(Nucleus::createCall(pmulhw, x.value, y.value)); |
| 7797 | } |
| 7798 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7799 | RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7800 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7801 | llvm::Function *pmulhuw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pmulhu_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7802 | |
| 7803 | return RValue<UShort8>(Nucleus::createCall(pmulhuw, x.value, y.value)); |
| 7804 | } |
| 7805 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7806 | RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7807 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7808 | llvm::Function *pmaddwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pmadd_wd); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7809 | |
| 7810 | return RValue<Int4>(Nucleus::createCall(pmaddwd, x.value, y.value)); |
| 7811 | } |
| 7812 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7813 | RValue<Int> movmskps(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7814 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7815 | llvm::Function *movmskps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_movmsk_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7816 | |
| 7817 | return RValue<Int>(Nucleus::createCall(movmskps, x.value)); |
| 7818 | } |
| 7819 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7820 | RValue<Int> pmovmskb(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7821 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7822 | llvm::Function *pmovmskb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmovmskb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7823 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7824 | return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7825 | } |
| 7826 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 7827 | //RValue<Int2> movd(RValue<Pointer<Int>> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7828 | //{ |
| 7829 | // Value *element = Nucleus::createLoad(x.value); |
| 7830 | |
| 7831 | //// Value *int2 = UndefValue::get(Int2::getType()); |
| 7832 | //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0)); |
| 7833 | |
| 7834 | // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType()); |
| 7835 | |
| 7836 | // return RValue<Int2>(int2); |
| 7837 | //} |
| 7838 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7839 | //RValue<Int2> movdq2q(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7840 | //{ |
| 7841 | // Value *long2 = Nucleus::createBitCast(x.value, Long2::getType()); |
| 7842 | // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0)); |
| 7843 | |
| 7844 | // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType())); |
| 7845 | //} |
| 7846 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7847 | RValue<Int4> pmovzxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7848 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7849 | llvm::Function *pmovzxbd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovzxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7850 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7851 | return RValue<Int4>(Nucleus::createCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType()))); |
| 7852 | } |
| 7853 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7854 | RValue<Int4> pmovsxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7855 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7856 | llvm::Function *pmovsxbd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovsxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7857 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7858 | return RValue<Int4>(Nucleus::createCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType()))); |
| 7859 | } |
| 7860 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7861 | RValue<Int4> pmovzxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7862 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7863 | llvm::Function *pmovzxwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovzxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7864 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7865 | return RValue<Int4>(Nucleus::createCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType()))); |
| 7866 | } |
| 7867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7868 | RValue<Int4> pmovsxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7869 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7870 | llvm::Function *pmovsxwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovsxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7871 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7872 | return RValue<Int4>(Nucleus::createCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType()))); |
| 7873 | } |
| 7874 | |
| 7875 | void emms() |
| 7876 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7877 | llvm::Function *emms = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_emms); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7878 | |
| 7879 | Nucleus::createCall(emms); |
| 7880 | } |
| 7881 | } |
| 7882 | } |