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: |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 80 | const static bool ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 81 | const static bool SSE4_1; |
| 82 | |
| 83 | private: |
| 84 | static void cpuid(int registers[4], int info) |
| 85 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 86 | #if defined(__i386__) || defined(__x86_64__) |
| 87 | #if defined(_WIN32) |
| 88 | __cpuid(registers, info); |
| 89 | #else |
| 90 | __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); |
| 91 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 92 | #else |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 93 | registers[0] = 0; |
| 94 | registers[1] = 0; |
| 95 | registers[2] = 0; |
| 96 | registers[3] = 0; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 97 | #endif |
| 98 | } |
| 99 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 100 | static bool detectARM() |
| 101 | { |
| 102 | #if defined(__arm__) |
| 103 | return true; |
| 104 | #elif defined(__i386__) || defined(__x86_64__) |
| 105 | return false; |
| 106 | #else |
| 107 | #error "Unknown architecture" |
| 108 | #endif |
| 109 | } |
| 110 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 111 | static bool detectSSE4_1() |
| 112 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 113 | #if defined(__i386__) || defined(__x86_64__) |
| 114 | int registers[4]; |
| 115 | cpuid(registers, 1); |
| 116 | return (registers[2] & 0x00080000) != 0; |
| 117 | #else |
| 118 | return false; |
| 119 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 120 | } |
| 121 | }; |
| 122 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 123 | const bool CPUID::ARM = CPUID::detectARM(); |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 124 | const bool CPUID::SSE4_1 = CPUID::detectSSE4_1(); |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 125 | const bool emulateIntrinsics = CPUID::ARM; |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame] | 126 | const bool emulateMismatchedBitCast = CPUID::ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 129 | namespace sw |
| 130 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 131 | enum EmulatedType |
| 132 | { |
| 133 | EmulatedShift = 16, |
| 134 | EmulatedV2 = 2 << EmulatedShift, |
| 135 | EmulatedV4 = 4 << EmulatedShift, |
| 136 | EmulatedV8 = 8 << EmulatedShift, |
| 137 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 138 | |
| 139 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 140 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 141 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 142 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 143 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 144 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 145 | }; |
| 146 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 147 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 148 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 149 | class BasicBlock : public Ice::CfgNode {}; |
| 150 | |
| 151 | Ice::Type T(Type *t) |
| 152 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 153 | 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] | 154 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | Type *T(Ice::Type t) |
| 158 | { |
| 159 | return reinterpret_cast<Type*>(t); |
| 160 | } |
| 161 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 162 | Type *T(EmulatedType t) |
| 163 | { |
| 164 | return reinterpret_cast<Type*>(t); |
| 165 | } |
| 166 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 167 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 168 | { |
| 169 | return reinterpret_cast<Value*>(v); |
| 170 | } |
| 171 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 172 | BasicBlock *B(Ice::CfgNode *b) |
| 173 | { |
| 174 | return reinterpret_cast<BasicBlock*>(b); |
| 175 | } |
| 176 | |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 177 | static size_t typeSize(Type *type) |
| 178 | { |
| 179 | if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) |
| 180 | { |
| 181 | switch(reinterpret_cast<std::intptr_t>(type)) |
| 182 | { |
| 183 | case Type_v2i32: return 8; |
| 184 | case Type_v4i16: return 8; |
| 185 | case Type_v2i16: return 4; |
| 186 | case Type_v8i8: return 8; |
| 187 | case Type_v4i8: return 4; |
| 188 | case Type_v2f32: return 8; |
| 189 | default: assert(false); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return Ice::typeWidthInBytes(T(type)); |
| 194 | } |
| 195 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 196 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 197 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 198 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 199 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 200 | |
| 201 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 202 | { |
| 203 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 204 | } |
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 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 207 | { |
| 208 | return §ionHeader(elfHeader)[index]; |
| 209 | } |
| 210 | |
| 211 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 212 | { |
| 213 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 214 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 215 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 216 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 217 | uint32_t index = relocation.getSymbol(); |
| 218 | int table = relocationTable.sh_link; |
| 219 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 220 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 221 | if(index != SHN_UNDEF) |
| 222 | { |
| 223 | if(table == SHN_UNDEF) return nullptr; |
| 224 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 225 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 226 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 227 | if(index >= symtab_entries) |
| 228 | { |
| 229 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 230 | return nullptr; |
| 231 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 232 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 233 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 234 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 235 | uint16_t section = symbol.st_shndx; |
| 236 | |
| 237 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 238 | { |
| 239 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 240 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | return nullptr; |
| 245 | } |
| 246 | } |
| 247 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 248 | if(CPUID::ARM) |
| 249 | { |
| 250 | switch(relocation.getType()) |
| 251 | { |
| 252 | case R_ARM_NONE: |
| 253 | // No relocation |
| 254 | break; |
| 255 | case R_ARM_MOVW_ABS_NC: |
| 256 | { |
| 257 | uint32_t thumb = 0; // Calls to Thumb code not supported. |
| 258 | uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb; |
| 259 | *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF); |
| 260 | } |
| 261 | break; |
| 262 | case R_ARM_MOVT_ABS: |
| 263 | { |
| 264 | uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16; |
| 265 | *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF); |
| 266 | } |
| 267 | break; |
| 268 | default: |
| 269 | assert(false && "Unsupported relocation type"); |
| 270 | return nullptr; |
| 271 | } |
| 272 | } |
| 273 | else |
| 274 | { |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 275 | switch(relocation.getType()) |
| 276 | { |
| 277 | case R_386_NONE: |
| 278 | // No relocation |
| 279 | break; |
| 280 | case R_386_32: |
| 281 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 282 | break; |
| 283 | // case R_386_PC32: |
| 284 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 285 | // break; |
| 286 | default: |
| 287 | assert(false && "Unsupported relocation type"); |
| 288 | return nullptr; |
| 289 | } |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 290 | } |
| 291 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 292 | |
| 293 | return symbolValue; |
| 294 | } |
| 295 | |
| 296 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 297 | { |
| 298 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 299 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 300 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 301 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 302 | uint32_t index = relocation.getSymbol(); |
| 303 | int table = relocationTable.sh_link; |
| 304 | void *symbolValue = nullptr; |
| 305 | |
| 306 | if(index != SHN_UNDEF) |
| 307 | { |
| 308 | if(table == SHN_UNDEF) return nullptr; |
| 309 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 310 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 311 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 312 | if(index >= symtab_entries) |
| 313 | { |
| 314 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 315 | return nullptr; |
| 316 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 317 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 318 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 319 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 320 | uint16_t section = symbol.st_shndx; |
| 321 | |
| 322 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 323 | { |
| 324 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 325 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | return nullptr; |
| 330 | } |
| 331 | } |
| 332 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 333 | switch(relocation.getType()) |
| 334 | { |
| 335 | case R_X86_64_NONE: |
| 336 | // No relocation |
| 337 | break; |
| 338 | case R_X86_64_64: |
| 339 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 340 | break; |
| 341 | case R_X86_64_PC32: |
| 342 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 343 | break; |
| 344 | case R_X86_64_32S: |
| 345 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 346 | break; |
| 347 | default: |
| 348 | assert(false && "Unsupported relocation type"); |
| 349 | return nullptr; |
| 350 | } |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 351 | |
| 352 | return symbolValue; |
| 353 | } |
| 354 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 355 | void *loadImage(uint8_t *const elfImage, size_t &codeSize) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 356 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 357 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 358 | |
| 359 | if(!elfHeader->checkMagic()) |
| 360 | { |
| 361 | return nullptr; |
| 362 | } |
| 363 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 364 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 365 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 366 | #if defined(__i386__) |
| 367 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386); |
| 368 | #elif defined(__x86_64__) |
| 369 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64); |
| 370 | #elif defined(__arm__) |
| 371 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM); |
| 372 | #else |
| 373 | #error "Unsupported platform" |
| 374 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 375 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 376 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 377 | void *entry = nullptr; |
| 378 | |
| 379 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 380 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 381 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 382 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 383 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 384 | { |
| 385 | entry = elfImage + sectionHeader[i].sh_offset; |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 386 | codeSize = sectionHeader[i].sh_size; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 390 | { |
| 391 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 392 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 393 | 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] | 394 | { |
| 395 | 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] | 396 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 400 | { |
| 401 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 402 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 403 | 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] | 404 | { |
| 405 | 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] | 406 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 407 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
| 411 | return entry; |
| 412 | } |
| 413 | |
| 414 | template<typename T> |
| 415 | struct ExecutableAllocator |
| 416 | { |
| 417 | ExecutableAllocator() {}; |
| 418 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 419 | |
| 420 | using value_type = T; |
| 421 | using size_type = std::size_t; |
| 422 | |
| 423 | T *allocate(size_type n) |
| 424 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 425 | #if defined(_WIN32) |
| 426 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 427 | #else |
| 428 | return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 429 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void deallocate(T *p, size_type n) |
| 433 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 434 | #if defined(_WIN32) |
| 435 | VirtualFree(p, 0, MEM_RELEASE); |
| 436 | #else |
| 437 | munmap(p, sizeof(T) * n); |
| 438 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 439 | } |
| 440 | }; |
| 441 | |
| 442 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 443 | { |
| 444 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 445 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 446 | |
| 447 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 448 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 449 | { |
| 450 | position = 0; |
| 451 | buffer.reserve(0x1000); |
| 452 | } |
| 453 | |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 454 | ~ELFMemoryStreamer() override |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 455 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 456 | #if defined(_WIN32) |
| 457 | if(buffer.size() != 0) |
| 458 | { |
| 459 | DWORD exeProtection; |
| 460 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 461 | } |
| 462 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void write8(uint8_t Value) override |
| 466 | { |
| 467 | if(position == (uint64_t)buffer.size()) |
| 468 | { |
| 469 | buffer.push_back(Value); |
| 470 | position++; |
| 471 | } |
| 472 | else if(position < (uint64_t)buffer.size()) |
| 473 | { |
| 474 | buffer[position] = Value; |
| 475 | position++; |
| 476 | } |
| 477 | else assert(false && "UNIMPLEMENTED"); |
| 478 | } |
| 479 | |
| 480 | void writeBytes(llvm::StringRef Bytes) override |
| 481 | { |
| 482 | std::size_t oldSize = buffer.size(); |
| 483 | buffer.resize(oldSize + Bytes.size()); |
| 484 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 485 | position += Bytes.size(); |
| 486 | } |
| 487 | |
| 488 | uint64_t tell() const override { return position; } |
| 489 | |
| 490 | void seek(uint64_t Off) override { position = Off; } |
| 491 | |
| 492 | const void *getEntry() override |
| 493 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 494 | if(!entry) |
| 495 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 496 | 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] | 497 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 498 | size_t codeSize = 0; |
| 499 | entry = loadImage(&buffer[0], codeSize); |
| 500 | |
| 501 | #if defined(_WIN32) |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 502 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 503 | FlushInstructionCache(GetCurrentProcess(), NULL, 0); |
| 504 | #else |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 505 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 506 | __builtin___clear_cache((char*)entry, (char*)entry + codeSize); |
| 507 | #endif |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 514 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 515 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 516 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 517 | |
| 518 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 519 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 520 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | Nucleus::Nucleus() |
| 524 | { |
| 525 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 526 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 527 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 528 | Ice::ClFlags::getParsedClFlags(Flags); |
| 529 | |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 530 | #if defined(__arm__) |
| 531 | Flags.setTargetArch(Ice::Target_ARM32); |
| 532 | Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm); |
| 533 | #else // x86 |
| 534 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 535 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
| 536 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 537 | Flags.setOutFileType(Ice::FT_Elf); |
| 538 | Flags.setOptLevel(Ice::Opt_2); |
| 539 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 540 | Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None); |
| 541 | Flags.setDisableHybridAssembly(true); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 542 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 543 | static llvm::raw_os_ostream cout(std::cout); |
| 544 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 545 | |
| 546 | if(false) // Write out to a file |
| 547 | { |
| 548 | std::error_code errorCode; |
| 549 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 550 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 551 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 552 | } |
| 553 | else |
| 554 | { |
| 555 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 556 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 557 | ::routine = elfMemory; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | Nucleus::~Nucleus() |
| 562 | { |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 563 | delete ::routine; |
| 564 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 565 | delete ::allocator; |
| 566 | delete ::function; |
| 567 | delete ::context; |
| 568 | |
| 569 | delete ::elfFile; |
| 570 | delete ::out; |
| 571 | |
| 572 | ::codegenMutex.unlock(); |
| 573 | } |
| 574 | |
| 575 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 576 | { |
| 577 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 578 | { |
| 579 | createRetVoid(); |
| 580 | } |
| 581 | |
| 582 | std::wstring wideName(name); |
| 583 | std::string asciiName(wideName.begin(), wideName.end()); |
| 584 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 585 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 586 | optimize(); |
| 587 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 588 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 589 | assert(!::function->hasError()); |
| 590 | |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 591 | auto globals = ::function->getGlobalInits(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 592 | |
| 593 | if(globals && !globals->empty()) |
| 594 | { |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 595 | ::context->getGlobals()->merge(globals.get()); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 596 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 597 | |
| 598 | ::context->emitFileHeader(); |
| 599 | ::function->emitIAS(); |
| 600 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 601 | auto objectWriter = ::context->getObjectWriter(); |
| 602 | assembler->alignFunction(); |
| 603 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 604 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 605 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 606 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 607 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 608 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 609 | |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 610 | Routine *handoffRoutine = ::routine; |
| 611 | ::routine = nullptr; |
| 612 | |
| 613 | return handoffRoutine; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | void Nucleus::optimize() |
| 617 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 618 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 622 | { |
| 623 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 624 | int typeSize = Ice::typeWidthInBytes(type); |
| 625 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 626 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 627 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 628 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 629 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 630 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 631 | |
| 632 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | BasicBlock *Nucleus::createBasicBlock() |
| 636 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 637 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | BasicBlock *Nucleus::getInsertBlock() |
| 641 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 642 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 646 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 647 | // 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] | 648 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 651 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 652 | { |
| 653 | uint32_t sequenceNumber = 0; |
| 654 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 655 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 656 | |
| 657 | for(Type *type : Params) |
| 658 | { |
| 659 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 660 | ::function->addArg(arg); |
| 661 | } |
| 662 | |
| 663 | Ice::CfgNode *node = ::function->makeNode(); |
| 664 | ::function->setEntryNode(node); |
| 665 | ::basicBlock = node; |
| 666 | } |
| 667 | |
| 668 | Value *Nucleus::getArgument(unsigned int index) |
| 669 | { |
| 670 | return V(::function->getArgs()[index]); |
| 671 | } |
| 672 | |
| 673 | void Nucleus::createRetVoid() |
| 674 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 675 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 676 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void Nucleus::createRet(Value *v) |
| 680 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 681 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 682 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void Nucleus::createBr(BasicBlock *dest) |
| 686 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 687 | auto br = Ice::InstBr::create(::function, dest); |
| 688 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 692 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 693 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 694 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 695 | } |
| 696 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 697 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 698 | { |
| 699 | switch(op) |
| 700 | { |
| 701 | case Ice::InstArithmetic::Add: |
| 702 | case Ice::InstArithmetic::Fadd: |
| 703 | case Ice::InstArithmetic::Mul: |
| 704 | case Ice::InstArithmetic::Fmul: |
| 705 | case Ice::InstArithmetic::And: |
| 706 | case Ice::InstArithmetic::Or: |
| 707 | case Ice::InstArithmetic::Xor: |
| 708 | return true; |
| 709 | default: |
| 710 | return false; |
| 711 | } |
| 712 | } |
| 713 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 714 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 715 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 716 | 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] | 717 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 718 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 719 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 720 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 721 | 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] | 722 | ::basicBlock->appendInst(arithmetic); |
| 723 | |
| 724 | return V(result); |
| 725 | } |
| 726 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 727 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 728 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 729 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 733 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 734 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 738 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 739 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 743 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 744 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 748 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 749 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 753 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 754 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 758 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 759 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 763 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 764 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 768 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 769 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 773 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 774 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 778 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 779 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 783 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 784 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 788 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 789 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 793 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 794 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 798 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 799 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 803 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 804 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 808 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 809 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 813 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 814 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | Value *Nucleus::createNeg(Value *v) |
| 818 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 819 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | Value *Nucleus::createFNeg(Value *v) |
| 823 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 824 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 825 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 826 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 827 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 828 | |
| 829 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | Value *Nucleus::createNot(Value *v) |
| 833 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 834 | if(Ice::isScalarIntegerType(v->getType())) |
| 835 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 836 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 837 | } |
| 838 | else // Vector |
| 839 | { |
Nicolas Capens | f34d1ac | 2017-05-08 17:06:11 -0400 | [diff] [blame] | 840 | int64_t c[16] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 841 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 842 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 843 | } |
| 844 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 845 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 846 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 847 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 848 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 849 | |
| 850 | if(valueType & EmulatedBits) |
| 851 | { |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 852 | if(emulateIntrinsics) |
| 853 | { |
| 854 | if(typeSize(type) == 4) |
| 855 | { |
| 856 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 857 | Int x = *Pointer<Int>(pointer +1-1); |
| 858 | |
| 859 | Int4 vector; |
| 860 | vector = Insert(vector, x, 0); |
| 861 | |
| 862 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue()); |
| 863 | ::basicBlock->appendInst(bitcast); |
| 864 | } |
| 865 | else if(typeSize(type) == 8) |
| 866 | { |
| 867 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 868 | Int x = *Pointer<Int>(pointer +1-1); |
| 869 | Int y = *Pointer<Int>(pointer + 4); |
| 870 | |
| 871 | Int4 vector; |
| 872 | vector = Insert(vector, x, 0); |
| 873 | vector = Insert(vector, y, 1); |
| 874 | |
| 875 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue()); |
| 876 | ::basicBlock->appendInst(bitcast); |
| 877 | } |
| 878 | else assert(false); |
| 879 | } |
| 880 | else |
| 881 | { |
| 882 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 883 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 884 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 885 | load->addArg(ptr); |
| 886 | load->addArg(::context->getConstantInt32(typeSize(type))); |
| 887 | ::basicBlock->appendInst(load); |
| 888 | } |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 889 | } |
| 890 | else |
| 891 | { |
| 892 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 893 | ::basicBlock->appendInst(load); |
| 894 | } |
| 895 | |
| 896 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 897 | } |
| 898 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 899 | 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] | 900 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 901 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 902 | |
| 903 | if(valueType & EmulatedBits) |
| 904 | { |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 905 | if(emulateIntrinsics) |
| 906 | { |
| 907 | if(typeSize(type) == 4) |
| 908 | { |
| 909 | Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32); |
| 910 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value); |
| 911 | ::basicBlock->appendInst(bitcast); |
| 912 | |
| 913 | RValue<Int4> v(V(vector)); |
| 914 | |
| 915 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 916 | Int x = Extract(v, 0); |
| 917 | *Pointer<Int>(pointer) = x; |
| 918 | } |
| 919 | else if(typeSize(type) == 8) |
| 920 | { |
| 921 | Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32); |
| 922 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value); |
| 923 | ::basicBlock->appendInst(bitcast); |
| 924 | |
| 925 | RValue<Int4> v(V(vector)); |
| 926 | |
| 927 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 928 | Int x = Extract(v, 0); |
| 929 | *Pointer<Int>(pointer) = x; |
| 930 | Int y = Extract(v, 1); |
| 931 | *Pointer<Int>(pointer + 4) = y; |
| 932 | } |
| 933 | else assert(false); |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 938 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 939 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
| 940 | store->addArg(value); |
| 941 | store->addArg(ptr); |
| 942 | store->addArg(::context->getConstantInt32(typeSize(type))); |
| 943 | ::basicBlock->appendInst(store); |
| 944 | } |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 945 | } |
| 946 | else |
| 947 | { |
| 948 | assert(T(value->getType()) == type); |
| 949 | |
| 950 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 951 | ::basicBlock->appendInst(store); |
| 952 | } |
| 953 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 954 | return value; |
| 955 | } |
| 956 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 957 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 958 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 959 | assert(index->getType() == Ice::IceType_i32); |
| 960 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 961 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 962 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 963 | int32_t offset = constant->getValue() * (int)typeSize(type); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 964 | |
| 965 | if(offset == 0) |
| 966 | { |
| 967 | return ptr; |
| 968 | } |
| 969 | |
| 970 | return createAdd(ptr, createConstantInt(offset)); |
| 971 | } |
| 972 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 973 | if(!Ice::isByteSizedType(T(type))) |
| 974 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 975 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | if(sizeof(void*) == 8) |
| 979 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 980 | if(unsignedIndex) |
| 981 | { |
| 982 | index = createZExt(index, T(Ice::IceType_i64)); |
| 983 | } |
| 984 | else |
| 985 | { |
| 986 | index = createSExt(index, T(Ice::IceType_i64)); |
| 987 | } |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 994 | { |
| 995 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 996 | } |
| 997 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 998 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 999 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 1000 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1001 | { |
| 1002 | return v; |
| 1003 | } |
| 1004 | |
| 1005 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 1006 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 1007 | ::basicBlock->appendInst(cast); |
| 1008 | |
| 1009 | return V(result); |
| 1010 | } |
| 1011 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1012 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 1013 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1014 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 1018 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1019 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 1023 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1024 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 1028 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1029 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1032 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 1033 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1034 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 1038 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1039 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 1043 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1044 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 1048 | { |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame] | 1049 | // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need |
| 1050 | // support for casting between scalars and wide vectors. For platforms where this is not supported, |
| 1051 | // emulate them by writing to the stack and reading back as the destination type. |
| 1052 | if(emulateMismatchedBitCast) |
| 1053 | { |
| 1054 | if(!Ice::isVectorType(v->getType()) && Ice::isVectorType(T(destType))) |
| 1055 | { |
| 1056 | Value *address = allocateStackVariable(destType); |
| 1057 | createStore(v, address, T(v->getType())); |
| 1058 | return createLoad(address, destType); |
| 1059 | } |
| 1060 | else if(Ice::isVectorType(v->getType()) && !Ice::isVectorType(T(destType))) |
| 1061 | { |
| 1062 | Value *address = allocateStackVariable(T(v->getType())); |
| 1063 | createStore(v, address, T(v->getType())); |
| 1064 | return createLoad(address, destType); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1068 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1071 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1072 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1073 | assert(lhs->getType() == rhs->getType()); |
| 1074 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1075 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 1076 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1077 | ::basicBlock->appendInst(cmp); |
| 1078 | |
| 1079 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1082 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 1083 | { |
| 1084 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 1085 | } |
| 1086 | |
| 1087 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 1088 | { |
| 1089 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 1090 | } |
| 1091 | |
| 1092 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 1093 | { |
| 1094 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 1095 | } |
| 1096 | |
| 1097 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 1098 | { |
| 1099 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 1100 | } |
| 1101 | |
| 1102 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 1103 | { |
| 1104 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 1105 | } |
| 1106 | |
| 1107 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 1108 | { |
| 1109 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 1110 | } |
| 1111 | |
| 1112 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 1113 | { |
| 1114 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 1115 | } |
| 1116 | |
| 1117 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 1118 | { |
| 1119 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 1120 | } |
| 1121 | |
| 1122 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 1123 | { |
| 1124 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 1125 | } |
| 1126 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1127 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 1128 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1129 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 1130 | } |
| 1131 | |
| 1132 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 1133 | { |
| 1134 | assert(lhs->getType() == rhs->getType()); |
| 1135 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 1136 | |
| 1137 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 1138 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 1139 | ::basicBlock->appendInst(cmp); |
| 1140 | |
| 1141 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 1145 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1146 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1150 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1151 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1155 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1156 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1160 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1161 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1165 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1166 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1170 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1171 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1175 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1176 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1180 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1181 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1185 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1186 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1190 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1191 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1195 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1196 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1200 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1201 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1205 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1206 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1210 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1211 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1214 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1215 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1216 | auto result = ::function->makeVariable(T(type)); |
| 1217 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1218 | ::basicBlock->appendInst(extract); |
| 1219 | |
| 1220 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1224 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1225 | auto result = ::function->makeVariable(vector->getType()); |
| 1226 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1227 | ::basicBlock->appendInst(insert); |
| 1228 | |
| 1229 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1232 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1233 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1234 | assert(V1->getType() == V2->getType()); |
| 1235 | |
| 1236 | int size = Ice::typeNumElements(V1->getType()); |
| 1237 | auto result = ::function->makeVariable(V1->getType()); |
| 1238 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1239 | |
| 1240 | for(int i = 0; i < size; i++) |
| 1241 | { |
| 1242 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1243 | } |
| 1244 | |
| 1245 | ::basicBlock->appendInst(shuffle); |
| 1246 | |
| 1247 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1251 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1252 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1253 | |
| 1254 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1255 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1256 | ::basicBlock->appendInst(select); |
| 1257 | |
| 1258 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1261 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1262 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1263 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1264 | ::basicBlock->appendInst(switchInst); |
| 1265 | |
| 1266 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1269 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1270 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1271 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | void Nucleus::createUnreachable() |
| 1275 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1276 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1277 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1280 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1281 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1282 | int swizzle[4] = |
| 1283 | { |
| 1284 | (select >> 0) & 0x03, |
| 1285 | (select >> 2) & 0x03, |
| 1286 | (select >> 4) & 0x03, |
| 1287 | (select >> 6) & 0x03, |
| 1288 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1289 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1290 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1293 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1294 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1295 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1296 | |
| 1297 | mask[(select >> 0) & 0x03] = -1; |
| 1298 | mask[(select >> 2) & 0x03] = -1; |
| 1299 | mask[(select >> 4) & 0x03] = -1; |
| 1300 | mask[(select >> 6) & 0x03] = -1; |
| 1301 | |
| 1302 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1303 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1304 | |
| 1305 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1306 | } |
| 1307 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1308 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1309 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1310 | if(sizeof(void*) == 8) |
| 1311 | { |
| 1312 | return T(Ice::IceType_i64); |
| 1313 | } |
| 1314 | else |
| 1315 | { |
| 1316 | return T(Ice::IceType_i32); |
| 1317 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1320 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1321 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1322 | if(Ice::isVectorType(T(Ty))) |
| 1323 | { |
Nicolas Capens | 30385f0 | 2017-04-18 13:03:47 -0400 | [diff] [blame] | 1324 | assert(Ice::typeNumElements(T(Ty)) <= 16); |
| 1325 | 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] | 1326 | return createConstantVector(c, Ty); |
| 1327 | } |
| 1328 | else |
| 1329 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1330 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1331 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1334 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1335 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1336 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1337 | } |
| 1338 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1339 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1340 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1341 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1344 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1345 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1346 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1349 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1350 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1351 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1354 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1355 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1356 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1357 | } |
| 1358 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1359 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1360 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1361 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1362 | } |
| 1363 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1364 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1365 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1366 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1369 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1370 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1371 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1372 | } |
| 1373 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1374 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1375 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1376 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1379 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1380 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1381 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1384 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1385 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1386 | const int vectorSize = 16; |
| 1387 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1388 | const int alignment = vectorSize; |
| 1389 | auto globalPool = ::function->getGlobalPool(); |
| 1390 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1391 | const int64_t *i = constants; |
| 1392 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1393 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1394 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1395 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1396 | { |
| 1397 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1398 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1399 | { |
| 1400 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1401 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1402 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1403 | } |
| 1404 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1405 | case Ice::IceType_v4f32: |
| 1406 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1407 | 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] | 1408 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1409 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1410 | } |
| 1411 | break; |
| 1412 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1413 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1414 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1415 | 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] | 1416 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1417 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1418 | } |
| 1419 | break; |
| 1420 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1421 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1422 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1423 | 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] | 1424 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1425 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1426 | } |
| 1427 | break; |
| 1428 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1429 | { |
| 1430 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1431 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1432 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1433 | } |
| 1434 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1435 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1436 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1437 | 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] | 1438 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1439 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1440 | } |
| 1441 | break; |
| 1442 | case Type_v4i16: |
| 1443 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1444 | 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] | 1445 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1446 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1447 | } |
| 1448 | break; |
| 1449 | case Type_v8i8: |
| 1450 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1451 | 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] | 1452 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1453 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1454 | } |
| 1455 | break; |
| 1456 | case Type_v4i8: |
| 1457 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1458 | 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] | 1459 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1460 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1461 | } |
| 1462 | break; |
| 1463 | default: |
| 1464 | assert(false && "Unknown constant vector type" && type); |
| 1465 | } |
| 1466 | |
| 1467 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1468 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1469 | variableDeclaration->setName(name); |
| 1470 | variableDeclaration->setAlignment(alignment); |
| 1471 | variableDeclaration->setIsConstant(true); |
| 1472 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1473 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1474 | ::function->addGlobal(variableDeclaration); |
| 1475 | |
| 1476 | constexpr int32_t offset = 0; |
| 1477 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1478 | |
| 1479 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1480 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1481 | ::basicBlock->appendInst(load); |
| 1482 | |
| 1483 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1487 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1488 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | Type *Void::getType() |
| 1492 | { |
| 1493 | return T(Ice::IceType_void); |
| 1494 | } |
| 1495 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1496 | Bool::Bool(Argument<Bool> argument) |
| 1497 | { |
| 1498 | storeValue(argument.value); |
| 1499 | } |
| 1500 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1501 | Bool::Bool(bool x) |
| 1502 | { |
| 1503 | storeValue(Nucleus::createConstantBool(x)); |
| 1504 | } |
| 1505 | |
| 1506 | Bool::Bool(RValue<Bool> rhs) |
| 1507 | { |
| 1508 | storeValue(rhs.value); |
| 1509 | } |
| 1510 | |
| 1511 | Bool::Bool(const Bool &rhs) |
| 1512 | { |
| 1513 | Value *value = rhs.loadValue(); |
| 1514 | storeValue(value); |
| 1515 | } |
| 1516 | |
| 1517 | Bool::Bool(const Reference<Bool> &rhs) |
| 1518 | { |
| 1519 | Value *value = rhs.loadValue(); |
| 1520 | storeValue(value); |
| 1521 | } |
| 1522 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1523 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1524 | { |
| 1525 | storeValue(rhs.value); |
| 1526 | |
| 1527 | return rhs; |
| 1528 | } |
| 1529 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1530 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1531 | { |
| 1532 | Value *value = rhs.loadValue(); |
| 1533 | storeValue(value); |
| 1534 | |
| 1535 | return RValue<Bool>(value); |
| 1536 | } |
| 1537 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1538 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1539 | { |
| 1540 | Value *value = rhs.loadValue(); |
| 1541 | storeValue(value); |
| 1542 | |
| 1543 | return RValue<Bool>(value); |
| 1544 | } |
| 1545 | |
| 1546 | RValue<Bool> operator!(RValue<Bool> val) |
| 1547 | { |
| 1548 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1549 | } |
| 1550 | |
| 1551 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1552 | { |
| 1553 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1554 | } |
| 1555 | |
| 1556 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1557 | { |
| 1558 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1559 | } |
| 1560 | |
| 1561 | Type *Bool::getType() |
| 1562 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1563 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | Byte::Byte(Argument<Byte> argument) |
| 1567 | { |
| 1568 | storeValue(argument.value); |
| 1569 | } |
| 1570 | |
| 1571 | Byte::Byte(RValue<Int> cast) |
| 1572 | { |
| 1573 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1574 | |
| 1575 | storeValue(integer); |
| 1576 | } |
| 1577 | |
| 1578 | Byte::Byte(RValue<UInt> cast) |
| 1579 | { |
| 1580 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1581 | |
| 1582 | storeValue(integer); |
| 1583 | } |
| 1584 | |
| 1585 | Byte::Byte(RValue<UShort> cast) |
| 1586 | { |
| 1587 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1588 | |
| 1589 | storeValue(integer); |
| 1590 | } |
| 1591 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1592 | Byte::Byte(int x) |
| 1593 | { |
| 1594 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1595 | } |
| 1596 | |
| 1597 | Byte::Byte(unsigned char x) |
| 1598 | { |
| 1599 | storeValue(Nucleus::createConstantByte(x)); |
| 1600 | } |
| 1601 | |
| 1602 | Byte::Byte(RValue<Byte> rhs) |
| 1603 | { |
| 1604 | storeValue(rhs.value); |
| 1605 | } |
| 1606 | |
| 1607 | Byte::Byte(const Byte &rhs) |
| 1608 | { |
| 1609 | Value *value = rhs.loadValue(); |
| 1610 | storeValue(value); |
| 1611 | } |
| 1612 | |
| 1613 | Byte::Byte(const Reference<Byte> &rhs) |
| 1614 | { |
| 1615 | Value *value = rhs.loadValue(); |
| 1616 | storeValue(value); |
| 1617 | } |
| 1618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1619 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1620 | { |
| 1621 | storeValue(rhs.value); |
| 1622 | |
| 1623 | return rhs; |
| 1624 | } |
| 1625 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1626 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1627 | { |
| 1628 | Value *value = rhs.loadValue(); |
| 1629 | storeValue(value); |
| 1630 | |
| 1631 | return RValue<Byte>(value); |
| 1632 | } |
| 1633 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1634 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1635 | { |
| 1636 | Value *value = rhs.loadValue(); |
| 1637 | storeValue(value); |
| 1638 | |
| 1639 | return RValue<Byte>(value); |
| 1640 | } |
| 1641 | |
| 1642 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1643 | { |
| 1644 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1645 | } |
| 1646 | |
| 1647 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1648 | { |
| 1649 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1650 | } |
| 1651 | |
| 1652 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1653 | { |
| 1654 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1655 | } |
| 1656 | |
| 1657 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1658 | { |
| 1659 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1660 | } |
| 1661 | |
| 1662 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1663 | { |
| 1664 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1665 | } |
| 1666 | |
| 1667 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1668 | { |
| 1669 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1670 | } |
| 1671 | |
| 1672 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1673 | { |
| 1674 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1675 | } |
| 1676 | |
| 1677 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1678 | { |
| 1679 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1680 | } |
| 1681 | |
| 1682 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1683 | { |
| 1684 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1685 | } |
| 1686 | |
| 1687 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1688 | { |
| 1689 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1690 | } |
| 1691 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1692 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1693 | { |
| 1694 | return lhs = lhs + rhs; |
| 1695 | } |
| 1696 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1697 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1698 | { |
| 1699 | return lhs = lhs - rhs; |
| 1700 | } |
| 1701 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1702 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1703 | { |
| 1704 | return lhs = lhs * rhs; |
| 1705 | } |
| 1706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1707 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1708 | { |
| 1709 | return lhs = lhs / rhs; |
| 1710 | } |
| 1711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1712 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1713 | { |
| 1714 | return lhs = lhs % rhs; |
| 1715 | } |
| 1716 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1717 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1718 | { |
| 1719 | return lhs = lhs & rhs; |
| 1720 | } |
| 1721 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1722 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1723 | { |
| 1724 | return lhs = lhs | rhs; |
| 1725 | } |
| 1726 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1727 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1728 | { |
| 1729 | return lhs = lhs ^ rhs; |
| 1730 | } |
| 1731 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1732 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1733 | { |
| 1734 | return lhs = lhs << rhs; |
| 1735 | } |
| 1736 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1737 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1738 | { |
| 1739 | return lhs = lhs >> rhs; |
| 1740 | } |
| 1741 | |
| 1742 | RValue<Byte> operator+(RValue<Byte> val) |
| 1743 | { |
| 1744 | return val; |
| 1745 | } |
| 1746 | |
| 1747 | RValue<Byte> operator-(RValue<Byte> val) |
| 1748 | { |
| 1749 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1750 | } |
| 1751 | |
| 1752 | RValue<Byte> operator~(RValue<Byte> val) |
| 1753 | { |
| 1754 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1755 | } |
| 1756 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1757 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1758 | { |
| 1759 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1760 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1761 | return res; |
| 1762 | } |
| 1763 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1764 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1765 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1766 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1767 | return val; |
| 1768 | } |
| 1769 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1770 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1771 | { |
| 1772 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1773 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1774 | return res; |
| 1775 | } |
| 1776 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1777 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1778 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1779 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1780 | return val; |
| 1781 | } |
| 1782 | |
| 1783 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1784 | { |
| 1785 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1786 | } |
| 1787 | |
| 1788 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1789 | { |
| 1790 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1791 | } |
| 1792 | |
| 1793 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1794 | { |
| 1795 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1796 | } |
| 1797 | |
| 1798 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1799 | { |
| 1800 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1801 | } |
| 1802 | |
| 1803 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1804 | { |
| 1805 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1806 | } |
| 1807 | |
| 1808 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1809 | { |
| 1810 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1811 | } |
| 1812 | |
| 1813 | Type *Byte::getType() |
| 1814 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1815 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | SByte::SByte(Argument<SByte> argument) |
| 1819 | { |
| 1820 | storeValue(argument.value); |
| 1821 | } |
| 1822 | |
| 1823 | SByte::SByte(RValue<Int> cast) |
| 1824 | { |
| 1825 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1826 | |
| 1827 | storeValue(integer); |
| 1828 | } |
| 1829 | |
| 1830 | SByte::SByte(RValue<Short> cast) |
| 1831 | { |
| 1832 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1833 | |
| 1834 | storeValue(integer); |
| 1835 | } |
| 1836 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1837 | SByte::SByte(signed char x) |
| 1838 | { |
| 1839 | storeValue(Nucleus::createConstantByte(x)); |
| 1840 | } |
| 1841 | |
| 1842 | SByte::SByte(RValue<SByte> rhs) |
| 1843 | { |
| 1844 | storeValue(rhs.value); |
| 1845 | } |
| 1846 | |
| 1847 | SByte::SByte(const SByte &rhs) |
| 1848 | { |
| 1849 | Value *value = rhs.loadValue(); |
| 1850 | storeValue(value); |
| 1851 | } |
| 1852 | |
| 1853 | SByte::SByte(const Reference<SByte> &rhs) |
| 1854 | { |
| 1855 | Value *value = rhs.loadValue(); |
| 1856 | storeValue(value); |
| 1857 | } |
| 1858 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1859 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1860 | { |
| 1861 | storeValue(rhs.value); |
| 1862 | |
| 1863 | return rhs; |
| 1864 | } |
| 1865 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1866 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1867 | { |
| 1868 | Value *value = rhs.loadValue(); |
| 1869 | storeValue(value); |
| 1870 | |
| 1871 | return RValue<SByte>(value); |
| 1872 | } |
| 1873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1874 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1875 | { |
| 1876 | Value *value = rhs.loadValue(); |
| 1877 | storeValue(value); |
| 1878 | |
| 1879 | return RValue<SByte>(value); |
| 1880 | } |
| 1881 | |
| 1882 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1883 | { |
| 1884 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1885 | } |
| 1886 | |
| 1887 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1888 | { |
| 1889 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1890 | } |
| 1891 | |
| 1892 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1893 | { |
| 1894 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1895 | } |
| 1896 | |
| 1897 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1898 | { |
| 1899 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1900 | } |
| 1901 | |
| 1902 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1903 | { |
| 1904 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1905 | } |
| 1906 | |
| 1907 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1908 | { |
| 1909 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1910 | } |
| 1911 | |
| 1912 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1913 | { |
| 1914 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1915 | } |
| 1916 | |
| 1917 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1918 | { |
| 1919 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1920 | } |
| 1921 | |
| 1922 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1923 | { |
| 1924 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1925 | } |
| 1926 | |
| 1927 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1928 | { |
| 1929 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1930 | } |
| 1931 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1932 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1933 | { |
| 1934 | return lhs = lhs + rhs; |
| 1935 | } |
| 1936 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1937 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1938 | { |
| 1939 | return lhs = lhs - rhs; |
| 1940 | } |
| 1941 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1942 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1943 | { |
| 1944 | return lhs = lhs * rhs; |
| 1945 | } |
| 1946 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1947 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1948 | { |
| 1949 | return lhs = lhs / rhs; |
| 1950 | } |
| 1951 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1952 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1953 | { |
| 1954 | return lhs = lhs % rhs; |
| 1955 | } |
| 1956 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1957 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1958 | { |
| 1959 | return lhs = lhs & rhs; |
| 1960 | } |
| 1961 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1962 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1963 | { |
| 1964 | return lhs = lhs | rhs; |
| 1965 | } |
| 1966 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1967 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1968 | { |
| 1969 | return lhs = lhs ^ rhs; |
| 1970 | } |
| 1971 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1972 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1973 | { |
| 1974 | return lhs = lhs << rhs; |
| 1975 | } |
| 1976 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1977 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1978 | { |
| 1979 | return lhs = lhs >> rhs; |
| 1980 | } |
| 1981 | |
| 1982 | RValue<SByte> operator+(RValue<SByte> val) |
| 1983 | { |
| 1984 | return val; |
| 1985 | } |
| 1986 | |
| 1987 | RValue<SByte> operator-(RValue<SByte> val) |
| 1988 | { |
| 1989 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1990 | } |
| 1991 | |
| 1992 | RValue<SByte> operator~(RValue<SByte> val) |
| 1993 | { |
| 1994 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1995 | } |
| 1996 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1997 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1998 | { |
| 1999 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2000 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2001 | return res; |
| 2002 | } |
| 2003 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2004 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2005 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2006 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2007 | return val; |
| 2008 | } |
| 2009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2010 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2011 | { |
| 2012 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2013 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2014 | return res; |
| 2015 | } |
| 2016 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2017 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2018 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2019 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2020 | return val; |
| 2021 | } |
| 2022 | |
| 2023 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2024 | { |
| 2025 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2026 | } |
| 2027 | |
| 2028 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2029 | { |
| 2030 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2031 | } |
| 2032 | |
| 2033 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2034 | { |
| 2035 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2036 | } |
| 2037 | |
| 2038 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2039 | { |
| 2040 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2041 | } |
| 2042 | |
| 2043 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2044 | { |
| 2045 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2046 | } |
| 2047 | |
| 2048 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2049 | { |
| 2050 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2051 | } |
| 2052 | |
| 2053 | Type *SByte::getType() |
| 2054 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2055 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | Short::Short(Argument<Short> argument) |
| 2059 | { |
| 2060 | storeValue(argument.value); |
| 2061 | } |
| 2062 | |
| 2063 | Short::Short(RValue<Int> cast) |
| 2064 | { |
| 2065 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2066 | |
| 2067 | storeValue(integer); |
| 2068 | } |
| 2069 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2070 | Short::Short(short x) |
| 2071 | { |
| 2072 | storeValue(Nucleus::createConstantShort(x)); |
| 2073 | } |
| 2074 | |
| 2075 | Short::Short(RValue<Short> rhs) |
| 2076 | { |
| 2077 | storeValue(rhs.value); |
| 2078 | } |
| 2079 | |
| 2080 | Short::Short(const Short &rhs) |
| 2081 | { |
| 2082 | Value *value = rhs.loadValue(); |
| 2083 | storeValue(value); |
| 2084 | } |
| 2085 | |
| 2086 | Short::Short(const Reference<Short> &rhs) |
| 2087 | { |
| 2088 | Value *value = rhs.loadValue(); |
| 2089 | storeValue(value); |
| 2090 | } |
| 2091 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2092 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2093 | { |
| 2094 | storeValue(rhs.value); |
| 2095 | |
| 2096 | return rhs; |
| 2097 | } |
| 2098 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2099 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2100 | { |
| 2101 | Value *value = rhs.loadValue(); |
| 2102 | storeValue(value); |
| 2103 | |
| 2104 | return RValue<Short>(value); |
| 2105 | } |
| 2106 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2107 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2108 | { |
| 2109 | Value *value = rhs.loadValue(); |
| 2110 | storeValue(value); |
| 2111 | |
| 2112 | return RValue<Short>(value); |
| 2113 | } |
| 2114 | |
| 2115 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 2116 | { |
| 2117 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2118 | } |
| 2119 | |
| 2120 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 2121 | { |
| 2122 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2123 | } |
| 2124 | |
| 2125 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 2126 | { |
| 2127 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2128 | } |
| 2129 | |
| 2130 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 2131 | { |
| 2132 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2133 | } |
| 2134 | |
| 2135 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 2136 | { |
| 2137 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2138 | } |
| 2139 | |
| 2140 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 2141 | { |
| 2142 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2143 | } |
| 2144 | |
| 2145 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 2146 | { |
| 2147 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2148 | } |
| 2149 | |
| 2150 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2151 | { |
| 2152 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2153 | } |
| 2154 | |
| 2155 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2156 | { |
| 2157 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2158 | } |
| 2159 | |
| 2160 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2161 | { |
| 2162 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2163 | } |
| 2164 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2165 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2166 | { |
| 2167 | return lhs = lhs + rhs; |
| 2168 | } |
| 2169 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2170 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2171 | { |
| 2172 | return lhs = lhs - rhs; |
| 2173 | } |
| 2174 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2175 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2176 | { |
| 2177 | return lhs = lhs * rhs; |
| 2178 | } |
| 2179 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2180 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2181 | { |
| 2182 | return lhs = lhs / rhs; |
| 2183 | } |
| 2184 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2185 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2186 | { |
| 2187 | return lhs = lhs % rhs; |
| 2188 | } |
| 2189 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2190 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2191 | { |
| 2192 | return lhs = lhs & rhs; |
| 2193 | } |
| 2194 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2195 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2196 | { |
| 2197 | return lhs = lhs | rhs; |
| 2198 | } |
| 2199 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2200 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2201 | { |
| 2202 | return lhs = lhs ^ rhs; |
| 2203 | } |
| 2204 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2205 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2206 | { |
| 2207 | return lhs = lhs << rhs; |
| 2208 | } |
| 2209 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2210 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2211 | { |
| 2212 | return lhs = lhs >> rhs; |
| 2213 | } |
| 2214 | |
| 2215 | RValue<Short> operator+(RValue<Short> val) |
| 2216 | { |
| 2217 | return val; |
| 2218 | } |
| 2219 | |
| 2220 | RValue<Short> operator-(RValue<Short> val) |
| 2221 | { |
| 2222 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2223 | } |
| 2224 | |
| 2225 | RValue<Short> operator~(RValue<Short> val) |
| 2226 | { |
| 2227 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2228 | } |
| 2229 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2230 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2231 | { |
| 2232 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2233 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2234 | return res; |
| 2235 | } |
| 2236 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2237 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2238 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2239 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2240 | return val; |
| 2241 | } |
| 2242 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2243 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2244 | { |
| 2245 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2246 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2247 | return res; |
| 2248 | } |
| 2249 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2250 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2251 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2252 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2253 | return val; |
| 2254 | } |
| 2255 | |
| 2256 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2257 | { |
| 2258 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2259 | } |
| 2260 | |
| 2261 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2262 | { |
| 2263 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2264 | } |
| 2265 | |
| 2266 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2267 | { |
| 2268 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2269 | } |
| 2270 | |
| 2271 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2272 | { |
| 2273 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2274 | } |
| 2275 | |
| 2276 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2277 | { |
| 2278 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2279 | } |
| 2280 | |
| 2281 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2282 | { |
| 2283 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2284 | } |
| 2285 | |
| 2286 | Type *Short::getType() |
| 2287 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2288 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | UShort::UShort(Argument<UShort> argument) |
| 2292 | { |
| 2293 | storeValue(argument.value); |
| 2294 | } |
| 2295 | |
| 2296 | UShort::UShort(RValue<UInt> cast) |
| 2297 | { |
| 2298 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2299 | |
| 2300 | storeValue(integer); |
| 2301 | } |
| 2302 | |
| 2303 | UShort::UShort(RValue<Int> cast) |
| 2304 | { |
| 2305 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2306 | |
| 2307 | storeValue(integer); |
| 2308 | } |
| 2309 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2310 | UShort::UShort(unsigned short x) |
| 2311 | { |
| 2312 | storeValue(Nucleus::createConstantShort(x)); |
| 2313 | } |
| 2314 | |
| 2315 | UShort::UShort(RValue<UShort> rhs) |
| 2316 | { |
| 2317 | storeValue(rhs.value); |
| 2318 | } |
| 2319 | |
| 2320 | UShort::UShort(const UShort &rhs) |
| 2321 | { |
| 2322 | Value *value = rhs.loadValue(); |
| 2323 | storeValue(value); |
| 2324 | } |
| 2325 | |
| 2326 | UShort::UShort(const Reference<UShort> &rhs) |
| 2327 | { |
| 2328 | Value *value = rhs.loadValue(); |
| 2329 | storeValue(value); |
| 2330 | } |
| 2331 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2332 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2333 | { |
| 2334 | storeValue(rhs.value); |
| 2335 | |
| 2336 | return rhs; |
| 2337 | } |
| 2338 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2339 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2340 | { |
| 2341 | Value *value = rhs.loadValue(); |
| 2342 | storeValue(value); |
| 2343 | |
| 2344 | return RValue<UShort>(value); |
| 2345 | } |
| 2346 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2347 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2348 | { |
| 2349 | Value *value = rhs.loadValue(); |
| 2350 | storeValue(value); |
| 2351 | |
| 2352 | return RValue<UShort>(value); |
| 2353 | } |
| 2354 | |
| 2355 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2356 | { |
| 2357 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2358 | } |
| 2359 | |
| 2360 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2361 | { |
| 2362 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2363 | } |
| 2364 | |
| 2365 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2366 | { |
| 2367 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2368 | } |
| 2369 | |
| 2370 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2371 | { |
| 2372 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2373 | } |
| 2374 | |
| 2375 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2376 | { |
| 2377 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2378 | } |
| 2379 | |
| 2380 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2381 | { |
| 2382 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2383 | } |
| 2384 | |
| 2385 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2386 | { |
| 2387 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2388 | } |
| 2389 | |
| 2390 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2391 | { |
| 2392 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2393 | } |
| 2394 | |
| 2395 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2396 | { |
| 2397 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2398 | } |
| 2399 | |
| 2400 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2401 | { |
| 2402 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2403 | } |
| 2404 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2405 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2406 | { |
| 2407 | return lhs = lhs + rhs; |
| 2408 | } |
| 2409 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2410 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2411 | { |
| 2412 | return lhs = lhs - rhs; |
| 2413 | } |
| 2414 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2415 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2416 | { |
| 2417 | return lhs = lhs * rhs; |
| 2418 | } |
| 2419 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2420 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2421 | { |
| 2422 | return lhs = lhs / rhs; |
| 2423 | } |
| 2424 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2425 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2426 | { |
| 2427 | return lhs = lhs % rhs; |
| 2428 | } |
| 2429 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2430 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2431 | { |
| 2432 | return lhs = lhs & rhs; |
| 2433 | } |
| 2434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2435 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2436 | { |
| 2437 | return lhs = lhs | rhs; |
| 2438 | } |
| 2439 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2440 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2441 | { |
| 2442 | return lhs = lhs ^ rhs; |
| 2443 | } |
| 2444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2445 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2446 | { |
| 2447 | return lhs = lhs << rhs; |
| 2448 | } |
| 2449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2450 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2451 | { |
| 2452 | return lhs = lhs >> rhs; |
| 2453 | } |
| 2454 | |
| 2455 | RValue<UShort> operator+(RValue<UShort> val) |
| 2456 | { |
| 2457 | return val; |
| 2458 | } |
| 2459 | |
| 2460 | RValue<UShort> operator-(RValue<UShort> val) |
| 2461 | { |
| 2462 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2463 | } |
| 2464 | |
| 2465 | RValue<UShort> operator~(RValue<UShort> val) |
| 2466 | { |
| 2467 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2468 | } |
| 2469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2470 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2471 | { |
| 2472 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2473 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2474 | return res; |
| 2475 | } |
| 2476 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2477 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2478 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2479 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2480 | return val; |
| 2481 | } |
| 2482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2483 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2484 | { |
| 2485 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2486 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2487 | return res; |
| 2488 | } |
| 2489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2490 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2491 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2492 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2493 | return val; |
| 2494 | } |
| 2495 | |
| 2496 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2497 | { |
| 2498 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2499 | } |
| 2500 | |
| 2501 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2502 | { |
| 2503 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2504 | } |
| 2505 | |
| 2506 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2507 | { |
| 2508 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2509 | } |
| 2510 | |
| 2511 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2512 | { |
| 2513 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2514 | } |
| 2515 | |
| 2516 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2517 | { |
| 2518 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2519 | } |
| 2520 | |
| 2521 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2522 | { |
| 2523 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2524 | } |
| 2525 | |
| 2526 | Type *UShort::getType() |
| 2527 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2528 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2529 | } |
| 2530 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2531 | Byte4::Byte4(RValue<Byte8> cast) |
| 2532 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2533 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2534 | } |
| 2535 | |
| 2536 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2537 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2538 | Value *value = rhs.loadValue(); |
| 2539 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2540 | } |
| 2541 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2542 | Type *Byte4::getType() |
| 2543 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2544 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | Type *SByte4::getType() |
| 2548 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2549 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2550 | } |
| 2551 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2552 | 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) |
| 2553 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2554 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2555 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2559 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2560 | storeValue(rhs.value); |
| 2561 | } |
| 2562 | |
| 2563 | Byte8::Byte8(const Byte8 &rhs) |
| 2564 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2565 | Value *value = rhs.loadValue(); |
| 2566 | storeValue(value); |
| 2567 | } |
| 2568 | |
| 2569 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2570 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2571 | Value *value = rhs.loadValue(); |
| 2572 | storeValue(value); |
| 2573 | } |
| 2574 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2575 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2576 | { |
| 2577 | storeValue(rhs.value); |
| 2578 | |
| 2579 | return rhs; |
| 2580 | } |
| 2581 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2582 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2583 | { |
| 2584 | Value *value = rhs.loadValue(); |
| 2585 | storeValue(value); |
| 2586 | |
| 2587 | return RValue<Byte8>(value); |
| 2588 | } |
| 2589 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2590 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2591 | { |
| 2592 | Value *value = rhs.loadValue(); |
| 2593 | storeValue(value); |
| 2594 | |
| 2595 | return RValue<Byte8>(value); |
| 2596 | } |
| 2597 | |
| 2598 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2599 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2600 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2604 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2605 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2609 | // { |
| 2610 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2611 | // } |
| 2612 | |
| 2613 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2614 | // { |
| 2615 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2616 | // } |
| 2617 | |
| 2618 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2619 | // { |
| 2620 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2621 | // } |
| 2622 | |
| 2623 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2624 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2625 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2629 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2630 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2634 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2635 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2639 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2640 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2641 | // } |
| 2642 | |
| 2643 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2644 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2645 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2646 | // } |
| 2647 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2648 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2649 | { |
| 2650 | return lhs = lhs + rhs; |
| 2651 | } |
| 2652 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2653 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2654 | { |
| 2655 | return lhs = lhs - rhs; |
| 2656 | } |
| 2657 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2658 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2659 | // { |
| 2660 | // return lhs = lhs * rhs; |
| 2661 | // } |
| 2662 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2663 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2664 | // { |
| 2665 | // return lhs = lhs / rhs; |
| 2666 | // } |
| 2667 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2668 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2669 | // { |
| 2670 | // return lhs = lhs % rhs; |
| 2671 | // } |
| 2672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2673 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2674 | { |
| 2675 | return lhs = lhs & rhs; |
| 2676 | } |
| 2677 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2678 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2679 | { |
| 2680 | return lhs = lhs | rhs; |
| 2681 | } |
| 2682 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2683 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2684 | { |
| 2685 | return lhs = lhs ^ rhs; |
| 2686 | } |
| 2687 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2688 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2689 | // { |
| 2690 | // return lhs = lhs << rhs; |
| 2691 | // } |
| 2692 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2693 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2694 | // { |
| 2695 | // return lhs = lhs >> rhs; |
| 2696 | // } |
| 2697 | |
| 2698 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2699 | // { |
| 2700 | // return val; |
| 2701 | // } |
| 2702 | |
| 2703 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2704 | // { |
| 2705 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2706 | // } |
| 2707 | |
| 2708 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2709 | { |
| 2710 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2711 | } |
| 2712 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 2713 | RValue<Byte> Extract(RValue<Byte8> val, int i) |
| 2714 | { |
| 2715 | return RValue<Byte>(Nucleus::createExtractElement(val.value, Byte::getType(), i)); |
| 2716 | } |
| 2717 | |
| 2718 | RValue<Byte8> Insert(RValue<Byte8> val, RValue<Byte> element, int i) |
| 2719 | { |
| 2720 | return RValue<Byte8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2721 | } |
| 2722 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2723 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2724 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2725 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2726 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2727 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2728 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2729 | paddusb->addArg(x.value); |
| 2730 | paddusb->addArg(y.value); |
| 2731 | ::basicBlock->appendInst(paddusb); |
| 2732 | |
| 2733 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2737 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2738 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2739 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2740 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2741 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2742 | psubusw->addArg(x.value); |
| 2743 | psubusw->addArg(y.value); |
| 2744 | ::basicBlock->appendInst(psubusw); |
| 2745 | |
| 2746 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2750 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2751 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 2752 | return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2753 | } |
| 2754 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2755 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2756 | { |
| 2757 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| 2758 | } |
| 2759 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2760 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2761 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2762 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 2763 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2767 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2768 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2769 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2770 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2771 | } |
| 2772 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 2773 | RValue<SByte> Extract(RValue<SByte8> val, int i) |
| 2774 | { |
| 2775 | return RValue<SByte>(Nucleus::createExtractElement(val.value, SByte::getType(), i)); |
| 2776 | } |
| 2777 | |
| 2778 | RValue<SByte8> Insert(RValue<SByte8> val, RValue<SByte> element, int i) |
| 2779 | { |
| 2780 | return RValue<SByte8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2781 | } |
| 2782 | |
| 2783 | RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2784 | { |
| 2785 | if(emulateIntrinsics) |
| 2786 | { |
| 2787 | SByte8 result; |
| 2788 | result = Insert(result, Extract(lhs, 0) >> SByte(rhs), 0); |
| 2789 | result = Insert(result, Extract(lhs, 1) >> SByte(rhs), 1); |
| 2790 | result = Insert(result, Extract(lhs, 2) >> SByte(rhs), 2); |
| 2791 | result = Insert(result, Extract(lhs, 3) >> SByte(rhs), 3); |
| 2792 | result = Insert(result, Extract(lhs, 4) >> SByte(rhs), 4); |
| 2793 | result = Insert(result, Extract(lhs, 5) >> SByte(rhs), 5); |
| 2794 | result = Insert(result, Extract(lhs, 6) >> SByte(rhs), 6); |
| 2795 | result = Insert(result, Extract(lhs, 7) >> SByte(rhs), 7); |
| 2796 | |
| 2797 | return result; |
| 2798 | } |
| 2799 | else |
| 2800 | { |
| 2801 | #if defined(__i386__) || defined(__x86_64__) |
| 2802 | // SSE2 doesn't support byte vector shifts, so shift as shorts and recombine. |
| 2803 | RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00); |
| 2804 | RValue<Short4> lo = As<Short4>(As<UShort4>((As<Short4>(lhs) << 8) >> rhs) >> 8); |
| 2805 | |
| 2806 | return As<SByte8>(hi | lo); |
| 2807 | #else |
| 2808 | return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 2809 | #endif |
| 2810 | } |
| 2811 | } |
| 2812 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2813 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2814 | { |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 2815 | if(emulateIntrinsics) |
| 2816 | { |
| 2817 | Byte8 xx = As<Byte8>(As<SByte8>(x) >> 7) & Byte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80); |
| 2818 | return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7)); |
| 2819 | } |
| 2820 | else |
| 2821 | { |
| 2822 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2823 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2824 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2825 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2826 | movmsk->addArg(x.value); |
| 2827 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2828 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 2829 | return RValue<Int>(V(result)); |
| 2830 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2834 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2835 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2836 | // } |
| 2837 | |
| 2838 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2839 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2840 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | Type *Byte8::getType() |
| 2844 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2845 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2846 | } |
| 2847 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2848 | 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) |
| 2849 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2850 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2851 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2852 | |
| 2853 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2854 | } |
| 2855 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2856 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2857 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2858 | storeValue(rhs.value); |
| 2859 | } |
| 2860 | |
| 2861 | SByte8::SByte8(const SByte8 &rhs) |
| 2862 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2863 | Value *value = rhs.loadValue(); |
| 2864 | storeValue(value); |
| 2865 | } |
| 2866 | |
| 2867 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2868 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2869 | Value *value = rhs.loadValue(); |
| 2870 | storeValue(value); |
| 2871 | } |
| 2872 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2873 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2874 | { |
| 2875 | storeValue(rhs.value); |
| 2876 | |
| 2877 | return rhs; |
| 2878 | } |
| 2879 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2880 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2881 | { |
| 2882 | Value *value = rhs.loadValue(); |
| 2883 | storeValue(value); |
| 2884 | |
| 2885 | return RValue<SByte8>(value); |
| 2886 | } |
| 2887 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2888 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2889 | { |
| 2890 | Value *value = rhs.loadValue(); |
| 2891 | storeValue(value); |
| 2892 | |
| 2893 | return RValue<SByte8>(value); |
| 2894 | } |
| 2895 | |
| 2896 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2897 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2898 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2902 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2903 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2907 | // { |
| 2908 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2909 | // } |
| 2910 | |
| 2911 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2912 | // { |
| 2913 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2914 | // } |
| 2915 | |
| 2916 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2917 | // { |
| 2918 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2919 | // } |
| 2920 | |
| 2921 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2922 | { |
| 2923 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2924 | } |
| 2925 | |
| 2926 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2927 | { |
| 2928 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2929 | } |
| 2930 | |
| 2931 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2932 | { |
| 2933 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2934 | } |
| 2935 | |
| 2936 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2937 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2938 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2939 | // } |
| 2940 | |
| 2941 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2942 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2943 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2944 | // } |
| 2945 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2946 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2947 | { |
| 2948 | return lhs = lhs + rhs; |
| 2949 | } |
| 2950 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2951 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2952 | { |
| 2953 | return lhs = lhs - rhs; |
| 2954 | } |
| 2955 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2956 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2957 | // { |
| 2958 | // return lhs = lhs * rhs; |
| 2959 | // } |
| 2960 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2961 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2962 | // { |
| 2963 | // return lhs = lhs / rhs; |
| 2964 | // } |
| 2965 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2966 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2967 | // { |
| 2968 | // return lhs = lhs % rhs; |
| 2969 | // } |
| 2970 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2971 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2972 | { |
| 2973 | return lhs = lhs & rhs; |
| 2974 | } |
| 2975 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2976 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2977 | { |
| 2978 | return lhs = lhs | rhs; |
| 2979 | } |
| 2980 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2981 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2982 | { |
| 2983 | return lhs = lhs ^ rhs; |
| 2984 | } |
| 2985 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2986 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2987 | // { |
| 2988 | // return lhs = lhs << rhs; |
| 2989 | // } |
| 2990 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2991 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2992 | // { |
| 2993 | // return lhs = lhs >> rhs; |
| 2994 | // } |
| 2995 | |
| 2996 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2997 | // { |
| 2998 | // return val; |
| 2999 | // } |
| 3000 | |
| 3001 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 3002 | // { |
| 3003 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 3004 | // } |
| 3005 | |
| 3006 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 3007 | { |
| 3008 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 3009 | } |
| 3010 | |
| 3011 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 3012 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3013 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3014 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3015 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3016 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3017 | paddsb->addArg(x.value); |
| 3018 | paddsb->addArg(y.value); |
| 3019 | ::basicBlock->appendInst(paddsb); |
| 3020 | |
| 3021 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 3025 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3026 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3027 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3028 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3029 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3030 | psubsb->addArg(x.value); |
| 3031 | psubsb->addArg(y.value); |
| 3032 | ::basicBlock->appendInst(psubsb); |
| 3033 | |
| 3034 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 3038 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3039 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3040 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 3044 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3045 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 3046 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3047 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | RValue<Int> SignMask(RValue<SByte8> x) |
| 3051 | { |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 3052 | if(emulateIntrinsics) |
| 3053 | { |
| 3054 | SByte8 xx = (x >> 7) & SByte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80); |
| 3055 | return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7)); |
| 3056 | } |
| 3057 | else |
| 3058 | { |
| 3059 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 3060 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3061 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3062 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 3063 | movmsk->addArg(x.value); |
| 3064 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 3065 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 3066 | return RValue<Int>(V(result)); |
| 3067 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 3071 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3072 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 3076 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3077 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | Type *SByte8::getType() |
| 3081 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3082 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | Byte16::Byte16(RValue<Byte16> rhs) |
| 3086 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3087 | storeValue(rhs.value); |
| 3088 | } |
| 3089 | |
| 3090 | Byte16::Byte16(const Byte16 &rhs) |
| 3091 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3092 | Value *value = rhs.loadValue(); |
| 3093 | storeValue(value); |
| 3094 | } |
| 3095 | |
| 3096 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 3097 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3098 | Value *value = rhs.loadValue(); |
| 3099 | storeValue(value); |
| 3100 | } |
| 3101 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3102 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3103 | { |
| 3104 | storeValue(rhs.value); |
| 3105 | |
| 3106 | return rhs; |
| 3107 | } |
| 3108 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3109 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3110 | { |
| 3111 | Value *value = rhs.loadValue(); |
| 3112 | storeValue(value); |
| 3113 | |
| 3114 | return RValue<Byte16>(value); |
| 3115 | } |
| 3116 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3117 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3118 | { |
| 3119 | Value *value = rhs.loadValue(); |
| 3120 | storeValue(value); |
| 3121 | |
| 3122 | return RValue<Byte16>(value); |
| 3123 | } |
| 3124 | |
| 3125 | Type *Byte16::getType() |
| 3126 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3127 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | Type *SByte16::getType() |
| 3131 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3132 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3133 | } |
| 3134 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3135 | Short2::Short2(RValue<Short4> cast) |
| 3136 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3137 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | Type *Short2::getType() |
| 3141 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3142 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | UShort2::UShort2(RValue<UShort4> cast) |
| 3146 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3147 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | Type *UShort2::getType() |
| 3151 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3152 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3153 | } |
| 3154 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3155 | Short4::Short4(RValue<Int> cast) |
| 3156 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3157 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 3158 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 3159 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3160 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3161 | |
| 3162 | storeValue(swizzle); |
| 3163 | } |
| 3164 | |
| 3165 | Short4::Short4(RValue<Int4> cast) |
| 3166 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 3167 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 3168 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 3169 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3170 | |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3171 | Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value; |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3172 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 3173 | |
| 3174 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | // Short4::Short4(RValue<Float> cast) |
| 3178 | // { |
| 3179 | // } |
| 3180 | |
| 3181 | Short4::Short4(RValue<Float4> cast) |
| 3182 | { |
| 3183 | assert(false && "UNIMPLEMENTED"); |
| 3184 | } |
| 3185 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3186 | Short4::Short4(short xyzw) |
| 3187 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3188 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3189 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | Short4::Short4(short x, short y, short z, short w) |
| 3193 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3194 | int64_t constantVector[4] = {x, y, z, w}; |
| 3195 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | Short4::Short4(RValue<Short4> rhs) |
| 3199 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3200 | storeValue(rhs.value); |
| 3201 | } |
| 3202 | |
| 3203 | Short4::Short4(const Short4 &rhs) |
| 3204 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3205 | Value *value = rhs.loadValue(); |
| 3206 | storeValue(value); |
| 3207 | } |
| 3208 | |
| 3209 | Short4::Short4(const Reference<Short4> &rhs) |
| 3210 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3211 | Value *value = rhs.loadValue(); |
| 3212 | storeValue(value); |
| 3213 | } |
| 3214 | |
| 3215 | Short4::Short4(RValue<UShort4> rhs) |
| 3216 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3217 | storeValue(rhs.value); |
| 3218 | } |
| 3219 | |
| 3220 | Short4::Short4(const UShort4 &rhs) |
| 3221 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3222 | storeValue(rhs.loadValue()); |
| 3223 | } |
| 3224 | |
| 3225 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3226 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3227 | storeValue(rhs.loadValue()); |
| 3228 | } |
| 3229 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3230 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3231 | { |
| 3232 | storeValue(rhs.value); |
| 3233 | |
| 3234 | return rhs; |
| 3235 | } |
| 3236 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3237 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3238 | { |
| 3239 | Value *value = rhs.loadValue(); |
| 3240 | storeValue(value); |
| 3241 | |
| 3242 | return RValue<Short4>(value); |
| 3243 | } |
| 3244 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3245 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3246 | { |
| 3247 | Value *value = rhs.loadValue(); |
| 3248 | storeValue(value); |
| 3249 | |
| 3250 | return RValue<Short4>(value); |
| 3251 | } |
| 3252 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3253 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3254 | { |
| 3255 | storeValue(rhs.value); |
| 3256 | |
| 3257 | return RValue<Short4>(rhs); |
| 3258 | } |
| 3259 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3260 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3261 | { |
| 3262 | Value *value = rhs.loadValue(); |
| 3263 | storeValue(value); |
| 3264 | |
| 3265 | return RValue<Short4>(value); |
| 3266 | } |
| 3267 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3268 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3269 | { |
| 3270 | Value *value = rhs.loadValue(); |
| 3271 | storeValue(value); |
| 3272 | |
| 3273 | return RValue<Short4>(value); |
| 3274 | } |
| 3275 | |
| 3276 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3277 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3278 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3282 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3283 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3287 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3288 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3292 | // { |
| 3293 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3294 | // } |
| 3295 | |
| 3296 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3297 | // { |
| 3298 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3299 | // } |
| 3300 | |
| 3301 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3302 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3303 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3307 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3308 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3312 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3313 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3317 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3318 | if(emulateIntrinsics) |
| 3319 | { |
| 3320 | Short4 result; |
| 3321 | result = Insert(result, Extract(lhs, 0) << Short(rhs), 0); |
| 3322 | result = Insert(result, Extract(lhs, 1) << Short(rhs), 1); |
| 3323 | result = Insert(result, Extract(lhs, 2) << Short(rhs), 2); |
| 3324 | result = Insert(result, Extract(lhs, 3) << Short(rhs), 3); |
| 3325 | |
| 3326 | return result; |
| 3327 | } |
| 3328 | else |
| 3329 | { |
| 3330 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3331 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3335 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3336 | if(emulateIntrinsics) |
| 3337 | { |
| 3338 | Short4 result; |
| 3339 | result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0); |
| 3340 | result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1); |
| 3341 | result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2); |
| 3342 | result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3); |
| 3343 | |
| 3344 | return result; |
| 3345 | } |
| 3346 | else |
| 3347 | { |
| 3348 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3349 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3350 | } |
| 3351 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3352 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3353 | { |
| 3354 | return lhs = lhs + rhs; |
| 3355 | } |
| 3356 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3357 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3358 | { |
| 3359 | return lhs = lhs - rhs; |
| 3360 | } |
| 3361 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3362 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3363 | { |
| 3364 | return lhs = lhs * rhs; |
| 3365 | } |
| 3366 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3367 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3368 | // { |
| 3369 | // return lhs = lhs / rhs; |
| 3370 | // } |
| 3371 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3372 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3373 | // { |
| 3374 | // return lhs = lhs % rhs; |
| 3375 | // } |
| 3376 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3377 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3378 | { |
| 3379 | return lhs = lhs & rhs; |
| 3380 | } |
| 3381 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3382 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3383 | { |
| 3384 | return lhs = lhs | rhs; |
| 3385 | } |
| 3386 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3387 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3388 | { |
| 3389 | return lhs = lhs ^ rhs; |
| 3390 | } |
| 3391 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3392 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3393 | { |
| 3394 | return lhs = lhs << rhs; |
| 3395 | } |
| 3396 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3397 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3398 | { |
| 3399 | return lhs = lhs >> rhs; |
| 3400 | } |
| 3401 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3402 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3403 | // { |
| 3404 | // return val; |
| 3405 | // } |
| 3406 | |
| 3407 | RValue<Short4> operator-(RValue<Short4> val) |
| 3408 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3409 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | RValue<Short4> operator~(RValue<Short4> val) |
| 3413 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3414 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3418 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3419 | RValue<Int4> int4 = RoundInt(cast); |
| 3420 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3424 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3425 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3426 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3427 | ::basicBlock->appendInst(cmp); |
| 3428 | |
| 3429 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3430 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3431 | ::basicBlock->appendInst(select); |
| 3432 | |
| 3433 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3437 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3438 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3439 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3440 | ::basicBlock->appendInst(cmp); |
| 3441 | |
| 3442 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3443 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3444 | ::basicBlock->appendInst(select); |
| 3445 | |
| 3446 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3450 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3451 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3452 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3453 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3454 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3455 | paddsw->addArg(x.value); |
| 3456 | paddsw->addArg(y.value); |
| 3457 | ::basicBlock->appendInst(paddsw); |
| 3458 | |
| 3459 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3463 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3464 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3465 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3466 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3467 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3468 | psubsw->addArg(x.value); |
| 3469 | psubsw->addArg(y.value); |
| 3470 | ::basicBlock->appendInst(psubsw); |
| 3471 | |
| 3472 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3476 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3477 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3478 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3479 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3480 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3481 | pmulhw->addArg(x.value); |
| 3482 | pmulhw->addArg(y.value); |
| 3483 | ::basicBlock->appendInst(pmulhw); |
| 3484 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3485 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3489 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3490 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3491 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3492 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3493 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3494 | pmaddwd->addArg(x.value); |
| 3495 | pmaddwd->addArg(y.value); |
| 3496 | ::basicBlock->appendInst(pmaddwd); |
| 3497 | |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3498 | return As<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3502 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3503 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3504 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3505 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3506 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3507 | pack->addArg(x.value); |
| 3508 | pack->addArg(y.value); |
| 3509 | ::basicBlock->appendInst(pack); |
| 3510 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3511 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3515 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3516 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3517 | return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3521 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3522 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3523 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3524 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3528 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3529 | // Real type is v8i16 |
| 3530 | int shuffle[8] = |
| 3531 | { |
| 3532 | (select >> 0) & 0x03, |
| 3533 | (select >> 2) & 0x03, |
| 3534 | (select >> 4) & 0x03, |
| 3535 | (select >> 6) & 0x03, |
| 3536 | (select >> 0) & 0x03, |
| 3537 | (select >> 2) & 0x03, |
| 3538 | (select >> 4) & 0x03, |
| 3539 | (select >> 6) & 0x03, |
| 3540 | }; |
| 3541 | |
| 3542 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3546 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3547 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3551 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3552 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3556 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3557 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3561 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3562 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | Type *Short4::getType() |
| 3566 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3567 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | UShort4::UShort4(RValue<Int4> cast) |
| 3571 | { |
| 3572 | *this = Short4(cast); |
| 3573 | } |
| 3574 | |
| 3575 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3576 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3577 | if(saturate) |
| 3578 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3579 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3580 | { |
| 3581 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3582 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3583 | } |
| 3584 | else |
| 3585 | { |
| 3586 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3587 | } |
| 3588 | } |
| 3589 | else |
| 3590 | { |
| 3591 | *this = Short4(Int4(cast)); |
| 3592 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3593 | } |
| 3594 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3595 | UShort4::UShort4(unsigned short xyzw) |
| 3596 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3597 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3598 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3602 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3603 | int64_t constantVector[4] = {x, y, z, w}; |
| 3604 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3608 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3609 | storeValue(rhs.value); |
| 3610 | } |
| 3611 | |
| 3612 | UShort4::UShort4(const UShort4 &rhs) |
| 3613 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3614 | Value *value = rhs.loadValue(); |
| 3615 | storeValue(value); |
| 3616 | } |
| 3617 | |
| 3618 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3619 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3620 | Value *value = rhs.loadValue(); |
| 3621 | storeValue(value); |
| 3622 | } |
| 3623 | |
| 3624 | UShort4::UShort4(RValue<Short4> rhs) |
| 3625 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3626 | storeValue(rhs.value); |
| 3627 | } |
| 3628 | |
| 3629 | UShort4::UShort4(const Short4 &rhs) |
| 3630 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3631 | Value *value = rhs.loadValue(); |
| 3632 | storeValue(value); |
| 3633 | } |
| 3634 | |
| 3635 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3636 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3637 | Value *value = rhs.loadValue(); |
| 3638 | storeValue(value); |
| 3639 | } |
| 3640 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3641 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3642 | { |
| 3643 | storeValue(rhs.value); |
| 3644 | |
| 3645 | return rhs; |
| 3646 | } |
| 3647 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3648 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3649 | { |
| 3650 | Value *value = rhs.loadValue(); |
| 3651 | storeValue(value); |
| 3652 | |
| 3653 | return RValue<UShort4>(value); |
| 3654 | } |
| 3655 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3656 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3657 | { |
| 3658 | Value *value = rhs.loadValue(); |
| 3659 | storeValue(value); |
| 3660 | |
| 3661 | return RValue<UShort4>(value); |
| 3662 | } |
| 3663 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3664 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3665 | { |
| 3666 | storeValue(rhs.value); |
| 3667 | |
| 3668 | return RValue<UShort4>(rhs); |
| 3669 | } |
| 3670 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3671 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3672 | { |
| 3673 | Value *value = rhs.loadValue(); |
| 3674 | storeValue(value); |
| 3675 | |
| 3676 | return RValue<UShort4>(value); |
| 3677 | } |
| 3678 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3679 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3680 | { |
| 3681 | Value *value = rhs.loadValue(); |
| 3682 | storeValue(value); |
| 3683 | |
| 3684 | return RValue<UShort4>(value); |
| 3685 | } |
| 3686 | |
| 3687 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3688 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3689 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3693 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3694 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3698 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3699 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3700 | } |
| 3701 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3702 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3703 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3704 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3708 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3709 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3713 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3714 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3715 | } |
| 3716 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3717 | RValue<UShort> Extract(RValue<UShort4> val, int i) |
| 3718 | { |
| 3719 | return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i)); |
| 3720 | } |
| 3721 | |
| 3722 | RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i) |
| 3723 | { |
| 3724 | return RValue<UShort4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 3725 | } |
| 3726 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3727 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3728 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3729 | if(emulateIntrinsics) |
| 3730 | { |
| 3731 | UShort4 result; |
| 3732 | result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0); |
| 3733 | result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1); |
| 3734 | result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2); |
| 3735 | result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3); |
| 3736 | |
| 3737 | return result; |
| 3738 | } |
| 3739 | else |
| 3740 | { |
| 3741 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3742 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3746 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3747 | if(emulateIntrinsics) |
| 3748 | { |
| 3749 | UShort4 result; |
| 3750 | result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0); |
| 3751 | result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1); |
| 3752 | result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2); |
| 3753 | result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3); |
| 3754 | |
| 3755 | return result; |
| 3756 | } |
| 3757 | else |
| 3758 | { |
| 3759 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3760 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3761 | } |
| 3762 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3763 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3764 | { |
| 3765 | return lhs = lhs << rhs; |
| 3766 | } |
| 3767 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3768 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3769 | { |
| 3770 | return lhs = lhs >> rhs; |
| 3771 | } |
| 3772 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3773 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3774 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3775 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3779 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3780 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3781 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3782 | ::basicBlock->appendInst(cmp); |
| 3783 | |
| 3784 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3785 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3786 | ::basicBlock->appendInst(select); |
| 3787 | |
| 3788 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3792 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3793 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3794 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3795 | ::basicBlock->appendInst(cmp); |
| 3796 | |
| 3797 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3798 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3799 | ::basicBlock->appendInst(select); |
| 3800 | |
| 3801 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3805 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3806 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3807 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3808 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3809 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3810 | paddusw->addArg(x.value); |
| 3811 | paddusw->addArg(y.value); |
| 3812 | ::basicBlock->appendInst(paddusw); |
| 3813 | |
| 3814 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3818 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3819 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3820 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3821 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3822 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3823 | psubusw->addArg(x.value); |
| 3824 | psubusw->addArg(y.value); |
| 3825 | ::basicBlock->appendInst(psubusw); |
| 3826 | |
| 3827 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3831 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3832 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3833 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3834 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3835 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3836 | pmulhuw->addArg(x.value); |
| 3837 | pmulhuw->addArg(y.value); |
| 3838 | ::basicBlock->appendInst(pmulhuw); |
| 3839 | |
| 3840 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3844 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3845 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3849 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3850 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3851 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3852 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3853 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3854 | pack->addArg(x.value); |
| 3855 | pack->addArg(y.value); |
| 3856 | ::basicBlock->appendInst(pack); |
| 3857 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3858 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | Type *UShort4::getType() |
| 3862 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3863 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3864 | } |
| 3865 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3866 | Short8::Short8(short c) |
| 3867 | { |
| 3868 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3869 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3870 | } |
| 3871 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3872 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3873 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3874 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3875 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | Short8::Short8(RValue<Short8> rhs) |
| 3879 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3880 | storeValue(rhs.value); |
| 3881 | } |
| 3882 | |
| 3883 | Short8::Short8(const Reference<Short8> &rhs) |
| 3884 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3885 | Value *value = rhs.loadValue(); |
| 3886 | storeValue(value); |
| 3887 | } |
| 3888 | |
| 3889 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3890 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3891 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3892 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3893 | |
| 3894 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3898 | { |
| 3899 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3900 | } |
| 3901 | |
| 3902 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3903 | { |
| 3904 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3905 | } |
| 3906 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3907 | RValue<Short> Extract(RValue<Short8> val, int i) |
| 3908 | { |
| 3909 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
| 3910 | } |
| 3911 | |
| 3912 | RValue<Short8> Insert(RValue<Short8> val, RValue<Short> element, int i) |
| 3913 | { |
| 3914 | return RValue<Short8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 3915 | } |
| 3916 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3917 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3918 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3919 | if(emulateIntrinsics) |
| 3920 | { |
| 3921 | Short8 result; |
| 3922 | result = Insert(result, Extract(lhs, 0) << Short(rhs), 0); |
| 3923 | result = Insert(result, Extract(lhs, 1) << Short(rhs), 1); |
| 3924 | result = Insert(result, Extract(lhs, 2) << Short(rhs), 2); |
| 3925 | result = Insert(result, Extract(lhs, 3) << Short(rhs), 3); |
| 3926 | result = Insert(result, Extract(lhs, 4) << Short(rhs), 4); |
| 3927 | result = Insert(result, Extract(lhs, 5) << Short(rhs), 5); |
| 3928 | result = Insert(result, Extract(lhs, 6) << Short(rhs), 6); |
| 3929 | result = Insert(result, Extract(lhs, 7) << Short(rhs), 7); |
| 3930 | |
| 3931 | return result; |
| 3932 | } |
| 3933 | else |
| 3934 | { |
| 3935 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3936 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3940 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3941 | if(emulateIntrinsics) |
| 3942 | { |
| 3943 | Short8 result; |
| 3944 | result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0); |
| 3945 | result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1); |
| 3946 | result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2); |
| 3947 | result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3); |
| 3948 | result = Insert(result, Extract(lhs, 4) >> Short(rhs), 4); |
| 3949 | result = Insert(result, Extract(lhs, 5) >> Short(rhs), 5); |
| 3950 | result = Insert(result, Extract(lhs, 6) >> Short(rhs), 6); |
| 3951 | result = Insert(result, Extract(lhs, 7) >> Short(rhs), 7); |
| 3952 | |
| 3953 | return result; |
| 3954 | } |
| 3955 | else |
| 3956 | { |
| 3957 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3958 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3962 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3963 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | RValue<Int4> Abs(RValue<Int4> x) |
| 3967 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3968 | auto negative = x >> 31; |
| 3969 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3973 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3974 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | Type *Short8::getType() |
| 3978 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3979 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3980 | } |
| 3981 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3982 | UShort8::UShort8(unsigned short c) |
| 3983 | { |
| 3984 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3985 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3986 | } |
| 3987 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3988 | 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) |
| 3989 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3990 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3991 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3995 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3996 | storeValue(rhs.value); |
| 3997 | } |
| 3998 | |
| 3999 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 4000 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4001 | Value *value = rhs.loadValue(); |
| 4002 | storeValue(value); |
| 4003 | } |
| 4004 | |
| 4005 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 4006 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4007 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 4008 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 4009 | |
| 4010 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4011 | } |
| 4012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4013 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4014 | { |
| 4015 | storeValue(rhs.value); |
| 4016 | |
| 4017 | return rhs; |
| 4018 | } |
| 4019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4020 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4021 | { |
| 4022 | Value *value = rhs.loadValue(); |
| 4023 | storeValue(value); |
| 4024 | |
| 4025 | return RValue<UShort8>(value); |
| 4026 | } |
| 4027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4028 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4029 | { |
| 4030 | Value *value = rhs.loadValue(); |
| 4031 | storeValue(value); |
| 4032 | |
| 4033 | return RValue<UShort8>(value); |
| 4034 | } |
| 4035 | |
| 4036 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4037 | { |
| 4038 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4039 | } |
| 4040 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4041 | RValue<UShort> Extract(RValue<UShort8> val, int i) |
| 4042 | { |
| 4043 | return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i)); |
| 4044 | } |
| 4045 | |
| 4046 | RValue<UShort8> Insert(RValue<UShort8> val, RValue<UShort> element, int i) |
| 4047 | { |
| 4048 | return RValue<UShort8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 4049 | } |
| 4050 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4051 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 4052 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4053 | if(emulateIntrinsics) |
| 4054 | { |
| 4055 | UShort8 result; |
| 4056 | result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0); |
| 4057 | result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1); |
| 4058 | result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2); |
| 4059 | result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3); |
| 4060 | result = Insert(result, Extract(lhs, 4) << UShort(rhs), 4); |
| 4061 | result = Insert(result, Extract(lhs, 5) << UShort(rhs), 5); |
| 4062 | result = Insert(result, Extract(lhs, 6) << UShort(rhs), 6); |
| 4063 | result = Insert(result, Extract(lhs, 7) << UShort(rhs), 7); |
| 4064 | |
| 4065 | return result; |
| 4066 | } |
| 4067 | else |
| 4068 | { |
| 4069 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4070 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 4074 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4075 | if(emulateIntrinsics) |
| 4076 | { |
| 4077 | UShort8 result; |
| 4078 | result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0); |
| 4079 | result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1); |
| 4080 | result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2); |
| 4081 | result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3); |
| 4082 | result = Insert(result, Extract(lhs, 4) >> UShort(rhs), 4); |
| 4083 | result = Insert(result, Extract(lhs, 5) >> UShort(rhs), 5); |
| 4084 | result = Insert(result, Extract(lhs, 6) >> UShort(rhs), 6); |
| 4085 | result = Insert(result, Extract(lhs, 7) >> UShort(rhs), 7); |
| 4086 | |
| 4087 | return result; |
| 4088 | } |
| 4089 | else |
| 4090 | { |
| 4091 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4092 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4096 | { |
| 4097 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4098 | } |
| 4099 | |
| 4100 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4101 | { |
| 4102 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4103 | } |
| 4104 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4105 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4106 | { |
| 4107 | return lhs = lhs + rhs; |
| 4108 | } |
| 4109 | |
| 4110 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 4111 | { |
| 4112 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 4113 | } |
| 4114 | |
| 4115 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 4116 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4117 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 4121 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4122 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 4126 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 4127 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4128 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4129 | // } |
| 4130 | |
| 4131 | Type *UShort8::getType() |
| 4132 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4133 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | Int::Int(Argument<Int> argument) |
| 4137 | { |
| 4138 | storeValue(argument.value); |
| 4139 | } |
| 4140 | |
| 4141 | Int::Int(RValue<Byte> cast) |
| 4142 | { |
| 4143 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 4144 | |
| 4145 | storeValue(integer); |
| 4146 | } |
| 4147 | |
| 4148 | Int::Int(RValue<SByte> cast) |
| 4149 | { |
| 4150 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 4151 | |
| 4152 | storeValue(integer); |
| 4153 | } |
| 4154 | |
| 4155 | Int::Int(RValue<Short> cast) |
| 4156 | { |
| 4157 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 4158 | |
| 4159 | storeValue(integer); |
| 4160 | } |
| 4161 | |
| 4162 | Int::Int(RValue<UShort> cast) |
| 4163 | { |
| 4164 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 4165 | |
| 4166 | storeValue(integer); |
| 4167 | } |
| 4168 | |
| 4169 | Int::Int(RValue<Int2> cast) |
| 4170 | { |
| 4171 | *this = Extract(cast, 0); |
| 4172 | } |
| 4173 | |
| 4174 | Int::Int(RValue<Long> cast) |
| 4175 | { |
| 4176 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 4177 | |
| 4178 | storeValue(integer); |
| 4179 | } |
| 4180 | |
| 4181 | Int::Int(RValue<Float> cast) |
| 4182 | { |
| 4183 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 4184 | |
| 4185 | storeValue(integer); |
| 4186 | } |
| 4187 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4188 | Int::Int(int x) |
| 4189 | { |
| 4190 | storeValue(Nucleus::createConstantInt(x)); |
| 4191 | } |
| 4192 | |
| 4193 | Int::Int(RValue<Int> rhs) |
| 4194 | { |
| 4195 | storeValue(rhs.value); |
| 4196 | } |
| 4197 | |
| 4198 | Int::Int(RValue<UInt> rhs) |
| 4199 | { |
| 4200 | storeValue(rhs.value); |
| 4201 | } |
| 4202 | |
| 4203 | Int::Int(const Int &rhs) |
| 4204 | { |
| 4205 | Value *value = rhs.loadValue(); |
| 4206 | storeValue(value); |
| 4207 | } |
| 4208 | |
| 4209 | Int::Int(const Reference<Int> &rhs) |
| 4210 | { |
| 4211 | Value *value = rhs.loadValue(); |
| 4212 | storeValue(value); |
| 4213 | } |
| 4214 | |
| 4215 | Int::Int(const UInt &rhs) |
| 4216 | { |
| 4217 | Value *value = rhs.loadValue(); |
| 4218 | storeValue(value); |
| 4219 | } |
| 4220 | |
| 4221 | Int::Int(const Reference<UInt> &rhs) |
| 4222 | { |
| 4223 | Value *value = rhs.loadValue(); |
| 4224 | storeValue(value); |
| 4225 | } |
| 4226 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4227 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4228 | { |
| 4229 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4230 | } |
| 4231 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4232 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4233 | { |
| 4234 | storeValue(rhs.value); |
| 4235 | |
| 4236 | return rhs; |
| 4237 | } |
| 4238 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4239 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4240 | { |
| 4241 | storeValue(rhs.value); |
| 4242 | |
| 4243 | return RValue<Int>(rhs); |
| 4244 | } |
| 4245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4246 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4247 | { |
| 4248 | Value *value = rhs.loadValue(); |
| 4249 | storeValue(value); |
| 4250 | |
| 4251 | return RValue<Int>(value); |
| 4252 | } |
| 4253 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4254 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4255 | { |
| 4256 | Value *value = rhs.loadValue(); |
| 4257 | storeValue(value); |
| 4258 | |
| 4259 | return RValue<Int>(value); |
| 4260 | } |
| 4261 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4262 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4263 | { |
| 4264 | Value *value = rhs.loadValue(); |
| 4265 | storeValue(value); |
| 4266 | |
| 4267 | return RValue<Int>(value); |
| 4268 | } |
| 4269 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4270 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4271 | { |
| 4272 | Value *value = rhs.loadValue(); |
| 4273 | storeValue(value); |
| 4274 | |
| 4275 | return RValue<Int>(value); |
| 4276 | } |
| 4277 | |
| 4278 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 4279 | { |
| 4280 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4281 | } |
| 4282 | |
| 4283 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 4284 | { |
| 4285 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4286 | } |
| 4287 | |
| 4288 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 4289 | { |
| 4290 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4291 | } |
| 4292 | |
| 4293 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 4294 | { |
| 4295 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4296 | } |
| 4297 | |
| 4298 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 4299 | { |
| 4300 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4301 | } |
| 4302 | |
| 4303 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 4304 | { |
| 4305 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4306 | } |
| 4307 | |
| 4308 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 4309 | { |
| 4310 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4311 | } |
| 4312 | |
| 4313 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 4314 | { |
| 4315 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4316 | } |
| 4317 | |
| 4318 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 4319 | { |
| 4320 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4321 | } |
| 4322 | |
| 4323 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 4324 | { |
| 4325 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4326 | } |
| 4327 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4328 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4329 | { |
| 4330 | return lhs = lhs + rhs; |
| 4331 | } |
| 4332 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4333 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4334 | { |
| 4335 | return lhs = lhs - rhs; |
| 4336 | } |
| 4337 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4338 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4339 | { |
| 4340 | return lhs = lhs * rhs; |
| 4341 | } |
| 4342 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4343 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4344 | { |
| 4345 | return lhs = lhs / rhs; |
| 4346 | } |
| 4347 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4348 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4349 | { |
| 4350 | return lhs = lhs % rhs; |
| 4351 | } |
| 4352 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4353 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4354 | { |
| 4355 | return lhs = lhs & rhs; |
| 4356 | } |
| 4357 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4358 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4359 | { |
| 4360 | return lhs = lhs | rhs; |
| 4361 | } |
| 4362 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4363 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4364 | { |
| 4365 | return lhs = lhs ^ rhs; |
| 4366 | } |
| 4367 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4368 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4369 | { |
| 4370 | return lhs = lhs << rhs; |
| 4371 | } |
| 4372 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4373 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4374 | { |
| 4375 | return lhs = lhs >> rhs; |
| 4376 | } |
| 4377 | |
| 4378 | RValue<Int> operator+(RValue<Int> val) |
| 4379 | { |
| 4380 | return val; |
| 4381 | } |
| 4382 | |
| 4383 | RValue<Int> operator-(RValue<Int> val) |
| 4384 | { |
| 4385 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4386 | } |
| 4387 | |
| 4388 | RValue<Int> operator~(RValue<Int> val) |
| 4389 | { |
| 4390 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4391 | } |
| 4392 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4393 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4394 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4395 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4396 | val += 1; |
| 4397 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4398 | } |
| 4399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4400 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4401 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4402 | val += 1; |
| 4403 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4404 | } |
| 4405 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4406 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4407 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4408 | RValue<Int> res = val; |
| 4409 | val -= 1; |
| 4410 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4411 | } |
| 4412 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4413 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4414 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4415 | val -= 1; |
| 4416 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4420 | { |
| 4421 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4422 | } |
| 4423 | |
| 4424 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4425 | { |
| 4426 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4427 | } |
| 4428 | |
| 4429 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4430 | { |
| 4431 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4432 | } |
| 4433 | |
| 4434 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4435 | { |
| 4436 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4437 | } |
| 4438 | |
| 4439 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4440 | { |
| 4441 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4442 | } |
| 4443 | |
| 4444 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4445 | { |
| 4446 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4447 | } |
| 4448 | |
| 4449 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4450 | { |
| 4451 | return IfThenElse(x > y, x, y); |
| 4452 | } |
| 4453 | |
| 4454 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4455 | { |
| 4456 | return IfThenElse(x < y, x, y); |
| 4457 | } |
| 4458 | |
| 4459 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4460 | { |
| 4461 | return Min(Max(x, min), max); |
| 4462 | } |
| 4463 | |
| 4464 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4465 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4466 | if(emulateIntrinsics) |
| 4467 | { |
| 4468 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 4469 | return Int((cast + Float(0x00C00000)) - Float(0x00C00000)); |
| 4470 | } |
| 4471 | else |
| 4472 | { |
| 4473 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 4474 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4475 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4476 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4477 | nearbyint->addArg(cast.value); |
| 4478 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4479 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4480 | return RValue<Int>(V(result)); |
| 4481 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | Type *Int::getType() |
| 4485 | { |
| 4486 | return T(Ice::IceType_i32); |
| 4487 | } |
| 4488 | |
| 4489 | Long::Long(RValue<Int> cast) |
| 4490 | { |
| 4491 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4492 | |
| 4493 | storeValue(integer); |
| 4494 | } |
| 4495 | |
| 4496 | Long::Long(RValue<UInt> cast) |
| 4497 | { |
| 4498 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4499 | |
| 4500 | storeValue(integer); |
| 4501 | } |
| 4502 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4503 | Long::Long(RValue<Long> rhs) |
| 4504 | { |
| 4505 | storeValue(rhs.value); |
| 4506 | } |
| 4507 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4508 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4509 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4510 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4511 | } |
| 4512 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4513 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4514 | { |
| 4515 | storeValue(rhs.value); |
| 4516 | |
| 4517 | return rhs; |
| 4518 | } |
| 4519 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4520 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4521 | { |
| 4522 | Value *value = rhs.loadValue(); |
| 4523 | storeValue(value); |
| 4524 | |
| 4525 | return RValue<Long>(value); |
| 4526 | } |
| 4527 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4528 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4529 | { |
| 4530 | Value *value = rhs.loadValue(); |
| 4531 | storeValue(value); |
| 4532 | |
| 4533 | return RValue<Long>(value); |
| 4534 | } |
| 4535 | |
| 4536 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4537 | { |
| 4538 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4539 | } |
| 4540 | |
| 4541 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4542 | { |
| 4543 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4544 | } |
| 4545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4546 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4547 | { |
| 4548 | return lhs = lhs + rhs; |
| 4549 | } |
| 4550 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4551 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4552 | { |
| 4553 | return lhs = lhs - rhs; |
| 4554 | } |
| 4555 | |
| 4556 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4557 | { |
| 4558 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4559 | } |
| 4560 | |
| 4561 | Type *Long::getType() |
| 4562 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4563 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4564 | } |
| 4565 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4566 | UInt::UInt(Argument<UInt> argument) |
| 4567 | { |
| 4568 | storeValue(argument.value); |
| 4569 | } |
| 4570 | |
| 4571 | UInt::UInt(RValue<UShort> cast) |
| 4572 | { |
| 4573 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4574 | |
| 4575 | storeValue(integer); |
| 4576 | } |
| 4577 | |
| 4578 | UInt::UInt(RValue<Long> cast) |
| 4579 | { |
| 4580 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4581 | |
| 4582 | storeValue(integer); |
| 4583 | } |
| 4584 | |
| 4585 | UInt::UInt(RValue<Float> cast) |
| 4586 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4587 | // Smallest positive value representable in UInt, but not in Int |
| 4588 | const unsigned int ustart = 0x80000000u; |
| 4589 | const float ustartf = float(ustart); |
| 4590 | |
| 4591 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4592 | storeValue((~(As<Int>(cast) >> 31) & |
| 4593 | // Check if the value can be represented as an Int |
| 4594 | IfThenElse(cast >= ustartf, |
| 4595 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4596 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4597 | // Otherwise, just convert normally |
| 4598 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4599 | } |
| 4600 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4601 | UInt::UInt(int x) |
| 4602 | { |
| 4603 | storeValue(Nucleus::createConstantInt(x)); |
| 4604 | } |
| 4605 | |
| 4606 | UInt::UInt(unsigned int x) |
| 4607 | { |
| 4608 | storeValue(Nucleus::createConstantInt(x)); |
| 4609 | } |
| 4610 | |
| 4611 | UInt::UInt(RValue<UInt> rhs) |
| 4612 | { |
| 4613 | storeValue(rhs.value); |
| 4614 | } |
| 4615 | |
| 4616 | UInt::UInt(RValue<Int> rhs) |
| 4617 | { |
| 4618 | storeValue(rhs.value); |
| 4619 | } |
| 4620 | |
| 4621 | UInt::UInt(const UInt &rhs) |
| 4622 | { |
| 4623 | Value *value = rhs.loadValue(); |
| 4624 | storeValue(value); |
| 4625 | } |
| 4626 | |
| 4627 | UInt::UInt(const Reference<UInt> &rhs) |
| 4628 | { |
| 4629 | Value *value = rhs.loadValue(); |
| 4630 | storeValue(value); |
| 4631 | } |
| 4632 | |
| 4633 | UInt::UInt(const Int &rhs) |
| 4634 | { |
| 4635 | Value *value = rhs.loadValue(); |
| 4636 | storeValue(value); |
| 4637 | } |
| 4638 | |
| 4639 | UInt::UInt(const Reference<Int> &rhs) |
| 4640 | { |
| 4641 | Value *value = rhs.loadValue(); |
| 4642 | storeValue(value); |
| 4643 | } |
| 4644 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4645 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4646 | { |
| 4647 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4648 | } |
| 4649 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4650 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4651 | { |
| 4652 | storeValue(rhs.value); |
| 4653 | |
| 4654 | return rhs; |
| 4655 | } |
| 4656 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4657 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4658 | { |
| 4659 | storeValue(rhs.value); |
| 4660 | |
| 4661 | return RValue<UInt>(rhs); |
| 4662 | } |
| 4663 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4664 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4665 | { |
| 4666 | Value *value = rhs.loadValue(); |
| 4667 | storeValue(value); |
| 4668 | |
| 4669 | return RValue<UInt>(value); |
| 4670 | } |
| 4671 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4672 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4673 | { |
| 4674 | Value *value = rhs.loadValue(); |
| 4675 | storeValue(value); |
| 4676 | |
| 4677 | return RValue<UInt>(value); |
| 4678 | } |
| 4679 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4680 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4681 | { |
| 4682 | Value *value = rhs.loadValue(); |
| 4683 | storeValue(value); |
| 4684 | |
| 4685 | return RValue<UInt>(value); |
| 4686 | } |
| 4687 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4688 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4689 | { |
| 4690 | Value *value = rhs.loadValue(); |
| 4691 | storeValue(value); |
| 4692 | |
| 4693 | return RValue<UInt>(value); |
| 4694 | } |
| 4695 | |
| 4696 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4697 | { |
| 4698 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4699 | } |
| 4700 | |
| 4701 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4702 | { |
| 4703 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4704 | } |
| 4705 | |
| 4706 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4707 | { |
| 4708 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4709 | } |
| 4710 | |
| 4711 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4712 | { |
| 4713 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4714 | } |
| 4715 | |
| 4716 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4717 | { |
| 4718 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4719 | } |
| 4720 | |
| 4721 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4722 | { |
| 4723 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4724 | } |
| 4725 | |
| 4726 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4727 | { |
| 4728 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4729 | } |
| 4730 | |
| 4731 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4732 | { |
| 4733 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4734 | } |
| 4735 | |
| 4736 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4737 | { |
| 4738 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4739 | } |
| 4740 | |
| 4741 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4742 | { |
| 4743 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4744 | } |
| 4745 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4746 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4747 | { |
| 4748 | return lhs = lhs + rhs; |
| 4749 | } |
| 4750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4751 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4752 | { |
| 4753 | return lhs = lhs - rhs; |
| 4754 | } |
| 4755 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4756 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4757 | { |
| 4758 | return lhs = lhs * rhs; |
| 4759 | } |
| 4760 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4761 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4762 | { |
| 4763 | return lhs = lhs / rhs; |
| 4764 | } |
| 4765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4766 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4767 | { |
| 4768 | return lhs = lhs % rhs; |
| 4769 | } |
| 4770 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4771 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4772 | { |
| 4773 | return lhs = lhs & rhs; |
| 4774 | } |
| 4775 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4776 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4777 | { |
| 4778 | return lhs = lhs | rhs; |
| 4779 | } |
| 4780 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4781 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4782 | { |
| 4783 | return lhs = lhs ^ rhs; |
| 4784 | } |
| 4785 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4786 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4787 | { |
| 4788 | return lhs = lhs << rhs; |
| 4789 | } |
| 4790 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4791 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4792 | { |
| 4793 | return lhs = lhs >> rhs; |
| 4794 | } |
| 4795 | |
| 4796 | RValue<UInt> operator+(RValue<UInt> val) |
| 4797 | { |
| 4798 | return val; |
| 4799 | } |
| 4800 | |
| 4801 | RValue<UInt> operator-(RValue<UInt> val) |
| 4802 | { |
| 4803 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4804 | } |
| 4805 | |
| 4806 | RValue<UInt> operator~(RValue<UInt> val) |
| 4807 | { |
| 4808 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4809 | } |
| 4810 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4811 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4812 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4813 | RValue<UInt> res = val; |
| 4814 | val += 1; |
| 4815 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4816 | } |
| 4817 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4818 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4819 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4820 | val += 1; |
| 4821 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4822 | } |
| 4823 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4824 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4825 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4826 | RValue<UInt> res = val; |
| 4827 | val -= 1; |
| 4828 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4829 | } |
| 4830 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4831 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4832 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4833 | val -= 1; |
| 4834 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4838 | { |
| 4839 | return IfThenElse(x > y, x, y); |
| 4840 | } |
| 4841 | |
| 4842 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4843 | { |
| 4844 | return IfThenElse(x < y, x, y); |
| 4845 | } |
| 4846 | |
| 4847 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4848 | { |
| 4849 | return Min(Max(x, min), max); |
| 4850 | } |
| 4851 | |
| 4852 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4853 | { |
| 4854 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4855 | } |
| 4856 | |
| 4857 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4858 | { |
| 4859 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4860 | } |
| 4861 | |
| 4862 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4863 | { |
| 4864 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4865 | } |
| 4866 | |
| 4867 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4868 | { |
| 4869 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4870 | } |
| 4871 | |
| 4872 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4873 | { |
| 4874 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4875 | } |
| 4876 | |
| 4877 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4878 | { |
| 4879 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4880 | } |
| 4881 | |
| 4882 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4883 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4884 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4885 | // } |
| 4886 | |
| 4887 | Type *UInt::getType() |
| 4888 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4889 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4890 | } |
| 4891 | |
| 4892 | // Int2::Int2(RValue<Int> cast) |
| 4893 | // { |
| 4894 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4895 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4896 | // |
| 4897 | // Constant *shuffle[2]; |
| 4898 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4899 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4900 | // |
| 4901 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4902 | // |
| 4903 | // storeValue(replicate); |
| 4904 | // } |
| 4905 | |
| 4906 | Int2::Int2(RValue<Int4> cast) |
| 4907 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4908 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4909 | } |
| 4910 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4911 | Int2::Int2(int x, int y) |
| 4912 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4913 | int64_t constantVector[2] = {x, y}; |
| 4914 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | Int2::Int2(RValue<Int2> rhs) |
| 4918 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4919 | storeValue(rhs.value); |
| 4920 | } |
| 4921 | |
| 4922 | Int2::Int2(const Int2 &rhs) |
| 4923 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4924 | Value *value = rhs.loadValue(); |
| 4925 | storeValue(value); |
| 4926 | } |
| 4927 | |
| 4928 | Int2::Int2(const Reference<Int2> &rhs) |
| 4929 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4930 | Value *value = rhs.loadValue(); |
| 4931 | storeValue(value); |
| 4932 | } |
| 4933 | |
| 4934 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4935 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4936 | int shuffle[4] = {0, 4, 1, 5}; |
| 4937 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4938 | |
| 4939 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4940 | } |
| 4941 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4942 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4943 | { |
| 4944 | storeValue(rhs.value); |
| 4945 | |
| 4946 | return rhs; |
| 4947 | } |
| 4948 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4949 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4950 | { |
| 4951 | Value *value = rhs.loadValue(); |
| 4952 | storeValue(value); |
| 4953 | |
| 4954 | return RValue<Int2>(value); |
| 4955 | } |
| 4956 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4957 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4958 | { |
| 4959 | Value *value = rhs.loadValue(); |
| 4960 | storeValue(value); |
| 4961 | |
| 4962 | return RValue<Int2>(value); |
| 4963 | } |
| 4964 | |
| 4965 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4966 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4967 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4971 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4972 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4976 | // { |
| 4977 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4978 | // } |
| 4979 | |
| 4980 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4981 | // { |
| 4982 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4983 | // } |
| 4984 | |
| 4985 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4986 | // { |
| 4987 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4988 | // } |
| 4989 | |
| 4990 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4991 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4992 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4996 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4997 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5001 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5002 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 5006 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5007 | if(emulateIntrinsics) |
| 5008 | { |
| 5009 | Int2 result; |
| 5010 | result = Insert(result, Extract(lhs, 0) << Int(rhs), 0); |
| 5011 | result = Insert(result, Extract(lhs, 1) << Int(rhs), 1); |
| 5012 | |
| 5013 | return result; |
| 5014 | } |
| 5015 | else |
| 5016 | { |
| 5017 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5018 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 5022 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5023 | if(emulateIntrinsics) |
| 5024 | { |
| 5025 | Int2 result; |
| 5026 | result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0); |
| 5027 | result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1); |
| 5028 | |
| 5029 | return result; |
| 5030 | } |
| 5031 | else |
| 5032 | { |
| 5033 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5034 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5035 | } |
| 5036 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5037 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5038 | { |
| 5039 | return lhs = lhs + rhs; |
| 5040 | } |
| 5041 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5042 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5043 | { |
| 5044 | return lhs = lhs - rhs; |
| 5045 | } |
| 5046 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5047 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5048 | // { |
| 5049 | // return lhs = lhs * rhs; |
| 5050 | // } |
| 5051 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5052 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5053 | // { |
| 5054 | // return lhs = lhs / rhs; |
| 5055 | // } |
| 5056 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5057 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5058 | // { |
| 5059 | // return lhs = lhs % rhs; |
| 5060 | // } |
| 5061 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5062 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5063 | { |
| 5064 | return lhs = lhs & rhs; |
| 5065 | } |
| 5066 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5067 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5068 | { |
| 5069 | return lhs = lhs | rhs; |
| 5070 | } |
| 5071 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5072 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5073 | { |
| 5074 | return lhs = lhs ^ rhs; |
| 5075 | } |
| 5076 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5077 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5078 | { |
| 5079 | return lhs = lhs << rhs; |
| 5080 | } |
| 5081 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5082 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5083 | { |
| 5084 | return lhs = lhs >> rhs; |
| 5085 | } |
| 5086 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5087 | // RValue<Int2> operator+(RValue<Int2> val) |
| 5088 | // { |
| 5089 | // return val; |
| 5090 | // } |
| 5091 | |
| 5092 | // RValue<Int2> operator-(RValue<Int2> val) |
| 5093 | // { |
| 5094 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 5095 | // } |
| 5096 | |
| 5097 | RValue<Int2> operator~(RValue<Int2> val) |
| 5098 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 5099 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5100 | } |
| 5101 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 5102 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5103 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5104 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 5105 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5106 | } |
| 5107 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 5108 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5109 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5110 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5111 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 5112 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 5116 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 5117 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 5121 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 5122 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | Type *Int2::getType() |
| 5126 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5127 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5128 | } |
| 5129 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5130 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 5131 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5132 | int64_t constantVector[2] = {x, y}; |
| 5133 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | UInt2::UInt2(RValue<UInt2> rhs) |
| 5137 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5138 | storeValue(rhs.value); |
| 5139 | } |
| 5140 | |
| 5141 | UInt2::UInt2(const UInt2 &rhs) |
| 5142 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5143 | Value *value = rhs.loadValue(); |
| 5144 | storeValue(value); |
| 5145 | } |
| 5146 | |
| 5147 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 5148 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5149 | Value *value = rhs.loadValue(); |
| 5150 | storeValue(value); |
| 5151 | } |
| 5152 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5153 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5154 | { |
| 5155 | storeValue(rhs.value); |
| 5156 | |
| 5157 | return rhs; |
| 5158 | } |
| 5159 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5160 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5161 | { |
| 5162 | Value *value = rhs.loadValue(); |
| 5163 | storeValue(value); |
| 5164 | |
| 5165 | return RValue<UInt2>(value); |
| 5166 | } |
| 5167 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5168 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5169 | { |
| 5170 | Value *value = rhs.loadValue(); |
| 5171 | storeValue(value); |
| 5172 | |
| 5173 | return RValue<UInt2>(value); |
| 5174 | } |
| 5175 | |
| 5176 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5177 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5178 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5182 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5183 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5187 | // { |
| 5188 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5189 | // } |
| 5190 | |
| 5191 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5192 | // { |
| 5193 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5194 | // } |
| 5195 | |
| 5196 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5197 | // { |
| 5198 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5199 | // } |
| 5200 | |
| 5201 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5202 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5203 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5207 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5208 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5212 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5213 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5214 | } |
| 5215 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5216 | RValue<UInt> Extract(RValue<UInt2> val, int i) |
| 5217 | { |
| 5218 | return RValue<UInt>(Nucleus::createExtractElement(val.value, UInt::getType(), i)); |
| 5219 | } |
| 5220 | |
| 5221 | RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i) |
| 5222 | { |
| 5223 | return RValue<UInt2>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 5224 | } |
| 5225 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5226 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 5227 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5228 | if(emulateIntrinsics) |
| 5229 | { |
| 5230 | UInt2 result; |
| 5231 | result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0); |
| 5232 | result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1); |
| 5233 | |
| 5234 | return result; |
| 5235 | } |
| 5236 | else |
| 5237 | { |
| 5238 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5239 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 5243 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5244 | if(emulateIntrinsics) |
| 5245 | { |
| 5246 | UInt2 result; |
| 5247 | result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0); |
| 5248 | result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1); |
| 5249 | |
| 5250 | return result; |
| 5251 | } |
| 5252 | else |
| 5253 | { |
| 5254 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5255 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5256 | } |
| 5257 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5258 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5259 | { |
| 5260 | return lhs = lhs + rhs; |
| 5261 | } |
| 5262 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5263 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5264 | { |
| 5265 | return lhs = lhs - rhs; |
| 5266 | } |
| 5267 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5268 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5269 | // { |
| 5270 | // return lhs = lhs * rhs; |
| 5271 | // } |
| 5272 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5273 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5274 | // { |
| 5275 | // return lhs = lhs / rhs; |
| 5276 | // } |
| 5277 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5278 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5279 | // { |
| 5280 | // return lhs = lhs % rhs; |
| 5281 | // } |
| 5282 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5283 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5284 | { |
| 5285 | return lhs = lhs & rhs; |
| 5286 | } |
| 5287 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5288 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5289 | { |
| 5290 | return lhs = lhs | rhs; |
| 5291 | } |
| 5292 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5293 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5294 | { |
| 5295 | return lhs = lhs ^ rhs; |
| 5296 | } |
| 5297 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5298 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5299 | { |
| 5300 | return lhs = lhs << rhs; |
| 5301 | } |
| 5302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5303 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5304 | { |
| 5305 | return lhs = lhs >> rhs; |
| 5306 | } |
| 5307 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5308 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 5309 | // { |
| 5310 | // return val; |
| 5311 | // } |
| 5312 | |
| 5313 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 5314 | // { |
| 5315 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 5316 | // } |
| 5317 | |
| 5318 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 5319 | { |
| 5320 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 5321 | } |
| 5322 | |
| 5323 | Type *UInt2::getType() |
| 5324 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5325 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | Int4::Int4(RValue<Byte4> cast) |
| 5329 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5330 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5331 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5332 | |
| 5333 | Value *e; |
| 5334 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 5335 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5336 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 5337 | |
| 5338 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5339 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5340 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 5341 | |
| 5342 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5343 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | Int4::Int4(RValue<SByte4> cast) |
| 5347 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5348 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5349 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5350 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5351 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 5352 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5353 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 5354 | |
| 5355 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5356 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5357 | Value *e = Nucleus::createShuffleVector(d, d, swizzle2); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5358 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5359 | *this = As<Int4>(e) >> 24; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | Int4::Int4(RValue<Float4> cast) |
| 5363 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5364 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 5365 | |
| 5366 | storeValue(xyzw); |
| 5367 | } |
| 5368 | |
| 5369 | Int4::Int4(RValue<Short4> cast) |
| 5370 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5371 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5372 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5373 | |
| 5374 | *this = As<Int4>(c) >> 16; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | Int4::Int4(RValue<UShort4> cast) |
| 5378 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5379 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5380 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5381 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5382 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5383 | } |
| 5384 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5385 | Int4::Int4(int xyzw) |
| 5386 | { |
| 5387 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5388 | } |
| 5389 | |
| 5390 | Int4::Int4(int x, int yzw) |
| 5391 | { |
| 5392 | constant(x, yzw, yzw, yzw); |
| 5393 | } |
| 5394 | |
| 5395 | Int4::Int4(int x, int y, int zw) |
| 5396 | { |
| 5397 | constant(x, y, zw, zw); |
| 5398 | } |
| 5399 | |
| 5400 | Int4::Int4(int x, int y, int z, int w) |
| 5401 | { |
| 5402 | constant(x, y, z, w); |
| 5403 | } |
| 5404 | |
| 5405 | void Int4::constant(int x, int y, int z, int w) |
| 5406 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5407 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5408 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | Int4::Int4(RValue<Int4> rhs) |
| 5412 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5413 | storeValue(rhs.value); |
| 5414 | } |
| 5415 | |
| 5416 | Int4::Int4(const Int4 &rhs) |
| 5417 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5418 | Value *value = rhs.loadValue(); |
| 5419 | storeValue(value); |
| 5420 | } |
| 5421 | |
| 5422 | Int4::Int4(const Reference<Int4> &rhs) |
| 5423 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5424 | Value *value = rhs.loadValue(); |
| 5425 | storeValue(value); |
| 5426 | } |
| 5427 | |
| 5428 | Int4::Int4(RValue<UInt4> rhs) |
| 5429 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5430 | storeValue(rhs.value); |
| 5431 | } |
| 5432 | |
| 5433 | Int4::Int4(const UInt4 &rhs) |
| 5434 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5435 | Value *value = rhs.loadValue(); |
| 5436 | storeValue(value); |
| 5437 | } |
| 5438 | |
| 5439 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5440 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5441 | Value *value = rhs.loadValue(); |
| 5442 | storeValue(value); |
| 5443 | } |
| 5444 | |
| 5445 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5446 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5447 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5448 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5449 | |
| 5450 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | Int4::Int4(RValue<Int> rhs) |
| 5454 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5455 | Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5456 | |
| 5457 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5458 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5459 | |
| 5460 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | Int4::Int4(const Int &rhs) |
| 5464 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5465 | *this = RValue<Int>(rhs.loadValue()); |
| 5466 | } |
| 5467 | |
| 5468 | Int4::Int4(const Reference<Int> &rhs) |
| 5469 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5470 | *this = RValue<Int>(rhs.loadValue()); |
| 5471 | } |
| 5472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5473 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5474 | { |
| 5475 | storeValue(rhs.value); |
| 5476 | |
| 5477 | return rhs; |
| 5478 | } |
| 5479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5480 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5481 | { |
| 5482 | Value *value = rhs.loadValue(); |
| 5483 | storeValue(value); |
| 5484 | |
| 5485 | return RValue<Int4>(value); |
| 5486 | } |
| 5487 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5488 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5489 | { |
| 5490 | Value *value = rhs.loadValue(); |
| 5491 | storeValue(value); |
| 5492 | |
| 5493 | return RValue<Int4>(value); |
| 5494 | } |
| 5495 | |
| 5496 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5497 | { |
| 5498 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5499 | } |
| 5500 | |
| 5501 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5502 | { |
| 5503 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5504 | } |
| 5505 | |
| 5506 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5507 | { |
| 5508 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5509 | } |
| 5510 | |
| 5511 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5512 | { |
| 5513 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5514 | } |
| 5515 | |
| 5516 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5517 | { |
| 5518 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5519 | } |
| 5520 | |
| 5521 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5522 | { |
| 5523 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5524 | } |
| 5525 | |
| 5526 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5527 | { |
| 5528 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5529 | } |
| 5530 | |
| 5531 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5532 | { |
| 5533 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5534 | } |
| 5535 | |
| 5536 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5537 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5538 | if(emulateIntrinsics) |
| 5539 | { |
| 5540 | Int4 result; |
| 5541 | result = Insert(result, Extract(lhs, 0) << Int(rhs), 0); |
| 5542 | result = Insert(result, Extract(lhs, 1) << Int(rhs), 1); |
| 5543 | result = Insert(result, Extract(lhs, 2) << Int(rhs), 2); |
| 5544 | result = Insert(result, Extract(lhs, 3) << Int(rhs), 3); |
| 5545 | |
| 5546 | return result; |
| 5547 | } |
| 5548 | else |
| 5549 | { |
| 5550 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5551 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5555 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5556 | if(emulateIntrinsics) |
| 5557 | { |
| 5558 | Int4 result; |
| 5559 | result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0); |
| 5560 | result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1); |
| 5561 | result = Insert(result, Extract(lhs, 2) >> Int(rhs), 2); |
| 5562 | result = Insert(result, Extract(lhs, 3) >> Int(rhs), 3); |
| 5563 | |
| 5564 | return result; |
| 5565 | } |
| 5566 | else |
| 5567 | { |
| 5568 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5569 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5573 | { |
| 5574 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5575 | } |
| 5576 | |
| 5577 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5578 | { |
| 5579 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5580 | } |
| 5581 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5582 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5583 | { |
| 5584 | return lhs = lhs + rhs; |
| 5585 | } |
| 5586 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5587 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5588 | { |
| 5589 | return lhs = lhs - rhs; |
| 5590 | } |
| 5591 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5592 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5593 | { |
| 5594 | return lhs = lhs * rhs; |
| 5595 | } |
| 5596 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5597 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5598 | // { |
| 5599 | // return lhs = lhs / rhs; |
| 5600 | // } |
| 5601 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5602 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5603 | // { |
| 5604 | // return lhs = lhs % rhs; |
| 5605 | // } |
| 5606 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5607 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5608 | { |
| 5609 | return lhs = lhs & rhs; |
| 5610 | } |
| 5611 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5612 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5613 | { |
| 5614 | return lhs = lhs | rhs; |
| 5615 | } |
| 5616 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5617 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5618 | { |
| 5619 | return lhs = lhs ^ rhs; |
| 5620 | } |
| 5621 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5622 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5623 | { |
| 5624 | return lhs = lhs << rhs; |
| 5625 | } |
| 5626 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5627 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5628 | { |
| 5629 | return lhs = lhs >> rhs; |
| 5630 | } |
| 5631 | |
| 5632 | RValue<Int4> operator+(RValue<Int4> val) |
| 5633 | { |
| 5634 | return val; |
| 5635 | } |
| 5636 | |
| 5637 | RValue<Int4> operator-(RValue<Int4> val) |
| 5638 | { |
| 5639 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5640 | } |
| 5641 | |
| 5642 | RValue<Int4> operator~(RValue<Int4> val) |
| 5643 | { |
| 5644 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5645 | } |
| 5646 | |
| 5647 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5648 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5649 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5653 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5654 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5655 | } |
| 5656 | |
| 5657 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5658 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5659 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5663 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5664 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5668 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5669 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5670 | } |
| 5671 | |
| 5672 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5673 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5674 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5678 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5679 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5680 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5681 | ::basicBlock->appendInst(cmp); |
| 5682 | |
| 5683 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5684 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5685 | ::basicBlock->appendInst(select); |
| 5686 | |
| 5687 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5691 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5692 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5693 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5694 | ::basicBlock->appendInst(cmp); |
| 5695 | |
| 5696 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5697 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5698 | ::basicBlock->appendInst(select); |
| 5699 | |
| 5700 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5704 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5705 | if(emulateIntrinsics) |
| 5706 | { |
| 5707 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 5708 | return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000)); |
| 5709 | } |
| 5710 | else |
| 5711 | { |
| 5712 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5713 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5714 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5715 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5716 | nearbyint->addArg(cast.value); |
| 5717 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5718 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5719 | return RValue<Int4>(V(result)); |
| 5720 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5724 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5725 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5726 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5727 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5728 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5729 | pack->addArg(x.value); |
| 5730 | pack->addArg(y.value); |
| 5731 | ::basicBlock->appendInst(pack); |
| 5732 | |
| 5733 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5737 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5738 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5742 | { |
| 5743 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5744 | } |
| 5745 | |
| 5746 | RValue<Int> SignMask(RValue<Int4> x) |
| 5747 | { |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 5748 | if(emulateIntrinsics) |
| 5749 | { |
| 5750 | Int4 xx = (x >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008); |
| 5751 | return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3); |
| 5752 | } |
| 5753 | else |
| 5754 | { |
| 5755 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5756 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5757 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5758 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5759 | movmsk->addArg(x.value); |
| 5760 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5761 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 5762 | return RValue<Int>(V(result)); |
| 5763 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5767 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5768 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | Type *Int4::getType() |
| 5772 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5773 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | UInt4::UInt4(RValue<Float4> cast) |
| 5777 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5778 | // Smallest positive value representable in UInt, but not in Int |
| 5779 | const unsigned int ustart = 0x80000000u; |
| 5780 | const float ustartf = float(ustart); |
| 5781 | |
| 5782 | // Check if the value can be represented as an Int |
| 5783 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5784 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5785 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5786 | // Otherwise, just convert normally |
| 5787 | (~uiValue & Int4(cast)); |
| 5788 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5789 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5790 | } |
| 5791 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5792 | UInt4::UInt4(int xyzw) |
| 5793 | { |
| 5794 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5795 | } |
| 5796 | |
| 5797 | UInt4::UInt4(int x, int yzw) |
| 5798 | { |
| 5799 | constant(x, yzw, yzw, yzw); |
| 5800 | } |
| 5801 | |
| 5802 | UInt4::UInt4(int x, int y, int zw) |
| 5803 | { |
| 5804 | constant(x, y, zw, zw); |
| 5805 | } |
| 5806 | |
| 5807 | UInt4::UInt4(int x, int y, int z, int w) |
| 5808 | { |
| 5809 | constant(x, y, z, w); |
| 5810 | } |
| 5811 | |
| 5812 | void UInt4::constant(int x, int y, int z, int w) |
| 5813 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5814 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5815 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5819 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5820 | storeValue(rhs.value); |
| 5821 | } |
| 5822 | |
| 5823 | UInt4::UInt4(const UInt4 &rhs) |
| 5824 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5825 | Value *value = rhs.loadValue(); |
| 5826 | storeValue(value); |
| 5827 | } |
| 5828 | |
| 5829 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5830 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5831 | Value *value = rhs.loadValue(); |
| 5832 | storeValue(value); |
| 5833 | } |
| 5834 | |
| 5835 | UInt4::UInt4(RValue<Int4> rhs) |
| 5836 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5837 | storeValue(rhs.value); |
| 5838 | } |
| 5839 | |
| 5840 | UInt4::UInt4(const Int4 &rhs) |
| 5841 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5842 | Value *value = rhs.loadValue(); |
| 5843 | storeValue(value); |
| 5844 | } |
| 5845 | |
| 5846 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5847 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5848 | Value *value = rhs.loadValue(); |
| 5849 | storeValue(value); |
| 5850 | } |
| 5851 | |
| 5852 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5853 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5854 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5855 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5856 | |
| 5857 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5858 | } |
| 5859 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5860 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5861 | { |
| 5862 | storeValue(rhs.value); |
| 5863 | |
| 5864 | return rhs; |
| 5865 | } |
| 5866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5867 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5868 | { |
| 5869 | Value *value = rhs.loadValue(); |
| 5870 | storeValue(value); |
| 5871 | |
| 5872 | return RValue<UInt4>(value); |
| 5873 | } |
| 5874 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5875 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5876 | { |
| 5877 | Value *value = rhs.loadValue(); |
| 5878 | storeValue(value); |
| 5879 | |
| 5880 | return RValue<UInt4>(value); |
| 5881 | } |
| 5882 | |
| 5883 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5884 | { |
| 5885 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5886 | } |
| 5887 | |
| 5888 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5889 | { |
| 5890 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5891 | } |
| 5892 | |
| 5893 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5894 | { |
| 5895 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5896 | } |
| 5897 | |
| 5898 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5899 | { |
| 5900 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5901 | } |
| 5902 | |
| 5903 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5904 | { |
| 5905 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5906 | } |
| 5907 | |
| 5908 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5909 | { |
| 5910 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5911 | } |
| 5912 | |
| 5913 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5914 | { |
| 5915 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5916 | } |
| 5917 | |
| 5918 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5919 | { |
| 5920 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5921 | } |
| 5922 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5923 | RValue<UInt> Extract(RValue<UInt4> x, int i) |
| 5924 | { |
| 5925 | return RValue<UInt>(Nucleus::createExtractElement(x.value, UInt::getType(), i)); |
| 5926 | } |
| 5927 | |
| 5928 | RValue<UInt4> Insert(RValue<UInt4> x, RValue<UInt> element, int i) |
| 5929 | { |
| 5930 | return RValue<UInt4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5931 | } |
| 5932 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5933 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5934 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5935 | if(emulateIntrinsics) |
| 5936 | { |
| 5937 | UInt4 result; |
| 5938 | result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0); |
| 5939 | result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1); |
| 5940 | result = Insert(result, Extract(lhs, 2) << UInt(rhs), 2); |
| 5941 | result = Insert(result, Extract(lhs, 3) << UInt(rhs), 3); |
| 5942 | |
| 5943 | return result; |
| 5944 | } |
| 5945 | else |
| 5946 | { |
| 5947 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5948 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5949 | } |
| 5950 | |
| 5951 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5952 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5953 | if(emulateIntrinsics) |
| 5954 | { |
| 5955 | UInt4 result; |
| 5956 | result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0); |
| 5957 | result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1); |
| 5958 | result = Insert(result, Extract(lhs, 2) >> UInt(rhs), 2); |
| 5959 | result = Insert(result, Extract(lhs, 3) >> UInt(rhs), 3); |
| 5960 | |
| 5961 | return result; |
| 5962 | } |
| 5963 | else |
| 5964 | { |
| 5965 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5966 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5970 | { |
| 5971 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5972 | } |
| 5973 | |
| 5974 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5975 | { |
| 5976 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5977 | } |
| 5978 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5979 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5980 | { |
| 5981 | return lhs = lhs + rhs; |
| 5982 | } |
| 5983 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5984 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5985 | { |
| 5986 | return lhs = lhs - rhs; |
| 5987 | } |
| 5988 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5989 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5990 | { |
| 5991 | return lhs = lhs * rhs; |
| 5992 | } |
| 5993 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5994 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5995 | // { |
| 5996 | // return lhs = lhs / rhs; |
| 5997 | // } |
| 5998 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5999 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6000 | // { |
| 6001 | // return lhs = lhs % rhs; |
| 6002 | // } |
| 6003 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6004 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6005 | { |
| 6006 | return lhs = lhs & rhs; |
| 6007 | } |
| 6008 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6009 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6010 | { |
| 6011 | return lhs = lhs | rhs; |
| 6012 | } |
| 6013 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6014 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6015 | { |
| 6016 | return lhs = lhs ^ rhs; |
| 6017 | } |
| 6018 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6019 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6020 | { |
| 6021 | return lhs = lhs << rhs; |
| 6022 | } |
| 6023 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6024 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6025 | { |
| 6026 | return lhs = lhs >> rhs; |
| 6027 | } |
| 6028 | |
| 6029 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 6030 | { |
| 6031 | return val; |
| 6032 | } |
| 6033 | |
| 6034 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 6035 | { |
| 6036 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 6037 | } |
| 6038 | |
| 6039 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 6040 | { |
| 6041 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 6042 | } |
| 6043 | |
| 6044 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6045 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6046 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6050 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6051 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6055 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6056 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6060 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6061 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6065 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6066 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6070 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6071 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6072 | } |
| 6073 | |
| 6074 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 6075 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6076 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6077 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 6078 | ::basicBlock->appendInst(cmp); |
| 6079 | |
| 6080 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6081 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6082 | ::basicBlock->appendInst(select); |
| 6083 | |
| 6084 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 6088 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6089 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6090 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 6091 | ::basicBlock->appendInst(cmp); |
| 6092 | |
| 6093 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6094 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6095 | ::basicBlock->appendInst(select); |
| 6096 | |
| 6097 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 6101 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6102 | if(CPUID::SSE4_1) |
| 6103 | { |
| 6104 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 6105 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6106 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6107 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6108 | pack->addArg(x.value); |
| 6109 | pack->addArg(y.value); |
| 6110 | ::basicBlock->appendInst(pack); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 6111 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6112 | return RValue<UShort8>(V(result)); |
| 6113 | } |
| 6114 | else |
| 6115 | { |
| 6116 | RValue<Int4> sx = As<Int4>(x); |
| 6117 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 6118 | |
| 6119 | RValue<Int4> sy = As<Int4>(y); |
| 6120 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 6121 | |
| 6122 | return As<UShort8>(Pack(bx, by) + Short8(0x8000u)); |
| 6123 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | Type *UInt4::getType() |
| 6127 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 6128 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | Float::Float(RValue<Int> cast) |
| 6132 | { |
| 6133 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 6134 | |
| 6135 | storeValue(integer); |
| 6136 | } |
| 6137 | |
Alexis Hetu | cfd9632 | 2017-07-24 14:44:33 -0400 | [diff] [blame] | 6138 | Float::Float(RValue<UInt> cast) |
| 6139 | { |
| 6140 | RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) + |
| 6141 | As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u))); |
| 6142 | |
| 6143 | storeValue(result.value); |
| 6144 | } |
| 6145 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6146 | Float::Float(float x) |
| 6147 | { |
| 6148 | storeValue(Nucleus::createConstantFloat(x)); |
| 6149 | } |
| 6150 | |
| 6151 | Float::Float(RValue<Float> rhs) |
| 6152 | { |
| 6153 | storeValue(rhs.value); |
| 6154 | } |
| 6155 | |
| 6156 | Float::Float(const Float &rhs) |
| 6157 | { |
| 6158 | Value *value = rhs.loadValue(); |
| 6159 | storeValue(value); |
| 6160 | } |
| 6161 | |
| 6162 | Float::Float(const Reference<Float> &rhs) |
| 6163 | { |
| 6164 | Value *value = rhs.loadValue(); |
| 6165 | storeValue(value); |
| 6166 | } |
| 6167 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6168 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6169 | { |
| 6170 | storeValue(rhs.value); |
| 6171 | |
| 6172 | return rhs; |
| 6173 | } |
| 6174 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6175 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6176 | { |
| 6177 | Value *value = rhs.loadValue(); |
| 6178 | storeValue(value); |
| 6179 | |
| 6180 | return RValue<Float>(value); |
| 6181 | } |
| 6182 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6183 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6184 | { |
| 6185 | Value *value = rhs.loadValue(); |
| 6186 | storeValue(value); |
| 6187 | |
| 6188 | return RValue<Float>(value); |
| 6189 | } |
| 6190 | |
| 6191 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 6192 | { |
| 6193 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6194 | } |
| 6195 | |
| 6196 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 6197 | { |
| 6198 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6199 | } |
| 6200 | |
| 6201 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 6202 | { |
| 6203 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6204 | } |
| 6205 | |
| 6206 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 6207 | { |
| 6208 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6209 | } |
| 6210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6211 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6212 | { |
| 6213 | return lhs = lhs + rhs; |
| 6214 | } |
| 6215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6216 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6217 | { |
| 6218 | return lhs = lhs - rhs; |
| 6219 | } |
| 6220 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6221 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6222 | { |
| 6223 | return lhs = lhs * rhs; |
| 6224 | } |
| 6225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6226 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6227 | { |
| 6228 | return lhs = lhs / rhs; |
| 6229 | } |
| 6230 | |
| 6231 | RValue<Float> operator+(RValue<Float> val) |
| 6232 | { |
| 6233 | return val; |
| 6234 | } |
| 6235 | |
| 6236 | RValue<Float> operator-(RValue<Float> val) |
| 6237 | { |
| 6238 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 6239 | } |
| 6240 | |
| 6241 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 6242 | { |
| 6243 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 6244 | } |
| 6245 | |
| 6246 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 6247 | { |
| 6248 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 6249 | } |
| 6250 | |
| 6251 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 6252 | { |
| 6253 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 6254 | } |
| 6255 | |
| 6256 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 6257 | { |
| 6258 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 6259 | } |
| 6260 | |
| 6261 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 6262 | { |
| 6263 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 6264 | } |
| 6265 | |
| 6266 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 6267 | { |
| 6268 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 6269 | } |
| 6270 | |
| 6271 | RValue<Float> Abs(RValue<Float> x) |
| 6272 | { |
| 6273 | return IfThenElse(x > 0.0f, x, -x); |
| 6274 | } |
| 6275 | |
| 6276 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 6277 | { |
| 6278 | return IfThenElse(x > y, x, y); |
| 6279 | } |
| 6280 | |
| 6281 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 6282 | { |
| 6283 | return IfThenElse(x < y, x, y); |
| 6284 | } |
| 6285 | |
| 6286 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 6287 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6288 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 6292 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6293 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | RValue<Float> Sqrt(RValue<Float> x) |
| 6297 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6298 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 6299 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6300 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6301 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6302 | sqrt->addArg(x.value); |
| 6303 | ::basicBlock->appendInst(sqrt); |
| 6304 | |
| 6305 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | RValue<Float> Round(RValue<Float> x) |
| 6309 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6310 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | RValue<Float> Trunc(RValue<Float> x) |
| 6314 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6315 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | RValue<Float> Frac(RValue<Float> x) |
| 6319 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6320 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6321 | } |
| 6322 | |
| 6323 | RValue<Float> Floor(RValue<Float> x) |
| 6324 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6325 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6326 | } |
| 6327 | |
| 6328 | RValue<Float> Ceil(RValue<Float> x) |
| 6329 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6330 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | Type *Float::getType() |
| 6334 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6335 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | Float2::Float2(RValue<Float4> cast) |
| 6339 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 6340 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6341 | } |
| 6342 | |
| 6343 | Type *Float2::getType() |
| 6344 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 6345 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6346 | } |
| 6347 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6348 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6349 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6350 | Value *a = Int4(cast).loadValue(); |
| 6351 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 6352 | |
| 6353 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6354 | } |
| 6355 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6356 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6357 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6358 | Value *a = Int4(cast).loadValue(); |
| 6359 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 6360 | |
| 6361 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6362 | } |
| 6363 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6364 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6365 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6366 | Int4 c(cast); |
| 6367 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 6368 | } |
| 6369 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6370 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6371 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6372 | Int4 c(cast); |
| 6373 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 6374 | } |
| 6375 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6376 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6377 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6378 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 6379 | |
| 6380 | storeValue(xyzw); |
| 6381 | } |
| 6382 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6383 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6384 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 6385 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 6386 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6387 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 6388 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6389 | } |
| 6390 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6391 | Float4::Float4() : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6392 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6395 | Float4::Float4(float xyzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6396 | { |
| 6397 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6398 | } |
| 6399 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6400 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6401 | { |
| 6402 | constant(x, yzw, yzw, yzw); |
| 6403 | } |
| 6404 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6405 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6406 | { |
| 6407 | constant(x, y, zw, zw); |
| 6408 | } |
| 6409 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6410 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6411 | { |
| 6412 | constant(x, y, z, w); |
| 6413 | } |
| 6414 | |
| 6415 | void Float4::constant(float x, float y, float z, float w) |
| 6416 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6417 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6418 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6419 | } |
| 6420 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6421 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6422 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6423 | storeValue(rhs.value); |
| 6424 | } |
| 6425 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6426 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6427 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6428 | Value *value = rhs.loadValue(); |
| 6429 | storeValue(value); |
| 6430 | } |
| 6431 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6432 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6433 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6434 | Value *value = rhs.loadValue(); |
| 6435 | storeValue(value); |
| 6436 | } |
| 6437 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6438 | Float4::Float4(RValue<Float> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6439 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6440 | Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6441 | |
| 6442 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6443 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6444 | |
| 6445 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6446 | } |
| 6447 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6448 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6449 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6450 | *this = RValue<Float>(rhs.loadValue()); |
| 6451 | } |
| 6452 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6453 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6454 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6455 | *this = RValue<Float>(rhs.loadValue()); |
| 6456 | } |
| 6457 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6458 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6459 | { |
| 6460 | return *this = Float4(x, x, x, x); |
| 6461 | } |
| 6462 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6463 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6464 | { |
| 6465 | storeValue(rhs.value); |
| 6466 | |
| 6467 | return rhs; |
| 6468 | } |
| 6469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6470 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6471 | { |
| 6472 | Value *value = rhs.loadValue(); |
| 6473 | storeValue(value); |
| 6474 | |
| 6475 | return RValue<Float4>(value); |
| 6476 | } |
| 6477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6478 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6479 | { |
| 6480 | Value *value = rhs.loadValue(); |
| 6481 | storeValue(value); |
| 6482 | |
| 6483 | return RValue<Float4>(value); |
| 6484 | } |
| 6485 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6486 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6487 | { |
| 6488 | return *this = Float4(rhs); |
| 6489 | } |
| 6490 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6491 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6492 | { |
| 6493 | return *this = Float4(rhs); |
| 6494 | } |
| 6495 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6496 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6497 | { |
| 6498 | return *this = Float4(rhs); |
| 6499 | } |
| 6500 | |
| 6501 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6502 | { |
| 6503 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6504 | } |
| 6505 | |
| 6506 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6507 | { |
| 6508 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6509 | } |
| 6510 | |
| 6511 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6512 | { |
| 6513 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6514 | } |
| 6515 | |
| 6516 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6517 | { |
| 6518 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6519 | } |
| 6520 | |
| 6521 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6522 | { |
| 6523 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6524 | } |
| 6525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6526 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6527 | { |
| 6528 | return lhs = lhs + rhs; |
| 6529 | } |
| 6530 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6531 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6532 | { |
| 6533 | return lhs = lhs - rhs; |
| 6534 | } |
| 6535 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6536 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6537 | { |
| 6538 | return lhs = lhs * rhs; |
| 6539 | } |
| 6540 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6541 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6542 | { |
| 6543 | return lhs = lhs / rhs; |
| 6544 | } |
| 6545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6546 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6547 | { |
| 6548 | return lhs = lhs % rhs; |
| 6549 | } |
| 6550 | |
| 6551 | RValue<Float4> operator+(RValue<Float4> val) |
| 6552 | { |
| 6553 | return val; |
| 6554 | } |
| 6555 | |
| 6556 | RValue<Float4> operator-(RValue<Float4> val) |
| 6557 | { |
| 6558 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6559 | } |
| 6560 | |
| 6561 | RValue<Float4> Abs(RValue<Float4> x) |
| 6562 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6563 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6564 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6565 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6566 | |
| 6567 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6571 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6572 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6573 | 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] | 6574 | ::basicBlock->appendInst(cmp); |
| 6575 | |
| 6576 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6577 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6578 | ::basicBlock->appendInst(select); |
| 6579 | |
| 6580 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6581 | } |
| 6582 | |
| 6583 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6584 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6585 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6586 | 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] | 6587 | ::basicBlock->appendInst(cmp); |
| 6588 | |
| 6589 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6590 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6591 | ::basicBlock->appendInst(select); |
| 6592 | |
| 6593 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6597 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6598 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6599 | } |
| 6600 | |
| 6601 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6602 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6603 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6607 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6608 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6609 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6610 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6611 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6612 | sqrt->addArg(x.value); |
| 6613 | ::basicBlock->appendInst(sqrt); |
| 6614 | |
| 6615 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6616 | } |
| 6617 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6618 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6619 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6620 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6624 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6625 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6626 | } |
| 6627 | |
| 6628 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6629 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6630 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6631 | } |
| 6632 | |
| 6633 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6634 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6635 | int shuffle[4] = |
| 6636 | { |
| 6637 | ((imm >> 0) & 0x03) + 0, |
| 6638 | ((imm >> 2) & 0x03) + 0, |
| 6639 | ((imm >> 4) & 0x03) + 4, |
| 6640 | ((imm >> 6) & 0x03) + 4, |
| 6641 | }; |
| 6642 | |
| 6643 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6644 | } |
| 6645 | |
| 6646 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6647 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6648 | int shuffle[4] = {0, 4, 1, 5}; |
| 6649 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6653 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6654 | int shuffle[4] = {2, 6, 3, 7}; |
| 6655 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6659 | { |
| 6660 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6661 | Value *result = createMask4(vector, rhs.value, select); |
| 6662 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6663 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6664 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | RValue<Int> SignMask(RValue<Float4> x) |
| 6668 | { |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 6669 | if(emulateIntrinsics) |
| 6670 | { |
| 6671 | Int4 xx = (As<Int4>(x) >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008); |
| 6672 | return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3); |
| 6673 | } |
| 6674 | else |
| 6675 | { |
| 6676 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6677 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6678 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6679 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6680 | movmsk->addArg(x.value); |
| 6681 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6682 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame^] | 6683 | return RValue<Int>(V(result)); |
| 6684 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6685 | } |
| 6686 | |
| 6687 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6688 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6689 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6693 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6694 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6698 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6699 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6703 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6704 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6708 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6709 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6713 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6714 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | RValue<Float4> Round(RValue<Float4> x) |
| 6718 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 6719 | if(emulateIntrinsics) |
| 6720 | { |
| 6721 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 6722 | return (x + Float4(0x00C00000)) - Float4(0x00C00000); |
| 6723 | } |
| 6724 | else if(CPUID::SSE4_1) |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6725 | { |
| 6726 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6727 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6728 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6729 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6730 | round->addArg(x.value); |
| 6731 | round->addArg(::context->getConstantInt32(0)); |
| 6732 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6733 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6734 | return RValue<Float4>(V(result)); |
| 6735 | } |
| 6736 | else |
| 6737 | { |
| 6738 | return Float4(RoundInt(x)); |
| 6739 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6740 | } |
| 6741 | |
| 6742 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6743 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6744 | if(CPUID::SSE4_1) |
| 6745 | { |
| 6746 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6747 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6748 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6749 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6750 | round->addArg(x.value); |
| 6751 | round->addArg(::context->getConstantInt32(3)); |
| 6752 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6753 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6754 | return RValue<Float4>(V(result)); |
| 6755 | } |
| 6756 | else |
| 6757 | { |
| 6758 | return Float4(Int4(x)); |
| 6759 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6760 | } |
| 6761 | |
| 6762 | RValue<Float4> Frac(RValue<Float4> x) |
| 6763 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6764 | Float4 frc; |
| 6765 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6766 | if(CPUID::SSE4_1) |
| 6767 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6768 | frc = x - Floor(x); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6769 | } |
| 6770 | else |
| 6771 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6772 | frc = x - Float4(Int4(x)); // Signed fractional part. |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6773 | |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6774 | frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); // Add 1.0 if negative. |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6775 | } |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6776 | |
| 6777 | // x - floor(x) can be 1.0 for very small negative x. |
| 6778 | // Clamp against the value just below 1.0. |
| 6779 | return Min(frc, As<Float4>(Int4(0x3F7FFFFF))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | RValue<Float4> Floor(RValue<Float4> x) |
| 6783 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6784 | if(CPUID::SSE4_1) |
| 6785 | { |
| 6786 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6787 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6788 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6789 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6790 | round->addArg(x.value); |
| 6791 | round->addArg(::context->getConstantInt32(1)); |
| 6792 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6793 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6794 | return RValue<Float4>(V(result)); |
| 6795 | } |
| 6796 | else |
| 6797 | { |
| 6798 | return x - Frac(x); |
| 6799 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6800 | } |
| 6801 | |
| 6802 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6803 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6804 | if(CPUID::SSE4_1) |
| 6805 | { |
| 6806 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6807 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6808 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6809 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6810 | round->addArg(x.value); |
| 6811 | round->addArg(::context->getConstantInt32(2)); |
| 6812 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6813 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6814 | return RValue<Float4>(V(result)); |
| 6815 | } |
| 6816 | else |
| 6817 | { |
| 6818 | return -Floor(-x); |
| 6819 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | Type *Float4::getType() |
| 6823 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6824 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6825 | } |
| 6826 | |
| 6827 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6828 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6829 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6830 | } |
| 6831 | |
| 6832 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6833 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6834 | 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] | 6835 | } |
| 6836 | |
| 6837 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6838 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6839 | 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] | 6840 | } |
| 6841 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6842 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6843 | { |
| 6844 | return lhs = lhs + offset; |
| 6845 | } |
| 6846 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6847 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6848 | { |
| 6849 | return lhs = lhs + offset; |
| 6850 | } |
| 6851 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6852 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6853 | { |
| 6854 | return lhs = lhs + offset; |
| 6855 | } |
| 6856 | |
| 6857 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6858 | { |
| 6859 | return lhs + -offset; |
| 6860 | } |
| 6861 | |
| 6862 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6863 | { |
| 6864 | return lhs + -offset; |
| 6865 | } |
| 6866 | |
| 6867 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6868 | { |
| 6869 | return lhs + -offset; |
| 6870 | } |
| 6871 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6872 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6873 | { |
| 6874 | return lhs = lhs - offset; |
| 6875 | } |
| 6876 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6877 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6878 | { |
| 6879 | return lhs = lhs - offset; |
| 6880 | } |
| 6881 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6882 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6883 | { |
| 6884 | return lhs = lhs - offset; |
| 6885 | } |
| 6886 | |
| 6887 | void Return() |
| 6888 | { |
| 6889 | Nucleus::createRetVoid(); |
| 6890 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6891 | Nucleus::createUnreachable(); |
| 6892 | } |
| 6893 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6894 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6895 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6896 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6897 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6898 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6899 | } |
| 6900 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 6901 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6902 | { |
| 6903 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6904 | Nucleus::setInsertBlock(bodyBB); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6905 | } |
| 6906 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6907 | RValue<Long> Ticks() |
| 6908 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6909 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6910 | } |
| 6911 | } |