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 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 15 | #include "Reactor.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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" |
Nicolas Capens | 708c24b | 2017-10-26 13:07:10 -0400 | [diff] [blame] | 35 | #include "Common/CPUID.hpp" |
| 36 | #include "Common/Thread.hpp" |
| 37 | #include "Common/Memory.hpp" |
| 38 | #include "Common/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 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 98 | uintptr_t type = reinterpret_cast<uintptr_t>(t); |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 99 | if(type < EmulatedTypeCount) |
| 100 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 101 | // Use 128-bit vectors to implement logically shorter ones. |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 102 | switch(type) |
| 103 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 104 | case Type_v2i32: return T(Int4::getType()); |
| 105 | case Type_v4i16: return T(Short8::getType()); |
| 106 | case Type_v2i16: return T(Short8::getType()); |
| 107 | case Type_v8i8: return T(Byte16::getType()); |
| 108 | case Type_v4i8: return T(Byte16::getType()); |
| 109 | case Type_v2f32: return T(Float4::getType()); |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 110 | default: assert(false); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return reinterpret_cast<llvm::Type*>(t); |
| 115 | } |
| 116 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 117 | inline Type *T(llvm::Type *t) |
| 118 | { |
| 119 | return reinterpret_cast<Type*>(t); |
| 120 | } |
| 121 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 122 | Type *T(EmulatedType t) |
| 123 | { |
| 124 | return reinterpret_cast<Type*>(t); |
| 125 | } |
| 126 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 127 | inline Value *V(llvm::Value *t) |
| 128 | { |
| 129 | return reinterpret_cast<Value*>(t); |
| 130 | } |
| 131 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 132 | inline std::vector<llvm::Type*> &T(std::vector<Type*> &t) |
| 133 | { |
| 134 | return reinterpret_cast<std::vector<llvm::Type*>&>(t); |
| 135 | } |
| 136 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 137 | inline BasicBlock *B(llvm::BasicBlock *t) |
| 138 | { |
| 139 | return reinterpret_cast<BasicBlock*>(t); |
| 140 | } |
| 141 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 142 | static size_t typeSize(Type *type) |
| 143 | { |
| 144 | uintptr_t t = reinterpret_cast<uintptr_t>(type); |
| 145 | if(t < EmulatedTypeCount) |
| 146 | { |
| 147 | switch(t) |
| 148 | { |
| 149 | case Type_v2i32: return 8; |
| 150 | case Type_v4i16: return 8; |
| 151 | case Type_v2i16: return 4; |
| 152 | case Type_v8i8: return 8; |
| 153 | case Type_v4i8: return 4; |
| 154 | case Type_v2f32: return 8; |
| 155 | default: assert(false); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return T(type)->getPrimitiveSizeInBits() / 8; |
| 160 | } |
| 161 | |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 162 | static unsigned int elementCount(Type *type) |
| 163 | { |
| 164 | uintptr_t t = reinterpret_cast<uintptr_t>(type); |
| 165 | if(t < EmulatedTypeCount) |
| 166 | { |
| 167 | switch(t) |
| 168 | { |
| 169 | case Type_v2i32: return 2; |
| 170 | case Type_v4i16: return 4; |
| 171 | case Type_v2i16: return 2; |
| 172 | case Type_v8i8: return 8; |
| 173 | case Type_v4i8: return 4; |
| 174 | case Type_v2f32: return 2; |
| 175 | default: assert(false); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return llvm::cast<llvm::VectorType>(T(type))->getNumElements(); |
| 180 | } |
| 181 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 182 | Nucleus::Nucleus() |
| 183 | { |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 184 | ::codegenMutex.lock(); // Reactor and LLVM are currently not thread safe |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 185 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 186 | llvm::InitializeNativeTarget(); |
| 187 | llvm::JITEmitDebugInfo = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 188 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 189 | if(!::context) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 190 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 191 | ::context = new llvm::LLVMContext(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 194 | ::module = new llvm::Module("", *::context); |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 195 | ::routineManager = new LLVMRoutineManager(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 196 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 197 | #if defined(__x86_64__) |
| 198 | const char *architecture = "x86-64"; |
| 199 | #else |
| 200 | const char *architecture = "x86"; |
| 201 | #endif |
| 202 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 203 | llvm::SmallVector<std::string, 1> MAttrs; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 204 | MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx"); |
| 205 | MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov"); |
| 206 | MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse"); |
| 207 | MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2"); |
| 208 | MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3"); |
| 209 | MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3"); |
| 210 | MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41"); |
| 211 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 212 | std::string error; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 213 | llvm::TargetMachine *targetMachine = llvm::EngineBuilder::selectTarget(::module, architecture, "", MAttrs, llvm::Reloc::Default, llvm::CodeModel::JITDefault, &error); |
| 214 | ::executionEngine = llvm::JIT::createJIT(::module, 0, ::routineManager, llvm::CodeGenOpt::Aggressive, true, targetMachine); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 215 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 216 | if(!::builder) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 217 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 218 | ::builder = new llvm::IRBuilder<>(*::context); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 219 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 220 | #if defined(_WIN32) |
| 221 | HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll"); |
| 222 | if(CodeAnalyst) |
| 223 | { |
| 224 | CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize"); |
| 225 | CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog"); |
| 226 | CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode"); |
| 227 | |
| 228 | CodeAnalystInitialize(); |
| 229 | } |
| 230 | #endif |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | Nucleus::~Nucleus() |
| 235 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 236 | delete ::executionEngine; |
| 237 | ::executionEngine = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 238 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 239 | ::routineManager = nullptr; |
| 240 | ::function = nullptr; |
| 241 | ::module = nullptr; |
Nicolas Capens | b7ea984 | 2015-04-01 10:54:59 -0400 | [diff] [blame] | 242 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 243 | ::codegenMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 247 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 248 | if(::builder->GetInsertBlock()->empty() || !::builder->GetInsertBlock()->back().isTerminator()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 249 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 250 | llvm::Type *type = ::function->getReturnType(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 251 | |
| 252 | if(type->isVoidTy()) |
| 253 | { |
| 254 | createRetVoid(); |
| 255 | } |
| 256 | else |
| 257 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 258 | createRet(V(llvm::UndefValue::get(type))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 259 | } |
| 260 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 261 | |
| 262 | if(false) |
| 263 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 264 | std::string error; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 265 | llvm::raw_fd_ostream file("llvm-dump-unopt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 266 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | if(runOptimizations) |
| 270 | { |
| 271 | optimize(); |
| 272 | } |
| 273 | |
| 274 | if(false) |
| 275 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 276 | std::string error; |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 277 | llvm::raw_fd_ostream file("llvm-dump-opt.txt", error); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 278 | ::module->print(file, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 279 | } |
| 280 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 281 | void *entry = ::executionEngine->getPointerToFunction(::function); |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 282 | LLVMRoutine *routine = ::routineManager->acquireRoutine(entry); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 283 | |
| 284 | if(CodeAnalystLogJITCode) |
| 285 | { |
Nicolas Capens | d946e0a | 2014-06-26 11:31:08 -0400 | [diff] [blame] | 286 | CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | return routine; |
| 290 | } |
| 291 | |
| 292 | void Nucleus::optimize() |
| 293 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 294 | static llvm::PassManager *passManager = nullptr; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 295 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 296 | if(!passManager) |
| 297 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 298 | passManager = new llvm::PassManager(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 299 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 300 | llvm::UnsafeFPMath = true; |
| 301 | // llvm::NoInfsFPMath = true; |
| 302 | // llvm::NoNaNsFPMath = true; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 303 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 304 | passManager->add(new llvm::TargetData(*::executionEngine->getTargetData())); |
| 305 | passManager->add(llvm::createScalarReplAggregatesPass()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 306 | |
| 307 | for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++) |
| 308 | { |
| 309 | switch(optimization[pass]) |
| 310 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 311 | case Disabled: break; |
| 312 | case CFGSimplification: passManager->add(llvm::createCFGSimplificationPass()); break; |
| 313 | case LICM: passManager->add(llvm::createLICMPass()); break; |
| 314 | case AggressiveDCE: passManager->add(llvm::createAggressiveDCEPass()); break; |
| 315 | case GVN: passManager->add(llvm::createGVNPass()); break; |
| 316 | case InstructionCombining: passManager->add(llvm::createInstructionCombiningPass()); break; |
| 317 | case Reassociate: passManager->add(llvm::createReassociatePass()); break; |
| 318 | case DeadStoreElimination: passManager->add(llvm::createDeadStoreEliminationPass()); break; |
| 319 | case SCCP: passManager->add(llvm::createSCCPPass()); break; |
| 320 | case ScalarReplAggregates: passManager->add(llvm::createScalarReplAggregatesPass()); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 321 | default: |
| 322 | assert(false); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 327 | passManager->run(*::module); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 328 | } |
| 329 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 330 | Value *Nucleus::allocateStackVariable(Type *type, int arraySize) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 331 | { |
| 332 | // Need to allocate it in the entry block for mem2reg to work |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 333 | llvm::BasicBlock &entryBlock = ::function->getEntryBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 334 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 335 | llvm::Instruction *declaration; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 336 | |
| 337 | if(arraySize) |
| 338 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 339 | declaration = new llvm::AllocaInst(T(type), Nucleus::createConstantInt(arraySize)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 340 | } |
| 341 | else |
| 342 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 343 | declaration = new llvm::AllocaInst(T(type), (Value*)nullptr); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | entryBlock.getInstList().push_front(declaration); |
| 347 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 348 | return V(declaration); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | BasicBlock *Nucleus::createBasicBlock() |
| 352 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 353 | return B(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | BasicBlock *Nucleus::getInsertBlock() |
| 357 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 358 | return B(::builder->GetInsertBlock()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 362 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 363 | // assert(::builder->GetInsertBlock()->back().isTerminator()); |
| 364 | return ::builder->SetInsertPoint(basicBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 367 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 368 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 369 | llvm::FunctionType *functionType = llvm::FunctionType::get(T(ReturnType), T(Params), false); |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 370 | ::function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", ::module); |
| 371 | ::function->setCallingConv(llvm::CallingConv::C); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 372 | |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 373 | ::builder->SetInsertPoint(BasicBlock::Create(*::context, "", ::function)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 376 | Value *Nucleus::getArgument(unsigned int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 377 | { |
Nicolas Capens | 5c1f5cc | 2016-09-23 16:45:13 -0400 | [diff] [blame] | 378 | llvm::Function::arg_iterator args = ::function->arg_begin(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 379 | |
| 380 | while(index) |
| 381 | { |
| 382 | args++; |
| 383 | index--; |
| 384 | } |
| 385 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 386 | return V(&*args); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 387 | } |
| 388 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 389 | void Nucleus::createRetVoid() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 390 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 391 | ::builder->CreateRetVoid(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 394 | void Nucleus::createRet(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 395 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 396 | ::builder->CreateRet(v); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 399 | void Nucleus::createBr(BasicBlock *dest) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 400 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 401 | ::builder->CreateBr(dest); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 402 | } |
| 403 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 404 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 405 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 406 | ::builder->CreateCondBr(cond, ifTrue, ifFalse); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 410 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 411 | return V(::builder->CreateAdd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 415 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 416 | return V(::builder->CreateSub(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 420 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 421 | return V(::builder->CreateMul(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 425 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 426 | return V(::builder->CreateUDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 430 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 431 | return V(::builder->CreateSDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 435 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 436 | return V(::builder->CreateFAdd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 440 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 441 | return V(::builder->CreateFSub(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 445 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 446 | return V(::builder->CreateFMul(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 450 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 451 | return V(::builder->CreateFDiv(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 455 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 456 | return V(::builder->CreateURem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 460 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 461 | return V(::builder->CreateSRem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 465 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 466 | return V(::builder->CreateFRem(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 470 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 471 | return V(::builder->CreateShl(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 475 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 476 | return V(::builder->CreateLShr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 480 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 481 | return V(::builder->CreateAShr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 485 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 486 | return V(::builder->CreateAnd(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 490 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 491 | return V(::builder->CreateOr(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 495 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 496 | return V(::builder->CreateXor(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 499 | Value *Nucleus::createNeg(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 500 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 501 | return V(::builder->CreateNeg(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 504 | Value *Nucleus::createFNeg(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 505 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 506 | return V(::builder->CreateFNeg(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 509 | Value *Nucleus::createNot(Value *v) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 510 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 511 | return V(::builder->CreateNot(v)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 514 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int alignment) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 515 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 516 | uintptr_t t = reinterpret_cast<uintptr_t>(type); |
| 517 | if(t < EmulatedTypeCount) |
| 518 | { |
| 519 | switch(t) |
| 520 | { |
| 521 | case Type_v2i32: |
| 522 | case Type_v4i16: |
| 523 | case Type_v8i8: |
| 524 | case Type_v2f32: |
| 525 | return createBitCast(createInsertElement(V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))), createLoad(createBitCast(ptr, Pointer<Long>::getType()), Long::getType(), isVolatile, alignment), 0), T(T(type))); |
| 526 | case Type_v2i16: |
| 527 | case Type_v4i8: |
| 528 | if(alignment != 0) // Not a local variable (all vectors are 128-bit). |
| 529 | { |
| 530 | Value *u = V(llvm::UndefValue::get(llvm::VectorType::get(T(Long::getType()), 2))); |
| 531 | Value *i = V(createLoad(createBitCast(ptr, Pointer<Int>::getType()), Int::getType(), isVolatile, alignment)); |
| 532 | i = createZExt(i, Long::getType()); |
| 533 | Value *v = V(createInsertElement(u, i, 0)); |
| 534 | return createBitCast(v, T(T(type))); |
| 535 | } |
| 536 | break; |
| 537 | default: |
| 538 | assert(false); |
| 539 | } |
| 540 | } |
| 541 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 542 | assert(ptr->getType()->getContainedType(0) == T(type)); |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 543 | return V(::builder->Insert(new llvm::LoadInst(ptr, "", isVolatile, alignment))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 546 | Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int alignment) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 547 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 548 | uintptr_t t = reinterpret_cast<uintptr_t>(type); |
| 549 | if(t < EmulatedTypeCount) |
| 550 | { |
| 551 | switch(t) |
| 552 | { |
| 553 | case Type_v2i32: |
| 554 | case Type_v4i16: |
| 555 | case Type_v8i8: |
| 556 | case Type_v2f32: |
| 557 | createStore(createExtractElement(createBitCast(value, T(llvm::VectorType::get(T(Long::getType()), 2))), Long::getType(), 0), createBitCast(ptr, Pointer<Long>::getType()), Long::getType(), isVolatile, alignment); |
| 558 | return value; |
| 559 | case Type_v2i16: |
| 560 | case Type_v4i8: |
| 561 | if(alignment != 0) // Not a local variable (all vectors are 128-bit). |
| 562 | { |
| 563 | createStore(createExtractElement(createBitCast(value, Int4::getType()), Int::getType(), 0), createBitCast(ptr, Pointer<Int>::getType()), Int::getType(), isVolatile, alignment); |
| 564 | return value; |
| 565 | } |
| 566 | break; |
| 567 | default: |
| 568 | assert(false); |
| 569 | } |
| 570 | } |
| 571 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 572 | assert(ptr->getType()->getContainedType(0) == T(type)); |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 573 | ::builder->Insert(new llvm::StoreInst(value, ptr, isVolatile, alignment)); |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 574 | return value; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 575 | } |
| 576 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 577 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 578 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 579 | if(sizeof(void*) == 8) |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 580 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 581 | if(unsignedIndex) |
| 582 | { |
| 583 | index = createZExt(index, Long::getType()); |
| 584 | } |
| 585 | else |
| 586 | { |
| 587 | index = createSExt(index, Long::getType()); |
| 588 | } |
| 589 | |
| 590 | index = createMul(index, createConstantLong((int64_t)typeSize(type))); |
| 591 | } |
| 592 | else |
| 593 | { |
| 594 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 597 | assert(ptr->getType()->getContainedType(0) == T(type)); |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 598 | return createBitCast(V(::builder->CreateGEP(createBitCast(ptr, T(llvm::PointerType::get(T(Byte::getType()), 0))), index)), T(llvm::PointerType::get(T(type), 0))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 599 | } |
| 600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 601 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 602 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 603 | return V(::builder->CreateAtomicRMW(llvm::AtomicRMWInst::Add, ptr, value, llvm::SequentiallyConsistent)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 606 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 607 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 608 | return V(::builder->CreateTrunc(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 609 | } |
| 610 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 611 | Value *Nucleus::createZExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 612 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 613 | return V(::builder->CreateZExt(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 616 | Value *Nucleus::createSExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 617 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 618 | return V(::builder->CreateSExt(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 619 | } |
| 620 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 621 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 622 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 623 | return V(::builder->CreateFPToSI(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 624 | } |
| 625 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 626 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 627 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 628 | return V(::builder->CreateSIToFP(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 629 | } |
| 630 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 631 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 632 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 633 | return V(::builder->CreateFPTrunc(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 636 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 637 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 638 | return V(::builder->CreateFPExt(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 639 | } |
| 640 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 641 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 642 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 643 | // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need |
| 644 | // support for casting between scalars and wide vectors. Emulate them by writing to the stack and |
| 645 | // reading back as the destination type. |
| 646 | if(!v->getType()->isVectorTy() && T(destType)->isVectorTy()) |
| 647 | { |
| 648 | Value *readAddress = allocateStackVariable(destType); |
| 649 | Value *writeAddress = createBitCast(readAddress, T(llvm::PointerType::get(v->getType(), 0))); |
| 650 | createStore(v, writeAddress, T(v->getType())); |
| 651 | return createLoad(readAddress, destType); |
| 652 | } |
| 653 | else if(v->getType()->isVectorTy() && !T(destType)->isVectorTy()) |
| 654 | { |
| 655 | Value *writeAddress = allocateStackVariable(T(v->getType())); |
| 656 | createStore(v, writeAddress, T(v->getType())); |
| 657 | Value *readAddress = createBitCast(writeAddress, T(llvm::PointerType::get(T(destType), 0))); |
| 658 | return createLoad(readAddress, destType); |
| 659 | } |
| 660 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 661 | return V(::builder->CreateBitCast(v, T(destType))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 662 | } |
| 663 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 664 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 665 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 666 | return V(::builder->CreateICmpEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 670 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 671 | return V(::builder->CreateICmpNE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 675 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 676 | return V(::builder->CreateICmpUGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 680 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 681 | return V(::builder->CreateICmpUGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 685 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 686 | return V(::builder->CreateICmpULT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 690 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 691 | return V(::builder->CreateICmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 695 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 696 | return V(::builder->CreateICmpSGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 700 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 701 | return V(::builder->CreateICmpSGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 705 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 706 | return V(::builder->CreateICmpSLT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 710 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 711 | return V(::builder->CreateICmpSLE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 715 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 716 | return V(::builder->CreateFCmpOEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 720 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 721 | return V(::builder->CreateFCmpOGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 725 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 726 | return V(::builder->CreateFCmpOGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 730 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 731 | return V(::builder->CreateFCmpOLT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 735 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 736 | return V(::builder->CreateFCmpOLE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 740 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 741 | return V(::builder->CreateFCmpONE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 745 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 746 | return V(::builder->CreateFCmpORD(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 750 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 751 | return V(::builder->CreateFCmpUNO(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 755 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 756 | return V(::builder->CreateFCmpUEQ(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 760 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 761 | return V(::builder->CreateFCmpUGT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 765 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 766 | return V(::builder->CreateFCmpUGE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 770 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 771 | return V(::builder->CreateFCmpULT(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 775 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 776 | return V(::builder->CreateFCmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 780 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 781 | return V(::builder->CreateFCmpULE(lhs, rhs)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 784 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 785 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 786 | assert(vector->getType()->getContainedType(0) == T(type)); |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 787 | return V(::builder->CreateExtractElement(vector, createConstantInt(index))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 791 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 792 | return V(::builder->CreateInsertElement(vector, element, createConstantInt(index))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 795 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 796 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 797 | int size = llvm::cast<llvm::VectorType>(V1->getType())->getNumElements(); |
| 798 | const int maxSize = 16; |
| 799 | llvm::Constant *swizzle[maxSize]; |
| 800 | assert(size <= maxSize); |
| 801 | |
| 802 | for(int i = 0; i < size; i++) |
| 803 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 804 | swizzle[i] = llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), select[i]); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | llvm::Value *shuffle = llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(swizzle, size)); |
| 808 | |
| 809 | return V(::builder->CreateShuffleVector(V1, V2, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 813 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 814 | return V(::builder->CreateSelect(C, ifTrue, ifFalse)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 815 | } |
| 816 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 817 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 818 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 819 | return reinterpret_cast<SwitchCases*>(::builder->CreateSwitch(control, defaultBranch, numCases)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 820 | } |
| 821 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 822 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 823 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 824 | switchCases->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), label, true), branch); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 827 | void Nucleus::createUnreachable() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 828 | { |
Nicolas Capens | 3d7c35f | 2016-09-28 10:36:57 -0400 | [diff] [blame] | 829 | ::builder->CreateUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 832 | static Value *createSwizzle4(Value *val, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 833 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 834 | int swizzle[4] = |
| 835 | { |
| 836 | (select >> 0) & 0x03, |
| 837 | (select >> 2) & 0x03, |
| 838 | (select >> 4) & 0x03, |
| 839 | (select >> 6) & 0x03, |
| 840 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 841 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 842 | return Nucleus::createShuffleVector(val, val, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 843 | } |
| 844 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 845 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 846 | { |
| 847 | bool mask[4] = {false, false, false, false}; |
| 848 | |
| 849 | mask[(select >> 0) & 0x03] = true; |
| 850 | mask[(select >> 2) & 0x03] = true; |
| 851 | mask[(select >> 4) & 0x03] = true; |
| 852 | mask[(select >> 6) & 0x03] = true; |
| 853 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 854 | int swizzle[4] = |
| 855 | { |
| 856 | mask[0] ? 4 : 0, |
| 857 | mask[1] ? 5 : 1, |
| 858 | mask[2] ? 6 : 2, |
| 859 | mask[3] ? 7 : 3, |
| 860 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 861 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 862 | return Nucleus::createShuffleVector(lhs, rhs, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 865 | Type *Nucleus::getPointerType(Type *ElementType) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 866 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 867 | return T(llvm::PointerType::get(T(ElementType), 0)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 870 | Value *Nucleus::createNullValue(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 871 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 872 | return V(llvm::Constant::getNullValue(T(Ty))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 873 | } |
| 874 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 875 | Value *Nucleus::createConstantLong(int64_t i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 876 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 877 | return V(llvm::ConstantInt::get(llvm::Type::getInt64Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 878 | } |
| 879 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 880 | Value *Nucleus::createConstantInt(int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 881 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 882 | return V(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | } |
| 884 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 885 | Value *Nucleus::createConstantInt(unsigned int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 886 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 887 | return V(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 888 | } |
| 889 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 890 | Value *Nucleus::createConstantBool(bool b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 891 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 892 | return V(llvm::ConstantInt::get(llvm::Type::getInt1Ty(*::context), b)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 893 | } |
| 894 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 895 | Value *Nucleus::createConstantByte(signed char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 896 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 897 | return V(llvm::ConstantInt::get(llvm::Type::getInt8Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 898 | } |
| 899 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 900 | Value *Nucleus::createConstantByte(unsigned char i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 901 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 902 | return V(llvm::ConstantInt::get(llvm::Type::getInt8Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 905 | Value *Nucleus::createConstantShort(short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 906 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 907 | return V(llvm::ConstantInt::get(llvm::Type::getInt16Ty(*::context), i, true)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 908 | } |
| 909 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 910 | Value *Nucleus::createConstantShort(unsigned short i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 911 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 912 | return V(llvm::ConstantInt::get(llvm::Type::getInt16Ty(*::context), i, false)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 915 | Value *Nucleus::createConstantFloat(float x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 916 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 917 | return V(llvm::ConstantFP::get(T(Float::getType()), x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 918 | } |
| 919 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 920 | Value *Nucleus::createNullPointer(Type *Ty) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 921 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 922 | return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(T(Ty), 0))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 923 | } |
| 924 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 925 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 926 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 927 | assert(llvm::isa<llvm::VectorType>(T(type))); |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 928 | const int numConstants = elementCount(type); // Number of provided constants for the (emulated) type. |
| 929 | const int numElements = llvm::cast<llvm::VectorType>(T(type))->getNumElements(); // Number of elements of the underlying vector type. |
| 930 | assert(numElements <= 16 && numConstants <= numElements); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 931 | llvm::Constant *constantVector[16]; |
| 932 | |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 933 | for(int i = 0; i < numElements; i++) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 934 | { |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 935 | constantVector[i] = llvm::ConstantInt::get(T(type)->getContainedType(0), constants[i % numConstants]); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 936 | } |
| 937 | |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 938 | return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numElements))); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
| 942 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 943 | assert(llvm::isa<llvm::VectorType>(T(type))); |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 944 | const int numConstants = elementCount(type); // Number of provided constants for the (emulated) type. |
| 945 | const int numElements = llvm::cast<llvm::VectorType>(T(type))->getNumElements(); // Number of elements of the underlying vector type. |
| 946 | assert(numElements <= 8 && numConstants <= numElements); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 947 | llvm::Constant *constantVector[8]; |
| 948 | |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 949 | for(int i = 0; i < numElements; i++) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 950 | { |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 951 | constantVector[i] = llvm::ConstantFP::get(T(type)->getContainedType(0), constants[i % numConstants]); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Nicolas Capens | 69674fb | 2017-09-01 11:08:44 -0400 | [diff] [blame] | 954 | return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numElements))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 955 | } |
| 956 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 957 | Type *Void::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 958 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 959 | return T(llvm::Type::getVoidTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 962 | Bool::Bool(Argument<Bool> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 963 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 964 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 965 | } |
| 966 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 967 | Bool::Bool(bool x) |
| 968 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 969 | storeValue(Nucleus::createConstantBool(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 970 | } |
| 971 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 972 | Bool::Bool(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 973 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 974 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | Bool::Bool(const Bool &rhs) |
| 978 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 979 | Value *value = rhs.loadValue(); |
| 980 | storeValue(value); |
| 981 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 982 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 983 | Bool::Bool(const Reference<Bool> &rhs) |
| 984 | { |
| 985 | Value *value = rhs.loadValue(); |
| 986 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 989 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 990 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 991 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 992 | |
| 993 | return rhs; |
| 994 | } |
| 995 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 996 | RValue<Bool> Bool::operator=(const Bool &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 997 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 998 | Value *value = rhs.loadValue(); |
| 999 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1000 | |
| 1001 | return RValue<Bool>(value); |
| 1002 | } |
| 1003 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1004 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1005 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1006 | Value *value = rhs.loadValue(); |
| 1007 | storeValue(value); |
| 1008 | |
| 1009 | return RValue<Bool>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1012 | RValue<Bool> operator!(RValue<Bool> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1013 | { |
| 1014 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1015 | } |
| 1016 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1017 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1018 | { |
| 1019 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1020 | } |
| 1021 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1022 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1023 | { |
| 1024 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1025 | } |
| 1026 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1027 | Type *Bool::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1028 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1029 | return T(llvm::Type::getInt1Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1032 | Byte::Byte(Argument<Byte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1033 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1034 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1037 | Byte::Byte(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1038 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1039 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1040 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1041 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1044 | Byte::Byte(RValue<UInt> cast) |
| 1045 | { |
| 1046 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1047 | |
| 1048 | storeValue(integer); |
| 1049 | } |
| 1050 | |
| 1051 | Byte::Byte(RValue<UShort> cast) |
| 1052 | { |
| 1053 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1054 | |
| 1055 | storeValue(integer); |
| 1056 | } |
| 1057 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1058 | Byte::Byte(int x) |
| 1059 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1060 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | Byte::Byte(unsigned char x) |
| 1064 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1065 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1068 | Byte::Byte(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1069 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1070 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | Byte::Byte(const Byte &rhs) |
| 1074 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1075 | Value *value = rhs.loadValue(); |
| 1076 | storeValue(value); |
| 1077 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1078 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1079 | Byte::Byte(const Reference<Byte> &rhs) |
| 1080 | { |
| 1081 | Value *value = rhs.loadValue(); |
| 1082 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1085 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1086 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1087 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1088 | |
| 1089 | return rhs; |
| 1090 | } |
| 1091 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 1092 | RValue<Byte> Byte::operator=(const Byte &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1093 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1094 | Value *value = rhs.loadValue(); |
| 1095 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1096 | |
| 1097 | return RValue<Byte>(value); |
| 1098 | } |
| 1099 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1100 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1101 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1102 | Value *value = rhs.loadValue(); |
| 1103 | storeValue(value); |
| 1104 | |
| 1105 | return RValue<Byte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1108 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1109 | { |
| 1110 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1111 | } |
| 1112 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1113 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1114 | { |
| 1115 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1116 | } |
| 1117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1118 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1119 | { |
| 1120 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1121 | } |
| 1122 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1123 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1124 | { |
| 1125 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1126 | } |
| 1127 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1128 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1129 | { |
| 1130 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1131 | } |
| 1132 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1133 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1134 | { |
| 1135 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1136 | } |
| 1137 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1138 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1139 | { |
| 1140 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1141 | } |
| 1142 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1143 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1144 | { |
| 1145 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1146 | } |
| 1147 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1148 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1149 | { |
| 1150 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1151 | } |
| 1152 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1153 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1154 | { |
| 1155 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1156 | } |
| 1157 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1158 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1159 | { |
| 1160 | return lhs = lhs + rhs; |
| 1161 | } |
| 1162 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1163 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1164 | { |
| 1165 | return lhs = lhs - rhs; |
| 1166 | } |
| 1167 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1168 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1169 | { |
| 1170 | return lhs = lhs * rhs; |
| 1171 | } |
| 1172 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1173 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1174 | { |
| 1175 | return lhs = lhs / rhs; |
| 1176 | } |
| 1177 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1178 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1179 | { |
| 1180 | return lhs = lhs % rhs; |
| 1181 | } |
| 1182 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1183 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1184 | { |
| 1185 | return lhs = lhs & rhs; |
| 1186 | } |
| 1187 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1188 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1189 | { |
| 1190 | return lhs = lhs | rhs; |
| 1191 | } |
| 1192 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1193 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1194 | { |
| 1195 | return lhs = lhs ^ rhs; |
| 1196 | } |
| 1197 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1198 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1199 | { |
| 1200 | return lhs = lhs << rhs; |
| 1201 | } |
| 1202 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1203 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1204 | { |
| 1205 | return lhs = lhs >> rhs; |
| 1206 | } |
| 1207 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1208 | RValue<Byte> operator+(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1209 | { |
| 1210 | return val; |
| 1211 | } |
| 1212 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1213 | RValue<Byte> operator-(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1214 | { |
| 1215 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1216 | } |
| 1217 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1218 | RValue<Byte> operator~(RValue<Byte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1219 | { |
| 1220 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1221 | } |
| 1222 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1223 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1224 | { |
| 1225 | RValue<Byte> res = val; |
| 1226 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1227 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1228 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1229 | |
| 1230 | return res; |
| 1231 | } |
| 1232 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1233 | const Byte &operator++(Byte &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1234 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1235 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1236 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1237 | |
| 1238 | return val; |
| 1239 | } |
| 1240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1241 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1242 | { |
| 1243 | RValue<Byte> res = val; |
| 1244 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1245 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1246 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1247 | |
| 1248 | return res; |
| 1249 | } |
| 1250 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1251 | const Byte &operator--(Byte &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1252 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1253 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((unsigned char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1254 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1255 | |
| 1256 | return val; |
| 1257 | } |
| 1258 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1259 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1260 | { |
| 1261 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1262 | } |
| 1263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1264 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1265 | { |
| 1266 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1267 | } |
| 1268 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1269 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1270 | { |
| 1271 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1272 | } |
| 1273 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1274 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1275 | { |
| 1276 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1277 | } |
| 1278 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1279 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1280 | { |
| 1281 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1282 | } |
| 1283 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1284 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1285 | { |
| 1286 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1287 | } |
| 1288 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1289 | Type *Byte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1290 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1291 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1292 | } |
| 1293 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1294 | SByte::SByte(Argument<SByte> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1295 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1296 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1299 | SByte::SByte(RValue<Int> cast) |
| 1300 | { |
| 1301 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1302 | |
| 1303 | storeValue(integer); |
| 1304 | } |
| 1305 | |
| 1306 | SByte::SByte(RValue<Short> cast) |
| 1307 | { |
| 1308 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1309 | |
| 1310 | storeValue(integer); |
| 1311 | } |
| 1312 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1313 | SByte::SByte(signed char x) |
| 1314 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1315 | storeValue(Nucleus::createConstantByte(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1316 | } |
| 1317 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1318 | SByte::SByte(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1319 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1320 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | SByte::SByte(const SByte &rhs) |
| 1324 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1325 | Value *value = rhs.loadValue(); |
| 1326 | storeValue(value); |
| 1327 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1328 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1329 | SByte::SByte(const Reference<SByte> &rhs) |
| 1330 | { |
| 1331 | Value *value = rhs.loadValue(); |
| 1332 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1333 | } |
| 1334 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1335 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1336 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1337 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1338 | |
| 1339 | return rhs; |
| 1340 | } |
| 1341 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1342 | RValue<SByte> SByte::operator=(const SByte &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1343 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1344 | Value *value = rhs.loadValue(); |
| 1345 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1346 | |
| 1347 | return RValue<SByte>(value); |
| 1348 | } |
| 1349 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1350 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1351 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1352 | Value *value = rhs.loadValue(); |
| 1353 | storeValue(value); |
| 1354 | |
| 1355 | return RValue<SByte>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1356 | } |
| 1357 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1358 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1359 | { |
| 1360 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1361 | } |
| 1362 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1363 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1364 | { |
| 1365 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1366 | } |
| 1367 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1368 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1369 | { |
| 1370 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1371 | } |
| 1372 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1373 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1374 | { |
| 1375 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1376 | } |
| 1377 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1378 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1379 | { |
| 1380 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1381 | } |
| 1382 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1383 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1384 | { |
| 1385 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1386 | } |
| 1387 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1388 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1389 | { |
| 1390 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1391 | } |
| 1392 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1393 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1394 | { |
| 1395 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1396 | } |
| 1397 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1398 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1399 | { |
| 1400 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1401 | } |
| 1402 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1403 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1404 | { |
| 1405 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1406 | } |
| 1407 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1408 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1409 | { |
| 1410 | return lhs = lhs + rhs; |
| 1411 | } |
| 1412 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1413 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1414 | { |
| 1415 | return lhs = lhs - rhs; |
| 1416 | } |
| 1417 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1418 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1419 | { |
| 1420 | return lhs = lhs * rhs; |
| 1421 | } |
| 1422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1423 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1424 | { |
| 1425 | return lhs = lhs / rhs; |
| 1426 | } |
| 1427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1428 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1429 | { |
| 1430 | return lhs = lhs % rhs; |
| 1431 | } |
| 1432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1433 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1434 | { |
| 1435 | return lhs = lhs & rhs; |
| 1436 | } |
| 1437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1438 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1439 | { |
| 1440 | return lhs = lhs | rhs; |
| 1441 | } |
| 1442 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1443 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1444 | { |
| 1445 | return lhs = lhs ^ rhs; |
| 1446 | } |
| 1447 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1448 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1449 | { |
| 1450 | return lhs = lhs << rhs; |
| 1451 | } |
| 1452 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1453 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1454 | { |
| 1455 | return lhs = lhs >> rhs; |
| 1456 | } |
| 1457 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1458 | RValue<SByte> operator+(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1459 | { |
| 1460 | return val; |
| 1461 | } |
| 1462 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1463 | RValue<SByte> operator-(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1464 | { |
| 1465 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1466 | } |
| 1467 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1468 | RValue<SByte> operator~(RValue<SByte> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1469 | { |
| 1470 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1471 | } |
| 1472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1473 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1474 | { |
| 1475 | RValue<SByte> res = val; |
| 1476 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1477 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1478 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1479 | |
| 1480 | return res; |
| 1481 | } |
| 1482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1483 | const SByte &operator++(SByte &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1484 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1485 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1486 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1487 | |
| 1488 | return val; |
| 1489 | } |
| 1490 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1491 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1492 | { |
| 1493 | RValue<SByte> res = val; |
| 1494 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1495 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1496 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1497 | |
| 1498 | return res; |
| 1499 | } |
| 1500 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1501 | const SByte &operator--(SByte &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1502 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1503 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantByte((signed char)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1504 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1505 | |
| 1506 | return val; |
| 1507 | } |
| 1508 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1509 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1510 | { |
| 1511 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1512 | } |
| 1513 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1514 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1515 | { |
| 1516 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1517 | } |
| 1518 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1519 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1520 | { |
| 1521 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1522 | } |
| 1523 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1524 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1525 | { |
| 1526 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1527 | } |
| 1528 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1529 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1530 | { |
| 1531 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1532 | } |
| 1533 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1534 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1535 | { |
| 1536 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1537 | } |
| 1538 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1539 | Type *SByte::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1540 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1541 | return T(llvm::Type::getInt8Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1542 | } |
| 1543 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1544 | Short::Short(Argument<Short> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1545 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1546 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1547 | } |
| 1548 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1549 | Short::Short(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1550 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1551 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1552 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1553 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1554 | } |
| 1555 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1556 | Short::Short(short x) |
| 1557 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1558 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1559 | } |
| 1560 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1561 | Short::Short(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1562 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1563 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | Short::Short(const Short &rhs) |
| 1567 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1568 | Value *value = rhs.loadValue(); |
| 1569 | storeValue(value); |
| 1570 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1571 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1572 | Short::Short(const Reference<Short> &rhs) |
| 1573 | { |
| 1574 | Value *value = rhs.loadValue(); |
| 1575 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1576 | } |
| 1577 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1578 | RValue<Short> Short::operator=(RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1579 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1580 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1581 | |
| 1582 | return rhs; |
| 1583 | } |
| 1584 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1585 | RValue<Short> Short::operator=(const Short &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1586 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1587 | Value *value = rhs.loadValue(); |
| 1588 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1589 | |
| 1590 | return RValue<Short>(value); |
| 1591 | } |
| 1592 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1593 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1594 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1595 | Value *value = rhs.loadValue(); |
| 1596 | storeValue(value); |
| 1597 | |
| 1598 | return RValue<Short>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1601 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1602 | { |
| 1603 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1604 | } |
| 1605 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1606 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1607 | { |
| 1608 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1609 | } |
| 1610 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1611 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1612 | { |
| 1613 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1614 | } |
| 1615 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1616 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1617 | { |
| 1618 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1619 | } |
| 1620 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1621 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1622 | { |
| 1623 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1624 | } |
| 1625 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1626 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1627 | { |
| 1628 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1629 | } |
| 1630 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1631 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1632 | { |
| 1633 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1634 | } |
| 1635 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1636 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1637 | { |
| 1638 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1639 | } |
| 1640 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1641 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1642 | { |
| 1643 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1644 | } |
| 1645 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1646 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1647 | { |
| 1648 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1649 | } |
| 1650 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1651 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1652 | { |
| 1653 | return lhs = lhs + rhs; |
| 1654 | } |
| 1655 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1656 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1657 | { |
| 1658 | return lhs = lhs - rhs; |
| 1659 | } |
| 1660 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1661 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1662 | { |
| 1663 | return lhs = lhs * rhs; |
| 1664 | } |
| 1665 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1666 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1667 | { |
| 1668 | return lhs = lhs / rhs; |
| 1669 | } |
| 1670 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1671 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1672 | { |
| 1673 | return lhs = lhs % rhs; |
| 1674 | } |
| 1675 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1676 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1677 | { |
| 1678 | return lhs = lhs & rhs; |
| 1679 | } |
| 1680 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1681 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1682 | { |
| 1683 | return lhs = lhs | rhs; |
| 1684 | } |
| 1685 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1686 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1687 | { |
| 1688 | return lhs = lhs ^ rhs; |
| 1689 | } |
| 1690 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1691 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1692 | { |
| 1693 | return lhs = lhs << rhs; |
| 1694 | } |
| 1695 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1696 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1697 | { |
| 1698 | return lhs = lhs >> rhs; |
| 1699 | } |
| 1700 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1701 | RValue<Short> operator+(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1702 | { |
| 1703 | return val; |
| 1704 | } |
| 1705 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1706 | RValue<Short> operator-(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1707 | { |
| 1708 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 1709 | } |
| 1710 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1711 | RValue<Short> operator~(RValue<Short> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1712 | { |
| 1713 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 1714 | } |
| 1715 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1716 | RValue<Short> operator++(Short &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1717 | { |
| 1718 | RValue<Short> res = val; |
| 1719 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1720 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1721 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | |
| 1723 | return res; |
| 1724 | } |
| 1725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1726 | const Short &operator++(Short &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1727 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1728 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1729 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1730 | |
| 1731 | return val; |
| 1732 | } |
| 1733 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1734 | RValue<Short> operator--(Short &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1735 | { |
| 1736 | RValue<Short> res = val; |
| 1737 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1738 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1739 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1740 | |
| 1741 | return res; |
| 1742 | } |
| 1743 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1744 | const Short &operator--(Short &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1745 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1746 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1747 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1748 | |
| 1749 | return val; |
| 1750 | } |
| 1751 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1752 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1753 | { |
| 1754 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1755 | } |
| 1756 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1757 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1758 | { |
| 1759 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1760 | } |
| 1761 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1762 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1763 | { |
| 1764 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1765 | } |
| 1766 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1767 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1768 | { |
| 1769 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1770 | } |
| 1771 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1772 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1773 | { |
| 1774 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1775 | } |
| 1776 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1777 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1778 | { |
| 1779 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1780 | } |
| 1781 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1782 | Type *Short::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1783 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 1784 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1785 | } |
| 1786 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1787 | UShort::UShort(Argument<UShort> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1788 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 1789 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
Alexis Hetu | 77dfab4 | 2015-11-23 13:31:22 -0500 | [diff] [blame] | 1792 | UShort::UShort(RValue<UInt> cast) |
| 1793 | { |
| 1794 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1795 | |
| 1796 | storeValue(integer); |
| 1797 | } |
| 1798 | |
Alexis Hetu | 75b650f | 2015-11-19 17:40:15 -0500 | [diff] [blame] | 1799 | UShort::UShort(RValue<Int> cast) |
| 1800 | { |
| 1801 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 1802 | |
| 1803 | storeValue(integer); |
| 1804 | } |
| 1805 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1806 | UShort::UShort(unsigned short x) |
| 1807 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1808 | storeValue(Nucleus::createConstantShort(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1809 | } |
| 1810 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1811 | UShort::UShort(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1812 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1813 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | UShort::UShort(const UShort &rhs) |
| 1817 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1818 | Value *value = rhs.loadValue(); |
| 1819 | storeValue(value); |
| 1820 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1821 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1822 | UShort::UShort(const Reference<UShort> &rhs) |
| 1823 | { |
| 1824 | Value *value = rhs.loadValue(); |
| 1825 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1826 | } |
| 1827 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1828 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1829 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1830 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1831 | |
| 1832 | return rhs; |
| 1833 | } |
| 1834 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1835 | RValue<UShort> UShort::operator=(const UShort &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1836 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1837 | Value *value = rhs.loadValue(); |
| 1838 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1839 | |
| 1840 | return RValue<UShort>(value); |
| 1841 | } |
| 1842 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1843 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1844 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1845 | Value *value = rhs.loadValue(); |
| 1846 | storeValue(value); |
| 1847 | |
| 1848 | return RValue<UShort>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1851 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1852 | { |
| 1853 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1854 | } |
| 1855 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1856 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1857 | { |
| 1858 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1859 | } |
| 1860 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1861 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1862 | { |
| 1863 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1864 | } |
| 1865 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1866 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1867 | { |
| 1868 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1869 | } |
| 1870 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1871 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1872 | { |
| 1873 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1874 | } |
| 1875 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1876 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1877 | { |
| 1878 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1879 | } |
| 1880 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1881 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1882 | { |
| 1883 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1884 | } |
| 1885 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1886 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1887 | { |
| 1888 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1889 | } |
| 1890 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1891 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1892 | { |
| 1893 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1894 | } |
| 1895 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1896 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1897 | { |
| 1898 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1899 | } |
| 1900 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1901 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1902 | { |
| 1903 | return lhs = lhs + rhs; |
| 1904 | } |
| 1905 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1906 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1907 | { |
| 1908 | return lhs = lhs - rhs; |
| 1909 | } |
| 1910 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1911 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1912 | { |
| 1913 | return lhs = lhs * rhs; |
| 1914 | } |
| 1915 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1916 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1917 | { |
| 1918 | return lhs = lhs / rhs; |
| 1919 | } |
| 1920 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1921 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1922 | { |
| 1923 | return lhs = lhs % rhs; |
| 1924 | } |
| 1925 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1926 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1927 | { |
| 1928 | return lhs = lhs & rhs; |
| 1929 | } |
| 1930 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1931 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1932 | { |
| 1933 | return lhs = lhs | rhs; |
| 1934 | } |
| 1935 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1936 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1937 | { |
| 1938 | return lhs = lhs ^ rhs; |
| 1939 | } |
| 1940 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1941 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1942 | { |
| 1943 | return lhs = lhs << rhs; |
| 1944 | } |
| 1945 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1946 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1947 | { |
| 1948 | return lhs = lhs >> rhs; |
| 1949 | } |
| 1950 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1951 | RValue<UShort> operator+(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1952 | { |
| 1953 | return val; |
| 1954 | } |
| 1955 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1956 | RValue<UShort> operator-(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1957 | { |
| 1958 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 1959 | } |
| 1960 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1961 | RValue<UShort> operator~(RValue<UShort> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1962 | { |
| 1963 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 1964 | } |
| 1965 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1966 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1967 | { |
| 1968 | RValue<UShort> res = val; |
| 1969 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1970 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1971 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1972 | |
| 1973 | return res; |
| 1974 | } |
| 1975 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1976 | const UShort &operator++(UShort &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1977 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1978 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1979 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1980 | |
| 1981 | return val; |
| 1982 | } |
| 1983 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1984 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1985 | { |
| 1986 | RValue<UShort> res = val; |
| 1987 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1988 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1989 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1990 | |
| 1991 | return res; |
| 1992 | } |
| 1993 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1994 | const UShort &operator--(UShort &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1995 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1996 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantShort((unsigned short)1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1997 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1998 | |
| 1999 | return val; |
| 2000 | } |
| 2001 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2002 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2003 | { |
| 2004 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2005 | } |
| 2006 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2007 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2008 | { |
| 2009 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2010 | } |
| 2011 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2012 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2013 | { |
| 2014 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2015 | } |
| 2016 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2017 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2018 | { |
| 2019 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2020 | } |
| 2021 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2022 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2023 | { |
| 2024 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2025 | } |
| 2026 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2027 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2028 | { |
| 2029 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2030 | } |
| 2031 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2032 | Type *UShort::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2033 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 2034 | return T(llvm::Type::getInt16Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2035 | } |
| 2036 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2037 | Byte4::Byte4(RValue<Byte8> cast) |
| 2038 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2039 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2043 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2044 | Value *value = rhs.loadValue(); |
| 2045 | storeValue(value); |
| 2046 | } |
| 2047 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2048 | Type *Byte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2049 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2050 | return T(Type_v4i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2053 | Type *SByte4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2054 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2055 | return T(Type_v4i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2056 | } |
| 2057 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 2058 | 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] | 2059 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2060 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2061 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2064 | Byte8::Byte8(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2065 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2066 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | Byte8::Byte8(const Byte8 &rhs) |
| 2070 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2071 | Value *value = rhs.loadValue(); |
| 2072 | storeValue(value); |
| 2073 | } |
| 2074 | |
| 2075 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2076 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2077 | Value *value = rhs.loadValue(); |
| 2078 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2079 | } |
| 2080 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2081 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2082 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2083 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2084 | |
| 2085 | return rhs; |
| 2086 | } |
| 2087 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2088 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2089 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2090 | Value *value = rhs.loadValue(); |
| 2091 | storeValue(value); |
| 2092 | |
| 2093 | return RValue<Byte8>(value); |
| 2094 | } |
| 2095 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2096 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2097 | { |
| 2098 | Value *value = rhs.loadValue(); |
| 2099 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2100 | |
| 2101 | return RValue<Byte8>(value); |
| 2102 | } |
| 2103 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2104 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2105 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2106 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2107 | } |
| 2108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2109 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2110 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2111 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2112 | } |
| 2113 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2114 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2115 | // { |
| 2116 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2117 | // } |
| 2118 | |
| 2119 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2120 | // { |
| 2121 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2122 | // } |
| 2123 | |
| 2124 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2125 | // { |
| 2126 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2127 | // } |
| 2128 | |
| 2129 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2130 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2131 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2132 | } |
| 2133 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2134 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2135 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2136 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2137 | } |
| 2138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2139 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2140 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2141 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2142 | } |
| 2143 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2144 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2145 | // { |
| 2146 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2147 | // } |
| 2148 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2149 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2150 | // { |
| 2151 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2152 | // } |
| 2153 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2154 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2155 | { |
| 2156 | return lhs = lhs + rhs; |
| 2157 | } |
| 2158 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2159 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2160 | { |
| 2161 | return lhs = lhs - rhs; |
| 2162 | } |
| 2163 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2164 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2165 | // { |
| 2166 | // return lhs = lhs * rhs; |
| 2167 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2168 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2169 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2170 | // { |
| 2171 | // return lhs = lhs / rhs; |
| 2172 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2173 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2174 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2175 | // { |
| 2176 | // return lhs = lhs % rhs; |
| 2177 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2178 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2179 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2180 | { |
| 2181 | return lhs = lhs & rhs; |
| 2182 | } |
| 2183 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2184 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2185 | { |
| 2186 | return lhs = lhs | rhs; |
| 2187 | } |
| 2188 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2189 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2190 | { |
| 2191 | return lhs = lhs ^ rhs; |
| 2192 | } |
| 2193 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2194 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2195 | // { |
| 2196 | // return lhs = lhs << rhs; |
| 2197 | // } |
| 2198 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2199 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2200 | // { |
| 2201 | // return lhs = lhs >> rhs; |
| 2202 | // } |
| 2203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2204 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2205 | // { |
| 2206 | // return val; |
| 2207 | // } |
| 2208 | |
| 2209 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2210 | // { |
| 2211 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2212 | // } |
| 2213 | |
| 2214 | RValue<Byte8> operator~(RValue<Byte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2215 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2216 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2217 | } |
| 2218 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2219 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2220 | { |
| 2221 | return x86::paddusb(x, y); |
| 2222 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2223 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2224 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2225 | { |
| 2226 | return x86::psubusb(x, y); |
| 2227 | } |
| 2228 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2229 | RValue<Short4> Unpack(RValue<Byte4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2230 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2231 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2232 | return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2233 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2234 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2235 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2236 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2237 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2240 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2241 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2242 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2243 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2244 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2245 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2246 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2247 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2248 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2249 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2250 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2251 | } |
| 2252 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2253 | RValue<Int> SignMask(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2254 | { |
| 2255 | return x86::pmovmskb(x); |
| 2256 | } |
| 2257 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2258 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2259 | // { |
| 2260 | // return x86::pcmpgtb(x, y); // FIXME: Signedness |
| 2261 | // } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2262 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2263 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2264 | { |
| 2265 | return x86::pcmpeqb(x, y); |
| 2266 | } |
| 2267 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2268 | Type *Byte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2269 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2270 | return T(Type_v8i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2271 | } |
| 2272 | |
Nicolas Capens | 3bbc5e1 | 2016-09-27 10:49:52 -0400 | [diff] [blame] | 2273 | 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] | 2274 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2275 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2276 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2277 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2278 | storeValue(Nucleus::createBitCast(vector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2279 | } |
| 2280 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2281 | SByte8::SByte8(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2282 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2283 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | SByte8::SByte8(const SByte8 &rhs) |
| 2287 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2288 | Value *value = rhs.loadValue(); |
| 2289 | storeValue(value); |
| 2290 | } |
| 2291 | |
| 2292 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2293 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2294 | Value *value = rhs.loadValue(); |
| 2295 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2296 | } |
| 2297 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2298 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2299 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2300 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2301 | |
| 2302 | return rhs; |
| 2303 | } |
| 2304 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2305 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2306 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2307 | Value *value = rhs.loadValue(); |
| 2308 | storeValue(value); |
| 2309 | |
| 2310 | return RValue<SByte8>(value); |
| 2311 | } |
| 2312 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2313 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2314 | { |
| 2315 | Value *value = rhs.loadValue(); |
| 2316 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2317 | |
| 2318 | return RValue<SByte8>(value); |
| 2319 | } |
| 2320 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2321 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2322 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2323 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2324 | } |
| 2325 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2326 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2327 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2328 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2329 | } |
| 2330 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2331 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2332 | // { |
| 2333 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2334 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2335 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2336 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2337 | // { |
| 2338 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2339 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2340 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2341 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2342 | // { |
| 2343 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2344 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2345 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2346 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2347 | { |
| 2348 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2349 | } |
| 2350 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2351 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2352 | { |
| 2353 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2354 | } |
| 2355 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2356 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2357 | { |
| 2358 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2359 | } |
| 2360 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2361 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2362 | // { |
| 2363 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2364 | // } |
| 2365 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2366 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2367 | // { |
| 2368 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2369 | // } |
| 2370 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2371 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2372 | { |
| 2373 | return lhs = lhs + rhs; |
| 2374 | } |
| 2375 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2376 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2377 | { |
| 2378 | return lhs = lhs - rhs; |
| 2379 | } |
| 2380 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2381 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2382 | // { |
| 2383 | // return lhs = lhs * rhs; |
| 2384 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2385 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2386 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2387 | // { |
| 2388 | // return lhs = lhs / rhs; |
| 2389 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2390 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2391 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2392 | // { |
| 2393 | // return lhs = lhs % rhs; |
| 2394 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2395 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2396 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2397 | { |
| 2398 | return lhs = lhs & rhs; |
| 2399 | } |
| 2400 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2401 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2402 | { |
| 2403 | return lhs = lhs | rhs; |
| 2404 | } |
| 2405 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2406 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2407 | { |
| 2408 | return lhs = lhs ^ rhs; |
| 2409 | } |
| 2410 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2411 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2412 | // { |
| 2413 | // return lhs = lhs << rhs; |
| 2414 | // } |
| 2415 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2416 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2417 | // { |
| 2418 | // return lhs = lhs >> rhs; |
| 2419 | // } |
| 2420 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2421 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2422 | // { |
| 2423 | // return val; |
| 2424 | // } |
| 2425 | |
| 2426 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2427 | // { |
| 2428 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2429 | // } |
| 2430 | |
| 2431 | RValue<SByte8> operator~(RValue<SByte8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2432 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2433 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2434 | } |
| 2435 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2436 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2437 | { |
| 2438 | return x86::paddsb(x, y); |
| 2439 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2440 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2441 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2442 | { |
| 2443 | return x86::psubsb(x, y); |
| 2444 | } |
| 2445 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2446 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2447 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2448 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2449 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2450 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2451 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2452 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2453 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2454 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2455 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2456 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2457 | } |
| 2458 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2459 | RValue<Int> SignMask(RValue<SByte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2460 | { |
| 2461 | return x86::pmovmskb(As<Byte8>(x)); |
| 2462 | } |
| 2463 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2464 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2465 | { |
| 2466 | return x86::pcmpgtb(x, y); |
| 2467 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2468 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2469 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2470 | { |
| 2471 | return x86::pcmpeqb(As<Byte8>(x), As<Byte8>(y)); |
| 2472 | } |
| 2473 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2474 | Type *SByte8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2475 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2476 | return T(Type_v8i8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2477 | } |
| 2478 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2479 | Byte16::Byte16(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2480 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2481 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | Byte16::Byte16(const Byte16 &rhs) |
| 2485 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2486 | Value *value = rhs.loadValue(); |
| 2487 | storeValue(value); |
| 2488 | } |
| 2489 | |
| 2490 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2491 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2492 | Value *value = rhs.loadValue(); |
| 2493 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2494 | } |
| 2495 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2496 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2497 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2498 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2499 | |
| 2500 | return rhs; |
| 2501 | } |
| 2502 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2503 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2504 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2505 | Value *value = rhs.loadValue(); |
| 2506 | storeValue(value); |
| 2507 | |
| 2508 | return RValue<Byte16>(value); |
| 2509 | } |
| 2510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2511 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2512 | { |
| 2513 | Value *value = rhs.loadValue(); |
| 2514 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2515 | |
| 2516 | return RValue<Byte16>(value); |
| 2517 | } |
| 2518 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2519 | Type *Byte16::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(Byte::getType()), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2522 | } |
| 2523 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2524 | Type *SByte16::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2525 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2526 | return T(llvm::VectorType::get(T(SByte::getType()), 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2527 | } |
| 2528 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2529 | Short2::Short2(RValue<Short4> cast) |
| 2530 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2531 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | Type *Short2::getType() |
| 2535 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2536 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | UShort2::UShort2(RValue<UShort4> cast) |
| 2540 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2541 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | Type *UShort2::getType() |
| 2545 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2546 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2549 | Short4::Short4(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2550 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2551 | Value *vector = loadValue(); |
| 2552 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2553 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
| 2554 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2555 | |
| 2556 | storeValue(swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2557 | } |
| 2558 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2559 | Short4::Short4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2560 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2561 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2562 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 2563 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2564 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
| 2565 | Value *short4 = As<Short4>(Int2(As<Int4>(packed))).value; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2566 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2567 | storeValue(short4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2568 | } |
| 2569 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2570 | // Short4::Short4(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2571 | // { |
| 2572 | // } |
| 2573 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2574 | Short4::Short4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2575 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2576 | Int4 v4i32 = Int4(cast); |
| 2577 | v4i32 = As<Int4>(x86::packssdw(v4i32, v4i32)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2578 | |
| 2579 | storeValue(As<Short4>(Int2(v4i32)).value); |
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(short xyzw) |
| 2583 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2584 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2585 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2586 | } |
| 2587 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2588 | Short4::Short4(short x, short y, short z, short w) |
| 2589 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2590 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2591 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
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(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2595 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2596 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | Short4::Short4(const Short4 &rhs) |
| 2600 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2601 | Value *value = rhs.loadValue(); |
| 2602 | storeValue(value); |
| 2603 | } |
| 2604 | |
| 2605 | Short4::Short4(const Reference<Short4> &rhs) |
| 2606 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2607 | Value *value = rhs.loadValue(); |
| 2608 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2609 | } |
| 2610 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2611 | Short4::Short4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2612 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2613 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | Short4::Short4(const UShort4 &rhs) |
| 2617 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2618 | storeValue(rhs.loadValue()); |
| 2619 | } |
| 2620 | |
| 2621 | Short4::Short4(const Reference<UShort4> &rhs) |
| 2622 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2623 | storeValue(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2624 | } |
| 2625 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2626 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2627 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2628 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2629 | |
| 2630 | return rhs; |
| 2631 | } |
| 2632 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2633 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2634 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2635 | Value *value = rhs.loadValue(); |
| 2636 | storeValue(value); |
| 2637 | |
| 2638 | return RValue<Short4>(value); |
| 2639 | } |
| 2640 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2641 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2642 | { |
| 2643 | Value *value = rhs.loadValue(); |
| 2644 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2645 | |
| 2646 | return RValue<Short4>(value); |
| 2647 | } |
| 2648 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2649 | RValue<Short4> Short4::operator=(RValue<UShort4> 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 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2652 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2653 | return RValue<Short4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2654 | } |
| 2655 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2656 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2657 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2658 | Value *value = rhs.loadValue(); |
| 2659 | storeValue(value); |
| 2660 | |
| 2661 | return RValue<Short4>(value); |
| 2662 | } |
| 2663 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2664 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2665 | { |
| 2666 | Value *value = rhs.loadValue(); |
| 2667 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2668 | |
| 2669 | return RValue<Short4>(value); |
| 2670 | } |
| 2671 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2672 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2673 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2674 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2675 | } |
| 2676 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2677 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2678 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2679 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2680 | } |
| 2681 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2682 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2683 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2684 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2685 | } |
| 2686 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2687 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2688 | // { |
| 2689 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2690 | // } |
| 2691 | |
| 2692 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 2693 | // { |
| 2694 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2695 | // } |
| 2696 | |
| 2697 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2698 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2699 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2700 | } |
| 2701 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2702 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2703 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2704 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2705 | } |
| 2706 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2707 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2708 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2709 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
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, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2713 | { |
| 2714 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2715 | |
| 2716 | return x86::psllw(lhs, rhs); |
| 2717 | } |
| 2718 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2719 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2720 | { |
| 2721 | // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2722 | |
| 2723 | return x86::psraw(lhs, rhs); |
| 2724 | } |
| 2725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2726 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2727 | { |
| 2728 | return lhs = lhs + rhs; |
| 2729 | } |
| 2730 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2731 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2732 | { |
| 2733 | return lhs = lhs - rhs; |
| 2734 | } |
| 2735 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2736 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2737 | { |
| 2738 | return lhs = lhs * rhs; |
| 2739 | } |
| 2740 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2741 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2742 | // { |
| 2743 | // return lhs = lhs / rhs; |
| 2744 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2746 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2747 | // { |
| 2748 | // return lhs = lhs % rhs; |
| 2749 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2751 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2752 | { |
| 2753 | return lhs = lhs & rhs; |
| 2754 | } |
| 2755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2756 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2757 | { |
| 2758 | return lhs = lhs | rhs; |
| 2759 | } |
| 2760 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2761 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2762 | { |
| 2763 | return lhs = lhs ^ rhs; |
| 2764 | } |
| 2765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2766 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2767 | { |
| 2768 | return lhs = lhs << rhs; |
| 2769 | } |
| 2770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2771 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2772 | { |
| 2773 | return lhs = lhs >> rhs; |
| 2774 | } |
| 2775 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2776 | // RValue<Short4> operator+(RValue<Short4> val) |
| 2777 | // { |
| 2778 | // return val; |
| 2779 | // } |
| 2780 | |
| 2781 | RValue<Short4> operator-(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2782 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2783 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2784 | } |
| 2785 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2786 | RValue<Short4> operator~(RValue<Short4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2787 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2788 | return RValue<Short4>(Nucleus::createNot(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2789 | } |
| 2790 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2791 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2792 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2793 | RValue<Int4> int4 = RoundInt(cast); |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2794 | return As<Short4>(PackSigned(int4, int4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2795 | } |
| 2796 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2797 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2798 | { |
| 2799 | return x86::pmaxsw(x, y); |
| 2800 | } |
| 2801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2802 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2803 | { |
| 2804 | return x86::pminsw(x, y); |
| 2805 | } |
| 2806 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2807 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2808 | { |
| 2809 | return x86::paddsw(x, y); |
| 2810 | } |
| 2811 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2812 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2813 | { |
| 2814 | return x86::psubsw(x, y); |
| 2815 | } |
| 2816 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2817 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2818 | { |
| 2819 | return x86::pmulhw(x, y); |
| 2820 | } |
| 2821 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2822 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2823 | { |
| 2824 | return x86::pmaddwd(x, y); |
| 2825 | } |
| 2826 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2827 | RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2828 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2829 | auto result = x86::packsswb(x, y); |
| 2830 | |
| 2831 | return As<SByte8>(Swizzle(As<Int4>(result), 0x88)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2834 | RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y) |
| 2835 | { |
| 2836 | auto result = x86::packuswb(x, y); |
| 2837 | |
| 2838 | return As<Byte8>(Swizzle(As<Int4>(result), 0x88)); |
| 2839 | } |
| 2840 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2841 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2842 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2843 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 2844 | return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2845 | } |
| 2846 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2847 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2848 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2849 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 2850 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2851 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2854 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2855 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2856 | // Real type is v8i16 |
| 2857 | int shuffle[8] = |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2858 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2859 | (select >> 0) & 0x03, |
| 2860 | (select >> 2) & 0x03, |
| 2861 | (select >> 4) & 0x03, |
| 2862 | (select >> 6) & 0x03, |
| 2863 | (select >> 0) & 0x03, |
| 2864 | (select >> 2) & 0x03, |
| 2865 | (select >> 4) & 0x03, |
| 2866 | (select >> 6) & 0x03, |
| 2867 | }; |
| 2868 | |
| 2869 | return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2870 | } |
| 2871 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2872 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2873 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2874 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2875 | } |
| 2876 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2877 | RValue<Short> Extract(RValue<Short4> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2878 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2879 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2880 | } |
| 2881 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2882 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2883 | { |
| 2884 | return x86::pcmpgtw(x, y); |
| 2885 | } |
| 2886 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2887 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2888 | { |
| 2889 | return x86::pcmpeqw(x, y); |
| 2890 | } |
| 2891 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2892 | Type *Short4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2893 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 2894 | return T(Type_v4i16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2895 | } |
| 2896 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2897 | UShort4::UShort4(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2898 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2899 | *this = Short4(cast); |
| 2900 | } |
| 2901 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2902 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2903 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2904 | if(saturate) |
| 2905 | { |
| 2906 | if(CPUID::supportsSSE4_1()) |
| 2907 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2908 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2909 | *this = As<Short4>(PackUnsigned(int4, int4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2910 | } |
| 2911 | else |
| 2912 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2913 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | else |
| 2917 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2918 | *this = Short4(Int4(cast)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 2922 | UShort4::UShort4(unsigned short xyzw) |
| 2923 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2924 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2925 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Alexis Hetu | 90c7ad6 | 2016-06-27 11:50:40 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2928 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 2929 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 2930 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 2931 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2932 | } |
| 2933 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2934 | UShort4::UShort4(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2935 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2936 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | UShort4::UShort4(const UShort4 &rhs) |
| 2940 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2941 | Value *value = rhs.loadValue(); |
| 2942 | storeValue(value); |
| 2943 | } |
| 2944 | |
| 2945 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 2946 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2947 | Value *value = rhs.loadValue(); |
| 2948 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2949 | } |
| 2950 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2951 | UShort4::UShort4(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2952 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2953 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | UShort4::UShort4(const Short4 &rhs) |
| 2957 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2958 | Value *value = rhs.loadValue(); |
| 2959 | storeValue(value); |
| 2960 | } |
| 2961 | |
| 2962 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 2963 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2964 | Value *value = rhs.loadValue(); |
| 2965 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2966 | } |
| 2967 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2968 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2969 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2970 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2971 | |
| 2972 | return rhs; |
| 2973 | } |
| 2974 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2975 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2976 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2977 | Value *value = rhs.loadValue(); |
| 2978 | storeValue(value); |
| 2979 | |
| 2980 | return RValue<UShort4>(value); |
| 2981 | } |
| 2982 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2983 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2984 | { |
| 2985 | Value *value = rhs.loadValue(); |
| 2986 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2987 | |
| 2988 | return RValue<UShort4>(value); |
| 2989 | } |
| 2990 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2991 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2992 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2993 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2994 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2995 | return RValue<UShort4>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2996 | } |
| 2997 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2998 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2999 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3000 | Value *value = rhs.loadValue(); |
| 3001 | storeValue(value); |
| 3002 | |
| 3003 | return RValue<UShort4>(value); |
| 3004 | } |
| 3005 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3006 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3007 | { |
| 3008 | Value *value = rhs.loadValue(); |
| 3009 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3010 | |
| 3011 | return RValue<UShort4>(value); |
| 3012 | } |
| 3013 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3014 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3015 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3016 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3017 | } |
| 3018 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3019 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3020 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3021 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3022 | } |
| 3023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3024 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3025 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3026 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3027 | } |
| 3028 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3029 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3030 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3031 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3035 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3036 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3040 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3041 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3042 | } |
| 3043 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3044 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3045 | { |
| 3046 | // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3047 | |
| 3048 | return As<UShort4>(x86::psllw(As<Short4>(lhs), rhs)); |
| 3049 | } |
| 3050 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3051 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3052 | { |
| 3053 | // return RValue<Short4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 3054 | |
| 3055 | return x86::psrlw(lhs, rhs); |
| 3056 | } |
| 3057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3058 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3059 | { |
| 3060 | return lhs = lhs << rhs; |
| 3061 | } |
| 3062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3063 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3064 | { |
| 3065 | return lhs = lhs >> rhs; |
| 3066 | } |
| 3067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3068 | RValue<UShort4> operator~(RValue<UShort4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3069 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3070 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3071 | } |
| 3072 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3073 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3074 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3075 | 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] | 3076 | } |
| 3077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3078 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3079 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3080 | 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] | 3081 | } |
| 3082 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3083 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3084 | { |
| 3085 | return x86::paddusw(x, y); |
| 3086 | } |
| 3087 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3088 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3089 | { |
| 3090 | return x86::psubusw(x, y); |
| 3091 | } |
| 3092 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3093 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3094 | { |
| 3095 | return x86::pmulhuw(x, y); |
| 3096 | } |
| 3097 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3098 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3099 | { |
| 3100 | return x86::pavgw(x, y); |
| 3101 | } |
| 3102 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3103 | Type *UShort4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3104 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3105 | return T(Type_v4i16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3106 | } |
| 3107 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3108 | Short8::Short8(short c) |
| 3109 | { |
| 3110 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3111 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3112 | } |
| 3113 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3114 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3115 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3116 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3117 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3118 | } |
| 3119 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3120 | Short8::Short8(RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3121 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3122 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3123 | } |
| 3124 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3125 | Short8::Short8(const Reference<Short8> &rhs) |
| 3126 | { |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3127 | Value *value = rhs.loadValue(); |
| 3128 | storeValue(value); |
| 3129 | } |
| 3130 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3131 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3132 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3133 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3134 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3135 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3136 | storeValue(packed); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3137 | } |
| 3138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3139 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3140 | { |
| 3141 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3142 | } |
| 3143 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3144 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3145 | { |
| 3146 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3147 | } |
| 3148 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3149 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3150 | { |
| 3151 | return x86::psllw(lhs, rhs); // FIXME: Fallback required |
| 3152 | } |
| 3153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3154 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3155 | { |
| 3156 | return x86::psraw(lhs, rhs); // FIXME: Fallback required |
| 3157 | } |
| 3158 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3159 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3160 | { |
| 3161 | return x86::pmaddwd(x, y); // FIXME: Fallback required |
| 3162 | } |
| 3163 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 3164 | RValue<Int4> Abs(RValue<Int4> x) |
| 3165 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3166 | auto negative = x >> 31; |
| 3167 | return (x ^ negative) - negative; |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 3168 | } |
| 3169 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3170 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3171 | { |
| 3172 | return x86::pmulhw(x, y); // FIXME: Fallback required |
| 3173 | } |
| 3174 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3175 | Type *Short8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3176 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3177 | return T(llvm::VectorType::get(T(Short::getType()), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3178 | } |
| 3179 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3180 | UShort8::UShort8(unsigned short c) |
| 3181 | { |
| 3182 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3183 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3184 | } |
| 3185 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3186 | 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) |
| 3187 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3188 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3189 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3190 | } |
| 3191 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3192 | UShort8::UShort8(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3193 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3194 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3195 | } |
| 3196 | |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3197 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3198 | { |
Nicolas Capens | ef8cd66 | 2016-06-30 15:34:40 -0400 | [diff] [blame] | 3199 | Value *value = rhs.loadValue(); |
| 3200 | storeValue(value); |
| 3201 | } |
| 3202 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3203 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3204 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3205 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3206 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3207 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 3208 | storeValue(packed); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 3209 | } |
| 3210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3211 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3212 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3213 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3214 | |
| 3215 | return rhs; |
| 3216 | } |
| 3217 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3218 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3219 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3220 | Value *value = rhs.loadValue(); |
| 3221 | storeValue(value); |
| 3222 | |
| 3223 | return RValue<UShort8>(value); |
| 3224 | } |
| 3225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3226 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3227 | { |
| 3228 | Value *value = rhs.loadValue(); |
| 3229 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3230 | |
| 3231 | return RValue<UShort8>(value); |
| 3232 | } |
| 3233 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3234 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3235 | { |
| 3236 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3237 | } |
| 3238 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3239 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3240 | { |
| 3241 | return As<UShort8>(x86::psllw(As<Short8>(lhs), rhs)); // FIXME: Fallback required |
| 3242 | } |
| 3243 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3244 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3245 | { |
| 3246 | return x86::psrlw(lhs, rhs); // FIXME: Fallback required |
| 3247 | } |
| 3248 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3249 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3250 | { |
| 3251 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3252 | } |
| 3253 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3254 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3255 | { |
| 3256 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3257 | } |
| 3258 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3259 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3260 | { |
| 3261 | return lhs = lhs + rhs; |
| 3262 | } |
| 3263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3264 | RValue<UShort8> operator~(RValue<UShort8> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3265 | { |
| 3266 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3267 | } |
| 3268 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3269 | 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] | 3270 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 3271 | int pshufb[16] = |
| 3272 | { |
| 3273 | select0 + 0, |
| 3274 | select0 + 1, |
| 3275 | select1 + 0, |
| 3276 | select1 + 1, |
| 3277 | select2 + 0, |
| 3278 | select2 + 1, |
| 3279 | select3 + 0, |
| 3280 | select3 + 1, |
| 3281 | select4 + 0, |
| 3282 | select4 + 1, |
| 3283 | select5 + 0, |
| 3284 | select5 + 1, |
| 3285 | select6 + 0, |
| 3286 | select6 + 1, |
| 3287 | select7 + 0, |
| 3288 | select7 + 1, |
| 3289 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3290 | |
| 3291 | Value *byte16 = Nucleus::createBitCast(x.value, Byte16::getType()); |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 3292 | Value *shuffle = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3293 | Value *short8 = Nucleus::createBitCast(shuffle, UShort8::getType()); |
| 3294 | |
| 3295 | return RValue<UShort8>(short8); |
| 3296 | } |
| 3297 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3298 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3299 | { |
| 3300 | return x86::pmulhuw(x, y); // FIXME: Fallback required |
| 3301 | } |
| 3302 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3303 | Type *UShort8::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3304 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 3305 | return T(llvm::VectorType::get(T(UShort::getType()), 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3306 | } |
| 3307 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3308 | Int::Int(Argument<Int> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3309 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3310 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3311 | } |
| 3312 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3313 | Int::Int(RValue<Byte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3314 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3315 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3316 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3317 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3318 | } |
| 3319 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3320 | Int::Int(RValue<SByte> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3321 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3322 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3323 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3324 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3325 | } |
| 3326 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3327 | Int::Int(RValue<Short> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3328 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3329 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3330 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3331 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3332 | } |
| 3333 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3334 | Int::Int(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3335 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3336 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3337 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3338 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3339 | } |
| 3340 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3341 | Int::Int(RValue<Int2> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3342 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3343 | *this = Extract(cast, 0); |
| 3344 | } |
| 3345 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3346 | Int::Int(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3347 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3348 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3349 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3350 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3351 | } |
| 3352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3353 | Int::Int(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3354 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3355 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3356 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3357 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3358 | } |
| 3359 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3360 | Int::Int(int x) |
| 3361 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3362 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3363 | } |
| 3364 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3365 | Int::Int(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3366 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3367 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3368 | } |
| 3369 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3370 | Int::Int(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3371 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3372 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | Int::Int(const Int &rhs) |
| 3376 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3377 | Value *value = rhs.loadValue(); |
| 3378 | storeValue(value); |
| 3379 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3380 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3381 | Int::Int(const Reference<Int> &rhs) |
| 3382 | { |
| 3383 | Value *value = rhs.loadValue(); |
| 3384 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | Int::Int(const UInt &rhs) |
| 3388 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3389 | Value *value = rhs.loadValue(); |
| 3390 | storeValue(value); |
| 3391 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3392 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3393 | Int::Int(const Reference<UInt> &rhs) |
| 3394 | { |
| 3395 | Value *value = rhs.loadValue(); |
| 3396 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3397 | } |
| 3398 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3399 | RValue<Int> Int::operator=(int rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3400 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3401 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3402 | } |
| 3403 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3404 | RValue<Int> Int::operator=(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3405 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3406 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3407 | |
| 3408 | return rhs; |
| 3409 | } |
| 3410 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3411 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3412 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3413 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3414 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3415 | return RValue<Int>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3416 | } |
| 3417 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3418 | RValue<Int> Int::operator=(const Int &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3419 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3420 | Value *value = rhs.loadValue(); |
| 3421 | storeValue(value); |
| 3422 | |
| 3423 | return RValue<Int>(value); |
| 3424 | } |
| 3425 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3426 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3427 | { |
| 3428 | Value *value = rhs.loadValue(); |
| 3429 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3430 | |
| 3431 | return RValue<Int>(value); |
| 3432 | } |
| 3433 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3434 | RValue<Int> Int::operator=(const UInt &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3435 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3436 | Value *value = rhs.loadValue(); |
| 3437 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3438 | |
| 3439 | return RValue<Int>(value); |
| 3440 | } |
| 3441 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3442 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3443 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3444 | Value *value = rhs.loadValue(); |
| 3445 | storeValue(value); |
| 3446 | |
| 3447 | return RValue<Int>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3448 | } |
| 3449 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3450 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3451 | { |
| 3452 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3453 | } |
| 3454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3455 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3456 | { |
| 3457 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3458 | } |
| 3459 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3460 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3461 | { |
| 3462 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3463 | } |
| 3464 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3465 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3466 | { |
| 3467 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3468 | } |
| 3469 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3470 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3471 | { |
| 3472 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3473 | } |
| 3474 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3475 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3476 | { |
| 3477 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3478 | } |
| 3479 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3480 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3481 | { |
| 3482 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3483 | } |
| 3484 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3485 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3486 | { |
| 3487 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3488 | } |
| 3489 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3490 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3491 | { |
| 3492 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3493 | } |
| 3494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3495 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3496 | { |
| 3497 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3498 | } |
| 3499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3500 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3501 | { |
| 3502 | return lhs = lhs + rhs; |
| 3503 | } |
| 3504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3505 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3506 | { |
| 3507 | return lhs = lhs - rhs; |
| 3508 | } |
| 3509 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3510 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3511 | { |
| 3512 | return lhs = lhs * rhs; |
| 3513 | } |
| 3514 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3515 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3516 | { |
| 3517 | return lhs = lhs / rhs; |
| 3518 | } |
| 3519 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3520 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3521 | { |
| 3522 | return lhs = lhs % rhs; |
| 3523 | } |
| 3524 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3525 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3526 | { |
| 3527 | return lhs = lhs & rhs; |
| 3528 | } |
| 3529 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3530 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3531 | { |
| 3532 | return lhs = lhs | rhs; |
| 3533 | } |
| 3534 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3535 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3536 | { |
| 3537 | return lhs = lhs ^ rhs; |
| 3538 | } |
| 3539 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3540 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3541 | { |
| 3542 | return lhs = lhs << rhs; |
| 3543 | } |
| 3544 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3545 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3546 | { |
| 3547 | return lhs = lhs >> rhs; |
| 3548 | } |
| 3549 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3550 | RValue<Int> operator+(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3551 | { |
| 3552 | return val; |
| 3553 | } |
| 3554 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3555 | RValue<Int> operator-(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3556 | { |
| 3557 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 3558 | } |
| 3559 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3560 | RValue<Int> operator~(RValue<Int> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3561 | { |
| 3562 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 3563 | } |
| 3564 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3565 | RValue<Int> operator++(Int &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3566 | { |
| 3567 | RValue<Int> res = val; |
| 3568 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3569 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3570 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3571 | |
| 3572 | return res; |
| 3573 | } |
| 3574 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3575 | const Int &operator++(Int &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3576 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3577 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3578 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3579 | |
| 3580 | return val; |
| 3581 | } |
| 3582 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3583 | RValue<Int> operator--(Int &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3584 | { |
| 3585 | RValue<Int> res = val; |
| 3586 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3587 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3588 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3589 | |
| 3590 | return res; |
| 3591 | } |
| 3592 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3593 | const Int &operator--(Int &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3594 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3595 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3596 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3597 | |
| 3598 | return val; |
| 3599 | } |
| 3600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3601 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3602 | { |
| 3603 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 3604 | } |
| 3605 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3606 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3607 | { |
| 3608 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 3609 | } |
| 3610 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3611 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3612 | { |
| 3613 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 3614 | } |
| 3615 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3616 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3617 | { |
| 3618 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 3619 | } |
| 3620 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3621 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3622 | { |
| 3623 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 3624 | } |
| 3625 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3626 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3627 | { |
| 3628 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 3629 | } |
| 3630 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3631 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 3632 | { |
| 3633 | return IfThenElse(x > y, x, y); |
| 3634 | } |
| 3635 | |
| 3636 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 3637 | { |
| 3638 | return IfThenElse(x < y, x, y); |
| 3639 | } |
| 3640 | |
| 3641 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 3642 | { |
| 3643 | return Min(Max(x, min), max); |
| 3644 | } |
| 3645 | |
| 3646 | RValue<Int> RoundInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3647 | { |
| 3648 | return x86::cvtss2si(cast); |
| 3649 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3650 | // 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] | 3651 | } |
| 3652 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3653 | Type *Int::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3654 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3655 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3656 | } |
| 3657 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3658 | Long::Long(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3659 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3660 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 3661 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3662 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3663 | } |
| 3664 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3665 | Long::Long(RValue<UInt> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3666 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3667 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 3668 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3669 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3670 | } |
| 3671 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3672 | Long::Long(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3673 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3674 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3675 | } |
| 3676 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3677 | RValue<Long> Long::operator=(int64_t rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3678 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 3679 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3680 | } |
| 3681 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3682 | RValue<Long> Long::operator=(RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3683 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3684 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3685 | |
| 3686 | return rhs; |
| 3687 | } |
| 3688 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3689 | RValue<Long> Long::operator=(const Long &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3690 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3691 | Value *value = rhs.loadValue(); |
| 3692 | storeValue(value); |
| 3693 | |
| 3694 | return RValue<Long>(value); |
| 3695 | } |
| 3696 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3697 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3698 | { |
| 3699 | Value *value = rhs.loadValue(); |
| 3700 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3701 | |
| 3702 | return RValue<Long>(value); |
| 3703 | } |
| 3704 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3705 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3706 | { |
| 3707 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3708 | } |
| 3709 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3710 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3711 | { |
| 3712 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3713 | } |
| 3714 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3715 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3716 | { |
| 3717 | return lhs = lhs + rhs; |
| 3718 | } |
| 3719 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3720 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3721 | { |
| 3722 | return lhs = lhs - rhs; |
| 3723 | } |
| 3724 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3725 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3726 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3727 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3728 | } |
| 3729 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3730 | Type *Long::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3731 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 3732 | return T(llvm::Type::getInt64Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3733 | } |
| 3734 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3735 | UInt::UInt(Argument<UInt> argument) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3736 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 3737 | storeValue(argument.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3738 | } |
| 3739 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3740 | UInt::UInt(RValue<UShort> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3741 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3742 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 3743 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3744 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3745 | } |
| 3746 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3747 | UInt::UInt(RValue<Long> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3748 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3749 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 3750 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3751 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3752 | } |
| 3753 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3754 | UInt::UInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3755 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 3756 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 3757 | // Value *integer = Nucleus::createFPToUI(cast.value, UInt::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3758 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 3759 | // Smallest positive value representable in UInt, but not in Int |
| 3760 | const unsigned int ustart = 0x80000000u; |
| 3761 | const float ustartf = float(ustart); |
| 3762 | |
| 3763 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 3764 | storeValue((~(As<Int>(cast) >> 31) & |
| 3765 | // Check if the value can be represented as an Int |
| 3766 | IfThenElse(cast >= ustartf, |
| 3767 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 3768 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 3769 | // Otherwise, just convert normally |
| 3770 | Int(cast))).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3771 | } |
| 3772 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3773 | UInt::UInt(int x) |
| 3774 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3775 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | UInt::UInt(unsigned int x) |
| 3779 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3780 | storeValue(Nucleus::createConstantInt(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3781 | } |
| 3782 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3783 | UInt::UInt(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3784 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3785 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3786 | } |
| 3787 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3788 | UInt::UInt(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3789 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3790 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | UInt::UInt(const UInt &rhs) |
| 3794 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3795 | Value *value = rhs.loadValue(); |
| 3796 | storeValue(value); |
| 3797 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3798 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3799 | UInt::UInt(const Reference<UInt> &rhs) |
| 3800 | { |
| 3801 | Value *value = rhs.loadValue(); |
| 3802 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | UInt::UInt(const Int &rhs) |
| 3806 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3807 | Value *value = rhs.loadValue(); |
| 3808 | storeValue(value); |
| 3809 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3810 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3811 | UInt::UInt(const Reference<Int> &rhs) |
| 3812 | { |
| 3813 | Value *value = rhs.loadValue(); |
| 3814 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3815 | } |
| 3816 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3817 | RValue<UInt> UInt::operator=(unsigned int rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3818 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3819 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3820 | } |
| 3821 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3822 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3823 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3824 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3825 | |
| 3826 | return rhs; |
| 3827 | } |
| 3828 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3829 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3830 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3831 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3832 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3833 | return RValue<UInt>(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3834 | } |
| 3835 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3836 | RValue<UInt> UInt::operator=(const UInt &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3837 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3838 | Value *value = rhs.loadValue(); |
| 3839 | storeValue(value); |
| 3840 | |
| 3841 | return RValue<UInt>(value); |
| 3842 | } |
| 3843 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3844 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3845 | { |
| 3846 | Value *value = rhs.loadValue(); |
| 3847 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3848 | |
| 3849 | return RValue<UInt>(value); |
| 3850 | } |
| 3851 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3852 | RValue<UInt> UInt::operator=(const Int &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3853 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3854 | Value *value = rhs.loadValue(); |
| 3855 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3856 | |
| 3857 | return RValue<UInt>(value); |
| 3858 | } |
| 3859 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3860 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3861 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3862 | Value *value = rhs.loadValue(); |
| 3863 | storeValue(value); |
| 3864 | |
| 3865 | return RValue<UInt>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3866 | } |
| 3867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3868 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3869 | { |
| 3870 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3871 | } |
| 3872 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3873 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3874 | { |
| 3875 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3876 | } |
| 3877 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3878 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3879 | { |
| 3880 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3881 | } |
| 3882 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3883 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3884 | { |
| 3885 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 3886 | } |
| 3887 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3888 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3889 | { |
| 3890 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 3891 | } |
| 3892 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3893 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3894 | { |
| 3895 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3896 | } |
| 3897 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3898 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3899 | { |
| 3900 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3901 | } |
| 3902 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3903 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3904 | { |
| 3905 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3906 | } |
| 3907 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3908 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3909 | { |
| 3910 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3911 | } |
| 3912 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3913 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3914 | { |
| 3915 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 3916 | } |
| 3917 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3918 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3919 | { |
| 3920 | return lhs = lhs + rhs; |
| 3921 | } |
| 3922 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3923 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3924 | { |
| 3925 | return lhs = lhs - rhs; |
| 3926 | } |
| 3927 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3928 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3929 | { |
| 3930 | return lhs = lhs * rhs; |
| 3931 | } |
| 3932 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3933 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3934 | { |
| 3935 | return lhs = lhs / rhs; |
| 3936 | } |
| 3937 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3938 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3939 | { |
| 3940 | return lhs = lhs % rhs; |
| 3941 | } |
| 3942 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3943 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3944 | { |
| 3945 | return lhs = lhs & rhs; |
| 3946 | } |
| 3947 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3948 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3949 | { |
| 3950 | return lhs = lhs | rhs; |
| 3951 | } |
| 3952 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3953 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3954 | { |
| 3955 | return lhs = lhs ^ rhs; |
| 3956 | } |
| 3957 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3958 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3959 | { |
| 3960 | return lhs = lhs << rhs; |
| 3961 | } |
| 3962 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3963 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3964 | { |
| 3965 | return lhs = lhs >> rhs; |
| 3966 | } |
| 3967 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3968 | RValue<UInt> operator+(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3969 | { |
| 3970 | return val; |
| 3971 | } |
| 3972 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3973 | RValue<UInt> operator-(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3974 | { |
| 3975 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 3976 | } |
| 3977 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3978 | RValue<UInt> operator~(RValue<UInt> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3979 | { |
| 3980 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 3981 | } |
| 3982 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3983 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3984 | { |
| 3985 | RValue<UInt> res = val; |
| 3986 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3987 | Value *inc = Nucleus::createAdd(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3988 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3989 | |
| 3990 | return res; |
| 3991 | } |
| 3992 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3993 | const UInt &operator++(UInt &val) // Pre-increment |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3994 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 3995 | Value *inc = Nucleus::createAdd(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3996 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3997 | |
| 3998 | return val; |
| 3999 | } |
| 4000 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4001 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4002 | { |
| 4003 | RValue<UInt> res = val; |
| 4004 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4005 | Value *inc = Nucleus::createSub(res.value, V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4006 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4007 | |
| 4008 | return res; |
| 4009 | } |
| 4010 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4011 | const UInt &operator--(UInt &val) // Pre-decrement |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4012 | { |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 4013 | Value *inc = Nucleus::createSub(val.loadValue(), V(Nucleus::createConstantInt(1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4014 | val.storeValue(inc); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4015 | |
| 4016 | return val; |
| 4017 | } |
| 4018 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4019 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4020 | { |
| 4021 | return IfThenElse(x > y, x, y); |
| 4022 | } |
| 4023 | |
| 4024 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4025 | { |
| 4026 | return IfThenElse(x < y, x, y); |
| 4027 | } |
| 4028 | |
| 4029 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4030 | { |
| 4031 | return Min(Max(x, min), max); |
| 4032 | } |
| 4033 | |
| 4034 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4035 | { |
| 4036 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4037 | } |
| 4038 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4039 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4040 | { |
| 4041 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4042 | } |
| 4043 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4044 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4045 | { |
| 4046 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4047 | } |
| 4048 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4049 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4050 | { |
| 4051 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4052 | } |
| 4053 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4054 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4055 | { |
| 4056 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4057 | } |
| 4058 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4059 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4060 | { |
| 4061 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4062 | } |
| 4063 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4064 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4065 | // { |
| 4066 | // return x86::cvtss2si(val); // FIXME: Unsigned |
| 4067 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4068 | // // 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] | 4069 | // } |
| 4070 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4071 | Type *UInt::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4072 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 4073 | return T(llvm::Type::getInt32Ty(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4074 | } |
| 4075 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4076 | // Int2::Int2(RValue<Int> cast) |
| 4077 | // { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4078 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4079 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4080 | // |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4081 | // int shuffle[2] = {0, 0}; |
| 4082 | // Value *replicate = Nucleus::createShuffleVector(vector, vector, shuffle); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4083 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4084 | // storeValue(replicate); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4085 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4086 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4087 | Int2::Int2(RValue<Int4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4088 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4089 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4090 | } |
| 4091 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4092 | Int2::Int2(int x, int y) |
| 4093 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4094 | int64_t constantVector[2] = {x, y}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4095 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4096 | } |
| 4097 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4098 | Int2::Int2(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4099 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4100 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | Int2::Int2(const Int2 &rhs) |
| 4104 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4105 | Value *value = rhs.loadValue(); |
| 4106 | storeValue(value); |
| 4107 | } |
| 4108 | |
| 4109 | Int2::Int2(const Reference<Int2> &rhs) |
| 4110 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4111 | Value *value = rhs.loadValue(); |
| 4112 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4113 | } |
| 4114 | |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4115 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4116 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4117 | int shuffle[4] = {0, 4, 1, 5}; |
| 4118 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4119 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4120 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4121 | } |
| 4122 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4123 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4124 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4125 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4126 | |
| 4127 | return rhs; |
| 4128 | } |
| 4129 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4130 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4131 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4132 | Value *value = rhs.loadValue(); |
| 4133 | storeValue(value); |
| 4134 | |
| 4135 | return RValue<Int2>(value); |
| 4136 | } |
| 4137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4138 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4139 | { |
| 4140 | Value *value = rhs.loadValue(); |
| 4141 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4142 | |
| 4143 | return RValue<Int2>(value); |
| 4144 | } |
| 4145 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4146 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4147 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4148 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4149 | } |
| 4150 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4151 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4152 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4153 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4154 | } |
| 4155 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4156 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4157 | // { |
| 4158 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4159 | // } |
| 4160 | |
| 4161 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4162 | // { |
| 4163 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4164 | // } |
| 4165 | |
| 4166 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4167 | // { |
| 4168 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4169 | // } |
| 4170 | |
| 4171 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4172 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4173 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4174 | } |
| 4175 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4176 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4177 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4178 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4179 | } |
| 4180 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4181 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4182 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4183 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4184 | } |
| 4185 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4186 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4187 | { |
| 4188 | // return RValue<Int2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4189 | |
| 4190 | return x86::pslld(lhs, rhs); |
| 4191 | } |
| 4192 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4193 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4194 | { |
| 4195 | // return RValue<Int2>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4196 | |
| 4197 | return x86::psrad(lhs, rhs); |
| 4198 | } |
| 4199 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4200 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4201 | { |
| 4202 | return lhs = lhs + rhs; |
| 4203 | } |
| 4204 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4205 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4206 | { |
| 4207 | return lhs = lhs - rhs; |
| 4208 | } |
| 4209 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4210 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4211 | // { |
| 4212 | // return lhs = lhs * rhs; |
| 4213 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4214 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4215 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4216 | // { |
| 4217 | // return lhs = lhs / rhs; |
| 4218 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4219 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4220 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4221 | // { |
| 4222 | // return lhs = lhs % rhs; |
| 4223 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4224 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4225 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4226 | { |
| 4227 | return lhs = lhs & rhs; |
| 4228 | } |
| 4229 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4230 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4231 | { |
| 4232 | return lhs = lhs | rhs; |
| 4233 | } |
| 4234 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4235 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4236 | { |
| 4237 | return lhs = lhs ^ rhs; |
| 4238 | } |
| 4239 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4240 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4241 | { |
| 4242 | return lhs = lhs << rhs; |
| 4243 | } |
| 4244 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4245 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4246 | { |
| 4247 | return lhs = lhs >> rhs; |
| 4248 | } |
| 4249 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4250 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4251 | // { |
| 4252 | // return val; |
| 4253 | // } |
| 4254 | |
| 4255 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4256 | // { |
| 4257 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4258 | // } |
| 4259 | |
| 4260 | RValue<Int2> operator~(RValue<Int2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4261 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4262 | return RValue<Int2>(Nucleus::createNot(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4263 | } |
| 4264 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4265 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4266 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4267 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4268 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4269 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4270 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4271 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4272 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4273 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4274 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4275 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4276 | } |
| 4277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4278 | RValue<Int> Extract(RValue<Int2> val, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4279 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4280 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4281 | } |
| 4282 | |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4283 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4284 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4285 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | fff3c9b | 2015-05-13 23:40:44 -0400 | [diff] [blame] | 4286 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4287 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4288 | Type *Int2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4289 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4290 | return T(Type_v2i32); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4291 | } |
| 4292 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4293 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4294 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4295 | int64_t constantVector[2] = {x, y}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4296 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4297 | } |
| 4298 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4299 | UInt2::UInt2(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4300 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4301 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | UInt2::UInt2(const UInt2 &rhs) |
| 4305 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4306 | Value *value = rhs.loadValue(); |
| 4307 | storeValue(value); |
| 4308 | } |
| 4309 | |
| 4310 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4311 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4312 | Value *value = rhs.loadValue(); |
| 4313 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4314 | } |
| 4315 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4316 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4317 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4318 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4319 | |
| 4320 | return rhs; |
| 4321 | } |
| 4322 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4323 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4324 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4325 | Value *value = rhs.loadValue(); |
| 4326 | storeValue(value); |
| 4327 | |
| 4328 | return RValue<UInt2>(value); |
| 4329 | } |
| 4330 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4331 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4332 | { |
| 4333 | Value *value = rhs.loadValue(); |
| 4334 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4335 | |
| 4336 | return RValue<UInt2>(value); |
| 4337 | } |
| 4338 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4339 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4340 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4341 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4342 | } |
| 4343 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4344 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4345 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4346 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4349 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4350 | // { |
| 4351 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4352 | // } |
| 4353 | |
| 4354 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4355 | // { |
| 4356 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4357 | // } |
| 4358 | |
| 4359 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4360 | // { |
| 4361 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4362 | // } |
| 4363 | |
| 4364 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4365 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4366 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
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<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4370 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4371 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4372 | } |
| 4373 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4374 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4375 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4376 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4377 | } |
| 4378 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4379 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4380 | { |
| 4381 | // return RValue<UInt2>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4382 | |
| 4383 | return As<UInt2>(x86::pslld(As<Int2>(lhs), rhs)); |
| 4384 | } |
| 4385 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4386 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4387 | { |
| 4388 | // return RValue<UInt2>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4389 | |
| 4390 | return x86::psrld(lhs, rhs); |
| 4391 | } |
| 4392 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4393 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4394 | { |
| 4395 | return lhs = lhs + rhs; |
| 4396 | } |
| 4397 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4398 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4399 | { |
| 4400 | return lhs = lhs - rhs; |
| 4401 | } |
| 4402 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4403 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4404 | // { |
| 4405 | // return lhs = lhs * rhs; |
| 4406 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4407 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4408 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4409 | // { |
| 4410 | // return lhs = lhs / rhs; |
| 4411 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4412 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4413 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4414 | // { |
| 4415 | // return lhs = lhs % rhs; |
| 4416 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4417 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4418 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4419 | { |
| 4420 | return lhs = lhs & rhs; |
| 4421 | } |
| 4422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4423 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4424 | { |
| 4425 | return lhs = lhs | rhs; |
| 4426 | } |
| 4427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4428 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4429 | { |
| 4430 | return lhs = lhs ^ rhs; |
| 4431 | } |
| 4432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4433 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4434 | { |
| 4435 | return lhs = lhs << rhs; |
| 4436 | } |
| 4437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4438 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4439 | { |
| 4440 | return lhs = lhs >> rhs; |
| 4441 | } |
| 4442 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4443 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4444 | // { |
| 4445 | // return val; |
| 4446 | // } |
| 4447 | |
| 4448 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4449 | // { |
| 4450 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4451 | // } |
| 4452 | |
| 4453 | RValue<UInt2> operator~(RValue<UInt2> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4454 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4455 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4456 | } |
| 4457 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4458 | Type *UInt2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4459 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4460 | return T(Type_v2i32); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4461 | } |
| 4462 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4463 | Int4::Int4() : XYZW(this) |
| 4464 | { |
| 4465 | } |
| 4466 | |
| 4467 | Int4::Int4(RValue<Byte4> cast) : XYZW(this) |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4468 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4469 | if(CPUID::supportsSSE4_1()) |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4470 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4471 | *this = x86::pmovzxbd(As<Byte16>(cast)); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4472 | } |
| 4473 | else |
| 4474 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4475 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4476 | Value *a = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 4477 | Value *b = Nucleus::createShuffleVector(a, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4478 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4479 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4480 | Value *c = Nucleus::createBitCast(b, Short8::getType()); |
| 4481 | Value *d = Nucleus::createShuffleVector(c, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4482 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4483 | *this = As<Int4>(d); |
| 4484 | } |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4485 | } |
| 4486 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4487 | Int4::Int4(RValue<SByte4> cast) : XYZW(this) |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4488 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4489 | if(CPUID::supportsSSE4_1()) |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4490 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4491 | *this = x86::pmovsxbd(As<SByte16>(cast)); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4492 | } |
| 4493 | else |
| 4494 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4495 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4496 | Value *a = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 4497 | Value *b = Nucleus::createShuffleVector(a, a, swizzle); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4498 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4499 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4500 | Value *c = Nucleus::createBitCast(b, Short8::getType()); |
| 4501 | Value *d = Nucleus::createShuffleVector(c, c, swizzle2); |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4502 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4503 | *this = As<Int4>(d) >> 24; |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4504 | } |
Meng-Lin Wu | 601d005 | 2016-06-10 14:18:41 -0400 | [diff] [blame] | 4505 | } |
| 4506 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4507 | Int4::Int4(RValue<Float4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4508 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4509 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4510 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4511 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4512 | } |
| 4513 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4514 | Int4::Int4(RValue<Short4> cast) : XYZW(this) |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4515 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4516 | if(CPUID::supportsSSE4_1()) |
| 4517 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4518 | *this = x86::pmovsxwd(As<Short8>(cast)); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4519 | } |
| 4520 | else |
| 4521 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4522 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4523 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 4524 | *this = As<Int4>(c) >> 16; |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4525 | } |
| 4526 | } |
| 4527 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4528 | Int4::Int4(RValue<UShort4> cast) : XYZW(this) |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4529 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4530 | if(CPUID::supportsSSE4_1()) |
| 4531 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4532 | *this = x86::pmovzxwd(As<UShort8>(cast)); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4533 | } |
| 4534 | else |
| 4535 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4536 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4537 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 4538 | *this = As<Int4>(c); |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 4539 | } |
| 4540 | } |
| 4541 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4542 | Int4::Int4(int xyzw) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4543 | { |
| 4544 | constant(xyzw, xyzw, xyzw, xyzw); |
| 4545 | } |
| 4546 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4547 | Int4::Int4(int x, int yzw) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4548 | { |
| 4549 | constant(x, yzw, yzw, yzw); |
| 4550 | } |
| 4551 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4552 | Int4::Int4(int x, int y, int zw) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4553 | { |
| 4554 | constant(x, y, zw, zw); |
| 4555 | } |
| 4556 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4557 | Int4::Int4(int x, int y, int z, int w) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4558 | { |
| 4559 | constant(x, y, z, w); |
| 4560 | } |
| 4561 | |
| 4562 | void Int4::constant(int x, int y, int z, int w) |
| 4563 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4564 | int64_t constantVector[4] = {x, y, z, w}; |
| 4565 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4566 | } |
| 4567 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4568 | Int4::Int4(RValue<Int4> rhs) : XYZW(this) |
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 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4573 | Int4::Int4(const Int4 &rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4574 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4575 | Value *value = rhs.loadValue(); |
| 4576 | storeValue(value); |
| 4577 | } |
| 4578 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4579 | Int4::Int4(const Reference<Int4> &rhs) : XYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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 | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4585 | Int4::Int4(RValue<UInt4> rhs) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4586 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4587 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4588 | } |
| 4589 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4590 | Int4::Int4(const UInt4 &rhs) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4591 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4592 | Value *value = rhs.loadValue(); |
| 4593 | storeValue(value); |
| 4594 | } |
| 4595 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4596 | Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4597 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4598 | Value *value = rhs.loadValue(); |
| 4599 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4600 | } |
| 4601 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4602 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this) |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4603 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4604 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 4605 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4606 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4607 | storeValue(packed); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4608 | } |
| 4609 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4610 | Int4::Int4(RValue<Int> rhs) : XYZW(this) |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4611 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4612 | Value *vector = loadValue(); |
| 4613 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 4614 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 4615 | int swizzle[4] = {0, 0, 0, 0}; |
| 4616 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4617 | |
| 4618 | storeValue(replicate); |
| 4619 | } |
| 4620 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4621 | Int4::Int4(const Int &rhs) : XYZW(this) |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4622 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4623 | *this = RValue<Int>(rhs.loadValue()); |
| 4624 | } |
| 4625 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4626 | Int4::Int4(const Reference<Int> &rhs) : XYZW(this) |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4627 | { |
Nicolas Capens | 24c8cf0 | 2016-08-15 15:33:14 -0400 | [diff] [blame] | 4628 | *this = RValue<Int>(rhs.loadValue()); |
| 4629 | } |
| 4630 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4631 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4632 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4633 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4634 | |
| 4635 | return rhs; |
| 4636 | } |
| 4637 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4638 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4639 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4640 | Value *value = rhs.loadValue(); |
| 4641 | storeValue(value); |
| 4642 | |
| 4643 | return RValue<Int4>(value); |
| 4644 | } |
| 4645 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4646 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4647 | { |
| 4648 | Value *value = rhs.loadValue(); |
| 4649 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4650 | |
| 4651 | return RValue<Int4>(value); |
| 4652 | } |
| 4653 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4654 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4655 | { |
| 4656 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4657 | } |
| 4658 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4659 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4660 | { |
| 4661 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4662 | } |
| 4663 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4664 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4665 | { |
| 4666 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4667 | } |
| 4668 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 4669 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 4670 | { |
| 4671 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4672 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4673 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 4674 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 4675 | { |
| 4676 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4677 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4678 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4679 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4680 | { |
| 4681 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4682 | } |
| 4683 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4684 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4685 | { |
| 4686 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4687 | } |
| 4688 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4689 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4690 | { |
| 4691 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4692 | } |
| 4693 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4694 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4695 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4696 | return x86::pslld(lhs, rhs); |
| 4697 | } |
| 4698 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4699 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4700 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4701 | return x86::psrad(lhs, rhs); |
| 4702 | } |
| 4703 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 4704 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 4705 | { |
| 4706 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4707 | } |
| 4708 | |
| 4709 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 4710 | { |
| 4711 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4712 | } |
| 4713 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4714 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4715 | { |
| 4716 | return lhs = lhs + rhs; |
| 4717 | } |
| 4718 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4719 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4720 | { |
| 4721 | return lhs = lhs - rhs; |
| 4722 | } |
| 4723 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4724 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4725 | { |
| 4726 | return lhs = lhs * rhs; |
| 4727 | } |
| 4728 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4729 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4730 | // { |
| 4731 | // return lhs = lhs / rhs; |
| 4732 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4733 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4734 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4735 | // { |
| 4736 | // return lhs = lhs % rhs; |
| 4737 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4738 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4739 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4740 | { |
| 4741 | return lhs = lhs & rhs; |
| 4742 | } |
| 4743 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4744 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4745 | { |
| 4746 | return lhs = lhs | rhs; |
| 4747 | } |
| 4748 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4749 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4750 | { |
| 4751 | return lhs = lhs ^ rhs; |
| 4752 | } |
| 4753 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4754 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4755 | { |
| 4756 | return lhs = lhs << rhs; |
| 4757 | } |
| 4758 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4759 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4760 | { |
| 4761 | return lhs = lhs >> rhs; |
| 4762 | } |
| 4763 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4764 | RValue<Int4> operator+(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4765 | { |
| 4766 | return val; |
| 4767 | } |
| 4768 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4769 | RValue<Int4> operator-(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4770 | { |
| 4771 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 4772 | } |
| 4773 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4774 | RValue<Int4> operator~(RValue<Int4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4775 | { |
| 4776 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 4777 | } |
| 4778 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4779 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 4780 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 4781 | // 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] | 4782 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 4783 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 4784 | 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] | 4785 | } |
| 4786 | |
| 4787 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 4788 | { |
Nicolas Capens | 9ae6cfd | 2017-11-27 14:58:53 -0500 | [diff] [blame^] | 4789 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 4790 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 4791 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 4792 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 4796 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 4797 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 4798 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 4799 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 4800 | 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] | 4801 | } |
| 4802 | |
| 4803 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 4804 | { |
Nicolas Capens | 9ae6cfd | 2017-11-27 14:58:53 -0500 | [diff] [blame^] | 4805 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 4806 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 4807 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 4808 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 4812 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 4813 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 4814 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 4815 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 4816 | 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] | 4817 | } |
| 4818 | |
| 4819 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 4820 | { |
Nicolas Capens | 9ae6cfd | 2017-11-27 14:58:53 -0500 | [diff] [blame^] | 4821 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 4822 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 4823 | // return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 4824 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())) ^ Int4(0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 4828 | { |
| 4829 | if(CPUID::supportsSSE4_1()) |
| 4830 | { |
| 4831 | return x86::pmaxsd(x, y); |
| 4832 | } |
| 4833 | else |
| 4834 | { |
| 4835 | RValue<Int4> greater = CmpNLE(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 4836 | return (x & greater) | (y & ~greater); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 4841 | { |
| 4842 | if(CPUID::supportsSSE4_1()) |
| 4843 | { |
| 4844 | return x86::pminsd(x, y); |
| 4845 | } |
| 4846 | else |
| 4847 | { |
| 4848 | RValue<Int4> less = CmpLT(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 4849 | return (x & less) | (y & ~less); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | RValue<Int4> RoundInt(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4854 | { |
| 4855 | return x86::cvtps2dq(cast); |
| 4856 | } |
| 4857 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 4858 | RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4859 | { |
| 4860 | return x86::packssdw(x, y); |
| 4861 | } |
| 4862 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 4863 | RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y) |
| 4864 | { |
| 4865 | return x86::packusdw(x, y); |
| 4866 | } |
| 4867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4868 | RValue<Int> Extract(RValue<Int4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4869 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 4870 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4871 | } |
| 4872 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4873 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4874 | { |
| 4875 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 4876 | } |
| 4877 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4878 | RValue<Int> SignMask(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4879 | { |
| 4880 | return x86::movmskps(As<Float4>(x)); |
| 4881 | } |
| 4882 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4883 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4884 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 4885 | return RValue<Int4>(createSwizzle4(x.value, select)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4886 | } |
| 4887 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4888 | Type *Int4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4889 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 4890 | return T(llvm::VectorType::get(T(Int::getType()), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4891 | } |
| 4892 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4893 | UInt4::UInt4() : XYZW(this) |
| 4894 | { |
| 4895 | } |
| 4896 | |
| 4897 | UInt4::UInt4(RValue<Float4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4898 | { |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 4899 | // Note: createFPToUI is broken, must perform conversion using createFPtoSI |
| 4900 | // Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4901 | |
Alexis Hetu | 764d142 | 2016-09-28 08:44:22 -0400 | [diff] [blame] | 4902 | // Smallest positive value representable in UInt, but not in Int |
| 4903 | const unsigned int ustart = 0x80000000u; |
| 4904 | const float ustartf = float(ustart); |
| 4905 | |
| 4906 | // Check if the value can be represented as an Int |
| 4907 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 4908 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4909 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 4910 | // Otherwise, just convert normally |
| 4911 | (~uiValue & Int4(cast)); |
| 4912 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4913 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4914 | } |
| 4915 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4916 | UInt4::UInt4(int xyzw) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4917 | { |
| 4918 | constant(xyzw, xyzw, xyzw, xyzw); |
| 4919 | } |
| 4920 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4921 | UInt4::UInt4(int x, int yzw) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4922 | { |
| 4923 | constant(x, yzw, yzw, yzw); |
| 4924 | } |
| 4925 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4926 | UInt4::UInt4(int x, int y, int zw) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4927 | { |
| 4928 | constant(x, y, zw, zw); |
| 4929 | } |
| 4930 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4931 | UInt4::UInt4(int x, int y, int z, int w) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4932 | { |
| 4933 | constant(x, y, z, w); |
| 4934 | } |
| 4935 | |
| 4936 | void UInt4::constant(int x, int y, int z, int w) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4937 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4938 | int64_t constantVector[4] = {x, y, z, w}; |
| 4939 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4940 | } |
| 4941 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4942 | UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4943 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4944 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4945 | } |
| 4946 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4947 | UInt4::UInt4(const UInt4 &rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4948 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4949 | Value *value = rhs.loadValue(); |
| 4950 | storeValue(value); |
| 4951 | } |
| 4952 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4953 | UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4954 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4955 | Value *value = rhs.loadValue(); |
| 4956 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4957 | } |
| 4958 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4959 | UInt4::UInt4(RValue<Int4> rhs) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4960 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4961 | storeValue(rhs.value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4962 | } |
| 4963 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4964 | UInt4::UInt4(const Int4 &rhs) : XYZW(this) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4965 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4966 | Value *value = rhs.loadValue(); |
| 4967 | storeValue(value); |
| 4968 | } |
| 4969 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4970 | UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4971 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4972 | Value *value = rhs.loadValue(); |
| 4973 | storeValue(value); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4974 | } |
| 4975 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 4976 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this) |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4977 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4978 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 4979 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4980 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 4981 | storeValue(packed); |
Nicolas Capens | 62abb55 | 2016-01-05 12:03:47 -0500 | [diff] [blame] | 4982 | } |
| 4983 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4984 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4985 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4986 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4987 | |
| 4988 | return rhs; |
| 4989 | } |
| 4990 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4991 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4992 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4993 | Value *value = rhs.loadValue(); |
| 4994 | storeValue(value); |
| 4995 | |
| 4996 | return RValue<UInt4>(value); |
| 4997 | } |
| 4998 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4999 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5000 | { |
| 5001 | Value *value = rhs.loadValue(); |
| 5002 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5003 | |
| 5004 | return RValue<UInt4>(value); |
| 5005 | } |
| 5006 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5007 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5008 | { |
| 5009 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5010 | } |
| 5011 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5012 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5013 | { |
| 5014 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5015 | } |
| 5016 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5017 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5018 | { |
| 5019 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5020 | } |
| 5021 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5022 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5023 | { |
| 5024 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5025 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5026 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5027 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5028 | { |
| 5029 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5030 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5031 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5032 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5033 | { |
| 5034 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5035 | } |
| 5036 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5037 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5038 | { |
| 5039 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5040 | } |
| 5041 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5042 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5043 | { |
| 5044 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5045 | } |
| 5046 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5047 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5048 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5049 | return As<UInt4>(x86::pslld(As<Int4>(lhs), rhs)); |
| 5050 | } |
| 5051 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5052 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5053 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5054 | return x86::psrld(lhs, rhs); |
| 5055 | } |
| 5056 | |
Alexis Hetu | d9d27bb | 2015-08-18 15:22:15 -0400 | [diff] [blame] | 5057 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5058 | { |
| 5059 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5060 | } |
| 5061 | |
| 5062 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5063 | { |
| 5064 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5065 | } |
| 5066 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5067 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5068 | { |
| 5069 | return lhs = lhs + rhs; |
| 5070 | } |
| 5071 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5072 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5073 | { |
| 5074 | return lhs = lhs - rhs; |
| 5075 | } |
| 5076 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5077 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5078 | { |
| 5079 | return lhs = lhs * rhs; |
| 5080 | } |
| 5081 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5082 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5083 | // { |
| 5084 | // return lhs = lhs / rhs; |
| 5085 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5086 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5087 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5088 | // { |
| 5089 | // return lhs = lhs % rhs; |
| 5090 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5091 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5092 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5093 | { |
| 5094 | return lhs = lhs & rhs; |
| 5095 | } |
| 5096 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5097 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5098 | { |
| 5099 | return lhs = lhs | rhs; |
| 5100 | } |
| 5101 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5102 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5103 | { |
| 5104 | return lhs = lhs ^ rhs; |
| 5105 | } |
| 5106 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5107 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5108 | { |
| 5109 | return lhs = lhs << rhs; |
| 5110 | } |
| 5111 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5112 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5113 | { |
| 5114 | return lhs = lhs >> rhs; |
| 5115 | } |
| 5116 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5117 | RValue<UInt4> operator+(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5118 | { |
| 5119 | return val; |
| 5120 | } |
| 5121 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5122 | RValue<UInt4> operator-(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5123 | { |
| 5124 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5125 | } |
| 5126 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5127 | RValue<UInt4> operator~(RValue<UInt4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5128 | { |
| 5129 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5130 | } |
| 5131 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5132 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5133 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5134 | // 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] | 5135 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5136 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5137 | 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] | 5138 | } |
| 5139 | |
| 5140 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5141 | { |
| 5142 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 5143 | } |
| 5144 | |
| 5145 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5146 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5147 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5148 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5149 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 5150 | 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] | 5151 | } |
| 5152 | |
| 5153 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5154 | { |
| 5155 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5156 | } |
| 5157 | |
| 5158 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5159 | { |
Nicolas Capens | 197226a | 2016-04-27 23:08:50 -0400 | [diff] [blame] | 5160 | // FIXME: An LLVM bug causes SExt(ICmpCC()) to produce 0 or 1 instead of 0 or ~0 |
| 5161 | // Restore the following line when LLVM is updated to a version where this issue is fixed. |
| 5162 | // return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 5163 | 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] | 5164 | } |
| 5165 | |
| 5166 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5167 | { |
| 5168 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 5169 | } |
| 5170 | |
| 5171 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5172 | { |
| 5173 | if(CPUID::supportsSSE4_1()) |
| 5174 | { |
| 5175 | return x86::pmaxud(x, y); |
| 5176 | } |
| 5177 | else |
| 5178 | { |
| 5179 | RValue<UInt4> greater = CmpNLE(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 5180 | return (x & greater) | (y & ~greater); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5181 | } |
| 5182 | } |
| 5183 | |
| 5184 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5185 | { |
| 5186 | if(CPUID::supportsSSE4_1()) |
| 5187 | { |
| 5188 | return x86::pminud(x, y); |
| 5189 | } |
| 5190 | else |
| 5191 | { |
| 5192 | RValue<UInt4> less = CmpLT(x, y); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 5193 | return (x & less) | (y & ~less); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5197 | Type *UInt4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5198 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5199 | return T(llvm::VectorType::get(T(UInt::getType()), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5200 | } |
| 5201 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5202 | Float::Float(RValue<Int> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5203 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5204 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5205 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5206 | storeValue(integer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5207 | } |
| 5208 | |
Alexis Hetu | cfd9632 | 2017-07-24 14:44:33 -0400 | [diff] [blame] | 5209 | Float::Float(RValue<UInt> cast) |
| 5210 | { |
| 5211 | RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) + |
| 5212 | As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u))); |
| 5213 | |
| 5214 | storeValue(result.value); |
| 5215 | } |
| 5216 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5217 | Float::Float(float x) |
| 5218 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5219 | storeValue(Nucleus::createConstantFloat(x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5220 | } |
| 5221 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5222 | Float::Float(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5223 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5224 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | Float::Float(const Float &rhs) |
| 5228 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5229 | Value *value = rhs.loadValue(); |
| 5230 | storeValue(value); |
| 5231 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5232 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5233 | Float::Float(const Reference<Float> &rhs) |
| 5234 | { |
| 5235 | Value *value = rhs.loadValue(); |
| 5236 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5237 | } |
| 5238 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5239 | RValue<Float> Float::operator=(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5240 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5241 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5242 | |
| 5243 | return rhs; |
| 5244 | } |
| 5245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5246 | RValue<Float> Float::operator=(const Float &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5247 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5248 | Value *value = rhs.loadValue(); |
| 5249 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5250 | |
| 5251 | return RValue<Float>(value); |
| 5252 | } |
| 5253 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5254 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5255 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5256 | Value *value = rhs.loadValue(); |
| 5257 | storeValue(value); |
| 5258 | |
| 5259 | return RValue<Float>(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5260 | } |
| 5261 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5262 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5263 | { |
| 5264 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5265 | } |
| 5266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5267 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5268 | { |
| 5269 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5270 | } |
| 5271 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5272 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5273 | { |
| 5274 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5275 | } |
| 5276 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5277 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5278 | { |
| 5279 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5280 | } |
| 5281 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5282 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5283 | { |
| 5284 | return lhs = lhs + rhs; |
| 5285 | } |
| 5286 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5287 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5288 | { |
| 5289 | return lhs = lhs - rhs; |
| 5290 | } |
| 5291 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5292 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5293 | { |
| 5294 | return lhs = lhs * rhs; |
| 5295 | } |
| 5296 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5297 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5298 | { |
| 5299 | return lhs = lhs / rhs; |
| 5300 | } |
| 5301 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5302 | RValue<Float> operator+(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5303 | { |
| 5304 | return val; |
| 5305 | } |
| 5306 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5307 | RValue<Float> operator-(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5308 | { |
| 5309 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5310 | } |
| 5311 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5312 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5313 | { |
| 5314 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5315 | } |
| 5316 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5317 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5318 | { |
| 5319 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5320 | } |
| 5321 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5322 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5323 | { |
| 5324 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5325 | } |
| 5326 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5327 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5328 | { |
| 5329 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5330 | } |
| 5331 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5332 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5333 | { |
| 5334 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5335 | } |
| 5336 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5337 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5338 | { |
| 5339 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5340 | } |
| 5341 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5342 | RValue<Float> Abs(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5343 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5344 | return IfThenElse(x > 0.0f, x, -x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5345 | } |
| 5346 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5347 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5348 | { |
| 5349 | return IfThenElse(x > y, x, y); |
| 5350 | } |
| 5351 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5352 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5353 | { |
| 5354 | return IfThenElse(x < y, x, y); |
| 5355 | } |
| 5356 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5357 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5358 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 5359 | #if defined(__i386__) || defined(__x86_64__) |
| 5360 | if(exactAtPow2) |
| 5361 | { |
| 5362 | // rcpss uses a piecewise-linear approximation which minimizes the relative error |
| 5363 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 5364 | return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 5365 | } |
| 5366 | #endif |
| 5367 | |
| 5368 | return x86::rcpss(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5369 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5370 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5371 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5372 | { |
| 5373 | return x86::rsqrtss(x); |
| 5374 | } |
| 5375 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5376 | RValue<Float> Sqrt(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5377 | { |
| 5378 | return x86::sqrtss(x); |
| 5379 | } |
| 5380 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5381 | RValue<Float> Round(RValue<Float> x) |
| 5382 | { |
| 5383 | if(CPUID::supportsSSE4_1()) |
| 5384 | { |
| 5385 | return x86::roundss(x, 0); |
| 5386 | } |
| 5387 | else |
| 5388 | { |
| 5389 | return Float4(Round(Float4(x))).x; |
| 5390 | } |
| 5391 | } |
| 5392 | |
| 5393 | RValue<Float> Trunc(RValue<Float> x) |
| 5394 | { |
| 5395 | if(CPUID::supportsSSE4_1()) |
| 5396 | { |
| 5397 | return x86::roundss(x, 3); |
| 5398 | } |
| 5399 | else |
| 5400 | { |
| 5401 | return Float(Int(x)); // Rounded toward zero |
| 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | RValue<Float> Frac(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5406 | { |
| 5407 | if(CPUID::supportsSSE4_1()) |
| 5408 | { |
| 5409 | return x - x86::floorss(x); |
| 5410 | } |
| 5411 | else |
| 5412 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5413 | return Float4(Frac(Float4(x))).x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5414 | } |
| 5415 | } |
| 5416 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5417 | RValue<Float> Floor(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5418 | { |
| 5419 | if(CPUID::supportsSSE4_1()) |
| 5420 | { |
| 5421 | return x86::floorss(x); |
| 5422 | } |
| 5423 | else |
| 5424 | { |
| 5425 | return Float4(Floor(Float4(x))).x; |
| 5426 | } |
| 5427 | } |
| 5428 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5429 | RValue<Float> Ceil(RValue<Float> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5430 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5431 | if(CPUID::supportsSSE4_1()) |
| 5432 | { |
| 5433 | return x86::ceilss(x); |
| 5434 | } |
| 5435 | else |
| 5436 | { |
| 5437 | return Float4(Ceil(Float4(x))).x; |
| 5438 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5439 | } |
| 5440 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5441 | Type *Float::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5442 | { |
Nicolas Capens | ac23012 | 2016-09-20 14:30:06 -0400 | [diff] [blame] | 5443 | return T(llvm::Type::getFloatTy(*::context)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5444 | } |
| 5445 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5446 | Float2::Float2(RValue<Float4> cast) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5447 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5448 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5449 | } |
| 5450 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5451 | Type *Float2::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5452 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5453 | return T(Type_v2f32); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5454 | } |
| 5455 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5456 | Float4::Float4(RValue<Byte4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5457 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 5458 | Value *a = Int4(cast).loadValue(); |
| 5459 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5460 | |
| 5461 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5462 | } |
| 5463 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5464 | Float4::Float4(RValue<SByte4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5465 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 5466 | Value *a = Int4(cast).loadValue(); |
| 5467 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5468 | |
| 5469 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5470 | } |
| 5471 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5472 | Float4::Float4(RValue<Short4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5473 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5474 | Int4 c(cast); |
| 5475 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5476 | } |
| 5477 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5478 | Float4::Float4(RValue<UShort4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5479 | { |
Alexis Hetu | 2aa852f | 2015-10-14 16:32:39 -0400 | [diff] [blame] | 5480 | Int4 c(cast); |
| 5481 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5482 | } |
| 5483 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5484 | Float4::Float4(RValue<Int4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5485 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5486 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5487 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5488 | storeValue(xyzw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5489 | } |
| 5490 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5491 | Float4::Float4(RValue<UInt4> cast) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5492 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5493 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5494 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5495 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5496 | storeValue(result.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5497 | } |
| 5498 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5499 | Float4::Float4() : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5500 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5501 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5502 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5503 | Float4::Float4(float xyzw) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5504 | { |
| 5505 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5506 | } |
| 5507 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5508 | Float4::Float4(float x, float yzw) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5509 | { |
| 5510 | constant(x, yzw, yzw, yzw); |
| 5511 | } |
| 5512 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5513 | Float4::Float4(float x, float y, float zw) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5514 | { |
| 5515 | constant(x, y, zw, zw); |
| 5516 | } |
| 5517 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5518 | Float4::Float4(float x, float y, float z, float w) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5519 | { |
| 5520 | constant(x, y, z, w); |
| 5521 | } |
| 5522 | |
| 5523 | void Float4::constant(float x, float y, float z, float w) |
| 5524 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5525 | double constantVector[4] = {x, y, z, w}; |
| 5526 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5527 | } |
| 5528 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5529 | Float4::Float4(RValue<Float4> rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5530 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5531 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5532 | } |
| 5533 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5534 | Float4::Float4(const Float4 &rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5535 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5536 | Value *value = rhs.loadValue(); |
| 5537 | storeValue(value); |
| 5538 | } |
| 5539 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5540 | Float4::Float4(const Reference<Float4> &rhs) : XYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5541 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5542 | Value *value = rhs.loadValue(); |
| 5543 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5544 | } |
| 5545 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5546 | Float4::Float4(RValue<Float> rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5547 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5548 | Value *vector = loadValue(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5549 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5550 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5551 | int swizzle[4] = {0, 0, 0, 0}; |
| 5552 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5553 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5554 | storeValue(replicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5555 | } |
| 5556 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5557 | Float4::Float4(const Float &rhs) : XYZW(this) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5558 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5559 | *this = RValue<Float>(rhs.loadValue()); |
| 5560 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5561 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5562 | Float4::Float4(const Reference<Float> &rhs) : XYZW(this) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5563 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5564 | *this = RValue<Float>(rhs.loadValue()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5565 | } |
| 5566 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5567 | RValue<Float4> Float4::operator=(float x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5568 | { |
| 5569 | return *this = Float4(x, x, x, x); |
| 5570 | } |
| 5571 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5572 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
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 | storeValue(rhs.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5575 | |
| 5576 | return rhs; |
| 5577 | } |
| 5578 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5579 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5580 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5581 | Value *value = rhs.loadValue(); |
| 5582 | storeValue(value); |
| 5583 | |
| 5584 | return RValue<Float4>(value); |
| 5585 | } |
| 5586 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5587 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5588 | { |
| 5589 | Value *value = rhs.loadValue(); |
| 5590 | storeValue(value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5591 | |
| 5592 | return RValue<Float4>(value); |
| 5593 | } |
| 5594 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5595 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5596 | { |
| 5597 | return *this = Float4(rhs); |
| 5598 | } |
| 5599 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5600 | RValue<Float4> Float4::operator=(const Float &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5601 | { |
| 5602 | return *this = Float4(rhs); |
| 5603 | } |
| 5604 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5605 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5606 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5607 | return *this = Float4(rhs); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5608 | } |
| 5609 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5610 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5611 | { |
| 5612 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5613 | } |
| 5614 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5615 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5616 | { |
| 5617 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5618 | } |
| 5619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5620 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5621 | { |
| 5622 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5623 | } |
| 5624 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5625 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5626 | { |
| 5627 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5628 | } |
| 5629 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5630 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5631 | { |
| 5632 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 5633 | } |
| 5634 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5635 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5636 | { |
| 5637 | return lhs = lhs + rhs; |
| 5638 | } |
| 5639 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5640 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5641 | { |
| 5642 | return lhs = lhs - rhs; |
| 5643 | } |
| 5644 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5645 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5646 | { |
| 5647 | return lhs = lhs * rhs; |
| 5648 | } |
| 5649 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5650 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5651 | { |
| 5652 | return lhs = lhs / rhs; |
| 5653 | } |
| 5654 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5655 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5656 | { |
| 5657 | return lhs = lhs % rhs; |
| 5658 | } |
| 5659 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5660 | RValue<Float4> operator+(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5661 | { |
| 5662 | return val; |
| 5663 | } |
| 5664 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5665 | RValue<Float4> operator-(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5666 | { |
| 5667 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 5668 | } |
| 5669 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5670 | RValue<Float4> Abs(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5671 | { |
| 5672 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5673 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 5674 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5675 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5676 | return As<Float4>(result); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5677 | } |
| 5678 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5679 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5680 | { |
| 5681 | return x86::maxps(x, y); |
| 5682 | } |
| 5683 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5684 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5685 | { |
| 5686 | return x86::minps(x, y); |
| 5687 | } |
| 5688 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 5689 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5690 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 5691 | #if defined(__i386__) || defined(__x86_64__) |
| 5692 | if(exactAtPow2) |
| 5693 | { |
| 5694 | // rcpps uses a piecewise-linear approximation which minimizes the relative error |
| 5695 | // but is not exact at power-of-two values. Rectify by multiplying by the inverse. |
| 5696 | return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); |
| 5697 | } |
| 5698 | #endif |
| 5699 | |
| 5700 | return x86::rcpps(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5701 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5702 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5703 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5704 | { |
| 5705 | return x86::rsqrtps(x); |
| 5706 | } |
| 5707 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5708 | RValue<Float4> Sqrt(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5709 | { |
| 5710 | return x86::sqrtps(x); |
| 5711 | } |
| 5712 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5713 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5714 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5715 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5716 | } |
| 5717 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5718 | RValue<Float> Extract(RValue<Float4> x, int i) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5719 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5720 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5721 | } |
| 5722 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5723 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5724 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5725 | return RValue<Float4>(createSwizzle4(x.value, select)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5726 | } |
| 5727 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5728 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5729 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5730 | int shuffle[4] = |
| 5731 | { |
| 5732 | ((imm >> 0) & 0x03) + 0, |
| 5733 | ((imm >> 2) & 0x03) + 0, |
| 5734 | ((imm >> 4) & 0x03) + 4, |
| 5735 | ((imm >> 6) & 0x03) + 4, |
| 5736 | }; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5737 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5738 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5739 | } |
| 5740 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5741 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5742 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5743 | int shuffle[4] = {0, 4, 1, 5}; |
| 5744 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5745 | } |
| 5746 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5747 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5748 | { |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 5749 | int shuffle[4] = {2, 6, 3, 7}; |
| 5750 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5751 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5752 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5753 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5754 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5755 | Value *vector = lhs.loadValue(); |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5756 | Value *result = createMask4(vector, rhs.value, select); |
| 5757 | lhs.storeValue(result); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5758 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5759 | return RValue<Float4>(result); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5760 | } |
| 5761 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5762 | RValue<Int> SignMask(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5763 | { |
| 5764 | return x86::movmskps(x); |
| 5765 | } |
| 5766 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5767 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5768 | { |
| 5769 | // return As<Int4>(x86::cmpeqps(x, y)); |
| 5770 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 5771 | } |
| 5772 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5773 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5774 | { |
| 5775 | // return As<Int4>(x86::cmpltps(x, y)); |
| 5776 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 5777 | } |
| 5778 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5779 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5780 | { |
| 5781 | // return As<Int4>(x86::cmpleps(x, y)); |
| 5782 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 5783 | } |
| 5784 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5785 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5786 | { |
| 5787 | // return As<Int4>(x86::cmpneqps(x, y)); |
| 5788 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 5789 | } |
| 5790 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5791 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5792 | { |
| 5793 | // return As<Int4>(x86::cmpnltps(x, y)); |
| 5794 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 5795 | } |
| 5796 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5797 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5798 | { |
| 5799 | // return As<Int4>(x86::cmpnleps(x, y)); |
| 5800 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 5801 | } |
| 5802 | |
Alexis Hetu | 8ef6d10 | 2017-11-09 15:49:09 -0500 | [diff] [blame] | 5803 | RValue<Int4> IsInf(RValue<Float4> x) |
| 5804 | { |
| 5805 | return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000)); |
| 5806 | } |
| 5807 | |
| 5808 | RValue<Int4> IsNan(RValue<Float4> x) |
| 5809 | { |
| 5810 | return ~CmpEQ(x, x); |
| 5811 | } |
| 5812 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5813 | RValue<Float4> Round(RValue<Float4> x) |
| 5814 | { |
| 5815 | if(CPUID::supportsSSE4_1()) |
| 5816 | { |
| 5817 | return x86::roundps(x, 0); |
| 5818 | } |
| 5819 | else |
| 5820 | { |
| 5821 | return Float4(RoundInt(x)); |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | RValue<Float4> Trunc(RValue<Float4> x) |
| 5826 | { |
| 5827 | if(CPUID::supportsSSE4_1()) |
| 5828 | { |
| 5829 | return x86::roundps(x, 3); |
| 5830 | } |
| 5831 | else |
| 5832 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5833 | return Float4(Int4(x)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5834 | } |
| 5835 | } |
| 5836 | |
| 5837 | RValue<Float4> Frac(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5838 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 5839 | Float4 frc; |
| 5840 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5841 | if(CPUID::supportsSSE4_1()) |
| 5842 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5843 | frc = x - Floor(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5844 | } |
| 5845 | else |
| 5846 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 5847 | frc = x - Float4(Int4(x)); // Signed fractional part. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5848 | |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 5849 | 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] | 5850 | } |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 5851 | |
| 5852 | // x - floor(x) can be 1.0 for very small negative x. |
| 5853 | // Clamp against the value just below 1.0. |
| 5854 | return Min(frc, As<Float4>(Int4(0x3F7FFFFF))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5855 | } |
| 5856 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5857 | RValue<Float4> Floor(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5858 | { |
| 5859 | if(CPUID::supportsSSE4_1()) |
| 5860 | { |
| 5861 | return x86::floorps(x); |
| 5862 | } |
| 5863 | else |
| 5864 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5865 | return x - Frac(x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5866 | } |
| 5867 | } |
| 5868 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5869 | RValue<Float4> Ceil(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5870 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5871 | if(CPUID::supportsSSE4_1()) |
| 5872 | { |
| 5873 | return x86::ceilps(x); |
| 5874 | } |
| 5875 | else |
| 5876 | { |
| 5877 | return -Floor(-x); |
| 5878 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5879 | } |
| 5880 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5881 | Type *Float4::getType() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5882 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5883 | return T(llvm::VectorType::get(T(Float::getType()), 4)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5884 | } |
| 5885 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 5886 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5887 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 5888 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5889 | } |
| 5890 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 5891 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5892 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 5893 | 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] | 5894 | } |
| 5895 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 5896 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5897 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 5898 | 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] | 5899 | } |
| 5900 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5901 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5902 | { |
| 5903 | return lhs = lhs + offset; |
| 5904 | } |
| 5905 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5906 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5907 | { |
| 5908 | return lhs = lhs + offset; |
| 5909 | } |
| 5910 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5911 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5912 | { |
| 5913 | return lhs = lhs + offset; |
| 5914 | } |
| 5915 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 5916 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5917 | { |
| 5918 | return lhs + -offset; |
| 5919 | } |
| 5920 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 5921 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5922 | { |
| 5923 | return lhs + -offset; |
| 5924 | } |
| 5925 | |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 5926 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5927 | { |
| 5928 | return lhs + -offset; |
| 5929 | } |
| 5930 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5931 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5932 | { |
| 5933 | return lhs = lhs - offset; |
| 5934 | } |
| 5935 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5936 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5937 | { |
| 5938 | return lhs = lhs - offset; |
| 5939 | } |
| 5940 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5941 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5942 | { |
| 5943 | return lhs = lhs - offset; |
| 5944 | } |
| 5945 | |
| 5946 | void Return() |
| 5947 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5948 | Nucleus::createRetVoid(); |
| 5949 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5950 | Nucleus::createUnreachable(); |
| 5951 | } |
| 5952 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 5953 | void Return(RValue<Int> ret) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5954 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 5955 | Nucleus::createRet(ret.value); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5956 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5957 | Nucleus::createUnreachable(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5958 | } |
| 5959 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 5960 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5961 | { |
| 5962 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5963 | Nucleus::setInsertBlock(bodyBB); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5964 | } |
| 5965 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5966 | RValue<Long> Ticks() |
| 5967 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5968 | llvm::Function *rdtsc = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::readcyclecounter); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5969 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 5970 | return RValue<Long>(V(::builder->CreateCall(rdtsc))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5971 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5972 | } |
| 5973 | |
| 5974 | namespace sw |
| 5975 | { |
| 5976 | namespace x86 |
| 5977 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5978 | RValue<Int> cvtss2si(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5979 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5980 | llvm::Function *cvtss2si = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse_cvtss2si); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5981 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5982 | Float4 vector; |
| 5983 | vector.x = val; |
| 5984 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 5985 | return RValue<Int>(V(::builder->CreateCall(cvtss2si, RValue<Float4>(vector).value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5986 | } |
| 5987 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5988 | RValue<Int4> cvtps2dq(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5989 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 5990 | llvm::Function *cvtps2dq = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_cvtps2dq); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5991 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 5992 | return RValue<Int4>(V(::builder->CreateCall(cvtps2dq, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5993 | } |
| 5994 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5995 | RValue<Float> rcpss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5996 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5997 | 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] | 5998 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 5999 | 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] | 6000 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6001 | 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] | 6002 | } |
| 6003 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6004 | RValue<Float> sqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6005 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6006 | 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] | 6007 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6008 | 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] | 6009 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6010 | 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] | 6011 | } |
| 6012 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6013 | RValue<Float> rsqrtss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6014 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6015 | 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] | 6016 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6017 | 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] | 6018 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6019 | 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] | 6020 | } |
| 6021 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6022 | RValue<Float4> rcpps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6023 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6024 | 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] | 6025 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6026 | return RValue<Float4>(V(::builder->CreateCall(rcpps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6027 | } |
| 6028 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6029 | RValue<Float4> sqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6030 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6031 | 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] | 6032 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6033 | return RValue<Float4>(V(::builder->CreateCall(sqrtps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6034 | } |
| 6035 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6036 | RValue<Float4> rsqrtps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6037 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6038 | 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] | 6039 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6040 | return RValue<Float4>(V(::builder->CreateCall(rsqrtps, val.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6041 | } |
| 6042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6043 | RValue<Float4> maxps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6044 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6045 | 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] | 6046 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6047 | return RValue<Float4>(V(::builder->CreateCall2(maxps, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6048 | } |
| 6049 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6050 | RValue<Float4> minps(RValue<Float4> x, RValue<Float4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6051 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6052 | 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] | 6053 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6054 | return RValue<Float4>(V(::builder->CreateCall2(minps, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6055 | } |
| 6056 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6057 | RValue<Float> roundss(RValue<Float> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6058 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6059 | 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] | 6060 | |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6061 | Value *undef = V(llvm::UndefValue::get(T(Float4::getType()))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6062 | Value *vector = Nucleus::createInsertElement(undef, val.value, 0); |
| 6063 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6064 | 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] | 6065 | } |
| 6066 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6067 | RValue<Float> floorss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6068 | { |
| 6069 | return roundss(val, 1); |
| 6070 | } |
| 6071 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6072 | RValue<Float> ceilss(RValue<Float> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6073 | { |
| 6074 | return roundss(val, 2); |
| 6075 | } |
| 6076 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6077 | RValue<Float4> roundps(RValue<Float4> val, unsigned char imm) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6078 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6079 | 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] | 6080 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6081 | 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] | 6082 | } |
| 6083 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6084 | RValue<Float4> floorps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6085 | { |
| 6086 | return roundps(val, 1); |
| 6087 | } |
| 6088 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6089 | RValue<Float4> ceilps(RValue<Float4> val) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6090 | { |
| 6091 | return roundps(val, 2); |
| 6092 | } |
| 6093 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 6094 | RValue<Int4> pabsd(RValue<Int4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6095 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6096 | 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] | 6097 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6098 | return RValue<Int4>(V(::builder->CreateCall(pabsd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6099 | } |
| 6100 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6101 | RValue<Short4> paddsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6102 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6103 | llvm::Function *paddsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_padds_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6104 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6105 | return As<Short4>(V(::builder->CreateCall2(paddsw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6106 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6107 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6108 | RValue<Short4> psubsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6109 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6110 | llvm::Function *psubsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6111 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6112 | return As<Short4>(V(::builder->CreateCall2(psubsw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6113 | } |
| 6114 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6115 | RValue<UShort4> paddusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6116 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6117 | llvm::Function *paddusw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_paddus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6118 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6119 | return As<UShort4>(V(::builder->CreateCall2(paddusw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6120 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6121 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6122 | RValue<UShort4> psubusw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6123 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6124 | llvm::Function *psubusw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubus_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6125 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6126 | return As<UShort4>(V(::builder->CreateCall2(psubusw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6127 | } |
| 6128 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6129 | RValue<SByte8> paddsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6130 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6131 | llvm::Function *paddsb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_padds_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6132 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6133 | return As<SByte8>(V(::builder->CreateCall2(paddsb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6134 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6136 | RValue<SByte8> psubsb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6137 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6138 | llvm::Function *psubsb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubs_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6139 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6140 | return As<SByte8>(V(::builder->CreateCall2(psubsb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6141 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6142 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6143 | RValue<Byte8> paddusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6144 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6145 | llvm::Function *paddusb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_paddus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6146 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6147 | return As<Byte8>(V(::builder->CreateCall2(paddusb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6148 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6149 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6150 | RValue<Byte8> psubusb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6151 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6152 | llvm::Function *psubusb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_psubus_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6153 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6154 | return As<Byte8>(V(::builder->CreateCall2(psubusb, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | RValue<UShort4> pavgw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6158 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6159 | llvm::Function *pavgw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pavg_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6160 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6161 | return As<UShort4>(V(::builder->CreateCall2(pavgw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6162 | } |
| 6163 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6164 | RValue<Short4> pmaxsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6165 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6166 | llvm::Function *pmaxsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmaxs_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6167 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6168 | return As<Short4>(V(::builder->CreateCall2(pmaxsw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6169 | } |
| 6170 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6171 | RValue<Short4> pminsw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6172 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6173 | llvm::Function *pminsw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmins_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6174 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6175 | return As<Short4>(V(::builder->CreateCall2(pminsw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6176 | } |
| 6177 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6178 | RValue<Short4> pcmpgtw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6179 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6180 | llvm::Function *pcmpgtw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpgt_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6181 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6182 | return As<Short4>(V(::builder->CreateCall2(pcmpgtw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6183 | } |
| 6184 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6185 | RValue<Short4> pcmpeqw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6186 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6187 | llvm::Function *pcmpeqw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpeq_w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6188 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6189 | return As<Short4>(V(::builder->CreateCall2(pcmpeqw, x.value, y.value))); |
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<Byte8> pcmpgtb(RValue<SByte8> x, RValue<SByte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6193 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6194 | llvm::Function *pcmpgtb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpgt_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6195 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6196 | return As<Byte8>(V(::builder->CreateCall2(pcmpgtb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6197 | } |
| 6198 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6199 | RValue<Byte8> pcmpeqb(RValue<Byte8> x, RValue<Byte8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6200 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6201 | llvm::Function *pcmpeqb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pcmpeq_b); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6202 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6203 | return As<Byte8>(V(::builder->CreateCall2(pcmpeqb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6206 | RValue<Short4> packssdw(RValue<Int2> x, RValue<Int2> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6207 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6208 | 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] | 6209 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6210 | return As<Short4>(V(::builder->CreateCall2(packssdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6211 | } |
| 6212 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6213 | RValue<Short8> packssdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6214 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6215 | 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] | 6216 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6217 | return RValue<Short8>(V(::builder->CreateCall2(packssdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6218 | } |
| 6219 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6220 | RValue<SByte8> packsswb(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6221 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6222 | llvm::Function *packsswb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packsswb_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6223 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6224 | return As<SByte8>(V(::builder->CreateCall2(packsswb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6225 | } |
| 6226 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6227 | RValue<Byte8> packuswb(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6228 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6229 | llvm::Function *packuswb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_packuswb_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6230 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6231 | return As<Byte8>(V(::builder->CreateCall2(packuswb, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6232 | } |
| 6233 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 6234 | RValue<UShort8> packusdw(RValue<Int4> x, RValue<Int4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6235 | { |
| 6236 | if(CPUID::supportsSSE4_1()) |
| 6237 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6238 | llvm::Function *packusdw = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_packusdw); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6239 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6240 | return RValue<UShort8>(V(::builder->CreateCall2(packusdw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6241 | } |
| 6242 | else |
| 6243 | { |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 6244 | RValue<Int4> bx = (x & ~(x >> 31)) - Int4(0x8000); |
| 6245 | RValue<Int4> by = (y & ~(y >> 31)) - Int4(0x8000); |
| 6246 | |
| 6247 | return As<UShort8>(packssdw(bx, by) + Short8(0x8000u)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6248 | } |
| 6249 | } |
| 6250 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6251 | RValue<UShort4> psrlw(RValue<UShort4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6252 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6253 | 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] | 6254 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6255 | return As<UShort4>(V(::builder->CreateCall2(psrlw, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6256 | } |
| 6257 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6258 | RValue<UShort8> psrlw(RValue<UShort8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6259 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6260 | 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] | 6261 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6262 | 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] | 6263 | } |
| 6264 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6265 | RValue<Short4> psraw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6266 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6267 | 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] | 6268 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6269 | return As<Short4>(V(::builder->CreateCall2(psraw, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6270 | } |
| 6271 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6272 | RValue<Short8> psraw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6273 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6274 | 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] | 6275 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6276 | 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] | 6277 | } |
| 6278 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6279 | RValue<Short4> psllw(RValue<Short4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6280 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6281 | 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] | 6282 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6283 | return As<Short4>(V(::builder->CreateCall2(psllw, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6284 | } |
| 6285 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6286 | RValue<Short8> psllw(RValue<Short8> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6287 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6288 | 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] | 6289 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6290 | 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] | 6291 | } |
| 6292 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6293 | RValue<Int2> pslld(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6294 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6295 | 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] | 6296 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6297 | return As<Int2>(V(::builder->CreateCall2(pslld, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6298 | } |
| 6299 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6300 | RValue<Int4> pslld(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6301 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6302 | 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] | 6303 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6304 | 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] | 6305 | } |
| 6306 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6307 | RValue<Int2> psrad(RValue<Int2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6308 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6309 | 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] | 6310 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6311 | return As<Int2>(V(::builder->CreateCall2(psrad, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6312 | } |
| 6313 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6314 | RValue<Int4> psrad(RValue<Int4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6315 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6316 | 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] | 6317 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6318 | 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] | 6319 | } |
| 6320 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6321 | RValue<UInt2> psrld(RValue<UInt2> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6322 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6323 | 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] | 6324 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6325 | return As<UInt2>(V(::builder->CreateCall2(psrld, x.value, V(Nucleus::createConstantInt(y))))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6326 | } |
| 6327 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6328 | RValue<UInt4> psrld(RValue<UInt4> x, unsigned char y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6329 | { |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6330 | 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] | 6331 | |
Nicolas Capens | 9e013d4 | 2017-07-28 17:26:14 -0400 | [diff] [blame] | 6332 | 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] | 6333 | } |
| 6334 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6335 | RValue<Int4> pmaxsd(RValue<Int4> x, RValue<Int4> y) |
| 6336 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6337 | llvm::Function *pmaxsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmaxsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6338 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6339 | return RValue<Int4>(V(::builder->CreateCall2(pmaxsd, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | RValue<Int4> pminsd(RValue<Int4> x, RValue<Int4> y) |
| 6343 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6344 | llvm::Function *pminsd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pminsd); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6345 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6346 | return RValue<Int4>(V(::builder->CreateCall2(pminsd, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | RValue<UInt4> pmaxud(RValue<UInt4> x, RValue<UInt4> y) |
| 6350 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6351 | llvm::Function *pmaxud = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmaxud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6352 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6353 | return RValue<UInt4>(V(::builder->CreateCall2(pmaxud, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | RValue<UInt4> pminud(RValue<UInt4> x, RValue<UInt4> y) |
| 6357 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6358 | llvm::Function *pminud = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pminud); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6359 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6360 | return RValue<UInt4>(V(::builder->CreateCall2(pminud, x.value, y.value))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6361 | } |
| 6362 | |
| 6363 | RValue<Short4> pmulhw(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6364 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6365 | 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] | 6366 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6367 | return As<Short4>(V(::builder->CreateCall2(pmulhw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6368 | } |
| 6369 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6370 | RValue<UShort4> pmulhuw(RValue<UShort4> x, RValue<UShort4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6371 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6372 | 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] | 6373 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6374 | return As<UShort4>(V(::builder->CreateCall2(pmulhuw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6375 | } |
| 6376 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6377 | RValue<Int2> pmaddwd(RValue<Short4> x, RValue<Short4> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6378 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6379 | 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] | 6380 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6381 | return As<Int2>(V(::builder->CreateCall2(pmaddwd, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6382 | } |
| 6383 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6384 | RValue<Short8> pmulhw(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6385 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6386 | 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] | 6387 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6388 | return RValue<Short8>(V(::builder->CreateCall2(pmulhw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6389 | } |
| 6390 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6391 | RValue<UShort8> pmulhuw(RValue<UShort8> x, RValue<UShort8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6392 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6393 | 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] | 6394 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6395 | return RValue<UShort8>(V(::builder->CreateCall2(pmulhuw, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6396 | } |
| 6397 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6398 | RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6399 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6400 | 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] | 6401 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6402 | return RValue<Int4>(V(::builder->CreateCall2(pmaddwd, x.value, y.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6403 | } |
| 6404 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6405 | RValue<Int> movmskps(RValue<Float4> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6406 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6407 | 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] | 6408 | |
Nicolas Capens | 2ab69ee | 2016-09-26 11:45:17 -0400 | [diff] [blame] | 6409 | return RValue<Int>(V(::builder->CreateCall(movmskps, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6410 | } |
| 6411 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6412 | RValue<Int> pmovmskb(RValue<Byte8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6413 | { |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6414 | llvm::Function *pmovmskb = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse2_pmovmskb_128); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6415 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6416 | return RValue<Int>(V(::builder->CreateCall(pmovmskb, x.value))) & 0xFF; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6417 | } |
| 6418 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6419 | RValue<Int4> pmovzxbd(RValue<Byte16> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6420 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6421 | llvm::Function *pmovzxbd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovzxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6422 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6423 | return RValue<Int4>(V(::builder->CreateCall(pmovzxbd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6424 | } |
| 6425 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6426 | RValue<Int4> pmovsxbd(RValue<SByte16> x) |
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 *pmovsxbd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovsxbd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6429 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6430 | return RValue<Int4>(V(::builder->CreateCall(pmovsxbd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6431 | } |
| 6432 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6433 | RValue<Int4> pmovzxwd(RValue<UShort8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6434 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6435 | llvm::Function *pmovzxwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovzxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6436 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6437 | return RValue<Int4>(V(::builder->CreateCall(pmovzxwd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6438 | } |
| 6439 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6440 | RValue<Int4> pmovsxwd(RValue<Short8> x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6441 | { |
Nicolas Capens | fbf2bc5 | 2017-07-26 17:26:17 -0400 | [diff] [blame] | 6442 | llvm::Function *pmovsxwd = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::x86_sse41_pmovsxwd); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6443 | |
Nicolas Capens | 01a9796 | 2017-07-28 17:30:51 -0400 | [diff] [blame] | 6444 | return RValue<Int4>(V(::builder->CreateCall(pmovsxwd, x.value))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6445 | } |
| 6446 | } |
| 6447 | } |