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 | |
| 40 | #include <fstream> |
| 41 | |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 42 | #if defined(__i386__) || defined(__x86_64__) |
| 43 | #include <xmmintrin.h> |
| 44 | #endif |
| 45 | |
Nicolas Capens | cb12258 | 2014-05-06 23:34:44 -0400 | [diff] [blame] | 46 | #if defined(__x86_64__) && defined(_WIN32) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 47 | extern "C" void X86CompilationCallback() |
| 48 | { |
| 49 | assert(false); // UNIMPLEMENTED |
| 50 | } |
| 51 | #endif |
| 52 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 53 | extern "C" |
| 54 | { |
| 55 | bool (*CodeAnalystInitialize)() = 0; |
| 56 | void (*CodeAnalystCompleteJITLog)() = 0; |
| 57 | bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0; |
| 58 | } |
| 59 | |
| 60 | namespace llvm |
| 61 | { |
| 62 | extern bool JITEmitDebugInfo; |
| 63 | } |
| 64 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 65 | namespace |
| 66 | { |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 67 | sw::LLVMRoutineManager *routineManager = nullptr; |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 68 | llvm::ExecutionEngine *executionEngine = nullptr; |
| 69 | llvm::IRBuilder<> *builder = nullptr; |
| 70 | llvm::LLVMContext *context = nullptr; |
| 71 | llvm::Module *module = nullptr; |
| 72 | llvm::Function *function = nullptr; |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 73 | |
Jorge E. Moreira | f8faed6 | 2016-12-02 17:03:54 -0800 | [diff] [blame] | 74 | sw::MutexLock codegenMutex; |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 75 | } |
| 76 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 77 | namespace sw |
| 78 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 79 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 80 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 81 | enum EmulatedType |
| 82 | { |
| 83 | Type_v2i32, |
| 84 | Type_v4i16, |
| 85 | Type_v2i16, |
| 86 | Type_v8i8, |
| 87 | Type_v4i8, |
| 88 | Type_v2f32, |
| 89 | EmulatedTypeCount |
| 90 | }; |
| 91 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 92 | class Value : public llvm::Value {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 93 | class SwitchCases : public llvm::SwitchInst {}; |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 94 | class BasicBlock : public llvm::BasicBlock {}; |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 95 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 96 | llvm::Type *T(Type *t) |
| 97 | { |
| 98 | std::uintptr_t type = reinterpret_cast<std::uintptr_t>(t); |
| 99 | if(type < EmulatedTypeCount) |
| 100 | { |
| 101 | switch(type) |
| 102 | { |
| 103 | case Type_v2i32: return llvm::Type::getX86_MMXTy(*::context); |
| 104 | case Type_v4i16: return llvm::Type::getX86_MMXTy(*::context); |
| 105 | case Type_v2i16: return llvm::Type::getInt32Ty(*::context); |
| 106 | case Type_v8i8: return llvm::Type::getX86_MMXTy(*::context); |
| 107 | case Type_v4i8: return llvm::Type::getInt32Ty(*::context); |
| 108 | case Type_v2f32: return llvm::VectorType::get(T(Float::getType()), 2); |
| 109 | default: assert(false); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return reinterpret_cast<llvm::Type*>(t); |
| 114 | } |
| 115 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 116 | inline Type *T(llvm::Type *t) |
| 117 | { |
| 118 | return reinterpret_cast<Type*>(t); |
| 119 | } |
| 120 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 121 | Type *T(EmulatedType t) |
| 122 | { |
| 123 | return reinterpret_cast<Type*>(t); |
| 124 | } |
| 125 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 126 | inline Value *V(llvm::Value *t) |
| 127 | { |
| 128 | return reinterpret_cast<Value*>(t); |
| 129 | } |
| 130 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 131 | inline std::vector<llvm::Type*> &T(std::vector<Type*> &t) |
| 132 | { |
| 133 | return reinterpret_cast<std::vector<llvm::Type*>&>(t); |
| 134 | } |
| 135 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 136 | inline BasicBlock *B(llvm::BasicBlock *t) |
| 137 | { |
| 138 | return reinterpret_cast<BasicBlock*>(t); |
| 139 | } |
| 140 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 141 | Nucleus::Nucleus() |
| 142 | { |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 143 | ::codegenMutex.lock(); // Reactor and LLVM are currently not thread safe |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 144 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 145 | llvm::InitializeNativeTarget(); |
| 146 | llvm::JITEmitDebugInfo = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 147 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 148 | if(!::context) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 149 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 150 | ::context = new llvm::LLVMContext(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 153 | ::module = new llvm::Module("", *::context); |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 154 | ::routineManager = new LLVMRoutineManager(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 155 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 156 | #if defined(__x86_64__) |
| 157 | const char *architecture = "x86-64"; |
| 158 | #else |
| 159 | const char *architecture = "x86"; |
| 160 | #endif |
| 161 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 162 | llvm::SmallVector<std::string, 1> MAttrs; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 163 | MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx"); |
| 164 | MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov"); |
| 165 | MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse"); |
| 166 | MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2"); |
| 167 | MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3"); |
| 168 | MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3"); |
| 169 | MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41"); |
| 170 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 171 | std::string error; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 172 | llvm::TargetMachine *targetMachine = llvm::EngineBuilder::selectTarget(::module, architecture, "", MAttrs, llvm::Reloc::Default, llvm::CodeModel::JITDefault, &error); |
| 173 | ::executionEngine = llvm::JIT::createJIT(::module, 0, ::routineManager, llvm::CodeGenOpt::Aggressive, true, targetMachine); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 174 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 175 | if(!::builder) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 176 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 177 | ::builder = new llvm::IRBuilder<>(*::context); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 178 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 179 | #if defined(_WIN32) |
| 180 | HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll"); |
| 181 | if(CodeAnalyst) |
| 182 | { |
| 183 | CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize"); |
| 184 | CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog"); |
| 185 | CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode"); |
| 186 | |
| 187 | CodeAnalystInitialize(); |
| 188 | } |
| 189 | #endif |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | Nucleus::~Nucleus() |
| 194 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 195 | delete ::executionEngine; |
| 196 | ::executionEngine = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 197 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 198 | ::routineManager = nullptr; |
| 199 | ::function = nullptr; |
| 200 | ::module = nullptr; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 201 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 202 | ::codegenMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 206 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 207 | if(::builder->GetInsertBlock()->empty() || !::builder->GetInsertBlock()->back().isTerminator()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 208 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 209 | llvm::Type *type = ::function->getReturnType(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 210 | |
| 211 | if(type->isVoidTy()) |
| 212 | { |
| 213 | createRetVoid(); |
| 214 | } |
| 215 | else |
| 216 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 217 | createRet(V(llvm::UndefValue::get(type))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 218 | } |
| 219 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 220 | |
| 221 | if(false) |
| 222 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 223 | std::string error; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 224 | llvm::raw_fd_ostream file("llvm-dump-unopt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 225 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | if(runOptimizations) |
| 229 | { |
| 230 | optimize(); |
| 231 | } |
| 232 | |
| 233 | if(false) |
| 234 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 235 | std::string error; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 236 | llvm::raw_fd_ostream file("llvm-dump-opt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 237 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 240 | void *entry = ::executionEngine->getPointerToFunction(::function); |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 241 | LLVMRoutine *routine = ::routineManager->acquireRoutine(entry); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 242 | |
| 243 | if(CodeAnalystLogJITCode) |
| 244 | { |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 245 | CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | return routine; |
| 249 | } |
| 250 | |
| 251 | void Nucleus::optimize() |
| 252 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 253 | static llvm::PassManager *passManager = nullptr; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 254 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 255 | if(!passManager) |
| 256 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 257 | passManager = new llvm::PassManager(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 258 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 259 | llvm::UnsafeFPMath = true; |
| 260 | // llvm::NoInfsFPMath = true; |
| 261 | // llvm::NoNaNsFPMath = true; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 262 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 263 | passManager->add(new llvm::TargetData(*::executionEngine->getTargetData())); |
| 264 | passManager->add(llvm::createScalarReplAggregatesPass()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 265 | |
| 266 | for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++) |
| 267 | { |
| 268 | switch(optimization[pass]) |
| 269 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 270 | case Disabled: break; |
| 271 | case CFGSimplification: passManager->add(llvm::createCFGSimplificationPass()); break; |
| 272 | case LICM: passManager->add(llvm::createLICMPass()); break; |
| 273 | case AggressiveDCE: passManager->add(llvm::createAggressiveDCEPass()); break; |
| 274 | case GVN: passManager->add(llvm::createGVNPass()); break; |
| 275 | case InstructionCombining: passManager->add(llvm::createInstructionCombiningPass()); break; |
| 276 | case Reassociate: passManager->add(llvm::createReassociatePass()); break; |
| 277 | case DeadStoreElimination: passManager->add(llvm::createDeadStoreEliminationPass()); break; |
| 278 | case SCCP: passManager->add(llvm::createSCCPPass()); break; |
| 279 | case ScalarReplAggregates: passManager->add(llvm::createScalarReplAggregatesPass()); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 280 | default: |
| 281 | assert(false); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 286 | passManager->run(*::module); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 287 | } |
| 288 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 289 | Value *Nucleus::allocateStackVariable(Type *type, int arraySize) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 290 | { |
| 291 | // Need to allocate it in the entry block for mem2reg to work |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 292 | llvm::BasicBlock &entryBlock = ::function->getEntryBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 293 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 294 | llvm::Instruction *declaration; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 295 | |
| 296 | if(arraySize) |
| 297 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 298 | declaration = new llvm::AllocaInst(T(type), Nucleus::createConstantInt(arraySize)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 299 | } |
| 300 | else |
| 301 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 302 | declaration = new llvm::AllocaInst(T(type), (Value*)nullptr); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | entryBlock.getInstList().push_front(declaration); |
| 306 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 307 | return V(declaration); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | BasicBlock *Nucleus::createBasicBlock() |
| 311 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 312 | return B(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | BasicBlock *Nucleus::getInsertBlock() |
| 316 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 317 | return B(::builder->GetInsertBlock()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 321 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 322 | // assert(::builder->GetInsertBlock()->back().isTerminator()); |
| 323 | return ::builder->SetInsertPoint(basicBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 326 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 327 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 328 | llvm::FunctionType *functionType = llvm::FunctionType::get(T(ReturnType), T(Params), false); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 329 | ::function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", ::module); |
| 330 | ::function->setCallingConv(llvm::CallingConv::C); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 331 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 332 | ::builder->SetInsertPoint(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 335 | Value *Nucleus::getArgument(unsigned int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 336 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 337 | llvm::Function::arg_iterator args = ::function->arg_begin(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 338 | |
| 339 | while(index) |
| 340 | { |
| 341 | args++; |
| 342 | index--; |
| 343 | } |
| 344 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 345 | return V(&*args); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 348 | void Nucleus::createRetVoid() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 349 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 350 | x86::emms(); |
| 351 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 352 | ::builder->CreateRetVoid(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 355 | void Nucleus::createRet(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 356 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 357 | x86::emms(); |
| 358 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 359 | ::builder->CreateRet(v); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 360 | } |
| 361 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 362 | void Nucleus::createBr(BasicBlock *dest) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 363 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 364 | ::builder->CreateBr(dest); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 367 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 368 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 369 | ::builder->CreateCondBr(cond, ifTrue, ifFalse); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 373 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 374 | return V(::builder->CreateAdd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 378 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 379 | return V(::builder->CreateSub(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 383 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 384 | return V(::builder->CreateMul(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 388 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 389 | return V(::builder->CreateUDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 393 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 394 | return V(::builder->CreateSDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 398 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 399 | return V(::builder->CreateFAdd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 403 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 404 | return V(::builder->CreateFSub(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 408 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 409 | return V(::builder->CreateFMul(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 413 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 414 | return V(::builder->CreateFDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 418 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 419 | return V(::builder->CreateURem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 423 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 424 | return V(::builder->CreateSRem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 428 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 429 | return V(::builder->CreateFRem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 433 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 434 | return V(::builder->CreateShl(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 438 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 439 | return V(::builder->CreateLShr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 443 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 444 | return V(::builder->CreateAShr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 448 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 449 | return V(::builder->CreateAnd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 453 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 454 | return V(::builder->CreateOr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 458 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 459 | return V(::builder->CreateXor(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 460 | } |
| 461 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 462 | Value *Nucleus::createNeg(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 463 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 464 | return V(::builder->CreateNeg(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 467 | Value *Nucleus::createFNeg(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 468 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 469 | return V(::builder->CreateFNeg(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 470 | } |
| 471 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 472 | Value *Nucleus::createNot(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 473 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 474 | return V(::builder->CreateNot(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 475 | } |
| 476 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 477 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 478 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 479 | assert(ptr->getType()->getContainedType(0) == T(type)); |
| 480 | return V(::builder->Insert(new llvm::LoadInst(ptr, "", isVolatile, align))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 483 | 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] | 484 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 485 | assert(ptr->getType()->getContainedType(0) == T(type)); |
| 486 | ::builder->Insert(new llvm::StoreInst(value, ptr, isVolatile, align)); |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 487 | return value; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 490 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 491 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 492 | if(unsignedIndex && sizeof(void*) == 8) |
| 493 | { |
| 494 | index = createZExt(index, Long::getType()); |
| 495 | } |
| 496 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 497 | assert(ptr->getType()->getContainedType(0) == T(type)); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 498 | return V(::builder->CreateGEP(ptr, index)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | } |
| 500 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 501 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 502 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 503 | return V(::builder->CreateAtomicRMW(llvm::AtomicRMWInst::Add, ptr, value, llvm::SequentiallyConsistent)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 504 | } |
| 505 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 506 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 507 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 508 | return V(::builder->CreateTrunc(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 511 | Value *Nucleus::createZExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 512 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 513 | return V(::builder->CreateZExt(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 514 | } |
| 515 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 516 | Value *Nucleus::createSExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 517 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 518 | return V(::builder->CreateSExt(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 521 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 522 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 523 | return V(::builder->CreateFPToSI(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 526 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 527 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 528 | return V(::builder->CreateSIToFP(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 529 | } |
| 530 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 531 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 532 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 533 | return V(::builder->CreateFPTrunc(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 536 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 537 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 538 | return V(::builder->CreateFPExt(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 541 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 542 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 543 | return V(::builder->CreateBitCast(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 544 | } |
| 545 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 546 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 547 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 548 | return V(::builder->CreateICmpEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 552 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 553 | return V(::builder->CreateICmpNE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 557 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 558 | return V(::builder->CreateICmpUGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 562 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 563 | return V(::builder->CreateICmpUGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 567 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 568 | return V(::builder->CreateICmpULT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 572 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 573 | return V(::builder->CreateICmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 577 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 578 | return V(::builder->CreateICmpSGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 582 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 583 | return V(::builder->CreateICmpSGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 587 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 588 | return V(::builder->CreateICmpSLT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 592 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 593 | return V(::builder->CreateICmpSLE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 597 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 598 | return V(::builder->CreateFCmpOEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 602 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 603 | return V(::builder->CreateFCmpOGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 607 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 608 | return V(::builder->CreateFCmpOGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 612 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 613 | return V(::builder->CreateFCmpOLT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 617 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 618 | return V(::builder->CreateFCmpOLE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 622 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 623 | return V(::builder->CreateFCmpONE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 627 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 628 | return V(::builder->CreateFCmpORD(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 632 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 633 | return V(::builder->CreateFCmpUNO(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 637 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 638 | return V(::builder->CreateFCmpUEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 642 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 643 | return V(::builder->CreateFCmpUGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 647 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 648 | return V(::builder->CreateFCmpUGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 652 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 653 | return V(::builder->CreateFCmpULT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 657 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 658 | return V(::builder->CreateFCmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 662 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 663 | return V(::builder->CreateFCmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 666 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 667 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 668 | assert(vector->getType()->getContainedType(0) == T(type)); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 669 | return V(::builder->CreateExtractElement(vector, createConstantInt(index))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 673 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 674 | return V(::builder->CreateInsertElement(vector, element, createConstantInt(index))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 675 | } |
| 676 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 677 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 678 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 679 | int size = llvm::cast<llvm::VectorType>(V1->getType())->getNumElements(); |
| 680 | const int maxSize = 16; |
| 681 | llvm::Constant *swizzle[maxSize]; |
| 682 | assert(size <= maxSize); |
| 683 | |
| 684 | for(int i = 0; i < size; i++) |
| 685 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 686 | swizzle[i] = llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), select[i]); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | llvm::Value *shuffle = llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(swizzle, size)); |
| 690 | |
| 691 | return V(::builder->CreateShuffleVector(V1, V2, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 695 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 696 | return V(::builder->CreateSelect(C, ifTrue, ifFalse)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 699 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 700 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 701 | return reinterpret_cast<SwitchCases*>(::builder->CreateSwitch(control, defaultBranch, numCases)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 702 | } |
| 703 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 704 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 705 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 706 | switchCases->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), label, true), branch); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 707 | } |
| 708 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 709 | void Nucleus::createUnreachable() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 710 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 711 | ::builder->CreateUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 712 | } |
| 713 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 714 | static Value *createSwizzle4(Value *val, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 715 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 716 | int swizzle[4] = |
| 717 | { |
| 718 | (select >> 0) & 0x03, |
| 719 | (select >> 2) & 0x03, |
| 720 | (select >> 4) & 0x03, |
| 721 | (select >> 6) & 0x03, |
| 722 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 723 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 724 | return Nucleus::createShuffleVector(val, val, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 725 | } |
| 726 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 727 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 728 | { |
| 729 | bool mask[4] = {false, false, false, false}; |
| 730 | |
| 731 | mask[(select >> 0) & 0x03] = true; |
| 732 | mask[(select >> 2) & 0x03] = true; |
| 733 | mask[(select >> 4) & 0x03] = true; |
| 734 | mask[(select >> 6) & 0x03] = true; |
| 735 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 736 | int swizzle[4] = |
| 737 | { |
| 738 | mask[0] ? 4 : 0, |
| 739 | mask[1] ? 5 : 1, |
| 740 | mask[2] ? 6 : 2, |
| 741 | mask[3] ? 7 : 3, |
| 742 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 743 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 744 | return Nucleus::createShuffleVector(lhs, rhs, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 745 | } |
| 746 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 747 | Type *Nucleus::getPointerType(Type *ElementType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 748 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 749 | return T(llvm::PointerType::get(T(ElementType), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 750 | } |
| 751 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 752 | Value *Nucleus::createNullValue(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 753 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 754 | return V(llvm::Constant::getNullValue(T(Ty))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 755 | } |
| 756 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 757 | Value *Nucleus::createConstantLong(int64_t i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 758 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 759 | return V(llvm::ConstantInt::get(llvm::Type::getInt64Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 760 | } |
| 761 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 762 | Value *Nucleus::createConstantInt(int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 763 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 764 | return V(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 767 | Value *Nucleus::createConstantInt(unsigned int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 768 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 769 | return V(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 770 | } |
| 771 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 772 | Value *Nucleus::createConstantBool(bool b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 773 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 774 | return V(llvm::ConstantInt::get(llvm::Type::getInt1Ty(*::context), b)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 775 | } |
| 776 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 777 | Value *Nucleus::createConstantByte(signed char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 778 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 779 | return V(llvm::ConstantInt::get(llvm::Type::getInt8Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 780 | } |
| 781 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 782 | Value *Nucleus::createConstantByte(unsigned char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 783 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 784 | return V(llvm::ConstantInt::get(llvm::Type::getInt8Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 787 | Value *Nucleus::createConstantShort(short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 788 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 789 | return V(llvm::ConstantInt::get(llvm::Type::getInt16Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 792 | Value *Nucleus::createConstantShort(unsigned short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 793 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 794 | return V(llvm::ConstantInt::get(llvm::Type::getInt16Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 795 | } |
| 796 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 797 | Value *Nucleus::createConstantFloat(float x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 798 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 799 | return V(llvm::ConstantFP::get(T(Float::getType()), x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 800 | } |
| 801 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 802 | Value *Nucleus::createNullPointer(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 803 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 804 | return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(T(Ty), 0))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 805 | } |
| 806 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 807 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 808 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 809 | assert(llvm::isa<llvm::VectorType>(T(type))); |
| 810 | const int numConstants = llvm::cast<llvm::VectorType>(T(type))->getNumElements(); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 811 | assert(numConstants <= 16); |
| 812 | llvm::Constant *constantVector[16]; |
| 813 | |
| 814 | for(int i = 0; i < numConstants; i++) |
| 815 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 816 | constantVector[i] = llvm::ConstantInt::get(T(type)->getContainedType(0), constants[i]); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numConstants))); |
| 820 | } |
| 821 | |
| 822 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
| 823 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 824 | assert(llvm::isa<llvm::VectorType>(T(type))); |
| 825 | const int numConstants = llvm::cast<llvm::VectorType>(T(type))->getNumElements(); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 826 | assert(numConstants <= 8); |
| 827 | llvm::Constant *constantVector[8]; |
| 828 | |
| 829 | for(int i = 0; i < numConstants; i++) |
| 830 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 831 | constantVector[i] = llvm::ConstantFP::get(T(type)->getContainedType(0), constants[i]); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numConstants))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 835 | } |
| 836 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 837 | Type *Void::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 838 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 839 | return T(llvm::Type::getVoidTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 840 | } |
| 841 | |
Nicolas Capens | 297d26e | 2016-11-18 12:52:17 -0500 | [diff] [blame] | 842 | class MMX : public LValue<MMX> |
Nicolas Capens | 4f738a1 | 2016-09-20 15:46:16 -0400 | [diff] [blame] | 843 | { |
| 844 | public: |
| 845 | static Type *getType(); |
| 846 | }; |
| 847 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 848 | Type *MMX::getType() |
| 849 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 850 | return T(llvm::Type::getX86_MMXTy(*::context)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 851 | } |
| 852 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 853 | Bool::Bool(Argument<Bool> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 854 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 855 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 856 | } |
| 857 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 858 | Bool::Bool(bool x) |
| 859 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 860 | storeValue(Nucleus::createConstantBool(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 861 | } |
| 862 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 863 | Bool::Bool(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 864 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 865 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | Bool::Bool(const Bool &rhs) |
| 869 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 870 | Value *value = rhs.loadValue(); |
| 871 | storeValue(value); |
| 872 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 873 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 874 | Bool::Bool(const Reference<Bool> &rhs) |
| 875 | { |
| 876 | Value *value = rhs.loadValue(); |
| 877 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 878 | } |
| 879 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 880 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 881 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 882 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | |
| 884 | return rhs; |
| 885 | } |
| 886 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 887 | RValue<Bool> Bool::operator=(const Bool &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 888 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 889 | Value *value = rhs.loadValue(); |
| 890 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 891 | |
| 892 | return RValue<Bool>(value); |
| 893 | } |
| 894 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 895 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 896 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 897 | Value *value = rhs.loadValue(); |
| 898 | storeValue(value); |
| 899 | |
| 900 | return RValue<Bool>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 901 | } |
| 902 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 903 | RValue<Bool> operator!(RValue<Bool> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 904 | { |
| 905 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 906 | } |
| 907 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 908 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 909 | { |
| 910 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 911 | } |
| 912 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 913 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 914 | { |
| 915 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 916 | } |
| 917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 918 | Type *Bool::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 919 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 920 | return T(llvm::Type::getInt1Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 923 | Byte::Byte(Argument<Byte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 924 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 925 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 926 | } |
| 927 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 928 | Byte::Byte(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 929 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 930 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 931 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 932 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 933 | } |
| 934 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 935 | Byte::Byte(RValue<UInt> cast) |
| 936 | { |
| 937 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 938 | |
| 939 | storeValue(integer); |
| 940 | } |
| 941 | |
| 942 | Byte::Byte(RValue<UShort> cast) |
| 943 | { |
| 944 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 945 | |
| 946 | storeValue(integer); |
| 947 | } |
| 948 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 949 | Byte::Byte(int x) |
| 950 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 951 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | Byte::Byte(unsigned char x) |
| 955 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 956 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 957 | } |
| 958 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 959 | Byte::Byte(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 960 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 961 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | Byte::Byte(const Byte &rhs) |
| 965 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 966 | Value *value = rhs.loadValue(); |
| 967 | storeValue(value); |
| 968 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 969 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 970 | Byte::Byte(const Reference<Byte> &rhs) |
| 971 | { |
| 972 | Value *value = rhs.loadValue(); |
| 973 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 974 | } |
| 975 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 976 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 977 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 978 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 979 | |
| 980 | return rhs; |
| 981 | } |
| 982 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 983 | RValue<Byte> Byte::operator=(const Byte &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 984 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 985 | Value *value = rhs.loadValue(); |
| 986 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 987 | |
| 988 | return RValue<Byte>(value); |
| 989 | } |
| 990 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 991 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 992 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 993 | Value *value = rhs.loadValue(); |
| 994 | storeValue(value); |
| 995 | |
| 996 | return RValue<Byte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 997 | } |
| 998 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 999 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1000 | { |
| 1001 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1002 | } |
| 1003 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1004 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1005 | { |
| 1006 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1007 | } |
| 1008 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1009 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | { |
| 1011 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1012 | } |
| 1013 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1014 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1015 | { |
| 1016 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1017 | } |
| 1018 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1019 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1020 | { |
| 1021 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1022 | } |
| 1023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1024 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1025 | { |
| 1026 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1027 | } |
| 1028 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1029 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1030 | { |
| 1031 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1032 | } |
| 1033 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1034 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1035 | { |
| 1036 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1037 | } |
| 1038 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1039 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1040 | { |
| 1041 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1042 | } |
| 1043 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1044 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1045 | { |
| 1046 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1047 | } |
| 1048 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1049 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1050 | { |
| 1051 | return lhs = lhs + rhs; |
| 1052 | } |
| 1053 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1054 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1055 | { |
| 1056 | return lhs = lhs - rhs; |
| 1057 | } |
| 1058 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1059 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1060 | { |
| 1061 | return lhs = lhs * rhs; |
| 1062 | } |
| 1063 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1064 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1065 | { |
| 1066 | return lhs = lhs / rhs; |
| 1067 | } |
| 1068 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1069 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1070 | { |
| 1071 | return lhs = lhs % rhs; |
| 1072 | } |
| 1073 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1074 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1075 | { |
| 1076 | return lhs = lhs & rhs; |
| 1077 | } |
| 1078 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1079 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1080 | { |
| 1081 | return lhs = lhs | rhs; |
| 1082 | } |
| 1083 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1084 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1085 | { |
| 1086 | return lhs = lhs ^ rhs; |
| 1087 | } |
| 1088 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1089 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1090 | { |
| 1091 | return lhs = lhs << rhs; |
| 1092 | } |
| 1093 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1094 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1095 | { |
| 1096 | return lhs = lhs >> rhs; |
| 1097 | } |
| 1098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1099 | RValue<Byte> operator+(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1100 | { |
| 1101 | return val; |
| 1102 | } |
| 1103 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1104 | RValue<Byte> operator-(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1105 | { |
| 1106 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1107 | } |
| 1108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1109 | RValue<Byte> operator~(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1110 | { |
| 1111 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1112 | } |
| 1113 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1114 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1115 | { |
| 1116 | RValue<Byte> res = val; |
| 1117 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1118 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1119 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1120 | |
| 1121 | return res; |
| 1122 | } |
| 1123 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1124 | const Byte &operator++(Byte &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1125 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1126 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1127 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1128 | |
| 1129 | return val; |
| 1130 | } |
| 1131 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1132 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1133 | { |
| 1134 | RValue<Byte> res = val; |
| 1135 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1136 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1137 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1138 | |
| 1139 | return res; |
| 1140 | } |
| 1141 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1142 | const Byte &operator--(Byte &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1143 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1144 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1145 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1146 | |
| 1147 | return val; |
| 1148 | } |
| 1149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1150 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1151 | { |
| 1152 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1153 | } |
| 1154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1155 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1156 | { |
| 1157 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1158 | } |
| 1159 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1160 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1161 | { |
| 1162 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1163 | } |
| 1164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1165 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1166 | { |
| 1167 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1168 | } |
| 1169 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1170 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1171 | { |
| 1172 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1173 | } |
| 1174 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1175 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1176 | { |
| 1177 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1178 | } |
| 1179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1180 | Type *Byte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1181 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1182 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1185 | SByte::SByte(Argument<SByte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1186 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1187 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1188 | } |
| 1189 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1190 | SByte::SByte(RValue<Int> cast) |
| 1191 | { |
| 1192 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1193 | |
| 1194 | storeValue(integer); |
| 1195 | } |
| 1196 | |
| 1197 | SByte::SByte(RValue<Short> cast) |
| 1198 | { |
| 1199 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1200 | |
| 1201 | storeValue(integer); |
| 1202 | } |
| 1203 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1204 | SByte::SByte(signed char x) |
| 1205 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1206 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1209 | SByte::SByte(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1210 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1211 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | SByte::SByte(const SByte &rhs) |
| 1215 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1216 | Value *value = rhs.loadValue(); |
| 1217 | storeValue(value); |
| 1218 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1219 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1220 | SByte::SByte(const Reference<SByte> &rhs) |
| 1221 | { |
| 1222 | Value *value = rhs.loadValue(); |
| 1223 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1226 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1227 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1228 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1229 | |
| 1230 | return rhs; |
| 1231 | } |
| 1232 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1233 | RValue<SByte> SByte::operator=(const SByte &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1234 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1235 | Value *value = rhs.loadValue(); |
| 1236 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1237 | |
| 1238 | return RValue<SByte>(value); |
| 1239 | } |
| 1240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1241 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1242 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1243 | Value *value = rhs.loadValue(); |
| 1244 | storeValue(value); |
| 1245 | |
| 1246 | return RValue<SByte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1247 | } |
| 1248 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1249 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1250 | { |
| 1251 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1252 | } |
| 1253 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1254 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1255 | { |
| 1256 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1257 | } |
| 1258 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1259 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1260 | { |
| 1261 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1262 | } |
| 1263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1264 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1265 | { |
| 1266 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1267 | } |
| 1268 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1269 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1270 | { |
| 1271 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1272 | } |
| 1273 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1274 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1275 | { |
| 1276 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1277 | } |
| 1278 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1279 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1280 | { |
| 1281 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1282 | } |
| 1283 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1284 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1285 | { |
| 1286 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1287 | } |
| 1288 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1289 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1290 | { |
| 1291 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1292 | } |
| 1293 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1294 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1295 | { |
| 1296 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1297 | } |
| 1298 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1299 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1300 | { |
| 1301 | return lhs = lhs + rhs; |
| 1302 | } |
| 1303 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1304 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1305 | { |
| 1306 | return lhs = lhs - rhs; |
| 1307 | } |
| 1308 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1309 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1310 | { |
| 1311 | return lhs = lhs * rhs; |
| 1312 | } |
| 1313 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1314 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1315 | { |
| 1316 | return lhs = lhs / rhs; |
| 1317 | } |
| 1318 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1319 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1320 | { |
| 1321 | return lhs = lhs % rhs; |
| 1322 | } |
| 1323 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1324 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1325 | { |
| 1326 | return lhs = lhs & rhs; |
| 1327 | } |
| 1328 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1329 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1330 | { |
| 1331 | return lhs = lhs | rhs; |
| 1332 | } |
| 1333 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1334 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1335 | { |
| 1336 | return lhs = lhs ^ rhs; |
| 1337 | } |
| 1338 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1339 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1340 | { |
| 1341 | return lhs = lhs << rhs; |
| 1342 | } |
| 1343 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1344 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1345 | { |
| 1346 | return lhs = lhs >> rhs; |
| 1347 | } |
| 1348 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1349 | RValue<SByte> operator+(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1350 | { |
| 1351 | return val; |
| 1352 | } |
| 1353 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1354 | RValue<SByte> operator-(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1355 | { |
| 1356 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1357 | } |
| 1358 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1359 | RValue<SByte> operator~(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1360 | { |
| 1361 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1362 | } |
| 1363 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1364 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1365 | { |
| 1366 | RValue<SByte> res = val; |
| 1367 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1368 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1369 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1370 | |
| 1371 | return res; |
| 1372 | } |
| 1373 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1374 | const SByte &operator++(SByte &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1375 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1376 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1377 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1378 | |
| 1379 | return val; |
| 1380 | } |
| 1381 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1382 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1383 | { |
| 1384 | RValue<SByte> res = val; |
| 1385 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1386 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1387 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1388 | |
| 1389 | return res; |
| 1390 | } |
| 1391 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1392 | const SByte &operator--(SByte &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1393 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1394 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1395 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1396 | |
| 1397 | return val; |
| 1398 | } |
| 1399 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1400 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1401 | { |
| 1402 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1403 | } |
| 1404 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1405 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1406 | { |
| 1407 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1408 | } |
| 1409 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1410 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1411 | { |
| 1412 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1413 | } |
| 1414 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1415 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1416 | { |
| 1417 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1418 | } |
| 1419 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1420 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1421 | { |
| 1422 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1423 | } |
| 1424 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1425 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1426 | { |
| 1427 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1428 | } |
| 1429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1430 | Type *SByte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1431 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1432 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1435 | Short::Short(Argument<Short> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1436 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1437 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1438 | } |
| 1439 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1440 | Short::Short(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1441 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1442 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1443 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1444 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1447 | Short::Short(short x) |
| 1448 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1449 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1452 | Short::Short(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1453 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1454 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | Short::Short(const Short &rhs) |
| 1458 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1459 | Value *value = rhs.loadValue(); |
| 1460 | storeValue(value); |
| 1461 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1462 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1463 | Short::Short(const Reference<Short> &rhs) |
| 1464 | { |
| 1465 | Value *value = rhs.loadValue(); |
| 1466 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1467 | } |
| 1468 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1469 | RValue<Short> Short::operator=(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1470 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1471 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1472 | |
| 1473 | return rhs; |
| 1474 | } |
| 1475 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1476 | RValue<Short> Short::operator=(const Short &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1477 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1478 | Value *value = rhs.loadValue(); |
| 1479 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1480 | |
| 1481 | return RValue<Short>(value); |
| 1482 | } |
| 1483 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1484 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1485 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1486 | Value *value = rhs.loadValue(); |
| 1487 | storeValue(value); |
| 1488 | |
| 1489 | return RValue<Short>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1490 | } |
| 1491 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1492 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1493 | { |
| 1494 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1495 | } |
| 1496 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1497 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1498 | { |
| 1499 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1500 | } |
| 1501 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1502 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1503 | { |
| 1504 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1505 | } |
| 1506 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1507 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1508 | { |
| 1509 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1510 | } |
| 1511 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1512 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1513 | { |
| 1514 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1515 | } |
| 1516 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1517 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1518 | { |
| 1519 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1520 | } |
| 1521 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1522 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1523 | { |
| 1524 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1525 | } |
| 1526 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1527 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1528 | { |
| 1529 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1530 | } |
| 1531 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1532 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1533 | { |
| 1534 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1535 | } |
| 1536 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1537 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1538 | { |
| 1539 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1540 | } |
| 1541 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1542 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1543 | { |
| 1544 | return lhs = lhs + rhs; |
| 1545 | } |
| 1546 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1547 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1548 | { |
| 1549 | return lhs = lhs - rhs; |
| 1550 | } |
| 1551 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1552 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1553 | { |
| 1554 | return lhs = lhs * rhs; |
| 1555 | } |
| 1556 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1557 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1558 | { |
| 1559 | return lhs = lhs / rhs; |
| 1560 | } |
| 1561 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1562 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1563 | { |
| 1564 | return lhs = lhs % rhs; |
| 1565 | } |
| 1566 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1567 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1568 | { |
| 1569 | return lhs = lhs & rhs; |
| 1570 | } |
| 1571 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1572 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1573 | { |
| 1574 | return lhs = lhs | rhs; |
| 1575 | } |
| 1576 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1577 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1578 | { |
| 1579 | return lhs = lhs ^ rhs; |
| 1580 | } |
| 1581 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1582 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1583 | { |
| 1584 | return lhs = lhs << rhs; |
| 1585 | } |
| 1586 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1587 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1588 | { |
| 1589 | return lhs = lhs >> rhs; |
| 1590 | } |
| 1591 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1592 | RValue<Short> operator+(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1593 | { |
| 1594 | return val; |
| 1595 | } |
| 1596 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1597 | RValue<Short> operator-(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1598 | { |
| 1599 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 1600 | } |
| 1601 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1602 | RValue<Short> operator~(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1603 | { |
| 1604 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 1605 | } |
| 1606 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1607 | RValue<Short> operator++(Short &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1608 | { |
| 1609 | RValue<Short> res = val; |
| 1610 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1611 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1612 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1613 | |
| 1614 | return res; |
| 1615 | } |
| 1616 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1617 | const Short &operator++(Short &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1618 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1619 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1620 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1621 | |
| 1622 | return val; |
| 1623 | } |
| 1624 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1625 | RValue<Short> operator--(Short &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1626 | { |
| 1627 | RValue<Short> res = val; |
| 1628 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1629 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1630 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1631 | |
| 1632 | return res; |
| 1633 | } |
| 1634 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1635 | const Short &operator--(Short &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1636 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1637 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1638 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1639 | |
| 1640 | return val; |
| 1641 | } |
| 1642 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1643 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1644 | { |
| 1645 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1646 | } |
| 1647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1648 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1649 | { |
| 1650 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1651 | } |
| 1652 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1653 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1654 | { |
| 1655 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1656 | } |
| 1657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1658 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1659 | { |
| 1660 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1661 | } |
| 1662 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1663 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1664 | { |
| 1665 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1666 | } |
| 1667 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1668 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1669 | { |
| 1670 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1671 | } |
| 1672 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1673 | Type *Short::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1674 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1675 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1678 | UShort::UShort(Argument<UShort> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1679 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1680 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1681 | } |
| 1682 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1683 | UShort::UShort(RValue<UInt> cast) |
| 1684 | { |
| 1685 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1686 | |
| 1687 | storeValue(integer); |
| 1688 | } |
| 1689 | |
Alexis Hetu | 75b650f | 2015-11-19 17:40:15 -0500 | [diff] [blame] | 1690 | UShort::UShort(RValue<Int> cast) |
| 1691 | { |
| 1692 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1693 | |
| 1694 | storeValue(integer); |
| 1695 | } |
| 1696 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1697 | UShort::UShort(unsigned short x) |
| 1698 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1699 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1700 | } |
| 1701 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1702 | UShort::UShort(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1703 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1704 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | UShort::UShort(const UShort &rhs) |
| 1708 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1709 | Value *value = rhs.loadValue(); |
| 1710 | storeValue(value); |
| 1711 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1712 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1713 | UShort::UShort(const Reference<UShort> &rhs) |
| 1714 | { |
| 1715 | Value *value = rhs.loadValue(); |
| 1716 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1717 | } |
| 1718 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1719 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1720 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1721 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | |
| 1723 | return rhs; |
| 1724 | } |
| 1725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1726 | RValue<UShort> UShort::operator=(const UShort &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1727 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1728 | Value *value = rhs.loadValue(); |
| 1729 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1730 | |
| 1731 | return RValue<UShort>(value); |
| 1732 | } |
| 1733 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1734 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1735 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1736 | Value *value = rhs.loadValue(); |
| 1737 | storeValue(value); |
| 1738 | |
| 1739 | return RValue<UShort>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1742 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1743 | { |
| 1744 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1745 | } |
| 1746 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1747 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1748 | { |
| 1749 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1750 | } |
| 1751 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1752 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1753 | { |
| 1754 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1755 | } |
| 1756 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1757 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1758 | { |
| 1759 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1760 | } |
| 1761 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1762 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1763 | { |
| 1764 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1765 | } |
| 1766 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1767 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1768 | { |
| 1769 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1770 | } |
| 1771 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1772 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1773 | { |
| 1774 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1775 | } |
| 1776 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1777 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1778 | { |
| 1779 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1780 | } |
| 1781 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1782 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1783 | { |
| 1784 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1785 | } |
| 1786 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1787 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1788 | { |
| 1789 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1790 | } |
| 1791 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1792 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1793 | { |
| 1794 | return lhs = lhs + rhs; |
| 1795 | } |
| 1796 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1797 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1798 | { |
| 1799 | return lhs = lhs - rhs; |
| 1800 | } |
| 1801 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1802 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1803 | { |
| 1804 | return lhs = lhs * rhs; |
| 1805 | } |
| 1806 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1807 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1808 | { |
| 1809 | return lhs = lhs / rhs; |
| 1810 | } |
| 1811 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1812 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1813 | { |
| 1814 | return lhs = lhs % rhs; |
| 1815 | } |
| 1816 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1817 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1818 | { |
| 1819 | return lhs = lhs & rhs; |
| 1820 | } |
| 1821 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1822 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1823 | { |
| 1824 | return lhs = lhs | rhs; |
| 1825 | } |
| 1826 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1827 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1828 | { |
| 1829 | return lhs = lhs ^ rhs; |
| 1830 | } |
| 1831 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1832 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1833 | { |
| 1834 | return lhs = lhs << rhs; |
| 1835 | } |
| 1836 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1837 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1838 | { |
| 1839 | return lhs = lhs >> rhs; |
| 1840 | } |
| 1841 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1842 | RValue<UShort> operator+(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1843 | { |
| 1844 | return val; |
| 1845 | } |
| 1846 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1847 | RValue<UShort> operator-(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1848 | { |
| 1849 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 1850 | } |
| 1851 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1852 | RValue<UShort> operator~(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1853 | { |
| 1854 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 1855 | } |
| 1856 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1857 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1858 | { |
| 1859 | RValue<UShort> res = val; |
| 1860 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1861 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1862 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1863 | |
| 1864 | return res; |
| 1865 | } |
| 1866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1867 | const UShort &operator++(UShort &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1868 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1869 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1870 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1871 | |
| 1872 | return val; |
| 1873 | } |
| 1874 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1875 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1876 | { |
| 1877 | RValue<UShort> res = val; |
| 1878 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1879 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1880 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1881 | |
| 1882 | return res; |
| 1883 | } |
| 1884 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1885 | const UShort &operator--(UShort &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1886 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1887 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1888 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1889 | |
| 1890 | return val; |
| 1891 | } |
| 1892 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1893 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1894 | { |
| 1895 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1896 | } |
| 1897 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1898 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1899 | { |
| 1900 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1901 | } |
| 1902 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1903 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1904 | { |
| 1905 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1906 | } |
| 1907 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1908 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1909 | { |
| 1910 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1911 | } |
| 1912 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1913 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1914 | { |
| 1915 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1916 | } |
| 1917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1918 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1919 | { |
| 1920 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1921 | } |
| 1922 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1923 | Type *UShort::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1924 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1925 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1926 | } |
| 1927 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 1928 | Byte4::Byte4(RValue<Byte8> cast) |
| 1929 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 1930 | storeValue(Nucleus::createTrunc(Nucleus::createBitCast(cast.value, Long::getType()), Int::getType())); |
| 1931 | } |
| 1932 | |
| 1933 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 1934 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 1935 | Value *value = rhs.loadValue(); |
| 1936 | storeValue(value); |
| 1937 | } |
| 1938 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1939 | Type *Byte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1940 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 1941 | return T(Type_v4i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1942 | } |
| 1943 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1944 | Type *SByte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1945 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 1946 | return T(Type_v4i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1947 | } |
| 1948 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 1949 | 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] | 1950 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1951 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 1952 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(Byte::getType()), 8)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1953 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1954 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1955 | } |
| 1956 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1957 | Byte8::Byte8(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1958 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1959 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | Byte8::Byte8(const Byte8 &rhs) |
| 1963 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1964 | Value *value = rhs.loadValue(); |
| 1965 | storeValue(value); |
| 1966 | } |
| 1967 | |
| 1968 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 1969 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1970 | Value *value = rhs.loadValue(); |
| 1971 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1974 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1975 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1976 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1977 | |
| 1978 | return rhs; |
| 1979 | } |
| 1980 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1981 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1982 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1983 | Value *value = rhs.loadValue(); |
| 1984 | storeValue(value); |
| 1985 | |
| 1986 | return RValue<Byte8>(value); |
| 1987 | } |
| 1988 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1989 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1990 | { |
| 1991 | Value *value = rhs.loadValue(); |
| 1992 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1993 | |
| 1994 | return RValue<Byte8>(value); |
| 1995 | } |
| 1996 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1997 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1998 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1999 | if(CPUID::supportsMMX2()) |
| 2000 | { |
| 2001 | return x86::paddb(lhs, rhs); |
| 2002 | } |
| 2003 | else |
| 2004 | { |
| 2005 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2006 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2007 | } |
| 2008 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2009 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2010 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2011 | if(CPUID::supportsMMX2()) |
| 2012 | { |
| 2013 | return x86::psubb(lhs, rhs); |
| 2014 | } |
| 2015 | else |
| 2016 | { |
| 2017 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2018 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2019 | } |
| 2020 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2021 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2022 | // { |
| 2023 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2024 | // } |
| 2025 | |
| 2026 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2027 | // { |
| 2028 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2029 | // } |
| 2030 | |
| 2031 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2032 | // { |
| 2033 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2034 | // } |
| 2035 | |
| 2036 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2037 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2038 | if(CPUID::supportsMMX2()) |
| 2039 | { |
| 2040 | return As<Byte8>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 2041 | } |
| 2042 | else |
| 2043 | { |
| 2044 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2045 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2046 | } |
| 2047 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2048 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2049 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2050 | if(CPUID::supportsMMX2()) |
| 2051 | { |
| 2052 | return As<Byte8>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 2053 | } |
| 2054 | else |
| 2055 | { |
| 2056 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2057 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2058 | } |
| 2059 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2060 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2061 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2062 | if(CPUID::supportsMMX2()) |
| 2063 | { |
| 2064 | return As<Byte8>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 2065 | } |
| 2066 | else |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2067 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2068 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2069 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2070 | } |
| 2071 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2072 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2073 | // { |
| 2074 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2075 | // } |
| 2076 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2077 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2078 | // { |
| 2079 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2080 | // } |
| 2081 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2082 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2083 | { |
| 2084 | return lhs = lhs + rhs; |
| 2085 | } |
| 2086 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2087 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2088 | { |
| 2089 | return lhs = lhs - rhs; |
| 2090 | } |
| 2091 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2092 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2093 | // { |
| 2094 | // return lhs = lhs * rhs; |
| 2095 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2096 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2097 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2098 | // { |
| 2099 | // return lhs = lhs / rhs; |
| 2100 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2101 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2102 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2103 | // { |
| 2104 | // return lhs = lhs % rhs; |
| 2105 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2106 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2107 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2108 | { |
| 2109 | return lhs = lhs & rhs; |
| 2110 | } |
| 2111 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2112 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2113 | { |
| 2114 | return lhs = lhs | rhs; |
| 2115 | } |
| 2116 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2117 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2118 | { |
| 2119 | return lhs = lhs ^ rhs; |
| 2120 | } |
| 2121 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2122 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2123 | // { |
| 2124 | // return lhs = lhs << rhs; |
| 2125 | // } |
| 2126 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2127 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2128 | // { |
| 2129 | // return lhs = lhs >> rhs; |
| 2130 | // } |
| 2131 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2132 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2133 | // { |
| 2134 | // return val; |
| 2135 | // } |
| 2136 | |
| 2137 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2138 | // { |
| 2139 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2140 | // } |
| 2141 | |
| 2142 | RValue<Byte8> operator~(RValue<Byte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2143 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2144 | if(CPUID::supportsMMX2()) |
| 2145 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2146 | return val ^ Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2147 | } |
| 2148 | else |
| 2149 | { |
| 2150 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2151 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2152 | } |
| 2153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2154 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2155 | { |
| 2156 | return x86::paddusb(x, y); |
| 2157 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2158 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2159 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2160 | { |
| 2161 | return x86::psubusb(x, y); |
| 2162 | } |
| 2163 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2164 | RValue<Short4> Unpack(RValue<Byte4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2165 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2166 | Value *int2 = Nucleus::createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Int::getType()), 2))), x.value, 0); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2167 | Value *byte8 = Nucleus::createBitCast(int2, Byte8::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2169 | return UnpackLow(RValue<Byte8>(byte8), RValue<Byte8>(byte8)); |
| 2170 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2171 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2172 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2173 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2174 | Value *xx = Nucleus::createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Int::getType()), 2))), x.value, 0); |
| 2175 | Value *yy = Nucleus::createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Int::getType()), 2))), y.value, 0); |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2176 | |
| 2177 | return UnpackLow(As<Byte8>(xx), As<Byte8>(yy)); |
| 2178 | } |
| 2179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2180 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2181 | { |
| 2182 | if(CPUID::supportsMMX2()) |
| 2183 | { |
| 2184 | return x86::punpcklbw(x, y); |
| 2185 | } |
| 2186 | else |
| 2187 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2188 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 2189 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2190 | |
| 2191 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2192 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2193 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2194 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2195 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2196 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2197 | if(CPUID::supportsMMX2()) |
| 2198 | { |
| 2199 | return x86::punpckhbw(x, y); |
| 2200 | } |
| 2201 | else |
| 2202 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2203 | int shuffle[8] = {4, 12, 5, 13, 6, 14, 7, 15}; |
| 2204 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2205 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2206 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2207 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2208 | } |
| 2209 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2210 | RValue<Int> SignMask(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2211 | { |
| 2212 | return x86::pmovmskb(x); |
| 2213 | } |
| 2214 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2215 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2216 | // { |
| 2217 | // return x86::pcmpgtb(x, y); // FIXME: Signedness |
| 2218 | // } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2219 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2220 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2221 | { |
| 2222 | return x86::pcmpeqb(x, y); |
| 2223 | } |
| 2224 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2225 | Type *Byte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2226 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2227 | return T(Type_v8i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2228 | } |
| 2229 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 2230 | 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] | 2231 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2232 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2233 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(SByte::getType()), 8)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2234 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2235 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2236 | } |
| 2237 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2238 | SByte8::SByte8(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2239 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2240 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | SByte8::SByte8(const SByte8 &rhs) |
| 2244 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2245 | Value *value = rhs.loadValue(); |
| 2246 | storeValue(value); |
| 2247 | } |
| 2248 | |
| 2249 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2250 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2251 | Value *value = rhs.loadValue(); |
| 2252 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2253 | } |
| 2254 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2255 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2256 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2257 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2258 | |
| 2259 | return rhs; |
| 2260 | } |
| 2261 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2262 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2263 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2264 | Value *value = rhs.loadValue(); |
| 2265 | storeValue(value); |
| 2266 | |
| 2267 | return RValue<SByte8>(value); |
| 2268 | } |
| 2269 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2270 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2271 | { |
| 2272 | Value *value = rhs.loadValue(); |
| 2273 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2274 | |
| 2275 | return RValue<SByte8>(value); |
| 2276 | } |
| 2277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2278 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2279 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2280 | if(CPUID::supportsMMX2()) |
| 2281 | { |
| 2282 | return As<SByte8>(x86::paddb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2283 | } |
| 2284 | else |
| 2285 | { |
| 2286 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2287 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2288 | } |
| 2289 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2290 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2291 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2292 | if(CPUID::supportsMMX2()) |
| 2293 | { |
| 2294 | return As<SByte8>(x86::psubb(As<Byte8>(lhs), As<Byte8>(rhs))); |
| 2295 | } |
| 2296 | else |
| 2297 | { |
| 2298 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2299 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2300 | } |
| 2301 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2302 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2303 | // { |
| 2304 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2305 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2306 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2307 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2308 | // { |
| 2309 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2310 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2311 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2312 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2313 | // { |
| 2314 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2315 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2316 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2317 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2318 | { |
| 2319 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2320 | } |
| 2321 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2322 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2323 | { |
| 2324 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2325 | } |
| 2326 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2327 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2328 | { |
| 2329 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2330 | } |
| 2331 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2332 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2333 | // { |
| 2334 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2335 | // } |
| 2336 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2337 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2338 | // { |
| 2339 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2340 | // } |
| 2341 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2342 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2343 | { |
| 2344 | return lhs = lhs + rhs; |
| 2345 | } |
| 2346 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2347 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2348 | { |
| 2349 | return lhs = lhs - rhs; |
| 2350 | } |
| 2351 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2352 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2353 | // { |
| 2354 | // return lhs = lhs * rhs; |
| 2355 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2356 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2357 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2358 | // { |
| 2359 | // return lhs = lhs / rhs; |
| 2360 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2361 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2362 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2363 | // { |
| 2364 | // return lhs = lhs % rhs; |
| 2365 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2366 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2367 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2368 | { |
| 2369 | return lhs = lhs & rhs; |
| 2370 | } |
| 2371 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2372 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2373 | { |
| 2374 | return lhs = lhs | rhs; |
| 2375 | } |
| 2376 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2377 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2378 | { |
| 2379 | return lhs = lhs ^ rhs; |
| 2380 | } |
| 2381 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2382 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2383 | // { |
| 2384 | // return lhs = lhs << rhs; |
| 2385 | // } |
| 2386 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2387 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2388 | // { |
| 2389 | // return lhs = lhs >> rhs; |
| 2390 | // } |
| 2391 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2392 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2393 | // { |
| 2394 | // return val; |
| 2395 | // } |
| 2396 | |
| 2397 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2398 | // { |
| 2399 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2400 | // } |
| 2401 | |
| 2402 | RValue<SByte8> operator~(RValue<SByte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2403 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2404 | if(CPUID::supportsMMX2()) |
| 2405 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2406 | return val ^ SByte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2407 | } |
| 2408 | else |
| 2409 | { |
| 2410 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2411 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2412 | } |
| 2413 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2414 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2415 | { |
| 2416 | return x86::paddsb(x, y); |
| 2417 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2418 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2419 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2420 | { |
| 2421 | return x86::psubsb(x, y); |
| 2422 | } |
| 2423 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2424 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2425 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2426 | if(CPUID::supportsMMX2()) |
| 2427 | { |
| 2428 | return As<Short4>(x86::punpcklbw(As<Byte8>(x), As<Byte8>(y))); |
| 2429 | } |
| 2430 | else |
| 2431 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2432 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 2433 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2434 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2435 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2436 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2437 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2438 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2439 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2440 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2441 | if(CPUID::supportsMMX2()) |
| 2442 | { |
| 2443 | return As<Short4>(x86::punpckhbw(As<Byte8>(x), As<Byte8>(y))); |
| 2444 | } |
| 2445 | else |
| 2446 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2447 | int shuffle[8] = {4, 12, 5, 13, 6, 14, 7, 15}; |
| 2448 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2449 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2450 | return RValue<Short4>(Nucleus::createBitCast(packed, Short4::getType())); |
| 2451 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2452 | } |
| 2453 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2454 | RValue<Int> SignMask(RValue<SByte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2455 | { |
| 2456 | return x86::pmovmskb(As<Byte8>(x)); |
| 2457 | } |
| 2458 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2459 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2460 | { |
| 2461 | return x86::pcmpgtb(x, y); |
| 2462 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2463 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2464 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2465 | { |
| 2466 | return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y)); |
| 2467 | } |
| 2468 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2469 | Type *SByte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2470 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2471 | return T(Type_v8i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2472 | } |
| 2473 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2474 | Byte16::Byte16(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2475 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2476 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | Byte16::Byte16(const Byte16 &rhs) |
| 2480 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2481 | Value *value = rhs.loadValue(); |
| 2482 | storeValue(value); |
| 2483 | } |
| 2484 | |
| 2485 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2486 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2487 | Value *value = rhs.loadValue(); |
| 2488 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2489 | } |
| 2490 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2491 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2492 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2493 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2494 | |
| 2495 | return rhs; |
| 2496 | } |
| 2497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2498 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2499 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2500 | Value *value = rhs.loadValue(); |
| 2501 | storeValue(value); |
| 2502 | |
| 2503 | return RValue<Byte16>(value); |
| 2504 | } |
| 2505 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2506 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2507 | { |
| 2508 | Value *value = rhs.loadValue(); |
| 2509 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2510 | |
| 2511 | return RValue<Byte16>(value); |
| 2512 | } |
| 2513 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2514 | Type *Byte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2515 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2516 | return T(llvm::VectorType::get(T(Byte::getType()), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2517 | } |
| 2518 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2519 | Type *SByte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2520 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2521 | return T(llvm::VectorType::get(T(SByte::getType()), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2522 | } |
| 2523 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2524 | Short2::Short2(RValue<Short4> cast) |
| 2525 | { |
| 2526 | storeValue(Nucleus::createTrunc(Nucleus::createBitCast(cast.value, Long::getType()), UInt::getType())); |
| 2527 | } |
| 2528 | |
| 2529 | Type *Short2::getType() |
| 2530 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2531 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | UShort2::UShort2(RValue<UShort4> cast) |
| 2535 | { |
| 2536 | storeValue(Nucleus::createTrunc(Nucleus::createBitCast(cast.value, Long::getType()), UInt::getType())); |
| 2537 | } |
| 2538 | |
| 2539 | Type *UShort2::getType() |
| 2540 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2541 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2544 | Short4::Short4(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2545 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2546 | Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 2547 | Value *swizzle = Swizzle(As<Short4>(extend), 0x00).value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2548 | |
| 2549 | storeValue(swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2550 | } |
| 2551 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2552 | Short4::Short4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2553 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2554 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 2555 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 2556 | Value *packed; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2557 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 2558 | // FIXME: Use Swizzle<Short8> |
| 2559 | if(!CPUID::supportsSSSE3()) |
| 2560 | { |
| 2561 | int pshuflw[8] = {0, 2, 0, 2, 4, 5, 6, 7}; |
| 2562 | int pshufhw[8] = {0, 1, 2, 3, 4, 6, 4, 6}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2563 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 2564 | Value *shuffle1 = Nucleus::createShuffleVector(short8, short8, pshuflw); |
| 2565 | Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, shuffle1, pshufhw); |
| 2566 | Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType()); |
| 2567 | packed = createSwizzle4(int4, 0x88); |
| 2568 | } |
| 2569 | else |
| 2570 | { |
| 2571 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
| 2572 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2573 | packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
| 2574 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2575 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 2576 | Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value; |
| 2577 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2578 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2579 | storeValue(short4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2580 | } |
| 2581 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2582 | // Short4::Short4(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2583 | // { |
| 2584 | // } |
| 2585 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2586 | Short4::Short4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2587 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2588 | Int4 v4i32 = Int4(cast); |
| 2589 | v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2590 | |
| 2591 | storeValue(As<Short4>(Int2(v4i32)).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2592 | } |
| 2593 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2594 | Short4::Short4(short xyzw) |
| 2595 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2596 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2597 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(Short::getType()), 4)))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2598 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2599 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2600 | } |
| 2601 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2602 | Short4::Short4(short x, short y, short z, short w) |
| 2603 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2604 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2605 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(Short::getType()), 4)))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2606 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2607 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2608 | } |
| 2609 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2610 | Short4::Short4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2611 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2612 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | Short4::Short4(const Short4 &rhs) |
| 2616 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2617 | Value *value = rhs.loadValue(); |
| 2618 | storeValue(value); |
| 2619 | } |
| 2620 | |
| 2621 | Short4::Short4(const Reference<Short4> &rhs) |
| 2622 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2623 | Value *value = rhs.loadValue(); |
| 2624 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2625 | } |
| 2626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2627 | Short4::Short4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2628 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2629 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | Short4::Short4(const UShort4 &rhs) |
| 2633 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2634 | storeValue(rhs.loadValue()); |
| 2635 | } |
| 2636 | |
| 2637 | Short4::Short4(const Reference<UShort4> &rhs) |
| 2638 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2639 | storeValue(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2640 | } |
| 2641 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2642 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2643 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2644 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2645 | |
| 2646 | return rhs; |
| 2647 | } |
| 2648 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2649 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2650 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2651 | Value *value = rhs.loadValue(); |
| 2652 | storeValue(value); |
| 2653 | |
| 2654 | return RValue<Short4>(value); |
| 2655 | } |
| 2656 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2657 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2658 | { |
| 2659 | Value *value = rhs.loadValue(); |
| 2660 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2661 | |
| 2662 | return RValue<Short4>(value); |
| 2663 | } |
| 2664 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2665 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2666 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2667 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2668 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2669 | return RValue<Short4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2670 | } |
| 2671 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2672 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2673 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2674 | Value *value = rhs.loadValue(); |
| 2675 | storeValue(value); |
| 2676 | |
| 2677 | return RValue<Short4>(value); |
| 2678 | } |
| 2679 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2680 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2681 | { |
| 2682 | Value *value = rhs.loadValue(); |
| 2683 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2684 | |
| 2685 | return RValue<Short4>(value); |
| 2686 | } |
| 2687 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2688 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2689 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2690 | if(CPUID::supportsMMX2()) |
| 2691 | { |
| 2692 | return x86::paddw(lhs, rhs); |
| 2693 | } |
| 2694 | else |
| 2695 | { |
| 2696 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2697 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2698 | } |
| 2699 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2700 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2701 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2702 | if(CPUID::supportsMMX2()) |
| 2703 | { |
| 2704 | return x86::psubw(lhs, rhs); |
| 2705 | } |
| 2706 | else |
| 2707 | { |
| 2708 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2709 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2710 | } |
| 2711 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2712 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2713 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2714 | if(CPUID::supportsMMX2()) |
| 2715 | { |
| 2716 | return x86::pmullw(lhs, rhs); |
| 2717 | } |
| 2718 | else |
| 2719 | { |
| 2720 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2721 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2724 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2725 | // { |
| 2726 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2727 | // } |
| 2728 | |
| 2729 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2730 | // { |
| 2731 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2732 | // } |
| 2733 | |
| 2734 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2735 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2736 | if(CPUID::supportsMMX2()) |
| 2737 | { |
| 2738 | return x86::pand(lhs, rhs); |
| 2739 | } |
| 2740 | else |
| 2741 | { |
| 2742 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2743 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2744 | } |
| 2745 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2746 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2747 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2748 | if(CPUID::supportsMMX2()) |
| 2749 | { |
| 2750 | return x86::por(lhs, rhs); |
| 2751 | } |
| 2752 | else |
| 2753 | { |
| 2754 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2755 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2756 | } |
| 2757 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2758 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2759 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2760 | if(CPUID::supportsMMX2()) |
| 2761 | { |
| 2762 | return x86::pxor(lhs, rhs); |
| 2763 | } |
| 2764 | else |
| 2765 | { |
| 2766 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2767 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2768 | } |
| 2769 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2770 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2771 | { |
| 2772 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2773 | |
| 2774 | return x86::psllw(lhs, rhs); |
| 2775 | } |
| 2776 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2777 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2778 | { |
| 2779 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2780 | |
| 2781 | return x86::psraw(lhs, rhs); |
| 2782 | } |
| 2783 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2784 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2785 | { |
| 2786 | return lhs = lhs + rhs; |
| 2787 | } |
| 2788 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2789 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2790 | { |
| 2791 | return lhs = lhs - rhs; |
| 2792 | } |
| 2793 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2794 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2795 | { |
| 2796 | return lhs = lhs * rhs; |
| 2797 | } |
| 2798 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2799 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2800 | // { |
| 2801 | // return lhs = lhs / rhs; |
| 2802 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2803 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2804 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2805 | // { |
| 2806 | // return lhs = lhs % rhs; |
| 2807 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2808 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2809 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2810 | { |
| 2811 | return lhs = lhs & rhs; |
| 2812 | } |
| 2813 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2814 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2815 | { |
| 2816 | return lhs = lhs | rhs; |
| 2817 | } |
| 2818 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2819 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2820 | { |
| 2821 | return lhs = lhs ^ rhs; |
| 2822 | } |
| 2823 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2824 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2825 | { |
| 2826 | return lhs = lhs << rhs; |
| 2827 | } |
| 2828 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2829 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2830 | { |
| 2831 | return lhs = lhs >> rhs; |
| 2832 | } |
| 2833 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2834 | // RValue<Short4> operator+(RValue<Short4> val) |
| 2835 | // { |
| 2836 | // return val; |
| 2837 | // } |
| 2838 | |
| 2839 | RValue<Short4> operator-(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2840 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2841 | if(CPUID::supportsMMX2()) |
| 2842 | { |
| 2843 | return Short4(0, 0, 0, 0) - val; |
| 2844 | } |
| 2845 | else |
| 2846 | { |
| 2847 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
| 2848 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2849 | } |
| 2850 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2851 | RValue<Short4> operator~(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2852 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2853 | if(CPUID::supportsMMX2()) |
| 2854 | { |
| 2855 | return val ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu); |
| 2856 | } |
| 2857 | else |
| 2858 | { |
| 2859 | return RValue<Short4>(Nucleus::createNot(val.value)); |
| 2860 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2861 | } |
| 2862 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2863 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2864 | { |
| 2865 | RValue<Int4> v4i32 = x86::cvtps2dq(cast); |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 2866 | RValue<Short8> v8i16 = x86::packssdw(v4i32, v4i32); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2867 | |
Nicolas Capens | 698633a | 2015-02-04 00:16:13 -0500 | [diff] [blame] | 2868 | return As<Short4>(Int2(As<Int4>(v8i16))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2869 | } |
| 2870 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2871 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2872 | { |
| 2873 | return x86::pmaxsw(x, y); |
| 2874 | } |
| 2875 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2876 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2877 | { |
| 2878 | return x86::pminsw(x, y); |
| 2879 | } |
| 2880 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2881 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2882 | { |
| 2883 | return x86::paddsw(x, y); |
| 2884 | } |
| 2885 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2886 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2887 | { |
| 2888 | return x86::psubsw(x, y); |
| 2889 | } |
| 2890 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2891 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2892 | { |
| 2893 | return x86::pmulhw(x, y); |
| 2894 | } |
| 2895 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2896 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2897 | { |
| 2898 | return x86::pmaddwd(x, y); |
| 2899 | } |
| 2900 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2901 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2902 | { |
| 2903 | return x86::packsswb(x, y); |
| 2904 | } |
| 2905 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2906 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2907 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2908 | if(CPUID::supportsMMX2()) |
| 2909 | { |
| 2910 | return x86::punpcklwd(x, y); |
| 2911 | } |
| 2912 | else |
| 2913 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2914 | int shuffle[4] = {0, 4, 1, 5}; |
| 2915 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2916 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2917 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 2918 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2919 | } |
| 2920 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2921 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2922 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2923 | if(CPUID::supportsMMX2()) |
| 2924 | { |
| 2925 | return x86::punpckhwd(x, y); |
| 2926 | } |
| 2927 | else |
| 2928 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 2929 | int shuffle[4] = {2, 6, 3, 7}; |
| 2930 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2931 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2932 | return RValue<Int2>(Nucleus::createBitCast(packed, Int2::getType())); |
| 2933 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2934 | } |
| 2935 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2936 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2937 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2938 | if(CPUID::supportsMMX2()) |
| 2939 | { |
| 2940 | return x86::pshufw(x, select); |
| 2941 | } |
| 2942 | else |
| 2943 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 2944 | return RValue<Short4>(createSwizzle4(x.value, select)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2945 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2946 | } |
| 2947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2948 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2949 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2950 | if(CPUID::supportsMMX2()) |
| 2951 | { |
| 2952 | return x86::pinsrw(val, Int(element), i); |
| 2953 | } |
| 2954 | else |
| 2955 | { |
| 2956 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2957 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2958 | } |
| 2959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2960 | RValue<Short> Extract(RValue<Short4> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2961 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2962 | if(CPUID::supportsMMX2()) |
| 2963 | { |
| 2964 | return Short(x86::pextrw(val, i)); |
| 2965 | } |
| 2966 | else |
| 2967 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 2968 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2969 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2970 | } |
| 2971 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2972 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2973 | { |
| 2974 | return x86::pcmpgtw(x, y); |
| 2975 | } |
| 2976 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2977 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2978 | { |
| 2979 | return x86::pcmpeqw(x, y); |
| 2980 | } |
| 2981 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2982 | Type *Short4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2983 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2984 | return T(Type_v4i16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2985 | } |
| 2986 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2987 | UShort4::UShort4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2988 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2989 | *this = Short4(cast); |
| 2990 | } |
| 2991 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2992 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2993 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2994 | Float4 sat; |
| 2995 | |
| 2996 | if(saturate) |
| 2997 | { |
| 2998 | if(CPUID::supportsSSE4_1()) |
| 2999 | { |
| 3000 | sat = Min(cast, Float4(0xFFFF)); // packusdw takes care of 0x0000 saturation |
| 3001 | } |
| 3002 | else |
| 3003 | { |
| 3004 | sat = Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)); |
| 3005 | } |
| 3006 | } |
| 3007 | else |
| 3008 | { |
| 3009 | sat = cast; |
| 3010 | } |
| 3011 | |
| 3012 | Int4 int4(sat); |
| 3013 | |
| 3014 | if(!saturate || !CPUID::supportsSSE4_1()) |
| 3015 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3016 | *this = Short4(int4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3017 | } |
| 3018 | else |
| 3019 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3020 | *this = As<Short4>(Int2(As<Int4>(x86::packusdw(int4, int4)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 3024 | UShort4::UShort4(unsigned short xyzw) |
| 3025 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3026 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3027 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(UShort::getType()), 4)))); |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 3028 | |
| 3029 | storeValue(Nucleus::createBitCast(vector, getType())); |
| 3030 | } |
| 3031 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3032 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3033 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3034 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3035 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(UShort::getType()), 4)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3036 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3037 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3038 | } |
| 3039 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3040 | UShort4::UShort4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3041 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3042 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | UShort4::UShort4(const UShort4 &rhs) |
| 3046 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3047 | Value *value = rhs.loadValue(); |
| 3048 | storeValue(value); |
| 3049 | } |
| 3050 | |
| 3051 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3052 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3053 | Value *value = rhs.loadValue(); |
| 3054 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3055 | } |
| 3056 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3057 | UShort4::UShort4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3058 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3059 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | UShort4::UShort4(const Short4 &rhs) |
| 3063 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3064 | Value *value = rhs.loadValue(); |
| 3065 | storeValue(value); |
| 3066 | } |
| 3067 | |
| 3068 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3069 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3070 | Value *value = rhs.loadValue(); |
| 3071 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3072 | } |
| 3073 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3074 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3075 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3076 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3077 | |
| 3078 | return rhs; |
| 3079 | } |
| 3080 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3081 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3082 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3083 | Value *value = rhs.loadValue(); |
| 3084 | storeValue(value); |
| 3085 | |
| 3086 | return RValue<UShort4>(value); |
| 3087 | } |
| 3088 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3089 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3090 | { |
| 3091 | Value *value = rhs.loadValue(); |
| 3092 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3093 | |
| 3094 | return RValue<UShort4>(value); |
| 3095 | } |
| 3096 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3097 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3098 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3099 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3100 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3101 | return RValue<UShort4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3102 | } |
| 3103 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3104 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3105 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3106 | Value *value = rhs.loadValue(); |
| 3107 | storeValue(value); |
| 3108 | |
| 3109 | return RValue<UShort4>(value); |
| 3110 | } |
| 3111 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3112 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3113 | { |
| 3114 | Value *value = rhs.loadValue(); |
| 3115 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3116 | |
| 3117 | return RValue<UShort4>(value); |
| 3118 | } |
| 3119 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3120 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3121 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3122 | if(CPUID::supportsMMX2()) |
| 3123 | { |
| 3124 | return As<UShort4>(x86::paddw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3125 | } |
| 3126 | else |
| 3127 | { |
| 3128 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3129 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3130 | } |
| 3131 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3132 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3133 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3134 | if(CPUID::supportsMMX2()) |
| 3135 | { |
| 3136 | return As<UShort4>(x86::psubw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3137 | } |
| 3138 | else |
| 3139 | { |
| 3140 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3141 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3142 | } |
| 3143 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3144 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3145 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3146 | if(CPUID::supportsMMX2()) |
| 3147 | { |
| 3148 | return As<UShort4>(x86::pmullw(As<Short4>(lhs), As<Short4>(rhs))); |
| 3149 | } |
| 3150 | else |
| 3151 | { |
| 3152 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3153 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3154 | } |
| 3155 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3156 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3157 | { |
| 3158 | if(CPUID::supportsMMX2()) |
| 3159 | { |
| 3160 | return As<UShort4>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 3161 | } |
| 3162 | else |
| 3163 | { |
| 3164 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3169 | { |
| 3170 | if(CPUID::supportsMMX2()) |
| 3171 | { |
| 3172 | return As<UShort4>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 3173 | } |
| 3174 | else |
| 3175 | { |
| 3176 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3181 | { |
| 3182 | if(CPUID::supportsMMX2()) |
| 3183 | { |
| 3184 | return As<UShort4>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 3185 | } |
| 3186 | else |
| 3187 | { |
| 3188 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3189 | } |
| 3190 | } |
| 3191 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3192 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3193 | { |
| 3194 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3195 | |
| 3196 | return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs)); |
| 3197 | } |
| 3198 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3199 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3200 | { |
| 3201 | // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 3202 | |
| 3203 | return x86::psrlw(lhs, rhs); |
| 3204 | } |
| 3205 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3206 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3207 | { |
| 3208 | return lhs = lhs << rhs; |
| 3209 | } |
| 3210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3211 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3212 | { |
| 3213 | return lhs = lhs >> rhs; |
| 3214 | } |
| 3215 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3216 | RValue<UShort4> operator~(RValue<UShort4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3217 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3218 | if(CPUID::supportsMMX2()) |
| 3219 | { |
| 3220 | return As<UShort4>(As<Short4>(val) ^ Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu)); |
| 3221 | } |
| 3222 | else |
| 3223 | { |
| 3224 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
| 3225 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3226 | } |
| 3227 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3228 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3229 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3230 | 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] | 3231 | } |
| 3232 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3233 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3234 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3235 | 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] | 3236 | } |
| 3237 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3238 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3239 | { |
| 3240 | return x86::paddusw(x, y); |
| 3241 | } |
| 3242 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3243 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3244 | { |
| 3245 | return x86::psubusw(x, y); |
| 3246 | } |
| 3247 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3248 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3249 | { |
| 3250 | return x86::pmulhuw(x, y); |
| 3251 | } |
| 3252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3253 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3254 | { |
| 3255 | return x86::pavgw(x, y); |
| 3256 | } |
| 3257 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3258 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3259 | { |
| 3260 | return x86::packuswb(x, y); |
| 3261 | } |
| 3262 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3263 | Type *UShort4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3264 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3265 | return T(Type_v4i16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3266 | } |
| 3267 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3268 | Short8::Short8(short c) |
| 3269 | { |
| 3270 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3271 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3272 | } |
| 3273 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3274 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3275 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3276 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3277 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3278 | } |
| 3279 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3280 | Short8::Short8(RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3281 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3282 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3283 | } |
| 3284 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3285 | Short8::Short8(const Reference<Short8> &rhs) |
| 3286 | { |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3287 | Value *value = rhs.loadValue(); |
| 3288 | storeValue(value); |
| 3289 | } |
| 3290 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3291 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3292 | { |
| 3293 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 3294 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 3295 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3296 | Value *long2 = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3297 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 3298 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 3299 | Value *short8 = Nucleus::createBitCast(long2, Short8::getType()); |
| 3300 | |
| 3301 | storeValue(short8); |
| 3302 | } |
| 3303 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3304 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3305 | { |
| 3306 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3307 | } |
| 3308 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3309 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3310 | { |
| 3311 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3312 | } |
| 3313 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3314 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3315 | { |
| 3316 | return x86::psllw(lhs, rhs); // FIXME: Fallback required |
| 3317 | } |
| 3318 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3319 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3320 | { |
| 3321 | return x86::psraw(lhs, rhs); // FIXME: Fallback required |
| 3322 | } |
| 3323 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3324 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3325 | { |
| 3326 | return x86::pmaddwd(x, y); // FIXME: Fallback required |
| 3327 | } |
| 3328 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 3329 | RValue<Int4> Abs(RValue<Int4> x) |
| 3330 | { |
| 3331 | if(CPUID::supportsSSSE3()) |
| 3332 | { |
| 3333 | return x86::pabsd(x); |
| 3334 | } |
| 3335 | else |
| 3336 | { |
| 3337 | Int4 mask = (x >> 31); |
| 3338 | return (mask ^ x) - mask; |
| 3339 | } |
| 3340 | } |
| 3341 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3342 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3343 | { |
| 3344 | return x86::pmulhw(x, y); // FIXME: Fallback required |
| 3345 | } |
| 3346 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3347 | Type *Short8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3348 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3349 | return T(llvm::VectorType::get(T(Short::getType()), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3350 | } |
| 3351 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3352 | UShort8::UShort8(unsigned short c) |
| 3353 | { |
| 3354 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3355 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3356 | } |
| 3357 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3358 | 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) |
| 3359 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3360 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3361 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3362 | } |
| 3363 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3364 | UShort8::UShort8(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3365 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3366 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3367 | } |
| 3368 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3369 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3370 | { |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3371 | Value *value = rhs.loadValue(); |
| 3372 | storeValue(value); |
| 3373 | } |
| 3374 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3375 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3376 | { |
| 3377 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 3378 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 3379 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3380 | Value *long2 = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3381 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 3382 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 3383 | Value *short8 = Nucleus::createBitCast(long2, Short8::getType()); |
| 3384 | |
| 3385 | storeValue(short8); |
| 3386 | } |
| 3387 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3388 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3389 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3390 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3391 | |
| 3392 | return rhs; |
| 3393 | } |
| 3394 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3395 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3396 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3397 | Value *value = rhs.loadValue(); |
| 3398 | storeValue(value); |
| 3399 | |
| 3400 | return RValue<UShort8>(value); |
| 3401 | } |
| 3402 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3403 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3404 | { |
| 3405 | Value *value = rhs.loadValue(); |
| 3406 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3407 | |
| 3408 | return RValue<UShort8>(value); |
| 3409 | } |
| 3410 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3411 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3412 | { |
| 3413 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3414 | } |
| 3415 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3416 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3417 | { |
| 3418 | return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required |
| 3419 | } |
| 3420 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3421 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3422 | { |
| 3423 | return x86::psrlw(lhs, rhs); // FIXME: Fallback required |
| 3424 | } |
| 3425 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3426 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3427 | { |
| 3428 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3429 | } |
| 3430 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3431 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3432 | { |
| 3433 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3434 | } |
| 3435 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3436 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3437 | { |
| 3438 | return lhs = lhs + rhs; |
| 3439 | } |
| 3440 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3441 | RValue<UShort8> operator~(RValue<UShort8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3442 | { |
| 3443 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3444 | } |
| 3445 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3446 | 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] | 3447 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 3448 | int pshufb[16] = |
| 3449 | { |
| 3450 | select0 + 0, |
| 3451 | select0 + 1, |
| 3452 | select1 + 0, |
| 3453 | select1 + 1, |
| 3454 | select2 + 0, |
| 3455 | select2 + 1, |
| 3456 | select3 + 0, |
| 3457 | select3 + 1, |
| 3458 | select4 + 0, |
| 3459 | select4 + 1, |
| 3460 | select5 + 0, |
| 3461 | select5 + 1, |
| 3462 | select6 + 0, |
| 3463 | select6 + 1, |
| 3464 | select7 + 0, |
| 3465 | select7 + 1, |
| 3466 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3467 | |
| 3468 | Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 3469 | Value *shuffle = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3470 | Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType()); |
| 3471 | |
| 3472 | return RValue<UShort8>(short8); |
| 3473 | } |
| 3474 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3475 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3476 | { |
| 3477 | return x86::pmulhuw(x, y); // FIXME: Fallback required |
| 3478 | } |
| 3479 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3480 | Type *UShort8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3481 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3482 | return T(llvm::VectorType::get(T(UShort::getType()), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3483 | } |
| 3484 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3485 | Int::Int(Argument<Int> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3486 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3487 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3488 | } |
| 3489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3490 | Int::Int(RValue<Byte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3491 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3492 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3493 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3494 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3495 | } |
| 3496 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3497 | Int::Int(RValue<SByte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3498 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3499 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3500 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3501 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3502 | } |
| 3503 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3504 | Int::Int(RValue<Short> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3505 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3506 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3507 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3508 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3509 | } |
| 3510 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3511 | Int::Int(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3512 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3513 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3514 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3515 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3516 | } |
| 3517 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3518 | Int::Int(RValue<Int2> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3519 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3520 | *this = Extract(cast, 0); |
| 3521 | } |
| 3522 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3523 | Int::Int(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3524 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3525 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3526 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3527 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3528 | } |
| 3529 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3530 | Int::Int(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3531 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3532 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3533 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3534 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3535 | } |
| 3536 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3537 | Int::Int(int x) |
| 3538 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3539 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3540 | } |
| 3541 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3542 | Int::Int(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3543 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3544 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3545 | } |
| 3546 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3547 | Int::Int(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3548 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3549 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | Int::Int(const Int &rhs) |
| 3553 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3554 | Value *value = rhs.loadValue(); |
| 3555 | storeValue(value); |
| 3556 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3557 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3558 | Int::Int(const Reference<Int> &rhs) |
| 3559 | { |
| 3560 | Value *value = rhs.loadValue(); |
| 3561 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | Int::Int(const UInt &rhs) |
| 3565 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3566 | Value *value = rhs.loadValue(); |
| 3567 | storeValue(value); |
| 3568 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3569 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3570 | Int::Int(const Reference<UInt> &rhs) |
| 3571 | { |
| 3572 | Value *value = rhs.loadValue(); |
| 3573 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3574 | } |
| 3575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3576 | RValue<Int> Int::operator=(int rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3577 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3578 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3579 | } |
| 3580 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3581 | RValue<Int> Int::operator=(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3582 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3583 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3584 | |
| 3585 | return rhs; |
| 3586 | } |
| 3587 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3588 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3589 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3590 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3591 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3592 | return RValue<Int>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3593 | } |
| 3594 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3595 | RValue<Int> Int::operator=(const Int &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3596 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3597 | Value *value = rhs.loadValue(); |
| 3598 | storeValue(value); |
| 3599 | |
| 3600 | return RValue<Int>(value); |
| 3601 | } |
| 3602 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3603 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3604 | { |
| 3605 | Value *value = rhs.loadValue(); |
| 3606 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3607 | |
| 3608 | return RValue<Int>(value); |
| 3609 | } |
| 3610 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3611 | RValue<Int> Int::operator=(const UInt &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3612 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3613 | Value *value = rhs.loadValue(); |
| 3614 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3615 | |
| 3616 | return RValue<Int>(value); |
| 3617 | } |
| 3618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3619 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3620 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3621 | Value *value = rhs.loadValue(); |
| 3622 | storeValue(value); |
| 3623 | |
| 3624 | return RValue<Int>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3625 | } |
| 3626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3627 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3628 | { |
| 3629 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3630 | } |
| 3631 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3632 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3633 | { |
| 3634 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3635 | } |
| 3636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3637 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3638 | { |
| 3639 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3640 | } |
| 3641 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3642 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3643 | { |
| 3644 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3645 | } |
| 3646 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3647 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3648 | { |
| 3649 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3650 | } |
| 3651 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3652 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3653 | { |
| 3654 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3655 | } |
| 3656 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3657 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3658 | { |
| 3659 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3660 | } |
| 3661 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3662 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3663 | { |
| 3664 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3665 | } |
| 3666 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3667 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3668 | { |
| 3669 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3670 | } |
| 3671 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3672 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3673 | { |
| 3674 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3675 | } |
| 3676 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3677 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3678 | { |
| 3679 | return lhs = lhs + rhs; |
| 3680 | } |
| 3681 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3682 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3683 | { |
| 3684 | return lhs = lhs - rhs; |
| 3685 | } |
| 3686 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3687 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3688 | { |
| 3689 | return lhs = lhs * rhs; |
| 3690 | } |
| 3691 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3692 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3693 | { |
| 3694 | return lhs = lhs / rhs; |
| 3695 | } |
| 3696 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3697 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3698 | { |
| 3699 | return lhs = lhs % rhs; |
| 3700 | } |
| 3701 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3702 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3703 | { |
| 3704 | return lhs = lhs & rhs; |
| 3705 | } |
| 3706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3707 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3708 | { |
| 3709 | return lhs = lhs | rhs; |
| 3710 | } |
| 3711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3712 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3713 | { |
| 3714 | return lhs = lhs ^ rhs; |
| 3715 | } |
| 3716 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3717 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3718 | { |
| 3719 | return lhs = lhs << rhs; |
| 3720 | } |
| 3721 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3722 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3723 | { |
| 3724 | return lhs = lhs >> rhs; |
| 3725 | } |
| 3726 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3727 | RValue<Int> operator+(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3728 | { |
| 3729 | return val; |
| 3730 | } |
| 3731 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3732 | RValue<Int> operator-(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3733 | { |
| 3734 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 3735 | } |
| 3736 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3737 | RValue<Int> operator~(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3738 | { |
| 3739 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 3740 | } |
| 3741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3742 | RValue<Int> operator++(Int &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3743 | { |
| 3744 | RValue<Int> res = val; |
| 3745 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3746 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3747 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3748 | |
| 3749 | return res; |
| 3750 | } |
| 3751 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3752 | const Int &operator++(Int &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3753 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3754 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3755 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3756 | |
| 3757 | return val; |
| 3758 | } |
| 3759 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3760 | RValue<Int> operator--(Int &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3761 | { |
| 3762 | RValue<Int> res = val; |
| 3763 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3764 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3765 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3766 | |
| 3767 | return res; |
| 3768 | } |
| 3769 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3770 | const Int &operator--(Int &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3771 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3772 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3773 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3774 | |
| 3775 | return val; |
| 3776 | } |
| 3777 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3778 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3779 | { |
| 3780 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 3781 | } |
| 3782 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3783 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3784 | { |
| 3785 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 3786 | } |
| 3787 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3788 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3789 | { |
| 3790 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 3791 | } |
| 3792 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3793 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3794 | { |
| 3795 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 3796 | } |
| 3797 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3798 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3799 | { |
| 3800 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 3801 | } |
| 3802 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3803 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3804 | { |
| 3805 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 3806 | } |
| 3807 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3808 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 3809 | { |
| 3810 | return IfThenElse(x > y, x, y); |
| 3811 | } |
| 3812 | |
| 3813 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 3814 | { |
| 3815 | return IfThenElse(x < y, x, y); |
| 3816 | } |
| 3817 | |
| 3818 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 3819 | { |
| 3820 | return Min(Max(x, min), max); |
| 3821 | } |
| 3822 | |
| 3823 | RValue<Int> RoundInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3824 | { |
| 3825 | return x86::cvtss2si(cast); |
| 3826 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3827 | // 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] | 3828 | } |
| 3829 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3830 | Type *Int::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3831 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3832 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3833 | } |
| 3834 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3835 | Long::Long(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3836 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3837 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 3838 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3839 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3840 | } |
| 3841 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3842 | Long::Long(RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3843 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3844 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 3845 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3846 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3847 | } |
| 3848 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3849 | Long::Long(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3850 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3851 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3852 | } |
| 3853 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3854 | RValue<Long> Long::operator=(int64_t rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3855 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3856 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3857 | } |
| 3858 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3859 | RValue<Long> Long::operator=(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3860 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3861 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3862 | |
| 3863 | return rhs; |
| 3864 | } |
| 3865 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3866 | RValue<Long> Long::operator=(const Long &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3867 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3868 | Value *value = rhs.loadValue(); |
| 3869 | storeValue(value); |
| 3870 | |
| 3871 | return RValue<Long>(value); |
| 3872 | } |
| 3873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3874 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3875 | { |
| 3876 | Value *value = rhs.loadValue(); |
| 3877 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3878 | |
| 3879 | return RValue<Long>(value); |
| 3880 | } |
| 3881 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3882 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3883 | { |
| 3884 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3885 | } |
| 3886 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3887 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3888 | { |
| 3889 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3890 | } |
| 3891 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3892 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3893 | { |
| 3894 | return lhs = lhs + rhs; |
| 3895 | } |
| 3896 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3897 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3898 | { |
| 3899 | return lhs = lhs - rhs; |
| 3900 | } |
| 3901 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3902 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3903 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3904 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3905 | } |
| 3906 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3907 | Type *Long::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3908 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3909 | return T(llvm::Type::getInt64Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3910 | } |
| 3911 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3912 | UInt::UInt(Argument<UInt> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3913 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3914 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3915 | } |
| 3916 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3917 | UInt::UInt(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3918 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3919 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 3920 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3921 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3922 | } |
| 3923 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3924 | UInt::UInt(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3925 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3926 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 3927 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3928 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3929 | } |
| 3930 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3931 | UInt::UInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3932 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 3933 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 3934 | // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3935 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 3936 | // Smallest positive value representable in UInt, but not in Int |
| 3937 | const unsigned int ustart = 0x80000000u; |
| 3938 | const float ustartf = float(ustart); |
| 3939 | |
| 3940 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 3941 | storeValue((~(As<Int>(cast) >> 31) & |
| 3942 | // Check if the value can be represented as an Int |
| 3943 | IfThenElse(cast >= ustartf, |
| 3944 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 3945 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 3946 | // Otherwise, just convert normally |
| 3947 | Int(cast))).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3948 | } |
| 3949 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3950 | UInt::UInt(int x) |
| 3951 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3952 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | UInt::UInt(unsigned int x) |
| 3956 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3957 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3958 | } |
| 3959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3960 | UInt::UInt(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3961 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3962 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3963 | } |
| 3964 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3965 | UInt::UInt(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3966 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3967 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | UInt::UInt(const UInt &rhs) |
| 3971 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3972 | Value *value = rhs.loadValue(); |
| 3973 | storeValue(value); |
| 3974 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3975 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3976 | UInt::UInt(const Reference<UInt> &rhs) |
| 3977 | { |
| 3978 | Value *value = rhs.loadValue(); |
| 3979 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | UInt::UInt(const Int &rhs) |
| 3983 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3984 | Value *value = rhs.loadValue(); |
| 3985 | storeValue(value); |
| 3986 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3987 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3988 | UInt::UInt(const Reference<Int> &rhs) |
| 3989 | { |
| 3990 | Value *value = rhs.loadValue(); |
| 3991 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3992 | } |
| 3993 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3994 | RValue<UInt> UInt::operator=(unsigned int rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3995 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3996 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3997 | } |
| 3998 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3999 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4000 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4001 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4002 | |
| 4003 | return rhs; |
| 4004 | } |
| 4005 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4006 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4007 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4008 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4009 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4010 | return RValue<UInt>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4011 | } |
| 4012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4013 | RValue<UInt> UInt::operator=(const UInt &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4014 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4015 | Value *value = rhs.loadValue(); |
| 4016 | storeValue(value); |
| 4017 | |
| 4018 | return RValue<UInt>(value); |
| 4019 | } |
| 4020 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4021 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4022 | { |
| 4023 | Value *value = rhs.loadValue(); |
| 4024 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4025 | |
| 4026 | return RValue<UInt>(value); |
| 4027 | } |
| 4028 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4029 | RValue<UInt> UInt::operator=(const Int &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4030 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4031 | Value *value = rhs.loadValue(); |
| 4032 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4033 | |
| 4034 | return RValue<UInt>(value); |
| 4035 | } |
| 4036 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4037 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4038 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4039 | Value *value = rhs.loadValue(); |
| 4040 | storeValue(value); |
| 4041 | |
| 4042 | return RValue<UInt>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4043 | } |
| 4044 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4045 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4046 | { |
| 4047 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4048 | } |
| 4049 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4050 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4051 | { |
| 4052 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4053 | } |
| 4054 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4055 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4056 | { |
| 4057 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4058 | } |
| 4059 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4060 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4061 | { |
| 4062 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4063 | } |
| 4064 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4065 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4066 | { |
| 4067 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4068 | } |
| 4069 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4070 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4071 | { |
| 4072 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4073 | } |
| 4074 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4075 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4076 | { |
| 4077 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4078 | } |
| 4079 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4080 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4081 | { |
| 4082 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4083 | } |
| 4084 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4085 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4086 | { |
| 4087 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4088 | } |
| 4089 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4090 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4091 | { |
| 4092 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4093 | } |
| 4094 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4095 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4096 | { |
| 4097 | return lhs = lhs + rhs; |
| 4098 | } |
| 4099 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4100 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4101 | { |
| 4102 | return lhs = lhs - rhs; |
| 4103 | } |
| 4104 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4105 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4106 | { |
| 4107 | return lhs = lhs * rhs; |
| 4108 | } |
| 4109 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4110 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4111 | { |
| 4112 | return lhs = lhs / rhs; |
| 4113 | } |
| 4114 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4115 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4116 | { |
| 4117 | return lhs = lhs % rhs; |
| 4118 | } |
| 4119 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4120 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4121 | { |
| 4122 | return lhs = lhs & rhs; |
| 4123 | } |
| 4124 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4125 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4126 | { |
| 4127 | return lhs = lhs | rhs; |
| 4128 | } |
| 4129 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4130 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4131 | { |
| 4132 | return lhs = lhs ^ rhs; |
| 4133 | } |
| 4134 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4135 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4136 | { |
| 4137 | return lhs = lhs << rhs; |
| 4138 | } |
| 4139 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4140 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4141 | { |
| 4142 | return lhs = lhs >> rhs; |
| 4143 | } |
| 4144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4145 | RValue<UInt> operator+(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4146 | { |
| 4147 | return val; |
| 4148 | } |
| 4149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4150 | RValue<UInt> operator-(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4151 | { |
| 4152 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4153 | } |
| 4154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4155 | RValue<UInt> operator~(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4156 | { |
| 4157 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4158 | } |
| 4159 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4160 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4161 | { |
| 4162 | RValue<UInt> res = val; |
| 4163 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4164 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4165 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4166 | |
| 4167 | return res; |
| 4168 | } |
| 4169 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4170 | const UInt &operator++(UInt &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4171 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4172 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4173 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4174 | |
| 4175 | return val; |
| 4176 | } |
| 4177 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4178 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4179 | { |
| 4180 | RValue<UInt> res = val; |
| 4181 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4182 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4183 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4184 | |
| 4185 | return res; |
| 4186 | } |
| 4187 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4188 | const UInt &operator--(UInt &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4189 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4190 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4191 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4192 | |
| 4193 | return val; |
| 4194 | } |
| 4195 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4196 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4197 | { |
| 4198 | return IfThenElse(x > y, x, y); |
| 4199 | } |
| 4200 | |
| 4201 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4202 | { |
| 4203 | return IfThenElse(x < y, x, y); |
| 4204 | } |
| 4205 | |
| 4206 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4207 | { |
| 4208 | return Min(Max(x, min), max); |
| 4209 | } |
| 4210 | |
| 4211 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4212 | { |
| 4213 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4214 | } |
| 4215 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4216 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4217 | { |
| 4218 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4219 | } |
| 4220 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4221 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4222 | { |
| 4223 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4224 | } |
| 4225 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4226 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4227 | { |
| 4228 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4229 | } |
| 4230 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4231 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4232 | { |
| 4233 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4234 | } |
| 4235 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4236 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4237 | { |
| 4238 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4239 | } |
| 4240 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4241 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4242 | // { |
| 4243 | // return x86::cvtss2si(val); // FIXME: Unsigned |
| 4244 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4245 | // // 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] | 4246 | // } |
| 4247 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4248 | Type *UInt::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4249 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 4250 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4251 | } |
| 4252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4253 | // Int2::Int2(RValue<Int> cast) |
| 4254 | // { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4255 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4256 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4257 | // |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4258 | // int shuffle[2] = {0, 0}; |
| 4259 | // Value *replicate = Nucleus::createShuffleVector(vector, vector, shuffle); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4260 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4261 | // storeValue(replicate); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4262 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4264 | Int2::Int2(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4265 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4266 | Value *long2 = Nucleus::createBitCast(cast.value, T(llvm::VectorType::get(T(Long::getType()), 2))); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 4267 | Value *element = Nucleus::createExtractElement(long2, Long::getType(), 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4268 | Value *int2 = Nucleus::createBitCast(element, Int2::getType()); |
| 4269 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4270 | storeValue(int2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4271 | } |
| 4272 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4273 | Int2::Int2(int x, int y) |
| 4274 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4275 | int64_t constantVector[2] = {x, y}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4276 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(Int::getType()), 2)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4277 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4278 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4279 | } |
| 4280 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4281 | Int2::Int2(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4282 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4283 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | Int2::Int2(const Int2 &rhs) |
| 4287 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4288 | Value *value = rhs.loadValue(); |
| 4289 | storeValue(value); |
| 4290 | } |
| 4291 | |
| 4292 | Int2::Int2(const Reference<Int2> &rhs) |
| 4293 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4294 | Value *value = rhs.loadValue(); |
| 4295 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4296 | } |
| 4297 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4298 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4299 | { |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4300 | if(CPUID::supportsMMX2()) |
| 4301 | { |
| 4302 | // movd mm0, lo |
| 4303 | // movd mm1, hi |
| 4304 | // punpckldq mm0, mm1 |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4305 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4306 | Value *loLong = Nucleus::createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Int::getType()), 2))), lo.value, 0); |
| 4307 | loLong = Nucleus::createInsertElement(loLong, V(llvm::ConstantInt::get(T(Int::getType()), 0)), 1); |
| 4308 | Value *hiLong = Nucleus::createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Int::getType()), 2))), hi.value, 0); |
| 4309 | hiLong = Nucleus::createInsertElement(hiLong, V(llvm::ConstantInt::get(T(Int::getType()), 0)), 1); |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4310 | |
| 4311 | storeValue(As<Int2>(UnpackLow(As<Int2>(loLong), As<Int2>(hiLong))).value); |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4312 | } |
| 4313 | else |
| 4314 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4315 | int shuffle[2] = {0, 1}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4316 | Value *packed = Nucleus::createShuffleVector(Nucleus::createBitCast(lo.value, T(llvm::VectorType::get(T(Int::getType()), 1))), Nucleus::createBitCast(hi.value, T(llvm::VectorType::get(T(Int::getType()), 1))), shuffle); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4317 | |
Nicolas Capens | b40a256 | 2016-01-05 00:08:45 -0500 | [diff] [blame] | 4318 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
| 4319 | } |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4320 | } |
| 4321 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4322 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4323 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4324 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4325 | |
| 4326 | return rhs; |
| 4327 | } |
| 4328 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4329 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4330 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4331 | Value *value = rhs.loadValue(); |
| 4332 | storeValue(value); |
| 4333 | |
| 4334 | return RValue<Int2>(value); |
| 4335 | } |
| 4336 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4337 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4338 | { |
| 4339 | Value *value = rhs.loadValue(); |
| 4340 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4341 | |
| 4342 | return RValue<Int2>(value); |
| 4343 | } |
| 4344 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4345 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4346 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4347 | if(CPUID::supportsMMX2()) |
| 4348 | { |
| 4349 | return x86::paddd(lhs, rhs); |
| 4350 | } |
| 4351 | else |
| 4352 | { |
| 4353 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4354 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4355 | } |
| 4356 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4357 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4358 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4359 | if(CPUID::supportsMMX2()) |
| 4360 | { |
| 4361 | return x86::psubd(lhs, rhs); |
| 4362 | } |
| 4363 | else |
| 4364 | { |
| 4365 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4366 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4367 | } |
| 4368 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4369 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4370 | // { |
| 4371 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4372 | // } |
| 4373 | |
| 4374 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4375 | // { |
| 4376 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4377 | // } |
| 4378 | |
| 4379 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4380 | // { |
| 4381 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4382 | // } |
| 4383 | |
| 4384 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4385 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4386 | if(CPUID::supportsMMX2()) |
| 4387 | { |
| 4388 | return As<Int2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 4389 | } |
| 4390 | else |
| 4391 | { |
| 4392 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4393 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4394 | } |
| 4395 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4396 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4397 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4398 | if(CPUID::supportsMMX2()) |
| 4399 | { |
| 4400 | return As<Int2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 4401 | } |
| 4402 | else |
| 4403 | { |
| 4404 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4405 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4406 | } |
| 4407 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4408 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4409 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4410 | if(CPUID::supportsMMX2()) |
| 4411 | { |
| 4412 | return As<Int2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 4413 | } |
| 4414 | else |
| 4415 | { |
| 4416 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4417 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4418 | } |
| 4419 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4420 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4421 | { |
| 4422 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4423 | |
| 4424 | return x86::pslld(lhs, rhs); |
| 4425 | } |
| 4426 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4427 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4428 | { |
| 4429 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4430 | |
| 4431 | return x86::psrad(lhs, rhs); |
| 4432 | } |
| 4433 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4434 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4435 | { |
| 4436 | return lhs = lhs + rhs; |
| 4437 | } |
| 4438 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4439 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4440 | { |
| 4441 | return lhs = lhs - rhs; |
| 4442 | } |
| 4443 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4444 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4445 | // { |
| 4446 | // return lhs = lhs * rhs; |
| 4447 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4448 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4449 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4450 | // { |
| 4451 | // return lhs = lhs / rhs; |
| 4452 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4453 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4454 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4455 | // { |
| 4456 | // return lhs = lhs % rhs; |
| 4457 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4458 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4459 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4460 | { |
| 4461 | return lhs = lhs & rhs; |
| 4462 | } |
| 4463 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4464 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4465 | { |
| 4466 | return lhs = lhs | rhs; |
| 4467 | } |
| 4468 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4469 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4470 | { |
| 4471 | return lhs = lhs ^ rhs; |
| 4472 | } |
| 4473 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4474 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4475 | { |
| 4476 | return lhs = lhs << rhs; |
| 4477 | } |
| 4478 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4479 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4480 | { |
| 4481 | return lhs = lhs >> rhs; |
| 4482 | } |
| 4483 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4484 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4485 | // { |
| 4486 | // return val; |
| 4487 | // } |
| 4488 | |
| 4489 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4490 | // { |
| 4491 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4492 | // } |
| 4493 | |
| 4494 | RValue<Int2> operator~(RValue<Int2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4495 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4496 | if(CPUID::supportsMMX2()) |
| 4497 | { |
| 4498 | return val ^ Int2(0xFFFFFFFF, 0xFFFFFFFF); |
| 4499 | } |
| 4500 | else |
| 4501 | { |
| 4502 | return RValue<Int2>(Nucleus::createNot(val.value)); |
| 4503 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4504 | } |
| 4505 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4506 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4507 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4508 | if(CPUID::supportsMMX2()) |
| 4509 | { |
| 4510 | return x86::punpckldq(x, y); |
| 4511 | } |
| 4512 | else |
| 4513 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4514 | int shuffle[2] = {0, 2}; |
| 4515 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4516 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4517 | return As<Short4>(packed); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4518 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4519 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4520 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4521 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4522 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4523 | if(CPUID::supportsMMX2()) |
| 4524 | { |
| 4525 | return x86::punpckhdq(x, y); |
| 4526 | } |
| 4527 | else |
| 4528 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4529 | int shuffle[2] = {1, 3}; |
| 4530 | Value *packed = Nucleus::createShuffleVector(x.value, y.value, shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4531 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4532 | return As<Short4>(packed); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4533 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4534 | } |
| 4535 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4536 | RValue<Int> Extract(RValue<Int2> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4537 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 4538 | if(i == 0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4539 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 4540 | return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, T(llvm::VectorType::get(T(Int::getType()), 2))), Int::getType(), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4541 | } |
| 4542 | else |
| 4543 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 4544 | Int2 val2 = As<Int2>(UnpackHigh(val, val)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4545 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 4546 | return Extract(val2, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4547 | } |
| 4548 | } |
| 4549 | |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4550 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4551 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4552 | return RValue<Int2>(Nucleus::createBitCast(Nucleus::createInsertElement(Nucleus::createBitCast(val.value, T(llvm::VectorType::get(T(Int::getType()), 2))), element.value, i), Int2::getType())); |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4553 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4554 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4555 | Type *Int2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4556 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4557 | return T(Type_v2i32); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4558 | } |
| 4559 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4560 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4561 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4562 | int64_t constantVector[2] = {x, y}; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4563 | Value *vector = V(Nucleus::createConstantVector(constantVector, T(llvm::VectorType::get(T(UInt::getType()), 2)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4564 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4565 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4566 | } |
| 4567 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4568 | UInt2::UInt2(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4569 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4570 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | UInt2::UInt2(const UInt2 &rhs) |
| 4574 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4575 | Value *value = rhs.loadValue(); |
| 4576 | storeValue(value); |
| 4577 | } |
| 4578 | |
| 4579 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4580 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4581 | Value *value = rhs.loadValue(); |
| 4582 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4583 | } |
| 4584 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4585 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4586 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4587 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4588 | |
| 4589 | return rhs; |
| 4590 | } |
| 4591 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4592 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4593 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4594 | Value *value = rhs.loadValue(); |
| 4595 | storeValue(value); |
| 4596 | |
| 4597 | return RValue<UInt2>(value); |
| 4598 | } |
| 4599 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4600 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4601 | { |
| 4602 | Value *value = rhs.loadValue(); |
| 4603 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4604 | |
| 4605 | return RValue<UInt2>(value); |
| 4606 | } |
| 4607 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4608 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4609 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4610 | if(CPUID::supportsMMX2()) |
| 4611 | { |
| 4612 | return As<UInt2>(x86::paddd(As<Int2>(lhs), As<Int2>(rhs))); |
| 4613 | } |
| 4614 | else |
| 4615 | { |
| 4616 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4617 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4618 | } |
| 4619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4620 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4621 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4622 | if(CPUID::supportsMMX2()) |
| 4623 | { |
| 4624 | return As<UInt2>(x86::psubd(As<Int2>(lhs), As<Int2>(rhs))); |
| 4625 | } |
| 4626 | else |
| 4627 | { |
| 4628 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4629 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4630 | } |
| 4631 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4632 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4633 | // { |
| 4634 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4635 | // } |
| 4636 | |
| 4637 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4638 | // { |
| 4639 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4640 | // } |
| 4641 | |
| 4642 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4643 | // { |
| 4644 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4645 | // } |
| 4646 | |
| 4647 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4648 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4649 | if(CPUID::supportsMMX2()) |
| 4650 | { |
| 4651 | return As<UInt2>(x86::pand(As<Short4>(lhs), As<Short4>(rhs))); |
| 4652 | } |
| 4653 | else |
| 4654 | { |
| 4655 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4656 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4657 | } |
| 4658 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4659 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4660 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4661 | if(CPUID::supportsMMX2()) |
| 4662 | { |
| 4663 | return As<UInt2>(x86::por(As<Short4>(lhs), As<Short4>(rhs))); |
| 4664 | } |
| 4665 | else |
| 4666 | { |
| 4667 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4668 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4669 | } |
| 4670 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4671 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4672 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4673 | if(CPUID::supportsMMX2()) |
| 4674 | { |
| 4675 | return As<UInt2>(x86::pxor(As<Short4>(lhs), As<Short4>(rhs))); |
| 4676 | } |
| 4677 | else |
| 4678 | { |
| 4679 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4680 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4681 | } |
| 4682 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4683 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4684 | { |
| 4685 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4686 | |
| 4687 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 4688 | } |
| 4689 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4690 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4691 | { |
| 4692 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4693 | |
| 4694 | return x86::psrld(lhs, rhs); |
| 4695 | } |
| 4696 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4697 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4698 | { |
| 4699 | return lhs = lhs + rhs; |
| 4700 | } |
| 4701 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4702 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4703 | { |
| 4704 | return lhs = lhs - rhs; |
| 4705 | } |
| 4706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4707 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4708 | // { |
| 4709 | // return lhs = lhs * rhs; |
| 4710 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4712 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4713 | // { |
| 4714 | // return lhs = lhs / rhs; |
| 4715 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4716 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4717 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4718 | // { |
| 4719 | // return lhs = lhs % rhs; |
| 4720 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4733 | { |
| 4734 | return lhs = lhs ^ rhs; |
| 4735 | } |
| 4736 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4737 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4738 | { |
| 4739 | return lhs = lhs << rhs; |
| 4740 | } |
| 4741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4742 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4743 | { |
| 4744 | return lhs = lhs >> rhs; |
| 4745 | } |
| 4746 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4747 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4748 | // { |
| 4749 | // return val; |
| 4750 | // } |
| 4751 | |
| 4752 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4753 | // { |
| 4754 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4755 | // } |
| 4756 | |
| 4757 | RValue<UInt2> operator~(RValue<UInt2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4758 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4759 | if(CPUID::supportsMMX2()) |
| 4760 | { |
| 4761 | return val ^ UInt2(0xFFFFFFFF, 0xFFFFFFFF); |
| 4762 | } |
| 4763 | else |
| 4764 | { |
| 4765 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4766 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4767 | } |
| 4768 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4769 | Type *UInt2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4770 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4771 | return T(Type_v2i32); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4772 | } |
| 4773 | |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4774 | Int4::Int4(RValue<Byte4> cast) |
| 4775 | { |
| 4776 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4777 | Value *a = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Int4::getType()))), x, 0); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4778 | |
| 4779 | Value *e; |
| 4780 | |
| 4781 | if (CPUID::supportsSSE4_1()) |
| 4782 | { |
| 4783 | e = x86::pmovzxbd(RValue<Int4>(a)).value; |
| 4784 | } |
| 4785 | else |
| 4786 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4787 | 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] | 4788 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4789 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4790 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4791 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4792 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4793 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4797 | storeValue(f); |
| 4798 | } |
| 4799 | |
| 4800 | Int4::Int4(RValue<SByte4> cast) |
| 4801 | { |
| 4802 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4803 | Value *a = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Int4::getType()))), x, 0); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4804 | |
| 4805 | Value *g; |
| 4806 | |
| 4807 | if (CPUID::supportsSSE4_1()) |
| 4808 | { |
| 4809 | g = x86::pmovsxbd(RValue<Int4>(a)).value; |
| 4810 | } |
| 4811 | else |
| 4812 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4813 | 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] | 4814 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4815 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4816 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4817 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4818 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4819 | Value *e = Nucleus::createShuffleVector(d, d, swizzle2); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4820 | |
| 4821 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4822 | // g = Nucleus::createAShr(f, Nucleus::createConstantInt(24)); |
| 4823 | g = x86::psrad(RValue<Int4>(f), 24).value; |
| 4824 | } |
| 4825 | |
| 4826 | storeValue(g); |
| 4827 | } |
| 4828 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4829 | Int4::Int4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4830 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4831 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4832 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4833 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4834 | } |
| 4835 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4836 | Int4::Int4(RValue<Short4> cast) |
| 4837 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4838 | Value *long2 = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4839 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 4840 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 4841 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 4842 | |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4843 | if(CPUID::supportsSSE4_1()) |
| 4844 | { |
| 4845 | storeValue(x86::pmovsxwd(vector).value); |
| 4846 | } |
| 4847 | else |
| 4848 | { |
| 4849 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 4850 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4851 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4852 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 4853 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4854 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4855 | |
| 4856 | // Each Short is packed into each Int in the (Short | Short) format. |
| 4857 | // Shifting by 16 will retrieve the original Short value. |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 4858 | // Shifting an Int will propagate the sign bit, which will work |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4859 | // for both positive and negative values of a Short. |
| 4860 | *this >>= 16; |
| 4861 | } |
| 4862 | } |
| 4863 | |
| 4864 | Int4::Int4(RValue<UShort4> cast) |
| 4865 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4866 | Value *long2 = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4867 | Value *element = Nucleus::createBitCast(cast.value, Long::getType()); |
| 4868 | long2 = Nucleus::createInsertElement(long2, element, 0); |
| 4869 | RValue<Int4> vector = RValue<Int4>(Nucleus::createBitCast(long2, Int4::getType())); |
| 4870 | |
| 4871 | if(CPUID::supportsSSE4_1()) |
| 4872 | { |
| 4873 | storeValue(x86::pmovzxwd(RValue<Int4>(vector)).value); |
| 4874 | } |
| 4875 | else |
| 4876 | { |
| 4877 | Value *b = Nucleus::createBitCast(vector.value, Short8::getType()); |
| 4878 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4879 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4880 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Short8::getType())), swizzle); |
Nicolas Capens | 6ce5c33 | 2015-10-28 01:58:18 -0400 | [diff] [blame] | 4881 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4882 | storeValue(d); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4886 | Int4::Int4(int xyzw) |
| 4887 | { |
| 4888 | constant(xyzw, xyzw, xyzw, xyzw); |
| 4889 | } |
| 4890 | |
| 4891 | Int4::Int4(int x, int yzw) |
| 4892 | { |
| 4893 | constant(x, yzw, yzw, yzw); |
| 4894 | } |
| 4895 | |
| 4896 | Int4::Int4(int x, int y, int zw) |
| 4897 | { |
| 4898 | constant(x, y, zw, zw); |
| 4899 | } |
| 4900 | |
| 4901 | Int4::Int4(int x, int y, int z, int w) |
| 4902 | { |
| 4903 | constant(x, y, z, w); |
| 4904 | } |
| 4905 | |
| 4906 | void Int4::constant(int x, int y, int z, int w) |
| 4907 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4908 | int64_t constantVector[4] = {x, y, z, w}; |
| 4909 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4910 | } |
| 4911 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4912 | Int4::Int4(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4913 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4914 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | Int4::Int4(const Int4 &rhs) |
| 4918 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4919 | Value *value = rhs.loadValue(); |
| 4920 | storeValue(value); |
| 4921 | } |
| 4922 | |
| 4923 | Int4::Int4(const Reference<Int4> &rhs) |
| 4924 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4925 | Value *value = rhs.loadValue(); |
| 4926 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4927 | } |
| 4928 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4929 | Int4::Int4(RValue<UInt4> rhs) |
| 4930 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4931 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | Int4::Int4(const UInt4 &rhs) |
| 4935 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4936 | Value *value = rhs.loadValue(); |
| 4937 | storeValue(value); |
| 4938 | } |
| 4939 | |
| 4940 | Int4::Int4(const Reference<UInt4> &rhs) |
| 4941 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4942 | Value *value = rhs.loadValue(); |
| 4943 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4944 | } |
| 4945 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4946 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 4947 | { |
| 4948 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 4949 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 4950 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4951 | Value *long2 = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4952 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 4953 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 4954 | Value *int4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 4955 | |
| 4956 | storeValue(int4); |
| 4957 | } |
| 4958 | |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4959 | Int4::Int4(RValue<Int> rhs) |
| 4960 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4961 | Value *vector = loadValue(); |
| 4962 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 4963 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4964 | int swizzle[4] = {0, 0, 0, 0}; |
| 4965 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4966 | |
| 4967 | storeValue(replicate); |
| 4968 | } |
| 4969 | |
| 4970 | Int4::Int4(const Int &rhs) |
| 4971 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4972 | *this = RValue<Int>(rhs.loadValue()); |
| 4973 | } |
| 4974 | |
| 4975 | Int4::Int4(const Reference<Int> &rhs) |
| 4976 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4977 | *this = RValue<Int>(rhs.loadValue()); |
| 4978 | } |
| 4979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4980 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4981 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4982 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4983 | |
| 4984 | return rhs; |
| 4985 | } |
| 4986 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4987 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4988 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4989 | Value *value = rhs.loadValue(); |
| 4990 | storeValue(value); |
| 4991 | |
| 4992 | return RValue<Int4>(value); |
| 4993 | } |
| 4994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4995 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4996 | { |
| 4997 | Value *value = rhs.loadValue(); |
| 4998 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4999 | |
| 5000 | return RValue<Int4>(value); |
| 5001 | } |
| 5002 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5003 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5004 | { |
| 5005 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5006 | } |
| 5007 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5008 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5009 | { |
| 5010 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5011 | } |
| 5012 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5013 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5014 | { |
| 5015 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5016 | } |
| 5017 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5018 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5019 | { |
| 5020 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5021 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5022 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5023 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5024 | { |
| 5025 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5026 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5027 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5028 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5029 | { |
| 5030 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5031 | } |
| 5032 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5033 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5034 | { |
| 5035 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5036 | } |
| 5037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5038 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5039 | { |
| 5040 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5041 | } |
| 5042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5043 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5044 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5045 | return x86::pslld(lhs, rhs); |
| 5046 | } |
| 5047 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5048 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5049 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5050 | return x86::psrad(lhs, rhs); |
| 5051 | } |
| 5052 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5053 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5054 | { |
| 5055 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5056 | } |
| 5057 | |
| 5058 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5059 | { |
| 5060 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5061 | } |
| 5062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5063 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5064 | { |
| 5065 | return lhs = lhs + rhs; |
| 5066 | } |
| 5067 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5068 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5069 | { |
| 5070 | return lhs = lhs - rhs; |
| 5071 | } |
| 5072 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5073 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5074 | { |
| 5075 | return lhs = lhs * rhs; |
| 5076 | } |
| 5077 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5078 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5079 | // { |
| 5080 | // return lhs = lhs / rhs; |
| 5081 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5082 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5083 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5084 | // { |
| 5085 | // return lhs = lhs % rhs; |
| 5086 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5087 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5088 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5089 | { |
| 5090 | return lhs = lhs & rhs; |
| 5091 | } |
| 5092 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5093 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5094 | { |
| 5095 | return lhs = lhs | rhs; |
| 5096 | } |
| 5097 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5098 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5099 | { |
| 5100 | return lhs = lhs ^ rhs; |
| 5101 | } |
| 5102 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5103 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5104 | { |
| 5105 | return lhs = lhs << rhs; |
| 5106 | } |
| 5107 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5108 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5109 | { |
| 5110 | return lhs = lhs >> rhs; |
| 5111 | } |
| 5112 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5113 | RValue<Int4> operator+(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5114 | { |
| 5115 | return val; |
| 5116 | } |
| 5117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5118 | RValue<Int4> operator-(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5119 | { |
| 5120 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5121 | } |
| 5122 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5123 | RValue<Int4> operator~(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5124 | { |
| 5125 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5126 | } |
| 5127 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5128 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5129 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5130 | // 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] | 5131 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5132 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5133 | 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] | 5134 | } |
| 5135 | |
| 5136 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5137 | { |
| 5138 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5139 | } |
| 5140 | |
| 5141 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5142 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5143 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5144 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5145 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5146 | 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] | 5147 | } |
| 5148 | |
| 5149 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5150 | { |
| 5151 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5152 | } |
| 5153 | |
| 5154 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5155 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5156 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5157 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5158 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5159 | 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] | 5160 | } |
| 5161 | |
| 5162 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5163 | { |
| 5164 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5165 | } |
| 5166 | |
| 5167 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5168 | { |
| 5169 | if(CPUID::supportsSSE4_1()) |
| 5170 | { |
| 5171 | return x86::pmaxsd(x, y); |
| 5172 | } |
| 5173 | else |
| 5174 | { |
| 5175 | RValue<Int4> greater = CmpNLE(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 5176 | return (x & greater) | (y & ~greater); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5177 | } |
| 5178 | } |
| 5179 | |
| 5180 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5181 | { |
| 5182 | if(CPUID::supportsSSE4_1()) |
| 5183 | { |
| 5184 | return x86::pminsd(x, y); |
| 5185 | } |
| 5186 | else |
| 5187 | { |
| 5188 | RValue<Int4> less = CmpLT(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 5189 | return (x & less) | (y & ~less); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5190 | } |
| 5191 | } |
| 5192 | |
| 5193 | RValue<Int4> RoundInt(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5194 | { |
| 5195 | return x86::cvtps2dq(cast); |
| 5196 | } |
| 5197 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5198 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5199 | { |
| 5200 | return x86::packssdw(x, y); |
| 5201 | } |
| 5202 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5203 | RValue<Int> Extract(RValue<Int4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5204 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5205 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5206 | } |
| 5207 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5208 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5209 | { |
| 5210 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5211 | } |
| 5212 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5213 | RValue<Int> SignMask(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5214 | { |
| 5215 | return x86::movmskps(As<Float4>(x)); |
| 5216 | } |
| 5217 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5218 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5219 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5220 | return RValue<Int4>(createSwizzle4(x.value, select)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5221 | } |
| 5222 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5223 | Type *Int4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5224 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5225 | return T(llvm::VectorType::get(T(Int::getType()), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5226 | } |
| 5227 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5228 | UInt4::UInt4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5229 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 5230 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 5231 | // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5232 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 5233 | // Smallest positive value representable in UInt, but not in Int |
| 5234 | const unsigned int ustart = 0x80000000u; |
| 5235 | const float ustartf = float(ustart); |
| 5236 | |
| 5237 | // Check if the value can be represented as an Int |
| 5238 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5239 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5240 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5241 | // Otherwise, just convert normally |
| 5242 | (~uiValue & Int4(cast)); |
| 5243 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5244 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5245 | } |
| 5246 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5247 | UInt4::UInt4(int xyzw) |
| 5248 | { |
| 5249 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5250 | } |
| 5251 | |
| 5252 | UInt4::UInt4(int x, int yzw) |
| 5253 | { |
| 5254 | constant(x, yzw, yzw, yzw); |
| 5255 | } |
| 5256 | |
| 5257 | UInt4::UInt4(int x, int y, int zw) |
| 5258 | { |
| 5259 | constant(x, y, zw, zw); |
| 5260 | } |
| 5261 | |
| 5262 | UInt4::UInt4(int x, int y, int z, int w) |
| 5263 | { |
| 5264 | constant(x, y, z, w); |
| 5265 | } |
| 5266 | |
| 5267 | void UInt4::constant(int x, int y, int z, int w) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5268 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5269 | int64_t constantVector[4] = {x, y, z, w}; |
| 5270 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5271 | } |
| 5272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5273 | UInt4::UInt4(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5274 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5275 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | UInt4::UInt4(const UInt4 &rhs) |
| 5279 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5280 | Value *value = rhs.loadValue(); |
| 5281 | storeValue(value); |
| 5282 | } |
| 5283 | |
| 5284 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5285 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5286 | Value *value = rhs.loadValue(); |
| 5287 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5288 | } |
| 5289 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5290 | UInt4::UInt4(RValue<Int4> rhs) |
| 5291 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5292 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | UInt4::UInt4(const Int4 &rhs) |
| 5296 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5297 | Value *value = rhs.loadValue(); |
| 5298 | storeValue(value); |
| 5299 | } |
| 5300 | |
| 5301 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5302 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5303 | Value *value = rhs.loadValue(); |
| 5304 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5305 | } |
| 5306 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5307 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5308 | { |
| 5309 | Value *loLong = Nucleus::createBitCast(lo.value, Long::getType()); |
| 5310 | Value *hiLong = Nucleus::createBitCast(hi.value, Long::getType()); |
| 5311 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5312 | Value *long2 = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 5313 | long2 = Nucleus::createInsertElement(long2, loLong, 0); |
| 5314 | long2 = Nucleus::createInsertElement(long2, hiLong, 1); |
| 5315 | Value *uint4 = Nucleus::createBitCast(long2, Int4::getType()); |
| 5316 | |
| 5317 | storeValue(uint4); |
| 5318 | } |
| 5319 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5320 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5321 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5322 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5323 | |
| 5324 | return rhs; |
| 5325 | } |
| 5326 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5327 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5328 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5329 | Value *value = rhs.loadValue(); |
| 5330 | storeValue(value); |
| 5331 | |
| 5332 | return RValue<UInt4>(value); |
| 5333 | } |
| 5334 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5335 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5336 | { |
| 5337 | Value *value = rhs.loadValue(); |
| 5338 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5339 | |
| 5340 | return RValue<UInt4>(value); |
| 5341 | } |
| 5342 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5343 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5344 | { |
| 5345 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5346 | } |
| 5347 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5348 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5349 | { |
| 5350 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5351 | } |
| 5352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5353 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5354 | { |
| 5355 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5356 | } |
| 5357 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5358 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5359 | { |
| 5360 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5361 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5362 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5363 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5364 | { |
| 5365 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5366 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5367 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5368 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5369 | { |
| 5370 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5371 | } |
| 5372 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5373 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5374 | { |
| 5375 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5376 | } |
| 5377 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5378 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5379 | { |
| 5380 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5381 | } |
| 5382 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5383 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5384 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5385 | return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs)); |
| 5386 | } |
| 5387 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5388 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5389 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5390 | return x86::psrld(lhs, rhs); |
| 5391 | } |
| 5392 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5393 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5394 | { |
| 5395 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5396 | } |
| 5397 | |
| 5398 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5399 | { |
| 5400 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5401 | } |
| 5402 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5403 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5404 | { |
| 5405 | return lhs = lhs + rhs; |
| 5406 | } |
| 5407 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5408 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5409 | { |
| 5410 | return lhs = lhs - rhs; |
| 5411 | } |
| 5412 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5413 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5414 | { |
| 5415 | return lhs = lhs * rhs; |
| 5416 | } |
| 5417 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5418 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5419 | // { |
| 5420 | // return lhs = lhs / rhs; |
| 5421 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5423 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5424 | // { |
| 5425 | // return lhs = lhs % rhs; |
| 5426 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5428 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5429 | { |
| 5430 | return lhs = lhs & rhs; |
| 5431 | } |
| 5432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5433 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5434 | { |
| 5435 | return lhs = lhs | rhs; |
| 5436 | } |
| 5437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5438 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5439 | { |
| 5440 | return lhs = lhs ^ rhs; |
| 5441 | } |
| 5442 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5443 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5444 | { |
| 5445 | return lhs = lhs << rhs; |
| 5446 | } |
| 5447 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5448 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5449 | { |
| 5450 | return lhs = lhs >> rhs; |
| 5451 | } |
| 5452 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5453 | RValue<UInt4> operator+(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5454 | { |
| 5455 | return val; |
| 5456 | } |
| 5457 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5458 | RValue<UInt4> operator-(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5459 | { |
| 5460 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5461 | } |
| 5462 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5463 | RValue<UInt4> operator~(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5464 | { |
| 5465 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5466 | } |
| 5467 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5468 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5469 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5470 | // 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] | 5471 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5472 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5473 | 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] | 5474 | } |
| 5475 | |
| 5476 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5477 | { |
| 5478 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 5479 | } |
| 5480 | |
| 5481 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5482 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5483 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5484 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5485 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 5486 | 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] | 5487 | } |
| 5488 | |
| 5489 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5490 | { |
| 5491 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5492 | } |
| 5493 | |
| 5494 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5495 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5496 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5497 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5498 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 5499 | 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] | 5500 | } |
| 5501 | |
| 5502 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5503 | { |
| 5504 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 5505 | } |
| 5506 | |
| 5507 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5508 | { |
| 5509 | if(CPUID::supportsSSE4_1()) |
| 5510 | { |
| 5511 | return x86::pmaxud(x, y); |
| 5512 | } |
| 5513 | else |
| 5514 | { |
| 5515 | RValue<UInt4> greater = CmpNLE(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 5516 | return (x & greater) | (y & ~greater); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5521 | { |
| 5522 | if(CPUID::supportsSSE4_1()) |
| 5523 | { |
| 5524 | return x86::pminud(x, y); |
| 5525 | } |
| 5526 | else |
| 5527 | { |
| 5528 | RValue<UInt4> less = CmpLT(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 5529 | return (x & less) | (y & ~less); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5534 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 5535 | return x86::packusdw(As<Int4>(x), As<Int4>(y)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5536 | } |
| 5537 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5538 | Type *UInt4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5539 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5540 | return T(llvm::VectorType::get(T(UInt::getType()), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5541 | } |
| 5542 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5543 | Float::Float(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5544 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5545 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5546 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5547 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5548 | } |
| 5549 | |
Alexis Hetu | cfd9632 | 2017-07-24 14:44:33 -0400 | [diff] [blame] | 5550 | Float::Float(RValue<UInt> cast) |
| 5551 | { |
| 5552 | RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) + |
| 5553 | As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u))); |
| 5554 | |
| 5555 | storeValue(result.value); |
| 5556 | } |
| 5557 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5558 | Float::Float(float x) |
| 5559 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5560 | storeValue(Nucleus::createConstantFloat(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5561 | } |
| 5562 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5563 | Float::Float(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5564 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5565 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | Float::Float(const Float &rhs) |
| 5569 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5570 | Value *value = rhs.loadValue(); |
| 5571 | storeValue(value); |
| 5572 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5573 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5574 | Float::Float(const Reference<Float> &rhs) |
| 5575 | { |
| 5576 | Value *value = rhs.loadValue(); |
| 5577 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5578 | } |
| 5579 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5580 | RValue<Float> Float::operator=(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5581 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5582 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5583 | |
| 5584 | return rhs; |
| 5585 | } |
| 5586 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5587 | RValue<Float> Float::operator=(const 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 | Value *value = rhs.loadValue(); |
| 5590 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5591 | |
| 5592 | return RValue<Float>(value); |
| 5593 | } |
| 5594 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5595 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5596 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5597 | Value *value = rhs.loadValue(); |
| 5598 | storeValue(value); |
| 5599 | |
| 5600 | return RValue<Float>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5601 | } |
| 5602 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5603 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5604 | { |
| 5605 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5606 | } |
| 5607 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5608 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5609 | { |
| 5610 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5611 | } |
| 5612 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5613 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5614 | { |
| 5615 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5616 | } |
| 5617 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5618 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5619 | { |
| 5620 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5621 | } |
| 5622 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5623 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5624 | { |
| 5625 | return lhs = lhs + rhs; |
| 5626 | } |
| 5627 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5628 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5629 | { |
| 5630 | return lhs = lhs - rhs; |
| 5631 | } |
| 5632 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5633 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5634 | { |
| 5635 | return lhs = lhs * rhs; |
| 5636 | } |
| 5637 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5638 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5639 | { |
| 5640 | return lhs = lhs / rhs; |
| 5641 | } |
| 5642 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5643 | RValue<Float> operator+(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5644 | { |
| 5645 | return val; |
| 5646 | } |
| 5647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5648 | RValue<Float> operator-(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5649 | { |
| 5650 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5651 | } |
| 5652 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5653 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5654 | { |
| 5655 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5656 | } |
| 5657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5658 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5659 | { |
| 5660 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5661 | } |
| 5662 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5663 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5664 | { |
| 5665 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5666 | } |
| 5667 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5668 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5669 | { |
| 5670 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5671 | } |
| 5672 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5673 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5674 | { |
| 5675 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5676 | } |
| 5677 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5678 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5679 | { |
| 5680 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5681 | } |
| 5682 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5683 | RValue<Float> Abs(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5684 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5685 | return IfThenElse(x > 0.0f, x, -x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5686 | } |
| 5687 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5688 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5689 | { |
| 5690 | return IfThenElse(x > y, x, y); |
| 5691 | } |
| 5692 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5693 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5694 | { |
| 5695 | return IfThenElse(x < y, x, y); |
| 5696 | } |
| 5697 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5698 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5699 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 5700 | #if defined(__i386__) || defined(__x86_64__) |
| 5701 | if(exactAtPow2) |
| 5702 | { |
| 5703 | // rcpss uses a piecewise-linear approximation which minimizes the relative error |
| 5704 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 5705 | return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 5706 | } |
| 5707 | #endif |
| 5708 | |
| 5709 | return x86::rcpss(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5710 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5711 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5712 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5713 | { |
| 5714 | return x86::rsqrtss(x); |
| 5715 | } |
| 5716 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5717 | RValue<Float> Sqrt(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5718 | { |
| 5719 | return x86::sqrtss(x); |
| 5720 | } |
| 5721 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5722 | RValue<Float> Round(RValue<Float> x) |
| 5723 | { |
| 5724 | if(CPUID::supportsSSE4_1()) |
| 5725 | { |
| 5726 | return x86::roundss(x, 0); |
| 5727 | } |
| 5728 | else |
| 5729 | { |
| 5730 | return Float4(Round(Float4(x))).x; |
| 5731 | } |
| 5732 | } |
| 5733 | |
| 5734 | RValue<Float> Trunc(RValue<Float> x) |
| 5735 | { |
| 5736 | if(CPUID::supportsSSE4_1()) |
| 5737 | { |
| 5738 | return x86::roundss(x, 3); |
| 5739 | } |
| 5740 | else |
| 5741 | { |
| 5742 | return Float(Int(x)); // Rounded toward zero |
| 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | RValue<Float> Frac(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5747 | { |
| 5748 | if(CPUID::supportsSSE4_1()) |
| 5749 | { |
| 5750 | return x - x86::floorss(x); |
| 5751 | } |
| 5752 | else |
| 5753 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5754 | return Float4(Frac(Float4(x))).x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5755 | } |
| 5756 | } |
| 5757 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5758 | RValue<Float> Floor(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5759 | { |
| 5760 | if(CPUID::supportsSSE4_1()) |
| 5761 | { |
| 5762 | return x86::floorss(x); |
| 5763 | } |
| 5764 | else |
| 5765 | { |
| 5766 | return Float4(Floor(Float4(x))).x; |
| 5767 | } |
| 5768 | } |
| 5769 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5770 | RValue<Float> Ceil(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5771 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5772 | if(CPUID::supportsSSE4_1()) |
| 5773 | { |
| 5774 | return x86::ceilss(x); |
| 5775 | } |
| 5776 | else |
| 5777 | { |
| 5778 | return Float4(Ceil(Float4(x))).x; |
| 5779 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5780 | } |
| 5781 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5782 | Type *Float::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5783 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 5784 | return T(llvm::Type::getFloatTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5785 | } |
| 5786 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5787 | Float2::Float2(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5788 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5789 | Value *int64x2 = Nucleus::createBitCast(cast.value, T(llvm::VectorType::get(T(Long::getType()), 2))); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5790 | Value *int64 = Nucleus::createExtractElement(int64x2, Long::getType(), 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5791 | Value *float2 = Nucleus::createBitCast(int64, Float2::getType()); |
| 5792 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5793 | storeValue(float2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5794 | } |
| 5795 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5796 | Type *Float2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5797 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5798 | return T(Type_v2f32); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5799 | } |
| 5800 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5801 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5802 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 5803 | Value *a = Int4(cast).loadValue(); |
| 5804 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5805 | |
| 5806 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5807 | } |
| 5808 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5809 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5810 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 5811 | Value *a = Int4(cast).loadValue(); |
| 5812 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5813 | |
| 5814 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5815 | } |
| 5816 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5817 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5818 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5819 | Int4 c(cast); |
| 5820 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5821 | } |
| 5822 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5823 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5824 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5825 | Int4 c(cast); |
| 5826 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5827 | } |
| 5828 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5829 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5830 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5831 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5832 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5833 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5834 | } |
| 5835 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5836 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5837 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5838 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5839 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5840 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5841 | storeValue(result.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5842 | } |
| 5843 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5844 | Float4::Float4() : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5845 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5846 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5847 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5848 | Float4::Float4(float xyzw) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5849 | { |
| 5850 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5851 | } |
| 5852 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5853 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5854 | { |
| 5855 | constant(x, yzw, yzw, yzw); |
| 5856 | } |
| 5857 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5858 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5859 | { |
| 5860 | constant(x, y, zw, zw); |
| 5861 | } |
| 5862 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5863 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5864 | { |
| 5865 | constant(x, y, z, w); |
| 5866 | } |
| 5867 | |
| 5868 | void Float4::constant(float x, float y, float z, float w) |
| 5869 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5870 | double constantVector[4] = {x, y, z, w}; |
| 5871 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5872 | } |
| 5873 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5874 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5875 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5876 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5877 | } |
| 5878 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5879 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5880 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5881 | Value *value = rhs.loadValue(); |
| 5882 | storeValue(value); |
| 5883 | } |
| 5884 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5885 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5886 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5887 | Value *value = rhs.loadValue(); |
| 5888 | storeValue(value); |
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<Float> rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5892 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5893 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5894 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5895 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5896 | int swizzle[4] = {0, 0, 0, 0}; |
| 5897 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5898 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5899 | storeValue(replicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5900 | } |
| 5901 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5902 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5903 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5904 | *this = RValue<Float>(rhs.loadValue()); |
| 5905 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5906 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5907 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5908 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5909 | *this = RValue<Float>(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5910 | } |
| 5911 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5912 | RValue<Float4> Float4::operator=(float x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5913 | { |
| 5914 | return *this = Float4(x, x, x, x); |
| 5915 | } |
| 5916 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5917 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5918 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5919 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5920 | |
| 5921 | return rhs; |
| 5922 | } |
| 5923 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5924 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5925 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5926 | Value *value = rhs.loadValue(); |
| 5927 | storeValue(value); |
| 5928 | |
| 5929 | return RValue<Float4>(value); |
| 5930 | } |
| 5931 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5932 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5933 | { |
| 5934 | Value *value = rhs.loadValue(); |
| 5935 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5936 | |
| 5937 | return RValue<Float4>(value); |
| 5938 | } |
| 5939 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5940 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5941 | { |
| 5942 | return *this = Float4(rhs); |
| 5943 | } |
| 5944 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5945 | RValue<Float4> Float4::operator=(const Float &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5946 | { |
| 5947 | return *this = Float4(rhs); |
| 5948 | } |
| 5949 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5950 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5951 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5952 | return *this = Float4(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5953 | } |
| 5954 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5955 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5956 | { |
| 5957 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5958 | } |
| 5959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5960 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5961 | { |
| 5962 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5963 | } |
| 5964 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5965 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5966 | { |
| 5967 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5968 | } |
| 5969 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5970 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5971 | { |
| 5972 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5973 | } |
| 5974 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5975 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5976 | { |
| 5977 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 5978 | } |
| 5979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5980 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5981 | { |
| 5982 | return lhs = lhs + rhs; |
| 5983 | } |
| 5984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5985 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5986 | { |
| 5987 | return lhs = lhs - rhs; |
| 5988 | } |
| 5989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5990 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5991 | { |
| 5992 | return lhs = lhs * rhs; |
| 5993 | } |
| 5994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5995 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5996 | { |
| 5997 | return lhs = lhs / rhs; |
| 5998 | } |
| 5999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6000 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6001 | { |
| 6002 | return lhs = lhs % rhs; |
| 6003 | } |
| 6004 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6005 | RValue<Float4> operator+(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6006 | { |
| 6007 | return val; |
| 6008 | } |
| 6009 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6010 | RValue<Float4> operator-(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6011 | { |
| 6012 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6013 | } |
| 6014 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6015 | RValue<Float4> Abs(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6016 | { |
| 6017 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6018 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6019 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6020 | |
| 6021 | return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType())); |
| 6022 | } |
| 6023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6024 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6025 | { |
| 6026 | return x86::maxps(x, y); |
| 6027 | } |
| 6028 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6029 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6030 | { |
| 6031 | return x86::minps(x, y); |
| 6032 | } |
| 6033 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 6034 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6035 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 6036 | #if defined(__i386__) || defined(__x86_64__) |
| 6037 | if(exactAtPow2) |
| 6038 | { |
| 6039 | // rcpps uses a piecewise-linear approximation which minimizes the relative error |
| 6040 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 6041 | return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 6042 | } |
| 6043 | #endif |
| 6044 | |
| 6045 | return x86::rcpps(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6046 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6047 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6048 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6049 | { |
| 6050 | return x86::rsqrtps(x); |
| 6051 | } |
| 6052 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6053 | RValue<Float4> Sqrt(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6054 | { |
| 6055 | return x86::sqrtps(x); |
| 6056 | } |
| 6057 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6058 | RValue<Float4> Insert(RValue<Float4> val, RValue<Float> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6059 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6060 | return RValue<Float4>(Nucleus::createInsertElement(val.value, element.value, i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6061 | } |
| 6062 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6063 | RValue<Float> Extract(RValue<Float4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6064 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6065 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6066 | } |
| 6067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6068 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6069 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6070 | return RValue<Float4>(createSwizzle4(x.value, select)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6071 | } |
| 6072 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6073 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6074 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6075 | int shuffle[4] = |
| 6076 | { |
| 6077 | ((imm >> 0) & 0x03) + 0, |
| 6078 | ((imm >> 2) & 0x03) + 0, |
| 6079 | ((imm >> 4) & 0x03) + 4, |
| 6080 | ((imm >> 6) & 0x03) + 4, |
| 6081 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6082 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6083 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6084 | } |
| 6085 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6086 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6087 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6088 | int shuffle[4] = {0, 4, 1, 5}; |
| 6089 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6090 | } |
| 6091 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6092 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6093 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 6094 | int shuffle[4] = {2, 6, 3, 7}; |
| 6095 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6096 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6097 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6098 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6099 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6100 | Value *vector = lhs.loadValue(); |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6101 | Value *shuffle = createMask4(vector, rhs.value, select); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6102 | lhs.storeValue(shuffle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6103 | |
| 6104 | return RValue<Float4>(shuffle); |
| 6105 | } |
| 6106 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6107 | RValue<Int> SignMask(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6108 | { |
| 6109 | return x86::movmskps(x); |
| 6110 | } |
| 6111 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6112 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6113 | { |
| 6114 | // return As<Int4>(x86::cmpeqps(x, y)); |
| 6115 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6116 | } |
| 6117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6118 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6119 | { |
| 6120 | // return As<Int4>(x86::cmpltps(x, y)); |
| 6121 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6122 | } |
| 6123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6124 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6125 | { |
| 6126 | // return As<Int4>(x86::cmpleps(x, y)); |
| 6127 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6128 | } |
| 6129 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6130 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6131 | { |
| 6132 | // return As<Int4>(x86::cmpneqps(x, y)); |
| 6133 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6134 | } |
| 6135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6136 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6137 | { |
| 6138 | // return As<Int4>(x86::cmpnltps(x, y)); |
| 6139 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6140 | } |
| 6141 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6142 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6143 | { |
| 6144 | // return As<Int4>(x86::cmpnleps(x, y)); |
| 6145 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6146 | } |
| 6147 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6148 | RValue<Float4> Round(RValue<Float4> x) |
| 6149 | { |
| 6150 | if(CPUID::supportsSSE4_1()) |
| 6151 | { |
| 6152 | return x86::roundps(x, 0); |
| 6153 | } |
| 6154 | else |
| 6155 | { |
| 6156 | return Float4(RoundInt(x)); |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6161 | { |
| 6162 | if(CPUID::supportsSSE4_1()) |
| 6163 | { |
| 6164 | return x86::roundps(x, 3); |
| 6165 | } |
| 6166 | else |
| 6167 | { |
| 6168 | return Float4(Int4(x)); // Rounded toward zero |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | RValue<Float4> Frac(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6173 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6174 | Float4 frc; |
| 6175 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6176 | if(CPUID::supportsSSE4_1()) |
| 6177 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6178 | frc = x - x86::floorps(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6179 | } |
| 6180 | else |
| 6181 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6182 | frc = x - Float4(Int4(x)); // Signed fractional part. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6183 | |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6184 | frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1.0f))); // Add 1.0 if negative. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6185 | } |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6186 | |
| 6187 | // x - floor(x) can be 1.0 for very small negative x. |
| 6188 | // Clamp against the value just below 1.0. |
| 6189 | return Min(frc, As<Float4>(Int4(0x3F7FFFFF))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6190 | } |
| 6191 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6192 | RValue<Float4> Floor(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6193 | { |
| 6194 | if(CPUID::supportsSSE4_1()) |
| 6195 | { |
| 6196 | return x86::floorps(x); |
| 6197 | } |
| 6198 | else |
| 6199 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6200 | return x - Frac(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6201 | } |
| 6202 | } |
| 6203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6204 | RValue<Float4> Ceil(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6205 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6206 | if(CPUID::supportsSSE4_1()) |
| 6207 | { |
| 6208 | return x86::ceilps(x); |
| 6209 | } |
| 6210 | else |
| 6211 | { |
| 6212 | return -Floor(-x); |
| 6213 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6214 | } |
| 6215 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6216 | Type *Float4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6217 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6218 | return T(llvm::VectorType::get(T(Float::getType()), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6219 | } |
| 6220 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6221 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6222 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6223 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), V(Nucleus::createConstantInt(offset)), false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6224 | } |
| 6225 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6226 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6227 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6228 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6229 | } |
| 6230 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6231 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6232 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6233 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6234 | } |
| 6235 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6236 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6237 | { |
| 6238 | return lhs = lhs + offset; |
| 6239 | } |
| 6240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6241 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6242 | { |
| 6243 | return lhs = lhs + offset; |
| 6244 | } |
| 6245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6246 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6247 | { |
| 6248 | return lhs = lhs + offset; |
| 6249 | } |
| 6250 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6251 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6252 | { |
| 6253 | return lhs + -offset; |
| 6254 | } |
| 6255 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6256 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6257 | { |
| 6258 | return lhs + -offset; |
| 6259 | } |
| 6260 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6261 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6262 | { |
| 6263 | return lhs + -offset; |
| 6264 | } |
| 6265 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6266 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6267 | { |
| 6268 | return lhs = lhs - offset; |
| 6269 | } |
| 6270 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6271 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6272 | { |
| 6273 | return lhs = lhs - offset; |
| 6274 | } |
| 6275 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6276 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6277 | { |
| 6278 | return lhs = lhs - offset; |
| 6279 | } |
| 6280 | |
| 6281 | void Return() |
| 6282 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6283 | Nucleus::createRetVoid(); |
| 6284 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6285 | Nucleus::createUnreachable(); |
| 6286 | } |
| 6287 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6288 | void Return(RValue<Int> ret) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6289 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6290 | Nucleus::createRet(ret.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6291 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6292 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6293 | } |
| 6294 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 6295 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6296 | { |
| 6297 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6298 | Nucleus::setInsertBlock(bodyBB); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6299 | } |
| 6300 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6301 | RValue<Long> Ticks() |
| 6302 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6303 | llvm::Function *rdtsc = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::readcyclecounter); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6304 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6305 | return RValue<Long>(V(::builder->CreateCall(rdtsc))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6306 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | namespace sw |
| 6310 | { |
| 6311 | namespace x86 |
| 6312 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6313 | RValue<Int> cvtss2si(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6314 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6315 | llvm::Function *cvtss2si = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cvtss2si); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6316 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6317 | Float4 vector; |
| 6318 | vector.x = val; |
| 6319 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6320 | return RValue<Int>(V(::builder->CreateCall(cvtss2si, RValue<Float4>(vector).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6321 | } |
| 6322 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6323 | RValue<Int2> cvtps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6324 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6325 | llvm::Function *cvtps2pi = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cvtps2pi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6326 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6327 | return RValue<Int2>(V(::builder->CreateCall(cvtps2pi, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6328 | } |
| 6329 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6330 | RValue<Int2> cvttps2pi(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6331 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6332 | llvm::Function *cvttps2pi = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cvttps2pi); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6333 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6334 | return RValue<Int2>(V(::builder->CreateCall(cvttps2pi, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6335 | } |
| 6336 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6337 | RValue<Int4> cvtps2dq(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6338 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6339 | llvm::Function *cvtps2dq = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_cvtps2dq); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6340 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6341 | return RValue<Int4>(V(::builder->CreateCall(cvtps2dq, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6342 | } |
| 6343 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6344 | RValue<Float> rcpss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6345 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6346 | llvm::Function *rcpss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rcp_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6347 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6348 | Value *vector = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6349 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6350 | 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] | 6351 | } |
| 6352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6353 | RValue<Float> sqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6354 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6355 | llvm::Function *sqrtss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_sqrt_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6356 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6357 | Value *vector = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), val.value, 0); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6358 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6359 | 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] | 6360 | } |
| 6361 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6362 | RValue<Float> rsqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6363 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6364 | llvm::Function *rsqrtss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rsqrt_ss); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6365 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6366 | Value *vector = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), val.value, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6367 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6368 | 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] | 6369 | } |
| 6370 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6371 | RValue<Float4> rcpps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6372 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6373 | llvm::Function *rcpps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rcp_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6374 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6375 | return RValue<Float4>(V(::builder->CreateCall(rcpps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6376 | } |
| 6377 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6378 | RValue<Float4> sqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6379 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6380 | llvm::Function *sqrtps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_sqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6381 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6382 | return RValue<Float4>(V(::builder->CreateCall(sqrtps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6383 | } |
| 6384 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6385 | RValue<Float4> rsqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6386 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6387 | llvm::Function *rsqrtps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_rsqrt_ps); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6388 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6389 | return RValue<Float4>(V(::builder->CreateCall(rsqrtps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6390 | } |
| 6391 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6392 | RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6393 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6394 | llvm::Function *maxps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_max_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6395 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6396 | return RValue<Float4>(V(::builder->CreateCall2(maxps, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6397 | } |
| 6398 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6399 | RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6400 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6401 | llvm::Function *minps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_min_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6402 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6403 | return RValue<Float4>(V(::builder->CreateCall2(minps, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6404 | } |
| 6405 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6406 | RValue<Float> roundss(RValue<Float> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6407 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6408 | llvm::Function *roundss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_round_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6409 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6410 | Value *undef = V(llvm::UndefValue::get(T(Float4::getType()))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6411 | Value *vector = Nucleus::createInsertElement(undef, val.value, 0); |
| 6412 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6413 | 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] | 6414 | } |
| 6415 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6416 | RValue<Float> floorss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6417 | { |
| 6418 | return roundss(val, 1); |
| 6419 | } |
| 6420 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6421 | RValue<Float> ceilss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6422 | { |
| 6423 | return roundss(val, 2); |
| 6424 | } |
| 6425 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6426 | RValue<Float4> roundps(RValue<Float4> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6427 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6428 | llvm::Function *roundps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_round_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6429 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6430 | 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] | 6431 | } |
| 6432 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6433 | RValue<Float4> floorps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6434 | { |
| 6435 | return roundps(val, 1); |
| 6436 | } |
| 6437 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6438 | RValue<Float4> ceilps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6439 | { |
| 6440 | return roundps(val, 2); |
| 6441 | } |
| 6442 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6443 | RValue<Float4> cmpps(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6444 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6445 | llvm::Function *cmpps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cmp_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6446 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6447 | 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] | 6448 | } |
| 6449 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6450 | RValue<Float4> cmpeqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6451 | { |
| 6452 | return cmpps(x, y, 0); |
| 6453 | } |
| 6454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6455 | RValue<Float4> cmpltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6456 | { |
| 6457 | return cmpps(x, y, 1); |
| 6458 | } |
| 6459 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6460 | RValue<Float4> cmpleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6461 | { |
| 6462 | return cmpps(x, y, 2); |
| 6463 | } |
| 6464 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6465 | RValue<Float4> cmpunordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6466 | { |
| 6467 | return cmpps(x, y, 3); |
| 6468 | } |
| 6469 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6470 | RValue<Float4> cmpneqps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6471 | { |
| 6472 | return cmpps(x, y, 4); |
| 6473 | } |
| 6474 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6475 | RValue<Float4> cmpnltps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6476 | { |
| 6477 | return cmpps(x, y, 5); |
| 6478 | } |
| 6479 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6480 | RValue<Float4> cmpnleps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6481 | { |
| 6482 | return cmpps(x, y, 6); |
| 6483 | } |
| 6484 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6485 | RValue<Float4> cmpordps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6486 | { |
| 6487 | return cmpps(x, y, 7); |
| 6488 | } |
| 6489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6490 | RValue<Float> cmpss(RValue<Float> x, RValue<Float> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6491 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6492 | llvm::Function *cmpss = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cmp_ss); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6493 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6494 | Value *vector1 = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), x.value, 0); |
| 6495 | Value *vector2 = Nucleus::createInsertElement(V(llvm::UndefValue::get(T(Float4::getType()))), y.value, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6496 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6497 | 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] | 6498 | } |
| 6499 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6500 | RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6501 | { |
| 6502 | return cmpss(x, y, 0); |
| 6503 | } |
| 6504 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6505 | RValue<Float> cmpltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6506 | { |
| 6507 | return cmpss(x, y, 1); |
| 6508 | } |
| 6509 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6510 | RValue<Float> cmpless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6511 | { |
| 6512 | return cmpss(x, y, 2); |
| 6513 | } |
| 6514 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6515 | RValue<Float> cmpunordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6516 | { |
| 6517 | return cmpss(x, y, 3); |
| 6518 | } |
| 6519 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6520 | RValue<Float> cmpneqss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6521 | { |
| 6522 | return cmpss(x, y, 4); |
| 6523 | } |
| 6524 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6525 | RValue<Float> cmpnltss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6526 | { |
| 6527 | return cmpss(x, y, 5); |
| 6528 | } |
| 6529 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6530 | RValue<Float> cmpnless(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6531 | { |
| 6532 | return cmpss(x, y, 6); |
| 6533 | } |
| 6534 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6535 | RValue<Float> cmpordss(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6536 | { |
| 6537 | return cmpss(x, y, 7); |
| 6538 | } |
| 6539 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 6540 | RValue<Int4> pabsd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6541 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6542 | llvm::Function *pabsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_ssse3_pabs_d_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6543 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6544 | return RValue<Int4>(V(::builder->CreateCall(pabsd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6545 | } |
| 6546 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6547 | RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6548 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6549 | llvm::Function *paddsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_padds_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6550 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6551 | 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] | 6552 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6553 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6554 | RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6555 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6556 | llvm::Function *psubsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psubs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6557 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6558 | 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] | 6559 | } |
| 6560 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6561 | RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6562 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6563 | llvm::Function *paddusw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_paddus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6564 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6565 | 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] | 6566 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6567 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6568 | RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6569 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6570 | llvm::Function *psubusw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psubus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6571 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6572 | 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] | 6573 | } |
| 6574 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6575 | RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6576 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6577 | llvm::Function *paddsb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_padds_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6578 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6579 | 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] | 6580 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6581 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6582 | RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6583 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6584 | llvm::Function *psubsb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psubs_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6585 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6586 | 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] | 6587 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6588 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6589 | RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6590 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6591 | llvm::Function *paddusb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_paddus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6592 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6593 | 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] | 6594 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6595 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6596 | RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6597 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6598 | llvm::Function *psubusb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psubus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6599 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6600 | 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] | 6601 | } |
| 6602 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6603 | RValue<Short4> paddw(RValue<Short4> x, RValue<Short4> y) |
| 6604 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6605 | llvm::Function *paddw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_padd_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6606 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6607 | 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] | 6608 | } |
| 6609 | |
| 6610 | RValue<Short4> psubw(RValue<Short4> x, RValue<Short4> y) |
| 6611 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6612 | llvm::Function *psubw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psub_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6613 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6614 | 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] | 6615 | } |
| 6616 | |
| 6617 | RValue<Short4> pmullw(RValue<Short4> x, RValue<Short4> y) |
| 6618 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6619 | llvm::Function *pmullw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmull_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6620 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6621 | 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] | 6622 | } |
| 6623 | |
| 6624 | RValue<Short4> pand(RValue<Short4> x, RValue<Short4> y) |
| 6625 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6626 | llvm::Function *pand = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pand); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6627 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6628 | 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] | 6629 | } |
| 6630 | |
| 6631 | RValue<Short4> por(RValue<Short4> x, RValue<Short4> y) |
| 6632 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6633 | llvm::Function *por = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_por); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6634 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6635 | 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] | 6636 | } |
| 6637 | |
| 6638 | RValue<Short4> pxor(RValue<Short4> x, RValue<Short4> y) |
| 6639 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6640 | llvm::Function *pxor = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pxor); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6641 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6642 | 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] | 6643 | } |
| 6644 | |
| 6645 | RValue<Short4> pshufw(RValue<Short4> x, unsigned char y) |
| 6646 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6647 | llvm::Function *pshufw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_pshuf_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6648 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6649 | 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] | 6650 | } |
| 6651 | |
| 6652 | RValue<Int2> punpcklwd(RValue<Short4> x, RValue<Short4> y) |
| 6653 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6654 | llvm::Function *punpcklwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_punpcklwd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6655 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6656 | 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] | 6657 | } |
| 6658 | |
| 6659 | RValue<Int2> punpckhwd(RValue<Short4> x, RValue<Short4> y) |
| 6660 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6661 | llvm::Function *punpckhwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_punpckhwd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6662 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6663 | 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] | 6664 | } |
| 6665 | |
| 6666 | RValue<Short4> pinsrw(RValue<Short4> x, RValue<Int> y, unsigned int i) |
| 6667 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6668 | llvm::Function *pinsrw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pinsr_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6669 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6670 | 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] | 6671 | } |
| 6672 | |
| 6673 | RValue<Int> pextrw(RValue<Short4> x, unsigned int i) |
| 6674 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6675 | llvm::Function *pextrw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pextr_w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6676 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6677 | 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] | 6678 | } |
| 6679 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6680 | RValue<Short4> punpckldq(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6681 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6682 | llvm::Function *punpckldq = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_punpckldq); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6683 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6684 | 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] | 6685 | } |
| 6686 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6687 | RValue<Short4> punpckhdq(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6688 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6689 | llvm::Function *punpckhdq = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_punpckhdq); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6690 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 6691 | 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] | 6692 | } |
| 6693 | |
| 6694 | RValue<Short4> punpcklbw(RValue<Byte8> x, RValue<Byte8> y) |
| 6695 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6696 | llvm::Function *punpcklbw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_punpcklbw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6697 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6698 | 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] | 6699 | } |
| 6700 | |
| 6701 | RValue<Short4> punpckhbw(RValue<Byte8> x, RValue<Byte8> y) |
| 6702 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6703 | llvm::Function *punpckhbw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_punpckhbw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6704 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6705 | 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] | 6706 | } |
| 6707 | |
| 6708 | RValue<Byte8> paddb(RValue<Byte8> x, RValue<Byte8> y) |
| 6709 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6710 | llvm::Function *paddb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_padd_b); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6711 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6712 | 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] | 6713 | } |
| 6714 | |
| 6715 | RValue<Byte8> psubb(RValue<Byte8> x, RValue<Byte8> y) |
| 6716 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6717 | llvm::Function *psubb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psub_b); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6718 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6719 | 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] | 6720 | } |
| 6721 | |
| 6722 | RValue<Int2> paddd(RValue<Int2> x, RValue<Int2> y) |
| 6723 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6724 | llvm::Function *paddd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_padd_d); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6725 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6726 | 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] | 6727 | } |
| 6728 | |
| 6729 | RValue<Int2> psubd(RValue<Int2> x, RValue<Int2> y) |
| 6730 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6731 | llvm::Function *psubd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psub_d); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6732 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6733 | 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] | 6734 | } |
| 6735 | |
| 6736 | RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6737 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6738 | llvm::Function *pavgw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pavg_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6739 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6740 | 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] | 6741 | } |
| 6742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6743 | RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6744 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6745 | llvm::Function *pmaxsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmaxs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6746 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6747 | 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] | 6748 | } |
| 6749 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6750 | RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6751 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6752 | llvm::Function *pminsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmins_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6753 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6754 | 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] | 6755 | } |
| 6756 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6757 | RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6758 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6759 | llvm::Function *pcmpgtw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pcmpgt_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6760 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6761 | 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] | 6762 | } |
| 6763 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6764 | RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6765 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6766 | llvm::Function *pcmpeqw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pcmpeq_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6767 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6768 | 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] | 6769 | } |
| 6770 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6771 | RValue<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6772 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6773 | llvm::Function *pcmpgtb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pcmpgt_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6774 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6775 | 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] | 6776 | } |
| 6777 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6778 | RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6779 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6780 | llvm::Function *pcmpeqb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pcmpeq_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6781 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6782 | 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] | 6783 | } |
| 6784 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6785 | RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6786 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6787 | llvm::Function *packssdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_packssdw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6788 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6789 | 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] | 6790 | } |
| 6791 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6792 | RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6793 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6794 | llvm::Function *packssdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packssdw_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6795 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6796 | return RValue<Short8>(V(::builder->CreateCall2(packssdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6797 | } |
| 6798 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6799 | RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6800 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6801 | llvm::Function *packsswb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_packsswb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6802 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6803 | 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] | 6804 | } |
| 6805 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6806 | RValue<Byte8> packuswb(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6807 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6808 | llvm::Function *packuswb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_packuswb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6809 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6810 | 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] | 6811 | } |
| 6812 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 6813 | RValue<UShort8> packusdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6814 | { |
| 6815 | if(CPUID::supportsSSE4_1()) |
| 6816 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6817 | llvm::Function *packusdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_packusdw); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6818 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6819 | return RValue<UShort8>(V(::builder->CreateCall2(packusdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6820 | } |
| 6821 | else |
| 6822 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 6823 | RValue<Int4> bx = (x & ~(x >> 31)) - Int4(0x8000); |
| 6824 | RValue<Int4> by = (y & ~(y >> 31)) - Int4(0x8000); |
| 6825 | |
| 6826 | return As<UShort8>(packssdw(bx, by) + Short8(0x8000u)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6827 | } |
| 6828 | } |
| 6829 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6830 | RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6831 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6832 | llvm::Function *psrlw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psrli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6833 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6834 | 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] | 6835 | } |
| 6836 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6837 | RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6838 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6839 | llvm::Function *psrlw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6840 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6841 | 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] | 6842 | } |
| 6843 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6844 | RValue<Short4> psraw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6845 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6846 | llvm::Function *psraw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psrai_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6847 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6848 | 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] | 6849 | } |
| 6850 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6851 | RValue<Short8> psraw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6852 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6853 | llvm::Function *psraw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrai_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6854 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6855 | 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] | 6856 | } |
| 6857 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6858 | RValue<Short4> psllw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6859 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6860 | llvm::Function *psllw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pslli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6861 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6862 | 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] | 6863 | } |
| 6864 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6865 | RValue<Short8> psllw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6866 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6867 | llvm::Function *psllw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pslli_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6868 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6869 | 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] | 6870 | } |
| 6871 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6872 | RValue<Int2> pslld(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6873 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6874 | llvm::Function *pslld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pslli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6875 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6876 | 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] | 6877 | } |
| 6878 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6879 | RValue<Int4> pslld(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6880 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6881 | llvm::Function *pslld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pslli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6882 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6883 | 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] | 6884 | } |
| 6885 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6886 | RValue<Int2> psrad(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6887 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6888 | llvm::Function *psrad = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psrai_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6889 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6890 | 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] | 6891 | } |
| 6892 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6893 | RValue<Int4> psrad(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6894 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6895 | llvm::Function *psrad = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrai_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6896 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6897 | 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] | 6898 | } |
| 6899 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6900 | RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6901 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6902 | llvm::Function *psrld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_psrli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6903 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6904 | 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] | 6905 | } |
| 6906 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6907 | RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6908 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6909 | llvm::Function *psrld = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psrli_d); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6910 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame^] | 6911 | 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] | 6912 | } |
| 6913 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6914 | RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y) |
| 6915 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6916 | llvm::Function *pmaxsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmaxsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6917 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6918 | return RValue<Int4>(V(::builder->CreateCall2(pmaxsd, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6919 | } |
| 6920 | |
| 6921 | RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y) |
| 6922 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6923 | llvm::Function *pminsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pminsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6924 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6925 | return RValue<Int4>(V(::builder->CreateCall2(pminsd, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y) |
| 6929 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6930 | llvm::Function *pmaxud = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmaxud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6931 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6932 | return RValue<UInt4>(V(::builder->CreateCall2(pmaxud, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6933 | } |
| 6934 | |
| 6935 | RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y) |
| 6936 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6937 | llvm::Function *pminud = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pminud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6938 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6939 | return RValue<UInt4>(V(::builder->CreateCall2(pminud, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6943 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6944 | llvm::Function *pmulhw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmulh_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6945 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6946 | 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] | 6947 | } |
| 6948 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6949 | RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6950 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6951 | llvm::Function *pmulhuw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmulhu_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6952 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6953 | 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] | 6954 | } |
| 6955 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6956 | RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6957 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6958 | llvm::Function *pmaddwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmadd_wd); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6959 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 6960 | 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] | 6961 | } |
| 6962 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6963 | RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6964 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6965 | llvm::Function *pmulhw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmulh_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6966 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6967 | return RValue<Short8>(V(::builder->CreateCall2(pmulhw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6968 | } |
| 6969 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6970 | RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6971 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6972 | llvm::Function *pmulhuw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmulhu_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6973 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6974 | return RValue<UShort8>(V(::builder->CreateCall2(pmulhuw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6975 | } |
| 6976 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6977 | RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6978 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6979 | llvm::Function *pmaddwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmadd_wd); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6980 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6981 | return RValue<Int4>(V(::builder->CreateCall2(pmaddwd, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6982 | } |
| 6983 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6984 | RValue<Int> movmskps(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6985 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6986 | llvm::Function *movmskps = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_movmsk_ps); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6987 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6988 | return RValue<Int>(V(::builder->CreateCall(movmskps, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6989 | } |
| 6990 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6991 | RValue<Int> pmovmskb(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6992 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6993 | llvm::Function *pmovmskb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_pmovmskb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6994 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6995 | return RValue<Int>(V(::builder->CreateCall(pmovmskb, As<MMX>(x).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6996 | } |
| 6997 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 6998 | //RValue<Int2> movd(RValue<Pointer<Int>> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6999 | //{ |
| 7000 | // Value *element = Nucleus::createLoad(x.value); |
| 7001 | |
| 7002 | //// Value *int2 = UndefValue::get(Int2::getType()); |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7003 | //// int2 = Nucleus::createInsertElement(int2, element, ConstantInt::get(T(Int::getType()), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7004 | |
| 7005 | // Value *int2 = Nucleus::createBitCast(Nucleus::createZExt(element, Long::getType()), Int2::getType()); |
| 7006 | |
| 7007 | // return RValue<Int2>(int2); |
| 7008 | //} |
| 7009 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7010 | //RValue<Int2> movdq2q(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7011 | //{ |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7012 | // Value *long2 = Nucleus::createBitCast(x.value, T(llvm::VectorType::get(T(Long::getType()), 2))); |
| 7013 | // Value *element = Nucleus::createExtractElement(long2, ConstantInt::get(T(Int::getType()), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7014 | |
| 7015 | // return RValue<Int2>(Nucleus::createBitCast(element, Int2::getType())); |
| 7016 | //} |
| 7017 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7018 | RValue<Int4> pmovzxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7019 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7020 | llvm::Function *pmovzxbd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovzxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7021 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7022 | 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] | 7023 | } |
| 7024 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7025 | RValue<Int4> pmovsxbd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7026 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7027 | llvm::Function *pmovsxbd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovsxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7028 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7029 | 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] | 7030 | } |
| 7031 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7032 | RValue<Int4> pmovzxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7033 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7034 | llvm::Function *pmovzxwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovzxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7035 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7036 | 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] | 7037 | } |
| 7038 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 7039 | RValue<Int4> pmovsxwd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7040 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7041 | llvm::Function *pmovsxwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovsxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 7042 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7043 | 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] | 7044 | } |
| 7045 | |
| 7046 | void emms() |
| 7047 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 7048 | llvm::Function *emms = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_mmx_emms); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7049 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 7050 | V(::builder->CreateCall(emms)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 7051 | } |
| 7052 | } |
| 7053 | } |