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 | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 72 | class Value : public Ice::Operand {}; |
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 | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 92 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 93 | { |
| 94 | return reinterpret_cast<Value*>(v); |
| 95 | } |
| 96 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 97 | BasicBlock *B(Ice::CfgNode *b) |
| 98 | { |
| 99 | return reinterpret_cast<BasicBlock*>(b); |
| 100 | } |
| 101 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 102 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 103 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 104 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 105 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 106 | |
| 107 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 108 | { |
| 109 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 110 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 111 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 112 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 113 | { |
| 114 | return §ionHeader(elfHeader)[index]; |
| 115 | } |
| 116 | |
| 117 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 118 | { |
| 119 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 120 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 121 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 122 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 123 | uint32_t index = relocation.getSymbol(); |
| 124 | int table = relocationTable.sh_link; |
| 125 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 126 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 127 | if(index != SHN_UNDEF) |
| 128 | { |
| 129 | if(table == SHN_UNDEF) return nullptr; |
| 130 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 131 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 132 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 133 | if(index >= symtab_entries) |
| 134 | { |
| 135 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 136 | return nullptr; |
| 137 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 138 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 139 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 140 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 141 | uint16_t section = symbol.st_shndx; |
| 142 | |
| 143 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 144 | { |
| 145 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 146 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | return nullptr; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | switch(relocation.getType()) |
| 155 | { |
| 156 | case R_386_NONE: |
| 157 | // No relocation |
| 158 | break; |
| 159 | case R_386_32: |
| 160 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 161 | break; |
| 162 | // case R_386_PC32: |
| 163 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 164 | // break; |
| 165 | default: |
| 166 | assert(false && "Unsupported relocation type"); |
| 167 | return nullptr; |
| 168 | } |
| 169 | |
| 170 | return symbolValue; |
| 171 | } |
| 172 | |
| 173 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 174 | { |
| 175 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 176 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 177 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 178 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 179 | uint32_t index = relocation.getSymbol(); |
| 180 | int table = relocationTable.sh_link; |
| 181 | void *symbolValue = nullptr; |
| 182 | |
| 183 | if(index != SHN_UNDEF) |
| 184 | { |
| 185 | if(table == SHN_UNDEF) return nullptr; |
| 186 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 187 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 188 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 189 | if(index >= symtab_entries) |
| 190 | { |
| 191 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 192 | return nullptr; |
| 193 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 194 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 195 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 196 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 197 | uint16_t section = symbol.st_shndx; |
| 198 | |
| 199 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 200 | { |
| 201 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 202 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | return nullptr; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | switch(relocation.getType()) |
| 211 | { |
| 212 | case R_X86_64_NONE: |
| 213 | // No relocation |
| 214 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 215 | case R_X86_64_64: |
| 216 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 217 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 218 | case R_X86_64_PC32: |
| 219 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 220 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 221 | case R_X86_64_32S: |
| 222 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 223 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 224 | default: |
| 225 | assert(false && "Unsupported relocation type"); |
| 226 | return nullptr; |
| 227 | } |
| 228 | |
| 229 | return symbolValue; |
| 230 | } |
| 231 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 232 | void *loadImage(uint8_t *const elfImage) |
| 233 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 234 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 235 | |
| 236 | if(!elfHeader->checkMagic()) |
| 237 | { |
| 238 | return nullptr; |
| 239 | } |
| 240 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 241 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 242 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 243 | assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386); |
| 244 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 245 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 246 | void *entry = nullptr; |
| 247 | |
| 248 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 249 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 250 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 251 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 252 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 253 | { |
| 254 | entry = elfImage + sectionHeader[i].sh_offset; |
| 255 | } |
| 256 | } |
| 257 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 258 | { |
| 259 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 260 | |
| 261 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 262 | { |
| 263 | const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 264 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 265 | } |
| 266 | } |
| 267 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 268 | { |
| 269 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 270 | |
| 271 | for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
| 272 | { |
| 273 | const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index]; |
| 274 | void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
| 275 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | return entry; |
| 280 | } |
| 281 | |
| 282 | template<typename T> |
| 283 | struct ExecutableAllocator |
| 284 | { |
| 285 | ExecutableAllocator() {}; |
| 286 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 287 | |
| 288 | using value_type = T; |
| 289 | using size_type = std::size_t; |
| 290 | |
| 291 | T *allocate(size_type n) |
| 292 | { |
| 293 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 294 | } |
| 295 | |
| 296 | void deallocate(T *p, size_type n) |
| 297 | { |
| 298 | VirtualFree(p, 0, MEM_RELEASE); |
| 299 | } |
| 300 | }; |
| 301 | |
| 302 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 303 | { |
| 304 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 305 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 306 | |
| 307 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 308 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 309 | { |
| 310 | position = 0; |
| 311 | buffer.reserve(0x1000); |
| 312 | } |
| 313 | |
| 314 | virtual ~ELFMemoryStreamer() |
| 315 | { |
| 316 | if(buffer.size() != 0) |
| 317 | { |
| 318 | DWORD exeProtection; |
| 319 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | void write8(uint8_t Value) override |
| 324 | { |
| 325 | if(position == (uint64_t)buffer.size()) |
| 326 | { |
| 327 | buffer.push_back(Value); |
| 328 | position++; |
| 329 | } |
| 330 | else if(position < (uint64_t)buffer.size()) |
| 331 | { |
| 332 | buffer[position] = Value; |
| 333 | position++; |
| 334 | } |
| 335 | else assert(false && "UNIMPLEMENTED"); |
| 336 | } |
| 337 | |
| 338 | void writeBytes(llvm::StringRef Bytes) override |
| 339 | { |
| 340 | std::size_t oldSize = buffer.size(); |
| 341 | buffer.resize(oldSize + Bytes.size()); |
| 342 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 343 | position += Bytes.size(); |
| 344 | } |
| 345 | |
| 346 | uint64_t tell() const override { return position; } |
| 347 | |
| 348 | void seek(uint64_t Off) override { position = Off; } |
| 349 | |
| 350 | const void *getEntry() override |
| 351 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 352 | if(!entry) |
| 353 | { |
| 354 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection); |
| 355 | 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] | 356 | |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 357 | entry = loadImage(&buffer[0]); |
| 358 | } |
| 359 | |
| 360 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 364 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 365 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 366 | std::size_t position; |
| 367 | DWORD oldProtection; |
| 368 | }; |
| 369 | |
| 370 | Nucleus::Nucleus() |
| 371 | { |
| 372 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 373 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 374 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 375 | Ice::ClFlags::getParsedClFlags(Flags); |
| 376 | |
| 377 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 378 | Flags.setOutFileType(Ice::FT_Elf); |
| 379 | Flags.setOptLevel(Ice::Opt_2); |
| 380 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 381 | Flags.setTargetInstructionSet(Ice::X86InstructionSet_SSE4_1); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 382 | Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 383 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 384 | static llvm::raw_os_ostream cout(std::cout); |
| 385 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 386 | |
| 387 | if(false) // Write out to a file |
| 388 | { |
| 389 | std::error_code errorCode; |
| 390 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 391 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 392 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 393 | } |
| 394 | else |
| 395 | { |
| 396 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 397 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 398 | ::routine = elfMemory; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | Nucleus::~Nucleus() |
| 403 | { |
| 404 | delete ::allocator; |
| 405 | delete ::function; |
| 406 | delete ::context; |
| 407 | |
| 408 | delete ::elfFile; |
| 409 | delete ::out; |
| 410 | |
| 411 | ::codegenMutex.unlock(); |
| 412 | } |
| 413 | |
| 414 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 415 | { |
| 416 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 417 | { |
| 418 | createRetVoid(); |
| 419 | } |
| 420 | |
| 421 | std::wstring wideName(name); |
| 422 | std::string asciiName(wideName.begin(), wideName.end()); |
| 423 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 424 | |
| 425 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 426 | assert(!::function->hasError()); |
| 427 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 428 | auto *globals = ::function->getGlobalInits().release(); |
| 429 | |
| 430 | if(globals && !globals->empty()) |
| 431 | { |
| 432 | ::context->getGlobals()->merge(globals); |
| 433 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 434 | |
| 435 | ::context->emitFileHeader(); |
| 436 | ::function->emitIAS(); |
| 437 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 438 | auto objectWriter = ::context->getObjectWriter(); |
| 439 | assembler->alignFunction(); |
| 440 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 441 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 442 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 443 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 444 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 445 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 446 | |
| 447 | return ::routine; |
| 448 | } |
| 449 | |
| 450 | void Nucleus::optimize() |
| 451 | { |
| 452 | } |
| 453 | |
| 454 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 455 | { |
| 456 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 457 | int typeSize = Ice::typeWidthInBytes(type); |
| 458 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 459 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 460 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 461 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 462 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 463 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 464 | |
| 465 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | BasicBlock *Nucleus::createBasicBlock() |
| 469 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 470 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | BasicBlock *Nucleus::getInsertBlock() |
| 474 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 475 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 479 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 480 | // 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] | 481 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 482 | } |
| 483 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 484 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 485 | { |
| 486 | uint32_t sequenceNumber = 0; |
| 487 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 488 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 489 | |
| 490 | for(Type *type : Params) |
| 491 | { |
| 492 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 493 | ::function->addArg(arg); |
| 494 | } |
| 495 | |
| 496 | Ice::CfgNode *node = ::function->makeNode(); |
| 497 | ::function->setEntryNode(node); |
| 498 | ::basicBlock = node; |
| 499 | } |
| 500 | |
| 501 | Value *Nucleus::getArgument(unsigned int index) |
| 502 | { |
| 503 | return V(::function->getArgs()[index]); |
| 504 | } |
| 505 | |
| 506 | void Nucleus::createRetVoid() |
| 507 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 508 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 509 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void Nucleus::createRet(Value *v) |
| 513 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 514 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 515 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void Nucleus::createBr(BasicBlock *dest) |
| 519 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 520 | auto br = Ice::InstBr::create(::function, dest); |
| 521 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 525 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 526 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 527 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 528 | } |
| 529 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 530 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 531 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 532 | 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] | 533 | |
| 534 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
| 535 | Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs); |
| 536 | ::basicBlock->appendInst(arithmetic); |
| 537 | |
| 538 | return V(result); |
| 539 | } |
| 540 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 541 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 542 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 543 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 547 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 548 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 552 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 553 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 557 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 558 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 562 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 563 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 567 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 568 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 572 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 573 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 577 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 578 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 582 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 583 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 587 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 588 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 592 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 593 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 597 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 598 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 602 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 603 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 607 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 608 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 612 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 613 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 617 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 618 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 622 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 623 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 627 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 628 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 629 | } |
| 630 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 631 | static Ice::Variable *createAssign(Ice::Operand *constant) |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 632 | { |
| 633 | Ice::Variable *value = ::function->makeVariable(constant->getType()); |
| 634 | auto assign = Ice::InstAssign::create(::function, value, constant); |
| 635 | ::basicBlock->appendInst(assign); |
| 636 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 637 | return value; |
Nicolas Capens | b955d5b | 2016-09-28 22:36:28 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 640 | Value *Nucleus::createNeg(Value *v) |
| 641 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 642 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | Value *Nucleus::createFNeg(Value *v) |
| 646 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 647 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 648 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 649 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 650 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 651 | |
| 652 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | Value *Nucleus::createNot(Value *v) |
| 656 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 657 | if(Ice::isScalarIntegerType(v->getType())) |
| 658 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 659 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 660 | } |
| 661 | else // Vector |
| 662 | { |
| 663 | int64_t c[4] = {-1, -1, -1, -1}; |
| 664 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 665 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 668 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 669 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 670 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 671 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 672 | |
| 673 | if(valueType & EmulatedBits) |
| 674 | { |
| 675 | switch(valueType) |
| 676 | { |
| 677 | case Type_v4i8: |
| 678 | case Type_v2i16: |
| 679 | { |
| 680 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 681 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 682 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 683 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 684 | load->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 685 | ::basicBlock->appendInst(load); |
| 686 | } |
| 687 | break; |
| 688 | case Type_v2i32: |
| 689 | case Type_v8i8: |
| 690 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 691 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 692 | { |
| 693 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 694 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 695 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 696 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 697 | load->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 698 | ::basicBlock->appendInst(load); |
| 699 | } |
| 700 | break; |
| 701 | default: assert(false && "UNIMPLEMENTED"); |
| 702 | } |
| 703 | } |
| 704 | else |
| 705 | { |
| 706 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 707 | ::basicBlock->appendInst(load); |
| 708 | } |
| 709 | |
| 710 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 711 | } |
| 712 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 713 | 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] | 714 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 715 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 716 | |
| 717 | if(valueType & EmulatedBits) |
| 718 | { |
| 719 | switch(valueType) |
| 720 | { |
| 721 | case Type_v4i8: |
| 722 | case Type_v2i16: |
| 723 | { |
| 724 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 725 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 726 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 727 | store->addArg(value); |
| 728 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 729 | store->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 730 | ::basicBlock->appendInst(store); |
| 731 | } |
| 732 | break; |
| 733 | case Type_v2i32: |
| 734 | case Type_v8i8: |
| 735 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 736 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 737 | { |
| 738 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 739 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 740 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 741 | store->addArg(value); |
| 742 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 743 | store->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 744 | ::basicBlock->appendInst(store); |
| 745 | } |
| 746 | break; |
| 747 | default: assert(false && "UNIMPLEMENTED"); |
| 748 | } |
| 749 | } |
| 750 | else |
| 751 | { |
| 752 | assert(T(value->getType()) == type); |
| 753 | |
| 754 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 755 | ::basicBlock->appendInst(store); |
| 756 | } |
| 757 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 758 | return value; |
| 759 | } |
| 760 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 761 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 762 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 763 | assert(index->getType() == Ice::IceType_i32); |
| 764 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 765 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 766 | { |
| 767 | int32_t offset = constant->getValue() * (int)Ice::typeWidthInBytes(T(type)); |
| 768 | |
| 769 | if(offset == 0) |
| 770 | { |
| 771 | return ptr; |
| 772 | } |
| 773 | |
| 774 | return createAdd(ptr, createConstantInt(offset)); |
| 775 | } |
| 776 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 777 | if(!Ice::isByteSizedType(T(type))) |
| 778 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 779 | index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type)))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | if(sizeof(void*) == 8) |
| 783 | { |
| 784 | index = createSExt(index, T(Ice::IceType_i64)); |
| 785 | } |
| 786 | |
| 787 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 791 | { |
| 792 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 793 | } |
| 794 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 795 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 796 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 797 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 798 | { |
| 799 | return v; |
| 800 | } |
| 801 | |
| 802 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 803 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 804 | ::basicBlock->appendInst(cast); |
| 805 | |
| 806 | return V(result); |
| 807 | } |
| 808 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 809 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 810 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 811 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 815 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 816 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 820 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 821 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 825 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 826 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | Value *Nucleus::createUIToFP(Value *v, Type *destType) |
| 830 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 831 | return createCast(Ice::InstCast::Uitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 835 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 836 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 840 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 841 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 845 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 846 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 850 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 851 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 852 | } |
| 853 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 854 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 855 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 856 | assert(lhs->getType() == rhs->getType()); |
| 857 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 858 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 859 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 860 | ::basicBlock->appendInst(cmp); |
| 861 | |
| 862 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 865 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 866 | { |
| 867 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 868 | } |
| 869 | |
| 870 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 871 | { |
| 872 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 873 | } |
| 874 | |
| 875 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 876 | { |
| 877 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 878 | } |
| 879 | |
| 880 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 881 | { |
| 882 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 883 | } |
| 884 | |
| 885 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 886 | { |
| 887 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 888 | } |
| 889 | |
| 890 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 891 | { |
| 892 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 893 | } |
| 894 | |
| 895 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 896 | { |
| 897 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 898 | } |
| 899 | |
| 900 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 901 | { |
| 902 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 903 | } |
| 904 | |
| 905 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 906 | { |
| 907 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 908 | } |
| 909 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 910 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 911 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 912 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 913 | } |
| 914 | |
| 915 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 916 | { |
| 917 | assert(lhs->getType() == rhs->getType()); |
| 918 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 919 | |
| 920 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 921 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 922 | ::basicBlock->appendInst(cmp); |
| 923 | |
| 924 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 928 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 929 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 933 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 934 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 938 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 939 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 943 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 944 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 948 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 949 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 953 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 954 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 958 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 959 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 963 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 964 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 968 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 969 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 973 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 974 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 978 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 979 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 983 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 984 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 988 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 989 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 993 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 994 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 995 | } |
| 996 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 997 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 998 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 999 | auto result = ::function->makeVariable(T(type)); |
| 1000 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1001 | ::basicBlock->appendInst(extract); |
| 1002 | |
| 1003 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1007 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1008 | auto result = ::function->makeVariable(vector->getType()); |
| 1009 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1010 | ::basicBlock->appendInst(insert); |
| 1011 | |
| 1012 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1015 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1016 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1017 | assert(V1->getType() == V2->getType()); |
| 1018 | |
| 1019 | int size = Ice::typeNumElements(V1->getType()); |
| 1020 | auto result = ::function->makeVariable(V1->getType()); |
| 1021 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1022 | |
| 1023 | for(int i = 0; i < size; i++) |
| 1024 | { |
| 1025 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1026 | } |
| 1027 | |
| 1028 | ::basicBlock->appendInst(shuffle); |
| 1029 | |
| 1030 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1034 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1035 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1036 | |
| 1037 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1038 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1039 | ::basicBlock->appendInst(select); |
| 1040 | |
| 1041 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1044 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1045 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1046 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1047 | ::basicBlock->appendInst(switchInst); |
| 1048 | |
| 1049 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1052 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1053 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1054 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | void Nucleus::createUnreachable() |
| 1058 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1059 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1060 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1063 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1064 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1065 | int swizzle[4] = |
| 1066 | { |
| 1067 | (select >> 0) & 0x03, |
| 1068 | (select >> 2) & 0x03, |
| 1069 | (select >> 4) & 0x03, |
| 1070 | (select >> 6) & 0x03, |
| 1071 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1072 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1073 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1076 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1077 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1078 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1079 | |
| 1080 | mask[(select >> 0) & 0x03] = -1; |
| 1081 | mask[(select >> 2) & 0x03] = -1; |
| 1082 | mask[(select >> 4) & 0x03] = -1; |
| 1083 | mask[(select >> 6) & 0x03] = -1; |
| 1084 | |
| 1085 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1086 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1087 | |
| 1088 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1091 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1092 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1093 | if(sizeof(void*) == 8) |
| 1094 | { |
| 1095 | return T(Ice::IceType_i64); |
| 1096 | } |
| 1097 | else |
| 1098 | { |
| 1099 | return T(Ice::IceType_i32); |
| 1100 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1103 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1104 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1105 | if(Ice::isVectorType(T(Ty))) |
| 1106 | { |
| 1107 | int64_t c[4] = {0, 0, 0, 0}; |
| 1108 | return createConstantVector(c, Ty); |
| 1109 | } |
| 1110 | else |
| 1111 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1112 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1113 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1114 | } |
| 1115 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1116 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1117 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1118 | return V(::context->getConstantInt64(i)); |
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::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1122 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1123 | return V(::context->getConstantInt32(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(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1127 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1128 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1131 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1132 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1133 | return V(::context->getConstantInt1(b)); |
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::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1137 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1138 | return V(::context->getConstantInt8(i)); |
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(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1142 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1143 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1144 | } |
| 1145 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1146 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1147 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1148 | return V(::context->getConstantInt16(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(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1152 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1153 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1154 | } |
| 1155 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1156 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1157 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 1158 | return V(::context->getConstantFloat(x)); |
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::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1162 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1163 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1166 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1167 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1168 | const int vectorSize = 16; |
| 1169 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1170 | const int alignment = vectorSize; |
| 1171 | auto globalPool = ::function->getGlobalPool(); |
| 1172 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1173 | const int64_t *i = constants; |
| 1174 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1175 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1176 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1177 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1178 | { |
| 1179 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1180 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1181 | { |
| 1182 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1183 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1184 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1185 | } |
| 1186 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1187 | case Ice::IceType_v4f32: |
| 1188 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1189 | 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] | 1190 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1191 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1192 | } |
| 1193 | break; |
| 1194 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1195 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1196 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1197 | 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] | 1198 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1199 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1200 | } |
| 1201 | break; |
| 1202 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1203 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1204 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1205 | 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] | 1206 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1207 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1208 | } |
| 1209 | break; |
| 1210 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1211 | { |
| 1212 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1213 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1214 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1215 | } |
| 1216 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1217 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1218 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1219 | const 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] | 1220 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1221 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1222 | } |
| 1223 | break; |
| 1224 | case Type_v4i16: |
| 1225 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1226 | 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] | 1227 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1228 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1229 | } |
| 1230 | break; |
| 1231 | case Type_v8i8: |
| 1232 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1233 | 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] | 1234 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1235 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1236 | } |
| 1237 | break; |
| 1238 | case Type_v4i8: |
| 1239 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1240 | 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] | 1241 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1242 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1243 | } |
| 1244 | break; |
| 1245 | default: |
| 1246 | assert(false && "Unknown constant vector type" && type); |
| 1247 | } |
| 1248 | |
| 1249 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1250 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1251 | variableDeclaration->setName(name); |
| 1252 | variableDeclaration->setAlignment(alignment); |
| 1253 | variableDeclaration->setIsConstant(true); |
| 1254 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1255 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1256 | ::function->addGlobal(variableDeclaration); |
| 1257 | |
| 1258 | constexpr int32_t offset = 0; |
| 1259 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1260 | |
| 1261 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1262 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1263 | ::basicBlock->appendInst(load); |
| 1264 | |
| 1265 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1269 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1270 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | Type *Void::getType() |
| 1274 | { |
| 1275 | return T(Ice::IceType_void); |
| 1276 | } |
| 1277 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1278 | Bool::Bool(Argument<Bool> argument) |
| 1279 | { |
| 1280 | storeValue(argument.value); |
| 1281 | } |
| 1282 | |
| 1283 | Bool::Bool() |
| 1284 | { |
| 1285 | } |
| 1286 | |
| 1287 | Bool::Bool(bool x) |
| 1288 | { |
| 1289 | storeValue(Nucleus::createConstantBool(x)); |
| 1290 | } |
| 1291 | |
| 1292 | Bool::Bool(RValue<Bool> rhs) |
| 1293 | { |
| 1294 | storeValue(rhs.value); |
| 1295 | } |
| 1296 | |
| 1297 | Bool::Bool(const Bool &rhs) |
| 1298 | { |
| 1299 | Value *value = rhs.loadValue(); |
| 1300 | storeValue(value); |
| 1301 | } |
| 1302 | |
| 1303 | Bool::Bool(const Reference<Bool> &rhs) |
| 1304 | { |
| 1305 | Value *value = rhs.loadValue(); |
| 1306 | storeValue(value); |
| 1307 | } |
| 1308 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1309 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1310 | { |
| 1311 | storeValue(rhs.value); |
| 1312 | |
| 1313 | return rhs; |
| 1314 | } |
| 1315 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1316 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1317 | { |
| 1318 | Value *value = rhs.loadValue(); |
| 1319 | storeValue(value); |
| 1320 | |
| 1321 | return RValue<Bool>(value); |
| 1322 | } |
| 1323 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1324 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1325 | { |
| 1326 | Value *value = rhs.loadValue(); |
| 1327 | storeValue(value); |
| 1328 | |
| 1329 | return RValue<Bool>(value); |
| 1330 | } |
| 1331 | |
| 1332 | RValue<Bool> operator!(RValue<Bool> val) |
| 1333 | { |
| 1334 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1335 | } |
| 1336 | |
| 1337 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1338 | { |
| 1339 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1340 | } |
| 1341 | |
| 1342 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1343 | { |
| 1344 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1345 | } |
| 1346 | |
| 1347 | Type *Bool::getType() |
| 1348 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1349 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | Byte::Byte(Argument<Byte> argument) |
| 1353 | { |
| 1354 | storeValue(argument.value); |
| 1355 | } |
| 1356 | |
| 1357 | Byte::Byte(RValue<Int> cast) |
| 1358 | { |
| 1359 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1360 | |
| 1361 | storeValue(integer); |
| 1362 | } |
| 1363 | |
| 1364 | Byte::Byte(RValue<UInt> cast) |
| 1365 | { |
| 1366 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1367 | |
| 1368 | storeValue(integer); |
| 1369 | } |
| 1370 | |
| 1371 | Byte::Byte(RValue<UShort> cast) |
| 1372 | { |
| 1373 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1374 | |
| 1375 | storeValue(integer); |
| 1376 | } |
| 1377 | |
| 1378 | Byte::Byte() |
| 1379 | { |
| 1380 | } |
| 1381 | |
| 1382 | Byte::Byte(int x) |
| 1383 | { |
| 1384 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1385 | } |
| 1386 | |
| 1387 | Byte::Byte(unsigned char x) |
| 1388 | { |
| 1389 | storeValue(Nucleus::createConstantByte(x)); |
| 1390 | } |
| 1391 | |
| 1392 | Byte::Byte(RValue<Byte> rhs) |
| 1393 | { |
| 1394 | storeValue(rhs.value); |
| 1395 | } |
| 1396 | |
| 1397 | Byte::Byte(const Byte &rhs) |
| 1398 | { |
| 1399 | Value *value = rhs.loadValue(); |
| 1400 | storeValue(value); |
| 1401 | } |
| 1402 | |
| 1403 | Byte::Byte(const Reference<Byte> &rhs) |
| 1404 | { |
| 1405 | Value *value = rhs.loadValue(); |
| 1406 | storeValue(value); |
| 1407 | } |
| 1408 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1409 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1410 | { |
| 1411 | storeValue(rhs.value); |
| 1412 | |
| 1413 | return rhs; |
| 1414 | } |
| 1415 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1416 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1417 | { |
| 1418 | Value *value = rhs.loadValue(); |
| 1419 | storeValue(value); |
| 1420 | |
| 1421 | return RValue<Byte>(value); |
| 1422 | } |
| 1423 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1424 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1425 | { |
| 1426 | Value *value = rhs.loadValue(); |
| 1427 | storeValue(value); |
| 1428 | |
| 1429 | return RValue<Byte>(value); |
| 1430 | } |
| 1431 | |
| 1432 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1433 | { |
| 1434 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1435 | } |
| 1436 | |
| 1437 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1438 | { |
| 1439 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1440 | } |
| 1441 | |
| 1442 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1443 | { |
| 1444 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1445 | } |
| 1446 | |
| 1447 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1448 | { |
| 1449 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1450 | } |
| 1451 | |
| 1452 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1453 | { |
| 1454 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1455 | } |
| 1456 | |
| 1457 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1458 | { |
| 1459 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1460 | } |
| 1461 | |
| 1462 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1463 | { |
| 1464 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1465 | } |
| 1466 | |
| 1467 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1468 | { |
| 1469 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1470 | } |
| 1471 | |
| 1472 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1473 | { |
| 1474 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1475 | } |
| 1476 | |
| 1477 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1478 | { |
| 1479 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1480 | } |
| 1481 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1482 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1483 | { |
| 1484 | return lhs = lhs + rhs; |
| 1485 | } |
| 1486 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1487 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1488 | { |
| 1489 | return lhs = lhs - rhs; |
| 1490 | } |
| 1491 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1492 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1493 | { |
| 1494 | return lhs = lhs * rhs; |
| 1495 | } |
| 1496 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1497 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1498 | { |
| 1499 | return lhs = lhs / rhs; |
| 1500 | } |
| 1501 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1502 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1503 | { |
| 1504 | return lhs = lhs % rhs; |
| 1505 | } |
| 1506 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1507 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1508 | { |
| 1509 | return lhs = lhs & rhs; |
| 1510 | } |
| 1511 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1512 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1513 | { |
| 1514 | return lhs = lhs | rhs; |
| 1515 | } |
| 1516 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1517 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1518 | { |
| 1519 | return lhs = lhs ^ rhs; |
| 1520 | } |
| 1521 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1522 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1523 | { |
| 1524 | return lhs = lhs << rhs; |
| 1525 | } |
| 1526 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1527 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1528 | { |
| 1529 | return lhs = lhs >> rhs; |
| 1530 | } |
| 1531 | |
| 1532 | RValue<Byte> operator+(RValue<Byte> val) |
| 1533 | { |
| 1534 | return val; |
| 1535 | } |
| 1536 | |
| 1537 | RValue<Byte> operator-(RValue<Byte> val) |
| 1538 | { |
| 1539 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1540 | } |
| 1541 | |
| 1542 | RValue<Byte> operator~(RValue<Byte> val) |
| 1543 | { |
| 1544 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1545 | } |
| 1546 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1547 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1548 | { |
| 1549 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1550 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1551 | return res; |
| 1552 | } |
| 1553 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1554 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1555 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1556 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1557 | return val; |
| 1558 | } |
| 1559 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1560 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1561 | { |
| 1562 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1563 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1564 | return res; |
| 1565 | } |
| 1566 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1567 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1568 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1569 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1570 | return val; |
| 1571 | } |
| 1572 | |
| 1573 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1574 | { |
| 1575 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1576 | } |
| 1577 | |
| 1578 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1579 | { |
| 1580 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1581 | } |
| 1582 | |
| 1583 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1584 | { |
| 1585 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1586 | } |
| 1587 | |
| 1588 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1589 | { |
| 1590 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1591 | } |
| 1592 | |
| 1593 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1594 | { |
| 1595 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1596 | } |
| 1597 | |
| 1598 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1599 | { |
| 1600 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1601 | } |
| 1602 | |
| 1603 | Type *Byte::getType() |
| 1604 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1605 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | SByte::SByte(Argument<SByte> argument) |
| 1609 | { |
| 1610 | storeValue(argument.value); |
| 1611 | } |
| 1612 | |
| 1613 | SByte::SByte(RValue<Int> cast) |
| 1614 | { |
| 1615 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1616 | |
| 1617 | storeValue(integer); |
| 1618 | } |
| 1619 | |
| 1620 | SByte::SByte(RValue<Short> cast) |
| 1621 | { |
| 1622 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1623 | |
| 1624 | storeValue(integer); |
| 1625 | } |
| 1626 | |
| 1627 | SByte::SByte() |
| 1628 | { |
| 1629 | } |
| 1630 | |
| 1631 | SByte::SByte(signed char x) |
| 1632 | { |
| 1633 | storeValue(Nucleus::createConstantByte(x)); |
| 1634 | } |
| 1635 | |
| 1636 | SByte::SByte(RValue<SByte> rhs) |
| 1637 | { |
| 1638 | storeValue(rhs.value); |
| 1639 | } |
| 1640 | |
| 1641 | SByte::SByte(const SByte &rhs) |
| 1642 | { |
| 1643 | Value *value = rhs.loadValue(); |
| 1644 | storeValue(value); |
| 1645 | } |
| 1646 | |
| 1647 | SByte::SByte(const Reference<SByte> &rhs) |
| 1648 | { |
| 1649 | Value *value = rhs.loadValue(); |
| 1650 | storeValue(value); |
| 1651 | } |
| 1652 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1653 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1654 | { |
| 1655 | storeValue(rhs.value); |
| 1656 | |
| 1657 | return rhs; |
| 1658 | } |
| 1659 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1660 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1661 | { |
| 1662 | Value *value = rhs.loadValue(); |
| 1663 | storeValue(value); |
| 1664 | |
| 1665 | return RValue<SByte>(value); |
| 1666 | } |
| 1667 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1668 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1669 | { |
| 1670 | Value *value = rhs.loadValue(); |
| 1671 | storeValue(value); |
| 1672 | |
| 1673 | return RValue<SByte>(value); |
| 1674 | } |
| 1675 | |
| 1676 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1677 | { |
| 1678 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1679 | } |
| 1680 | |
| 1681 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1682 | { |
| 1683 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1684 | } |
| 1685 | |
| 1686 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1687 | { |
| 1688 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1689 | } |
| 1690 | |
| 1691 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1692 | { |
| 1693 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1694 | } |
| 1695 | |
| 1696 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1697 | { |
| 1698 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1699 | } |
| 1700 | |
| 1701 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1702 | { |
| 1703 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1704 | } |
| 1705 | |
| 1706 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1707 | { |
| 1708 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1709 | } |
| 1710 | |
| 1711 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1712 | { |
| 1713 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1714 | } |
| 1715 | |
| 1716 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1717 | { |
| 1718 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1719 | } |
| 1720 | |
| 1721 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1722 | { |
| 1723 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1724 | } |
| 1725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1726 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1727 | { |
| 1728 | return lhs = lhs + rhs; |
| 1729 | } |
| 1730 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1731 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1732 | { |
| 1733 | return lhs = lhs - rhs; |
| 1734 | } |
| 1735 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1736 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1737 | { |
| 1738 | return lhs = lhs * rhs; |
| 1739 | } |
| 1740 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1741 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1742 | { |
| 1743 | return lhs = lhs / rhs; |
| 1744 | } |
| 1745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1746 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1747 | { |
| 1748 | return lhs = lhs % rhs; |
| 1749 | } |
| 1750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1751 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1752 | { |
| 1753 | return lhs = lhs & rhs; |
| 1754 | } |
| 1755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1756 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1757 | { |
| 1758 | return lhs = lhs | rhs; |
| 1759 | } |
| 1760 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1761 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1762 | { |
| 1763 | return lhs = lhs ^ rhs; |
| 1764 | } |
| 1765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1766 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1767 | { |
| 1768 | return lhs = lhs << rhs; |
| 1769 | } |
| 1770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1771 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1772 | { |
| 1773 | return lhs = lhs >> rhs; |
| 1774 | } |
| 1775 | |
| 1776 | RValue<SByte> operator+(RValue<SByte> val) |
| 1777 | { |
| 1778 | return val; |
| 1779 | } |
| 1780 | |
| 1781 | RValue<SByte> operator-(RValue<SByte> val) |
| 1782 | { |
| 1783 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1784 | } |
| 1785 | |
| 1786 | RValue<SByte> operator~(RValue<SByte> val) |
| 1787 | { |
| 1788 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1789 | } |
| 1790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1791 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1792 | { |
| 1793 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1794 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1795 | return res; |
| 1796 | } |
| 1797 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1798 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1799 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1800 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1801 | return val; |
| 1802 | } |
| 1803 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1804 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1805 | { |
| 1806 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1807 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1808 | return res; |
| 1809 | } |
| 1810 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1811 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1812 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1813 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1814 | return val; |
| 1815 | } |
| 1816 | |
| 1817 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1818 | { |
| 1819 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1820 | } |
| 1821 | |
| 1822 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1823 | { |
| 1824 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1825 | } |
| 1826 | |
| 1827 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1828 | { |
| 1829 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1830 | } |
| 1831 | |
| 1832 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1833 | { |
| 1834 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1835 | } |
| 1836 | |
| 1837 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1838 | { |
| 1839 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1840 | } |
| 1841 | |
| 1842 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1843 | { |
| 1844 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1845 | } |
| 1846 | |
| 1847 | Type *SByte::getType() |
| 1848 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1849 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | Short::Short(Argument<Short> argument) |
| 1853 | { |
| 1854 | storeValue(argument.value); |
| 1855 | } |
| 1856 | |
| 1857 | Short::Short(RValue<Int> cast) |
| 1858 | { |
| 1859 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1860 | |
| 1861 | storeValue(integer); |
| 1862 | } |
| 1863 | |
| 1864 | Short::Short() |
| 1865 | { |
| 1866 | } |
| 1867 | |
| 1868 | Short::Short(short x) |
| 1869 | { |
| 1870 | storeValue(Nucleus::createConstantShort(x)); |
| 1871 | } |
| 1872 | |
| 1873 | Short::Short(RValue<Short> rhs) |
| 1874 | { |
| 1875 | storeValue(rhs.value); |
| 1876 | } |
| 1877 | |
| 1878 | Short::Short(const Short &rhs) |
| 1879 | { |
| 1880 | Value *value = rhs.loadValue(); |
| 1881 | storeValue(value); |
| 1882 | } |
| 1883 | |
| 1884 | Short::Short(const Reference<Short> &rhs) |
| 1885 | { |
| 1886 | Value *value = rhs.loadValue(); |
| 1887 | storeValue(value); |
| 1888 | } |
| 1889 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1890 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1891 | { |
| 1892 | storeValue(rhs.value); |
| 1893 | |
| 1894 | return rhs; |
| 1895 | } |
| 1896 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1897 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1898 | { |
| 1899 | Value *value = rhs.loadValue(); |
| 1900 | storeValue(value); |
| 1901 | |
| 1902 | return RValue<Short>(value); |
| 1903 | } |
| 1904 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1905 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1906 | { |
| 1907 | Value *value = rhs.loadValue(); |
| 1908 | storeValue(value); |
| 1909 | |
| 1910 | return RValue<Short>(value); |
| 1911 | } |
| 1912 | |
| 1913 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 1914 | { |
| 1915 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1916 | } |
| 1917 | |
| 1918 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 1919 | { |
| 1920 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1921 | } |
| 1922 | |
| 1923 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 1924 | { |
| 1925 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1926 | } |
| 1927 | |
| 1928 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 1929 | { |
| 1930 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1931 | } |
| 1932 | |
| 1933 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 1934 | { |
| 1935 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1936 | } |
| 1937 | |
| 1938 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 1939 | { |
| 1940 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1941 | } |
| 1942 | |
| 1943 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 1944 | { |
| 1945 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1946 | } |
| 1947 | |
| 1948 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 1949 | { |
| 1950 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1951 | } |
| 1952 | |
| 1953 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 1954 | { |
| 1955 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1956 | } |
| 1957 | |
| 1958 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 1959 | { |
| 1960 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1961 | } |
| 1962 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1963 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1964 | { |
| 1965 | return lhs = lhs + rhs; |
| 1966 | } |
| 1967 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1968 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1969 | { |
| 1970 | return lhs = lhs - rhs; |
| 1971 | } |
| 1972 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1973 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1974 | { |
| 1975 | return lhs = lhs * rhs; |
| 1976 | } |
| 1977 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1978 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1979 | { |
| 1980 | return lhs = lhs / rhs; |
| 1981 | } |
| 1982 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1983 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1984 | { |
| 1985 | return lhs = lhs % rhs; |
| 1986 | } |
| 1987 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1988 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1989 | { |
| 1990 | return lhs = lhs & rhs; |
| 1991 | } |
| 1992 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1993 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1994 | { |
| 1995 | return lhs = lhs | rhs; |
| 1996 | } |
| 1997 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1998 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1999 | { |
| 2000 | return lhs = lhs ^ rhs; |
| 2001 | } |
| 2002 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2003 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2004 | { |
| 2005 | return lhs = lhs << rhs; |
| 2006 | } |
| 2007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2008 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2009 | { |
| 2010 | return lhs = lhs >> rhs; |
| 2011 | } |
| 2012 | |
| 2013 | RValue<Short> operator+(RValue<Short> val) |
| 2014 | { |
| 2015 | return val; |
| 2016 | } |
| 2017 | |
| 2018 | RValue<Short> operator-(RValue<Short> val) |
| 2019 | { |
| 2020 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2021 | } |
| 2022 | |
| 2023 | RValue<Short> operator~(RValue<Short> val) |
| 2024 | { |
| 2025 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2026 | } |
| 2027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2028 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2029 | { |
| 2030 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2031 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2032 | return res; |
| 2033 | } |
| 2034 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2035 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2036 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2037 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2038 | return val; |
| 2039 | } |
| 2040 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2041 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2042 | { |
| 2043 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2044 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2045 | return res; |
| 2046 | } |
| 2047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2048 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2049 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2050 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2051 | return val; |
| 2052 | } |
| 2053 | |
| 2054 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2055 | { |
| 2056 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2057 | } |
| 2058 | |
| 2059 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2060 | { |
| 2061 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2062 | } |
| 2063 | |
| 2064 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2065 | { |
| 2066 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2067 | } |
| 2068 | |
| 2069 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2070 | { |
| 2071 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2072 | } |
| 2073 | |
| 2074 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2075 | { |
| 2076 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2077 | } |
| 2078 | |
| 2079 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2080 | { |
| 2081 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2082 | } |
| 2083 | |
| 2084 | Type *Short::getType() |
| 2085 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2086 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | UShort::UShort(Argument<UShort> argument) |
| 2090 | { |
| 2091 | storeValue(argument.value); |
| 2092 | } |
| 2093 | |
| 2094 | UShort::UShort(RValue<UInt> cast) |
| 2095 | { |
| 2096 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2097 | |
| 2098 | storeValue(integer); |
| 2099 | } |
| 2100 | |
| 2101 | UShort::UShort(RValue<Int> cast) |
| 2102 | { |
| 2103 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2104 | |
| 2105 | storeValue(integer); |
| 2106 | } |
| 2107 | |
| 2108 | UShort::UShort() |
| 2109 | { |
| 2110 | } |
| 2111 | |
| 2112 | UShort::UShort(unsigned short x) |
| 2113 | { |
| 2114 | storeValue(Nucleus::createConstantShort(x)); |
| 2115 | } |
| 2116 | |
| 2117 | UShort::UShort(RValue<UShort> rhs) |
| 2118 | { |
| 2119 | storeValue(rhs.value); |
| 2120 | } |
| 2121 | |
| 2122 | UShort::UShort(const UShort &rhs) |
| 2123 | { |
| 2124 | Value *value = rhs.loadValue(); |
| 2125 | storeValue(value); |
| 2126 | } |
| 2127 | |
| 2128 | UShort::UShort(const Reference<UShort> &rhs) |
| 2129 | { |
| 2130 | Value *value = rhs.loadValue(); |
| 2131 | storeValue(value); |
| 2132 | } |
| 2133 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2134 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2135 | { |
| 2136 | storeValue(rhs.value); |
| 2137 | |
| 2138 | return rhs; |
| 2139 | } |
| 2140 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2141 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2142 | { |
| 2143 | Value *value = rhs.loadValue(); |
| 2144 | storeValue(value); |
| 2145 | |
| 2146 | return RValue<UShort>(value); |
| 2147 | } |
| 2148 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2149 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2150 | { |
| 2151 | Value *value = rhs.loadValue(); |
| 2152 | storeValue(value); |
| 2153 | |
| 2154 | return RValue<UShort>(value); |
| 2155 | } |
| 2156 | |
| 2157 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2158 | { |
| 2159 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2160 | } |
| 2161 | |
| 2162 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2163 | { |
| 2164 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2165 | } |
| 2166 | |
| 2167 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2168 | { |
| 2169 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2170 | } |
| 2171 | |
| 2172 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2173 | { |
| 2174 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2175 | } |
| 2176 | |
| 2177 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2178 | { |
| 2179 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2180 | } |
| 2181 | |
| 2182 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2183 | { |
| 2184 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2185 | } |
| 2186 | |
| 2187 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2188 | { |
| 2189 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2190 | } |
| 2191 | |
| 2192 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2193 | { |
| 2194 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2195 | } |
| 2196 | |
| 2197 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2198 | { |
| 2199 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2200 | } |
| 2201 | |
| 2202 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2203 | { |
| 2204 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2205 | } |
| 2206 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2207 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2208 | { |
| 2209 | return lhs = lhs + rhs; |
| 2210 | } |
| 2211 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2212 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2213 | { |
| 2214 | return lhs = lhs - rhs; |
| 2215 | } |
| 2216 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2217 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2218 | { |
| 2219 | return lhs = lhs * rhs; |
| 2220 | } |
| 2221 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2222 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2223 | { |
| 2224 | return lhs = lhs / rhs; |
| 2225 | } |
| 2226 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2227 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2228 | { |
| 2229 | return lhs = lhs % rhs; |
| 2230 | } |
| 2231 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2232 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2233 | { |
| 2234 | return lhs = lhs & rhs; |
| 2235 | } |
| 2236 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2237 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2238 | { |
| 2239 | return lhs = lhs | rhs; |
| 2240 | } |
| 2241 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2242 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2243 | { |
| 2244 | return lhs = lhs ^ rhs; |
| 2245 | } |
| 2246 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2247 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2248 | { |
| 2249 | return lhs = lhs << rhs; |
| 2250 | } |
| 2251 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2252 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2253 | { |
| 2254 | return lhs = lhs >> rhs; |
| 2255 | } |
| 2256 | |
| 2257 | RValue<UShort> operator+(RValue<UShort> val) |
| 2258 | { |
| 2259 | return val; |
| 2260 | } |
| 2261 | |
| 2262 | RValue<UShort> operator-(RValue<UShort> val) |
| 2263 | { |
| 2264 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2265 | } |
| 2266 | |
| 2267 | RValue<UShort> operator~(RValue<UShort> val) |
| 2268 | { |
| 2269 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2270 | } |
| 2271 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2272 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2273 | { |
| 2274 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2275 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2276 | return res; |
| 2277 | } |
| 2278 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2279 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2280 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2281 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2282 | return val; |
| 2283 | } |
| 2284 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2285 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2286 | { |
| 2287 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2288 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2289 | return res; |
| 2290 | } |
| 2291 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2292 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2293 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2294 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2295 | return val; |
| 2296 | } |
| 2297 | |
| 2298 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2299 | { |
| 2300 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2301 | } |
| 2302 | |
| 2303 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2304 | { |
| 2305 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2306 | } |
| 2307 | |
| 2308 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2309 | { |
| 2310 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2311 | } |
| 2312 | |
| 2313 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2314 | { |
| 2315 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2316 | } |
| 2317 | |
| 2318 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2319 | { |
| 2320 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2321 | } |
| 2322 | |
| 2323 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2324 | { |
| 2325 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2326 | } |
| 2327 | |
| 2328 | Type *UShort::getType() |
| 2329 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2330 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2331 | } |
| 2332 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2333 | Byte4::Byte4(RValue<Byte8> cast) |
| 2334 | { |
| 2335 | // xyzw.parent = this; |
| 2336 | |
| 2337 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2338 | } |
| 2339 | |
| 2340 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2341 | { |
| 2342 | // xyzw.parent = this; |
| 2343 | |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2344 | Value *value = rhs.loadValue(); |
| 2345 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2346 | } |
| 2347 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2348 | Type *Byte4::getType() |
| 2349 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2350 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | Type *SByte4::getType() |
| 2354 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2355 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | Byte8::Byte8() |
| 2359 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | 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) |
| 2363 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2364 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2365 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2369 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2370 | storeValue(rhs.value); |
| 2371 | } |
| 2372 | |
| 2373 | Byte8::Byte8(const Byte8 &rhs) |
| 2374 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2375 | Value *value = rhs.loadValue(); |
| 2376 | storeValue(value); |
| 2377 | } |
| 2378 | |
| 2379 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2380 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2381 | Value *value = rhs.loadValue(); |
| 2382 | storeValue(value); |
| 2383 | } |
| 2384 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2385 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2386 | { |
| 2387 | storeValue(rhs.value); |
| 2388 | |
| 2389 | return rhs; |
| 2390 | } |
| 2391 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2392 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2393 | { |
| 2394 | Value *value = rhs.loadValue(); |
| 2395 | storeValue(value); |
| 2396 | |
| 2397 | return RValue<Byte8>(value); |
| 2398 | } |
| 2399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2400 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2401 | { |
| 2402 | Value *value = rhs.loadValue(); |
| 2403 | storeValue(value); |
| 2404 | |
| 2405 | return RValue<Byte8>(value); |
| 2406 | } |
| 2407 | |
| 2408 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2409 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2410 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2414 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2415 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2419 | // { |
| 2420 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2421 | // } |
| 2422 | |
| 2423 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2424 | // { |
| 2425 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2426 | // } |
| 2427 | |
| 2428 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2429 | // { |
| 2430 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2431 | // } |
| 2432 | |
| 2433 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2434 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2435 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2439 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2440 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2444 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2445 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2449 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 2450 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2451 | // } |
| 2452 | |
| 2453 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2454 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 2455 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2456 | // } |
| 2457 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2458 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2459 | { |
| 2460 | return lhs = lhs + rhs; |
| 2461 | } |
| 2462 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2463 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2464 | { |
| 2465 | return lhs = lhs - rhs; |
| 2466 | } |
| 2467 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2468 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2469 | // { |
| 2470 | // return lhs = lhs * rhs; |
| 2471 | // } |
| 2472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2473 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2474 | // { |
| 2475 | // return lhs = lhs / rhs; |
| 2476 | // } |
| 2477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2478 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2479 | // { |
| 2480 | // return lhs = lhs % rhs; |
| 2481 | // } |
| 2482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2483 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2484 | { |
| 2485 | return lhs = lhs & rhs; |
| 2486 | } |
| 2487 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2488 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2489 | { |
| 2490 | return lhs = lhs | rhs; |
| 2491 | } |
| 2492 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2493 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2494 | { |
| 2495 | return lhs = lhs ^ rhs; |
| 2496 | } |
| 2497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2498 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2499 | // { |
| 2500 | // return lhs = lhs << rhs; |
| 2501 | // } |
| 2502 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2503 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2504 | // { |
| 2505 | // return lhs = lhs >> rhs; |
| 2506 | // } |
| 2507 | |
| 2508 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2509 | // { |
| 2510 | // return val; |
| 2511 | // } |
| 2512 | |
| 2513 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2514 | // { |
| 2515 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2516 | // } |
| 2517 | |
| 2518 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2519 | { |
| 2520 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2521 | } |
| 2522 | |
| 2523 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2524 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2525 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2526 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2527 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2528 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2529 | paddusb->addArg(x.value); |
| 2530 | paddusb->addArg(y.value); |
| 2531 | ::basicBlock->appendInst(paddusb); |
| 2532 | |
| 2533 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2537 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2538 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2539 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2540 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2541 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2542 | psubusw->addArg(x.value); |
| 2543 | psubusw->addArg(y.value); |
| 2544 | ::basicBlock->appendInst(psubusw); |
| 2545 | |
| 2546 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2550 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2551 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2552 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2556 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2557 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2558 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2562 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2563 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2564 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2565 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2569 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2570 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2571 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2572 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2573 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2574 | movmsk->addArg(x.value); |
| 2575 | ::basicBlock->appendInst(movmsk); |
| 2576 | |
| 2577 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2581 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2582 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2583 | // } |
| 2584 | |
| 2585 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2586 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2587 | 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] | 2588 | } |
| 2589 | |
| 2590 | Type *Byte8::getType() |
| 2591 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2592 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | SByte8::SByte8() |
| 2596 | { |
| 2597 | // xyzw.parent = this; |
| 2598 | } |
| 2599 | |
| 2600 | 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) |
| 2601 | { |
| 2602 | // xyzw.parent = this; |
| 2603 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2604 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2605 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2606 | |
| 2607 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2608 | } |
| 2609 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2610 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2611 | { |
| 2612 | // xyzw.parent = this; |
| 2613 | |
| 2614 | storeValue(rhs.value); |
| 2615 | } |
| 2616 | |
| 2617 | SByte8::SByte8(const SByte8 &rhs) |
| 2618 | { |
| 2619 | // xyzw.parent = this; |
| 2620 | |
| 2621 | Value *value = rhs.loadValue(); |
| 2622 | storeValue(value); |
| 2623 | } |
| 2624 | |
| 2625 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2626 | { |
| 2627 | // xyzw.parent = this; |
| 2628 | |
| 2629 | Value *value = rhs.loadValue(); |
| 2630 | storeValue(value); |
| 2631 | } |
| 2632 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2633 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2634 | { |
| 2635 | storeValue(rhs.value); |
| 2636 | |
| 2637 | return rhs; |
| 2638 | } |
| 2639 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2640 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2641 | { |
| 2642 | Value *value = rhs.loadValue(); |
| 2643 | storeValue(value); |
| 2644 | |
| 2645 | return RValue<SByte8>(value); |
| 2646 | } |
| 2647 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2648 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2649 | { |
| 2650 | Value *value = rhs.loadValue(); |
| 2651 | storeValue(value); |
| 2652 | |
| 2653 | return RValue<SByte8>(value); |
| 2654 | } |
| 2655 | |
| 2656 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2657 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2658 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2662 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2663 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2667 | // { |
| 2668 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2669 | // } |
| 2670 | |
| 2671 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2672 | // { |
| 2673 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2674 | // } |
| 2675 | |
| 2676 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2677 | // { |
| 2678 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2679 | // } |
| 2680 | |
| 2681 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2682 | { |
| 2683 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2684 | } |
| 2685 | |
| 2686 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2687 | { |
| 2688 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2689 | } |
| 2690 | |
| 2691 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2692 | { |
| 2693 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2694 | } |
| 2695 | |
| 2696 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2697 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 2698 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2699 | // } |
| 2700 | |
| 2701 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2702 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 2703 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2704 | // } |
| 2705 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2706 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2707 | { |
| 2708 | return lhs = lhs + rhs; |
| 2709 | } |
| 2710 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2711 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2712 | { |
| 2713 | return lhs = lhs - rhs; |
| 2714 | } |
| 2715 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2716 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2717 | // { |
| 2718 | // return lhs = lhs * rhs; |
| 2719 | // } |
| 2720 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2721 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2722 | // { |
| 2723 | // return lhs = lhs / rhs; |
| 2724 | // } |
| 2725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2726 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2727 | // { |
| 2728 | // return lhs = lhs % rhs; |
| 2729 | // } |
| 2730 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2731 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2732 | { |
| 2733 | return lhs = lhs & rhs; |
| 2734 | } |
| 2735 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2736 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2737 | { |
| 2738 | return lhs = lhs | rhs; |
| 2739 | } |
| 2740 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2741 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2742 | { |
| 2743 | return lhs = lhs ^ rhs; |
| 2744 | } |
| 2745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2746 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2747 | // { |
| 2748 | // return lhs = lhs << rhs; |
| 2749 | // } |
| 2750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2751 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2752 | // { |
| 2753 | // return lhs = lhs >> rhs; |
| 2754 | // } |
| 2755 | |
| 2756 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2757 | // { |
| 2758 | // return val; |
| 2759 | // } |
| 2760 | |
| 2761 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2762 | // { |
| 2763 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2764 | // } |
| 2765 | |
| 2766 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2767 | { |
| 2768 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2769 | } |
| 2770 | |
| 2771 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2772 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2773 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2774 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2775 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2776 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2777 | paddsb->addArg(x.value); |
| 2778 | paddsb->addArg(y.value); |
| 2779 | ::basicBlock->appendInst(paddsb); |
| 2780 | |
| 2781 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2785 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2786 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2787 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2788 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2789 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2790 | psubsb->addArg(x.value); |
| 2791 | psubsb->addArg(y.value); |
| 2792 | ::basicBlock->appendInst(psubsb); |
| 2793 | |
| 2794 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2798 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2799 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2800 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2804 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2805 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2806 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2807 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2811 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2812 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2813 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2814 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2815 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2816 | movmsk->addArg(x.value); |
| 2817 | ::basicBlock->appendInst(movmsk); |
| 2818 | |
| 2819 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2823 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2824 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2828 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2829 | 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] | 2830 | } |
| 2831 | |
| 2832 | Type *SByte8::getType() |
| 2833 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2834 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2838 | { |
| 2839 | // xyzw.parent = this; |
| 2840 | |
| 2841 | storeValue(rhs.value); |
| 2842 | } |
| 2843 | |
| 2844 | Byte16::Byte16(const Byte16 &rhs) |
| 2845 | { |
| 2846 | // xyzw.parent = this; |
| 2847 | |
| 2848 | Value *value = rhs.loadValue(); |
| 2849 | storeValue(value); |
| 2850 | } |
| 2851 | |
| 2852 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2853 | { |
| 2854 | // xyzw.parent = this; |
| 2855 | |
| 2856 | Value *value = rhs.loadValue(); |
| 2857 | storeValue(value); |
| 2858 | } |
| 2859 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2860 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2861 | { |
| 2862 | storeValue(rhs.value); |
| 2863 | |
| 2864 | return rhs; |
| 2865 | } |
| 2866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2867 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2868 | { |
| 2869 | Value *value = rhs.loadValue(); |
| 2870 | storeValue(value); |
| 2871 | |
| 2872 | return RValue<Byte16>(value); |
| 2873 | } |
| 2874 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2875 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2876 | { |
| 2877 | Value *value = rhs.loadValue(); |
| 2878 | storeValue(value); |
| 2879 | |
| 2880 | return RValue<Byte16>(value); |
| 2881 | } |
| 2882 | |
| 2883 | Type *Byte16::getType() |
| 2884 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2885 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | Type *SByte16::getType() |
| 2889 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2890 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2891 | } |
| 2892 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2893 | Short2::Short2(RValue<Short4> cast) |
| 2894 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2895 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | Type *Short2::getType() |
| 2899 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2900 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | UShort2::UShort2(RValue<UShort4> cast) |
| 2904 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2905 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | Type *UShort2::getType() |
| 2909 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2910 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2911 | } |
| 2912 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2913 | Short4::Short4(RValue<Int> cast) |
| 2914 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2915 | Value *vector = loadValue(); |
| 2916 | Value *insert = Nucleus::createInsertElement(vector, cast.value, 0); |
| 2917 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2918 | |
| 2919 | storeValue(swizzle); |
| 2920 | } |
| 2921 | |
| 2922 | Short4::Short4(RValue<Int4> cast) |
| 2923 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2924 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
| 2925 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2926 | Value *packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
| 2927 | |
| 2928 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2929 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2930 | |
| 2931 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | // Short4::Short4(RValue<Float> cast) |
| 2935 | // { |
| 2936 | // } |
| 2937 | |
| 2938 | Short4::Short4(RValue<Float4> cast) |
| 2939 | { |
| 2940 | assert(false && "UNIMPLEMENTED"); |
| 2941 | } |
| 2942 | |
| 2943 | Short4::Short4() |
| 2944 | { |
| 2945 | // xyzw.parent = this; |
| 2946 | } |
| 2947 | |
| 2948 | Short4::Short4(short xyzw) |
| 2949 | { |
| 2950 | // xyzw.parent = this; |
| 2951 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2952 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2953 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | Short4::Short4(short x, short y, short z, short w) |
| 2957 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2958 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2959 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2960 | int64_t constantVector[4] = {x, y, z, w}; |
| 2961 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | Short4::Short4(RValue<Short4> rhs) |
| 2965 | { |
| 2966 | // xyzw.parent = this; |
| 2967 | |
| 2968 | storeValue(rhs.value); |
| 2969 | } |
| 2970 | |
| 2971 | Short4::Short4(const Short4 &rhs) |
| 2972 | { |
| 2973 | // xyzw.parent = this; |
| 2974 | |
| 2975 | Value *value = rhs.loadValue(); |
| 2976 | storeValue(value); |
| 2977 | } |
| 2978 | |
| 2979 | Short4::Short4(const Reference<Short4> &rhs) |
| 2980 | { |
| 2981 | // xyzw.parent = this; |
| 2982 | |
| 2983 | Value *value = rhs.loadValue(); |
| 2984 | storeValue(value); |
| 2985 | } |
| 2986 | |
| 2987 | Short4::Short4(RValue<UShort4> rhs) |
| 2988 | { |
| 2989 | // xyzw.parent = this; |
| 2990 | |
| 2991 | storeValue(rhs.value); |
| 2992 | } |
| 2993 | |
| 2994 | Short4::Short4(const UShort4 &rhs) |
| 2995 | { |
| 2996 | // xyzw.parent = this; |
| 2997 | |
| 2998 | storeValue(rhs.loadValue()); |
| 2999 | } |
| 3000 | |
| 3001 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3002 | { |
| 3003 | // xyzw.parent = this; |
| 3004 | |
| 3005 | storeValue(rhs.loadValue()); |
| 3006 | } |
| 3007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3008 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3009 | { |
| 3010 | storeValue(rhs.value); |
| 3011 | |
| 3012 | return rhs; |
| 3013 | } |
| 3014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3015 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3016 | { |
| 3017 | Value *value = rhs.loadValue(); |
| 3018 | storeValue(value); |
| 3019 | |
| 3020 | return RValue<Short4>(value); |
| 3021 | } |
| 3022 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3023 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3024 | { |
| 3025 | Value *value = rhs.loadValue(); |
| 3026 | storeValue(value); |
| 3027 | |
| 3028 | return RValue<Short4>(value); |
| 3029 | } |
| 3030 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3031 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3032 | { |
| 3033 | storeValue(rhs.value); |
| 3034 | |
| 3035 | return RValue<Short4>(rhs); |
| 3036 | } |
| 3037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3038 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3039 | { |
| 3040 | Value *value = rhs.loadValue(); |
| 3041 | storeValue(value); |
| 3042 | |
| 3043 | return RValue<Short4>(value); |
| 3044 | } |
| 3045 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3046 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3047 | { |
| 3048 | Value *value = rhs.loadValue(); |
| 3049 | storeValue(value); |
| 3050 | |
| 3051 | return RValue<Short4>(value); |
| 3052 | } |
| 3053 | |
| 3054 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3055 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3056 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3060 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3061 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3065 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3066 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3070 | // { |
| 3071 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3072 | // } |
| 3073 | |
| 3074 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3075 | // { |
| 3076 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3077 | // } |
| 3078 | |
| 3079 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3080 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3081 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3085 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3086 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3090 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3091 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3095 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3096 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3100 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3101 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3102 | } |
| 3103 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3104 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3105 | { |
| 3106 | return lhs = lhs + rhs; |
| 3107 | } |
| 3108 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3109 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3110 | { |
| 3111 | return lhs = lhs - rhs; |
| 3112 | } |
| 3113 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3114 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3115 | { |
| 3116 | return lhs = lhs * rhs; |
| 3117 | } |
| 3118 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3119 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3120 | // { |
| 3121 | // return lhs = lhs / rhs; |
| 3122 | // } |
| 3123 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3124 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3125 | // { |
| 3126 | // return lhs = lhs % rhs; |
| 3127 | // } |
| 3128 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3129 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3130 | { |
| 3131 | return lhs = lhs & rhs; |
| 3132 | } |
| 3133 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3134 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3135 | { |
| 3136 | return lhs = lhs | rhs; |
| 3137 | } |
| 3138 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3139 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3140 | { |
| 3141 | return lhs = lhs ^ rhs; |
| 3142 | } |
| 3143 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3144 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3145 | { |
| 3146 | return lhs = lhs << rhs; |
| 3147 | } |
| 3148 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3149 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3150 | { |
| 3151 | return lhs = lhs >> rhs; |
| 3152 | } |
| 3153 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3154 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3155 | // { |
| 3156 | // return val; |
| 3157 | // } |
| 3158 | |
| 3159 | RValue<Short4> operator-(RValue<Short4> val) |
| 3160 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3161 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | RValue<Short4> operator~(RValue<Short4> val) |
| 3165 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3166 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3170 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3171 | RValue<Int4> int4 = RoundInt(cast); |
| 3172 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3176 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3177 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3178 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3179 | ::basicBlock->appendInst(cmp); |
| 3180 | |
| 3181 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3182 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3183 | ::basicBlock->appendInst(select); |
| 3184 | |
| 3185 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3189 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3190 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3191 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3192 | ::basicBlock->appendInst(cmp); |
| 3193 | |
| 3194 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3195 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3196 | ::basicBlock->appendInst(select); |
| 3197 | |
| 3198 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3202 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3203 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3204 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3205 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3206 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3207 | paddsw->addArg(x.value); |
| 3208 | paddsw->addArg(y.value); |
| 3209 | ::basicBlock->appendInst(paddsw); |
| 3210 | |
| 3211 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3215 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3216 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3217 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3218 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3219 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3220 | psubsw->addArg(x.value); |
| 3221 | psubsw->addArg(y.value); |
| 3222 | ::basicBlock->appendInst(psubsw); |
| 3223 | |
| 3224 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3228 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3229 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3230 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3231 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3232 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3233 | pmulhw->addArg(x.value); |
| 3234 | pmulhw->addArg(y.value); |
| 3235 | ::basicBlock->appendInst(pmulhw); |
| 3236 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3237 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3241 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3242 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3243 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3244 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3245 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3246 | pmaddwd->addArg(x.value); |
| 3247 | pmaddwd->addArg(y.value); |
| 3248 | ::basicBlock->appendInst(pmaddwd); |
| 3249 | |
| 3250 | return RValue<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3254 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3255 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3256 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3257 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3258 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3259 | pack->addArg(x.value); |
| 3260 | pack->addArg(y.value); |
| 3261 | ::basicBlock->appendInst(pack); |
| 3262 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3263 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3267 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3268 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3269 | return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3273 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3274 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3275 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3276 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3280 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3281 | // Real type is v8i16 |
| 3282 | int shuffle[8] = |
| 3283 | { |
| 3284 | (select >> 0) & 0x03, |
| 3285 | (select >> 2) & 0x03, |
| 3286 | (select >> 4) & 0x03, |
| 3287 | (select >> 6) & 0x03, |
| 3288 | (select >> 0) & 0x03, |
| 3289 | (select >> 2) & 0x03, |
| 3290 | (select >> 4) & 0x03, |
| 3291 | (select >> 6) & 0x03, |
| 3292 | }; |
| 3293 | |
| 3294 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3298 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3299 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3303 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3304 | return RValue<Short>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3308 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3309 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3313 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3314 | 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] | 3315 | } |
| 3316 | |
| 3317 | Type *Short4::getType() |
| 3318 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3319 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | UShort4::UShort4(RValue<Int4> cast) |
| 3323 | { |
| 3324 | *this = Short4(cast); |
| 3325 | } |
| 3326 | |
| 3327 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3328 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3329 | if(saturate) |
| 3330 | { |
| 3331 | if(true) // SSE 4.1 |
| 3332 | { |
| 3333 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3334 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3335 | } |
| 3336 | else |
| 3337 | { |
| 3338 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3339 | } |
| 3340 | } |
| 3341 | else |
| 3342 | { |
| 3343 | *this = Short4(Int4(cast)); |
| 3344 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | UShort4::UShort4() |
| 3348 | { |
| 3349 | // xyzw.parent = this; |
| 3350 | } |
| 3351 | |
| 3352 | UShort4::UShort4(unsigned short xyzw) |
| 3353 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3354 | // xyzw.parent = this; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3355 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3356 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3357 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3361 | { |
| 3362 | // xyzw.parent = this; |
| 3363 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3364 | int64_t constantVector[4] = {x, y, z, w}; |
| 3365 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3369 | { |
| 3370 | // xyzw.parent = this; |
| 3371 | |
| 3372 | storeValue(rhs.value); |
| 3373 | } |
| 3374 | |
| 3375 | UShort4::UShort4(const UShort4 &rhs) |
| 3376 | { |
| 3377 | // xyzw.parent = this; |
| 3378 | |
| 3379 | Value *value = rhs.loadValue(); |
| 3380 | storeValue(value); |
| 3381 | } |
| 3382 | |
| 3383 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3384 | { |
| 3385 | // xyzw.parent = this; |
| 3386 | |
| 3387 | Value *value = rhs.loadValue(); |
| 3388 | storeValue(value); |
| 3389 | } |
| 3390 | |
| 3391 | UShort4::UShort4(RValue<Short4> rhs) |
| 3392 | { |
| 3393 | // xyzw.parent = this; |
| 3394 | |
| 3395 | storeValue(rhs.value); |
| 3396 | } |
| 3397 | |
| 3398 | UShort4::UShort4(const Short4 &rhs) |
| 3399 | { |
| 3400 | // xyzw.parent = this; |
| 3401 | |
| 3402 | Value *value = rhs.loadValue(); |
| 3403 | storeValue(value); |
| 3404 | } |
| 3405 | |
| 3406 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3407 | { |
| 3408 | // xyzw.parent = this; |
| 3409 | |
| 3410 | Value *value = rhs.loadValue(); |
| 3411 | storeValue(value); |
| 3412 | } |
| 3413 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3414 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3415 | { |
| 3416 | storeValue(rhs.value); |
| 3417 | |
| 3418 | return rhs; |
| 3419 | } |
| 3420 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3421 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3422 | { |
| 3423 | Value *value = rhs.loadValue(); |
| 3424 | storeValue(value); |
| 3425 | |
| 3426 | return RValue<UShort4>(value); |
| 3427 | } |
| 3428 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3429 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3430 | { |
| 3431 | Value *value = rhs.loadValue(); |
| 3432 | storeValue(value); |
| 3433 | |
| 3434 | return RValue<UShort4>(value); |
| 3435 | } |
| 3436 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3437 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3438 | { |
| 3439 | storeValue(rhs.value); |
| 3440 | |
| 3441 | return RValue<UShort4>(rhs); |
| 3442 | } |
| 3443 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3444 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3445 | { |
| 3446 | Value *value = rhs.loadValue(); |
| 3447 | storeValue(value); |
| 3448 | |
| 3449 | return RValue<UShort4>(value); |
| 3450 | } |
| 3451 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3452 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3453 | { |
| 3454 | Value *value = rhs.loadValue(); |
| 3455 | storeValue(value); |
| 3456 | |
| 3457 | return RValue<UShort4>(value); |
| 3458 | } |
| 3459 | |
| 3460 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3461 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3462 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3466 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3467 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3471 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3472 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3473 | } |
| 3474 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3475 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3476 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3477 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3481 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3482 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3486 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3487 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3488 | } |
| 3489 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3490 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3491 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3492 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3496 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3497 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3498 | } |
| 3499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3500 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3501 | { |
| 3502 | return lhs = lhs << rhs; |
| 3503 | } |
| 3504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3505 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3506 | { |
| 3507 | return lhs = lhs >> rhs; |
| 3508 | } |
| 3509 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3510 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3511 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3512 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3516 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3517 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3518 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3519 | ::basicBlock->appendInst(cmp); |
| 3520 | |
| 3521 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3522 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3523 | ::basicBlock->appendInst(select); |
| 3524 | |
| 3525 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3529 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3530 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3531 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3532 | ::basicBlock->appendInst(cmp); |
| 3533 | |
| 3534 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3535 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3536 | ::basicBlock->appendInst(select); |
| 3537 | |
| 3538 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3542 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3543 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3544 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3545 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3546 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3547 | paddusw->addArg(x.value); |
| 3548 | paddusw->addArg(y.value); |
| 3549 | ::basicBlock->appendInst(paddusw); |
| 3550 | |
| 3551 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3555 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3556 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3557 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3558 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3559 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3560 | psubusw->addArg(x.value); |
| 3561 | psubusw->addArg(y.value); |
| 3562 | ::basicBlock->appendInst(psubusw); |
| 3563 | |
| 3564 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3568 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3569 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3570 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3571 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3572 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3573 | pmulhuw->addArg(x.value); |
| 3574 | pmulhuw->addArg(y.value); |
| 3575 | ::basicBlock->appendInst(pmulhuw); |
| 3576 | |
| 3577 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3581 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3582 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3586 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3587 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3588 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3589 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3590 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3591 | pack->addArg(x.value); |
| 3592 | pack->addArg(y.value); |
| 3593 | ::basicBlock->appendInst(pack); |
| 3594 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3595 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | Type *UShort4::getType() |
| 3599 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3600 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3604 | { |
| 3605 | // xyzw.parent = this; |
| 3606 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3607 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3608 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | Short8::Short8(RValue<Short8> rhs) |
| 3612 | { |
| 3613 | // xyzw.parent = this; |
| 3614 | |
| 3615 | storeValue(rhs.value); |
| 3616 | } |
| 3617 | |
| 3618 | Short8::Short8(const Reference<Short8> &rhs) |
| 3619 | { |
| 3620 | // xyzw.parent = this; |
| 3621 | |
| 3622 | Value *value = rhs.loadValue(); |
| 3623 | storeValue(value); |
| 3624 | } |
| 3625 | |
| 3626 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3627 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3628 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3629 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3630 | |
| 3631 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3635 | { |
| 3636 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3637 | } |
| 3638 | |
| 3639 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3640 | { |
| 3641 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3642 | } |
| 3643 | |
| 3644 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3645 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3646 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3650 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3651 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3655 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3656 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | RValue<Int4> Abs(RValue<Int4> x) |
| 3660 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3661 | auto negative = x >> 31; |
| 3662 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3666 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3667 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | Type *Short8::getType() |
| 3671 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3672 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | 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) |
| 3676 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3677 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3678 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3682 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3683 | storeValue(rhs.value); |
| 3684 | } |
| 3685 | |
| 3686 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3687 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3688 | Value *value = rhs.loadValue(); |
| 3689 | storeValue(value); |
| 3690 | } |
| 3691 | |
| 3692 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3693 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3694 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3695 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3696 | |
| 3697 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3698 | } |
| 3699 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3700 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3701 | { |
| 3702 | storeValue(rhs.value); |
| 3703 | |
| 3704 | return rhs; |
| 3705 | } |
| 3706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3707 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3708 | { |
| 3709 | Value *value = rhs.loadValue(); |
| 3710 | storeValue(value); |
| 3711 | |
| 3712 | return RValue<UShort8>(value); |
| 3713 | } |
| 3714 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3715 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3716 | { |
| 3717 | Value *value = rhs.loadValue(); |
| 3718 | storeValue(value); |
| 3719 | |
| 3720 | return RValue<UShort8>(value); |
| 3721 | } |
| 3722 | |
| 3723 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3724 | { |
| 3725 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3726 | } |
| 3727 | |
| 3728 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3729 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3730 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3734 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 3735 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3739 | { |
| 3740 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3741 | } |
| 3742 | |
| 3743 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3744 | { |
| 3745 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3746 | } |
| 3747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3748 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3749 | { |
| 3750 | return lhs = lhs + rhs; |
| 3751 | } |
| 3752 | |
| 3753 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3754 | { |
| 3755 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3756 | } |
| 3757 | |
| 3758 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3759 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3760 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3764 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3765 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3769 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 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 | Type *UShort8::getType() |
| 3775 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3776 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | Int::Int(Argument<Int> argument) |
| 3780 | { |
| 3781 | storeValue(argument.value); |
| 3782 | } |
| 3783 | |
| 3784 | Int::Int(RValue<Byte> cast) |
| 3785 | { |
| 3786 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3787 | |
| 3788 | storeValue(integer); |
| 3789 | } |
| 3790 | |
| 3791 | Int::Int(RValue<SByte> cast) |
| 3792 | { |
| 3793 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3794 | |
| 3795 | storeValue(integer); |
| 3796 | } |
| 3797 | |
| 3798 | Int::Int(RValue<Short> cast) |
| 3799 | { |
| 3800 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3801 | |
| 3802 | storeValue(integer); |
| 3803 | } |
| 3804 | |
| 3805 | Int::Int(RValue<UShort> cast) |
| 3806 | { |
| 3807 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3808 | |
| 3809 | storeValue(integer); |
| 3810 | } |
| 3811 | |
| 3812 | Int::Int(RValue<Int2> cast) |
| 3813 | { |
| 3814 | *this = Extract(cast, 0); |
| 3815 | } |
| 3816 | |
| 3817 | Int::Int(RValue<Long> cast) |
| 3818 | { |
| 3819 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3820 | |
| 3821 | storeValue(integer); |
| 3822 | } |
| 3823 | |
| 3824 | Int::Int(RValue<Float> cast) |
| 3825 | { |
| 3826 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3827 | |
| 3828 | storeValue(integer); |
| 3829 | } |
| 3830 | |
| 3831 | Int::Int() |
| 3832 | { |
| 3833 | } |
| 3834 | |
| 3835 | Int::Int(int x) |
| 3836 | { |
| 3837 | storeValue(Nucleus::createConstantInt(x)); |
| 3838 | } |
| 3839 | |
| 3840 | Int::Int(RValue<Int> rhs) |
| 3841 | { |
| 3842 | storeValue(rhs.value); |
| 3843 | } |
| 3844 | |
| 3845 | Int::Int(RValue<UInt> rhs) |
| 3846 | { |
| 3847 | storeValue(rhs.value); |
| 3848 | } |
| 3849 | |
| 3850 | Int::Int(const Int &rhs) |
| 3851 | { |
| 3852 | Value *value = rhs.loadValue(); |
| 3853 | storeValue(value); |
| 3854 | } |
| 3855 | |
| 3856 | Int::Int(const Reference<Int> &rhs) |
| 3857 | { |
| 3858 | Value *value = rhs.loadValue(); |
| 3859 | storeValue(value); |
| 3860 | } |
| 3861 | |
| 3862 | Int::Int(const UInt &rhs) |
| 3863 | { |
| 3864 | Value *value = rhs.loadValue(); |
| 3865 | storeValue(value); |
| 3866 | } |
| 3867 | |
| 3868 | Int::Int(const Reference<UInt> &rhs) |
| 3869 | { |
| 3870 | Value *value = rhs.loadValue(); |
| 3871 | storeValue(value); |
| 3872 | } |
| 3873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3874 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3875 | { |
| 3876 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3877 | } |
| 3878 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3879 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3880 | { |
| 3881 | storeValue(rhs.value); |
| 3882 | |
| 3883 | return rhs; |
| 3884 | } |
| 3885 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3886 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3887 | { |
| 3888 | storeValue(rhs.value); |
| 3889 | |
| 3890 | return RValue<Int>(rhs); |
| 3891 | } |
| 3892 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3893 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3894 | { |
| 3895 | Value *value = rhs.loadValue(); |
| 3896 | storeValue(value); |
| 3897 | |
| 3898 | return RValue<Int>(value); |
| 3899 | } |
| 3900 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3901 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3902 | { |
| 3903 | Value *value = rhs.loadValue(); |
| 3904 | storeValue(value); |
| 3905 | |
| 3906 | return RValue<Int>(value); |
| 3907 | } |
| 3908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3909 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3910 | { |
| 3911 | Value *value = rhs.loadValue(); |
| 3912 | storeValue(value); |
| 3913 | |
| 3914 | return RValue<Int>(value); |
| 3915 | } |
| 3916 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3917 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3918 | { |
| 3919 | Value *value = rhs.loadValue(); |
| 3920 | storeValue(value); |
| 3921 | |
| 3922 | return RValue<Int>(value); |
| 3923 | } |
| 3924 | |
| 3925 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3926 | { |
| 3927 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3928 | } |
| 3929 | |
| 3930 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3931 | { |
| 3932 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3933 | } |
| 3934 | |
| 3935 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3936 | { |
| 3937 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3938 | } |
| 3939 | |
| 3940 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3941 | { |
| 3942 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3943 | } |
| 3944 | |
| 3945 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3946 | { |
| 3947 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3948 | } |
| 3949 | |
| 3950 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3951 | { |
| 3952 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3953 | } |
| 3954 | |
| 3955 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 3956 | { |
| 3957 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3958 | } |
| 3959 | |
| 3960 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 3961 | { |
| 3962 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3963 | } |
| 3964 | |
| 3965 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 3966 | { |
| 3967 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3968 | } |
| 3969 | |
| 3970 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 3971 | { |
| 3972 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3973 | } |
| 3974 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3975 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3976 | { |
| 3977 | return lhs = lhs + rhs; |
| 3978 | } |
| 3979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3980 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3981 | { |
| 3982 | return lhs = lhs - rhs; |
| 3983 | } |
| 3984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3985 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3986 | { |
| 3987 | return lhs = lhs * rhs; |
| 3988 | } |
| 3989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3990 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3991 | { |
| 3992 | return lhs = lhs / rhs; |
| 3993 | } |
| 3994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3995 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3996 | { |
| 3997 | return lhs = lhs % rhs; |
| 3998 | } |
| 3999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4000 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4001 | { |
| 4002 | return lhs = lhs & rhs; |
| 4003 | } |
| 4004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4005 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4006 | { |
| 4007 | return lhs = lhs | rhs; |
| 4008 | } |
| 4009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4010 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4011 | { |
| 4012 | return lhs = lhs ^ rhs; |
| 4013 | } |
| 4014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4015 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4016 | { |
| 4017 | return lhs = lhs << rhs; |
| 4018 | } |
| 4019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4020 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4021 | { |
| 4022 | return lhs = lhs >> rhs; |
| 4023 | } |
| 4024 | |
| 4025 | RValue<Int> operator+(RValue<Int> val) |
| 4026 | { |
| 4027 | return val; |
| 4028 | } |
| 4029 | |
| 4030 | RValue<Int> operator-(RValue<Int> val) |
| 4031 | { |
| 4032 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4033 | } |
| 4034 | |
| 4035 | RValue<Int> operator~(RValue<Int> val) |
| 4036 | { |
| 4037 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4038 | } |
| 4039 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4040 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4041 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4042 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4043 | val += 1; |
| 4044 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4045 | } |
| 4046 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4047 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4048 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4049 | val += 1; |
| 4050 | return val; |
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 | RValue<Int> operator--(Int &val, int) // Post-decrement |
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 | RValue<Int> res = val; |
| 4056 | val -= 1; |
| 4057 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4058 | } |
| 4059 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4060 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4061 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4062 | val -= 1; |
| 4063 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4067 | { |
| 4068 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4069 | } |
| 4070 | |
| 4071 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4072 | { |
| 4073 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4074 | } |
| 4075 | |
| 4076 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4077 | { |
| 4078 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4079 | } |
| 4080 | |
| 4081 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4082 | { |
| 4083 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4084 | } |
| 4085 | |
| 4086 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4087 | { |
| 4088 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4089 | } |
| 4090 | |
| 4091 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4092 | { |
| 4093 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4094 | } |
| 4095 | |
| 4096 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4097 | { |
| 4098 | return IfThenElse(x > y, x, y); |
| 4099 | } |
| 4100 | |
| 4101 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4102 | { |
| 4103 | return IfThenElse(x < y, x, y); |
| 4104 | } |
| 4105 | |
| 4106 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4107 | { |
| 4108 | return Min(Max(x, min), max); |
| 4109 | } |
| 4110 | |
| 4111 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4112 | { |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 4113 | RValue<Float> rounded = Round(cast); |
| 4114 | |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4115 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 4116 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4117 | ::basicBlock->appendInst(round); |
| 4118 | |
| 4119 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | Type *Int::getType() |
| 4123 | { |
| 4124 | return T(Ice::IceType_i32); |
| 4125 | } |
| 4126 | |
| 4127 | Long::Long(RValue<Int> cast) |
| 4128 | { |
| 4129 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4130 | |
| 4131 | storeValue(integer); |
| 4132 | } |
| 4133 | |
| 4134 | Long::Long(RValue<UInt> cast) |
| 4135 | { |
| 4136 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4137 | |
| 4138 | storeValue(integer); |
| 4139 | } |
| 4140 | |
| 4141 | Long::Long() |
| 4142 | { |
| 4143 | } |
| 4144 | |
| 4145 | Long::Long(RValue<Long> rhs) |
| 4146 | { |
| 4147 | storeValue(rhs.value); |
| 4148 | } |
| 4149 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4150 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4151 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4152 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4153 | } |
| 4154 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4155 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4156 | { |
| 4157 | storeValue(rhs.value); |
| 4158 | |
| 4159 | return rhs; |
| 4160 | } |
| 4161 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4162 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4163 | { |
| 4164 | Value *value = rhs.loadValue(); |
| 4165 | storeValue(value); |
| 4166 | |
| 4167 | return RValue<Long>(value); |
| 4168 | } |
| 4169 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4170 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4171 | { |
| 4172 | Value *value = rhs.loadValue(); |
| 4173 | storeValue(value); |
| 4174 | |
| 4175 | return RValue<Long>(value); |
| 4176 | } |
| 4177 | |
| 4178 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4179 | { |
| 4180 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4181 | } |
| 4182 | |
| 4183 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4184 | { |
| 4185 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4186 | } |
| 4187 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4188 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4189 | { |
| 4190 | return lhs = lhs + rhs; |
| 4191 | } |
| 4192 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4193 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4194 | { |
| 4195 | return lhs = lhs - rhs; |
| 4196 | } |
| 4197 | |
| 4198 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4199 | { |
| 4200 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4201 | } |
| 4202 | |
| 4203 | Type *Long::getType() |
| 4204 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4205 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4206 | } |
| 4207 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4208 | UInt::UInt(Argument<UInt> argument) |
| 4209 | { |
| 4210 | storeValue(argument.value); |
| 4211 | } |
| 4212 | |
| 4213 | UInt::UInt(RValue<UShort> cast) |
| 4214 | { |
| 4215 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4216 | |
| 4217 | storeValue(integer); |
| 4218 | } |
| 4219 | |
| 4220 | UInt::UInt(RValue<Long> cast) |
| 4221 | { |
| 4222 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4223 | |
| 4224 | storeValue(integer); |
| 4225 | } |
| 4226 | |
| 4227 | UInt::UInt(RValue<Float> cast) |
| 4228 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4229 | // Smallest positive value representable in UInt, but not in Int |
| 4230 | const unsigned int ustart = 0x80000000u; |
| 4231 | const float ustartf = float(ustart); |
| 4232 | |
| 4233 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4234 | storeValue((~(As<Int>(cast) >> 31) & |
| 4235 | // Check if the value can be represented as an Int |
| 4236 | IfThenElse(cast >= ustartf, |
| 4237 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4238 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4239 | // Otherwise, just convert normally |
| 4240 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | UInt::UInt() |
| 4244 | { |
| 4245 | } |
| 4246 | |
| 4247 | UInt::UInt(int x) |
| 4248 | { |
| 4249 | storeValue(Nucleus::createConstantInt(x)); |
| 4250 | } |
| 4251 | |
| 4252 | UInt::UInt(unsigned int x) |
| 4253 | { |
| 4254 | storeValue(Nucleus::createConstantInt(x)); |
| 4255 | } |
| 4256 | |
| 4257 | UInt::UInt(RValue<UInt> rhs) |
| 4258 | { |
| 4259 | storeValue(rhs.value); |
| 4260 | } |
| 4261 | |
| 4262 | UInt::UInt(RValue<Int> rhs) |
| 4263 | { |
| 4264 | storeValue(rhs.value); |
| 4265 | } |
| 4266 | |
| 4267 | UInt::UInt(const UInt &rhs) |
| 4268 | { |
| 4269 | Value *value = rhs.loadValue(); |
| 4270 | storeValue(value); |
| 4271 | } |
| 4272 | |
| 4273 | UInt::UInt(const Reference<UInt> &rhs) |
| 4274 | { |
| 4275 | Value *value = rhs.loadValue(); |
| 4276 | storeValue(value); |
| 4277 | } |
| 4278 | |
| 4279 | UInt::UInt(const Int &rhs) |
| 4280 | { |
| 4281 | Value *value = rhs.loadValue(); |
| 4282 | storeValue(value); |
| 4283 | } |
| 4284 | |
| 4285 | UInt::UInt(const Reference<Int> &rhs) |
| 4286 | { |
| 4287 | Value *value = rhs.loadValue(); |
| 4288 | storeValue(value); |
| 4289 | } |
| 4290 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4291 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4292 | { |
| 4293 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4294 | } |
| 4295 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4296 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4297 | { |
| 4298 | storeValue(rhs.value); |
| 4299 | |
| 4300 | return rhs; |
| 4301 | } |
| 4302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4303 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4304 | { |
| 4305 | storeValue(rhs.value); |
| 4306 | |
| 4307 | return RValue<UInt>(rhs); |
| 4308 | } |
| 4309 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4310 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4311 | { |
| 4312 | Value *value = rhs.loadValue(); |
| 4313 | storeValue(value); |
| 4314 | |
| 4315 | return RValue<UInt>(value); |
| 4316 | } |
| 4317 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4318 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4319 | { |
| 4320 | Value *value = rhs.loadValue(); |
| 4321 | storeValue(value); |
| 4322 | |
| 4323 | return RValue<UInt>(value); |
| 4324 | } |
| 4325 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4326 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4327 | { |
| 4328 | Value *value = rhs.loadValue(); |
| 4329 | storeValue(value); |
| 4330 | |
| 4331 | return RValue<UInt>(value); |
| 4332 | } |
| 4333 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4334 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4335 | { |
| 4336 | Value *value = rhs.loadValue(); |
| 4337 | storeValue(value); |
| 4338 | |
| 4339 | return RValue<UInt>(value); |
| 4340 | } |
| 4341 | |
| 4342 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4343 | { |
| 4344 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4345 | } |
| 4346 | |
| 4347 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4348 | { |
| 4349 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4350 | } |
| 4351 | |
| 4352 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4353 | { |
| 4354 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4355 | } |
| 4356 | |
| 4357 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4358 | { |
| 4359 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4360 | } |
| 4361 | |
| 4362 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4363 | { |
| 4364 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4365 | } |
| 4366 | |
| 4367 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4368 | { |
| 4369 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4370 | } |
| 4371 | |
| 4372 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4373 | { |
| 4374 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4375 | } |
| 4376 | |
| 4377 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4378 | { |
| 4379 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4380 | } |
| 4381 | |
| 4382 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4383 | { |
| 4384 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4385 | } |
| 4386 | |
| 4387 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4388 | { |
| 4389 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4390 | } |
| 4391 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4392 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4393 | { |
| 4394 | return lhs = lhs + rhs; |
| 4395 | } |
| 4396 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4397 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4398 | { |
| 4399 | return lhs = lhs - rhs; |
| 4400 | } |
| 4401 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4402 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4403 | { |
| 4404 | return lhs = lhs * rhs; |
| 4405 | } |
| 4406 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4407 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4408 | { |
| 4409 | return lhs = lhs / rhs; |
| 4410 | } |
| 4411 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4412 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4413 | { |
| 4414 | return lhs = lhs % rhs; |
| 4415 | } |
| 4416 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4417 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4418 | { |
| 4419 | return lhs = lhs & rhs; |
| 4420 | } |
| 4421 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4422 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4423 | { |
| 4424 | return lhs = lhs | rhs; |
| 4425 | } |
| 4426 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4427 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4428 | { |
| 4429 | return lhs = lhs ^ rhs; |
| 4430 | } |
| 4431 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4432 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4433 | { |
| 4434 | return lhs = lhs << rhs; |
| 4435 | } |
| 4436 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4437 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4438 | { |
| 4439 | return lhs = lhs >> rhs; |
| 4440 | } |
| 4441 | |
| 4442 | RValue<UInt> operator+(RValue<UInt> val) |
| 4443 | { |
| 4444 | return val; |
| 4445 | } |
| 4446 | |
| 4447 | RValue<UInt> operator-(RValue<UInt> val) |
| 4448 | { |
| 4449 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4450 | } |
| 4451 | |
| 4452 | RValue<UInt> operator~(RValue<UInt> val) |
| 4453 | { |
| 4454 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4455 | } |
| 4456 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4457 | RValue<UInt> operator++(UInt &val, int) // Post-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 | RValue<UInt> res = val; |
| 4460 | val += 1; |
| 4461 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4462 | } |
| 4463 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4464 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4465 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4466 | val += 1; |
| 4467 | return val; |
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 | RValue<UInt> operator--(UInt &val, int) // Post-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 | RValue<UInt> res = val; |
| 4473 | val -= 1; |
| 4474 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4475 | } |
| 4476 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4477 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4478 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4479 | val -= 1; |
| 4480 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4484 | { |
| 4485 | return IfThenElse(x > y, x, y); |
| 4486 | } |
| 4487 | |
| 4488 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4489 | { |
| 4490 | return IfThenElse(x < y, x, y); |
| 4491 | } |
| 4492 | |
| 4493 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4494 | { |
| 4495 | return Min(Max(x, min), max); |
| 4496 | } |
| 4497 | |
| 4498 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4499 | { |
| 4500 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4501 | } |
| 4502 | |
| 4503 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4504 | { |
| 4505 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4506 | } |
| 4507 | |
| 4508 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4509 | { |
| 4510 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4511 | } |
| 4512 | |
| 4513 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4514 | { |
| 4515 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4516 | } |
| 4517 | |
| 4518 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4519 | { |
| 4520 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4521 | } |
| 4522 | |
| 4523 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4524 | { |
| 4525 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4526 | } |
| 4527 | |
| 4528 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4529 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4530 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4531 | // } |
| 4532 | |
| 4533 | Type *UInt::getType() |
| 4534 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4535 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | // Int2::Int2(RValue<Int> cast) |
| 4539 | // { |
| 4540 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4541 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4542 | // |
| 4543 | // Constant *shuffle[2]; |
| 4544 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4545 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4546 | // |
| 4547 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4548 | // |
| 4549 | // storeValue(replicate); |
| 4550 | // } |
| 4551 | |
| 4552 | Int2::Int2(RValue<Int4> cast) |
| 4553 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4554 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | Int2::Int2() |
| 4558 | { |
| 4559 | // xy.parent = this; |
| 4560 | } |
| 4561 | |
| 4562 | Int2::Int2(int x, int y) |
| 4563 | { |
| 4564 | // xy.parent = this; |
| 4565 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4566 | int64_t constantVector[2] = {x, y}; |
| 4567 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | Int2::Int2(RValue<Int2> rhs) |
| 4571 | { |
| 4572 | // xy.parent = this; |
| 4573 | |
| 4574 | storeValue(rhs.value); |
| 4575 | } |
| 4576 | |
| 4577 | Int2::Int2(const Int2 &rhs) |
| 4578 | { |
| 4579 | // xy.parent = this; |
| 4580 | |
| 4581 | Value *value = rhs.loadValue(); |
| 4582 | storeValue(value); |
| 4583 | } |
| 4584 | |
| 4585 | Int2::Int2(const Reference<Int2> &rhs) |
| 4586 | { |
| 4587 | // xy.parent = this; |
| 4588 | |
| 4589 | Value *value = rhs.loadValue(); |
| 4590 | storeValue(value); |
| 4591 | } |
| 4592 | |
| 4593 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4594 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4595 | int shuffle[4] = {0, 4, 1, 5}; |
| 4596 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4597 | |
| 4598 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4599 | } |
| 4600 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4601 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4602 | { |
| 4603 | storeValue(rhs.value); |
| 4604 | |
| 4605 | return rhs; |
| 4606 | } |
| 4607 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4608 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4609 | { |
| 4610 | Value *value = rhs.loadValue(); |
| 4611 | storeValue(value); |
| 4612 | |
| 4613 | return RValue<Int2>(value); |
| 4614 | } |
| 4615 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4616 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4617 | { |
| 4618 | Value *value = rhs.loadValue(); |
| 4619 | storeValue(value); |
| 4620 | |
| 4621 | return RValue<Int2>(value); |
| 4622 | } |
| 4623 | |
| 4624 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4625 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4626 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4630 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4631 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4635 | // { |
| 4636 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4637 | // } |
| 4638 | |
| 4639 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4640 | // { |
| 4641 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4642 | // } |
| 4643 | |
| 4644 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4645 | // { |
| 4646 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4647 | // } |
| 4648 | |
| 4649 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4650 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4651 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4655 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4656 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4660 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4661 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4665 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 4666 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4670 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 4671 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4672 | } |
| 4673 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4674 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4675 | { |
| 4676 | return lhs = lhs + rhs; |
| 4677 | } |
| 4678 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4679 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4680 | { |
| 4681 | return lhs = lhs - rhs; |
| 4682 | } |
| 4683 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4684 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4685 | // { |
| 4686 | // return lhs = lhs * rhs; |
| 4687 | // } |
| 4688 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4689 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4690 | // { |
| 4691 | // return lhs = lhs / rhs; |
| 4692 | // } |
| 4693 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4694 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4695 | // { |
| 4696 | // return lhs = lhs % rhs; |
| 4697 | // } |
| 4698 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4699 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4700 | { |
| 4701 | return lhs = lhs & rhs; |
| 4702 | } |
| 4703 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4704 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4705 | { |
| 4706 | return lhs = lhs | rhs; |
| 4707 | } |
| 4708 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4709 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4710 | { |
| 4711 | return lhs = lhs ^ rhs; |
| 4712 | } |
| 4713 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4714 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4715 | { |
| 4716 | return lhs = lhs << rhs; |
| 4717 | } |
| 4718 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4719 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4720 | { |
| 4721 | return lhs = lhs >> rhs; |
| 4722 | } |
| 4723 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4724 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4725 | // { |
| 4726 | // return val; |
| 4727 | // } |
| 4728 | |
| 4729 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4730 | // { |
| 4731 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4732 | // } |
| 4733 | |
| 4734 | RValue<Int2> operator~(RValue<Int2> val) |
| 4735 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4736 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4737 | } |
| 4738 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4739 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4740 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4741 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4742 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4743 | } |
| 4744 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4745 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4746 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4747 | int shuffle[16] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4748 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4749 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4753 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4754 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4758 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4759 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | Type *Int2::getType() |
| 4763 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4764 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | UInt2::UInt2() |
| 4768 | { |
| 4769 | // xy.parent = this; |
| 4770 | } |
| 4771 | |
| 4772 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4773 | { |
| 4774 | // xy.parent = this; |
| 4775 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4776 | int64_t constantVector[2] = {x, y}; |
| 4777 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4781 | { |
| 4782 | // xy.parent = this; |
| 4783 | |
| 4784 | storeValue(rhs.value); |
| 4785 | } |
| 4786 | |
| 4787 | UInt2::UInt2(const UInt2 &rhs) |
| 4788 | { |
| 4789 | // xy.parent = this; |
| 4790 | |
| 4791 | Value *value = rhs.loadValue(); |
| 4792 | storeValue(value); |
| 4793 | } |
| 4794 | |
| 4795 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4796 | { |
| 4797 | // xy.parent = this; |
| 4798 | |
| 4799 | Value *value = rhs.loadValue(); |
| 4800 | storeValue(value); |
| 4801 | } |
| 4802 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4803 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4804 | { |
| 4805 | storeValue(rhs.value); |
| 4806 | |
| 4807 | return rhs; |
| 4808 | } |
| 4809 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4810 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4811 | { |
| 4812 | Value *value = rhs.loadValue(); |
| 4813 | storeValue(value); |
| 4814 | |
| 4815 | return RValue<UInt2>(value); |
| 4816 | } |
| 4817 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4818 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4819 | { |
| 4820 | Value *value = rhs.loadValue(); |
| 4821 | storeValue(value); |
| 4822 | |
| 4823 | return RValue<UInt2>(value); |
| 4824 | } |
| 4825 | |
| 4826 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4827 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4828 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4829 | } |
| 4830 | |
| 4831 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4832 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4833 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4837 | // { |
| 4838 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4839 | // } |
| 4840 | |
| 4841 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4842 | // { |
| 4843 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4844 | // } |
| 4845 | |
| 4846 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4847 | // { |
| 4848 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 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::createAnd(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, RValue<UInt2> rhs) |
| 4857 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4858 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4862 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4863 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4867 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 4868 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4872 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 4873 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 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, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4907 | { |
| 4908 | return lhs = lhs | rhs; |
| 4909 | } |
| 4910 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4911 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4912 | { |
| 4913 | return lhs = lhs ^ rhs; |
| 4914 | } |
| 4915 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4916 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4917 | { |
| 4918 | return lhs = lhs << rhs; |
| 4919 | } |
| 4920 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4921 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4922 | { |
| 4923 | return lhs = lhs >> rhs; |
| 4924 | } |
| 4925 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4926 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4927 | // { |
| 4928 | // return val; |
| 4929 | // } |
| 4930 | |
| 4931 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4932 | // { |
| 4933 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4934 | // } |
| 4935 | |
| 4936 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4937 | { |
| 4938 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4939 | } |
| 4940 | |
| 4941 | Type *UInt2::getType() |
| 4942 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4943 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | Int4::Int4(RValue<Byte4> cast) |
| 4947 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4948 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4949 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4950 | |
| 4951 | Value *e; |
| 4952 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4953 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4954 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4955 | |
| 4956 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4957 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4958 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4959 | |
| 4960 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4961 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | Int4::Int4(RValue<SByte4> cast) |
| 4965 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4966 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4967 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4968 | |
| 4969 | Value *e; |
| 4970 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4971 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4972 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4973 | |
| 4974 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4975 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4976 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 4977 | |
| 4978 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 4979 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4980 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4981 | } |
| 4982 | |
| 4983 | Int4::Int4(RValue<Float4> cast) |
| 4984 | { |
| 4985 | // xyzw.parent = this; |
| 4986 | |
| 4987 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 4988 | |
| 4989 | storeValue(xyzw); |
| 4990 | } |
| 4991 | |
| 4992 | Int4::Int4(RValue<Short4> cast) |
| 4993 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4994 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4995 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 4996 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 4997 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4998 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | Int4::Int4(RValue<UShort4> cast) |
| 5002 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5003 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5004 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5005 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5006 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | Int4::Int4() |
| 5010 | { |
| 5011 | // xyzw.parent = this; |
| 5012 | } |
| 5013 | |
| 5014 | Int4::Int4(int xyzw) |
| 5015 | { |
| 5016 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5017 | } |
| 5018 | |
| 5019 | Int4::Int4(int x, int yzw) |
| 5020 | { |
| 5021 | constant(x, yzw, yzw, yzw); |
| 5022 | } |
| 5023 | |
| 5024 | Int4::Int4(int x, int y, int zw) |
| 5025 | { |
| 5026 | constant(x, y, zw, zw); |
| 5027 | } |
| 5028 | |
| 5029 | Int4::Int4(int x, int y, int z, int w) |
| 5030 | { |
| 5031 | constant(x, y, z, w); |
| 5032 | } |
| 5033 | |
| 5034 | void Int4::constant(int x, int y, int z, int w) |
| 5035 | { |
| 5036 | // xyzw.parent = this; |
| 5037 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5038 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5039 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | Int4::Int4(RValue<Int4> rhs) |
| 5043 | { |
| 5044 | // xyzw.parent = this; |
| 5045 | |
| 5046 | storeValue(rhs.value); |
| 5047 | } |
| 5048 | |
| 5049 | Int4::Int4(const Int4 &rhs) |
| 5050 | { |
| 5051 | // xyzw.parent = this; |
| 5052 | |
| 5053 | Value *value = rhs.loadValue(); |
| 5054 | storeValue(value); |
| 5055 | } |
| 5056 | |
| 5057 | Int4::Int4(const Reference<Int4> &rhs) |
| 5058 | { |
| 5059 | // xyzw.parent = this; |
| 5060 | |
| 5061 | Value *value = rhs.loadValue(); |
| 5062 | storeValue(value); |
| 5063 | } |
| 5064 | |
| 5065 | Int4::Int4(RValue<UInt4> rhs) |
| 5066 | { |
| 5067 | // xyzw.parent = this; |
| 5068 | |
| 5069 | storeValue(rhs.value); |
| 5070 | } |
| 5071 | |
| 5072 | Int4::Int4(const UInt4 &rhs) |
| 5073 | { |
| 5074 | // xyzw.parent = this; |
| 5075 | |
| 5076 | Value *value = rhs.loadValue(); |
| 5077 | storeValue(value); |
| 5078 | } |
| 5079 | |
| 5080 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5081 | { |
| 5082 | // xyzw.parent = this; |
| 5083 | |
| 5084 | Value *value = rhs.loadValue(); |
| 5085 | storeValue(value); |
| 5086 | } |
| 5087 | |
| 5088 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5089 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5090 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5091 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5092 | |
| 5093 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | Int4::Int4(RValue<Int> rhs) |
| 5097 | { |
| 5098 | // xyzw.parent = this; |
| 5099 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5100 | Value *vector = loadValue(); |
| 5101 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5102 | |
| 5103 | int swizzle[4] = {0, 0, 0, 0}; |
| 5104 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 5105 | |
| 5106 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | Int4::Int4(const Int &rhs) |
| 5110 | { |
| 5111 | // xyzw.parent = this; |
| 5112 | |
| 5113 | *this = RValue<Int>(rhs.loadValue()); |
| 5114 | } |
| 5115 | |
| 5116 | Int4::Int4(const Reference<Int> &rhs) |
| 5117 | { |
| 5118 | // xyzw.parent = this; |
| 5119 | |
| 5120 | *this = RValue<Int>(rhs.loadValue()); |
| 5121 | } |
| 5122 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5123 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5124 | { |
| 5125 | storeValue(rhs.value); |
| 5126 | |
| 5127 | return rhs; |
| 5128 | } |
| 5129 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5130 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5131 | { |
| 5132 | Value *value = rhs.loadValue(); |
| 5133 | storeValue(value); |
| 5134 | |
| 5135 | return RValue<Int4>(value); |
| 5136 | } |
| 5137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5138 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5139 | { |
| 5140 | Value *value = rhs.loadValue(); |
| 5141 | storeValue(value); |
| 5142 | |
| 5143 | return RValue<Int4>(value); |
| 5144 | } |
| 5145 | |
| 5146 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5147 | { |
| 5148 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5149 | } |
| 5150 | |
| 5151 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5152 | { |
| 5153 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5154 | } |
| 5155 | |
| 5156 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5157 | { |
| 5158 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5159 | } |
| 5160 | |
| 5161 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5162 | { |
| 5163 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5164 | } |
| 5165 | |
| 5166 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5167 | { |
| 5168 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5169 | } |
| 5170 | |
| 5171 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5172 | { |
| 5173 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5174 | } |
| 5175 | |
| 5176 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5177 | { |
| 5178 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5179 | } |
| 5180 | |
| 5181 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5182 | { |
| 5183 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5184 | } |
| 5185 | |
| 5186 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5187 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 5188 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5192 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 5193 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5197 | { |
| 5198 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5199 | } |
| 5200 | |
| 5201 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5202 | { |
| 5203 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5204 | } |
| 5205 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5206 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5207 | { |
| 5208 | return lhs = lhs + rhs; |
| 5209 | } |
| 5210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5211 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5212 | { |
| 5213 | return lhs = lhs - rhs; |
| 5214 | } |
| 5215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5216 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5217 | { |
| 5218 | return lhs = lhs * rhs; |
| 5219 | } |
| 5220 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5221 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5222 | // { |
| 5223 | // return lhs = lhs / rhs; |
| 5224 | // } |
| 5225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5226 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5227 | // { |
| 5228 | // return lhs = lhs % rhs; |
| 5229 | // } |
| 5230 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5231 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5232 | { |
| 5233 | return lhs = lhs & rhs; |
| 5234 | } |
| 5235 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5236 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5237 | { |
| 5238 | return lhs = lhs | rhs; |
| 5239 | } |
| 5240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5241 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5242 | { |
| 5243 | return lhs = lhs ^ rhs; |
| 5244 | } |
| 5245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5246 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5247 | { |
| 5248 | return lhs = lhs << rhs; |
| 5249 | } |
| 5250 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5251 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5252 | { |
| 5253 | return lhs = lhs >> rhs; |
| 5254 | } |
| 5255 | |
| 5256 | RValue<Int4> operator+(RValue<Int4> val) |
| 5257 | { |
| 5258 | return val; |
| 5259 | } |
| 5260 | |
| 5261 | RValue<Int4> operator-(RValue<Int4> val) |
| 5262 | { |
| 5263 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5264 | } |
| 5265 | |
| 5266 | RValue<Int4> operator~(RValue<Int4> val) |
| 5267 | { |
| 5268 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5269 | } |
| 5270 | |
| 5271 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5272 | { |
| 5273 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5274 | } |
| 5275 | |
| 5276 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5277 | { |
| 5278 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType())); |
| 5279 | } |
| 5280 | |
| 5281 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5282 | { |
| 5283 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType())); |
| 5284 | } |
| 5285 | |
| 5286 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5287 | { |
| 5288 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5289 | } |
| 5290 | |
| 5291 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5292 | { |
| 5293 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType())); |
| 5294 | } |
| 5295 | |
| 5296 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5297 | { |
| 5298 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType())); |
| 5299 | } |
| 5300 | |
| 5301 | RValue<Int4> Max(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::Sle, 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> Min(RValue<Int4> x, RValue<Int4> y) |
| 5315 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5316 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5317 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5318 | ::basicBlock->appendInst(cmp); |
| 5319 | |
| 5320 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5321 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5322 | ::basicBlock->appendInst(select); |
| 5323 | |
| 5324 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5328 | { |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 5329 | RValue<Float4> rounded = Round(cast); |
| 5330 | |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5331 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
Nicolas Capens | b13cf49 | 2016-12-08 08:58:54 -0500 | [diff] [blame] | 5332 | auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5333 | ::basicBlock->appendInst(round); |
| 5334 | |
| 5335 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5339 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5340 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5341 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5342 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5343 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5344 | pack->addArg(x.value); |
| 5345 | pack->addArg(y.value); |
| 5346 | ::basicBlock->appendInst(pack); |
| 5347 | |
| 5348 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5352 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5353 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5357 | { |
| 5358 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5359 | } |
| 5360 | |
| 5361 | RValue<Int> SignMask(RValue<Int4> x) |
| 5362 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5363 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5364 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5365 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5366 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5367 | movmsk->addArg(x.value); |
| 5368 | ::basicBlock->appendInst(movmsk); |
| 5369 | |
| 5370 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5374 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5375 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | Type *Int4::getType() |
| 5379 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5380 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | UInt4::UInt4(RValue<Float4> cast) |
| 5384 | { |
| 5385 | // xyzw.parent = this; |
| 5386 | |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5387 | // Smallest positive value representable in UInt, but not in Int |
| 5388 | const unsigned int ustart = 0x80000000u; |
| 5389 | const float ustartf = float(ustart); |
| 5390 | |
| 5391 | // Check if the value can be represented as an Int |
| 5392 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5393 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5394 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5395 | // Otherwise, just convert normally |
| 5396 | (~uiValue & Int4(cast)); |
| 5397 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5398 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | UInt4::UInt4() |
| 5402 | { |
| 5403 | // xyzw.parent = this; |
| 5404 | } |
| 5405 | |
| 5406 | UInt4::UInt4(int xyzw) |
| 5407 | { |
| 5408 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5409 | } |
| 5410 | |
| 5411 | UInt4::UInt4(int x, int yzw) |
| 5412 | { |
| 5413 | constant(x, yzw, yzw, yzw); |
| 5414 | } |
| 5415 | |
| 5416 | UInt4::UInt4(int x, int y, int zw) |
| 5417 | { |
| 5418 | constant(x, y, zw, zw); |
| 5419 | } |
| 5420 | |
| 5421 | UInt4::UInt4(int x, int y, int z, int w) |
| 5422 | { |
| 5423 | constant(x, y, z, w); |
| 5424 | } |
| 5425 | |
| 5426 | void UInt4::constant(int x, int y, int z, int w) |
| 5427 | { |
| 5428 | // xyzw.parent = this; |
| 5429 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5430 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5431 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5435 | { |
| 5436 | // xyzw.parent = this; |
| 5437 | |
| 5438 | storeValue(rhs.value); |
| 5439 | } |
| 5440 | |
| 5441 | UInt4::UInt4(const UInt4 &rhs) |
| 5442 | { |
| 5443 | // xyzw.parent = this; |
| 5444 | |
| 5445 | Value *value = rhs.loadValue(); |
| 5446 | storeValue(value); |
| 5447 | } |
| 5448 | |
| 5449 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5450 | { |
| 5451 | // xyzw.parent = this; |
| 5452 | |
| 5453 | Value *value = rhs.loadValue(); |
| 5454 | storeValue(value); |
| 5455 | } |
| 5456 | |
| 5457 | UInt4::UInt4(RValue<Int4> rhs) |
| 5458 | { |
| 5459 | // xyzw.parent = this; |
| 5460 | |
| 5461 | storeValue(rhs.value); |
| 5462 | } |
| 5463 | |
| 5464 | UInt4::UInt4(const Int4 &rhs) |
| 5465 | { |
| 5466 | // xyzw.parent = this; |
| 5467 | |
| 5468 | Value *value = rhs.loadValue(); |
| 5469 | storeValue(value); |
| 5470 | } |
| 5471 | |
| 5472 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5473 | { |
| 5474 | // xyzw.parent = this; |
| 5475 | |
| 5476 | Value *value = rhs.loadValue(); |
| 5477 | storeValue(value); |
| 5478 | } |
| 5479 | |
| 5480 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5481 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5482 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5483 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5484 | |
| 5485 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5486 | } |
| 5487 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5488 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5489 | { |
| 5490 | storeValue(rhs.value); |
| 5491 | |
| 5492 | return rhs; |
| 5493 | } |
| 5494 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5495 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5496 | { |
| 5497 | Value *value = rhs.loadValue(); |
| 5498 | storeValue(value); |
| 5499 | |
| 5500 | return RValue<UInt4>(value); |
| 5501 | } |
| 5502 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5503 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5504 | { |
| 5505 | Value *value = rhs.loadValue(); |
| 5506 | storeValue(value); |
| 5507 | |
| 5508 | return RValue<UInt4>(value); |
| 5509 | } |
| 5510 | |
| 5511 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5512 | { |
| 5513 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5514 | } |
| 5515 | |
| 5516 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5517 | { |
| 5518 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5519 | } |
| 5520 | |
| 5521 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5522 | { |
| 5523 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5524 | } |
| 5525 | |
| 5526 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5527 | { |
| 5528 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5529 | } |
| 5530 | |
| 5531 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5532 | { |
| 5533 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5534 | } |
| 5535 | |
| 5536 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5537 | { |
| 5538 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5539 | } |
| 5540 | |
| 5541 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5542 | { |
| 5543 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5544 | } |
| 5545 | |
| 5546 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5547 | { |
| 5548 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5549 | } |
| 5550 | |
| 5551 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5552 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 5553 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5554 | } |
| 5555 | |
| 5556 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5557 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame^] | 5558 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5562 | { |
| 5563 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5564 | } |
| 5565 | |
| 5566 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5567 | { |
| 5568 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5569 | } |
| 5570 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5571 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5572 | { |
| 5573 | return lhs = lhs + rhs; |
| 5574 | } |
| 5575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5576 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5577 | { |
| 5578 | return lhs = lhs - rhs; |
| 5579 | } |
| 5580 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5581 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5582 | { |
| 5583 | return lhs = lhs * rhs; |
| 5584 | } |
| 5585 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5586 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5587 | // { |
| 5588 | // return lhs = lhs / rhs; |
| 5589 | // } |
| 5590 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5591 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5592 | // { |
| 5593 | // return lhs = lhs % rhs; |
| 5594 | // } |
| 5595 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5596 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5597 | { |
| 5598 | return lhs = lhs & rhs; |
| 5599 | } |
| 5600 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5601 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5602 | { |
| 5603 | return lhs = lhs | rhs; |
| 5604 | } |
| 5605 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5606 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5607 | { |
| 5608 | return lhs = lhs ^ rhs; |
| 5609 | } |
| 5610 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5611 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5612 | { |
| 5613 | return lhs = lhs << rhs; |
| 5614 | } |
| 5615 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5616 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5617 | { |
| 5618 | return lhs = lhs >> rhs; |
| 5619 | } |
| 5620 | |
| 5621 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5622 | { |
| 5623 | return val; |
| 5624 | } |
| 5625 | |
| 5626 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5627 | { |
| 5628 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5629 | } |
| 5630 | |
| 5631 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5632 | { |
| 5633 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5634 | } |
| 5635 | |
| 5636 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5637 | { |
| 5638 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType())); |
| 5639 | } |
| 5640 | |
| 5641 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5642 | { |
| 5643 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType())); |
| 5644 | } |
| 5645 | |
| 5646 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5647 | { |
| 5648 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType())); |
| 5649 | } |
| 5650 | |
| 5651 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5652 | { |
| 5653 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType())); |
| 5654 | } |
| 5655 | |
| 5656 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5657 | { |
| 5658 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType())); |
| 5659 | } |
| 5660 | |
| 5661 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5662 | { |
| 5663 | return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType())); |
| 5664 | } |
| 5665 | |
| 5666 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5667 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5668 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5669 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5670 | ::basicBlock->appendInst(cmp); |
| 5671 | |
| 5672 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5673 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5674 | ::basicBlock->appendInst(select); |
| 5675 | |
| 5676 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5680 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5681 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5682 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5683 | ::basicBlock->appendInst(cmp); |
| 5684 | |
| 5685 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5686 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5687 | ::basicBlock->appendInst(select); |
| 5688 | |
| 5689 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5693 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5694 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5695 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5696 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5697 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5698 | pack->addArg(x.value); |
| 5699 | pack->addArg(y.value); |
| 5700 | ::basicBlock->appendInst(pack); |
| 5701 | |
| 5702 | return RValue<UShort8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | Type *UInt4::getType() |
| 5706 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5707 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | Float::Float(RValue<Int> cast) |
| 5711 | { |
| 5712 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5713 | |
| 5714 | storeValue(integer); |
| 5715 | } |
| 5716 | |
| 5717 | Float::Float() |
| 5718 | { |
| 5719 | } |
| 5720 | |
| 5721 | Float::Float(float x) |
| 5722 | { |
| 5723 | storeValue(Nucleus::createConstantFloat(x)); |
| 5724 | } |
| 5725 | |
| 5726 | Float::Float(RValue<Float> rhs) |
| 5727 | { |
| 5728 | storeValue(rhs.value); |
| 5729 | } |
| 5730 | |
| 5731 | Float::Float(const Float &rhs) |
| 5732 | { |
| 5733 | Value *value = rhs.loadValue(); |
| 5734 | storeValue(value); |
| 5735 | } |
| 5736 | |
| 5737 | Float::Float(const Reference<Float> &rhs) |
| 5738 | { |
| 5739 | Value *value = rhs.loadValue(); |
| 5740 | storeValue(value); |
| 5741 | } |
| 5742 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5743 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5744 | { |
| 5745 | storeValue(rhs.value); |
| 5746 | |
| 5747 | return rhs; |
| 5748 | } |
| 5749 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5750 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5751 | { |
| 5752 | Value *value = rhs.loadValue(); |
| 5753 | storeValue(value); |
| 5754 | |
| 5755 | return RValue<Float>(value); |
| 5756 | } |
| 5757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5758 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5759 | { |
| 5760 | Value *value = rhs.loadValue(); |
| 5761 | storeValue(value); |
| 5762 | |
| 5763 | return RValue<Float>(value); |
| 5764 | } |
| 5765 | |
| 5766 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5767 | { |
| 5768 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5769 | } |
| 5770 | |
| 5771 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5772 | { |
| 5773 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5774 | } |
| 5775 | |
| 5776 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5777 | { |
| 5778 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5779 | } |
| 5780 | |
| 5781 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5782 | { |
| 5783 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5784 | } |
| 5785 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5786 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5787 | { |
| 5788 | return lhs = lhs + rhs; |
| 5789 | } |
| 5790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5791 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5792 | { |
| 5793 | return lhs = lhs - rhs; |
| 5794 | } |
| 5795 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5796 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5797 | { |
| 5798 | return lhs = lhs * rhs; |
| 5799 | } |
| 5800 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5801 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5802 | { |
| 5803 | return lhs = lhs / rhs; |
| 5804 | } |
| 5805 | |
| 5806 | RValue<Float> operator+(RValue<Float> val) |
| 5807 | { |
| 5808 | return val; |
| 5809 | } |
| 5810 | |
| 5811 | RValue<Float> operator-(RValue<Float> val) |
| 5812 | { |
| 5813 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5814 | } |
| 5815 | |
| 5816 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5817 | { |
| 5818 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5819 | } |
| 5820 | |
| 5821 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5822 | { |
| 5823 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5824 | } |
| 5825 | |
| 5826 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5827 | { |
| 5828 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5829 | } |
| 5830 | |
| 5831 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5832 | { |
| 5833 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5834 | } |
| 5835 | |
| 5836 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5837 | { |
| 5838 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5839 | } |
| 5840 | |
| 5841 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5842 | { |
| 5843 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5844 | } |
| 5845 | |
| 5846 | RValue<Float> Abs(RValue<Float> x) |
| 5847 | { |
| 5848 | return IfThenElse(x > 0.0f, x, -x); |
| 5849 | } |
| 5850 | |
| 5851 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5852 | { |
| 5853 | return IfThenElse(x > y, x, y); |
| 5854 | } |
| 5855 | |
| 5856 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5857 | { |
| 5858 | return IfThenElse(x < y, x, y); |
| 5859 | } |
| 5860 | |
| 5861 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5862 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5863 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5867 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5868 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | RValue<Float> Sqrt(RValue<Float> x) |
| 5872 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5873 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5874 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5875 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5876 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5877 | sqrt->addArg(x.value); |
| 5878 | ::basicBlock->appendInst(sqrt); |
| 5879 | |
| 5880 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5881 | } |
| 5882 | |
| 5883 | RValue<Float> Round(RValue<Float> x) |
| 5884 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5885 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | RValue<Float> Trunc(RValue<Float> x) |
| 5889 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5890 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | RValue<Float> Frac(RValue<Float> x) |
| 5894 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5895 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | RValue<Float> Floor(RValue<Float> x) |
| 5899 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5900 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | RValue<Float> Ceil(RValue<Float> x) |
| 5904 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5905 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | Type *Float::getType() |
| 5909 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5910 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | Float2::Float2(RValue<Float4> cast) |
| 5914 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5915 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | Type *Float2::getType() |
| 5919 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5920 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | Float4::Float4(RValue<Byte4> cast) |
| 5924 | { |
| 5925 | xyzw.parent = this; |
| 5926 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5927 | Value *a = Int4(cast).loadValue(); |
| 5928 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5929 | |
| 5930 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | Float4::Float4(RValue<SByte4> cast) |
| 5934 | { |
| 5935 | xyzw.parent = this; |
| 5936 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5937 | Value *a = Int4(cast).loadValue(); |
| 5938 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5939 | |
| 5940 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | Float4::Float4(RValue<Short4> cast) |
| 5944 | { |
| 5945 | xyzw.parent = this; |
| 5946 | |
| 5947 | Int4 c(cast); |
| 5948 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5949 | } |
| 5950 | |
| 5951 | Float4::Float4(RValue<UShort4> cast) |
| 5952 | { |
| 5953 | xyzw.parent = this; |
| 5954 | |
| 5955 | Int4 c(cast); |
| 5956 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5957 | } |
| 5958 | |
| 5959 | Float4::Float4(RValue<Int4> cast) |
| 5960 | { |
| 5961 | xyzw.parent = this; |
| 5962 | |
| 5963 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5964 | |
| 5965 | storeValue(xyzw); |
| 5966 | } |
| 5967 | |
| 5968 | Float4::Float4(RValue<UInt4> cast) |
| 5969 | { |
| 5970 | xyzw.parent = this; |
| 5971 | |
| 5972 | Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType()); |
| 5973 | |
| 5974 | storeValue(xyzw); |
| 5975 | } |
| 5976 | |
| 5977 | Float4::Float4() |
| 5978 | { |
| 5979 | xyzw.parent = this; |
| 5980 | } |
| 5981 | |
| 5982 | Float4::Float4(float xyzw) |
| 5983 | { |
| 5984 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5985 | } |
| 5986 | |
| 5987 | Float4::Float4(float x, float yzw) |
| 5988 | { |
| 5989 | constant(x, yzw, yzw, yzw); |
| 5990 | } |
| 5991 | |
| 5992 | Float4::Float4(float x, float y, float zw) |
| 5993 | { |
| 5994 | constant(x, y, zw, zw); |
| 5995 | } |
| 5996 | |
| 5997 | Float4::Float4(float x, float y, float z, float w) |
| 5998 | { |
| 5999 | constant(x, y, z, w); |
| 6000 | } |
| 6001 | |
| 6002 | void Float4::constant(float x, float y, float z, float w) |
| 6003 | { |
| 6004 | xyzw.parent = this; |
| 6005 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6006 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6007 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6008 | } |
| 6009 | |
| 6010 | Float4::Float4(RValue<Float4> rhs) |
| 6011 | { |
| 6012 | xyzw.parent = this; |
| 6013 | |
| 6014 | storeValue(rhs.value); |
| 6015 | } |
| 6016 | |
| 6017 | Float4::Float4(const Float4 &rhs) |
| 6018 | { |
| 6019 | xyzw.parent = this; |
| 6020 | |
| 6021 | Value *value = rhs.loadValue(); |
| 6022 | storeValue(value); |
| 6023 | } |
| 6024 | |
| 6025 | Float4::Float4(const Reference<Float4> &rhs) |
| 6026 | { |
| 6027 | xyzw.parent = this; |
| 6028 | |
| 6029 | Value *value = rhs.loadValue(); |
| 6030 | storeValue(value); |
| 6031 | } |
| 6032 | |
| 6033 | Float4::Float4(RValue<Float> rhs) |
| 6034 | { |
| 6035 | xyzw.parent = this; |
| 6036 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6037 | Value *vector = loadValue(); |
| 6038 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 6039 | |
| 6040 | int swizzle[4] = {0, 0, 0, 0}; |
| 6041 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 6042 | |
| 6043 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | Float4::Float4(const Float &rhs) |
| 6047 | { |
| 6048 | xyzw.parent = this; |
| 6049 | |
| 6050 | *this = RValue<Float>(rhs.loadValue()); |
| 6051 | } |
| 6052 | |
| 6053 | Float4::Float4(const Reference<Float> &rhs) |
| 6054 | { |
| 6055 | xyzw.parent = this; |
| 6056 | |
| 6057 | *this = RValue<Float>(rhs.loadValue()); |
| 6058 | } |
| 6059 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6060 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6061 | { |
| 6062 | return *this = Float4(x, x, x, x); |
| 6063 | } |
| 6064 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6065 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6066 | { |
| 6067 | storeValue(rhs.value); |
| 6068 | |
| 6069 | return rhs; |
| 6070 | } |
| 6071 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6072 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6073 | { |
| 6074 | Value *value = rhs.loadValue(); |
| 6075 | storeValue(value); |
| 6076 | |
| 6077 | return RValue<Float4>(value); |
| 6078 | } |
| 6079 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6080 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6081 | { |
| 6082 | Value *value = rhs.loadValue(); |
| 6083 | storeValue(value); |
| 6084 | |
| 6085 | return RValue<Float4>(value); |
| 6086 | } |
| 6087 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6088 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6089 | { |
| 6090 | return *this = Float4(rhs); |
| 6091 | } |
| 6092 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6093 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6094 | { |
| 6095 | return *this = Float4(rhs); |
| 6096 | } |
| 6097 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6098 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6099 | { |
| 6100 | return *this = Float4(rhs); |
| 6101 | } |
| 6102 | |
| 6103 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6104 | { |
| 6105 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6106 | } |
| 6107 | |
| 6108 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6109 | { |
| 6110 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6111 | } |
| 6112 | |
| 6113 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6114 | { |
| 6115 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6116 | } |
| 6117 | |
| 6118 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6119 | { |
| 6120 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6121 | } |
| 6122 | |
| 6123 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6124 | { |
| 6125 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6126 | } |
| 6127 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6128 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6129 | { |
| 6130 | return lhs = lhs + rhs; |
| 6131 | } |
| 6132 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6133 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6134 | { |
| 6135 | return lhs = lhs - rhs; |
| 6136 | } |
| 6137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6138 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6139 | { |
| 6140 | return lhs = lhs * rhs; |
| 6141 | } |
| 6142 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6143 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6144 | { |
| 6145 | return lhs = lhs / rhs; |
| 6146 | } |
| 6147 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6148 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6149 | { |
| 6150 | return lhs = lhs % rhs; |
| 6151 | } |
| 6152 | |
| 6153 | RValue<Float4> operator+(RValue<Float4> val) |
| 6154 | { |
| 6155 | return val; |
| 6156 | } |
| 6157 | |
| 6158 | RValue<Float4> operator-(RValue<Float4> val) |
| 6159 | { |
| 6160 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6161 | } |
| 6162 | |
| 6163 | RValue<Float4> Abs(RValue<Float4> x) |
| 6164 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6165 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6166 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6167 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6168 | |
| 6169 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6173 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6174 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6175 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value); |
| 6176 | ::basicBlock->appendInst(cmp); |
| 6177 | |
| 6178 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6179 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6180 | ::basicBlock->appendInst(select); |
| 6181 | |
| 6182 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6183 | } |
| 6184 | |
| 6185 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6186 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6187 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6188 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value); |
| 6189 | ::basicBlock->appendInst(cmp); |
| 6190 | |
| 6191 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6192 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6193 | ::basicBlock->appendInst(select); |
| 6194 | |
| 6195 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6199 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6200 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6204 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6205 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6209 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6210 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6211 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6212 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6213 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6214 | sqrt->addArg(x.value); |
| 6215 | ::basicBlock->appendInst(sqrt); |
| 6216 | |
| 6217 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6218 | } |
| 6219 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6220 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6221 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6222 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6226 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6227 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6231 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6232 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6236 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6237 | int shuffle[4] = |
| 6238 | { |
| 6239 | ((imm >> 0) & 0x03) + 0, |
| 6240 | ((imm >> 2) & 0x03) + 0, |
| 6241 | ((imm >> 4) & 0x03) + 4, |
| 6242 | ((imm >> 6) & 0x03) + 4, |
| 6243 | }; |
| 6244 | |
| 6245 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6249 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6250 | int shuffle[4] = {0, 4, 1, 5}; |
| 6251 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6255 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6256 | int shuffle[4] = {2, 6, 3, 7}; |
| 6257 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6261 | { |
| 6262 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6263 | Value *result = createMask4(vector, rhs.value, select); |
| 6264 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6265 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6266 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | RValue<Int> SignMask(RValue<Float4> x) |
| 6270 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6271 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6272 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6273 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6274 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6275 | movmsk->addArg(x.value); |
| 6276 | ::basicBlock->appendInst(movmsk); |
| 6277 | |
| 6278 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6282 | { |
| 6283 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType())); |
| 6284 | } |
| 6285 | |
| 6286 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6287 | { |
| 6288 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType())); |
| 6289 | } |
| 6290 | |
| 6291 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6292 | { |
| 6293 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType())); |
| 6294 | } |
| 6295 | |
| 6296 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6297 | { |
| 6298 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType())); |
| 6299 | } |
| 6300 | |
| 6301 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6302 | { |
| 6303 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType())); |
| 6304 | } |
| 6305 | |
| 6306 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6307 | { |
| 6308 | return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType())); |
| 6309 | } |
| 6310 | |
| 6311 | RValue<Float4> Round(RValue<Float4> x) |
| 6312 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6313 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6314 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6315 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6316 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6317 | round->addArg(x.value); |
| 6318 | round->addArg(::context->getConstantInt32(0)); |
| 6319 | ::basicBlock->appendInst(round); |
| 6320 | |
| 6321 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6325 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6326 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6327 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6328 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6329 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6330 | round->addArg(x.value); |
| 6331 | round->addArg(::context->getConstantInt32(3)); |
| 6332 | ::basicBlock->appendInst(round); |
| 6333 | |
| 6334 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | RValue<Float4> Frac(RValue<Float4> x) |
| 6338 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6339 | return x - Floor(x); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | RValue<Float4> Floor(RValue<Float4> x) |
| 6343 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6344 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6345 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6346 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6347 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6348 | round->addArg(x.value); |
| 6349 | round->addArg(::context->getConstantInt32(1)); |
| 6350 | ::basicBlock->appendInst(round); |
| 6351 | |
| 6352 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6356 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6357 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6358 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6359 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6360 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6361 | round->addArg(x.value); |
| 6362 | round->addArg(::context->getConstantInt32(2)); |
| 6363 | ::basicBlock->appendInst(round); |
| 6364 | |
| 6365 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | Type *Float4::getType() |
| 6369 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6370 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6374 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6375 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6379 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6380 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6384 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6385 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6386 | } |
| 6387 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6388 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6389 | { |
| 6390 | return lhs = lhs + offset; |
| 6391 | } |
| 6392 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6393 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6394 | { |
| 6395 | return lhs = lhs + offset; |
| 6396 | } |
| 6397 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6398 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6399 | { |
| 6400 | return lhs = lhs + offset; |
| 6401 | } |
| 6402 | |
| 6403 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6404 | { |
| 6405 | return lhs + -offset; |
| 6406 | } |
| 6407 | |
| 6408 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6409 | { |
| 6410 | return lhs + -offset; |
| 6411 | } |
| 6412 | |
| 6413 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6414 | { |
| 6415 | return lhs + -offset; |
| 6416 | } |
| 6417 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6418 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6419 | { |
| 6420 | return lhs = lhs - offset; |
| 6421 | } |
| 6422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6423 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6424 | { |
| 6425 | return lhs = lhs - offset; |
| 6426 | } |
| 6427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6428 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6429 | { |
| 6430 | return lhs = lhs - offset; |
| 6431 | } |
| 6432 | |
| 6433 | void Return() |
| 6434 | { |
| 6435 | Nucleus::createRetVoid(); |
| 6436 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6437 | Nucleus::createUnreachable(); |
| 6438 | } |
| 6439 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6440 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6441 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6442 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6443 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6444 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6445 | } |
| 6446 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6447 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
| 6448 | { |
| 6449 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6450 | Nucleus::setInsertBlock(bodyBB); |
| 6451 | |
| 6452 | return true; |
| 6453 | } |
| 6454 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6455 | RValue<Long> Ticks() |
| 6456 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6457 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6458 | } |
| 6459 | } |