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 | |
| 20 | #include "src/IceTypes.h" |
| 21 | #include "src/IceCfg.h" |
| 22 | #include "src/IceELFStreamer.h" |
| 23 | #include "src/IceGlobalContext.h" |
| 24 | #include "src/IceCfgNode.h" |
| 25 | #include "src/IceELFObjectWriter.h" |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 26 | #include "src/IceGlobalInits.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 27 | |
| 28 | #include "llvm/Support/FileSystem.h" |
| 29 | #include "llvm/Support/raw_os_ostream.h" |
| 30 | |
| 31 | #define WIN32_LEAN_AND_MEAN |
| 32 | #define NOMINMAX |
| 33 | #include <Windows.h> |
| 34 | |
| 35 | #include <mutex> |
| 36 | #include <limits> |
| 37 | #include <iostream> |
| 38 | #include <cassert> |
| 39 | |
| 40 | namespace |
| 41 | { |
| 42 | Ice::GlobalContext *context = nullptr; |
| 43 | Ice::Cfg *function = nullptr; |
| 44 | Ice::CfgNode *basicBlock = nullptr; |
| 45 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
| 46 | sw::Routine *routine = nullptr; |
| 47 | |
| 48 | std::mutex codegenMutex; |
| 49 | |
| 50 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 51 | Ice::Fdstream *out = nullptr; |
| 52 | } |
| 53 | |
| 54 | namespace sw |
| 55 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 56 | enum EmulatedType |
| 57 | { |
| 58 | EmulatedShift = 16, |
| 59 | EmulatedV2 = 2 << EmulatedShift, |
| 60 | EmulatedV4 = 4 << EmulatedShift, |
| 61 | EmulatedV8 = 8 << EmulatedShift, |
| 62 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 63 | |
| 64 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 65 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 66 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 67 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 68 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 69 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 72 | class Value : public Ice::Variable {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 73 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 74 | class BasicBlock : public Ice::CfgNode {}; |
| 75 | |
| 76 | Ice::Type T(Type *t) |
| 77 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 78 | static_assert(Ice::IceType_NUM < EmulatedBits, "Ice::Type overlaps with our emulated types!"); |
| 79 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | Type *T(Ice::Type t) |
| 83 | { |
| 84 | return reinterpret_cast<Type*>(t); |
| 85 | } |
| 86 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 87 | Type *T(EmulatedType t) |
| 88 | { |
| 89 | return reinterpret_cast<Type*>(t); |
| 90 | } |
| 91 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 92 | Value *V(Ice::Variable *v) |
| 93 | { |
| 94 | return reinterpret_cast<Value*>(v); |
| 95 | } |
| 96 | |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 97 | Value *C(Ice::Constant *c) |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 98 | { |
| 99 | return reinterpret_cast<Value*>(c); |
| 100 | } |
| 101 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 102 | BasicBlock *B(Ice::CfgNode *b) |
| 103 | { |
| 104 | return reinterpret_cast<BasicBlock*>(b); |
| 105 | } |
| 106 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 107 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 108 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 109 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 110 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 111 | |
| 112 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 113 | { |
| 114 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 115 | } |
| 116 | |
| 117 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 118 | { |
| 119 | return §ionHeader(elfHeader)[index]; |
| 120 | } |
| 121 | |
| 122 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 123 | { |
| 124 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
| 125 | |
| 126 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 127 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 128 | uint32_t index = relocation.getSymbol(); |
| 129 | int table = relocationTable.sh_link; |
| 130 | void *symbolValue = nullptr; |
| 131 | |
| 132 | if(index != SHN_UNDEF) |
| 133 | { |
| 134 | if(table == SHN_UNDEF) return nullptr; |
| 135 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
| 136 | |
| 137 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 138 | if(index >= symtab_entries) |
| 139 | { |
| 140 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 141 | return nullptr; |
| 142 | } |
| 143 | |
| 144 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 145 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 146 | uint16_t section = symbol.st_shndx; |
| 147 | |
| 148 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 149 | { |
| 150 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 151 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | return nullptr; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | switch(relocation.getType()) |
| 160 | { |
| 161 | case R_386_NONE: |
| 162 | // No relocation |
| 163 | break; |
| 164 | case R_386_32: |
| 165 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 166 | break; |
| 167 | // case R_386_PC32: |
| 168 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 169 | // break; |
| 170 | default: |
| 171 | assert(false && "Unsupported relocation type"); |
| 172 | return nullptr; |
| 173 | } |
| 174 | |
| 175 | return symbolValue; |
| 176 | } |
| 177 | |
| 178 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 179 | { |
| 180 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
| 181 | |
| 182 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 183 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 184 | uint32_t index = relocation.getSymbol(); |
| 185 | int table = relocationTable.sh_link; |
| 186 | void *symbolValue = nullptr; |
| 187 | |
| 188 | if(index != SHN_UNDEF) |
| 189 | { |
| 190 | if(table == SHN_UNDEF) return nullptr; |
| 191 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
| 192 | |
| 193 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 194 | if(index >= symtab_entries) |
| 195 | { |
| 196 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 197 | return nullptr; |
| 198 | } |
| 199 | |
| 200 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 201 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 202 | uint16_t section = symbol.st_shndx; |
| 203 | |
| 204 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 205 | { |
| 206 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 207 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | return nullptr; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | switch(relocation.getType()) |
| 216 | { |
| 217 | case R_X86_64_NONE: |
| 218 | // No relocation |
| 219 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 220 | case R_X86_64_64: |
| 221 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 222 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 223 | case R_X86_64_PC32: |
| 224 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 225 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 226 | case R_X86_64_32S: |
| 227 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 228 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 229 | default: |
| 230 | assert(false && "Unsupported relocation type"); |
| 231 | return nullptr; |
| 232 | } |
| 233 | |
| 234 | return symbolValue; |
| 235 | } |
| 236 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 237 | void *loadImage(uint8_t *const elfImage) |
| 238 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 239 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 240 | |
| 241 | if(!elfHeader->checkMagic()) |
| 242 | { |
| 243 | return nullptr; |
| 244 | } |
| 245 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 246 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 247 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 248 | assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386); |
| 249 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 250 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 251 | void *entry = nullptr; |
| 252 | |
| 253 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 254 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 255 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 256 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 257 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 258 | { |
| 259 | entry = elfImage + sectionHeader[i].sh_offset; |
| 260 | } |
| 261 | } |
| 262 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 263 | { |
| 264 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 265 | |
| 266 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 267 | { |
| 268 | const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 269 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 270 | } |
| 271 | } |
| 272 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 273 | { |
| 274 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 275 | |
| 276 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 277 | { |
| 278 | const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 279 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 280 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | return entry; |
| 285 | } |
| 286 | |
| 287 | template<typename T> |
| 288 | struct ExecutableAllocator |
| 289 | { |
| 290 | ExecutableAllocator() {}; |
| 291 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 292 | |
| 293 | using value_type = T; |
| 294 | using size_type = std::size_t; |
| 295 | |
| 296 | T *allocate(size_type n) |
| 297 | { |
| 298 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 299 | } |
| 300 | |
| 301 | void deallocate(T *p, size_type n) |
| 302 | { |
| 303 | VirtualFree(p, 0, MEM_RELEASE); |
| 304 | } |
| 305 | }; |
| 306 | |
| 307 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 308 | { |
| 309 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 310 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 311 | |
| 312 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 313 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 314 | { |
| 315 | position = 0; |
| 316 | buffer.reserve(0x1000); |
| 317 | } |
| 318 | |
| 319 | virtual ~ELFMemoryStreamer() |
| 320 | { |
| 321 | if(buffer.size() != 0) |
| 322 | { |
| 323 | DWORD exeProtection; |
| 324 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | void write8(uint8_t Value) override |
| 329 | { |
| 330 | if(position == (uint64_t)buffer.size()) |
| 331 | { |
| 332 | buffer.push_back(Value); |
| 333 | position++; |
| 334 | } |
| 335 | else if(position < (uint64_t)buffer.size()) |
| 336 | { |
| 337 | buffer[position] = Value; |
| 338 | position++; |
| 339 | } |
| 340 | else assert(false && "UNIMPLEMENTED"); |
| 341 | } |
| 342 | |
| 343 | void writeBytes(llvm::StringRef Bytes) override |
| 344 | { |
| 345 | std::size_t oldSize = buffer.size(); |
| 346 | buffer.resize(oldSize + Bytes.size()); |
| 347 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 348 | position += Bytes.size(); |
| 349 | } |
| 350 | |
| 351 | uint64_t tell() const override { return position; } |
| 352 | |
| 353 | void seek(uint64_t Off) override { position = Off; } |
| 354 | |
| 355 | const void *getEntry() override |
| 356 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 357 | if(!entry) |
| 358 | { |
| 359 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection); |
| 360 | 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] | 361 | |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 362 | entry = loadImage(&buffer[0]); |
| 363 | } |
| 364 | |
| 365 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 369 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 370 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 371 | std::size_t position; |
| 372 | DWORD oldProtection; |
| 373 | }; |
| 374 | |
| 375 | Nucleus::Nucleus() |
| 376 | { |
| 377 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 378 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 379 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 380 | Ice::ClFlags::getParsedClFlags(Flags); |
| 381 | |
| 382 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 383 | Flags.setOutFileType(Ice::FT_Elf); |
| 384 | Flags.setOptLevel(Ice::Opt_2); |
| 385 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 386 | Flags.setTargetInstructionSet(Ice::X86InstructionSet_SSE4_1); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 387 | Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 388 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 389 | static llvm::raw_os_ostream cout(std::cout); |
| 390 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 391 | |
| 392 | if(false) // Write out to a file |
| 393 | { |
| 394 | std::error_code errorCode; |
| 395 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 396 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 397 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 398 | } |
| 399 | else |
| 400 | { |
| 401 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 402 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 403 | ::routine = elfMemory; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | Nucleus::~Nucleus() |
| 408 | { |
| 409 | delete ::allocator; |
| 410 | delete ::function; |
| 411 | delete ::context; |
| 412 | |
| 413 | delete ::elfFile; |
| 414 | delete ::out; |
| 415 | |
| 416 | ::codegenMutex.unlock(); |
| 417 | } |
| 418 | |
| 419 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 420 | { |
| 421 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 422 | { |
| 423 | createRetVoid(); |
| 424 | } |
| 425 | |
| 426 | std::wstring wideName(name); |
| 427 | std::string asciiName(wideName.begin(), wideName.end()); |
| 428 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 429 | |
| 430 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 431 | assert(!::function->hasError()); |
| 432 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 433 | auto *globals = ::function->getGlobalInits().release(); |
| 434 | |
| 435 | if(globals && !globals->empty()) |
| 436 | { |
| 437 | ::context->getGlobals()->merge(globals); |
| 438 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 439 | |
| 440 | ::context->emitFileHeader(); |
| 441 | ::function->emitIAS(); |
| 442 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 443 | auto objectWriter = ::context->getObjectWriter(); |
| 444 | assembler->alignFunction(); |
| 445 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 446 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 447 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 448 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 449 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 450 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 451 | |
| 452 | return ::routine; |
| 453 | } |
| 454 | |
| 455 | void Nucleus::optimize() |
| 456 | { |
| 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 | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 636 | static Value *createAssign(Ice::Constant *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 | |
| 642 | return V(value); |
| 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())) : |
| 655 | C(::context->getConstantFloat(-0.0f)); |
| 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 | { |
| 664 | return createXor(v, C(::context->getConstantInt(v->getType(), -1))); |
| 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); |
| 688 | load->addArg(::context->getConstantInt32(4)); |
| 689 | load->addArg(ptr); |
| 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); |
| 701 | load->addArg(::context->getConstantInt32(8)); |
| 702 | load->addArg(ptr); |
| 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); |
| 732 | store->addArg(::context->getConstantInt32(4)); |
| 733 | store->addArg(value); |
| 734 | store->addArg(ptr); |
| 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); |
| 746 | store->addArg(::context->getConstantInt32(8)); |
| 747 | store->addArg(value); |
| 748 | store->addArg(ptr); |
| 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 | |
| 770 | if(!Ice::isByteSizedType(T(type))) |
| 771 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 772 | index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type)))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | if(sizeof(void*) == 8) |
| 776 | { |
| 777 | index = createSExt(index, T(Ice::IceType_i64)); |
| 778 | } |
| 779 | |
| 780 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 784 | { |
| 785 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 786 | } |
| 787 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 788 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 789 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 790 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 791 | { |
| 792 | return v; |
| 793 | } |
| 794 | |
| 795 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 796 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 797 | ::basicBlock->appendInst(cast); |
| 798 | |
| 799 | return V(result); |
| 800 | } |
| 801 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 802 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 803 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 804 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 808 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 809 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 813 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 814 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 818 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 819 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | Value *Nucleus::createUIToFP(Value *v, Type *destType) |
| 823 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 824 | return createCast(Ice::InstCast::Uitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 828 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 829 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 833 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 834 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 838 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 839 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 843 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 844 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 845 | } |
| 846 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 847 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 848 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 849 | assert(lhs->getType() == rhs->getType()); |
| 850 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 851 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 852 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 853 | ::basicBlock->appendInst(cmp); |
| 854 | |
| 855 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 856 | } |
| 857 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 858 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 859 | { |
| 860 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 861 | } |
| 862 | |
| 863 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 864 | { |
| 865 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 866 | } |
| 867 | |
| 868 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 869 | { |
| 870 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 871 | } |
| 872 | |
| 873 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 874 | { |
| 875 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 876 | } |
| 877 | |
| 878 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 879 | { |
| 880 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 881 | } |
| 882 | |
| 883 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 884 | { |
| 885 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 886 | } |
| 887 | |
| 888 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 889 | { |
| 890 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 891 | } |
| 892 | |
| 893 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 894 | { |
| 895 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 896 | } |
| 897 | |
| 898 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 899 | { |
| 900 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 901 | } |
| 902 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 903 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 904 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 905 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 906 | } |
| 907 | |
| 908 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 909 | { |
| 910 | assert(lhs->getType() == rhs->getType()); |
| 911 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 912 | |
| 913 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 914 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 915 | ::basicBlock->appendInst(cmp); |
| 916 | |
| 917 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 921 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 922 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 926 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 927 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 931 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 932 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 936 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 937 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 941 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 942 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 946 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 947 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 951 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 952 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 956 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 957 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 961 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 962 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 966 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 967 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 971 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 972 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 976 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 977 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 981 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 982 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 986 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 987 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 988 | } |
| 989 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 990 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 991 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 992 | auto result = ::function->makeVariable(T(type)); |
| 993 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 994 | ::basicBlock->appendInst(extract); |
| 995 | |
| 996 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1000 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1001 | auto result = ::function->makeVariable(vector->getType()); |
| 1002 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1003 | ::basicBlock->appendInst(insert); |
| 1004 | |
| 1005 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1006 | } |
| 1007 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1008 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1009 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1010 | assert(V1->getType() == V2->getType()); |
| 1011 | |
| 1012 | int size = Ice::typeNumElements(V1->getType()); |
| 1013 | auto result = ::function->makeVariable(V1->getType()); |
| 1014 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1015 | |
| 1016 | for(int i = 0; i < size; i++) |
| 1017 | { |
| 1018 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1019 | } |
| 1020 | |
| 1021 | ::basicBlock->appendInst(shuffle); |
| 1022 | |
| 1023 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1027 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1028 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1029 | |
| 1030 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1031 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1032 | ::basicBlock->appendInst(select); |
| 1033 | |
| 1034 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1037 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1038 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1039 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1040 | ::basicBlock->appendInst(switchInst); |
| 1041 | |
| 1042 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1045 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1046 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1047 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | void Nucleus::createUnreachable() |
| 1051 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1052 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1053 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1056 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1057 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1058 | int swizzle[4] = |
| 1059 | { |
| 1060 | (select >> 0) & 0x03, |
| 1061 | (select >> 2) & 0x03, |
| 1062 | (select >> 4) & 0x03, |
| 1063 | (select >> 6) & 0x03, |
| 1064 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1065 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1066 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1067 | } |
| 1068 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1069 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1070 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1071 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1072 | |
| 1073 | mask[(select >> 0) & 0x03] = -1; |
| 1074 | mask[(select >> 2) & 0x03] = -1; |
| 1075 | mask[(select >> 4) & 0x03] = -1; |
| 1076 | mask[(select >> 6) & 0x03] = -1; |
| 1077 | |
| 1078 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1079 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1080 | |
| 1081 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1084 | Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1085 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1086 | if(sizeof(void*) == 8) |
| 1087 | { |
| 1088 | return createAssign(::context->getConstantInt64(reinterpret_cast<intptr_t>(address))); |
| 1089 | } |
| 1090 | else |
| 1091 | { |
| 1092 | return createAssign(::context->getConstantInt32(reinterpret_cast<intptr_t>(address))); |
| 1093 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1094 | } |
| 1095 | |
| 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 | { |
| 1117 | return createAssign(::context->getConstantZero(T(Ty))); |
| 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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1123 | return createAssign(::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 | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1128 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1133 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1138 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1143 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1148 | return createAssign(::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 | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1153 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1158 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1163 | return createAssign(::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 | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1168 | if(true) |
| 1169 | { |
| 1170 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
| 1171 | } |
| 1172 | else |
| 1173 | { |
| 1174 | return createConstantPointer(nullptr, Ty); |
| 1175 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1178 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1179 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1180 | const int vectorSize = 16; |
| 1181 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1182 | const int alignment = vectorSize; |
| 1183 | auto globalPool = ::function->getGlobalPool(); |
| 1184 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1185 | const int64_t *i = constants; |
| 1186 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1187 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1188 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1189 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1190 | { |
| 1191 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1192 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1193 | { |
| 1194 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1195 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1196 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1197 | } |
| 1198 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1199 | case Ice::IceType_v4f32: |
| 1200 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1201 | 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] | 1202 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1203 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1204 | } |
| 1205 | break; |
| 1206 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1207 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1208 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1209 | 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] | 1210 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1211 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1212 | } |
| 1213 | break; |
| 1214 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1215 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1216 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1217 | 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] | 1218 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1219 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1220 | } |
| 1221 | break; |
| 1222 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1223 | { |
| 1224 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1225 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1226 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1227 | } |
| 1228 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1229 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1230 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1231 | 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] | 1232 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1233 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1234 | } |
| 1235 | break; |
| 1236 | case Type_v4i16: |
| 1237 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1238 | 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] | 1239 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1240 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1241 | } |
| 1242 | break; |
| 1243 | case Type_v8i8: |
| 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[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] | 1246 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1247 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1248 | } |
| 1249 | break; |
| 1250 | case Type_v4i8: |
| 1251 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1252 | 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] | 1253 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1254 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1255 | } |
| 1256 | break; |
| 1257 | default: |
| 1258 | assert(false && "Unknown constant vector type" && type); |
| 1259 | } |
| 1260 | |
| 1261 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1262 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1263 | variableDeclaration->setName(name); |
| 1264 | variableDeclaration->setAlignment(alignment); |
| 1265 | variableDeclaration->setIsConstant(true); |
| 1266 | variableDeclaration->addInitializer(dataInitializer); |
| 1267 | |
| 1268 | ::function->addGlobal(variableDeclaration); |
| 1269 | |
| 1270 | constexpr int32_t offset = 0; |
| 1271 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1272 | |
| 1273 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1274 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1275 | ::basicBlock->appendInst(load); |
| 1276 | |
| 1277 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1281 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1282 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | Type *Void::getType() |
| 1286 | { |
| 1287 | return T(Ice::IceType_void); |
| 1288 | } |
| 1289 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1290 | Bool::Bool(Argument<Bool> argument) |
| 1291 | { |
| 1292 | storeValue(argument.value); |
| 1293 | } |
| 1294 | |
| 1295 | Bool::Bool() |
| 1296 | { |
| 1297 | } |
| 1298 | |
| 1299 | Bool::Bool(bool x) |
| 1300 | { |
| 1301 | storeValue(Nucleus::createConstantBool(x)); |
| 1302 | } |
| 1303 | |
| 1304 | Bool::Bool(RValue<Bool> rhs) |
| 1305 | { |
| 1306 | storeValue(rhs.value); |
| 1307 | } |
| 1308 | |
| 1309 | Bool::Bool(const Bool &rhs) |
| 1310 | { |
| 1311 | Value *value = rhs.loadValue(); |
| 1312 | storeValue(value); |
| 1313 | } |
| 1314 | |
| 1315 | Bool::Bool(const Reference<Bool> &rhs) |
| 1316 | { |
| 1317 | Value *value = rhs.loadValue(); |
| 1318 | storeValue(value); |
| 1319 | } |
| 1320 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1321 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1322 | { |
| 1323 | storeValue(rhs.value); |
| 1324 | |
| 1325 | return rhs; |
| 1326 | } |
| 1327 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1328 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1329 | { |
| 1330 | Value *value = rhs.loadValue(); |
| 1331 | storeValue(value); |
| 1332 | |
| 1333 | return RValue<Bool>(value); |
| 1334 | } |
| 1335 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1336 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1337 | { |
| 1338 | Value *value = rhs.loadValue(); |
| 1339 | storeValue(value); |
| 1340 | |
| 1341 | return RValue<Bool>(value); |
| 1342 | } |
| 1343 | |
| 1344 | RValue<Bool> operator!(RValue<Bool> val) |
| 1345 | { |
| 1346 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1347 | } |
| 1348 | |
| 1349 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1350 | { |
| 1351 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1352 | } |
| 1353 | |
| 1354 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1355 | { |
| 1356 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1357 | } |
| 1358 | |
| 1359 | Type *Bool::getType() |
| 1360 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1361 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | Byte::Byte(Argument<Byte> argument) |
| 1365 | { |
| 1366 | storeValue(argument.value); |
| 1367 | } |
| 1368 | |
| 1369 | Byte::Byte(RValue<Int> cast) |
| 1370 | { |
| 1371 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1372 | |
| 1373 | storeValue(integer); |
| 1374 | } |
| 1375 | |
| 1376 | Byte::Byte(RValue<UInt> cast) |
| 1377 | { |
| 1378 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1379 | |
| 1380 | storeValue(integer); |
| 1381 | } |
| 1382 | |
| 1383 | Byte::Byte(RValue<UShort> cast) |
| 1384 | { |
| 1385 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1386 | |
| 1387 | storeValue(integer); |
| 1388 | } |
| 1389 | |
| 1390 | Byte::Byte() |
| 1391 | { |
| 1392 | } |
| 1393 | |
| 1394 | Byte::Byte(int x) |
| 1395 | { |
| 1396 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1397 | } |
| 1398 | |
| 1399 | Byte::Byte(unsigned char x) |
| 1400 | { |
| 1401 | storeValue(Nucleus::createConstantByte(x)); |
| 1402 | } |
| 1403 | |
| 1404 | Byte::Byte(RValue<Byte> rhs) |
| 1405 | { |
| 1406 | storeValue(rhs.value); |
| 1407 | } |
| 1408 | |
| 1409 | Byte::Byte(const Byte &rhs) |
| 1410 | { |
| 1411 | Value *value = rhs.loadValue(); |
| 1412 | storeValue(value); |
| 1413 | } |
| 1414 | |
| 1415 | Byte::Byte(const Reference<Byte> &rhs) |
| 1416 | { |
| 1417 | Value *value = rhs.loadValue(); |
| 1418 | storeValue(value); |
| 1419 | } |
| 1420 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1421 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1422 | { |
| 1423 | storeValue(rhs.value); |
| 1424 | |
| 1425 | return rhs; |
| 1426 | } |
| 1427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1428 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1429 | { |
| 1430 | Value *value = rhs.loadValue(); |
| 1431 | storeValue(value); |
| 1432 | |
| 1433 | return RValue<Byte>(value); |
| 1434 | } |
| 1435 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1436 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1437 | { |
| 1438 | Value *value = rhs.loadValue(); |
| 1439 | storeValue(value); |
| 1440 | |
| 1441 | return RValue<Byte>(value); |
| 1442 | } |
| 1443 | |
| 1444 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1445 | { |
| 1446 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1447 | } |
| 1448 | |
| 1449 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1450 | { |
| 1451 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1452 | } |
| 1453 | |
| 1454 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1455 | { |
| 1456 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1457 | } |
| 1458 | |
| 1459 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1460 | { |
| 1461 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1462 | } |
| 1463 | |
| 1464 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1465 | { |
| 1466 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1467 | } |
| 1468 | |
| 1469 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1470 | { |
| 1471 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1472 | } |
| 1473 | |
| 1474 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1475 | { |
| 1476 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1477 | } |
| 1478 | |
| 1479 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1480 | { |
| 1481 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1482 | } |
| 1483 | |
| 1484 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1485 | { |
| 1486 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1487 | } |
| 1488 | |
| 1489 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1490 | { |
| 1491 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1492 | } |
| 1493 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1494 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1495 | { |
| 1496 | return lhs = lhs + rhs; |
| 1497 | } |
| 1498 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1499 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1500 | { |
| 1501 | return lhs = lhs - rhs; |
| 1502 | } |
| 1503 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1504 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1505 | { |
| 1506 | return lhs = lhs * rhs; |
| 1507 | } |
| 1508 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1509 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1510 | { |
| 1511 | return lhs = lhs / rhs; |
| 1512 | } |
| 1513 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1514 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1515 | { |
| 1516 | return lhs = lhs % rhs; |
| 1517 | } |
| 1518 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1519 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1520 | { |
| 1521 | return lhs = lhs & rhs; |
| 1522 | } |
| 1523 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1524 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1525 | { |
| 1526 | return lhs = lhs | rhs; |
| 1527 | } |
| 1528 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1529 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1530 | { |
| 1531 | return lhs = lhs ^ rhs; |
| 1532 | } |
| 1533 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1534 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1535 | { |
| 1536 | return lhs = lhs << rhs; |
| 1537 | } |
| 1538 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1539 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1540 | { |
| 1541 | return lhs = lhs >> rhs; |
| 1542 | } |
| 1543 | |
| 1544 | RValue<Byte> operator+(RValue<Byte> val) |
| 1545 | { |
| 1546 | return val; |
| 1547 | } |
| 1548 | |
| 1549 | RValue<Byte> operator-(RValue<Byte> val) |
| 1550 | { |
| 1551 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1552 | } |
| 1553 | |
| 1554 | RValue<Byte> operator~(RValue<Byte> val) |
| 1555 | { |
| 1556 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1557 | } |
| 1558 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1559 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1560 | { |
| 1561 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1562 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1563 | return res; |
| 1564 | } |
| 1565 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1566 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1567 | { |
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 val; |
| 1570 | } |
| 1571 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1572 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1573 | { |
| 1574 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1575 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1576 | return res; |
| 1577 | } |
| 1578 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1579 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1580 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1581 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1582 | return val; |
| 1583 | } |
| 1584 | |
| 1585 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1586 | { |
| 1587 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1588 | } |
| 1589 | |
| 1590 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1591 | { |
| 1592 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1593 | } |
| 1594 | |
| 1595 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1596 | { |
| 1597 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1598 | } |
| 1599 | |
| 1600 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1601 | { |
| 1602 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1603 | } |
| 1604 | |
| 1605 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1606 | { |
| 1607 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1608 | } |
| 1609 | |
| 1610 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1611 | { |
| 1612 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1613 | } |
| 1614 | |
| 1615 | Type *Byte::getType() |
| 1616 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1617 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | SByte::SByte(Argument<SByte> argument) |
| 1621 | { |
| 1622 | storeValue(argument.value); |
| 1623 | } |
| 1624 | |
| 1625 | SByte::SByte(RValue<Int> cast) |
| 1626 | { |
| 1627 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1628 | |
| 1629 | storeValue(integer); |
| 1630 | } |
| 1631 | |
| 1632 | SByte::SByte(RValue<Short> cast) |
| 1633 | { |
| 1634 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1635 | |
| 1636 | storeValue(integer); |
| 1637 | } |
| 1638 | |
| 1639 | SByte::SByte() |
| 1640 | { |
| 1641 | } |
| 1642 | |
| 1643 | SByte::SByte(signed char x) |
| 1644 | { |
| 1645 | storeValue(Nucleus::createConstantByte(x)); |
| 1646 | } |
| 1647 | |
| 1648 | SByte::SByte(RValue<SByte> rhs) |
| 1649 | { |
| 1650 | storeValue(rhs.value); |
| 1651 | } |
| 1652 | |
| 1653 | SByte::SByte(const SByte &rhs) |
| 1654 | { |
| 1655 | Value *value = rhs.loadValue(); |
| 1656 | storeValue(value); |
| 1657 | } |
| 1658 | |
| 1659 | SByte::SByte(const Reference<SByte> &rhs) |
| 1660 | { |
| 1661 | Value *value = rhs.loadValue(); |
| 1662 | storeValue(value); |
| 1663 | } |
| 1664 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1665 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1666 | { |
| 1667 | storeValue(rhs.value); |
| 1668 | |
| 1669 | return rhs; |
| 1670 | } |
| 1671 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1672 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1673 | { |
| 1674 | Value *value = rhs.loadValue(); |
| 1675 | storeValue(value); |
| 1676 | |
| 1677 | return RValue<SByte>(value); |
| 1678 | } |
| 1679 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1680 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1681 | { |
| 1682 | Value *value = rhs.loadValue(); |
| 1683 | storeValue(value); |
| 1684 | |
| 1685 | return RValue<SByte>(value); |
| 1686 | } |
| 1687 | |
| 1688 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1689 | { |
| 1690 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1691 | } |
| 1692 | |
| 1693 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1694 | { |
| 1695 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1696 | } |
| 1697 | |
| 1698 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1699 | { |
| 1700 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1701 | } |
| 1702 | |
| 1703 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1704 | { |
| 1705 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1706 | } |
| 1707 | |
| 1708 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1709 | { |
| 1710 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1711 | } |
| 1712 | |
| 1713 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1714 | { |
| 1715 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1716 | } |
| 1717 | |
| 1718 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1719 | { |
| 1720 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1721 | } |
| 1722 | |
| 1723 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1724 | { |
| 1725 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1726 | } |
| 1727 | |
| 1728 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1729 | { |
| 1730 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1731 | } |
| 1732 | |
| 1733 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1734 | { |
| 1735 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1736 | } |
| 1737 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1738 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1739 | { |
| 1740 | return lhs = lhs + rhs; |
| 1741 | } |
| 1742 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1743 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1744 | { |
| 1745 | return lhs = lhs - rhs; |
| 1746 | } |
| 1747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1748 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1749 | { |
| 1750 | return lhs = lhs * rhs; |
| 1751 | } |
| 1752 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1753 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1754 | { |
| 1755 | return lhs = lhs / rhs; |
| 1756 | } |
| 1757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1758 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1759 | { |
| 1760 | return lhs = lhs % rhs; |
| 1761 | } |
| 1762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1763 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1764 | { |
| 1765 | return lhs = lhs & rhs; |
| 1766 | } |
| 1767 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1768 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1769 | { |
| 1770 | return lhs = lhs | rhs; |
| 1771 | } |
| 1772 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1773 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1774 | { |
| 1775 | return lhs = lhs ^ rhs; |
| 1776 | } |
| 1777 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1778 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1779 | { |
| 1780 | return lhs = lhs << rhs; |
| 1781 | } |
| 1782 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1783 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1784 | { |
| 1785 | return lhs = lhs >> rhs; |
| 1786 | } |
| 1787 | |
| 1788 | RValue<SByte> operator+(RValue<SByte> val) |
| 1789 | { |
| 1790 | return val; |
| 1791 | } |
| 1792 | |
| 1793 | RValue<SByte> operator-(RValue<SByte> val) |
| 1794 | { |
| 1795 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1796 | } |
| 1797 | |
| 1798 | RValue<SByte> operator~(RValue<SByte> val) |
| 1799 | { |
| 1800 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1801 | } |
| 1802 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1803 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1804 | { |
| 1805 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1806 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1807 | return res; |
| 1808 | } |
| 1809 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1810 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1811 | { |
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 val; |
| 1814 | } |
| 1815 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1816 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1817 | { |
| 1818 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1819 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1820 | return res; |
| 1821 | } |
| 1822 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1823 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1824 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1825 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1826 | return val; |
| 1827 | } |
| 1828 | |
| 1829 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1830 | { |
| 1831 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1832 | } |
| 1833 | |
| 1834 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1835 | { |
| 1836 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1837 | } |
| 1838 | |
| 1839 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1840 | { |
| 1841 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1842 | } |
| 1843 | |
| 1844 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1845 | { |
| 1846 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1847 | } |
| 1848 | |
| 1849 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1850 | { |
| 1851 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1852 | } |
| 1853 | |
| 1854 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1855 | { |
| 1856 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1857 | } |
| 1858 | |
| 1859 | Type *SByte::getType() |
| 1860 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1861 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | Short::Short(Argument<Short> argument) |
| 1865 | { |
| 1866 | storeValue(argument.value); |
| 1867 | } |
| 1868 | |
| 1869 | Short::Short(RValue<Int> cast) |
| 1870 | { |
| 1871 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1872 | |
| 1873 | storeValue(integer); |
| 1874 | } |
| 1875 | |
| 1876 | Short::Short() |
| 1877 | { |
| 1878 | } |
| 1879 | |
| 1880 | Short::Short(short x) |
| 1881 | { |
| 1882 | storeValue(Nucleus::createConstantShort(x)); |
| 1883 | } |
| 1884 | |
| 1885 | Short::Short(RValue<Short> rhs) |
| 1886 | { |
| 1887 | storeValue(rhs.value); |
| 1888 | } |
| 1889 | |
| 1890 | Short::Short(const Short &rhs) |
| 1891 | { |
| 1892 | Value *value = rhs.loadValue(); |
| 1893 | storeValue(value); |
| 1894 | } |
| 1895 | |
| 1896 | Short::Short(const Reference<Short> &rhs) |
| 1897 | { |
| 1898 | Value *value = rhs.loadValue(); |
| 1899 | storeValue(value); |
| 1900 | } |
| 1901 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1902 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1903 | { |
| 1904 | storeValue(rhs.value); |
| 1905 | |
| 1906 | return rhs; |
| 1907 | } |
| 1908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1909 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1910 | { |
| 1911 | Value *value = rhs.loadValue(); |
| 1912 | storeValue(value); |
| 1913 | |
| 1914 | return RValue<Short>(value); |
| 1915 | } |
| 1916 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1917 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1918 | { |
| 1919 | Value *value = rhs.loadValue(); |
| 1920 | storeValue(value); |
| 1921 | |
| 1922 | return RValue<Short>(value); |
| 1923 | } |
| 1924 | |
| 1925 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 1926 | { |
| 1927 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1928 | } |
| 1929 | |
| 1930 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 1931 | { |
| 1932 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1933 | } |
| 1934 | |
| 1935 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 1936 | { |
| 1937 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1938 | } |
| 1939 | |
| 1940 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 1941 | { |
| 1942 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1943 | } |
| 1944 | |
| 1945 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 1946 | { |
| 1947 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1948 | } |
| 1949 | |
| 1950 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 1951 | { |
| 1952 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1953 | } |
| 1954 | |
| 1955 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 1956 | { |
| 1957 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1958 | } |
| 1959 | |
| 1960 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 1961 | { |
| 1962 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1963 | } |
| 1964 | |
| 1965 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 1966 | { |
| 1967 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1968 | } |
| 1969 | |
| 1970 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 1971 | { |
| 1972 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1973 | } |
| 1974 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1975 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1976 | { |
| 1977 | return lhs = lhs + rhs; |
| 1978 | } |
| 1979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1980 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1981 | { |
| 1982 | return lhs = lhs - rhs; |
| 1983 | } |
| 1984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1985 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1986 | { |
| 1987 | return lhs = lhs * rhs; |
| 1988 | } |
| 1989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1990 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1991 | { |
| 1992 | return lhs = lhs / rhs; |
| 1993 | } |
| 1994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1995 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1996 | { |
| 1997 | return lhs = lhs % rhs; |
| 1998 | } |
| 1999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2000 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2001 | { |
| 2002 | return lhs = lhs & rhs; |
| 2003 | } |
| 2004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2005 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2006 | { |
| 2007 | return lhs = lhs | rhs; |
| 2008 | } |
| 2009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2010 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2011 | { |
| 2012 | return lhs = lhs ^ rhs; |
| 2013 | } |
| 2014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2015 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2016 | { |
| 2017 | return lhs = lhs << rhs; |
| 2018 | } |
| 2019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2020 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2021 | { |
| 2022 | return lhs = lhs >> rhs; |
| 2023 | } |
| 2024 | |
| 2025 | RValue<Short> operator+(RValue<Short> val) |
| 2026 | { |
| 2027 | return val; |
| 2028 | } |
| 2029 | |
| 2030 | RValue<Short> operator-(RValue<Short> val) |
| 2031 | { |
| 2032 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2033 | } |
| 2034 | |
| 2035 | RValue<Short> operator~(RValue<Short> val) |
| 2036 | { |
| 2037 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2038 | } |
| 2039 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2040 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2041 | { |
| 2042 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2043 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2044 | return res; |
| 2045 | } |
| 2046 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2047 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2048 | { |
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 val; |
| 2051 | } |
| 2052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2053 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2054 | { |
| 2055 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2056 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2057 | return res; |
| 2058 | } |
| 2059 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2060 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2061 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2062 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2063 | return val; |
| 2064 | } |
| 2065 | |
| 2066 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2067 | { |
| 2068 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2069 | } |
| 2070 | |
| 2071 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2072 | { |
| 2073 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2074 | } |
| 2075 | |
| 2076 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2077 | { |
| 2078 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2079 | } |
| 2080 | |
| 2081 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2082 | { |
| 2083 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2084 | } |
| 2085 | |
| 2086 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2087 | { |
| 2088 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2089 | } |
| 2090 | |
| 2091 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2092 | { |
| 2093 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2094 | } |
| 2095 | |
| 2096 | Type *Short::getType() |
| 2097 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2098 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | UShort::UShort(Argument<UShort> argument) |
| 2102 | { |
| 2103 | storeValue(argument.value); |
| 2104 | } |
| 2105 | |
| 2106 | UShort::UShort(RValue<UInt> cast) |
| 2107 | { |
| 2108 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2109 | |
| 2110 | storeValue(integer); |
| 2111 | } |
| 2112 | |
| 2113 | UShort::UShort(RValue<Int> cast) |
| 2114 | { |
| 2115 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2116 | |
| 2117 | storeValue(integer); |
| 2118 | } |
| 2119 | |
| 2120 | UShort::UShort() |
| 2121 | { |
| 2122 | } |
| 2123 | |
| 2124 | UShort::UShort(unsigned short x) |
| 2125 | { |
| 2126 | storeValue(Nucleus::createConstantShort(x)); |
| 2127 | } |
| 2128 | |
| 2129 | UShort::UShort(RValue<UShort> rhs) |
| 2130 | { |
| 2131 | storeValue(rhs.value); |
| 2132 | } |
| 2133 | |
| 2134 | UShort::UShort(const UShort &rhs) |
| 2135 | { |
| 2136 | Value *value = rhs.loadValue(); |
| 2137 | storeValue(value); |
| 2138 | } |
| 2139 | |
| 2140 | UShort::UShort(const Reference<UShort> &rhs) |
| 2141 | { |
| 2142 | Value *value = rhs.loadValue(); |
| 2143 | storeValue(value); |
| 2144 | } |
| 2145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2146 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2147 | { |
| 2148 | storeValue(rhs.value); |
| 2149 | |
| 2150 | return rhs; |
| 2151 | } |
| 2152 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2153 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2154 | { |
| 2155 | Value *value = rhs.loadValue(); |
| 2156 | storeValue(value); |
| 2157 | |
| 2158 | return RValue<UShort>(value); |
| 2159 | } |
| 2160 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2161 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2162 | { |
| 2163 | Value *value = rhs.loadValue(); |
| 2164 | storeValue(value); |
| 2165 | |
| 2166 | return RValue<UShort>(value); |
| 2167 | } |
| 2168 | |
| 2169 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2170 | { |
| 2171 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2172 | } |
| 2173 | |
| 2174 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2175 | { |
| 2176 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2177 | } |
| 2178 | |
| 2179 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2180 | { |
| 2181 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2182 | } |
| 2183 | |
| 2184 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2185 | { |
| 2186 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2187 | } |
| 2188 | |
| 2189 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2190 | { |
| 2191 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2192 | } |
| 2193 | |
| 2194 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2195 | { |
| 2196 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2197 | } |
| 2198 | |
| 2199 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2200 | { |
| 2201 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2202 | } |
| 2203 | |
| 2204 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2205 | { |
| 2206 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2207 | } |
| 2208 | |
| 2209 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2210 | { |
| 2211 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2212 | } |
| 2213 | |
| 2214 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2215 | { |
| 2216 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2217 | } |
| 2218 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2219 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2220 | { |
| 2221 | return lhs = lhs + rhs; |
| 2222 | } |
| 2223 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2224 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2225 | { |
| 2226 | return lhs = lhs - rhs; |
| 2227 | } |
| 2228 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2229 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2230 | { |
| 2231 | return lhs = lhs * rhs; |
| 2232 | } |
| 2233 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2234 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2235 | { |
| 2236 | return lhs = lhs / rhs; |
| 2237 | } |
| 2238 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2239 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2240 | { |
| 2241 | return lhs = lhs % rhs; |
| 2242 | } |
| 2243 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2244 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2245 | { |
| 2246 | return lhs = lhs & rhs; |
| 2247 | } |
| 2248 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2249 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2250 | { |
| 2251 | return lhs = lhs | rhs; |
| 2252 | } |
| 2253 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2254 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2255 | { |
| 2256 | return lhs = lhs ^ rhs; |
| 2257 | } |
| 2258 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2259 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2260 | { |
| 2261 | return lhs = lhs << rhs; |
| 2262 | } |
| 2263 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2264 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2265 | { |
| 2266 | return lhs = lhs >> rhs; |
| 2267 | } |
| 2268 | |
| 2269 | RValue<UShort> operator+(RValue<UShort> val) |
| 2270 | { |
| 2271 | return val; |
| 2272 | } |
| 2273 | |
| 2274 | RValue<UShort> operator-(RValue<UShort> val) |
| 2275 | { |
| 2276 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2277 | } |
| 2278 | |
| 2279 | RValue<UShort> operator~(RValue<UShort> val) |
| 2280 | { |
| 2281 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2282 | } |
| 2283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2284 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2285 | { |
| 2286 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2287 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2288 | return res; |
| 2289 | } |
| 2290 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2291 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2292 | { |
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 val; |
| 2295 | } |
| 2296 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2297 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2298 | { |
| 2299 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2300 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2301 | return res; |
| 2302 | } |
| 2303 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2304 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2305 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2306 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2307 | return val; |
| 2308 | } |
| 2309 | |
| 2310 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2311 | { |
| 2312 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2313 | } |
| 2314 | |
| 2315 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2316 | { |
| 2317 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2318 | } |
| 2319 | |
| 2320 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2321 | { |
| 2322 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2323 | } |
| 2324 | |
| 2325 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2326 | { |
| 2327 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2328 | } |
| 2329 | |
| 2330 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2331 | { |
| 2332 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2333 | } |
| 2334 | |
| 2335 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2336 | { |
| 2337 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2338 | } |
| 2339 | |
| 2340 | Type *UShort::getType() |
| 2341 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2342 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2343 | } |
| 2344 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2345 | Byte4::Byte4(RValue<Byte8> cast) |
| 2346 | { |
| 2347 | // xyzw.parent = this; |
| 2348 | |
| 2349 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2350 | } |
| 2351 | |
| 2352 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2353 | { |
| 2354 | // xyzw.parent = this; |
| 2355 | |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2356 | Value *value = rhs.loadValue(); |
| 2357 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2358 | } |
| 2359 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2360 | Type *Byte4::getType() |
| 2361 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2362 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | Type *SByte4::getType() |
| 2366 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2367 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | Byte8::Byte8() |
| 2371 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | 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) |
| 2375 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2376 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2377 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2381 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2382 | storeValue(rhs.value); |
| 2383 | } |
| 2384 | |
| 2385 | Byte8::Byte8(const Byte8 &rhs) |
| 2386 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2387 | Value *value = rhs.loadValue(); |
| 2388 | storeValue(value); |
| 2389 | } |
| 2390 | |
| 2391 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2392 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2393 | Value *value = rhs.loadValue(); |
| 2394 | storeValue(value); |
| 2395 | } |
| 2396 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2397 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2398 | { |
| 2399 | storeValue(rhs.value); |
| 2400 | |
| 2401 | return rhs; |
| 2402 | } |
| 2403 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2404 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2405 | { |
| 2406 | Value *value = rhs.loadValue(); |
| 2407 | storeValue(value); |
| 2408 | |
| 2409 | return RValue<Byte8>(value); |
| 2410 | } |
| 2411 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2412 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2413 | { |
| 2414 | Value *value = rhs.loadValue(); |
| 2415 | storeValue(value); |
| 2416 | |
| 2417 | return RValue<Byte8>(value); |
| 2418 | } |
| 2419 | |
| 2420 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2421 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2422 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2426 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2427 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2431 | // { |
| 2432 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2433 | // } |
| 2434 | |
| 2435 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2436 | // { |
| 2437 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2438 | // } |
| 2439 | |
| 2440 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2441 | // { |
| 2442 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2443 | // } |
| 2444 | |
| 2445 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2446 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2447 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2451 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2452 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2456 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2457 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2461 | // { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 2462 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2463 | // } |
| 2464 | |
| 2465 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2466 | // { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 2467 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2468 | // } |
| 2469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2470 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2471 | { |
| 2472 | return lhs = lhs + rhs; |
| 2473 | } |
| 2474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2475 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2476 | { |
| 2477 | return lhs = lhs - rhs; |
| 2478 | } |
| 2479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2480 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2481 | // { |
| 2482 | // return lhs = lhs * rhs; |
| 2483 | // } |
| 2484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2485 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2486 | // { |
| 2487 | // return lhs = lhs / rhs; |
| 2488 | // } |
| 2489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2490 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2491 | // { |
| 2492 | // return lhs = lhs % rhs; |
| 2493 | // } |
| 2494 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2495 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2496 | { |
| 2497 | return lhs = lhs & rhs; |
| 2498 | } |
| 2499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2500 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2501 | { |
| 2502 | return lhs = lhs | rhs; |
| 2503 | } |
| 2504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2505 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2506 | { |
| 2507 | return lhs = lhs ^ rhs; |
| 2508 | } |
| 2509 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2510 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2511 | // { |
| 2512 | // return lhs = lhs << rhs; |
| 2513 | // } |
| 2514 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2515 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2516 | // { |
| 2517 | // return lhs = lhs >> rhs; |
| 2518 | // } |
| 2519 | |
| 2520 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2521 | // { |
| 2522 | // return val; |
| 2523 | // } |
| 2524 | |
| 2525 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2526 | // { |
| 2527 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2528 | // } |
| 2529 | |
| 2530 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2531 | { |
| 2532 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2533 | } |
| 2534 | |
| 2535 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2536 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2537 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2538 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2539 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2540 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2541 | paddusb->addArg(x.value); |
| 2542 | paddusb->addArg(y.value); |
| 2543 | ::basicBlock->appendInst(paddusb); |
| 2544 | |
| 2545 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2549 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2550 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2551 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2552 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2553 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2554 | psubusw->addArg(x.value); |
| 2555 | psubusw->addArg(y.value); |
| 2556 | ::basicBlock->appendInst(psubusw); |
| 2557 | |
| 2558 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2562 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2563 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2564 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2568 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2569 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2570 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2574 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2575 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2576 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2577 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2581 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2582 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2583 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2584 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2585 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2586 | movmsk->addArg(x.value); |
| 2587 | ::basicBlock->appendInst(movmsk); |
| 2588 | |
| 2589 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2593 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2594 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2595 | // } |
| 2596 | |
| 2597 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2598 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2599 | 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] | 2600 | } |
| 2601 | |
| 2602 | Type *Byte8::getType() |
| 2603 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2604 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | SByte8::SByte8() |
| 2608 | { |
| 2609 | // xyzw.parent = this; |
| 2610 | } |
| 2611 | |
| 2612 | 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) |
| 2613 | { |
| 2614 | // xyzw.parent = this; |
| 2615 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2616 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2617 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2618 | |
| 2619 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2620 | } |
| 2621 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2622 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2623 | { |
| 2624 | // xyzw.parent = this; |
| 2625 | |
| 2626 | storeValue(rhs.value); |
| 2627 | } |
| 2628 | |
| 2629 | SByte8::SByte8(const SByte8 &rhs) |
| 2630 | { |
| 2631 | // xyzw.parent = this; |
| 2632 | |
| 2633 | Value *value = rhs.loadValue(); |
| 2634 | storeValue(value); |
| 2635 | } |
| 2636 | |
| 2637 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2638 | { |
| 2639 | // xyzw.parent = this; |
| 2640 | |
| 2641 | Value *value = rhs.loadValue(); |
| 2642 | storeValue(value); |
| 2643 | } |
| 2644 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2645 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2646 | { |
| 2647 | storeValue(rhs.value); |
| 2648 | |
| 2649 | return rhs; |
| 2650 | } |
| 2651 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2652 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2653 | { |
| 2654 | Value *value = rhs.loadValue(); |
| 2655 | storeValue(value); |
| 2656 | |
| 2657 | return RValue<SByte8>(value); |
| 2658 | } |
| 2659 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2660 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2661 | { |
| 2662 | Value *value = rhs.loadValue(); |
| 2663 | storeValue(value); |
| 2664 | |
| 2665 | return RValue<SByte8>(value); |
| 2666 | } |
| 2667 | |
| 2668 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2669 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2670 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2674 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2675 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2679 | // { |
| 2680 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2681 | // } |
| 2682 | |
| 2683 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2684 | // { |
| 2685 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2686 | // } |
| 2687 | |
| 2688 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2689 | // { |
| 2690 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2691 | // } |
| 2692 | |
| 2693 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2694 | { |
| 2695 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2696 | } |
| 2697 | |
| 2698 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2699 | { |
| 2700 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2701 | } |
| 2702 | |
| 2703 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2704 | { |
| 2705 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2706 | } |
| 2707 | |
| 2708 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2709 | // { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 2710 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2711 | // } |
| 2712 | |
| 2713 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2714 | // { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 2715 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2716 | // } |
| 2717 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2718 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2719 | { |
| 2720 | return lhs = lhs + rhs; |
| 2721 | } |
| 2722 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2723 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2724 | { |
| 2725 | return lhs = lhs - rhs; |
| 2726 | } |
| 2727 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2728 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2729 | // { |
| 2730 | // return lhs = lhs * rhs; |
| 2731 | // } |
| 2732 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2733 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2734 | // { |
| 2735 | // return lhs = lhs / rhs; |
| 2736 | // } |
| 2737 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2738 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2739 | // { |
| 2740 | // return lhs = lhs % rhs; |
| 2741 | // } |
| 2742 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2743 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2744 | { |
| 2745 | return lhs = lhs & rhs; |
| 2746 | } |
| 2747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2748 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2749 | { |
| 2750 | return lhs = lhs | rhs; |
| 2751 | } |
| 2752 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2753 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2754 | { |
| 2755 | return lhs = lhs ^ rhs; |
| 2756 | } |
| 2757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2758 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2759 | // { |
| 2760 | // return lhs = lhs << rhs; |
| 2761 | // } |
| 2762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2763 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2764 | // { |
| 2765 | // return lhs = lhs >> rhs; |
| 2766 | // } |
| 2767 | |
| 2768 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2769 | // { |
| 2770 | // return val; |
| 2771 | // } |
| 2772 | |
| 2773 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2774 | // { |
| 2775 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2776 | // } |
| 2777 | |
| 2778 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2779 | { |
| 2780 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2781 | } |
| 2782 | |
| 2783 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2784 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2785 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2786 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2787 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2788 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2789 | paddsb->addArg(x.value); |
| 2790 | paddsb->addArg(y.value); |
| 2791 | ::basicBlock->appendInst(paddsb); |
| 2792 | |
| 2793 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2797 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2798 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2799 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2800 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2801 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2802 | psubsb->addArg(x.value); |
| 2803 | psubsb->addArg(y.value); |
| 2804 | ::basicBlock->appendInst(psubsb); |
| 2805 | |
| 2806 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2810 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2811 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2812 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2816 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2817 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2818 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2819 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2823 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2824 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2825 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2826 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2827 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2828 | movmsk->addArg(x.value); |
| 2829 | ::basicBlock->appendInst(movmsk); |
| 2830 | |
| 2831 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2835 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2836 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2840 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2841 | 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] | 2842 | } |
| 2843 | |
| 2844 | Type *SByte8::getType() |
| 2845 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2846 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2850 | { |
| 2851 | // xyzw.parent = this; |
| 2852 | |
| 2853 | storeValue(rhs.value); |
| 2854 | } |
| 2855 | |
| 2856 | Byte16::Byte16(const Byte16 &rhs) |
| 2857 | { |
| 2858 | // xyzw.parent = this; |
| 2859 | |
| 2860 | Value *value = rhs.loadValue(); |
| 2861 | storeValue(value); |
| 2862 | } |
| 2863 | |
| 2864 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2865 | { |
| 2866 | // xyzw.parent = this; |
| 2867 | |
| 2868 | Value *value = rhs.loadValue(); |
| 2869 | storeValue(value); |
| 2870 | } |
| 2871 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2872 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2873 | { |
| 2874 | storeValue(rhs.value); |
| 2875 | |
| 2876 | return rhs; |
| 2877 | } |
| 2878 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2879 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2880 | { |
| 2881 | Value *value = rhs.loadValue(); |
| 2882 | storeValue(value); |
| 2883 | |
| 2884 | return RValue<Byte16>(value); |
| 2885 | } |
| 2886 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2887 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2888 | { |
| 2889 | Value *value = rhs.loadValue(); |
| 2890 | storeValue(value); |
| 2891 | |
| 2892 | return RValue<Byte16>(value); |
| 2893 | } |
| 2894 | |
| 2895 | Type *Byte16::getType() |
| 2896 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2897 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | Type *SByte16::getType() |
| 2901 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2902 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2903 | } |
| 2904 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2905 | Short2::Short2(RValue<Short4> cast) |
| 2906 | { |
| 2907 | assert(false && "UNIMPLEMENTED"); |
| 2908 | } |
| 2909 | |
| 2910 | Type *Short2::getType() |
| 2911 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2912 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | UShort2::UShort2(RValue<UShort4> cast) |
| 2916 | { |
| 2917 | assert(false && "UNIMPLEMENTED"); |
| 2918 | } |
| 2919 | |
| 2920 | Type *UShort2::getType() |
| 2921 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2922 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2923 | } |
| 2924 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2925 | Short4::Short4(RValue<Int> cast) |
| 2926 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2927 | Value *vector = loadValue(); |
| 2928 | Value *insert = Nucleus::createInsertElement(vector, cast.value, 0); |
| 2929 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2930 | |
| 2931 | storeValue(swizzle); |
| 2932 | } |
| 2933 | |
| 2934 | Short4::Short4(RValue<Int4> cast) |
| 2935 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2936 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
| 2937 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2938 | Value *packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
| 2939 | |
| 2940 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2941 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2942 | |
| 2943 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | // Short4::Short4(RValue<Float> cast) |
| 2947 | // { |
| 2948 | // } |
| 2949 | |
| 2950 | Short4::Short4(RValue<Float4> cast) |
| 2951 | { |
| 2952 | assert(false && "UNIMPLEMENTED"); |
| 2953 | } |
| 2954 | |
| 2955 | Short4::Short4() |
| 2956 | { |
| 2957 | // xyzw.parent = this; |
| 2958 | } |
| 2959 | |
| 2960 | Short4::Short4(short xyzw) |
| 2961 | { |
| 2962 | // xyzw.parent = this; |
| 2963 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2964 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2965 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | Short4::Short4(short x, short y, short z, short w) |
| 2969 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2970 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2971 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2972 | int64_t constantVector[4] = {x, y, z, w}; |
| 2973 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | Short4::Short4(RValue<Short4> rhs) |
| 2977 | { |
| 2978 | // xyzw.parent = this; |
| 2979 | |
| 2980 | storeValue(rhs.value); |
| 2981 | } |
| 2982 | |
| 2983 | Short4::Short4(const Short4 &rhs) |
| 2984 | { |
| 2985 | // xyzw.parent = this; |
| 2986 | |
| 2987 | Value *value = rhs.loadValue(); |
| 2988 | storeValue(value); |
| 2989 | } |
| 2990 | |
| 2991 | Short4::Short4(const Reference<Short4> &rhs) |
| 2992 | { |
| 2993 | // xyzw.parent = this; |
| 2994 | |
| 2995 | Value *value = rhs.loadValue(); |
| 2996 | storeValue(value); |
| 2997 | } |
| 2998 | |
| 2999 | Short4::Short4(RValue<UShort4> rhs) |
| 3000 | { |
| 3001 | // xyzw.parent = this; |
| 3002 | |
| 3003 | storeValue(rhs.value); |
| 3004 | } |
| 3005 | |
| 3006 | Short4::Short4(const UShort4 &rhs) |
| 3007 | { |
| 3008 | // xyzw.parent = this; |
| 3009 | |
| 3010 | storeValue(rhs.loadValue()); |
| 3011 | } |
| 3012 | |
| 3013 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3014 | { |
| 3015 | // xyzw.parent = this; |
| 3016 | |
| 3017 | storeValue(rhs.loadValue()); |
| 3018 | } |
| 3019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3020 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3021 | { |
| 3022 | storeValue(rhs.value); |
| 3023 | |
| 3024 | return rhs; |
| 3025 | } |
| 3026 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3027 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3028 | { |
| 3029 | Value *value = rhs.loadValue(); |
| 3030 | storeValue(value); |
| 3031 | |
| 3032 | return RValue<Short4>(value); |
| 3033 | } |
| 3034 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3035 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3036 | { |
| 3037 | Value *value = rhs.loadValue(); |
| 3038 | storeValue(value); |
| 3039 | |
| 3040 | return RValue<Short4>(value); |
| 3041 | } |
| 3042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3043 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3044 | { |
| 3045 | storeValue(rhs.value); |
| 3046 | |
| 3047 | return RValue<Short4>(rhs); |
| 3048 | } |
| 3049 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3050 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3051 | { |
| 3052 | Value *value = rhs.loadValue(); |
| 3053 | storeValue(value); |
| 3054 | |
| 3055 | return RValue<Short4>(value); |
| 3056 | } |
| 3057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3058 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3059 | { |
| 3060 | Value *value = rhs.loadValue(); |
| 3061 | storeValue(value); |
| 3062 | |
| 3063 | return RValue<Short4>(value); |
| 3064 | } |
| 3065 | |
| 3066 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3067 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3068 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3072 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3073 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3077 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3078 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3082 | // { |
| 3083 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3084 | // } |
| 3085 | |
| 3086 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3087 | // { |
| 3088 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3089 | // } |
| 3090 | |
| 3091 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3092 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3093 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3097 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3098 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3102 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3103 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3107 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3108 | return RValue<Short4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3112 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3113 | return RValue<Short4>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3114 | } |
| 3115 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3116 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3117 | { |
| 3118 | return lhs = lhs + rhs; |
| 3119 | } |
| 3120 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3121 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3122 | { |
| 3123 | return lhs = lhs - rhs; |
| 3124 | } |
| 3125 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3126 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3127 | { |
| 3128 | return lhs = lhs * rhs; |
| 3129 | } |
| 3130 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3131 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3132 | // { |
| 3133 | // return lhs = lhs / rhs; |
| 3134 | // } |
| 3135 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3136 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3137 | // { |
| 3138 | // return lhs = lhs % rhs; |
| 3139 | // } |
| 3140 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3141 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3142 | { |
| 3143 | return lhs = lhs & rhs; |
| 3144 | } |
| 3145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3146 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3147 | { |
| 3148 | return lhs = lhs | rhs; |
| 3149 | } |
| 3150 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3151 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3152 | { |
| 3153 | return lhs = lhs ^ rhs; |
| 3154 | } |
| 3155 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3156 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3157 | { |
| 3158 | return lhs = lhs << rhs; |
| 3159 | } |
| 3160 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3161 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3162 | { |
| 3163 | return lhs = lhs >> rhs; |
| 3164 | } |
| 3165 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3166 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3167 | // { |
| 3168 | // return val; |
| 3169 | // } |
| 3170 | |
| 3171 | RValue<Short4> operator-(RValue<Short4> val) |
| 3172 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3173 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | RValue<Short4> operator~(RValue<Short4> val) |
| 3177 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3178 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3182 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3183 | RValue<Int4> int4 = RoundInt(cast); |
| 3184 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3188 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3189 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3190 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3191 | ::basicBlock->appendInst(cmp); |
| 3192 | |
| 3193 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3194 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3195 | ::basicBlock->appendInst(select); |
| 3196 | |
| 3197 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3201 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3202 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3203 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3204 | ::basicBlock->appendInst(cmp); |
| 3205 | |
| 3206 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3207 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3208 | ::basicBlock->appendInst(select); |
| 3209 | |
| 3210 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3214 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3215 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3216 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3217 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3218 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3219 | paddsw->addArg(x.value); |
| 3220 | paddsw->addArg(y.value); |
| 3221 | ::basicBlock->appendInst(paddsw); |
| 3222 | |
| 3223 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3227 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3228 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3229 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3230 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3231 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3232 | psubsw->addArg(x.value); |
| 3233 | psubsw->addArg(y.value); |
| 3234 | ::basicBlock->appendInst(psubsw); |
| 3235 | |
| 3236 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3240 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3241 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3242 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3243 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3244 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3245 | pmulhw->addArg(x.value); |
| 3246 | pmulhw->addArg(y.value); |
| 3247 | ::basicBlock->appendInst(pmulhw); |
| 3248 | |
| 3249 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3253 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3254 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3255 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3256 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3257 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3258 | pmaddwd->addArg(x.value); |
| 3259 | pmaddwd->addArg(y.value); |
| 3260 | ::basicBlock->appendInst(pmaddwd); |
| 3261 | |
| 3262 | return RValue<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3266 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3267 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3268 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3269 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3270 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3271 | pack->addArg(x.value); |
| 3272 | pack->addArg(y.value); |
| 3273 | ::basicBlock->appendInst(pack); |
| 3274 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3275 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3279 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3280 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3281 | return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3285 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3286 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3287 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3288 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3292 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3293 | // Real type is v8i16 |
| 3294 | int shuffle[8] = |
| 3295 | { |
| 3296 | (select >> 0) & 0x03, |
| 3297 | (select >> 2) & 0x03, |
| 3298 | (select >> 4) & 0x03, |
| 3299 | (select >> 6) & 0x03, |
| 3300 | (select >> 0) & 0x03, |
| 3301 | (select >> 2) & 0x03, |
| 3302 | (select >> 4) & 0x03, |
| 3303 | (select >> 6) & 0x03, |
| 3304 | }; |
| 3305 | |
| 3306 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3310 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3311 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3315 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3316 | return RValue<Short>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3320 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3321 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3325 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3326 | 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] | 3327 | } |
| 3328 | |
| 3329 | Type *Short4::getType() |
| 3330 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3331 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | UShort4::UShort4(RValue<Int4> cast) |
| 3335 | { |
| 3336 | *this = Short4(cast); |
| 3337 | } |
| 3338 | |
| 3339 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3340 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3341 | if(saturate) |
| 3342 | { |
| 3343 | if(true) // SSE 4.1 |
| 3344 | { |
| 3345 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3346 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3347 | } |
| 3348 | else |
| 3349 | { |
| 3350 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3351 | } |
| 3352 | } |
| 3353 | else |
| 3354 | { |
| 3355 | *this = Short4(Int4(cast)); |
| 3356 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | UShort4::UShort4() |
| 3360 | { |
| 3361 | // xyzw.parent = this; |
| 3362 | } |
| 3363 | |
| 3364 | UShort4::UShort4(unsigned short xyzw) |
| 3365 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3366 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3367 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3368 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3369 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3373 | { |
| 3374 | // xyzw.parent = this; |
| 3375 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3376 | int64_t constantVector[4] = {x, y, z, w}; |
| 3377 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3381 | { |
| 3382 | // xyzw.parent = this; |
| 3383 | |
| 3384 | storeValue(rhs.value); |
| 3385 | } |
| 3386 | |
| 3387 | UShort4::UShort4(const UShort4 &rhs) |
| 3388 | { |
| 3389 | // xyzw.parent = this; |
| 3390 | |
| 3391 | Value *value = rhs.loadValue(); |
| 3392 | storeValue(value); |
| 3393 | } |
| 3394 | |
| 3395 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3396 | { |
| 3397 | // xyzw.parent = this; |
| 3398 | |
| 3399 | Value *value = rhs.loadValue(); |
| 3400 | storeValue(value); |
| 3401 | } |
| 3402 | |
| 3403 | UShort4::UShort4(RValue<Short4> rhs) |
| 3404 | { |
| 3405 | // xyzw.parent = this; |
| 3406 | |
| 3407 | storeValue(rhs.value); |
| 3408 | } |
| 3409 | |
| 3410 | UShort4::UShort4(const Short4 &rhs) |
| 3411 | { |
| 3412 | // xyzw.parent = this; |
| 3413 | |
| 3414 | Value *value = rhs.loadValue(); |
| 3415 | storeValue(value); |
| 3416 | } |
| 3417 | |
| 3418 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3419 | { |
| 3420 | // xyzw.parent = this; |
| 3421 | |
| 3422 | Value *value = rhs.loadValue(); |
| 3423 | storeValue(value); |
| 3424 | } |
| 3425 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3426 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3427 | { |
| 3428 | storeValue(rhs.value); |
| 3429 | |
| 3430 | return rhs; |
| 3431 | } |
| 3432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3433 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3434 | { |
| 3435 | Value *value = rhs.loadValue(); |
| 3436 | storeValue(value); |
| 3437 | |
| 3438 | return RValue<UShort4>(value); |
| 3439 | } |
| 3440 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3441 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3442 | { |
| 3443 | Value *value = rhs.loadValue(); |
| 3444 | storeValue(value); |
| 3445 | |
| 3446 | return RValue<UShort4>(value); |
| 3447 | } |
| 3448 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3449 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3450 | { |
| 3451 | storeValue(rhs.value); |
| 3452 | |
| 3453 | return RValue<UShort4>(rhs); |
| 3454 | } |
| 3455 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3456 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3457 | { |
| 3458 | Value *value = rhs.loadValue(); |
| 3459 | storeValue(value); |
| 3460 | |
| 3461 | return RValue<UShort4>(value); |
| 3462 | } |
| 3463 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3464 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3465 | { |
| 3466 | Value *value = rhs.loadValue(); |
| 3467 | storeValue(value); |
| 3468 | |
| 3469 | return RValue<UShort4>(value); |
| 3470 | } |
| 3471 | |
| 3472 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3473 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3474 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3478 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3479 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3483 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3484 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3485 | } |
| 3486 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3487 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3488 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3489 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3493 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3494 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3498 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3499 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3500 | } |
| 3501 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3502 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3503 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3504 | return RValue<UShort4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3508 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3509 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3510 | } |
| 3511 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3512 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3513 | { |
| 3514 | return lhs = lhs << rhs; |
| 3515 | } |
| 3516 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3517 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3518 | { |
| 3519 | return lhs = lhs >> rhs; |
| 3520 | } |
| 3521 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3522 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3523 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3524 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3528 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3529 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3530 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3531 | ::basicBlock->appendInst(cmp); |
| 3532 | |
| 3533 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3534 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3535 | ::basicBlock->appendInst(select); |
| 3536 | |
| 3537 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3541 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3542 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3543 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3544 | ::basicBlock->appendInst(cmp); |
| 3545 | |
| 3546 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3547 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3548 | ::basicBlock->appendInst(select); |
| 3549 | |
| 3550 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3554 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3555 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3556 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3557 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3558 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3559 | paddusw->addArg(x.value); |
| 3560 | paddusw->addArg(y.value); |
| 3561 | ::basicBlock->appendInst(paddusw); |
| 3562 | |
| 3563 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3567 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3568 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3569 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3570 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3571 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3572 | psubusw->addArg(x.value); |
| 3573 | psubusw->addArg(y.value); |
| 3574 | ::basicBlock->appendInst(psubusw); |
| 3575 | |
| 3576 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3580 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3581 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3582 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3583 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3584 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3585 | pmulhuw->addArg(x.value); |
| 3586 | pmulhuw->addArg(y.value); |
| 3587 | ::basicBlock->appendInst(pmulhuw); |
| 3588 | |
| 3589 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3593 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3594 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3598 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3599 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3600 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3601 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3602 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3603 | pack->addArg(x.value); |
| 3604 | pack->addArg(y.value); |
| 3605 | ::basicBlock->appendInst(pack); |
| 3606 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3607 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | Type *UShort4::getType() |
| 3611 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3612 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3616 | { |
| 3617 | // xyzw.parent = this; |
| 3618 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3619 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3620 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | Short8::Short8(RValue<Short8> rhs) |
| 3624 | { |
| 3625 | // xyzw.parent = this; |
| 3626 | |
| 3627 | storeValue(rhs.value); |
| 3628 | } |
| 3629 | |
| 3630 | Short8::Short8(const Reference<Short8> &rhs) |
| 3631 | { |
| 3632 | // xyzw.parent = this; |
| 3633 | |
| 3634 | Value *value = rhs.loadValue(); |
| 3635 | storeValue(value); |
| 3636 | } |
| 3637 | |
| 3638 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3639 | { |
| 3640 | assert(false && "UNIMPLEMENTED"); |
| 3641 | } |
| 3642 | |
| 3643 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3644 | { |
| 3645 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3646 | } |
| 3647 | |
| 3648 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3649 | { |
| 3650 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3651 | } |
| 3652 | |
| 3653 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3654 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3655 | return RValue<Short8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3659 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3660 | return RValue<Short8>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3664 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3665 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | RValue<Int4> Abs(RValue<Int4> x) |
| 3669 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3670 | auto negative = x >> 31; |
| 3671 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3672 | } |
| 3673 | |
| 3674 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3675 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3676 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | Type *Short8::getType() |
| 3680 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3681 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | 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) |
| 3685 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3686 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3687 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3691 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3692 | storeValue(rhs.value); |
| 3693 | } |
| 3694 | |
| 3695 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3696 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3697 | Value *value = rhs.loadValue(); |
| 3698 | storeValue(value); |
| 3699 | } |
| 3700 | |
| 3701 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3702 | { |
| 3703 | assert(false && "UNIMPLEMENTED"); |
| 3704 | } |
| 3705 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3706 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3707 | { |
| 3708 | storeValue(rhs.value); |
| 3709 | |
| 3710 | return rhs; |
| 3711 | } |
| 3712 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3713 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3714 | { |
| 3715 | Value *value = rhs.loadValue(); |
| 3716 | storeValue(value); |
| 3717 | |
| 3718 | return RValue<UShort8>(value); |
| 3719 | } |
| 3720 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3721 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3722 | { |
| 3723 | Value *value = rhs.loadValue(); |
| 3724 | storeValue(value); |
| 3725 | |
| 3726 | return RValue<UShort8>(value); |
| 3727 | } |
| 3728 | |
| 3729 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3730 | { |
| 3731 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3732 | } |
| 3733 | |
| 3734 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3735 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3736 | return RValue<UShort8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3740 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 3741 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3745 | { |
| 3746 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3747 | } |
| 3748 | |
| 3749 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3750 | { |
| 3751 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3752 | } |
| 3753 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3754 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3755 | { |
| 3756 | return lhs = lhs + rhs; |
| 3757 | } |
| 3758 | |
| 3759 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3760 | { |
| 3761 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3762 | } |
| 3763 | |
| 3764 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3765 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3766 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3770 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3771 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3775 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3776 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3777 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3778 | // } |
| 3779 | |
| 3780 | Type *UShort8::getType() |
| 3781 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3782 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | Int::Int(Argument<Int> argument) |
| 3786 | { |
| 3787 | storeValue(argument.value); |
| 3788 | } |
| 3789 | |
| 3790 | Int::Int(RValue<Byte> cast) |
| 3791 | { |
| 3792 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3793 | |
| 3794 | storeValue(integer); |
| 3795 | } |
| 3796 | |
| 3797 | Int::Int(RValue<SByte> cast) |
| 3798 | { |
| 3799 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3800 | |
| 3801 | storeValue(integer); |
| 3802 | } |
| 3803 | |
| 3804 | Int::Int(RValue<Short> cast) |
| 3805 | { |
| 3806 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3807 | |
| 3808 | storeValue(integer); |
| 3809 | } |
| 3810 | |
| 3811 | Int::Int(RValue<UShort> cast) |
| 3812 | { |
| 3813 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3814 | |
| 3815 | storeValue(integer); |
| 3816 | } |
| 3817 | |
| 3818 | Int::Int(RValue<Int2> cast) |
| 3819 | { |
| 3820 | *this = Extract(cast, 0); |
| 3821 | } |
| 3822 | |
| 3823 | Int::Int(RValue<Long> cast) |
| 3824 | { |
| 3825 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3826 | |
| 3827 | storeValue(integer); |
| 3828 | } |
| 3829 | |
| 3830 | Int::Int(RValue<Float> cast) |
| 3831 | { |
| 3832 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3833 | |
| 3834 | storeValue(integer); |
| 3835 | } |
| 3836 | |
| 3837 | Int::Int() |
| 3838 | { |
| 3839 | } |
| 3840 | |
| 3841 | Int::Int(int x) |
| 3842 | { |
| 3843 | storeValue(Nucleus::createConstantInt(x)); |
| 3844 | } |
| 3845 | |
| 3846 | Int::Int(RValue<Int> rhs) |
| 3847 | { |
| 3848 | storeValue(rhs.value); |
| 3849 | } |
| 3850 | |
| 3851 | Int::Int(RValue<UInt> rhs) |
| 3852 | { |
| 3853 | storeValue(rhs.value); |
| 3854 | } |
| 3855 | |
| 3856 | Int::Int(const Int &rhs) |
| 3857 | { |
| 3858 | Value *value = rhs.loadValue(); |
| 3859 | storeValue(value); |
| 3860 | } |
| 3861 | |
| 3862 | Int::Int(const Reference<Int> &rhs) |
| 3863 | { |
| 3864 | Value *value = rhs.loadValue(); |
| 3865 | storeValue(value); |
| 3866 | } |
| 3867 | |
| 3868 | Int::Int(const UInt &rhs) |
| 3869 | { |
| 3870 | Value *value = rhs.loadValue(); |
| 3871 | storeValue(value); |
| 3872 | } |
| 3873 | |
| 3874 | Int::Int(const Reference<UInt> &rhs) |
| 3875 | { |
| 3876 | Value *value = rhs.loadValue(); |
| 3877 | storeValue(value); |
| 3878 | } |
| 3879 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3880 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3881 | { |
| 3882 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3883 | } |
| 3884 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3885 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3886 | { |
| 3887 | storeValue(rhs.value); |
| 3888 | |
| 3889 | return rhs; |
| 3890 | } |
| 3891 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3892 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3893 | { |
| 3894 | storeValue(rhs.value); |
| 3895 | |
| 3896 | return RValue<Int>(rhs); |
| 3897 | } |
| 3898 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3899 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3900 | { |
| 3901 | Value *value = rhs.loadValue(); |
| 3902 | storeValue(value); |
| 3903 | |
| 3904 | return RValue<Int>(value); |
| 3905 | } |
| 3906 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3907 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3908 | { |
| 3909 | Value *value = rhs.loadValue(); |
| 3910 | storeValue(value); |
| 3911 | |
| 3912 | return RValue<Int>(value); |
| 3913 | } |
| 3914 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3915 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3916 | { |
| 3917 | Value *value = rhs.loadValue(); |
| 3918 | storeValue(value); |
| 3919 | |
| 3920 | return RValue<Int>(value); |
| 3921 | } |
| 3922 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3923 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3924 | { |
| 3925 | Value *value = rhs.loadValue(); |
| 3926 | storeValue(value); |
| 3927 | |
| 3928 | return RValue<Int>(value); |
| 3929 | } |
| 3930 | |
| 3931 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3932 | { |
| 3933 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3934 | } |
| 3935 | |
| 3936 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3937 | { |
| 3938 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3939 | } |
| 3940 | |
| 3941 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3942 | { |
| 3943 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3944 | } |
| 3945 | |
| 3946 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3947 | { |
| 3948 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3949 | } |
| 3950 | |
| 3951 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3952 | { |
| 3953 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3954 | } |
| 3955 | |
| 3956 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3957 | { |
| 3958 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3959 | } |
| 3960 | |
| 3961 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 3962 | { |
| 3963 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3964 | } |
| 3965 | |
| 3966 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 3967 | { |
| 3968 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3969 | } |
| 3970 | |
| 3971 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 3972 | { |
| 3973 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3974 | } |
| 3975 | |
| 3976 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 3977 | { |
| 3978 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3979 | } |
| 3980 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3981 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3982 | { |
| 3983 | return lhs = lhs + rhs; |
| 3984 | } |
| 3985 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3986 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3987 | { |
| 3988 | return lhs = lhs - rhs; |
| 3989 | } |
| 3990 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3991 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3992 | { |
| 3993 | return lhs = lhs * rhs; |
| 3994 | } |
| 3995 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3996 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3997 | { |
| 3998 | return lhs = lhs / rhs; |
| 3999 | } |
| 4000 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4001 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4002 | { |
| 4003 | return lhs = lhs % rhs; |
| 4004 | } |
| 4005 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4006 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4007 | { |
| 4008 | return lhs = lhs & rhs; |
| 4009 | } |
| 4010 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4011 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4012 | { |
| 4013 | return lhs = lhs | rhs; |
| 4014 | } |
| 4015 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4016 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4017 | { |
| 4018 | return lhs = lhs ^ rhs; |
| 4019 | } |
| 4020 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4021 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4022 | { |
| 4023 | return lhs = lhs << rhs; |
| 4024 | } |
| 4025 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4026 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4027 | { |
| 4028 | return lhs = lhs >> rhs; |
| 4029 | } |
| 4030 | |
| 4031 | RValue<Int> operator+(RValue<Int> val) |
| 4032 | { |
| 4033 | return val; |
| 4034 | } |
| 4035 | |
| 4036 | RValue<Int> operator-(RValue<Int> val) |
| 4037 | { |
| 4038 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4039 | } |
| 4040 | |
| 4041 | RValue<Int> operator~(RValue<Int> val) |
| 4042 | { |
| 4043 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4044 | } |
| 4045 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4046 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4047 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4048 | RValue<UInt> res = val; |
| 4049 | val += 1; |
| 4050 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4051 | } |
| 4052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4053 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4054 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4055 | val += 1; |
| 4056 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4057 | } |
| 4058 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4059 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4060 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4061 | RValue<Int> res = val; |
| 4062 | val -= 1; |
| 4063 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4064 | } |
| 4065 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4066 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4067 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4068 | val -= 1; |
| 4069 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4073 | { |
| 4074 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4075 | } |
| 4076 | |
| 4077 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4078 | { |
| 4079 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4080 | } |
| 4081 | |
| 4082 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4083 | { |
| 4084 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4085 | } |
| 4086 | |
| 4087 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4088 | { |
| 4089 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4090 | } |
| 4091 | |
| 4092 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4093 | { |
| 4094 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4095 | } |
| 4096 | |
| 4097 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4098 | { |
| 4099 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4100 | } |
| 4101 | |
| 4102 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4103 | { |
| 4104 | return IfThenElse(x > y, x, y); |
| 4105 | } |
| 4106 | |
| 4107 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4108 | { |
| 4109 | return IfThenElse(x < y, x, y); |
| 4110 | } |
| 4111 | |
| 4112 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4113 | { |
| 4114 | return Min(Max(x, min), max); |
| 4115 | } |
| 4116 | |
| 4117 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4118 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4119 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 4120 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, cast.value); |
| 4121 | ::basicBlock->appendInst(round); |
| 4122 | |
| 4123 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | Type *Int::getType() |
| 4127 | { |
| 4128 | return T(Ice::IceType_i32); |
| 4129 | } |
| 4130 | |
| 4131 | Long::Long(RValue<Int> cast) |
| 4132 | { |
| 4133 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4134 | |
| 4135 | storeValue(integer); |
| 4136 | } |
| 4137 | |
| 4138 | Long::Long(RValue<UInt> cast) |
| 4139 | { |
| 4140 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4141 | |
| 4142 | storeValue(integer); |
| 4143 | } |
| 4144 | |
| 4145 | Long::Long() |
| 4146 | { |
| 4147 | } |
| 4148 | |
| 4149 | Long::Long(RValue<Long> rhs) |
| 4150 | { |
| 4151 | storeValue(rhs.value); |
| 4152 | } |
| 4153 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4154 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4155 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4156 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4157 | } |
| 4158 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4159 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4160 | { |
| 4161 | storeValue(rhs.value); |
| 4162 | |
| 4163 | return rhs; |
| 4164 | } |
| 4165 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4166 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4167 | { |
| 4168 | Value *value = rhs.loadValue(); |
| 4169 | storeValue(value); |
| 4170 | |
| 4171 | return RValue<Long>(value); |
| 4172 | } |
| 4173 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4174 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4175 | { |
| 4176 | Value *value = rhs.loadValue(); |
| 4177 | storeValue(value); |
| 4178 | |
| 4179 | return RValue<Long>(value); |
| 4180 | } |
| 4181 | |
| 4182 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4183 | { |
| 4184 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4185 | } |
| 4186 | |
| 4187 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4188 | { |
| 4189 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4190 | } |
| 4191 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4192 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4193 | { |
| 4194 | return lhs = lhs + rhs; |
| 4195 | } |
| 4196 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4197 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4198 | { |
| 4199 | return lhs = lhs - rhs; |
| 4200 | } |
| 4201 | |
| 4202 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4203 | { |
| 4204 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4205 | } |
| 4206 | |
| 4207 | Type *Long::getType() |
| 4208 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4209 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4210 | } |
| 4211 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4212 | UInt::UInt(Argument<UInt> argument) |
| 4213 | { |
| 4214 | storeValue(argument.value); |
| 4215 | } |
| 4216 | |
| 4217 | UInt::UInt(RValue<UShort> cast) |
| 4218 | { |
| 4219 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4220 | |
| 4221 | storeValue(integer); |
| 4222 | } |
| 4223 | |
| 4224 | UInt::UInt(RValue<Long> cast) |
| 4225 | { |
| 4226 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4227 | |
| 4228 | storeValue(integer); |
| 4229 | } |
| 4230 | |
| 4231 | UInt::UInt(RValue<Float> cast) |
| 4232 | { |
| 4233 | assert(false && "UNIMPLEMENTED"); |
| 4234 | } |
| 4235 | |
| 4236 | UInt::UInt() |
| 4237 | { |
| 4238 | } |
| 4239 | |
| 4240 | UInt::UInt(int x) |
| 4241 | { |
| 4242 | storeValue(Nucleus::createConstantInt(x)); |
| 4243 | } |
| 4244 | |
| 4245 | UInt::UInt(unsigned int x) |
| 4246 | { |
| 4247 | storeValue(Nucleus::createConstantInt(x)); |
| 4248 | } |
| 4249 | |
| 4250 | UInt::UInt(RValue<UInt> rhs) |
| 4251 | { |
| 4252 | storeValue(rhs.value); |
| 4253 | } |
| 4254 | |
| 4255 | UInt::UInt(RValue<Int> rhs) |
| 4256 | { |
| 4257 | storeValue(rhs.value); |
| 4258 | } |
| 4259 | |
| 4260 | UInt::UInt(const UInt &rhs) |
| 4261 | { |
| 4262 | Value *value = rhs.loadValue(); |
| 4263 | storeValue(value); |
| 4264 | } |
| 4265 | |
| 4266 | UInt::UInt(const Reference<UInt> &rhs) |
| 4267 | { |
| 4268 | Value *value = rhs.loadValue(); |
| 4269 | storeValue(value); |
| 4270 | } |
| 4271 | |
| 4272 | UInt::UInt(const Int &rhs) |
| 4273 | { |
| 4274 | Value *value = rhs.loadValue(); |
| 4275 | storeValue(value); |
| 4276 | } |
| 4277 | |
| 4278 | UInt::UInt(const Reference<Int> &rhs) |
| 4279 | { |
| 4280 | Value *value = rhs.loadValue(); |
| 4281 | storeValue(value); |
| 4282 | } |
| 4283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4284 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4285 | { |
| 4286 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4287 | } |
| 4288 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4289 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4290 | { |
| 4291 | storeValue(rhs.value); |
| 4292 | |
| 4293 | return rhs; |
| 4294 | } |
| 4295 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4296 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4297 | { |
| 4298 | storeValue(rhs.value); |
| 4299 | |
| 4300 | return RValue<UInt>(rhs); |
| 4301 | } |
| 4302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4303 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4304 | { |
| 4305 | Value *value = rhs.loadValue(); |
| 4306 | storeValue(value); |
| 4307 | |
| 4308 | return RValue<UInt>(value); |
| 4309 | } |
| 4310 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4311 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4312 | { |
| 4313 | Value *value = rhs.loadValue(); |
| 4314 | storeValue(value); |
| 4315 | |
| 4316 | return RValue<UInt>(value); |
| 4317 | } |
| 4318 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4319 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4320 | { |
| 4321 | Value *value = rhs.loadValue(); |
| 4322 | storeValue(value); |
| 4323 | |
| 4324 | return RValue<UInt>(value); |
| 4325 | } |
| 4326 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4327 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4328 | { |
| 4329 | Value *value = rhs.loadValue(); |
| 4330 | storeValue(value); |
| 4331 | |
| 4332 | return RValue<UInt>(value); |
| 4333 | } |
| 4334 | |
| 4335 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4336 | { |
| 4337 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4338 | } |
| 4339 | |
| 4340 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4341 | { |
| 4342 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4343 | } |
| 4344 | |
| 4345 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4346 | { |
| 4347 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4348 | } |
| 4349 | |
| 4350 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4351 | { |
| 4352 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4353 | } |
| 4354 | |
| 4355 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4356 | { |
| 4357 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4358 | } |
| 4359 | |
| 4360 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4361 | { |
| 4362 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4363 | } |
| 4364 | |
| 4365 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4366 | { |
| 4367 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4368 | } |
| 4369 | |
| 4370 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4371 | { |
| 4372 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4373 | } |
| 4374 | |
| 4375 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4376 | { |
| 4377 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4378 | } |
| 4379 | |
| 4380 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4381 | { |
| 4382 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4383 | } |
| 4384 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4385 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4386 | { |
| 4387 | return lhs = lhs + rhs; |
| 4388 | } |
| 4389 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4390 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4391 | { |
| 4392 | return lhs = lhs - rhs; |
| 4393 | } |
| 4394 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4395 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4396 | { |
| 4397 | return lhs = lhs * rhs; |
| 4398 | } |
| 4399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4400 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4401 | { |
| 4402 | return lhs = lhs / rhs; |
| 4403 | } |
| 4404 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4405 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4406 | { |
| 4407 | return lhs = lhs % rhs; |
| 4408 | } |
| 4409 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4410 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4411 | { |
| 4412 | return lhs = lhs & rhs; |
| 4413 | } |
| 4414 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4415 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4416 | { |
| 4417 | return lhs = lhs | rhs; |
| 4418 | } |
| 4419 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4420 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4421 | { |
| 4422 | return lhs = lhs ^ rhs; |
| 4423 | } |
| 4424 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4425 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4426 | { |
| 4427 | return lhs = lhs << rhs; |
| 4428 | } |
| 4429 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4430 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4431 | { |
| 4432 | return lhs = lhs >> rhs; |
| 4433 | } |
| 4434 | |
| 4435 | RValue<UInt> operator+(RValue<UInt> val) |
| 4436 | { |
| 4437 | return val; |
| 4438 | } |
| 4439 | |
| 4440 | RValue<UInt> operator-(RValue<UInt> val) |
| 4441 | { |
| 4442 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4443 | } |
| 4444 | |
| 4445 | RValue<UInt> operator~(RValue<UInt> val) |
| 4446 | { |
| 4447 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4448 | } |
| 4449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4450 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4451 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4452 | RValue<UInt> res = val; |
| 4453 | val += 1; |
| 4454 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4455 | } |
| 4456 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4457 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4458 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4459 | val += 1; |
| 4460 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4461 | } |
| 4462 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4463 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4464 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4465 | RValue<UInt> res = val; |
| 4466 | val -= 1; |
| 4467 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4468 | } |
| 4469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4470 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4471 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4472 | val -= 1; |
| 4473 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4474 | } |
| 4475 | |
| 4476 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4477 | { |
| 4478 | return IfThenElse(x > y, x, y); |
| 4479 | } |
| 4480 | |
| 4481 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4482 | { |
| 4483 | return IfThenElse(x < y, x, y); |
| 4484 | } |
| 4485 | |
| 4486 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4487 | { |
| 4488 | return Min(Max(x, min), max); |
| 4489 | } |
| 4490 | |
| 4491 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4492 | { |
| 4493 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4494 | } |
| 4495 | |
| 4496 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4497 | { |
| 4498 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4499 | } |
| 4500 | |
| 4501 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4502 | { |
| 4503 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4504 | } |
| 4505 | |
| 4506 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4507 | { |
| 4508 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4509 | } |
| 4510 | |
| 4511 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4512 | { |
| 4513 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4514 | } |
| 4515 | |
| 4516 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4517 | { |
| 4518 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4519 | } |
| 4520 | |
| 4521 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4522 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4523 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4524 | // } |
| 4525 | |
| 4526 | Type *UInt::getType() |
| 4527 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4528 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | // Int2::Int2(RValue<Int> cast) |
| 4532 | // { |
| 4533 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4534 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4535 | // |
| 4536 | // Constant *shuffle[2]; |
| 4537 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4538 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4539 | // |
| 4540 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4541 | // |
| 4542 | // storeValue(replicate); |
| 4543 | // } |
| 4544 | |
| 4545 | Int2::Int2(RValue<Int4> cast) |
| 4546 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4547 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | Int2::Int2() |
| 4551 | { |
| 4552 | // xy.parent = this; |
| 4553 | } |
| 4554 | |
| 4555 | Int2::Int2(int x, int y) |
| 4556 | { |
| 4557 | // xy.parent = this; |
| 4558 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4559 | int64_t constantVector[2] = {x, y}; |
| 4560 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | Int2::Int2(RValue<Int2> rhs) |
| 4564 | { |
| 4565 | // xy.parent = this; |
| 4566 | |
| 4567 | storeValue(rhs.value); |
| 4568 | } |
| 4569 | |
| 4570 | Int2::Int2(const Int2 &rhs) |
| 4571 | { |
| 4572 | // xy.parent = this; |
| 4573 | |
| 4574 | Value *value = rhs.loadValue(); |
| 4575 | storeValue(value); |
| 4576 | } |
| 4577 | |
| 4578 | Int2::Int2(const Reference<Int2> &rhs) |
| 4579 | { |
| 4580 | // xy.parent = this; |
| 4581 | |
| 4582 | Value *value = rhs.loadValue(); |
| 4583 | storeValue(value); |
| 4584 | } |
| 4585 | |
| 4586 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4587 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4588 | int shuffle[4] = {0, 4, 1, 5}; |
| 4589 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4590 | |
| 4591 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4592 | } |
| 4593 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4594 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4595 | { |
| 4596 | storeValue(rhs.value); |
| 4597 | |
| 4598 | return rhs; |
| 4599 | } |
| 4600 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4601 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4602 | { |
| 4603 | Value *value = rhs.loadValue(); |
| 4604 | storeValue(value); |
| 4605 | |
| 4606 | return RValue<Int2>(value); |
| 4607 | } |
| 4608 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4609 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4610 | { |
| 4611 | Value *value = rhs.loadValue(); |
| 4612 | storeValue(value); |
| 4613 | |
| 4614 | return RValue<Int2>(value); |
| 4615 | } |
| 4616 | |
| 4617 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4618 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4619 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4623 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4624 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4628 | // { |
| 4629 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4630 | // } |
| 4631 | |
| 4632 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4633 | // { |
| 4634 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4635 | // } |
| 4636 | |
| 4637 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4638 | // { |
| 4639 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4640 | // } |
| 4641 | |
| 4642 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4643 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4644 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4648 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4649 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4653 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4654 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4658 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 4659 | return RValue<Int2>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4663 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 4664 | return RValue<Int2>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4665 | } |
| 4666 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4667 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4668 | { |
| 4669 | return lhs = lhs + rhs; |
| 4670 | } |
| 4671 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4672 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4673 | { |
| 4674 | return lhs = lhs - rhs; |
| 4675 | } |
| 4676 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4677 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4678 | // { |
| 4679 | // return lhs = lhs * rhs; |
| 4680 | // } |
| 4681 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4682 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4683 | // { |
| 4684 | // return lhs = lhs / rhs; |
| 4685 | // } |
| 4686 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4687 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4688 | // { |
| 4689 | // return lhs = lhs % rhs; |
| 4690 | // } |
| 4691 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4692 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4693 | { |
| 4694 | return lhs = lhs & rhs; |
| 4695 | } |
| 4696 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4697 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4698 | { |
| 4699 | return lhs = lhs | rhs; |
| 4700 | } |
| 4701 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4702 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4703 | { |
| 4704 | return lhs = lhs ^ rhs; |
| 4705 | } |
| 4706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4707 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4708 | { |
| 4709 | return lhs = lhs << rhs; |
| 4710 | } |
| 4711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4712 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4713 | { |
| 4714 | return lhs = lhs >> rhs; |
| 4715 | } |
| 4716 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4717 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4718 | // { |
| 4719 | // return val; |
| 4720 | // } |
| 4721 | |
| 4722 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4723 | // { |
| 4724 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4725 | // } |
| 4726 | |
| 4727 | RValue<Int2> operator~(RValue<Int2> val) |
| 4728 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4729 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4730 | } |
| 4731 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame^] | 4732 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4733 | { |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame^] | 4734 | assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4735 | } |
| 4736 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame^] | 4737 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4738 | { |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame^] | 4739 | assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4743 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4744 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4748 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4749 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | Type *Int2::getType() |
| 4753 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4754 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | UInt2::UInt2() |
| 4758 | { |
| 4759 | // xy.parent = this; |
| 4760 | } |
| 4761 | |
| 4762 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4763 | { |
| 4764 | // xy.parent = this; |
| 4765 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4766 | int64_t constantVector[2] = {x, y}; |
| 4767 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4771 | { |
| 4772 | // xy.parent = this; |
| 4773 | |
| 4774 | storeValue(rhs.value); |
| 4775 | } |
| 4776 | |
| 4777 | UInt2::UInt2(const UInt2 &rhs) |
| 4778 | { |
| 4779 | // xy.parent = this; |
| 4780 | |
| 4781 | Value *value = rhs.loadValue(); |
| 4782 | storeValue(value); |
| 4783 | } |
| 4784 | |
| 4785 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4786 | { |
| 4787 | // xy.parent = this; |
| 4788 | |
| 4789 | Value *value = rhs.loadValue(); |
| 4790 | storeValue(value); |
| 4791 | } |
| 4792 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4793 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4794 | { |
| 4795 | storeValue(rhs.value); |
| 4796 | |
| 4797 | return rhs; |
| 4798 | } |
| 4799 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4800 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4801 | { |
| 4802 | Value *value = rhs.loadValue(); |
| 4803 | storeValue(value); |
| 4804 | |
| 4805 | return RValue<UInt2>(value); |
| 4806 | } |
| 4807 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4808 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4809 | { |
| 4810 | Value *value = rhs.loadValue(); |
| 4811 | storeValue(value); |
| 4812 | |
| 4813 | return RValue<UInt2>(value); |
| 4814 | } |
| 4815 | |
| 4816 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4817 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4818 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4822 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4823 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4824 | } |
| 4825 | |
| 4826 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4827 | // { |
| 4828 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4829 | // } |
| 4830 | |
| 4831 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4832 | // { |
| 4833 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4834 | // } |
| 4835 | |
| 4836 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4837 | // { |
| 4838 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4839 | // } |
| 4840 | |
| 4841 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4842 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4843 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4847 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4848 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4852 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4853 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4857 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 4858 | return RValue<UInt2>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4862 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 4863 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4864 | } |
| 4865 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4866 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4867 | { |
| 4868 | return lhs = lhs + rhs; |
| 4869 | } |
| 4870 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4871 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4872 | { |
| 4873 | return lhs = lhs - rhs; |
| 4874 | } |
| 4875 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4876 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4877 | // { |
| 4878 | // return lhs = lhs * rhs; |
| 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, unsigned char 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, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4912 | { |
| 4913 | return lhs = lhs >> rhs; |
| 4914 | } |
| 4915 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4916 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4917 | // { |
| 4918 | // return val; |
| 4919 | // } |
| 4920 | |
| 4921 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4922 | // { |
| 4923 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4924 | // } |
| 4925 | |
| 4926 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4927 | { |
| 4928 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4929 | } |
| 4930 | |
| 4931 | Type *UInt2::getType() |
| 4932 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4933 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | Int4::Int4(RValue<Byte4> cast) |
| 4937 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4938 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4939 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4940 | |
| 4941 | Value *e; |
| 4942 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4943 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4944 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4945 | |
| 4946 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4947 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4948 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4949 | |
| 4950 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4951 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | Int4::Int4(RValue<SByte4> cast) |
| 4955 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4956 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4957 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4958 | |
| 4959 | Value *e; |
| 4960 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4961 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4962 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4963 | |
| 4964 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4965 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4966 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 4967 | |
| 4968 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4969 | Value *g = Nucleus::createAShr(f, C(::context->getConstantInt32(24))); |
| 4970 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | Int4::Int4(RValue<Float4> cast) |
| 4974 | { |
| 4975 | // xyzw.parent = this; |
| 4976 | |
| 4977 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 4978 | |
| 4979 | storeValue(xyzw); |
| 4980 | } |
| 4981 | |
| 4982 | Int4::Int4(RValue<Short4> cast) |
| 4983 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4984 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4985 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 4986 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4987 | Value *e = Nucleus::createAShr(d, C(::context->getConstantInt32(16))); |
| 4988 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | Int4::Int4(RValue<UShort4> cast) |
| 4992 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4993 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4994 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 4995 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4996 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | Int4::Int4() |
| 5000 | { |
| 5001 | // xyzw.parent = this; |
| 5002 | } |
| 5003 | |
| 5004 | Int4::Int4(int xyzw) |
| 5005 | { |
| 5006 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5007 | } |
| 5008 | |
| 5009 | Int4::Int4(int x, int yzw) |
| 5010 | { |
| 5011 | constant(x, yzw, yzw, yzw); |
| 5012 | } |
| 5013 | |
| 5014 | Int4::Int4(int x, int y, int zw) |
| 5015 | { |
| 5016 | constant(x, y, zw, zw); |
| 5017 | } |
| 5018 | |
| 5019 | Int4::Int4(int x, int y, int z, int w) |
| 5020 | { |
| 5021 | constant(x, y, z, w); |
| 5022 | } |
| 5023 | |
| 5024 | void Int4::constant(int x, int y, int z, int w) |
| 5025 | { |
| 5026 | // xyzw.parent = this; |
| 5027 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5028 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5029 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | Int4::Int4(RValue<Int4> rhs) |
| 5033 | { |
| 5034 | // xyzw.parent = this; |
| 5035 | |
| 5036 | storeValue(rhs.value); |
| 5037 | } |
| 5038 | |
| 5039 | Int4::Int4(const Int4 &rhs) |
| 5040 | { |
| 5041 | // xyzw.parent = this; |
| 5042 | |
| 5043 | Value *value = rhs.loadValue(); |
| 5044 | storeValue(value); |
| 5045 | } |
| 5046 | |
| 5047 | Int4::Int4(const Reference<Int4> &rhs) |
| 5048 | { |
| 5049 | // xyzw.parent = this; |
| 5050 | |
| 5051 | Value *value = rhs.loadValue(); |
| 5052 | storeValue(value); |
| 5053 | } |
| 5054 | |
| 5055 | Int4::Int4(RValue<UInt4> rhs) |
| 5056 | { |
| 5057 | // xyzw.parent = this; |
| 5058 | |
| 5059 | storeValue(rhs.value); |
| 5060 | } |
| 5061 | |
| 5062 | Int4::Int4(const UInt4 &rhs) |
| 5063 | { |
| 5064 | // xyzw.parent = this; |
| 5065 | |
| 5066 | Value *value = rhs.loadValue(); |
| 5067 | storeValue(value); |
| 5068 | } |
| 5069 | |
| 5070 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5071 | { |
| 5072 | // xyzw.parent = this; |
| 5073 | |
| 5074 | Value *value = rhs.loadValue(); |
| 5075 | storeValue(value); |
| 5076 | } |
| 5077 | |
| 5078 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5079 | { |
| 5080 | assert(false && "UNIMPLEMENTED"); |
| 5081 | } |
| 5082 | |
| 5083 | Int4::Int4(RValue<Int> rhs) |
| 5084 | { |
| 5085 | // xyzw.parent = this; |
| 5086 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5087 | Value *vector = loadValue(); |
| 5088 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5089 | |
| 5090 | int swizzle[4] = {0, 0, 0, 0}; |
| 5091 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 5092 | |
| 5093 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | Int4::Int4(const Int &rhs) |
| 5097 | { |
| 5098 | // xyzw.parent = this; |
| 5099 | |
| 5100 | *this = RValue<Int>(rhs.loadValue()); |
| 5101 | } |
| 5102 | |
| 5103 | Int4::Int4(const Reference<Int> &rhs) |
| 5104 | { |
| 5105 | // xyzw.parent = this; |
| 5106 | |
| 5107 | *this = RValue<Int>(rhs.loadValue()); |
| 5108 | } |
| 5109 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5110 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5111 | { |
| 5112 | storeValue(rhs.value); |
| 5113 | |
| 5114 | return rhs; |
| 5115 | } |
| 5116 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5117 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5118 | { |
| 5119 | Value *value = rhs.loadValue(); |
| 5120 | storeValue(value); |
| 5121 | |
| 5122 | return RValue<Int4>(value); |
| 5123 | } |
| 5124 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5125 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5126 | { |
| 5127 | Value *value = rhs.loadValue(); |
| 5128 | storeValue(value); |
| 5129 | |
| 5130 | return RValue<Int4>(value); |
| 5131 | } |
| 5132 | |
| 5133 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5134 | { |
| 5135 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5136 | } |
| 5137 | |
| 5138 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5139 | { |
| 5140 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5141 | } |
| 5142 | |
| 5143 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5144 | { |
| 5145 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5146 | } |
| 5147 | |
| 5148 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5149 | { |
| 5150 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5151 | } |
| 5152 | |
| 5153 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5154 | { |
| 5155 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5156 | } |
| 5157 | |
| 5158 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5159 | { |
| 5160 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5161 | } |
| 5162 | |
| 5163 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5164 | { |
| 5165 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5166 | } |
| 5167 | |
| 5168 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5169 | { |
| 5170 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5171 | } |
| 5172 | |
| 5173 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5174 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 5175 | return RValue<Int4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5179 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 5180 | return RValue<Int4>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5184 | { |
| 5185 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5186 | } |
| 5187 | |
| 5188 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5189 | { |
| 5190 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5191 | } |
| 5192 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5193 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5194 | { |
| 5195 | return lhs = lhs + rhs; |
| 5196 | } |
| 5197 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5198 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5199 | { |
| 5200 | return lhs = lhs - rhs; |
| 5201 | } |
| 5202 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5203 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5204 | { |
| 5205 | return lhs = lhs * rhs; |
| 5206 | } |
| 5207 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5208 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5209 | // { |
| 5210 | // return lhs = lhs / rhs; |
| 5211 | // } |
| 5212 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5213 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5214 | // { |
| 5215 | // return lhs = lhs % rhs; |
| 5216 | // } |
| 5217 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5218 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5219 | { |
| 5220 | return lhs = lhs & rhs; |
| 5221 | } |
| 5222 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5223 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5224 | { |
| 5225 | return lhs = lhs | rhs; |
| 5226 | } |
| 5227 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5228 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5229 | { |
| 5230 | return lhs = lhs ^ rhs; |
| 5231 | } |
| 5232 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5233 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5234 | { |
| 5235 | return lhs = lhs << rhs; |
| 5236 | } |
| 5237 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5238 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5239 | { |
| 5240 | return lhs = lhs >> rhs; |
| 5241 | } |
| 5242 | |
| 5243 | RValue<Int4> operator+(RValue<Int4> val) |
| 5244 | { |
| 5245 | return val; |
| 5246 | } |
| 5247 | |
| 5248 | RValue<Int4> operator-(RValue<Int4> val) |
| 5249 | { |
| 5250 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5251 | } |
| 5252 | |
| 5253 | RValue<Int4> operator~(RValue<Int4> val) |
| 5254 | { |
| 5255 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5256 | } |
| 5257 | |
| 5258 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5259 | { |
| 5260 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5261 | } |
| 5262 | |
| 5263 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5264 | { |
| 5265 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5266 | } |
| 5267 | |
| 5268 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5269 | { |
| 5270 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5271 | } |
| 5272 | |
| 5273 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5274 | { |
| 5275 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5276 | } |
| 5277 | |
| 5278 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5279 | { |
| 5280 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5281 | } |
| 5282 | |
| 5283 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5284 | { |
| 5285 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5286 | } |
| 5287 | |
| 5288 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5289 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5290 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5291 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5292 | ::basicBlock->appendInst(cmp); |
| 5293 | |
| 5294 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5295 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5296 | ::basicBlock->appendInst(select); |
| 5297 | |
| 5298 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5302 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5303 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5304 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5305 | ::basicBlock->appendInst(cmp); |
| 5306 | |
| 5307 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5308 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5309 | ::basicBlock->appendInst(select); |
| 5310 | |
| 5311 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5315 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5316 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5317 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, cast.value); |
| 5318 | ::basicBlock->appendInst(round); |
| 5319 | |
| 5320 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5324 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5325 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5326 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5327 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5328 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5329 | pack->addArg(x.value); |
| 5330 | pack->addArg(y.value); |
| 5331 | ::basicBlock->appendInst(pack); |
| 5332 | |
| 5333 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5337 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5338 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5342 | { |
| 5343 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5344 | } |
| 5345 | |
| 5346 | RValue<Int> SignMask(RValue<Int4> x) |
| 5347 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5348 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5349 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5350 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5351 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5352 | movmsk->addArg(x.value); |
| 5353 | ::basicBlock->appendInst(movmsk); |
| 5354 | |
| 5355 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5359 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5360 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | Type *Int4::getType() |
| 5364 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5365 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | UInt4::UInt4(RValue<Float4> cast) |
| 5369 | { |
| 5370 | // xyzw.parent = this; |
| 5371 | |
| 5372 | assert(false && "UNIMPLEMENTED"); |
| 5373 | } |
| 5374 | |
| 5375 | UInt4::UInt4() |
| 5376 | { |
| 5377 | // xyzw.parent = this; |
| 5378 | } |
| 5379 | |
| 5380 | UInt4::UInt4(int xyzw) |
| 5381 | { |
| 5382 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5383 | } |
| 5384 | |
| 5385 | UInt4::UInt4(int x, int yzw) |
| 5386 | { |
| 5387 | constant(x, yzw, yzw, yzw); |
| 5388 | } |
| 5389 | |
| 5390 | UInt4::UInt4(int x, int y, int zw) |
| 5391 | { |
| 5392 | constant(x, y, zw, zw); |
| 5393 | } |
| 5394 | |
| 5395 | UInt4::UInt4(int x, int y, int z, int w) |
| 5396 | { |
| 5397 | constant(x, y, z, w); |
| 5398 | } |
| 5399 | |
| 5400 | void UInt4::constant(int x, int y, int z, int w) |
| 5401 | { |
| 5402 | // xyzw.parent = this; |
| 5403 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5404 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5405 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5406 | } |
| 5407 | |
| 5408 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5409 | { |
| 5410 | // xyzw.parent = this; |
| 5411 | |
| 5412 | storeValue(rhs.value); |
| 5413 | } |
| 5414 | |
| 5415 | UInt4::UInt4(const UInt4 &rhs) |
| 5416 | { |
| 5417 | // xyzw.parent = this; |
| 5418 | |
| 5419 | Value *value = rhs.loadValue(); |
| 5420 | storeValue(value); |
| 5421 | } |
| 5422 | |
| 5423 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5424 | { |
| 5425 | // xyzw.parent = this; |
| 5426 | |
| 5427 | Value *value = rhs.loadValue(); |
| 5428 | storeValue(value); |
| 5429 | } |
| 5430 | |
| 5431 | UInt4::UInt4(RValue<Int4> rhs) |
| 5432 | { |
| 5433 | // xyzw.parent = this; |
| 5434 | |
| 5435 | storeValue(rhs.value); |
| 5436 | } |
| 5437 | |
| 5438 | UInt4::UInt4(const Int4 &rhs) |
| 5439 | { |
| 5440 | // xyzw.parent = this; |
| 5441 | |
| 5442 | Value *value = rhs.loadValue(); |
| 5443 | storeValue(value); |
| 5444 | } |
| 5445 | |
| 5446 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5447 | { |
| 5448 | // xyzw.parent = this; |
| 5449 | |
| 5450 | Value *value = rhs.loadValue(); |
| 5451 | storeValue(value); |
| 5452 | } |
| 5453 | |
| 5454 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5455 | { |
| 5456 | assert(false && "UNIMPLEMENTED"); |
| 5457 | } |
| 5458 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5459 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5460 | { |
| 5461 | storeValue(rhs.value); |
| 5462 | |
| 5463 | return rhs; |
| 5464 | } |
| 5465 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5466 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5467 | { |
| 5468 | Value *value = rhs.loadValue(); |
| 5469 | storeValue(value); |
| 5470 | |
| 5471 | return RValue<UInt4>(value); |
| 5472 | } |
| 5473 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5474 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5475 | { |
| 5476 | Value *value = rhs.loadValue(); |
| 5477 | storeValue(value); |
| 5478 | |
| 5479 | return RValue<UInt4>(value); |
| 5480 | } |
| 5481 | |
| 5482 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5483 | { |
| 5484 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5485 | } |
| 5486 | |
| 5487 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5488 | { |
| 5489 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5490 | } |
| 5491 | |
| 5492 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5493 | { |
| 5494 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5495 | } |
| 5496 | |
| 5497 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5498 | { |
| 5499 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5500 | } |
| 5501 | |
| 5502 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5503 | { |
| 5504 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5505 | } |
| 5506 | |
| 5507 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5508 | { |
| 5509 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5510 | } |
| 5511 | |
| 5512 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5513 | { |
| 5514 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5515 | } |
| 5516 | |
| 5517 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5518 | { |
| 5519 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5520 | } |
| 5521 | |
| 5522 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5523 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 5524 | return RValue<UInt4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5528 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 5529 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5533 | { |
| 5534 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5535 | } |
| 5536 | |
| 5537 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5538 | { |
| 5539 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5540 | } |
| 5541 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5542 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5543 | { |
| 5544 | return lhs = lhs + rhs; |
| 5545 | } |
| 5546 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5547 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5548 | { |
| 5549 | return lhs = lhs - rhs; |
| 5550 | } |
| 5551 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5552 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5553 | { |
| 5554 | return lhs = lhs * rhs; |
| 5555 | } |
| 5556 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5557 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5558 | // { |
| 5559 | // return lhs = lhs / rhs; |
| 5560 | // } |
| 5561 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5562 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5563 | // { |
| 5564 | // return lhs = lhs % rhs; |
| 5565 | // } |
| 5566 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5567 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5568 | { |
| 5569 | return lhs = lhs & rhs; |
| 5570 | } |
| 5571 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5572 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5573 | { |
| 5574 | return lhs = lhs | rhs; |
| 5575 | } |
| 5576 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5577 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5578 | { |
| 5579 | return lhs = lhs ^ rhs; |
| 5580 | } |
| 5581 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5582 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5583 | { |
| 5584 | return lhs = lhs << rhs; |
| 5585 | } |
| 5586 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5587 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5588 | { |
| 5589 | return lhs = lhs >> rhs; |
| 5590 | } |
| 5591 | |
| 5592 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5593 | { |
| 5594 | return val; |
| 5595 | } |
| 5596 | |
| 5597 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5598 | { |
| 5599 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5600 | } |
| 5601 | |
| 5602 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5603 | { |
| 5604 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5605 | } |
| 5606 | |
| 5607 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5608 | { |
| 5609 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5610 | } |
| 5611 | |
| 5612 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5613 | { |
| 5614 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 5615 | } |
| 5616 | |
| 5617 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5618 | { |
| 5619 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 5620 | } |
| 5621 | |
| 5622 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5623 | { |
| 5624 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5625 | } |
| 5626 | |
| 5627 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5628 | { |
| 5629 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 5630 | } |
| 5631 | |
| 5632 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5633 | { |
| 5634 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 5635 | } |
| 5636 | |
| 5637 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5638 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5639 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5640 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5641 | ::basicBlock->appendInst(cmp); |
| 5642 | |
| 5643 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5644 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5645 | ::basicBlock->appendInst(select); |
| 5646 | |
| 5647 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5651 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5652 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5653 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5654 | ::basicBlock->appendInst(cmp); |
| 5655 | |
| 5656 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5657 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5658 | ::basicBlock->appendInst(select); |
| 5659 | |
| 5660 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5661 | } |
| 5662 | |
| 5663 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5664 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5665 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5666 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5667 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5668 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5669 | pack->addArg(x.value); |
| 5670 | pack->addArg(y.value); |
| 5671 | ::basicBlock->appendInst(pack); |
| 5672 | |
| 5673 | return RValue<UShort8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | Type *UInt4::getType() |
| 5677 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5678 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | Float::Float(RValue<Int> cast) |
| 5682 | { |
| 5683 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5684 | |
| 5685 | storeValue(integer); |
| 5686 | } |
| 5687 | |
| 5688 | Float::Float() |
| 5689 | { |
| 5690 | } |
| 5691 | |
| 5692 | Float::Float(float x) |
| 5693 | { |
| 5694 | storeValue(Nucleus::createConstantFloat(x)); |
| 5695 | } |
| 5696 | |
| 5697 | Float::Float(RValue<Float> rhs) |
| 5698 | { |
| 5699 | storeValue(rhs.value); |
| 5700 | } |
| 5701 | |
| 5702 | Float::Float(const Float &rhs) |
| 5703 | { |
| 5704 | Value *value = rhs.loadValue(); |
| 5705 | storeValue(value); |
| 5706 | } |
| 5707 | |
| 5708 | Float::Float(const Reference<Float> &rhs) |
| 5709 | { |
| 5710 | Value *value = rhs.loadValue(); |
| 5711 | storeValue(value); |
| 5712 | } |
| 5713 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5714 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5715 | { |
| 5716 | storeValue(rhs.value); |
| 5717 | |
| 5718 | return rhs; |
| 5719 | } |
| 5720 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5721 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5722 | { |
| 5723 | Value *value = rhs.loadValue(); |
| 5724 | storeValue(value); |
| 5725 | |
| 5726 | return RValue<Float>(value); |
| 5727 | } |
| 5728 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5729 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5730 | { |
| 5731 | Value *value = rhs.loadValue(); |
| 5732 | storeValue(value); |
| 5733 | |
| 5734 | return RValue<Float>(value); |
| 5735 | } |
| 5736 | |
| 5737 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5738 | { |
| 5739 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5740 | } |
| 5741 | |
| 5742 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5743 | { |
| 5744 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5745 | } |
| 5746 | |
| 5747 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5748 | { |
| 5749 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5750 | } |
| 5751 | |
| 5752 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5753 | { |
| 5754 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5755 | } |
| 5756 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5757 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5758 | { |
| 5759 | return lhs = lhs + rhs; |
| 5760 | } |
| 5761 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5762 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5763 | { |
| 5764 | return lhs = lhs - rhs; |
| 5765 | } |
| 5766 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5767 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5768 | { |
| 5769 | return lhs = lhs * rhs; |
| 5770 | } |
| 5771 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5772 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5773 | { |
| 5774 | return lhs = lhs / rhs; |
| 5775 | } |
| 5776 | |
| 5777 | RValue<Float> operator+(RValue<Float> val) |
| 5778 | { |
| 5779 | return val; |
| 5780 | } |
| 5781 | |
| 5782 | RValue<Float> operator-(RValue<Float> val) |
| 5783 | { |
| 5784 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5785 | } |
| 5786 | |
| 5787 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5788 | { |
| 5789 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5790 | } |
| 5791 | |
| 5792 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5793 | { |
| 5794 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5795 | } |
| 5796 | |
| 5797 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5798 | { |
| 5799 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5800 | } |
| 5801 | |
| 5802 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5803 | { |
| 5804 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5805 | } |
| 5806 | |
| 5807 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5808 | { |
| 5809 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5810 | } |
| 5811 | |
| 5812 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5813 | { |
| 5814 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5815 | } |
| 5816 | |
| 5817 | RValue<Float> Abs(RValue<Float> x) |
| 5818 | { |
| 5819 | return IfThenElse(x > 0.0f, x, -x); |
| 5820 | } |
| 5821 | |
| 5822 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5823 | { |
| 5824 | return IfThenElse(x > y, x, y); |
| 5825 | } |
| 5826 | |
| 5827 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5828 | { |
| 5829 | return IfThenElse(x < y, x, y); |
| 5830 | } |
| 5831 | |
| 5832 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5833 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5834 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5838 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5839 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | RValue<Float> Sqrt(RValue<Float> x) |
| 5843 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5844 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5845 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5846 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5847 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5848 | sqrt->addArg(x.value); |
| 5849 | ::basicBlock->appendInst(sqrt); |
| 5850 | |
| 5851 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | RValue<Float> Round(RValue<Float> x) |
| 5855 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5856 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | RValue<Float> Trunc(RValue<Float> x) |
| 5860 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5861 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | RValue<Float> Frac(RValue<Float> x) |
| 5865 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5866 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | RValue<Float> Floor(RValue<Float> x) |
| 5870 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5871 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | RValue<Float> Ceil(RValue<Float> x) |
| 5875 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5876 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | Type *Float::getType() |
| 5880 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5881 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | Float2::Float2(RValue<Float4> cast) |
| 5885 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5886 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | Type *Float2::getType() |
| 5890 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5891 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | Float4::Float4(RValue<Byte4> cast) |
| 5895 | { |
| 5896 | xyzw.parent = this; |
| 5897 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5898 | Value *a = Int4(cast).loadValue(); |
| 5899 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5900 | |
| 5901 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | Float4::Float4(RValue<SByte4> cast) |
| 5905 | { |
| 5906 | xyzw.parent = this; |
| 5907 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5908 | Value *a = Int4(cast).loadValue(); |
| 5909 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5910 | |
| 5911 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | Float4::Float4(RValue<Short4> cast) |
| 5915 | { |
| 5916 | xyzw.parent = this; |
| 5917 | |
| 5918 | Int4 c(cast); |
| 5919 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5920 | } |
| 5921 | |
| 5922 | Float4::Float4(RValue<UShort4> cast) |
| 5923 | { |
| 5924 | xyzw.parent = this; |
| 5925 | |
| 5926 | Int4 c(cast); |
| 5927 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5928 | } |
| 5929 | |
| 5930 | Float4::Float4(RValue<Int4> cast) |
| 5931 | { |
| 5932 | xyzw.parent = this; |
| 5933 | |
| 5934 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5935 | |
| 5936 | storeValue(xyzw); |
| 5937 | } |
| 5938 | |
| 5939 | Float4::Float4(RValue<UInt4> cast) |
| 5940 | { |
| 5941 | xyzw.parent = this; |
| 5942 | |
| 5943 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); |
| 5944 | |
| 5945 | storeValue(xyzw); |
| 5946 | } |
| 5947 | |
| 5948 | Float4::Float4() |
| 5949 | { |
| 5950 | xyzw.parent = this; |
| 5951 | } |
| 5952 | |
| 5953 | Float4::Float4(float xyzw) |
| 5954 | { |
| 5955 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5956 | } |
| 5957 | |
| 5958 | Float4::Float4(float x, float yzw) |
| 5959 | { |
| 5960 | constant(x, yzw, yzw, yzw); |
| 5961 | } |
| 5962 | |
| 5963 | Float4::Float4(float x, float y, float zw) |
| 5964 | { |
| 5965 | constant(x, y, zw, zw); |
| 5966 | } |
| 5967 | |
| 5968 | Float4::Float4(float x, float y, float z, float w) |
| 5969 | { |
| 5970 | constant(x, y, z, w); |
| 5971 | } |
| 5972 | |
| 5973 | void Float4::constant(float x, float y, float z, float w) |
| 5974 | { |
| 5975 | xyzw.parent = this; |
| 5976 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5977 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5978 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | Float4::Float4(RValue<Float4> rhs) |
| 5982 | { |
| 5983 | xyzw.parent = this; |
| 5984 | |
| 5985 | storeValue(rhs.value); |
| 5986 | } |
| 5987 | |
| 5988 | Float4::Float4(const Float4 &rhs) |
| 5989 | { |
| 5990 | xyzw.parent = this; |
| 5991 | |
| 5992 | Value *value = rhs.loadValue(); |
| 5993 | storeValue(value); |
| 5994 | } |
| 5995 | |
| 5996 | Float4::Float4(const Reference<Float4> &rhs) |
| 5997 | { |
| 5998 | xyzw.parent = this; |
| 5999 | |
| 6000 | Value *value = rhs.loadValue(); |
| 6001 | storeValue(value); |
| 6002 | } |
| 6003 | |
| 6004 | Float4::Float4(RValue<Float> rhs) |
| 6005 | { |
| 6006 | xyzw.parent = this; |
| 6007 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6008 | Value *vector = loadValue(); |
| 6009 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 6010 | |
| 6011 | int swizzle[4] = {0, 0, 0, 0}; |
| 6012 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 6013 | |
| 6014 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | Float4::Float4(const Float &rhs) |
| 6018 | { |
| 6019 | xyzw.parent = this; |
| 6020 | |
| 6021 | *this = RValue<Float>(rhs.loadValue()); |
| 6022 | } |
| 6023 | |
| 6024 | Float4::Float4(const Reference<Float> &rhs) |
| 6025 | { |
| 6026 | xyzw.parent = this; |
| 6027 | |
| 6028 | *this = RValue<Float>(rhs.loadValue()); |
| 6029 | } |
| 6030 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6031 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6032 | { |
| 6033 | return *this = Float4(x, x, x, x); |
| 6034 | } |
| 6035 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6036 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6037 | { |
| 6038 | storeValue(rhs.value); |
| 6039 | |
| 6040 | return rhs; |
| 6041 | } |
| 6042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6043 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6044 | { |
| 6045 | Value *value = rhs.loadValue(); |
| 6046 | storeValue(value); |
| 6047 | |
| 6048 | return RValue<Float4>(value); |
| 6049 | } |
| 6050 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6051 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6052 | { |
| 6053 | Value *value = rhs.loadValue(); |
| 6054 | storeValue(value); |
| 6055 | |
| 6056 | return RValue<Float4>(value); |
| 6057 | } |
| 6058 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6059 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6060 | { |
| 6061 | return *this = Float4(rhs); |
| 6062 | } |
| 6063 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6064 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6065 | { |
| 6066 | return *this = Float4(rhs); |
| 6067 | } |
| 6068 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6069 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6070 | { |
| 6071 | return *this = Float4(rhs); |
| 6072 | } |
| 6073 | |
| 6074 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6075 | { |
| 6076 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6077 | } |
| 6078 | |
| 6079 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6080 | { |
| 6081 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6082 | } |
| 6083 | |
| 6084 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6085 | { |
| 6086 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6087 | } |
| 6088 | |
| 6089 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6090 | { |
| 6091 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6092 | } |
| 6093 | |
| 6094 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6095 | { |
| 6096 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6097 | } |
| 6098 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6099 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6100 | { |
| 6101 | return lhs = lhs + rhs; |
| 6102 | } |
| 6103 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6104 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6105 | { |
| 6106 | return lhs = lhs - rhs; |
| 6107 | } |
| 6108 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6109 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6110 | { |
| 6111 | return lhs = lhs * rhs; |
| 6112 | } |
| 6113 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6114 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6115 | { |
| 6116 | return lhs = lhs / rhs; |
| 6117 | } |
| 6118 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6119 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6120 | { |
| 6121 | return lhs = lhs % rhs; |
| 6122 | } |
| 6123 | |
| 6124 | RValue<Float4> operator+(RValue<Float4> val) |
| 6125 | { |
| 6126 | return val; |
| 6127 | } |
| 6128 | |
| 6129 | RValue<Float4> operator-(RValue<Float4> val) |
| 6130 | { |
| 6131 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6132 | } |
| 6133 | |
| 6134 | RValue<Float4> Abs(RValue<Float4> x) |
| 6135 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6136 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6137 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6138 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6139 | |
| 6140 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6144 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6145 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6146 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value); |
| 6147 | ::basicBlock->appendInst(cmp); |
| 6148 | |
| 6149 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6150 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6151 | ::basicBlock->appendInst(select); |
| 6152 | |
| 6153 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6157 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6158 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6159 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value); |
| 6160 | ::basicBlock->appendInst(cmp); |
| 6161 | |
| 6162 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6163 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6164 | ::basicBlock->appendInst(select); |
| 6165 | |
| 6166 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6167 | } |
| 6168 | |
| 6169 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6170 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6171 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6175 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6176 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6180 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6181 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6182 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6183 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6184 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6185 | sqrt->addArg(x.value); |
| 6186 | ::basicBlock->appendInst(sqrt); |
| 6187 | |
| 6188 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6189 | } |
| 6190 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6191 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6192 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6193 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6197 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6198 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6202 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6203 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6207 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6208 | int shuffle[4] = |
| 6209 | { |
| 6210 | ((imm >> 0) & 0x03) + 0, |
| 6211 | ((imm >> 2) & 0x03) + 0, |
| 6212 | ((imm >> 4) & 0x03) + 4, |
| 6213 | ((imm >> 6) & 0x03) + 4, |
| 6214 | }; |
| 6215 | |
| 6216 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6220 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6221 | int shuffle[4] = {0, 4, 1, 5}; |
| 6222 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6226 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6227 | int shuffle[4] = {2, 6, 3, 7}; |
| 6228 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6232 | { |
| 6233 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6234 | Value *result = createMask4(vector, rhs.value, select); |
| 6235 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6236 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6237 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | RValue<Int> SignMask(RValue<Float4> x) |
| 6241 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6242 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6243 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6244 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6245 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6246 | movmsk->addArg(x.value); |
| 6247 | ::basicBlock->appendInst(movmsk); |
| 6248 | |
| 6249 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6253 | { |
| 6254 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6255 | } |
| 6256 | |
| 6257 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6258 | { |
| 6259 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6260 | } |
| 6261 | |
| 6262 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6263 | { |
| 6264 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6265 | } |
| 6266 | |
| 6267 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6268 | { |
| 6269 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6270 | } |
| 6271 | |
| 6272 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6273 | { |
| 6274 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6275 | } |
| 6276 | |
| 6277 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6278 | { |
| 6279 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6280 | } |
| 6281 | |
| 6282 | RValue<Float4> Round(RValue<Float4> x) |
| 6283 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6284 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6285 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6286 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6287 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6288 | round->addArg(x.value); |
| 6289 | round->addArg(::context->getConstantInt32(0)); |
| 6290 | ::basicBlock->appendInst(round); |
| 6291 | |
| 6292 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6296 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6297 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6298 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6299 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6300 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6301 | round->addArg(x.value); |
| 6302 | round->addArg(::context->getConstantInt32(3)); |
| 6303 | ::basicBlock->appendInst(round); |
| 6304 | |
| 6305 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | RValue<Float4> Frac(RValue<Float4> x) |
| 6309 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6310 | return x - Floor(x); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | RValue<Float4> Floor(RValue<Float4> x) |
| 6314 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6315 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6316 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6317 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6318 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6319 | round->addArg(x.value); |
| 6320 | round->addArg(::context->getConstantInt32(1)); |
| 6321 | ::basicBlock->appendInst(round); |
| 6322 | |
| 6323 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6327 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6328 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6329 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6330 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6331 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6332 | round->addArg(x.value); |
| 6333 | round->addArg(::context->getConstantInt32(2)); |
| 6334 | ::basicBlock->appendInst(round); |
| 6335 | |
| 6336 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6337 | } |
| 6338 | |
| 6339 | Type *Float4::getType() |
| 6340 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6341 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6345 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6346 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6350 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6351 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6352 | } |
| 6353 | |
| 6354 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6355 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6356 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6357 | } |
| 6358 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6359 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6360 | { |
| 6361 | return lhs = lhs + offset; |
| 6362 | } |
| 6363 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6364 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6365 | { |
| 6366 | return lhs = lhs + offset; |
| 6367 | } |
| 6368 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6369 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6370 | { |
| 6371 | return lhs = lhs + offset; |
| 6372 | } |
| 6373 | |
| 6374 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6375 | { |
| 6376 | return lhs + -offset; |
| 6377 | } |
| 6378 | |
| 6379 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6380 | { |
| 6381 | return lhs + -offset; |
| 6382 | } |
| 6383 | |
| 6384 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6385 | { |
| 6386 | return lhs + -offset; |
| 6387 | } |
| 6388 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6389 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6390 | { |
| 6391 | return lhs = lhs - offset; |
| 6392 | } |
| 6393 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6394 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6395 | { |
| 6396 | return lhs = lhs - offset; |
| 6397 | } |
| 6398 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6399 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6400 | { |
| 6401 | return lhs = lhs - offset; |
| 6402 | } |
| 6403 | |
| 6404 | void Return() |
| 6405 | { |
| 6406 | Nucleus::createRetVoid(); |
| 6407 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6408 | Nucleus::createUnreachable(); |
| 6409 | } |
| 6410 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6411 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6412 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6413 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6414 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6415 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6416 | } |
| 6417 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6418 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
| 6419 | { |
| 6420 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6421 | Nucleus::setInsertBlock(bodyBB); |
| 6422 | |
| 6423 | return true; |
| 6424 | } |
| 6425 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6426 | RValue<Long> Ticks() |
| 6427 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6428 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6429 | } |
| 6430 | } |