Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "Nucleus.hpp" |
| 16 | |
| 17 | #include "Reactor.hpp" |
| 18 | #include "Routine.hpp" |
| 19 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 20 | #include "Optimizer.hpp" |
| 21 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 22 | #include "src/IceTypes.h" |
| 23 | #include "src/IceCfg.h" |
| 24 | #include "src/IceELFStreamer.h" |
| 25 | #include "src/IceGlobalContext.h" |
| 26 | #include "src/IceCfgNode.h" |
| 27 | #include "src/IceELFObjectWriter.h" |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 28 | #include "src/IceGlobalInits.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 29 | |
| 30 | #include "llvm/Support/FileSystem.h" |
| 31 | #include "llvm/Support/raw_os_ostream.h" |
| 32 | |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 33 | #if defined(_WIN32) |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 34 | #ifndef WIN32_LEAN_AND_MEAN |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 35 | #define WIN32_LEAN_AND_MEAN |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 36 | #endif // !WIN32_LEAN_AND_MEAN |
| 37 | #ifndef NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 38 | #define NOMINMAX |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 39 | #endif // !NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 40 | #include <Windows.h> |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 41 | #else |
| 42 | #include <sys/mman.h> |
Nicolas Capens | 8b27574 | 2017-01-20 17:11:41 -0500 | [diff] [blame] | 43 | #if !defined(MAP_ANONYMOUS)
|
| 44 | #define MAP_ANONYMOUS MAP_ANON
|
| 45 | #endif |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 46 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 47 | |
| 48 | #include <mutex> |
| 49 | #include <limits> |
| 50 | #include <iostream> |
| 51 | #include <cassert> |
| 52 | |
| 53 | namespace |
| 54 | { |
| 55 | Ice::GlobalContext *context = nullptr; |
| 56 | Ice::Cfg *function = nullptr; |
| 57 | Ice::CfgNode *basicBlock = nullptr; |
| 58 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
| 59 | sw::Routine *routine = nullptr; |
| 60 | |
| 61 | std::mutex codegenMutex; |
| 62 | |
| 63 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 64 | Ice::Fdstream *out = nullptr; |
| 65 | } |
| 66 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 67 | namespace |
| 68 | { |
| 69 | class CPUID |
| 70 | { |
| 71 | public: |
| 72 | const static bool SSE4_1; |
| 73 | |
| 74 | private: |
| 75 | static void cpuid(int registers[4], int info) |
| 76 | { |
| 77 | #if defined(_WIN32) |
| 78 | __cpuid(registers, info); |
| 79 | #else |
| 80 | __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); |
| 81 | #endif |
| 82 | } |
| 83 | |
| 84 | static bool detectSSE4_1() |
| 85 | { |
| 86 | int registers[4]; |
| 87 | cpuid(registers, 1); |
| 88 | return (registers[2] & 0x00080000) != 0; |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | const bool CPUID::SSE4_1 = CPUID::detectSSE4_1(); |
| 93 | } |
| 94 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 95 | namespace sw |
| 96 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 97 | enum EmulatedType |
| 98 | { |
| 99 | EmulatedShift = 16, |
| 100 | EmulatedV2 = 2 << EmulatedShift, |
| 101 | EmulatedV4 = 4 << EmulatedShift, |
| 102 | EmulatedV8 = 8 << EmulatedShift, |
| 103 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 104 | |
| 105 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 106 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 107 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 108 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 109 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 110 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 111 | }; |
| 112 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 113 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 114 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 115 | class BasicBlock : public Ice::CfgNode {}; |
| 116 | |
| 117 | Ice::Type T(Type *t) |
| 118 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 119 | static_assert(static_cast<unsigned int>(Ice::IceType_NUM) < static_cast<unsigned int>(EmulatedBits), "Ice::Type overlaps with our emulated types!"); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 120 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | Type *T(Ice::Type t) |
| 124 | { |
| 125 | return reinterpret_cast<Type*>(t); |
| 126 | } |
| 127 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 128 | Type *T(EmulatedType t) |
| 129 | { |
| 130 | return reinterpret_cast<Type*>(t); |
| 131 | } |
| 132 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 133 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 134 | { |
| 135 | return reinterpret_cast<Value*>(v); |
| 136 | } |
| 137 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 138 | BasicBlock *B(Ice::CfgNode *b) |
| 139 | { |
| 140 | return reinterpret_cast<BasicBlock*>(b); |
| 141 | } |
| 142 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 143 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 144 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 145 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 146 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 147 | |
| 148 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 149 | { |
| 150 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 151 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 152 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 153 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 154 | { |
| 155 | return §ionHeader(elfHeader)[index]; |
| 156 | } |
| 157 | |
| 158 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 159 | { |
| 160 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 161 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 162 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 163 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 164 | uint32_t index = relocation.getSymbol(); |
| 165 | int table = relocationTable.sh_link; |
| 166 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 167 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 168 | if(index != SHN_UNDEF) |
| 169 | { |
| 170 | if(table == SHN_UNDEF) return nullptr; |
| 171 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 172 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 173 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 174 | if(index >= symtab_entries) |
| 175 | { |
| 176 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 177 | return nullptr; |
| 178 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 179 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 180 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 181 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 182 | uint16_t section = symbol.st_shndx; |
| 183 | |
| 184 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 185 | { |
| 186 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 187 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | return nullptr; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | switch(relocation.getType()) |
| 196 | { |
| 197 | case R_386_NONE: |
| 198 | // No relocation |
| 199 | break; |
| 200 | case R_386_32: |
| 201 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 202 | break; |
| 203 | // case R_386_PC32: |
| 204 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 205 | // break; |
| 206 | default: |
| 207 | assert(false && "Unsupported relocation type"); |
| 208 | return nullptr; |
| 209 | } |
| 210 | |
| 211 | return symbolValue; |
| 212 | } |
| 213 | |
| 214 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 215 | { |
| 216 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 217 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 218 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 219 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 220 | uint32_t index = relocation.getSymbol(); |
| 221 | int table = relocationTable.sh_link; |
| 222 | void *symbolValue = nullptr; |
| 223 | |
| 224 | if(index != SHN_UNDEF) |
| 225 | { |
| 226 | if(table == SHN_UNDEF) return nullptr; |
| 227 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 228 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 229 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 230 | if(index >= symtab_entries) |
| 231 | { |
| 232 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 233 | return nullptr; |
| 234 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 235 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 236 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 237 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 238 | uint16_t section = symbol.st_shndx; |
| 239 | |
| 240 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 241 | { |
| 242 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 243 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | return nullptr; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | switch(relocation.getType()) |
| 252 | { |
| 253 | case R_X86_64_NONE: |
| 254 | // No relocation |
| 255 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 256 | case R_X86_64_64: |
| 257 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 258 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 259 | case R_X86_64_PC32: |
| 260 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 261 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 262 | case R_X86_64_32S: |
| 263 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 264 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 265 | default: |
| 266 | assert(false && "Unsupported relocation type"); |
| 267 | return nullptr; |
| 268 | } |
| 269 | |
| 270 | return symbolValue; |
| 271 | } |
| 272 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 273 | void *loadImage(uint8_t *const elfImage) |
| 274 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 275 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 276 | |
| 277 | if(!elfHeader->checkMagic()) |
| 278 | { |
| 279 | return nullptr; |
| 280 | } |
| 281 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 282 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 283 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 284 | assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386); |
| 285 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 286 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 287 | void *entry = nullptr; |
| 288 | |
| 289 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 290 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 291 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 292 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 293 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 294 | { |
| 295 | entry = elfImage + sectionHeader[i].sh_offset; |
| 296 | } |
| 297 | } |
| 298 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 299 | { |
| 300 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 301 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 302 | for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 303 | { |
| 304 | const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index]; |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 305 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 309 | { |
| 310 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 311 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 312 | for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 313 | { |
| 314 | const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index]; |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 315 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 316 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | return entry; |
| 321 | } |
| 322 | |
| 323 | template<typename T> |
| 324 | struct ExecutableAllocator |
| 325 | { |
| 326 | ExecutableAllocator() {}; |
| 327 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 328 | |
| 329 | using value_type = T; |
| 330 | using size_type = std::size_t; |
| 331 | |
| 332 | T *allocate(size_type n) |
| 333 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 334 | #if defined(_WIN32) |
| 335 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 336 | #else |
| 337 | return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 338 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void deallocate(T *p, size_type n) |
| 342 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 343 | #if defined(_WIN32) |
| 344 | VirtualFree(p, 0, MEM_RELEASE); |
| 345 | #else |
| 346 | munmap(p, sizeof(T) * n); |
| 347 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 348 | } |
| 349 | }; |
| 350 | |
| 351 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 352 | { |
| 353 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 354 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 355 | |
| 356 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 357 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 358 | { |
| 359 | position = 0; |
| 360 | buffer.reserve(0x1000); |
| 361 | } |
| 362 | |
| 363 | virtual ~ELFMemoryStreamer() |
| 364 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 365 | #if defined(_WIN32) |
| 366 | if(buffer.size() != 0) |
| 367 | { |
| 368 | DWORD exeProtection; |
| 369 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 370 | } |
| 371 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void write8(uint8_t Value) override |
| 375 | { |
| 376 | if(position == (uint64_t)buffer.size()) |
| 377 | { |
| 378 | buffer.push_back(Value); |
| 379 | position++; |
| 380 | } |
| 381 | else if(position < (uint64_t)buffer.size()) |
| 382 | { |
| 383 | buffer[position] = Value; |
| 384 | position++; |
| 385 | } |
| 386 | else assert(false && "UNIMPLEMENTED"); |
| 387 | } |
| 388 | |
| 389 | void writeBytes(llvm::StringRef Bytes) override |
| 390 | { |
| 391 | std::size_t oldSize = buffer.size(); |
| 392 | buffer.resize(oldSize + Bytes.size()); |
| 393 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 394 | position += Bytes.size(); |
| 395 | } |
| 396 | |
| 397 | uint64_t tell() const override { return position; } |
| 398 | |
| 399 | void seek(uint64_t Off) override { position = Off; } |
| 400 | |
| 401 | const void *getEntry() override |
| 402 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 403 | if(!entry) |
| 404 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 405 | #if defined(_WIN32) |
| 406 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection); |
| 407 | #else |
| 408 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_WRITE | PROT_EXEC); |
| 409 | #endif |
| 410 | |
| 411 | 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] | 412 | |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 413 | entry = loadImage(&buffer[0]); |
| 414 | } |
| 415 | |
| 416 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 420 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 421 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 422 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 423 | |
| 424 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 425 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 426 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | Nucleus::Nucleus() |
| 430 | { |
| 431 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 432 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 433 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 434 | Ice::ClFlags::getParsedClFlags(Flags); |
| 435 | |
| 436 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 437 | Flags.setOutFileType(Ice::FT_Elf); |
| 438 | Flags.setOptLevel(Ice::Opt_2); |
| 439 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 440 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 441 | Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 442 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 443 | static llvm::raw_os_ostream cout(std::cout); |
| 444 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 445 | |
| 446 | if(false) // Write out to a file |
| 447 | { |
| 448 | std::error_code errorCode; |
| 449 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 450 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 451 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 452 | } |
| 453 | else |
| 454 | { |
| 455 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 456 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 457 | ::routine = elfMemory; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | Nucleus::~Nucleus() |
| 462 | { |
| 463 | delete ::allocator; |
| 464 | delete ::function; |
| 465 | delete ::context; |
| 466 | |
| 467 | delete ::elfFile; |
| 468 | delete ::out; |
| 469 | |
| 470 | ::codegenMutex.unlock(); |
| 471 | } |
| 472 | |
| 473 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 474 | { |
| 475 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 476 | { |
| 477 | createRetVoid(); |
| 478 | } |
| 479 | |
| 480 | std::wstring wideName(name); |
| 481 | std::string asciiName(wideName.begin(), wideName.end()); |
| 482 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 483 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 484 | optimize(); |
| 485 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 486 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 487 | assert(!::function->hasError()); |
| 488 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 489 | auto *globals = ::function->getGlobalInits().release(); |
| 490 | |
| 491 | if(globals && !globals->empty()) |
| 492 | { |
| 493 | ::context->getGlobals()->merge(globals); |
| 494 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 495 | |
| 496 | ::context->emitFileHeader(); |
| 497 | ::function->emitIAS(); |
| 498 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 499 | auto objectWriter = ::context->getObjectWriter(); |
| 500 | assembler->alignFunction(); |
| 501 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 502 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 503 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 504 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 505 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 506 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 507 | |
| 508 | return ::routine; |
| 509 | } |
| 510 | |
| 511 | void Nucleus::optimize() |
| 512 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 513 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 517 | { |
| 518 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 519 | int typeSize = Ice::typeWidthInBytes(type); |
| 520 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 521 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 522 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 523 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 524 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 525 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 526 | |
| 527 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | BasicBlock *Nucleus::createBasicBlock() |
| 531 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 532 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | BasicBlock *Nucleus::getInsertBlock() |
| 536 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 537 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 541 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 542 | // 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] | 543 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 546 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 547 | { |
| 548 | uint32_t sequenceNumber = 0; |
| 549 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 550 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 551 | |
| 552 | for(Type *type : Params) |
| 553 | { |
| 554 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 555 | ::function->addArg(arg); |
| 556 | } |
| 557 | |
| 558 | Ice::CfgNode *node = ::function->makeNode(); |
| 559 | ::function->setEntryNode(node); |
| 560 | ::basicBlock = node; |
| 561 | } |
| 562 | |
| 563 | Value *Nucleus::getArgument(unsigned int index) |
| 564 | { |
| 565 | return V(::function->getArgs()[index]); |
| 566 | } |
| 567 | |
| 568 | void Nucleus::createRetVoid() |
| 569 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 570 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 571 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | void Nucleus::createRet(Value *v) |
| 575 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 576 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 577 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | void Nucleus::createBr(BasicBlock *dest) |
| 581 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 582 | auto br = Ice::InstBr::create(::function, dest); |
| 583 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 587 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 588 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 589 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame^] | 592 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 593 | { |
| 594 | switch(op) |
| 595 | { |
| 596 | case Ice::InstArithmetic::Add: |
| 597 | case Ice::InstArithmetic::Fadd: |
| 598 | case Ice::InstArithmetic::Mul: |
| 599 | case Ice::InstArithmetic::Fmul: |
| 600 | case Ice::InstArithmetic::And: |
| 601 | case Ice::InstArithmetic::Or: |
| 602 | case Ice::InstArithmetic::Xor: |
| 603 | return true; |
| 604 | default: |
| 605 | return false; |
| 606 | } |
| 607 | } |
| 608 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 609 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 610 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 611 | 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] | 612 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame^] | 613 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 614 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 615 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame^] | 616 | Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, swapOperands ? rhs : lhs, swapOperands ? lhs : rhs); |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 617 | ::basicBlock->appendInst(arithmetic); |
| 618 | |
| 619 | return V(result); |
| 620 | } |
| 621 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 622 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 623 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 624 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 628 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 629 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 633 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 634 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 638 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 639 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 643 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 644 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 648 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 649 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 653 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 654 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 658 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 659 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 663 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 664 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 668 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 669 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 673 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 674 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 678 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 679 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 683 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 684 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 688 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 689 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 693 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 694 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 698 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 699 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 703 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 704 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 708 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 709 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | Value *Nucleus::createNeg(Value *v) |
| 713 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 714 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | Value *Nucleus::createFNeg(Value *v) |
| 718 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 719 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 720 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 721 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 722 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 723 | |
| 724 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | Value *Nucleus::createNot(Value *v) |
| 728 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 729 | if(Ice::isScalarIntegerType(v->getType())) |
| 730 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 731 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 732 | } |
| 733 | else // Vector |
| 734 | { |
| 735 | int64_t c[4] = {-1, -1, -1, -1}; |
| 736 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 737 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 738 | } |
| 739 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 740 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 741 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 742 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 743 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 744 | |
| 745 | if(valueType & EmulatedBits) |
| 746 | { |
| 747 | switch(valueType) |
| 748 | { |
| 749 | case Type_v4i8: |
| 750 | case Type_v2i16: |
| 751 | { |
| 752 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 753 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 754 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 755 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 756 | load->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 757 | ::basicBlock->appendInst(load); |
| 758 | } |
| 759 | break; |
| 760 | case Type_v2i32: |
| 761 | case Type_v8i8: |
| 762 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 763 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 764 | { |
| 765 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 766 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 767 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 768 | load->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 769 | load->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 770 | ::basicBlock->appendInst(load); |
| 771 | } |
| 772 | break; |
| 773 | default: assert(false && "UNIMPLEMENTED"); |
| 774 | } |
| 775 | } |
| 776 | else |
| 777 | { |
| 778 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 779 | ::basicBlock->appendInst(load); |
| 780 | } |
| 781 | |
| 782 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 783 | } |
| 784 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 785 | 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] | 786 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 787 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 788 | |
| 789 | if(valueType & EmulatedBits) |
| 790 | { |
| 791 | switch(valueType) |
| 792 | { |
| 793 | case Type_v4i8: |
| 794 | case Type_v2i16: |
| 795 | { |
| 796 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 797 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 798 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 799 | store->addArg(value); |
| 800 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 801 | store->addArg(::context->getConstantInt32(4)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 802 | ::basicBlock->appendInst(store); |
| 803 | } |
| 804 | break; |
| 805 | case Type_v2i32: |
| 806 | case Type_v8i8: |
| 807 | case Type_v4i16: |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 808 | case Type_v2f32: |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 809 | { |
| 810 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 811 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 812 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 813 | store->addArg(value); |
| 814 | store->addArg(ptr); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 815 | store->addArg(::context->getConstantInt32(8)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 816 | ::basicBlock->appendInst(store); |
| 817 | } |
| 818 | break; |
| 819 | default: assert(false && "UNIMPLEMENTED"); |
| 820 | } |
| 821 | } |
| 822 | else |
| 823 | { |
| 824 | assert(T(value->getType()) == type); |
| 825 | |
| 826 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 827 | ::basicBlock->appendInst(store); |
| 828 | } |
| 829 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 830 | return value; |
| 831 | } |
| 832 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 833 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 834 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 835 | assert(index->getType() == Ice::IceType_i32); |
| 836 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 837 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 838 | { |
| 839 | int32_t offset = constant->getValue() * (int)Ice::typeWidthInBytes(T(type)); |
| 840 | |
| 841 | if(offset == 0) |
| 842 | { |
| 843 | return ptr; |
| 844 | } |
| 845 | |
| 846 | return createAdd(ptr, createConstantInt(offset)); |
| 847 | } |
| 848 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 849 | if(!Ice::isByteSizedType(T(type))) |
| 850 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 851 | index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type)))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | if(sizeof(void*) == 8) |
| 855 | { |
| 856 | index = createSExt(index, T(Ice::IceType_i64)); |
| 857 | } |
| 858 | |
| 859 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 863 | { |
| 864 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 865 | } |
| 866 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 867 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 868 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 869 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 870 | { |
| 871 | return v; |
| 872 | } |
| 873 | |
| 874 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 875 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 876 | ::basicBlock->appendInst(cast); |
| 877 | |
| 878 | return V(result); |
| 879 | } |
| 880 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 881 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 882 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 883 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 887 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 888 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 892 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 893 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 897 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 898 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 899 | } |
| 900 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 901 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 902 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 903 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 907 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 908 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 912 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 913 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 917 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 918 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 919 | } |
| 920 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 921 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 922 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 923 | assert(lhs->getType() == rhs->getType()); |
| 924 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 925 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 926 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 927 | ::basicBlock->appendInst(cmp); |
| 928 | |
| 929 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 930 | } |
| 931 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 932 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 933 | { |
| 934 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 935 | } |
| 936 | |
| 937 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 938 | { |
| 939 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 940 | } |
| 941 | |
| 942 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 943 | { |
| 944 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 945 | } |
| 946 | |
| 947 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 948 | { |
| 949 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 950 | } |
| 951 | |
| 952 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 953 | { |
| 954 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 955 | } |
| 956 | |
| 957 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 958 | { |
| 959 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 960 | } |
| 961 | |
| 962 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 963 | { |
| 964 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 965 | } |
| 966 | |
| 967 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 968 | { |
| 969 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 970 | } |
| 971 | |
| 972 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 973 | { |
| 974 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 975 | } |
| 976 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 977 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 978 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 979 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 980 | } |
| 981 | |
| 982 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 983 | { |
| 984 | assert(lhs->getType() == rhs->getType()); |
| 985 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 986 | |
| 987 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 988 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 989 | ::basicBlock->appendInst(cmp); |
| 990 | |
| 991 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 995 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 996 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1000 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1001 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1005 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1006 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1010 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1011 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1015 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1016 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1020 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1021 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1025 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1026 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1030 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1031 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1035 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1036 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1040 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1041 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1045 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1046 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1050 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1051 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1055 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1056 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1060 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1061 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1064 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1065 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1066 | auto result = ::function->makeVariable(T(type)); |
| 1067 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1068 | ::basicBlock->appendInst(extract); |
| 1069 | |
| 1070 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1074 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1075 | auto result = ::function->makeVariable(vector->getType()); |
| 1076 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1077 | ::basicBlock->appendInst(insert); |
| 1078 | |
| 1079 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1082 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1083 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1084 | assert(V1->getType() == V2->getType()); |
| 1085 | |
| 1086 | int size = Ice::typeNumElements(V1->getType()); |
| 1087 | auto result = ::function->makeVariable(V1->getType()); |
| 1088 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1089 | |
| 1090 | for(int i = 0; i < size; i++) |
| 1091 | { |
| 1092 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1093 | } |
| 1094 | |
| 1095 | ::basicBlock->appendInst(shuffle); |
| 1096 | |
| 1097 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1101 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1102 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1103 | |
| 1104 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1105 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1106 | ::basicBlock->appendInst(select); |
| 1107 | |
| 1108 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1109 | } |
| 1110 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1111 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1112 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1113 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1114 | ::basicBlock->appendInst(switchInst); |
| 1115 | |
| 1116 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1119 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1120 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1121 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | void Nucleus::createUnreachable() |
| 1125 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1126 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1127 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1128 | } |
| 1129 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1130 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1131 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1132 | int swizzle[4] = |
| 1133 | { |
| 1134 | (select >> 0) & 0x03, |
| 1135 | (select >> 2) & 0x03, |
| 1136 | (select >> 4) & 0x03, |
| 1137 | (select >> 6) & 0x03, |
| 1138 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1139 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1140 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1143 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1144 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1145 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1146 | |
| 1147 | mask[(select >> 0) & 0x03] = -1; |
| 1148 | mask[(select >> 2) & 0x03] = -1; |
| 1149 | mask[(select >> 4) & 0x03] = -1; |
| 1150 | mask[(select >> 6) & 0x03] = -1; |
| 1151 | |
| 1152 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1153 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1154 | |
| 1155 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1158 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1159 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1160 | if(sizeof(void*) == 8) |
| 1161 | { |
| 1162 | return T(Ice::IceType_i64); |
| 1163 | } |
| 1164 | else |
| 1165 | { |
| 1166 | return T(Ice::IceType_i32); |
| 1167 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1168 | } |
| 1169 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1170 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1171 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1172 | if(Ice::isVectorType(T(Ty))) |
| 1173 | { |
| 1174 | int64_t c[4] = {0, 0, 0, 0}; |
| 1175 | return createConstantVector(c, Ty); |
| 1176 | } |
| 1177 | else |
| 1178 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1179 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1180 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1183 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1184 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1185 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1188 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1189 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1190 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1193 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1194 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1195 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1198 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1199 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1200 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1203 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1204 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1205 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1208 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1209 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1210 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1211 | } |
| 1212 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1213 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1214 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1215 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1218 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1219 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1220 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1221 | } |
| 1222 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1223 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1224 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1225 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1228 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1229 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1230 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1233 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1234 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1235 | const int vectorSize = 16; |
| 1236 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1237 | const int alignment = vectorSize; |
| 1238 | auto globalPool = ::function->getGlobalPool(); |
| 1239 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1240 | const int64_t *i = constants; |
| 1241 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1242 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1243 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1244 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1245 | { |
| 1246 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1247 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1248 | { |
| 1249 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1250 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1251 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1252 | } |
| 1253 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1254 | case Ice::IceType_v4f32: |
| 1255 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1256 | 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] | 1257 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1258 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1259 | } |
| 1260 | break; |
| 1261 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1262 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1263 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1264 | 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] | 1265 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1266 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1267 | } |
| 1268 | break; |
| 1269 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1270 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1271 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1272 | 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] | 1273 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1274 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1275 | } |
| 1276 | break; |
| 1277 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1278 | { |
| 1279 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1280 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1281 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1282 | } |
| 1283 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1284 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1285 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1286 | 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] | 1287 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1288 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1289 | } |
| 1290 | break; |
| 1291 | case Type_v4i16: |
| 1292 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1293 | 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] | 1294 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1295 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1296 | } |
| 1297 | break; |
| 1298 | case Type_v8i8: |
| 1299 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1300 | 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] | 1301 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1302 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1303 | } |
| 1304 | break; |
| 1305 | case Type_v4i8: |
| 1306 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1307 | 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] | 1308 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1309 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1310 | } |
| 1311 | break; |
| 1312 | default: |
| 1313 | assert(false && "Unknown constant vector type" && type); |
| 1314 | } |
| 1315 | |
| 1316 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1317 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1318 | variableDeclaration->setName(name); |
| 1319 | variableDeclaration->setAlignment(alignment); |
| 1320 | variableDeclaration->setIsConstant(true); |
| 1321 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1322 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1323 | ::function->addGlobal(variableDeclaration); |
| 1324 | |
| 1325 | constexpr int32_t offset = 0; |
| 1326 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1327 | |
| 1328 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1329 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1330 | ::basicBlock->appendInst(load); |
| 1331 | |
| 1332 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1336 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1337 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | Type *Void::getType() |
| 1341 | { |
| 1342 | return T(Ice::IceType_void); |
| 1343 | } |
| 1344 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1345 | Bool::Bool(Argument<Bool> argument) |
| 1346 | { |
| 1347 | storeValue(argument.value); |
| 1348 | } |
| 1349 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1350 | Bool::Bool(bool x) |
| 1351 | { |
| 1352 | storeValue(Nucleus::createConstantBool(x)); |
| 1353 | } |
| 1354 | |
| 1355 | Bool::Bool(RValue<Bool> rhs) |
| 1356 | { |
| 1357 | storeValue(rhs.value); |
| 1358 | } |
| 1359 | |
| 1360 | Bool::Bool(const Bool &rhs) |
| 1361 | { |
| 1362 | Value *value = rhs.loadValue(); |
| 1363 | storeValue(value); |
| 1364 | } |
| 1365 | |
| 1366 | Bool::Bool(const Reference<Bool> &rhs) |
| 1367 | { |
| 1368 | Value *value = rhs.loadValue(); |
| 1369 | storeValue(value); |
| 1370 | } |
| 1371 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1372 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1373 | { |
| 1374 | storeValue(rhs.value); |
| 1375 | |
| 1376 | return rhs; |
| 1377 | } |
| 1378 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1379 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1380 | { |
| 1381 | Value *value = rhs.loadValue(); |
| 1382 | storeValue(value); |
| 1383 | |
| 1384 | return RValue<Bool>(value); |
| 1385 | } |
| 1386 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1387 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1388 | { |
| 1389 | Value *value = rhs.loadValue(); |
| 1390 | storeValue(value); |
| 1391 | |
| 1392 | return RValue<Bool>(value); |
| 1393 | } |
| 1394 | |
| 1395 | RValue<Bool> operator!(RValue<Bool> val) |
| 1396 | { |
| 1397 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1398 | } |
| 1399 | |
| 1400 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1401 | { |
| 1402 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1403 | } |
| 1404 | |
| 1405 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1406 | { |
| 1407 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1408 | } |
| 1409 | |
| 1410 | Type *Bool::getType() |
| 1411 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1412 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | Byte::Byte(Argument<Byte> argument) |
| 1416 | { |
| 1417 | storeValue(argument.value); |
| 1418 | } |
| 1419 | |
| 1420 | Byte::Byte(RValue<Int> cast) |
| 1421 | { |
| 1422 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1423 | |
| 1424 | storeValue(integer); |
| 1425 | } |
| 1426 | |
| 1427 | Byte::Byte(RValue<UInt> cast) |
| 1428 | { |
| 1429 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1430 | |
| 1431 | storeValue(integer); |
| 1432 | } |
| 1433 | |
| 1434 | Byte::Byte(RValue<UShort> cast) |
| 1435 | { |
| 1436 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1437 | |
| 1438 | storeValue(integer); |
| 1439 | } |
| 1440 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1441 | Byte::Byte(int x) |
| 1442 | { |
| 1443 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1444 | } |
| 1445 | |
| 1446 | Byte::Byte(unsigned char x) |
| 1447 | { |
| 1448 | storeValue(Nucleus::createConstantByte(x)); |
| 1449 | } |
| 1450 | |
| 1451 | Byte::Byte(RValue<Byte> rhs) |
| 1452 | { |
| 1453 | storeValue(rhs.value); |
| 1454 | } |
| 1455 | |
| 1456 | Byte::Byte(const Byte &rhs) |
| 1457 | { |
| 1458 | Value *value = rhs.loadValue(); |
| 1459 | storeValue(value); |
| 1460 | } |
| 1461 | |
| 1462 | Byte::Byte(const Reference<Byte> &rhs) |
| 1463 | { |
| 1464 | Value *value = rhs.loadValue(); |
| 1465 | storeValue(value); |
| 1466 | } |
| 1467 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1468 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1469 | { |
| 1470 | storeValue(rhs.value); |
| 1471 | |
| 1472 | return rhs; |
| 1473 | } |
| 1474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1475 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1476 | { |
| 1477 | Value *value = rhs.loadValue(); |
| 1478 | storeValue(value); |
| 1479 | |
| 1480 | return RValue<Byte>(value); |
| 1481 | } |
| 1482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1483 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1484 | { |
| 1485 | Value *value = rhs.loadValue(); |
| 1486 | storeValue(value); |
| 1487 | |
| 1488 | return RValue<Byte>(value); |
| 1489 | } |
| 1490 | |
| 1491 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1492 | { |
| 1493 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1494 | } |
| 1495 | |
| 1496 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1497 | { |
| 1498 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1499 | } |
| 1500 | |
| 1501 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1502 | { |
| 1503 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1504 | } |
| 1505 | |
| 1506 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1507 | { |
| 1508 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1509 | } |
| 1510 | |
| 1511 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1512 | { |
| 1513 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1514 | } |
| 1515 | |
| 1516 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1517 | { |
| 1518 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1519 | } |
| 1520 | |
| 1521 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1522 | { |
| 1523 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1524 | } |
| 1525 | |
| 1526 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1527 | { |
| 1528 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1529 | } |
| 1530 | |
| 1531 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1532 | { |
| 1533 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1534 | } |
| 1535 | |
| 1536 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1537 | { |
| 1538 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1539 | } |
| 1540 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1541 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1542 | { |
| 1543 | return lhs = lhs + rhs; |
| 1544 | } |
| 1545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1546 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1547 | { |
| 1548 | return lhs = lhs - rhs; |
| 1549 | } |
| 1550 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1551 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1552 | { |
| 1553 | return lhs = lhs * rhs; |
| 1554 | } |
| 1555 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1556 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1557 | { |
| 1558 | return lhs = lhs / rhs; |
| 1559 | } |
| 1560 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1561 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1562 | { |
| 1563 | return lhs = lhs % rhs; |
| 1564 | } |
| 1565 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1566 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1567 | { |
| 1568 | return lhs = lhs & rhs; |
| 1569 | } |
| 1570 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1571 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1572 | { |
| 1573 | return lhs = lhs | rhs; |
| 1574 | } |
| 1575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1576 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1577 | { |
| 1578 | return lhs = lhs ^ rhs; |
| 1579 | } |
| 1580 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1581 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1582 | { |
| 1583 | return lhs = lhs << rhs; |
| 1584 | } |
| 1585 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1586 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1587 | { |
| 1588 | return lhs = lhs >> rhs; |
| 1589 | } |
| 1590 | |
| 1591 | RValue<Byte> operator+(RValue<Byte> val) |
| 1592 | { |
| 1593 | return val; |
| 1594 | } |
| 1595 | |
| 1596 | RValue<Byte> operator-(RValue<Byte> val) |
| 1597 | { |
| 1598 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1599 | } |
| 1600 | |
| 1601 | RValue<Byte> operator~(RValue<Byte> val) |
| 1602 | { |
| 1603 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1604 | } |
| 1605 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1606 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1607 | { |
| 1608 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1609 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1610 | return res; |
| 1611 | } |
| 1612 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1613 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1614 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1615 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1616 | return val; |
| 1617 | } |
| 1618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1619 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1620 | { |
| 1621 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1622 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1623 | return res; |
| 1624 | } |
| 1625 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1626 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1627 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1628 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1629 | return val; |
| 1630 | } |
| 1631 | |
| 1632 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1633 | { |
| 1634 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1635 | } |
| 1636 | |
| 1637 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1638 | { |
| 1639 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1640 | } |
| 1641 | |
| 1642 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1643 | { |
| 1644 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1645 | } |
| 1646 | |
| 1647 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1648 | { |
| 1649 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1650 | } |
| 1651 | |
| 1652 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1653 | { |
| 1654 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1655 | } |
| 1656 | |
| 1657 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1658 | { |
| 1659 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1660 | } |
| 1661 | |
| 1662 | Type *Byte::getType() |
| 1663 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1664 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | SByte::SByte(Argument<SByte> argument) |
| 1668 | { |
| 1669 | storeValue(argument.value); |
| 1670 | } |
| 1671 | |
| 1672 | SByte::SByte(RValue<Int> cast) |
| 1673 | { |
| 1674 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1675 | |
| 1676 | storeValue(integer); |
| 1677 | } |
| 1678 | |
| 1679 | SByte::SByte(RValue<Short> cast) |
| 1680 | { |
| 1681 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1682 | |
| 1683 | storeValue(integer); |
| 1684 | } |
| 1685 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1686 | SByte::SByte(signed char x) |
| 1687 | { |
| 1688 | storeValue(Nucleus::createConstantByte(x)); |
| 1689 | } |
| 1690 | |
| 1691 | SByte::SByte(RValue<SByte> rhs) |
| 1692 | { |
| 1693 | storeValue(rhs.value); |
| 1694 | } |
| 1695 | |
| 1696 | SByte::SByte(const SByte &rhs) |
| 1697 | { |
| 1698 | Value *value = rhs.loadValue(); |
| 1699 | storeValue(value); |
| 1700 | } |
| 1701 | |
| 1702 | SByte::SByte(const Reference<SByte> &rhs) |
| 1703 | { |
| 1704 | Value *value = rhs.loadValue(); |
| 1705 | storeValue(value); |
| 1706 | } |
| 1707 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1708 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1709 | { |
| 1710 | storeValue(rhs.value); |
| 1711 | |
| 1712 | return rhs; |
| 1713 | } |
| 1714 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1715 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1716 | { |
| 1717 | Value *value = rhs.loadValue(); |
| 1718 | storeValue(value); |
| 1719 | |
| 1720 | return RValue<SByte>(value); |
| 1721 | } |
| 1722 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1723 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1724 | { |
| 1725 | Value *value = rhs.loadValue(); |
| 1726 | storeValue(value); |
| 1727 | |
| 1728 | return RValue<SByte>(value); |
| 1729 | } |
| 1730 | |
| 1731 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1732 | { |
| 1733 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1734 | } |
| 1735 | |
| 1736 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1737 | { |
| 1738 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1739 | } |
| 1740 | |
| 1741 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1742 | { |
| 1743 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1744 | } |
| 1745 | |
| 1746 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1747 | { |
| 1748 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1749 | } |
| 1750 | |
| 1751 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1752 | { |
| 1753 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1754 | } |
| 1755 | |
| 1756 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1757 | { |
| 1758 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1759 | } |
| 1760 | |
| 1761 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1762 | { |
| 1763 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1764 | } |
| 1765 | |
| 1766 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1767 | { |
| 1768 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1769 | } |
| 1770 | |
| 1771 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1772 | { |
| 1773 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1774 | } |
| 1775 | |
| 1776 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1777 | { |
| 1778 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1779 | } |
| 1780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1781 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1782 | { |
| 1783 | return lhs = lhs + rhs; |
| 1784 | } |
| 1785 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1786 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1787 | { |
| 1788 | return lhs = lhs - rhs; |
| 1789 | } |
| 1790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1791 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1792 | { |
| 1793 | return lhs = lhs * rhs; |
| 1794 | } |
| 1795 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1796 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1797 | { |
| 1798 | return lhs = lhs / rhs; |
| 1799 | } |
| 1800 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1801 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1802 | { |
| 1803 | return lhs = lhs % rhs; |
| 1804 | } |
| 1805 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1806 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1807 | { |
| 1808 | return lhs = lhs & rhs; |
| 1809 | } |
| 1810 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1811 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1812 | { |
| 1813 | return lhs = lhs | rhs; |
| 1814 | } |
| 1815 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1816 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1817 | { |
| 1818 | return lhs = lhs ^ rhs; |
| 1819 | } |
| 1820 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1821 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1822 | { |
| 1823 | return lhs = lhs << rhs; |
| 1824 | } |
| 1825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1826 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1827 | { |
| 1828 | return lhs = lhs >> rhs; |
| 1829 | } |
| 1830 | |
| 1831 | RValue<SByte> operator+(RValue<SByte> val) |
| 1832 | { |
| 1833 | return val; |
| 1834 | } |
| 1835 | |
| 1836 | RValue<SByte> operator-(RValue<SByte> val) |
| 1837 | { |
| 1838 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1839 | } |
| 1840 | |
| 1841 | RValue<SByte> operator~(RValue<SByte> val) |
| 1842 | { |
| 1843 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1844 | } |
| 1845 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1846 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1847 | { |
| 1848 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1849 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1850 | return res; |
| 1851 | } |
| 1852 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1853 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1854 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1855 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1856 | return val; |
| 1857 | } |
| 1858 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1859 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1860 | { |
| 1861 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1862 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1863 | return res; |
| 1864 | } |
| 1865 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1866 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1867 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1868 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1869 | return val; |
| 1870 | } |
| 1871 | |
| 1872 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1873 | { |
| 1874 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1875 | } |
| 1876 | |
| 1877 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1878 | { |
| 1879 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1880 | } |
| 1881 | |
| 1882 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1883 | { |
| 1884 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1885 | } |
| 1886 | |
| 1887 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1888 | { |
| 1889 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1890 | } |
| 1891 | |
| 1892 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1893 | { |
| 1894 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1895 | } |
| 1896 | |
| 1897 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1898 | { |
| 1899 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1900 | } |
| 1901 | |
| 1902 | Type *SByte::getType() |
| 1903 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1904 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | Short::Short(Argument<Short> argument) |
| 1908 | { |
| 1909 | storeValue(argument.value); |
| 1910 | } |
| 1911 | |
| 1912 | Short::Short(RValue<Int> cast) |
| 1913 | { |
| 1914 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1915 | |
| 1916 | storeValue(integer); |
| 1917 | } |
| 1918 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1919 | Short::Short(short x) |
| 1920 | { |
| 1921 | storeValue(Nucleus::createConstantShort(x)); |
| 1922 | } |
| 1923 | |
| 1924 | Short::Short(RValue<Short> rhs) |
| 1925 | { |
| 1926 | storeValue(rhs.value); |
| 1927 | } |
| 1928 | |
| 1929 | Short::Short(const Short &rhs) |
| 1930 | { |
| 1931 | Value *value = rhs.loadValue(); |
| 1932 | storeValue(value); |
| 1933 | } |
| 1934 | |
| 1935 | Short::Short(const Reference<Short> &rhs) |
| 1936 | { |
| 1937 | Value *value = rhs.loadValue(); |
| 1938 | storeValue(value); |
| 1939 | } |
| 1940 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1941 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1942 | { |
| 1943 | storeValue(rhs.value); |
| 1944 | |
| 1945 | return rhs; |
| 1946 | } |
| 1947 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1948 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1949 | { |
| 1950 | Value *value = rhs.loadValue(); |
| 1951 | storeValue(value); |
| 1952 | |
| 1953 | return RValue<Short>(value); |
| 1954 | } |
| 1955 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1956 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1957 | { |
| 1958 | Value *value = rhs.loadValue(); |
| 1959 | storeValue(value); |
| 1960 | |
| 1961 | return RValue<Short>(value); |
| 1962 | } |
| 1963 | |
| 1964 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 1965 | { |
| 1966 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1967 | } |
| 1968 | |
| 1969 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 1970 | { |
| 1971 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1972 | } |
| 1973 | |
| 1974 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 1975 | { |
| 1976 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1977 | } |
| 1978 | |
| 1979 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 1980 | { |
| 1981 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1982 | } |
| 1983 | |
| 1984 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 1985 | { |
| 1986 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1987 | } |
| 1988 | |
| 1989 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 1990 | { |
| 1991 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1992 | } |
| 1993 | |
| 1994 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 1995 | { |
| 1996 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1997 | } |
| 1998 | |
| 1999 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2000 | { |
| 2001 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2002 | } |
| 2003 | |
| 2004 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2005 | { |
| 2006 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2007 | } |
| 2008 | |
| 2009 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2010 | { |
| 2011 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2012 | } |
| 2013 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2014 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2015 | { |
| 2016 | return lhs = lhs + rhs; |
| 2017 | } |
| 2018 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2019 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2020 | { |
| 2021 | return lhs = lhs - rhs; |
| 2022 | } |
| 2023 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2024 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2025 | { |
| 2026 | return lhs = lhs * rhs; |
| 2027 | } |
| 2028 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2029 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2030 | { |
| 2031 | return lhs = lhs / rhs; |
| 2032 | } |
| 2033 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2034 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2035 | { |
| 2036 | return lhs = lhs % rhs; |
| 2037 | } |
| 2038 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2039 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2040 | { |
| 2041 | return lhs = lhs & rhs; |
| 2042 | } |
| 2043 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2044 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2045 | { |
| 2046 | return lhs = lhs | rhs; |
| 2047 | } |
| 2048 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2049 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2050 | { |
| 2051 | return lhs = lhs ^ rhs; |
| 2052 | } |
| 2053 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2054 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2055 | { |
| 2056 | return lhs = lhs << rhs; |
| 2057 | } |
| 2058 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2059 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2060 | { |
| 2061 | return lhs = lhs >> rhs; |
| 2062 | } |
| 2063 | |
| 2064 | RValue<Short> operator+(RValue<Short> val) |
| 2065 | { |
| 2066 | return val; |
| 2067 | } |
| 2068 | |
| 2069 | RValue<Short> operator-(RValue<Short> val) |
| 2070 | { |
| 2071 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2072 | } |
| 2073 | |
| 2074 | RValue<Short> operator~(RValue<Short> val) |
| 2075 | { |
| 2076 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2077 | } |
| 2078 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2079 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2080 | { |
| 2081 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2082 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2083 | return res; |
| 2084 | } |
| 2085 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2086 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2087 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2088 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2089 | return val; |
| 2090 | } |
| 2091 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2092 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2093 | { |
| 2094 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2095 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2096 | return res; |
| 2097 | } |
| 2098 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2099 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2100 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2101 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2102 | return val; |
| 2103 | } |
| 2104 | |
| 2105 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2106 | { |
| 2107 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2108 | } |
| 2109 | |
| 2110 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2111 | { |
| 2112 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2113 | } |
| 2114 | |
| 2115 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2116 | { |
| 2117 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2118 | } |
| 2119 | |
| 2120 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2121 | { |
| 2122 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2123 | } |
| 2124 | |
| 2125 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2126 | { |
| 2127 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2128 | } |
| 2129 | |
| 2130 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2131 | { |
| 2132 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2133 | } |
| 2134 | |
| 2135 | Type *Short::getType() |
| 2136 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2137 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | UShort::UShort(Argument<UShort> argument) |
| 2141 | { |
| 2142 | storeValue(argument.value); |
| 2143 | } |
| 2144 | |
| 2145 | UShort::UShort(RValue<UInt> cast) |
| 2146 | { |
| 2147 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2148 | |
| 2149 | storeValue(integer); |
| 2150 | } |
| 2151 | |
| 2152 | UShort::UShort(RValue<Int> cast) |
| 2153 | { |
| 2154 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2155 | |
| 2156 | storeValue(integer); |
| 2157 | } |
| 2158 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2159 | UShort::UShort(unsigned short x) |
| 2160 | { |
| 2161 | storeValue(Nucleus::createConstantShort(x)); |
| 2162 | } |
| 2163 | |
| 2164 | UShort::UShort(RValue<UShort> rhs) |
| 2165 | { |
| 2166 | storeValue(rhs.value); |
| 2167 | } |
| 2168 | |
| 2169 | UShort::UShort(const UShort &rhs) |
| 2170 | { |
| 2171 | Value *value = rhs.loadValue(); |
| 2172 | storeValue(value); |
| 2173 | } |
| 2174 | |
| 2175 | UShort::UShort(const Reference<UShort> &rhs) |
| 2176 | { |
| 2177 | Value *value = rhs.loadValue(); |
| 2178 | storeValue(value); |
| 2179 | } |
| 2180 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2181 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2182 | { |
| 2183 | storeValue(rhs.value); |
| 2184 | |
| 2185 | return rhs; |
| 2186 | } |
| 2187 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2188 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2189 | { |
| 2190 | Value *value = rhs.loadValue(); |
| 2191 | storeValue(value); |
| 2192 | |
| 2193 | return RValue<UShort>(value); |
| 2194 | } |
| 2195 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2196 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2197 | { |
| 2198 | Value *value = rhs.loadValue(); |
| 2199 | storeValue(value); |
| 2200 | |
| 2201 | return RValue<UShort>(value); |
| 2202 | } |
| 2203 | |
| 2204 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2205 | { |
| 2206 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2207 | } |
| 2208 | |
| 2209 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2210 | { |
| 2211 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2212 | } |
| 2213 | |
| 2214 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2215 | { |
| 2216 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2217 | } |
| 2218 | |
| 2219 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2220 | { |
| 2221 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2222 | } |
| 2223 | |
| 2224 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2225 | { |
| 2226 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2227 | } |
| 2228 | |
| 2229 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2230 | { |
| 2231 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2232 | } |
| 2233 | |
| 2234 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2235 | { |
| 2236 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2237 | } |
| 2238 | |
| 2239 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2240 | { |
| 2241 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2242 | } |
| 2243 | |
| 2244 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2245 | { |
| 2246 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2247 | } |
| 2248 | |
| 2249 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2250 | { |
| 2251 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2252 | } |
| 2253 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2254 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2255 | { |
| 2256 | return lhs = lhs + rhs; |
| 2257 | } |
| 2258 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2259 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2260 | { |
| 2261 | return lhs = lhs - rhs; |
| 2262 | } |
| 2263 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2264 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2265 | { |
| 2266 | return lhs = lhs * rhs; |
| 2267 | } |
| 2268 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2269 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2270 | { |
| 2271 | return lhs = lhs / rhs; |
| 2272 | } |
| 2273 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2274 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2275 | { |
| 2276 | return lhs = lhs % rhs; |
| 2277 | } |
| 2278 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2279 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2280 | { |
| 2281 | return lhs = lhs & rhs; |
| 2282 | } |
| 2283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2284 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2285 | { |
| 2286 | return lhs = lhs | rhs; |
| 2287 | } |
| 2288 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2289 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2290 | { |
| 2291 | return lhs = lhs ^ rhs; |
| 2292 | } |
| 2293 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2294 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2295 | { |
| 2296 | return lhs = lhs << rhs; |
| 2297 | } |
| 2298 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2299 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2300 | { |
| 2301 | return lhs = lhs >> rhs; |
| 2302 | } |
| 2303 | |
| 2304 | RValue<UShort> operator+(RValue<UShort> val) |
| 2305 | { |
| 2306 | return val; |
| 2307 | } |
| 2308 | |
| 2309 | RValue<UShort> operator-(RValue<UShort> val) |
| 2310 | { |
| 2311 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2312 | } |
| 2313 | |
| 2314 | RValue<UShort> operator~(RValue<UShort> val) |
| 2315 | { |
| 2316 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2317 | } |
| 2318 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2319 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2320 | { |
| 2321 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2322 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2323 | return res; |
| 2324 | } |
| 2325 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2326 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2327 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2328 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2329 | return val; |
| 2330 | } |
| 2331 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2332 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2333 | { |
| 2334 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2335 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2336 | return res; |
| 2337 | } |
| 2338 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2339 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2340 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2341 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2342 | return val; |
| 2343 | } |
| 2344 | |
| 2345 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2346 | { |
| 2347 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2348 | } |
| 2349 | |
| 2350 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2351 | { |
| 2352 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2353 | } |
| 2354 | |
| 2355 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2356 | { |
| 2357 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2358 | } |
| 2359 | |
| 2360 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2361 | { |
| 2362 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2363 | } |
| 2364 | |
| 2365 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2366 | { |
| 2367 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2368 | } |
| 2369 | |
| 2370 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2371 | { |
| 2372 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2373 | } |
| 2374 | |
| 2375 | Type *UShort::getType() |
| 2376 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2377 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2378 | } |
| 2379 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2380 | Byte4::Byte4(RValue<Byte8> cast) |
| 2381 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2382 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2383 | } |
| 2384 | |
| 2385 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2386 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2387 | Value *value = rhs.loadValue(); |
| 2388 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2389 | } |
| 2390 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2391 | Type *Byte4::getType() |
| 2392 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2393 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | Type *SByte4::getType() |
| 2397 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2398 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2399 | } |
| 2400 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2401 | 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) |
| 2402 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2403 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2404 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2408 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2409 | storeValue(rhs.value); |
| 2410 | } |
| 2411 | |
| 2412 | Byte8::Byte8(const Byte8 &rhs) |
| 2413 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2414 | Value *value = rhs.loadValue(); |
| 2415 | storeValue(value); |
| 2416 | } |
| 2417 | |
| 2418 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2419 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2420 | Value *value = rhs.loadValue(); |
| 2421 | storeValue(value); |
| 2422 | } |
| 2423 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2424 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2425 | { |
| 2426 | storeValue(rhs.value); |
| 2427 | |
| 2428 | return rhs; |
| 2429 | } |
| 2430 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2431 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2432 | { |
| 2433 | Value *value = rhs.loadValue(); |
| 2434 | storeValue(value); |
| 2435 | |
| 2436 | return RValue<Byte8>(value); |
| 2437 | } |
| 2438 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2439 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2440 | { |
| 2441 | Value *value = rhs.loadValue(); |
| 2442 | storeValue(value); |
| 2443 | |
| 2444 | return RValue<Byte8>(value); |
| 2445 | } |
| 2446 | |
| 2447 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2448 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2449 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2453 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2454 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2458 | // { |
| 2459 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2460 | // } |
| 2461 | |
| 2462 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2463 | // { |
| 2464 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2465 | // } |
| 2466 | |
| 2467 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2468 | // { |
| 2469 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2470 | // } |
| 2471 | |
| 2472 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2473 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2474 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2478 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2479 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2483 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2484 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2488 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2489 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2490 | // } |
| 2491 | |
| 2492 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2493 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2494 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2495 | // } |
| 2496 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2497 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2498 | { |
| 2499 | return lhs = lhs + rhs; |
| 2500 | } |
| 2501 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2502 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2503 | { |
| 2504 | return lhs = lhs - rhs; |
| 2505 | } |
| 2506 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2507 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2508 | // { |
| 2509 | // return lhs = lhs * rhs; |
| 2510 | // } |
| 2511 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2512 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2513 | // { |
| 2514 | // return lhs = lhs / rhs; |
| 2515 | // } |
| 2516 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2517 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2518 | // { |
| 2519 | // return lhs = lhs % rhs; |
| 2520 | // } |
| 2521 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2522 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2523 | { |
| 2524 | return lhs = lhs & rhs; |
| 2525 | } |
| 2526 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2527 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2528 | { |
| 2529 | return lhs = lhs | rhs; |
| 2530 | } |
| 2531 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2532 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2533 | { |
| 2534 | return lhs = lhs ^ rhs; |
| 2535 | } |
| 2536 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2537 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2538 | // { |
| 2539 | // return lhs = lhs << rhs; |
| 2540 | // } |
| 2541 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2542 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2543 | // { |
| 2544 | // return lhs = lhs >> rhs; |
| 2545 | // } |
| 2546 | |
| 2547 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2548 | // { |
| 2549 | // return val; |
| 2550 | // } |
| 2551 | |
| 2552 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2553 | // { |
| 2554 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2555 | // } |
| 2556 | |
| 2557 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2558 | { |
| 2559 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2560 | } |
| 2561 | |
| 2562 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2563 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2564 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2565 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2566 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2567 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2568 | paddusb->addArg(x.value); |
| 2569 | paddusb->addArg(y.value); |
| 2570 | ::basicBlock->appendInst(paddusb); |
| 2571 | |
| 2572 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2576 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2577 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2578 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2579 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2580 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2581 | psubusw->addArg(x.value); |
| 2582 | psubusw->addArg(y.value); |
| 2583 | ::basicBlock->appendInst(psubusw); |
| 2584 | |
| 2585 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2589 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2590 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2591 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2595 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2596 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2597 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2601 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2602 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2603 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2604 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2608 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2609 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2610 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2611 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2612 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2613 | movmsk->addArg(x.value); |
| 2614 | ::basicBlock->appendInst(movmsk); |
| 2615 | |
| 2616 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2620 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2621 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2622 | // } |
| 2623 | |
| 2624 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2625 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2626 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | Type *Byte8::getType() |
| 2630 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2631 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2632 | } |
| 2633 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2634 | 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) |
| 2635 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2636 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2637 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2638 | |
| 2639 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2640 | } |
| 2641 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2642 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2643 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2644 | storeValue(rhs.value); |
| 2645 | } |
| 2646 | |
| 2647 | SByte8::SByte8(const SByte8 &rhs) |
| 2648 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2649 | Value *value = rhs.loadValue(); |
| 2650 | storeValue(value); |
| 2651 | } |
| 2652 | |
| 2653 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2654 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2655 | Value *value = rhs.loadValue(); |
| 2656 | storeValue(value); |
| 2657 | } |
| 2658 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2659 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2660 | { |
| 2661 | storeValue(rhs.value); |
| 2662 | |
| 2663 | return rhs; |
| 2664 | } |
| 2665 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2666 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2667 | { |
| 2668 | Value *value = rhs.loadValue(); |
| 2669 | storeValue(value); |
| 2670 | |
| 2671 | return RValue<SByte8>(value); |
| 2672 | } |
| 2673 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2674 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2675 | { |
| 2676 | Value *value = rhs.loadValue(); |
| 2677 | storeValue(value); |
| 2678 | |
| 2679 | return RValue<SByte8>(value); |
| 2680 | } |
| 2681 | |
| 2682 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2683 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2684 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2688 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2689 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2693 | // { |
| 2694 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2695 | // } |
| 2696 | |
| 2697 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2698 | // { |
| 2699 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2700 | // } |
| 2701 | |
| 2702 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2703 | // { |
| 2704 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2705 | // } |
| 2706 | |
| 2707 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2708 | { |
| 2709 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2710 | } |
| 2711 | |
| 2712 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2713 | { |
| 2714 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2715 | } |
| 2716 | |
| 2717 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2718 | { |
| 2719 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2720 | } |
| 2721 | |
| 2722 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2723 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2724 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2725 | // } |
| 2726 | |
| 2727 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2728 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2729 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2730 | // } |
| 2731 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2732 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2733 | { |
| 2734 | return lhs = lhs + rhs; |
| 2735 | } |
| 2736 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2737 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2738 | { |
| 2739 | return lhs = lhs - rhs; |
| 2740 | } |
| 2741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2742 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2743 | // { |
| 2744 | // return lhs = lhs * rhs; |
| 2745 | // } |
| 2746 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2747 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2748 | // { |
| 2749 | // return lhs = lhs / rhs; |
| 2750 | // } |
| 2751 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2752 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2753 | // { |
| 2754 | // return lhs = lhs % rhs; |
| 2755 | // } |
| 2756 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2757 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2758 | { |
| 2759 | return lhs = lhs & rhs; |
| 2760 | } |
| 2761 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2762 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2763 | { |
| 2764 | return lhs = lhs | rhs; |
| 2765 | } |
| 2766 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2767 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2768 | { |
| 2769 | return lhs = lhs ^ rhs; |
| 2770 | } |
| 2771 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2772 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2773 | // { |
| 2774 | // return lhs = lhs << rhs; |
| 2775 | // } |
| 2776 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2777 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2778 | // { |
| 2779 | // return lhs = lhs >> rhs; |
| 2780 | // } |
| 2781 | |
| 2782 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2783 | // { |
| 2784 | // return val; |
| 2785 | // } |
| 2786 | |
| 2787 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2788 | // { |
| 2789 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2790 | // } |
| 2791 | |
| 2792 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2793 | { |
| 2794 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2795 | } |
| 2796 | |
| 2797 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2798 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2799 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2800 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2801 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2802 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2803 | paddsb->addArg(x.value); |
| 2804 | paddsb->addArg(y.value); |
| 2805 | ::basicBlock->appendInst(paddsb); |
| 2806 | |
| 2807 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2811 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2812 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2813 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2814 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2815 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2816 | psubsb->addArg(x.value); |
| 2817 | psubsb->addArg(y.value); |
| 2818 | ::basicBlock->appendInst(psubsb); |
| 2819 | |
| 2820 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2824 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2825 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2826 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2830 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2831 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2832 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2833 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2837 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2838 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2839 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2840 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2841 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2842 | movmsk->addArg(x.value); |
| 2843 | ::basicBlock->appendInst(movmsk); |
| 2844 | |
| 2845 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2849 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2850 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2854 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2855 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | Type *SByte8::getType() |
| 2859 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2860 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2864 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2865 | storeValue(rhs.value); |
| 2866 | } |
| 2867 | |
| 2868 | Byte16::Byte16(const Byte16 &rhs) |
| 2869 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2870 | Value *value = rhs.loadValue(); |
| 2871 | storeValue(value); |
| 2872 | } |
| 2873 | |
| 2874 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2875 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2876 | Value *value = rhs.loadValue(); |
| 2877 | storeValue(value); |
| 2878 | } |
| 2879 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2880 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2881 | { |
| 2882 | storeValue(rhs.value); |
| 2883 | |
| 2884 | return rhs; |
| 2885 | } |
| 2886 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2887 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2888 | { |
| 2889 | Value *value = rhs.loadValue(); |
| 2890 | storeValue(value); |
| 2891 | |
| 2892 | return RValue<Byte16>(value); |
| 2893 | } |
| 2894 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2895 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2896 | { |
| 2897 | Value *value = rhs.loadValue(); |
| 2898 | storeValue(value); |
| 2899 | |
| 2900 | return RValue<Byte16>(value); |
| 2901 | } |
| 2902 | |
| 2903 | Type *Byte16::getType() |
| 2904 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2905 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | Type *SByte16::getType() |
| 2909 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2910 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2911 | } |
| 2912 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2913 | Short2::Short2(RValue<Short4> cast) |
| 2914 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2915 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | Type *Short2::getType() |
| 2919 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2920 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | UShort2::UShort2(RValue<UShort4> cast) |
| 2924 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2925 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | Type *UShort2::getType() |
| 2929 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2930 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2931 | } |
| 2932 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2933 | Short4::Short4(RValue<Int> cast) |
| 2934 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2935 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 2936 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2937 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2938 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2939 | |
| 2940 | storeValue(swizzle); |
| 2941 | } |
| 2942 | |
| 2943 | Short4::Short4(RValue<Int4> cast) |
| 2944 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2945 | int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13}; |
| 2946 | Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType()); |
| 2947 | Value *packed = Nucleus::createShuffleVector(byte16, byte16, pshufb); |
| 2948 | |
| 2949 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2950 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2951 | |
| 2952 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | // Short4::Short4(RValue<Float> cast) |
| 2956 | // { |
| 2957 | // } |
| 2958 | |
| 2959 | Short4::Short4(RValue<Float4> cast) |
| 2960 | { |
| 2961 | assert(false && "UNIMPLEMENTED"); |
| 2962 | } |
| 2963 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2964 | Short4::Short4(short xyzw) |
| 2965 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2966 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2967 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | Short4::Short4(short x, short y, short z, short w) |
| 2971 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2972 | int64_t constantVector[4] = {x, y, z, w}; |
| 2973 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | Short4::Short4(RValue<Short4> rhs) |
| 2977 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2978 | storeValue(rhs.value); |
| 2979 | } |
| 2980 | |
| 2981 | Short4::Short4(const Short4 &rhs) |
| 2982 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2983 | Value *value = rhs.loadValue(); |
| 2984 | storeValue(value); |
| 2985 | } |
| 2986 | |
| 2987 | Short4::Short4(const Reference<Short4> &rhs) |
| 2988 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2989 | Value *value = rhs.loadValue(); |
| 2990 | storeValue(value); |
| 2991 | } |
| 2992 | |
| 2993 | Short4::Short4(RValue<UShort4> rhs) |
| 2994 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2995 | storeValue(rhs.value); |
| 2996 | } |
| 2997 | |
| 2998 | Short4::Short4(const UShort4 &rhs) |
| 2999 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3000 | storeValue(rhs.loadValue()); |
| 3001 | } |
| 3002 | |
| 3003 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3004 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 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 | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3304 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::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 | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3314 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
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 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3331 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 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 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3347 | UShort4::UShort4(unsigned short xyzw) |
| 3348 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3349 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3350 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3354 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3355 | int64_t constantVector[4] = {x, y, z, w}; |
| 3356 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3360 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3361 | storeValue(rhs.value); |
| 3362 | } |
| 3363 | |
| 3364 | UShort4::UShort4(const UShort4 &rhs) |
| 3365 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3366 | Value *value = rhs.loadValue(); |
| 3367 | storeValue(value); |
| 3368 | } |
| 3369 | |
| 3370 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3371 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3372 | Value *value = rhs.loadValue(); |
| 3373 | storeValue(value); |
| 3374 | } |
| 3375 | |
| 3376 | UShort4::UShort4(RValue<Short4> rhs) |
| 3377 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3378 | storeValue(rhs.value); |
| 3379 | } |
| 3380 | |
| 3381 | UShort4::UShort4(const Short4 &rhs) |
| 3382 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3383 | Value *value = rhs.loadValue(); |
| 3384 | storeValue(value); |
| 3385 | } |
| 3386 | |
| 3387 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3388 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3389 | Value *value = rhs.loadValue(); |
| 3390 | storeValue(value); |
| 3391 | } |
| 3392 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3393 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3394 | { |
| 3395 | storeValue(rhs.value); |
| 3396 | |
| 3397 | return rhs; |
| 3398 | } |
| 3399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3400 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3401 | { |
| 3402 | Value *value = rhs.loadValue(); |
| 3403 | storeValue(value); |
| 3404 | |
| 3405 | return RValue<UShort4>(value); |
| 3406 | } |
| 3407 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3408 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3409 | { |
| 3410 | Value *value = rhs.loadValue(); |
| 3411 | storeValue(value); |
| 3412 | |
| 3413 | return RValue<UShort4>(value); |
| 3414 | } |
| 3415 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3416 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3417 | { |
| 3418 | storeValue(rhs.value); |
| 3419 | |
| 3420 | return RValue<UShort4>(rhs); |
| 3421 | } |
| 3422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3423 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3424 | { |
| 3425 | Value *value = rhs.loadValue(); |
| 3426 | storeValue(value); |
| 3427 | |
| 3428 | return RValue<UShort4>(value); |
| 3429 | } |
| 3430 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3431 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3432 | { |
| 3433 | Value *value = rhs.loadValue(); |
| 3434 | storeValue(value); |
| 3435 | |
| 3436 | return RValue<UShort4>(value); |
| 3437 | } |
| 3438 | |
| 3439 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3440 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3441 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3445 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3446 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3450 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3451 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3452 | } |
| 3453 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3454 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3455 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3456 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3460 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3461 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3465 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3466 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3467 | } |
| 3468 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3469 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3470 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3471 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3475 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3476 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3477 | } |
| 3478 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3479 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3480 | { |
| 3481 | return lhs = lhs << rhs; |
| 3482 | } |
| 3483 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3484 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3485 | { |
| 3486 | return lhs = lhs >> rhs; |
| 3487 | } |
| 3488 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3489 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3490 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3491 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3495 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3496 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3497 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3498 | ::basicBlock->appendInst(cmp); |
| 3499 | |
| 3500 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3501 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3502 | ::basicBlock->appendInst(select); |
| 3503 | |
| 3504 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3508 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3509 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3510 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3511 | ::basicBlock->appendInst(cmp); |
| 3512 | |
| 3513 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3514 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3515 | ::basicBlock->appendInst(select); |
| 3516 | |
| 3517 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3521 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3522 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3523 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3524 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3525 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3526 | paddusw->addArg(x.value); |
| 3527 | paddusw->addArg(y.value); |
| 3528 | ::basicBlock->appendInst(paddusw); |
| 3529 | |
| 3530 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3534 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3535 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3536 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3537 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3538 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3539 | psubusw->addArg(x.value); |
| 3540 | psubusw->addArg(y.value); |
| 3541 | ::basicBlock->appendInst(psubusw); |
| 3542 | |
| 3543 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3547 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3548 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3549 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3550 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3551 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3552 | pmulhuw->addArg(x.value); |
| 3553 | pmulhuw->addArg(y.value); |
| 3554 | ::basicBlock->appendInst(pmulhuw); |
| 3555 | |
| 3556 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3560 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3561 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3565 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3566 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3567 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3568 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3569 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3570 | pack->addArg(x.value); |
| 3571 | pack->addArg(y.value); |
| 3572 | ::basicBlock->appendInst(pack); |
| 3573 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3574 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | Type *UShort4::getType() |
| 3578 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3579 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3580 | } |
| 3581 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3582 | Short8::Short8(short c) |
| 3583 | { |
| 3584 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3585 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3586 | } |
| 3587 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3588 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3589 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3590 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3591 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | Short8::Short8(RValue<Short8> rhs) |
| 3595 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3596 | storeValue(rhs.value); |
| 3597 | } |
| 3598 | |
| 3599 | Short8::Short8(const Reference<Short8> &rhs) |
| 3600 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3601 | Value *value = rhs.loadValue(); |
| 3602 | storeValue(value); |
| 3603 | } |
| 3604 | |
| 3605 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3606 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3607 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3608 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3609 | |
| 3610 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3614 | { |
| 3615 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3616 | } |
| 3617 | |
| 3618 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3619 | { |
| 3620 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3621 | } |
| 3622 | |
| 3623 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3624 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3625 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3629 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3630 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3634 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3635 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | RValue<Int4> Abs(RValue<Int4> x) |
| 3639 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3640 | auto negative = x >> 31; |
| 3641 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3645 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3646 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | Type *Short8::getType() |
| 3650 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3651 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3652 | } |
| 3653 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3654 | UShort8::UShort8(unsigned short c) |
| 3655 | { |
| 3656 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3657 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3658 | } |
| 3659 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3660 | 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) |
| 3661 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3662 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3663 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3667 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3668 | storeValue(rhs.value); |
| 3669 | } |
| 3670 | |
| 3671 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3672 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3673 | Value *value = rhs.loadValue(); |
| 3674 | storeValue(value); |
| 3675 | } |
| 3676 | |
| 3677 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3678 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3679 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3680 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3681 | |
| 3682 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3683 | } |
| 3684 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3685 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3686 | { |
| 3687 | storeValue(rhs.value); |
| 3688 | |
| 3689 | return rhs; |
| 3690 | } |
| 3691 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3692 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3693 | { |
| 3694 | Value *value = rhs.loadValue(); |
| 3695 | storeValue(value); |
| 3696 | |
| 3697 | return RValue<UShort8>(value); |
| 3698 | } |
| 3699 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3700 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3701 | { |
| 3702 | Value *value = rhs.loadValue(); |
| 3703 | storeValue(value); |
| 3704 | |
| 3705 | return RValue<UShort8>(value); |
| 3706 | } |
| 3707 | |
| 3708 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3709 | { |
| 3710 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3711 | } |
| 3712 | |
| 3713 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3714 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3715 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3719 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3720 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3724 | { |
| 3725 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3726 | } |
| 3727 | |
| 3728 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3729 | { |
| 3730 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3731 | } |
| 3732 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3733 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3734 | { |
| 3735 | return lhs = lhs + rhs; |
| 3736 | } |
| 3737 | |
| 3738 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3739 | { |
| 3740 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3741 | } |
| 3742 | |
| 3743 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3744 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3745 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3749 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3750 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3754 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3755 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3756 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3757 | // } |
| 3758 | |
| 3759 | Type *UShort8::getType() |
| 3760 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3761 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | Int::Int(Argument<Int> argument) |
| 3765 | { |
| 3766 | storeValue(argument.value); |
| 3767 | } |
| 3768 | |
| 3769 | Int::Int(RValue<Byte> cast) |
| 3770 | { |
| 3771 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3772 | |
| 3773 | storeValue(integer); |
| 3774 | } |
| 3775 | |
| 3776 | Int::Int(RValue<SByte> cast) |
| 3777 | { |
| 3778 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3779 | |
| 3780 | storeValue(integer); |
| 3781 | } |
| 3782 | |
| 3783 | Int::Int(RValue<Short> cast) |
| 3784 | { |
| 3785 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3786 | |
| 3787 | storeValue(integer); |
| 3788 | } |
| 3789 | |
| 3790 | Int::Int(RValue<UShort> cast) |
| 3791 | { |
| 3792 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3793 | |
| 3794 | storeValue(integer); |
| 3795 | } |
| 3796 | |
| 3797 | Int::Int(RValue<Int2> cast) |
| 3798 | { |
| 3799 | *this = Extract(cast, 0); |
| 3800 | } |
| 3801 | |
| 3802 | Int::Int(RValue<Long> cast) |
| 3803 | { |
| 3804 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3805 | |
| 3806 | storeValue(integer); |
| 3807 | } |
| 3808 | |
| 3809 | Int::Int(RValue<Float> cast) |
| 3810 | { |
| 3811 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3812 | |
| 3813 | storeValue(integer); |
| 3814 | } |
| 3815 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3816 | Int::Int(int x) |
| 3817 | { |
| 3818 | storeValue(Nucleus::createConstantInt(x)); |
| 3819 | } |
| 3820 | |
| 3821 | Int::Int(RValue<Int> rhs) |
| 3822 | { |
| 3823 | storeValue(rhs.value); |
| 3824 | } |
| 3825 | |
| 3826 | Int::Int(RValue<UInt> rhs) |
| 3827 | { |
| 3828 | storeValue(rhs.value); |
| 3829 | } |
| 3830 | |
| 3831 | Int::Int(const Int &rhs) |
| 3832 | { |
| 3833 | Value *value = rhs.loadValue(); |
| 3834 | storeValue(value); |
| 3835 | } |
| 3836 | |
| 3837 | Int::Int(const Reference<Int> &rhs) |
| 3838 | { |
| 3839 | Value *value = rhs.loadValue(); |
| 3840 | storeValue(value); |
| 3841 | } |
| 3842 | |
| 3843 | Int::Int(const UInt &rhs) |
| 3844 | { |
| 3845 | Value *value = rhs.loadValue(); |
| 3846 | storeValue(value); |
| 3847 | } |
| 3848 | |
| 3849 | Int::Int(const Reference<UInt> &rhs) |
| 3850 | { |
| 3851 | Value *value = rhs.loadValue(); |
| 3852 | storeValue(value); |
| 3853 | } |
| 3854 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3855 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3856 | { |
| 3857 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3858 | } |
| 3859 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3860 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3861 | { |
| 3862 | storeValue(rhs.value); |
| 3863 | |
| 3864 | return rhs; |
| 3865 | } |
| 3866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3867 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3868 | { |
| 3869 | storeValue(rhs.value); |
| 3870 | |
| 3871 | return RValue<Int>(rhs); |
| 3872 | } |
| 3873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3874 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3875 | { |
| 3876 | Value *value = rhs.loadValue(); |
| 3877 | storeValue(value); |
| 3878 | |
| 3879 | return RValue<Int>(value); |
| 3880 | } |
| 3881 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3882 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3883 | { |
| 3884 | Value *value = rhs.loadValue(); |
| 3885 | storeValue(value); |
| 3886 | |
| 3887 | return RValue<Int>(value); |
| 3888 | } |
| 3889 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3890 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3891 | { |
| 3892 | Value *value = rhs.loadValue(); |
| 3893 | storeValue(value); |
| 3894 | |
| 3895 | return RValue<Int>(value); |
| 3896 | } |
| 3897 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3898 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3899 | { |
| 3900 | Value *value = rhs.loadValue(); |
| 3901 | storeValue(value); |
| 3902 | |
| 3903 | return RValue<Int>(value); |
| 3904 | } |
| 3905 | |
| 3906 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3907 | { |
| 3908 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3909 | } |
| 3910 | |
| 3911 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3912 | { |
| 3913 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3914 | } |
| 3915 | |
| 3916 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3917 | { |
| 3918 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3919 | } |
| 3920 | |
| 3921 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3922 | { |
| 3923 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3924 | } |
| 3925 | |
| 3926 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3927 | { |
| 3928 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3929 | } |
| 3930 | |
| 3931 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3932 | { |
| 3933 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3934 | } |
| 3935 | |
| 3936 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 3937 | { |
| 3938 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3939 | } |
| 3940 | |
| 3941 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 3942 | { |
| 3943 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3944 | } |
| 3945 | |
| 3946 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 3947 | { |
| 3948 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3949 | } |
| 3950 | |
| 3951 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 3952 | { |
| 3953 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3954 | } |
| 3955 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3956 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3957 | { |
| 3958 | return lhs = lhs + rhs; |
| 3959 | } |
| 3960 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3961 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3962 | { |
| 3963 | return lhs = lhs - rhs; |
| 3964 | } |
| 3965 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3966 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3967 | { |
| 3968 | return lhs = lhs * rhs; |
| 3969 | } |
| 3970 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3971 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3972 | { |
| 3973 | return lhs = lhs / rhs; |
| 3974 | } |
| 3975 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3976 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3977 | { |
| 3978 | return lhs = lhs % rhs; |
| 3979 | } |
| 3980 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3981 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3982 | { |
| 3983 | return lhs = lhs & rhs; |
| 3984 | } |
| 3985 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3986 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3987 | { |
| 3988 | return lhs = lhs | rhs; |
| 3989 | } |
| 3990 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3991 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3992 | { |
| 3993 | return lhs = lhs ^ rhs; |
| 3994 | } |
| 3995 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3996 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3997 | { |
| 3998 | return lhs = lhs << rhs; |
| 3999 | } |
| 4000 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4001 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4002 | { |
| 4003 | return lhs = lhs >> rhs; |
| 4004 | } |
| 4005 | |
| 4006 | RValue<Int> operator+(RValue<Int> val) |
| 4007 | { |
| 4008 | return val; |
| 4009 | } |
| 4010 | |
| 4011 | RValue<Int> operator-(RValue<Int> val) |
| 4012 | { |
| 4013 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4014 | } |
| 4015 | |
| 4016 | RValue<Int> operator~(RValue<Int> val) |
| 4017 | { |
| 4018 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4019 | } |
| 4020 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4021 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4022 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4023 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4024 | val += 1; |
| 4025 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4026 | } |
| 4027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4028 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4029 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4030 | val += 1; |
| 4031 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4032 | } |
| 4033 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4034 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4035 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4036 | RValue<Int> res = val; |
| 4037 | val -= 1; |
| 4038 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4039 | } |
| 4040 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4041 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4042 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4043 | val -= 1; |
| 4044 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4048 | { |
| 4049 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4050 | } |
| 4051 | |
| 4052 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4053 | { |
| 4054 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4055 | } |
| 4056 | |
| 4057 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4058 | { |
| 4059 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4060 | } |
| 4061 | |
| 4062 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4063 | { |
| 4064 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4065 | } |
| 4066 | |
| 4067 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4068 | { |
| 4069 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4070 | } |
| 4071 | |
| 4072 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4073 | { |
| 4074 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4075 | } |
| 4076 | |
| 4077 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4078 | { |
| 4079 | return IfThenElse(x > y, x, y); |
| 4080 | } |
| 4081 | |
| 4082 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4083 | { |
| 4084 | return IfThenElse(x < y, x, y); |
| 4085 | } |
| 4086 | |
| 4087 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4088 | { |
| 4089 | return Min(Max(x, min), max); |
| 4090 | } |
| 4091 | |
| 4092 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4093 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4094 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 4095 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4096 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4097 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4098 | nearbyint->addArg(cast.value); |
| 4099 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4100 | |
| 4101 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | Type *Int::getType() |
| 4105 | { |
| 4106 | return T(Ice::IceType_i32); |
| 4107 | } |
| 4108 | |
| 4109 | Long::Long(RValue<Int> cast) |
| 4110 | { |
| 4111 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4112 | |
| 4113 | storeValue(integer); |
| 4114 | } |
| 4115 | |
| 4116 | Long::Long(RValue<UInt> cast) |
| 4117 | { |
| 4118 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4119 | |
| 4120 | storeValue(integer); |
| 4121 | } |
| 4122 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4123 | Long::Long(RValue<Long> rhs) |
| 4124 | { |
| 4125 | storeValue(rhs.value); |
| 4126 | } |
| 4127 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4128 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4129 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4130 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4131 | } |
| 4132 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4133 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4134 | { |
| 4135 | storeValue(rhs.value); |
| 4136 | |
| 4137 | return rhs; |
| 4138 | } |
| 4139 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4140 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4141 | { |
| 4142 | Value *value = rhs.loadValue(); |
| 4143 | storeValue(value); |
| 4144 | |
| 4145 | return RValue<Long>(value); |
| 4146 | } |
| 4147 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4148 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4149 | { |
| 4150 | Value *value = rhs.loadValue(); |
| 4151 | storeValue(value); |
| 4152 | |
| 4153 | return RValue<Long>(value); |
| 4154 | } |
| 4155 | |
| 4156 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4157 | { |
| 4158 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4159 | } |
| 4160 | |
| 4161 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4162 | { |
| 4163 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4164 | } |
| 4165 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4166 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4167 | { |
| 4168 | return lhs = lhs + rhs; |
| 4169 | } |
| 4170 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4171 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4172 | { |
| 4173 | return lhs = lhs - rhs; |
| 4174 | } |
| 4175 | |
| 4176 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4177 | { |
| 4178 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4179 | } |
| 4180 | |
| 4181 | Type *Long::getType() |
| 4182 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4183 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4184 | } |
| 4185 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4186 | UInt::UInt(Argument<UInt> argument) |
| 4187 | { |
| 4188 | storeValue(argument.value); |
| 4189 | } |
| 4190 | |
| 4191 | UInt::UInt(RValue<UShort> cast) |
| 4192 | { |
| 4193 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4194 | |
| 4195 | storeValue(integer); |
| 4196 | } |
| 4197 | |
| 4198 | UInt::UInt(RValue<Long> cast) |
| 4199 | { |
| 4200 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4201 | |
| 4202 | storeValue(integer); |
| 4203 | } |
| 4204 | |
| 4205 | UInt::UInt(RValue<Float> cast) |
| 4206 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4207 | // Smallest positive value representable in UInt, but not in Int |
| 4208 | const unsigned int ustart = 0x80000000u; |
| 4209 | const float ustartf = float(ustart); |
| 4210 | |
| 4211 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4212 | storeValue((~(As<Int>(cast) >> 31) & |
| 4213 | // Check if the value can be represented as an Int |
| 4214 | IfThenElse(cast >= ustartf, |
| 4215 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4216 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4217 | // Otherwise, just convert normally |
| 4218 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4219 | } |
| 4220 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4221 | UInt::UInt(int x) |
| 4222 | { |
| 4223 | storeValue(Nucleus::createConstantInt(x)); |
| 4224 | } |
| 4225 | |
| 4226 | UInt::UInt(unsigned int x) |
| 4227 | { |
| 4228 | storeValue(Nucleus::createConstantInt(x)); |
| 4229 | } |
| 4230 | |
| 4231 | UInt::UInt(RValue<UInt> rhs) |
| 4232 | { |
| 4233 | storeValue(rhs.value); |
| 4234 | } |
| 4235 | |
| 4236 | UInt::UInt(RValue<Int> rhs) |
| 4237 | { |
| 4238 | storeValue(rhs.value); |
| 4239 | } |
| 4240 | |
| 4241 | UInt::UInt(const UInt &rhs) |
| 4242 | { |
| 4243 | Value *value = rhs.loadValue(); |
| 4244 | storeValue(value); |
| 4245 | } |
| 4246 | |
| 4247 | UInt::UInt(const Reference<UInt> &rhs) |
| 4248 | { |
| 4249 | Value *value = rhs.loadValue(); |
| 4250 | storeValue(value); |
| 4251 | } |
| 4252 | |
| 4253 | UInt::UInt(const Int &rhs) |
| 4254 | { |
| 4255 | Value *value = rhs.loadValue(); |
| 4256 | storeValue(value); |
| 4257 | } |
| 4258 | |
| 4259 | UInt::UInt(const Reference<Int> &rhs) |
| 4260 | { |
| 4261 | Value *value = rhs.loadValue(); |
| 4262 | storeValue(value); |
| 4263 | } |
| 4264 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4265 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4266 | { |
| 4267 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4268 | } |
| 4269 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4270 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4271 | { |
| 4272 | storeValue(rhs.value); |
| 4273 | |
| 4274 | return rhs; |
| 4275 | } |
| 4276 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4277 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4278 | { |
| 4279 | storeValue(rhs.value); |
| 4280 | |
| 4281 | return RValue<UInt>(rhs); |
| 4282 | } |
| 4283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4284 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4285 | { |
| 4286 | Value *value = rhs.loadValue(); |
| 4287 | storeValue(value); |
| 4288 | |
| 4289 | return RValue<UInt>(value); |
| 4290 | } |
| 4291 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4292 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4293 | { |
| 4294 | Value *value = rhs.loadValue(); |
| 4295 | storeValue(value); |
| 4296 | |
| 4297 | return RValue<UInt>(value); |
| 4298 | } |
| 4299 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4300 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4301 | { |
| 4302 | Value *value = rhs.loadValue(); |
| 4303 | storeValue(value); |
| 4304 | |
| 4305 | return RValue<UInt>(value); |
| 4306 | } |
| 4307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4308 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4309 | { |
| 4310 | Value *value = rhs.loadValue(); |
| 4311 | storeValue(value); |
| 4312 | |
| 4313 | return RValue<UInt>(value); |
| 4314 | } |
| 4315 | |
| 4316 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4317 | { |
| 4318 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4319 | } |
| 4320 | |
| 4321 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4322 | { |
| 4323 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4324 | } |
| 4325 | |
| 4326 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4327 | { |
| 4328 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4329 | } |
| 4330 | |
| 4331 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4332 | { |
| 4333 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4334 | } |
| 4335 | |
| 4336 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4337 | { |
| 4338 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4339 | } |
| 4340 | |
| 4341 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4342 | { |
| 4343 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4344 | } |
| 4345 | |
| 4346 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4347 | { |
| 4348 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4349 | } |
| 4350 | |
| 4351 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4352 | { |
| 4353 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4354 | } |
| 4355 | |
| 4356 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4357 | { |
| 4358 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4359 | } |
| 4360 | |
| 4361 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4362 | { |
| 4363 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4364 | } |
| 4365 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4366 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4367 | { |
| 4368 | return lhs = lhs + rhs; |
| 4369 | } |
| 4370 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4371 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4372 | { |
| 4373 | return lhs = lhs - rhs; |
| 4374 | } |
| 4375 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4376 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4377 | { |
| 4378 | return lhs = lhs * rhs; |
| 4379 | } |
| 4380 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4381 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4382 | { |
| 4383 | return lhs = lhs / rhs; |
| 4384 | } |
| 4385 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4386 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4387 | { |
| 4388 | return lhs = lhs % rhs; |
| 4389 | } |
| 4390 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4391 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4392 | { |
| 4393 | return lhs = lhs & rhs; |
| 4394 | } |
| 4395 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4396 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4397 | { |
| 4398 | return lhs = lhs | rhs; |
| 4399 | } |
| 4400 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4401 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4402 | { |
| 4403 | return lhs = lhs ^ rhs; |
| 4404 | } |
| 4405 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4406 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4407 | { |
| 4408 | return lhs = lhs << rhs; |
| 4409 | } |
| 4410 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4411 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4412 | { |
| 4413 | return lhs = lhs >> rhs; |
| 4414 | } |
| 4415 | |
| 4416 | RValue<UInt> operator+(RValue<UInt> val) |
| 4417 | { |
| 4418 | return val; |
| 4419 | } |
| 4420 | |
| 4421 | RValue<UInt> operator-(RValue<UInt> val) |
| 4422 | { |
| 4423 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4424 | } |
| 4425 | |
| 4426 | RValue<UInt> operator~(RValue<UInt> val) |
| 4427 | { |
| 4428 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4429 | } |
| 4430 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4431 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4432 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4433 | RValue<UInt> res = val; |
| 4434 | val += 1; |
| 4435 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4436 | } |
| 4437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4438 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4439 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4440 | val += 1; |
| 4441 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4442 | } |
| 4443 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4444 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4445 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4446 | RValue<UInt> res = val; |
| 4447 | val -= 1; |
| 4448 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4449 | } |
| 4450 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4451 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4452 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4453 | val -= 1; |
| 4454 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4458 | { |
| 4459 | return IfThenElse(x > y, x, y); |
| 4460 | } |
| 4461 | |
| 4462 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4463 | { |
| 4464 | return IfThenElse(x < y, x, y); |
| 4465 | } |
| 4466 | |
| 4467 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4468 | { |
| 4469 | return Min(Max(x, min), max); |
| 4470 | } |
| 4471 | |
| 4472 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4473 | { |
| 4474 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4475 | } |
| 4476 | |
| 4477 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4478 | { |
| 4479 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4480 | } |
| 4481 | |
| 4482 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4483 | { |
| 4484 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4485 | } |
| 4486 | |
| 4487 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4488 | { |
| 4489 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4490 | } |
| 4491 | |
| 4492 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4493 | { |
| 4494 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4495 | } |
| 4496 | |
| 4497 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4498 | { |
| 4499 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4500 | } |
| 4501 | |
| 4502 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4503 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4504 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4505 | // } |
| 4506 | |
| 4507 | Type *UInt::getType() |
| 4508 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4509 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | // Int2::Int2(RValue<Int> cast) |
| 4513 | // { |
| 4514 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4515 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4516 | // |
| 4517 | // Constant *shuffle[2]; |
| 4518 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4519 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4520 | // |
| 4521 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4522 | // |
| 4523 | // storeValue(replicate); |
| 4524 | // } |
| 4525 | |
| 4526 | Int2::Int2(RValue<Int4> cast) |
| 4527 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4528 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4529 | } |
| 4530 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4531 | Int2::Int2(int x, int y) |
| 4532 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4533 | int64_t constantVector[2] = {x, y}; |
| 4534 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | Int2::Int2(RValue<Int2> rhs) |
| 4538 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4539 | storeValue(rhs.value); |
| 4540 | } |
| 4541 | |
| 4542 | Int2::Int2(const Int2 &rhs) |
| 4543 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4544 | Value *value = rhs.loadValue(); |
| 4545 | storeValue(value); |
| 4546 | } |
| 4547 | |
| 4548 | Int2::Int2(const Reference<Int2> &rhs) |
| 4549 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4550 | Value *value = rhs.loadValue(); |
| 4551 | storeValue(value); |
| 4552 | } |
| 4553 | |
| 4554 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4555 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4556 | int shuffle[4] = {0, 4, 1, 5}; |
| 4557 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4558 | |
| 4559 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4560 | } |
| 4561 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4562 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4563 | { |
| 4564 | storeValue(rhs.value); |
| 4565 | |
| 4566 | return rhs; |
| 4567 | } |
| 4568 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4569 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4570 | { |
| 4571 | Value *value = rhs.loadValue(); |
| 4572 | storeValue(value); |
| 4573 | |
| 4574 | return RValue<Int2>(value); |
| 4575 | } |
| 4576 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4577 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4578 | { |
| 4579 | Value *value = rhs.loadValue(); |
| 4580 | storeValue(value); |
| 4581 | |
| 4582 | return RValue<Int2>(value); |
| 4583 | } |
| 4584 | |
| 4585 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4586 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4587 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4591 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4592 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4596 | // { |
| 4597 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4598 | // } |
| 4599 | |
| 4600 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4601 | // { |
| 4602 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4603 | // } |
| 4604 | |
| 4605 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4606 | // { |
| 4607 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4608 | // } |
| 4609 | |
| 4610 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4611 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4612 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4616 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4617 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4621 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4622 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4626 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4627 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4631 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4632 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4633 | } |
| 4634 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4635 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4636 | { |
| 4637 | return lhs = lhs + rhs; |
| 4638 | } |
| 4639 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4640 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4641 | { |
| 4642 | return lhs = lhs - rhs; |
| 4643 | } |
| 4644 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4645 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4646 | // { |
| 4647 | // return lhs = lhs * rhs; |
| 4648 | // } |
| 4649 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4650 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4651 | // { |
| 4652 | // return lhs = lhs / rhs; |
| 4653 | // } |
| 4654 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4655 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4656 | // { |
| 4657 | // return lhs = lhs % rhs; |
| 4658 | // } |
| 4659 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4660 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4661 | { |
| 4662 | return lhs = lhs & rhs; |
| 4663 | } |
| 4664 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4665 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4666 | { |
| 4667 | return lhs = lhs | rhs; |
| 4668 | } |
| 4669 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4670 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4671 | { |
| 4672 | return lhs = lhs ^ rhs; |
| 4673 | } |
| 4674 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4675 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4676 | { |
| 4677 | return lhs = lhs << rhs; |
| 4678 | } |
| 4679 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4680 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4681 | { |
| 4682 | return lhs = lhs >> rhs; |
| 4683 | } |
| 4684 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4685 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4686 | // { |
| 4687 | // return val; |
| 4688 | // } |
| 4689 | |
| 4690 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4691 | // { |
| 4692 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4693 | // } |
| 4694 | |
| 4695 | RValue<Int2> operator~(RValue<Int2> val) |
| 4696 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4697 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4698 | } |
| 4699 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4700 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4701 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4702 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4703 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4704 | } |
| 4705 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4706 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4707 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4708 | int shuffle[16] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4709 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4710 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4714 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4715 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4719 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4720 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | Type *Int2::getType() |
| 4724 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4725 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4726 | } |
| 4727 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4728 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4729 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4730 | int64_t constantVector[2] = {x, y}; |
| 4731 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4735 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4736 | storeValue(rhs.value); |
| 4737 | } |
| 4738 | |
| 4739 | UInt2::UInt2(const UInt2 &rhs) |
| 4740 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4741 | Value *value = rhs.loadValue(); |
| 4742 | storeValue(value); |
| 4743 | } |
| 4744 | |
| 4745 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4746 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4747 | Value *value = rhs.loadValue(); |
| 4748 | storeValue(value); |
| 4749 | } |
| 4750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4751 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4752 | { |
| 4753 | storeValue(rhs.value); |
| 4754 | |
| 4755 | return rhs; |
| 4756 | } |
| 4757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4758 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4759 | { |
| 4760 | Value *value = rhs.loadValue(); |
| 4761 | storeValue(value); |
| 4762 | |
| 4763 | return RValue<UInt2>(value); |
| 4764 | } |
| 4765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4766 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4767 | { |
| 4768 | Value *value = rhs.loadValue(); |
| 4769 | storeValue(value); |
| 4770 | |
| 4771 | return RValue<UInt2>(value); |
| 4772 | } |
| 4773 | |
| 4774 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4775 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4776 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4780 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4781 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4785 | // { |
| 4786 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4787 | // } |
| 4788 | |
| 4789 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4790 | // { |
| 4791 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4792 | // } |
| 4793 | |
| 4794 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4795 | // { |
| 4796 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4797 | // } |
| 4798 | |
| 4799 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4800 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4801 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4805 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4806 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4810 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4811 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4815 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4816 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4820 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4821 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4822 | } |
| 4823 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4824 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4825 | { |
| 4826 | return lhs = lhs + rhs; |
| 4827 | } |
| 4828 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4829 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4830 | { |
| 4831 | return lhs = lhs - rhs; |
| 4832 | } |
| 4833 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4834 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4835 | // { |
| 4836 | // return lhs = lhs * rhs; |
| 4837 | // } |
| 4838 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4839 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4840 | // { |
| 4841 | // return lhs = lhs / rhs; |
| 4842 | // } |
| 4843 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4844 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4845 | // { |
| 4846 | // return lhs = lhs % rhs; |
| 4847 | // } |
| 4848 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4849 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4850 | { |
| 4851 | return lhs = lhs & rhs; |
| 4852 | } |
| 4853 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4854 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4855 | { |
| 4856 | return lhs = lhs | rhs; |
| 4857 | } |
| 4858 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4859 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4860 | { |
| 4861 | return lhs = lhs ^ rhs; |
| 4862 | } |
| 4863 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4864 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4865 | { |
| 4866 | return lhs = lhs << rhs; |
| 4867 | } |
| 4868 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4869 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4870 | { |
| 4871 | return lhs = lhs >> rhs; |
| 4872 | } |
| 4873 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4874 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4875 | // { |
| 4876 | // return val; |
| 4877 | // } |
| 4878 | |
| 4879 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4880 | // { |
| 4881 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4882 | // } |
| 4883 | |
| 4884 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4885 | { |
| 4886 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4887 | } |
| 4888 | |
| 4889 | Type *UInt2::getType() |
| 4890 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4891 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | Int4::Int4(RValue<Byte4> cast) |
| 4895 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4896 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4897 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4898 | |
| 4899 | Value *e; |
| 4900 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4901 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4902 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4903 | |
| 4904 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4905 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4906 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4907 | |
| 4908 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4909 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | Int4::Int4(RValue<SByte4> cast) |
| 4913 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4914 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4915 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4916 | |
| 4917 | Value *e; |
| 4918 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4919 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4920 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4921 | |
| 4922 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4923 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4924 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 4925 | |
| 4926 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4927 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4928 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | Int4::Int4(RValue<Float4> cast) |
| 4932 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4933 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 4934 | |
| 4935 | storeValue(xyzw); |
| 4936 | } |
| 4937 | |
| 4938 | Int4::Int4(RValue<Short4> cast) |
| 4939 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4940 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4941 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 4942 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4943 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4944 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | Int4::Int4(RValue<UShort4> cast) |
| 4948 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4949 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4950 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 4951 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4952 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4953 | } |
| 4954 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4955 | Int4::Int4(int xyzw) |
| 4956 | { |
| 4957 | constant(xyzw, xyzw, xyzw, xyzw); |
| 4958 | } |
| 4959 | |
| 4960 | Int4::Int4(int x, int yzw) |
| 4961 | { |
| 4962 | constant(x, yzw, yzw, yzw); |
| 4963 | } |
| 4964 | |
| 4965 | Int4::Int4(int x, int y, int zw) |
| 4966 | { |
| 4967 | constant(x, y, zw, zw); |
| 4968 | } |
| 4969 | |
| 4970 | Int4::Int4(int x, int y, int z, int w) |
| 4971 | { |
| 4972 | constant(x, y, z, w); |
| 4973 | } |
| 4974 | |
| 4975 | void Int4::constant(int x, int y, int z, int w) |
| 4976 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4977 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4978 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | Int4::Int4(RValue<Int4> rhs) |
| 4982 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4983 | storeValue(rhs.value); |
| 4984 | } |
| 4985 | |
| 4986 | Int4::Int4(const Int4 &rhs) |
| 4987 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4988 | Value *value = rhs.loadValue(); |
| 4989 | storeValue(value); |
| 4990 | } |
| 4991 | |
| 4992 | Int4::Int4(const Reference<Int4> &rhs) |
| 4993 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4994 | Value *value = rhs.loadValue(); |
| 4995 | storeValue(value); |
| 4996 | } |
| 4997 | |
| 4998 | Int4::Int4(RValue<UInt4> rhs) |
| 4999 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5000 | storeValue(rhs.value); |
| 5001 | } |
| 5002 | |
| 5003 | Int4::Int4(const UInt4 &rhs) |
| 5004 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5005 | Value *value = rhs.loadValue(); |
| 5006 | storeValue(value); |
| 5007 | } |
| 5008 | |
| 5009 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5010 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5011 | Value *value = rhs.loadValue(); |
| 5012 | storeValue(value); |
| 5013 | } |
| 5014 | |
| 5015 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5016 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5017 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5018 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5019 | |
| 5020 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | Int4::Int4(RValue<Int> rhs) |
| 5024 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5025 | Value *vector = loadValue(); |
| 5026 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5027 | |
| 5028 | int swizzle[4] = {0, 0, 0, 0}; |
| 5029 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 5030 | |
| 5031 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | Int4::Int4(const Int &rhs) |
| 5035 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5036 | *this = RValue<Int>(rhs.loadValue()); |
| 5037 | } |
| 5038 | |
| 5039 | Int4::Int4(const Reference<Int> &rhs) |
| 5040 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5041 | *this = RValue<Int>(rhs.loadValue()); |
| 5042 | } |
| 5043 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5044 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5045 | { |
| 5046 | storeValue(rhs.value); |
| 5047 | |
| 5048 | return rhs; |
| 5049 | } |
| 5050 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5051 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5052 | { |
| 5053 | Value *value = rhs.loadValue(); |
| 5054 | storeValue(value); |
| 5055 | |
| 5056 | return RValue<Int4>(value); |
| 5057 | } |
| 5058 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5059 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5060 | { |
| 5061 | Value *value = rhs.loadValue(); |
| 5062 | storeValue(value); |
| 5063 | |
| 5064 | return RValue<Int4>(value); |
| 5065 | } |
| 5066 | |
| 5067 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5068 | { |
| 5069 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5070 | } |
| 5071 | |
| 5072 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5073 | { |
| 5074 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5075 | } |
| 5076 | |
| 5077 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5078 | { |
| 5079 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5080 | } |
| 5081 | |
| 5082 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5083 | { |
| 5084 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5085 | } |
| 5086 | |
| 5087 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5088 | { |
| 5089 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5090 | } |
| 5091 | |
| 5092 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5093 | { |
| 5094 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5095 | } |
| 5096 | |
| 5097 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5098 | { |
| 5099 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5100 | } |
| 5101 | |
| 5102 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5103 | { |
| 5104 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5105 | } |
| 5106 | |
| 5107 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5108 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5109 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5113 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5114 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5118 | { |
| 5119 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5120 | } |
| 5121 | |
| 5122 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5123 | { |
| 5124 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5125 | } |
| 5126 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5127 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5128 | { |
| 5129 | return lhs = lhs + rhs; |
| 5130 | } |
| 5131 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5132 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5133 | { |
| 5134 | return lhs = lhs - rhs; |
| 5135 | } |
| 5136 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5137 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5138 | { |
| 5139 | return lhs = lhs * rhs; |
| 5140 | } |
| 5141 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5142 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5143 | // { |
| 5144 | // return lhs = lhs / rhs; |
| 5145 | // } |
| 5146 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5147 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5148 | // { |
| 5149 | // return lhs = lhs % rhs; |
| 5150 | // } |
| 5151 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5152 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5153 | { |
| 5154 | return lhs = lhs & rhs; |
| 5155 | } |
| 5156 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5157 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5158 | { |
| 5159 | return lhs = lhs | rhs; |
| 5160 | } |
| 5161 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5162 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5163 | { |
| 5164 | return lhs = lhs ^ rhs; |
| 5165 | } |
| 5166 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5167 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5168 | { |
| 5169 | return lhs = lhs << rhs; |
| 5170 | } |
| 5171 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5172 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5173 | { |
| 5174 | return lhs = lhs >> rhs; |
| 5175 | } |
| 5176 | |
| 5177 | RValue<Int4> operator+(RValue<Int4> val) |
| 5178 | { |
| 5179 | return val; |
| 5180 | } |
| 5181 | |
| 5182 | RValue<Int4> operator-(RValue<Int4> val) |
| 5183 | { |
| 5184 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5185 | } |
| 5186 | |
| 5187 | RValue<Int4> operator~(RValue<Int4> val) |
| 5188 | { |
| 5189 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5190 | } |
| 5191 | |
| 5192 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5193 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5194 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5198 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5199 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5203 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5204 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5208 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5209 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5213 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5214 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5218 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5219 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5223 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5224 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5225 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5226 | ::basicBlock->appendInst(cmp); |
| 5227 | |
| 5228 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5229 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5230 | ::basicBlock->appendInst(select); |
| 5231 | |
| 5232 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5236 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5237 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5238 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5239 | ::basicBlock->appendInst(cmp); |
| 5240 | |
| 5241 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5242 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5243 | ::basicBlock->appendInst(select); |
| 5244 | |
| 5245 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5249 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5250 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5251 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5252 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5253 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5254 | nearbyint->addArg(cast.value); |
| 5255 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5256 | |
| 5257 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5261 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5262 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5263 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5264 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5265 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5266 | pack->addArg(x.value); |
| 5267 | pack->addArg(y.value); |
| 5268 | ::basicBlock->appendInst(pack); |
| 5269 | |
| 5270 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5274 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5275 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5279 | { |
| 5280 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5281 | } |
| 5282 | |
| 5283 | RValue<Int> SignMask(RValue<Int4> x) |
| 5284 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5285 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5286 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5287 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5288 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5289 | movmsk->addArg(x.value); |
| 5290 | ::basicBlock->appendInst(movmsk); |
| 5291 | |
| 5292 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5296 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5297 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | Type *Int4::getType() |
| 5301 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5302 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | UInt4::UInt4(RValue<Float4> cast) |
| 5306 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5307 | // Smallest positive value representable in UInt, but not in Int |
| 5308 | const unsigned int ustart = 0x80000000u; |
| 5309 | const float ustartf = float(ustart); |
| 5310 | |
| 5311 | // Check if the value can be represented as an Int |
| 5312 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5313 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5314 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5315 | // Otherwise, just convert normally |
| 5316 | (~uiValue & Int4(cast)); |
| 5317 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5318 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5319 | } |
| 5320 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5321 | UInt4::UInt4(int xyzw) |
| 5322 | { |
| 5323 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5324 | } |
| 5325 | |
| 5326 | UInt4::UInt4(int x, int yzw) |
| 5327 | { |
| 5328 | constant(x, yzw, yzw, yzw); |
| 5329 | } |
| 5330 | |
| 5331 | UInt4::UInt4(int x, int y, int zw) |
| 5332 | { |
| 5333 | constant(x, y, zw, zw); |
| 5334 | } |
| 5335 | |
| 5336 | UInt4::UInt4(int x, int y, int z, int w) |
| 5337 | { |
| 5338 | constant(x, y, z, w); |
| 5339 | } |
| 5340 | |
| 5341 | void UInt4::constant(int x, int y, int z, int w) |
| 5342 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5343 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5344 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5348 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5349 | storeValue(rhs.value); |
| 5350 | } |
| 5351 | |
| 5352 | UInt4::UInt4(const UInt4 &rhs) |
| 5353 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5354 | Value *value = rhs.loadValue(); |
| 5355 | storeValue(value); |
| 5356 | } |
| 5357 | |
| 5358 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5359 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5360 | Value *value = rhs.loadValue(); |
| 5361 | storeValue(value); |
| 5362 | } |
| 5363 | |
| 5364 | UInt4::UInt4(RValue<Int4> rhs) |
| 5365 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5366 | storeValue(rhs.value); |
| 5367 | } |
| 5368 | |
| 5369 | UInt4::UInt4(const Int4 &rhs) |
| 5370 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5371 | Value *value = rhs.loadValue(); |
| 5372 | storeValue(value); |
| 5373 | } |
| 5374 | |
| 5375 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5376 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5377 | Value *value = rhs.loadValue(); |
| 5378 | storeValue(value); |
| 5379 | } |
| 5380 | |
| 5381 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5382 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5383 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5384 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5385 | |
| 5386 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5387 | } |
| 5388 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5389 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5390 | { |
| 5391 | storeValue(rhs.value); |
| 5392 | |
| 5393 | return rhs; |
| 5394 | } |
| 5395 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5396 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5397 | { |
| 5398 | Value *value = rhs.loadValue(); |
| 5399 | storeValue(value); |
| 5400 | |
| 5401 | return RValue<UInt4>(value); |
| 5402 | } |
| 5403 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5404 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5405 | { |
| 5406 | Value *value = rhs.loadValue(); |
| 5407 | storeValue(value); |
| 5408 | |
| 5409 | return RValue<UInt4>(value); |
| 5410 | } |
| 5411 | |
| 5412 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5413 | { |
| 5414 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5415 | } |
| 5416 | |
| 5417 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5418 | { |
| 5419 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5420 | } |
| 5421 | |
| 5422 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5423 | { |
| 5424 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5425 | } |
| 5426 | |
| 5427 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5428 | { |
| 5429 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5430 | } |
| 5431 | |
| 5432 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5433 | { |
| 5434 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5435 | } |
| 5436 | |
| 5437 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5438 | { |
| 5439 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5440 | } |
| 5441 | |
| 5442 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5443 | { |
| 5444 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5445 | } |
| 5446 | |
| 5447 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5448 | { |
| 5449 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5450 | } |
| 5451 | |
| 5452 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5453 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5454 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5458 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5459 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5463 | { |
| 5464 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5465 | } |
| 5466 | |
| 5467 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5468 | { |
| 5469 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5470 | } |
| 5471 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5472 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5473 | { |
| 5474 | return lhs = lhs + rhs; |
| 5475 | } |
| 5476 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5477 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5478 | { |
| 5479 | return lhs = lhs - rhs; |
| 5480 | } |
| 5481 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5482 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5483 | { |
| 5484 | return lhs = lhs * rhs; |
| 5485 | } |
| 5486 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5487 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5488 | // { |
| 5489 | // return lhs = lhs / rhs; |
| 5490 | // } |
| 5491 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5492 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5493 | // { |
| 5494 | // return lhs = lhs % rhs; |
| 5495 | // } |
| 5496 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5497 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5498 | { |
| 5499 | return lhs = lhs & rhs; |
| 5500 | } |
| 5501 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5502 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5503 | { |
| 5504 | return lhs = lhs | rhs; |
| 5505 | } |
| 5506 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5507 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5508 | { |
| 5509 | return lhs = lhs ^ rhs; |
| 5510 | } |
| 5511 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5512 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5513 | { |
| 5514 | return lhs = lhs << rhs; |
| 5515 | } |
| 5516 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5517 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5518 | { |
| 5519 | return lhs = lhs >> rhs; |
| 5520 | } |
| 5521 | |
| 5522 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5523 | { |
| 5524 | return val; |
| 5525 | } |
| 5526 | |
| 5527 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5528 | { |
| 5529 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5530 | } |
| 5531 | |
| 5532 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5533 | { |
| 5534 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5535 | } |
| 5536 | |
| 5537 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5538 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5539 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5543 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5544 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5548 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5549 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5553 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5554 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5558 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5559 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5563 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5564 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5568 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5569 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5570 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5571 | ::basicBlock->appendInst(cmp); |
| 5572 | |
| 5573 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5574 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5575 | ::basicBlock->appendInst(select); |
| 5576 | |
| 5577 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5581 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5582 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5583 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5584 | ::basicBlock->appendInst(cmp); |
| 5585 | |
| 5586 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5587 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5588 | ::basicBlock->appendInst(select); |
| 5589 | |
| 5590 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5594 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5595 | if(CPUID::SSE4_1) |
| 5596 | { |
| 5597 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5598 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5599 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5600 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5601 | pack->addArg(x.value); |
| 5602 | pack->addArg(y.value); |
| 5603 | ::basicBlock->appendInst(pack); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5604 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5605 | return RValue<UShort8>(V(result)); |
| 5606 | } |
| 5607 | else |
| 5608 | { |
| 5609 | RValue<Int4> sx = As<Int4>(x); |
| 5610 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 5611 | |
| 5612 | RValue<Int4> sy = As<Int4>(y); |
| 5613 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 5614 | |
| 5615 | return As<UShort8>(Pack(bx, by) + Short8(0x8000u)); |
| 5616 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | Type *UInt4::getType() |
| 5620 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5621 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | Float::Float(RValue<Int> cast) |
| 5625 | { |
| 5626 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5627 | |
| 5628 | storeValue(integer); |
| 5629 | } |
| 5630 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5631 | Float::Float(float x) |
| 5632 | { |
| 5633 | storeValue(Nucleus::createConstantFloat(x)); |
| 5634 | } |
| 5635 | |
| 5636 | Float::Float(RValue<Float> rhs) |
| 5637 | { |
| 5638 | storeValue(rhs.value); |
| 5639 | } |
| 5640 | |
| 5641 | Float::Float(const Float &rhs) |
| 5642 | { |
| 5643 | Value *value = rhs.loadValue(); |
| 5644 | storeValue(value); |
| 5645 | } |
| 5646 | |
| 5647 | Float::Float(const Reference<Float> &rhs) |
| 5648 | { |
| 5649 | Value *value = rhs.loadValue(); |
| 5650 | storeValue(value); |
| 5651 | } |
| 5652 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5653 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5654 | { |
| 5655 | storeValue(rhs.value); |
| 5656 | |
| 5657 | return rhs; |
| 5658 | } |
| 5659 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5660 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5661 | { |
| 5662 | Value *value = rhs.loadValue(); |
| 5663 | storeValue(value); |
| 5664 | |
| 5665 | return RValue<Float>(value); |
| 5666 | } |
| 5667 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5668 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5669 | { |
| 5670 | Value *value = rhs.loadValue(); |
| 5671 | storeValue(value); |
| 5672 | |
| 5673 | return RValue<Float>(value); |
| 5674 | } |
| 5675 | |
| 5676 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5677 | { |
| 5678 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5679 | } |
| 5680 | |
| 5681 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5682 | { |
| 5683 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5684 | } |
| 5685 | |
| 5686 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5687 | { |
| 5688 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5689 | } |
| 5690 | |
| 5691 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5692 | { |
| 5693 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5694 | } |
| 5695 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5696 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5697 | { |
| 5698 | return lhs = lhs + rhs; |
| 5699 | } |
| 5700 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5701 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5702 | { |
| 5703 | return lhs = lhs - rhs; |
| 5704 | } |
| 5705 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5706 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5707 | { |
| 5708 | return lhs = lhs * rhs; |
| 5709 | } |
| 5710 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5711 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5712 | { |
| 5713 | return lhs = lhs / rhs; |
| 5714 | } |
| 5715 | |
| 5716 | RValue<Float> operator+(RValue<Float> val) |
| 5717 | { |
| 5718 | return val; |
| 5719 | } |
| 5720 | |
| 5721 | RValue<Float> operator-(RValue<Float> val) |
| 5722 | { |
| 5723 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5724 | } |
| 5725 | |
| 5726 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5727 | { |
| 5728 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5729 | } |
| 5730 | |
| 5731 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5732 | { |
| 5733 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5734 | } |
| 5735 | |
| 5736 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5737 | { |
| 5738 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5739 | } |
| 5740 | |
| 5741 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5742 | { |
| 5743 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5744 | } |
| 5745 | |
| 5746 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5747 | { |
| 5748 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5749 | } |
| 5750 | |
| 5751 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5752 | { |
| 5753 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5754 | } |
| 5755 | |
| 5756 | RValue<Float> Abs(RValue<Float> x) |
| 5757 | { |
| 5758 | return IfThenElse(x > 0.0f, x, -x); |
| 5759 | } |
| 5760 | |
| 5761 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5762 | { |
| 5763 | return IfThenElse(x > y, x, y); |
| 5764 | } |
| 5765 | |
| 5766 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5767 | { |
| 5768 | return IfThenElse(x < y, x, y); |
| 5769 | } |
| 5770 | |
| 5771 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5772 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5773 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5777 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5778 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | RValue<Float> Sqrt(RValue<Float> x) |
| 5782 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5783 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5784 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5785 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5786 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5787 | sqrt->addArg(x.value); |
| 5788 | ::basicBlock->appendInst(sqrt); |
| 5789 | |
| 5790 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | RValue<Float> Round(RValue<Float> x) |
| 5794 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5795 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | RValue<Float> Trunc(RValue<Float> x) |
| 5799 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5800 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | RValue<Float> Frac(RValue<Float> x) |
| 5804 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5805 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | RValue<Float> Floor(RValue<Float> x) |
| 5809 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5810 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | RValue<Float> Ceil(RValue<Float> x) |
| 5814 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5815 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | Type *Float::getType() |
| 5819 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5820 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5821 | } |
| 5822 | |
| 5823 | Float2::Float2(RValue<Float4> cast) |
| 5824 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5825 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | Type *Float2::getType() |
| 5829 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5830 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5831 | } |
| 5832 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5833 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5834 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5835 | Value *a = Int4(cast).loadValue(); |
| 5836 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5837 | |
| 5838 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5839 | } |
| 5840 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5841 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5842 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5843 | Value *a = Int4(cast).loadValue(); |
| 5844 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5845 | |
| 5846 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5847 | } |
| 5848 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5849 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5850 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5851 | Int4 c(cast); |
| 5852 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5853 | } |
| 5854 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5855 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5856 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5857 | Int4 c(cast); |
| 5858 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5859 | } |
| 5860 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5861 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5862 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5863 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5864 | |
| 5865 | storeValue(xyzw); |
| 5866 | } |
| 5867 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5868 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5869 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5870 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5871 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5872 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5873 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5874 | } |
| 5875 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5876 | Float4::Float4() : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5877 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5878 | } |
| 5879 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5880 | Float4::Float4(float xyzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5881 | { |
| 5882 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5883 | } |
| 5884 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5885 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5886 | { |
| 5887 | constant(x, yzw, yzw, yzw); |
| 5888 | } |
| 5889 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5890 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5891 | { |
| 5892 | constant(x, y, zw, zw); |
| 5893 | } |
| 5894 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5895 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5896 | { |
| 5897 | constant(x, y, z, w); |
| 5898 | } |
| 5899 | |
| 5900 | void Float4::constant(float x, float y, float z, float w) |
| 5901 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5902 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5903 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5904 | } |
| 5905 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5906 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5907 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5908 | storeValue(rhs.value); |
| 5909 | } |
| 5910 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5911 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5912 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5913 | Value *value = rhs.loadValue(); |
| 5914 | storeValue(value); |
| 5915 | } |
| 5916 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5917 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5918 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5919 | Value *value = rhs.loadValue(); |
| 5920 | storeValue(value); |
| 5921 | } |
| 5922 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5923 | Float4::Float4(RValue<Float> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5924 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5925 | Value *vector = loadValue(); |
| 5926 | Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0); |
| 5927 | |
| 5928 | int swizzle[4] = {0, 0, 0, 0}; |
| 5929 | Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle); |
| 5930 | |
| 5931 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5932 | } |
| 5933 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5934 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5935 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5936 | *this = RValue<Float>(rhs.loadValue()); |
| 5937 | } |
| 5938 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5939 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5940 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5941 | *this = RValue<Float>(rhs.loadValue()); |
| 5942 | } |
| 5943 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5944 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5945 | { |
| 5946 | return *this = Float4(x, x, x, x); |
| 5947 | } |
| 5948 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5949 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5950 | { |
| 5951 | storeValue(rhs.value); |
| 5952 | |
| 5953 | return rhs; |
| 5954 | } |
| 5955 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5956 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5957 | { |
| 5958 | Value *value = rhs.loadValue(); |
| 5959 | storeValue(value); |
| 5960 | |
| 5961 | return RValue<Float4>(value); |
| 5962 | } |
| 5963 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5964 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5965 | { |
| 5966 | Value *value = rhs.loadValue(); |
| 5967 | storeValue(value); |
| 5968 | |
| 5969 | return RValue<Float4>(value); |
| 5970 | } |
| 5971 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5972 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5973 | { |
| 5974 | return *this = Float4(rhs); |
| 5975 | } |
| 5976 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5977 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5978 | { |
| 5979 | return *this = Float4(rhs); |
| 5980 | } |
| 5981 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5982 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5983 | { |
| 5984 | return *this = Float4(rhs); |
| 5985 | } |
| 5986 | |
| 5987 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 5988 | { |
| 5989 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5990 | } |
| 5991 | |
| 5992 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 5993 | { |
| 5994 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5995 | } |
| 5996 | |
| 5997 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 5998 | { |
| 5999 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6000 | } |
| 6001 | |
| 6002 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6003 | { |
| 6004 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6005 | } |
| 6006 | |
| 6007 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6008 | { |
| 6009 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6010 | } |
| 6011 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6012 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6013 | { |
| 6014 | return lhs = lhs + rhs; |
| 6015 | } |
| 6016 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6017 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6018 | { |
| 6019 | return lhs = lhs - rhs; |
| 6020 | } |
| 6021 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6022 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6023 | { |
| 6024 | return lhs = lhs * rhs; |
| 6025 | } |
| 6026 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6027 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6028 | { |
| 6029 | return lhs = lhs / rhs; |
| 6030 | } |
| 6031 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6032 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6033 | { |
| 6034 | return lhs = lhs % rhs; |
| 6035 | } |
| 6036 | |
| 6037 | RValue<Float4> operator+(RValue<Float4> val) |
| 6038 | { |
| 6039 | return val; |
| 6040 | } |
| 6041 | |
| 6042 | RValue<Float4> operator-(RValue<Float4> val) |
| 6043 | { |
| 6044 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6045 | } |
| 6046 | |
| 6047 | RValue<Float4> Abs(RValue<Float4> x) |
| 6048 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6049 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6050 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6051 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6052 | |
| 6053 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6057 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6058 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6059 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value); |
| 6060 | ::basicBlock->appendInst(cmp); |
| 6061 | |
| 6062 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6063 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6064 | ::basicBlock->appendInst(select); |
| 6065 | |
| 6066 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6070 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6071 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6072 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value); |
| 6073 | ::basicBlock->appendInst(cmp); |
| 6074 | |
| 6075 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6076 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6077 | ::basicBlock->appendInst(select); |
| 6078 | |
| 6079 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6083 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6084 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6088 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6089 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6090 | } |
| 6091 | |
| 6092 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6093 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6094 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6095 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6096 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6097 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6098 | sqrt->addArg(x.value); |
| 6099 | ::basicBlock->appendInst(sqrt); |
| 6100 | |
| 6101 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6102 | } |
| 6103 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6104 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6105 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6106 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6110 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6111 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6115 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6116 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6117 | } |
| 6118 | |
| 6119 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6120 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6121 | int shuffle[4] = |
| 6122 | { |
| 6123 | ((imm >> 0) & 0x03) + 0, |
| 6124 | ((imm >> 2) & 0x03) + 0, |
| 6125 | ((imm >> 4) & 0x03) + 4, |
| 6126 | ((imm >> 6) & 0x03) + 4, |
| 6127 | }; |
| 6128 | |
| 6129 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6133 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6134 | int shuffle[4] = {0, 4, 1, 5}; |
| 6135 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6139 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6140 | int shuffle[4] = {2, 6, 3, 7}; |
| 6141 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6145 | { |
| 6146 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6147 | Value *result = createMask4(vector, rhs.value, select); |
| 6148 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6149 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6150 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | RValue<Int> SignMask(RValue<Float4> x) |
| 6154 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6155 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6156 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6157 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6158 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6159 | movmsk->addArg(x.value); |
| 6160 | ::basicBlock->appendInst(movmsk); |
| 6161 | |
| 6162 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6166 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6167 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6171 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6172 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6176 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6177 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6181 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6182 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6183 | } |
| 6184 | |
| 6185 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6186 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6187 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6191 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6192 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | RValue<Float4> Round(RValue<Float4> x) |
| 6196 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6197 | if(CPUID::SSE4_1) |
| 6198 | { |
| 6199 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6200 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6201 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6202 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6203 | round->addArg(x.value); |
| 6204 | round->addArg(::context->getConstantInt32(0)); |
| 6205 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6206 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6207 | return RValue<Float4>(V(result)); |
| 6208 | } |
| 6209 | else |
| 6210 | { |
| 6211 | return Float4(RoundInt(x)); |
| 6212 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6216 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6217 | if(CPUID::SSE4_1) |
| 6218 | { |
| 6219 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6220 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6221 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6222 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6223 | round->addArg(x.value); |
| 6224 | round->addArg(::context->getConstantInt32(3)); |
| 6225 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6226 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6227 | return RValue<Float4>(V(result)); |
| 6228 | } |
| 6229 | else |
| 6230 | { |
| 6231 | return Float4(Int4(x)); |
| 6232 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | RValue<Float4> Frac(RValue<Float4> x) |
| 6236 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6237 | if(CPUID::SSE4_1) |
| 6238 | { |
| 6239 | return x - Floor(x); |
| 6240 | } |
| 6241 | else |
| 6242 | { |
| 6243 | Float4 frc = x - Float4(Int4(x)); // Signed fractional part |
| 6244 | |
| 6245 | return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); |
| 6246 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6247 | } |
| 6248 | |
| 6249 | RValue<Float4> Floor(RValue<Float4> x) |
| 6250 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6251 | if(CPUID::SSE4_1) |
| 6252 | { |
| 6253 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6254 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6255 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6256 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6257 | round->addArg(x.value); |
| 6258 | round->addArg(::context->getConstantInt32(1)); |
| 6259 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6260 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6261 | return RValue<Float4>(V(result)); |
| 6262 | } |
| 6263 | else |
| 6264 | { |
| 6265 | return x - Frac(x); |
| 6266 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6270 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6271 | if(CPUID::SSE4_1) |
| 6272 | { |
| 6273 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6274 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6275 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6276 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6277 | round->addArg(x.value); |
| 6278 | round->addArg(::context->getConstantInt32(2)); |
| 6279 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6280 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6281 | return RValue<Float4>(V(result)); |
| 6282 | } |
| 6283 | else |
| 6284 | { |
| 6285 | return -Floor(-x); |
| 6286 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | Type *Float4::getType() |
| 6290 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6291 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6295 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6296 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6300 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6301 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6305 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 6306 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6307 | } |
| 6308 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6309 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6310 | { |
| 6311 | return lhs = lhs + offset; |
| 6312 | } |
| 6313 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6314 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6315 | { |
| 6316 | return lhs = lhs + offset; |
| 6317 | } |
| 6318 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6319 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6320 | { |
| 6321 | return lhs = lhs + offset; |
| 6322 | } |
| 6323 | |
| 6324 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6325 | { |
| 6326 | return lhs + -offset; |
| 6327 | } |
| 6328 | |
| 6329 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6330 | { |
| 6331 | return lhs + -offset; |
| 6332 | } |
| 6333 | |
| 6334 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6335 | { |
| 6336 | return lhs + -offset; |
| 6337 | } |
| 6338 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6339 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6340 | { |
| 6341 | return lhs = lhs - offset; |
| 6342 | } |
| 6343 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6344 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6345 | { |
| 6346 | return lhs = lhs - offset; |
| 6347 | } |
| 6348 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6349 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6350 | { |
| 6351 | return lhs = lhs - offset; |
| 6352 | } |
| 6353 | |
| 6354 | void Return() |
| 6355 | { |
| 6356 | Nucleus::createRetVoid(); |
| 6357 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6358 | Nucleus::createUnreachable(); |
| 6359 | } |
| 6360 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6361 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6362 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6363 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6364 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6365 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6366 | } |
| 6367 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6368 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
| 6369 | { |
| 6370 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6371 | Nucleus::setInsertBlock(bodyBB); |
| 6372 | |
| 6373 | return true; |
| 6374 | } |
| 6375 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6376 | RValue<Long> Ticks() |
| 6377 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6378 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6379 | } |
| 6380 | } |