Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 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 |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 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. |
| 14 | |
| 15 | #include "Nucleus.hpp" |
| 16 | |
| 17 | #include "Reactor.hpp" |
| 18 | #include "Routine.hpp" |
| 19 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 20 | #include "Optimizer.hpp" |
| 21 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 22 | #include "src/IceTypes.h" |
| 23 | #include "src/IceCfg.h" |
| 24 | #include "src/IceELFStreamer.h" |
| 25 | #include "src/IceGlobalContext.h" |
| 26 | #include "src/IceCfgNode.h" |
| 27 | #include "src/IceELFObjectWriter.h" |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 28 | #include "src/IceGlobalInits.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 29 | |
| 30 | #include "llvm/Support/FileSystem.h" |
| 31 | #include "llvm/Support/raw_os_ostream.h" |
| 32 | |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 33 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 34 | #define WIN32_LEAN_AND_MEAN |
| 35 | #define NOMINMAX |
| 36 | #include <Windows.h> |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 37 | #else |
| 38 | #include <sys/mman.h> |
| 39 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 40 | |
| 41 | #include <mutex> |
| 42 | #include <limits> |
| 43 | #include <iostream> |
| 44 | #include <cassert> |
| 45 | |
| 46 | namespace |
| 47 | { |
| 48 | Ice::GlobalContext *context = nullptr; |
| 49 | Ice::Cfg *function = nullptr; |
| 50 | Ice::CfgNode *basicBlock = nullptr; |
| 51 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
| 52 | sw::Routine *routine = nullptr; |
| 53 | |
| 54 | std::mutex codegenMutex; |
| 55 | |
| 56 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 57 | Ice::Fdstream *out = nullptr; |
| 58 | } |
| 59 | |
| 60 | namespace sw |
| 61 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 62 | enum EmulatedType |
| 63 | { |
| 64 | EmulatedShift = 16, |
| 65 | EmulatedV2 = 2 << EmulatedShift, |
| 66 | EmulatedV4 = 4 << EmulatedShift, |
| 67 | EmulatedV8 = 8 << EmulatedShift, |
| 68 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 69 | |
| 70 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 71 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 72 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 73 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 74 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 75 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 78 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 79 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 80 | class BasicBlock : public Ice::CfgNode {}; |
| 81 | |
| 82 | Ice::Type T(Type *t) |
| 83 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 84 | static_assert(Ice::IceType_NUM < EmulatedBits, "Ice::Type overlaps with our emulated types!"); |
| 85 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | Type *T(Ice::Type t) |
| 89 | { |
| 90 | return reinterpret_cast<Type*>(t); |
| 91 | } |
| 92 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 93 | Type *T(EmulatedType t) |
| 94 | { |
| 95 | return reinterpret_cast<Type*>(t); |
| 96 | } |
| 97 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 98 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 99 | { |
| 100 | return reinterpret_cast<Value*>(v); |
| 101 | } |
| 102 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 103 | BasicBlock *B(Ice::CfgNode *b) |
| 104 | { |
| 105 | return reinterpret_cast<BasicBlock*>(b); |
| 106 | } |
| 107 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 108 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 109 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 110 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 111 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 112 | |
| 113 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 114 | { |
| 115 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 116 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 117 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 118 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 119 | { |
| 120 | return §ionHeader(elfHeader)[index]; |
| 121 | } |
| 122 | |
| 123 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 124 | { |
| 125 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 126 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 127 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 128 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 129 | uint32_t index = relocation.getSymbol(); |
| 130 | int table = relocationTable.sh_link; |
| 131 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 132 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 133 | if(index != SHN_UNDEF) |
| 134 | { |
| 135 | if(table == SHN_UNDEF) return nullptr; |
| 136 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 137 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 138 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 139 | if(index >= symtab_entries) |
| 140 | { |
| 141 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 142 | return nullptr; |
| 143 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 144 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 145 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 146 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 147 | uint16_t section = symbol.st_shndx; |
| 148 | |
| 149 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 150 | { |
| 151 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 152 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | return nullptr; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | switch(relocation.getType()) |
| 161 | { |
| 162 | case R_386_NONE: |
| 163 | // No relocation |
| 164 | break; |
| 165 | case R_386_32: |
| 166 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 167 | break; |
| 168 | // case R_386_PC32: |
| 169 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 170 | // break; |
| 171 | default: |
| 172 | assert(false && "Unsupported relocation type"); |
| 173 | return nullptr; |
| 174 | } |
| 175 | |
| 176 | return symbolValue; |
| 177 | } |
| 178 | |
| 179 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 180 | { |
| 181 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 182 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 183 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 184 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 185 | uint32_t index = relocation.getSymbol(); |
| 186 | int table = relocationTable.sh_link; |
| 187 | void *symbolValue = nullptr; |
| 188 | |
| 189 | if(index != SHN_UNDEF) |
| 190 | { |
| 191 | if(table == SHN_UNDEF) return nullptr; |
| 192 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 193 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 194 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 195 | if(index >= symtab_entries) |
| 196 | { |
| 197 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 198 | return nullptr; |
| 199 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 200 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 201 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 202 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 203 | uint16_t section = symbol.st_shndx; |
| 204 | |
| 205 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 206 | { |
| 207 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 208 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | return nullptr; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | switch(relocation.getType()) |
| 217 | { |
| 218 | case R_X86_64_NONE: |
| 219 | // No relocation |
| 220 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 221 | case R_X86_64_64: |
| 222 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 223 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 224 | case R_X86_64_PC32: |
| 225 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 226 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 227 | case R_X86_64_32S: |
| 228 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 229 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 230 | default: |
| 231 | assert(false && "Unsupported relocation type"); |
| 232 | return nullptr; |
| 233 | } |
| 234 | |
| 235 | return symbolValue; |
| 236 | } |
| 237 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 238 | void *loadImage(uint8_t *const elfImage) |
| 239 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 240 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 241 | |
| 242 | if(!elfHeader->checkMagic()) |
| 243 | { |
| 244 | return nullptr; |
| 245 | } |
| 246 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 247 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 248 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 249 | assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386); |
| 250 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 251 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 252 | void *entry = nullptr; |
| 253 | |
| 254 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 255 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 256 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 257 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 258 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 259 | { |
| 260 | entry = elfImage + sectionHeader[i].sh_offset; |
| 261 | } |
| 262 | } |
| 263 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 264 | { |
| 265 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 266 | |
| 267 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 268 | { |
| 269 | const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 270 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 271 | } |
| 272 | } |
| 273 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 274 | { |
| 275 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 276 | |
| 277 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 278 | { |
| 279 | const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 280 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 281 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | return entry; |
| 286 | } |
| 287 | |
| 288 | template<typename T> |
| 289 | struct ExecutableAllocator |
| 290 | { |
| 291 | ExecutableAllocator() {}; |
| 292 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 293 | |
| 294 | using value_type = T; |
| 295 | using size_type = std::size_t; |
| 296 | |
| 297 | T *allocate(size_type n) |
| 298 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 299 | #if defined(_WIN32) |
| 300 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 301 | #else |
| 302 | return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 303 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void deallocate(T *p, size_type n) |
| 307 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 308 | #if defined(_WIN32) |
| 309 | VirtualFree(p, 0, MEM_RELEASE); |
| 310 | #else |
| 311 | munmap(p, sizeof(T) * n); |
| 312 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 313 | } |
| 314 | }; |
| 315 | |
| 316 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 317 | { |
| 318 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 319 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 320 | |
| 321 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 322 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 323 | { |
| 324 | position = 0; |
| 325 | buffer.reserve(0x1000); |
| 326 | } |
| 327 | |
| 328 | virtual ~ELFMemoryStreamer() |
| 329 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 330 | #if defined(_WIN32) |
| 331 | if(buffer.size() != 0) |
| 332 | { |
| 333 | DWORD exeProtection; |
| 334 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 335 | } |
| 336 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void write8(uint8_t Value) override |
| 340 | { |
| 341 | if(position == (uint64_t)buffer.size()) |
| 342 | { |
| 343 | buffer.push_back(Value); |
| 344 | position++; |
| 345 | } |
| 346 | else if(position < (uint64_t)buffer.size()) |
| 347 | { |
| 348 | buffer[position] = Value; |
| 349 | position++; |
| 350 | } |
| 351 | else assert(false && "UNIMPLEMENTED"); |
| 352 | } |
| 353 | |
| 354 | void writeBytes(llvm::StringRef Bytes) override |
| 355 | { |
| 356 | std::size_t oldSize = buffer.size(); |
| 357 | buffer.resize(oldSize + Bytes.size()); |
| 358 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 359 | position += Bytes.size(); |
| 360 | } |
| 361 | |
| 362 | uint64_t tell() const override { return position; } |
| 363 | |
| 364 | void seek(uint64_t Off) override { position = Off; } |
| 365 | |
| 366 | const void *getEntry() override |
| 367 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 368 | if(!entry) |
| 369 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 370 | #if defined(_WIN32) |
| 371 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection); |
| 372 | #else |
| 373 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_WRITE | PROT_EXEC); |
| 374 | #endif |
| 375 | |
| 376 | position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 377 | |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 378 | entry = loadImage(&buffer[0]); |
| 379 | } |
| 380 | |
| 381 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 385 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 386 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 387 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 388 | |
| 389 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 390 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 391 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 392 | }; |
| 393 | |
| 394 | Nucleus::Nucleus() |
| 395 | { |
| 396 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 397 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 398 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 399 | Ice::ClFlags::getParsedClFlags(Flags); |
| 400 | |
| 401 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 402 | Flags.setOutFileType(Ice::FT_Elf); |
| 403 | Flags.setOptLevel(Ice::Opt_2); |
| 404 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 405 | Flags.setTargetInstructionSet(Ice::X86InstructionSet_SSE4_1); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 406 | Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 407 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 408 | static llvm::raw_os_ostream cout(std::cout); |
| 409 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 410 | |
| 411 | if(false) // Write out to a file |
| 412 | { |
| 413 | std::error_code errorCode; |
| 414 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 415 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 416 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 417 | } |
| 418 | else |
| 419 | { |
| 420 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 421 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 422 | ::routine = elfMemory; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | Nucleus::~Nucleus() |
| 427 | { |
| 428 | delete ::allocator; |
| 429 | delete ::function; |
| 430 | delete ::context; |
| 431 | |
| 432 | delete ::elfFile; |
| 433 | delete ::out; |
| 434 | |
| 435 | ::codegenMutex.unlock(); |
| 436 | } |
| 437 | |
| 438 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 439 | { |
| 440 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 441 | { |
| 442 | createRetVoid(); |
| 443 | } |
| 444 | |
| 445 | std::wstring wideName(name); |
| 446 | std::string asciiName(wideName.begin(), wideName.end()); |
| 447 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 448 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 449 | optimize(); |
| 450 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 451 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 452 | assert(!::function->hasError()); |
| 453 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 454 | auto *globals = ::function->getGlobalInits().release(); |
| 455 | |
| 456 | if(globals && !globals->empty()) |
| 457 | { |
| 458 | ::context->getGlobals()->merge(globals); |
| 459 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 460 | |
| 461 | ::context->emitFileHeader(); |
| 462 | ::function->emitIAS(); |
| 463 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 464 | auto objectWriter = ::context->getObjectWriter(); |
| 465 | assembler->alignFunction(); |
| 466 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 467 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 468 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 469 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 470 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 471 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 472 | |
| 473 | return ::routine; |
| 474 | } |
| 475 | |
| 476 | void Nucleus::optimize() |
| 477 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 478 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 482 | { |
| 483 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 484 | int typeSize = Ice::typeWidthInBytes(type); |
| 485 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 486 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 487 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 488 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 489 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 490 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 491 | |
| 492 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | BasicBlock *Nucleus::createBasicBlock() |
| 496 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 497 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | BasicBlock *Nucleus::getInsertBlock() |
| 501 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 502 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 506 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 507 | // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator"); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 508 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 511 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 512 | { |
| 513 | uint32_t sequenceNumber = 0; |
| 514 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 515 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 516 | |
| 517 | for(Type *type : Params) |
| 518 | { |
| 519 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 520 | ::function->addArg(arg); |
| 521 | } |
| 522 | |
| 523 | Ice::CfgNode *node = ::function->makeNode(); |
| 524 | ::function->setEntryNode(node); |
| 525 | ::basicBlock = node; |
| 526 | } |
| 527 | |
| 528 | Value *Nucleus::getArgument(unsigned int index) |
| 529 | { |
| 530 | return V(::function->getArgs()[index]); |
| 531 | } |
| 532 | |
| 533 | void Nucleus::createRetVoid() |
| 534 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 535 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 536 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | void Nucleus::createRet(Value *v) |
| 540 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 541 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 542 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void Nucleus::createBr(BasicBlock *dest) |
| 546 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 547 | auto br = Ice::InstBr::create(::function, dest); |
| 548 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 552 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 553 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 554 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 555 | } |
| 556 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 557 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 558 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 559 | assert(lhs->getType() == rhs->getType() || (llvm::isa<Ice::Constant>(rhs) && (op == Ice::InstArithmetic::Shl || Ice::InstArithmetic::Lshr || Ice::InstArithmetic::Ashr))); |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 560 | |
| 561 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
| 562 | Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs); |
| 563 | ::basicBlock->appendInst(arithmetic); |
| 564 | |
| 565 | return V(result); |
| 566 | } |
| 567 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 568 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 569 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 570 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 574 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 575 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 579 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 580 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 584 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 585 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 589 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 590 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 594 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 595 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 599 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 600 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 604 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 605 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 609 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 610 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 614 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 615 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 619 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 620 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 624 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 625 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 629 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 630 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 634 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 635 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 639 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 640 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 644 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 645 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 649 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 650 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 654 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 655 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 658 | static Ice::Variable *createAssign(Ice::Operand *constant) |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 659 | { |
| 660 | Ice::Variable *value = ::function->makeVariable(constant->getType()); |
| 661 | auto assign = Ice::InstAssign::create(::function, value, constant); |
| 662 | ::basicBlock->appendInst(assign); |
| 663 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 664 | return value; |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 665 | } |
| 666 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 667 | Value *Nucleus::createNeg(Value *v) |
| 668 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 669 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | Value *Nucleus::createFNeg(Value *v) |
| 673 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 674 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 675 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 676 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 677 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 678 | |
| 679 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | Value *Nucleus::createNot(Value *v) |
| 683 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 684 | if(Ice::isScalarIntegerType(v->getType())) |
| 685 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 686 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 687 | } |
| 688 | else // Vector |
| 689 | { |
| 690 | int64_t c[4] = {-1, -1, -1, -1}; |
| 691 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 692 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 693 | } |
| 694 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 695 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 696 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 697 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 698 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 699 | |
| 700 | if(valueType & EmulatedBits) |
| 701 | { |
| 702 | switch(valueType) |
| 703 | { |
| 704 | case Type_v4i8: |
| 705 | case Type_v2i16: |
| 706 | { |
| 707 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 708 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 709 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 710 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 711 | load->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 712 | ::basicBlock->appendInst(load); |
| 713 | } |
| 714 | break; |
| 715 | case Type_v2i32: |
| 716 | case Type_v8i8: |
| 717 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 718 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 719 | { |
| 720 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 721 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 722 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 723 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 724 | load->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 725 | ::basicBlock->appendInst(load); |
| 726 | } |
| 727 | break; |
| 728 | default: assert(false && "UNIMPLEMENTED"); |
| 729 | } |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 734 | ::basicBlock->appendInst(load); |
| 735 | } |
| 736 | |
| 737 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 738 | } |
| 739 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 740 | Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 741 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 742 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 743 | |
| 744 | if(valueType & EmulatedBits) |
| 745 | { |
| 746 | switch(valueType) |
| 747 | { |
| 748 | case Type_v4i8: |
| 749 | case Type_v2i16: |
| 750 | { |
| 751 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 752 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 753 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 754 | store->addArg(value); |
| 755 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 756 | store->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 757 | ::basicBlock->appendInst(store); |
| 758 | } |
| 759 | break; |
| 760 | case Type_v2i32: |
| 761 | case Type_v8i8: |
| 762 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 763 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 764 | { |
| 765 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 766 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 767 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 768 | store->addArg(value); |
| 769 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 770 | store->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 771 | ::basicBlock->appendInst(store); |
| 772 | } |
| 773 | break; |
| 774 | default: assert(false && "UNIMPLEMENTED"); |
| 775 | } |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | assert(T(value->getType()) == type); |
| 780 | |
| 781 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 782 | ::basicBlock->appendInst(store); |
| 783 | } |
| 784 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 785 | return value; |
| 786 | } |
| 787 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 788 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 789 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 790 | assert(index->getType() == Ice::IceType_i32); |
| 791 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 792 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 793 | { |
| 794 | int32_t offset = constant->getValue() * (int)Ice::typeWidthInBytes(T(type)); |
| 795 | |
| 796 | if(offset == 0) |
| 797 | { |
| 798 | return ptr; |
| 799 | } |
| 800 | |
| 801 | return createAdd(ptr, createConstantInt(offset)); |
| 802 | } |
| 803 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 804 | if(!Ice::isByteSizedType(T(type))) |
| 805 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 806 | index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type)))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | if(sizeof(void*) == 8) |
| 810 | { |
| 811 | index = createSExt(index, T(Ice::IceType_i64)); |
| 812 | } |
| 813 | |
| 814 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 818 | { |
| 819 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 820 | } |
| 821 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 822 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 823 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 824 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 825 | { |
| 826 | return v; |
| 827 | } |
| 828 | |
| 829 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 830 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 831 | ::basicBlock->appendInst(cast); |
| 832 | |
| 833 | return V(result); |
| 834 | } |
| 835 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 836 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 837 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 838 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 842 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 843 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 847 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 848 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 852 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 853 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 854 | } |
| 855 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 856 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 857 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 858 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 862 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 863 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 867 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 868 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 872 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 873 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 874 | } |
| 875 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 876 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 877 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 878 | assert(lhs->getType() == rhs->getType()); |
| 879 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 880 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 881 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 882 | ::basicBlock->appendInst(cmp); |
| 883 | |
| 884 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 885 | } |
| 886 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 887 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 888 | { |
| 889 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 890 | } |
| 891 | |
| 892 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 893 | { |
| 894 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 895 | } |
| 896 | |
| 897 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 898 | { |
| 899 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 900 | } |
| 901 | |
| 902 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 903 | { |
| 904 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 905 | } |
| 906 | |
| 907 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 908 | { |
| 909 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 910 | } |
| 911 | |
| 912 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 913 | { |
| 914 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 915 | } |
| 916 | |
| 917 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 918 | { |
| 919 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 920 | } |
| 921 | |
| 922 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 923 | { |
| 924 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 925 | } |
| 926 | |
| 927 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 928 | { |
| 929 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 930 | } |
| 931 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 932 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 933 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 934 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 935 | } |
| 936 | |
| 937 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 938 | { |
| 939 | assert(lhs->getType() == rhs->getType()); |
| 940 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 941 | |
| 942 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 943 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 944 | ::basicBlock->appendInst(cmp); |
| 945 | |
| 946 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 950 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 951 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 955 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 956 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 960 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 961 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 965 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 966 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 970 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 971 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 975 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 976 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 980 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 981 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 985 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 986 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 990 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 991 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 995 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 996 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1000 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1001 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1005 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1006 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1010 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1011 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1015 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1016 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1019 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1020 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1021 | auto result = ::function->makeVariable(T(type)); |
| 1022 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1023 | ::basicBlock->appendInst(extract); |
| 1024 | |
| 1025 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1029 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1030 | auto result = ::function->makeVariable(vector->getType()); |
| 1031 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1032 | ::basicBlock->appendInst(insert); |
| 1033 | |
| 1034 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1037 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1038 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1039 | assert(V1->getType() == V2->getType()); |
| 1040 | |
| 1041 | int size = Ice::typeNumElements(V1->getType()); |
| 1042 | auto result = ::function->makeVariable(V1->getType()); |
| 1043 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1044 | |
| 1045 | for(int i = 0; i < size; i++) |
| 1046 | { |
| 1047 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1048 | } |
| 1049 | |
| 1050 | ::basicBlock->appendInst(shuffle); |
| 1051 | |
| 1052 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1056 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1057 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1058 | |
| 1059 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1060 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1061 | ::basicBlock->appendInst(select); |
| 1062 | |
| 1063 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1064 | } |
| 1065 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1066 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1067 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1068 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1069 | ::basicBlock->appendInst(switchInst); |
| 1070 | |
| 1071 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1074 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1075 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1076 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | void Nucleus::createUnreachable() |
| 1080 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1081 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1082 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1085 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1086 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1087 | int swizzle[4] = |
| 1088 | { |
| 1089 | (select >> 0) & 0x03, |
| 1090 | (select >> 2) & 0x03, |
| 1091 | (select >> 4) & 0x03, |
| 1092 | (select >> 6) & 0x03, |
| 1093 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1094 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1095 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1096 | } |
| 1097 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1098 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1099 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1100 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1101 | |
| 1102 | mask[(select >> 0) & 0x03] = -1; |
| 1103 | mask[(select >> 2) & 0x03] = -1; |
| 1104 | mask[(select >> 4) & 0x03] = -1; |
| 1105 | mask[(select >> 6) & 0x03] = -1; |
| 1106 | |
| 1107 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1108 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1109 | |
| 1110 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1113 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1114 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1115 | if(sizeof(void*) == 8) |
| 1116 | { |
| 1117 | return T(Ice::IceType_i64); |
| 1118 | } |
| 1119 | else |
| 1120 | { |
| 1121 | return T(Ice::IceType_i32); |
| 1122 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1125 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1126 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1127 | if(Ice::isVectorType(T(Ty))) |
| 1128 | { |
| 1129 | int64_t c[4] = {0, 0, 0, 0}; |
| 1130 | return createConstantVector(c, Ty); |
| 1131 | } |
| 1132 | else |
| 1133 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1134 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1135 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1138 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1139 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1140 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1143 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1144 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1145 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1146 | } |
| 1147 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1148 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1149 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1150 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1151 | } |
| 1152 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1153 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1154 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1155 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1158 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1159 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1160 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1163 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1164 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1165 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1168 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1169 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1170 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1173 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1174 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1175 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1178 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1179 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1180 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1183 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1184 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1185 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1188 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1189 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1190 | const int vectorSize = 16; |
| 1191 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1192 | const int alignment = vectorSize; |
| 1193 | auto globalPool = ::function->getGlobalPool(); |
| 1194 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1195 | const int64_t *i = constants; |
| 1196 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1197 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1198 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1199 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1200 | { |
| 1201 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1202 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1203 | { |
| 1204 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1205 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1206 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1207 | } |
| 1208 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1209 | case Ice::IceType_v4f32: |
| 1210 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1211 | const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1212 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1213 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1214 | } |
| 1215 | break; |
| 1216 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1217 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1218 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1219 | const short initializer[8] = {(short)i[0], (short)i[1], (short)i[2], (short)i[3], (short)i[4], (short)i[5], (short)i[6], (short)i[7]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1220 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1221 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1222 | } |
| 1223 | break; |
| 1224 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1225 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1226 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1227 | const char initializer[16] = {(char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[4], (char)i[5], (char)i[6], (char)i[7], (char)i[8], (char)i[9], (char)i[10], (char)i[11], (char)i[12], (char)i[13], (char)i[14], (char)i[15]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1228 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1229 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1230 | } |
| 1231 | break; |
| 1232 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1233 | { |
| 1234 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1235 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1236 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1237 | } |
| 1238 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1239 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1240 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1241 | const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1242 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1243 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1244 | } |
| 1245 | break; |
| 1246 | case Type_v4i16: |
| 1247 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1248 | const short initializer[8] = {(short)i[0], (short)i[1], (short)i[2], (short)i[3], (short)i[0], (short)i[1], (short)i[2], (short)i[3]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1249 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1250 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1251 | } |
| 1252 | break; |
| 1253 | case Type_v8i8: |
| 1254 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1255 | const char initializer[16] = {(char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[4], (char)i[5], (char)i[6], (char)i[7], (char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[4], (char)i[5], (char)i[6], (char)i[7]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1256 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1257 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1258 | } |
| 1259 | break; |
| 1260 | case Type_v4i8: |
| 1261 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1262 | const char initializer[16] = {(char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[0], (char)i[1], (char)i[2], (char)i[3]}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1263 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1264 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1265 | } |
| 1266 | break; |
| 1267 | default: |
| 1268 | assert(false && "Unknown constant vector type" && type); |
| 1269 | } |
| 1270 | |
| 1271 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1272 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1273 | variableDeclaration->setName(name); |
| 1274 | variableDeclaration->setAlignment(alignment); |
| 1275 | variableDeclaration->setIsConstant(true); |
| 1276 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1277 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1278 | ::function->addGlobal(variableDeclaration); |
| 1279 | |
| 1280 | constexpr int32_t offset = 0; |
| 1281 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1282 | |
| 1283 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1284 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1285 | ::basicBlock->appendInst(load); |
| 1286 | |
| 1287 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1291 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1292 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | Type *Void::getType() |
| 1296 | { |
| 1297 | return T(Ice::IceType_void); |
| 1298 | } |
| 1299 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1300 | Bool::Bool(Argument<Bool> argument) |
| 1301 | { |
| 1302 | storeValue(argument.value); |
| 1303 | } |
| 1304 | |
| 1305 | Bool::Bool() |
| 1306 | { |
| 1307 | } |
| 1308 | |
| 1309 | Bool::Bool(bool x) |
| 1310 | { |
| 1311 | storeValue(Nucleus::createConstantBool(x)); |
| 1312 | } |
| 1313 | |
| 1314 | Bool::Bool(RValue<Bool> rhs) |
| 1315 | { |
| 1316 | storeValue(rhs.value); |
| 1317 | } |
| 1318 | |
| 1319 | Bool::Bool(const Bool &rhs) |
| 1320 | { |
| 1321 | Value *value = rhs.loadValue(); |
| 1322 | storeValue(value); |
| 1323 | } |
| 1324 | |
| 1325 | Bool::Bool(const Reference<Bool> &rhs) |
| 1326 | { |
| 1327 | Value *value = rhs.loadValue(); |
| 1328 | storeValue(value); |
| 1329 | } |
| 1330 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1331 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1332 | { |
| 1333 | storeValue(rhs.value); |
| 1334 | |
| 1335 | return rhs; |
| 1336 | } |
| 1337 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1338 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1339 | { |
| 1340 | Value *value = rhs.loadValue(); |
| 1341 | storeValue(value); |
| 1342 | |
| 1343 | return RValue<Bool>(value); |
| 1344 | } |
| 1345 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1346 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1347 | { |
| 1348 | Value *value = rhs.loadValue(); |
| 1349 | storeValue(value); |
| 1350 | |
| 1351 | return RValue<Bool>(value); |
| 1352 | } |
| 1353 | |
| 1354 | RValue<Bool> operator!(RValue<Bool> val) |
| 1355 | { |
| 1356 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1357 | } |
| 1358 | |
| 1359 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1360 | { |
| 1361 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1362 | } |
| 1363 | |
| 1364 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1365 | { |
| 1366 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1367 | } |
| 1368 | |
| 1369 | Type *Bool::getType() |
| 1370 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1371 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | Byte::Byte(Argument<Byte> argument) |
| 1375 | { |
| 1376 | storeValue(argument.value); |
| 1377 | } |
| 1378 | |
| 1379 | Byte::Byte(RValue<Int> cast) |
| 1380 | { |
| 1381 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1382 | |
| 1383 | storeValue(integer); |
| 1384 | } |
| 1385 | |
| 1386 | Byte::Byte(RValue<UInt> cast) |
| 1387 | { |
| 1388 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1389 | |
| 1390 | storeValue(integer); |
| 1391 | } |
| 1392 | |
| 1393 | Byte::Byte(RValue<UShort> cast) |
| 1394 | { |
| 1395 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1396 | |
| 1397 | storeValue(integer); |
| 1398 | } |
| 1399 | |
| 1400 | Byte::Byte() |
| 1401 | { |
| 1402 | } |
| 1403 | |
| 1404 | Byte::Byte(int x) |
| 1405 | { |
| 1406 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1407 | } |
| 1408 | |
| 1409 | Byte::Byte(unsigned char x) |
| 1410 | { |
| 1411 | storeValue(Nucleus::createConstantByte(x)); |
| 1412 | } |
| 1413 | |
| 1414 | Byte::Byte(RValue<Byte> rhs) |
| 1415 | { |
| 1416 | storeValue(rhs.value); |
| 1417 | } |
| 1418 | |
| 1419 | Byte::Byte(const Byte &rhs) |
| 1420 | { |
| 1421 | Value *value = rhs.loadValue(); |
| 1422 | storeValue(value); |
| 1423 | } |
| 1424 | |
| 1425 | Byte::Byte(const Reference<Byte> &rhs) |
| 1426 | { |
| 1427 | Value *value = rhs.loadValue(); |
| 1428 | storeValue(value); |
| 1429 | } |
| 1430 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1431 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1432 | { |
| 1433 | storeValue(rhs.value); |
| 1434 | |
| 1435 | return rhs; |
| 1436 | } |
| 1437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1438 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1439 | { |
| 1440 | Value *value = rhs.loadValue(); |
| 1441 | storeValue(value); |
| 1442 | |
| 1443 | return RValue<Byte>(value); |
| 1444 | } |
| 1445 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1446 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1447 | { |
| 1448 | Value *value = rhs.loadValue(); |
| 1449 | storeValue(value); |
| 1450 | |
| 1451 | return RValue<Byte>(value); |
| 1452 | } |
| 1453 | |
| 1454 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1455 | { |
| 1456 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1457 | } |
| 1458 | |
| 1459 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1460 | { |
| 1461 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1462 | } |
| 1463 | |
| 1464 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1465 | { |
| 1466 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1467 | } |
| 1468 | |
| 1469 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1470 | { |
| 1471 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1472 | } |
| 1473 | |
| 1474 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1475 | { |
| 1476 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1477 | } |
| 1478 | |
| 1479 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1480 | { |
| 1481 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1482 | } |
| 1483 | |
| 1484 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1485 | { |
| 1486 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1487 | } |
| 1488 | |
| 1489 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1490 | { |
| 1491 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1492 | } |
| 1493 | |
| 1494 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1495 | { |
| 1496 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1497 | } |
| 1498 | |
| 1499 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1500 | { |
| 1501 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1502 | } |
| 1503 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1504 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1505 | { |
| 1506 | return lhs = lhs + rhs; |
| 1507 | } |
| 1508 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1509 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1510 | { |
| 1511 | return lhs = lhs - rhs; |
| 1512 | } |
| 1513 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1514 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1515 | { |
| 1516 | return lhs = lhs * rhs; |
| 1517 | } |
| 1518 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1519 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1520 | { |
| 1521 | return lhs = lhs / rhs; |
| 1522 | } |
| 1523 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1524 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1525 | { |
| 1526 | return lhs = lhs % rhs; |
| 1527 | } |
| 1528 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1529 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1530 | { |
| 1531 | return lhs = lhs & rhs; |
| 1532 | } |
| 1533 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1534 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1535 | { |
| 1536 | return lhs = lhs | rhs; |
| 1537 | } |
| 1538 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1539 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1540 | { |
| 1541 | return lhs = lhs ^ rhs; |
| 1542 | } |
| 1543 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1544 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1545 | { |
| 1546 | return lhs = lhs << rhs; |
| 1547 | } |
| 1548 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1549 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1550 | { |
| 1551 | return lhs = lhs >> rhs; |
| 1552 | } |
| 1553 | |
| 1554 | RValue<Byte> operator+(RValue<Byte> val) |
| 1555 | { |
| 1556 | return val; |
| 1557 | } |
| 1558 | |
| 1559 | RValue<Byte> operator-(RValue<Byte> val) |
| 1560 | { |
| 1561 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1562 | } |
| 1563 | |
| 1564 | RValue<Byte> operator~(RValue<Byte> val) |
| 1565 | { |
| 1566 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1567 | } |
| 1568 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1569 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1570 | { |
| 1571 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1572 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1573 | return res; |
| 1574 | } |
| 1575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1576 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1577 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1578 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1579 | return val; |
| 1580 | } |
| 1581 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1582 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1583 | { |
| 1584 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1585 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1586 | return res; |
| 1587 | } |
| 1588 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1589 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1590 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1591 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1592 | return val; |
| 1593 | } |
| 1594 | |
| 1595 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1596 | { |
| 1597 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1598 | } |
| 1599 | |
| 1600 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1601 | { |
| 1602 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1603 | } |
| 1604 | |
| 1605 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1606 | { |
| 1607 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1608 | } |
| 1609 | |
| 1610 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1611 | { |
| 1612 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1613 | } |
| 1614 | |
| 1615 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1616 | { |
| 1617 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1618 | } |
| 1619 | |
| 1620 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1621 | { |
| 1622 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1623 | } |
| 1624 | |
| 1625 | Type *Byte::getType() |
| 1626 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1627 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | SByte::SByte(Argument<SByte> argument) |
| 1631 | { |
| 1632 | storeValue(argument.value); |
| 1633 | } |
| 1634 | |
| 1635 | SByte::SByte(RValue<Int> cast) |
| 1636 | { |
| 1637 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1638 | |
| 1639 | storeValue(integer); |
| 1640 | } |
| 1641 | |
| 1642 | SByte::SByte(RValue<Short> cast) |
| 1643 | { |
| 1644 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1645 | |
| 1646 | storeValue(integer); |
| 1647 | } |
| 1648 | |
| 1649 | SByte::SByte() |
| 1650 | { |
| 1651 | } |
| 1652 | |
| 1653 | SByte::SByte(signed char x) |
| 1654 | { |
| 1655 | storeValue(Nucleus::createConstantByte(x)); |
| 1656 | } |
| 1657 | |
| 1658 | SByte::SByte(RValue<SByte> rhs) |
| 1659 | { |
| 1660 | storeValue(rhs.value); |
| 1661 | } |
| 1662 | |
| 1663 | SByte::SByte(const SByte &rhs) |
| 1664 | { |
| 1665 | Value *value = rhs.loadValue(); |
| 1666 | storeValue(value); |
| 1667 | } |
| 1668 | |
| 1669 | SByte::SByte(const Reference<SByte> &rhs) |
| 1670 | { |
| 1671 | Value *value = rhs.loadValue(); |
| 1672 | storeValue(value); |
| 1673 | } |
| 1674 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1675 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1676 | { |
| 1677 | storeValue(rhs.value); |
| 1678 | |
| 1679 | return rhs; |
| 1680 | } |
| 1681 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1682 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1683 | { |
| 1684 | Value *value = rhs.loadValue(); |
| 1685 | storeValue(value); |
| 1686 | |
| 1687 | return RValue<SByte>(value); |
| 1688 | } |
| 1689 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1690 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1691 | { |
| 1692 | Value *value = rhs.loadValue(); |
| 1693 | storeValue(value); |
| 1694 | |
| 1695 | return RValue<SByte>(value); |
| 1696 | } |
| 1697 | |
| 1698 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1699 | { |
| 1700 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1701 | } |
| 1702 | |
| 1703 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1704 | { |
| 1705 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1706 | } |
| 1707 | |
| 1708 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1709 | { |
| 1710 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1711 | } |
| 1712 | |
| 1713 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1714 | { |
| 1715 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1716 | } |
| 1717 | |
| 1718 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1719 | { |
| 1720 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1721 | } |
| 1722 | |
| 1723 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1724 | { |
| 1725 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1726 | } |
| 1727 | |
| 1728 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1729 | { |
| 1730 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1731 | } |
| 1732 | |
| 1733 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1734 | { |
| 1735 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1736 | } |
| 1737 | |
| 1738 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1739 | { |
| 1740 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1741 | } |
| 1742 | |
| 1743 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1744 | { |
| 1745 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1746 | } |
| 1747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1748 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1749 | { |
| 1750 | return lhs = lhs + rhs; |
| 1751 | } |
| 1752 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1753 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1754 | { |
| 1755 | return lhs = lhs - rhs; |
| 1756 | } |
| 1757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1758 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1759 | { |
| 1760 | return lhs = lhs * rhs; |
| 1761 | } |
| 1762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1763 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1764 | { |
| 1765 | return lhs = lhs / rhs; |
| 1766 | } |
| 1767 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1768 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1769 | { |
| 1770 | return lhs = lhs % rhs; |
| 1771 | } |
| 1772 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1773 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1774 | { |
| 1775 | return lhs = lhs & rhs; |
| 1776 | } |
| 1777 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1778 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1779 | { |
| 1780 | return lhs = lhs | rhs; |
| 1781 | } |
| 1782 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1783 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1784 | { |
| 1785 | return lhs = lhs ^ rhs; |
| 1786 | } |
| 1787 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1788 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1789 | { |
| 1790 | return lhs = lhs << rhs; |
| 1791 | } |
| 1792 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1793 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1794 | { |
| 1795 | return lhs = lhs >> rhs; |
| 1796 | } |
| 1797 | |
| 1798 | RValue<SByte> operator+(RValue<SByte> val) |
| 1799 | { |
| 1800 | return val; |
| 1801 | } |
| 1802 | |
| 1803 | RValue<SByte> operator-(RValue<SByte> val) |
| 1804 | { |
| 1805 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1806 | } |
| 1807 | |
| 1808 | RValue<SByte> operator~(RValue<SByte> val) |
| 1809 | { |
| 1810 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1811 | } |
| 1812 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1813 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1814 | { |
| 1815 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1816 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1817 | return res; |
| 1818 | } |
| 1819 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1820 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1821 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1822 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1823 | return val; |
| 1824 | } |
| 1825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1826 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1827 | { |
| 1828 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1829 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1830 | return res; |
| 1831 | } |
| 1832 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1833 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1834 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1835 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1836 | return val; |
| 1837 | } |
| 1838 | |
| 1839 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1840 | { |
| 1841 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1842 | } |
| 1843 | |
| 1844 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1845 | { |
| 1846 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1847 | } |
| 1848 | |
| 1849 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1850 | { |
| 1851 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1852 | } |
| 1853 | |
| 1854 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1855 | { |
| 1856 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1857 | } |
| 1858 | |
| 1859 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1860 | { |
| 1861 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1862 | } |
| 1863 | |
| 1864 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1865 | { |
| 1866 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1867 | } |
| 1868 | |
| 1869 | Type *SByte::getType() |
| 1870 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1871 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | Short::Short(Argument<Short> argument) |
| 1875 | { |
| 1876 | storeValue(argument.value); |
| 1877 | } |
| 1878 | |
| 1879 | Short::Short(RValue<Int> cast) |
| 1880 | { |
| 1881 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1882 | |
| 1883 | storeValue(integer); |
| 1884 | } |
| 1885 | |
| 1886 | Short::Short() |
| 1887 | { |
| 1888 | } |
| 1889 | |
| 1890 | Short::Short(short x) |
| 1891 | { |
| 1892 | storeValue(Nucleus::createConstantShort(x)); |
| 1893 | } |
| 1894 | |
| 1895 | Short::Short(RValue<Short> rhs) |
| 1896 | { |
| 1897 | storeValue(rhs.value); |
| 1898 | } |
| 1899 | |
| 1900 | Short::Short(const Short &rhs) |
| 1901 | { |
| 1902 | Value *value = rhs.loadValue(); |
| 1903 | storeValue(value); |
| 1904 | } |
| 1905 | |
| 1906 | Short::Short(const Reference<Short> &rhs) |
| 1907 | { |
| 1908 | Value *value = rhs.loadValue(); |
| 1909 | storeValue(value); |
| 1910 | } |
| 1911 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1912 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1913 | { |
| 1914 | storeValue(rhs.value); |
| 1915 | |
| 1916 | return rhs; |
| 1917 | } |
| 1918 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1919 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1920 | { |
| 1921 | Value *value = rhs.loadValue(); |
| 1922 | storeValue(value); |
| 1923 | |
| 1924 | return RValue<Short>(value); |
| 1925 | } |
| 1926 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1927 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1928 | { |
| 1929 | Value *value = rhs.loadValue(); |
| 1930 | storeValue(value); |
| 1931 | |
| 1932 | return RValue<Short>(value); |
| 1933 | } |
| 1934 | |
| 1935 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 1936 | { |
| 1937 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1938 | } |
| 1939 | |
| 1940 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 1941 | { |
| 1942 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1943 | } |
| 1944 | |
| 1945 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 1946 | { |
| 1947 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1948 | } |
| 1949 | |
| 1950 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 1951 | { |
| 1952 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1953 | } |
| 1954 | |
| 1955 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 1956 | { |
| 1957 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1958 | } |
| 1959 | |
| 1960 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 1961 | { |
| 1962 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1963 | } |
| 1964 | |
| 1965 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 1966 | { |
| 1967 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1968 | } |
| 1969 | |
| 1970 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 1971 | { |
| 1972 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1973 | } |
| 1974 | |
| 1975 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 1976 | { |
| 1977 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1978 | } |
| 1979 | |
| 1980 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 1981 | { |
| 1982 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1983 | } |
| 1984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1985 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1986 | { |
| 1987 | return lhs = lhs + rhs; |
| 1988 | } |
| 1989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1990 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1991 | { |
| 1992 | return lhs = lhs - rhs; |
| 1993 | } |
| 1994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1995 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1996 | { |
| 1997 | return lhs = lhs * rhs; |
| 1998 | } |
| 1999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2000 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2001 | { |
| 2002 | return lhs = lhs / rhs; |
| 2003 | } |
| 2004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2005 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2006 | { |
| 2007 | return lhs = lhs % rhs; |
| 2008 | } |
| 2009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2010 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2011 | { |
| 2012 | return lhs = lhs & rhs; |
| 2013 | } |
| 2014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2015 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2016 | { |
| 2017 | return lhs = lhs | rhs; |
| 2018 | } |
| 2019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2020 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2021 | { |
| 2022 | return lhs = lhs ^ rhs; |
| 2023 | } |
| 2024 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2025 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2026 | { |
| 2027 | return lhs = lhs << rhs; |
| 2028 | } |
| 2029 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2030 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2031 | { |
| 2032 | return lhs = lhs >> rhs; |
| 2033 | } |
| 2034 | |
| 2035 | RValue<Short> operator+(RValue<Short> val) |
| 2036 | { |
| 2037 | return val; |
| 2038 | } |
| 2039 | |
| 2040 | RValue<Short> operator-(RValue<Short> val) |
| 2041 | { |
| 2042 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2043 | } |
| 2044 | |
| 2045 | RValue<Short> operator~(RValue<Short> val) |
| 2046 | { |
| 2047 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2048 | } |
| 2049 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2050 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2051 | { |
| 2052 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2053 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2054 | return res; |
| 2055 | } |
| 2056 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2057 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2058 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2059 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2060 | return val; |
| 2061 | } |
| 2062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2063 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2064 | { |
| 2065 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2066 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2067 | return res; |
| 2068 | } |
| 2069 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2070 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2071 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2072 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2073 | return val; |
| 2074 | } |
| 2075 | |
| 2076 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2077 | { |
| 2078 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2079 | } |
| 2080 | |
| 2081 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2082 | { |
| 2083 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2084 | } |
| 2085 | |
| 2086 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2087 | { |
| 2088 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2089 | } |
| 2090 | |
| 2091 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2092 | { |
| 2093 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2094 | } |
| 2095 | |
| 2096 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2097 | { |
| 2098 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2099 | } |
| 2100 | |
| 2101 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2102 | { |
| 2103 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2104 | } |
| 2105 | |
| 2106 | Type *Short::getType() |
| 2107 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2108 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | UShort::UShort(Argument<UShort> argument) |
| 2112 | { |
| 2113 | storeValue(argument.value); |
| 2114 | } |
| 2115 | |
| 2116 | UShort::UShort(RValue<UInt> cast) |
| 2117 | { |
| 2118 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2119 | |
| 2120 | storeValue(integer); |
| 2121 | } |
| 2122 | |
| 2123 | UShort::UShort(RValue<Int> cast) |
| 2124 | { |
| 2125 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2126 | |
| 2127 | storeValue(integer); |
| 2128 | } |
| 2129 | |
| 2130 | UShort::UShort() |
| 2131 | { |
| 2132 | } |
| 2133 | |
| 2134 | UShort::UShort(unsigned short x) |
| 2135 | { |
| 2136 | storeValue(Nucleus::createConstantShort(x)); |
| 2137 | } |
| 2138 | |
| 2139 | UShort::UShort(RValue<UShort> rhs) |
| 2140 | { |
| 2141 | storeValue(rhs.value); |
| 2142 | } |
| 2143 | |
| 2144 | UShort::UShort(const UShort &rhs) |
| 2145 | { |
| 2146 | Value *value = rhs.loadValue(); |
| 2147 | storeValue(value); |
| 2148 | } |
| 2149 | |
| 2150 | UShort::UShort(const Reference<UShort> &rhs) |
| 2151 | { |
| 2152 | Value *value = rhs.loadValue(); |
| 2153 | storeValue(value); |
| 2154 | } |
| 2155 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2156 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2157 | { |
| 2158 | storeValue(rhs.value); |
| 2159 | |
| 2160 | return rhs; |
| 2161 | } |
| 2162 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2163 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2164 | { |
| 2165 | Value *value = rhs.loadValue(); |
| 2166 | storeValue(value); |
| 2167 | |
| 2168 | return RValue<UShort>(value); |
| 2169 | } |
| 2170 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2171 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2172 | { |
| 2173 | Value *value = rhs.loadValue(); |
| 2174 | storeValue(value); |
| 2175 | |
| 2176 | return RValue<UShort>(value); |
| 2177 | } |
| 2178 | |
| 2179 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2180 | { |
| 2181 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2182 | } |
| 2183 | |
| 2184 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2185 | { |
| 2186 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2187 | } |
| 2188 | |
| 2189 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2190 | { |
| 2191 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2192 | } |
| 2193 | |
| 2194 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2195 | { |
| 2196 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2197 | } |
| 2198 | |
| 2199 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2200 | { |
| 2201 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2202 | } |
| 2203 | |
| 2204 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2205 | { |
| 2206 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2207 | } |
| 2208 | |
| 2209 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2210 | { |
| 2211 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2212 | } |
| 2213 | |
| 2214 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2215 | { |
| 2216 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2217 | } |
| 2218 | |
| 2219 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2220 | { |
| 2221 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2222 | } |
| 2223 | |
| 2224 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2225 | { |
| 2226 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2227 | } |
| 2228 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2229 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2230 | { |
| 2231 | return lhs = lhs + rhs; |
| 2232 | } |
| 2233 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2234 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2235 | { |
| 2236 | return lhs = lhs - rhs; |
| 2237 | } |
| 2238 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2239 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2240 | { |
| 2241 | return lhs = lhs * rhs; |
| 2242 | } |
| 2243 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2244 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2245 | { |
| 2246 | return lhs = lhs / rhs; |
| 2247 | } |
| 2248 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2249 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2250 | { |
| 2251 | return lhs = lhs % rhs; |
| 2252 | } |
| 2253 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2254 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2255 | { |
| 2256 | return lhs = lhs & rhs; |
| 2257 | } |
| 2258 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2259 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2260 | { |
| 2261 | return lhs = lhs | rhs; |
| 2262 | } |
| 2263 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2264 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2265 | { |
| 2266 | return lhs = lhs ^ rhs; |
| 2267 | } |
| 2268 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2269 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2270 | { |
| 2271 | return lhs = lhs << rhs; |
| 2272 | } |
| 2273 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2274 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2275 | { |
| 2276 | return lhs = lhs >> rhs; |
| 2277 | } |
| 2278 | |
| 2279 | RValue<UShort> operator+(RValue<UShort> val) |
| 2280 | { |
| 2281 | return val; |
| 2282 | } |
| 2283 | |
| 2284 | RValue<UShort> operator-(RValue<UShort> val) |
| 2285 | { |
| 2286 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2287 | } |
| 2288 | |
| 2289 | RValue<UShort> operator~(RValue<UShort> val) |
| 2290 | { |
| 2291 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2292 | } |
| 2293 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2294 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2295 | { |
| 2296 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2297 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2298 | return res; |
| 2299 | } |
| 2300 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2301 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2302 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2303 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2304 | return val; |
| 2305 | } |
| 2306 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2307 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2308 | { |
| 2309 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2310 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2311 | return res; |
| 2312 | } |
| 2313 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2314 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2315 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2316 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2317 | return val; |
| 2318 | } |
| 2319 | |
| 2320 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2321 | { |
| 2322 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2323 | } |
| 2324 | |
| 2325 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2326 | { |
| 2327 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2328 | } |
| 2329 | |
| 2330 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2331 | { |
| 2332 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2333 | } |
| 2334 | |
| 2335 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2336 | { |
| 2337 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2338 | } |
| 2339 | |
| 2340 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2341 | { |
| 2342 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2343 | } |
| 2344 | |
| 2345 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2346 | { |
| 2347 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2348 | } |
| 2349 | |
| 2350 | Type *UShort::getType() |
| 2351 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2352 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2353 | } |
| 2354 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2355 | Byte4::Byte4(RValue<Byte8> cast) |
| 2356 | { |
| 2357 | // xyzw.parent = this; |
| 2358 | |
| 2359 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2360 | } |
| 2361 | |
| 2362 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2363 | { |
| 2364 | // xyzw.parent = this; |
| 2365 | |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2366 | Value *value = rhs.loadValue(); |
| 2367 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2368 | } |
| 2369 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2370 | Type *Byte4::getType() |
| 2371 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2372 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | Type *SByte4::getType() |
| 2376 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2377 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | Byte8::Byte8() |
| 2381 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | 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) |
| 2385 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2386 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2387 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2391 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2392 | storeValue(rhs.value); |
| 2393 | } |
| 2394 | |
| 2395 | Byte8::Byte8(const Byte8 &rhs) |
| 2396 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2397 | Value *value = rhs.loadValue(); |
| 2398 | storeValue(value); |
| 2399 | } |
| 2400 | |
| 2401 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2402 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2403 | Value *value = rhs.loadValue(); |
| 2404 | storeValue(value); |
| 2405 | } |
| 2406 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2407 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2408 | { |
| 2409 | storeValue(rhs.value); |
| 2410 | |
| 2411 | return rhs; |
| 2412 | } |
| 2413 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2414 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2415 | { |
| 2416 | Value *value = rhs.loadValue(); |
| 2417 | storeValue(value); |
| 2418 | |
| 2419 | return RValue<Byte8>(value); |
| 2420 | } |
| 2421 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2422 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2423 | { |
| 2424 | Value *value = rhs.loadValue(); |
| 2425 | storeValue(value); |
| 2426 | |
| 2427 | return RValue<Byte8>(value); |
| 2428 | } |
| 2429 | |
| 2430 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2431 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2432 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2436 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2437 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2441 | // { |
| 2442 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2443 | // } |
| 2444 | |
| 2445 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2446 | // { |
| 2447 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2448 | // } |
| 2449 | |
| 2450 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2451 | // { |
| 2452 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2453 | // } |
| 2454 | |
| 2455 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2456 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2457 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2461 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2462 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2466 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2467 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2471 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2472 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2473 | // } |
| 2474 | |
| 2475 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2476 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2477 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2478 | // } |
| 2479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2480 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2481 | { |
| 2482 | return lhs = lhs + rhs; |
| 2483 | } |
| 2484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2485 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2486 | { |
| 2487 | return lhs = lhs - rhs; |
| 2488 | } |
| 2489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2490 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2491 | // { |
| 2492 | // return lhs = lhs * rhs; |
| 2493 | // } |
| 2494 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2495 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2496 | // { |
| 2497 | // return lhs = lhs / rhs; |
| 2498 | // } |
| 2499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2500 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2501 | // { |
| 2502 | // return lhs = lhs % rhs; |
| 2503 | // } |
| 2504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2505 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2506 | { |
| 2507 | return lhs = lhs & rhs; |
| 2508 | } |
| 2509 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2510 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2511 | { |
| 2512 | return lhs = lhs | rhs; |
| 2513 | } |
| 2514 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2515 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2516 | { |
| 2517 | return lhs = lhs ^ rhs; |
| 2518 | } |
| 2519 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2520 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2521 | // { |
| 2522 | // return lhs = lhs << rhs; |
| 2523 | // } |
| 2524 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2525 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2526 | // { |
| 2527 | // return lhs = lhs >> rhs; |
| 2528 | // } |
| 2529 | |
| 2530 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2531 | // { |
| 2532 | // return val; |
| 2533 | // } |
| 2534 | |
| 2535 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2536 | // { |
| 2537 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2538 | // } |
| 2539 | |
| 2540 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2541 | { |
| 2542 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2543 | } |
| 2544 | |
| 2545 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2546 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2547 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2548 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2549 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2550 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2551 | paddusb->addArg(x.value); |
| 2552 | paddusb->addArg(y.value); |
| 2553 | ::basicBlock->appendInst(paddusb); |
| 2554 | |
| 2555 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2559 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2560 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2561 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2562 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2563 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2564 | psubusw->addArg(x.value); |
| 2565 | psubusw->addArg(y.value); |
| 2566 | ::basicBlock->appendInst(psubusw); |
| 2567 | |
| 2568 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2572 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2573 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2574 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2578 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2579 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2580 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2584 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2585 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2586 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2587 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2591 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2592 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2593 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2594 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2595 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2596 | movmsk->addArg(x.value); |
| 2597 | ::basicBlock->appendInst(movmsk); |
| 2598 | |
| 2599 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2603 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2604 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2605 | // } |
| 2606 | |
| 2607 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2608 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2609 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | Type *Byte8::getType() |
| 2613 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2614 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | SByte8::SByte8() |
| 2618 | { |
| 2619 | // xyzw.parent = this; |
| 2620 | } |
| 2621 | |
| 2622 | 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) |
| 2623 | { |
| 2624 | // xyzw.parent = this; |
| 2625 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2626 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2627 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2628 | |
| 2629 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2630 | } |
| 2631 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2632 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2633 | { |
| 2634 | // xyzw.parent = this; |
| 2635 | |
| 2636 | storeValue(rhs.value); |
| 2637 | } |
| 2638 | |
| 2639 | SByte8::SByte8(const SByte8 &rhs) |
| 2640 | { |
| 2641 | // xyzw.parent = this; |
| 2642 | |
| 2643 | Value *value = rhs.loadValue(); |
| 2644 | storeValue(value); |
| 2645 | } |
| 2646 | |
| 2647 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2648 | { |
| 2649 | // xyzw.parent = this; |
| 2650 | |
| 2651 | Value *value = rhs.loadValue(); |
| 2652 | storeValue(value); |
| 2653 | } |
| 2654 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2655 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2656 | { |
| 2657 | storeValue(rhs.value); |
| 2658 | |
| 2659 | return rhs; |
| 2660 | } |
| 2661 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2662 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2663 | { |
| 2664 | Value *value = rhs.loadValue(); |
| 2665 | storeValue(value); |
| 2666 | |
| 2667 | return RValue<SByte8>(value); |
| 2668 | } |
| 2669 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2670 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2671 | { |
| 2672 | Value *value = rhs.loadValue(); |
| 2673 | storeValue(value); |
| 2674 | |
| 2675 | return RValue<SByte8>(value); |
| 2676 | } |
| 2677 | |
| 2678 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2679 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2680 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2684 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2685 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2689 | // { |
| 2690 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2691 | // } |
| 2692 | |
| 2693 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2694 | // { |
| 2695 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2696 | // } |
| 2697 | |
| 2698 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2699 | // { |
| 2700 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2701 | // } |
| 2702 | |
| 2703 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2704 | { |
| 2705 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2706 | } |
| 2707 | |
| 2708 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2709 | { |
| 2710 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2711 | } |
| 2712 | |
| 2713 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2714 | { |
| 2715 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2716 | } |
| 2717 | |
| 2718 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2719 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2720 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2721 | // } |
| 2722 | |
| 2723 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2724 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2725 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2726 | // } |
| 2727 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2728 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2729 | { |
| 2730 | return lhs = lhs + rhs; |
| 2731 | } |
| 2732 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2733 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2734 | { |
| 2735 | return lhs = lhs - rhs; |
| 2736 | } |
| 2737 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2738 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2739 | // { |
| 2740 | // return lhs = lhs * rhs; |
| 2741 | // } |
| 2742 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2743 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2744 | // { |
| 2745 | // return lhs = lhs / rhs; |
| 2746 | // } |
| 2747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2748 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2749 | // { |
| 2750 | // return lhs = lhs % rhs; |
| 2751 | // } |
| 2752 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2753 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2754 | { |
| 2755 | return lhs = lhs & rhs; |
| 2756 | } |
| 2757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2758 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2759 | { |
| 2760 | return lhs = lhs | rhs; |
| 2761 | } |
| 2762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2763 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2764 | { |
| 2765 | return lhs = lhs ^ rhs; |
| 2766 | } |
| 2767 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2768 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2769 | // { |
| 2770 | // return lhs = lhs << rhs; |
| 2771 | // } |
| 2772 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2773 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2774 | // { |
| 2775 | // return lhs = lhs >> rhs; |
| 2776 | // } |
| 2777 | |
| 2778 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2779 | // { |
| 2780 | // return val; |
| 2781 | // } |
| 2782 | |
| 2783 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2784 | // { |
| 2785 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2786 | // } |
| 2787 | |
| 2788 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2789 | { |
| 2790 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2791 | } |
| 2792 | |
| 2793 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2794 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2795 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2796 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2797 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2798 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2799 | paddsb->addArg(x.value); |
| 2800 | paddsb->addArg(y.value); |
| 2801 | ::basicBlock->appendInst(paddsb); |
| 2802 | |
| 2803 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2807 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2808 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2809 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2810 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2811 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2812 | psubsb->addArg(x.value); |
| 2813 | psubsb->addArg(y.value); |
| 2814 | ::basicBlock->appendInst(psubsb); |
| 2815 | |
| 2816 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2820 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2821 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2822 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2826 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2827 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2828 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2829 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2833 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2834 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2835 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2836 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2837 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2838 | movmsk->addArg(x.value); |
| 2839 | ::basicBlock->appendInst(movmsk); |
| 2840 | |
| 2841 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2845 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2846 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2850 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2851 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | Type *SByte8::getType() |
| 2855 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2856 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2857 | } |
| 2858 | |
| 2859 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2860 | { |
| 2861 | // xyzw.parent = this; |
| 2862 | |
| 2863 | storeValue(rhs.value); |
| 2864 | } |
| 2865 | |
| 2866 | Byte16::Byte16(const Byte16 &rhs) |
| 2867 | { |
| 2868 | // xyzw.parent = this; |
| 2869 | |
| 2870 | Value *value = rhs.loadValue(); |
| 2871 | storeValue(value); |
| 2872 | } |
| 2873 | |
| 2874 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2875 | { |
| 2876 | // xyzw.parent = this; |
| 2877 | |
| 2878 | Value *value = rhs.loadValue(); |
| 2879 | storeValue(value); |
| 2880 | } |
| 2881 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2882 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2883 | { |
| 2884 | storeValue(rhs.value); |
| 2885 | |
| 2886 | return rhs; |
| 2887 | } |
| 2888 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2889 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2890 | { |
| 2891 | Value *value = rhs.loadValue(); |
| 2892 | storeValue(value); |
| 2893 | |
| 2894 | return RValue<Byte16>(value); |
| 2895 | } |
| 2896 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2897 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2898 | { |
| 2899 | Value *value = rhs.loadValue(); |
| 2900 | storeValue(value); |
| 2901 | |
| 2902 | return RValue<Byte16>(value); |
| 2903 | } |
| 2904 | |
| 2905 | Type *Byte16::getType() |
| 2906 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2907 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | Type *SByte16::getType() |
| 2911 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2912 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2915 | Short2::Short2(RValue<Short4> cast) |
| 2916 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2917 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | Type *Short2::getType() |
| 2921 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2922 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | UShort2::UShort2(RValue<UShort4> cast) |
| 2926 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2927 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | Type *UShort2::getType() |
| 2931 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2932 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2933 | } |
| 2934 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2935 | Short4::Short4(RValue<Int> cast) |
| 2936 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2937 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 2938 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2939 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2940 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2941 | |
| 2942 | storeValue(swizzle); |
| 2943 | } |
| 2944 | |
| 2945 | Short4::Short4(RValue<Int4> cast) |
| 2946 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2947 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
| 2948 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2949 | Value *packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
| 2950 | |
| 2951 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2952 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2953 | |
| 2954 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | // Short4::Short4(RValue<Float> cast) |
| 2958 | // { |
| 2959 | // } |
| 2960 | |
| 2961 | Short4::Short4(RValue<Float4> cast) |
| 2962 | { |
| 2963 | assert(false && "UNIMPLEMENTED"); |
| 2964 | } |
| 2965 | |
| 2966 | Short4::Short4() |
| 2967 | { |
| 2968 | // xyzw.parent = this; |
| 2969 | } |
| 2970 | |
| 2971 | Short4::Short4(short xyzw) |
| 2972 | { |
| 2973 | // xyzw.parent = this; |
| 2974 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2975 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2976 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | Short4::Short4(short x, short y, short z, short w) |
| 2980 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2981 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2982 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2983 | int64_t constantVector[4] = {x, y, z, w}; |
| 2984 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | Short4::Short4(RValue<Short4> rhs) |
| 2988 | { |
| 2989 | // xyzw.parent = this; |
| 2990 | |
| 2991 | storeValue(rhs.value); |
| 2992 | } |
| 2993 | |
| 2994 | Short4::Short4(const Short4 &rhs) |
| 2995 | { |
| 2996 | // xyzw.parent = this; |
| 2997 | |
| 2998 | Value *value = rhs.loadValue(); |
| 2999 | storeValue(value); |
| 3000 | } |
| 3001 | |
| 3002 | Short4::Short4(const Reference<Short4> &rhs) |
| 3003 | { |
| 3004 | // xyzw.parent = this; |
| 3005 | |
| 3006 | Value *value = rhs.loadValue(); |
| 3007 | storeValue(value); |
| 3008 | } |
| 3009 | |
| 3010 | Short4::Short4(RValue<UShort4> rhs) |
| 3011 | { |
| 3012 | // xyzw.parent = this; |
| 3013 | |
| 3014 | storeValue(rhs.value); |
| 3015 | } |
| 3016 | |
| 3017 | Short4::Short4(const UShort4 &rhs) |
| 3018 | { |
| 3019 | // xyzw.parent = this; |
| 3020 | |
| 3021 | storeValue(rhs.loadValue()); |
| 3022 | } |
| 3023 | |
| 3024 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3025 | { |
| 3026 | // xyzw.parent = this; |
| 3027 | |
| 3028 | storeValue(rhs.loadValue()); |
| 3029 | } |
| 3030 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3031 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3032 | { |
| 3033 | storeValue(rhs.value); |
| 3034 | |
| 3035 | return rhs; |
| 3036 | } |
| 3037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3038 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3039 | { |
| 3040 | Value *value = rhs.loadValue(); |
| 3041 | storeValue(value); |
| 3042 | |
| 3043 | return RValue<Short4>(value); |
| 3044 | } |
| 3045 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3046 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3047 | { |
| 3048 | Value *value = rhs.loadValue(); |
| 3049 | storeValue(value); |
| 3050 | |
| 3051 | return RValue<Short4>(value); |
| 3052 | } |
| 3053 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3054 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3055 | { |
| 3056 | storeValue(rhs.value); |
| 3057 | |
| 3058 | return RValue<Short4>(rhs); |
| 3059 | } |
| 3060 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3061 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3062 | { |
| 3063 | Value *value = rhs.loadValue(); |
| 3064 | storeValue(value); |
| 3065 | |
| 3066 | return RValue<Short4>(value); |
| 3067 | } |
| 3068 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3069 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3070 | { |
| 3071 | Value *value = rhs.loadValue(); |
| 3072 | storeValue(value); |
| 3073 | |
| 3074 | return RValue<Short4>(value); |
| 3075 | } |
| 3076 | |
| 3077 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3078 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3079 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3083 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3084 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3088 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3089 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3093 | // { |
| 3094 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3095 | // } |
| 3096 | |
| 3097 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3098 | // { |
| 3099 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3100 | // } |
| 3101 | |
| 3102 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3103 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3104 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3108 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3109 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3113 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3114 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3118 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3119 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3123 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3124 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3125 | } |
| 3126 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3127 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3128 | { |
| 3129 | return lhs = lhs + rhs; |
| 3130 | } |
| 3131 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3132 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3133 | { |
| 3134 | return lhs = lhs - rhs; |
| 3135 | } |
| 3136 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3137 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3138 | { |
| 3139 | return lhs = lhs * rhs; |
| 3140 | } |
| 3141 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3142 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3143 | // { |
| 3144 | // return lhs = lhs / rhs; |
| 3145 | // } |
| 3146 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3147 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3148 | // { |
| 3149 | // return lhs = lhs % rhs; |
| 3150 | // } |
| 3151 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3152 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3153 | { |
| 3154 | return lhs = lhs & rhs; |
| 3155 | } |
| 3156 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3157 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3158 | { |
| 3159 | return lhs = lhs | rhs; |
| 3160 | } |
| 3161 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3162 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3163 | { |
| 3164 | return lhs = lhs ^ rhs; |
| 3165 | } |
| 3166 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3167 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3168 | { |
| 3169 | return lhs = lhs << rhs; |
| 3170 | } |
| 3171 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3172 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3173 | { |
| 3174 | return lhs = lhs >> rhs; |
| 3175 | } |
| 3176 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3177 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3178 | // { |
| 3179 | // return val; |
| 3180 | // } |
| 3181 | |
| 3182 | RValue<Short4> operator-(RValue<Short4> val) |
| 3183 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3184 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | RValue<Short4> operator~(RValue<Short4> val) |
| 3188 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3189 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3193 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3194 | RValue<Int4> int4 = RoundInt(cast); |
| 3195 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3199 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3200 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3201 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3202 | ::basicBlock->appendInst(cmp); |
| 3203 | |
| 3204 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3205 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3206 | ::basicBlock->appendInst(select); |
| 3207 | |
| 3208 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3212 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3213 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3214 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3215 | ::basicBlock->appendInst(cmp); |
| 3216 | |
| 3217 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3218 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3219 | ::basicBlock->appendInst(select); |
| 3220 | |
| 3221 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3225 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3226 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3227 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3228 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3229 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3230 | paddsw->addArg(x.value); |
| 3231 | paddsw->addArg(y.value); |
| 3232 | ::basicBlock->appendInst(paddsw); |
| 3233 | |
| 3234 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3238 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3239 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3240 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3241 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3242 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3243 | psubsw->addArg(x.value); |
| 3244 | psubsw->addArg(y.value); |
| 3245 | ::basicBlock->appendInst(psubsw); |
| 3246 | |
| 3247 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3251 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3252 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3253 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3254 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3255 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3256 | pmulhw->addArg(x.value); |
| 3257 | pmulhw->addArg(y.value); |
| 3258 | ::basicBlock->appendInst(pmulhw); |
| 3259 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3260 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3264 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3265 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3266 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3267 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3268 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3269 | pmaddwd->addArg(x.value); |
| 3270 | pmaddwd->addArg(y.value); |
| 3271 | ::basicBlock->appendInst(pmaddwd); |
| 3272 | |
| 3273 | return RValue<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3277 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3278 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3279 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3280 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3281 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3282 | pack->addArg(x.value); |
| 3283 | pack->addArg(y.value); |
| 3284 | ::basicBlock->appendInst(pack); |
| 3285 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3286 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3290 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3291 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3292 | return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3296 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3297 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3298 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3299 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3303 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3304 | // Real type is v8i16 |
| 3305 | int shuffle[8] = |
| 3306 | { |
| 3307 | (select >> 0) & 0x03, |
| 3308 | (select >> 2) & 0x03, |
| 3309 | (select >> 4) & 0x03, |
| 3310 | (select >> 6) & 0x03, |
| 3311 | (select >> 0) & 0x03, |
| 3312 | (select >> 2) & 0x03, |
| 3313 | (select >> 4) & 0x03, |
| 3314 | (select >> 6) & 0x03, |
| 3315 | }; |
| 3316 | |
| 3317 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3321 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3322 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3326 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame^] | 3327 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3331 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3332 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3336 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3337 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | Type *Short4::getType() |
| 3341 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3342 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | UShort4::UShort4(RValue<Int4> cast) |
| 3346 | { |
| 3347 | *this = Short4(cast); |
| 3348 | } |
| 3349 | |
| 3350 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3351 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3352 | if(saturate) |
| 3353 | { |
| 3354 | if(true) // SSE 4.1 |
| 3355 | { |
| 3356 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3357 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3358 | } |
| 3359 | else |
| 3360 | { |
| 3361 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3362 | } |
| 3363 | } |
| 3364 | else |
| 3365 | { |
| 3366 | *this = Short4(Int4(cast)); |
| 3367 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | UShort4::UShort4() |
| 3371 | { |
| 3372 | // xyzw.parent = this; |
| 3373 | } |
| 3374 | |
| 3375 | UShort4::UShort4(unsigned short xyzw) |
| 3376 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3377 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3378 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3379 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3380 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3384 | { |
| 3385 | // xyzw.parent = this; |
| 3386 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3387 | int64_t constantVector[4] = {x, y, z, w}; |
| 3388 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3392 | { |
| 3393 | // xyzw.parent = this; |
| 3394 | |
| 3395 | storeValue(rhs.value); |
| 3396 | } |
| 3397 | |
| 3398 | UShort4::UShort4(const UShort4 &rhs) |
| 3399 | { |
| 3400 | // xyzw.parent = this; |
| 3401 | |
| 3402 | Value *value = rhs.loadValue(); |
| 3403 | storeValue(value); |
| 3404 | } |
| 3405 | |
| 3406 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3407 | { |
| 3408 | // xyzw.parent = this; |
| 3409 | |
| 3410 | Value *value = rhs.loadValue(); |
| 3411 | storeValue(value); |
| 3412 | } |
| 3413 | |
| 3414 | UShort4::UShort4(RValue<Short4> rhs) |
| 3415 | { |
| 3416 | // xyzw.parent = this; |
| 3417 | |
| 3418 | storeValue(rhs.value); |
| 3419 | } |
| 3420 | |
| 3421 | UShort4::UShort4(const Short4 &rhs) |
| 3422 | { |
| 3423 | // xyzw.parent = this; |
| 3424 | |
| 3425 | Value *value = rhs.loadValue(); |
| 3426 | storeValue(value); |
| 3427 | } |
| 3428 | |
| 3429 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3430 | { |
| 3431 | // xyzw.parent = this; |
| 3432 | |
| 3433 | Value *value = rhs.loadValue(); |
| 3434 | storeValue(value); |
| 3435 | } |
| 3436 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3437 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3438 | { |
| 3439 | storeValue(rhs.value); |
| 3440 | |
| 3441 | return rhs; |
| 3442 | } |
| 3443 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3444 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3445 | { |
| 3446 | Value *value = rhs.loadValue(); |
| 3447 | storeValue(value); |
| 3448 | |
| 3449 | return RValue<UShort4>(value); |
| 3450 | } |
| 3451 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3452 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3453 | { |
| 3454 | Value *value = rhs.loadValue(); |
| 3455 | storeValue(value); |
| 3456 | |
| 3457 | return RValue<UShort4>(value); |
| 3458 | } |
| 3459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3460 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3461 | { |
| 3462 | storeValue(rhs.value); |
| 3463 | |
| 3464 | return RValue<UShort4>(rhs); |
| 3465 | } |
| 3466 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3467 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3468 | { |
| 3469 | Value *value = rhs.loadValue(); |
| 3470 | storeValue(value); |
| 3471 | |
| 3472 | return RValue<UShort4>(value); |
| 3473 | } |
| 3474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3475 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3476 | { |
| 3477 | Value *value = rhs.loadValue(); |
| 3478 | storeValue(value); |
| 3479 | |
| 3480 | return RValue<UShort4>(value); |
| 3481 | } |
| 3482 | |
| 3483 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3484 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3485 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3489 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3490 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3494 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3495 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3496 | } |
| 3497 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3498 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3499 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3500 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3504 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3505 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3509 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3510 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3511 | } |
| 3512 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3513 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3514 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3515 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3519 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3520 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3521 | } |
| 3522 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3523 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3524 | { |
| 3525 | return lhs = lhs << rhs; |
| 3526 | } |
| 3527 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3528 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3529 | { |
| 3530 | return lhs = lhs >> rhs; |
| 3531 | } |
| 3532 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3533 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3534 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3535 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3536 | } |
| 3537 | |
| 3538 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3539 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3540 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3541 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3542 | ::basicBlock->appendInst(cmp); |
| 3543 | |
| 3544 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3545 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3546 | ::basicBlock->appendInst(select); |
| 3547 | |
| 3548 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3552 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3553 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3554 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3555 | ::basicBlock->appendInst(cmp); |
| 3556 | |
| 3557 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3558 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3559 | ::basicBlock->appendInst(select); |
| 3560 | |
| 3561 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3565 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3566 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3567 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3568 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3569 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3570 | paddusw->addArg(x.value); |
| 3571 | paddusw->addArg(y.value); |
| 3572 | ::basicBlock->appendInst(paddusw); |
| 3573 | |
| 3574 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3578 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3579 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3580 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3581 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3582 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3583 | psubusw->addArg(x.value); |
| 3584 | psubusw->addArg(y.value); |
| 3585 | ::basicBlock->appendInst(psubusw); |
| 3586 | |
| 3587 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3591 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3592 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3593 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3594 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3595 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3596 | pmulhuw->addArg(x.value); |
| 3597 | pmulhuw->addArg(y.value); |
| 3598 | ::basicBlock->appendInst(pmulhuw); |
| 3599 | |
| 3600 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3604 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3605 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3609 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3610 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3611 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3612 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3613 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3614 | pack->addArg(x.value); |
| 3615 | pack->addArg(y.value); |
| 3616 | ::basicBlock->appendInst(pack); |
| 3617 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3618 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | Type *UShort4::getType() |
| 3622 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3623 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3627 | { |
| 3628 | // xyzw.parent = this; |
| 3629 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3630 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3631 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | Short8::Short8(RValue<Short8> rhs) |
| 3635 | { |
| 3636 | // xyzw.parent = this; |
| 3637 | |
| 3638 | storeValue(rhs.value); |
| 3639 | } |
| 3640 | |
| 3641 | Short8::Short8(const Reference<Short8> &rhs) |
| 3642 | { |
| 3643 | // xyzw.parent = this; |
| 3644 | |
| 3645 | Value *value = rhs.loadValue(); |
| 3646 | storeValue(value); |
| 3647 | } |
| 3648 | |
| 3649 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3650 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3651 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3652 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3653 | |
| 3654 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3658 | { |
| 3659 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3660 | } |
| 3661 | |
| 3662 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3663 | { |
| 3664 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3665 | } |
| 3666 | |
| 3667 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3668 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3669 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3673 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3674 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3678 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3679 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | RValue<Int4> Abs(RValue<Int4> x) |
| 3683 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3684 | auto negative = x >> 31; |
| 3685 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3689 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3690 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | Type *Short8::getType() |
| 3694 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3695 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | 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) |
| 3699 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3700 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3701 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3705 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3706 | storeValue(rhs.value); |
| 3707 | } |
| 3708 | |
| 3709 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3710 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3711 | Value *value = rhs.loadValue(); |
| 3712 | storeValue(value); |
| 3713 | } |
| 3714 | |
| 3715 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3716 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3717 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3718 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3719 | |
| 3720 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3721 | } |
| 3722 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3723 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3724 | { |
| 3725 | storeValue(rhs.value); |
| 3726 | |
| 3727 | return rhs; |
| 3728 | } |
| 3729 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3730 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3731 | { |
| 3732 | Value *value = rhs.loadValue(); |
| 3733 | storeValue(value); |
| 3734 | |
| 3735 | return RValue<UShort8>(value); |
| 3736 | } |
| 3737 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3738 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3739 | { |
| 3740 | Value *value = rhs.loadValue(); |
| 3741 | storeValue(value); |
| 3742 | |
| 3743 | return RValue<UShort8>(value); |
| 3744 | } |
| 3745 | |
| 3746 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3747 | { |
| 3748 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3749 | } |
| 3750 | |
| 3751 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3752 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3753 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3757 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3758 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3762 | { |
| 3763 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3764 | } |
| 3765 | |
| 3766 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3767 | { |
| 3768 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3769 | } |
| 3770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3771 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3772 | { |
| 3773 | return lhs = lhs + rhs; |
| 3774 | } |
| 3775 | |
| 3776 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3777 | { |
| 3778 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3779 | } |
| 3780 | |
| 3781 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3782 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3783 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3787 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3788 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3792 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3793 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3794 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3795 | // } |
| 3796 | |
| 3797 | Type *UShort8::getType() |
| 3798 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3799 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | Int::Int(Argument<Int> argument) |
| 3803 | { |
| 3804 | storeValue(argument.value); |
| 3805 | } |
| 3806 | |
| 3807 | Int::Int(RValue<Byte> cast) |
| 3808 | { |
| 3809 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3810 | |
| 3811 | storeValue(integer); |
| 3812 | } |
| 3813 | |
| 3814 | Int::Int(RValue<SByte> cast) |
| 3815 | { |
| 3816 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3817 | |
| 3818 | storeValue(integer); |
| 3819 | } |
| 3820 | |
| 3821 | Int::Int(RValue<Short> cast) |
| 3822 | { |
| 3823 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3824 | |
| 3825 | storeValue(integer); |
| 3826 | } |
| 3827 | |
| 3828 | Int::Int(RValue<UShort> cast) |
| 3829 | { |
| 3830 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3831 | |
| 3832 | storeValue(integer); |
| 3833 | } |
| 3834 | |
| 3835 | Int::Int(RValue<Int2> cast) |
| 3836 | { |
| 3837 | *this = Extract(cast, 0); |
| 3838 | } |
| 3839 | |
| 3840 | Int::Int(RValue<Long> cast) |
| 3841 | { |
| 3842 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3843 | |
| 3844 | storeValue(integer); |
| 3845 | } |
| 3846 | |
| 3847 | Int::Int(RValue<Float> cast) |
| 3848 | { |
| 3849 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3850 | |
| 3851 | storeValue(integer); |
| 3852 | } |
| 3853 | |
| 3854 | Int::Int() |
| 3855 | { |
| 3856 | } |
| 3857 | |
| 3858 | Int::Int(int x) |
| 3859 | { |
| 3860 | storeValue(Nucleus::createConstantInt(x)); |
| 3861 | } |
| 3862 | |
| 3863 | Int::Int(RValue<Int> rhs) |
| 3864 | { |
| 3865 | storeValue(rhs.value); |
| 3866 | } |
| 3867 | |
| 3868 | Int::Int(RValue<UInt> rhs) |
| 3869 | { |
| 3870 | storeValue(rhs.value); |
| 3871 | } |
| 3872 | |
| 3873 | Int::Int(const Int &rhs) |
| 3874 | { |
| 3875 | Value *value = rhs.loadValue(); |
| 3876 | storeValue(value); |
| 3877 | } |
| 3878 | |
| 3879 | Int::Int(const Reference<Int> &rhs) |
| 3880 | { |
| 3881 | Value *value = rhs.loadValue(); |
| 3882 | storeValue(value); |
| 3883 | } |
| 3884 | |
| 3885 | Int::Int(const UInt &rhs) |
| 3886 | { |
| 3887 | Value *value = rhs.loadValue(); |
| 3888 | storeValue(value); |
| 3889 | } |
| 3890 | |
| 3891 | Int::Int(const Reference<UInt> &rhs) |
| 3892 | { |
| 3893 | Value *value = rhs.loadValue(); |
| 3894 | storeValue(value); |
| 3895 | } |
| 3896 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3897 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3898 | { |
| 3899 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3900 | } |
| 3901 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3902 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3903 | { |
| 3904 | storeValue(rhs.value); |
| 3905 | |
| 3906 | return rhs; |
| 3907 | } |
| 3908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3909 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3910 | { |
| 3911 | storeValue(rhs.value); |
| 3912 | |
| 3913 | return RValue<Int>(rhs); |
| 3914 | } |
| 3915 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3916 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3917 | { |
| 3918 | Value *value = rhs.loadValue(); |
| 3919 | storeValue(value); |
| 3920 | |
| 3921 | return RValue<Int>(value); |
| 3922 | } |
| 3923 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3924 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3925 | { |
| 3926 | Value *value = rhs.loadValue(); |
| 3927 | storeValue(value); |
| 3928 | |
| 3929 | return RValue<Int>(value); |
| 3930 | } |
| 3931 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3932 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3933 | { |
| 3934 | Value *value = rhs.loadValue(); |
| 3935 | storeValue(value); |
| 3936 | |
| 3937 | return RValue<Int>(value); |
| 3938 | } |
| 3939 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3940 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3941 | { |
| 3942 | Value *value = rhs.loadValue(); |
| 3943 | storeValue(value); |
| 3944 | |
| 3945 | return RValue<Int>(value); |
| 3946 | } |
| 3947 | |
| 3948 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3949 | { |
| 3950 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3951 | } |
| 3952 | |
| 3953 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3954 | { |
| 3955 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3956 | } |
| 3957 | |
| 3958 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3959 | { |
| 3960 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3961 | } |
| 3962 | |
| 3963 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3964 | { |
| 3965 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3966 | } |
| 3967 | |
| 3968 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3969 | { |
| 3970 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3971 | } |
| 3972 | |
| 3973 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3974 | { |
| 3975 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3976 | } |
| 3977 | |
| 3978 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 3979 | { |
| 3980 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3981 | } |
| 3982 | |
| 3983 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 3984 | { |
| 3985 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3986 | } |
| 3987 | |
| 3988 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 3989 | { |
| 3990 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3991 | } |
| 3992 | |
| 3993 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 3994 | { |
| 3995 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3996 | } |
| 3997 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3998 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3999 | { |
| 4000 | return lhs = lhs + rhs; |
| 4001 | } |
| 4002 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4003 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4004 | { |
| 4005 | return lhs = lhs - rhs; |
| 4006 | } |
| 4007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4008 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4009 | { |
| 4010 | return lhs = lhs * rhs; |
| 4011 | } |
| 4012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4013 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4014 | { |
| 4015 | return lhs = lhs / rhs; |
| 4016 | } |
| 4017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4018 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4019 | { |
| 4020 | return lhs = lhs % rhs; |
| 4021 | } |
| 4022 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4023 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4024 | { |
| 4025 | return lhs = lhs & rhs; |
| 4026 | } |
| 4027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4028 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4029 | { |
| 4030 | return lhs = lhs | rhs; |
| 4031 | } |
| 4032 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4033 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4034 | { |
| 4035 | return lhs = lhs ^ rhs; |
| 4036 | } |
| 4037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4038 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4039 | { |
| 4040 | return lhs = lhs << rhs; |
| 4041 | } |
| 4042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4043 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4044 | { |
| 4045 | return lhs = lhs >> rhs; |
| 4046 | } |
| 4047 | |
| 4048 | RValue<Int> operator+(RValue<Int> val) |
| 4049 | { |
| 4050 | return val; |
| 4051 | } |
| 4052 | |
| 4053 | RValue<Int> operator-(RValue<Int> val) |
| 4054 | { |
| 4055 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4056 | } |
| 4057 | |
| 4058 | RValue<Int> operator~(RValue<Int> val) |
| 4059 | { |
| 4060 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4061 | } |
| 4062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4063 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4064 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4065 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4066 | val += 1; |
| 4067 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4068 | } |
| 4069 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4070 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4071 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4072 | val += 1; |
| 4073 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4074 | } |
| 4075 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4076 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4077 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4078 | RValue<Int> res = val; |
| 4079 | val -= 1; |
| 4080 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4081 | } |
| 4082 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4083 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4084 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4085 | val -= 1; |
| 4086 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4090 | { |
| 4091 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4092 | } |
| 4093 | |
| 4094 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4095 | { |
| 4096 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4097 | } |
| 4098 | |
| 4099 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4100 | { |
| 4101 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4102 | } |
| 4103 | |
| 4104 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4105 | { |
| 4106 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4107 | } |
| 4108 | |
| 4109 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4110 | { |
| 4111 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4112 | } |
| 4113 | |
| 4114 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4115 | { |
| 4116 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4117 | } |
| 4118 | |
| 4119 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4120 | { |
| 4121 | return IfThenElse(x > y, x, y); |
| 4122 | } |
| 4123 | |
| 4124 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4125 | { |
| 4126 | return IfThenElse(x < y, x, y); |
| 4127 | } |
| 4128 | |
| 4129 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4130 | { |
| 4131 | return Min(Max(x, min), max); |
| 4132 | } |
| 4133 | |
| 4134 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4135 | { |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 4136 | RValue<Float> rounded = Round(cast); |
| 4137 | |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4138 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 4139 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4140 | ::basicBlock->appendInst(round); |
| 4141 | |
| 4142 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | Type *Int::getType() |
| 4146 | { |
| 4147 | return T(Ice::IceType_i32); |
| 4148 | } |
| 4149 | |
| 4150 | Long::Long(RValue<Int> cast) |
| 4151 | { |
| 4152 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4153 | |
| 4154 | storeValue(integer); |
| 4155 | } |
| 4156 | |
| 4157 | Long::Long(RValue<UInt> cast) |
| 4158 | { |
| 4159 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4160 | |
| 4161 | storeValue(integer); |
| 4162 | } |
| 4163 | |
| 4164 | Long::Long() |
| 4165 | { |
| 4166 | } |
| 4167 | |
| 4168 | Long::Long(RValue<Long> rhs) |
| 4169 | { |
| 4170 | storeValue(rhs.value); |
| 4171 | } |
| 4172 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4173 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4174 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4175 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4176 | } |
| 4177 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4178 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4179 | { |
| 4180 | storeValue(rhs.value); |
| 4181 | |
| 4182 | return rhs; |
| 4183 | } |
| 4184 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4185 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4186 | { |
| 4187 | Value *value = rhs.loadValue(); |
| 4188 | storeValue(value); |
| 4189 | |
| 4190 | return RValue<Long>(value); |
| 4191 | } |
| 4192 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4193 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4194 | { |
| 4195 | Value *value = rhs.loadValue(); |
| 4196 | storeValue(value); |
| 4197 | |
| 4198 | return RValue<Long>(value); |
| 4199 | } |
| 4200 | |
| 4201 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4202 | { |
| 4203 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4204 | } |
| 4205 | |
| 4206 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4207 | { |
| 4208 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4209 | } |
| 4210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4211 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4212 | { |
| 4213 | return lhs = lhs + rhs; |
| 4214 | } |
| 4215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4216 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4217 | { |
| 4218 | return lhs = lhs - rhs; |
| 4219 | } |
| 4220 | |
| 4221 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4222 | { |
| 4223 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4224 | } |
| 4225 | |
| 4226 | Type *Long::getType() |
| 4227 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4228 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4229 | } |
| 4230 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4231 | UInt::UInt(Argument<UInt> argument) |
| 4232 | { |
| 4233 | storeValue(argument.value); |
| 4234 | } |
| 4235 | |
| 4236 | UInt::UInt(RValue<UShort> cast) |
| 4237 | { |
| 4238 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4239 | |
| 4240 | storeValue(integer); |
| 4241 | } |
| 4242 | |
| 4243 | UInt::UInt(RValue<Long> cast) |
| 4244 | { |
| 4245 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4246 | |
| 4247 | storeValue(integer); |
| 4248 | } |
| 4249 | |
| 4250 | UInt::UInt(RValue<Float> cast) |
| 4251 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4252 | // Smallest positive value representable in UInt, but not in Int |
| 4253 | const unsigned int ustart = 0x80000000u; |
| 4254 | const float ustartf = float(ustart); |
| 4255 | |
| 4256 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4257 | storeValue((~(As<Int>(cast) >> 31) & |
| 4258 | // Check if the value can be represented as an Int |
| 4259 | IfThenElse(cast >= ustartf, |
| 4260 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4261 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4262 | // Otherwise, just convert normally |
| 4263 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | UInt::UInt() |
| 4267 | { |
| 4268 | } |
| 4269 | |
| 4270 | UInt::UInt(int x) |
| 4271 | { |
| 4272 | storeValue(Nucleus::createConstantInt(x)); |
| 4273 | } |
| 4274 | |
| 4275 | UInt::UInt(unsigned int x) |
| 4276 | { |
| 4277 | storeValue(Nucleus::createConstantInt(x)); |
| 4278 | } |
| 4279 | |
| 4280 | UInt::UInt(RValue<UInt> rhs) |
| 4281 | { |
| 4282 | storeValue(rhs.value); |
| 4283 | } |
| 4284 | |
| 4285 | UInt::UInt(RValue<Int> rhs) |
| 4286 | { |
| 4287 | storeValue(rhs.value); |
| 4288 | } |
| 4289 | |
| 4290 | UInt::UInt(const UInt &rhs) |
| 4291 | { |
| 4292 | Value *value = rhs.loadValue(); |
| 4293 | storeValue(value); |
| 4294 | } |
| 4295 | |
| 4296 | UInt::UInt(const Reference<UInt> &rhs) |
| 4297 | { |
| 4298 | Value *value = rhs.loadValue(); |
| 4299 | storeValue(value); |
| 4300 | } |
| 4301 | |
| 4302 | UInt::UInt(const Int &rhs) |
| 4303 | { |
| 4304 | Value *value = rhs.loadValue(); |
| 4305 | storeValue(value); |
| 4306 | } |
| 4307 | |
| 4308 | UInt::UInt(const Reference<Int> &rhs) |
| 4309 | { |
| 4310 | Value *value = rhs.loadValue(); |
| 4311 | storeValue(value); |
| 4312 | } |
| 4313 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4314 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4315 | { |
| 4316 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4317 | } |
| 4318 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4319 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4320 | { |
| 4321 | storeValue(rhs.value); |
| 4322 | |
| 4323 | return rhs; |
| 4324 | } |
| 4325 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4326 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4327 | { |
| 4328 | storeValue(rhs.value); |
| 4329 | |
| 4330 | return RValue<UInt>(rhs); |
| 4331 | } |
| 4332 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4333 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4334 | { |
| 4335 | Value *value = rhs.loadValue(); |
| 4336 | storeValue(value); |
| 4337 | |
| 4338 | return RValue<UInt>(value); |
| 4339 | } |
| 4340 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4341 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4342 | { |
| 4343 | Value *value = rhs.loadValue(); |
| 4344 | storeValue(value); |
| 4345 | |
| 4346 | return RValue<UInt>(value); |
| 4347 | } |
| 4348 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4349 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4350 | { |
| 4351 | Value *value = rhs.loadValue(); |
| 4352 | storeValue(value); |
| 4353 | |
| 4354 | return RValue<UInt>(value); |
| 4355 | } |
| 4356 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4357 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4358 | { |
| 4359 | Value *value = rhs.loadValue(); |
| 4360 | storeValue(value); |
| 4361 | |
| 4362 | return RValue<UInt>(value); |
| 4363 | } |
| 4364 | |
| 4365 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4366 | { |
| 4367 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4368 | } |
| 4369 | |
| 4370 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4371 | { |
| 4372 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4373 | } |
| 4374 | |
| 4375 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4376 | { |
| 4377 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4378 | } |
| 4379 | |
| 4380 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4381 | { |
| 4382 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4383 | } |
| 4384 | |
| 4385 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4386 | { |
| 4387 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4388 | } |
| 4389 | |
| 4390 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4391 | { |
| 4392 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4393 | } |
| 4394 | |
| 4395 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4396 | { |
| 4397 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4398 | } |
| 4399 | |
| 4400 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4401 | { |
| 4402 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4403 | } |
| 4404 | |
| 4405 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4406 | { |
| 4407 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4408 | } |
| 4409 | |
| 4410 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4411 | { |
| 4412 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4413 | } |
| 4414 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4415 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4416 | { |
| 4417 | return lhs = lhs + rhs; |
| 4418 | } |
| 4419 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4420 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4421 | { |
| 4422 | return lhs = lhs - rhs; |
| 4423 | } |
| 4424 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4425 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4426 | { |
| 4427 | return lhs = lhs * rhs; |
| 4428 | } |
| 4429 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4430 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4431 | { |
| 4432 | return lhs = lhs / rhs; |
| 4433 | } |
| 4434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4435 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4436 | { |
| 4437 | return lhs = lhs % rhs; |
| 4438 | } |
| 4439 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4440 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4441 | { |
| 4442 | return lhs = lhs & rhs; |
| 4443 | } |
| 4444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4445 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4446 | { |
| 4447 | return lhs = lhs | rhs; |
| 4448 | } |
| 4449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4450 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4451 | { |
| 4452 | return lhs = lhs ^ rhs; |
| 4453 | } |
| 4454 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4455 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4456 | { |
| 4457 | return lhs = lhs << rhs; |
| 4458 | } |
| 4459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4460 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4461 | { |
| 4462 | return lhs = lhs >> rhs; |
| 4463 | } |
| 4464 | |
| 4465 | RValue<UInt> operator+(RValue<UInt> val) |
| 4466 | { |
| 4467 | return val; |
| 4468 | } |
| 4469 | |
| 4470 | RValue<UInt> operator-(RValue<UInt> val) |
| 4471 | { |
| 4472 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4473 | } |
| 4474 | |
| 4475 | RValue<UInt> operator~(RValue<UInt> val) |
| 4476 | { |
| 4477 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4478 | } |
| 4479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4480 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4481 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4482 | RValue<UInt> res = val; |
| 4483 | val += 1; |
| 4484 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4485 | } |
| 4486 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4487 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4488 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4489 | val += 1; |
| 4490 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4491 | } |
| 4492 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4493 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4494 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4495 | RValue<UInt> res = val; |
| 4496 | val -= 1; |
| 4497 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4498 | } |
| 4499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4500 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4501 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4502 | val -= 1; |
| 4503 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4507 | { |
| 4508 | return IfThenElse(x > y, x, y); |
| 4509 | } |
| 4510 | |
| 4511 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4512 | { |
| 4513 | return IfThenElse(x < y, x, y); |
| 4514 | } |
| 4515 | |
| 4516 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4517 | { |
| 4518 | return Min(Max(x, min), max); |
| 4519 | } |
| 4520 | |
| 4521 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4522 | { |
| 4523 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4524 | } |
| 4525 | |
| 4526 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4527 | { |
| 4528 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4529 | } |
| 4530 | |
| 4531 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4532 | { |
| 4533 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4534 | } |
| 4535 | |
| 4536 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4537 | { |
| 4538 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4539 | } |
| 4540 | |
| 4541 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4542 | { |
| 4543 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4544 | } |
| 4545 | |
| 4546 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4547 | { |
| 4548 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4549 | } |
| 4550 | |
| 4551 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4552 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4553 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4554 | // } |
| 4555 | |
| 4556 | Type *UInt::getType() |
| 4557 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4558 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | // Int2::Int2(RValue<Int> cast) |
| 4562 | // { |
| 4563 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4564 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4565 | // |
| 4566 | // Constant *shuffle[2]; |
| 4567 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4568 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4569 | // |
| 4570 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4571 | // |
| 4572 | // storeValue(replicate); |
| 4573 | // } |
| 4574 | |
| 4575 | Int2::Int2(RValue<Int4> cast) |
| 4576 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4577 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | Int2::Int2() |
| 4581 | { |
| 4582 | // xy.parent = this; |
| 4583 | } |
| 4584 | |
| 4585 | Int2::Int2(int x, int y) |
| 4586 | { |
| 4587 | // xy.parent = this; |
| 4588 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4589 | int64_t constantVector[2] = {x, y}; |
| 4590 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | Int2::Int2(RValue<Int2> rhs) |
| 4594 | { |
| 4595 | // xy.parent = this; |
| 4596 | |
| 4597 | storeValue(rhs.value); |
| 4598 | } |
| 4599 | |
| 4600 | Int2::Int2(const Int2 &rhs) |
| 4601 | { |
| 4602 | // xy.parent = this; |
| 4603 | |
| 4604 | Value *value = rhs.loadValue(); |
| 4605 | storeValue(value); |
| 4606 | } |
| 4607 | |
| 4608 | Int2::Int2(const Reference<Int2> &rhs) |
| 4609 | { |
| 4610 | // xy.parent = this; |
| 4611 | |
| 4612 | Value *value = rhs.loadValue(); |
| 4613 | storeValue(value); |
| 4614 | } |
| 4615 | |
| 4616 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4617 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4618 | int shuffle[4] = {0, 4, 1, 5}; |
| 4619 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4620 | |
| 4621 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4622 | } |
| 4623 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4624 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4625 | { |
| 4626 | storeValue(rhs.value); |
| 4627 | |
| 4628 | return rhs; |
| 4629 | } |
| 4630 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4631 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4632 | { |
| 4633 | Value *value = rhs.loadValue(); |
| 4634 | storeValue(value); |
| 4635 | |
| 4636 | return RValue<Int2>(value); |
| 4637 | } |
| 4638 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4639 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4640 | { |
| 4641 | Value *value = rhs.loadValue(); |
| 4642 | storeValue(value); |
| 4643 | |
| 4644 | return RValue<Int2>(value); |
| 4645 | } |
| 4646 | |
| 4647 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4648 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4649 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4653 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4654 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4658 | // { |
| 4659 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4660 | // } |
| 4661 | |
| 4662 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4663 | // { |
| 4664 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4665 | // } |
| 4666 | |
| 4667 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4668 | // { |
| 4669 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4670 | // } |
| 4671 | |
| 4672 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4673 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4674 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4678 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4679 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4683 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4684 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4688 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4689 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4693 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4694 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4695 | } |
| 4696 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4697 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4698 | { |
| 4699 | return lhs = lhs + rhs; |
| 4700 | } |
| 4701 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4702 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4703 | { |
| 4704 | return lhs = lhs - rhs; |
| 4705 | } |
| 4706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4707 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4708 | // { |
| 4709 | // return lhs = lhs * rhs; |
| 4710 | // } |
| 4711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4712 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4713 | // { |
| 4714 | // return lhs = lhs / rhs; |
| 4715 | // } |
| 4716 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4717 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4718 | // { |
| 4719 | // return lhs = lhs % rhs; |
| 4720 | // } |
| 4721 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4722 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4723 | { |
| 4724 | return lhs = lhs & rhs; |
| 4725 | } |
| 4726 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4727 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4728 | { |
| 4729 | return lhs = lhs | rhs; |
| 4730 | } |
| 4731 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4732 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4733 | { |
| 4734 | return lhs = lhs ^ rhs; |
| 4735 | } |
| 4736 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4737 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4738 | { |
| 4739 | return lhs = lhs << rhs; |
| 4740 | } |
| 4741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4742 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4743 | { |
| 4744 | return lhs = lhs >> rhs; |
| 4745 | } |
| 4746 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4747 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4748 | // { |
| 4749 | // return val; |
| 4750 | // } |
| 4751 | |
| 4752 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4753 | // { |
| 4754 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4755 | // } |
| 4756 | |
| 4757 | RValue<Int2> operator~(RValue<Int2> val) |
| 4758 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4759 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4760 | } |
| 4761 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4762 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4763 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4764 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4765 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4766 | } |
| 4767 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4768 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4769 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4770 | int shuffle[16] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4771 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4772 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4776 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4777 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4781 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4782 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | Type *Int2::getType() |
| 4786 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4787 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | UInt2::UInt2() |
| 4791 | { |
| 4792 | // xy.parent = this; |
| 4793 | } |
| 4794 | |
| 4795 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4796 | { |
| 4797 | // xy.parent = this; |
| 4798 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4799 | int64_t constantVector[2] = {x, y}; |
| 4800 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4804 | { |
| 4805 | // xy.parent = this; |
| 4806 | |
| 4807 | storeValue(rhs.value); |
| 4808 | } |
| 4809 | |
| 4810 | UInt2::UInt2(const UInt2 &rhs) |
| 4811 | { |
| 4812 | // xy.parent = this; |
| 4813 | |
| 4814 | Value *value = rhs.loadValue(); |
| 4815 | storeValue(value); |
| 4816 | } |
| 4817 | |
| 4818 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4819 | { |
| 4820 | // xy.parent = this; |
| 4821 | |
| 4822 | Value *value = rhs.loadValue(); |
| 4823 | storeValue(value); |
| 4824 | } |
| 4825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4826 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4827 | { |
| 4828 | storeValue(rhs.value); |
| 4829 | |
| 4830 | return rhs; |
| 4831 | } |
| 4832 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4833 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4834 | { |
| 4835 | Value *value = rhs.loadValue(); |
| 4836 | storeValue(value); |
| 4837 | |
| 4838 | return RValue<UInt2>(value); |
| 4839 | } |
| 4840 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4841 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4842 | { |
| 4843 | Value *value = rhs.loadValue(); |
| 4844 | storeValue(value); |
| 4845 | |
| 4846 | return RValue<UInt2>(value); |
| 4847 | } |
| 4848 | |
| 4849 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4850 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4851 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4855 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4856 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4860 | // { |
| 4861 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4862 | // } |
| 4863 | |
| 4864 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4865 | // { |
| 4866 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4867 | // } |
| 4868 | |
| 4869 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4870 | // { |
| 4871 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4872 | // } |
| 4873 | |
| 4874 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4875 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4876 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4880 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4881 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4885 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4886 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4890 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4891 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4895 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4896 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4897 | } |
| 4898 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4899 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4900 | { |
| 4901 | return lhs = lhs + rhs; |
| 4902 | } |
| 4903 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4904 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4905 | { |
| 4906 | return lhs = lhs - rhs; |
| 4907 | } |
| 4908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4909 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4910 | // { |
| 4911 | // return lhs = lhs * rhs; |
| 4912 | // } |
| 4913 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4914 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4915 | // { |
| 4916 | // return lhs = lhs / rhs; |
| 4917 | // } |
| 4918 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4919 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4920 | // { |
| 4921 | // return lhs = lhs % rhs; |
| 4922 | // } |
| 4923 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4924 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4925 | { |
| 4926 | return lhs = lhs & rhs; |
| 4927 | } |
| 4928 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4929 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4930 | { |
| 4931 | return lhs = lhs | rhs; |
| 4932 | } |
| 4933 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4934 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4935 | { |
| 4936 | return lhs = lhs ^ rhs; |
| 4937 | } |
| 4938 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4939 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4940 | { |
| 4941 | return lhs = lhs << rhs; |
| 4942 | } |
| 4943 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4944 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4945 | { |
| 4946 | return lhs = lhs >> rhs; |
| 4947 | } |
| 4948 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4949 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4950 | // { |
| 4951 | // return val; |
| 4952 | // } |
| 4953 | |
| 4954 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4955 | // { |
| 4956 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4957 | // } |
| 4958 | |
| 4959 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4960 | { |
| 4961 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4962 | } |
| 4963 | |
| 4964 | Type *UInt2::getType() |
| 4965 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4966 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | Int4::Int4(RValue<Byte4> cast) |
| 4970 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4971 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4972 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4973 | |
| 4974 | Value *e; |
| 4975 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4976 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4977 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4978 | |
| 4979 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4980 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4981 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4982 | |
| 4983 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4984 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | Int4::Int4(RValue<SByte4> cast) |
| 4988 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4989 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4990 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4991 | |
| 4992 | Value *e; |
| 4993 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4994 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4995 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4996 | |
| 4997 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4998 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4999 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 5000 | |
| 5001 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5002 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5003 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | Int4::Int4(RValue<Float4> cast) |
| 5007 | { |
| 5008 | // xyzw.parent = this; |
| 5009 | |
| 5010 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 5011 | |
| 5012 | storeValue(xyzw); |
| 5013 | } |
| 5014 | |
| 5015 | Int4::Int4(RValue<Short4> cast) |
| 5016 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5017 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5018 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 5019 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5020 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5021 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | Int4::Int4(RValue<UShort4> cast) |
| 5025 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5026 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5027 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5028 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5029 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | Int4::Int4() |
| 5033 | { |
| 5034 | // xyzw.parent = this; |
| 5035 | } |
| 5036 | |
| 5037 | Int4::Int4(int xyzw) |
| 5038 | { |
| 5039 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5040 | } |
| 5041 | |
| 5042 | Int4::Int4(int x, int yzw) |
| 5043 | { |
| 5044 | constant(x, yzw, yzw, yzw); |
| 5045 | } |
| 5046 | |
| 5047 | Int4::Int4(int x, int y, int zw) |
| 5048 | { |
| 5049 | constant(x, y, zw, zw); |
| 5050 | } |
| 5051 | |
| 5052 | Int4::Int4(int x, int y, int z, int w) |
| 5053 | { |
| 5054 | constant(x, y, z, w); |
| 5055 | } |
| 5056 | |
| 5057 | void Int4::constant(int x, int y, int z, int w) |
| 5058 | { |
| 5059 | // xyzw.parent = this; |
| 5060 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5061 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5062 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | Int4::Int4(RValue<Int4> rhs) |
| 5066 | { |
| 5067 | // xyzw.parent = this; |
| 5068 | |
| 5069 | storeValue(rhs.value); |
| 5070 | } |
| 5071 | |
| 5072 | Int4::Int4(const Int4 &rhs) |
| 5073 | { |
| 5074 | // xyzw.parent = this; |
| 5075 | |
| 5076 | Value *value = rhs.loadValue(); |
| 5077 | storeValue(value); |
| 5078 | } |
| 5079 | |
| 5080 | Int4::Int4(const Reference<Int4> &rhs) |
| 5081 | { |
| 5082 | // xyzw.parent = this; |
| 5083 | |
| 5084 | Value *value = rhs.loadValue(); |
| 5085 | storeValue(value); |
| 5086 | } |
| 5087 | |
| 5088 | Int4::Int4(RValue<UInt4> rhs) |
| 5089 | { |
| 5090 | // xyzw.parent = this; |
| 5091 | |
| 5092 | storeValue(rhs.value); |
| 5093 | } |
| 5094 | |
| 5095 | Int4::Int4(const UInt4 &rhs) |
| 5096 | { |
| 5097 | // xyzw.parent = this; |
| 5098 | |
| 5099 | Value *value = rhs.loadValue(); |
| 5100 | storeValue(value); |
| 5101 | } |
| 5102 | |
| 5103 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5104 | { |
| 5105 | // xyzw.parent = this; |
| 5106 | |
| 5107 | Value *value = rhs.loadValue(); |
| 5108 | storeValue(value); |
| 5109 | } |
| 5110 | |
| 5111 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5112 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5113 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5114 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5115 | |
| 5116 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | Int4::Int4(RValue<Int> rhs) |
| 5120 | { |
| 5121 | // xyzw.parent = this; |
| 5122 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5123 | Value *vector = loadValue(); |
| 5124 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5125 | |
| 5126 | int swizzle[4] = {0, 0, 0, 0}; |
| 5127 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 5128 | |
| 5129 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | Int4::Int4(const Int &rhs) |
| 5133 | { |
| 5134 | // xyzw.parent = this; |
| 5135 | |
| 5136 | *this = RValue<Int>(rhs.loadValue()); |
| 5137 | } |
| 5138 | |
| 5139 | Int4::Int4(const Reference<Int> &rhs) |
| 5140 | { |
| 5141 | // xyzw.parent = this; |
| 5142 | |
| 5143 | *this = RValue<Int>(rhs.loadValue()); |
| 5144 | } |
| 5145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5146 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5147 | { |
| 5148 | storeValue(rhs.value); |
| 5149 | |
| 5150 | return rhs; |
| 5151 | } |
| 5152 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5153 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5154 | { |
| 5155 | Value *value = rhs.loadValue(); |
| 5156 | storeValue(value); |
| 5157 | |
| 5158 | return RValue<Int4>(value); |
| 5159 | } |
| 5160 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5161 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5162 | { |
| 5163 | Value *value = rhs.loadValue(); |
| 5164 | storeValue(value); |
| 5165 | |
| 5166 | return RValue<Int4>(value); |
| 5167 | } |
| 5168 | |
| 5169 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5170 | { |
| 5171 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5172 | } |
| 5173 | |
| 5174 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5175 | { |
| 5176 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5177 | } |
| 5178 | |
| 5179 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5180 | { |
| 5181 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5182 | } |
| 5183 | |
| 5184 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5185 | { |
| 5186 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5187 | } |
| 5188 | |
| 5189 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5190 | { |
| 5191 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5192 | } |
| 5193 | |
| 5194 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5195 | { |
| 5196 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5197 | } |
| 5198 | |
| 5199 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5200 | { |
| 5201 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5202 | } |
| 5203 | |
| 5204 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5205 | { |
| 5206 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5207 | } |
| 5208 | |
| 5209 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5210 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5211 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5215 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5216 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5220 | { |
| 5221 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5222 | } |
| 5223 | |
| 5224 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5225 | { |
| 5226 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5227 | } |
| 5228 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5229 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5230 | { |
| 5231 | return lhs = lhs + rhs; |
| 5232 | } |
| 5233 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5234 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5235 | { |
| 5236 | return lhs = lhs - rhs; |
| 5237 | } |
| 5238 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5239 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5240 | { |
| 5241 | return lhs = lhs * rhs; |
| 5242 | } |
| 5243 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5244 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5245 | // { |
| 5246 | // return lhs = lhs / rhs; |
| 5247 | // } |
| 5248 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5249 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5250 | // { |
| 5251 | // return lhs = lhs % rhs; |
| 5252 | // } |
| 5253 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5254 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5255 | { |
| 5256 | return lhs = lhs & rhs; |
| 5257 | } |
| 5258 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5259 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5260 | { |
| 5261 | return lhs = lhs | rhs; |
| 5262 | } |
| 5263 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5264 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5265 | { |
| 5266 | return lhs = lhs ^ rhs; |
| 5267 | } |
| 5268 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5269 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5270 | { |
| 5271 | return lhs = lhs << rhs; |
| 5272 | } |
| 5273 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5274 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5275 | { |
| 5276 | return lhs = lhs >> rhs; |
| 5277 | } |
| 5278 | |
| 5279 | RValue<Int4> operator+(RValue<Int4> val) |
| 5280 | { |
| 5281 | return val; |
| 5282 | } |
| 5283 | |
| 5284 | RValue<Int4> operator-(RValue<Int4> val) |
| 5285 | { |
| 5286 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5287 | } |
| 5288 | |
| 5289 | RValue<Int4> operator~(RValue<Int4> val) |
| 5290 | { |
| 5291 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5292 | } |
| 5293 | |
| 5294 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5295 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5296 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5300 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5301 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5305 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5306 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5310 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5311 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5315 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5316 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5320 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5321 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5325 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5326 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5327 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5328 | ::basicBlock->appendInst(cmp); |
| 5329 | |
| 5330 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5331 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5332 | ::basicBlock->appendInst(select); |
| 5333 | |
| 5334 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5338 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5339 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5340 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5341 | ::basicBlock->appendInst(cmp); |
| 5342 | |
| 5343 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5344 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5345 | ::basicBlock->appendInst(select); |
| 5346 | |
| 5347 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5351 | { |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 5352 | RValue<Float4> rounded = Round(cast); |
| 5353 | |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5354 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 5355 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5356 | ::basicBlock->appendInst(round); |
| 5357 | |
| 5358 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5362 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5363 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5364 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5365 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5366 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5367 | pack->addArg(x.value); |
| 5368 | pack->addArg(y.value); |
| 5369 | ::basicBlock->appendInst(pack); |
| 5370 | |
| 5371 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5375 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5376 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5380 | { |
| 5381 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5382 | } |
| 5383 | |
| 5384 | RValue<Int> SignMask(RValue<Int4> x) |
| 5385 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5386 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5387 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5388 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5389 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5390 | movmsk->addArg(x.value); |
| 5391 | ::basicBlock->appendInst(movmsk); |
| 5392 | |
| 5393 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5397 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5398 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | Type *Int4::getType() |
| 5402 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5403 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | UInt4::UInt4(RValue<Float4> cast) |
| 5407 | { |
| 5408 | // xyzw.parent = this; |
| 5409 | |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5410 | // Smallest positive value representable in UInt, but not in Int |
| 5411 | const unsigned int ustart = 0x80000000u; |
| 5412 | const float ustartf = float(ustart); |
| 5413 | |
| 5414 | // Check if the value can be represented as an Int |
| 5415 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5416 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5417 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5418 | // Otherwise, just convert normally |
| 5419 | (~uiValue & Int4(cast)); |
| 5420 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5421 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | UInt4::UInt4() |
| 5425 | { |
| 5426 | // xyzw.parent = this; |
| 5427 | } |
| 5428 | |
| 5429 | UInt4::UInt4(int xyzw) |
| 5430 | { |
| 5431 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5432 | } |
| 5433 | |
| 5434 | UInt4::UInt4(int x, int yzw) |
| 5435 | { |
| 5436 | constant(x, yzw, yzw, yzw); |
| 5437 | } |
| 5438 | |
| 5439 | UInt4::UInt4(int x, int y, int zw) |
| 5440 | { |
| 5441 | constant(x, y, zw, zw); |
| 5442 | } |
| 5443 | |
| 5444 | UInt4::UInt4(int x, int y, int z, int w) |
| 5445 | { |
| 5446 | constant(x, y, z, w); |
| 5447 | } |
| 5448 | |
| 5449 | void UInt4::constant(int x, int y, int z, int w) |
| 5450 | { |
| 5451 | // xyzw.parent = this; |
| 5452 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5453 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5454 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5458 | { |
| 5459 | // xyzw.parent = this; |
| 5460 | |
| 5461 | storeValue(rhs.value); |
| 5462 | } |
| 5463 | |
| 5464 | UInt4::UInt4(const UInt4 &rhs) |
| 5465 | { |
| 5466 | // xyzw.parent = this; |
| 5467 | |
| 5468 | Value *value = rhs.loadValue(); |
| 5469 | storeValue(value); |
| 5470 | } |
| 5471 | |
| 5472 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5473 | { |
| 5474 | // xyzw.parent = this; |
| 5475 | |
| 5476 | Value *value = rhs.loadValue(); |
| 5477 | storeValue(value); |
| 5478 | } |
| 5479 | |
| 5480 | UInt4::UInt4(RValue<Int4> rhs) |
| 5481 | { |
| 5482 | // xyzw.parent = this; |
| 5483 | |
| 5484 | storeValue(rhs.value); |
| 5485 | } |
| 5486 | |
| 5487 | UInt4::UInt4(const Int4 &rhs) |
| 5488 | { |
| 5489 | // xyzw.parent = this; |
| 5490 | |
| 5491 | Value *value = rhs.loadValue(); |
| 5492 | storeValue(value); |
| 5493 | } |
| 5494 | |
| 5495 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5496 | { |
| 5497 | // xyzw.parent = this; |
| 5498 | |
| 5499 | Value *value = rhs.loadValue(); |
| 5500 | storeValue(value); |
| 5501 | } |
| 5502 | |
| 5503 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5504 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5505 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5506 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5507 | |
| 5508 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5509 | } |
| 5510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5511 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5512 | { |
| 5513 | storeValue(rhs.value); |
| 5514 | |
| 5515 | return rhs; |
| 5516 | } |
| 5517 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5518 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5519 | { |
| 5520 | Value *value = rhs.loadValue(); |
| 5521 | storeValue(value); |
| 5522 | |
| 5523 | return RValue<UInt4>(value); |
| 5524 | } |
| 5525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5526 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5527 | { |
| 5528 | Value *value = rhs.loadValue(); |
| 5529 | storeValue(value); |
| 5530 | |
| 5531 | return RValue<UInt4>(value); |
| 5532 | } |
| 5533 | |
| 5534 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5535 | { |
| 5536 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5537 | } |
| 5538 | |
| 5539 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5540 | { |
| 5541 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5542 | } |
| 5543 | |
| 5544 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5545 | { |
| 5546 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5547 | } |
| 5548 | |
| 5549 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5550 | { |
| 5551 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5552 | } |
| 5553 | |
| 5554 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5555 | { |
| 5556 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5557 | } |
| 5558 | |
| 5559 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5560 | { |
| 5561 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5562 | } |
| 5563 | |
| 5564 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5565 | { |
| 5566 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5567 | } |
| 5568 | |
| 5569 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5570 | { |
| 5571 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5572 | } |
| 5573 | |
| 5574 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5575 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5576 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5580 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5581 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5585 | { |
| 5586 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5587 | } |
| 5588 | |
| 5589 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5590 | { |
| 5591 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5592 | } |
| 5593 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5594 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5595 | { |
| 5596 | return lhs = lhs + rhs; |
| 5597 | } |
| 5598 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5599 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5600 | { |
| 5601 | return lhs = lhs - rhs; |
| 5602 | } |
| 5603 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5604 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5605 | { |
| 5606 | return lhs = lhs * rhs; |
| 5607 | } |
| 5608 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5609 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5610 | // { |
| 5611 | // return lhs = lhs / rhs; |
| 5612 | // } |
| 5613 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5614 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5615 | // { |
| 5616 | // return lhs = lhs % rhs; |
| 5617 | // } |
| 5618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5619 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5620 | { |
| 5621 | return lhs = lhs & rhs; |
| 5622 | } |
| 5623 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5624 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5625 | { |
| 5626 | return lhs = lhs | rhs; |
| 5627 | } |
| 5628 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5629 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5630 | { |
| 5631 | return lhs = lhs ^ rhs; |
| 5632 | } |
| 5633 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5634 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5635 | { |
| 5636 | return lhs = lhs << rhs; |
| 5637 | } |
| 5638 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5639 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5640 | { |
| 5641 | return lhs = lhs >> rhs; |
| 5642 | } |
| 5643 | |
| 5644 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5645 | { |
| 5646 | return val; |
| 5647 | } |
| 5648 | |
| 5649 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5650 | { |
| 5651 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5652 | } |
| 5653 | |
| 5654 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5655 | { |
| 5656 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5657 | } |
| 5658 | |
| 5659 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5660 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5661 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5665 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5666 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5670 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5671 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5675 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5676 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5680 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5681 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5685 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5686 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5690 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5691 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5692 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5693 | ::basicBlock->appendInst(cmp); |
| 5694 | |
| 5695 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5696 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5697 | ::basicBlock->appendInst(select); |
| 5698 | |
| 5699 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5703 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5704 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5705 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5706 | ::basicBlock->appendInst(cmp); |
| 5707 | |
| 5708 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5709 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5710 | ::basicBlock->appendInst(select); |
| 5711 | |
| 5712 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5716 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5717 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5718 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5719 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5720 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5721 | pack->addArg(x.value); |
| 5722 | pack->addArg(y.value); |
| 5723 | ::basicBlock->appendInst(pack); |
| 5724 | |
| 5725 | return RValue<UShort8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | Type *UInt4::getType() |
| 5729 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5730 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | Float::Float(RValue<Int> cast) |
| 5734 | { |
| 5735 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5736 | |
| 5737 | storeValue(integer); |
| 5738 | } |
| 5739 | |
| 5740 | Float::Float() |
| 5741 | { |
| 5742 | } |
| 5743 | |
| 5744 | Float::Float(float x) |
| 5745 | { |
| 5746 | storeValue(Nucleus::createConstantFloat(x)); |
| 5747 | } |
| 5748 | |
| 5749 | Float::Float(RValue<Float> rhs) |
| 5750 | { |
| 5751 | storeValue(rhs.value); |
| 5752 | } |
| 5753 | |
| 5754 | Float::Float(const Float &rhs) |
| 5755 | { |
| 5756 | Value *value = rhs.loadValue(); |
| 5757 | storeValue(value); |
| 5758 | } |
| 5759 | |
| 5760 | Float::Float(const Reference<Float> &rhs) |
| 5761 | { |
| 5762 | Value *value = rhs.loadValue(); |
| 5763 | storeValue(value); |
| 5764 | } |
| 5765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5766 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5767 | { |
| 5768 | storeValue(rhs.value); |
| 5769 | |
| 5770 | return rhs; |
| 5771 | } |
| 5772 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5773 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5774 | { |
| 5775 | Value *value = rhs.loadValue(); |
| 5776 | storeValue(value); |
| 5777 | |
| 5778 | return RValue<Float>(value); |
| 5779 | } |
| 5780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5781 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5782 | { |
| 5783 | Value *value = rhs.loadValue(); |
| 5784 | storeValue(value); |
| 5785 | |
| 5786 | return RValue<Float>(value); |
| 5787 | } |
| 5788 | |
| 5789 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5790 | { |
| 5791 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5792 | } |
| 5793 | |
| 5794 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5795 | { |
| 5796 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5797 | } |
| 5798 | |
| 5799 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5800 | { |
| 5801 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5802 | } |
| 5803 | |
| 5804 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5805 | { |
| 5806 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5807 | } |
| 5808 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5809 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5810 | { |
| 5811 | return lhs = lhs + rhs; |
| 5812 | } |
| 5813 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5814 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5815 | { |
| 5816 | return lhs = lhs - rhs; |
| 5817 | } |
| 5818 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5819 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5820 | { |
| 5821 | return lhs = lhs * rhs; |
| 5822 | } |
| 5823 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5824 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5825 | { |
| 5826 | return lhs = lhs / rhs; |
| 5827 | } |
| 5828 | |
| 5829 | RValue<Float> operator+(RValue<Float> val) |
| 5830 | { |
| 5831 | return val; |
| 5832 | } |
| 5833 | |
| 5834 | RValue<Float> operator-(RValue<Float> val) |
| 5835 | { |
| 5836 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5837 | } |
| 5838 | |
| 5839 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5840 | { |
| 5841 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5842 | } |
| 5843 | |
| 5844 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5845 | { |
| 5846 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5847 | } |
| 5848 | |
| 5849 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5850 | { |
| 5851 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5852 | } |
| 5853 | |
| 5854 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5855 | { |
| 5856 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5857 | } |
| 5858 | |
| 5859 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5860 | { |
| 5861 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5862 | } |
| 5863 | |
| 5864 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5865 | { |
| 5866 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5867 | } |
| 5868 | |
| 5869 | RValue<Float> Abs(RValue<Float> x) |
| 5870 | { |
| 5871 | return IfThenElse(x > 0.0f, x, -x); |
| 5872 | } |
| 5873 | |
| 5874 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5875 | { |
| 5876 | return IfThenElse(x > y, x, y); |
| 5877 | } |
| 5878 | |
| 5879 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5880 | { |
| 5881 | return IfThenElse(x < y, x, y); |
| 5882 | } |
| 5883 | |
| 5884 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5885 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5886 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5890 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5891 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | RValue<Float> Sqrt(RValue<Float> x) |
| 5895 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5896 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5897 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5898 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5899 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5900 | sqrt->addArg(x.value); |
| 5901 | ::basicBlock->appendInst(sqrt); |
| 5902 | |
| 5903 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | RValue<Float> Round(RValue<Float> x) |
| 5907 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5908 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | RValue<Float> Trunc(RValue<Float> x) |
| 5912 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5913 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | RValue<Float> Frac(RValue<Float> x) |
| 5917 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5918 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5919 | } |
| 5920 | |
| 5921 | RValue<Float> Floor(RValue<Float> x) |
| 5922 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5923 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | RValue<Float> Ceil(RValue<Float> x) |
| 5927 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5928 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | Type *Float::getType() |
| 5932 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5933 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | Float2::Float2(RValue<Float4> cast) |
| 5937 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5938 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | Type *Float2::getType() |
| 5942 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5943 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | Float4::Float4(RValue<Byte4> cast) |
| 5947 | { |
| 5948 | xyzw.parent = this; |
| 5949 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5950 | Value *a = Int4(cast).loadValue(); |
| 5951 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5952 | |
| 5953 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | Float4::Float4(RValue<SByte4> cast) |
| 5957 | { |
| 5958 | xyzw.parent = this; |
| 5959 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5960 | Value *a = Int4(cast).loadValue(); |
| 5961 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5962 | |
| 5963 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5964 | } |
| 5965 | |
| 5966 | Float4::Float4(RValue<Short4> cast) |
| 5967 | { |
| 5968 | xyzw.parent = this; |
| 5969 | |
| 5970 | Int4 c(cast); |
| 5971 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5972 | } |
| 5973 | |
| 5974 | Float4::Float4(RValue<UShort4> cast) |
| 5975 | { |
| 5976 | xyzw.parent = this; |
| 5977 | |
| 5978 | Int4 c(cast); |
| 5979 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5980 | } |
| 5981 | |
| 5982 | Float4::Float4(RValue<Int4> cast) |
| 5983 | { |
| 5984 | xyzw.parent = this; |
| 5985 | |
| 5986 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5987 | |
| 5988 | storeValue(xyzw); |
| 5989 | } |
| 5990 | |
| 5991 | Float4::Float4(RValue<UInt4> cast) |
| 5992 | { |
| 5993 | xyzw.parent = this; |
| 5994 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5995 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5996 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5997 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5998 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | Float4::Float4() |
| 6002 | { |
| 6003 | xyzw.parent = this; |
| 6004 | } |
| 6005 | |
| 6006 | Float4::Float4(float xyzw) |
| 6007 | { |
| 6008 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6009 | } |
| 6010 | |
| 6011 | Float4::Float4(float x, float yzw) |
| 6012 | { |
| 6013 | constant(x, yzw, yzw, yzw); |
| 6014 | } |
| 6015 | |
| 6016 | Float4::Float4(float x, float y, float zw) |
| 6017 | { |
| 6018 | constant(x, y, zw, zw); |
| 6019 | } |
| 6020 | |
| 6021 | Float4::Float4(float x, float y, float z, float w) |
| 6022 | { |
| 6023 | constant(x, y, z, w); |
| 6024 | } |
| 6025 | |
| 6026 | void Float4::constant(float x, float y, float z, float w) |
| 6027 | { |
| 6028 | xyzw.parent = this; |
| 6029 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6030 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6031 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6032 | } |
| 6033 | |
| 6034 | Float4::Float4(RValue<Float4> rhs) |
| 6035 | { |
| 6036 | xyzw.parent = this; |
| 6037 | |
| 6038 | storeValue(rhs.value); |
| 6039 | } |
| 6040 | |
| 6041 | Float4::Float4(const Float4 &rhs) |
| 6042 | { |
| 6043 | xyzw.parent = this; |
| 6044 | |
| 6045 | Value *value = rhs.loadValue(); |
| 6046 | storeValue(value); |
| 6047 | } |
| 6048 | |
| 6049 | Float4::Float4(const Reference<Float4> &rhs) |
| 6050 | { |
| 6051 | xyzw.parent = this; |
| 6052 | |
| 6053 | Value *value = rhs.loadValue(); |
| 6054 | storeValue(value); |
| 6055 | } |
| 6056 | |
| 6057 | Float4::Float4(RValue<Float> rhs) |
| 6058 | { |
| 6059 | xyzw.parent = this; |
| 6060 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6061 | Value *vector = loadValue(); |
| 6062 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 6063 | |
| 6064 | int swizzle[4] = {0, 0, 0, 0}; |
| 6065 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 6066 | |
| 6067 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | Float4::Float4(const Float &rhs) |
| 6071 | { |
| 6072 | xyzw.parent = this; |
| 6073 | |
| 6074 | *this = RValue<Float>(rhs.loadValue()); |
| 6075 | } |
| 6076 | |
| 6077 | Float4::Float4(const Reference<Float> &rhs) |
| 6078 | { |
| 6079 | xyzw.parent = this; |
| 6080 | |
| 6081 | *this = RValue<Float>(rhs.loadValue()); |
| 6082 | } |
| 6083 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6084 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6085 | { |
| 6086 | return *this = Float4(x, x, x, x); |
| 6087 | } |
| 6088 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6089 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6090 | { |
| 6091 | storeValue(rhs.value); |
| 6092 | |
| 6093 | return rhs; |
| 6094 | } |
| 6095 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6096 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6097 | { |
| 6098 | Value *value = rhs.loadValue(); |
| 6099 | storeValue(value); |
| 6100 | |
| 6101 | return RValue<Float4>(value); |
| 6102 | } |
| 6103 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6104 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6105 | { |
| 6106 | Value *value = rhs.loadValue(); |
| 6107 | storeValue(value); |
| 6108 | |
| 6109 | return RValue<Float4>(value); |
| 6110 | } |
| 6111 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6112 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6113 | { |
| 6114 | return *this = Float4(rhs); |
| 6115 | } |
| 6116 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6117 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6118 | { |
| 6119 | return *this = Float4(rhs); |
| 6120 | } |
| 6121 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6122 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6123 | { |
| 6124 | return *this = Float4(rhs); |
| 6125 | } |
| 6126 | |
| 6127 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6128 | { |
| 6129 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6130 | } |
| 6131 | |
| 6132 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6133 | { |
| 6134 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6135 | } |
| 6136 | |
| 6137 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6138 | { |
| 6139 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6140 | } |
| 6141 | |
| 6142 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6143 | { |
| 6144 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6145 | } |
| 6146 | |
| 6147 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6148 | { |
| 6149 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6150 | } |
| 6151 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6152 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6153 | { |
| 6154 | return lhs = lhs + rhs; |
| 6155 | } |
| 6156 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6157 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6158 | { |
| 6159 | return lhs = lhs - rhs; |
| 6160 | } |
| 6161 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6162 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6163 | { |
| 6164 | return lhs = lhs * rhs; |
| 6165 | } |
| 6166 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6167 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6168 | { |
| 6169 | return lhs = lhs / rhs; |
| 6170 | } |
| 6171 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6172 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6173 | { |
| 6174 | return lhs = lhs % rhs; |
| 6175 | } |
| 6176 | |
| 6177 | RValue<Float4> operator+(RValue<Float4> val) |
| 6178 | { |
| 6179 | return val; |
| 6180 | } |
| 6181 | |
| 6182 | RValue<Float4> operator-(RValue<Float4> val) |
| 6183 | { |
| 6184 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6185 | } |
| 6186 | |
| 6187 | RValue<Float4> Abs(RValue<Float4> x) |
| 6188 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6189 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6190 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6191 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6192 | |
| 6193 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6197 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6198 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6199 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value); |
| 6200 | ::basicBlock->appendInst(cmp); |
| 6201 | |
| 6202 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6203 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6204 | ::basicBlock->appendInst(select); |
| 6205 | |
| 6206 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6207 | } |
| 6208 | |
| 6209 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6210 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6211 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6212 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value); |
| 6213 | ::basicBlock->appendInst(cmp); |
| 6214 | |
| 6215 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6216 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6217 | ::basicBlock->appendInst(select); |
| 6218 | |
| 6219 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6220 | } |
| 6221 | |
| 6222 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6223 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6224 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6228 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6229 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6230 | } |
| 6231 | |
| 6232 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6233 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6234 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6235 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6236 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6237 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6238 | sqrt->addArg(x.value); |
| 6239 | ::basicBlock->appendInst(sqrt); |
| 6240 | |
| 6241 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6242 | } |
| 6243 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6244 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6245 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6246 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6247 | } |
| 6248 | |
| 6249 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6250 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6251 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6255 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6256 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6260 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6261 | int shuffle[4] = |
| 6262 | { |
| 6263 | ((imm >> 0) & 0x03) + 0, |
| 6264 | ((imm >> 2) & 0x03) + 0, |
| 6265 | ((imm >> 4) & 0x03) + 4, |
| 6266 | ((imm >> 6) & 0x03) + 4, |
| 6267 | }; |
| 6268 | |
| 6269 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6273 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6274 | int shuffle[4] = {0, 4, 1, 5}; |
| 6275 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6279 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6280 | int shuffle[4] = {2, 6, 3, 7}; |
| 6281 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6285 | { |
| 6286 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6287 | Value *result = createMask4(vector, rhs.value, select); |
| 6288 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6289 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6290 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | RValue<Int> SignMask(RValue<Float4> x) |
| 6294 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6295 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6296 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6297 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6298 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6299 | movmsk->addArg(x.value); |
| 6300 | ::basicBlock->appendInst(movmsk); |
| 6301 | |
| 6302 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6303 | } |
| 6304 | |
| 6305 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6306 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6307 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6308 | } |
| 6309 | |
| 6310 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6311 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6312 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6313 | } |
| 6314 | |
| 6315 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6316 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6317 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6321 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6322 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6323 | } |
| 6324 | |
| 6325 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6326 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6327 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6331 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6332 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | RValue<Float4> Round(RValue<Float4> x) |
| 6336 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6337 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6338 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6339 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6340 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6341 | round->addArg(x.value); |
| 6342 | round->addArg(::context->getConstantInt32(0)); |
| 6343 | ::basicBlock->appendInst(round); |
| 6344 | |
| 6345 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6349 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6350 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6351 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6352 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6353 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6354 | round->addArg(x.value); |
| 6355 | round->addArg(::context->getConstantInt32(3)); |
| 6356 | ::basicBlock->appendInst(round); |
| 6357 | |
| 6358 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | RValue<Float4> Frac(RValue<Float4> x) |
| 6362 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6363 | return x - Floor(x); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | RValue<Float4> Floor(RValue<Float4> x) |
| 6367 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6368 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6369 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6370 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6371 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6372 | round->addArg(x.value); |
| 6373 | round->addArg(::context->getConstantInt32(1)); |
| 6374 | ::basicBlock->appendInst(round); |
| 6375 | |
| 6376 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6380 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6381 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6382 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6383 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6384 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6385 | round->addArg(x.value); |
| 6386 | round->addArg(::context->getConstantInt32(2)); |
| 6387 | ::basicBlock->appendInst(round); |
| 6388 | |
| 6389 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | Type *Float4::getType() |
| 6393 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6394 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6398 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6399 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6403 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6404 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6408 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6409 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6410 | } |
| 6411 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6412 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6413 | { |
| 6414 | return lhs = lhs + offset; |
| 6415 | } |
| 6416 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6417 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6418 | { |
| 6419 | return lhs = lhs + offset; |
| 6420 | } |
| 6421 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6422 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6423 | { |
| 6424 | return lhs = lhs + offset; |
| 6425 | } |
| 6426 | |
| 6427 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6428 | { |
| 6429 | return lhs + -offset; |
| 6430 | } |
| 6431 | |
| 6432 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6433 | { |
| 6434 | return lhs + -offset; |
| 6435 | } |
| 6436 | |
| 6437 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6438 | { |
| 6439 | return lhs + -offset; |
| 6440 | } |
| 6441 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6442 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6443 | { |
| 6444 | return lhs = lhs - offset; |
| 6445 | } |
| 6446 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6447 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6448 | { |
| 6449 | return lhs = lhs - offset; |
| 6450 | } |
| 6451 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6452 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6453 | { |
| 6454 | return lhs = lhs - offset; |
| 6455 | } |
| 6456 | |
| 6457 | void Return() |
| 6458 | { |
| 6459 | Nucleus::createRetVoid(); |
| 6460 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6461 | Nucleus::createUnreachable(); |
| 6462 | } |
| 6463 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6464 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6465 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6466 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6467 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6468 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6469 | } |
| 6470 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6471 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
| 6472 | { |
| 6473 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6474 | Nucleus::setInsertBlock(bodyBB); |
| 6475 | |
| 6476 | return true; |
| 6477 | } |
| 6478 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6479 | RValue<Long> Ticks() |
| 6480 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6481 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6482 | } |
| 6483 | } |