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 | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 43 | #if !defined(MAP_ANONYMOUS) |
| 44 | #define MAP_ANONYMOUS MAP_ANON |
Nicolas Capens | 8b27574 | 2017-01-20 17:11:41 -0500 | [diff] [blame] | 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 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame^] | 69 | #if !defined(__i386__) && defined(_M_IX86) |
| 70 | #define __i386__ 1 |
| 71 | #endif |
| 72 | |
| 73 | #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) |
| 74 | #define __x86_64__ 1 |
| 75 | #endif |
| 76 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 77 | class CPUID |
| 78 | { |
| 79 | public: |
| 80 | const static bool SSE4_1; |
| 81 | |
| 82 | private: |
| 83 | static void cpuid(int registers[4], int info) |
| 84 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame^] | 85 | #if defined(__i386__) || defined(__x86_64__) |
| 86 | #if defined(_WIN32) |
| 87 | __cpuid(registers, info); |
| 88 | #else |
| 89 | __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); |
| 90 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 91 | #else |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame^] | 92 | registers[0] = 0; |
| 93 | registers[1] = 0; |
| 94 | registers[2] = 0; |
| 95 | registers[3] = 0; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 96 | #endif |
| 97 | } |
| 98 | |
| 99 | static bool detectSSE4_1() |
| 100 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame^] | 101 | #if defined(__i386__) || defined(__x86_64__) |
| 102 | int registers[4]; |
| 103 | cpuid(registers, 1); |
| 104 | return (registers[2] & 0x00080000) != 0; |
| 105 | #else |
| 106 | return false; |
| 107 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 108 | } |
| 109 | }; |
| 110 | |
| 111 | const bool CPUID::SSE4_1 = CPUID::detectSSE4_1(); |
| 112 | } |
| 113 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 114 | namespace sw |
| 115 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 116 | enum EmulatedType |
| 117 | { |
| 118 | EmulatedShift = 16, |
| 119 | EmulatedV2 = 2 << EmulatedShift, |
| 120 | EmulatedV4 = 4 << EmulatedShift, |
| 121 | EmulatedV8 = 8 << EmulatedShift, |
| 122 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 123 | |
| 124 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 125 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 126 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 127 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 128 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 129 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 130 | }; |
| 131 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 132 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 133 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 134 | class BasicBlock : public Ice::CfgNode {}; |
| 135 | |
| 136 | Ice::Type T(Type *t) |
| 137 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 138 | 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] | 139 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | Type *T(Ice::Type t) |
| 143 | { |
| 144 | return reinterpret_cast<Type*>(t); |
| 145 | } |
| 146 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 147 | Type *T(EmulatedType t) |
| 148 | { |
| 149 | return reinterpret_cast<Type*>(t); |
| 150 | } |
| 151 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 152 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 153 | { |
| 154 | return reinterpret_cast<Value*>(v); |
| 155 | } |
| 156 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 157 | BasicBlock *B(Ice::CfgNode *b) |
| 158 | { |
| 159 | return reinterpret_cast<BasicBlock*>(b); |
| 160 | } |
| 161 | |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 162 | static size_t typeSize(Type *type) |
| 163 | { |
| 164 | if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) |
| 165 | { |
| 166 | switch(reinterpret_cast<std::intptr_t>(type)) |
| 167 | { |
| 168 | case Type_v2i32: return 8; |
| 169 | case Type_v4i16: return 8; |
| 170 | case Type_v2i16: return 4; |
| 171 | case Type_v8i8: return 8; |
| 172 | case Type_v4i8: return 4; |
| 173 | case Type_v2f32: return 8; |
| 174 | default: assert(false); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | return Ice::typeWidthInBytes(T(type)); |
| 179 | } |
| 180 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 181 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 182 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 183 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 184 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 185 | |
| 186 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 187 | { |
| 188 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 189 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 190 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 191 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 192 | { |
| 193 | return §ionHeader(elfHeader)[index]; |
| 194 | } |
| 195 | |
| 196 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 197 | { |
| 198 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 199 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 200 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 201 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 202 | uint32_t index = relocation.getSymbol(); |
| 203 | int table = relocationTable.sh_link; |
| 204 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 205 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 206 | if(index != SHN_UNDEF) |
| 207 | { |
| 208 | if(table == SHN_UNDEF) return nullptr; |
| 209 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 210 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 211 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 212 | if(index >= symtab_entries) |
| 213 | { |
| 214 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 215 | return nullptr; |
| 216 | } |
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 symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 219 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 220 | uint16_t section = symbol.st_shndx; |
| 221 | |
| 222 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 223 | { |
| 224 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 225 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | return nullptr; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | switch(relocation.getType()) |
| 234 | { |
| 235 | case R_386_NONE: |
| 236 | // No relocation |
| 237 | break; |
| 238 | case R_386_32: |
| 239 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 240 | break; |
| 241 | // case R_386_PC32: |
| 242 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 243 | // break; |
| 244 | default: |
| 245 | assert(false && "Unsupported relocation type"); |
| 246 | return nullptr; |
| 247 | } |
| 248 | |
| 249 | return symbolValue; |
| 250 | } |
| 251 | |
| 252 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 253 | { |
| 254 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 255 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 256 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 257 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 258 | uint32_t index = relocation.getSymbol(); |
| 259 | int table = relocationTable.sh_link; |
| 260 | void *symbolValue = nullptr; |
| 261 | |
| 262 | if(index != SHN_UNDEF) |
| 263 | { |
| 264 | if(table == SHN_UNDEF) return nullptr; |
| 265 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 266 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 267 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 268 | if(index >= symtab_entries) |
| 269 | { |
| 270 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 271 | return nullptr; |
| 272 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 273 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 274 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 275 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 276 | uint16_t section = symbol.st_shndx; |
| 277 | |
| 278 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 279 | { |
| 280 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 281 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | return nullptr; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | switch(relocation.getType()) |
| 290 | { |
| 291 | case R_X86_64_NONE: |
| 292 | // No relocation |
| 293 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 294 | case R_X86_64_64: |
| 295 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 296 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 297 | case R_X86_64_PC32: |
| 298 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 299 | break; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 300 | case R_X86_64_32S: |
| 301 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 302 | break; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 303 | default: |
| 304 | assert(false && "Unsupported relocation type"); |
| 305 | return nullptr; |
| 306 | } |
| 307 | |
| 308 | return symbolValue; |
| 309 | } |
| 310 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 311 | void *loadImage(uint8_t *const elfImage, size_t &codeSize) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 312 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 313 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 314 | |
| 315 | if(!elfHeader->checkMagic()) |
| 316 | { |
| 317 | return nullptr; |
| 318 | } |
| 319 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 320 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 321 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 322 | assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386); |
| 323 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 324 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 325 | void *entry = nullptr; |
| 326 | |
| 327 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 328 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 329 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 330 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 331 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 332 | { |
| 333 | entry = elfImage + sectionHeader[i].sh_offset; |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 334 | codeSize = sectionHeader[i].sh_size; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 338 | { |
| 339 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 340 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 341 | 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] | 342 | { |
| 343 | 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] | 344 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 348 | { |
| 349 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 350 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 351 | 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] | 352 | { |
| 353 | 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] | 354 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 355 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | return entry; |
| 360 | } |
| 361 | |
| 362 | template<typename T> |
| 363 | struct ExecutableAllocator |
| 364 | { |
| 365 | ExecutableAllocator() {}; |
| 366 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 367 | |
| 368 | using value_type = T; |
| 369 | using size_type = std::size_t; |
| 370 | |
| 371 | T *allocate(size_type n) |
| 372 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 373 | #if defined(_WIN32) |
| 374 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 375 | #else |
| 376 | return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 377 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void deallocate(T *p, size_type n) |
| 381 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 382 | #if defined(_WIN32) |
| 383 | VirtualFree(p, 0, MEM_RELEASE); |
| 384 | #else |
| 385 | munmap(p, sizeof(T) * n); |
| 386 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 387 | } |
| 388 | }; |
| 389 | |
| 390 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 391 | { |
| 392 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 393 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 394 | |
| 395 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 396 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 397 | { |
| 398 | position = 0; |
| 399 | buffer.reserve(0x1000); |
| 400 | } |
| 401 | |
| 402 | virtual ~ELFMemoryStreamer() |
| 403 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 404 | #if defined(_WIN32) |
| 405 | if(buffer.size() != 0) |
| 406 | { |
| 407 | DWORD exeProtection; |
| 408 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 409 | } |
| 410 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void write8(uint8_t Value) override |
| 414 | { |
| 415 | if(position == (uint64_t)buffer.size()) |
| 416 | { |
| 417 | buffer.push_back(Value); |
| 418 | position++; |
| 419 | } |
| 420 | else if(position < (uint64_t)buffer.size()) |
| 421 | { |
| 422 | buffer[position] = Value; |
| 423 | position++; |
| 424 | } |
| 425 | else assert(false && "UNIMPLEMENTED"); |
| 426 | } |
| 427 | |
| 428 | void writeBytes(llvm::StringRef Bytes) override |
| 429 | { |
| 430 | std::size_t oldSize = buffer.size(); |
| 431 | buffer.resize(oldSize + Bytes.size()); |
| 432 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 433 | position += Bytes.size(); |
| 434 | } |
| 435 | |
| 436 | uint64_t tell() const override { return position; } |
| 437 | |
| 438 | void seek(uint64_t Off) override { position = Off; } |
| 439 | |
| 440 | const void *getEntry() override |
| 441 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 442 | if(!entry) |
| 443 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 444 | #if defined(_WIN32) |
| 445 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection); |
| 446 | #else |
| 447 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_WRITE | PROT_EXEC); |
| 448 | #endif |
| 449 | |
| 450 | 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] | 451 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 452 | size_t codeSize = 0; |
| 453 | entry = loadImage(&buffer[0], codeSize); |
| 454 | |
| 455 | #if defined(_WIN32) |
| 456 | FlushInstructionCache(GetCurrentProcess(), NULL, 0); |
| 457 | #else |
| 458 | __builtin___clear_cache((char*)entry, (char*)entry + codeSize); |
| 459 | #endif |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 466 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 467 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 468 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 469 | |
| 470 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 471 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 472 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | Nucleus::Nucleus() |
| 476 | { |
| 477 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 478 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 479 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 480 | Ice::ClFlags::getParsedClFlags(Flags); |
| 481 | |
| 482 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 483 | Flags.setOutFileType(Ice::FT_Elf); |
| 484 | Flags.setOptLevel(Ice::Opt_2); |
| 485 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 486 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 487 | Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 488 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 489 | static llvm::raw_os_ostream cout(std::cout); |
| 490 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 491 | |
| 492 | if(false) // Write out to a file |
| 493 | { |
| 494 | std::error_code errorCode; |
| 495 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 496 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 497 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 498 | } |
| 499 | else |
| 500 | { |
| 501 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 502 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 503 | ::routine = elfMemory; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | Nucleus::~Nucleus() |
| 508 | { |
| 509 | delete ::allocator; |
| 510 | delete ::function; |
| 511 | delete ::context; |
| 512 | |
| 513 | delete ::elfFile; |
| 514 | delete ::out; |
| 515 | |
| 516 | ::codegenMutex.unlock(); |
| 517 | } |
| 518 | |
| 519 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 520 | { |
| 521 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 522 | { |
| 523 | createRetVoid(); |
| 524 | } |
| 525 | |
| 526 | std::wstring wideName(name); |
| 527 | std::string asciiName(wideName.begin(), wideName.end()); |
| 528 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 529 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 530 | optimize(); |
| 531 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 532 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 533 | assert(!::function->hasError()); |
| 534 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 535 | auto *globals = ::function->getGlobalInits().release(); |
| 536 | |
| 537 | if(globals && !globals->empty()) |
| 538 | { |
| 539 | ::context->getGlobals()->merge(globals); |
| 540 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 541 | |
| 542 | ::context->emitFileHeader(); |
| 543 | ::function->emitIAS(); |
| 544 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 545 | auto objectWriter = ::context->getObjectWriter(); |
| 546 | assembler->alignFunction(); |
| 547 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 548 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 549 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 550 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 551 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 552 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 553 | |
| 554 | return ::routine; |
| 555 | } |
| 556 | |
| 557 | void Nucleus::optimize() |
| 558 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 559 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 563 | { |
| 564 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 565 | int typeSize = Ice::typeWidthInBytes(type); |
| 566 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 567 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 568 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 569 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 570 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 571 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 572 | |
| 573 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | BasicBlock *Nucleus::createBasicBlock() |
| 577 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 578 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | BasicBlock *Nucleus::getInsertBlock() |
| 582 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 583 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 587 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 588 | // 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] | 589 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 592 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 593 | { |
| 594 | uint32_t sequenceNumber = 0; |
| 595 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 596 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 597 | |
| 598 | for(Type *type : Params) |
| 599 | { |
| 600 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 601 | ::function->addArg(arg); |
| 602 | } |
| 603 | |
| 604 | Ice::CfgNode *node = ::function->makeNode(); |
| 605 | ::function->setEntryNode(node); |
| 606 | ::basicBlock = node; |
| 607 | } |
| 608 | |
| 609 | Value *Nucleus::getArgument(unsigned int index) |
| 610 | { |
| 611 | return V(::function->getArgs()[index]); |
| 612 | } |
| 613 | |
| 614 | void Nucleus::createRetVoid() |
| 615 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 616 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 617 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void Nucleus::createRet(Value *v) |
| 621 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 622 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 623 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | void Nucleus::createBr(BasicBlock *dest) |
| 627 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 628 | auto br = Ice::InstBr::create(::function, dest); |
| 629 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 633 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 634 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 635 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 636 | } |
| 637 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 638 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 639 | { |
| 640 | switch(op) |
| 641 | { |
| 642 | case Ice::InstArithmetic::Add: |
| 643 | case Ice::InstArithmetic::Fadd: |
| 644 | case Ice::InstArithmetic::Mul: |
| 645 | case Ice::InstArithmetic::Fmul: |
| 646 | case Ice::InstArithmetic::And: |
| 647 | case Ice::InstArithmetic::Or: |
| 648 | case Ice::InstArithmetic::Xor: |
| 649 | return true; |
| 650 | default: |
| 651 | return false; |
| 652 | } |
| 653 | } |
| 654 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 655 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 656 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 657 | 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] | 658 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 659 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 660 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 661 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 662 | 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] | 663 | ::basicBlock->appendInst(arithmetic); |
| 664 | |
| 665 | return V(result); |
| 666 | } |
| 667 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 668 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 669 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 670 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 674 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 675 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 679 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 680 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 684 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 685 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 689 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 690 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 694 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 695 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 699 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 700 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 704 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 705 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 709 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 710 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 714 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 715 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 719 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 720 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 724 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 725 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 729 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 730 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 734 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 735 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 739 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 740 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 744 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 745 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 749 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 750 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 754 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 755 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | Value *Nucleus::createNeg(Value *v) |
| 759 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 760 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | Value *Nucleus::createFNeg(Value *v) |
| 764 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 765 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 766 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 767 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 768 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 769 | |
| 770 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | Value *Nucleus::createNot(Value *v) |
| 774 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 775 | if(Ice::isScalarIntegerType(v->getType())) |
| 776 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 777 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 778 | } |
| 779 | else // Vector |
| 780 | { |
| 781 | int64_t c[4] = {-1, -1, -1, -1}; |
| 782 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 783 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 784 | } |
| 785 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 786 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 787 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 788 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 789 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 790 | |
| 791 | if(valueType & EmulatedBits) |
| 792 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 793 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 794 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 795 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 796 | load->addArg(ptr); |
| 797 | load->addArg(::context->getConstantInt32(typeSize(type))); |
| 798 | ::basicBlock->appendInst(load); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 799 | } |
| 800 | else |
| 801 | { |
| 802 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 803 | ::basicBlock->appendInst(load); |
| 804 | } |
| 805 | |
| 806 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 807 | } |
| 808 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 809 | 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] | 810 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 811 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 812 | |
| 813 | if(valueType & EmulatedBits) |
| 814 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 815 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 816 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 817 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
| 818 | store->addArg(value); |
| 819 | store->addArg(ptr); |
| 820 | store->addArg(::context->getConstantInt32(typeSize(type))); |
| 821 | ::basicBlock->appendInst(store); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 822 | } |
| 823 | else |
| 824 | { |
| 825 | assert(T(value->getType()) == type); |
| 826 | |
| 827 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 828 | ::basicBlock->appendInst(store); |
| 829 | } |
| 830 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 831 | return value; |
| 832 | } |
| 833 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 834 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 835 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 836 | assert(index->getType() == Ice::IceType_i32); |
| 837 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 838 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 839 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 840 | int32_t offset = constant->getValue() * (int)typeSize(type); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 841 | |
| 842 | if(offset == 0) |
| 843 | { |
| 844 | return ptr; |
| 845 | } |
| 846 | |
| 847 | return createAdd(ptr, createConstantInt(offset)); |
| 848 | } |
| 849 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 850 | if(!Ice::isByteSizedType(T(type))) |
| 851 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 852 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | if(sizeof(void*) == 8) |
| 856 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 857 | if(unsignedIndex) |
| 858 | { |
| 859 | index = createZExt(index, T(Ice::IceType_i64)); |
| 860 | } |
| 861 | else |
| 862 | { |
| 863 | index = createSExt(index, T(Ice::IceType_i64)); |
| 864 | } |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 871 | { |
| 872 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 873 | } |
| 874 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 875 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 876 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 877 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 878 | { |
| 879 | return v; |
| 880 | } |
| 881 | |
| 882 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 883 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 884 | ::basicBlock->appendInst(cast); |
| 885 | |
| 886 | return V(result); |
| 887 | } |
| 888 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 889 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 890 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 891 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 895 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 896 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 900 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 901 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 905 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 906 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 907 | } |
| 908 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 909 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 910 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 911 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 915 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 916 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 920 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 921 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 925 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 926 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 929 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 930 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 931 | assert(lhs->getType() == rhs->getType()); |
| 932 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 933 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 934 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 935 | ::basicBlock->appendInst(cmp); |
| 936 | |
| 937 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 938 | } |
| 939 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 940 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 941 | { |
| 942 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 943 | } |
| 944 | |
| 945 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 946 | { |
| 947 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 948 | } |
| 949 | |
| 950 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 951 | { |
| 952 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 953 | } |
| 954 | |
| 955 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 956 | { |
| 957 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 958 | } |
| 959 | |
| 960 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 961 | { |
| 962 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 963 | } |
| 964 | |
| 965 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 966 | { |
| 967 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 968 | } |
| 969 | |
| 970 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 971 | { |
| 972 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 973 | } |
| 974 | |
| 975 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 976 | { |
| 977 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 978 | } |
| 979 | |
| 980 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 981 | { |
| 982 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 983 | } |
| 984 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 985 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 986 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 987 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 988 | } |
| 989 | |
| 990 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 991 | { |
| 992 | assert(lhs->getType() == rhs->getType()); |
| 993 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 994 | |
| 995 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 996 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 997 | ::basicBlock->appendInst(cmp); |
| 998 | |
| 999 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 1003 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1004 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1008 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1009 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1013 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1014 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1018 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1019 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1023 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1024 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1028 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1029 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1033 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1034 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1038 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1039 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1043 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1044 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1048 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1049 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1053 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1054 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1058 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1059 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1063 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1064 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1068 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1069 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1072 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1073 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1074 | auto result = ::function->makeVariable(T(type)); |
| 1075 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1076 | ::basicBlock->appendInst(extract); |
| 1077 | |
| 1078 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1082 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1083 | auto result = ::function->makeVariable(vector->getType()); |
| 1084 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1085 | ::basicBlock->appendInst(insert); |
| 1086 | |
| 1087 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1088 | } |
| 1089 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1090 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1091 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1092 | assert(V1->getType() == V2->getType()); |
| 1093 | |
| 1094 | int size = Ice::typeNumElements(V1->getType()); |
| 1095 | auto result = ::function->makeVariable(V1->getType()); |
| 1096 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1097 | |
| 1098 | for(int i = 0; i < size; i++) |
| 1099 | { |
| 1100 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1101 | } |
| 1102 | |
| 1103 | ::basicBlock->appendInst(shuffle); |
| 1104 | |
| 1105 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1109 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1110 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1111 | |
| 1112 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1113 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1114 | ::basicBlock->appendInst(select); |
| 1115 | |
| 1116 | return V(result); |
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 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
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 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1122 | ::basicBlock->appendInst(switchInst); |
| 1123 | |
| 1124 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1127 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1128 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1129 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | void Nucleus::createUnreachable() |
| 1133 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1134 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1135 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1138 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1139 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1140 | int swizzle[4] = |
| 1141 | { |
| 1142 | (select >> 0) & 0x03, |
| 1143 | (select >> 2) & 0x03, |
| 1144 | (select >> 4) & 0x03, |
| 1145 | (select >> 6) & 0x03, |
| 1146 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1147 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1148 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1151 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1152 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1153 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1154 | |
| 1155 | mask[(select >> 0) & 0x03] = -1; |
| 1156 | mask[(select >> 2) & 0x03] = -1; |
| 1157 | mask[(select >> 4) & 0x03] = -1; |
| 1158 | mask[(select >> 6) & 0x03] = -1; |
| 1159 | |
| 1160 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1161 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1162 | |
| 1163 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1166 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1167 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1168 | if(sizeof(void*) == 8) |
| 1169 | { |
| 1170 | return T(Ice::IceType_i64); |
| 1171 | } |
| 1172 | else |
| 1173 | { |
| 1174 | return T(Ice::IceType_i32); |
| 1175 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1178 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1179 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1180 | if(Ice::isVectorType(T(Ty))) |
| 1181 | { |
Nicolas Capens | 30385f0 | 2017-04-18 13:03:47 -0400 | [diff] [blame] | 1182 | assert(Ice::typeNumElements(T(Ty)) <= 16); |
| 1183 | int64_t c[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1184 | return createConstantVector(c, Ty); |
| 1185 | } |
| 1186 | else |
| 1187 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1188 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1189 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1192 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1193 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1194 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1197 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1198 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1199 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1202 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1203 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1204 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1205 | } |
| 1206 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1207 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1208 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1209 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1212 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1213 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1214 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1215 | } |
| 1216 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1217 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1218 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1219 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1220 | } |
| 1221 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1222 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1223 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1224 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1225 | } |
| 1226 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1227 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1228 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1229 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1232 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1233 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1234 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1235 | } |
| 1236 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1237 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1238 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1239 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1240 | } |
| 1241 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1242 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1243 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1244 | const int vectorSize = 16; |
| 1245 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1246 | const int alignment = vectorSize; |
| 1247 | auto globalPool = ::function->getGlobalPool(); |
| 1248 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1249 | const int64_t *i = constants; |
| 1250 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1251 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1252 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1253 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1254 | { |
| 1255 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1256 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1257 | { |
| 1258 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1259 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1260 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1261 | } |
| 1262 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1263 | case Ice::IceType_v4f32: |
| 1264 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1265 | 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] | 1266 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1267 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1268 | } |
| 1269 | break; |
| 1270 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1271 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1272 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1273 | 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] | 1274 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1275 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1276 | } |
| 1277 | break; |
| 1278 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1279 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1280 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1281 | 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] | 1282 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1283 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1284 | } |
| 1285 | break; |
| 1286 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1287 | { |
| 1288 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1289 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1290 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1291 | } |
| 1292 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1293 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1294 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1295 | 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] | 1296 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1297 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1298 | } |
| 1299 | break; |
| 1300 | case Type_v4i16: |
| 1301 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1302 | 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] | 1303 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1304 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1305 | } |
| 1306 | break; |
| 1307 | case Type_v8i8: |
| 1308 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1309 | 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] | 1310 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1311 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1312 | } |
| 1313 | break; |
| 1314 | case Type_v4i8: |
| 1315 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1316 | 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] | 1317 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1318 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1319 | } |
| 1320 | break; |
| 1321 | default: |
| 1322 | assert(false && "Unknown constant vector type" && type); |
| 1323 | } |
| 1324 | |
| 1325 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1326 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1327 | variableDeclaration->setName(name); |
| 1328 | variableDeclaration->setAlignment(alignment); |
| 1329 | variableDeclaration->setIsConstant(true); |
| 1330 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1331 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1332 | ::function->addGlobal(variableDeclaration); |
| 1333 | |
| 1334 | constexpr int32_t offset = 0; |
| 1335 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1336 | |
| 1337 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1338 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1339 | ::basicBlock->appendInst(load); |
| 1340 | |
| 1341 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1345 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1346 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | Type *Void::getType() |
| 1350 | { |
| 1351 | return T(Ice::IceType_void); |
| 1352 | } |
| 1353 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1354 | Bool::Bool(Argument<Bool> argument) |
| 1355 | { |
| 1356 | storeValue(argument.value); |
| 1357 | } |
| 1358 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1359 | Bool::Bool(bool x) |
| 1360 | { |
| 1361 | storeValue(Nucleus::createConstantBool(x)); |
| 1362 | } |
| 1363 | |
| 1364 | Bool::Bool(RValue<Bool> rhs) |
| 1365 | { |
| 1366 | storeValue(rhs.value); |
| 1367 | } |
| 1368 | |
| 1369 | Bool::Bool(const Bool &rhs) |
| 1370 | { |
| 1371 | Value *value = rhs.loadValue(); |
| 1372 | storeValue(value); |
| 1373 | } |
| 1374 | |
| 1375 | Bool::Bool(const Reference<Bool> &rhs) |
| 1376 | { |
| 1377 | Value *value = rhs.loadValue(); |
| 1378 | storeValue(value); |
| 1379 | } |
| 1380 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1381 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1382 | { |
| 1383 | storeValue(rhs.value); |
| 1384 | |
| 1385 | return rhs; |
| 1386 | } |
| 1387 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1388 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1389 | { |
| 1390 | Value *value = rhs.loadValue(); |
| 1391 | storeValue(value); |
| 1392 | |
| 1393 | return RValue<Bool>(value); |
| 1394 | } |
| 1395 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1396 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1397 | { |
| 1398 | Value *value = rhs.loadValue(); |
| 1399 | storeValue(value); |
| 1400 | |
| 1401 | return RValue<Bool>(value); |
| 1402 | } |
| 1403 | |
| 1404 | RValue<Bool> operator!(RValue<Bool> val) |
| 1405 | { |
| 1406 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1407 | } |
| 1408 | |
| 1409 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1410 | { |
| 1411 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1412 | } |
| 1413 | |
| 1414 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1415 | { |
| 1416 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1417 | } |
| 1418 | |
| 1419 | Type *Bool::getType() |
| 1420 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1421 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | Byte::Byte(Argument<Byte> argument) |
| 1425 | { |
| 1426 | storeValue(argument.value); |
| 1427 | } |
| 1428 | |
| 1429 | Byte::Byte(RValue<Int> cast) |
| 1430 | { |
| 1431 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1432 | |
| 1433 | storeValue(integer); |
| 1434 | } |
| 1435 | |
| 1436 | Byte::Byte(RValue<UInt> cast) |
| 1437 | { |
| 1438 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1439 | |
| 1440 | storeValue(integer); |
| 1441 | } |
| 1442 | |
| 1443 | Byte::Byte(RValue<UShort> cast) |
| 1444 | { |
| 1445 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1446 | |
| 1447 | storeValue(integer); |
| 1448 | } |
| 1449 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1450 | Byte::Byte(int x) |
| 1451 | { |
| 1452 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1453 | } |
| 1454 | |
| 1455 | Byte::Byte(unsigned char x) |
| 1456 | { |
| 1457 | storeValue(Nucleus::createConstantByte(x)); |
| 1458 | } |
| 1459 | |
| 1460 | Byte::Byte(RValue<Byte> rhs) |
| 1461 | { |
| 1462 | storeValue(rhs.value); |
| 1463 | } |
| 1464 | |
| 1465 | Byte::Byte(const Byte &rhs) |
| 1466 | { |
| 1467 | Value *value = rhs.loadValue(); |
| 1468 | storeValue(value); |
| 1469 | } |
| 1470 | |
| 1471 | Byte::Byte(const Reference<Byte> &rhs) |
| 1472 | { |
| 1473 | Value *value = rhs.loadValue(); |
| 1474 | storeValue(value); |
| 1475 | } |
| 1476 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1477 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1478 | { |
| 1479 | storeValue(rhs.value); |
| 1480 | |
| 1481 | return rhs; |
| 1482 | } |
| 1483 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1484 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1485 | { |
| 1486 | Value *value = rhs.loadValue(); |
| 1487 | storeValue(value); |
| 1488 | |
| 1489 | return RValue<Byte>(value); |
| 1490 | } |
| 1491 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1492 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1493 | { |
| 1494 | Value *value = rhs.loadValue(); |
| 1495 | storeValue(value); |
| 1496 | |
| 1497 | return RValue<Byte>(value); |
| 1498 | } |
| 1499 | |
| 1500 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1501 | { |
| 1502 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1503 | } |
| 1504 | |
| 1505 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1506 | { |
| 1507 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1508 | } |
| 1509 | |
| 1510 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1511 | { |
| 1512 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1513 | } |
| 1514 | |
| 1515 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1516 | { |
| 1517 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1518 | } |
| 1519 | |
| 1520 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1521 | { |
| 1522 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1523 | } |
| 1524 | |
| 1525 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1526 | { |
| 1527 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1528 | } |
| 1529 | |
| 1530 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1531 | { |
| 1532 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1533 | } |
| 1534 | |
| 1535 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1536 | { |
| 1537 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1538 | } |
| 1539 | |
| 1540 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1541 | { |
| 1542 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1543 | } |
| 1544 | |
| 1545 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1546 | { |
| 1547 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1548 | } |
| 1549 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1550 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1551 | { |
| 1552 | return lhs = lhs + rhs; |
| 1553 | } |
| 1554 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1555 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1556 | { |
| 1557 | return lhs = lhs - rhs; |
| 1558 | } |
| 1559 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1560 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1561 | { |
| 1562 | return lhs = lhs * rhs; |
| 1563 | } |
| 1564 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1565 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1566 | { |
| 1567 | return lhs = lhs / rhs; |
| 1568 | } |
| 1569 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1570 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1571 | { |
| 1572 | return lhs = lhs % rhs; |
| 1573 | } |
| 1574 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1575 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1576 | { |
| 1577 | return lhs = lhs & rhs; |
| 1578 | } |
| 1579 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1580 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1581 | { |
| 1582 | return lhs = lhs | rhs; |
| 1583 | } |
| 1584 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1585 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1586 | { |
| 1587 | return lhs = lhs ^ rhs; |
| 1588 | } |
| 1589 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1590 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1591 | { |
| 1592 | return lhs = lhs << rhs; |
| 1593 | } |
| 1594 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1595 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1596 | { |
| 1597 | return lhs = lhs >> rhs; |
| 1598 | } |
| 1599 | |
| 1600 | RValue<Byte> operator+(RValue<Byte> val) |
| 1601 | { |
| 1602 | return val; |
| 1603 | } |
| 1604 | |
| 1605 | RValue<Byte> operator-(RValue<Byte> val) |
| 1606 | { |
| 1607 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1608 | } |
| 1609 | |
| 1610 | RValue<Byte> operator~(RValue<Byte> val) |
| 1611 | { |
| 1612 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1613 | } |
| 1614 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1615 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1616 | { |
| 1617 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1618 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1619 | return res; |
| 1620 | } |
| 1621 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1622 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1623 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1624 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1625 | return val; |
| 1626 | } |
| 1627 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1628 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1629 | { |
| 1630 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1631 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1632 | return res; |
| 1633 | } |
| 1634 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1635 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1636 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1637 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1638 | return val; |
| 1639 | } |
| 1640 | |
| 1641 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1642 | { |
| 1643 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1644 | } |
| 1645 | |
| 1646 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1647 | { |
| 1648 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1649 | } |
| 1650 | |
| 1651 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1652 | { |
| 1653 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1654 | } |
| 1655 | |
| 1656 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1657 | { |
| 1658 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1659 | } |
| 1660 | |
| 1661 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1662 | { |
| 1663 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1664 | } |
| 1665 | |
| 1666 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1667 | { |
| 1668 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1669 | } |
| 1670 | |
| 1671 | Type *Byte::getType() |
| 1672 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1673 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | SByte::SByte(Argument<SByte> argument) |
| 1677 | { |
| 1678 | storeValue(argument.value); |
| 1679 | } |
| 1680 | |
| 1681 | SByte::SByte(RValue<Int> cast) |
| 1682 | { |
| 1683 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1684 | |
| 1685 | storeValue(integer); |
| 1686 | } |
| 1687 | |
| 1688 | SByte::SByte(RValue<Short> cast) |
| 1689 | { |
| 1690 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1691 | |
| 1692 | storeValue(integer); |
| 1693 | } |
| 1694 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1695 | SByte::SByte(signed char x) |
| 1696 | { |
| 1697 | storeValue(Nucleus::createConstantByte(x)); |
| 1698 | } |
| 1699 | |
| 1700 | SByte::SByte(RValue<SByte> rhs) |
| 1701 | { |
| 1702 | storeValue(rhs.value); |
| 1703 | } |
| 1704 | |
| 1705 | SByte::SByte(const SByte &rhs) |
| 1706 | { |
| 1707 | Value *value = rhs.loadValue(); |
| 1708 | storeValue(value); |
| 1709 | } |
| 1710 | |
| 1711 | SByte::SByte(const Reference<SByte> &rhs) |
| 1712 | { |
| 1713 | Value *value = rhs.loadValue(); |
| 1714 | storeValue(value); |
| 1715 | } |
| 1716 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1717 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1718 | { |
| 1719 | storeValue(rhs.value); |
| 1720 | |
| 1721 | return rhs; |
| 1722 | } |
| 1723 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1724 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1725 | { |
| 1726 | Value *value = rhs.loadValue(); |
| 1727 | storeValue(value); |
| 1728 | |
| 1729 | return RValue<SByte>(value); |
| 1730 | } |
| 1731 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1732 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1733 | { |
| 1734 | Value *value = rhs.loadValue(); |
| 1735 | storeValue(value); |
| 1736 | |
| 1737 | return RValue<SByte>(value); |
| 1738 | } |
| 1739 | |
| 1740 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1741 | { |
| 1742 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1743 | } |
| 1744 | |
| 1745 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1746 | { |
| 1747 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1748 | } |
| 1749 | |
| 1750 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1751 | { |
| 1752 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1753 | } |
| 1754 | |
| 1755 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1756 | { |
| 1757 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1758 | } |
| 1759 | |
| 1760 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1761 | { |
| 1762 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1763 | } |
| 1764 | |
| 1765 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1766 | { |
| 1767 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1768 | } |
| 1769 | |
| 1770 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1771 | { |
| 1772 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1773 | } |
| 1774 | |
| 1775 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1776 | { |
| 1777 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1778 | } |
| 1779 | |
| 1780 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1781 | { |
| 1782 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1783 | } |
| 1784 | |
| 1785 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1786 | { |
| 1787 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1788 | } |
| 1789 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1790 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1791 | { |
| 1792 | return lhs = lhs + rhs; |
| 1793 | } |
| 1794 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1795 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1796 | { |
| 1797 | return lhs = lhs - rhs; |
| 1798 | } |
| 1799 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1800 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1801 | { |
| 1802 | return lhs = lhs * rhs; |
| 1803 | } |
| 1804 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1805 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1806 | { |
| 1807 | return lhs = lhs / rhs; |
| 1808 | } |
| 1809 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1810 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1811 | { |
| 1812 | return lhs = lhs % rhs; |
| 1813 | } |
| 1814 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1815 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1816 | { |
| 1817 | return lhs = lhs & rhs; |
| 1818 | } |
| 1819 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1820 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1821 | { |
| 1822 | return lhs = lhs | rhs; |
| 1823 | } |
| 1824 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1825 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1826 | { |
| 1827 | return lhs = lhs ^ rhs; |
| 1828 | } |
| 1829 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1830 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1831 | { |
| 1832 | return lhs = lhs << rhs; |
| 1833 | } |
| 1834 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1835 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1836 | { |
| 1837 | return lhs = lhs >> rhs; |
| 1838 | } |
| 1839 | |
| 1840 | RValue<SByte> operator+(RValue<SByte> val) |
| 1841 | { |
| 1842 | return val; |
| 1843 | } |
| 1844 | |
| 1845 | RValue<SByte> operator-(RValue<SByte> val) |
| 1846 | { |
| 1847 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1848 | } |
| 1849 | |
| 1850 | RValue<SByte> operator~(RValue<SByte> val) |
| 1851 | { |
| 1852 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1853 | } |
| 1854 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1855 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1856 | { |
| 1857 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1858 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1859 | return res; |
| 1860 | } |
| 1861 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1862 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1863 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1864 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1865 | return val; |
| 1866 | } |
| 1867 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1868 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1869 | { |
| 1870 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1871 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1872 | return res; |
| 1873 | } |
| 1874 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1875 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1876 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1877 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1878 | return val; |
| 1879 | } |
| 1880 | |
| 1881 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1882 | { |
| 1883 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1884 | } |
| 1885 | |
| 1886 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1887 | { |
| 1888 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1889 | } |
| 1890 | |
| 1891 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1892 | { |
| 1893 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1894 | } |
| 1895 | |
| 1896 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1897 | { |
| 1898 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1899 | } |
| 1900 | |
| 1901 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1902 | { |
| 1903 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1904 | } |
| 1905 | |
| 1906 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1907 | { |
| 1908 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1909 | } |
| 1910 | |
| 1911 | Type *SByte::getType() |
| 1912 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1913 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | Short::Short(Argument<Short> argument) |
| 1917 | { |
| 1918 | storeValue(argument.value); |
| 1919 | } |
| 1920 | |
| 1921 | Short::Short(RValue<Int> cast) |
| 1922 | { |
| 1923 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1924 | |
| 1925 | storeValue(integer); |
| 1926 | } |
| 1927 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1928 | Short::Short(short x) |
| 1929 | { |
| 1930 | storeValue(Nucleus::createConstantShort(x)); |
| 1931 | } |
| 1932 | |
| 1933 | Short::Short(RValue<Short> rhs) |
| 1934 | { |
| 1935 | storeValue(rhs.value); |
| 1936 | } |
| 1937 | |
| 1938 | Short::Short(const Short &rhs) |
| 1939 | { |
| 1940 | Value *value = rhs.loadValue(); |
| 1941 | storeValue(value); |
| 1942 | } |
| 1943 | |
| 1944 | Short::Short(const Reference<Short> &rhs) |
| 1945 | { |
| 1946 | Value *value = rhs.loadValue(); |
| 1947 | storeValue(value); |
| 1948 | } |
| 1949 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1950 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1951 | { |
| 1952 | storeValue(rhs.value); |
| 1953 | |
| 1954 | return rhs; |
| 1955 | } |
| 1956 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1957 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1958 | { |
| 1959 | Value *value = rhs.loadValue(); |
| 1960 | storeValue(value); |
| 1961 | |
| 1962 | return RValue<Short>(value); |
| 1963 | } |
| 1964 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1965 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1966 | { |
| 1967 | Value *value = rhs.loadValue(); |
| 1968 | storeValue(value); |
| 1969 | |
| 1970 | return RValue<Short>(value); |
| 1971 | } |
| 1972 | |
| 1973 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 1974 | { |
| 1975 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1976 | } |
| 1977 | |
| 1978 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 1979 | { |
| 1980 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1981 | } |
| 1982 | |
| 1983 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 1984 | { |
| 1985 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1986 | } |
| 1987 | |
| 1988 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 1989 | { |
| 1990 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1991 | } |
| 1992 | |
| 1993 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 1994 | { |
| 1995 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1996 | } |
| 1997 | |
| 1998 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 1999 | { |
| 2000 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2001 | } |
| 2002 | |
| 2003 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 2004 | { |
| 2005 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2006 | } |
| 2007 | |
| 2008 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2009 | { |
| 2010 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2011 | } |
| 2012 | |
| 2013 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2014 | { |
| 2015 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2016 | } |
| 2017 | |
| 2018 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2019 | { |
| 2020 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2021 | } |
| 2022 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2023 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2024 | { |
| 2025 | return lhs = lhs + rhs; |
| 2026 | } |
| 2027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2028 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2029 | { |
| 2030 | return lhs = lhs - rhs; |
| 2031 | } |
| 2032 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2033 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2034 | { |
| 2035 | return lhs = lhs * rhs; |
| 2036 | } |
| 2037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2038 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2039 | { |
| 2040 | return lhs = lhs / rhs; |
| 2041 | } |
| 2042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2043 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2044 | { |
| 2045 | return lhs = lhs % rhs; |
| 2046 | } |
| 2047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2048 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2049 | { |
| 2050 | return lhs = lhs & rhs; |
| 2051 | } |
| 2052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2053 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2054 | { |
| 2055 | return lhs = lhs | rhs; |
| 2056 | } |
| 2057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2058 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2059 | { |
| 2060 | return lhs = lhs ^ rhs; |
| 2061 | } |
| 2062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2063 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2064 | { |
| 2065 | return lhs = lhs << rhs; |
| 2066 | } |
| 2067 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2068 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2069 | { |
| 2070 | return lhs = lhs >> rhs; |
| 2071 | } |
| 2072 | |
| 2073 | RValue<Short> operator+(RValue<Short> val) |
| 2074 | { |
| 2075 | return val; |
| 2076 | } |
| 2077 | |
| 2078 | RValue<Short> operator-(RValue<Short> val) |
| 2079 | { |
| 2080 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2081 | } |
| 2082 | |
| 2083 | RValue<Short> operator~(RValue<Short> val) |
| 2084 | { |
| 2085 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2086 | } |
| 2087 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2088 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2089 | { |
| 2090 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2091 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2092 | return res; |
| 2093 | } |
| 2094 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2095 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2096 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2097 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2098 | return val; |
| 2099 | } |
| 2100 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2101 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2102 | { |
| 2103 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2104 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2105 | return res; |
| 2106 | } |
| 2107 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2108 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2109 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2110 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2111 | return val; |
| 2112 | } |
| 2113 | |
| 2114 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2115 | { |
| 2116 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2117 | } |
| 2118 | |
| 2119 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2120 | { |
| 2121 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2122 | } |
| 2123 | |
| 2124 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2125 | { |
| 2126 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2127 | } |
| 2128 | |
| 2129 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2130 | { |
| 2131 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2132 | } |
| 2133 | |
| 2134 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2135 | { |
| 2136 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2137 | } |
| 2138 | |
| 2139 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2140 | { |
| 2141 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2142 | } |
| 2143 | |
| 2144 | Type *Short::getType() |
| 2145 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2146 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | UShort::UShort(Argument<UShort> argument) |
| 2150 | { |
| 2151 | storeValue(argument.value); |
| 2152 | } |
| 2153 | |
| 2154 | UShort::UShort(RValue<UInt> cast) |
| 2155 | { |
| 2156 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2157 | |
| 2158 | storeValue(integer); |
| 2159 | } |
| 2160 | |
| 2161 | UShort::UShort(RValue<Int> cast) |
| 2162 | { |
| 2163 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2164 | |
| 2165 | storeValue(integer); |
| 2166 | } |
| 2167 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2168 | UShort::UShort(unsigned short x) |
| 2169 | { |
| 2170 | storeValue(Nucleus::createConstantShort(x)); |
| 2171 | } |
| 2172 | |
| 2173 | UShort::UShort(RValue<UShort> rhs) |
| 2174 | { |
| 2175 | storeValue(rhs.value); |
| 2176 | } |
| 2177 | |
| 2178 | UShort::UShort(const UShort &rhs) |
| 2179 | { |
| 2180 | Value *value = rhs.loadValue(); |
| 2181 | storeValue(value); |
| 2182 | } |
| 2183 | |
| 2184 | UShort::UShort(const Reference<UShort> &rhs) |
| 2185 | { |
| 2186 | Value *value = rhs.loadValue(); |
| 2187 | storeValue(value); |
| 2188 | } |
| 2189 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2190 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2191 | { |
| 2192 | storeValue(rhs.value); |
| 2193 | |
| 2194 | return rhs; |
| 2195 | } |
| 2196 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2197 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2198 | { |
| 2199 | Value *value = rhs.loadValue(); |
| 2200 | storeValue(value); |
| 2201 | |
| 2202 | return RValue<UShort>(value); |
| 2203 | } |
| 2204 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2205 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2206 | { |
| 2207 | Value *value = rhs.loadValue(); |
| 2208 | storeValue(value); |
| 2209 | |
| 2210 | return RValue<UShort>(value); |
| 2211 | } |
| 2212 | |
| 2213 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2214 | { |
| 2215 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2216 | } |
| 2217 | |
| 2218 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2219 | { |
| 2220 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2221 | } |
| 2222 | |
| 2223 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2224 | { |
| 2225 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2226 | } |
| 2227 | |
| 2228 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2229 | { |
| 2230 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2231 | } |
| 2232 | |
| 2233 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2234 | { |
| 2235 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2236 | } |
| 2237 | |
| 2238 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2239 | { |
| 2240 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2241 | } |
| 2242 | |
| 2243 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2244 | { |
| 2245 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2246 | } |
| 2247 | |
| 2248 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2249 | { |
| 2250 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2251 | } |
| 2252 | |
| 2253 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2254 | { |
| 2255 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2256 | } |
| 2257 | |
| 2258 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2259 | { |
| 2260 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2261 | } |
| 2262 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2263 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2264 | { |
| 2265 | return lhs = lhs + rhs; |
| 2266 | } |
| 2267 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2268 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2269 | { |
| 2270 | return lhs = lhs - rhs; |
| 2271 | } |
| 2272 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2273 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2274 | { |
| 2275 | return lhs = lhs * rhs; |
| 2276 | } |
| 2277 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2278 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2279 | { |
| 2280 | return lhs = lhs / rhs; |
| 2281 | } |
| 2282 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2283 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2284 | { |
| 2285 | return lhs = lhs % rhs; |
| 2286 | } |
| 2287 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2288 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2289 | { |
| 2290 | return lhs = lhs & rhs; |
| 2291 | } |
| 2292 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2293 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2294 | { |
| 2295 | return lhs = lhs | rhs; |
| 2296 | } |
| 2297 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2298 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2299 | { |
| 2300 | return lhs = lhs ^ rhs; |
| 2301 | } |
| 2302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2303 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2304 | { |
| 2305 | return lhs = lhs << rhs; |
| 2306 | } |
| 2307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2308 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2309 | { |
| 2310 | return lhs = lhs >> rhs; |
| 2311 | } |
| 2312 | |
| 2313 | RValue<UShort> operator+(RValue<UShort> val) |
| 2314 | { |
| 2315 | return val; |
| 2316 | } |
| 2317 | |
| 2318 | RValue<UShort> operator-(RValue<UShort> val) |
| 2319 | { |
| 2320 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2321 | } |
| 2322 | |
| 2323 | RValue<UShort> operator~(RValue<UShort> val) |
| 2324 | { |
| 2325 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2326 | } |
| 2327 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2328 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2329 | { |
| 2330 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2331 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2332 | return res; |
| 2333 | } |
| 2334 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2335 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2336 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2337 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2338 | return val; |
| 2339 | } |
| 2340 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2341 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2342 | { |
| 2343 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2344 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2345 | return res; |
| 2346 | } |
| 2347 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2348 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2349 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2350 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2351 | return val; |
| 2352 | } |
| 2353 | |
| 2354 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2355 | { |
| 2356 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2357 | } |
| 2358 | |
| 2359 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2360 | { |
| 2361 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2362 | } |
| 2363 | |
| 2364 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2365 | { |
| 2366 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2367 | } |
| 2368 | |
| 2369 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2370 | { |
| 2371 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2372 | } |
| 2373 | |
| 2374 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2375 | { |
| 2376 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2377 | } |
| 2378 | |
| 2379 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2380 | { |
| 2381 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2382 | } |
| 2383 | |
| 2384 | Type *UShort::getType() |
| 2385 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2386 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2387 | } |
| 2388 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2389 | Byte4::Byte4(RValue<Byte8> cast) |
| 2390 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2391 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2392 | } |
| 2393 | |
| 2394 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2395 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2396 | Value *value = rhs.loadValue(); |
| 2397 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2398 | } |
| 2399 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2400 | Type *Byte4::getType() |
| 2401 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2402 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | Type *SByte4::getType() |
| 2406 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2407 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2408 | } |
| 2409 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2410 | 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) |
| 2411 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2412 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2413 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2417 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2418 | storeValue(rhs.value); |
| 2419 | } |
| 2420 | |
| 2421 | Byte8::Byte8(const Byte8 &rhs) |
| 2422 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2423 | Value *value = rhs.loadValue(); |
| 2424 | storeValue(value); |
| 2425 | } |
| 2426 | |
| 2427 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2428 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2429 | Value *value = rhs.loadValue(); |
| 2430 | storeValue(value); |
| 2431 | } |
| 2432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2433 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2434 | { |
| 2435 | storeValue(rhs.value); |
| 2436 | |
| 2437 | return rhs; |
| 2438 | } |
| 2439 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2440 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2441 | { |
| 2442 | Value *value = rhs.loadValue(); |
| 2443 | storeValue(value); |
| 2444 | |
| 2445 | return RValue<Byte8>(value); |
| 2446 | } |
| 2447 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2448 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2449 | { |
| 2450 | Value *value = rhs.loadValue(); |
| 2451 | storeValue(value); |
| 2452 | |
| 2453 | return RValue<Byte8>(value); |
| 2454 | } |
| 2455 | |
| 2456 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2457 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2458 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2462 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2463 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2467 | // { |
| 2468 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2469 | // } |
| 2470 | |
| 2471 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2472 | // { |
| 2473 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2474 | // } |
| 2475 | |
| 2476 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2477 | // { |
| 2478 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2479 | // } |
| 2480 | |
| 2481 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2482 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2483 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2487 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2488 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2492 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2493 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2497 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2498 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2499 | // } |
| 2500 | |
| 2501 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2502 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2503 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2504 | // } |
| 2505 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2506 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2507 | { |
| 2508 | return lhs = lhs + rhs; |
| 2509 | } |
| 2510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2511 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2512 | { |
| 2513 | return lhs = lhs - rhs; |
| 2514 | } |
| 2515 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2516 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2517 | // { |
| 2518 | // return lhs = lhs * rhs; |
| 2519 | // } |
| 2520 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2521 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2522 | // { |
| 2523 | // return lhs = lhs / rhs; |
| 2524 | // } |
| 2525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2526 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2527 | // { |
| 2528 | // return lhs = lhs % rhs; |
| 2529 | // } |
| 2530 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2531 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2532 | { |
| 2533 | return lhs = lhs & rhs; |
| 2534 | } |
| 2535 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2536 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2537 | { |
| 2538 | return lhs = lhs | rhs; |
| 2539 | } |
| 2540 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2541 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2542 | { |
| 2543 | return lhs = lhs ^ rhs; |
| 2544 | } |
| 2545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2546 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2547 | // { |
| 2548 | // return lhs = lhs << rhs; |
| 2549 | // } |
| 2550 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2551 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2552 | // { |
| 2553 | // return lhs = lhs >> rhs; |
| 2554 | // } |
| 2555 | |
| 2556 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2557 | // { |
| 2558 | // return val; |
| 2559 | // } |
| 2560 | |
| 2561 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2562 | // { |
| 2563 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2564 | // } |
| 2565 | |
| 2566 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2567 | { |
| 2568 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2569 | } |
| 2570 | |
| 2571 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2572 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2573 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2574 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2575 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2576 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2577 | paddusb->addArg(x.value); |
| 2578 | paddusb->addArg(y.value); |
| 2579 | ::basicBlock->appendInst(paddusb); |
| 2580 | |
| 2581 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2585 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2586 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2587 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2588 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2589 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2590 | psubusw->addArg(x.value); |
| 2591 | psubusw->addArg(y.value); |
| 2592 | ::basicBlock->appendInst(psubusw); |
| 2593 | |
| 2594 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2598 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2599 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2600 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2601 | } |
| 2602 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2603 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2604 | { |
| 2605 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| 2606 | } |
| 2607 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2608 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2609 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2610 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2611 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2615 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2616 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2617 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2618 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2622 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2623 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2624 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2625 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2626 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2627 | movmsk->addArg(x.value); |
| 2628 | ::basicBlock->appendInst(movmsk); |
| 2629 | |
| 2630 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2634 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2635 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2636 | // } |
| 2637 | |
| 2638 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2639 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2640 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | Type *Byte8::getType() |
| 2644 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2645 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2646 | } |
| 2647 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2648 | 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) |
| 2649 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2650 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2651 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2652 | |
| 2653 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2654 | } |
| 2655 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2656 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2657 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2658 | storeValue(rhs.value); |
| 2659 | } |
| 2660 | |
| 2661 | SByte8::SByte8(const SByte8 &rhs) |
| 2662 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2663 | Value *value = rhs.loadValue(); |
| 2664 | storeValue(value); |
| 2665 | } |
| 2666 | |
| 2667 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2668 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2669 | Value *value = rhs.loadValue(); |
| 2670 | storeValue(value); |
| 2671 | } |
| 2672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2673 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2674 | { |
| 2675 | storeValue(rhs.value); |
| 2676 | |
| 2677 | return rhs; |
| 2678 | } |
| 2679 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2680 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2681 | { |
| 2682 | Value *value = rhs.loadValue(); |
| 2683 | storeValue(value); |
| 2684 | |
| 2685 | return RValue<SByte8>(value); |
| 2686 | } |
| 2687 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2688 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2689 | { |
| 2690 | Value *value = rhs.loadValue(); |
| 2691 | storeValue(value); |
| 2692 | |
| 2693 | return RValue<SByte8>(value); |
| 2694 | } |
| 2695 | |
| 2696 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2697 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2698 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2702 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2703 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2707 | // { |
| 2708 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2709 | // } |
| 2710 | |
| 2711 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2712 | // { |
| 2713 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2714 | // } |
| 2715 | |
| 2716 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2717 | // { |
| 2718 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2719 | // } |
| 2720 | |
| 2721 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2722 | { |
| 2723 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2724 | } |
| 2725 | |
| 2726 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2727 | { |
| 2728 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2729 | } |
| 2730 | |
| 2731 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2732 | { |
| 2733 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2734 | } |
| 2735 | |
| 2736 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2737 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2738 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2739 | // } |
| 2740 | |
| 2741 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2742 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2743 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2744 | // } |
| 2745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2746 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2747 | { |
| 2748 | return lhs = lhs + rhs; |
| 2749 | } |
| 2750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2751 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2752 | { |
| 2753 | return lhs = lhs - rhs; |
| 2754 | } |
| 2755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2756 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2757 | // { |
| 2758 | // return lhs = lhs * rhs; |
| 2759 | // } |
| 2760 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2761 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2762 | // { |
| 2763 | // return lhs = lhs / rhs; |
| 2764 | // } |
| 2765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2766 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2767 | // { |
| 2768 | // return lhs = lhs % rhs; |
| 2769 | // } |
| 2770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2771 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2772 | { |
| 2773 | return lhs = lhs & rhs; |
| 2774 | } |
| 2775 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2776 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2777 | { |
| 2778 | return lhs = lhs | rhs; |
| 2779 | } |
| 2780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2781 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2782 | { |
| 2783 | return lhs = lhs ^ rhs; |
| 2784 | } |
| 2785 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2786 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2787 | // { |
| 2788 | // return lhs = lhs << rhs; |
| 2789 | // } |
| 2790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2791 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2792 | // { |
| 2793 | // return lhs = lhs >> rhs; |
| 2794 | // } |
| 2795 | |
| 2796 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2797 | // { |
| 2798 | // return val; |
| 2799 | // } |
| 2800 | |
| 2801 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2802 | // { |
| 2803 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2804 | // } |
| 2805 | |
| 2806 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2807 | { |
| 2808 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2809 | } |
| 2810 | |
| 2811 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2812 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2813 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2814 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2815 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2816 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2817 | paddsb->addArg(x.value); |
| 2818 | paddsb->addArg(y.value); |
| 2819 | ::basicBlock->appendInst(paddsb); |
| 2820 | |
| 2821 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2825 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2826 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2827 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2828 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2829 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2830 | psubsb->addArg(x.value); |
| 2831 | psubsb->addArg(y.value); |
| 2832 | ::basicBlock->appendInst(psubsb); |
| 2833 | |
| 2834 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2838 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2839 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2840 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2844 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2845 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2846 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2847 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2851 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2852 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2853 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2854 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2855 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2856 | movmsk->addArg(x.value); |
| 2857 | ::basicBlock->appendInst(movmsk); |
| 2858 | |
| 2859 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2863 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2864 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2868 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2869 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | Type *SByte8::getType() |
| 2873 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2874 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2878 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2879 | storeValue(rhs.value); |
| 2880 | } |
| 2881 | |
| 2882 | Byte16::Byte16(const Byte16 &rhs) |
| 2883 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2884 | Value *value = rhs.loadValue(); |
| 2885 | storeValue(value); |
| 2886 | } |
| 2887 | |
| 2888 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2889 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2890 | Value *value = rhs.loadValue(); |
| 2891 | storeValue(value); |
| 2892 | } |
| 2893 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2894 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2895 | { |
| 2896 | storeValue(rhs.value); |
| 2897 | |
| 2898 | return rhs; |
| 2899 | } |
| 2900 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2901 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2902 | { |
| 2903 | Value *value = rhs.loadValue(); |
| 2904 | storeValue(value); |
| 2905 | |
| 2906 | return RValue<Byte16>(value); |
| 2907 | } |
| 2908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2909 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2910 | { |
| 2911 | Value *value = rhs.loadValue(); |
| 2912 | storeValue(value); |
| 2913 | |
| 2914 | return RValue<Byte16>(value); |
| 2915 | } |
| 2916 | |
| 2917 | Type *Byte16::getType() |
| 2918 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2919 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | Type *SByte16::getType() |
| 2923 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2924 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2925 | } |
| 2926 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2927 | Short2::Short2(RValue<Short4> cast) |
| 2928 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2929 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | Type *Short2::getType() |
| 2933 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2934 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | UShort2::UShort2(RValue<UShort4> cast) |
| 2938 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2939 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | Type *UShort2::getType() |
| 2943 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2944 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2945 | } |
| 2946 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2947 | Short4::Short4(RValue<Int> cast) |
| 2948 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2949 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 2950 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2951 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2952 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2953 | |
| 2954 | storeValue(swizzle); |
| 2955 | } |
| 2956 | |
| 2957 | Short4::Short4(RValue<Int4> cast) |
| 2958 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 2959 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 2960 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 2961 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 2962 | |
| 2963 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 2964 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 2965 | |
| 2966 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | // Short4::Short4(RValue<Float> cast) |
| 2970 | // { |
| 2971 | // } |
| 2972 | |
| 2973 | Short4::Short4(RValue<Float4> cast) |
| 2974 | { |
| 2975 | assert(false && "UNIMPLEMENTED"); |
| 2976 | } |
| 2977 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2978 | Short4::Short4(short xyzw) |
| 2979 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2980 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 2981 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | Short4::Short4(short x, short y, short z, short w) |
| 2985 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2986 | int64_t constantVector[4] = {x, y, z, w}; |
| 2987 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | Short4::Short4(RValue<Short4> rhs) |
| 2991 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2992 | storeValue(rhs.value); |
| 2993 | } |
| 2994 | |
| 2995 | Short4::Short4(const Short4 &rhs) |
| 2996 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2997 | Value *value = rhs.loadValue(); |
| 2998 | storeValue(value); |
| 2999 | } |
| 3000 | |
| 3001 | Short4::Short4(const Reference<Short4> &rhs) |
| 3002 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3003 | Value *value = rhs.loadValue(); |
| 3004 | storeValue(value); |
| 3005 | } |
| 3006 | |
| 3007 | Short4::Short4(RValue<UShort4> rhs) |
| 3008 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3009 | storeValue(rhs.value); |
| 3010 | } |
| 3011 | |
| 3012 | Short4::Short4(const UShort4 &rhs) |
| 3013 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3014 | storeValue(rhs.loadValue()); |
| 3015 | } |
| 3016 | |
| 3017 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3018 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3019 | storeValue(rhs.loadValue()); |
| 3020 | } |
| 3021 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3022 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3023 | { |
| 3024 | storeValue(rhs.value); |
| 3025 | |
| 3026 | return rhs; |
| 3027 | } |
| 3028 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3029 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3030 | { |
| 3031 | Value *value = rhs.loadValue(); |
| 3032 | storeValue(value); |
| 3033 | |
| 3034 | return RValue<Short4>(value); |
| 3035 | } |
| 3036 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3037 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3038 | { |
| 3039 | Value *value = rhs.loadValue(); |
| 3040 | storeValue(value); |
| 3041 | |
| 3042 | return RValue<Short4>(value); |
| 3043 | } |
| 3044 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3045 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3046 | { |
| 3047 | storeValue(rhs.value); |
| 3048 | |
| 3049 | return RValue<Short4>(rhs); |
| 3050 | } |
| 3051 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3052 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3053 | { |
| 3054 | Value *value = rhs.loadValue(); |
| 3055 | storeValue(value); |
| 3056 | |
| 3057 | return RValue<Short4>(value); |
| 3058 | } |
| 3059 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3060 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3061 | { |
| 3062 | Value *value = rhs.loadValue(); |
| 3063 | storeValue(value); |
| 3064 | |
| 3065 | return RValue<Short4>(value); |
| 3066 | } |
| 3067 | |
| 3068 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3069 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3070 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3074 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3075 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3079 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3080 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3084 | // { |
| 3085 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3086 | // } |
| 3087 | |
| 3088 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3089 | // { |
| 3090 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3091 | // } |
| 3092 | |
| 3093 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3094 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3095 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3099 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3100 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3104 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3105 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3109 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3110 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3114 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3115 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3116 | } |
| 3117 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3118 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3119 | { |
| 3120 | return lhs = lhs + rhs; |
| 3121 | } |
| 3122 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3123 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3124 | { |
| 3125 | return lhs = lhs - rhs; |
| 3126 | } |
| 3127 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3128 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3129 | { |
| 3130 | return lhs = lhs * rhs; |
| 3131 | } |
| 3132 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3133 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3134 | // { |
| 3135 | // return lhs = lhs / rhs; |
| 3136 | // } |
| 3137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3138 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3139 | // { |
| 3140 | // return lhs = lhs % rhs; |
| 3141 | // } |
| 3142 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3143 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3144 | { |
| 3145 | return lhs = lhs & rhs; |
| 3146 | } |
| 3147 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3148 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3149 | { |
| 3150 | return lhs = lhs | rhs; |
| 3151 | } |
| 3152 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3153 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3154 | { |
| 3155 | return lhs = lhs ^ rhs; |
| 3156 | } |
| 3157 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3158 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3159 | { |
| 3160 | return lhs = lhs << rhs; |
| 3161 | } |
| 3162 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3163 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3164 | { |
| 3165 | return lhs = lhs >> rhs; |
| 3166 | } |
| 3167 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3168 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3169 | // { |
| 3170 | // return val; |
| 3171 | // } |
| 3172 | |
| 3173 | RValue<Short4> operator-(RValue<Short4> val) |
| 3174 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3175 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | RValue<Short4> operator~(RValue<Short4> val) |
| 3179 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3180 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3184 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3185 | RValue<Int4> int4 = RoundInt(cast); |
| 3186 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3190 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3191 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3192 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3193 | ::basicBlock->appendInst(cmp); |
| 3194 | |
| 3195 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3196 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3197 | ::basicBlock->appendInst(select); |
| 3198 | |
| 3199 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3203 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3204 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3205 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3206 | ::basicBlock->appendInst(cmp); |
| 3207 | |
| 3208 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3209 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3210 | ::basicBlock->appendInst(select); |
| 3211 | |
| 3212 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3216 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3217 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3218 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3219 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3220 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3221 | paddsw->addArg(x.value); |
| 3222 | paddsw->addArg(y.value); |
| 3223 | ::basicBlock->appendInst(paddsw); |
| 3224 | |
| 3225 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3229 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3230 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3231 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3232 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3233 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3234 | psubsw->addArg(x.value); |
| 3235 | psubsw->addArg(y.value); |
| 3236 | ::basicBlock->appendInst(psubsw); |
| 3237 | |
| 3238 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3242 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3243 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3244 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3245 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3246 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3247 | pmulhw->addArg(x.value); |
| 3248 | pmulhw->addArg(y.value); |
| 3249 | ::basicBlock->appendInst(pmulhw); |
| 3250 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3251 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3255 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3256 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3257 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3258 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3259 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3260 | pmaddwd->addArg(x.value); |
| 3261 | pmaddwd->addArg(y.value); |
| 3262 | ::basicBlock->appendInst(pmaddwd); |
| 3263 | |
| 3264 | return RValue<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3268 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3269 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3270 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3271 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3272 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3273 | pack->addArg(x.value); |
| 3274 | pack->addArg(y.value); |
| 3275 | ::basicBlock->appendInst(pack); |
| 3276 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3277 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3281 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3282 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3283 | return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3287 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3288 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3289 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3290 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3294 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3295 | // Real type is v8i16 |
| 3296 | int shuffle[8] = |
| 3297 | { |
| 3298 | (select >> 0) & 0x03, |
| 3299 | (select >> 2) & 0x03, |
| 3300 | (select >> 4) & 0x03, |
| 3301 | (select >> 6) & 0x03, |
| 3302 | (select >> 0) & 0x03, |
| 3303 | (select >> 2) & 0x03, |
| 3304 | (select >> 4) & 0x03, |
| 3305 | (select >> 6) & 0x03, |
| 3306 | }; |
| 3307 | |
| 3308 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3312 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3313 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3317 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3318 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3322 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3323 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3327 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3328 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | Type *Short4::getType() |
| 3332 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3333 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | UShort4::UShort4(RValue<Int4> cast) |
| 3337 | { |
| 3338 | *this = Short4(cast); |
| 3339 | } |
| 3340 | |
| 3341 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3342 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3343 | if(saturate) |
| 3344 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3345 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3346 | { |
| 3347 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3348 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3349 | } |
| 3350 | else |
| 3351 | { |
| 3352 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3353 | } |
| 3354 | } |
| 3355 | else |
| 3356 | { |
| 3357 | *this = Short4(Int4(cast)); |
| 3358 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3359 | } |
| 3360 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3361 | UShort4::UShort4(unsigned short xyzw) |
| 3362 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3363 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3364 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3368 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3369 | int64_t constantVector[4] = {x, y, z, w}; |
| 3370 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3374 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3375 | storeValue(rhs.value); |
| 3376 | } |
| 3377 | |
| 3378 | UShort4::UShort4(const UShort4 &rhs) |
| 3379 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3380 | Value *value = rhs.loadValue(); |
| 3381 | storeValue(value); |
| 3382 | } |
| 3383 | |
| 3384 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3385 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3386 | Value *value = rhs.loadValue(); |
| 3387 | storeValue(value); |
| 3388 | } |
| 3389 | |
| 3390 | UShort4::UShort4(RValue<Short4> rhs) |
| 3391 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3392 | storeValue(rhs.value); |
| 3393 | } |
| 3394 | |
| 3395 | UShort4::UShort4(const Short4 &rhs) |
| 3396 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3397 | Value *value = rhs.loadValue(); |
| 3398 | storeValue(value); |
| 3399 | } |
| 3400 | |
| 3401 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3402 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3403 | Value *value = rhs.loadValue(); |
| 3404 | storeValue(value); |
| 3405 | } |
| 3406 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3407 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3408 | { |
| 3409 | storeValue(rhs.value); |
| 3410 | |
| 3411 | return rhs; |
| 3412 | } |
| 3413 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3414 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3415 | { |
| 3416 | Value *value = rhs.loadValue(); |
| 3417 | storeValue(value); |
| 3418 | |
| 3419 | return RValue<UShort4>(value); |
| 3420 | } |
| 3421 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3422 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3423 | { |
| 3424 | Value *value = rhs.loadValue(); |
| 3425 | storeValue(value); |
| 3426 | |
| 3427 | return RValue<UShort4>(value); |
| 3428 | } |
| 3429 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3430 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3431 | { |
| 3432 | storeValue(rhs.value); |
| 3433 | |
| 3434 | return RValue<UShort4>(rhs); |
| 3435 | } |
| 3436 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3437 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3438 | { |
| 3439 | Value *value = rhs.loadValue(); |
| 3440 | storeValue(value); |
| 3441 | |
| 3442 | return RValue<UShort4>(value); |
| 3443 | } |
| 3444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3445 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3446 | { |
| 3447 | Value *value = rhs.loadValue(); |
| 3448 | storeValue(value); |
| 3449 | |
| 3450 | return RValue<UShort4>(value); |
| 3451 | } |
| 3452 | |
| 3453 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3454 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3455 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3459 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3460 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3464 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3465 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3466 | } |
| 3467 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3468 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3469 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3470 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3474 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3475 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3479 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3480 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3481 | } |
| 3482 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3483 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3484 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3485 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3489 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3490 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3491 | } |
| 3492 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3493 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3494 | { |
| 3495 | return lhs = lhs << rhs; |
| 3496 | } |
| 3497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3498 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3499 | { |
| 3500 | return lhs = lhs >> rhs; |
| 3501 | } |
| 3502 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3503 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3504 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3505 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3509 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3510 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3511 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3512 | ::basicBlock->appendInst(cmp); |
| 3513 | |
| 3514 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3515 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3516 | ::basicBlock->appendInst(select); |
| 3517 | |
| 3518 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3522 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3523 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3524 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3525 | ::basicBlock->appendInst(cmp); |
| 3526 | |
| 3527 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3528 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3529 | ::basicBlock->appendInst(select); |
| 3530 | |
| 3531 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3535 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3536 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3537 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3538 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3539 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3540 | paddusw->addArg(x.value); |
| 3541 | paddusw->addArg(y.value); |
| 3542 | ::basicBlock->appendInst(paddusw); |
| 3543 | |
| 3544 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3548 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3549 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3550 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3551 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3552 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3553 | psubusw->addArg(x.value); |
| 3554 | psubusw->addArg(y.value); |
| 3555 | ::basicBlock->appendInst(psubusw); |
| 3556 | |
| 3557 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3561 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3562 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3563 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3564 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3565 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3566 | pmulhuw->addArg(x.value); |
| 3567 | pmulhuw->addArg(y.value); |
| 3568 | ::basicBlock->appendInst(pmulhuw); |
| 3569 | |
| 3570 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3574 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3575 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3579 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3580 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3581 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3582 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3583 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3584 | pack->addArg(x.value); |
| 3585 | pack->addArg(y.value); |
| 3586 | ::basicBlock->appendInst(pack); |
| 3587 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3588 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | Type *UShort4::getType() |
| 3592 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3593 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3594 | } |
| 3595 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3596 | Short8::Short8(short c) |
| 3597 | { |
| 3598 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3599 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3600 | } |
| 3601 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3602 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3603 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3604 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3605 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | Short8::Short8(RValue<Short8> rhs) |
| 3609 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3610 | storeValue(rhs.value); |
| 3611 | } |
| 3612 | |
| 3613 | Short8::Short8(const Reference<Short8> &rhs) |
| 3614 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3615 | Value *value = rhs.loadValue(); |
| 3616 | storeValue(value); |
| 3617 | } |
| 3618 | |
| 3619 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3620 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3621 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3622 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3623 | |
| 3624 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3628 | { |
| 3629 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3630 | } |
| 3631 | |
| 3632 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3633 | { |
| 3634 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3635 | } |
| 3636 | |
| 3637 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3638 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3639 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3643 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3644 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3648 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3649 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | RValue<Int4> Abs(RValue<Int4> x) |
| 3653 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3654 | auto negative = x >> 31; |
| 3655 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3659 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3660 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | Type *Short8::getType() |
| 3664 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3665 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3666 | } |
| 3667 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3668 | UShort8::UShort8(unsigned short c) |
| 3669 | { |
| 3670 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3671 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3672 | } |
| 3673 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3674 | 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) |
| 3675 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3676 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3677 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3681 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3682 | storeValue(rhs.value); |
| 3683 | } |
| 3684 | |
| 3685 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3686 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3687 | Value *value = rhs.loadValue(); |
| 3688 | storeValue(value); |
| 3689 | } |
| 3690 | |
| 3691 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3692 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3693 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3694 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3695 | |
| 3696 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3697 | } |
| 3698 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3699 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3700 | { |
| 3701 | storeValue(rhs.value); |
| 3702 | |
| 3703 | return rhs; |
| 3704 | } |
| 3705 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3706 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3707 | { |
| 3708 | Value *value = rhs.loadValue(); |
| 3709 | storeValue(value); |
| 3710 | |
| 3711 | return RValue<UShort8>(value); |
| 3712 | } |
| 3713 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3714 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3715 | { |
| 3716 | Value *value = rhs.loadValue(); |
| 3717 | storeValue(value); |
| 3718 | |
| 3719 | return RValue<UShort8>(value); |
| 3720 | } |
| 3721 | |
| 3722 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3723 | { |
| 3724 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3725 | } |
| 3726 | |
| 3727 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3728 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3729 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3733 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3734 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3738 | { |
| 3739 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3740 | } |
| 3741 | |
| 3742 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3743 | { |
| 3744 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3745 | } |
| 3746 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3747 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3748 | { |
| 3749 | return lhs = lhs + rhs; |
| 3750 | } |
| 3751 | |
| 3752 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3753 | { |
| 3754 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3755 | } |
| 3756 | |
| 3757 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3758 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3759 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3763 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3764 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3768 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3769 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3770 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3771 | // } |
| 3772 | |
| 3773 | Type *UShort8::getType() |
| 3774 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3775 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | Int::Int(Argument<Int> argument) |
| 3779 | { |
| 3780 | storeValue(argument.value); |
| 3781 | } |
| 3782 | |
| 3783 | Int::Int(RValue<Byte> cast) |
| 3784 | { |
| 3785 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3786 | |
| 3787 | storeValue(integer); |
| 3788 | } |
| 3789 | |
| 3790 | Int::Int(RValue<SByte> cast) |
| 3791 | { |
| 3792 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3793 | |
| 3794 | storeValue(integer); |
| 3795 | } |
| 3796 | |
| 3797 | Int::Int(RValue<Short> cast) |
| 3798 | { |
| 3799 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3800 | |
| 3801 | storeValue(integer); |
| 3802 | } |
| 3803 | |
| 3804 | Int::Int(RValue<UShort> cast) |
| 3805 | { |
| 3806 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3807 | |
| 3808 | storeValue(integer); |
| 3809 | } |
| 3810 | |
| 3811 | Int::Int(RValue<Int2> cast) |
| 3812 | { |
| 3813 | *this = Extract(cast, 0); |
| 3814 | } |
| 3815 | |
| 3816 | Int::Int(RValue<Long> cast) |
| 3817 | { |
| 3818 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3819 | |
| 3820 | storeValue(integer); |
| 3821 | } |
| 3822 | |
| 3823 | Int::Int(RValue<Float> cast) |
| 3824 | { |
| 3825 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3826 | |
| 3827 | storeValue(integer); |
| 3828 | } |
| 3829 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3830 | Int::Int(int x) |
| 3831 | { |
| 3832 | storeValue(Nucleus::createConstantInt(x)); |
| 3833 | } |
| 3834 | |
| 3835 | Int::Int(RValue<Int> rhs) |
| 3836 | { |
| 3837 | storeValue(rhs.value); |
| 3838 | } |
| 3839 | |
| 3840 | Int::Int(RValue<UInt> rhs) |
| 3841 | { |
| 3842 | storeValue(rhs.value); |
| 3843 | } |
| 3844 | |
| 3845 | Int::Int(const Int &rhs) |
| 3846 | { |
| 3847 | Value *value = rhs.loadValue(); |
| 3848 | storeValue(value); |
| 3849 | } |
| 3850 | |
| 3851 | Int::Int(const Reference<Int> &rhs) |
| 3852 | { |
| 3853 | Value *value = rhs.loadValue(); |
| 3854 | storeValue(value); |
| 3855 | } |
| 3856 | |
| 3857 | Int::Int(const UInt &rhs) |
| 3858 | { |
| 3859 | Value *value = rhs.loadValue(); |
| 3860 | storeValue(value); |
| 3861 | } |
| 3862 | |
| 3863 | Int::Int(const Reference<UInt> &rhs) |
| 3864 | { |
| 3865 | Value *value = rhs.loadValue(); |
| 3866 | storeValue(value); |
| 3867 | } |
| 3868 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3869 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3870 | { |
| 3871 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3872 | } |
| 3873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3874 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3875 | { |
| 3876 | storeValue(rhs.value); |
| 3877 | |
| 3878 | return rhs; |
| 3879 | } |
| 3880 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3881 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3882 | { |
| 3883 | storeValue(rhs.value); |
| 3884 | |
| 3885 | return RValue<Int>(rhs); |
| 3886 | } |
| 3887 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3888 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3889 | { |
| 3890 | Value *value = rhs.loadValue(); |
| 3891 | storeValue(value); |
| 3892 | |
| 3893 | return RValue<Int>(value); |
| 3894 | } |
| 3895 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3896 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3897 | { |
| 3898 | Value *value = rhs.loadValue(); |
| 3899 | storeValue(value); |
| 3900 | |
| 3901 | return RValue<Int>(value); |
| 3902 | } |
| 3903 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3904 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3905 | { |
| 3906 | Value *value = rhs.loadValue(); |
| 3907 | storeValue(value); |
| 3908 | |
| 3909 | return RValue<Int>(value); |
| 3910 | } |
| 3911 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3912 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3913 | { |
| 3914 | Value *value = rhs.loadValue(); |
| 3915 | storeValue(value); |
| 3916 | |
| 3917 | return RValue<Int>(value); |
| 3918 | } |
| 3919 | |
| 3920 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3921 | { |
| 3922 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3923 | } |
| 3924 | |
| 3925 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3926 | { |
| 3927 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3928 | } |
| 3929 | |
| 3930 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3931 | { |
| 3932 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3933 | } |
| 3934 | |
| 3935 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3936 | { |
| 3937 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3938 | } |
| 3939 | |
| 3940 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3941 | { |
| 3942 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3943 | } |
| 3944 | |
| 3945 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3946 | { |
| 3947 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3948 | } |
| 3949 | |
| 3950 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 3951 | { |
| 3952 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 3953 | } |
| 3954 | |
| 3955 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 3956 | { |
| 3957 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 3958 | } |
| 3959 | |
| 3960 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 3961 | { |
| 3962 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 3963 | } |
| 3964 | |
| 3965 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 3966 | { |
| 3967 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 3968 | } |
| 3969 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3970 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3971 | { |
| 3972 | return lhs = lhs + rhs; |
| 3973 | } |
| 3974 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3975 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3976 | { |
| 3977 | return lhs = lhs - rhs; |
| 3978 | } |
| 3979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3980 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3981 | { |
| 3982 | return lhs = lhs * rhs; |
| 3983 | } |
| 3984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3985 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3986 | { |
| 3987 | return lhs = lhs / rhs; |
| 3988 | } |
| 3989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3990 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3991 | { |
| 3992 | return lhs = lhs % rhs; |
| 3993 | } |
| 3994 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3995 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3996 | { |
| 3997 | return lhs = lhs & rhs; |
| 3998 | } |
| 3999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4000 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4001 | { |
| 4002 | return lhs = lhs | rhs; |
| 4003 | } |
| 4004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4005 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4006 | { |
| 4007 | return lhs = lhs ^ rhs; |
| 4008 | } |
| 4009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4010 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4011 | { |
| 4012 | return lhs = lhs << rhs; |
| 4013 | } |
| 4014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4015 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4016 | { |
| 4017 | return lhs = lhs >> rhs; |
| 4018 | } |
| 4019 | |
| 4020 | RValue<Int> operator+(RValue<Int> val) |
| 4021 | { |
| 4022 | return val; |
| 4023 | } |
| 4024 | |
| 4025 | RValue<Int> operator-(RValue<Int> val) |
| 4026 | { |
| 4027 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4028 | } |
| 4029 | |
| 4030 | RValue<Int> operator~(RValue<Int> val) |
| 4031 | { |
| 4032 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4033 | } |
| 4034 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4035 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4036 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4037 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4038 | val += 1; |
| 4039 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4040 | } |
| 4041 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4042 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4043 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4044 | val += 1; |
| 4045 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4046 | } |
| 4047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4048 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4049 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4050 | RValue<Int> res = val; |
| 4051 | val -= 1; |
| 4052 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4053 | } |
| 4054 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4055 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4056 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4057 | val -= 1; |
| 4058 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4062 | { |
| 4063 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4064 | } |
| 4065 | |
| 4066 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4067 | { |
| 4068 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4069 | } |
| 4070 | |
| 4071 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4072 | { |
| 4073 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4074 | } |
| 4075 | |
| 4076 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4077 | { |
| 4078 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4079 | } |
| 4080 | |
| 4081 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4082 | { |
| 4083 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4084 | } |
| 4085 | |
| 4086 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4087 | { |
| 4088 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4089 | } |
| 4090 | |
| 4091 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4092 | { |
| 4093 | return IfThenElse(x > y, x, y); |
| 4094 | } |
| 4095 | |
| 4096 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4097 | { |
| 4098 | return IfThenElse(x < y, x, y); |
| 4099 | } |
| 4100 | |
| 4101 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4102 | { |
| 4103 | return Min(Max(x, min), max); |
| 4104 | } |
| 4105 | |
| 4106 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4107 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4108 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 4109 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4110 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4111 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4112 | nearbyint->addArg(cast.value); |
| 4113 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4114 | |
| 4115 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | Type *Int::getType() |
| 4119 | { |
| 4120 | return T(Ice::IceType_i32); |
| 4121 | } |
| 4122 | |
| 4123 | Long::Long(RValue<Int> cast) |
| 4124 | { |
| 4125 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4126 | |
| 4127 | storeValue(integer); |
| 4128 | } |
| 4129 | |
| 4130 | Long::Long(RValue<UInt> cast) |
| 4131 | { |
| 4132 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4133 | |
| 4134 | storeValue(integer); |
| 4135 | } |
| 4136 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4137 | Long::Long(RValue<Long> rhs) |
| 4138 | { |
| 4139 | storeValue(rhs.value); |
| 4140 | } |
| 4141 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4142 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4143 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4144 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4145 | } |
| 4146 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4147 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4148 | { |
| 4149 | storeValue(rhs.value); |
| 4150 | |
| 4151 | return rhs; |
| 4152 | } |
| 4153 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4154 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4155 | { |
| 4156 | Value *value = rhs.loadValue(); |
| 4157 | storeValue(value); |
| 4158 | |
| 4159 | return RValue<Long>(value); |
| 4160 | } |
| 4161 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4162 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4163 | { |
| 4164 | Value *value = rhs.loadValue(); |
| 4165 | storeValue(value); |
| 4166 | |
| 4167 | return RValue<Long>(value); |
| 4168 | } |
| 4169 | |
| 4170 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4171 | { |
| 4172 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4173 | } |
| 4174 | |
| 4175 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4176 | { |
| 4177 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4178 | } |
| 4179 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4180 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4181 | { |
| 4182 | return lhs = lhs + rhs; |
| 4183 | } |
| 4184 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4185 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4186 | { |
| 4187 | return lhs = lhs - rhs; |
| 4188 | } |
| 4189 | |
| 4190 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4191 | { |
| 4192 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4193 | } |
| 4194 | |
| 4195 | Type *Long::getType() |
| 4196 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4197 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4198 | } |
| 4199 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4200 | UInt::UInt(Argument<UInt> argument) |
| 4201 | { |
| 4202 | storeValue(argument.value); |
| 4203 | } |
| 4204 | |
| 4205 | UInt::UInt(RValue<UShort> cast) |
| 4206 | { |
| 4207 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4208 | |
| 4209 | storeValue(integer); |
| 4210 | } |
| 4211 | |
| 4212 | UInt::UInt(RValue<Long> cast) |
| 4213 | { |
| 4214 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4215 | |
| 4216 | storeValue(integer); |
| 4217 | } |
| 4218 | |
| 4219 | UInt::UInt(RValue<Float> cast) |
| 4220 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4221 | // Smallest positive value representable in UInt, but not in Int |
| 4222 | const unsigned int ustart = 0x80000000u; |
| 4223 | const float ustartf = float(ustart); |
| 4224 | |
| 4225 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4226 | storeValue((~(As<Int>(cast) >> 31) & |
| 4227 | // Check if the value can be represented as an Int |
| 4228 | IfThenElse(cast >= ustartf, |
| 4229 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4230 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4231 | // Otherwise, just convert normally |
| 4232 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4233 | } |
| 4234 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4235 | UInt::UInt(int x) |
| 4236 | { |
| 4237 | storeValue(Nucleus::createConstantInt(x)); |
| 4238 | } |
| 4239 | |
| 4240 | UInt::UInt(unsigned int x) |
| 4241 | { |
| 4242 | storeValue(Nucleus::createConstantInt(x)); |
| 4243 | } |
| 4244 | |
| 4245 | UInt::UInt(RValue<UInt> rhs) |
| 4246 | { |
| 4247 | storeValue(rhs.value); |
| 4248 | } |
| 4249 | |
| 4250 | UInt::UInt(RValue<Int> rhs) |
| 4251 | { |
| 4252 | storeValue(rhs.value); |
| 4253 | } |
| 4254 | |
| 4255 | UInt::UInt(const UInt &rhs) |
| 4256 | { |
| 4257 | Value *value = rhs.loadValue(); |
| 4258 | storeValue(value); |
| 4259 | } |
| 4260 | |
| 4261 | UInt::UInt(const Reference<UInt> &rhs) |
| 4262 | { |
| 4263 | Value *value = rhs.loadValue(); |
| 4264 | storeValue(value); |
| 4265 | } |
| 4266 | |
| 4267 | UInt::UInt(const Int &rhs) |
| 4268 | { |
| 4269 | Value *value = rhs.loadValue(); |
| 4270 | storeValue(value); |
| 4271 | } |
| 4272 | |
| 4273 | UInt::UInt(const Reference<Int> &rhs) |
| 4274 | { |
| 4275 | Value *value = rhs.loadValue(); |
| 4276 | storeValue(value); |
| 4277 | } |
| 4278 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4279 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4280 | { |
| 4281 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4282 | } |
| 4283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4284 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4285 | { |
| 4286 | storeValue(rhs.value); |
| 4287 | |
| 4288 | return rhs; |
| 4289 | } |
| 4290 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4291 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4292 | { |
| 4293 | storeValue(rhs.value); |
| 4294 | |
| 4295 | return RValue<UInt>(rhs); |
| 4296 | } |
| 4297 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4298 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4299 | { |
| 4300 | Value *value = rhs.loadValue(); |
| 4301 | storeValue(value); |
| 4302 | |
| 4303 | return RValue<UInt>(value); |
| 4304 | } |
| 4305 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4306 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4307 | { |
| 4308 | Value *value = rhs.loadValue(); |
| 4309 | storeValue(value); |
| 4310 | |
| 4311 | return RValue<UInt>(value); |
| 4312 | } |
| 4313 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4314 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4315 | { |
| 4316 | Value *value = rhs.loadValue(); |
| 4317 | storeValue(value); |
| 4318 | |
| 4319 | return RValue<UInt>(value); |
| 4320 | } |
| 4321 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4322 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4323 | { |
| 4324 | Value *value = rhs.loadValue(); |
| 4325 | storeValue(value); |
| 4326 | |
| 4327 | return RValue<UInt>(value); |
| 4328 | } |
| 4329 | |
| 4330 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4331 | { |
| 4332 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4333 | } |
| 4334 | |
| 4335 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4336 | { |
| 4337 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4338 | } |
| 4339 | |
| 4340 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4341 | { |
| 4342 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4343 | } |
| 4344 | |
| 4345 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4346 | { |
| 4347 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4348 | } |
| 4349 | |
| 4350 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4351 | { |
| 4352 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4353 | } |
| 4354 | |
| 4355 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4356 | { |
| 4357 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4358 | } |
| 4359 | |
| 4360 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4361 | { |
| 4362 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4363 | } |
| 4364 | |
| 4365 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4366 | { |
| 4367 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4368 | } |
| 4369 | |
| 4370 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4371 | { |
| 4372 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4373 | } |
| 4374 | |
| 4375 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4376 | { |
| 4377 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4378 | } |
| 4379 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4380 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4381 | { |
| 4382 | return lhs = lhs + rhs; |
| 4383 | } |
| 4384 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4385 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4386 | { |
| 4387 | return lhs = lhs - rhs; |
| 4388 | } |
| 4389 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4390 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4391 | { |
| 4392 | return lhs = lhs * rhs; |
| 4393 | } |
| 4394 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4395 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4396 | { |
| 4397 | return lhs = lhs / rhs; |
| 4398 | } |
| 4399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4400 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4401 | { |
| 4402 | return lhs = lhs % rhs; |
| 4403 | } |
| 4404 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4405 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4406 | { |
| 4407 | return lhs = lhs & rhs; |
| 4408 | } |
| 4409 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4410 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4411 | { |
| 4412 | return lhs = lhs | rhs; |
| 4413 | } |
| 4414 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4415 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4416 | { |
| 4417 | return lhs = lhs ^ rhs; |
| 4418 | } |
| 4419 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4420 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4421 | { |
| 4422 | return lhs = lhs << rhs; |
| 4423 | } |
| 4424 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4425 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4426 | { |
| 4427 | return lhs = lhs >> rhs; |
| 4428 | } |
| 4429 | |
| 4430 | RValue<UInt> operator+(RValue<UInt> val) |
| 4431 | { |
| 4432 | return val; |
| 4433 | } |
| 4434 | |
| 4435 | RValue<UInt> operator-(RValue<UInt> val) |
| 4436 | { |
| 4437 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4438 | } |
| 4439 | |
| 4440 | RValue<UInt> operator~(RValue<UInt> val) |
| 4441 | { |
| 4442 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4443 | } |
| 4444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4445 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4446 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4447 | RValue<UInt> res = val; |
| 4448 | val += 1; |
| 4449 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4450 | } |
| 4451 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4452 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4453 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4454 | val += 1; |
| 4455 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4456 | } |
| 4457 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4458 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4459 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4460 | RValue<UInt> res = val; |
| 4461 | val -= 1; |
| 4462 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4463 | } |
| 4464 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4465 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4466 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4467 | val -= 1; |
| 4468 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4472 | { |
| 4473 | return IfThenElse(x > y, x, y); |
| 4474 | } |
| 4475 | |
| 4476 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4477 | { |
| 4478 | return IfThenElse(x < y, x, y); |
| 4479 | } |
| 4480 | |
| 4481 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4482 | { |
| 4483 | return Min(Max(x, min), max); |
| 4484 | } |
| 4485 | |
| 4486 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4487 | { |
| 4488 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4489 | } |
| 4490 | |
| 4491 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4492 | { |
| 4493 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4494 | } |
| 4495 | |
| 4496 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4497 | { |
| 4498 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4499 | } |
| 4500 | |
| 4501 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4502 | { |
| 4503 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4504 | } |
| 4505 | |
| 4506 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4507 | { |
| 4508 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4509 | } |
| 4510 | |
| 4511 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4512 | { |
| 4513 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4514 | } |
| 4515 | |
| 4516 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4517 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4518 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4519 | // } |
| 4520 | |
| 4521 | Type *UInt::getType() |
| 4522 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4523 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | // Int2::Int2(RValue<Int> cast) |
| 4527 | // { |
| 4528 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4529 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4530 | // |
| 4531 | // Constant *shuffle[2]; |
| 4532 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4533 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4534 | // |
| 4535 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4536 | // |
| 4537 | // storeValue(replicate); |
| 4538 | // } |
| 4539 | |
| 4540 | Int2::Int2(RValue<Int4> cast) |
| 4541 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4542 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4543 | } |
| 4544 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4545 | Int2::Int2(int x, int y) |
| 4546 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4547 | int64_t constantVector[2] = {x, y}; |
| 4548 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | Int2::Int2(RValue<Int2> rhs) |
| 4552 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4553 | storeValue(rhs.value); |
| 4554 | } |
| 4555 | |
| 4556 | Int2::Int2(const Int2 &rhs) |
| 4557 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4558 | Value *value = rhs.loadValue(); |
| 4559 | storeValue(value); |
| 4560 | } |
| 4561 | |
| 4562 | Int2::Int2(const Reference<Int2> &rhs) |
| 4563 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4564 | Value *value = rhs.loadValue(); |
| 4565 | storeValue(value); |
| 4566 | } |
| 4567 | |
| 4568 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4569 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4570 | int shuffle[4] = {0, 4, 1, 5}; |
| 4571 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4572 | |
| 4573 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4574 | } |
| 4575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4576 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4577 | { |
| 4578 | storeValue(rhs.value); |
| 4579 | |
| 4580 | return rhs; |
| 4581 | } |
| 4582 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4583 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4584 | { |
| 4585 | Value *value = rhs.loadValue(); |
| 4586 | storeValue(value); |
| 4587 | |
| 4588 | return RValue<Int2>(value); |
| 4589 | } |
| 4590 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4591 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4592 | { |
| 4593 | Value *value = rhs.loadValue(); |
| 4594 | storeValue(value); |
| 4595 | |
| 4596 | return RValue<Int2>(value); |
| 4597 | } |
| 4598 | |
| 4599 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4600 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4601 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4605 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4606 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4607 | } |
| 4608 | |
| 4609 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4610 | // { |
| 4611 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4612 | // } |
| 4613 | |
| 4614 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4615 | // { |
| 4616 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4617 | // } |
| 4618 | |
| 4619 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4620 | // { |
| 4621 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4622 | // } |
| 4623 | |
| 4624 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4625 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4626 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4630 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4631 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4635 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4636 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4640 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4641 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4645 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4646 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4647 | } |
| 4648 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4649 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4650 | { |
| 4651 | return lhs = lhs + rhs; |
| 4652 | } |
| 4653 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4654 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4655 | { |
| 4656 | return lhs = lhs - rhs; |
| 4657 | } |
| 4658 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4659 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4660 | // { |
| 4661 | // return lhs = lhs * rhs; |
| 4662 | // } |
| 4663 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4664 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4665 | // { |
| 4666 | // return lhs = lhs / rhs; |
| 4667 | // } |
| 4668 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4669 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4670 | // { |
| 4671 | // return lhs = lhs % rhs; |
| 4672 | // } |
| 4673 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4674 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4675 | { |
| 4676 | return lhs = lhs & rhs; |
| 4677 | } |
| 4678 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4679 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4680 | { |
| 4681 | return lhs = lhs | rhs; |
| 4682 | } |
| 4683 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4684 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4685 | { |
| 4686 | return lhs = lhs ^ rhs; |
| 4687 | } |
| 4688 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4689 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4690 | { |
| 4691 | return lhs = lhs << rhs; |
| 4692 | } |
| 4693 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4694 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4695 | { |
| 4696 | return lhs = lhs >> rhs; |
| 4697 | } |
| 4698 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4699 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4700 | // { |
| 4701 | // return val; |
| 4702 | // } |
| 4703 | |
| 4704 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4705 | // { |
| 4706 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4707 | // } |
| 4708 | |
| 4709 | RValue<Int2> operator~(RValue<Int2> val) |
| 4710 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4711 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4712 | } |
| 4713 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4714 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4715 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4716 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4717 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4718 | } |
| 4719 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4720 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4721 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 4722 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4723 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4724 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4728 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4729 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4733 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4734 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | Type *Int2::getType() |
| 4738 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4739 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4740 | } |
| 4741 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4742 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4743 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4744 | int64_t constantVector[2] = {x, y}; |
| 4745 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4749 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4750 | storeValue(rhs.value); |
| 4751 | } |
| 4752 | |
| 4753 | UInt2::UInt2(const UInt2 &rhs) |
| 4754 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4755 | Value *value = rhs.loadValue(); |
| 4756 | storeValue(value); |
| 4757 | } |
| 4758 | |
| 4759 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4760 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4761 | Value *value = rhs.loadValue(); |
| 4762 | storeValue(value); |
| 4763 | } |
| 4764 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4765 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4766 | { |
| 4767 | storeValue(rhs.value); |
| 4768 | |
| 4769 | return rhs; |
| 4770 | } |
| 4771 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4772 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4773 | { |
| 4774 | Value *value = rhs.loadValue(); |
| 4775 | storeValue(value); |
| 4776 | |
| 4777 | return RValue<UInt2>(value); |
| 4778 | } |
| 4779 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4780 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4781 | { |
| 4782 | Value *value = rhs.loadValue(); |
| 4783 | storeValue(value); |
| 4784 | |
| 4785 | return RValue<UInt2>(value); |
| 4786 | } |
| 4787 | |
| 4788 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4789 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4790 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4794 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4795 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4799 | // { |
| 4800 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4801 | // } |
| 4802 | |
| 4803 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4804 | // { |
| 4805 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4806 | // } |
| 4807 | |
| 4808 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4809 | // { |
| 4810 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4811 | // } |
| 4812 | |
| 4813 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4814 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4815 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4819 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4820 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4824 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4825 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4829 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4830 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4834 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4835 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4836 | } |
| 4837 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4838 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4839 | { |
| 4840 | return lhs = lhs + rhs; |
| 4841 | } |
| 4842 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4843 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4844 | { |
| 4845 | return lhs = lhs - rhs; |
| 4846 | } |
| 4847 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4848 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4849 | // { |
| 4850 | // return lhs = lhs * rhs; |
| 4851 | // } |
| 4852 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4853 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4854 | // { |
| 4855 | // return lhs = lhs / rhs; |
| 4856 | // } |
| 4857 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4858 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4859 | // { |
| 4860 | // return lhs = lhs % rhs; |
| 4861 | // } |
| 4862 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4863 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4864 | { |
| 4865 | return lhs = lhs & rhs; |
| 4866 | } |
| 4867 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4868 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4869 | { |
| 4870 | return lhs = lhs | rhs; |
| 4871 | } |
| 4872 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4873 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4874 | { |
| 4875 | return lhs = lhs ^ rhs; |
| 4876 | } |
| 4877 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4878 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4879 | { |
| 4880 | return lhs = lhs << rhs; |
| 4881 | } |
| 4882 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4883 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4884 | { |
| 4885 | return lhs = lhs >> rhs; |
| 4886 | } |
| 4887 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4888 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4889 | // { |
| 4890 | // return val; |
| 4891 | // } |
| 4892 | |
| 4893 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4894 | // { |
| 4895 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4896 | // } |
| 4897 | |
| 4898 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4899 | { |
| 4900 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4901 | } |
| 4902 | |
| 4903 | Type *UInt2::getType() |
| 4904 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4905 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | Int4::Int4(RValue<Byte4> cast) |
| 4909 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4910 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4911 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4912 | |
| 4913 | Value *e; |
| 4914 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4915 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4916 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4917 | |
| 4918 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4919 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4920 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4921 | |
| 4922 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4923 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | Int4::Int4(RValue<SByte4> cast) |
| 4927 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4928 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4929 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4930 | |
| 4931 | Value *e; |
| 4932 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4933 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4934 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4935 | |
| 4936 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4937 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4938 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 4939 | |
| 4940 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4941 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4942 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | Int4::Int4(RValue<Float4> cast) |
| 4946 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4947 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 4948 | |
| 4949 | storeValue(xyzw); |
| 4950 | } |
| 4951 | |
| 4952 | Int4::Int4(RValue<Short4> cast) |
| 4953 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4954 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4955 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 4956 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4957 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4958 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | Int4::Int4(RValue<UShort4> cast) |
| 4962 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4963 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4964 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 4965 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 4966 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4967 | } |
| 4968 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4969 | Int4::Int4(int xyzw) |
| 4970 | { |
| 4971 | constant(xyzw, xyzw, xyzw, xyzw); |
| 4972 | } |
| 4973 | |
| 4974 | Int4::Int4(int x, int yzw) |
| 4975 | { |
| 4976 | constant(x, yzw, yzw, yzw); |
| 4977 | } |
| 4978 | |
| 4979 | Int4::Int4(int x, int y, int zw) |
| 4980 | { |
| 4981 | constant(x, y, zw, zw); |
| 4982 | } |
| 4983 | |
| 4984 | Int4::Int4(int x, int y, int z, int w) |
| 4985 | { |
| 4986 | constant(x, y, z, w); |
| 4987 | } |
| 4988 | |
| 4989 | void Int4::constant(int x, int y, int z, int w) |
| 4990 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4991 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4992 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | Int4::Int4(RValue<Int4> rhs) |
| 4996 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4997 | storeValue(rhs.value); |
| 4998 | } |
| 4999 | |
| 5000 | Int4::Int4(const Int4 &rhs) |
| 5001 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5002 | Value *value = rhs.loadValue(); |
| 5003 | storeValue(value); |
| 5004 | } |
| 5005 | |
| 5006 | Int4::Int4(const Reference<Int4> &rhs) |
| 5007 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5008 | Value *value = rhs.loadValue(); |
| 5009 | storeValue(value); |
| 5010 | } |
| 5011 | |
| 5012 | Int4::Int4(RValue<UInt4> rhs) |
| 5013 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5014 | storeValue(rhs.value); |
| 5015 | } |
| 5016 | |
| 5017 | Int4::Int4(const UInt4 &rhs) |
| 5018 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5019 | Value *value = rhs.loadValue(); |
| 5020 | storeValue(value); |
| 5021 | } |
| 5022 | |
| 5023 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5024 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5025 | Value *value = rhs.loadValue(); |
| 5026 | storeValue(value); |
| 5027 | } |
| 5028 | |
| 5029 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5030 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5031 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5032 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5033 | |
| 5034 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | Int4::Int4(RValue<Int> rhs) |
| 5038 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5039 | Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5040 | |
| 5041 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5042 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5043 | |
| 5044 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | Int4::Int4(const Int &rhs) |
| 5048 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5049 | *this = RValue<Int>(rhs.loadValue()); |
| 5050 | } |
| 5051 | |
| 5052 | Int4::Int4(const Reference<Int> &rhs) |
| 5053 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5054 | *this = RValue<Int>(rhs.loadValue()); |
| 5055 | } |
| 5056 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5057 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5058 | { |
| 5059 | storeValue(rhs.value); |
| 5060 | |
| 5061 | return rhs; |
| 5062 | } |
| 5063 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5064 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5065 | { |
| 5066 | Value *value = rhs.loadValue(); |
| 5067 | storeValue(value); |
| 5068 | |
| 5069 | return RValue<Int4>(value); |
| 5070 | } |
| 5071 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5072 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5073 | { |
| 5074 | Value *value = rhs.loadValue(); |
| 5075 | storeValue(value); |
| 5076 | |
| 5077 | return RValue<Int4>(value); |
| 5078 | } |
| 5079 | |
| 5080 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5081 | { |
| 5082 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5083 | } |
| 5084 | |
| 5085 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5086 | { |
| 5087 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5088 | } |
| 5089 | |
| 5090 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5091 | { |
| 5092 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5093 | } |
| 5094 | |
| 5095 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5096 | { |
| 5097 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5098 | } |
| 5099 | |
| 5100 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5101 | { |
| 5102 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5103 | } |
| 5104 | |
| 5105 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5106 | { |
| 5107 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5108 | } |
| 5109 | |
| 5110 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5111 | { |
| 5112 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5113 | } |
| 5114 | |
| 5115 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5116 | { |
| 5117 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5118 | } |
| 5119 | |
| 5120 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5121 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5122 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5126 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5127 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5131 | { |
| 5132 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5133 | } |
| 5134 | |
| 5135 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5136 | { |
| 5137 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5138 | } |
| 5139 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5140 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5141 | { |
| 5142 | return lhs = lhs + rhs; |
| 5143 | } |
| 5144 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5145 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5146 | { |
| 5147 | return lhs = lhs - rhs; |
| 5148 | } |
| 5149 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5150 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5151 | { |
| 5152 | return lhs = lhs * rhs; |
| 5153 | } |
| 5154 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5155 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5156 | // { |
| 5157 | // return lhs = lhs / rhs; |
| 5158 | // } |
| 5159 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5160 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5161 | // { |
| 5162 | // return lhs = lhs % rhs; |
| 5163 | // } |
| 5164 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5165 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5166 | { |
| 5167 | return lhs = lhs & rhs; |
| 5168 | } |
| 5169 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5170 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5171 | { |
| 5172 | return lhs = lhs | rhs; |
| 5173 | } |
| 5174 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5175 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5176 | { |
| 5177 | return lhs = lhs ^ rhs; |
| 5178 | } |
| 5179 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5180 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5181 | { |
| 5182 | return lhs = lhs << rhs; |
| 5183 | } |
| 5184 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5185 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5186 | { |
| 5187 | return lhs = lhs >> rhs; |
| 5188 | } |
| 5189 | |
| 5190 | RValue<Int4> operator+(RValue<Int4> val) |
| 5191 | { |
| 5192 | return val; |
| 5193 | } |
| 5194 | |
| 5195 | RValue<Int4> operator-(RValue<Int4> val) |
| 5196 | { |
| 5197 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5198 | } |
| 5199 | |
| 5200 | RValue<Int4> operator~(RValue<Int4> val) |
| 5201 | { |
| 5202 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5203 | } |
| 5204 | |
| 5205 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5206 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5207 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5211 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5212 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5216 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5217 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5221 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5222 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5226 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5227 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5231 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5232 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | RValue<Int4> Max(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::Sle, 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> Min(RValue<Int4> x, RValue<Int4> y) |
| 5249 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5250 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5251 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5252 | ::basicBlock->appendInst(cmp); |
| 5253 | |
| 5254 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5255 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5256 | ::basicBlock->appendInst(select); |
| 5257 | |
| 5258 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5262 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5263 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5264 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5265 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5266 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5267 | nearbyint->addArg(cast.value); |
| 5268 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5269 | |
| 5270 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5274 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5275 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5276 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5277 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5278 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5279 | pack->addArg(x.value); |
| 5280 | pack->addArg(y.value); |
| 5281 | ::basicBlock->appendInst(pack); |
| 5282 | |
| 5283 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5287 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5288 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5292 | { |
| 5293 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5294 | } |
| 5295 | |
| 5296 | RValue<Int> SignMask(RValue<Int4> x) |
| 5297 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5298 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5299 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5300 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5301 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5302 | movmsk->addArg(x.value); |
| 5303 | ::basicBlock->appendInst(movmsk); |
| 5304 | |
| 5305 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5309 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5310 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | Type *Int4::getType() |
| 5314 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5315 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | UInt4::UInt4(RValue<Float4> cast) |
| 5319 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5320 | // Smallest positive value representable in UInt, but not in Int |
| 5321 | const unsigned int ustart = 0x80000000u; |
| 5322 | const float ustartf = float(ustart); |
| 5323 | |
| 5324 | // Check if the value can be represented as an Int |
| 5325 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5326 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5327 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5328 | // Otherwise, just convert normally |
| 5329 | (~uiValue & Int4(cast)); |
| 5330 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5331 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5332 | } |
| 5333 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5334 | UInt4::UInt4(int xyzw) |
| 5335 | { |
| 5336 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5337 | } |
| 5338 | |
| 5339 | UInt4::UInt4(int x, int yzw) |
| 5340 | { |
| 5341 | constant(x, yzw, yzw, yzw); |
| 5342 | } |
| 5343 | |
| 5344 | UInt4::UInt4(int x, int y, int zw) |
| 5345 | { |
| 5346 | constant(x, y, zw, zw); |
| 5347 | } |
| 5348 | |
| 5349 | UInt4::UInt4(int x, int y, int z, int w) |
| 5350 | { |
| 5351 | constant(x, y, z, w); |
| 5352 | } |
| 5353 | |
| 5354 | void UInt4::constant(int x, int y, int z, int w) |
| 5355 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5356 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5357 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5361 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5362 | storeValue(rhs.value); |
| 5363 | } |
| 5364 | |
| 5365 | UInt4::UInt4(const UInt4 &rhs) |
| 5366 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5367 | Value *value = rhs.loadValue(); |
| 5368 | storeValue(value); |
| 5369 | } |
| 5370 | |
| 5371 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5372 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5373 | Value *value = rhs.loadValue(); |
| 5374 | storeValue(value); |
| 5375 | } |
| 5376 | |
| 5377 | UInt4::UInt4(RValue<Int4> rhs) |
| 5378 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5379 | storeValue(rhs.value); |
| 5380 | } |
| 5381 | |
| 5382 | UInt4::UInt4(const Int4 &rhs) |
| 5383 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5384 | Value *value = rhs.loadValue(); |
| 5385 | storeValue(value); |
| 5386 | } |
| 5387 | |
| 5388 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5389 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5390 | Value *value = rhs.loadValue(); |
| 5391 | storeValue(value); |
| 5392 | } |
| 5393 | |
| 5394 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5395 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5396 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5397 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5398 | |
| 5399 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5400 | } |
| 5401 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5402 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5403 | { |
| 5404 | storeValue(rhs.value); |
| 5405 | |
| 5406 | return rhs; |
| 5407 | } |
| 5408 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5409 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5410 | { |
| 5411 | Value *value = rhs.loadValue(); |
| 5412 | storeValue(value); |
| 5413 | |
| 5414 | return RValue<UInt4>(value); |
| 5415 | } |
| 5416 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5417 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5418 | { |
| 5419 | Value *value = rhs.loadValue(); |
| 5420 | storeValue(value); |
| 5421 | |
| 5422 | return RValue<UInt4>(value); |
| 5423 | } |
| 5424 | |
| 5425 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5426 | { |
| 5427 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5428 | } |
| 5429 | |
| 5430 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5431 | { |
| 5432 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5433 | } |
| 5434 | |
| 5435 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5436 | { |
| 5437 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5438 | } |
| 5439 | |
| 5440 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5441 | { |
| 5442 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5443 | } |
| 5444 | |
| 5445 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5446 | { |
| 5447 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5448 | } |
| 5449 | |
| 5450 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5451 | { |
| 5452 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5453 | } |
| 5454 | |
| 5455 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5456 | { |
| 5457 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5458 | } |
| 5459 | |
| 5460 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5461 | { |
| 5462 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5463 | } |
| 5464 | |
| 5465 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5466 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5467 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5471 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5472 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5473 | } |
| 5474 | |
| 5475 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5476 | { |
| 5477 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5478 | } |
| 5479 | |
| 5480 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5481 | { |
| 5482 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5483 | } |
| 5484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5485 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5486 | { |
| 5487 | return lhs = lhs + rhs; |
| 5488 | } |
| 5489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5490 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5491 | { |
| 5492 | return lhs = lhs - rhs; |
| 5493 | } |
| 5494 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5495 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5496 | { |
| 5497 | return lhs = lhs * rhs; |
| 5498 | } |
| 5499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5500 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5501 | // { |
| 5502 | // return lhs = lhs / rhs; |
| 5503 | // } |
| 5504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5505 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5506 | // { |
| 5507 | // return lhs = lhs % rhs; |
| 5508 | // } |
| 5509 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5510 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5511 | { |
| 5512 | return lhs = lhs & rhs; |
| 5513 | } |
| 5514 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5515 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5516 | { |
| 5517 | return lhs = lhs | rhs; |
| 5518 | } |
| 5519 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5520 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5521 | { |
| 5522 | return lhs = lhs ^ rhs; |
| 5523 | } |
| 5524 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5525 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5526 | { |
| 5527 | return lhs = lhs << rhs; |
| 5528 | } |
| 5529 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5530 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5531 | { |
| 5532 | return lhs = lhs >> rhs; |
| 5533 | } |
| 5534 | |
| 5535 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5536 | { |
| 5537 | return val; |
| 5538 | } |
| 5539 | |
| 5540 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5541 | { |
| 5542 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5543 | } |
| 5544 | |
| 5545 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5546 | { |
| 5547 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5548 | } |
| 5549 | |
| 5550 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5551 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5552 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5556 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5557 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5561 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5562 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5566 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5567 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5571 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5572 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5576 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5577 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | RValue<UInt4> Max(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::Ule, 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<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5594 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5595 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5596 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5597 | ::basicBlock->appendInst(cmp); |
| 5598 | |
| 5599 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5600 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5601 | ::basicBlock->appendInst(select); |
| 5602 | |
| 5603 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5607 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5608 | if(CPUID::SSE4_1) |
| 5609 | { |
| 5610 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5611 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5612 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5613 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5614 | pack->addArg(x.value); |
| 5615 | pack->addArg(y.value); |
| 5616 | ::basicBlock->appendInst(pack); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5617 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5618 | return RValue<UShort8>(V(result)); |
| 5619 | } |
| 5620 | else |
| 5621 | { |
| 5622 | RValue<Int4> sx = As<Int4>(x); |
| 5623 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 5624 | |
| 5625 | RValue<Int4> sy = As<Int4>(y); |
| 5626 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 5627 | |
| 5628 | return As<UShort8>(Pack(bx, by) + Short8(0x8000u)); |
| 5629 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | Type *UInt4::getType() |
| 5633 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5634 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | Float::Float(RValue<Int> cast) |
| 5638 | { |
| 5639 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5640 | |
| 5641 | storeValue(integer); |
| 5642 | } |
| 5643 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5644 | Float::Float(float x) |
| 5645 | { |
| 5646 | storeValue(Nucleus::createConstantFloat(x)); |
| 5647 | } |
| 5648 | |
| 5649 | Float::Float(RValue<Float> rhs) |
| 5650 | { |
| 5651 | storeValue(rhs.value); |
| 5652 | } |
| 5653 | |
| 5654 | Float::Float(const Float &rhs) |
| 5655 | { |
| 5656 | Value *value = rhs.loadValue(); |
| 5657 | storeValue(value); |
| 5658 | } |
| 5659 | |
| 5660 | Float::Float(const Reference<Float> &rhs) |
| 5661 | { |
| 5662 | Value *value = rhs.loadValue(); |
| 5663 | storeValue(value); |
| 5664 | } |
| 5665 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5666 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5667 | { |
| 5668 | storeValue(rhs.value); |
| 5669 | |
| 5670 | return rhs; |
| 5671 | } |
| 5672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5673 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5674 | { |
| 5675 | Value *value = rhs.loadValue(); |
| 5676 | storeValue(value); |
| 5677 | |
| 5678 | return RValue<Float>(value); |
| 5679 | } |
| 5680 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5681 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5682 | { |
| 5683 | Value *value = rhs.loadValue(); |
| 5684 | storeValue(value); |
| 5685 | |
| 5686 | return RValue<Float>(value); |
| 5687 | } |
| 5688 | |
| 5689 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5690 | { |
| 5691 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5692 | } |
| 5693 | |
| 5694 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5695 | { |
| 5696 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5697 | } |
| 5698 | |
| 5699 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5700 | { |
| 5701 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5702 | } |
| 5703 | |
| 5704 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5705 | { |
| 5706 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5707 | } |
| 5708 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5709 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5710 | { |
| 5711 | return lhs = lhs + rhs; |
| 5712 | } |
| 5713 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5714 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5715 | { |
| 5716 | return lhs = lhs - rhs; |
| 5717 | } |
| 5718 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5719 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5720 | { |
| 5721 | return lhs = lhs * rhs; |
| 5722 | } |
| 5723 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5724 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5725 | { |
| 5726 | return lhs = lhs / rhs; |
| 5727 | } |
| 5728 | |
| 5729 | RValue<Float> operator+(RValue<Float> val) |
| 5730 | { |
| 5731 | return val; |
| 5732 | } |
| 5733 | |
| 5734 | RValue<Float> operator-(RValue<Float> val) |
| 5735 | { |
| 5736 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5737 | } |
| 5738 | |
| 5739 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5740 | { |
| 5741 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5742 | } |
| 5743 | |
| 5744 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5745 | { |
| 5746 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5747 | } |
| 5748 | |
| 5749 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5750 | { |
| 5751 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5752 | } |
| 5753 | |
| 5754 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5755 | { |
| 5756 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5757 | } |
| 5758 | |
| 5759 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5760 | { |
| 5761 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5762 | } |
| 5763 | |
| 5764 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5765 | { |
| 5766 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5767 | } |
| 5768 | |
| 5769 | RValue<Float> Abs(RValue<Float> x) |
| 5770 | { |
| 5771 | return IfThenElse(x > 0.0f, x, -x); |
| 5772 | } |
| 5773 | |
| 5774 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5775 | { |
| 5776 | return IfThenElse(x > y, x, y); |
| 5777 | } |
| 5778 | |
| 5779 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5780 | { |
| 5781 | return IfThenElse(x < y, x, y); |
| 5782 | } |
| 5783 | |
| 5784 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5785 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5786 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5790 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5791 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | RValue<Float> Sqrt(RValue<Float> x) |
| 5795 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5796 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5797 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5798 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5799 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5800 | sqrt->addArg(x.value); |
| 5801 | ::basicBlock->appendInst(sqrt); |
| 5802 | |
| 5803 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | RValue<Float> Round(RValue<Float> x) |
| 5807 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5808 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | RValue<Float> Trunc(RValue<Float> x) |
| 5812 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5813 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | RValue<Float> Frac(RValue<Float> x) |
| 5817 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5818 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | RValue<Float> Floor(RValue<Float> x) |
| 5822 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5823 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | RValue<Float> Ceil(RValue<Float> x) |
| 5827 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5828 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | Type *Float::getType() |
| 5832 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5833 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | Float2::Float2(RValue<Float4> cast) |
| 5837 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5838 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | Type *Float2::getType() |
| 5842 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5843 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5844 | } |
| 5845 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5846 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5847 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5848 | Value *a = Int4(cast).loadValue(); |
| 5849 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5850 | |
| 5851 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5852 | } |
| 5853 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5854 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5855 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5856 | Value *a = Int4(cast).loadValue(); |
| 5857 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5858 | |
| 5859 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5860 | } |
| 5861 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5862 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5863 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5864 | Int4 c(cast); |
| 5865 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5866 | } |
| 5867 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5868 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5869 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5870 | Int4 c(cast); |
| 5871 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5872 | } |
| 5873 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5874 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5875 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5876 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5877 | |
| 5878 | storeValue(xyzw); |
| 5879 | } |
| 5880 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5881 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5882 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5883 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5884 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5885 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5886 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5887 | } |
| 5888 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5889 | Float4::Float4() : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5890 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5891 | } |
| 5892 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5893 | Float4::Float4(float xyzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5894 | { |
| 5895 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5896 | } |
| 5897 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5898 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5899 | { |
| 5900 | constant(x, yzw, yzw, yzw); |
| 5901 | } |
| 5902 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5903 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5904 | { |
| 5905 | constant(x, y, zw, zw); |
| 5906 | } |
| 5907 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5908 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5909 | { |
| 5910 | constant(x, y, z, w); |
| 5911 | } |
| 5912 | |
| 5913 | void Float4::constant(float x, float y, float z, float w) |
| 5914 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5915 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5916 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5917 | } |
| 5918 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5919 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5920 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5921 | storeValue(rhs.value); |
| 5922 | } |
| 5923 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5924 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5925 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5926 | Value *value = rhs.loadValue(); |
| 5927 | storeValue(value); |
| 5928 | } |
| 5929 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5930 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5931 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5932 | Value *value = rhs.loadValue(); |
| 5933 | storeValue(value); |
| 5934 | } |
| 5935 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5936 | Float4::Float4(RValue<Float> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5937 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5938 | Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5939 | |
| 5940 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5941 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5942 | |
| 5943 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5944 | } |
| 5945 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5946 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5947 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5948 | *this = RValue<Float>(rhs.loadValue()); |
| 5949 | } |
| 5950 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5951 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5952 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5953 | *this = RValue<Float>(rhs.loadValue()); |
| 5954 | } |
| 5955 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5956 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5957 | { |
| 5958 | return *this = Float4(x, x, x, x); |
| 5959 | } |
| 5960 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5961 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5962 | { |
| 5963 | storeValue(rhs.value); |
| 5964 | |
| 5965 | return rhs; |
| 5966 | } |
| 5967 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5968 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5969 | { |
| 5970 | Value *value = rhs.loadValue(); |
| 5971 | storeValue(value); |
| 5972 | |
| 5973 | return RValue<Float4>(value); |
| 5974 | } |
| 5975 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5976 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5977 | { |
| 5978 | Value *value = rhs.loadValue(); |
| 5979 | storeValue(value); |
| 5980 | |
| 5981 | return RValue<Float4>(value); |
| 5982 | } |
| 5983 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5984 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5985 | { |
| 5986 | return *this = Float4(rhs); |
| 5987 | } |
| 5988 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5989 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5990 | { |
| 5991 | return *this = Float4(rhs); |
| 5992 | } |
| 5993 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5994 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5995 | { |
| 5996 | return *this = Float4(rhs); |
| 5997 | } |
| 5998 | |
| 5999 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6000 | { |
| 6001 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6002 | } |
| 6003 | |
| 6004 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6005 | { |
| 6006 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6007 | } |
| 6008 | |
| 6009 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6010 | { |
| 6011 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6012 | } |
| 6013 | |
| 6014 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6015 | { |
| 6016 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6017 | } |
| 6018 | |
| 6019 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6020 | { |
| 6021 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6022 | } |
| 6023 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6024 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6025 | { |
| 6026 | return lhs = lhs + rhs; |
| 6027 | } |
| 6028 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6029 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6030 | { |
| 6031 | return lhs = lhs - rhs; |
| 6032 | } |
| 6033 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6034 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6035 | { |
| 6036 | return lhs = lhs * rhs; |
| 6037 | } |
| 6038 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6039 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6040 | { |
| 6041 | return lhs = lhs / rhs; |
| 6042 | } |
| 6043 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6044 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6045 | { |
| 6046 | return lhs = lhs % rhs; |
| 6047 | } |
| 6048 | |
| 6049 | RValue<Float4> operator+(RValue<Float4> val) |
| 6050 | { |
| 6051 | return val; |
| 6052 | } |
| 6053 | |
| 6054 | RValue<Float4> operator-(RValue<Float4> val) |
| 6055 | { |
| 6056 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6057 | } |
| 6058 | |
| 6059 | RValue<Float4> Abs(RValue<Float4> x) |
| 6060 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6061 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6062 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6063 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6064 | |
| 6065 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6066 | } |
| 6067 | |
| 6068 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6069 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6070 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6071 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ogt, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6072 | ::basicBlock->appendInst(cmp); |
| 6073 | |
| 6074 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6075 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6076 | ::basicBlock->appendInst(select); |
| 6077 | |
| 6078 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6082 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6083 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6084 | auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Olt, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6085 | ::basicBlock->appendInst(cmp); |
| 6086 | |
| 6087 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6088 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6089 | ::basicBlock->appendInst(select); |
| 6090 | |
| 6091 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6095 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6096 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6100 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6101 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6102 | } |
| 6103 | |
| 6104 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6105 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6106 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6107 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6108 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6109 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6110 | sqrt->addArg(x.value); |
| 6111 | ::basicBlock->appendInst(sqrt); |
| 6112 | |
| 6113 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6114 | } |
| 6115 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6116 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6117 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6118 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6122 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6123 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6127 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6128 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6132 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6133 | int shuffle[4] = |
| 6134 | { |
| 6135 | ((imm >> 0) & 0x03) + 0, |
| 6136 | ((imm >> 2) & 0x03) + 0, |
| 6137 | ((imm >> 4) & 0x03) + 4, |
| 6138 | ((imm >> 6) & 0x03) + 4, |
| 6139 | }; |
| 6140 | |
| 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> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6145 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6146 | int shuffle[4] = {0, 4, 1, 5}; |
| 6147 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6151 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6152 | int shuffle[4] = {2, 6, 3, 7}; |
| 6153 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6157 | { |
| 6158 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6159 | Value *result = createMask4(vector, rhs.value, select); |
| 6160 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6161 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6162 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | RValue<Int> SignMask(RValue<Float4> x) |
| 6166 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6167 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6168 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6169 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6170 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6171 | movmsk->addArg(x.value); |
| 6172 | ::basicBlock->appendInst(movmsk); |
| 6173 | |
| 6174 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6178 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6179 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6183 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6184 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6188 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6189 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6193 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6194 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6195 | } |
| 6196 | |
| 6197 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6198 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6199 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6203 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6204 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | RValue<Float4> Round(RValue<Float4> x) |
| 6208 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6209 | if(CPUID::SSE4_1) |
| 6210 | { |
| 6211 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6212 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6213 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6214 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6215 | round->addArg(x.value); |
| 6216 | round->addArg(::context->getConstantInt32(0)); |
| 6217 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6218 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6219 | return RValue<Float4>(V(result)); |
| 6220 | } |
| 6221 | else |
| 6222 | { |
| 6223 | return Float4(RoundInt(x)); |
| 6224 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6228 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6229 | if(CPUID::SSE4_1) |
| 6230 | { |
| 6231 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6232 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6233 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6234 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6235 | round->addArg(x.value); |
| 6236 | round->addArg(::context->getConstantInt32(3)); |
| 6237 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6238 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6239 | return RValue<Float4>(V(result)); |
| 6240 | } |
| 6241 | else |
| 6242 | { |
| 6243 | return Float4(Int4(x)); |
| 6244 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | RValue<Float4> Frac(RValue<Float4> x) |
| 6248 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6249 | if(CPUID::SSE4_1) |
| 6250 | { |
| 6251 | return x - Floor(x); |
| 6252 | } |
| 6253 | else |
| 6254 | { |
| 6255 | Float4 frc = x - Float4(Int4(x)); // Signed fractional part |
| 6256 | |
| 6257 | return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); |
| 6258 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | RValue<Float4> Floor(RValue<Float4> x) |
| 6262 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6263 | if(CPUID::SSE4_1) |
| 6264 | { |
| 6265 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6266 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6267 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6268 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6269 | round->addArg(x.value); |
| 6270 | round->addArg(::context->getConstantInt32(1)); |
| 6271 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6272 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6273 | return RValue<Float4>(V(result)); |
| 6274 | } |
| 6275 | else |
| 6276 | { |
| 6277 | return x - Frac(x); |
| 6278 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6282 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6283 | if(CPUID::SSE4_1) |
| 6284 | { |
| 6285 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6286 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6287 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6288 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6289 | round->addArg(x.value); |
| 6290 | round->addArg(::context->getConstantInt32(2)); |
| 6291 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6292 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6293 | return RValue<Float4>(V(result)); |
| 6294 | } |
| 6295 | else |
| 6296 | { |
| 6297 | return -Floor(-x); |
| 6298 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | Type *Float4::getType() |
| 6302 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6303 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6307 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6308 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6312 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6313 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6314 | } |
| 6315 | |
| 6316 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6317 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6318 | return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6319 | } |
| 6320 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6321 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6322 | { |
| 6323 | return lhs = lhs + offset; |
| 6324 | } |
| 6325 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6326 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6327 | { |
| 6328 | return lhs = lhs + offset; |
| 6329 | } |
| 6330 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6331 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6332 | { |
| 6333 | return lhs = lhs + offset; |
| 6334 | } |
| 6335 | |
| 6336 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6337 | { |
| 6338 | return lhs + -offset; |
| 6339 | } |
| 6340 | |
| 6341 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6342 | { |
| 6343 | return lhs + -offset; |
| 6344 | } |
| 6345 | |
| 6346 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6347 | { |
| 6348 | return lhs + -offset; |
| 6349 | } |
| 6350 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6351 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6352 | { |
| 6353 | return lhs = lhs - offset; |
| 6354 | } |
| 6355 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6356 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6357 | { |
| 6358 | return lhs = lhs - offset; |
| 6359 | } |
| 6360 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6361 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6362 | { |
| 6363 | return lhs = lhs - offset; |
| 6364 | } |
| 6365 | |
| 6366 | void Return() |
| 6367 | { |
| 6368 | Nucleus::createRetVoid(); |
| 6369 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6370 | Nucleus::createUnreachable(); |
| 6371 | } |
| 6372 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6373 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6374 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6375 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6376 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6377 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6378 | } |
| 6379 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6380 | bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
| 6381 | { |
| 6382 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6383 | Nucleus::setInsertBlock(bodyBB); |
| 6384 | |
| 6385 | return true; |
| 6386 | } |
| 6387 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6388 | RValue<Long> Ticks() |
| 6389 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6390 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6391 | } |
| 6392 | } |