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 | |
| 33 | #define WIN32_LEAN_AND_MEAN |
| 34 | #define NOMINMAX |
| 35 | #include <Windows.h> |
| 36 | |
| 37 | #include <mutex> |
| 38 | #include <limits> |
| 39 | #include <iostream> |
| 40 | #include <cassert> |
| 41 | |
| 42 | namespace |
| 43 | { |
| 44 | Ice::GlobalContext *context = nullptr; |
| 45 | Ice::Cfg *function = nullptr; |
| 46 | Ice::CfgNode *basicBlock = nullptr; |
| 47 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
| 48 | sw::Routine *routine = nullptr; |
| 49 | |
| 50 | std::mutex codegenMutex; |
| 51 | |
| 52 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 53 | Ice::Fdstream *out = nullptr; |
| 54 | } |
| 55 | |
| 56 | namespace sw |
| 57 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 58 | enum EmulatedType |
| 59 | { |
| 60 | EmulatedShift = 16, |
| 61 | EmulatedV2 = 2 << EmulatedShift, |
| 62 | EmulatedV4 = 4 << EmulatedShift, |
| 63 | EmulatedV8 = 8 << EmulatedShift, |
| 64 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 65 | |
| 66 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 67 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 68 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 69 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 70 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 71 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 72 | }; |
| 73 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 74 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 75 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 76 | class BasicBlock : public Ice::CfgNode {}; |
| 77 | |
| 78 | Ice::Type T(Type *t) |
| 79 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 80 | static_assert(Ice::IceType_NUM < EmulatedBits, "Ice::Type overlaps with our emulated types!"); |
| 81 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | Type *T(Ice::Type t) |
| 85 | { |
| 86 | return reinterpret_cast<Type*>(t); |
| 87 | } |
| 88 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 89 | Type *T(EmulatedType t) |
| 90 | { |
| 91 | return reinterpret_cast<Type*>(t); |
| 92 | } |
| 93 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 94 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 95 | { |
| 96 | return reinterpret_cast<Value*>(v); |
| 97 | } |
| 98 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 99 | BasicBlock *B(Ice::CfgNode *b) |
| 100 | { |
| 101 | return reinterpret_cast<BasicBlock*>(b); |
| 102 | } |
| 103 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 104 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 105 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 106 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 107 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 108 | |
| 109 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 110 | { |
| 111 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 112 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 113 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 114 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 115 | { |
| 116 | return §ionHeader(elfHeader)[index]; |
| 117 | } |
| 118 | |
| 119 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 120 | { |
| 121 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 122 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 123 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 124 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 125 | uint32_t index = relocation.getSymbol(); |
| 126 | int table = relocationTable.sh_link; |
| 127 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 128 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 129 | if(index != SHN_UNDEF) |
| 130 | { |
| 131 | if(table == SHN_UNDEF) return nullptr; |
| 132 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 133 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 134 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 135 | if(index >= symtab_entries) |
| 136 | { |
| 137 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 138 | return nullptr; |
| 139 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 140 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 141 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 142 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 143 | uint16_t section = symbol.st_shndx; |
| 144 | |
| 145 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 146 | { |
| 147 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 148 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | return nullptr; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | switch(relocation.getType()) |
| 157 | { |
| 158 | case R_386_NONE: |
| 159 | // No relocation |
| 160 | break; |
| 161 | case R_386_32: |
| 162 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 163 | break; |
| 164 | // case R_386_PC32: |
| 165 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 166 | // break; |
| 167 | default: |
| 168 | assert(false && "Unsupported relocation type"); |
| 169 | return nullptr; |
| 170 | } |
| 171 | |
| 172 | return symbolValue; |
| 173 | } |
| 174 | |
| 175 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 176 | { |
| 177 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 178 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 179 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 180 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 181 | uint32_t index = relocation.getSymbol(); |
| 182 | int table = relocationTable.sh_link; |
| 183 | void *symbolValue = nullptr; |
| 184 | |
| 185 | if(index != SHN_UNDEF) |
| 186 | { |
| 187 | if(table == SHN_UNDEF) return nullptr; |
| 188 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 189 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 190 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 191 | if(index >= symtab_entries) |
| 192 | { |
| 193 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 194 | return nullptr; |
| 195 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 196 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 197 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 198 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 199 | uint16_t section = symbol.st_shndx; |
| 200 | |
| 201 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 202 | { |
| 203 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 204 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | return nullptr; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | switch(relocation.getType()) |
| 213 | { |
| 214 | case R_X86_64_NONE: |
| 215 | // No relocation |
| 216 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 217 | case R_X86_64_64: |
| 218 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 219 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 220 | case R_X86_64_PC32: |
| 221 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 222 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 223 | case R_X86_64_32S: |
| 224 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 225 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 226 | default: |
| 227 | assert(false && "Unsupported relocation type"); |
| 228 | return nullptr; |
| 229 | } |
| 230 | |
| 231 | return symbolValue; |
| 232 | } |
| 233 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 234 | void *loadImage(uint8_t *const elfImage) |
| 235 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 236 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 237 | |
| 238 | if(!elfHeader->checkMagic()) |
| 239 | { |
| 240 | return nullptr; |
| 241 | } |
| 242 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 243 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 244 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 245 | assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386); |
| 246 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 247 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 248 | void *entry = nullptr; |
| 249 | |
| 250 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 251 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 252 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 253 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 254 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 255 | { |
| 256 | entry = elfImage + sectionHeader[i].sh_offset; |
| 257 | } |
| 258 | } |
| 259 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 260 | { |
| 261 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 262 | |
| 263 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 264 | { |
| 265 | const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 266 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 267 | } |
| 268 | } |
| 269 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 270 | { |
| 271 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 272 | |
| 273 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 274 | { |
| 275 | const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 276 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 277 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | return entry; |
| 282 | } |
| 283 | |
| 284 | template<typename T> |
| 285 | struct ExecutableAllocator |
| 286 | { |
| 287 | ExecutableAllocator() {}; |
| 288 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 289 | |
| 290 | using value_type = T; |
| 291 | using size_type = std::size_t; |
| 292 | |
| 293 | T *allocate(size_type n) |
| 294 | { |
| 295 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 296 | } |
| 297 | |
| 298 | void deallocate(T *p, size_type n) |
| 299 | { |
| 300 | VirtualFree(p, 0, MEM_RELEASE); |
| 301 | } |
| 302 | }; |
| 303 | |
| 304 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 305 | { |
| 306 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 307 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 308 | |
| 309 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 310 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 311 | { |
| 312 | position = 0; |
| 313 | buffer.reserve(0x1000); |
| 314 | } |
| 315 | |
| 316 | virtual ~ELFMemoryStreamer() |
| 317 | { |
| 318 | if(buffer.size() != 0) |
| 319 | { |
| 320 | DWORD exeProtection; |
| 321 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | void write8(uint8_t Value) override |
| 326 | { |
| 327 | if(position == (uint64_t)buffer.size()) |
| 328 | { |
| 329 | buffer.push_back(Value); |
| 330 | position++; |
| 331 | } |
| 332 | else if(position < (uint64_t)buffer.size()) |
| 333 | { |
| 334 | buffer[position] = Value; |
| 335 | position++; |
| 336 | } |
| 337 | else assert(false && "UNIMPLEMENTED"); |
| 338 | } |
| 339 | |
| 340 | void writeBytes(llvm::StringRef Bytes) override |
| 341 | { |
| 342 | std::size_t oldSize = buffer.size(); |
| 343 | buffer.resize(oldSize + Bytes.size()); |
| 344 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 345 | position += Bytes.size(); |
| 346 | } |
| 347 | |
| 348 | uint64_t tell() const override { return position; } |
| 349 | |
| 350 | void seek(uint64_t Off) override { position = Off; } |
| 351 | |
| 352 | const void *getEntry() override |
| 353 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 354 | if(!entry) |
| 355 | { |
| 356 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection); |
| 357 | 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] | 358 | |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 359 | entry = loadImage(&buffer[0]); |
| 360 | } |
| 361 | |
| 362 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 366 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 367 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 368 | std::size_t position; |
| 369 | DWORD oldProtection; |
| 370 | }; |
| 371 | |
| 372 | Nucleus::Nucleus() |
| 373 | { |
| 374 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 375 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 376 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 377 | Ice::ClFlags::getParsedClFlags(Flags); |
| 378 | |
| 379 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 380 | Flags.setOutFileType(Ice::FT_Elf); |
| 381 | Flags.setOptLevel(Ice::Opt_2); |
| 382 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 383 | Flags.setTargetInstructionSet(Ice::X86InstructionSet_SSE4_1); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 384 | Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 385 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 386 | static llvm::raw_os_ostream cout(std::cout); |
| 387 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 388 | |
| 389 | if(false) // Write out to a file |
| 390 | { |
| 391 | std::error_code errorCode; |
| 392 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 393 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 394 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 395 | } |
| 396 | else |
| 397 | { |
| 398 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 399 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 400 | ::routine = elfMemory; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | Nucleus::~Nucleus() |
| 405 | { |
| 406 | delete ::allocator; |
| 407 | delete ::function; |
| 408 | delete ::context; |
| 409 | |
| 410 | delete ::elfFile; |
| 411 | delete ::out; |
| 412 | |
| 413 | ::codegenMutex.unlock(); |
| 414 | } |
| 415 | |
| 416 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 417 | { |
| 418 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 419 | { |
| 420 | createRetVoid(); |
| 421 | } |
| 422 | |
| 423 | std::wstring wideName(name); |
| 424 | std::string asciiName(wideName.begin(), wideName.end()); |
| 425 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 426 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame^] | 427 | optimize(); |
| 428 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 429 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 430 | assert(!::function->hasError()); |
| 431 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 432 | auto *globals = ::function->getGlobalInits().release(); |
| 433 | |
| 434 | if(globals && !globals->empty()) |
| 435 | { |
| 436 | ::context->getGlobals()->merge(globals); |
| 437 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 438 | |
| 439 | ::context->emitFileHeader(); |
| 440 | ::function->emitIAS(); |
| 441 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 442 | auto objectWriter = ::context->getObjectWriter(); |
| 443 | assembler->alignFunction(); |
| 444 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 445 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 446 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 447 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 448 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 449 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 450 | |
| 451 | return ::routine; |
| 452 | } |
| 453 | |
| 454 | void Nucleus::optimize() |
| 455 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame^] | 456 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 460 | { |
| 461 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 462 | int typeSize = Ice::typeWidthInBytes(type); |
| 463 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 464 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 465 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 466 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 467 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 468 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 469 | |
| 470 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | BasicBlock *Nucleus::createBasicBlock() |
| 474 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 475 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | BasicBlock *Nucleus::getInsertBlock() |
| 479 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 480 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 484 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 485 | // 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] | 486 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 487 | } |
| 488 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 489 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 490 | { |
| 491 | uint32_t sequenceNumber = 0; |
| 492 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 493 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 494 | |
| 495 | for(Type *type : Params) |
| 496 | { |
| 497 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 498 | ::function->addArg(arg); |
| 499 | } |
| 500 | |
| 501 | Ice::CfgNode *node = ::function->makeNode(); |
| 502 | ::function->setEntryNode(node); |
| 503 | ::basicBlock = node; |
| 504 | } |
| 505 | |
| 506 | Value *Nucleus::getArgument(unsigned int index) |
| 507 | { |
| 508 | return V(::function->getArgs()[index]); |
| 509 | } |
| 510 | |
| 511 | void Nucleus::createRetVoid() |
| 512 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 513 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 514 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | void Nucleus::createRet(Value *v) |
| 518 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 519 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 520 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | void Nucleus::createBr(BasicBlock *dest) |
| 524 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 525 | auto br = Ice::InstBr::create(::function, dest); |
| 526 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 530 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 531 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 532 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 535 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 536 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 537 | 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] | 538 | |
| 539 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
| 540 | Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs); |
| 541 | ::basicBlock->appendInst(arithmetic); |
| 542 | |
| 543 | return V(result); |
| 544 | } |
| 545 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 546 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 547 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 548 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 552 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 553 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 557 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 558 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 562 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 563 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 567 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 568 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 572 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 573 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 577 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 578 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 582 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 583 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 587 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 588 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 592 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 593 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 597 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 598 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 602 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 603 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 607 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 608 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 612 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 613 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 617 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 618 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 622 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 623 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 627 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 628 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 632 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 633 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 636 | static Ice::Variable *createAssign(Ice::Operand *constant) |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 637 | { |
| 638 | Ice::Variable *value = ::function->makeVariable(constant->getType()); |
| 639 | auto assign = Ice::InstAssign::create(::function, value, constant); |
| 640 | ::basicBlock->appendInst(assign); |
| 641 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 642 | return value; |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 645 | Value *Nucleus::createNeg(Value *v) |
| 646 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 647 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | Value *Nucleus::createFNeg(Value *v) |
| 651 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 652 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 653 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 654 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 655 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 656 | |
| 657 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | Value *Nucleus::createNot(Value *v) |
| 661 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 662 | if(Ice::isScalarIntegerType(v->getType())) |
| 663 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 664 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 665 | } |
| 666 | else // Vector |
| 667 | { |
| 668 | int64_t c[4] = {-1, -1, -1, -1}; |
| 669 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 670 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 671 | } |
| 672 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 673 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 674 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 675 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 676 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 677 | |
| 678 | if(valueType & EmulatedBits) |
| 679 | { |
| 680 | switch(valueType) |
| 681 | { |
| 682 | case Type_v4i8: |
| 683 | case Type_v2i16: |
| 684 | { |
| 685 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 686 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 687 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 688 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 689 | load->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 690 | ::basicBlock->appendInst(load); |
| 691 | } |
| 692 | break; |
| 693 | case Type_v2i32: |
| 694 | case Type_v8i8: |
| 695 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 696 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 697 | { |
| 698 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 699 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 700 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 701 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 702 | load->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 703 | ::basicBlock->appendInst(load); |
| 704 | } |
| 705 | break; |
| 706 | default: assert(false && "UNIMPLEMENTED"); |
| 707 | } |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 712 | ::basicBlock->appendInst(load); |
| 713 | } |
| 714 | |
| 715 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 718 | 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] | 719 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 720 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 721 | |
| 722 | if(valueType & EmulatedBits) |
| 723 | { |
| 724 | switch(valueType) |
| 725 | { |
| 726 | case Type_v4i8: |
| 727 | case Type_v2i16: |
| 728 | { |
| 729 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 730 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 731 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 732 | store->addArg(value); |
| 733 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 734 | store->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 735 | ::basicBlock->appendInst(store); |
| 736 | } |
| 737 | break; |
| 738 | case Type_v2i32: |
| 739 | case Type_v8i8: |
| 740 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 741 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 742 | { |
| 743 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 744 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 745 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 746 | store->addArg(value); |
| 747 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 748 | store->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 749 | ::basicBlock->appendInst(store); |
| 750 | } |
| 751 | break; |
| 752 | default: assert(false && "UNIMPLEMENTED"); |
| 753 | } |
| 754 | } |
| 755 | else |
| 756 | { |
| 757 | assert(T(value->getType()) == type); |
| 758 | |
| 759 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 760 | ::basicBlock->appendInst(store); |
| 761 | } |
| 762 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 763 | return value; |
| 764 | } |
| 765 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 766 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 767 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 768 | assert(index->getType() == Ice::IceType_i32); |
| 769 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 770 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 771 | { |
| 772 | int32_t offset = constant->getValue() * (int)Ice::typeWidthInBytes(T(type)); |
| 773 | |
| 774 | if(offset == 0) |
| 775 | { |
| 776 | return ptr; |
| 777 | } |
| 778 | |
| 779 | return createAdd(ptr, createConstantInt(offset)); |
| 780 | } |
| 781 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 782 | if(!Ice::isByteSizedType(T(type))) |
| 783 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 784 | index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type)))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | if(sizeof(void*) == 8) |
| 788 | { |
| 789 | index = createSExt(index, T(Ice::IceType_i64)); |
| 790 | } |
| 791 | |
| 792 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 796 | { |
| 797 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 798 | } |
| 799 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 800 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 801 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 802 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 803 | { |
| 804 | return v; |
| 805 | } |
| 806 | |
| 807 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 808 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 809 | ::basicBlock->appendInst(cast); |
| 810 | |
| 811 | return V(result); |
| 812 | } |
| 813 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 814 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 815 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 816 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 820 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 821 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 825 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 826 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 830 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 831 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | Value *Nucleus::createUIToFP(Value *v, Type *destType) |
| 835 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 836 | return createCast(Ice::InstCast::Uitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 840 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 841 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 845 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 846 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 850 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 851 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 855 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 856 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 859 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 860 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 861 | assert(lhs->getType() == rhs->getType()); |
| 862 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 863 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 864 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 865 | ::basicBlock->appendInst(cmp); |
| 866 | |
| 867 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 870 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 871 | { |
| 872 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 873 | } |
| 874 | |
| 875 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 876 | { |
| 877 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 878 | } |
| 879 | |
| 880 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 881 | { |
| 882 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 883 | } |
| 884 | |
| 885 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 886 | { |
| 887 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 888 | } |
| 889 | |
| 890 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 891 | { |
| 892 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 893 | } |
| 894 | |
| 895 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 896 | { |
| 897 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 898 | } |
| 899 | |
| 900 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 901 | { |
| 902 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 903 | } |
| 904 | |
| 905 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 906 | { |
| 907 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 908 | } |
| 909 | |
| 910 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 911 | { |
| 912 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 913 | } |
| 914 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 915 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 916 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 917 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 918 | } |
| 919 | |
| 920 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 921 | { |
| 922 | assert(lhs->getType() == rhs->getType()); |
| 923 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 924 | |
| 925 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 926 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 927 | ::basicBlock->appendInst(cmp); |
| 928 | |
| 929 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 933 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 934 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 938 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 939 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 943 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 944 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 948 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 949 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 953 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 954 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 958 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 959 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 963 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 964 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 968 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 969 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 973 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 974 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 978 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 979 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 983 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 984 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 988 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 989 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 993 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 994 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 998 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 999 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1002 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1003 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1004 | auto result = ::function->makeVariable(T(type)); |
| 1005 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1006 | ::basicBlock->appendInst(extract); |
| 1007 | |
| 1008 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1012 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1013 | auto result = ::function->makeVariable(vector->getType()); |
| 1014 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1015 | ::basicBlock->appendInst(insert); |
| 1016 | |
| 1017 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1018 | } |
| 1019 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1020 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1021 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1022 | assert(V1->getType() == V2->getType()); |
| 1023 | |
| 1024 | int size = Ice::typeNumElements(V1->getType()); |
| 1025 | auto result = ::function->makeVariable(V1->getType()); |
| 1026 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1027 | |
| 1028 | for(int i = 0; i < size; i++) |
| 1029 | { |
| 1030 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1031 | } |
| 1032 | |
| 1033 | ::basicBlock->appendInst(shuffle); |
| 1034 | |
| 1035 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1039 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1040 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1041 | |
| 1042 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1043 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1044 | ::basicBlock->appendInst(select); |
| 1045 | |
| 1046 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1049 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1050 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1051 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1052 | ::basicBlock->appendInst(switchInst); |
| 1053 | |
| 1054 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1057 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1058 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1059 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | void Nucleus::createUnreachable() |
| 1063 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1064 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1065 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1068 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1069 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1070 | int swizzle[4] = |
| 1071 | { |
| 1072 | (select >> 0) & 0x03, |
| 1073 | (select >> 2) & 0x03, |
| 1074 | (select >> 4) & 0x03, |
| 1075 | (select >> 6) & 0x03, |
| 1076 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1077 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1078 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1081 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1082 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1083 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1084 | |
| 1085 | mask[(select >> 0) & 0x03] = -1; |
| 1086 | mask[(select >> 2) & 0x03] = -1; |
| 1087 | mask[(select >> 4) & 0x03] = -1; |
| 1088 | mask[(select >> 6) & 0x03] = -1; |
| 1089 | |
| 1090 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1091 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1092 | |
| 1093 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1094 | } |
| 1095 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1096 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1097 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1098 | if(sizeof(void*) == 8) |
| 1099 | { |
| 1100 | return T(Ice::IceType_i64); |
| 1101 | } |
| 1102 | else |
| 1103 | { |
| 1104 | return T(Ice::IceType_i32); |
| 1105 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1108 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1109 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1110 | if(Ice::isVectorType(T(Ty))) |
| 1111 | { |
| 1112 | int64_t c[4] = {0, 0, 0, 0}; |
| 1113 | return createConstantVector(c, Ty); |
| 1114 | } |
| 1115 | else |
| 1116 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1117 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1118 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1121 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1122 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1123 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1126 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1127 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1128 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1131 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1132 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1133 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1134 | } |
| 1135 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1136 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1137 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1138 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1141 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1142 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1143 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1144 | } |
| 1145 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1146 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1147 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1148 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1151 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1152 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1153 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1154 | } |
| 1155 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1156 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1157 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1158 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1159 | } |
| 1160 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1161 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1162 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1163 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1166 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1167 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1168 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1171 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1172 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1173 | const int vectorSize = 16; |
| 1174 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1175 | const int alignment = vectorSize; |
| 1176 | auto globalPool = ::function->getGlobalPool(); |
| 1177 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1178 | const int64_t *i = constants; |
| 1179 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1180 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1181 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1182 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1183 | { |
| 1184 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1185 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1186 | { |
| 1187 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1188 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1189 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1190 | } |
| 1191 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1192 | case Ice::IceType_v4f32: |
| 1193 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1194 | 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] | 1195 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1196 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1197 | } |
| 1198 | break; |
| 1199 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1200 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1201 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1202 | 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] | 1203 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1204 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1205 | } |
| 1206 | break; |
| 1207 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1208 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1209 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1210 | 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] | 1211 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1212 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1213 | } |
| 1214 | break; |
| 1215 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1216 | { |
| 1217 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1218 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1219 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1220 | } |
| 1221 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1222 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1223 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1224 | 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] | 1225 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1226 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1227 | } |
| 1228 | break; |
| 1229 | case Type_v4i16: |
| 1230 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1231 | 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] | 1232 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1233 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1234 | } |
| 1235 | break; |
| 1236 | case Type_v8i8: |
| 1237 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1238 | 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] | 1239 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1240 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1241 | } |
| 1242 | break; |
| 1243 | case Type_v4i8: |
| 1244 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1245 | 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] | 1246 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1247 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1248 | } |
| 1249 | break; |
| 1250 | default: |
| 1251 | assert(false && "Unknown constant vector type" && type); |
| 1252 | } |
| 1253 | |
| 1254 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1255 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1256 | variableDeclaration->setName(name); |
| 1257 | variableDeclaration->setAlignment(alignment); |
| 1258 | variableDeclaration->setIsConstant(true); |
| 1259 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1260 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1261 | ::function->addGlobal(variableDeclaration); |
| 1262 | |
| 1263 | constexpr int32_t offset = 0; |
| 1264 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1265 | |
| 1266 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1267 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1268 | ::basicBlock->appendInst(load); |
| 1269 | |
| 1270 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1274 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1275 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | Type *Void::getType() |
| 1279 | { |
| 1280 | return T(Ice::IceType_void); |
| 1281 | } |
| 1282 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1283 | Bool::Bool(Argument<Bool> argument) |
| 1284 | { |
| 1285 | storeValue(argument.value); |
| 1286 | } |
| 1287 | |
| 1288 | Bool::Bool() |
| 1289 | { |
| 1290 | } |
| 1291 | |
| 1292 | Bool::Bool(bool x) |
| 1293 | { |
| 1294 | storeValue(Nucleus::createConstantBool(x)); |
| 1295 | } |
| 1296 | |
| 1297 | Bool::Bool(RValue<Bool> rhs) |
| 1298 | { |
| 1299 | storeValue(rhs.value); |
| 1300 | } |
| 1301 | |
| 1302 | Bool::Bool(const Bool &rhs) |
| 1303 | { |
| 1304 | Value *value = rhs.loadValue(); |
| 1305 | storeValue(value); |
| 1306 | } |
| 1307 | |
| 1308 | Bool::Bool(const Reference<Bool> &rhs) |
| 1309 | { |
| 1310 | Value *value = rhs.loadValue(); |
| 1311 | storeValue(value); |
| 1312 | } |
| 1313 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1314 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1315 | { |
| 1316 | storeValue(rhs.value); |
| 1317 | |
| 1318 | return rhs; |
| 1319 | } |
| 1320 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1321 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1322 | { |
| 1323 | Value *value = rhs.loadValue(); |
| 1324 | storeValue(value); |
| 1325 | |
| 1326 | return RValue<Bool>(value); |
| 1327 | } |
| 1328 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1329 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1330 | { |
| 1331 | Value *value = rhs.loadValue(); |
| 1332 | storeValue(value); |
| 1333 | |
| 1334 | return RValue<Bool>(value); |
| 1335 | } |
| 1336 | |
| 1337 | RValue<Bool> operator!(RValue<Bool> val) |
| 1338 | { |
| 1339 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1340 | } |
| 1341 | |
| 1342 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1343 | { |
| 1344 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1345 | } |
| 1346 | |
| 1347 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1348 | { |
| 1349 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1350 | } |
| 1351 | |
| 1352 | Type *Bool::getType() |
| 1353 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1354 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | Byte::Byte(Argument<Byte> argument) |
| 1358 | { |
| 1359 | storeValue(argument.value); |
| 1360 | } |
| 1361 | |
| 1362 | Byte::Byte(RValue<Int> cast) |
| 1363 | { |
| 1364 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1365 | |
| 1366 | storeValue(integer); |
| 1367 | } |
| 1368 | |
| 1369 | Byte::Byte(RValue<UInt> cast) |
| 1370 | { |
| 1371 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1372 | |
| 1373 | storeValue(integer); |
| 1374 | } |
| 1375 | |
| 1376 | Byte::Byte(RValue<UShort> cast) |
| 1377 | { |
| 1378 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1379 | |
| 1380 | storeValue(integer); |
| 1381 | } |
| 1382 | |
| 1383 | Byte::Byte() |
| 1384 | { |
| 1385 | } |
| 1386 | |
| 1387 | Byte::Byte(int x) |
| 1388 | { |
| 1389 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1390 | } |
| 1391 | |
| 1392 | Byte::Byte(unsigned char x) |
| 1393 | { |
| 1394 | storeValue(Nucleus::createConstantByte(x)); |
| 1395 | } |
| 1396 | |
| 1397 | Byte::Byte(RValue<Byte> rhs) |
| 1398 | { |
| 1399 | storeValue(rhs.value); |
| 1400 | } |
| 1401 | |
| 1402 | Byte::Byte(const Byte &rhs) |
| 1403 | { |
| 1404 | Value *value = rhs.loadValue(); |
| 1405 | storeValue(value); |
| 1406 | } |
| 1407 | |
| 1408 | Byte::Byte(const Reference<Byte> &rhs) |
| 1409 | { |
| 1410 | Value *value = rhs.loadValue(); |
| 1411 | storeValue(value); |
| 1412 | } |
| 1413 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1414 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1415 | { |
| 1416 | storeValue(rhs.value); |
| 1417 | |
| 1418 | return rhs; |
| 1419 | } |
| 1420 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1421 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1422 | { |
| 1423 | Value *value = rhs.loadValue(); |
| 1424 | storeValue(value); |
| 1425 | |
| 1426 | return RValue<Byte>(value); |
| 1427 | } |
| 1428 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1429 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1430 | { |
| 1431 | Value *value = rhs.loadValue(); |
| 1432 | storeValue(value); |
| 1433 | |
| 1434 | return RValue<Byte>(value); |
| 1435 | } |
| 1436 | |
| 1437 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1438 | { |
| 1439 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1440 | } |
| 1441 | |
| 1442 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1443 | { |
| 1444 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1445 | } |
| 1446 | |
| 1447 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1448 | { |
| 1449 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1450 | } |
| 1451 | |
| 1452 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1453 | { |
| 1454 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1455 | } |
| 1456 | |
| 1457 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1458 | { |
| 1459 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1460 | } |
| 1461 | |
| 1462 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1463 | { |
| 1464 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1465 | } |
| 1466 | |
| 1467 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1468 | { |
| 1469 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1470 | } |
| 1471 | |
| 1472 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1473 | { |
| 1474 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1475 | } |
| 1476 | |
| 1477 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1478 | { |
| 1479 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1480 | } |
| 1481 | |
| 1482 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1483 | { |
| 1484 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1485 | } |
| 1486 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1487 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1488 | { |
| 1489 | return lhs = lhs + rhs; |
| 1490 | } |
| 1491 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1492 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1493 | { |
| 1494 | return lhs = lhs - rhs; |
| 1495 | } |
| 1496 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1497 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1498 | { |
| 1499 | return lhs = lhs * rhs; |
| 1500 | } |
| 1501 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1502 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1503 | { |
| 1504 | return lhs = lhs / rhs; |
| 1505 | } |
| 1506 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1507 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1508 | { |
| 1509 | return lhs = lhs % rhs; |
| 1510 | } |
| 1511 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1512 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1513 | { |
| 1514 | return lhs = lhs & rhs; |
| 1515 | } |
| 1516 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1517 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1518 | { |
| 1519 | return lhs = lhs | rhs; |
| 1520 | } |
| 1521 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1522 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1523 | { |
| 1524 | return lhs = lhs ^ rhs; |
| 1525 | } |
| 1526 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1527 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1528 | { |
| 1529 | return lhs = lhs << rhs; |
| 1530 | } |
| 1531 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1532 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1533 | { |
| 1534 | return lhs = lhs >> rhs; |
| 1535 | } |
| 1536 | |
| 1537 | RValue<Byte> operator+(RValue<Byte> val) |
| 1538 | { |
| 1539 | return val; |
| 1540 | } |
| 1541 | |
| 1542 | RValue<Byte> operator-(RValue<Byte> val) |
| 1543 | { |
| 1544 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1545 | } |
| 1546 | |
| 1547 | RValue<Byte> operator~(RValue<Byte> val) |
| 1548 | { |
| 1549 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1550 | } |
| 1551 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1552 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1553 | { |
| 1554 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1555 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1556 | return res; |
| 1557 | } |
| 1558 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1559 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1560 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1561 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1562 | return val; |
| 1563 | } |
| 1564 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1565 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1566 | { |
| 1567 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1568 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1569 | return res; |
| 1570 | } |
| 1571 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1572 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1573 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1574 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1575 | return val; |
| 1576 | } |
| 1577 | |
| 1578 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1579 | { |
| 1580 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1581 | } |
| 1582 | |
| 1583 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1584 | { |
| 1585 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1586 | } |
| 1587 | |
| 1588 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1589 | { |
| 1590 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1591 | } |
| 1592 | |
| 1593 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1594 | { |
| 1595 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1596 | } |
| 1597 | |
| 1598 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1599 | { |
| 1600 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1601 | } |
| 1602 | |
| 1603 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1604 | { |
| 1605 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1606 | } |
| 1607 | |
| 1608 | Type *Byte::getType() |
| 1609 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1610 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | SByte::SByte(Argument<SByte> argument) |
| 1614 | { |
| 1615 | storeValue(argument.value); |
| 1616 | } |
| 1617 | |
| 1618 | SByte::SByte(RValue<Int> cast) |
| 1619 | { |
| 1620 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1621 | |
| 1622 | storeValue(integer); |
| 1623 | } |
| 1624 | |
| 1625 | SByte::SByte(RValue<Short> cast) |
| 1626 | { |
| 1627 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1628 | |
| 1629 | storeValue(integer); |
| 1630 | } |
| 1631 | |
| 1632 | SByte::SByte() |
| 1633 | { |
| 1634 | } |
| 1635 | |
| 1636 | SByte::SByte(signed char x) |
| 1637 | { |
| 1638 | storeValue(Nucleus::createConstantByte(x)); |
| 1639 | } |
| 1640 | |
| 1641 | SByte::SByte(RValue<SByte> rhs) |
| 1642 | { |
| 1643 | storeValue(rhs.value); |
| 1644 | } |
| 1645 | |
| 1646 | SByte::SByte(const SByte &rhs) |
| 1647 | { |
| 1648 | Value *value = rhs.loadValue(); |
| 1649 | storeValue(value); |
| 1650 | } |
| 1651 | |
| 1652 | SByte::SByte(const Reference<SByte> &rhs) |
| 1653 | { |
| 1654 | Value *value = rhs.loadValue(); |
| 1655 | storeValue(value); |
| 1656 | } |
| 1657 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1658 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1659 | { |
| 1660 | storeValue(rhs.value); |
| 1661 | |
| 1662 | return rhs; |
| 1663 | } |
| 1664 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1665 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1666 | { |
| 1667 | Value *value = rhs.loadValue(); |
| 1668 | storeValue(value); |
| 1669 | |
| 1670 | return RValue<SByte>(value); |
| 1671 | } |
| 1672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1673 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1674 | { |
| 1675 | Value *value = rhs.loadValue(); |
| 1676 | storeValue(value); |
| 1677 | |
| 1678 | return RValue<SByte>(value); |
| 1679 | } |
| 1680 | |
| 1681 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1682 | { |
| 1683 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1684 | } |
| 1685 | |
| 1686 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1687 | { |
| 1688 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1689 | } |
| 1690 | |
| 1691 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1692 | { |
| 1693 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1694 | } |
| 1695 | |
| 1696 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1697 | { |
| 1698 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1699 | } |
| 1700 | |
| 1701 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1702 | { |
| 1703 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1704 | } |
| 1705 | |
| 1706 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1707 | { |
| 1708 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1709 | } |
| 1710 | |
| 1711 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1712 | { |
| 1713 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1714 | } |
| 1715 | |
| 1716 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1717 | { |
| 1718 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1719 | } |
| 1720 | |
| 1721 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1722 | { |
| 1723 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1724 | } |
| 1725 | |
| 1726 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1727 | { |
| 1728 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1729 | } |
| 1730 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1731 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1732 | { |
| 1733 | return lhs = lhs + rhs; |
| 1734 | } |
| 1735 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1736 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1737 | { |
| 1738 | return lhs = lhs - rhs; |
| 1739 | } |
| 1740 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1741 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1742 | { |
| 1743 | return lhs = lhs * rhs; |
| 1744 | } |
| 1745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1746 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1747 | { |
| 1748 | return lhs = lhs / rhs; |
| 1749 | } |
| 1750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1751 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1752 | { |
| 1753 | return lhs = lhs % rhs; |
| 1754 | } |
| 1755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1756 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1757 | { |
| 1758 | return lhs = lhs & rhs; |
| 1759 | } |
| 1760 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1761 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1762 | { |
| 1763 | return lhs = lhs | rhs; |
| 1764 | } |
| 1765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1766 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1767 | { |
| 1768 | return lhs = lhs ^ rhs; |
| 1769 | } |
| 1770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1771 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1772 | { |
| 1773 | return lhs = lhs << rhs; |
| 1774 | } |
| 1775 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1776 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1777 | { |
| 1778 | return lhs = lhs >> rhs; |
| 1779 | } |
| 1780 | |
| 1781 | RValue<SByte> operator+(RValue<SByte> val) |
| 1782 | { |
| 1783 | return val; |
| 1784 | } |
| 1785 | |
| 1786 | RValue<SByte> operator-(RValue<SByte> val) |
| 1787 | { |
| 1788 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1789 | } |
| 1790 | |
| 1791 | RValue<SByte> operator~(RValue<SByte> val) |
| 1792 | { |
| 1793 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1794 | } |
| 1795 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1796 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1797 | { |
| 1798 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1799 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1800 | return res; |
| 1801 | } |
| 1802 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1803 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1804 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1805 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1806 | return val; |
| 1807 | } |
| 1808 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1809 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1810 | { |
| 1811 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1812 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1813 | return res; |
| 1814 | } |
| 1815 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1816 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1817 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1818 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1819 | return val; |
| 1820 | } |
| 1821 | |
| 1822 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1823 | { |
| 1824 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1825 | } |
| 1826 | |
| 1827 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1828 | { |
| 1829 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1830 | } |
| 1831 | |
| 1832 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1833 | { |
| 1834 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1835 | } |
| 1836 | |
| 1837 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1838 | { |
| 1839 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1840 | } |
| 1841 | |
| 1842 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1843 | { |
| 1844 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1845 | } |
| 1846 | |
| 1847 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1848 | { |
| 1849 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1850 | } |
| 1851 | |
| 1852 | Type *SByte::getType() |
| 1853 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1854 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | Short::Short(Argument<Short> argument) |
| 1858 | { |
| 1859 | storeValue(argument.value); |
| 1860 | } |
| 1861 | |
| 1862 | Short::Short(RValue<Int> cast) |
| 1863 | { |
| 1864 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1865 | |
| 1866 | storeValue(integer); |
| 1867 | } |
| 1868 | |
| 1869 | Short::Short() |
| 1870 | { |
| 1871 | } |
| 1872 | |
| 1873 | Short::Short(short x) |
| 1874 | { |
| 1875 | storeValue(Nucleus::createConstantShort(x)); |
| 1876 | } |
| 1877 | |
| 1878 | Short::Short(RValue<Short> rhs) |
| 1879 | { |
| 1880 | storeValue(rhs.value); |
| 1881 | } |
| 1882 | |
| 1883 | Short::Short(const Short &rhs) |
| 1884 | { |
| 1885 | Value *value = rhs.loadValue(); |
| 1886 | storeValue(value); |
| 1887 | } |
| 1888 | |
| 1889 | Short::Short(const Reference<Short> &rhs) |
| 1890 | { |
| 1891 | Value *value = rhs.loadValue(); |
| 1892 | storeValue(value); |
| 1893 | } |
| 1894 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1895 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1896 | { |
| 1897 | storeValue(rhs.value); |
| 1898 | |
| 1899 | return rhs; |
| 1900 | } |
| 1901 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1902 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1903 | { |
| 1904 | Value *value = rhs.loadValue(); |
| 1905 | storeValue(value); |
| 1906 | |
| 1907 | return RValue<Short>(value); |
| 1908 | } |
| 1909 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1910 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1911 | { |
| 1912 | Value *value = rhs.loadValue(); |
| 1913 | storeValue(value); |
| 1914 | |
| 1915 | return RValue<Short>(value); |
| 1916 | } |
| 1917 | |
| 1918 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 1919 | { |
| 1920 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1921 | } |
| 1922 | |
| 1923 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 1924 | { |
| 1925 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1926 | } |
| 1927 | |
| 1928 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 1929 | { |
| 1930 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1931 | } |
| 1932 | |
| 1933 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 1934 | { |
| 1935 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1936 | } |
| 1937 | |
| 1938 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 1939 | { |
| 1940 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1941 | } |
| 1942 | |
| 1943 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 1944 | { |
| 1945 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1946 | } |
| 1947 | |
| 1948 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 1949 | { |
| 1950 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1951 | } |
| 1952 | |
| 1953 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 1954 | { |
| 1955 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1956 | } |
| 1957 | |
| 1958 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 1959 | { |
| 1960 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1961 | } |
| 1962 | |
| 1963 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 1964 | { |
| 1965 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1966 | } |
| 1967 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1968 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1969 | { |
| 1970 | return lhs = lhs + rhs; |
| 1971 | } |
| 1972 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1973 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1974 | { |
| 1975 | return lhs = lhs - rhs; |
| 1976 | } |
| 1977 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1978 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1979 | { |
| 1980 | return lhs = lhs * rhs; |
| 1981 | } |
| 1982 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1983 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1984 | { |
| 1985 | return lhs = lhs / rhs; |
| 1986 | } |
| 1987 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1988 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1989 | { |
| 1990 | return lhs = lhs % rhs; |
| 1991 | } |
| 1992 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1993 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1994 | { |
| 1995 | return lhs = lhs & rhs; |
| 1996 | } |
| 1997 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1998 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1999 | { |
| 2000 | return lhs = lhs | rhs; |
| 2001 | } |
| 2002 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2003 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2004 | { |
| 2005 | return lhs = lhs ^ rhs; |
| 2006 | } |
| 2007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2008 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2009 | { |
| 2010 | return lhs = lhs << rhs; |
| 2011 | } |
| 2012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2013 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2014 | { |
| 2015 | return lhs = lhs >> rhs; |
| 2016 | } |
| 2017 | |
| 2018 | RValue<Short> operator+(RValue<Short> val) |
| 2019 | { |
| 2020 | return val; |
| 2021 | } |
| 2022 | |
| 2023 | RValue<Short> operator-(RValue<Short> val) |
| 2024 | { |
| 2025 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2026 | } |
| 2027 | |
| 2028 | RValue<Short> operator~(RValue<Short> val) |
| 2029 | { |
| 2030 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2031 | } |
| 2032 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2033 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2034 | { |
| 2035 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2036 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2037 | return res; |
| 2038 | } |
| 2039 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2040 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2041 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2042 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2043 | return val; |
| 2044 | } |
| 2045 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2046 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2047 | { |
| 2048 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2049 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2050 | return res; |
| 2051 | } |
| 2052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2053 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2054 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2055 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2056 | return val; |
| 2057 | } |
| 2058 | |
| 2059 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2060 | { |
| 2061 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2062 | } |
| 2063 | |
| 2064 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2065 | { |
| 2066 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2067 | } |
| 2068 | |
| 2069 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2070 | { |
| 2071 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2072 | } |
| 2073 | |
| 2074 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2075 | { |
| 2076 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2077 | } |
| 2078 | |
| 2079 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2080 | { |
| 2081 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2082 | } |
| 2083 | |
| 2084 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2085 | { |
| 2086 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2087 | } |
| 2088 | |
| 2089 | Type *Short::getType() |
| 2090 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2091 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | UShort::UShort(Argument<UShort> argument) |
| 2095 | { |
| 2096 | storeValue(argument.value); |
| 2097 | } |
| 2098 | |
| 2099 | UShort::UShort(RValue<UInt> cast) |
| 2100 | { |
| 2101 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2102 | |
| 2103 | storeValue(integer); |
| 2104 | } |
| 2105 | |
| 2106 | UShort::UShort(RValue<Int> cast) |
| 2107 | { |
| 2108 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2109 | |
| 2110 | storeValue(integer); |
| 2111 | } |
| 2112 | |
| 2113 | UShort::UShort() |
| 2114 | { |
| 2115 | } |
| 2116 | |
| 2117 | UShort::UShort(unsigned short x) |
| 2118 | { |
| 2119 | storeValue(Nucleus::createConstantShort(x)); |
| 2120 | } |
| 2121 | |
| 2122 | UShort::UShort(RValue<UShort> rhs) |
| 2123 | { |
| 2124 | storeValue(rhs.value); |
| 2125 | } |
| 2126 | |
| 2127 | UShort::UShort(const UShort &rhs) |
| 2128 | { |
| 2129 | Value *value = rhs.loadValue(); |
| 2130 | storeValue(value); |
| 2131 | } |
| 2132 | |
| 2133 | UShort::UShort(const Reference<UShort> &rhs) |
| 2134 | { |
| 2135 | Value *value = rhs.loadValue(); |
| 2136 | storeValue(value); |
| 2137 | } |
| 2138 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2139 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2140 | { |
| 2141 | storeValue(rhs.value); |
| 2142 | |
| 2143 | return rhs; |
| 2144 | } |
| 2145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2146 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2147 | { |
| 2148 | Value *value = rhs.loadValue(); |
| 2149 | storeValue(value); |
| 2150 | |
| 2151 | return RValue<UShort>(value); |
| 2152 | } |
| 2153 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2154 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2155 | { |
| 2156 | Value *value = rhs.loadValue(); |
| 2157 | storeValue(value); |
| 2158 | |
| 2159 | return RValue<UShort>(value); |
| 2160 | } |
| 2161 | |
| 2162 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2163 | { |
| 2164 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2165 | } |
| 2166 | |
| 2167 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2168 | { |
| 2169 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2170 | } |
| 2171 | |
| 2172 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2173 | { |
| 2174 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2175 | } |
| 2176 | |
| 2177 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2178 | { |
| 2179 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2180 | } |
| 2181 | |
| 2182 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2183 | { |
| 2184 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2185 | } |
| 2186 | |
| 2187 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2188 | { |
| 2189 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2190 | } |
| 2191 | |
| 2192 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2193 | { |
| 2194 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2195 | } |
| 2196 | |
| 2197 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2198 | { |
| 2199 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2200 | } |
| 2201 | |
| 2202 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2203 | { |
| 2204 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2205 | } |
| 2206 | |
| 2207 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2208 | { |
| 2209 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2210 | } |
| 2211 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2212 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2213 | { |
| 2214 | return lhs = lhs + rhs; |
| 2215 | } |
| 2216 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2217 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2218 | { |
| 2219 | return lhs = lhs - rhs; |
| 2220 | } |
| 2221 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2222 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2223 | { |
| 2224 | return lhs = lhs * rhs; |
| 2225 | } |
| 2226 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2227 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2228 | { |
| 2229 | return lhs = lhs / rhs; |
| 2230 | } |
| 2231 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2232 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2233 | { |
| 2234 | return lhs = lhs % rhs; |
| 2235 | } |
| 2236 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2237 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2238 | { |
| 2239 | return lhs = lhs & rhs; |
| 2240 | } |
| 2241 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2242 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2243 | { |
| 2244 | return lhs = lhs | rhs; |
| 2245 | } |
| 2246 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2247 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2248 | { |
| 2249 | return lhs = lhs ^ rhs; |
| 2250 | } |
| 2251 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2252 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2253 | { |
| 2254 | return lhs = lhs << rhs; |
| 2255 | } |
| 2256 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2257 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2258 | { |
| 2259 | return lhs = lhs >> rhs; |
| 2260 | } |
| 2261 | |
| 2262 | RValue<UShort> operator+(RValue<UShort> val) |
| 2263 | { |
| 2264 | return val; |
| 2265 | } |
| 2266 | |
| 2267 | RValue<UShort> operator-(RValue<UShort> val) |
| 2268 | { |
| 2269 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2270 | } |
| 2271 | |
| 2272 | RValue<UShort> operator~(RValue<UShort> val) |
| 2273 | { |
| 2274 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2275 | } |
| 2276 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2277 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2278 | { |
| 2279 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2280 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2281 | return res; |
| 2282 | } |
| 2283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2284 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2285 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2286 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2287 | return val; |
| 2288 | } |
| 2289 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2290 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2291 | { |
| 2292 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2293 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2294 | return res; |
| 2295 | } |
| 2296 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2297 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2298 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2299 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2300 | return val; |
| 2301 | } |
| 2302 | |
| 2303 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2304 | { |
| 2305 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2306 | } |
| 2307 | |
| 2308 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2309 | { |
| 2310 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2311 | } |
| 2312 | |
| 2313 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2314 | { |
| 2315 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2316 | } |
| 2317 | |
| 2318 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2319 | { |
| 2320 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2321 | } |
| 2322 | |
| 2323 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2324 | { |
| 2325 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2326 | } |
| 2327 | |
| 2328 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2329 | { |
| 2330 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2331 | } |
| 2332 | |
| 2333 | Type *UShort::getType() |
| 2334 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2335 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2336 | } |
| 2337 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2338 | Byte4::Byte4(RValue<Byte8> cast) |
| 2339 | { |
| 2340 | // xyzw.parent = this; |
| 2341 | |
| 2342 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2343 | } |
| 2344 | |
| 2345 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2346 | { |
| 2347 | // xyzw.parent = this; |
| 2348 | |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2349 | Value *value = rhs.loadValue(); |
| 2350 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2351 | } |
| 2352 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2353 | Type *Byte4::getType() |
| 2354 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2355 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | Type *SByte4::getType() |
| 2359 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2360 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | Byte8::Byte8() |
| 2364 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | 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) |
| 2368 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2369 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2370 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2374 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2375 | storeValue(rhs.value); |
| 2376 | } |
| 2377 | |
| 2378 | Byte8::Byte8(const Byte8 &rhs) |
| 2379 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2380 | Value *value = rhs.loadValue(); |
| 2381 | storeValue(value); |
| 2382 | } |
| 2383 | |
| 2384 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2385 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2386 | Value *value = rhs.loadValue(); |
| 2387 | storeValue(value); |
| 2388 | } |
| 2389 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2390 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2391 | { |
| 2392 | storeValue(rhs.value); |
| 2393 | |
| 2394 | return rhs; |
| 2395 | } |
| 2396 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2397 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2398 | { |
| 2399 | Value *value = rhs.loadValue(); |
| 2400 | storeValue(value); |
| 2401 | |
| 2402 | return RValue<Byte8>(value); |
| 2403 | } |
| 2404 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2405 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2406 | { |
| 2407 | Value *value = rhs.loadValue(); |
| 2408 | storeValue(value); |
| 2409 | |
| 2410 | return RValue<Byte8>(value); |
| 2411 | } |
| 2412 | |
| 2413 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2414 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2415 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2419 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2420 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2424 | // { |
| 2425 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2426 | // } |
| 2427 | |
| 2428 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2429 | // { |
| 2430 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2431 | // } |
| 2432 | |
| 2433 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2434 | // { |
| 2435 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2436 | // } |
| 2437 | |
| 2438 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2439 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2440 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2444 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2445 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2449 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2450 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2454 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2455 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2456 | // } |
| 2457 | |
| 2458 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2459 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2460 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2461 | // } |
| 2462 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2463 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2464 | { |
| 2465 | return lhs = lhs + rhs; |
| 2466 | } |
| 2467 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2468 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2469 | { |
| 2470 | return lhs = lhs - rhs; |
| 2471 | } |
| 2472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2473 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2474 | // { |
| 2475 | // return lhs = lhs * rhs; |
| 2476 | // } |
| 2477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2478 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2479 | // { |
| 2480 | // return lhs = lhs / rhs; |
| 2481 | // } |
| 2482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2483 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2484 | // { |
| 2485 | // return lhs = lhs % rhs; |
| 2486 | // } |
| 2487 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2488 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2489 | { |
| 2490 | return lhs = lhs & rhs; |
| 2491 | } |
| 2492 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2493 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2494 | { |
| 2495 | return lhs = lhs | rhs; |
| 2496 | } |
| 2497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2498 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2499 | { |
| 2500 | return lhs = lhs ^ rhs; |
| 2501 | } |
| 2502 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2503 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2504 | // { |
| 2505 | // return lhs = lhs << rhs; |
| 2506 | // } |
| 2507 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2508 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2509 | // { |
| 2510 | // return lhs = lhs >> rhs; |
| 2511 | // } |
| 2512 | |
| 2513 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2514 | // { |
| 2515 | // return val; |
| 2516 | // } |
| 2517 | |
| 2518 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2519 | // { |
| 2520 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2521 | // } |
| 2522 | |
| 2523 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2524 | { |
| 2525 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2526 | } |
| 2527 | |
| 2528 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2529 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2530 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2531 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2532 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2533 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2534 | paddusb->addArg(x.value); |
| 2535 | paddusb->addArg(y.value); |
| 2536 | ::basicBlock->appendInst(paddusb); |
| 2537 | |
| 2538 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2542 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2543 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2544 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2545 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2546 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2547 | psubusw->addArg(x.value); |
| 2548 | psubusw->addArg(y.value); |
| 2549 | ::basicBlock->appendInst(psubusw); |
| 2550 | |
| 2551 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2555 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2556 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2557 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2561 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2562 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2563 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2567 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2568 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2569 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2570 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2574 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2575 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2576 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2577 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2578 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2579 | movmsk->addArg(x.value); |
| 2580 | ::basicBlock->appendInst(movmsk); |
| 2581 | |
| 2582 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2586 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2587 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2588 | // } |
| 2589 | |
| 2590 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2591 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2592 | return RValue<Byte8>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | Type *Byte8::getType() |
| 2596 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2597 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | SByte8::SByte8() |
| 2601 | { |
| 2602 | // xyzw.parent = this; |
| 2603 | } |
| 2604 | |
| 2605 | 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) |
| 2606 | { |
| 2607 | // xyzw.parent = this; |
| 2608 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2609 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2610 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2611 | |
| 2612 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2613 | } |
| 2614 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2615 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2616 | { |
| 2617 | // xyzw.parent = this; |
| 2618 | |
| 2619 | storeValue(rhs.value); |
| 2620 | } |
| 2621 | |
| 2622 | SByte8::SByte8(const SByte8 &rhs) |
| 2623 | { |
| 2624 | // xyzw.parent = this; |
| 2625 | |
| 2626 | Value *value = rhs.loadValue(); |
| 2627 | storeValue(value); |
| 2628 | } |
| 2629 | |
| 2630 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2631 | { |
| 2632 | // xyzw.parent = this; |
| 2633 | |
| 2634 | Value *value = rhs.loadValue(); |
| 2635 | storeValue(value); |
| 2636 | } |
| 2637 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2638 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2639 | { |
| 2640 | storeValue(rhs.value); |
| 2641 | |
| 2642 | return rhs; |
| 2643 | } |
| 2644 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2645 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2646 | { |
| 2647 | Value *value = rhs.loadValue(); |
| 2648 | storeValue(value); |
| 2649 | |
| 2650 | return RValue<SByte8>(value); |
| 2651 | } |
| 2652 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2653 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2654 | { |
| 2655 | Value *value = rhs.loadValue(); |
| 2656 | storeValue(value); |
| 2657 | |
| 2658 | return RValue<SByte8>(value); |
| 2659 | } |
| 2660 | |
| 2661 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2662 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2663 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2667 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2668 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2672 | // { |
| 2673 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2674 | // } |
| 2675 | |
| 2676 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2677 | // { |
| 2678 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2679 | // } |
| 2680 | |
| 2681 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2682 | // { |
| 2683 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2684 | // } |
| 2685 | |
| 2686 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2687 | { |
| 2688 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2689 | } |
| 2690 | |
| 2691 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2692 | { |
| 2693 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2694 | } |
| 2695 | |
| 2696 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2697 | { |
| 2698 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2699 | } |
| 2700 | |
| 2701 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2702 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2703 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2704 | // } |
| 2705 | |
| 2706 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2707 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2708 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2709 | // } |
| 2710 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2711 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2712 | { |
| 2713 | return lhs = lhs + rhs; |
| 2714 | } |
| 2715 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2716 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2717 | { |
| 2718 | return lhs = lhs - rhs; |
| 2719 | } |
| 2720 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2721 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2722 | // { |
| 2723 | // return lhs = lhs * rhs; |
| 2724 | // } |
| 2725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2726 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2727 | // { |
| 2728 | // return lhs = lhs / rhs; |
| 2729 | // } |
| 2730 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2731 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2732 | // { |
| 2733 | // return lhs = lhs % rhs; |
| 2734 | // } |
| 2735 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2736 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2737 | { |
| 2738 | return lhs = lhs & rhs; |
| 2739 | } |
| 2740 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2741 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2742 | { |
| 2743 | return lhs = lhs | rhs; |
| 2744 | } |
| 2745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2746 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2747 | { |
| 2748 | return lhs = lhs ^ rhs; |
| 2749 | } |
| 2750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2751 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2752 | // { |
| 2753 | // return lhs = lhs << rhs; |
| 2754 | // } |
| 2755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2756 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2757 | // { |
| 2758 | // return lhs = lhs >> rhs; |
| 2759 | // } |
| 2760 | |
| 2761 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2762 | // { |
| 2763 | // return val; |
| 2764 | // } |
| 2765 | |
| 2766 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2767 | // { |
| 2768 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2769 | // } |
| 2770 | |
| 2771 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2772 | { |
| 2773 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2774 | } |
| 2775 | |
| 2776 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2777 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2778 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2779 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2780 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2781 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2782 | paddsb->addArg(x.value); |
| 2783 | paddsb->addArg(y.value); |
| 2784 | ::basicBlock->appendInst(paddsb); |
| 2785 | |
| 2786 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2790 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2791 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2792 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2793 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2794 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2795 | psubsb->addArg(x.value); |
| 2796 | psubsb->addArg(y.value); |
| 2797 | ::basicBlock->appendInst(psubsb); |
| 2798 | |
| 2799 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2803 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2804 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2805 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2809 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2810 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2811 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2812 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2816 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2817 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2818 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2819 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2820 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2821 | movmsk->addArg(x.value); |
| 2822 | ::basicBlock->appendInst(movmsk); |
| 2823 | |
| 2824 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2828 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2829 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2833 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2834 | return RValue<Byte8>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | Type *SByte8::getType() |
| 2838 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2839 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2843 | { |
| 2844 | // xyzw.parent = this; |
| 2845 | |
| 2846 | storeValue(rhs.value); |
| 2847 | } |
| 2848 | |
| 2849 | Byte16::Byte16(const Byte16 &rhs) |
| 2850 | { |
| 2851 | // xyzw.parent = this; |
| 2852 | |
| 2853 | Value *value = rhs.loadValue(); |
| 2854 | storeValue(value); |
| 2855 | } |
| 2856 | |
| 2857 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2858 | { |
| 2859 | // xyzw.parent = this; |
| 2860 | |
| 2861 | Value *value = rhs.loadValue(); |
| 2862 | storeValue(value); |
| 2863 | } |
| 2864 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2865 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2866 | { |
| 2867 | storeValue(rhs.value); |
| 2868 | |
| 2869 | return rhs; |
| 2870 | } |
| 2871 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2872 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2873 | { |
| 2874 | Value *value = rhs.loadValue(); |
| 2875 | storeValue(value); |
| 2876 | |
| 2877 | return RValue<Byte16>(value); |
| 2878 | } |
| 2879 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2880 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2881 | { |
| 2882 | Value *value = rhs.loadValue(); |
| 2883 | storeValue(value); |
| 2884 | |
| 2885 | return RValue<Byte16>(value); |
| 2886 | } |
| 2887 | |
| 2888 | Type *Byte16::getType() |
| 2889 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2890 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | Type *SByte16::getType() |
| 2894 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2895 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2896 | } |
| 2897 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2898 | Short2::Short2(RValue<Short4> cast) |
| 2899 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2900 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | Type *Short2::getType() |
| 2904 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2905 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | UShort2::UShort2(RValue<UShort4> cast) |
| 2909 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2910 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | Type *UShort2::getType() |
| 2914 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2915 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2916 | } |
| 2917 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2918 | Short4::Short4(RValue<Int> cast) |
| 2919 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2920 | Value *vector = loadValue(); |
| 2921 | Value *insert = Nucleus::createInsertElement(vector, cast.value, 0); |
| 2922 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2923 | |
| 2924 | storeValue(swizzle); |
| 2925 | } |
| 2926 | |
| 2927 | Short4::Short4(RValue<Int4> cast) |
| 2928 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2929 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
| 2930 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2931 | Value *packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
| 2932 | |
| 2933 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2934 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2935 | |
| 2936 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | // Short4::Short4(RValue<Float> cast) |
| 2940 | // { |
| 2941 | // } |
| 2942 | |
| 2943 | Short4::Short4(RValue<Float4> cast) |
| 2944 | { |
| 2945 | assert(false && "UNIMPLEMENTED"); |
| 2946 | } |
| 2947 | |
| 2948 | Short4::Short4() |
| 2949 | { |
| 2950 | // xyzw.parent = this; |
| 2951 | } |
| 2952 | |
| 2953 | Short4::Short4(short xyzw) |
| 2954 | { |
| 2955 | // xyzw.parent = this; |
| 2956 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2957 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2958 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | Short4::Short4(short x, short y, short z, short w) |
| 2962 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2963 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2964 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2965 | int64_t constantVector[4] = {x, y, z, w}; |
| 2966 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | Short4::Short4(RValue<Short4> rhs) |
| 2970 | { |
| 2971 | // xyzw.parent = this; |
| 2972 | |
| 2973 | storeValue(rhs.value); |
| 2974 | } |
| 2975 | |
| 2976 | Short4::Short4(const Short4 &rhs) |
| 2977 | { |
| 2978 | // xyzw.parent = this; |
| 2979 | |
| 2980 | Value *value = rhs.loadValue(); |
| 2981 | storeValue(value); |
| 2982 | } |
| 2983 | |
| 2984 | Short4::Short4(const Reference<Short4> &rhs) |
| 2985 | { |
| 2986 | // xyzw.parent = this; |
| 2987 | |
| 2988 | Value *value = rhs.loadValue(); |
| 2989 | storeValue(value); |
| 2990 | } |
| 2991 | |
| 2992 | Short4::Short4(RValue<UShort4> rhs) |
| 2993 | { |
| 2994 | // xyzw.parent = this; |
| 2995 | |
| 2996 | storeValue(rhs.value); |
| 2997 | } |
| 2998 | |
| 2999 | Short4::Short4(const UShort4 &rhs) |
| 3000 | { |
| 3001 | // xyzw.parent = this; |
| 3002 | |
| 3003 | storeValue(rhs.loadValue()); |
| 3004 | } |
| 3005 | |
| 3006 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3007 | { |
| 3008 | // xyzw.parent = this; |
| 3009 | |
| 3010 | storeValue(rhs.loadValue()); |
| 3011 | } |
| 3012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3013 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3014 | { |
| 3015 | storeValue(rhs.value); |
| 3016 | |
| 3017 | return rhs; |
| 3018 | } |
| 3019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3020 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3021 | { |
| 3022 | Value *value = rhs.loadValue(); |
| 3023 | storeValue(value); |
| 3024 | |
| 3025 | return RValue<Short4>(value); |
| 3026 | } |
| 3027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3028 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3029 | { |
| 3030 | Value *value = rhs.loadValue(); |
| 3031 | storeValue(value); |
| 3032 | |
| 3033 | return RValue<Short4>(value); |
| 3034 | } |
| 3035 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3036 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3037 | { |
| 3038 | storeValue(rhs.value); |
| 3039 | |
| 3040 | return RValue<Short4>(rhs); |
| 3041 | } |
| 3042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3043 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3044 | { |
| 3045 | Value *value = rhs.loadValue(); |
| 3046 | storeValue(value); |
| 3047 | |
| 3048 | return RValue<Short4>(value); |
| 3049 | } |
| 3050 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3051 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3052 | { |
| 3053 | Value *value = rhs.loadValue(); |
| 3054 | storeValue(value); |
| 3055 | |
| 3056 | return RValue<Short4>(value); |
| 3057 | } |
| 3058 | |
| 3059 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3060 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3061 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3065 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3066 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3070 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3071 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3075 | // { |
| 3076 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3077 | // } |
| 3078 | |
| 3079 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3080 | // { |
| 3081 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3082 | // } |
| 3083 | |
| 3084 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3085 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3086 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3090 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3091 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3095 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3096 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3100 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3101 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3105 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3106 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3107 | } |
| 3108 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3109 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3110 | { |
| 3111 | return lhs = lhs + rhs; |
| 3112 | } |
| 3113 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3114 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3115 | { |
| 3116 | return lhs = lhs - rhs; |
| 3117 | } |
| 3118 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3119 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3120 | { |
| 3121 | return lhs = lhs * rhs; |
| 3122 | } |
| 3123 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3124 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3125 | // { |
| 3126 | // return lhs = lhs / rhs; |
| 3127 | // } |
| 3128 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3129 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3130 | // { |
| 3131 | // return lhs = lhs % rhs; |
| 3132 | // } |
| 3133 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3134 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3135 | { |
| 3136 | return lhs = lhs & rhs; |
| 3137 | } |
| 3138 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3139 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3140 | { |
| 3141 | return lhs = lhs | rhs; |
| 3142 | } |
| 3143 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3144 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3145 | { |
| 3146 | return lhs = lhs ^ rhs; |
| 3147 | } |
| 3148 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3149 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3150 | { |
| 3151 | return lhs = lhs << rhs; |
| 3152 | } |
| 3153 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3154 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3155 | { |
| 3156 | return lhs = lhs >> rhs; |
| 3157 | } |
| 3158 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3159 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3160 | // { |
| 3161 | // return val; |
| 3162 | // } |
| 3163 | |
| 3164 | RValue<Short4> operator-(RValue<Short4> val) |
| 3165 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3166 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | RValue<Short4> operator~(RValue<Short4> val) |
| 3170 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3171 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3175 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3176 | RValue<Int4> int4 = RoundInt(cast); |
| 3177 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3181 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3182 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3183 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3184 | ::basicBlock->appendInst(cmp); |
| 3185 | |
| 3186 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3187 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3188 | ::basicBlock->appendInst(select); |
| 3189 | |
| 3190 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3194 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3195 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3196 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3197 | ::basicBlock->appendInst(cmp); |
| 3198 | |
| 3199 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3200 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3201 | ::basicBlock->appendInst(select); |
| 3202 | |
| 3203 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3207 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3208 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3209 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3210 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3211 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3212 | paddsw->addArg(x.value); |
| 3213 | paddsw->addArg(y.value); |
| 3214 | ::basicBlock->appendInst(paddsw); |
| 3215 | |
| 3216 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3220 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3221 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3222 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3223 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3224 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3225 | psubsw->addArg(x.value); |
| 3226 | psubsw->addArg(y.value); |
| 3227 | ::basicBlock->appendInst(psubsw); |
| 3228 | |
| 3229 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3233 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3234 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3235 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3236 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3237 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3238 | pmulhw->addArg(x.value); |
| 3239 | pmulhw->addArg(y.value); |
| 3240 | ::basicBlock->appendInst(pmulhw); |
| 3241 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3242 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3246 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3247 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3248 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3249 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3250 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3251 | pmaddwd->addArg(x.value); |
| 3252 | pmaddwd->addArg(y.value); |
| 3253 | ::basicBlock->appendInst(pmaddwd); |
| 3254 | |
| 3255 | return RValue<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3259 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3260 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3261 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3262 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3263 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3264 | pack->addArg(x.value); |
| 3265 | pack->addArg(y.value); |
| 3266 | ::basicBlock->appendInst(pack); |
| 3267 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3268 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3272 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3273 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3274 | return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3278 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3279 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3280 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3281 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3285 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3286 | // Real type is v8i16 |
| 3287 | int shuffle[8] = |
| 3288 | { |
| 3289 | (select >> 0) & 0x03, |
| 3290 | (select >> 2) & 0x03, |
| 3291 | (select >> 4) & 0x03, |
| 3292 | (select >> 6) & 0x03, |
| 3293 | (select >> 0) & 0x03, |
| 3294 | (select >> 2) & 0x03, |
| 3295 | (select >> 4) & 0x03, |
| 3296 | (select >> 6) & 0x03, |
| 3297 | }; |
| 3298 | |
| 3299 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3303 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3304 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3308 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3309 | return RValue<Short>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3313 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3314 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3318 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3319 | return RValue<Short4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | Type *Short4::getType() |
| 3323 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3324 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | UShort4::UShort4(RValue<Int4> cast) |
| 3328 | { |
| 3329 | *this = Short4(cast); |
| 3330 | } |
| 3331 | |
| 3332 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3333 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3334 | if(saturate) |
| 3335 | { |
| 3336 | if(true) // SSE 4.1 |
| 3337 | { |
| 3338 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3339 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3340 | } |
| 3341 | else |
| 3342 | { |
| 3343 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3344 | } |
| 3345 | } |
| 3346 | else |
| 3347 | { |
| 3348 | *this = Short4(Int4(cast)); |
| 3349 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | UShort4::UShort4() |
| 3353 | { |
| 3354 | // xyzw.parent = this; |
| 3355 | } |
| 3356 | |
| 3357 | UShort4::UShort4(unsigned short xyzw) |
| 3358 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3359 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3360 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3361 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3362 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3366 | { |
| 3367 | // xyzw.parent = this; |
| 3368 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3369 | int64_t constantVector[4] = {x, y, z, w}; |
| 3370 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3374 | { |
| 3375 | // xyzw.parent = this; |
| 3376 | |
| 3377 | storeValue(rhs.value); |
| 3378 | } |
| 3379 | |
| 3380 | UShort4::UShort4(const UShort4 &rhs) |
| 3381 | { |
| 3382 | // xyzw.parent = this; |
| 3383 | |
| 3384 | Value *value = rhs.loadValue(); |
| 3385 | storeValue(value); |
| 3386 | } |
| 3387 | |
| 3388 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3389 | { |
| 3390 | // xyzw.parent = this; |
| 3391 | |
| 3392 | Value *value = rhs.loadValue(); |
| 3393 | storeValue(value); |
| 3394 | } |
| 3395 | |
| 3396 | UShort4::UShort4(RValue<Short4> rhs) |
| 3397 | { |
| 3398 | // xyzw.parent = this; |
| 3399 | |
| 3400 | storeValue(rhs.value); |
| 3401 | } |
| 3402 | |
| 3403 | UShort4::UShort4(const Short4 &rhs) |
| 3404 | { |
| 3405 | // xyzw.parent = this; |
| 3406 | |
| 3407 | Value *value = rhs.loadValue(); |
| 3408 | storeValue(value); |
| 3409 | } |
| 3410 | |
| 3411 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3412 | { |
| 3413 | // xyzw.parent = this; |
| 3414 | |
| 3415 | Value *value = rhs.loadValue(); |
| 3416 | storeValue(value); |
| 3417 | } |
| 3418 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3419 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3420 | { |
| 3421 | storeValue(rhs.value); |
| 3422 | |
| 3423 | return rhs; |
| 3424 | } |
| 3425 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3426 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3427 | { |
| 3428 | Value *value = rhs.loadValue(); |
| 3429 | storeValue(value); |
| 3430 | |
| 3431 | return RValue<UShort4>(value); |
| 3432 | } |
| 3433 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3434 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3435 | { |
| 3436 | Value *value = rhs.loadValue(); |
| 3437 | storeValue(value); |
| 3438 | |
| 3439 | return RValue<UShort4>(value); |
| 3440 | } |
| 3441 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3442 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3443 | { |
| 3444 | storeValue(rhs.value); |
| 3445 | |
| 3446 | return RValue<UShort4>(rhs); |
| 3447 | } |
| 3448 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3449 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3450 | { |
| 3451 | Value *value = rhs.loadValue(); |
| 3452 | storeValue(value); |
| 3453 | |
| 3454 | return RValue<UShort4>(value); |
| 3455 | } |
| 3456 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3457 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3458 | { |
| 3459 | Value *value = rhs.loadValue(); |
| 3460 | storeValue(value); |
| 3461 | |
| 3462 | return RValue<UShort4>(value); |
| 3463 | } |
| 3464 | |
| 3465 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3466 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3467 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3471 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3472 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3476 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3477 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3478 | } |
| 3479 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3480 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3481 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3482 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3486 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3487 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3491 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3492 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3493 | } |
| 3494 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3495 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3496 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3497 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3501 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3502 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3503 | } |
| 3504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3505 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3506 | { |
| 3507 | return lhs = lhs << rhs; |
| 3508 | } |
| 3509 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3510 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3511 | { |
| 3512 | return lhs = lhs >> rhs; |
| 3513 | } |
| 3514 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3515 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3516 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3517 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3521 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3522 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3523 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3524 | ::basicBlock->appendInst(cmp); |
| 3525 | |
| 3526 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3527 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3528 | ::basicBlock->appendInst(select); |
| 3529 | |
| 3530 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3534 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3535 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3536 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3537 | ::basicBlock->appendInst(cmp); |
| 3538 | |
| 3539 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3540 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3541 | ::basicBlock->appendInst(select); |
| 3542 | |
| 3543 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3547 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3548 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3549 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3550 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3551 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3552 | paddusw->addArg(x.value); |
| 3553 | paddusw->addArg(y.value); |
| 3554 | ::basicBlock->appendInst(paddusw); |
| 3555 | |
| 3556 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3560 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3561 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3562 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3563 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3564 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3565 | psubusw->addArg(x.value); |
| 3566 | psubusw->addArg(y.value); |
| 3567 | ::basicBlock->appendInst(psubusw); |
| 3568 | |
| 3569 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3573 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3574 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3575 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3576 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3577 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3578 | pmulhuw->addArg(x.value); |
| 3579 | pmulhuw->addArg(y.value); |
| 3580 | ::basicBlock->appendInst(pmulhuw); |
| 3581 | |
| 3582 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3586 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3587 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3591 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3592 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3593 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3594 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3595 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3596 | pack->addArg(x.value); |
| 3597 | pack->addArg(y.value); |
| 3598 | ::basicBlock->appendInst(pack); |
| 3599 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3600 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | Type *UShort4::getType() |
| 3604 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3605 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3609 | { |
| 3610 | // xyzw.parent = this; |
| 3611 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3612 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3613 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | Short8::Short8(RValue<Short8> rhs) |
| 3617 | { |
| 3618 | // xyzw.parent = this; |
| 3619 | |
| 3620 | storeValue(rhs.value); |
| 3621 | } |
| 3622 | |
| 3623 | Short8::Short8(const Reference<Short8> &rhs) |
| 3624 | { |
| 3625 | // xyzw.parent = this; |
| 3626 | |
| 3627 | Value *value = rhs.loadValue(); |
| 3628 | storeValue(value); |
| 3629 | } |
| 3630 | |
| 3631 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3632 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3633 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3634 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3635 | |
| 3636 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3640 | { |
| 3641 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3642 | } |
| 3643 | |
| 3644 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3645 | { |
| 3646 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3647 | } |
| 3648 | |
| 3649 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3650 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3651 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3655 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3656 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3660 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3661 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | RValue<Int4> Abs(RValue<Int4> x) |
| 3665 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3666 | auto negative = x >> 31; |
| 3667 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3671 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3672 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | Type *Short8::getType() |
| 3676 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3677 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | 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) |
| 3681 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3682 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3683 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3687 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3688 | storeValue(rhs.value); |
| 3689 | } |
| 3690 | |
| 3691 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3692 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3693 | Value *value = rhs.loadValue(); |
| 3694 | storeValue(value); |
| 3695 | } |
| 3696 | |
| 3697 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3698 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3699 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3700 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3701 | |
| 3702 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3703 | } |
| 3704 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3705 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3706 | { |
| 3707 | storeValue(rhs.value); |
| 3708 | |
| 3709 | return rhs; |
| 3710 | } |
| 3711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3712 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3713 | { |
| 3714 | Value *value = rhs.loadValue(); |
| 3715 | storeValue(value); |
| 3716 | |
| 3717 | return RValue<UShort8>(value); |
| 3718 | } |
| 3719 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3720 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3721 | { |
| 3722 | Value *value = rhs.loadValue(); |
| 3723 | storeValue(value); |
| 3724 | |
| 3725 | return RValue<UShort8>(value); |
| 3726 | } |
| 3727 | |
| 3728 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3729 | { |
| 3730 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3731 | } |
| 3732 | |
| 3733 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3734 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3735 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3739 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3740 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3744 | { |
| 3745 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3746 | } |
| 3747 | |
| 3748 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3749 | { |
| 3750 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3751 | } |
| 3752 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3753 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3754 | { |
| 3755 | return lhs = lhs + rhs; |
| 3756 | } |
| 3757 | |
| 3758 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3759 | { |
| 3760 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3761 | } |
| 3762 | |
| 3763 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3764 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3765 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3769 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3770 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3774 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3775 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3776 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3777 | // } |
| 3778 | |
| 3779 | Type *UShort8::getType() |
| 3780 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3781 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | Int::Int(Argument<Int> argument) |
| 3785 | { |
| 3786 | storeValue(argument.value); |
| 3787 | } |
| 3788 | |
| 3789 | Int::Int(RValue<Byte> cast) |
| 3790 | { |
| 3791 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3792 | |
| 3793 | storeValue(integer); |
| 3794 | } |
| 3795 | |
| 3796 | Int::Int(RValue<SByte> cast) |
| 3797 | { |
| 3798 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3799 | |
| 3800 | storeValue(integer); |
| 3801 | } |
| 3802 | |
| 3803 | Int::Int(RValue<Short> cast) |
| 3804 | { |
| 3805 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3806 | |
| 3807 | storeValue(integer); |
| 3808 | } |
| 3809 | |
| 3810 | Int::Int(RValue<UShort> cast) |
| 3811 | { |
| 3812 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3813 | |
| 3814 | storeValue(integer); |
| 3815 | } |
| 3816 | |
| 3817 | Int::Int(RValue<Int2> cast) |
| 3818 | { |
| 3819 | *this = Extract(cast, 0); |
| 3820 | } |
| 3821 | |
| 3822 | Int::Int(RValue<Long> cast) |
| 3823 | { |
| 3824 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3825 | |
| 3826 | storeValue(integer); |
| 3827 | } |
| 3828 | |
| 3829 | Int::Int(RValue<Float> cast) |
| 3830 | { |
| 3831 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3832 | |
| 3833 | storeValue(integer); |
| 3834 | } |
| 3835 | |
| 3836 | Int::Int() |
| 3837 | { |
| 3838 | } |
| 3839 | |
| 3840 | Int::Int(int x) |
| 3841 | { |
| 3842 | storeValue(Nucleus::createConstantInt(x)); |
| 3843 | } |
| 3844 | |
| 3845 | Int::Int(RValue<Int> rhs) |
| 3846 | { |
| 3847 | storeValue(rhs.value); |
| 3848 | } |
| 3849 | |
| 3850 | Int::Int(RValue<UInt> rhs) |
| 3851 | { |
| 3852 | storeValue(rhs.value); |
| 3853 | } |
| 3854 | |
| 3855 | Int::Int(const Int &rhs) |
| 3856 | { |
| 3857 | Value *value = rhs.loadValue(); |
| 3858 | storeValue(value); |
| 3859 | } |
| 3860 | |
| 3861 | Int::Int(const Reference<Int> &rhs) |
| 3862 | { |
| 3863 | Value *value = rhs.loadValue(); |
| 3864 | storeValue(value); |
| 3865 | } |
| 3866 | |
| 3867 | Int::Int(const UInt &rhs) |
| 3868 | { |
| 3869 | Value *value = rhs.loadValue(); |
| 3870 | storeValue(value); |
| 3871 | } |
| 3872 | |
| 3873 | Int::Int(const Reference<UInt> &rhs) |
| 3874 | { |
| 3875 | Value *value = rhs.loadValue(); |
| 3876 | storeValue(value); |
| 3877 | } |
| 3878 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3879 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3880 | { |
| 3881 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3882 | } |
| 3883 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3884 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3885 | { |
| 3886 | storeValue(rhs.value); |
| 3887 | |
| 3888 | return rhs; |
| 3889 | } |
| 3890 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3891 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3892 | { |
| 3893 | storeValue(rhs.value); |
| 3894 | |
| 3895 | return RValue<Int>(rhs); |
| 3896 | } |
| 3897 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3898 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3899 | { |
| 3900 | Value *value = rhs.loadValue(); |
| 3901 | storeValue(value); |
| 3902 | |
| 3903 | return RValue<Int>(value); |
| 3904 | } |
| 3905 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3906 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3907 | { |
| 3908 | Value *value = rhs.loadValue(); |
| 3909 | storeValue(value); |
| 3910 | |
| 3911 | return RValue<Int>(value); |
| 3912 | } |
| 3913 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3914 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3915 | { |
| 3916 | Value *value = rhs.loadValue(); |
| 3917 | storeValue(value); |
| 3918 | |
| 3919 | return RValue<Int>(value); |
| 3920 | } |
| 3921 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3922 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3923 | { |
| 3924 | Value *value = rhs.loadValue(); |
| 3925 | storeValue(value); |
| 3926 | |
| 3927 | return RValue<Int>(value); |
| 3928 | } |
| 3929 | |
| 3930 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3931 | { |
| 3932 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3933 | } |
| 3934 | |
| 3935 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3936 | { |
| 3937 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3938 | } |
| 3939 | |
| 3940 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3941 | { |
| 3942 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3943 | } |
| 3944 | |
| 3945 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3946 | { |
| 3947 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3948 | } |
| 3949 | |
| 3950 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3951 | { |
| 3952 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3953 | } |
| 3954 | |
| 3955 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3956 | { |
| 3957 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3958 | } |
| 3959 | |
| 3960 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 3961 | { |
| 3962 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3963 | } |
| 3964 | |
| 3965 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 3966 | { |
| 3967 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3968 | } |
| 3969 | |
| 3970 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 3971 | { |
| 3972 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3973 | } |
| 3974 | |
| 3975 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 3976 | { |
| 3977 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3978 | } |
| 3979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3980 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3981 | { |
| 3982 | return lhs = lhs + rhs; |
| 3983 | } |
| 3984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3985 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3986 | { |
| 3987 | return lhs = lhs - rhs; |
| 3988 | } |
| 3989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3990 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3991 | { |
| 3992 | return lhs = lhs * rhs; |
| 3993 | } |
| 3994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3995 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3996 | { |
| 3997 | return lhs = lhs / rhs; |
| 3998 | } |
| 3999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4000 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4001 | { |
| 4002 | return lhs = lhs % rhs; |
| 4003 | } |
| 4004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4005 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4006 | { |
| 4007 | return lhs = lhs & rhs; |
| 4008 | } |
| 4009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4010 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4011 | { |
| 4012 | return lhs = lhs | rhs; |
| 4013 | } |
| 4014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4015 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4016 | { |
| 4017 | return lhs = lhs ^ rhs; |
| 4018 | } |
| 4019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4020 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4021 | { |
| 4022 | return lhs = lhs << rhs; |
| 4023 | } |
| 4024 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4025 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4026 | { |
| 4027 | return lhs = lhs >> rhs; |
| 4028 | } |
| 4029 | |
| 4030 | RValue<Int> operator+(RValue<Int> val) |
| 4031 | { |
| 4032 | return val; |
| 4033 | } |
| 4034 | |
| 4035 | RValue<Int> operator-(RValue<Int> val) |
| 4036 | { |
| 4037 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4038 | } |
| 4039 | |
| 4040 | RValue<Int> operator~(RValue<Int> val) |
| 4041 | { |
| 4042 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4043 | } |
| 4044 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4045 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4046 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4047 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4048 | val += 1; |
| 4049 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4050 | } |
| 4051 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4052 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4053 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4054 | val += 1; |
| 4055 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4056 | } |
| 4057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4058 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4059 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4060 | RValue<Int> res = val; |
| 4061 | val -= 1; |
| 4062 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4063 | } |
| 4064 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4065 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4066 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4067 | val -= 1; |
| 4068 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4072 | { |
| 4073 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4074 | } |
| 4075 | |
| 4076 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4077 | { |
| 4078 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4079 | } |
| 4080 | |
| 4081 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4082 | { |
| 4083 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4084 | } |
| 4085 | |
| 4086 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4087 | { |
| 4088 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4089 | } |
| 4090 | |
| 4091 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4092 | { |
| 4093 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4094 | } |
| 4095 | |
| 4096 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4097 | { |
| 4098 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4099 | } |
| 4100 | |
| 4101 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4102 | { |
| 4103 | return IfThenElse(x > y, x, y); |
| 4104 | } |
| 4105 | |
| 4106 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4107 | { |
| 4108 | return IfThenElse(x < y, x, y); |
| 4109 | } |
| 4110 | |
| 4111 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4112 | { |
| 4113 | return Min(Max(x, min), max); |
| 4114 | } |
| 4115 | |
| 4116 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4117 | { |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 4118 | RValue<Float> rounded = Round(cast); |
| 4119 | |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4120 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 4121 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4122 | ::basicBlock->appendInst(round); |
| 4123 | |
| 4124 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | Type *Int::getType() |
| 4128 | { |
| 4129 | return T(Ice::IceType_i32); |
| 4130 | } |
| 4131 | |
| 4132 | Long::Long(RValue<Int> cast) |
| 4133 | { |
| 4134 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4135 | |
| 4136 | storeValue(integer); |
| 4137 | } |
| 4138 | |
| 4139 | Long::Long(RValue<UInt> cast) |
| 4140 | { |
| 4141 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4142 | |
| 4143 | storeValue(integer); |
| 4144 | } |
| 4145 | |
| 4146 | Long::Long() |
| 4147 | { |
| 4148 | } |
| 4149 | |
| 4150 | Long::Long(RValue<Long> rhs) |
| 4151 | { |
| 4152 | storeValue(rhs.value); |
| 4153 | } |
| 4154 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4155 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4156 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4157 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4158 | } |
| 4159 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4160 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4161 | { |
| 4162 | storeValue(rhs.value); |
| 4163 | |
| 4164 | return rhs; |
| 4165 | } |
| 4166 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4167 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4168 | { |
| 4169 | Value *value = rhs.loadValue(); |
| 4170 | storeValue(value); |
| 4171 | |
| 4172 | return RValue<Long>(value); |
| 4173 | } |
| 4174 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4175 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4176 | { |
| 4177 | Value *value = rhs.loadValue(); |
| 4178 | storeValue(value); |
| 4179 | |
| 4180 | return RValue<Long>(value); |
| 4181 | } |
| 4182 | |
| 4183 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4184 | { |
| 4185 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4186 | } |
| 4187 | |
| 4188 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4189 | { |
| 4190 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4191 | } |
| 4192 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4193 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4194 | { |
| 4195 | return lhs = lhs + rhs; |
| 4196 | } |
| 4197 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4198 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4199 | { |
| 4200 | return lhs = lhs - rhs; |
| 4201 | } |
| 4202 | |
| 4203 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4204 | { |
| 4205 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4206 | } |
| 4207 | |
| 4208 | Type *Long::getType() |
| 4209 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4210 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4211 | } |
| 4212 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4213 | UInt::UInt(Argument<UInt> argument) |
| 4214 | { |
| 4215 | storeValue(argument.value); |
| 4216 | } |
| 4217 | |
| 4218 | UInt::UInt(RValue<UShort> cast) |
| 4219 | { |
| 4220 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4221 | |
| 4222 | storeValue(integer); |
| 4223 | } |
| 4224 | |
| 4225 | UInt::UInt(RValue<Long> cast) |
| 4226 | { |
| 4227 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4228 | |
| 4229 | storeValue(integer); |
| 4230 | } |
| 4231 | |
| 4232 | UInt::UInt(RValue<Float> cast) |
| 4233 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4234 | // Smallest positive value representable in UInt, but not in Int |
| 4235 | const unsigned int ustart = 0x80000000u; |
| 4236 | const float ustartf = float(ustart); |
| 4237 | |
| 4238 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4239 | storeValue((~(As<Int>(cast) >> 31) & |
| 4240 | // Check if the value can be represented as an Int |
| 4241 | IfThenElse(cast >= ustartf, |
| 4242 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4243 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4244 | // Otherwise, just convert normally |
| 4245 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | UInt::UInt() |
| 4249 | { |
| 4250 | } |
| 4251 | |
| 4252 | UInt::UInt(int x) |
| 4253 | { |
| 4254 | storeValue(Nucleus::createConstantInt(x)); |
| 4255 | } |
| 4256 | |
| 4257 | UInt::UInt(unsigned int x) |
| 4258 | { |
| 4259 | storeValue(Nucleus::createConstantInt(x)); |
| 4260 | } |
| 4261 | |
| 4262 | UInt::UInt(RValue<UInt> rhs) |
| 4263 | { |
| 4264 | storeValue(rhs.value); |
| 4265 | } |
| 4266 | |
| 4267 | UInt::UInt(RValue<Int> rhs) |
| 4268 | { |
| 4269 | storeValue(rhs.value); |
| 4270 | } |
| 4271 | |
| 4272 | UInt::UInt(const UInt &rhs) |
| 4273 | { |
| 4274 | Value *value = rhs.loadValue(); |
| 4275 | storeValue(value); |
| 4276 | } |
| 4277 | |
| 4278 | UInt::UInt(const Reference<UInt> &rhs) |
| 4279 | { |
| 4280 | Value *value = rhs.loadValue(); |
| 4281 | storeValue(value); |
| 4282 | } |
| 4283 | |
| 4284 | UInt::UInt(const Int &rhs) |
| 4285 | { |
| 4286 | Value *value = rhs.loadValue(); |
| 4287 | storeValue(value); |
| 4288 | } |
| 4289 | |
| 4290 | UInt::UInt(const Reference<Int> &rhs) |
| 4291 | { |
| 4292 | Value *value = rhs.loadValue(); |
| 4293 | storeValue(value); |
| 4294 | } |
| 4295 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4296 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4297 | { |
| 4298 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4299 | } |
| 4300 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4301 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4302 | { |
| 4303 | storeValue(rhs.value); |
| 4304 | |
| 4305 | return rhs; |
| 4306 | } |
| 4307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4308 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4309 | { |
| 4310 | storeValue(rhs.value); |
| 4311 | |
| 4312 | return RValue<UInt>(rhs); |
| 4313 | } |
| 4314 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4315 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4316 | { |
| 4317 | Value *value = rhs.loadValue(); |
| 4318 | storeValue(value); |
| 4319 | |
| 4320 | return RValue<UInt>(value); |
| 4321 | } |
| 4322 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4323 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4324 | { |
| 4325 | Value *value = rhs.loadValue(); |
| 4326 | storeValue(value); |
| 4327 | |
| 4328 | return RValue<UInt>(value); |
| 4329 | } |
| 4330 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4331 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4332 | { |
| 4333 | Value *value = rhs.loadValue(); |
| 4334 | storeValue(value); |
| 4335 | |
| 4336 | return RValue<UInt>(value); |
| 4337 | } |
| 4338 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4339 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4340 | { |
| 4341 | Value *value = rhs.loadValue(); |
| 4342 | storeValue(value); |
| 4343 | |
| 4344 | return RValue<UInt>(value); |
| 4345 | } |
| 4346 | |
| 4347 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4348 | { |
| 4349 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4350 | } |
| 4351 | |
| 4352 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4353 | { |
| 4354 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4355 | } |
| 4356 | |
| 4357 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4358 | { |
| 4359 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4360 | } |
| 4361 | |
| 4362 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4363 | { |
| 4364 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4365 | } |
| 4366 | |
| 4367 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4368 | { |
| 4369 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4370 | } |
| 4371 | |
| 4372 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4373 | { |
| 4374 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4375 | } |
| 4376 | |
| 4377 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4378 | { |
| 4379 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4380 | } |
| 4381 | |
| 4382 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4383 | { |
| 4384 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4385 | } |
| 4386 | |
| 4387 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4388 | { |
| 4389 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4390 | } |
| 4391 | |
| 4392 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4393 | { |
| 4394 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4395 | } |
| 4396 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4397 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4398 | { |
| 4399 | return lhs = lhs + rhs; |
| 4400 | } |
| 4401 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4402 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4403 | { |
| 4404 | return lhs = lhs - rhs; |
| 4405 | } |
| 4406 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4407 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4408 | { |
| 4409 | return lhs = lhs * rhs; |
| 4410 | } |
| 4411 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4412 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4413 | { |
| 4414 | return lhs = lhs / rhs; |
| 4415 | } |
| 4416 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4417 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4418 | { |
| 4419 | return lhs = lhs % rhs; |
| 4420 | } |
| 4421 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4422 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4423 | { |
| 4424 | return lhs = lhs & rhs; |
| 4425 | } |
| 4426 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4427 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4428 | { |
| 4429 | return lhs = lhs | rhs; |
| 4430 | } |
| 4431 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4432 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4433 | { |
| 4434 | return lhs = lhs ^ rhs; |
| 4435 | } |
| 4436 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4437 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4438 | { |
| 4439 | return lhs = lhs << rhs; |
| 4440 | } |
| 4441 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4442 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4443 | { |
| 4444 | return lhs = lhs >> rhs; |
| 4445 | } |
| 4446 | |
| 4447 | RValue<UInt> operator+(RValue<UInt> val) |
| 4448 | { |
| 4449 | return val; |
| 4450 | } |
| 4451 | |
| 4452 | RValue<UInt> operator-(RValue<UInt> val) |
| 4453 | { |
| 4454 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4455 | } |
| 4456 | |
| 4457 | RValue<UInt> operator~(RValue<UInt> val) |
| 4458 | { |
| 4459 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4460 | } |
| 4461 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4462 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4463 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4464 | RValue<UInt> res = val; |
| 4465 | val += 1; |
| 4466 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4467 | } |
| 4468 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4469 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4470 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4471 | val += 1; |
| 4472 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4473 | } |
| 4474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4475 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4476 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4477 | RValue<UInt> res = val; |
| 4478 | val -= 1; |
| 4479 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4480 | } |
| 4481 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4482 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4483 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4484 | val -= 1; |
| 4485 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4489 | { |
| 4490 | return IfThenElse(x > y, x, y); |
| 4491 | } |
| 4492 | |
| 4493 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4494 | { |
| 4495 | return IfThenElse(x < y, x, y); |
| 4496 | } |
| 4497 | |
| 4498 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4499 | { |
| 4500 | return Min(Max(x, min), max); |
| 4501 | } |
| 4502 | |
| 4503 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4504 | { |
| 4505 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4506 | } |
| 4507 | |
| 4508 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4509 | { |
| 4510 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4511 | } |
| 4512 | |
| 4513 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4514 | { |
| 4515 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4516 | } |
| 4517 | |
| 4518 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4519 | { |
| 4520 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4521 | } |
| 4522 | |
| 4523 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4524 | { |
| 4525 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4526 | } |
| 4527 | |
| 4528 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4529 | { |
| 4530 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4531 | } |
| 4532 | |
| 4533 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4534 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4535 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4536 | // } |
| 4537 | |
| 4538 | Type *UInt::getType() |
| 4539 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4540 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | // Int2::Int2(RValue<Int> cast) |
| 4544 | // { |
| 4545 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4546 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4547 | // |
| 4548 | // Constant *shuffle[2]; |
| 4549 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4550 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4551 | // |
| 4552 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4553 | // |
| 4554 | // storeValue(replicate); |
| 4555 | // } |
| 4556 | |
| 4557 | Int2::Int2(RValue<Int4> cast) |
| 4558 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4559 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | Int2::Int2() |
| 4563 | { |
| 4564 | // xy.parent = this; |
| 4565 | } |
| 4566 | |
| 4567 | Int2::Int2(int x, int y) |
| 4568 | { |
| 4569 | // xy.parent = this; |
| 4570 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4571 | int64_t constantVector[2] = {x, y}; |
| 4572 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | Int2::Int2(RValue<Int2> rhs) |
| 4576 | { |
| 4577 | // xy.parent = this; |
| 4578 | |
| 4579 | storeValue(rhs.value); |
| 4580 | } |
| 4581 | |
| 4582 | Int2::Int2(const Int2 &rhs) |
| 4583 | { |
| 4584 | // xy.parent = this; |
| 4585 | |
| 4586 | Value *value = rhs.loadValue(); |
| 4587 | storeValue(value); |
| 4588 | } |
| 4589 | |
| 4590 | Int2::Int2(const Reference<Int2> &rhs) |
| 4591 | { |
| 4592 | // xy.parent = this; |
| 4593 | |
| 4594 | Value *value = rhs.loadValue(); |
| 4595 | storeValue(value); |
| 4596 | } |
| 4597 | |
| 4598 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4599 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4600 | int shuffle[4] = {0, 4, 1, 5}; |
| 4601 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4602 | |
| 4603 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4604 | } |
| 4605 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4606 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4607 | { |
| 4608 | storeValue(rhs.value); |
| 4609 | |
| 4610 | return rhs; |
| 4611 | } |
| 4612 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4613 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4614 | { |
| 4615 | Value *value = rhs.loadValue(); |
| 4616 | storeValue(value); |
| 4617 | |
| 4618 | return RValue<Int2>(value); |
| 4619 | } |
| 4620 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4621 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4622 | { |
| 4623 | Value *value = rhs.loadValue(); |
| 4624 | storeValue(value); |
| 4625 | |
| 4626 | return RValue<Int2>(value); |
| 4627 | } |
| 4628 | |
| 4629 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4630 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4631 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4635 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4636 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4640 | // { |
| 4641 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4642 | // } |
| 4643 | |
| 4644 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4645 | // { |
| 4646 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4647 | // } |
| 4648 | |
| 4649 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4650 | // { |
| 4651 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4652 | // } |
| 4653 | |
| 4654 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4655 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4656 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4660 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4661 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4665 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4666 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4670 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4671 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4675 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4676 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4677 | } |
| 4678 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4679 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4680 | { |
| 4681 | return lhs = lhs + rhs; |
| 4682 | } |
| 4683 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4684 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4685 | { |
| 4686 | return lhs = lhs - rhs; |
| 4687 | } |
| 4688 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4689 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4690 | // { |
| 4691 | // return lhs = lhs * rhs; |
| 4692 | // } |
| 4693 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4694 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4695 | // { |
| 4696 | // return lhs = lhs / rhs; |
| 4697 | // } |
| 4698 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4699 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4700 | // { |
| 4701 | // return lhs = lhs % rhs; |
| 4702 | // } |
| 4703 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4704 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4705 | { |
| 4706 | return lhs = lhs & rhs; |
| 4707 | } |
| 4708 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4709 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4710 | { |
| 4711 | return lhs = lhs | rhs; |
| 4712 | } |
| 4713 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4714 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4715 | { |
| 4716 | return lhs = lhs ^ rhs; |
| 4717 | } |
| 4718 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4719 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4720 | { |
| 4721 | return lhs = lhs << rhs; |
| 4722 | } |
| 4723 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4724 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4725 | { |
| 4726 | return lhs = lhs >> rhs; |
| 4727 | } |
| 4728 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4729 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4730 | // { |
| 4731 | // return val; |
| 4732 | // } |
| 4733 | |
| 4734 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4735 | // { |
| 4736 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4737 | // } |
| 4738 | |
| 4739 | RValue<Int2> operator~(RValue<Int2> val) |
| 4740 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4741 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4742 | } |
| 4743 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4744 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4745 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4746 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4747 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4748 | } |
| 4749 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4750 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4751 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4752 | int shuffle[16] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4753 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4754 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4758 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4759 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4763 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4764 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | Type *Int2::getType() |
| 4768 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4769 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | UInt2::UInt2() |
| 4773 | { |
| 4774 | // xy.parent = this; |
| 4775 | } |
| 4776 | |
| 4777 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4778 | { |
| 4779 | // xy.parent = this; |
| 4780 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4781 | int64_t constantVector[2] = {x, y}; |
| 4782 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4786 | { |
| 4787 | // xy.parent = this; |
| 4788 | |
| 4789 | storeValue(rhs.value); |
| 4790 | } |
| 4791 | |
| 4792 | UInt2::UInt2(const UInt2 &rhs) |
| 4793 | { |
| 4794 | // xy.parent = this; |
| 4795 | |
| 4796 | Value *value = rhs.loadValue(); |
| 4797 | storeValue(value); |
| 4798 | } |
| 4799 | |
| 4800 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4801 | { |
| 4802 | // xy.parent = this; |
| 4803 | |
| 4804 | Value *value = rhs.loadValue(); |
| 4805 | storeValue(value); |
| 4806 | } |
| 4807 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4808 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4809 | { |
| 4810 | storeValue(rhs.value); |
| 4811 | |
| 4812 | return rhs; |
| 4813 | } |
| 4814 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4815 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4816 | { |
| 4817 | Value *value = rhs.loadValue(); |
| 4818 | storeValue(value); |
| 4819 | |
| 4820 | return RValue<UInt2>(value); |
| 4821 | } |
| 4822 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4823 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4824 | { |
| 4825 | Value *value = rhs.loadValue(); |
| 4826 | storeValue(value); |
| 4827 | |
| 4828 | return RValue<UInt2>(value); |
| 4829 | } |
| 4830 | |
| 4831 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4832 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4833 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4837 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4838 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4842 | // { |
| 4843 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4844 | // } |
| 4845 | |
| 4846 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4847 | // { |
| 4848 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4849 | // } |
| 4850 | |
| 4851 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4852 | // { |
| 4853 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4854 | // } |
| 4855 | |
| 4856 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4857 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4858 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4862 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4863 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4867 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4868 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4872 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4873 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4877 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4878 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4879 | } |
| 4880 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4881 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4882 | { |
| 4883 | return lhs = lhs + rhs; |
| 4884 | } |
| 4885 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4886 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4887 | { |
| 4888 | return lhs = lhs - rhs; |
| 4889 | } |
| 4890 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4891 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4892 | // { |
| 4893 | // return lhs = lhs * rhs; |
| 4894 | // } |
| 4895 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4896 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4897 | // { |
| 4898 | // return lhs = lhs / rhs; |
| 4899 | // } |
| 4900 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4901 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4902 | // { |
| 4903 | // return lhs = lhs % rhs; |
| 4904 | // } |
| 4905 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4906 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4907 | { |
| 4908 | return lhs = lhs & rhs; |
| 4909 | } |
| 4910 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4911 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4912 | { |
| 4913 | return lhs = lhs | rhs; |
| 4914 | } |
| 4915 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4916 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4917 | { |
| 4918 | return lhs = lhs ^ rhs; |
| 4919 | } |
| 4920 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4921 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4922 | { |
| 4923 | return lhs = lhs << rhs; |
| 4924 | } |
| 4925 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4926 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4927 | { |
| 4928 | return lhs = lhs >> rhs; |
| 4929 | } |
| 4930 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4931 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4932 | // { |
| 4933 | // return val; |
| 4934 | // } |
| 4935 | |
| 4936 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4937 | // { |
| 4938 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4939 | // } |
| 4940 | |
| 4941 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4942 | { |
| 4943 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4944 | } |
| 4945 | |
| 4946 | Type *UInt2::getType() |
| 4947 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4948 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | Int4::Int4(RValue<Byte4> cast) |
| 4952 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4953 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4954 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4955 | |
| 4956 | Value *e; |
| 4957 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4958 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4959 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4960 | |
| 4961 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4962 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4963 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4964 | |
| 4965 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4966 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | Int4::Int4(RValue<SByte4> 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, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4976 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4977 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4978 | |
| 4979 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4980 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4981 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 4982 | |
| 4983 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4984 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4985 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | Int4::Int4(RValue<Float4> cast) |
| 4989 | { |
| 4990 | // xyzw.parent = this; |
| 4991 | |
| 4992 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 4993 | |
| 4994 | storeValue(xyzw); |
| 4995 | } |
| 4996 | |
| 4997 | Int4::Int4(RValue<Short4> cast) |
| 4998 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4999 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5000 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 5001 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5002 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5003 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | Int4::Int4(RValue<UShort4> cast) |
| 5007 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5008 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5009 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5010 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5011 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | Int4::Int4() |
| 5015 | { |
| 5016 | // xyzw.parent = this; |
| 5017 | } |
| 5018 | |
| 5019 | Int4::Int4(int xyzw) |
| 5020 | { |
| 5021 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5022 | } |
| 5023 | |
| 5024 | Int4::Int4(int x, int yzw) |
| 5025 | { |
| 5026 | constant(x, yzw, yzw, yzw); |
| 5027 | } |
| 5028 | |
| 5029 | Int4::Int4(int x, int y, int zw) |
| 5030 | { |
| 5031 | constant(x, y, zw, zw); |
| 5032 | } |
| 5033 | |
| 5034 | Int4::Int4(int x, int y, int z, int w) |
| 5035 | { |
| 5036 | constant(x, y, z, w); |
| 5037 | } |
| 5038 | |
| 5039 | void Int4::constant(int x, int y, int z, int w) |
| 5040 | { |
| 5041 | // xyzw.parent = this; |
| 5042 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5043 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5044 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | Int4::Int4(RValue<Int4> rhs) |
| 5048 | { |
| 5049 | // xyzw.parent = this; |
| 5050 | |
| 5051 | storeValue(rhs.value); |
| 5052 | } |
| 5053 | |
| 5054 | Int4::Int4(const Int4 &rhs) |
| 5055 | { |
| 5056 | // xyzw.parent = this; |
| 5057 | |
| 5058 | Value *value = rhs.loadValue(); |
| 5059 | storeValue(value); |
| 5060 | } |
| 5061 | |
| 5062 | Int4::Int4(const Reference<Int4> &rhs) |
| 5063 | { |
| 5064 | // xyzw.parent = this; |
| 5065 | |
| 5066 | Value *value = rhs.loadValue(); |
| 5067 | storeValue(value); |
| 5068 | } |
| 5069 | |
| 5070 | Int4::Int4(RValue<UInt4> rhs) |
| 5071 | { |
| 5072 | // xyzw.parent = this; |
| 5073 | |
| 5074 | storeValue(rhs.value); |
| 5075 | } |
| 5076 | |
| 5077 | Int4::Int4(const UInt4 &rhs) |
| 5078 | { |
| 5079 | // xyzw.parent = this; |
| 5080 | |
| 5081 | Value *value = rhs.loadValue(); |
| 5082 | storeValue(value); |
| 5083 | } |
| 5084 | |
| 5085 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5086 | { |
| 5087 | // xyzw.parent = this; |
| 5088 | |
| 5089 | Value *value = rhs.loadValue(); |
| 5090 | storeValue(value); |
| 5091 | } |
| 5092 | |
| 5093 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5094 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5095 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5096 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5097 | |
| 5098 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | Int4::Int4(RValue<Int> rhs) |
| 5102 | { |
| 5103 | // xyzw.parent = this; |
| 5104 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5105 | Value *vector = loadValue(); |
| 5106 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5107 | |
| 5108 | int swizzle[4] = {0, 0, 0, 0}; |
| 5109 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 5110 | |
| 5111 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | Int4::Int4(const Int &rhs) |
| 5115 | { |
| 5116 | // xyzw.parent = this; |
| 5117 | |
| 5118 | *this = RValue<Int>(rhs.loadValue()); |
| 5119 | } |
| 5120 | |
| 5121 | Int4::Int4(const Reference<Int> &rhs) |
| 5122 | { |
| 5123 | // xyzw.parent = this; |
| 5124 | |
| 5125 | *this = RValue<Int>(rhs.loadValue()); |
| 5126 | } |
| 5127 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5128 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5129 | { |
| 5130 | storeValue(rhs.value); |
| 5131 | |
| 5132 | return rhs; |
| 5133 | } |
| 5134 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5135 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5136 | { |
| 5137 | Value *value = rhs.loadValue(); |
| 5138 | storeValue(value); |
| 5139 | |
| 5140 | return RValue<Int4>(value); |
| 5141 | } |
| 5142 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5143 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5144 | { |
| 5145 | Value *value = rhs.loadValue(); |
| 5146 | storeValue(value); |
| 5147 | |
| 5148 | return RValue<Int4>(value); |
| 5149 | } |
| 5150 | |
| 5151 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5152 | { |
| 5153 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5154 | } |
| 5155 | |
| 5156 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5157 | { |
| 5158 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5159 | } |
| 5160 | |
| 5161 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5162 | { |
| 5163 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5164 | } |
| 5165 | |
| 5166 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5167 | { |
| 5168 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5169 | } |
| 5170 | |
| 5171 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5172 | { |
| 5173 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5174 | } |
| 5175 | |
| 5176 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5177 | { |
| 5178 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5179 | } |
| 5180 | |
| 5181 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5182 | { |
| 5183 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5184 | } |
| 5185 | |
| 5186 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5187 | { |
| 5188 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5189 | } |
| 5190 | |
| 5191 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5192 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5193 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5197 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5198 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5202 | { |
| 5203 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5204 | } |
| 5205 | |
| 5206 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5207 | { |
| 5208 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5209 | } |
| 5210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5211 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5212 | { |
| 5213 | return lhs = lhs + rhs; |
| 5214 | } |
| 5215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5216 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5217 | { |
| 5218 | return lhs = lhs - rhs; |
| 5219 | } |
| 5220 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5221 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5222 | { |
| 5223 | return lhs = lhs * rhs; |
| 5224 | } |
| 5225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5226 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5227 | // { |
| 5228 | // return lhs = lhs / rhs; |
| 5229 | // } |
| 5230 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5231 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5232 | // { |
| 5233 | // return lhs = lhs % rhs; |
| 5234 | // } |
| 5235 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5236 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5237 | { |
| 5238 | return lhs = lhs & rhs; |
| 5239 | } |
| 5240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5241 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5242 | { |
| 5243 | return lhs = lhs | rhs; |
| 5244 | } |
| 5245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5246 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5247 | { |
| 5248 | return lhs = lhs ^ rhs; |
| 5249 | } |
| 5250 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5251 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5252 | { |
| 5253 | return lhs = lhs << rhs; |
| 5254 | } |
| 5255 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5256 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5257 | { |
| 5258 | return lhs = lhs >> rhs; |
| 5259 | } |
| 5260 | |
| 5261 | RValue<Int4> operator+(RValue<Int4> val) |
| 5262 | { |
| 5263 | return val; |
| 5264 | } |
| 5265 | |
| 5266 | RValue<Int4> operator-(RValue<Int4> val) |
| 5267 | { |
| 5268 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5269 | } |
| 5270 | |
| 5271 | RValue<Int4> operator~(RValue<Int4> val) |
| 5272 | { |
| 5273 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5274 | } |
| 5275 | |
| 5276 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5277 | { |
| 5278 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5279 | } |
| 5280 | |
| 5281 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5282 | { |
| 5283 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5284 | } |
| 5285 | |
| 5286 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5287 | { |
| 5288 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5289 | } |
| 5290 | |
| 5291 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5292 | { |
| 5293 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5294 | } |
| 5295 | |
| 5296 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5297 | { |
| 5298 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5299 | } |
| 5300 | |
| 5301 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5302 | { |
| 5303 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5304 | } |
| 5305 | |
| 5306 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5307 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5308 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5309 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5310 | ::basicBlock->appendInst(cmp); |
| 5311 | |
| 5312 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5313 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5314 | ::basicBlock->appendInst(select); |
| 5315 | |
| 5316 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5320 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5321 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5322 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5323 | ::basicBlock->appendInst(cmp); |
| 5324 | |
| 5325 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5326 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5327 | ::basicBlock->appendInst(select); |
| 5328 | |
| 5329 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5333 | { |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 5334 | RValue<Float4> rounded = Round(cast); |
| 5335 | |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5336 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 5337 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5338 | ::basicBlock->appendInst(round); |
| 5339 | |
| 5340 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5344 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5345 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5346 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5347 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5348 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5349 | pack->addArg(x.value); |
| 5350 | pack->addArg(y.value); |
| 5351 | ::basicBlock->appendInst(pack); |
| 5352 | |
| 5353 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5357 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5358 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5362 | { |
| 5363 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5364 | } |
| 5365 | |
| 5366 | RValue<Int> SignMask(RValue<Int4> x) |
| 5367 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5368 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5369 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5370 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5371 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5372 | movmsk->addArg(x.value); |
| 5373 | ::basicBlock->appendInst(movmsk); |
| 5374 | |
| 5375 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5379 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5380 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | Type *Int4::getType() |
| 5384 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5385 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | UInt4::UInt4(RValue<Float4> cast) |
| 5389 | { |
| 5390 | // xyzw.parent = this; |
| 5391 | |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5392 | // Smallest positive value representable in UInt, but not in Int |
| 5393 | const unsigned int ustart = 0x80000000u; |
| 5394 | const float ustartf = float(ustart); |
| 5395 | |
| 5396 | // Check if the value can be represented as an Int |
| 5397 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5398 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5399 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5400 | // Otherwise, just convert normally |
| 5401 | (~uiValue & Int4(cast)); |
| 5402 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5403 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | UInt4::UInt4() |
| 5407 | { |
| 5408 | // xyzw.parent = this; |
| 5409 | } |
| 5410 | |
| 5411 | UInt4::UInt4(int xyzw) |
| 5412 | { |
| 5413 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5414 | } |
| 5415 | |
| 5416 | UInt4::UInt4(int x, int yzw) |
| 5417 | { |
| 5418 | constant(x, yzw, yzw, yzw); |
| 5419 | } |
| 5420 | |
| 5421 | UInt4::UInt4(int x, int y, int zw) |
| 5422 | { |
| 5423 | constant(x, y, zw, zw); |
| 5424 | } |
| 5425 | |
| 5426 | UInt4::UInt4(int x, int y, int z, int w) |
| 5427 | { |
| 5428 | constant(x, y, z, w); |
| 5429 | } |
| 5430 | |
| 5431 | void UInt4::constant(int x, int y, int z, int w) |
| 5432 | { |
| 5433 | // xyzw.parent = this; |
| 5434 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5435 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5436 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5440 | { |
| 5441 | // xyzw.parent = this; |
| 5442 | |
| 5443 | storeValue(rhs.value); |
| 5444 | } |
| 5445 | |
| 5446 | UInt4::UInt4(const UInt4 &rhs) |
| 5447 | { |
| 5448 | // xyzw.parent = this; |
| 5449 | |
| 5450 | Value *value = rhs.loadValue(); |
| 5451 | storeValue(value); |
| 5452 | } |
| 5453 | |
| 5454 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5455 | { |
| 5456 | // xyzw.parent = this; |
| 5457 | |
| 5458 | Value *value = rhs.loadValue(); |
| 5459 | storeValue(value); |
| 5460 | } |
| 5461 | |
| 5462 | UInt4::UInt4(RValue<Int4> rhs) |
| 5463 | { |
| 5464 | // xyzw.parent = this; |
| 5465 | |
| 5466 | storeValue(rhs.value); |
| 5467 | } |
| 5468 | |
| 5469 | UInt4::UInt4(const Int4 &rhs) |
| 5470 | { |
| 5471 | // xyzw.parent = this; |
| 5472 | |
| 5473 | Value *value = rhs.loadValue(); |
| 5474 | storeValue(value); |
| 5475 | } |
| 5476 | |
| 5477 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5478 | { |
| 5479 | // xyzw.parent = this; |
| 5480 | |
| 5481 | Value *value = rhs.loadValue(); |
| 5482 | storeValue(value); |
| 5483 | } |
| 5484 | |
| 5485 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5486 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5487 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5488 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5489 | |
| 5490 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5491 | } |
| 5492 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5493 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5494 | { |
| 5495 | storeValue(rhs.value); |
| 5496 | |
| 5497 | return rhs; |
| 5498 | } |
| 5499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5500 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5501 | { |
| 5502 | Value *value = rhs.loadValue(); |
| 5503 | storeValue(value); |
| 5504 | |
| 5505 | return RValue<UInt4>(value); |
| 5506 | } |
| 5507 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5508 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5509 | { |
| 5510 | Value *value = rhs.loadValue(); |
| 5511 | storeValue(value); |
| 5512 | |
| 5513 | return RValue<UInt4>(value); |
| 5514 | } |
| 5515 | |
| 5516 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5517 | { |
| 5518 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5519 | } |
| 5520 | |
| 5521 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5522 | { |
| 5523 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5524 | } |
| 5525 | |
| 5526 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5527 | { |
| 5528 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5529 | } |
| 5530 | |
| 5531 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5532 | { |
| 5533 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5534 | } |
| 5535 | |
| 5536 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5537 | { |
| 5538 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5539 | } |
| 5540 | |
| 5541 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5542 | { |
| 5543 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5544 | } |
| 5545 | |
| 5546 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5547 | { |
| 5548 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5549 | } |
| 5550 | |
| 5551 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5552 | { |
| 5553 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5554 | } |
| 5555 | |
| 5556 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5557 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5558 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5562 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5563 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5567 | { |
| 5568 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5569 | } |
| 5570 | |
| 5571 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5572 | { |
| 5573 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5574 | } |
| 5575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5576 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5577 | { |
| 5578 | return lhs = lhs + rhs; |
| 5579 | } |
| 5580 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5581 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5582 | { |
| 5583 | return lhs = lhs - rhs; |
| 5584 | } |
| 5585 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5586 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5587 | { |
| 5588 | return lhs = lhs * rhs; |
| 5589 | } |
| 5590 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5591 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5592 | // { |
| 5593 | // return lhs = lhs / rhs; |
| 5594 | // } |
| 5595 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5596 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5597 | // { |
| 5598 | // return lhs = lhs % rhs; |
| 5599 | // } |
| 5600 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5601 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5602 | { |
| 5603 | return lhs = lhs & rhs; |
| 5604 | } |
| 5605 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5606 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5607 | { |
| 5608 | return lhs = lhs | rhs; |
| 5609 | } |
| 5610 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5611 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5612 | { |
| 5613 | return lhs = lhs ^ rhs; |
| 5614 | } |
| 5615 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5616 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5617 | { |
| 5618 | return lhs = lhs << rhs; |
| 5619 | } |
| 5620 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5621 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5622 | { |
| 5623 | return lhs = lhs >> rhs; |
| 5624 | } |
| 5625 | |
| 5626 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5627 | { |
| 5628 | return val; |
| 5629 | } |
| 5630 | |
| 5631 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5632 | { |
| 5633 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5634 | } |
| 5635 | |
| 5636 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5637 | { |
| 5638 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5639 | } |
| 5640 | |
| 5641 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5642 | { |
| 5643 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5644 | } |
| 5645 | |
| 5646 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5647 | { |
| 5648 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 5649 | } |
| 5650 | |
| 5651 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5652 | { |
| 5653 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 5654 | } |
| 5655 | |
| 5656 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5657 | { |
| 5658 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5659 | } |
| 5660 | |
| 5661 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5662 | { |
| 5663 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 5664 | } |
| 5665 | |
| 5666 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5667 | { |
| 5668 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 5669 | } |
| 5670 | |
| 5671 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5672 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5673 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5674 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5675 | ::basicBlock->appendInst(cmp); |
| 5676 | |
| 5677 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5678 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5679 | ::basicBlock->appendInst(select); |
| 5680 | |
| 5681 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5685 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5686 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5687 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5688 | ::basicBlock->appendInst(cmp); |
| 5689 | |
| 5690 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5691 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5692 | ::basicBlock->appendInst(select); |
| 5693 | |
| 5694 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5698 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5699 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5700 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5701 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5702 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5703 | pack->addArg(x.value); |
| 5704 | pack->addArg(y.value); |
| 5705 | ::basicBlock->appendInst(pack); |
| 5706 | |
| 5707 | return RValue<UShort8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | Type *UInt4::getType() |
| 5711 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5712 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | Float::Float(RValue<Int> cast) |
| 5716 | { |
| 5717 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5718 | |
| 5719 | storeValue(integer); |
| 5720 | } |
| 5721 | |
| 5722 | Float::Float() |
| 5723 | { |
| 5724 | } |
| 5725 | |
| 5726 | Float::Float(float x) |
| 5727 | { |
| 5728 | storeValue(Nucleus::createConstantFloat(x)); |
| 5729 | } |
| 5730 | |
| 5731 | Float::Float(RValue<Float> rhs) |
| 5732 | { |
| 5733 | storeValue(rhs.value); |
| 5734 | } |
| 5735 | |
| 5736 | Float::Float(const Float &rhs) |
| 5737 | { |
| 5738 | Value *value = rhs.loadValue(); |
| 5739 | storeValue(value); |
| 5740 | } |
| 5741 | |
| 5742 | Float::Float(const Reference<Float> &rhs) |
| 5743 | { |
| 5744 | Value *value = rhs.loadValue(); |
| 5745 | storeValue(value); |
| 5746 | } |
| 5747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5748 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5749 | { |
| 5750 | storeValue(rhs.value); |
| 5751 | |
| 5752 | return rhs; |
| 5753 | } |
| 5754 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5755 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5756 | { |
| 5757 | Value *value = rhs.loadValue(); |
| 5758 | storeValue(value); |
| 5759 | |
| 5760 | return RValue<Float>(value); |
| 5761 | } |
| 5762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5763 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5764 | { |
| 5765 | Value *value = rhs.loadValue(); |
| 5766 | storeValue(value); |
| 5767 | |
| 5768 | return RValue<Float>(value); |
| 5769 | } |
| 5770 | |
| 5771 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5772 | { |
| 5773 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5774 | } |
| 5775 | |
| 5776 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5777 | { |
| 5778 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5779 | } |
| 5780 | |
| 5781 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5782 | { |
| 5783 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5784 | } |
| 5785 | |
| 5786 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5787 | { |
| 5788 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5789 | } |
| 5790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5791 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5792 | { |
| 5793 | return lhs = lhs + rhs; |
| 5794 | } |
| 5795 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5796 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5797 | { |
| 5798 | return lhs = lhs - rhs; |
| 5799 | } |
| 5800 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5801 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5802 | { |
| 5803 | return lhs = lhs * rhs; |
| 5804 | } |
| 5805 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5806 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5807 | { |
| 5808 | return lhs = lhs / rhs; |
| 5809 | } |
| 5810 | |
| 5811 | RValue<Float> operator+(RValue<Float> val) |
| 5812 | { |
| 5813 | return val; |
| 5814 | } |
| 5815 | |
| 5816 | RValue<Float> operator-(RValue<Float> val) |
| 5817 | { |
| 5818 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5819 | } |
| 5820 | |
| 5821 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5822 | { |
| 5823 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5824 | } |
| 5825 | |
| 5826 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5827 | { |
| 5828 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5829 | } |
| 5830 | |
| 5831 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5832 | { |
| 5833 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5834 | } |
| 5835 | |
| 5836 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5837 | { |
| 5838 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5839 | } |
| 5840 | |
| 5841 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5842 | { |
| 5843 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5844 | } |
| 5845 | |
| 5846 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5847 | { |
| 5848 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5849 | } |
| 5850 | |
| 5851 | RValue<Float> Abs(RValue<Float> x) |
| 5852 | { |
| 5853 | return IfThenElse(x > 0.0f, x, -x); |
| 5854 | } |
| 5855 | |
| 5856 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5857 | { |
| 5858 | return IfThenElse(x > y, x, y); |
| 5859 | } |
| 5860 | |
| 5861 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5862 | { |
| 5863 | return IfThenElse(x < y, x, y); |
| 5864 | } |
| 5865 | |
| 5866 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5867 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5868 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5872 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5873 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5874 | } |
| 5875 | |
| 5876 | RValue<Float> Sqrt(RValue<Float> x) |
| 5877 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5878 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5879 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5880 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5881 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5882 | sqrt->addArg(x.value); |
| 5883 | ::basicBlock->appendInst(sqrt); |
| 5884 | |
| 5885 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | RValue<Float> Round(RValue<Float> x) |
| 5889 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5890 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | RValue<Float> Trunc(RValue<Float> x) |
| 5894 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5895 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | RValue<Float> Frac(RValue<Float> x) |
| 5899 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5900 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | RValue<Float> Floor(RValue<Float> x) |
| 5904 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5905 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | RValue<Float> Ceil(RValue<Float> x) |
| 5909 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5910 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | Type *Float::getType() |
| 5914 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5915 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | Float2::Float2(RValue<Float4> cast) |
| 5919 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5920 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | Type *Float2::getType() |
| 5924 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5925 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | Float4::Float4(RValue<Byte4> cast) |
| 5929 | { |
| 5930 | xyzw.parent = this; |
| 5931 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5932 | Value *a = Int4(cast).loadValue(); |
| 5933 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5934 | |
| 5935 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | Float4::Float4(RValue<SByte4> cast) |
| 5939 | { |
| 5940 | xyzw.parent = this; |
| 5941 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5942 | Value *a = Int4(cast).loadValue(); |
| 5943 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5944 | |
| 5945 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | Float4::Float4(RValue<Short4> cast) |
| 5949 | { |
| 5950 | xyzw.parent = this; |
| 5951 | |
| 5952 | Int4 c(cast); |
| 5953 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5954 | } |
| 5955 | |
| 5956 | Float4::Float4(RValue<UShort4> cast) |
| 5957 | { |
| 5958 | xyzw.parent = this; |
| 5959 | |
| 5960 | Int4 c(cast); |
| 5961 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5962 | } |
| 5963 | |
| 5964 | Float4::Float4(RValue<Int4> cast) |
| 5965 | { |
| 5966 | xyzw.parent = this; |
| 5967 | |
| 5968 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5969 | |
| 5970 | storeValue(xyzw); |
| 5971 | } |
| 5972 | |
| 5973 | Float4::Float4(RValue<UInt4> cast) |
| 5974 | { |
| 5975 | xyzw.parent = this; |
| 5976 | |
| 5977 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); |
| 5978 | |
| 5979 | storeValue(xyzw); |
| 5980 | } |
| 5981 | |
| 5982 | Float4::Float4() |
| 5983 | { |
| 5984 | xyzw.parent = this; |
| 5985 | } |
| 5986 | |
| 5987 | Float4::Float4(float xyzw) |
| 5988 | { |
| 5989 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5990 | } |
| 5991 | |
| 5992 | Float4::Float4(float x, float yzw) |
| 5993 | { |
| 5994 | constant(x, yzw, yzw, yzw); |
| 5995 | } |
| 5996 | |
| 5997 | Float4::Float4(float x, float y, float zw) |
| 5998 | { |
| 5999 | constant(x, y, zw, zw); |
| 6000 | } |
| 6001 | |
| 6002 | Float4::Float4(float x, float y, float z, float w) |
| 6003 | { |
| 6004 | constant(x, y, z, w); |
| 6005 | } |
| 6006 | |
| 6007 | void Float4::constant(float x, float y, float z, float w) |
| 6008 | { |
| 6009 | xyzw.parent = this; |
| 6010 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6011 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6012 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | Float4::Float4(RValue<Float4> rhs) |
| 6016 | { |
| 6017 | xyzw.parent = this; |
| 6018 | |
| 6019 | storeValue(rhs.value); |
| 6020 | } |
| 6021 | |
| 6022 | Float4::Float4(const Float4 &rhs) |
| 6023 | { |
| 6024 | xyzw.parent = this; |
| 6025 | |
| 6026 | Value *value = rhs.loadValue(); |
| 6027 | storeValue(value); |
| 6028 | } |
| 6029 | |
| 6030 | Float4::Float4(const Reference<Float4> &rhs) |
| 6031 | { |
| 6032 | xyzw.parent = this; |
| 6033 | |
| 6034 | Value *value = rhs.loadValue(); |
| 6035 | storeValue(value); |
| 6036 | } |
| 6037 | |
| 6038 | Float4::Float4(RValue<Float> rhs) |
| 6039 | { |
| 6040 | xyzw.parent = this; |
| 6041 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6042 | Value *vector = loadValue(); |
| 6043 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 6044 | |
| 6045 | int swizzle[4] = {0, 0, 0, 0}; |
| 6046 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 6047 | |
| 6048 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | Float4::Float4(const Float &rhs) |
| 6052 | { |
| 6053 | xyzw.parent = this; |
| 6054 | |
| 6055 | *this = RValue<Float>(rhs.loadValue()); |
| 6056 | } |
| 6057 | |
| 6058 | Float4::Float4(const Reference<Float> &rhs) |
| 6059 | { |
| 6060 | xyzw.parent = this; |
| 6061 | |
| 6062 | *this = RValue<Float>(rhs.loadValue()); |
| 6063 | } |
| 6064 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6065 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6066 | { |
| 6067 | return *this = Float4(x, x, x, x); |
| 6068 | } |
| 6069 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6070 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6071 | { |
| 6072 | storeValue(rhs.value); |
| 6073 | |
| 6074 | return rhs; |
| 6075 | } |
| 6076 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6077 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6078 | { |
| 6079 | Value *value = rhs.loadValue(); |
| 6080 | storeValue(value); |
| 6081 | |
| 6082 | return RValue<Float4>(value); |
| 6083 | } |
| 6084 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6085 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6086 | { |
| 6087 | Value *value = rhs.loadValue(); |
| 6088 | storeValue(value); |
| 6089 | |
| 6090 | return RValue<Float4>(value); |
| 6091 | } |
| 6092 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6093 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6094 | { |
| 6095 | return *this = Float4(rhs); |
| 6096 | } |
| 6097 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6098 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6099 | { |
| 6100 | return *this = Float4(rhs); |
| 6101 | } |
| 6102 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6103 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6104 | { |
| 6105 | return *this = Float4(rhs); |
| 6106 | } |
| 6107 | |
| 6108 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6109 | { |
| 6110 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6111 | } |
| 6112 | |
| 6113 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6114 | { |
| 6115 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6116 | } |
| 6117 | |
| 6118 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6119 | { |
| 6120 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6121 | } |
| 6122 | |
| 6123 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6124 | { |
| 6125 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6126 | } |
| 6127 | |
| 6128 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6129 | { |
| 6130 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6131 | } |
| 6132 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6133 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6134 | { |
| 6135 | return lhs = lhs + rhs; |
| 6136 | } |
| 6137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6138 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6139 | { |
| 6140 | return lhs = lhs - rhs; |
| 6141 | } |
| 6142 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6143 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6144 | { |
| 6145 | return lhs = lhs * rhs; |
| 6146 | } |
| 6147 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6148 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6149 | { |
| 6150 | return lhs = lhs / rhs; |
| 6151 | } |
| 6152 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6153 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6154 | { |
| 6155 | return lhs = lhs % rhs; |
| 6156 | } |
| 6157 | |
| 6158 | RValue<Float4> operator+(RValue<Float4> val) |
| 6159 | { |
| 6160 | return val; |
| 6161 | } |
| 6162 | |
| 6163 | RValue<Float4> operator-(RValue<Float4> val) |
| 6164 | { |
| 6165 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6166 | } |
| 6167 | |
| 6168 | RValue<Float4> Abs(RValue<Float4> x) |
| 6169 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6170 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6171 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6172 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6173 | |
| 6174 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6178 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6179 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6180 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value); |
| 6181 | ::basicBlock->appendInst(cmp); |
| 6182 | |
| 6183 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6184 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6185 | ::basicBlock->appendInst(select); |
| 6186 | |
| 6187 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6191 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6192 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6193 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value); |
| 6194 | ::basicBlock->appendInst(cmp); |
| 6195 | |
| 6196 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6197 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6198 | ::basicBlock->appendInst(select); |
| 6199 | |
| 6200 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6204 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6205 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6209 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6210 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6214 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6215 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6216 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6217 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6218 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6219 | sqrt->addArg(x.value); |
| 6220 | ::basicBlock->appendInst(sqrt); |
| 6221 | |
| 6222 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6223 | } |
| 6224 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6225 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6226 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6227 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6231 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6232 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6236 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6237 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6241 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6242 | int shuffle[4] = |
| 6243 | { |
| 6244 | ((imm >> 0) & 0x03) + 0, |
| 6245 | ((imm >> 2) & 0x03) + 0, |
| 6246 | ((imm >> 4) & 0x03) + 4, |
| 6247 | ((imm >> 6) & 0x03) + 4, |
| 6248 | }; |
| 6249 | |
| 6250 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6254 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6255 | int shuffle[4] = {0, 4, 1, 5}; |
| 6256 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6260 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6261 | int shuffle[4] = {2, 6, 3, 7}; |
| 6262 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6266 | { |
| 6267 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6268 | Value *result = createMask4(vector, rhs.value, select); |
| 6269 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6270 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6271 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6272 | } |
| 6273 | |
| 6274 | RValue<Int> SignMask(RValue<Float4> x) |
| 6275 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6276 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6277 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6278 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6279 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6280 | movmsk->addArg(x.value); |
| 6281 | ::basicBlock->appendInst(movmsk); |
| 6282 | |
| 6283 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6287 | { |
| 6288 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6289 | } |
| 6290 | |
| 6291 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6292 | { |
| 6293 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6294 | } |
| 6295 | |
| 6296 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6297 | { |
| 6298 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6299 | } |
| 6300 | |
| 6301 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6302 | { |
| 6303 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6304 | } |
| 6305 | |
| 6306 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6307 | { |
| 6308 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6309 | } |
| 6310 | |
| 6311 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6312 | { |
| 6313 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6314 | } |
| 6315 | |
| 6316 | RValue<Float4> Round(RValue<Float4> x) |
| 6317 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6318 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6319 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6320 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6321 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6322 | round->addArg(x.value); |
| 6323 | round->addArg(::context->getConstantInt32(0)); |
| 6324 | ::basicBlock->appendInst(round); |
| 6325 | |
| 6326 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6330 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6331 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6332 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6333 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6334 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6335 | round->addArg(x.value); |
| 6336 | round->addArg(::context->getConstantInt32(3)); |
| 6337 | ::basicBlock->appendInst(round); |
| 6338 | |
| 6339 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | RValue<Float4> Frac(RValue<Float4> x) |
| 6343 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6344 | return x - Floor(x); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | RValue<Float4> Floor(RValue<Float4> x) |
| 6348 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6349 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6350 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6351 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6352 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6353 | round->addArg(x.value); |
| 6354 | round->addArg(::context->getConstantInt32(1)); |
| 6355 | ::basicBlock->appendInst(round); |
| 6356 | |
| 6357 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6358 | } |
| 6359 | |
| 6360 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6361 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6362 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6363 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6364 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6365 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6366 | round->addArg(x.value); |
| 6367 | round->addArg(::context->getConstantInt32(2)); |
| 6368 | ::basicBlock->appendInst(round); |
| 6369 | |
| 6370 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | Type *Float4::getType() |
| 6374 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6375 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6379 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6380 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6384 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6385 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6389 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6390 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6391 | } |
| 6392 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6393 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6394 | { |
| 6395 | return lhs = lhs + offset; |
| 6396 | } |
| 6397 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6398 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6399 | { |
| 6400 | return lhs = lhs + offset; |
| 6401 | } |
| 6402 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6403 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6404 | { |
| 6405 | return lhs = lhs + offset; |
| 6406 | } |
| 6407 | |
| 6408 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6409 | { |
| 6410 | return lhs + -offset; |
| 6411 | } |
| 6412 | |
| 6413 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6414 | { |
| 6415 | return lhs + -offset; |
| 6416 | } |
| 6417 | |
| 6418 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6419 | { |
| 6420 | return lhs + -offset; |
| 6421 | } |
| 6422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6423 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6424 | { |
| 6425 | return lhs = lhs - offset; |
| 6426 | } |
| 6427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6428 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6429 | { |
| 6430 | return lhs = lhs - offset; |
| 6431 | } |
| 6432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6433 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6434 | { |
| 6435 | return lhs = lhs - offset; |
| 6436 | } |
| 6437 | |
| 6438 | void Return() |
| 6439 | { |
| 6440 | Nucleus::createRetVoid(); |
| 6441 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6442 | Nucleus::createUnreachable(); |
| 6443 | } |
| 6444 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6445 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6446 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6447 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6448 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6449 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6450 | } |
| 6451 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6452 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
| 6453 | { |
| 6454 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6455 | Nucleus::setInsertBlock(bodyBB); |
| 6456 | |
| 6457 | return true; |
| 6458 | } |
| 6459 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6460 | RValue<Long> Ticks() |
| 6461 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6462 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6463 | } |
| 6464 | } |