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 | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 32 | #include "LLVMRoutine.hpp" |
| 33 | #include "LLVMRoutineManager.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" |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 38 | #include "MutexLock.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 39 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 40 | #include <xmmintrin.h> |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 41 | #include <fstream> |
| 42 | |
Nicolas Capens | cb12258 | 2014-05-06 23:34:44 -0400 | [diff] [blame] | 43 | #if defined(__x86_64__) && defined(_WIN32) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 44 | extern "C" void X86CompilationCallback() |
| 45 | { |
| 46 | assert(false); // UNIMPLEMENTED |
| 47 | } |
| 48 | #endif |
| 49 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 50 | extern "C" |
| 51 | { |
| 52 | bool (*CodeAnalystInitialize)() = 0; |
| 53 | void (*CodeAnalystCompleteJITLog)() = 0; |
| 54 | bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0; |
| 55 | } |
| 56 | |
| 57 | namespace llvm |
| 58 | { |
| 59 | extern bool JITEmitDebugInfo; |
| 60 | } |
| 61 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 62 | namespace |
| 63 | { |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 64 | sw::LLVMRoutineManager *routineManager = nullptr; |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 65 | llvm::ExecutionEngine *executionEngine = nullptr; |
| 66 | llvm::IRBuilder<> *builder = nullptr; |
| 67 | llvm::LLVMContext *context = nullptr; |
| 68 | llvm::Module *module = nullptr; |
| 69 | llvm::Function *function = nullptr; |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 70 | |
| 71 | sw::BackoffLock codegenMutex; |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 72 | } |
| 73 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 74 | namespace sw |
| 75 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 76 | using namespace llvm; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 77 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 78 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 79 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 80 | class Type : public llvm::Type {}; |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 81 | class Value : public llvm::Value {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 82 | class SwitchCases : public llvm::SwitchInst {}; |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 83 | class BasicBlock : public llvm::BasicBlock {}; |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 84 | |
| 85 | inline Type *T(llvm::Type *t) |
| 86 | { |
| 87 | return reinterpret_cast<Type*>(t); |
| 88 | } |
| 89 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 90 | inline Value *V(llvm::Value *t) |
| 91 | { |
| 92 | return reinterpret_cast<Value*>(t); |
| 93 | } |
| 94 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 95 | inline std::vector<llvm::Type*> &T(std::vector<Type*> &t) |
| 96 | { |
| 97 | return reinterpret_cast<std::vector<llvm::Type*>&>(t); |
| 98 | } |
| 99 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 100 | inline BasicBlock *B(llvm::BasicBlock *t) |
| 101 | { |
| 102 | return reinterpret_cast<BasicBlock*>(t); |
| 103 | } |
| 104 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 105 | Nucleus::Nucleus() |
| 106 | { |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 107 | ::codegenMutex.lock(); // Reactor and LLVM are currently not thread safe |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 109 | InitializeNativeTarget(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 110 | JITEmitDebugInfo = false; |
| 111 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 112 | if(!::context) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 113 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 114 | ::context = new LLVMContext(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 117 | ::module = new Module("", *::context); |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 118 | ::routineManager = new LLVMRoutineManager(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 119 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 120 | #if defined(__x86_64__) |
| 121 | const char *architecture = "x86-64"; |
| 122 | #else |
| 123 | const char *architecture = "x86"; |
| 124 | #endif |
| 125 | |
| 126 | SmallVector<std::string, 1> MAttrs; |
| 127 | MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx"); |
| 128 | MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov"); |
| 129 | MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse"); |
| 130 | MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2"); |
| 131 | MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3"); |
| 132 | MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3"); |
| 133 | MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41"); |
| 134 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 135 | std::string error; |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 136 | TargetMachine *targetMachine = EngineBuilder::selectTarget(::module, architecture, "", MAttrs, Reloc::Default, CodeModel::JITDefault, &error); |
| 137 | ::executionEngine = JIT::createJIT(::module, 0, ::routineManager, CodeGenOpt::Aggressive, true, targetMachine); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 138 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 139 | if(!::builder) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 140 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 141 | ::builder = new IRBuilder<>(*::context); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 142 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 143 | #if defined(_WIN32) |
| 144 | HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll"); |
| 145 | if(CodeAnalyst) |
| 146 | { |
| 147 | CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize"); |
| 148 | CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog"); |
| 149 | CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode"); |
| 150 | |
| 151 | CodeAnalystInitialize(); |
| 152 | } |
| 153 | #endif |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
| 157 | Nucleus::~Nucleus() |
| 158 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 159 | delete ::executionEngine; |
| 160 | ::executionEngine = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 161 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 162 | ::routineManager = nullptr; |
| 163 | ::function = nullptr; |
| 164 | ::module = nullptr; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 165 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 166 | ::codegenMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 170 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 171 | if(::builder->GetInsertBlock()->empty() || !::builder->GetInsertBlock()->back().isTerminator()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 172 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 173 | llvm::Type *type = ::function->getReturnType(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 174 | |
| 175 | if(type->isVoidTy()) |
| 176 | { |
| 177 | createRetVoid(); |
| 178 | } |
| 179 | else |
| 180 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 181 | createRet(V(UndefValue::get(type))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 182 | } |
| 183 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 184 | |
| 185 | if(false) |
| 186 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 187 | std::string error; |
| 188 | raw_fd_ostream file("llvm-dump-unopt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 189 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | if(runOptimizations) |
| 193 | { |
| 194 | optimize(); |
| 195 | } |
| 196 | |
| 197 | if(false) |
| 198 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 199 | std::string error; |
| 200 | raw_fd_ostream file("llvm-dump-opt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 201 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 204 | void *entry = ::executionEngine->getPointerToFunction(::function); |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 205 | LLVMRoutine *routine = ::routineManager->acquireRoutine(entry); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 206 | |
| 207 | if(CodeAnalystLogJITCode) |
| 208 | { |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 209 | CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | return routine; |
| 213 | } |
| 214 | |
| 215 | void Nucleus::optimize() |
| 216 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 217 | static PassManager *passManager = nullptr; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 218 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 219 | if(!passManager) |
| 220 | { |
| 221 | passManager = new PassManager(); |
| 222 | |
| 223 | UnsafeFPMath = true; |
| 224 | // NoInfsFPMath = true; |
| 225 | // NoNaNsFPMath = true; |
| 226 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 227 | passManager->add(new TargetData(*::executionEngine->getTargetData())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 228 | passManager->add(createScalarReplAggregatesPass()); |
| 229 | |
| 230 | for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++) |
| 231 | { |
| 232 | switch(optimization[pass]) |
| 233 | { |
| 234 | case Disabled: break; |
| 235 | case CFGSimplification: passManager->add(createCFGSimplificationPass()); break; |
| 236 | case LICM: passManager->add(createLICMPass()); break; |
| 237 | case AggressiveDCE: passManager->add(createAggressiveDCEPass()); break; |
| 238 | case GVN: passManager->add(createGVNPass()); break; |
| 239 | case InstructionCombining: passManager->add(createInstructionCombiningPass()); break; |
| 240 | case Reassociate: passManager->add(createReassociatePass()); break; |
| 241 | case DeadStoreElimination: passManager->add(createDeadStoreEliminationPass()); break; |
| 242 | case SCCP: passManager->add(createSCCPPass()); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 243 | case ScalarReplAggregates: passManager->add(createScalarReplAggregatesPass()); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 244 | default: |
| 245 | assert(false); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 250 | passManager->run(*::module); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 251 | } |
| 252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 253 | Value *Nucleus::allocateStackVariable(Type *type, int arraySize) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 254 | { |
| 255 | // Need to allocate it in the entry block for mem2reg to work |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 256 | llvm::BasicBlock &entryBlock = ::function->getEntryBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 257 | |
| 258 | Instruction *declaration; |
| 259 | |
| 260 | if(arraySize) |
| 261 | { |
| 262 | declaration = new AllocaInst(type, Nucleus::createConstantInt(arraySize)); |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | declaration = new AllocaInst(type, (Value*)0); |
| 267 | } |
| 268 | |
| 269 | entryBlock.getInstList().push_front(declaration); |
| 270 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 271 | return V(declaration); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | BasicBlock *Nucleus::createBasicBlock() |
| 275 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 276 | return B(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | BasicBlock *Nucleus::getInsertBlock() |
| 280 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 281 | return B(::builder->GetInsertBlock()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 285 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 286 | // assert(::builder->GetInsertBlock()->back().isTerminator()); |
| 287 | return ::builder->SetInsertPoint(basicBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 290 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 291 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 292 | llvm::FunctionType *functionType = llvm::FunctionType::get(ReturnType, T(Params), false); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 293 | ::function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", ::module); |
| 294 | ::function->setCallingConv(llvm::CallingConv::C); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 295 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 296 | ::builder->SetInsertPoint(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 299 | Value *Nucleus::getArgument(unsigned int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 300 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 301 | llvm::Function::arg_iterator args = ::function->arg_begin(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 302 | |
| 303 | while(index) |
| 304 | { |
| 305 | args++; |
| 306 | index--; |
| 307 | } |
| 308 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 309 | return V(&*args); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 312 | void Nucleus::createRetVoid() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 313 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 314 | x86::emms(); |
| 315 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 316 | ::builder->CreateRetVoid(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 319 | void Nucleus::createRet(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 320 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 321 | x86::emms(); |
| 322 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 323 | ::builder->CreateRet(v); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 326 | void Nucleus::createBr(BasicBlock *dest) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 327 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 328 | ::builder->CreateBr(dest); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 329 | } |
| 330 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 331 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 332 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 333 | ::builder->CreateCondBr(cond, ifTrue, ifFalse); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 337 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 338 | return V(::builder->CreateAdd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 342 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 343 | return V(::builder->CreateSub(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 347 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 348 | return V(::builder->CreateMul(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 352 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 353 | return V(::builder->CreateUDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 357 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 358 | return V(::builder->CreateSDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 362 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 363 | return V(::builder->CreateFAdd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 367 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 368 | return V(::builder->CreateFSub(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 372 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 373 | return V(::builder->CreateFMul(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 377 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 378 | return V(::builder->CreateFDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 382 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 383 | return V(::builder->CreateURem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 387 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 388 | return V(::builder->CreateSRem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 392 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 393 | return V(::builder->CreateFRem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 397 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 398 | return V(::builder->CreateShl(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 402 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 403 | return V(::builder->CreateLShr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 407 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 408 | return V(::builder->CreateAShr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 412 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 413 | return V(::builder->CreateAnd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 417 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 418 | return V(::builder->CreateOr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 422 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 423 | return V(::builder->CreateXor(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 424 | } |
| 425 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 426 | Value *Nucleus::createNeg(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 427 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 428 | return V(::builder->CreateNeg(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 431 | Value *Nucleus::createFNeg(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 432 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 433 | return V(::builder->CreateFNeg(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 434 | } |
| 435 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 436 | Value *Nucleus::createNot(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 437 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 438 | return V(::builder->CreateNot(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 441 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 442 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 443 | assert(ptr->getType()->getContainedType(0) == type); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 444 | return V(::builder->Insert(new LoadInst(ptr, "", isVolatile, align))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 447 | Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 448 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 449 | assert(ptr->getType()->getContainedType(0) == type); |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 450 | ::builder->Insert(new StoreInst(value, ptr, isVolatile, align)); |
| 451 | return value; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 452 | } |
| 453 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 454 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 455 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 456 | assert(ptr->getType()->getContainedType(0) == type); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 457 | return V(::builder->CreateGEP(ptr, index)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 458 | } |
| 459 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 460 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 461 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 462 | return V(::builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, value, SequentiallyConsistent)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 465 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 466 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 467 | return V(::builder->CreateTrunc(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 468 | } |
| 469 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 470 | Value *Nucleus::createZExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 471 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 472 | return V(::builder->CreateZExt(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 475 | Value *Nucleus::createSExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 476 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 477 | return V(::builder->CreateSExt(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 478 | } |
| 479 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 480 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 481 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 482 | return V(::builder->CreateFPToSI(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 483 | } |
| 484 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 485 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 486 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 487 | return V(::builder->CreateSIToFP(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 490 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 491 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 492 | return V(::builder->CreateFPTrunc(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 495 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 496 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 497 | return V(::builder->CreateFPExt(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 500 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 501 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 502 | return V(::builder->CreateBitCast(v, destType)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 503 | } |
| 504 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 505 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 506 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 507 | return V(::builder->CreateICmpEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 511 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 512 | return V(::builder->CreateICmpNE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 516 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 517 | return V(::builder->CreateICmpUGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 521 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 522 | return V(::builder->CreateICmpUGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 526 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 527 | return V(::builder->CreateICmpULT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 531 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 532 | return V(::builder->CreateICmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 536 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 537 | return V(::builder->CreateICmpSGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 541 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 542 | return V(::builder->CreateICmpSGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 546 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 547 | return V(::builder->CreateICmpSLT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 551 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 552 | return V(::builder->CreateICmpSLE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 556 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 557 | return V(::builder->CreateFCmpOEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 561 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 562 | return V(::builder->CreateFCmpOGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 566 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 567 | return V(::builder->CreateFCmpOGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 571 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 572 | return V(::builder->CreateFCmpOLT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 576 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 577 | return V(::builder->CreateFCmpOLE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 581 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 582 | return V(::builder->CreateFCmpONE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 586 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 587 | return V(::builder->CreateFCmpORD(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 591 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 592 | return V(::builder->CreateFCmpUNO(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 596 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 597 | return V(::builder->CreateFCmpUEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 601 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 602 | return V(::builder->CreateFCmpUGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 606 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 607 | return V(::builder->CreateFCmpUGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 611 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 612 | return V(::builder->CreateFCmpULT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 616 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 617 | return V(::builder->CreateFCmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 621 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 622 | return V(::builder->CreateFCmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 623 | } |
| 624 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 625 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 626 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 627 | assert(vector->getType()->getContainedType(0) == type); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 628 | return V(::builder->CreateExtractElement(vector, createConstantInt(index))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 632 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 633 | return V(::builder->CreateInsertElement(vector, element, createConstantInt(index))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 636 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 637 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 638 | int size = llvm::cast<llvm::VectorType>(V1->getType())->getNumElements(); |
| 639 | const int maxSize = 16; |
| 640 | llvm::Constant *swizzle[maxSize]; |
| 641 | assert(size <= maxSize); |
| 642 | |
| 643 | for(int i = 0; i < size; i++) |
| 644 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 645 | swizzle[i] = llvm::ConstantInt::get(Type::getInt32Ty(*::context), select[i]); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | llvm::Value *shuffle = llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(swizzle, size)); |
| 649 | |
| 650 | return V(::builder->CreateShuffleVector(V1, V2, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 654 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 655 | return V(::builder->CreateSelect(C, ifTrue, ifFalse)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 658 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 659 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 660 | return reinterpret_cast<SwitchCases*>(::builder->CreateSwitch(control, defaultBranch, numCases)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 661 | } |
| 662 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 663 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 664 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 665 | switchCases->addCase(llvm::ConstantInt::get(Type::getInt32Ty(*::context), label, true), branch); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 668 | void Nucleus::createUnreachable() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 669 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 670 | ::builder->CreateUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 671 | } |
| 672 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 673 | static Value *createSwizzle4(Value *val, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 674 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 675 | int swizzle[4] = |
| 676 | { |
| 677 | (select >> 0) & 0x03, |
| 678 | (select >> 2) & 0x03, |
| 679 | (select >> 4) & 0x03, |
| 680 | (select >> 6) & 0x03, |
| 681 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 682 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 683 | return Nucleus::createShuffleVector(val, val, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 686 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 687 | { |
| 688 | bool mask[4] = {false, false, false, false}; |
| 689 | |
| 690 | mask[(select >> 0) & 0x03] = true; |
| 691 | mask[(select >> 2) & 0x03] = true; |
| 692 | mask[(select >> 4) & 0x03] = true; |
| 693 | mask[(select >> 6) & 0x03] = true; |
| 694 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 695 | int swizzle[4] = |
| 696 | { |
| 697 | mask[0] ? 4 : 0, |
| 698 | mask[1] ? 5 : 1, |
| 699 | mask[2] ? 6 : 2, |
| 700 | mask[3] ? 7 : 3, |
| 701 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 702 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 703 | return Nucleus::createShuffleVector(lhs, rhs, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 704 | } |
| 705 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 706 | Type *Nucleus::getPointerType(Type *ElementType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 707 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 708 | return T(llvm::PointerType::get(ElementType, 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 709 | } |
| 710 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 711 | Value *Nucleus::createNullValue(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 712 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 713 | return V(llvm::Constant::getNullValue(Ty)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 716 | Value *Nucleus::createConstantLong(int64_t i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 717 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 718 | return V(llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 719 | } |
| 720 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 721 | Value *Nucleus::createConstantInt(int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 722 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 723 | return V(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 724 | } |
| 725 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 726 | Value *Nucleus::createConstantInt(unsigned int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 727 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 728 | return V(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 731 | Value *Nucleus::createConstantBool(bool b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 732 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 733 | return V(llvm::ConstantInt::get(Type::getInt1Ty(*::context), b)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 736 | Value *Nucleus::createConstantByte(signed char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 737 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 738 | return V(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 739 | } |
| 740 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 741 | Value *Nucleus::createConstantByte(unsigned char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 742 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 743 | return V(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 746 | Value *Nucleus::createConstantShort(short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 747 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 748 | return V(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 751 | Value *Nucleus::createConstantShort(unsigned short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 752 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 753 | return V(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 754 | } |
| 755 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 756 | Value *Nucleus::createConstantFloat(float x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 757 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 758 | return V(llvm::ConstantFP::get(Float::getType(), x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 759 | } |
| 760 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 761 | Value *Nucleus::createNullPointer(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 762 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 763 | return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 766 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 767 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 768 | assert(llvm::isa<VectorType>(type)); |
| 769 | const int numConstants = llvm::cast<VectorType>(type)->getNumElements(); |
| 770 | assert(numConstants <= 16); |
| 771 | llvm::Constant *constantVector[16]; |
| 772 | |
| 773 | for(int i = 0; i < numConstants; i++) |
| 774 | { |
| 775 | constantVector[i] = llvm::ConstantInt::get(type->getContainedType(0), constants[i]); |
| 776 | } |
| 777 | |
| 778 | return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numConstants))); |
| 779 | } |
| 780 | |
| 781 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
| 782 | { |
| 783 | assert(llvm::isa<VectorType>(type)); |
| 784 | const int numConstants = llvm::cast<VectorType>(type)->getNumElements(); |
| 785 | assert(numConstants <= 8); |
| 786 | llvm::Constant *constantVector[8]; |
| 787 | |
| 788 | for(int i = 0; i < numConstants; i++) |
| 789 | { |
| 790 | constantVector[i] = llvm::ConstantFP::get(type->getContainedType(0), constants[i]); |
| 791 | } |
| 792 | |
| 793 | return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numConstants))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 794 | } |
| 795 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 796 | Type *Void::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 797 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 798 | return T(llvm::Type::getVoidTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 799 | } |
| 800 | |
Nicolas Capens | 297d26e | 2016-11-18 12:52:17 -0500 | [diff] [blame] | 801 | class MMX : public LValue<MMX> |
Nicolas Capens | 4f738a1 | 2016-09-20 15:46:16 -0400 | [diff] [blame] | 802 | { |
| 803 | public: |
| 804 | static Type *getType(); |
| 805 | }; |
| 806 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 807 | Type *MMX::getType() |
| 808 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 809 | return T(llvm::Type::getX86_MMXTy(*::context)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 810 | } |
| 811 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 812 | Bool::Bool(Argument<Bool> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 813 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 814 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 815 | } |
| 816 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 817 | Bool::Bool(bool x) |
| 818 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 819 | storeValue(Nucleus::createConstantBool(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 820 | } |
| 821 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 822 | Bool::Bool(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 823 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 824 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | Bool::Bool(const Bool &rhs) |
| 828 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 829 | Value *value = rhs.loadValue(); |
| 830 | storeValue(value); |
| 831 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 832 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 833 | Bool::Bool(const Reference<Bool> &rhs) |
| 834 | { |
| 835 | Value *value = rhs.loadValue(); |
| 836 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 839 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 840 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 841 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 842 | |
| 843 | return rhs; |
| 844 | } |
| 845 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 846 | RValue<Bool> Bool::operator=(const Bool &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 847 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 848 | Value *value = rhs.loadValue(); |
| 849 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 850 | |
| 851 | return RValue<Bool>(value); |
| 852 | } |
| 853 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 854 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 855 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 856 | Value *value = rhs.loadValue(); |
| 857 | storeValue(value); |
| 858 | |
| 859 | return RValue<Bool>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 860 | } |
| 861 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 862 | RValue<Bool> operator!(RValue<Bool> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 863 | { |
| 864 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 865 | } |
| 866 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 867 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 868 | { |
| 869 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 870 | } |
| 871 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 872 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 873 | { |
| 874 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 875 | } |
| 876 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 877 | Type *Bool::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 878 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 879 | return T(llvm::Type::getInt1Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 880 | } |
| 881 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 882 | Byte::Byte(Argument<Byte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 884 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 885 | } |
| 886 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 887 | Byte::Byte(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 888 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 889 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 890 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 891 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 894 | Byte::Byte(RValue<UInt> cast) |
| 895 | { |
| 896 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 897 | |
| 898 | storeValue(integer); |
| 899 | } |
| 900 | |
| 901 | Byte::Byte(RValue<UShort> cast) |
| 902 | { |
| 903 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 904 | |
| 905 | storeValue(integer); |
| 906 | } |
| 907 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 908 | Byte::Byte(int x) |
| 909 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 910 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | Byte::Byte(unsigned char x) |
| 914 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 915 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 916 | } |
| 917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 918 | Byte::Byte(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 919 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 920 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | Byte::Byte(const Byte &rhs) |
| 924 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 925 | Value *value = rhs.loadValue(); |
| 926 | storeValue(value); |
| 927 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 928 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 929 | Byte::Byte(const Reference<Byte> &rhs) |
| 930 | { |
| 931 | Value *value = rhs.loadValue(); |
| 932 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 933 | } |
| 934 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 935 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 936 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 937 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 938 | |
| 939 | return rhs; |
| 940 | } |
| 941 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 942 | RValue<Byte> Byte::operator=(const Byte &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 943 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 944 | Value *value = rhs.loadValue(); |
| 945 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 946 | |
| 947 | return RValue<Byte>(value); |
| 948 | } |
| 949 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 950 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 951 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 952 | Value *value = rhs.loadValue(); |
| 953 | storeValue(value); |
| 954 | |
| 955 | return RValue<Byte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 956 | } |
| 957 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 958 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 959 | { |
| 960 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 961 | } |
| 962 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 963 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 964 | { |
| 965 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 966 | } |
| 967 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 968 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 969 | { |
| 970 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 971 | } |
| 972 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 973 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 974 | { |
| 975 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 976 | } |
| 977 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 978 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 979 | { |
| 980 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 981 | } |
| 982 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 983 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 984 | { |
| 985 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 986 | } |
| 987 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 988 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 989 | { |
| 990 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 991 | } |
| 992 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 993 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 994 | { |
| 995 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 996 | } |
| 997 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 998 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 999 | { |
| 1000 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1001 | } |
| 1002 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1003 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1004 | { |
| 1005 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1006 | } |
| 1007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1008 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1009 | { |
| 1010 | return lhs = lhs + rhs; |
| 1011 | } |
| 1012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1013 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1014 | { |
| 1015 | return lhs = lhs - rhs; |
| 1016 | } |
| 1017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1018 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1019 | { |
| 1020 | return lhs = lhs * rhs; |
| 1021 | } |
| 1022 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1023 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1024 | { |
| 1025 | return lhs = lhs / rhs; |
| 1026 | } |
| 1027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1028 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1029 | { |
| 1030 | return lhs = lhs % rhs; |
| 1031 | } |
| 1032 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1033 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1034 | { |
| 1035 | return lhs = lhs & rhs; |
| 1036 | } |
| 1037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1038 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1039 | { |
| 1040 | return lhs = lhs | rhs; |
| 1041 | } |
| 1042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1043 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1044 | { |
| 1045 | return lhs = lhs ^ rhs; |
| 1046 | } |
| 1047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1048 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1049 | { |
| 1050 | return lhs = lhs << rhs; |
| 1051 | } |
| 1052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1053 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1054 | { |
| 1055 | return lhs = lhs >> rhs; |
| 1056 | } |
| 1057 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1058 | RValue<Byte> operator+(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1059 | { |
| 1060 | return val; |
| 1061 | } |
| 1062 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1063 | RValue<Byte> operator-(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1064 | { |
| 1065 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1066 | } |
| 1067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1068 | RValue<Byte> operator~(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1069 | { |
| 1070 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1071 | } |
| 1072 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1073 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1074 | { |
| 1075 | RValue<Byte> res = val; |
| 1076 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1077 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1078 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1079 | |
| 1080 | return res; |
| 1081 | } |
| 1082 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1083 | const Byte &operator++(Byte &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1084 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1085 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1086 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1087 | |
| 1088 | return val; |
| 1089 | } |
| 1090 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1091 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1092 | { |
| 1093 | RValue<Byte> res = val; |
| 1094 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1095 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1096 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1097 | |
| 1098 | return res; |
| 1099 | } |
| 1100 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1101 | const Byte &operator--(Byte &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1102 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1103 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1104 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1105 | |
| 1106 | return val; |
| 1107 | } |
| 1108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1109 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1110 | { |
| 1111 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1112 | } |
| 1113 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1114 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1115 | { |
| 1116 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1117 | } |
| 1118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1119 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1120 | { |
| 1121 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1122 | } |
| 1123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1124 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1125 | { |
| 1126 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1127 | } |
| 1128 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1129 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1130 | { |
| 1131 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1132 | } |
| 1133 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1134 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1135 | { |
| 1136 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1137 | } |
| 1138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1139 | Type *Byte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1140 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1141 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1144 | SByte::SByte(Argument<SByte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1145 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1146 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1149 | SByte::SByte(RValue<Int> cast) |
| 1150 | { |
| 1151 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1152 | |
| 1153 | storeValue(integer); |
| 1154 | } |
| 1155 | |
| 1156 | SByte::SByte(RValue<Short> cast) |
| 1157 | { |
| 1158 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1159 | |
| 1160 | storeValue(integer); |
| 1161 | } |
| 1162 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1163 | SByte::SByte(signed char x) |
| 1164 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1165 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1168 | SByte::SByte(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1169 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1170 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | SByte::SByte(const SByte &rhs) |
| 1174 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1175 | Value *value = rhs.loadValue(); |
| 1176 | storeValue(value); |
| 1177 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1178 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1179 | SByte::SByte(const Reference<SByte> &rhs) |
| 1180 | { |
| 1181 | Value *value = rhs.loadValue(); |
| 1182 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1185 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1186 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1187 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1188 | |
| 1189 | return rhs; |
| 1190 | } |
| 1191 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1192 | RValue<SByte> SByte::operator=(const SByte &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1193 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1194 | Value *value = rhs.loadValue(); |
| 1195 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1196 | |
| 1197 | return RValue<SByte>(value); |
| 1198 | } |
| 1199 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1200 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1201 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1202 | Value *value = rhs.loadValue(); |
| 1203 | storeValue(value); |
| 1204 | |
| 1205 | return RValue<SByte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1208 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1209 | { |
| 1210 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1211 | } |
| 1212 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1213 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1214 | { |
| 1215 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1216 | } |
| 1217 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1218 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1219 | { |
| 1220 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1221 | } |
| 1222 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1223 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1224 | { |
| 1225 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1226 | } |
| 1227 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1228 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1229 | { |
| 1230 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1231 | } |
| 1232 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1233 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1234 | { |
| 1235 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1236 | } |
| 1237 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1238 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1239 | { |
| 1240 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1241 | } |
| 1242 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1243 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1244 | { |
| 1245 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1246 | } |
| 1247 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1248 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1249 | { |
| 1250 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1251 | } |
| 1252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1253 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1254 | { |
| 1255 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1256 | } |
| 1257 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1258 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1259 | { |
| 1260 | return lhs = lhs + rhs; |
| 1261 | } |
| 1262 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1263 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1264 | { |
| 1265 | return lhs = lhs - rhs; |
| 1266 | } |
| 1267 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1268 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1269 | { |
| 1270 | return lhs = lhs * rhs; |
| 1271 | } |
| 1272 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1273 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1274 | { |
| 1275 | return lhs = lhs / rhs; |
| 1276 | } |
| 1277 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1278 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1279 | { |
| 1280 | return lhs = lhs % rhs; |
| 1281 | } |
| 1282 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1283 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1284 | { |
| 1285 | return lhs = lhs & rhs; |
| 1286 | } |
| 1287 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1288 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1289 | { |
| 1290 | return lhs = lhs | rhs; |
| 1291 | } |
| 1292 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1293 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1294 | { |
| 1295 | return lhs = lhs ^ rhs; |
| 1296 | } |
| 1297 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1298 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1299 | { |
| 1300 | return lhs = lhs << rhs; |
| 1301 | } |
| 1302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1303 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1304 | { |
| 1305 | return lhs = lhs >> rhs; |
| 1306 | } |
| 1307 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1308 | RValue<SByte> operator+(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1309 | { |
| 1310 | return val; |
| 1311 | } |
| 1312 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1313 | RValue<SByte> operator-(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1314 | { |
| 1315 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1316 | } |
| 1317 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1318 | RValue<SByte> operator~(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1319 | { |
| 1320 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1321 | } |
| 1322 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1323 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1324 | { |
| 1325 | RValue<SByte> res = val; |
| 1326 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1327 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1328 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1329 | |
| 1330 | return res; |
| 1331 | } |
| 1332 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1333 | const SByte &operator++(SByte &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1334 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1335 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1336 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1337 | |
| 1338 | return val; |
| 1339 | } |
| 1340 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1341 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1342 | { |
| 1343 | RValue<SByte> res = val; |
| 1344 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1345 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1346 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1347 | |
| 1348 | return res; |
| 1349 | } |
| 1350 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1351 | const SByte &operator--(SByte &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1352 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1353 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1354 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1355 | |
| 1356 | return val; |
| 1357 | } |
| 1358 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1359 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1360 | { |
| 1361 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1362 | } |
| 1363 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1364 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1365 | { |
| 1366 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1367 | } |
| 1368 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1369 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1370 | { |
| 1371 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1372 | } |
| 1373 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1374 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1375 | { |
| 1376 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1377 | } |
| 1378 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1379 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1380 | { |
| 1381 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1382 | } |
| 1383 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1384 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1385 | { |
| 1386 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1387 | } |
| 1388 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1389 | Type *SByte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1390 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1391 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1394 | Short::Short(Argument<Short> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1395 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1396 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1397 | } |
| 1398 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1399 | Short::Short(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1400 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1401 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1402 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1403 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1404 | } |
| 1405 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1406 | Short::Short(short x) |
| 1407 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1408 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1409 | } |
| 1410 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1411 | Short::Short(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1412 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1413 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | Short::Short(const Short &rhs) |
| 1417 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1418 | Value *value = rhs.loadValue(); |
| 1419 | storeValue(value); |
| 1420 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1421 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1422 | Short::Short(const Reference<Short> &rhs) |
| 1423 | { |
| 1424 | Value *value = rhs.loadValue(); |
| 1425 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1428 | RValue<Short> Short::operator=(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1429 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1430 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1431 | |
| 1432 | return rhs; |
| 1433 | } |
| 1434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1435 | RValue<Short> Short::operator=(const Short &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1436 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1437 | Value *value = rhs.loadValue(); |
| 1438 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1439 | |
| 1440 | return RValue<Short>(value); |
| 1441 | } |
| 1442 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1443 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1444 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1445 | Value *value = rhs.loadValue(); |
| 1446 | storeValue(value); |
| 1447 | |
| 1448 | return RValue<Short>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1449 | } |
| 1450 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1451 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1452 | { |
| 1453 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1454 | } |
| 1455 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1456 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1457 | { |
| 1458 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1459 | } |
| 1460 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1461 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1462 | { |
| 1463 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1464 | } |
| 1465 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1466 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1467 | { |
| 1468 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1469 | } |
| 1470 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1471 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1472 | { |
| 1473 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1474 | } |
| 1475 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1476 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1477 | { |
| 1478 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1479 | } |
| 1480 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1481 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1482 | { |
| 1483 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1484 | } |
| 1485 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1486 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1487 | { |
| 1488 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1489 | } |
| 1490 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1491 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1492 | { |
| 1493 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1494 | } |
| 1495 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1496 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1497 | { |
| 1498 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1499 | } |
| 1500 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1501 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1502 | { |
| 1503 | return lhs = lhs + rhs; |
| 1504 | } |
| 1505 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1506 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1507 | { |
| 1508 | return lhs = lhs - rhs; |
| 1509 | } |
| 1510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1511 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1512 | { |
| 1513 | return lhs = lhs * rhs; |
| 1514 | } |
| 1515 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1516 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1517 | { |
| 1518 | return lhs = lhs / rhs; |
| 1519 | } |
| 1520 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1521 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1522 | { |
| 1523 | return lhs = lhs % rhs; |
| 1524 | } |
| 1525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1526 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1527 | { |
| 1528 | return lhs = lhs & rhs; |
| 1529 | } |
| 1530 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1531 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1532 | { |
| 1533 | return lhs = lhs | rhs; |
| 1534 | } |
| 1535 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1536 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1537 | { |
| 1538 | return lhs = lhs ^ rhs; |
| 1539 | } |
| 1540 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1541 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1542 | { |
| 1543 | return lhs = lhs << rhs; |
| 1544 | } |
| 1545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1546 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1547 | { |
| 1548 | return lhs = lhs >> rhs; |
| 1549 | } |
| 1550 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1551 | RValue<Short> operator+(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1552 | { |
| 1553 | return val; |
| 1554 | } |
| 1555 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1556 | RValue<Short> operator-(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1557 | { |
| 1558 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 1559 | } |
| 1560 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1561 | RValue<Short> operator~(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1562 | { |
| 1563 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 1564 | } |
| 1565 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1566 | RValue<Short> operator++(Short &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1567 | { |
| 1568 | RValue<Short> res = val; |
| 1569 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1570 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1571 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1572 | |
| 1573 | return res; |
| 1574 | } |
| 1575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1576 | const Short &operator++(Short &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1577 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1578 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1579 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1580 | |
| 1581 | return val; |
| 1582 | } |
| 1583 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1584 | RValue<Short> operator--(Short &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1585 | { |
| 1586 | RValue<Short> res = val; |
| 1587 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1588 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1589 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1590 | |
| 1591 | return res; |
| 1592 | } |
| 1593 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1594 | const Short &operator--(Short &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1595 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1596 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1597 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1598 | |
| 1599 | return val; |
| 1600 | } |
| 1601 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1602 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1603 | { |
| 1604 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1605 | } |
| 1606 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1607 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1608 | { |
| 1609 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1610 | } |
| 1611 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1612 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1613 | { |
| 1614 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1615 | } |
| 1616 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1617 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1618 | { |
| 1619 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1620 | } |
| 1621 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1622 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1623 | { |
| 1624 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1625 | } |
| 1626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1627 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1628 | { |
| 1629 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1630 | } |
| 1631 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1632 | Type *Short::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1633 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1634 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1637 | UShort::UShort(Argument<UShort> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1638 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1639 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1642 | UShort::UShort(RValue<UInt> cast) |
| 1643 | { |
| 1644 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1645 | |
| 1646 | storeValue(integer); |
| 1647 | } |
| 1648 | |
Alexis Hetu | 75b650f | 2015-11-19 17:40:15 -0500 | [diff] [blame] | 1649 | UShort::UShort(RValue<Int> cast) |
| 1650 | { |
| 1651 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1652 | |
| 1653 | storeValue(integer); |
| 1654 | } |
| 1655 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1656 | UShort::UShort(unsigned short x) |
| 1657 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1658 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1661 | UShort::UShort(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1662 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1663 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | UShort::UShort(const UShort &rhs) |
| 1667 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1668 | Value *value = rhs.loadValue(); |
| 1669 | storeValue(value); |
| 1670 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1671 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1672 | UShort::UShort(const Reference<UShort> &rhs) |
| 1673 | { |
| 1674 | Value *value = rhs.loadValue(); |
| 1675 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1678 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1679 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1680 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1681 | |
| 1682 | return rhs; |
| 1683 | } |
| 1684 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1685 | RValue<UShort> UShort::operator=(const UShort &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1686 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1687 | Value *value = rhs.loadValue(); |
| 1688 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1689 | |
| 1690 | return RValue<UShort>(value); |
| 1691 | } |
| 1692 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1693 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1694 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1695 | Value *value = rhs.loadValue(); |
| 1696 | storeValue(value); |
| 1697 | |
| 1698 | return RValue<UShort>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1699 | } |
| 1700 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1701 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1702 | { |
| 1703 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1704 | } |
| 1705 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1706 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1707 | { |
| 1708 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1709 | } |
| 1710 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1711 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1712 | { |
| 1713 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1714 | } |
| 1715 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1716 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1717 | { |
| 1718 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1719 | } |
| 1720 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1721 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | { |
| 1723 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1724 | } |
| 1725 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1726 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1727 | { |
| 1728 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1729 | } |
| 1730 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1731 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1732 | { |
| 1733 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1734 | } |
| 1735 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1736 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1737 | { |
| 1738 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1739 | } |
| 1740 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1741 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1742 | { |
| 1743 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1744 | } |
| 1745 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1746 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1747 | { |
| 1748 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1749 | } |
| 1750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1751 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1752 | { |
| 1753 | return lhs = lhs + rhs; |
| 1754 | } |
| 1755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1756 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1757 | { |
| 1758 | return lhs = lhs - rhs; |
| 1759 | } |
| 1760 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1761 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1762 | { |
| 1763 | return lhs = lhs * rhs; |
| 1764 | } |
| 1765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1766 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1767 | { |
| 1768 | return lhs = lhs / rhs; |
| 1769 | } |
| 1770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1771 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1772 | { |
| 1773 | return lhs = lhs % rhs; |
| 1774 | } |
| 1775 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1776 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1777 | { |
| 1778 | return lhs = lhs & rhs; |
| 1779 | } |
| 1780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1781 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1782 | { |
| 1783 | return lhs = lhs | rhs; |
| 1784 | } |
| 1785 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1786 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1787 | { |
| 1788 | return lhs = lhs ^ rhs; |
| 1789 | } |
| 1790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1791 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1792 | { |
| 1793 | return lhs = lhs << rhs; |
| 1794 | } |
| 1795 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1796 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1797 | { |
| 1798 | return lhs = lhs >> rhs; |
| 1799 | } |
| 1800 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1801 | RValue<UShort> operator+(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1802 | { |
| 1803 | return val; |
| 1804 | } |
| 1805 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1806 | RValue<UShort> operator-(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1807 | { |
| 1808 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 1809 | } |
| 1810 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1811 | RValue<UShort> operator~(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1812 | { |
| 1813 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 1814 | } |
| 1815 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1816 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1817 | { |
| 1818 | RValue<UShort> res = val; |
| 1819 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1820 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1821 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1822 | |
| 1823 | return res; |
| 1824 | } |
| 1825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1826 | const UShort &operator++(UShort &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1827 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1828 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1829 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1830 | |
| 1831 | return val; |
| 1832 | } |
| 1833 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1834 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1835 | { |
| 1836 | RValue<UShort> res = val; |
| 1837 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1838 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1839 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1840 | |
| 1841 | return res; |
| 1842 | } |
| 1843 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1844 | const UShort &operator--(UShort &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1845 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1846 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1847 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1848 | |
| 1849 | return val; |
| 1850 | } |
| 1851 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1852 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1853 | { |
| 1854 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1855 | } |
| 1856 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1857 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1858 | { |
| 1859 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1860 | } |
| 1861 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1862 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1863 | { |
| 1864 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1865 | } |
| 1866 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1867 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1868 | { |
| 1869 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1870 | } |
| 1871 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1872 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1873 | { |
| 1874 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1875 | } |
| 1876 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1877 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1878 | { |
| 1879 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1880 | } |
| 1881 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1882 | Type *UShort::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1883 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1884 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1885 | } |
| 1886 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 1887 | Byte4::Byte4(RValue<Byte8> cast) |
| 1888 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 1889 | storeValue(Nucleus::createTrunc(Nucleus::createBitCast(cast.value, Long::getType()), Int::getType())); |
| 1890 | } |
| 1891 | |
| 1892 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 1893 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 1894 | Value *value = rhs.loadValue(); |
| 1895 | storeValue(value); |
| 1896 | } |
| 1897 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1898 | Type *Byte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1899 | { |
| 1900 | #if 0 |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1901 | return T(VectorType::get(Byte::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1902 | #else |
| 1903 | return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 1904 | #endif |
| 1905 | } |
| 1906 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1907 | Type *SByte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1908 | { |
| 1909 | #if 0 |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1910 | return T(VectorType::get(SByte::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1911 | #else |
| 1912 | return Int::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 1913 | #endif |
| 1914 | } |
| 1915 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 1916 | Byte8::Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1917 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1918 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 1919 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Byte::getType(), 8)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1920 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1921 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1922 | } |
| 1923 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1924 | Byte8::Byte8(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1925 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1926 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | Byte8::Byte8(const Byte8 &rhs) |
| 1930 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1931 | Value *value = rhs.loadValue(); |
| 1932 | storeValue(value); |
| 1933 | } |
| 1934 | |
| 1935 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 1936 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1937 | Value *value = rhs.loadValue(); |
| 1938 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1939 | } |
| 1940 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1941 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1942 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1943 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1944 | |
| 1945 | return rhs; |
| 1946 | } |
| 1947 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1948 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1949 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1950 | Value *value = rhs.loadValue(); |
| 1951 | storeValue(value); |
| 1952 | |
| 1953 | return RValue<Byte8>(value); |
| 1954 | } |
| 1955 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1956 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1957 | { |
| 1958 | Value *value = rhs.loadValue(); |
| 1959 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1960 | |
| 1961 | return RValue<Byte8>(value); |
| 1962 | } |
| 1963 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1964 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1965 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1966 | if(CPUID::supportsMMX2()) |
| 1967 | { |
| 1968 | return x86::paddb(lhs, rhs); |
| 1969 | } |
| 1970 | else |
| 1971 | { |
| 1972 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1973 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1974 | } |
| 1975 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1976 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1977 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1978 | if(CPUID::supportsMMX2()) |
| 1979 | { |
| 1980 | return x86::psubb(lhs, rhs); |
| 1981 | } |
| 1982 | else |
| 1983 | { |
| 1984 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1985 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1986 | } |
| 1987 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1988 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 1989 | // { |
| 1990 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1991 | // } |
| 1992 | |
| 1993 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 1994 | // { |
| 1995 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1996 | // } |
| 1997 | |
| 1998 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 1999 | // { |
| 2000 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2001 | // } |
| 2002 | |
| 2003 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2004 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2005 | if(CPUID::supportsMMX2()) |
| 2006 | { |
| 2007 | return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 2008 | } |
| 2009 | else |
| 2010 | { |
| 2011 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2012 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2013 | } |
| 2014 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2015 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2016 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2017 | if(CPUID::supportsMMX2()) |
| 2018 | { |
| 2019 | return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 2020 | } |
| 2021 | else |
| 2022 | { |
| 2023 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2024 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2025 | } |
| 2026 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2027 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2028 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2029 | if(CPUID::supportsMMX2()) |
| 2030 | { |
| 2031 | return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 2032 | } |
| 2033 | else |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2034 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2035 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2036 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2037 | } |
| 2038 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2039 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2040 | // { |
| 2041 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2042 | // } |
| 2043 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2044 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2045 | // { |
| 2046 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2047 | // } |
| 2048 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2049 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2050 | { |
| 2051 | return lhs = lhs + rhs; |
| 2052 | } |
| 2053 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2054 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2055 | { |
| 2056 | return lhs = lhs - rhs; |
| 2057 | } |
| 2058 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2059 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2060 | // { |
| 2061 | // return lhs = lhs * rhs; |
| 2062 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2063 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2064 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2065 | // { |
| 2066 | // return lhs = lhs / rhs; |
| 2067 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2068 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2069 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2070 | // { |
| 2071 | // return lhs = lhs % rhs; |
| 2072 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2073 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2074 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2075 | { |
| 2076 | return lhs = lhs & rhs; |
| 2077 | } |
| 2078 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2079 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2080 | { |
| 2081 | return lhs = lhs | rhs; |
| 2082 | } |
| 2083 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2084 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2085 | { |
| 2086 | return lhs = lhs ^ rhs; |
| 2087 | } |
| 2088 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2089 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2090 | // { |
| 2091 | // return lhs = lhs << rhs; |
| 2092 | // } |
| 2093 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2094 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2095 | // { |
| 2096 | // return lhs = lhs >> rhs; |
| 2097 | // } |
| 2098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2099 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2100 | // { |
| 2101 | // return val; |
| 2102 | // } |
| 2103 | |
| 2104 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2105 | // { |
| 2106 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2107 | // } |
| 2108 | |
| 2109 | RValue<Byte8> operator~(RValue<Byte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2110 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2111 | if(CPUID::supportsMMX2()) |
| 2112 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2113 | return val ^ Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2114 | } |
| 2115 | else |
| 2116 | { |
| 2117 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2118 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2119 | } |
| 2120 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2121 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2122 | { |
| 2123 | return x86::paddusb(x, y); |
| 2124 | } |
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 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2127 | { |
| 2128 | return x86::psubusb(x, y); |
| 2129 | } |
| 2130 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2131 | RValue<Short4> Unpack(RValue<Byte4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2132 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 2133 | Value *int2 = Nucleus::createInsertElement(V(UndefValue::get(VectorType::get(Int::getType(), 2))), x.value, 0); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2134 | Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2136 | return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8)); |
| 2137 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2139 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2140 | { |
| 2141 | if(CPUID::supportsMMX2()) |
| 2142 | { |
| 2143 | return x86::punpcklbw(x, y); |
| 2144 | } |
| 2145 | else |
| 2146 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2147 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 2148 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2149 | |
| 2150 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2151 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2152 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2154 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2155 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2156 | if(CPUID::supportsMMX2()) |
| 2157 | { |
| 2158 | return x86::punpckhbw(x, y); |
| 2159 | } |
| 2160 | else |
| 2161 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2162 | int shuffle[8] = {4, 12, 5, 13, 6, 14, 7, 15}; |
| 2163 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
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 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2166 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2167 | } |
| 2168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2169 | RValue<Int> SignMask(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2170 | { |
| 2171 | return x86::pmovmskb(x); |
| 2172 | } |
| 2173 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2174 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2175 | // { |
| 2176 | // return x86::pcmpgtb(x, y); // FIXME: Signedness |
| 2177 | // } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2178 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2179 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2180 | { |
| 2181 | return x86::pcmpeqb(x, y); |
| 2182 | } |
| 2183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2184 | Type *Byte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2185 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2186 | if(CPUID::supportsMMX2()) |
| 2187 | { |
| 2188 | return MMX::getType(); |
| 2189 | } |
| 2190 | else |
| 2191 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 2192 | return T(VectorType::get(Byte::getType(), 8)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2193 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2194 | } |
| 2195 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 2196 | SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2197 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2198 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2199 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(SByte::getType(), 8)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2200 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2201 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2202 | } |
| 2203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2204 | SByte8::SByte8(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2205 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2206 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | SByte8::SByte8(const SByte8 &rhs) |
| 2210 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2211 | Value *value = rhs.loadValue(); |
| 2212 | storeValue(value); |
| 2213 | } |
| 2214 | |
| 2215 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2216 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2217 | Value *value = rhs.loadValue(); |
| 2218 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2219 | } |
| 2220 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2221 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2222 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2223 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2224 | |
| 2225 | return rhs; |
| 2226 | } |
| 2227 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2228 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2229 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2230 | Value *value = rhs.loadValue(); |
| 2231 | storeValue(value); |
| 2232 | |
| 2233 | return RValue<SByte8>(value); |
| 2234 | } |
| 2235 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2236 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2237 | { |
| 2238 | Value *value = rhs.loadValue(); |
| 2239 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2240 | |
| 2241 | return RValue<SByte8>(value); |
| 2242 | } |
| 2243 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2244 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2245 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2246 | if(CPUID::supportsMMX2()) |
| 2247 | { |
| 2248 | return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2249 | } |
| 2250 | else |
| 2251 | { |
| 2252 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2253 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2254 | } |
| 2255 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2256 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2257 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2258 | if(CPUID::supportsMMX2()) |
| 2259 | { |
| 2260 | return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2261 | } |
| 2262 | else |
| 2263 | { |
| 2264 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2265 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2266 | } |
| 2267 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2268 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2269 | // { |
| 2270 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2271 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2273 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2274 | // { |
| 2275 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2276 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2278 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2279 | // { |
| 2280 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2281 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2282 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2283 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2284 | { |
| 2285 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2286 | } |
| 2287 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2288 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2289 | { |
| 2290 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2291 | } |
| 2292 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2293 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2294 | { |
| 2295 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2296 | } |
| 2297 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2298 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2299 | // { |
| 2300 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2301 | // } |
| 2302 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2303 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2304 | // { |
| 2305 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2306 | // } |
| 2307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2308 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2309 | { |
| 2310 | return lhs = lhs + rhs; |
| 2311 | } |
| 2312 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2313 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2314 | { |
| 2315 | return lhs = lhs - rhs; |
| 2316 | } |
| 2317 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2318 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2319 | // { |
| 2320 | // return lhs = lhs * rhs; |
| 2321 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2322 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2323 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2324 | // { |
| 2325 | // return lhs = lhs / rhs; |
| 2326 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2327 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2328 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2329 | // { |
| 2330 | // return lhs = lhs % rhs; |
| 2331 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2332 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2333 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2334 | { |
| 2335 | return lhs = lhs & rhs; |
| 2336 | } |
| 2337 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2338 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2339 | { |
| 2340 | return lhs = lhs | rhs; |
| 2341 | } |
| 2342 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2343 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2344 | { |
| 2345 | return lhs = lhs ^ rhs; |
| 2346 | } |
| 2347 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2348 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2349 | // { |
| 2350 | // return lhs = lhs << rhs; |
| 2351 | // } |
| 2352 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2353 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2354 | // { |
| 2355 | // return lhs = lhs >> rhs; |
| 2356 | // } |
| 2357 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2358 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2359 | // { |
| 2360 | // return val; |
| 2361 | // } |
| 2362 | |
| 2363 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2364 | // { |
| 2365 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2366 | // } |
| 2367 | |
| 2368 | RValue<SByte8> operator~(RValue<SByte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2369 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2370 | if(CPUID::supportsMMX2()) |
| 2371 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2372 | return val ^ SByte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2373 | } |
| 2374 | else |
| 2375 | { |
| 2376 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2377 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2378 | } |
| 2379 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2380 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2381 | { |
| 2382 | return x86::paddsb(x, y); |
| 2383 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2384 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2385 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2386 | { |
| 2387 | return x86::psubsb(x, y); |
| 2388 | } |
| 2389 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2390 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2391 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2392 | if(CPUID::supportsMMX2()) |
| 2393 | { |
| 2394 | return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y))); |
| 2395 | } |
| 2396 | else |
| 2397 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2398 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 2399 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2400 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2401 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2402 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2403 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2404 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2405 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2406 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2407 | if(CPUID::supportsMMX2()) |
| 2408 | { |
| 2409 | return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y))); |
| 2410 | } |
| 2411 | else |
| 2412 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2413 | int shuffle[8] = {4, 12, 5, 13, 6, 14, 7, 15}; |
| 2414 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2415 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2416 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2417 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2418 | } |
| 2419 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2420 | RValue<Int> SignMask(RValue<SByte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2421 | { |
| 2422 | return x86::pmovmskb(As<Byte8>(x)); |
| 2423 | } |
| 2424 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2425 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2426 | { |
| 2427 | return x86::pcmpgtb(x, y); |
| 2428 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2430 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2431 | { |
| 2432 | return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y)); |
| 2433 | } |
| 2434 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2435 | Type *SByte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2436 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2437 | if(CPUID::supportsMMX2()) |
| 2438 | { |
| 2439 | return MMX::getType(); |
| 2440 | } |
| 2441 | else |
| 2442 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 2443 | return T(VectorType::get(SByte::getType(), 8)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2444 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2445 | } |
| 2446 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2447 | Byte16::Byte16(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2448 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2449 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | Byte16::Byte16(const Byte16 &rhs) |
| 2453 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2454 | Value *value = rhs.loadValue(); |
| 2455 | storeValue(value); |
| 2456 | } |
| 2457 | |
| 2458 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2459 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2460 | Value *value = rhs.loadValue(); |
| 2461 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2462 | } |
| 2463 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2464 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2465 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2466 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2467 | |
| 2468 | return rhs; |
| 2469 | } |
| 2470 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2471 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2472 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2473 | Value *value = rhs.loadValue(); |
| 2474 | storeValue(value); |
| 2475 | |
| 2476 | return RValue<Byte16>(value); |
| 2477 | } |
| 2478 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2479 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2480 | { |
| 2481 | Value *value = rhs.loadValue(); |
| 2482 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2483 | |
| 2484 | return RValue<Byte16>(value); |
| 2485 | } |
| 2486 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2487 | Type *Byte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2488 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 2489 | return T(VectorType::get(Byte::getType(), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2490 | } |
| 2491 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2492 | Type *SByte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2493 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 2494 | return T( VectorType::get(SByte::getType(), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2495 | } |
| 2496 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2497 | Short2::Short2(RValue<Short4> cast) |
| 2498 | { |
| 2499 | storeValue(Nucleus::createTrunc(Nucleus::createBitCast(cast.value, Long::getType()), UInt::getType())); |
| 2500 | } |
| 2501 | |
| 2502 | Type *Short2::getType() |
| 2503 | { |
| 2504 | #if 0 |
| 2505 | return T(VectorType::get(Short::getType(), 2)); |
| 2506 | #else |
| 2507 | return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 2508 | #endif |
| 2509 | } |
| 2510 | |
| 2511 | UShort2::UShort2(RValue<UShort4> cast) |
| 2512 | { |
| 2513 | storeValue(Nucleus::createTrunc(Nucleus::createBitCast(cast.value, Long::getType()), UInt::getType())); |
| 2514 | } |
| 2515 | |
| 2516 | Type *UShort2::getType() |
| 2517 | { |
| 2518 | #if 0 |
| 2519 | return T(VectorType::get(UShort::getType(), 2)); |
| 2520 | #else |
| 2521 | return UInt::getType(); // FIXME: LLVM doesn't manipulate it as one 32-bit block |
| 2522 | #endif |
| 2523 | } |
| 2524 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2525 | Short4::Short4(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2526 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2527 | Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2528 | Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2529 | |
| 2530 | storeValue(swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2531 | } |
| 2532 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2533 | Short4::Short4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2534 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2535 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 2536 | |
| 2537 | #if 0 // FIXME: Check codegen (pshuflw phshufhw pshufd) |
| 2538 | Constant *pack[8]; |
| 2539 | pack[0] = Nucleus::createConstantInt(0); |
| 2540 | pack[1] = Nucleus::createConstantInt(2); |
| 2541 | pack[2] = Nucleus::createConstantInt(4); |
| 2542 | pack[3] = Nucleus::createConstantInt(6); |
| 2543 | |
| 2544 | Value *short4 = Nucleus::createShuffleVector(short8, short8, Nucleus::createConstantVector(pack, 4)); |
| 2545 | #else |
| 2546 | Value *packed; |
| 2547 | |
| 2548 | // FIXME: Use Swizzle<Short8> |
| 2549 | if(!CPUID::supportsSSSE3()) |
| 2550 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2551 | int pshuflw[8] = {0, 2, 0, 2, 4, 5, 6, 7}; |
| 2552 | int pshufhw[8] = {0, 1, 2, 3, 4, 6, 4, 6}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2553 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2554 | Value *shuffle1 = Nucleus::createShuffleVector(short8, short8, pshuflw); |
| 2555 | Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, shuffle1, pshufhw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2556 | Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType()); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 2557 | packed = createSwizzle4(int4, 0x88); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2558 | } |
| 2559 | else |
| 2560 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2561 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2562 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2563 | packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | #if 0 // FIXME: No optimal instruction selection |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 2567 | Value *qword2 = Nucleus::createBitCast(packed, T(VectorType::get(Long::getType(), 2))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2568 | Value *element = Nucleus::createExtractElement(qword2, 0); |
| 2569 | Value *short4 = Nucleus::createBitCast(element, Short4::getType()); |
| 2570 | #else // FIXME: Requires SSE |
| 2571 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2572 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2573 | #endif |
| 2574 | #endif |
| 2575 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2576 | storeValue(short4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2577 | } |
| 2578 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2579 | // Short4::Short4(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2580 | // { |
| 2581 | // } |
| 2582 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2583 | Short4::Short4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2584 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2585 | Int4 v4i32 = Int4(cast); |
| 2586 | v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2587 | |
| 2588 | storeValue(As<Short4>(Int2(v4i32)).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2589 | } |
| 2590 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2591 | Short4::Short4(short xyzw) |
| 2592 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2593 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2594 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Short::getType(), 4)))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2595 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2596 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2599 | Short4::Short4(short x, short y, short z, short w) |
| 2600 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2601 | int64_t constantVector[4] = {x, y, z, w}; |
| 2602 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Short::getType(), 4)))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2603 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2604 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2605 | } |
| 2606 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2607 | Short4::Short4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2608 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2609 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | Short4::Short4(const Short4 &rhs) |
| 2613 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2614 | Value *value = rhs.loadValue(); |
| 2615 | storeValue(value); |
| 2616 | } |
| 2617 | |
| 2618 | Short4::Short4(const Reference<Short4> &rhs) |
| 2619 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2620 | Value *value = rhs.loadValue(); |
| 2621 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2622 | } |
| 2623 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2624 | Short4::Short4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2625 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2626 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | Short4::Short4(const UShort4 &rhs) |
| 2630 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2631 | storeValue(rhs.loadValue()); |
| 2632 | } |
| 2633 | |
| 2634 | Short4::Short4(const Reference<UShort4> &rhs) |
| 2635 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2636 | storeValue(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2637 | } |
| 2638 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2639 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2640 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2641 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2642 | |
| 2643 | return rhs; |
| 2644 | } |
| 2645 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2646 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2647 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2648 | Value *value = rhs.loadValue(); |
| 2649 | storeValue(value); |
| 2650 | |
| 2651 | return RValue<Short4>(value); |
| 2652 | } |
| 2653 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2654 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2655 | { |
| 2656 | Value *value = rhs.loadValue(); |
| 2657 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2658 | |
| 2659 | return RValue<Short4>(value); |
| 2660 | } |
| 2661 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2662 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2663 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2664 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2665 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2666 | return RValue<Short4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2667 | } |
| 2668 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2669 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2670 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2671 | Value *value = rhs.loadValue(); |
| 2672 | storeValue(value); |
| 2673 | |
| 2674 | return RValue<Short4>(value); |
| 2675 | } |
| 2676 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2677 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2678 | { |
| 2679 | Value *value = rhs.loadValue(); |
| 2680 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2681 | |
| 2682 | return RValue<Short4>(value); |
| 2683 | } |
| 2684 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2685 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2686 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2687 | if(CPUID::supportsMMX2()) |
| 2688 | { |
| 2689 | return x86::paddw(lhs, rhs); |
| 2690 | } |
| 2691 | else |
| 2692 | { |
| 2693 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2694 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2697 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2698 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2699 | if(CPUID::supportsMMX2()) |
| 2700 | { |
| 2701 | return x86::psubw(lhs, rhs); |
| 2702 | } |
| 2703 | else |
| 2704 | { |
| 2705 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2706 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2707 | } |
| 2708 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2709 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2710 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2711 | if(CPUID::supportsMMX2()) |
| 2712 | { |
| 2713 | return x86::pmullw(lhs, rhs); |
| 2714 | } |
| 2715 | else |
| 2716 | { |
| 2717 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2718 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2719 | } |
| 2720 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2721 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2722 | // { |
| 2723 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2724 | // } |
| 2725 | |
| 2726 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2727 | // { |
| 2728 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2729 | // } |
| 2730 | |
| 2731 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2732 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2733 | if(CPUID::supportsMMX2()) |
| 2734 | { |
| 2735 | return x86::pand(lhs, rhs); |
| 2736 | } |
| 2737 | else |
| 2738 | { |
| 2739 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2740 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2741 | } |
| 2742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2743 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2744 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2745 | if(CPUID::supportsMMX2()) |
| 2746 | { |
| 2747 | return x86::por(lhs, rhs); |
| 2748 | } |
| 2749 | else |
| 2750 | { |
| 2751 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2752 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2753 | } |
| 2754 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2755 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2756 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2757 | if(CPUID::supportsMMX2()) |
| 2758 | { |
| 2759 | return x86::pxor(lhs, rhs); |
| 2760 | } |
| 2761 | else |
| 2762 | { |
| 2763 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2764 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2765 | } |
| 2766 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2767 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2768 | { |
| 2769 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2770 | |
| 2771 | return x86::psllw(lhs, rhs); |
| 2772 | } |
| 2773 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2774 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2775 | { |
| 2776 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2777 | |
| 2778 | return x86::psraw(lhs, rhs); |
| 2779 | } |
| 2780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2781 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2782 | { |
| 2783 | return lhs = lhs + rhs; |
| 2784 | } |
| 2785 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2786 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2787 | { |
| 2788 | return lhs = lhs - rhs; |
| 2789 | } |
| 2790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2791 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2792 | { |
| 2793 | return lhs = lhs * rhs; |
| 2794 | } |
| 2795 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2796 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2797 | // { |
| 2798 | // return lhs = lhs / rhs; |
| 2799 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2800 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2801 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2802 | // { |
| 2803 | // return lhs = lhs % rhs; |
| 2804 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2805 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2806 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2807 | { |
| 2808 | return lhs = lhs & rhs; |
| 2809 | } |
| 2810 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2811 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2812 | { |
| 2813 | return lhs = lhs | rhs; |
| 2814 | } |
| 2815 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2816 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2817 | { |
| 2818 | return lhs = lhs ^ rhs; |
| 2819 | } |
| 2820 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2821 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2822 | { |
| 2823 | return lhs = lhs << rhs; |
| 2824 | } |
| 2825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2826 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2827 | { |
| 2828 | return lhs = lhs >> rhs; |
| 2829 | } |
| 2830 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2831 | // RValue<Short4> operator+(RValue<Short4> val) |
| 2832 | // { |
| 2833 | // return val; |
| 2834 | // } |
| 2835 | |
| 2836 | RValue<Short4> operator-(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2837 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2838 | if(CPUID::supportsMMX2()) |
| 2839 | { |
| 2840 | return Short4(0, 0, 0, 0) - val; |
| 2841 | } |
| 2842 | else |
| 2843 | { |
| 2844 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
| 2845 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2846 | } |
| 2847 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2848 | RValue<Short4> operator~(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2849 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2850 | if(CPUID::supportsMMX2()) |
| 2851 | { |
| 2852 | return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu); |
| 2853 | } |
| 2854 | else |
| 2855 | { |
| 2856 | return RValue<Short4>(Nucleus::createNot(val.value)); |
| 2857 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2858 | } |
| 2859 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2860 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2861 | { |
| 2862 | RValue<Int4> v4i32 = x86::cvtps2dq(cast); |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 2863 | RValue<Short8> v8i16 = x86::packssdw(v4i32, v4i32); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2864 | |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 2865 | return As<Short4>(Int2(As<Int4>(v8i16))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2866 | } |
| 2867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2868 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2869 | { |
| 2870 | return x86::pmaxsw(x, y); |
| 2871 | } |
| 2872 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2873 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2874 | { |
| 2875 | return x86::pminsw(x, y); |
| 2876 | } |
| 2877 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2878 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2879 | { |
| 2880 | return x86::paddsw(x, y); |
| 2881 | } |
| 2882 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2883 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2884 | { |
| 2885 | return x86::psubsw(x, y); |
| 2886 | } |
| 2887 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2888 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2889 | { |
| 2890 | return x86::pmulhw(x, y); |
| 2891 | } |
| 2892 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2893 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2894 | { |
| 2895 | return x86::pmaddwd(x, y); |
| 2896 | } |
| 2897 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2898 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2899 | { |
| 2900 | return x86::packsswb(x, y); |
| 2901 | } |
| 2902 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2903 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2904 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2905 | if(CPUID::supportsMMX2()) |
| 2906 | { |
| 2907 | return x86::punpcklwd(x, y); |
| 2908 | } |
| 2909 | else |
| 2910 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2911 | int shuffle[4] = {0, 4, 1, 5}; |
| 2912 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2913 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2914 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 2915 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2916 | } |
| 2917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2918 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2919 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2920 | if(CPUID::supportsMMX2()) |
| 2921 | { |
| 2922 | return x86::punpckhwd(x, y); |
| 2923 | } |
| 2924 | else |
| 2925 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2926 | int shuffle[4] = {2, 6, 3, 7}; |
| 2927 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2928 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2929 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 2930 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2931 | } |
| 2932 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2933 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2934 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2935 | if(CPUID::supportsMMX2()) |
| 2936 | { |
| 2937 | return x86::pshufw(x, select); |
| 2938 | } |
| 2939 | else |
| 2940 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 2941 | return RValue<Short4>(createSwizzle4(x.value, select)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2942 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2943 | } |
| 2944 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2945 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2946 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2947 | if(CPUID::supportsMMX2()) |
| 2948 | { |
| 2949 | return x86::pinsrw(val, Int(element), i); |
| 2950 | } |
| 2951 | else |
| 2952 | { |
| 2953 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2954 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2955 | } |
| 2956 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2957 | RValue<Short> Extract(RValue<Short4> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2958 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2959 | if(CPUID::supportsMMX2()) |
| 2960 | { |
| 2961 | return Short(x86::pextrw(val, i)); |
| 2962 | } |
| 2963 | else |
| 2964 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 2965 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2966 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2967 | } |
| 2968 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2969 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2970 | { |
| 2971 | return x86::pcmpgtw(x, y); |
| 2972 | } |
| 2973 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2974 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2975 | { |
| 2976 | return x86::pcmpeqw(x, y); |
| 2977 | } |
| 2978 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2979 | Type *Short4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2980 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2981 | if(CPUID::supportsMMX2()) |
| 2982 | { |
| 2983 | return MMX::getType(); |
| 2984 | } |
| 2985 | else |
| 2986 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 2987 | return T(VectorType::get(Short::getType(), 4)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2988 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2989 | } |
| 2990 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2991 | UShort4::UShort4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2992 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2993 | *this = Short4(cast); |
| 2994 | } |
| 2995 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2996 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2997 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2998 | Float4 sat; |
| 2999 | |
| 3000 | if(saturate) |
| 3001 | { |
| 3002 | if(CPUID::supportsSSE4_1()) |
| 3003 | { |
| 3004 | sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation |
| 3005 | } |
| 3006 | else |
| 3007 | { |
| 3008 | sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)); |
| 3009 | } |
| 3010 | } |
| 3011 | else |
| 3012 | { |
| 3013 | sat = cast; |
| 3014 | } |
| 3015 | |
| 3016 | Int4 int4(sat); |
| 3017 | |
| 3018 | if(!saturate || !CPUID::supportsSSE4_1()) |
| 3019 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3020 | *this = Short4(int4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3021 | } |
| 3022 | else |
| 3023 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3024 | *this = As<Short4>(Int2(As<Int4>(x86::packusdw(int4, int4)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3025 | } |
| 3026 | } |
| 3027 | |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 3028 | UShort4::UShort4(unsigned short xyzw) |
| 3029 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3030 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3031 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(UShort::getType(), 4)))); |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 3032 | |
| 3033 | storeValue(Nucleus::createBitCast(vector, getType())); |
| 3034 | } |
| 3035 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3036 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3037 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3038 | int64_t constantVector[4] = {x, y, z, w}; |
| 3039 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(UShort::getType(), 4)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3040 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3041 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3042 | } |
| 3043 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3044 | UShort4::UShort4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3045 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3046 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | UShort4::UShort4(const UShort4 &rhs) |
| 3050 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3051 | Value *value = rhs.loadValue(); |
| 3052 | storeValue(value); |
| 3053 | } |
| 3054 | |
| 3055 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3056 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3057 | Value *value = rhs.loadValue(); |
| 3058 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3059 | } |
| 3060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3061 | UShort4::UShort4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3062 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3063 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | UShort4::UShort4(const Short4 &rhs) |
| 3067 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3068 | Value *value = rhs.loadValue(); |
| 3069 | storeValue(value); |
| 3070 | } |
| 3071 | |
| 3072 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3073 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3074 | Value *value = rhs.loadValue(); |
| 3075 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3076 | } |
| 3077 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3078 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3079 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3080 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3081 | |
| 3082 | return rhs; |
| 3083 | } |
| 3084 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3085 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3086 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3087 | Value *value = rhs.loadValue(); |
| 3088 | storeValue(value); |
| 3089 | |
| 3090 | return RValue<UShort4>(value); |
| 3091 | } |
| 3092 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3093 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3094 | { |
| 3095 | Value *value = rhs.loadValue(); |
| 3096 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3097 | |
| 3098 | return RValue<UShort4>(value); |
| 3099 | } |
| 3100 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3101 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3102 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3103 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3104 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3105 | return RValue<UShort4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3106 | } |
| 3107 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3108 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3109 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3110 | Value *value = rhs.loadValue(); |
| 3111 | storeValue(value); |
| 3112 | |
| 3113 | return RValue<UShort4>(value); |
| 3114 | } |
| 3115 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3116 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3117 | { |
| 3118 | Value *value = rhs.loadValue(); |
| 3119 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3120 | |
| 3121 | return RValue<UShort4>(value); |
| 3122 | } |
| 3123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3124 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3125 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3126 | if(CPUID::supportsMMX2()) |
| 3127 | { |
| 3128 | return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3129 | } |
| 3130 | else |
| 3131 | { |
| 3132 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3133 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3134 | } |
| 3135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3136 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3137 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3138 | if(CPUID::supportsMMX2()) |
| 3139 | { |
| 3140 | return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3141 | } |
| 3142 | else |
| 3143 | { |
| 3144 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3145 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3146 | } |
| 3147 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3148 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
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 | if(CPUID::supportsMMX2()) |
| 3151 | { |
| 3152 | return As<UShort4>(x86::pmullw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3153 | } |
| 3154 | else |
| 3155 | { |
| 3156 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3157 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3158 | } |
| 3159 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3160 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3161 | { |
| 3162 | if(CPUID::supportsMMX2()) |
| 3163 | { |
| 3164 | return As<UShort4>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 3165 | } |
| 3166 | else |
| 3167 | { |
| 3168 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3173 | { |
| 3174 | if(CPUID::supportsMMX2()) |
| 3175 | { |
| 3176 | return As<UShort4>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 3177 | } |
| 3178 | else |
| 3179 | { |
| 3180 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3185 | { |
| 3186 | if(CPUID::supportsMMX2()) |
| 3187 | { |
| 3188 | return As<UShort4>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 3189 | } |
| 3190 | else |
| 3191 | { |
| 3192 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3193 | } |
| 3194 | } |
| 3195 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3196 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3197 | { |
| 3198 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3199 | |
| 3200 | return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs)); |
| 3201 | } |
| 3202 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3203 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3204 | { |
| 3205 | // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 3206 | |
| 3207 | return x86::psrlw(lhs, rhs); |
| 3208 | } |
| 3209 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3210 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3211 | { |
| 3212 | return lhs = lhs << rhs; |
| 3213 | } |
| 3214 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3215 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3216 | { |
| 3217 | return lhs = lhs >> rhs; |
| 3218 | } |
| 3219 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3220 | RValue<UShort4> operator~(RValue<UShort4> val) |
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 As<UShort4>(As<Short4>(val) ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu)); |
| 3225 | } |
| 3226 | else |
| 3227 | { |
| 3228 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
| 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 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3233 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3234 | 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] | 3235 | } |
| 3236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3237 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3238 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3239 | 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] | 3240 | } |
| 3241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3242 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3243 | { |
| 3244 | return x86::paddusw(x, y); |
| 3245 | } |
| 3246 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3247 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3248 | { |
| 3249 | return x86::psubusw(x, y); |
| 3250 | } |
| 3251 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3252 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3253 | { |
| 3254 | return x86::pmulhuw(x, y); |
| 3255 | } |
| 3256 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3257 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3258 | { |
| 3259 | return x86::pavgw(x, y); |
| 3260 | } |
| 3261 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3262 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3263 | { |
| 3264 | return x86::packuswb(x, y); |
| 3265 | } |
| 3266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3267 | Type *UShort4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3268 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3269 | if(CPUID::supportsMMX2()) |
| 3270 | { |
| 3271 | return MMX::getType(); |
| 3272 | } |
| 3273 | else |
| 3274 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3275 | return T(VectorType::get(UShort::getType(), 4)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3276 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3277 | } |
| 3278 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3279 | Short8::Short8(short c) |
| 3280 | { |
| 3281 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3282 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3283 | } |
| 3284 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3285 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3286 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3287 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3288 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3289 | } |
| 3290 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3291 | Short8::Short8(RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3292 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3293 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3294 | } |
| 3295 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3296 | Short8::Short8(const Reference<Short8> &rhs) |
| 3297 | { |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3298 | Value *value = rhs.loadValue(); |
| 3299 | storeValue(value); |
| 3300 | } |
| 3301 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3302 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3303 | { |
| 3304 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 3305 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 3306 | |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 3307 | Value *long2 = V(UndefValue::get(VectorType::get(Long::getType(), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3308 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 3309 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 3310 | Value *short8 = Nucleus::createBitCast(long2, Short8::getType()); |
| 3311 | |
| 3312 | storeValue(short8); |
| 3313 | } |
| 3314 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3315 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3316 | { |
| 3317 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3318 | } |
| 3319 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3320 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3321 | { |
| 3322 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3323 | } |
| 3324 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3325 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3326 | { |
| 3327 | return x86::psllw(lhs, rhs); // FIXME: Fallback required |
| 3328 | } |
| 3329 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3330 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3331 | { |
| 3332 | return x86::psraw(lhs, rhs); // FIXME: Fallback required |
| 3333 | } |
| 3334 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3335 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3336 | { |
| 3337 | return x86::pmaddwd(x, y); // FIXME: Fallback required |
| 3338 | } |
| 3339 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 3340 | RValue<Int4> Abs(RValue<Int4> x) |
| 3341 | { |
| 3342 | if(CPUID::supportsSSSE3()) |
| 3343 | { |
| 3344 | return x86::pabsd(x); |
| 3345 | } |
| 3346 | else |
| 3347 | { |
| 3348 | Int4 mask = (x >> 31); |
| 3349 | return (mask ^ x) - mask; |
| 3350 | } |
| 3351 | } |
| 3352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3353 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3354 | { |
| 3355 | return x86::pmulhw(x, y); // FIXME: Fallback required |
| 3356 | } |
| 3357 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3358 | Type *Short8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3359 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3360 | return T(VectorType::get(Short::getType(), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3361 | } |
| 3362 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3363 | UShort8::UShort8(unsigned short c) |
| 3364 | { |
| 3365 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3366 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3367 | } |
| 3368 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3369 | 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) |
| 3370 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3371 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3372 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3373 | } |
| 3374 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3375 | UShort8::UShort8(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3376 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3377 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3378 | } |
| 3379 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3380 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3381 | { |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3382 | Value *value = rhs.loadValue(); |
| 3383 | storeValue(value); |
| 3384 | } |
| 3385 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3386 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3387 | { |
| 3388 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 3389 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 3390 | |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 3391 | Value *long2 = V(UndefValue::get(VectorType::get(Long::getType(), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3392 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 3393 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 3394 | Value *short8 = Nucleus::createBitCast(long2, Short8::getType()); |
| 3395 | |
| 3396 | storeValue(short8); |
| 3397 | } |
| 3398 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3399 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3400 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3401 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3402 | |
| 3403 | return rhs; |
| 3404 | } |
| 3405 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3406 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3407 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3408 | Value *value = rhs.loadValue(); |
| 3409 | storeValue(value); |
| 3410 | |
| 3411 | return RValue<UShort8>(value); |
| 3412 | } |
| 3413 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3414 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3415 | { |
| 3416 | Value *value = rhs.loadValue(); |
| 3417 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3418 | |
| 3419 | return RValue<UShort8>(value); |
| 3420 | } |
| 3421 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3422 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3423 | { |
| 3424 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3425 | } |
| 3426 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3427 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3428 | { |
| 3429 | return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required |
| 3430 | } |
| 3431 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3432 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3433 | { |
| 3434 | return x86::psrlw(lhs, rhs); // FIXME: Fallback required |
| 3435 | } |
| 3436 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3437 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3438 | { |
| 3439 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3440 | } |
| 3441 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3442 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3443 | { |
| 3444 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3445 | } |
| 3446 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3447 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3448 | { |
| 3449 | return lhs = lhs + rhs; |
| 3450 | } |
| 3451 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3452 | RValue<UShort8> operator~(RValue<UShort8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3453 | { |
| 3454 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3455 | } |
| 3456 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3457 | 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] | 3458 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 3459 | int pshufb[16] = |
| 3460 | { |
| 3461 | select0 + 0, |
| 3462 | select0 + 1, |
| 3463 | select1 + 0, |
| 3464 | select1 + 1, |
| 3465 | select2 + 0, |
| 3466 | select2 + 1, |
| 3467 | select3 + 0, |
| 3468 | select3 + 1, |
| 3469 | select4 + 0, |
| 3470 | select4 + 1, |
| 3471 | select5 + 0, |
| 3472 | select5 + 1, |
| 3473 | select6 + 0, |
| 3474 | select6 + 1, |
| 3475 | select7 + 0, |
| 3476 | select7 + 1, |
| 3477 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3478 | |
| 3479 | Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 3480 | Value *shuffle = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3481 | Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType()); |
| 3482 | |
| 3483 | return RValue<UShort8>(short8); |
| 3484 | } |
| 3485 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3486 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3487 | { |
| 3488 | return x86::pmulhuw(x, y); // FIXME: Fallback required |
| 3489 | } |
| 3490 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3491 | Type *UShort8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3492 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3493 | return T(VectorType::get(UShort::getType(), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3494 | } |
| 3495 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3496 | Int::Int(Argument<Int> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3497 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3498 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3499 | } |
| 3500 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3501 | Int::Int(RValue<Byte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3502 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3503 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3504 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3505 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3506 | } |
| 3507 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3508 | Int::Int(RValue<SByte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3509 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3510 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3511 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3512 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3513 | } |
| 3514 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3515 | Int::Int(RValue<Short> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3516 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3517 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3518 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3519 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3520 | } |
| 3521 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3522 | Int::Int(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3523 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3524 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3525 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3526 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3527 | } |
| 3528 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3529 | Int::Int(RValue<Int2> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3530 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3531 | *this = Extract(cast, 0); |
| 3532 | } |
| 3533 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3534 | Int::Int(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3535 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3536 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3537 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3538 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3539 | } |
| 3540 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3541 | Int::Int(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3542 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3543 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3544 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3545 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3546 | } |
| 3547 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3548 | Int::Int(int x) |
| 3549 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3550 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3551 | } |
| 3552 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3553 | Int::Int(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3554 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3555 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3556 | } |
| 3557 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3558 | Int::Int(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3559 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3560 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | Int::Int(const Int &rhs) |
| 3564 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3565 | Value *value = rhs.loadValue(); |
| 3566 | storeValue(value); |
| 3567 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3568 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3569 | Int::Int(const Reference<Int> &rhs) |
| 3570 | { |
| 3571 | Value *value = rhs.loadValue(); |
| 3572 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | Int::Int(const UInt &rhs) |
| 3576 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3577 | Value *value = rhs.loadValue(); |
| 3578 | storeValue(value); |
| 3579 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3580 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3581 | Int::Int(const Reference<UInt> &rhs) |
| 3582 | { |
| 3583 | Value *value = rhs.loadValue(); |
| 3584 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3585 | } |
| 3586 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3587 | RValue<Int> Int::operator=(int rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3588 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3589 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3590 | } |
| 3591 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3592 | RValue<Int> Int::operator=(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3593 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3594 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3595 | |
| 3596 | return rhs; |
| 3597 | } |
| 3598 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3599 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3600 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3601 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3602 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3603 | return RValue<Int>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3604 | } |
| 3605 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3606 | RValue<Int> Int::operator=(const Int &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3607 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3608 | Value *value = rhs.loadValue(); |
| 3609 | storeValue(value); |
| 3610 | |
| 3611 | return RValue<Int>(value); |
| 3612 | } |
| 3613 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3614 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3615 | { |
| 3616 | Value *value = rhs.loadValue(); |
| 3617 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3618 | |
| 3619 | return RValue<Int>(value); |
| 3620 | } |
| 3621 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3622 | RValue<Int> Int::operator=(const UInt &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3623 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3624 | Value *value = rhs.loadValue(); |
| 3625 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3626 | |
| 3627 | return RValue<Int>(value); |
| 3628 | } |
| 3629 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3630 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3631 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3632 | Value *value = rhs.loadValue(); |
| 3633 | storeValue(value); |
| 3634 | |
| 3635 | return RValue<Int>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3636 | } |
| 3637 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3638 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3639 | { |
| 3640 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3641 | } |
| 3642 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3643 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3644 | { |
| 3645 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3646 | } |
| 3647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3648 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3649 | { |
| 3650 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3651 | } |
| 3652 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3653 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3654 | { |
| 3655 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3656 | } |
| 3657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3658 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3659 | { |
| 3660 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3661 | } |
| 3662 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3663 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3664 | { |
| 3665 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3666 | } |
| 3667 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3668 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3669 | { |
| 3670 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3671 | } |
| 3672 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3673 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3674 | { |
| 3675 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3676 | } |
| 3677 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3678 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3679 | { |
| 3680 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3681 | } |
| 3682 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3683 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3684 | { |
| 3685 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3686 | } |
| 3687 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3688 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3689 | { |
| 3690 | return lhs = lhs + rhs; |
| 3691 | } |
| 3692 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3693 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3694 | { |
| 3695 | return lhs = lhs - rhs; |
| 3696 | } |
| 3697 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3698 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3699 | { |
| 3700 | return lhs = lhs * rhs; |
| 3701 | } |
| 3702 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3703 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3704 | { |
| 3705 | return lhs = lhs / rhs; |
| 3706 | } |
| 3707 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3708 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3709 | { |
| 3710 | return lhs = lhs % rhs; |
| 3711 | } |
| 3712 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3713 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3714 | { |
| 3715 | return lhs = lhs & rhs; |
| 3716 | } |
| 3717 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3718 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3719 | { |
| 3720 | return lhs = lhs | rhs; |
| 3721 | } |
| 3722 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3723 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3724 | { |
| 3725 | return lhs = lhs ^ rhs; |
| 3726 | } |
| 3727 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3728 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3729 | { |
| 3730 | return lhs = lhs << rhs; |
| 3731 | } |
| 3732 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3733 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3734 | { |
| 3735 | return lhs = lhs >> rhs; |
| 3736 | } |
| 3737 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3738 | RValue<Int> operator+(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3739 | { |
| 3740 | return val; |
| 3741 | } |
| 3742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3743 | RValue<Int> operator-(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3744 | { |
| 3745 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 3746 | } |
| 3747 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3748 | RValue<Int> operator~(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3749 | { |
| 3750 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 3751 | } |
| 3752 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3753 | RValue<Int> operator++(Int &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3754 | { |
| 3755 | RValue<Int> res = val; |
| 3756 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3757 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3758 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3759 | |
| 3760 | return res; |
| 3761 | } |
| 3762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3763 | const Int &operator++(Int &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3764 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3765 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3766 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3767 | |
| 3768 | return val; |
| 3769 | } |
| 3770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3771 | RValue<Int> operator--(Int &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3772 | { |
| 3773 | RValue<Int> res = val; |
| 3774 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3775 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3776 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3777 | |
| 3778 | return res; |
| 3779 | } |
| 3780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3781 | const Int &operator--(Int &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3782 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3783 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3784 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3785 | |
| 3786 | return val; |
| 3787 | } |
| 3788 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3789 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3790 | { |
| 3791 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 3792 | } |
| 3793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3794 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3795 | { |
| 3796 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 3797 | } |
| 3798 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3799 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3800 | { |
| 3801 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 3802 | } |
| 3803 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3804 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3805 | { |
| 3806 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 3807 | } |
| 3808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3809 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3810 | { |
| 3811 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 3812 | } |
| 3813 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3814 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3815 | { |
| 3816 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 3817 | } |
| 3818 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3819 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 3820 | { |
| 3821 | return IfThenElse(x > y, x, y); |
| 3822 | } |
| 3823 | |
| 3824 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 3825 | { |
| 3826 | return IfThenElse(x < y, x, y); |
| 3827 | } |
| 3828 | |
| 3829 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 3830 | { |
| 3831 | return Min(Max(x, min), max); |
| 3832 | } |
| 3833 | |
| 3834 | RValue<Int> RoundInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3835 | { |
| 3836 | return x86::cvtss2si(cast); |
| 3837 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3838 | // 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] | 3839 | } |
| 3840 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3841 | Type *Int::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3842 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3843 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3844 | } |
| 3845 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3846 | Long::Long(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3847 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3848 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 3849 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3850 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3851 | } |
| 3852 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3853 | Long::Long(RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3854 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3855 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 3856 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3857 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3858 | } |
| 3859 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3860 | Long::Long(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3861 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3862 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3863 | } |
| 3864 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3865 | RValue<Long> Long::operator=(int64_t rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3866 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3867 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3868 | } |
| 3869 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3870 | RValue<Long> Long::operator=(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3871 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3872 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3873 | |
| 3874 | return rhs; |
| 3875 | } |
| 3876 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3877 | RValue<Long> Long::operator=(const Long &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3878 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3879 | Value *value = rhs.loadValue(); |
| 3880 | storeValue(value); |
| 3881 | |
| 3882 | return RValue<Long>(value); |
| 3883 | } |
| 3884 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3885 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3886 | { |
| 3887 | Value *value = rhs.loadValue(); |
| 3888 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3889 | |
| 3890 | return RValue<Long>(value); |
| 3891 | } |
| 3892 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3893 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3894 | { |
| 3895 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3896 | } |
| 3897 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3898 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3899 | { |
| 3900 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3901 | } |
| 3902 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3903 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3904 | { |
| 3905 | return lhs = lhs + rhs; |
| 3906 | } |
| 3907 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3908 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3909 | { |
| 3910 | return lhs = lhs - rhs; |
| 3911 | } |
| 3912 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3913 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3914 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3915 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3916 | } |
| 3917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3918 | Type *Long::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3919 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3920 | return T(llvm::Type::getInt64Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3921 | } |
| 3922 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3923 | UInt::UInt(Argument<UInt> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3924 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3925 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3926 | } |
| 3927 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3928 | UInt::UInt(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3929 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3930 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 3931 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3932 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3933 | } |
| 3934 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3935 | UInt::UInt(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3936 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3937 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 3938 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3939 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3940 | } |
| 3941 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3942 | UInt::UInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3943 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 3944 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 3945 | // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3946 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 3947 | // Smallest positive value representable in UInt, but not in Int |
| 3948 | const unsigned int ustart = 0x80000000u; |
| 3949 | const float ustartf = float(ustart); |
| 3950 | |
| 3951 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 3952 | storeValue((~(As<Int>(cast) >> 31) & |
| 3953 | // Check if the value can be represented as an Int |
| 3954 | IfThenElse(cast >= ustartf, |
| 3955 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 3956 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 3957 | // Otherwise, just convert normally |
| 3958 | Int(cast))).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3959 | } |
| 3960 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3961 | UInt::UInt(int x) |
| 3962 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3963 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | UInt::UInt(unsigned int x) |
| 3967 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3968 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3969 | } |
| 3970 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3971 | UInt::UInt(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3972 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3973 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3974 | } |
| 3975 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3976 | UInt::UInt(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3977 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3978 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | UInt::UInt(const UInt &rhs) |
| 3982 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3983 | Value *value = rhs.loadValue(); |
| 3984 | storeValue(value); |
| 3985 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3986 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3987 | UInt::UInt(const Reference<UInt> &rhs) |
| 3988 | { |
| 3989 | Value *value = rhs.loadValue(); |
| 3990 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | UInt::UInt(const Int &rhs) |
| 3994 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3995 | Value *value = rhs.loadValue(); |
| 3996 | storeValue(value); |
| 3997 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3998 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3999 | UInt::UInt(const Reference<Int> &rhs) |
| 4000 | { |
| 4001 | Value *value = rhs.loadValue(); |
| 4002 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4003 | } |
| 4004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4005 | RValue<UInt> UInt::operator=(unsigned int rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4006 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4007 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4008 | } |
| 4009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4010 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4011 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4012 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4013 | |
| 4014 | return rhs; |
| 4015 | } |
| 4016 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4017 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4018 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4019 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4020 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4021 | return RValue<UInt>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4022 | } |
| 4023 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4024 | RValue<UInt> UInt::operator=(const UInt &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4025 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4026 | Value *value = rhs.loadValue(); |
| 4027 | storeValue(value); |
| 4028 | |
| 4029 | return RValue<UInt>(value); |
| 4030 | } |
| 4031 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4032 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4033 | { |
| 4034 | Value *value = rhs.loadValue(); |
| 4035 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4036 | |
| 4037 | return RValue<UInt>(value); |
| 4038 | } |
| 4039 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4040 | RValue<UInt> UInt::operator=(const Int &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4041 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4042 | Value *value = rhs.loadValue(); |
| 4043 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4044 | |
| 4045 | return RValue<UInt>(value); |
| 4046 | } |
| 4047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4048 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4049 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4050 | Value *value = rhs.loadValue(); |
| 4051 | storeValue(value); |
| 4052 | |
| 4053 | return RValue<UInt>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4054 | } |
| 4055 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4056 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4057 | { |
| 4058 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4059 | } |
| 4060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4061 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4062 | { |
| 4063 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4064 | } |
| 4065 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4066 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4067 | { |
| 4068 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4069 | } |
| 4070 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4071 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4072 | { |
| 4073 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4074 | } |
| 4075 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4076 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4077 | { |
| 4078 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4079 | } |
| 4080 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4081 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4082 | { |
| 4083 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4084 | } |
| 4085 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4086 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4087 | { |
| 4088 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4089 | } |
| 4090 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4091 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4092 | { |
| 4093 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4094 | } |
| 4095 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4096 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4097 | { |
| 4098 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4099 | } |
| 4100 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4101 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4102 | { |
| 4103 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4104 | } |
| 4105 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4106 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4107 | { |
| 4108 | return lhs = lhs + rhs; |
| 4109 | } |
| 4110 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4111 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4112 | { |
| 4113 | return lhs = lhs - rhs; |
| 4114 | } |
| 4115 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4116 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4117 | { |
| 4118 | return lhs = lhs * rhs; |
| 4119 | } |
| 4120 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4121 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4122 | { |
| 4123 | return lhs = lhs / rhs; |
| 4124 | } |
| 4125 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4126 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4127 | { |
| 4128 | return lhs = lhs % rhs; |
| 4129 | } |
| 4130 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4131 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4132 | { |
| 4133 | return lhs = lhs & rhs; |
| 4134 | } |
| 4135 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4136 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4137 | { |
| 4138 | return lhs = lhs | rhs; |
| 4139 | } |
| 4140 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4141 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4142 | { |
| 4143 | return lhs = lhs ^ rhs; |
| 4144 | } |
| 4145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4146 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4147 | { |
| 4148 | return lhs = lhs << rhs; |
| 4149 | } |
| 4150 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4151 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4152 | { |
| 4153 | return lhs = lhs >> rhs; |
| 4154 | } |
| 4155 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4156 | RValue<UInt> operator+(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4157 | { |
| 4158 | return val; |
| 4159 | } |
| 4160 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4161 | RValue<UInt> operator-(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4162 | { |
| 4163 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4164 | } |
| 4165 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4166 | RValue<UInt> operator~(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4167 | { |
| 4168 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4169 | } |
| 4170 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4171 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4172 | { |
| 4173 | RValue<UInt> res = val; |
| 4174 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4175 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4176 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4177 | |
| 4178 | return res; |
| 4179 | } |
| 4180 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4181 | const UInt &operator++(UInt &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4182 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4183 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4184 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4185 | |
| 4186 | return val; |
| 4187 | } |
| 4188 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4189 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4190 | { |
| 4191 | RValue<UInt> res = val; |
| 4192 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4193 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4194 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4195 | |
| 4196 | return res; |
| 4197 | } |
| 4198 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4199 | const UInt &operator--(UInt &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4200 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4201 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4202 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4203 | |
| 4204 | return val; |
| 4205 | } |
| 4206 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4207 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4208 | { |
| 4209 | return IfThenElse(x > y, x, y); |
| 4210 | } |
| 4211 | |
| 4212 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4213 | { |
| 4214 | return IfThenElse(x < y, x, y); |
| 4215 | } |
| 4216 | |
| 4217 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4218 | { |
| 4219 | return Min(Max(x, min), max); |
| 4220 | } |
| 4221 | |
| 4222 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4223 | { |
| 4224 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4225 | } |
| 4226 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4227 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4228 | { |
| 4229 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4230 | } |
| 4231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4232 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4233 | { |
| 4234 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4235 | } |
| 4236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4237 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4238 | { |
| 4239 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4240 | } |
| 4241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4242 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4243 | { |
| 4244 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4245 | } |
| 4246 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4247 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4248 | { |
| 4249 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4250 | } |
| 4251 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4252 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4253 | // { |
| 4254 | // return x86::cvtss2si(val); // FIXME: Unsigned |
| 4255 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4256 | // // 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] | 4257 | // } |
| 4258 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4259 | Type *UInt::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4260 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 4261 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4262 | } |
| 4263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4264 | // Int2::Int2(RValue<Int> cast) |
| 4265 | // { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4266 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4267 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4268 | // |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4269 | // int shuffle[2] = {0, 0}; |
| 4270 | // Value *replicate = Nucleus::createShuffleVector(vector, vector, shuffle); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4271 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4272 | // storeValue(replicate); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4273 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4274 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4275 | Int2::Int2(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4276 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4277 | Value *long2 = Nucleus::createBitCast(cast.value, T(VectorType::get(Long::getType(), 2))); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 4278 | Value *element = Nucleus::createExtractElement(long2, Long::getType(), 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4279 | Value *int2 = Nucleus::createBitCast(element, Int2::getType()); |
| 4280 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4281 | storeValue(int2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4282 | } |
| 4283 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4284 | Int2::Int2(int x, int y) |
| 4285 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4286 | int64_t constantVector[2] = {x, y}; |
| 4287 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Int::getType(), 2)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4288 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4289 | storeValue(Nucleus::createBitCast(vector, getType())); |
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 | Int2::Int2(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4293 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4294 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | Int2::Int2(const Int2 &rhs) |
| 4298 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4299 | Value *value = rhs.loadValue(); |
| 4300 | storeValue(value); |
| 4301 | } |
| 4302 | |
| 4303 | Int2::Int2(const Reference<Int2> &rhs) |
| 4304 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4305 | Value *value = rhs.loadValue(); |
| 4306 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4307 | } |
| 4308 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4309 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4310 | { |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4311 | if(CPUID::supportsMMX2()) |
| 4312 | { |
| 4313 | // movd mm0, lo |
| 4314 | // movd mm1, hi |
| 4315 | // punpckldq mm0, mm1 |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4316 | |
| 4317 | Value *loLong = Nucleus::createInsertElement(V(UndefValue::get(VectorType::get(Int::getType(), 2))), lo.value, 0); |
| 4318 | loLong = Nucleus::createInsertElement(loLong, V(ConstantInt::get(Int::getType(), 0)), 1); |
| 4319 | Value *hiLong = Nucleus::createInsertElement(V(UndefValue::get(VectorType::get(Int::getType(), 2))), hi.value, 0); |
| 4320 | hiLong = Nucleus::createInsertElement(hiLong, V(ConstantInt::get(Int::getType(), 0)), 1); |
| 4321 | |
| 4322 | storeValue(As<Int2>(UnpackLow(As<Int2>(loLong), As<Int2>(hiLong))).value); |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4323 | } |
| 4324 | else |
| 4325 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4326 | int shuffle[2] = {0, 1}; |
| 4327 | Value *packed = Nucleus::createShuffleVector(Nucleus::createBitCast(lo.value, T(VectorType::get(Int::getType(), 1))), Nucleus::createBitCast(hi.value, T(VectorType::get(Int::getType(), 1))), shuffle); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4328 | |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4329 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
| 4330 | } |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4331 | } |
| 4332 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4333 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4334 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4335 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4336 | |
| 4337 | return rhs; |
| 4338 | } |
| 4339 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4340 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4341 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4342 | Value *value = rhs.loadValue(); |
| 4343 | storeValue(value); |
| 4344 | |
| 4345 | return RValue<Int2>(value); |
| 4346 | } |
| 4347 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4348 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4349 | { |
| 4350 | Value *value = rhs.loadValue(); |
| 4351 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4352 | |
| 4353 | return RValue<Int2>(value); |
| 4354 | } |
| 4355 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4356 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4357 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4358 | if(CPUID::supportsMMX2()) |
| 4359 | { |
| 4360 | return x86::paddd(lhs, rhs); |
| 4361 | } |
| 4362 | else |
| 4363 | { |
| 4364 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4365 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4366 | } |
| 4367 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4368 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4369 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4370 | if(CPUID::supportsMMX2()) |
| 4371 | { |
| 4372 | return x86::psubd(lhs, rhs); |
| 4373 | } |
| 4374 | else |
| 4375 | { |
| 4376 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4377 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4378 | } |
| 4379 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4380 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4381 | // { |
| 4382 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4383 | // } |
| 4384 | |
| 4385 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4386 | // { |
| 4387 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4388 | // } |
| 4389 | |
| 4390 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4391 | // { |
| 4392 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4393 | // } |
| 4394 | |
| 4395 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4396 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4397 | if(CPUID::supportsMMX2()) |
| 4398 | { |
| 4399 | return As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 4400 | } |
| 4401 | else |
| 4402 | { |
| 4403 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4404 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4405 | } |
| 4406 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4407 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4408 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4409 | if(CPUID::supportsMMX2()) |
| 4410 | { |
| 4411 | return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 4412 | } |
| 4413 | else |
| 4414 | { |
| 4415 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4416 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4417 | } |
| 4418 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4419 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4420 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4421 | if(CPUID::supportsMMX2()) |
| 4422 | { |
| 4423 | return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 4424 | } |
| 4425 | else |
| 4426 | { |
| 4427 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4428 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4429 | } |
| 4430 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4431 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4432 | { |
| 4433 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4434 | |
| 4435 | return x86::pslld(lhs, rhs); |
| 4436 | } |
| 4437 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4438 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4439 | { |
| 4440 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4441 | |
| 4442 | return x86::psrad(lhs, rhs); |
| 4443 | } |
| 4444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4445 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4446 | { |
| 4447 | return lhs = lhs + rhs; |
| 4448 | } |
| 4449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4450 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4451 | { |
| 4452 | return lhs = lhs - rhs; |
| 4453 | } |
| 4454 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4455 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4456 | // { |
| 4457 | // return lhs = lhs * rhs; |
| 4458 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4460 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4461 | // { |
| 4462 | // return lhs = lhs / rhs; |
| 4463 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4464 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4465 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4466 | // { |
| 4467 | // return lhs = lhs % rhs; |
| 4468 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4470 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4471 | { |
| 4472 | return lhs = lhs & rhs; |
| 4473 | } |
| 4474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4475 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4476 | { |
| 4477 | return lhs = lhs | rhs; |
| 4478 | } |
| 4479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4480 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4481 | { |
| 4482 | return lhs = lhs ^ rhs; |
| 4483 | } |
| 4484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4485 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4486 | { |
| 4487 | return lhs = lhs << rhs; |
| 4488 | } |
| 4489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4490 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char 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<Int2> operator+(RValue<Int2> val) |
| 4496 | // { |
| 4497 | // return val; |
| 4498 | // } |
| 4499 | |
| 4500 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4501 | // { |
| 4502 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4503 | // } |
| 4504 | |
| 4505 | RValue<Int2> operator~(RValue<Int2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4506 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4507 | if(CPUID::supportsMMX2()) |
| 4508 | { |
| 4509 | return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF); |
| 4510 | } |
| 4511 | else |
| 4512 | { |
| 4513 | return RValue<Int2>(Nucleus::createNot(val.value)); |
| 4514 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4515 | } |
| 4516 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4517 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4518 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4519 | if(CPUID::supportsMMX2()) |
| 4520 | { |
| 4521 | return x86::punpckldq(x, y); |
| 4522 | } |
| 4523 | else |
| 4524 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4525 | int shuffle[2] = {0, 2}; |
| 4526 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4527 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4528 | return As<Short4>(packed); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4529 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4530 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4531 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4532 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4533 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4534 | if(CPUID::supportsMMX2()) |
| 4535 | { |
| 4536 | return x86::punpckhdq(x, y); |
| 4537 | } |
| 4538 | else |
| 4539 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4540 | int shuffle[2] = {1, 3}; |
| 4541 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4542 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4543 | return As<Short4>(packed); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4544 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4545 | } |
| 4546 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4547 | RValue<Int> Extract(RValue<Int2> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4548 | { |
| 4549 | if(false) // FIXME: LLVM does not generate optimal code |
| 4550 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 4551 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4552 | } |
| 4553 | else |
| 4554 | { |
| 4555 | if(i == 0) |
| 4556 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 4557 | return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, T(VectorType::get(Int::getType(), 2))), Int::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4558 | } |
| 4559 | else |
| 4560 | { |
| 4561 | Int2 val2 = As<Int2>(UnpackHigh(val, val)); |
| 4562 | |
| 4563 | return Extract(val2, 0); |
| 4564 | } |
| 4565 | } |
| 4566 | } |
| 4567 | |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4568 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4569 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 4570 | 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] | 4571 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4572 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4573 | Type *Int2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4574 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4575 | if(CPUID::supportsMMX2()) |
| 4576 | { |
| 4577 | return MMX::getType(); |
| 4578 | } |
| 4579 | else |
| 4580 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 4581 | return T(VectorType::get(Int::getType(), 2)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4582 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4583 | } |
| 4584 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4585 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4586 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4587 | int64_t constantVector[2] = {x, y}; |
| 4588 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(UInt::getType(), 2)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4589 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4590 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4591 | } |
| 4592 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4593 | UInt2::UInt2(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4594 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4595 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | UInt2::UInt2(const UInt2 &rhs) |
| 4599 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4600 | Value *value = rhs.loadValue(); |
| 4601 | storeValue(value); |
| 4602 | } |
| 4603 | |
| 4604 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4605 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4606 | Value *value = rhs.loadValue(); |
| 4607 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4608 | } |
| 4609 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4610 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4611 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4612 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4613 | |
| 4614 | return rhs; |
| 4615 | } |
| 4616 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4617 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4618 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4619 | Value *value = rhs.loadValue(); |
| 4620 | storeValue(value); |
| 4621 | |
| 4622 | return RValue<UInt2>(value); |
| 4623 | } |
| 4624 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4625 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4626 | { |
| 4627 | Value *value = rhs.loadValue(); |
| 4628 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4629 | |
| 4630 | return RValue<UInt2>(value); |
| 4631 | } |
| 4632 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4633 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4634 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4635 | if(CPUID::supportsMMX2()) |
| 4636 | { |
| 4637 | return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs))); |
| 4638 | } |
| 4639 | else |
| 4640 | { |
| 4641 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4642 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4643 | } |
| 4644 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4645 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4646 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4647 | if(CPUID::supportsMMX2()) |
| 4648 | { |
| 4649 | return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs))); |
| 4650 | } |
| 4651 | else |
| 4652 | { |
| 4653 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4654 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4655 | } |
| 4656 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4657 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4658 | // { |
| 4659 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4660 | // } |
| 4661 | |
| 4662 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4663 | // { |
| 4664 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4665 | // } |
| 4666 | |
| 4667 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4668 | // { |
| 4669 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4670 | // } |
| 4671 | |
| 4672 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4673 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4674 | if(CPUID::supportsMMX2()) |
| 4675 | { |
| 4676 | return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 4677 | } |
| 4678 | else |
| 4679 | { |
| 4680 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4681 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4682 | } |
| 4683 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4684 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4685 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4686 | if(CPUID::supportsMMX2()) |
| 4687 | { |
| 4688 | return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 4689 | } |
| 4690 | else |
| 4691 | { |
| 4692 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4693 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4694 | } |
| 4695 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4696 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4697 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4698 | if(CPUID::supportsMMX2()) |
| 4699 | { |
| 4700 | return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 4701 | } |
| 4702 | else |
| 4703 | { |
| 4704 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4705 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4706 | } |
| 4707 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4708 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4709 | { |
| 4710 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4711 | |
| 4712 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 4713 | } |
| 4714 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4715 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4716 | { |
| 4717 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4718 | |
| 4719 | return x86::psrld(lhs, rhs); |
| 4720 | } |
| 4721 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4722 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4723 | { |
| 4724 | return lhs = lhs + rhs; |
| 4725 | } |
| 4726 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4727 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4728 | { |
| 4729 | return lhs = lhs - rhs; |
| 4730 | } |
| 4731 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4732 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4733 | // { |
| 4734 | // return lhs = lhs * rhs; |
| 4735 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4736 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4737 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4738 | // { |
| 4739 | // return lhs = lhs / rhs; |
| 4740 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4742 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4743 | // { |
| 4744 | // return lhs = lhs % rhs; |
| 4745 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4746 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4747 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4748 | { |
| 4749 | return lhs = lhs & rhs; |
| 4750 | } |
| 4751 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4752 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4753 | { |
| 4754 | return lhs = lhs | rhs; |
| 4755 | } |
| 4756 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4757 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4758 | { |
| 4759 | return lhs = lhs ^ rhs; |
| 4760 | } |
| 4761 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4762 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4763 | { |
| 4764 | return lhs = lhs << rhs; |
| 4765 | } |
| 4766 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4767 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4768 | { |
| 4769 | return lhs = lhs >> rhs; |
| 4770 | } |
| 4771 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4772 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4773 | // { |
| 4774 | // return val; |
| 4775 | // } |
| 4776 | |
| 4777 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4778 | // { |
| 4779 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4780 | // } |
| 4781 | |
| 4782 | RValue<UInt2> operator~(RValue<UInt2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4783 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4784 | if(CPUID::supportsMMX2()) |
| 4785 | { |
| 4786 | return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF); |
| 4787 | } |
| 4788 | else |
| 4789 | { |
| 4790 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4791 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4792 | } |
| 4793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4794 | Type *UInt2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4795 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4796 | if(CPUID::supportsMMX2()) |
| 4797 | { |
| 4798 | return MMX::getType(); |
| 4799 | } |
| 4800 | else |
| 4801 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 4802 | return T(VectorType::get(UInt::getType(), 2)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4803 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4804 | } |
| 4805 | |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4806 | Int4::Int4(RValue<Byte4> cast) |
| 4807 | { |
| 4808 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4809 | Value *a = Nucleus::createInsertElement(V(UndefValue::get(Int4::getType())), x, 0); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4810 | |
| 4811 | Value *e; |
| 4812 | |
| 4813 | if (CPUID::supportsSSE4_1()) |
| 4814 | { |
| 4815 | e = x86::pmovzxbd(RValue<Int4>(a)).value; |
| 4816 | } |
| 4817 | else |
| 4818 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4819 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4820 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4821 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4822 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4823 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4824 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4825 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4829 | storeValue(f); |
| 4830 | } |
| 4831 | |
| 4832 | Int4::Int4(RValue<SByte4> cast) |
| 4833 | { |
| 4834 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4835 | Value *a = Nucleus::createInsertElement(V(UndefValue::get(Int4::getType())), x, 0); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4836 | |
| 4837 | Value *g; |
| 4838 | |
| 4839 | if (CPUID::supportsSSE4_1()) |
| 4840 | { |
| 4841 | g = x86::pmovsxbd(RValue<Int4>(a)).value; |
| 4842 | } |
| 4843 | else |
| 4844 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4845 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4846 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4847 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4848 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4849 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4850 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4851 | Value *e = Nucleus::createShuffleVector(d, d, swizzle2); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4852 | |
| 4853 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4854 | // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24)); |
| 4855 | g = x86::psrad(RValue<Int4>(f), 24).value; |
| 4856 | } |
| 4857 | |
| 4858 | storeValue(g); |
| 4859 | } |
| 4860 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4861 | Int4::Int4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4862 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4863 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4864 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4865 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4866 | } |
| 4867 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4868 | Int4::Int4(RValue<Short4> cast) |
| 4869 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4870 | Value *long2 = V(UndefValue::get(VectorType::get(Long::getType(), 2))); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4871 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 4872 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 4873 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4874 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4875 | if(CPUID::supportsSSE4_1()) |
| 4876 | { |
| 4877 | storeValue(x86::pmovsxwd(vector).value); |
| 4878 | } |
| 4879 | else |
| 4880 | { |
| 4881 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 4882 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4883 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4884 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 4885 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4886 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4887 | |
| 4888 | // Each Short is packed into each Int in the (Short | Short) format. |
| 4889 | // Shifting by 16 will retrieve the original Short value. |
| 4890 | // Shitfing an Int will propagate the sign bit, which will work |
| 4891 | // for both positive and negative values of a Short. |
| 4892 | *this >>= 16; |
| 4893 | } |
| 4894 | } |
| 4895 | |
| 4896 | Int4::Int4(RValue<UShort4> cast) |
| 4897 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4898 | Value *long2 = V(UndefValue::get(VectorType::get(Long::getType(), 2))); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4899 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 4900 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 4901 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
| 4902 | |
| 4903 | if(CPUID::supportsSSE4_1()) |
| 4904 | { |
| 4905 | storeValue(x86::pmovzxwd(RValue<Int4>(vector)).value); |
| 4906 | } |
| 4907 | else |
| 4908 | { |
| 4909 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 4910 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4911 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4912 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Short8::getType())), swizzle); |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 4913 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4914 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4915 | } |
| 4916 | } |
| 4917 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4918 | Int4::Int4(int xyzw) |
| 4919 | { |
| 4920 | constant(xyzw, xyzw, xyzw, xyzw); |
| 4921 | } |
| 4922 | |
| 4923 | Int4::Int4(int x, int yzw) |
| 4924 | { |
| 4925 | constant(x, yzw, yzw, yzw); |
| 4926 | } |
| 4927 | |
| 4928 | Int4::Int4(int x, int y, int zw) |
| 4929 | { |
| 4930 | constant(x, y, zw, zw); |
| 4931 | } |
| 4932 | |
| 4933 | Int4::Int4(int x, int y, int z, int w) |
| 4934 | { |
| 4935 | constant(x, y, z, w); |
| 4936 | } |
| 4937 | |
| 4938 | void Int4::constant(int x, int y, int z, int w) |
| 4939 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4940 | int64_t constantVector[4] = {x, y, z, w}; |
| 4941 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4942 | } |
| 4943 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4944 | Int4::Int4(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4945 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4946 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | Int4::Int4(const Int4 &rhs) |
| 4950 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4951 | Value *value = rhs.loadValue(); |
| 4952 | storeValue(value); |
| 4953 | } |
| 4954 | |
| 4955 | Int4::Int4(const Reference<Int4> &rhs) |
| 4956 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4957 | Value *value = rhs.loadValue(); |
| 4958 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4959 | } |
| 4960 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4961 | Int4::Int4(RValue<UInt4> rhs) |
| 4962 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4963 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | Int4::Int4(const UInt4 &rhs) |
| 4967 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4968 | Value *value = rhs.loadValue(); |
| 4969 | storeValue(value); |
| 4970 | } |
| 4971 | |
| 4972 | Int4::Int4(const Reference<UInt4> &rhs) |
| 4973 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4974 | Value *value = rhs.loadValue(); |
| 4975 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4976 | } |
| 4977 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4978 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 4979 | { |
| 4980 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 4981 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 4982 | |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4983 | Value *long2 = V(UndefValue::get(VectorType::get(Long::getType(), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4984 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 4985 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 4986 | Value *int4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 4987 | |
| 4988 | storeValue(int4); |
| 4989 | } |
| 4990 | |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4991 | Int4::Int4(RValue<Int> rhs) |
| 4992 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4993 | Value *vector = loadValue(); |
| 4994 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 4995 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4996 | int swizzle[4] = {0, 0, 0, 0}; |
| 4997 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4998 | |
| 4999 | storeValue(replicate); |
| 5000 | } |
| 5001 | |
| 5002 | Int4::Int4(const Int &rhs) |
| 5003 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 5004 | *this = RValue<Int>(rhs.loadValue()); |
| 5005 | } |
| 5006 | |
| 5007 | Int4::Int4(const Reference<Int> &rhs) |
| 5008 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 5009 | *this = RValue<Int>(rhs.loadValue()); |
| 5010 | } |
| 5011 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5012 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5013 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5014 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5015 | |
| 5016 | return rhs; |
| 5017 | } |
| 5018 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5019 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5020 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5021 | Value *value = rhs.loadValue(); |
| 5022 | storeValue(value); |
| 5023 | |
| 5024 | return RValue<Int4>(value); |
| 5025 | } |
| 5026 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5027 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5028 | { |
| 5029 | Value *value = rhs.loadValue(); |
| 5030 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5031 | |
| 5032 | return RValue<Int4>(value); |
| 5033 | } |
| 5034 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5035 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5036 | { |
| 5037 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5038 | } |
| 5039 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5040 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5041 | { |
| 5042 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5043 | } |
| 5044 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5045 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5046 | { |
| 5047 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5048 | } |
| 5049 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5050 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5051 | { |
| 5052 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5053 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5054 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5055 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5056 | { |
| 5057 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5058 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5059 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5060 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5061 | { |
| 5062 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5063 | } |
| 5064 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5065 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5066 | { |
| 5067 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5068 | } |
| 5069 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5070 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5071 | { |
| 5072 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5073 | } |
| 5074 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5075 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5076 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5077 | return x86::pslld(lhs, rhs); |
| 5078 | } |
| 5079 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5080 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5081 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5082 | return x86::psrad(lhs, rhs); |
| 5083 | } |
| 5084 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5085 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5086 | { |
| 5087 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5088 | } |
| 5089 | |
| 5090 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5091 | { |
| 5092 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5093 | } |
| 5094 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5095 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5096 | { |
| 5097 | return lhs = lhs + rhs; |
| 5098 | } |
| 5099 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5100 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5101 | { |
| 5102 | return lhs = lhs - rhs; |
| 5103 | } |
| 5104 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5105 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5106 | { |
| 5107 | return lhs = lhs * rhs; |
| 5108 | } |
| 5109 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5110 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5111 | // { |
| 5112 | // return lhs = lhs / rhs; |
| 5113 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5114 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5115 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5116 | // { |
| 5117 | // return lhs = lhs % rhs; |
| 5118 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5119 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5120 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5121 | { |
| 5122 | return lhs = lhs & rhs; |
| 5123 | } |
| 5124 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5125 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5126 | { |
| 5127 | return lhs = lhs | rhs; |
| 5128 | } |
| 5129 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5130 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5131 | { |
| 5132 | return lhs = lhs ^ rhs; |
| 5133 | } |
| 5134 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5135 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5136 | { |
| 5137 | return lhs = lhs << rhs; |
| 5138 | } |
| 5139 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5140 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5141 | { |
| 5142 | return lhs = lhs >> rhs; |
| 5143 | } |
| 5144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5145 | RValue<Int4> operator+(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5146 | { |
| 5147 | return val; |
| 5148 | } |
| 5149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5150 | RValue<Int4> operator-(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5151 | { |
| 5152 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5153 | } |
| 5154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5155 | RValue<Int4> operator~(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5156 | { |
| 5157 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5158 | } |
| 5159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5160 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5161 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5162 | // 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] | 5163 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5164 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5165 | 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] | 5166 | } |
| 5167 | |
| 5168 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5169 | { |
| 5170 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5171 | } |
| 5172 | |
| 5173 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5174 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5175 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5176 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5177 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5178 | 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] | 5179 | } |
| 5180 | |
| 5181 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5182 | { |
| 5183 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5184 | } |
| 5185 | |
| 5186 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5187 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5188 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5189 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5190 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5191 | 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] | 5192 | } |
| 5193 | |
| 5194 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5195 | { |
| 5196 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5197 | } |
| 5198 | |
| 5199 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5200 | { |
| 5201 | if(CPUID::supportsSSE4_1()) |
| 5202 | { |
| 5203 | return x86::pmaxsd(x, y); |
| 5204 | } |
| 5205 | else |
| 5206 | { |
| 5207 | RValue<Int4> greater = CmpNLE(x, y); |
| 5208 | return x & greater | y & ~greater; |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5213 | { |
| 5214 | if(CPUID::supportsSSE4_1()) |
| 5215 | { |
| 5216 | return x86::pminsd(x, y); |
| 5217 | } |
| 5218 | else |
| 5219 | { |
| 5220 | RValue<Int4> less = CmpLT(x, y); |
| 5221 | return x & less | y & ~less; |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | RValue<Int4> RoundInt(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5226 | { |
| 5227 | return x86::cvtps2dq(cast); |
| 5228 | } |
| 5229 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5230 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5231 | { |
| 5232 | return x86::packssdw(x, y); |
| 5233 | } |
| 5234 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5235 | RValue<Int> Extract(RValue<Int4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5236 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5237 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5238 | } |
| 5239 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5240 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5241 | { |
| 5242 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5243 | } |
| 5244 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5245 | RValue<Int> SignMask(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5246 | { |
| 5247 | return x86::movmskps(As<Float4>(x)); |
| 5248 | } |
| 5249 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5250 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5251 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5252 | return RValue<Int4>(createSwizzle4(x.value, select)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5253 | } |
| 5254 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5255 | Type *Int4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5256 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 5257 | return T(VectorType::get(Int::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5260 | UInt4::UInt4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5261 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 5262 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 5263 | // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5264 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 5265 | // Smallest positive value representable in UInt, but not in Int |
| 5266 | const unsigned int ustart = 0x80000000u; |
| 5267 | const float ustartf = float(ustart); |
| 5268 | |
| 5269 | // Check if the value can be represented as an Int |
| 5270 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5271 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5272 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5273 | // Otherwise, just convert normally |
| 5274 | (~uiValue & Int4(cast)); |
| 5275 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5276 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5277 | } |
| 5278 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5279 | UInt4::UInt4(int xyzw) |
| 5280 | { |
| 5281 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5282 | } |
| 5283 | |
| 5284 | UInt4::UInt4(int x, int yzw) |
| 5285 | { |
| 5286 | constant(x, yzw, yzw, yzw); |
| 5287 | } |
| 5288 | |
| 5289 | UInt4::UInt4(int x, int y, int zw) |
| 5290 | { |
| 5291 | constant(x, y, zw, zw); |
| 5292 | } |
| 5293 | |
| 5294 | UInt4::UInt4(int x, int y, int z, int w) |
| 5295 | { |
| 5296 | constant(x, y, z, w); |
| 5297 | } |
| 5298 | |
| 5299 | void UInt4::constant(int x, int y, int z, int w) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5300 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5301 | int64_t constantVector[4] = {x, y, z, w}; |
| 5302 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5303 | } |
| 5304 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5305 | UInt4::UInt4(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5306 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5307 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | UInt4::UInt4(const UInt4 &rhs) |
| 5311 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5312 | Value *value = rhs.loadValue(); |
| 5313 | storeValue(value); |
| 5314 | } |
| 5315 | |
| 5316 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5317 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5318 | Value *value = rhs.loadValue(); |
| 5319 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5320 | } |
| 5321 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5322 | UInt4::UInt4(RValue<Int4> rhs) |
| 5323 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5324 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | UInt4::UInt4(const Int4 &rhs) |
| 5328 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5329 | Value *value = rhs.loadValue(); |
| 5330 | storeValue(value); |
| 5331 | } |
| 5332 | |
| 5333 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5334 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5335 | Value *value = rhs.loadValue(); |
| 5336 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5337 | } |
| 5338 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5339 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5340 | { |
| 5341 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 5342 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 5343 | |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5344 | Value *long2 = V(UndefValue::get(VectorType::get(Long::getType(), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5345 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 5346 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 5347 | Value *uint4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 5348 | |
| 5349 | storeValue(uint4); |
| 5350 | } |
| 5351 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5352 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5353 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5354 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5355 | |
| 5356 | return rhs; |
| 5357 | } |
| 5358 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5359 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5360 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5361 | Value *value = rhs.loadValue(); |
| 5362 | storeValue(value); |
| 5363 | |
| 5364 | return RValue<UInt4>(value); |
| 5365 | } |
| 5366 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5367 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5368 | { |
| 5369 | Value *value = rhs.loadValue(); |
| 5370 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5371 | |
| 5372 | return RValue<UInt4>(value); |
| 5373 | } |
| 5374 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5375 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5376 | { |
| 5377 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5378 | } |
| 5379 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5380 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5381 | { |
| 5382 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5383 | } |
| 5384 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5385 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5386 | { |
| 5387 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5388 | } |
| 5389 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5390 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5391 | { |
| 5392 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5393 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5394 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5395 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5396 | { |
| 5397 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5398 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5399 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5400 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5401 | { |
| 5402 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5403 | } |
| 5404 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5405 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5406 | { |
| 5407 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5408 | } |
| 5409 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5410 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5411 | { |
| 5412 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5413 | } |
| 5414 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5415 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5416 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5417 | return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs)); |
| 5418 | } |
| 5419 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5420 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5421 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5422 | return x86::psrld(lhs, rhs); |
| 5423 | } |
| 5424 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5425 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5426 | { |
| 5427 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5428 | } |
| 5429 | |
| 5430 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5431 | { |
| 5432 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5433 | } |
| 5434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5435 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5436 | { |
| 5437 | return lhs = lhs + rhs; |
| 5438 | } |
| 5439 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5440 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5441 | { |
| 5442 | return lhs = lhs - rhs; |
| 5443 | } |
| 5444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5445 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5446 | { |
| 5447 | return lhs = lhs * rhs; |
| 5448 | } |
| 5449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5450 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5451 | // { |
| 5452 | // return lhs = lhs / rhs; |
| 5453 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5454 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5455 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5456 | // { |
| 5457 | // return lhs = lhs % rhs; |
| 5458 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5460 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5461 | { |
| 5462 | return lhs = lhs & rhs; |
| 5463 | } |
| 5464 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5465 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5466 | { |
| 5467 | return lhs = lhs | rhs; |
| 5468 | } |
| 5469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5470 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5471 | { |
| 5472 | return lhs = lhs ^ rhs; |
| 5473 | } |
| 5474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5475 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5476 | { |
| 5477 | return lhs = lhs << rhs; |
| 5478 | } |
| 5479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5480 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5481 | { |
| 5482 | return lhs = lhs >> rhs; |
| 5483 | } |
| 5484 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5485 | RValue<UInt4> operator+(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5486 | { |
| 5487 | return val; |
| 5488 | } |
| 5489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5490 | RValue<UInt4> operator-(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5491 | { |
| 5492 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5493 | } |
| 5494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5495 | RValue<UInt4> operator~(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5496 | { |
| 5497 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5498 | } |
| 5499 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5500 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5501 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5502 | // 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] | 5503 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5504 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5505 | 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] | 5506 | } |
| 5507 | |
| 5508 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5509 | { |
| 5510 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 5511 | } |
| 5512 | |
| 5513 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5514 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5515 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5516 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5517 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 5518 | 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] | 5519 | } |
| 5520 | |
| 5521 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5522 | { |
| 5523 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5524 | } |
| 5525 | |
| 5526 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5527 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5528 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5529 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5530 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 5531 | 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] | 5532 | } |
| 5533 | |
| 5534 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5535 | { |
| 5536 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 5537 | } |
| 5538 | |
| 5539 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5540 | { |
| 5541 | if(CPUID::supportsSSE4_1()) |
| 5542 | { |
| 5543 | return x86::pmaxud(x, y); |
| 5544 | } |
| 5545 | else |
| 5546 | { |
| 5547 | RValue<UInt4> greater = CmpNLE(x, y); |
| 5548 | return x & greater | y & ~greater; |
| 5549 | } |
| 5550 | } |
| 5551 | |
| 5552 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5553 | { |
| 5554 | if(CPUID::supportsSSE4_1()) |
| 5555 | { |
| 5556 | return x86::pminud(x, y); |
| 5557 | } |
| 5558 | else |
| 5559 | { |
| 5560 | RValue<UInt4> less = CmpLT(x, y); |
| 5561 | return x & less | y & ~less; |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5566 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 5567 | return x86::packusdw(As<Int4>(x), As<Int4>(y)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5568 | } |
| 5569 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5570 | Type *UInt4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5571 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 5572 | return T(VectorType::get(UInt::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5573 | } |
| 5574 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5575 | Float::Float(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5576 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5577 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5578 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5579 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5580 | } |
| 5581 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5582 | Float::Float(float x) |
| 5583 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5584 | storeValue(Nucleus::createConstantFloat(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5585 | } |
| 5586 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5587 | Float::Float(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5588 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5589 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | Float::Float(const Float &rhs) |
| 5593 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5594 | Value *value = rhs.loadValue(); |
| 5595 | storeValue(value); |
| 5596 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5597 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5598 | Float::Float(const Reference<Float> &rhs) |
| 5599 | { |
| 5600 | Value *value = rhs.loadValue(); |
| 5601 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5602 | } |
| 5603 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5604 | RValue<Float> Float::operator=(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5605 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5606 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5607 | |
| 5608 | return rhs; |
| 5609 | } |
| 5610 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5611 | RValue<Float> Float::operator=(const Float &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5612 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5613 | Value *value = rhs.loadValue(); |
| 5614 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5615 | |
| 5616 | return RValue<Float>(value); |
| 5617 | } |
| 5618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5619 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5620 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5621 | Value *value = rhs.loadValue(); |
| 5622 | storeValue(value); |
| 5623 | |
| 5624 | return RValue<Float>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5625 | } |
| 5626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5627 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5628 | { |
| 5629 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5630 | } |
| 5631 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5632 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5633 | { |
| 5634 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5635 | } |
| 5636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5637 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5638 | { |
| 5639 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5640 | } |
| 5641 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5642 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5643 | { |
| 5644 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5645 | } |
| 5646 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5647 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5648 | { |
| 5649 | return lhs = lhs + rhs; |
| 5650 | } |
| 5651 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5652 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5653 | { |
| 5654 | return lhs = lhs - rhs; |
| 5655 | } |
| 5656 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5657 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5658 | { |
| 5659 | return lhs = lhs * rhs; |
| 5660 | } |
| 5661 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5662 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5663 | { |
| 5664 | return lhs = lhs / rhs; |
| 5665 | } |
| 5666 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5667 | RValue<Float> operator+(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5668 | { |
| 5669 | return val; |
| 5670 | } |
| 5671 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5672 | RValue<Float> operator-(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5673 | { |
| 5674 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5675 | } |
| 5676 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5677 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5678 | { |
| 5679 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5680 | } |
| 5681 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5682 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5683 | { |
| 5684 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5685 | } |
| 5686 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5687 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5688 | { |
| 5689 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5690 | } |
| 5691 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5692 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5693 | { |
| 5694 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5695 | } |
| 5696 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5697 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5698 | { |
| 5699 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5700 | } |
| 5701 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5702 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5703 | { |
| 5704 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5705 | } |
| 5706 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5707 | RValue<Float> Abs(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5708 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5709 | return IfThenElse(x > 0.0f, x, -x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5710 | } |
| 5711 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5712 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5713 | { |
| 5714 | return IfThenElse(x > y, x, y); |
| 5715 | } |
| 5716 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5717 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5718 | { |
| 5719 | return IfThenElse(x < y, x, y); |
| 5720 | } |
| 5721 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5722 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5723 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5724 | if(exactAtPow2) |
| 5725 | { |
| 5726 | // rcpss uses a piecewise-linear approximation which minimizes the relative error |
| 5727 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 5728 | return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 5729 | } |
| 5730 | else |
| 5731 | { |
| 5732 | return x86::rcpss(x); |
| 5733 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5734 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5735 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5736 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5737 | { |
| 5738 | return x86::rsqrtss(x); |
| 5739 | } |
| 5740 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5741 | RValue<Float> Sqrt(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5742 | { |
| 5743 | return x86::sqrtss(x); |
| 5744 | } |
| 5745 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5746 | RValue<Float> Round(RValue<Float> x) |
| 5747 | { |
| 5748 | if(CPUID::supportsSSE4_1()) |
| 5749 | { |
| 5750 | return x86::roundss(x, 0); |
| 5751 | } |
| 5752 | else |
| 5753 | { |
| 5754 | return Float4(Round(Float4(x))).x; |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | RValue<Float> Trunc(RValue<Float> x) |
| 5759 | { |
| 5760 | if(CPUID::supportsSSE4_1()) |
| 5761 | { |
| 5762 | return x86::roundss(x, 3); |
| 5763 | } |
| 5764 | else |
| 5765 | { |
| 5766 | return Float(Int(x)); // Rounded toward zero |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | RValue<Float> Frac(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5771 | { |
| 5772 | if(CPUID::supportsSSE4_1()) |
| 5773 | { |
| 5774 | return x - x86::floorss(x); |
| 5775 | } |
| 5776 | else |
| 5777 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5778 | return Float4(Frac(Float4(x))).x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5779 | } |
| 5780 | } |
| 5781 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5782 | RValue<Float> Floor(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5783 | { |
| 5784 | if(CPUID::supportsSSE4_1()) |
| 5785 | { |
| 5786 | return x86::floorss(x); |
| 5787 | } |
| 5788 | else |
| 5789 | { |
| 5790 | return Float4(Floor(Float4(x))).x; |
| 5791 | } |
| 5792 | } |
| 5793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5794 | RValue<Float> Ceil(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5795 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5796 | if(CPUID::supportsSSE4_1()) |
| 5797 | { |
| 5798 | return x86::ceilss(x); |
| 5799 | } |
| 5800 | else |
| 5801 | { |
| 5802 | return Float4(Ceil(Float4(x))).x; |
| 5803 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5804 | } |
| 5805 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5806 | Type *Float::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5807 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 5808 | return T(llvm::Type::getFloatTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5809 | } |
| 5810 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5811 | Float2::Float2(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5812 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5813 | Value *int64x2 = Nucleus::createBitCast(cast.value, T(VectorType::get(Long::getType(), 2))); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5814 | Value *int64 = Nucleus::createExtractElement(int64x2, Long::getType(), 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5815 | Value *float2 = Nucleus::createBitCast(int64, Float2::getType()); |
| 5816 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5817 | storeValue(float2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5818 | } |
| 5819 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5820 | Type *Float2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5821 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 5822 | return T(VectorType::get(Float::getType(), 2)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5823 | } |
| 5824 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5825 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5826 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5827 | #if 0 |
| 5828 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); // FIXME: Crashes |
| 5829 | #elif 0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5830 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5831 | |
| 5832 | Value *i8x = Nucleus::createExtractElement(cast.value, 0); |
| 5833 | Value *f32x = Nucleus::createUIToFP(i8x, Float::getType()); |
| 5834 | Value *x = Nucleus::createInsertElement(vector, f32x, 0); |
| 5835 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 5836 | Value *i8y = Nucleus::createExtractElement(cast.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5837 | Value *f32y = Nucleus::createUIToFP(i8y, Float::getType()); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 5838 | Value *xy = Nucleus::createInsertElement(x, f32y, V(Nucleus::createConstantInt(1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5839 | |
| 5840 | Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2)); |
| 5841 | Value *f32z = Nucleus::createUIToFP(i8z, Float::getType()); |
| 5842 | Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2)); |
| 5843 | |
| 5844 | Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3)); |
| 5845 | Value *f32w = Nucleus::createUIToFP(i8w, Float::getType()); |
| 5846 | Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3)); |
| 5847 | #else |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 5848 | Value *a = Int4(cast).loadValue(); |
| 5849 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5850 | #endif |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5851 | |
| 5852 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5853 | } |
| 5854 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5855 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5856 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5857 | #if 0 |
| 5858 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); // FIXME: Crashes |
| 5859 | #elif 0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5860 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5861 | |
| 5862 | Value *i8x = Nucleus::createExtractElement(cast.value, 0); |
| 5863 | Value *f32x = Nucleus::createSIToFP(i8x, Float::getType()); |
| 5864 | Value *x = Nucleus::createInsertElement(vector, f32x, 0); |
| 5865 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 5866 | Value *i8y = Nucleus::createExtractElement(cast.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5867 | Value *f32y = Nucleus::createSIToFP(i8y, Float::getType()); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 5868 | Value *xy = Nucleus::createInsertElement(x, f32y, V(Nucleus::createConstantInt(1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5869 | |
| 5870 | Value *i8z = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(2)); |
| 5871 | Value *f32z = Nucleus::createSIToFP(i8z, Float::getType()); |
| 5872 | Value *xyz = Nucleus::createInsertElement(xy, f32z, Nucleus::createConstantInt(2)); |
| 5873 | |
| 5874 | Value *i8w = Nucleus::createExtractElement(cast.value, Nucleus::createConstantInt(3)); |
| 5875 | Value *f32w = Nucleus::createSIToFP(i8w, Float::getType()); |
| 5876 | Value *xyzw = Nucleus::createInsertElement(xyz, f32w, Nucleus::createConstantInt(3)); |
| 5877 | #else |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 5878 | Value *a = Int4(cast).loadValue(); |
| 5879 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5880 | #endif |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5881 | |
| 5882 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5883 | } |
| 5884 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5885 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5886 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5887 | Int4 c(cast); |
| 5888 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5889 | } |
| 5890 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5891 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5892 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5893 | Int4 c(cast); |
| 5894 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5895 | } |
| 5896 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5897 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5898 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5899 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5900 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5901 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5902 | } |
| 5903 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5904 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5905 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5906 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5907 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5908 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5909 | storeValue(result.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5910 | } |
| 5911 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5912 | Float4::Float4() : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5913 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5914 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5915 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5916 | Float4::Float4(float xyzw) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5917 | { |
| 5918 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5919 | } |
| 5920 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5921 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5922 | { |
| 5923 | constant(x, yzw, yzw, yzw); |
| 5924 | } |
| 5925 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5926 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5927 | { |
| 5928 | constant(x, y, zw, zw); |
| 5929 | } |
| 5930 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5931 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5932 | { |
| 5933 | constant(x, y, z, w); |
| 5934 | } |
| 5935 | |
| 5936 | void Float4::constant(float x, float y, float z, float w) |
| 5937 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5938 | double constantVector[4] = {x, y, z, w}; |
| 5939 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5940 | } |
| 5941 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5942 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5943 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5944 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5945 | } |
| 5946 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5947 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5948 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5949 | Value *value = rhs.loadValue(); |
| 5950 | storeValue(value); |
| 5951 | } |
| 5952 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5953 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5954 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5955 | Value *value = rhs.loadValue(); |
| 5956 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5957 | } |
| 5958 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5959 | Float4::Float4(RValue<Float> rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5960 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5961 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5962 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5963 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5964 | int swizzle[4] = {0, 0, 0, 0}; |
| 5965 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5966 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5967 | storeValue(replicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5968 | } |
| 5969 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5970 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5971 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5972 | *this = RValue<Float>(rhs.loadValue()); |
| 5973 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5974 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5975 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5976 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5977 | *this = RValue<Float>(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5978 | } |
| 5979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5980 | RValue<Float4> Float4::operator=(float x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5981 | { |
| 5982 | return *this = Float4(x, x, x, x); |
| 5983 | } |
| 5984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5985 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5986 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5987 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5988 | |
| 5989 | return rhs; |
| 5990 | } |
| 5991 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5992 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5993 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5994 | Value *value = rhs.loadValue(); |
| 5995 | storeValue(value); |
| 5996 | |
| 5997 | return RValue<Float4>(value); |
| 5998 | } |
| 5999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6000 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6001 | { |
| 6002 | Value *value = rhs.loadValue(); |
| 6003 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6004 | |
| 6005 | return RValue<Float4>(value); |
| 6006 | } |
| 6007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6008 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6009 | { |
| 6010 | return *this = Float4(rhs); |
| 6011 | } |
| 6012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6013 | RValue<Float4> Float4::operator=(const Float &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6014 | { |
| 6015 | return *this = Float4(rhs); |
| 6016 | } |
| 6017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6018 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6019 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6020 | return *this = Float4(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6021 | } |
| 6022 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6023 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6024 | { |
| 6025 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6026 | } |
| 6027 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6028 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6029 | { |
| 6030 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6031 | } |
| 6032 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6033 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6034 | { |
| 6035 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6036 | } |
| 6037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6038 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6039 | { |
| 6040 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6041 | } |
| 6042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6043 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6044 | { |
| 6045 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6046 | } |
| 6047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6048 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6049 | { |
| 6050 | return lhs = lhs + rhs; |
| 6051 | } |
| 6052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6053 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6054 | { |
| 6055 | return lhs = lhs - rhs; |
| 6056 | } |
| 6057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6058 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6059 | { |
| 6060 | return lhs = lhs * rhs; |
| 6061 | } |
| 6062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6063 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6064 | { |
| 6065 | return lhs = lhs / rhs; |
| 6066 | } |
| 6067 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6068 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6069 | { |
| 6070 | return lhs = lhs % rhs; |
| 6071 | } |
| 6072 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6073 | RValue<Float4> operator+(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6074 | { |
| 6075 | return val; |
| 6076 | } |
| 6077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6078 | RValue<Float4> operator-(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6079 | { |
| 6080 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6081 | } |
| 6082 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6083 | RValue<Float4> Abs(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6084 | { |
| 6085 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6086 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6087 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6088 | |
| 6089 | return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType())); |
| 6090 | } |
| 6091 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6092 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6093 | { |
| 6094 | return x86::maxps(x, y); |
| 6095 | } |
| 6096 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6097 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6098 | { |
| 6099 | return x86::minps(x, y); |
| 6100 | } |
| 6101 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6102 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6103 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6104 | if(exactAtPow2) |
| 6105 | { |
| 6106 | // rcpps uses a piecewise-linear approximation which minimizes the relative error |
| 6107 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 6108 | return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 6109 | } |
| 6110 | else |
| 6111 | { |
| 6112 | return x86::rcpps(x); |
| 6113 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6114 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6115 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6116 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6117 | { |
| 6118 | return x86::rsqrtps(x); |
| 6119 | } |
| 6120 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6121 | RValue<Float4> Sqrt(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6122 | { |
| 6123 | return x86::sqrtps(x); |
| 6124 | } |
| 6125 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6126 | RValue<Float4> Insert(RValue<Float4> val, RValue<Float> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6127 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6128 | return RValue<Float4>(Nucleus::createInsertElement(val.value, element.value, i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6129 | } |
| 6130 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6131 | RValue<Float> Extract(RValue<Float4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6132 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6133 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6134 | } |
| 6135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6136 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6137 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6138 | return RValue<Float4>(createSwizzle4(x.value, select)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6139 | } |
| 6140 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6141 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6142 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6143 | int shuffle[4] = |
| 6144 | { |
| 6145 | ((imm >> 0) & 0x03) + 0, |
| 6146 | ((imm >> 2) & 0x03) + 0, |
| 6147 | ((imm >> 4) & 0x03) + 4, |
| 6148 | ((imm >> 6) & 0x03) + 4, |
| 6149 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6150 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6151 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6152 | } |
| 6153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6154 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6155 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6156 | int shuffle[4] = {0, 4, 1, 5}; |
| 6157 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6158 | } |
| 6159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6160 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6161 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6162 | int shuffle[4] = {2, 6, 3, 7}; |
| 6163 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6164 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6165 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6166 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6167 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6168 | Value *vector = lhs.loadValue(); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6169 | Value *shuffle = createMask4(vector, rhs.value, select); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6170 | lhs.storeValue(shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6171 | |
| 6172 | return RValue<Float4>(shuffle); |
| 6173 | } |
| 6174 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6175 | RValue<Int> SignMask(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6176 | { |
| 6177 | return x86::movmskps(x); |
| 6178 | } |
| 6179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6180 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6181 | { |
| 6182 | // return As<Int4>(x86::cmpeqps(x, y)); |
| 6183 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6184 | } |
| 6185 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6186 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6187 | { |
| 6188 | // return As<Int4>(x86::cmpltps(x, y)); |
| 6189 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6190 | } |
| 6191 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6192 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6193 | { |
| 6194 | // return As<Int4>(x86::cmpleps(x, y)); |
| 6195 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6196 | } |
| 6197 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6198 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6199 | { |
| 6200 | // return As<Int4>(x86::cmpneqps(x, y)); |
| 6201 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6202 | } |
| 6203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6204 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6205 | { |
| 6206 | // return As<Int4>(x86::cmpnltps(x, y)); |
| 6207 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6208 | } |
| 6209 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6210 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6211 | { |
| 6212 | // return As<Int4>(x86::cmpnleps(x, y)); |
| 6213 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6214 | } |
| 6215 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6216 | RValue<Float4> Round(RValue<Float4> x) |
| 6217 | { |
| 6218 | if(CPUID::supportsSSE4_1()) |
| 6219 | { |
| 6220 | return x86::roundps(x, 0); |
| 6221 | } |
| 6222 | else |
| 6223 | { |
| 6224 | return Float4(RoundInt(x)); |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6229 | { |
| 6230 | if(CPUID::supportsSSE4_1()) |
| 6231 | { |
| 6232 | return x86::roundps(x, 3); |
| 6233 | } |
| 6234 | else |
| 6235 | { |
| 6236 | return Float4(Int4(x)); // Rounded toward zero |
| 6237 | } |
| 6238 | } |
| 6239 | |
| 6240 | RValue<Float4> Frac(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6241 | { |
| 6242 | if(CPUID::supportsSSE4_1()) |
| 6243 | { |
| 6244 | return x - x86::floorps(x); |
| 6245 | } |
| 6246 | else |
| 6247 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6248 | Float4 frc = x - Float4(Int4(x)); // Signed fractional part |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6249 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6250 | 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] | 6251 | } |
| 6252 | } |
| 6253 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6254 | RValue<Float4> Floor(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6255 | { |
| 6256 | if(CPUID::supportsSSE4_1()) |
| 6257 | { |
| 6258 | return x86::floorps(x); |
| 6259 | } |
| 6260 | else |
| 6261 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6262 | return x - Frac(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6263 | } |
| 6264 | } |
| 6265 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6266 | RValue<Float4> Ceil(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6267 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6268 | if(CPUID::supportsSSE4_1()) |
| 6269 | { |
| 6270 | return x86::ceilps(x); |
| 6271 | } |
| 6272 | else |
| 6273 | { |
| 6274 | return -Floor(-x); |
| 6275 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6276 | } |
| 6277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6278 | Type *Float4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6279 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 6280 | return T(VectorType::get(Float::getType(), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6281 | } |
| 6282 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6283 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6284 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6285 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), V(Nucleus::createConstantInt(offset)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6286 | } |
| 6287 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6288 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6289 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6290 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6291 | } |
| 6292 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6293 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6294 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6295 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6296 | } |
| 6297 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6298 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6299 | { |
| 6300 | return lhs = lhs + offset; |
| 6301 | } |
| 6302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6303 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6304 | { |
| 6305 | return lhs = lhs + offset; |
| 6306 | } |
| 6307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6308 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6309 | { |
| 6310 | return lhs = lhs + offset; |
| 6311 | } |
| 6312 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6313 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6314 | { |
| 6315 | return lhs + -offset; |
| 6316 | } |
| 6317 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6318 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6319 | { |
| 6320 | return lhs + -offset; |
| 6321 | } |
| 6322 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6323 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6324 | { |
| 6325 | return lhs + -offset; |
| 6326 | } |
| 6327 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6328 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6329 | { |
| 6330 | return lhs = lhs - offset; |
| 6331 | } |
| 6332 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6333 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6334 | { |
| 6335 | return lhs = lhs - offset; |
| 6336 | } |
| 6337 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6338 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6339 | { |
| 6340 | return lhs = lhs - offset; |
| 6341 | } |
| 6342 | |
| 6343 | void Return() |
| 6344 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6345 | Nucleus::createRetVoid(); |
| 6346 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6347 | Nucleus::createUnreachable(); |
| 6348 | } |
| 6349 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6350 | void Return(RValue<Int> ret) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6351 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6352 | Nucleus::createRet(ret.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6353 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6354 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6355 | } |
| 6356 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6357 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6358 | { |
| 6359 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6360 | Nucleus::setInsertBlock(bodyBB); |
| 6361 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6362 | return true; |
| 6363 | } |
| 6364 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6365 | RValue<Long> Ticks() |
| 6366 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6367 | llvm::Function *rdtsc = Intrinsic::getDeclaration(::module, Intrinsic::readcyclecounter); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6368 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6369 | return RValue<Long>(V(::builder->CreateCall(rdtsc))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6370 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | namespace sw |
| 6374 | { |
| 6375 | namespace x86 |
| 6376 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6377 | RValue<Int> cvtss2si(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6378 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6379 | llvm::Function *cvtss2si = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cvtss2si); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6380 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6381 | Float4 vector; |
| 6382 | vector.x = val; |
| 6383 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6384 | return RValue<Int>(V(::builder->CreateCall(cvtss2si, RValue<Float4>(vector).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6385 | } |
| 6386 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6387 | RValue<Int2> cvtps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6388 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6389 | llvm::Function *cvtps2pi = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cvtps2pi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6390 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6391 | return RValue<Int2>(V(::builder->CreateCall(cvtps2pi, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6392 | } |
| 6393 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6394 | RValue<Int2> cvttps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6395 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6396 | llvm::Function *cvttps2pi = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cvttps2pi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6397 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6398 | return RValue<Int2>(V(::builder->CreateCall(cvttps2pi, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6399 | } |
| 6400 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6401 | RValue<Int4> cvtps2dq(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6402 | { |
| 6403 | if(CPUID::supportsSSE2()) |
| 6404 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6405 | llvm::Function *cvtps2dq = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_cvtps2dq); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6406 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6407 | return RValue<Int4>(V(::builder->CreateCall(cvtps2dq, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6408 | } |
| 6409 | else |
| 6410 | { |
| 6411 | Int2 lo = x86::cvtps2pi(val); |
| 6412 | Int2 hi = x86::cvtps2pi(Swizzle(val, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6413 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 6414 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6415 | } |
| 6416 | } |
| 6417 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6418 | RValue<Float> rcpss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6419 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6420 | llvm::Function *rcpss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rcp_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6421 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 6422 | Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6423 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6424 | return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rcpss, vector)), Float::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6425 | } |
| 6426 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6427 | RValue<Float> sqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6428 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6429 | llvm::Function *sqrtss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_sqrt_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6430 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 6431 | Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6432 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6433 | return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(sqrtss, vector)), Float::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6434 | } |
| 6435 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6436 | RValue<Float> rsqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6437 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6438 | llvm::Function *rsqrtss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rsqrt_ss); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6439 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 6440 | Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6441 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6442 | return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rsqrtss, vector)), Float::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6443 | } |
| 6444 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6445 | RValue<Float4> rcpps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6446 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6447 | llvm::Function *rcpps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rcp_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6448 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6449 | return RValue<Float4>(V(::builder->CreateCall(rcpps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6450 | } |
| 6451 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6452 | RValue<Float4> sqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6453 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6454 | llvm::Function *sqrtps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_sqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6455 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6456 | return RValue<Float4>(V(::builder->CreateCall(sqrtps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6457 | } |
| 6458 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6459 | RValue<Float4> rsqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6460 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6461 | llvm::Function *rsqrtps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_rsqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6462 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6463 | return RValue<Float4>(V(::builder->CreateCall(rsqrtps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6464 | } |
| 6465 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6466 | RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6467 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6468 | llvm::Function *maxps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_max_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6469 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6470 | return RValue<Float4>(V(::builder->CreateCall2(maxps, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6471 | } |
| 6472 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6473 | RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6474 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6475 | llvm::Function *minps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_min_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6476 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6477 | return RValue<Float4>(V(::builder->CreateCall2(minps, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6478 | } |
| 6479 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6480 | RValue<Float> roundss(RValue<Float> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6481 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6482 | llvm::Function *roundss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_round_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6483 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 6484 | Value *undef = V(UndefValue::get(Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6485 | Value *vector = Nucleus::createInsertElement(undef, val.value, 0); |
| 6486 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6487 | return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(roundss, undef, vector, V(Nucleus::createConstantInt(imm)))), Float::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6488 | } |
| 6489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6490 | RValue<Float> floorss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6491 | { |
| 6492 | return roundss(val, 1); |
| 6493 | } |
| 6494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6495 | RValue<Float> ceilss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6496 | { |
| 6497 | return roundss(val, 2); |
| 6498 | } |
| 6499 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6500 | RValue<Float4> roundps(RValue<Float4> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6501 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6502 | llvm::Function *roundps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_round_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6503 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6504 | return RValue<Float4>(V(::builder->CreateCall2(roundps, val.value, V(Nucleus::createConstantInt(imm))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6505 | } |
| 6506 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6507 | RValue<Float4> floorps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6508 | { |
| 6509 | return roundps(val, 1); |
| 6510 | } |
| 6511 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6512 | RValue<Float4> ceilps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6513 | { |
| 6514 | return roundps(val, 2); |
| 6515 | } |
| 6516 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6517 | RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6518 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6519 | llvm::Function *cmpps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cmp_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6520 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6521 | return RValue<Float4>(V(::builder->CreateCall3(cmpps, x.value, y.value, V(Nucleus::createConstantByte(imm))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6522 | } |
| 6523 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6524 | RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6525 | { |
| 6526 | return cmpps(x, y, 0); |
| 6527 | } |
| 6528 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6529 | RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6530 | { |
| 6531 | return cmpps(x, y, 1); |
| 6532 | } |
| 6533 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6534 | RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6535 | { |
| 6536 | return cmpps(x, y, 2); |
| 6537 | } |
| 6538 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6539 | RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6540 | { |
| 6541 | return cmpps(x, y, 3); |
| 6542 | } |
| 6543 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6544 | RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6545 | { |
| 6546 | return cmpps(x, y, 4); |
| 6547 | } |
| 6548 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6549 | RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6550 | { |
| 6551 | return cmpps(x, y, 5); |
| 6552 | } |
| 6553 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6554 | RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6555 | { |
| 6556 | return cmpps(x, y, 6); |
| 6557 | } |
| 6558 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6559 | RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6560 | { |
| 6561 | return cmpps(x, y, 7); |
| 6562 | } |
| 6563 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6564 | RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6565 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6566 | llvm::Function *cmpss = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_cmp_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6567 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 6568 | Value *vector1 = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), x.value, 0); |
| 6569 | Value *vector2 = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), y.value, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6570 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6571 | return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(cmpss, vector1, vector2, V(Nucleus::createConstantByte(imm)))), Float::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6572 | } |
| 6573 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6574 | RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6575 | { |
| 6576 | return cmpss(x, y, 0); |
| 6577 | } |
| 6578 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6579 | RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6580 | { |
| 6581 | return cmpss(x, y, 1); |
| 6582 | } |
| 6583 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6584 | RValue<Float> cmpless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6585 | { |
| 6586 | return cmpss(x, y, 2); |
| 6587 | } |
| 6588 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6589 | RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6590 | { |
| 6591 | return cmpss(x, y, 3); |
| 6592 | } |
| 6593 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6594 | RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6595 | { |
| 6596 | return cmpss(x, y, 4); |
| 6597 | } |
| 6598 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6599 | RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6600 | { |
| 6601 | return cmpss(x, y, 5); |
| 6602 | } |
| 6603 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6604 | RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6605 | { |
| 6606 | return cmpss(x, y, 6); |
| 6607 | } |
| 6608 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6609 | RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6610 | { |
| 6611 | return cmpss(x, y, 7); |
| 6612 | } |
| 6613 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 6614 | RValue<Int4> pabsd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6615 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6616 | llvm::Function *pabsd = Intrinsic::getDeclaration(::module, Intrinsic::x86_ssse3_pabs_d_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6617 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6618 | return RValue<Int4>(V(::builder->CreateCall(pabsd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6619 | } |
| 6620 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6621 | RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6622 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6623 | llvm::Function *paddsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padds_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6624 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6625 | return As<Short4>(V(::builder->CreateCall2(paddsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6626 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6627 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6628 | RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6629 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6630 | llvm::Function *psubsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6631 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6632 | return As<Short4>(V(::builder->CreateCall2(psubsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6633 | } |
| 6634 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6635 | RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6636 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6637 | llvm::Function *paddusw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_paddus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6638 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6639 | return As<UShort4>(V(::builder->CreateCall2(paddusw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6640 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6641 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6642 | RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6643 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6644 | llvm::Function *psubusw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6645 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6646 | return As<UShort4>(V(::builder->CreateCall2(psubusw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6647 | } |
| 6648 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6649 | RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6650 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6651 | llvm::Function *paddsb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padds_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6652 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6653 | return As<SByte8>(V(::builder->CreateCall2(paddsb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6654 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6655 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6656 | RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6657 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6658 | llvm::Function *psubsb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubs_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6659 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6660 | return As<SByte8>(V(::builder->CreateCall2(psubsb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6661 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6662 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6663 | RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6664 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6665 | llvm::Function *paddusb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_paddus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6666 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6667 | return As<Byte8>(V(::builder->CreateCall2(paddusb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6668 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6669 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6670 | RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6671 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6672 | llvm::Function *psubusb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psubus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6673 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6674 | return As<Byte8>(V(::builder->CreateCall2(psubusb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6675 | } |
| 6676 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6677 | RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y) |
| 6678 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6679 | llvm::Function *paddw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padd_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6680 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6681 | return As<Short4>(V(::builder->CreateCall2(paddw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6682 | } |
| 6683 | |
| 6684 | RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y) |
| 6685 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6686 | llvm::Function *psubw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psub_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6687 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6688 | return As<Short4>(V(::builder->CreateCall2(psubw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6689 | } |
| 6690 | |
| 6691 | RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y) |
| 6692 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6693 | llvm::Function *pmullw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmull_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6694 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6695 | return As<Short4>(V(::builder->CreateCall2(pmullw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6696 | } |
| 6697 | |
| 6698 | RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y) |
| 6699 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6700 | llvm::Function *pand = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pand); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6701 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6702 | return As<Short4>(V(::builder->CreateCall2(pand, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | RValue<Short4> por(RValue<Short4> x, RValue<Short4> y) |
| 6706 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6707 | llvm::Function *por = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_por); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6708 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6709 | return As<Short4>(V(::builder->CreateCall2(por, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y) |
| 6713 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6714 | llvm::Function *pxor = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pxor); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6715 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6716 | return As<Short4>(V(::builder->CreateCall2(pxor, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6717 | } |
| 6718 | |
| 6719 | RValue<Short4> pshufw(RValue<Short4> x, unsigned char y) |
| 6720 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6721 | llvm::Function *pshufw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_pshuf_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6722 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6723 | return As<Short4>(V(::builder->CreateCall2(pshufw, As<MMX>(x).value, V(Nucleus::createConstantByte(y))))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y) |
| 6727 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6728 | llvm::Function *punpcklwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpcklwd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6729 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6730 | return As<Int2>(V(::builder->CreateCall2(punpcklwd, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y) |
| 6734 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6735 | llvm::Function *punpckhwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckhwd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6736 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6737 | return As<Int2>(V(::builder->CreateCall2(punpckhwd, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i) |
| 6741 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6742 | llvm::Function *pinsrw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pinsr_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6743 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6744 | return As<Short4>(V(::builder->CreateCall3(pinsrw, As<MMX>(x).value, y.value, V(Nucleus::createConstantInt(i))))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6745 | } |
| 6746 | |
| 6747 | RValue<Int> pextrw(RValue<Short4> x, unsigned int i) |
| 6748 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6749 | llvm::Function *pextrw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pextr_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6750 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6751 | return RValue<Int>(V(::builder->CreateCall2(pextrw, As<MMX>(x).value, V(Nucleus::createConstantInt(i))))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6752 | } |
| 6753 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6754 | RValue<Short4> punpckldq(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6755 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6756 | llvm::Function *punpckldq = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckldq); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6757 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6758 | return As<Short4>(V(::builder->CreateCall2(punpckldq, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6759 | } |
| 6760 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6761 | RValue<Short4> punpckhdq(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6762 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6763 | llvm::Function *punpckhdq = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckhdq); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6764 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6765 | return As<Short4>(V(::builder->CreateCall2(punpckhdq, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y) |
| 6769 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6770 | llvm::Function *punpcklbw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpcklbw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6771 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6772 | return As<Short4>(V(::builder->CreateCall2(punpcklbw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y) |
| 6776 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6777 | llvm::Function *punpckhbw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_punpckhbw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6778 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6779 | return As<Short4>(V(::builder->CreateCall2(punpckhbw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y) |
| 6783 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6784 | llvm::Function *paddb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padd_b); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6785 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6786 | return As<Byte8>(V(::builder->CreateCall2(paddb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y) |
| 6790 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6791 | llvm::Function *psubb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psub_b); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6792 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6793 | return As<Byte8>(V(::builder->CreateCall2(psubb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6794 | } |
| 6795 | |
| 6796 | RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y) |
| 6797 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6798 | llvm::Function *paddd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_padd_d); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6799 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6800 | return As<Int2>(V(::builder->CreateCall2(paddd, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6801 | } |
| 6802 | |
| 6803 | RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y) |
| 6804 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6805 | llvm::Function *psubd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psub_d); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6806 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6807 | return As<Int2>(V(::builder->CreateCall2(psubd, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6811 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6812 | llvm::Function *pavgw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pavg_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6813 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6814 | return As<UShort4>(V(::builder->CreateCall2(pavgw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6815 | } |
| 6816 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6817 | RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6818 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6819 | llvm::Function *pmaxsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmaxs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6820 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6821 | return As<Short4>(V(::builder->CreateCall2(pmaxsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6822 | } |
| 6823 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6824 | RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6825 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6826 | llvm::Function *pminsw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmins_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6827 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6828 | return As<Short4>(V(::builder->CreateCall2(pminsw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6829 | } |
| 6830 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6831 | RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6832 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6833 | llvm::Function *pcmpgtw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpgt_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6834 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6835 | return As<Short4>(V(::builder->CreateCall2(pcmpgtw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6836 | } |
| 6837 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6838 | RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6839 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6840 | llvm::Function *pcmpeqw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpeq_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6841 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6842 | return As<Short4>(V(::builder->CreateCall2(pcmpeqw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6843 | } |
| 6844 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6845 | RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6846 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6847 | llvm::Function *pcmpgtb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpgt_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6848 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6849 | return As<Byte8>(V(::builder->CreateCall2(pcmpgtb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6850 | } |
| 6851 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6852 | RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6853 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6854 | llvm::Function *pcmpeqb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pcmpeq_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6855 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6856 | return As<Byte8>(V(::builder->CreateCall2(pcmpeqb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6857 | } |
| 6858 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6859 | RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6860 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6861 | llvm::Function *packssdw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_packssdw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6862 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6863 | return As<Short4>(V(::builder->CreateCall2(packssdw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6864 | } |
| 6865 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6866 | RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6867 | { |
| 6868 | if(CPUID::supportsSSE2()) |
| 6869 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6870 | llvm::Function *packssdw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_packssdw_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6871 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6872 | return RValue<Short8>(V(::builder->CreateCall2(packssdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6873 | } |
| 6874 | else |
| 6875 | { |
| 6876 | Int2 loX = Int2(x); |
| 6877 | Int2 hiX = Int2(Swizzle(x, 0xEE)); |
| 6878 | |
| 6879 | Int2 loY = Int2(y); |
| 6880 | Int2 hiY = Int2(Swizzle(y, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6881 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6882 | Short4 lo = x86::packssdw(loX, hiX); |
| 6883 | Short4 hi = x86::packssdw(loY, hiY); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6884 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 6885 | return Short8(lo, hi); |
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<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6890 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6891 | llvm::Function *packsswb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_packsswb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6892 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6893 | return As<SByte8>(V(::builder->CreateCall2(packsswb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6894 | } |
| 6895 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6896 | RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6897 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6898 | llvm::Function *packuswb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_packuswb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6899 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6900 | return As<Byte8>(V(::builder->CreateCall2(packuswb, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6901 | } |
| 6902 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 6903 | RValue<UShort8> packusdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6904 | { |
| 6905 | if(CPUID::supportsSSE4_1()) |
| 6906 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6907 | llvm::Function *packusdw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_packusdw); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6908 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6909 | return RValue<UShort8>(V(::builder->CreateCall2(packusdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6910 | } |
| 6911 | else |
| 6912 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 6913 | RValue<Int4> bx = (x & ~(x >> 31)) - Int4(0x8000); |
| 6914 | RValue<Int4> by = (y & ~(y >> 31)) - Int4(0x8000); |
| 6915 | |
| 6916 | return As<UShort8>(packssdw(bx, by) + Short8(0x8000u)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6917 | } |
| 6918 | } |
| 6919 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6920 | RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6921 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6922 | llvm::Function *psrlw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6923 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6924 | return As<UShort4>(V(::builder->CreateCall2(psrlw, As<MMX>(x).value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6925 | } |
| 6926 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6927 | RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6928 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6929 | llvm::Function *psrlw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6930 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6931 | return RValue<UShort8>(V(::builder->CreateCall2(psrlw, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6932 | } |
| 6933 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6934 | RValue<Short4> psraw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6935 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6936 | llvm::Function *psraw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrai_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6937 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6938 | return As<Short4>(V(::builder->CreateCall2(psraw, As<MMX>(x).value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6939 | } |
| 6940 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6941 | RValue<Short8> psraw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6942 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6943 | llvm::Function *psraw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrai_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6944 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6945 | return RValue<Short8>(V(::builder->CreateCall2(psraw, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6946 | } |
| 6947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6948 | RValue<Short4> psllw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6949 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6950 | llvm::Function *psllw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pslli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6951 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6952 | return As<Short4>(V(::builder->CreateCall2(psllw, As<MMX>(x).value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6953 | } |
| 6954 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6955 | RValue<Short8> psllw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6956 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6957 | llvm::Function *psllw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pslli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6958 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6959 | return RValue<Short8>(V(::builder->CreateCall2(psllw, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6960 | } |
| 6961 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6962 | RValue<Int2> pslld(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6963 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6964 | llvm::Function *pslld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pslli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6965 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6966 | return As<Int2>(V(::builder->CreateCall2(pslld, As<MMX>(x).value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6967 | } |
| 6968 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6969 | RValue<Int4> pslld(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6970 | { |
| 6971 | if(CPUID::supportsSSE2()) |
| 6972 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6973 | llvm::Function *pslld = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pslli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6974 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6975 | return RValue<Int4>(V(::builder->CreateCall2(pslld, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6976 | } |
| 6977 | else |
| 6978 | { |
| 6979 | Int2 lo = Int2(x); |
| 6980 | Int2 hi = Int2(Swizzle(x, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6981 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6982 | lo = x86::pslld(lo, y); |
| 6983 | hi = x86::pslld(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6984 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 6985 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6986 | } |
| 6987 | } |
| 6988 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6989 | RValue<Int2> psrad(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6990 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 6991 | llvm::Function *psrad = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrai_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6992 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6993 | return As<Int2>(V(::builder->CreateCall2(psrad, As<MMX>(x).value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6994 | } |
| 6995 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6996 | RValue<Int4> psrad(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6997 | { |
| 6998 | if(CPUID::supportsSSE2()) |
| 6999 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7000 | llvm::Function *psrad = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrai_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7001 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7002 | return RValue<Int4>(V(::builder->CreateCall2(psrad, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7003 | } |
| 7004 | else |
| 7005 | { |
| 7006 | Int2 lo = Int2(x); |
| 7007 | Int2 hi = Int2(Swizzle(x, 0xEE)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7008 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7009 | lo = x86::psrad(lo, y); |
| 7010 | hi = x86::psrad(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7011 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7012 | return Int4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7013 | } |
| 7014 | } |
| 7015 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7016 | RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7017 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7018 | llvm::Function *psrld = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_psrli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7019 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 7020 | return As<UInt2>(V(::builder->CreateCall2(psrld, As<MMX>(x).value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7021 | } |
| 7022 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7023 | RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7024 | { |
| 7025 | if(CPUID::supportsSSE2()) |
| 7026 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7027 | llvm::Function *psrld = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_psrli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7028 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7029 | return RValue<UInt4>(V(::builder->CreateCall2(psrld, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7030 | } |
| 7031 | else |
| 7032 | { |
| 7033 | UInt2 lo = As<UInt2>(Int2(As<Int4>(x))); |
| 7034 | UInt2 hi = As<UInt2>(Int2(Swizzle(As<Int4>(x), 0xEE))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7035 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7036 | lo = x86::psrld(lo, y); |
| 7037 | hi = x86::psrld(hi, y); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7038 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 7039 | return UInt4(lo, hi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7040 | } |
| 7041 | } |
| 7042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7043 | RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y) |
| 7044 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7045 | llvm::Function *pmaxsd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmaxsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7046 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7047 | return RValue<Int4>(V(::builder->CreateCall2(pmaxsd, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7048 | } |
| 7049 | |
| 7050 | RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y) |
| 7051 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7052 | llvm::Function *pminsd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pminsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7053 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7054 | return RValue<Int4>(V(::builder->CreateCall2(pminsd, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y) |
| 7058 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7059 | llvm::Function *pmaxud = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmaxud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7060 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7061 | return RValue<UInt4>(V(::builder->CreateCall2(pmaxud, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7062 | } |
| 7063 | |
| 7064 | RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y) |
| 7065 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7066 | llvm::Function *pminud = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pminud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7067 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7068 | return RValue<UInt4>(V(::builder->CreateCall2(pminud, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7069 | } |
| 7070 | |
| 7071 | RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7072 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7073 | llvm::Function *pmulhw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmulh_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7074 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 7075 | return As<Short4>(V(::builder->CreateCall2(pmulhw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7076 | } |
| 7077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7078 | RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y) |
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 *pmulhuw = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmulhu_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7081 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 7082 | return As<UShort4>(V(::builder->CreateCall2(pmulhuw, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7083 | } |
| 7084 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7085 | RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7086 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7087 | llvm::Function *pmaddwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmadd_wd); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7088 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 7089 | return As<Int2>(V(::builder->CreateCall2(pmaddwd, As<MMX>(x).value, As<MMX>(y).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7090 | } |
| 7091 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7092 | RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7093 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7094 | llvm::Function *pmulhw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pmulh_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7095 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7096 | return RValue<Short8>(V(::builder->CreateCall2(pmulhw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7097 | } |
| 7098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7099 | RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7100 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7101 | llvm::Function *pmulhuw = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pmulhu_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7102 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7103 | return RValue<UShort8>(V(::builder->CreateCall2(pmulhuw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7104 | } |
| 7105 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7106 | RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7107 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7108 | llvm::Function *pmaddwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse2_pmadd_wd); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7109 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7110 | return RValue<Int4>(V(::builder->CreateCall2(pmaddwd, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7111 | } |
| 7112 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7113 | RValue<Int> movmskps(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7114 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7115 | llvm::Function *movmskps = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse_movmsk_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7116 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7117 | return RValue<Int>(V(::builder->CreateCall(movmskps, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7118 | } |
| 7119 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7120 | RValue<Int> pmovmskb(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7121 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7122 | llvm::Function *pmovmskb = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_pmovmskb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7123 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7124 | return RValue<Int>(V(::builder->CreateCall(pmovmskb, As<MMX>(x).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7125 | } |
| 7126 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 7127 | //RValue<Int2> movd(RValue<Pointer<Int>> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7128 | //{ |
| 7129 | // Value *element = Nucleus::createLoad(x.value); |
| 7130 | |
| 7131 | //// Value *int2 = UndefValue::get(Int2::getType()); |
| 7132 | //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(Int::getType(), 0)); |
| 7133 | |
| 7134 | // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType()); |
| 7135 | |
| 7136 | // return RValue<Int2>(int2); |
| 7137 | //} |
| 7138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7139 | //RValue<Int2> movdq2q(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7140 | //{ |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 7141 | // Value *long2 = Nucleus::createBitCast(x.value, T(VectorType::get(Long::getType(), 2))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7142 | // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(Int::getType(), 0)); |
| 7143 | |
| 7144 | // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType())); |
| 7145 | //} |
| 7146 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7147 | RValue<Int4> pmovzxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7148 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7149 | llvm::Function *pmovzxbd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovzxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7150 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7151 | return RValue<Int4>(V(::builder->CreateCall(pmovzxbd, Nucleus::createBitCast(x.value, Byte16::getType())))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7152 | } |
| 7153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7154 | RValue<Int4> pmovsxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7155 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7156 | llvm::Function *pmovsxbd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovsxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7157 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7158 | return RValue<Int4>(V(::builder->CreateCall(pmovsxbd, Nucleus::createBitCast(x.value, SByte16::getType())))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7159 | } |
| 7160 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7161 | RValue<Int4> pmovzxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7162 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7163 | llvm::Function *pmovzxwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovzxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7164 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7165 | return RValue<Int4>(V(::builder->CreateCall(pmovzxwd, Nucleus::createBitCast(x.value, UShort8::getType())))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7166 | } |
| 7167 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7168 | RValue<Int4> pmovsxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7169 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7170 | llvm::Function *pmovsxwd = Intrinsic::getDeclaration(::module, Intrinsic::x86_sse41_pmovsxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7171 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7172 | return RValue<Int4>(V(::builder->CreateCall(pmovsxwd, Nucleus::createBitCast(x.value, Short8::getType())))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7173 | } |
| 7174 | |
| 7175 | void emms() |
| 7176 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 7177 | llvm::Function *emms = Intrinsic::getDeclaration(::module, Intrinsic::x86_mmx_emms); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7178 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7179 | V(::builder->CreateCall(emms)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7180 | } |
| 7181 | } |
| 7182 | } |