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 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 15 | #include "Reactor.hpp" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 16 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 17 | #include "Optimizer.hpp" |
| 18 | |
Nicolas Capens | a062f32 | 2018-09-06 15:34:46 -0400 | [diff] [blame] | 19 | #include "Common/Memory.hpp" |
| 20 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 21 | #include "src/IceTypes.h" |
| 22 | #include "src/IceCfg.h" |
| 23 | #include "src/IceELFStreamer.h" |
| 24 | #include "src/IceGlobalContext.h" |
| 25 | #include "src/IceCfgNode.h" |
| 26 | #include "src/IceELFObjectWriter.h" |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 27 | #include "src/IceGlobalInits.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 28 | |
| 29 | #include "llvm/Support/FileSystem.h" |
| 30 | #include "llvm/Support/raw_os_ostream.h" |
Nicolas Capens | 6a990f8 | 2018-07-06 15:54:07 -0400 | [diff] [blame] | 31 | #include "llvm/Support/Compiler.h" |
| 32 | |
| 33 | #if __has_feature(memory_sanitizer) |
| 34 | #include <sanitizer/msan_interface.h> |
| 35 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 36 | |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 37 | #if defined(_WIN32) |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 38 | #ifndef WIN32_LEAN_AND_MEAN |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 39 | #define WIN32_LEAN_AND_MEAN |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 40 | #endif // !WIN32_LEAN_AND_MEAN |
| 41 | #ifndef NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 42 | #define NOMINMAX |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 43 | #endif // !NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 44 | #include <Windows.h> |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 45 | #else |
| 46 | #include <sys/mman.h> |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 47 | #if !defined(MAP_ANONYMOUS) |
| 48 | #define MAP_ANONYMOUS MAP_ANON |
Nicolas Capens | 8b27574 | 2017-01-20 17:11:41 -0500 | [diff] [blame] | 49 | #endif |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 50 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 51 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 52 | //#include <mutex> |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 53 | #include <limits> |
| 54 | #include <iostream> |
| 55 | #include <cassert> |
| 56 | |
| 57 | namespace |
| 58 | { |
| 59 | Ice::GlobalContext *context = nullptr; |
| 60 | Ice::Cfg *function = nullptr; |
| 61 | Ice::CfgNode *basicBlock = nullptr; |
| 62 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame^] | 63 | rr::Routine *routine = nullptr; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 64 | |
| 65 | std::mutex codegenMutex; |
| 66 | |
| 67 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 68 | Ice::Fdstream *out = nullptr; |
| 69 | } |
| 70 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 71 | namespace |
| 72 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 73 | #if !defined(__i386__) && defined(_M_IX86) |
| 74 | #define __i386__ 1 |
| 75 | #endif |
| 76 | |
| 77 | #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) |
| 78 | #define __x86_64__ 1 |
| 79 | #endif |
| 80 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 81 | class CPUID |
| 82 | { |
| 83 | public: |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 84 | const static bool ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 85 | const static bool SSE4_1; |
| 86 | |
| 87 | private: |
| 88 | static void cpuid(int registers[4], int info) |
| 89 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 90 | #if defined(__i386__) || defined(__x86_64__) |
| 91 | #if defined(_WIN32) |
| 92 | __cpuid(registers, info); |
| 93 | #else |
| 94 | __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); |
| 95 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 96 | #else |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 97 | registers[0] = 0; |
| 98 | registers[1] = 0; |
| 99 | registers[2] = 0; |
| 100 | registers[3] = 0; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 101 | #endif |
| 102 | } |
| 103 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 104 | static bool detectARM() |
| 105 | { |
Stephen Lanham | fe79649 | 2018-09-07 11:59:54 -0700 | [diff] [blame] | 106 | #if defined(__arm__) || defined(__aarch64__) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 107 | return true; |
| 108 | #elif defined(__i386__) || defined(__x86_64__) |
| 109 | return false; |
| 110 | #else |
| 111 | #error "Unknown architecture" |
| 112 | #endif |
| 113 | } |
| 114 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 115 | static bool detectSSE4_1() |
| 116 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 117 | #if defined(__i386__) || defined(__x86_64__) |
| 118 | int registers[4]; |
| 119 | cpuid(registers, 1); |
| 120 | return (registers[2] & 0x00080000) != 0; |
| 121 | #else |
| 122 | return false; |
| 123 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 124 | } |
| 125 | }; |
| 126 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 127 | const bool CPUID::ARM = CPUID::detectARM(); |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 128 | const bool CPUID::SSE4_1 = CPUID::detectSSE4_1(); |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 129 | const bool emulateIntrinsics = false; |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame] | 130 | const bool emulateMismatchedBitCast = CPUID::ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame^] | 133 | namespace rr |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 134 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 135 | enum EmulatedType |
| 136 | { |
| 137 | EmulatedShift = 16, |
| 138 | EmulatedV2 = 2 << EmulatedShift, |
| 139 | EmulatedV4 = 4 << EmulatedShift, |
| 140 | EmulatedV8 = 8 << EmulatedShift, |
| 141 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 142 | |
| 143 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 144 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 145 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 146 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 147 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 148 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 149 | }; |
| 150 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 151 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 152 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 153 | class BasicBlock : public Ice::CfgNode {}; |
| 154 | |
| 155 | Ice::Type T(Type *t) |
| 156 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 157 | 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] | 158 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | Type *T(Ice::Type t) |
| 162 | { |
| 163 | return reinterpret_cast<Type*>(t); |
| 164 | } |
| 165 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 166 | Type *T(EmulatedType t) |
| 167 | { |
| 168 | return reinterpret_cast<Type*>(t); |
| 169 | } |
| 170 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 171 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 172 | { |
| 173 | return reinterpret_cast<Value*>(v); |
| 174 | } |
| 175 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 176 | BasicBlock *B(Ice::CfgNode *b) |
| 177 | { |
| 178 | return reinterpret_cast<BasicBlock*>(b); |
| 179 | } |
| 180 | |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 181 | static size_t typeSize(Type *type) |
| 182 | { |
| 183 | if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) |
| 184 | { |
| 185 | switch(reinterpret_cast<std::intptr_t>(type)) |
| 186 | { |
| 187 | case Type_v2i32: return 8; |
| 188 | case Type_v4i16: return 8; |
| 189 | case Type_v2i16: return 4; |
| 190 | case Type_v8i8: return 8; |
| 191 | case Type_v4i8: return 4; |
| 192 | case Type_v2f32: return 8; |
| 193 | default: assert(false); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return Ice::typeWidthInBytes(T(type)); |
| 198 | } |
| 199 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 200 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 201 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 202 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 203 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 204 | |
| 205 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 206 | { |
| 207 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 208 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 209 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 210 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 211 | { |
| 212 | return §ionHeader(elfHeader)[index]; |
| 213 | } |
| 214 | |
| 215 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 216 | { |
| 217 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 218 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 219 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 220 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 221 | uint32_t index = relocation.getSymbol(); |
| 222 | int table = relocationTable.sh_link; |
| 223 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 224 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 225 | if(index != SHN_UNDEF) |
| 226 | { |
| 227 | if(table == SHN_UNDEF) return nullptr; |
| 228 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 229 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 230 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 231 | if(index >= symtab_entries) |
| 232 | { |
| 233 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 234 | return nullptr; |
| 235 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 236 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 237 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 238 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 239 | uint16_t section = symbol.st_shndx; |
| 240 | |
| 241 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 242 | { |
| 243 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 244 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | return nullptr; |
| 249 | } |
| 250 | } |
| 251 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 252 | if(CPUID::ARM) |
| 253 | { |
| 254 | switch(relocation.getType()) |
| 255 | { |
| 256 | case R_ARM_NONE: |
| 257 | // No relocation |
| 258 | break; |
| 259 | case R_ARM_MOVW_ABS_NC: |
| 260 | { |
| 261 | uint32_t thumb = 0; // Calls to Thumb code not supported. |
| 262 | uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb; |
| 263 | *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF); |
| 264 | } |
| 265 | break; |
| 266 | case R_ARM_MOVT_ABS: |
| 267 | { |
| 268 | uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16; |
| 269 | *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF); |
| 270 | } |
| 271 | break; |
| 272 | default: |
| 273 | assert(false && "Unsupported relocation type"); |
| 274 | return nullptr; |
| 275 | } |
| 276 | } |
| 277 | else |
| 278 | { |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 279 | switch(relocation.getType()) |
| 280 | { |
| 281 | case R_386_NONE: |
| 282 | // No relocation |
| 283 | break; |
| 284 | case R_386_32: |
| 285 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 286 | break; |
| 287 | // case R_386_PC32: |
| 288 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 289 | // break; |
| 290 | default: |
| 291 | assert(false && "Unsupported relocation type"); |
| 292 | return nullptr; |
| 293 | } |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 296 | return symbolValue; |
| 297 | } |
| 298 | |
| 299 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 300 | { |
| 301 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 302 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 303 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 304 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 305 | uint32_t index = relocation.getSymbol(); |
| 306 | int table = relocationTable.sh_link; |
| 307 | void *symbolValue = nullptr; |
| 308 | |
| 309 | if(index != SHN_UNDEF) |
| 310 | { |
| 311 | if(table == SHN_UNDEF) return nullptr; |
| 312 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 313 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 314 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 315 | if(index >= symtab_entries) |
| 316 | { |
| 317 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 318 | return nullptr; |
| 319 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 320 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 321 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 322 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 323 | uint16_t section = symbol.st_shndx; |
| 324 | |
| 325 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 326 | { |
| 327 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 328 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | return nullptr; |
| 333 | } |
| 334 | } |
| 335 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 336 | switch(relocation.getType()) |
| 337 | { |
| 338 | case R_X86_64_NONE: |
| 339 | // No relocation |
| 340 | break; |
| 341 | case R_X86_64_64: |
| 342 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 343 | break; |
| 344 | case R_X86_64_PC32: |
| 345 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 346 | break; |
| 347 | case R_X86_64_32S: |
| 348 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 349 | break; |
| 350 | default: |
| 351 | assert(false && "Unsupported relocation type"); |
| 352 | return nullptr; |
| 353 | } |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 354 | |
| 355 | return symbolValue; |
| 356 | } |
| 357 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 358 | void *loadImage(uint8_t *const elfImage, size_t &codeSize) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 359 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 360 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 361 | |
| 362 | if(!elfHeader->checkMagic()) |
| 363 | { |
| 364 | return nullptr; |
| 365 | } |
| 366 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 367 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 368 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 369 | #if defined(__i386__) |
| 370 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386); |
| 371 | #elif defined(__x86_64__) |
| 372 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64); |
| 373 | #elif defined(__arm__) |
| 374 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM); |
Stephen Lanham | fe79649 | 2018-09-07 11:59:54 -0700 | [diff] [blame] | 375 | #elif defined(__aarch64__) |
| 376 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_AARCH64); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 377 | #else |
| 378 | #error "Unsupported platform" |
| 379 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 380 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 381 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 382 | void *entry = nullptr; |
| 383 | |
| 384 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 385 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 386 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 387 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 388 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 389 | { |
| 390 | entry = elfImage + sectionHeader[i].sh_offset; |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 391 | codeSize = sectionHeader[i].sh_size; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 395 | { |
| 396 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 397 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 398 | 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] | 399 | { |
| 400 | 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] | 401 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 405 | { |
| 406 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 407 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 408 | 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] | 409 | { |
| 410 | 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] | 411 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 412 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
| 416 | return entry; |
| 417 | } |
| 418 | |
| 419 | template<typename T> |
| 420 | struct ExecutableAllocator |
| 421 | { |
| 422 | ExecutableAllocator() {}; |
| 423 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 424 | |
| 425 | using value_type = T; |
| 426 | using size_type = std::size_t; |
| 427 | |
| 428 | T *allocate(size_type n) |
| 429 | { |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame^] | 430 | return (T*)sw::allocateExecutable(sizeof(T) * n); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void deallocate(T *p, size_type n) |
| 434 | { |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame^] | 435 | sw::deallocateExecutable(p, sizeof(T) * n); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 436 | } |
| 437 | }; |
| 438 | |
| 439 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 440 | { |
| 441 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 442 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 443 | |
| 444 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 445 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 446 | { |
| 447 | position = 0; |
| 448 | buffer.reserve(0x1000); |
| 449 | } |
| 450 | |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 451 | ~ELFMemoryStreamer() override |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 452 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 453 | #if defined(_WIN32) |
| 454 | if(buffer.size() != 0) |
| 455 | { |
| 456 | DWORD exeProtection; |
| 457 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 458 | } |
| 459 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void write8(uint8_t Value) override |
| 463 | { |
| 464 | if(position == (uint64_t)buffer.size()) |
| 465 | { |
| 466 | buffer.push_back(Value); |
| 467 | position++; |
| 468 | } |
| 469 | else if(position < (uint64_t)buffer.size()) |
| 470 | { |
| 471 | buffer[position] = Value; |
| 472 | position++; |
| 473 | } |
| 474 | else assert(false && "UNIMPLEMENTED"); |
| 475 | } |
| 476 | |
| 477 | void writeBytes(llvm::StringRef Bytes) override |
| 478 | { |
| 479 | std::size_t oldSize = buffer.size(); |
| 480 | buffer.resize(oldSize + Bytes.size()); |
| 481 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 482 | position += Bytes.size(); |
| 483 | } |
| 484 | |
| 485 | uint64_t tell() const override { return position; } |
| 486 | |
| 487 | void seek(uint64_t Off) override { position = Off; } |
| 488 | |
| 489 | const void *getEntry() override |
| 490 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 491 | if(!entry) |
| 492 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 493 | 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] | 494 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 495 | size_t codeSize = 0; |
| 496 | entry = loadImage(&buffer[0], codeSize); |
| 497 | |
| 498 | #if defined(_WIN32) |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 499 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 500 | FlushInstructionCache(GetCurrentProcess(), NULL, 0); |
| 501 | #else |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 502 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 503 | __builtin___clear_cache((char*)entry, (char*)entry + codeSize); |
| 504 | #endif |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 511 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 512 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 513 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 514 | |
| 515 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 516 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 517 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | Nucleus::Nucleus() |
| 521 | { |
| 522 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 523 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 524 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 525 | Ice::ClFlags::getParsedClFlags(Flags); |
| 526 | |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 527 | #if defined(__arm__) |
| 528 | Flags.setTargetArch(Ice::Target_ARM32); |
| 529 | Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm); |
| 530 | #else // x86 |
| 531 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 532 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
| 533 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 534 | Flags.setOutFileType(Ice::FT_Elf); |
| 535 | Flags.setOptLevel(Ice::Opt_2); |
| 536 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 537 | Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None); |
| 538 | Flags.setDisableHybridAssembly(true); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 539 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 540 | static llvm::raw_os_ostream cout(std::cout); |
| 541 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 542 | |
| 543 | if(false) // Write out to a file |
| 544 | { |
| 545 | std::error_code errorCode; |
| 546 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 547 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 548 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 549 | } |
| 550 | else |
| 551 | { |
| 552 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 553 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 554 | ::routine = elfMemory; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | Nucleus::~Nucleus() |
| 559 | { |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 560 | delete ::routine; |
| 561 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 562 | delete ::allocator; |
| 563 | delete ::function; |
| 564 | delete ::context; |
| 565 | |
| 566 | delete ::elfFile; |
| 567 | delete ::out; |
| 568 | |
| 569 | ::codegenMutex.unlock(); |
| 570 | } |
| 571 | |
| 572 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 573 | { |
| 574 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 575 | { |
| 576 | createRetVoid(); |
| 577 | } |
| 578 | |
| 579 | std::wstring wideName(name); |
| 580 | std::string asciiName(wideName.begin(), wideName.end()); |
| 581 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 582 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 583 | optimize(); |
| 584 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 585 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 586 | assert(!::function->hasError()); |
| 587 | |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 588 | auto globals = ::function->getGlobalInits(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 589 | |
| 590 | if(globals && !globals->empty()) |
| 591 | { |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 592 | ::context->getGlobals()->merge(globals.get()); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 593 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 594 | |
| 595 | ::context->emitFileHeader(); |
| 596 | ::function->emitIAS(); |
| 597 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 598 | auto objectWriter = ::context->getObjectWriter(); |
| 599 | assembler->alignFunction(); |
| 600 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 601 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 602 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 603 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 604 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 605 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 606 | |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 607 | Routine *handoffRoutine = ::routine; |
| 608 | ::routine = nullptr; |
| 609 | |
| 610 | return handoffRoutine; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | void Nucleus::optimize() |
| 614 | { |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame^] | 615 | rr::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 619 | { |
| 620 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 621 | int typeSize = Ice::typeWidthInBytes(type); |
| 622 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 623 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 624 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 625 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 626 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 627 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 628 | |
| 629 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | BasicBlock *Nucleus::createBasicBlock() |
| 633 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 634 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | BasicBlock *Nucleus::getInsertBlock() |
| 638 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 639 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 643 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 644 | // 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] | 645 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 646 | } |
| 647 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 648 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 649 | { |
| 650 | uint32_t sequenceNumber = 0; |
| 651 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 652 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 653 | |
| 654 | for(Type *type : Params) |
| 655 | { |
| 656 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 657 | ::function->addArg(arg); |
| 658 | } |
| 659 | |
| 660 | Ice::CfgNode *node = ::function->makeNode(); |
| 661 | ::function->setEntryNode(node); |
| 662 | ::basicBlock = node; |
| 663 | } |
| 664 | |
| 665 | Value *Nucleus::getArgument(unsigned int index) |
| 666 | { |
| 667 | return V(::function->getArgs()[index]); |
| 668 | } |
| 669 | |
| 670 | void Nucleus::createRetVoid() |
| 671 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 672 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 673 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | void Nucleus::createRet(Value *v) |
| 677 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 678 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 679 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void Nucleus::createBr(BasicBlock *dest) |
| 683 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 684 | auto br = Ice::InstBr::create(::function, dest); |
| 685 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 689 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 690 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 691 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 692 | } |
| 693 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 694 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 695 | { |
| 696 | switch(op) |
| 697 | { |
| 698 | case Ice::InstArithmetic::Add: |
| 699 | case Ice::InstArithmetic::Fadd: |
| 700 | case Ice::InstArithmetic::Mul: |
| 701 | case Ice::InstArithmetic::Fmul: |
| 702 | case Ice::InstArithmetic::And: |
| 703 | case Ice::InstArithmetic::Or: |
| 704 | case Ice::InstArithmetic::Xor: |
| 705 | return true; |
| 706 | default: |
| 707 | return false; |
| 708 | } |
| 709 | } |
| 710 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 711 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 712 | { |
Nicolas Capens | b64e0ce | 2018-01-26 01:24:57 +0000 | [diff] [blame] | 713 | assert(lhs->getType() == rhs->getType() || llvm::isa<Ice::Constant>(rhs)); |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 714 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 715 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 716 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 717 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 718 | 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] | 719 | ::basicBlock->appendInst(arithmetic); |
| 720 | |
| 721 | return V(result); |
| 722 | } |
| 723 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 724 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 725 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 726 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 730 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 731 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 735 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 736 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 740 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 741 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 745 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 746 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 750 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 751 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 755 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 756 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 760 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 761 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 765 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 766 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 770 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 771 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 775 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 776 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 780 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 781 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 785 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 786 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 790 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 791 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 795 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 796 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 800 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 801 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 805 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 806 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 810 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 811 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | Value *Nucleus::createNeg(Value *v) |
| 815 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 816 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | Value *Nucleus::createFNeg(Value *v) |
| 820 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 821 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 822 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 823 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 824 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 825 | |
| 826 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | Value *Nucleus::createNot(Value *v) |
| 830 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 831 | if(Ice::isScalarIntegerType(v->getType())) |
| 832 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 833 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 834 | } |
| 835 | else // Vector |
| 836 | { |
Nicolas Capens | f34d1ac | 2017-05-08 17:06:11 -0400 | [diff] [blame] | 837 | 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] | 838 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 839 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 840 | } |
| 841 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 842 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 843 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 844 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 845 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 846 | |
Nicolas Capens | f4c4eca | 2017-10-03 14:26:07 -0400 | [diff] [blame] | 847 | if((valueType & EmulatedBits) && (align != 0)) // Narrow vector not stored on stack. |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 848 | { |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 849 | if(emulateIntrinsics) |
| 850 | { |
| 851 | if(typeSize(type) == 4) |
| 852 | { |
| 853 | auto pointer = RValue<Pointer<Byte>>(ptr); |
Nicolas Capens | 1894cfa | 2017-07-27 14:21:46 -0400 | [diff] [blame] | 854 | Int x = *Pointer<Int>(pointer); |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 855 | |
| 856 | Int4 vector; |
| 857 | vector = Insert(vector, x, 0); |
| 858 | |
| 859 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue()); |
| 860 | ::basicBlock->appendInst(bitcast); |
| 861 | } |
| 862 | else if(typeSize(type) == 8) |
| 863 | { |
| 864 | auto pointer = RValue<Pointer<Byte>>(ptr); |
Nicolas Capens | 1894cfa | 2017-07-27 14:21:46 -0400 | [diff] [blame] | 865 | Int x = *Pointer<Int>(pointer); |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 866 | Int y = *Pointer<Int>(pointer + 4); |
| 867 | |
| 868 | Int4 vector; |
| 869 | vector = Insert(vector, x, 0); |
| 870 | vector = Insert(vector, y, 1); |
| 871 | |
| 872 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue()); |
| 873 | ::basicBlock->appendInst(bitcast); |
| 874 | } |
| 875 | else assert(false); |
| 876 | } |
| 877 | else |
| 878 | { |
| 879 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 880 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 881 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 882 | load->addArg(ptr); |
| 883 | load->addArg(::context->getConstantInt32(typeSize(type))); |
| 884 | ::basicBlock->appendInst(load); |
| 885 | } |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 886 | } |
| 887 | else |
| 888 | { |
| 889 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 890 | ::basicBlock->appendInst(load); |
| 891 | } |
| 892 | |
| 893 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 894 | } |
| 895 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 896 | 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] | 897 | { |
Nicolas Capens | 6a990f8 | 2018-07-06 15:54:07 -0400 | [diff] [blame] | 898 | #if __has_feature(memory_sanitizer) |
| 899 | // Mark all (non-stack) memory writes as initialized by calling __msan_unpoison |
| 900 | if(align != 0) |
| 901 | { |
| 902 | auto call = Ice::InstCall::create(::function, 2, nullptr, ::context->getConstantInt64(reinterpret_cast<intptr_t>(__msan_unpoison)), false); |
| 903 | call->addArg(ptr); |
| 904 | call->addArg(::context->getConstantInt64(typeSize(type))); |
| 905 | ::basicBlock->appendInst(call); |
| 906 | } |
| 907 | #endif |
| 908 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 909 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 910 | |
Nicolas Capens | f4c4eca | 2017-10-03 14:26:07 -0400 | [diff] [blame] | 911 | if((valueType & EmulatedBits) && (align != 0)) // Narrow vector not stored on stack. |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 912 | { |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 913 | if(emulateIntrinsics) |
| 914 | { |
| 915 | if(typeSize(type) == 4) |
| 916 | { |
| 917 | Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32); |
| 918 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value); |
| 919 | ::basicBlock->appendInst(bitcast); |
| 920 | |
| 921 | RValue<Int4> v(V(vector)); |
| 922 | |
| 923 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 924 | Int x = Extract(v, 0); |
| 925 | *Pointer<Int>(pointer) = x; |
| 926 | } |
| 927 | else if(typeSize(type) == 8) |
| 928 | { |
| 929 | Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32); |
| 930 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value); |
| 931 | ::basicBlock->appendInst(bitcast); |
| 932 | |
| 933 | RValue<Int4> v(V(vector)); |
| 934 | |
| 935 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 936 | Int x = Extract(v, 0); |
| 937 | *Pointer<Int>(pointer) = x; |
| 938 | Int y = Extract(v, 1); |
| 939 | *Pointer<Int>(pointer + 4) = y; |
| 940 | } |
| 941 | else assert(false); |
| 942 | } |
| 943 | else |
| 944 | { |
| 945 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 946 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 947 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
| 948 | store->addArg(value); |
| 949 | store->addArg(ptr); |
| 950 | store->addArg(::context->getConstantInt32(typeSize(type))); |
| 951 | ::basicBlock->appendInst(store); |
| 952 | } |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 953 | } |
| 954 | else |
| 955 | { |
Nicolas Capens | f4c4eca | 2017-10-03 14:26:07 -0400 | [diff] [blame] | 956 | assert(value->getType() == T(type)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 957 | |
| 958 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 959 | ::basicBlock->appendInst(store); |
| 960 | } |
| 961 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 962 | return value; |
| 963 | } |
| 964 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 965 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 966 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 967 | assert(index->getType() == Ice::IceType_i32); |
| 968 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 969 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 970 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 971 | int32_t offset = constant->getValue() * (int)typeSize(type); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 972 | |
| 973 | if(offset == 0) |
| 974 | { |
| 975 | return ptr; |
| 976 | } |
| 977 | |
| 978 | return createAdd(ptr, createConstantInt(offset)); |
| 979 | } |
| 980 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 981 | if(!Ice::isByteSizedType(T(type))) |
| 982 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 983 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | if(sizeof(void*) == 8) |
| 987 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 988 | if(unsignedIndex) |
| 989 | { |
| 990 | index = createZExt(index, T(Ice::IceType_i64)); |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | index = createSExt(index, T(Ice::IceType_i64)); |
| 995 | } |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 1002 | { |
| 1003 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 1004 | } |
| 1005 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1006 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 1007 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 1008 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1009 | { |
| 1010 | return v; |
| 1011 | } |
| 1012 | |
| 1013 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 1014 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 1015 | ::basicBlock->appendInst(cast); |
| 1016 | |
| 1017 | return V(result); |
| 1018 | } |
| 1019 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1020 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 1021 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1022 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 1026 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1027 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 1031 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1032 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 1036 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1037 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1040 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 1041 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1042 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 1046 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1047 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 1051 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1052 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 1056 | { |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame] | 1057 | // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need |
| 1058 | // support for casting between scalars and wide vectors. For platforms where this is not supported, |
| 1059 | // emulate them by writing to the stack and reading back as the destination type. |
| 1060 | if(emulateMismatchedBitCast) |
| 1061 | { |
| 1062 | if(!Ice::isVectorType(v->getType()) && Ice::isVectorType(T(destType))) |
| 1063 | { |
| 1064 | Value *address = allocateStackVariable(destType); |
| 1065 | createStore(v, address, T(v->getType())); |
| 1066 | return createLoad(address, destType); |
| 1067 | } |
| 1068 | else if(Ice::isVectorType(v->getType()) && !Ice::isVectorType(T(destType))) |
| 1069 | { |
| 1070 | Value *address = allocateStackVariable(T(v->getType())); |
| 1071 | createStore(v, address, T(v->getType())); |
| 1072 | return createLoad(address, destType); |
| 1073 | } |
| 1074 | } |
| 1075 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1076 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1079 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1080 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1081 | assert(lhs->getType() == rhs->getType()); |
| 1082 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1083 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 1084 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1085 | ::basicBlock->appendInst(cmp); |
| 1086 | |
| 1087 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1088 | } |
| 1089 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1090 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 1091 | { |
| 1092 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 1093 | } |
| 1094 | |
| 1095 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 1096 | { |
| 1097 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 1098 | } |
| 1099 | |
| 1100 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 1101 | { |
| 1102 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 1103 | } |
| 1104 | |
| 1105 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 1106 | { |
| 1107 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 1108 | } |
| 1109 | |
| 1110 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 1111 | { |
| 1112 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 1113 | } |
| 1114 | |
| 1115 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 1116 | { |
| 1117 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 1118 | } |
| 1119 | |
| 1120 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 1121 | { |
| 1122 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 1123 | } |
| 1124 | |
| 1125 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 1126 | { |
| 1127 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 1128 | } |
| 1129 | |
| 1130 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 1131 | { |
| 1132 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 1133 | } |
| 1134 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1135 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 1136 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1137 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 1138 | } |
| 1139 | |
| 1140 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 1141 | { |
| 1142 | assert(lhs->getType() == rhs->getType()); |
| 1143 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 1144 | |
| 1145 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 1146 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 1147 | ::basicBlock->appendInst(cmp); |
| 1148 | |
| 1149 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 1153 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1154 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1158 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1159 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1163 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1164 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1168 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1169 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1173 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1174 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1178 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1179 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1183 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1184 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1188 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1189 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1193 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1194 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1198 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1199 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1203 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1204 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1208 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1209 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1213 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1214 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1218 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1219 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1220 | } |
| 1221 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1222 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1223 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1224 | auto result = ::function->makeVariable(T(type)); |
| 1225 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1226 | ::basicBlock->appendInst(extract); |
| 1227 | |
| 1228 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1232 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1233 | auto result = ::function->makeVariable(vector->getType()); |
| 1234 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1235 | ::basicBlock->appendInst(insert); |
| 1236 | |
| 1237 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1240 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1241 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1242 | assert(V1->getType() == V2->getType()); |
| 1243 | |
| 1244 | int size = Ice::typeNumElements(V1->getType()); |
| 1245 | auto result = ::function->makeVariable(V1->getType()); |
| 1246 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1247 | |
| 1248 | for(int i = 0; i < size; i++) |
| 1249 | { |
| 1250 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1251 | } |
| 1252 | |
| 1253 | ::basicBlock->appendInst(shuffle); |
| 1254 | |
| 1255 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1259 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1260 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1261 | |
| 1262 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1263 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1264 | ::basicBlock->appendInst(select); |
| 1265 | |
| 1266 | return V(result); |
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 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
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 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1272 | ::basicBlock->appendInst(switchInst); |
| 1273 | |
| 1274 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1275 | } |
| 1276 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1277 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1278 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1279 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | void Nucleus::createUnreachable() |
| 1283 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1284 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1285 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1286 | } |
| 1287 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1288 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1289 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1290 | int swizzle[4] = |
| 1291 | { |
| 1292 | (select >> 0) & 0x03, |
| 1293 | (select >> 2) & 0x03, |
| 1294 | (select >> 4) & 0x03, |
| 1295 | (select >> 6) & 0x03, |
| 1296 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1297 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1298 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1301 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1302 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1303 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1304 | |
| 1305 | mask[(select >> 0) & 0x03] = -1; |
| 1306 | mask[(select >> 2) & 0x03] = -1; |
| 1307 | mask[(select >> 4) & 0x03] = -1; |
| 1308 | mask[(select >> 6) & 0x03] = -1; |
| 1309 | |
| 1310 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1311 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1312 | |
| 1313 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1316 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1317 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1318 | if(sizeof(void*) == 8) |
| 1319 | { |
| 1320 | return T(Ice::IceType_i64); |
| 1321 | } |
| 1322 | else |
| 1323 | { |
| 1324 | return T(Ice::IceType_i32); |
| 1325 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1326 | } |
| 1327 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1328 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1329 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1330 | if(Ice::isVectorType(T(Ty))) |
| 1331 | { |
Nicolas Capens | 30385f0 | 2017-04-18 13:03:47 -0400 | [diff] [blame] | 1332 | assert(Ice::typeNumElements(T(Ty)) <= 16); |
| 1333 | 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] | 1334 | return createConstantVector(c, Ty); |
| 1335 | } |
| 1336 | else |
| 1337 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1338 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1339 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1340 | } |
| 1341 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1342 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1343 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1344 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1345 | } |
| 1346 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1347 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1348 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1349 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1352 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1353 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1354 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1357 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1358 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1359 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1360 | } |
| 1361 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1362 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1363 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1364 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1367 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1368 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1369 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1372 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1373 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1374 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1375 | } |
| 1376 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1377 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1378 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1379 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1380 | } |
| 1381 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1382 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1383 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1384 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1385 | } |
| 1386 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1387 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1388 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1389 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1392 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1393 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1394 | const int vectorSize = 16; |
| 1395 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1396 | const int alignment = vectorSize; |
| 1397 | auto globalPool = ::function->getGlobalPool(); |
| 1398 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1399 | const int64_t *i = constants; |
| 1400 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1401 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1402 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1403 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1404 | { |
| 1405 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1406 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1407 | { |
| 1408 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1409 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1410 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1411 | } |
| 1412 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1413 | case Ice::IceType_v4f32: |
| 1414 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1415 | 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] | 1416 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1417 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1418 | } |
| 1419 | break; |
| 1420 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1421 | case Ice::IceType_v8i1: |
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 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] | 1424 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1425 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1426 | } |
| 1427 | break; |
| 1428 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1429 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1430 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1431 | 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] | 1432 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1433 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1434 | } |
| 1435 | break; |
| 1436 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1437 | { |
| 1438 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1439 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1440 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1441 | } |
| 1442 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1443 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1444 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1445 | 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] | 1446 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1447 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1448 | } |
| 1449 | break; |
| 1450 | case Type_v4i16: |
| 1451 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1452 | 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] | 1453 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1454 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1455 | } |
| 1456 | break; |
| 1457 | case Type_v8i8: |
| 1458 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1459 | 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] | 1460 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1461 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1462 | } |
| 1463 | break; |
| 1464 | case Type_v4i8: |
| 1465 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1466 | 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] | 1467 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1468 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1469 | } |
| 1470 | break; |
| 1471 | default: |
| 1472 | assert(false && "Unknown constant vector type" && type); |
| 1473 | } |
| 1474 | |
| 1475 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1476 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1477 | variableDeclaration->setName(name); |
| 1478 | variableDeclaration->setAlignment(alignment); |
| 1479 | variableDeclaration->setIsConstant(true); |
| 1480 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1481 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1482 | ::function->addGlobal(variableDeclaration); |
| 1483 | |
| 1484 | constexpr int32_t offset = 0; |
| 1485 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1486 | |
| 1487 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1488 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1489 | ::basicBlock->appendInst(load); |
| 1490 | |
| 1491 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1495 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1496 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | Type *Void::getType() |
| 1500 | { |
| 1501 | return T(Ice::IceType_void); |
| 1502 | } |
| 1503 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1504 | Bool::Bool(Argument<Bool> argument) |
| 1505 | { |
| 1506 | storeValue(argument.value); |
| 1507 | } |
| 1508 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1509 | Bool::Bool(bool x) |
| 1510 | { |
| 1511 | storeValue(Nucleus::createConstantBool(x)); |
| 1512 | } |
| 1513 | |
| 1514 | Bool::Bool(RValue<Bool> rhs) |
| 1515 | { |
| 1516 | storeValue(rhs.value); |
| 1517 | } |
| 1518 | |
| 1519 | Bool::Bool(const Bool &rhs) |
| 1520 | { |
| 1521 | Value *value = rhs.loadValue(); |
| 1522 | storeValue(value); |
| 1523 | } |
| 1524 | |
| 1525 | Bool::Bool(const Reference<Bool> &rhs) |
| 1526 | { |
| 1527 | Value *value = rhs.loadValue(); |
| 1528 | storeValue(value); |
| 1529 | } |
| 1530 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1531 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1532 | { |
| 1533 | storeValue(rhs.value); |
| 1534 | |
| 1535 | return rhs; |
| 1536 | } |
| 1537 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1538 | RValue<Bool> Bool::operator=(const 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 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1546 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1547 | { |
| 1548 | Value *value = rhs.loadValue(); |
| 1549 | storeValue(value); |
| 1550 | |
| 1551 | return RValue<Bool>(value); |
| 1552 | } |
| 1553 | |
| 1554 | RValue<Bool> operator!(RValue<Bool> val) |
| 1555 | { |
| 1556 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1557 | } |
| 1558 | |
| 1559 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1560 | { |
| 1561 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1562 | } |
| 1563 | |
| 1564 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1565 | { |
| 1566 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1567 | } |
| 1568 | |
| 1569 | Type *Bool::getType() |
| 1570 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1571 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | Byte::Byte(Argument<Byte> argument) |
| 1575 | { |
| 1576 | storeValue(argument.value); |
| 1577 | } |
| 1578 | |
| 1579 | Byte::Byte(RValue<Int> cast) |
| 1580 | { |
| 1581 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1582 | |
| 1583 | storeValue(integer); |
| 1584 | } |
| 1585 | |
| 1586 | Byte::Byte(RValue<UInt> cast) |
| 1587 | { |
| 1588 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1589 | |
| 1590 | storeValue(integer); |
| 1591 | } |
| 1592 | |
| 1593 | Byte::Byte(RValue<UShort> cast) |
| 1594 | { |
| 1595 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1596 | |
| 1597 | storeValue(integer); |
| 1598 | } |
| 1599 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1600 | Byte::Byte(int x) |
| 1601 | { |
| 1602 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1603 | } |
| 1604 | |
| 1605 | Byte::Byte(unsigned char x) |
| 1606 | { |
| 1607 | storeValue(Nucleus::createConstantByte(x)); |
| 1608 | } |
| 1609 | |
| 1610 | Byte::Byte(RValue<Byte> rhs) |
| 1611 | { |
| 1612 | storeValue(rhs.value); |
| 1613 | } |
| 1614 | |
| 1615 | Byte::Byte(const Byte &rhs) |
| 1616 | { |
| 1617 | Value *value = rhs.loadValue(); |
| 1618 | storeValue(value); |
| 1619 | } |
| 1620 | |
| 1621 | Byte::Byte(const Reference<Byte> &rhs) |
| 1622 | { |
| 1623 | Value *value = rhs.loadValue(); |
| 1624 | storeValue(value); |
| 1625 | } |
| 1626 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1627 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1628 | { |
| 1629 | storeValue(rhs.value); |
| 1630 | |
| 1631 | return rhs; |
| 1632 | } |
| 1633 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1634 | RValue<Byte> Byte::operator=(const 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 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1642 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1643 | { |
| 1644 | Value *value = rhs.loadValue(); |
| 1645 | storeValue(value); |
| 1646 | |
| 1647 | return RValue<Byte>(value); |
| 1648 | } |
| 1649 | |
| 1650 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1651 | { |
| 1652 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1653 | } |
| 1654 | |
| 1655 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1656 | { |
| 1657 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1658 | } |
| 1659 | |
| 1660 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1661 | { |
| 1662 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1663 | } |
| 1664 | |
| 1665 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1666 | { |
| 1667 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1668 | } |
| 1669 | |
| 1670 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1671 | { |
| 1672 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1673 | } |
| 1674 | |
| 1675 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1676 | { |
| 1677 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1678 | } |
| 1679 | |
| 1680 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1681 | { |
| 1682 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1683 | } |
| 1684 | |
| 1685 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1686 | { |
| 1687 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1688 | } |
| 1689 | |
| 1690 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1691 | { |
| 1692 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1693 | } |
| 1694 | |
| 1695 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1696 | { |
| 1697 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1698 | } |
| 1699 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1700 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1701 | { |
| 1702 | return lhs = lhs + rhs; |
| 1703 | } |
| 1704 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1705 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1706 | { |
| 1707 | return lhs = lhs - rhs; |
| 1708 | } |
| 1709 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1710 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1711 | { |
| 1712 | return lhs = lhs * rhs; |
| 1713 | } |
| 1714 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1715 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1716 | { |
| 1717 | return lhs = lhs / rhs; |
| 1718 | } |
| 1719 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1720 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1721 | { |
| 1722 | return lhs = lhs % rhs; |
| 1723 | } |
| 1724 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1725 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1726 | { |
| 1727 | return lhs = lhs & rhs; |
| 1728 | } |
| 1729 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1730 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1731 | { |
| 1732 | return lhs = lhs | rhs; |
| 1733 | } |
| 1734 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1735 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1736 | { |
| 1737 | return lhs = lhs ^ rhs; |
| 1738 | } |
| 1739 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1740 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1741 | { |
| 1742 | return lhs = lhs << rhs; |
| 1743 | } |
| 1744 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1745 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1746 | { |
| 1747 | return lhs = lhs >> rhs; |
| 1748 | } |
| 1749 | |
| 1750 | RValue<Byte> operator+(RValue<Byte> val) |
| 1751 | { |
| 1752 | return val; |
| 1753 | } |
| 1754 | |
| 1755 | RValue<Byte> operator-(RValue<Byte> val) |
| 1756 | { |
| 1757 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1758 | } |
| 1759 | |
| 1760 | RValue<Byte> operator~(RValue<Byte> val) |
| 1761 | { |
| 1762 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1763 | } |
| 1764 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1765 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1766 | { |
| 1767 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1768 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1769 | return res; |
| 1770 | } |
| 1771 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1772 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1773 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1774 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1775 | return val; |
| 1776 | } |
| 1777 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1778 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1779 | { |
| 1780 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1781 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1782 | return res; |
| 1783 | } |
| 1784 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1785 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1786 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1787 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1788 | return val; |
| 1789 | } |
| 1790 | |
| 1791 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1792 | { |
| 1793 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1794 | } |
| 1795 | |
| 1796 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1797 | { |
| 1798 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1799 | } |
| 1800 | |
| 1801 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1802 | { |
| 1803 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1804 | } |
| 1805 | |
| 1806 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1807 | { |
| 1808 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1809 | } |
| 1810 | |
| 1811 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1812 | { |
| 1813 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1814 | } |
| 1815 | |
| 1816 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1817 | { |
| 1818 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1819 | } |
| 1820 | |
| 1821 | Type *Byte::getType() |
| 1822 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1823 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | SByte::SByte(Argument<SByte> argument) |
| 1827 | { |
| 1828 | storeValue(argument.value); |
| 1829 | } |
| 1830 | |
| 1831 | SByte::SByte(RValue<Int> cast) |
| 1832 | { |
| 1833 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1834 | |
| 1835 | storeValue(integer); |
| 1836 | } |
| 1837 | |
| 1838 | SByte::SByte(RValue<Short> cast) |
| 1839 | { |
| 1840 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1841 | |
| 1842 | storeValue(integer); |
| 1843 | } |
| 1844 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1845 | SByte::SByte(signed char x) |
| 1846 | { |
| 1847 | storeValue(Nucleus::createConstantByte(x)); |
| 1848 | } |
| 1849 | |
| 1850 | SByte::SByte(RValue<SByte> rhs) |
| 1851 | { |
| 1852 | storeValue(rhs.value); |
| 1853 | } |
| 1854 | |
| 1855 | SByte::SByte(const SByte &rhs) |
| 1856 | { |
| 1857 | Value *value = rhs.loadValue(); |
| 1858 | storeValue(value); |
| 1859 | } |
| 1860 | |
| 1861 | SByte::SByte(const Reference<SByte> &rhs) |
| 1862 | { |
| 1863 | Value *value = rhs.loadValue(); |
| 1864 | storeValue(value); |
| 1865 | } |
| 1866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1867 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1868 | { |
| 1869 | storeValue(rhs.value); |
| 1870 | |
| 1871 | return rhs; |
| 1872 | } |
| 1873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1874 | RValue<SByte> SByte::operator=(const 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 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1882 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1883 | { |
| 1884 | Value *value = rhs.loadValue(); |
| 1885 | storeValue(value); |
| 1886 | |
| 1887 | return RValue<SByte>(value); |
| 1888 | } |
| 1889 | |
| 1890 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1891 | { |
| 1892 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1893 | } |
| 1894 | |
| 1895 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1896 | { |
| 1897 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1898 | } |
| 1899 | |
| 1900 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1901 | { |
| 1902 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1903 | } |
| 1904 | |
| 1905 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1906 | { |
| 1907 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1908 | } |
| 1909 | |
| 1910 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1911 | { |
| 1912 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1913 | } |
| 1914 | |
| 1915 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1916 | { |
| 1917 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1918 | } |
| 1919 | |
| 1920 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1921 | { |
| 1922 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1923 | } |
| 1924 | |
| 1925 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1926 | { |
| 1927 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1928 | } |
| 1929 | |
| 1930 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1931 | { |
| 1932 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1933 | } |
| 1934 | |
| 1935 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1936 | { |
| 1937 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1938 | } |
| 1939 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1940 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1941 | { |
| 1942 | return lhs = lhs + rhs; |
| 1943 | } |
| 1944 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1945 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1946 | { |
| 1947 | return lhs = lhs - rhs; |
| 1948 | } |
| 1949 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1950 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1951 | { |
| 1952 | return lhs = lhs * rhs; |
| 1953 | } |
| 1954 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1955 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1956 | { |
| 1957 | return lhs = lhs / rhs; |
| 1958 | } |
| 1959 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1960 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1961 | { |
| 1962 | return lhs = lhs % rhs; |
| 1963 | } |
| 1964 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1965 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1966 | { |
| 1967 | return lhs = lhs & rhs; |
| 1968 | } |
| 1969 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1970 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1971 | { |
| 1972 | return lhs = lhs | rhs; |
| 1973 | } |
| 1974 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1975 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1976 | { |
| 1977 | return lhs = lhs ^ rhs; |
| 1978 | } |
| 1979 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1980 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1981 | { |
| 1982 | return lhs = lhs << rhs; |
| 1983 | } |
| 1984 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1985 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1986 | { |
| 1987 | return lhs = lhs >> rhs; |
| 1988 | } |
| 1989 | |
| 1990 | RValue<SByte> operator+(RValue<SByte> val) |
| 1991 | { |
| 1992 | return val; |
| 1993 | } |
| 1994 | |
| 1995 | RValue<SByte> operator-(RValue<SByte> val) |
| 1996 | { |
| 1997 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1998 | } |
| 1999 | |
| 2000 | RValue<SByte> operator~(RValue<SByte> val) |
| 2001 | { |
| 2002 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 2003 | } |
| 2004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2005 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2006 | { |
| 2007 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2008 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2009 | return res; |
| 2010 | } |
| 2011 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2012 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2013 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2014 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2015 | return val; |
| 2016 | } |
| 2017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2018 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2019 | { |
| 2020 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2021 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2022 | return res; |
| 2023 | } |
| 2024 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2025 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2026 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2027 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2028 | return val; |
| 2029 | } |
| 2030 | |
| 2031 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2032 | { |
| 2033 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2034 | } |
| 2035 | |
| 2036 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2037 | { |
| 2038 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2039 | } |
| 2040 | |
| 2041 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2042 | { |
| 2043 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2044 | } |
| 2045 | |
| 2046 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2047 | { |
| 2048 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2049 | } |
| 2050 | |
| 2051 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2052 | { |
| 2053 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2054 | } |
| 2055 | |
| 2056 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2057 | { |
| 2058 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2059 | } |
| 2060 | |
| 2061 | Type *SByte::getType() |
| 2062 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2063 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | Short::Short(Argument<Short> argument) |
| 2067 | { |
| 2068 | storeValue(argument.value); |
| 2069 | } |
| 2070 | |
| 2071 | Short::Short(RValue<Int> cast) |
| 2072 | { |
| 2073 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2074 | |
| 2075 | storeValue(integer); |
| 2076 | } |
| 2077 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2078 | Short::Short(short x) |
| 2079 | { |
| 2080 | storeValue(Nucleus::createConstantShort(x)); |
| 2081 | } |
| 2082 | |
| 2083 | Short::Short(RValue<Short> rhs) |
| 2084 | { |
| 2085 | storeValue(rhs.value); |
| 2086 | } |
| 2087 | |
| 2088 | Short::Short(const Short &rhs) |
| 2089 | { |
| 2090 | Value *value = rhs.loadValue(); |
| 2091 | storeValue(value); |
| 2092 | } |
| 2093 | |
| 2094 | Short::Short(const Reference<Short> &rhs) |
| 2095 | { |
| 2096 | Value *value = rhs.loadValue(); |
| 2097 | storeValue(value); |
| 2098 | } |
| 2099 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2100 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2101 | { |
| 2102 | storeValue(rhs.value); |
| 2103 | |
| 2104 | return rhs; |
| 2105 | } |
| 2106 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2107 | RValue<Short> Short::operator=(const 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 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2115 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2116 | { |
| 2117 | Value *value = rhs.loadValue(); |
| 2118 | storeValue(value); |
| 2119 | |
| 2120 | return RValue<Short>(value); |
| 2121 | } |
| 2122 | |
| 2123 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 2124 | { |
| 2125 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2126 | } |
| 2127 | |
| 2128 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 2129 | { |
| 2130 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2131 | } |
| 2132 | |
| 2133 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 2134 | { |
| 2135 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2136 | } |
| 2137 | |
| 2138 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 2139 | { |
| 2140 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2141 | } |
| 2142 | |
| 2143 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 2144 | { |
| 2145 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2146 | } |
| 2147 | |
| 2148 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 2149 | { |
| 2150 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2151 | } |
| 2152 | |
| 2153 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 2154 | { |
| 2155 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2156 | } |
| 2157 | |
| 2158 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2159 | { |
| 2160 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2161 | } |
| 2162 | |
| 2163 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2164 | { |
| 2165 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2166 | } |
| 2167 | |
| 2168 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2169 | { |
| 2170 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2171 | } |
| 2172 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2173 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2174 | { |
| 2175 | return lhs = lhs + rhs; |
| 2176 | } |
| 2177 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2178 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2179 | { |
| 2180 | return lhs = lhs - rhs; |
| 2181 | } |
| 2182 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2183 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2184 | { |
| 2185 | return lhs = lhs * rhs; |
| 2186 | } |
| 2187 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2188 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2189 | { |
| 2190 | return lhs = lhs / rhs; |
| 2191 | } |
| 2192 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2193 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2194 | { |
| 2195 | return lhs = lhs % rhs; |
| 2196 | } |
| 2197 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2198 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2199 | { |
| 2200 | return lhs = lhs & rhs; |
| 2201 | } |
| 2202 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2203 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2204 | { |
| 2205 | return lhs = lhs | rhs; |
| 2206 | } |
| 2207 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2208 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2209 | { |
| 2210 | return lhs = lhs ^ rhs; |
| 2211 | } |
| 2212 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2213 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2214 | { |
| 2215 | return lhs = lhs << rhs; |
| 2216 | } |
| 2217 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2218 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2219 | { |
| 2220 | return lhs = lhs >> rhs; |
| 2221 | } |
| 2222 | |
| 2223 | RValue<Short> operator+(RValue<Short> val) |
| 2224 | { |
| 2225 | return val; |
| 2226 | } |
| 2227 | |
| 2228 | RValue<Short> operator-(RValue<Short> val) |
| 2229 | { |
| 2230 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2231 | } |
| 2232 | |
| 2233 | RValue<Short> operator~(RValue<Short> val) |
| 2234 | { |
| 2235 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2236 | } |
| 2237 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2238 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2239 | { |
| 2240 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2241 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2242 | return res; |
| 2243 | } |
| 2244 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2245 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2246 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2247 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2248 | return val; |
| 2249 | } |
| 2250 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2251 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2252 | { |
| 2253 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2254 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2255 | return res; |
| 2256 | } |
| 2257 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2258 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2259 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2260 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2261 | return val; |
| 2262 | } |
| 2263 | |
| 2264 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2265 | { |
| 2266 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2267 | } |
| 2268 | |
| 2269 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2270 | { |
| 2271 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2272 | } |
| 2273 | |
| 2274 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2275 | { |
| 2276 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2277 | } |
| 2278 | |
| 2279 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2280 | { |
| 2281 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2282 | } |
| 2283 | |
| 2284 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2285 | { |
| 2286 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2287 | } |
| 2288 | |
| 2289 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2290 | { |
| 2291 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2292 | } |
| 2293 | |
| 2294 | Type *Short::getType() |
| 2295 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2296 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | UShort::UShort(Argument<UShort> argument) |
| 2300 | { |
| 2301 | storeValue(argument.value); |
| 2302 | } |
| 2303 | |
| 2304 | UShort::UShort(RValue<UInt> cast) |
| 2305 | { |
| 2306 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2307 | |
| 2308 | storeValue(integer); |
| 2309 | } |
| 2310 | |
| 2311 | UShort::UShort(RValue<Int> cast) |
| 2312 | { |
| 2313 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2314 | |
| 2315 | storeValue(integer); |
| 2316 | } |
| 2317 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2318 | UShort::UShort(unsigned short x) |
| 2319 | { |
| 2320 | storeValue(Nucleus::createConstantShort(x)); |
| 2321 | } |
| 2322 | |
| 2323 | UShort::UShort(RValue<UShort> rhs) |
| 2324 | { |
| 2325 | storeValue(rhs.value); |
| 2326 | } |
| 2327 | |
| 2328 | UShort::UShort(const UShort &rhs) |
| 2329 | { |
| 2330 | Value *value = rhs.loadValue(); |
| 2331 | storeValue(value); |
| 2332 | } |
| 2333 | |
| 2334 | UShort::UShort(const Reference<UShort> &rhs) |
| 2335 | { |
| 2336 | Value *value = rhs.loadValue(); |
| 2337 | storeValue(value); |
| 2338 | } |
| 2339 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2340 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2341 | { |
| 2342 | storeValue(rhs.value); |
| 2343 | |
| 2344 | return rhs; |
| 2345 | } |
| 2346 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2347 | RValue<UShort> UShort::operator=(const 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 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2355 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2356 | { |
| 2357 | Value *value = rhs.loadValue(); |
| 2358 | storeValue(value); |
| 2359 | |
| 2360 | return RValue<UShort>(value); |
| 2361 | } |
| 2362 | |
| 2363 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2364 | { |
| 2365 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2366 | } |
| 2367 | |
| 2368 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2369 | { |
| 2370 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2371 | } |
| 2372 | |
| 2373 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2374 | { |
| 2375 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2376 | } |
| 2377 | |
| 2378 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2379 | { |
| 2380 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2381 | } |
| 2382 | |
| 2383 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2384 | { |
| 2385 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2386 | } |
| 2387 | |
| 2388 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2389 | { |
| 2390 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2391 | } |
| 2392 | |
| 2393 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2394 | { |
| 2395 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2396 | } |
| 2397 | |
| 2398 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2399 | { |
| 2400 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2401 | } |
| 2402 | |
| 2403 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2404 | { |
| 2405 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2406 | } |
| 2407 | |
| 2408 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2409 | { |
| 2410 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2411 | } |
| 2412 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2413 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2414 | { |
| 2415 | return lhs = lhs + rhs; |
| 2416 | } |
| 2417 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2418 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2419 | { |
| 2420 | return lhs = lhs - rhs; |
| 2421 | } |
| 2422 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2423 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2424 | { |
| 2425 | return lhs = lhs * rhs; |
| 2426 | } |
| 2427 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2428 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2429 | { |
| 2430 | return lhs = lhs / rhs; |
| 2431 | } |
| 2432 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2433 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2434 | { |
| 2435 | return lhs = lhs % rhs; |
| 2436 | } |
| 2437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2438 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2439 | { |
| 2440 | return lhs = lhs & rhs; |
| 2441 | } |
| 2442 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2443 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2444 | { |
| 2445 | return lhs = lhs | rhs; |
| 2446 | } |
| 2447 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2448 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2449 | { |
| 2450 | return lhs = lhs ^ rhs; |
| 2451 | } |
| 2452 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2453 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2454 | { |
| 2455 | return lhs = lhs << rhs; |
| 2456 | } |
| 2457 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2458 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2459 | { |
| 2460 | return lhs = lhs >> rhs; |
| 2461 | } |
| 2462 | |
| 2463 | RValue<UShort> operator+(RValue<UShort> val) |
| 2464 | { |
| 2465 | return val; |
| 2466 | } |
| 2467 | |
| 2468 | RValue<UShort> operator-(RValue<UShort> val) |
| 2469 | { |
| 2470 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2471 | } |
| 2472 | |
| 2473 | RValue<UShort> operator~(RValue<UShort> val) |
| 2474 | { |
| 2475 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2476 | } |
| 2477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2478 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2479 | { |
| 2480 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2481 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2482 | return res; |
| 2483 | } |
| 2484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2485 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2486 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2487 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2488 | return val; |
| 2489 | } |
| 2490 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2491 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2492 | { |
| 2493 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2494 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2495 | return res; |
| 2496 | } |
| 2497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2498 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2499 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2500 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2501 | return val; |
| 2502 | } |
| 2503 | |
| 2504 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2505 | { |
| 2506 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2507 | } |
| 2508 | |
| 2509 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2510 | { |
| 2511 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2512 | } |
| 2513 | |
| 2514 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2515 | { |
| 2516 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2517 | } |
| 2518 | |
| 2519 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2520 | { |
| 2521 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2522 | } |
| 2523 | |
| 2524 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2525 | { |
| 2526 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2527 | } |
| 2528 | |
| 2529 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2530 | { |
| 2531 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2532 | } |
| 2533 | |
| 2534 | Type *UShort::getType() |
| 2535 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2536 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2537 | } |
| 2538 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2539 | Byte4::Byte4(RValue<Byte8> cast) |
| 2540 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2541 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2542 | } |
| 2543 | |
| 2544 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2545 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2546 | Value *value = rhs.loadValue(); |
| 2547 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2548 | } |
| 2549 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2550 | Type *Byte4::getType() |
| 2551 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2552 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | Type *SByte4::getType() |
| 2556 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2557 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2558 | } |
| 2559 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2560 | 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) |
| 2561 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2562 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2563 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2567 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2568 | storeValue(rhs.value); |
| 2569 | } |
| 2570 | |
| 2571 | Byte8::Byte8(const Byte8 &rhs) |
| 2572 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2573 | Value *value = rhs.loadValue(); |
| 2574 | storeValue(value); |
| 2575 | } |
| 2576 | |
| 2577 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2578 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2579 | Value *value = rhs.loadValue(); |
| 2580 | storeValue(value); |
| 2581 | } |
| 2582 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2583 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2584 | { |
| 2585 | storeValue(rhs.value); |
| 2586 | |
| 2587 | return rhs; |
| 2588 | } |
| 2589 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2590 | RValue<Byte8> Byte8::operator=(const 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 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2598 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2599 | { |
| 2600 | Value *value = rhs.loadValue(); |
| 2601 | storeValue(value); |
| 2602 | |
| 2603 | return RValue<Byte8>(value); |
| 2604 | } |
| 2605 | |
| 2606 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2607 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2608 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2612 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2613 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2617 | // { |
| 2618 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2619 | // } |
| 2620 | |
| 2621 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2622 | // { |
| 2623 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2624 | // } |
| 2625 | |
| 2626 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2627 | // { |
| 2628 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2629 | // } |
| 2630 | |
| 2631 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2632 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2633 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2637 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2638 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2642 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2643 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2647 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2648 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2649 | // } |
| 2650 | |
| 2651 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2652 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2653 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2654 | // } |
| 2655 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2656 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2657 | { |
| 2658 | return lhs = lhs + rhs; |
| 2659 | } |
| 2660 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2661 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2662 | { |
| 2663 | return lhs = lhs - rhs; |
| 2664 | } |
| 2665 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2666 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2667 | // { |
| 2668 | // return lhs = lhs * rhs; |
| 2669 | // } |
| 2670 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2671 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2672 | // { |
| 2673 | // return lhs = lhs / rhs; |
| 2674 | // } |
| 2675 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2676 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2677 | // { |
| 2678 | // return lhs = lhs % rhs; |
| 2679 | // } |
| 2680 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2681 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2682 | { |
| 2683 | return lhs = lhs & rhs; |
| 2684 | } |
| 2685 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2686 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2687 | { |
| 2688 | return lhs = lhs | rhs; |
| 2689 | } |
| 2690 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2691 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2692 | { |
| 2693 | return lhs = lhs ^ rhs; |
| 2694 | } |
| 2695 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2696 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2697 | // { |
| 2698 | // return lhs = lhs << rhs; |
| 2699 | // } |
| 2700 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2701 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2702 | // { |
| 2703 | // return lhs = lhs >> rhs; |
| 2704 | // } |
| 2705 | |
| 2706 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2707 | // { |
| 2708 | // return val; |
| 2709 | // } |
| 2710 | |
| 2711 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2712 | // { |
| 2713 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2714 | // } |
| 2715 | |
| 2716 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2717 | { |
| 2718 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2719 | } |
| 2720 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2721 | RValue<Byte> Extract(RValue<Byte8> val, int i) |
| 2722 | { |
| 2723 | return RValue<Byte>(Nucleus::createExtractElement(val.value, Byte::getType(), i)); |
| 2724 | } |
| 2725 | |
| 2726 | RValue<Byte8> Insert(RValue<Byte8> val, RValue<Byte> element, int i) |
| 2727 | { |
| 2728 | return RValue<Byte8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2729 | } |
| 2730 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2731 | RValue<Byte> SaturateUnsigned(RValue<Short> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2732 | { |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 2733 | return Byte(IfThenElse(Int(x) > 0xFF, Int(0xFF), IfThenElse(Int(x) < 0, Int(0), Int(x)))); |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2734 | } |
| 2735 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2736 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2737 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2738 | if(emulateIntrinsics) |
| 2739 | { |
| 2740 | Byte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2741 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0); |
| 2742 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1); |
| 2743 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2); |
| 2744 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3); |
| 2745 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4); |
| 2746 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5); |
| 2747 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6); |
| 2748 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2749 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2750 | return result; |
| 2751 | } |
| 2752 | else |
| 2753 | { |
| 2754 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2755 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2756 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2757 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2758 | paddusb->addArg(x.value); |
| 2759 | paddusb->addArg(y.value); |
| 2760 | ::basicBlock->appendInst(paddusb); |
| 2761 | |
| 2762 | return RValue<Byte8>(V(result)); |
| 2763 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2767 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2768 | if(emulateIntrinsics) |
| 2769 | { |
| 2770 | Byte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2771 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0); |
| 2772 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1); |
| 2773 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2); |
| 2774 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3); |
| 2775 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4); |
| 2776 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5); |
| 2777 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6); |
| 2778 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2779 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2780 | return result; |
| 2781 | } |
| 2782 | else |
| 2783 | { |
| 2784 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2785 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2786 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2787 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2788 | psubusw->addArg(x.value); |
| 2789 | psubusw->addArg(y.value); |
| 2790 | ::basicBlock->appendInst(psubusw); |
| 2791 | |
| 2792 | return RValue<Byte8>(V(result)); |
| 2793 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2797 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2798 | 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] | 2799 | return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2802 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2803 | { |
| 2804 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| 2805 | } |
| 2806 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2807 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2808 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2809 | 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] | 2810 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2814 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2815 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2816 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2817 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2818 | } |
| 2819 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2820 | RValue<SByte> Extract(RValue<SByte8> val, int i) |
| 2821 | { |
| 2822 | return RValue<SByte>(Nucleus::createExtractElement(val.value, SByte::getType(), i)); |
| 2823 | } |
| 2824 | |
| 2825 | RValue<SByte8> Insert(RValue<SByte8> val, RValue<SByte> element, int i) |
| 2826 | { |
| 2827 | return RValue<SByte8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2828 | } |
| 2829 | |
| 2830 | RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2831 | { |
| 2832 | if(emulateIntrinsics) |
| 2833 | { |
| 2834 | SByte8 result; |
| 2835 | result = Insert(result, Extract(lhs, 0) >> SByte(rhs), 0); |
| 2836 | result = Insert(result, Extract(lhs, 1) >> SByte(rhs), 1); |
| 2837 | result = Insert(result, Extract(lhs, 2) >> SByte(rhs), 2); |
| 2838 | result = Insert(result, Extract(lhs, 3) >> SByte(rhs), 3); |
| 2839 | result = Insert(result, Extract(lhs, 4) >> SByte(rhs), 4); |
| 2840 | result = Insert(result, Extract(lhs, 5) >> SByte(rhs), 5); |
| 2841 | result = Insert(result, Extract(lhs, 6) >> SByte(rhs), 6); |
| 2842 | result = Insert(result, Extract(lhs, 7) >> SByte(rhs), 7); |
| 2843 | |
| 2844 | return result; |
| 2845 | } |
| 2846 | else |
| 2847 | { |
| 2848 | #if defined(__i386__) || defined(__x86_64__) |
| 2849 | // SSE2 doesn't support byte vector shifts, so shift as shorts and recombine. |
Alexis Hetu | e18c530 | 2017-08-04 11:48:17 -0400 | [diff] [blame] | 2850 | RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00u); |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2851 | RValue<Short4> lo = As<Short4>(As<UShort4>((As<Short4>(lhs) << 8) >> rhs) >> 8); |
| 2852 | |
| 2853 | return As<SByte8>(hi | lo); |
| 2854 | #else |
| 2855 | return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 2856 | #endif |
| 2857 | } |
| 2858 | } |
| 2859 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2860 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2861 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 2862 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2863 | { |
| 2864 | Byte8 xx = As<Byte8>(As<SByte8>(x) >> 7) & Byte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80); |
| 2865 | 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)); |
| 2866 | } |
| 2867 | else |
| 2868 | { |
| 2869 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2870 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2871 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2872 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2873 | movmsk->addArg(x.value); |
| 2874 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2875 | |
Nicolas Capens | 0f70a7f | 2017-07-26 13:50:04 -0400 | [diff] [blame] | 2876 | return RValue<Int>(V(result)) & 0xFF; |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2877 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2881 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2882 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2883 | // } |
| 2884 | |
| 2885 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2886 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2887 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | Type *Byte8::getType() |
| 2891 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2892 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2893 | } |
| 2894 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2895 | 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) |
| 2896 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2897 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2898 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2899 | |
| 2900 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2901 | } |
| 2902 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2903 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2904 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2905 | storeValue(rhs.value); |
| 2906 | } |
| 2907 | |
| 2908 | SByte8::SByte8(const SByte8 &rhs) |
| 2909 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2910 | Value *value = rhs.loadValue(); |
| 2911 | storeValue(value); |
| 2912 | } |
| 2913 | |
| 2914 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2915 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2916 | Value *value = rhs.loadValue(); |
| 2917 | storeValue(value); |
| 2918 | } |
| 2919 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2920 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2921 | { |
| 2922 | storeValue(rhs.value); |
| 2923 | |
| 2924 | return rhs; |
| 2925 | } |
| 2926 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2927 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2928 | { |
| 2929 | Value *value = rhs.loadValue(); |
| 2930 | storeValue(value); |
| 2931 | |
| 2932 | return RValue<SByte8>(value); |
| 2933 | } |
| 2934 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2935 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2936 | { |
| 2937 | Value *value = rhs.loadValue(); |
| 2938 | storeValue(value); |
| 2939 | |
| 2940 | return RValue<SByte8>(value); |
| 2941 | } |
| 2942 | |
| 2943 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2944 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2945 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2949 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2950 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2954 | // { |
| 2955 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2956 | // } |
| 2957 | |
| 2958 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2959 | // { |
| 2960 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2961 | // } |
| 2962 | |
| 2963 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2964 | // { |
| 2965 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2966 | // } |
| 2967 | |
| 2968 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2969 | { |
| 2970 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2971 | } |
| 2972 | |
| 2973 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2974 | { |
| 2975 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2976 | } |
| 2977 | |
| 2978 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2979 | { |
| 2980 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2981 | } |
| 2982 | |
| 2983 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2984 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2985 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2986 | // } |
| 2987 | |
| 2988 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2989 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2990 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2991 | // } |
| 2992 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2993 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2994 | { |
| 2995 | return lhs = lhs + rhs; |
| 2996 | } |
| 2997 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2998 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2999 | { |
| 3000 | return lhs = lhs - rhs; |
| 3001 | } |
| 3002 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3003 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3004 | // { |
| 3005 | // return lhs = lhs * rhs; |
| 3006 | // } |
| 3007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3008 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3009 | // { |
| 3010 | // return lhs = lhs / rhs; |
| 3011 | // } |
| 3012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3013 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3014 | // { |
| 3015 | // return lhs = lhs % rhs; |
| 3016 | // } |
| 3017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3018 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3019 | { |
| 3020 | return lhs = lhs & rhs; |
| 3021 | } |
| 3022 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3023 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3024 | { |
| 3025 | return lhs = lhs | rhs; |
| 3026 | } |
| 3027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3028 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3029 | { |
| 3030 | return lhs = lhs ^ rhs; |
| 3031 | } |
| 3032 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3033 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3034 | // { |
| 3035 | // return lhs = lhs << rhs; |
| 3036 | // } |
| 3037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3038 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3039 | // { |
| 3040 | // return lhs = lhs >> rhs; |
| 3041 | // } |
| 3042 | |
| 3043 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 3044 | // { |
| 3045 | // return val; |
| 3046 | // } |
| 3047 | |
| 3048 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 3049 | // { |
| 3050 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 3051 | // } |
| 3052 | |
| 3053 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 3054 | { |
| 3055 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 3056 | } |
| 3057 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3058 | RValue<SByte> SaturateSigned(RValue<Short> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3059 | { |
| 3060 | return SByte(IfThenElse(Int(x) > 0x7F, Int(0x7F), IfThenElse(Int(x) < -0x80, Int(0x80), Int(x)))); |
| 3061 | } |
| 3062 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3063 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 3064 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3065 | if(emulateIntrinsics) |
| 3066 | { |
| 3067 | SByte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3068 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0); |
| 3069 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1); |
| 3070 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2); |
| 3071 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3); |
| 3072 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4); |
| 3073 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5); |
| 3074 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6); |
| 3075 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3076 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3077 | return result; |
| 3078 | } |
| 3079 | else |
| 3080 | { |
| 3081 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3082 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3083 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3084 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3085 | paddsb->addArg(x.value); |
| 3086 | paddsb->addArg(y.value); |
| 3087 | ::basicBlock->appendInst(paddsb); |
| 3088 | |
| 3089 | return RValue<SByte8>(V(result)); |
| 3090 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 3094 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3095 | if(emulateIntrinsics) |
| 3096 | { |
| 3097 | SByte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3098 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0); |
| 3099 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1); |
| 3100 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2); |
| 3101 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3); |
| 3102 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4); |
| 3103 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5); |
| 3104 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6); |
| 3105 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3106 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3107 | return result; |
| 3108 | } |
| 3109 | else |
| 3110 | { |
| 3111 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3112 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3113 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3114 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3115 | psubsb->addArg(x.value); |
| 3116 | psubsb->addArg(y.value); |
| 3117 | ::basicBlock->appendInst(psubsb); |
| 3118 | |
| 3119 | return RValue<SByte8>(V(result)); |
| 3120 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 3124 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3125 | 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] | 3126 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 3130 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3131 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 3132 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3133 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | RValue<Int> SignMask(RValue<SByte8> x) |
| 3137 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 3138 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3139 | { |
| 3140 | SByte8 xx = (x >> 7) & SByte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80); |
| 3141 | 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)); |
| 3142 | } |
| 3143 | else |
| 3144 | { |
| 3145 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 3146 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3147 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3148 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 3149 | movmsk->addArg(x.value); |
| 3150 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 3151 | |
Nicolas Capens | 0f70a7f | 2017-07-26 13:50:04 -0400 | [diff] [blame] | 3152 | return RValue<Int>(V(result)) & 0xFF; |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3153 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 3157 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3158 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 3162 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3163 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | Type *SByte8::getType() |
| 3167 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3168 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | Byte16::Byte16(RValue<Byte16> rhs) |
| 3172 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3173 | storeValue(rhs.value); |
| 3174 | } |
| 3175 | |
| 3176 | Byte16::Byte16(const Byte16 &rhs) |
| 3177 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3178 | Value *value = rhs.loadValue(); |
| 3179 | storeValue(value); |
| 3180 | } |
| 3181 | |
| 3182 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 3183 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3184 | Value *value = rhs.loadValue(); |
| 3185 | storeValue(value); |
| 3186 | } |
| 3187 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3188 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3189 | { |
| 3190 | storeValue(rhs.value); |
| 3191 | |
| 3192 | return rhs; |
| 3193 | } |
| 3194 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3195 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3196 | { |
| 3197 | Value *value = rhs.loadValue(); |
| 3198 | storeValue(value); |
| 3199 | |
| 3200 | return RValue<Byte16>(value); |
| 3201 | } |
| 3202 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3203 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3204 | { |
| 3205 | Value *value = rhs.loadValue(); |
| 3206 | storeValue(value); |
| 3207 | |
| 3208 | return RValue<Byte16>(value); |
| 3209 | } |
| 3210 | |
| 3211 | Type *Byte16::getType() |
| 3212 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3213 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | Type *SByte16::getType() |
| 3217 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3218 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3219 | } |
| 3220 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3221 | Short2::Short2(RValue<Short4> cast) |
| 3222 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3223 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | Type *Short2::getType() |
| 3227 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3228 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | UShort2::UShort2(RValue<UShort4> cast) |
| 3232 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3233 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | Type *UShort2::getType() |
| 3237 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3238 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3239 | } |
| 3240 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3241 | Short4::Short4(RValue<Int> cast) |
| 3242 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3243 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 3244 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 3245 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3246 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3247 | |
| 3248 | storeValue(swizzle); |
| 3249 | } |
| 3250 | |
| 3251 | Short4::Short4(RValue<Int4> cast) |
| 3252 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 3253 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 3254 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 3255 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3256 | |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3257 | Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value; |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3258 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 3259 | |
| 3260 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | // Short4::Short4(RValue<Float> cast) |
| 3264 | // { |
| 3265 | // } |
| 3266 | |
| 3267 | Short4::Short4(RValue<Float4> cast) |
| 3268 | { |
| 3269 | assert(false && "UNIMPLEMENTED"); |
| 3270 | } |
| 3271 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3272 | Short4::Short4(short xyzw) |
| 3273 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3274 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3275 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | Short4::Short4(short x, short y, short z, short w) |
| 3279 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3280 | int64_t constantVector[4] = {x, y, z, w}; |
| 3281 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | Short4::Short4(RValue<Short4> rhs) |
| 3285 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3286 | storeValue(rhs.value); |
| 3287 | } |
| 3288 | |
| 3289 | Short4::Short4(const Short4 &rhs) |
| 3290 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3291 | Value *value = rhs.loadValue(); |
| 3292 | storeValue(value); |
| 3293 | } |
| 3294 | |
| 3295 | Short4::Short4(const Reference<Short4> &rhs) |
| 3296 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3297 | Value *value = rhs.loadValue(); |
| 3298 | storeValue(value); |
| 3299 | } |
| 3300 | |
| 3301 | Short4::Short4(RValue<UShort4> rhs) |
| 3302 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3303 | storeValue(rhs.value); |
| 3304 | } |
| 3305 | |
| 3306 | Short4::Short4(const UShort4 &rhs) |
| 3307 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3308 | storeValue(rhs.loadValue()); |
| 3309 | } |
| 3310 | |
| 3311 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3312 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3313 | storeValue(rhs.loadValue()); |
| 3314 | } |
| 3315 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3316 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3317 | { |
| 3318 | storeValue(rhs.value); |
| 3319 | |
| 3320 | return rhs; |
| 3321 | } |
| 3322 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3323 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3324 | { |
| 3325 | Value *value = rhs.loadValue(); |
| 3326 | storeValue(value); |
| 3327 | |
| 3328 | return RValue<Short4>(value); |
| 3329 | } |
| 3330 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3331 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3332 | { |
| 3333 | Value *value = rhs.loadValue(); |
| 3334 | storeValue(value); |
| 3335 | |
| 3336 | return RValue<Short4>(value); |
| 3337 | } |
| 3338 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3339 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3340 | { |
| 3341 | storeValue(rhs.value); |
| 3342 | |
| 3343 | return RValue<Short4>(rhs); |
| 3344 | } |
| 3345 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3346 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3347 | { |
| 3348 | Value *value = rhs.loadValue(); |
| 3349 | storeValue(value); |
| 3350 | |
| 3351 | return RValue<Short4>(value); |
| 3352 | } |
| 3353 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3354 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3355 | { |
| 3356 | Value *value = rhs.loadValue(); |
| 3357 | storeValue(value); |
| 3358 | |
| 3359 | return RValue<Short4>(value); |
| 3360 | } |
| 3361 | |
| 3362 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3363 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3364 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3368 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3369 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3373 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3374 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3378 | // { |
| 3379 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3380 | // } |
| 3381 | |
| 3382 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3383 | // { |
| 3384 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3385 | // } |
| 3386 | |
| 3387 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3388 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3389 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3393 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3394 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3398 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3399 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3403 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3404 | if(emulateIntrinsics) |
| 3405 | { |
| 3406 | Short4 result; |
| 3407 | result = Insert(result, Extract(lhs, 0) << Short(rhs), 0); |
| 3408 | result = Insert(result, Extract(lhs, 1) << Short(rhs), 1); |
| 3409 | result = Insert(result, Extract(lhs, 2) << Short(rhs), 2); |
| 3410 | result = Insert(result, Extract(lhs, 3) << Short(rhs), 3); |
| 3411 | |
| 3412 | return result; |
| 3413 | } |
| 3414 | else |
| 3415 | { |
| 3416 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3417 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3421 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3422 | if(emulateIntrinsics) |
| 3423 | { |
| 3424 | Short4 result; |
| 3425 | result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0); |
| 3426 | result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1); |
| 3427 | result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2); |
| 3428 | result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3); |
| 3429 | |
| 3430 | return result; |
| 3431 | } |
| 3432 | else |
| 3433 | { |
| 3434 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3435 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3436 | } |
| 3437 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3438 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3439 | { |
| 3440 | return lhs = lhs + rhs; |
| 3441 | } |
| 3442 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3443 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3444 | { |
| 3445 | return lhs = lhs - rhs; |
| 3446 | } |
| 3447 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3448 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3449 | { |
| 3450 | return lhs = lhs * rhs; |
| 3451 | } |
| 3452 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3453 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3454 | // { |
| 3455 | // return lhs = lhs / rhs; |
| 3456 | // } |
| 3457 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3458 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3459 | // { |
| 3460 | // return lhs = lhs % rhs; |
| 3461 | // } |
| 3462 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3463 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3464 | { |
| 3465 | return lhs = lhs & rhs; |
| 3466 | } |
| 3467 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3468 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3469 | { |
| 3470 | return lhs = lhs | rhs; |
| 3471 | } |
| 3472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3473 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3474 | { |
| 3475 | return lhs = lhs ^ rhs; |
| 3476 | } |
| 3477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3478 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3479 | { |
| 3480 | return lhs = lhs << rhs; |
| 3481 | } |
| 3482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3483 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3484 | { |
| 3485 | return lhs = lhs >> rhs; |
| 3486 | } |
| 3487 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3488 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3489 | // { |
| 3490 | // return val; |
| 3491 | // } |
| 3492 | |
| 3493 | RValue<Short4> operator-(RValue<Short4> val) |
| 3494 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3495 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | RValue<Short4> operator~(RValue<Short4> val) |
| 3499 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3500 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3504 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3505 | RValue<Int4> int4 = RoundInt(cast); |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3506 | return As<Short4>(PackSigned(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3510 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3511 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3512 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3513 | ::basicBlock->appendInst(cmp); |
| 3514 | |
| 3515 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3516 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3517 | ::basicBlock->appendInst(select); |
| 3518 | |
| 3519 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3523 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3524 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3525 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3526 | ::basicBlock->appendInst(cmp); |
| 3527 | |
| 3528 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3529 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3530 | ::basicBlock->appendInst(select); |
| 3531 | |
| 3532 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3533 | } |
| 3534 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3535 | RValue<Short> SaturateSigned(RValue<Int> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3536 | { |
| 3537 | return Short(IfThenElse(x > 0x7FFF, Int(0x7FFF), IfThenElse(x < -0x8000, Int(0x8000), x))); |
| 3538 | } |
| 3539 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3540 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3541 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3542 | if(emulateIntrinsics) |
| 3543 | { |
| 3544 | Short4 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3545 | result = Insert(result, SaturateSigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0); |
| 3546 | result = Insert(result, SaturateSigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1); |
| 3547 | result = Insert(result, SaturateSigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2); |
| 3548 | result = Insert(result, SaturateSigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3549 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3550 | return result; |
| 3551 | } |
| 3552 | else |
| 3553 | { |
| 3554 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3555 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3556 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3557 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3558 | paddsw->addArg(x.value); |
| 3559 | paddsw->addArg(y.value); |
| 3560 | ::basicBlock->appendInst(paddsw); |
| 3561 | |
| 3562 | return RValue<Short4>(V(result)); |
| 3563 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3567 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3568 | if(emulateIntrinsics) |
| 3569 | { |
| 3570 | Short4 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3571 | result = Insert(result, SaturateSigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0); |
| 3572 | result = Insert(result, SaturateSigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1); |
| 3573 | result = Insert(result, SaturateSigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2); |
| 3574 | result = Insert(result, SaturateSigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3575 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3576 | return result; |
| 3577 | } |
| 3578 | else |
| 3579 | { |
| 3580 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3581 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3582 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3583 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3584 | psubsw->addArg(x.value); |
| 3585 | psubsw->addArg(y.value); |
| 3586 | ::basicBlock->appendInst(psubsw); |
| 3587 | |
| 3588 | return RValue<Short4>(V(result)); |
| 3589 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3593 | { |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3594 | if(emulateIntrinsics) |
| 3595 | { |
| 3596 | Short4 result; |
| 3597 | result = Insert(result, Short((Int(Extract(x, 0)) * Int(Extract(y, 0))) >> 16), 0); |
| 3598 | result = Insert(result, Short((Int(Extract(x, 1)) * Int(Extract(y, 1))) >> 16), 1); |
| 3599 | result = Insert(result, Short((Int(Extract(x, 2)) * Int(Extract(y, 2))) >> 16), 2); |
| 3600 | result = Insert(result, Short((Int(Extract(x, 3)) * Int(Extract(y, 3))) >> 16), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3601 | |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3602 | return result; |
| 3603 | } |
| 3604 | else |
| 3605 | { |
| 3606 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3607 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3608 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3609 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3610 | pmulhw->addArg(x.value); |
| 3611 | pmulhw->addArg(y.value); |
| 3612 | ::basicBlock->appendInst(pmulhw); |
| 3613 | |
| 3614 | return RValue<Short4>(V(result)); |
| 3615 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3619 | { |
Nicolas Capens | afe27e9 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3620 | if(emulateIntrinsics) |
| 3621 | { |
| 3622 | Int2 result; |
| 3623 | result = Insert(result, Int(Extract(x, 0)) * Int(Extract(y, 0)) + Int(Extract(x, 1)) * Int(Extract(y, 1)), 0); |
| 3624 | result = Insert(result, Int(Extract(x, 2)) * Int(Extract(y, 2)) + Int(Extract(x, 3)) * Int(Extract(y, 3)), 1); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3625 | |
Nicolas Capens | afe27e9 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3626 | return result; |
| 3627 | } |
| 3628 | else |
| 3629 | { |
| 3630 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3631 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3632 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3633 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3634 | pmaddwd->addArg(x.value); |
| 3635 | pmaddwd->addArg(y.value); |
| 3636 | ::basicBlock->appendInst(pmaddwd); |
| 3637 | |
| 3638 | return As<Int2>(V(result)); |
| 3639 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3640 | } |
| 3641 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3642 | RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3643 | { |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3644 | if(emulateIntrinsics) |
| 3645 | { |
| 3646 | SByte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3647 | result = Insert(result, SaturateSigned(Extract(x, 0)), 0); |
| 3648 | result = Insert(result, SaturateSigned(Extract(x, 1)), 1); |
| 3649 | result = Insert(result, SaturateSigned(Extract(x, 2)), 2); |
| 3650 | result = Insert(result, SaturateSigned(Extract(x, 3)), 3); |
| 3651 | result = Insert(result, SaturateSigned(Extract(y, 0)), 4); |
| 3652 | result = Insert(result, SaturateSigned(Extract(y, 1)), 5); |
| 3653 | result = Insert(result, SaturateSigned(Extract(y, 2)), 6); |
| 3654 | result = Insert(result, SaturateSigned(Extract(y, 3)), 7); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3655 | |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3656 | return result; |
| 3657 | } |
| 3658 | else |
| 3659 | { |
| 3660 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3661 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3662 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3663 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3664 | pack->addArg(x.value); |
| 3665 | pack->addArg(y.value); |
| 3666 | ::basicBlock->appendInst(pack); |
| 3667 | |
| 3668 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
| 3669 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3670 | } |
| 3671 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3672 | RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y) |
| 3673 | { |
| 3674 | if(emulateIntrinsics) |
| 3675 | { |
| 3676 | Byte8 result; |
| 3677 | result = Insert(result, SaturateUnsigned(Extract(x, 0)), 0); |
| 3678 | result = Insert(result, SaturateUnsigned(Extract(x, 1)), 1); |
| 3679 | result = Insert(result, SaturateUnsigned(Extract(x, 2)), 2); |
| 3680 | result = Insert(result, SaturateUnsigned(Extract(x, 3)), 3); |
| 3681 | result = Insert(result, SaturateUnsigned(Extract(y, 0)), 4); |
| 3682 | result = Insert(result, SaturateUnsigned(Extract(y, 1)), 5); |
| 3683 | result = Insert(result, SaturateUnsigned(Extract(y, 2)), 6); |
| 3684 | result = Insert(result, SaturateUnsigned(Extract(y, 3)), 7); |
| 3685 | |
| 3686 | return result; |
| 3687 | } |
| 3688 | else |
| 3689 | { |
| 3690 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3691 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3692 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3693 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3694 | pack->addArg(x.value); |
| 3695 | pack->addArg(y.value); |
| 3696 | ::basicBlock->appendInst(pack); |
| 3697 | |
| 3698 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
| 3699 | } |
| 3700 | } |
| 3701 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3702 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3703 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3704 | 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] | 3705 | return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3709 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3710 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3711 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3712 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3716 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3717 | // Real type is v8i16 |
| 3718 | int shuffle[8] = |
| 3719 | { |
| 3720 | (select >> 0) & 0x03, |
| 3721 | (select >> 2) & 0x03, |
| 3722 | (select >> 4) & 0x03, |
| 3723 | (select >> 6) & 0x03, |
| 3724 | (select >> 0) & 0x03, |
| 3725 | (select >> 2) & 0x03, |
| 3726 | (select >> 4) & 0x03, |
| 3727 | (select >> 6) & 0x03, |
| 3728 | }; |
| 3729 | |
| 3730 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3734 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3735 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3739 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3740 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3744 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3745 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3749 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3750 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | Type *Short4::getType() |
| 3754 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3755 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | UShort4::UShort4(RValue<Int4> cast) |
| 3759 | { |
| 3760 | *this = Short4(cast); |
| 3761 | } |
| 3762 | |
| 3763 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3764 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3765 | if(saturate) |
| 3766 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3767 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3768 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 3769 | // x86 produces 0x80000000 on 32-bit integer overflow/underflow. |
| 3770 | // PackUnsigned takes care of 0x0000 saturation. |
| 3771 | Int4 int4(Min(cast, Float4(0xFFFF))); |
| 3772 | *this = As<UShort4>(PackUnsigned(int4, int4)); |
| 3773 | } |
| 3774 | else if(CPUID::ARM) |
| 3775 | { |
| 3776 | // ARM saturates the 32-bit integer result on overflow/undeflow. |
| 3777 | Int4 int4(cast); |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3778 | *this = As<UShort4>(PackUnsigned(int4, int4)); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3779 | } |
| 3780 | else |
| 3781 | { |
| 3782 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3783 | } |
| 3784 | } |
| 3785 | else |
| 3786 | { |
| 3787 | *this = Short4(Int4(cast)); |
| 3788 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3789 | } |
| 3790 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3791 | UShort4::UShort4(unsigned short xyzw) |
| 3792 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3793 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3794 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3798 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3799 | int64_t constantVector[4] = {x, y, z, w}; |
| 3800 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3804 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3805 | storeValue(rhs.value); |
| 3806 | } |
| 3807 | |
| 3808 | UShort4::UShort4(const UShort4 &rhs) |
| 3809 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3810 | Value *value = rhs.loadValue(); |
| 3811 | storeValue(value); |
| 3812 | } |
| 3813 | |
| 3814 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3815 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3816 | Value *value = rhs.loadValue(); |
| 3817 | storeValue(value); |
| 3818 | } |
| 3819 | |
| 3820 | UShort4::UShort4(RValue<Short4> rhs) |
| 3821 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3822 | storeValue(rhs.value); |
| 3823 | } |
| 3824 | |
| 3825 | UShort4::UShort4(const Short4 &rhs) |
| 3826 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3827 | Value *value = rhs.loadValue(); |
| 3828 | storeValue(value); |
| 3829 | } |
| 3830 | |
| 3831 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3832 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3833 | Value *value = rhs.loadValue(); |
| 3834 | storeValue(value); |
| 3835 | } |
| 3836 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3837 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3838 | { |
| 3839 | storeValue(rhs.value); |
| 3840 | |
| 3841 | return rhs; |
| 3842 | } |
| 3843 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3844 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3845 | { |
| 3846 | Value *value = rhs.loadValue(); |
| 3847 | storeValue(value); |
| 3848 | |
| 3849 | return RValue<UShort4>(value); |
| 3850 | } |
| 3851 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3852 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3853 | { |
| 3854 | Value *value = rhs.loadValue(); |
| 3855 | storeValue(value); |
| 3856 | |
| 3857 | return RValue<UShort4>(value); |
| 3858 | } |
| 3859 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3860 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3861 | { |
| 3862 | storeValue(rhs.value); |
| 3863 | |
| 3864 | return RValue<UShort4>(rhs); |
| 3865 | } |
| 3866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3867 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3868 | { |
| 3869 | Value *value = rhs.loadValue(); |
| 3870 | storeValue(value); |
| 3871 | |
| 3872 | return RValue<UShort4>(value); |
| 3873 | } |
| 3874 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3875 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3876 | { |
| 3877 | Value *value = rhs.loadValue(); |
| 3878 | storeValue(value); |
| 3879 | |
| 3880 | return RValue<UShort4>(value); |
| 3881 | } |
| 3882 | |
| 3883 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3884 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3885 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3889 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3890 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3894 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3895 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3896 | } |
| 3897 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3898 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3899 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3900 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3904 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3905 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3909 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3910 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3911 | } |
| 3912 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3913 | RValue<UShort> Extract(RValue<UShort4> val, int i) |
| 3914 | { |
| 3915 | return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i)); |
| 3916 | } |
| 3917 | |
| 3918 | RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i) |
| 3919 | { |
| 3920 | return RValue<UShort4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 3921 | } |
| 3922 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3923 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3924 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3925 | if(emulateIntrinsics) |
| 3926 | { |
| 3927 | UShort4 result; |
| 3928 | result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0); |
| 3929 | result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1); |
| 3930 | result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2); |
| 3931 | result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3); |
| 3932 | |
| 3933 | return result; |
| 3934 | } |
| 3935 | else |
| 3936 | { |
| 3937 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3938 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3942 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3943 | if(emulateIntrinsics) |
| 3944 | { |
| 3945 | UShort4 result; |
| 3946 | result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0); |
| 3947 | result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1); |
| 3948 | result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2); |
| 3949 | result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3); |
| 3950 | |
| 3951 | return result; |
| 3952 | } |
| 3953 | else |
| 3954 | { |
| 3955 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3956 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3957 | } |
| 3958 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3959 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3960 | { |
| 3961 | return lhs = lhs << rhs; |
| 3962 | } |
| 3963 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3964 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3965 | { |
| 3966 | return lhs = lhs >> rhs; |
| 3967 | } |
| 3968 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3969 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3970 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3971 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3975 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3976 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3977 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3978 | ::basicBlock->appendInst(cmp); |
| 3979 | |
| 3980 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3981 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3982 | ::basicBlock->appendInst(select); |
| 3983 | |
| 3984 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3988 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3989 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3990 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3991 | ::basicBlock->appendInst(cmp); |
| 3992 | |
| 3993 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3994 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3995 | ::basicBlock->appendInst(select); |
| 3996 | |
| 3997 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3998 | } |
| 3999 | |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 4000 | RValue<UShort> SaturateUnsigned(RValue<Int> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4001 | { |
| 4002 | return UShort(IfThenElse(x > 0xFFFF, Int(0xFFFF), IfThenElse(x < 0, Int(0), x))); |
| 4003 | } |
| 4004 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4005 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 4006 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4007 | if(emulateIntrinsics) |
| 4008 | { |
| 4009 | UShort4 result; |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 4010 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0); |
| 4011 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1); |
| 4012 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2); |
| 4013 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 4014 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4015 | return result; |
| 4016 | } |
| 4017 | else |
| 4018 | { |
| 4019 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4020 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4021 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4022 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 4023 | paddusw->addArg(x.value); |
| 4024 | paddusw->addArg(y.value); |
| 4025 | ::basicBlock->appendInst(paddusw); |
| 4026 | |
| 4027 | return RValue<UShort4>(V(result)); |
| 4028 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 4032 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4033 | if(emulateIntrinsics) |
| 4034 | { |
| 4035 | UShort4 result; |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 4036 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0); |
| 4037 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1); |
| 4038 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2); |
| 4039 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 4040 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4041 | return result; |
| 4042 | } |
| 4043 | else |
| 4044 | { |
| 4045 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4046 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4047 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4048 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 4049 | psubusw->addArg(x.value); |
| 4050 | psubusw->addArg(y.value); |
| 4051 | ::basicBlock->appendInst(psubusw); |
| 4052 | |
| 4053 | return RValue<UShort4>(V(result)); |
| 4054 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 4058 | { |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4059 | if(emulateIntrinsics) |
| 4060 | { |
| 4061 | UShort4 result; |
| 4062 | result = Insert(result, UShort((UInt(Extract(x, 0)) * UInt(Extract(y, 0))) >> 16), 0); |
| 4063 | result = Insert(result, UShort((UInt(Extract(x, 1)) * UInt(Extract(y, 1))) >> 16), 1); |
| 4064 | result = Insert(result, UShort((UInt(Extract(x, 2)) * UInt(Extract(y, 2))) >> 16), 2); |
| 4065 | result = Insert(result, UShort((UInt(Extract(x, 3)) * UInt(Extract(y, 3))) >> 16), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 4066 | |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4067 | return result; |
| 4068 | } |
| 4069 | else |
| 4070 | { |
| 4071 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4072 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4073 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4074 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 4075 | pmulhuw->addArg(x.value); |
| 4076 | pmulhuw->addArg(y.value); |
| 4077 | ::basicBlock->appendInst(pmulhuw); |
| 4078 | |
| 4079 | return RValue<UShort4>(V(result)); |
| 4080 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 4084 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4085 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4086 | } |
| 4087 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4088 | Type *UShort4::getType() |
| 4089 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 4090 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4091 | } |
| 4092 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 4093 | Short8::Short8(short c) |
| 4094 | { |
| 4095 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 4096 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 4097 | } |
| 4098 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4099 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 4100 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4101 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 4102 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | Short8::Short8(RValue<Short8> rhs) |
| 4106 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4107 | storeValue(rhs.value); |
| 4108 | } |
| 4109 | |
| 4110 | Short8::Short8(const Reference<Short8> &rhs) |
| 4111 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4112 | Value *value = rhs.loadValue(); |
| 4113 | storeValue(value); |
| 4114 | } |
| 4115 | |
| 4116 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 4117 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4118 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 4119 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 4120 | |
| 4121 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 4125 | { |
| 4126 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4127 | } |
| 4128 | |
| 4129 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 4130 | { |
| 4131 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4132 | } |
| 4133 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4134 | RValue<Short> Extract(RValue<Short8> val, int i) |
| 4135 | { |
| 4136 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
| 4137 | } |
| 4138 | |
| 4139 | RValue<Short8> Insert(RValue<Short8> val, RValue<Short> element, int i) |
| 4140 | { |
| 4141 | return RValue<Short8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 4142 | } |
| 4143 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4144 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 4145 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4146 | if(emulateIntrinsics) |
| 4147 | { |
| 4148 | Short8 result; |
| 4149 | result = Insert(result, Extract(lhs, 0) << Short(rhs), 0); |
| 4150 | result = Insert(result, Extract(lhs, 1) << Short(rhs), 1); |
| 4151 | result = Insert(result, Extract(lhs, 2) << Short(rhs), 2); |
| 4152 | result = Insert(result, Extract(lhs, 3) << Short(rhs), 3); |
| 4153 | result = Insert(result, Extract(lhs, 4) << Short(rhs), 4); |
| 4154 | result = Insert(result, Extract(lhs, 5) << Short(rhs), 5); |
| 4155 | result = Insert(result, Extract(lhs, 6) << Short(rhs), 6); |
| 4156 | result = Insert(result, Extract(lhs, 7) << Short(rhs), 7); |
| 4157 | |
| 4158 | return result; |
| 4159 | } |
| 4160 | else |
| 4161 | { |
| 4162 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4163 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 4167 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4168 | if(emulateIntrinsics) |
| 4169 | { |
| 4170 | Short8 result; |
| 4171 | result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0); |
| 4172 | result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1); |
| 4173 | result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2); |
| 4174 | result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3); |
| 4175 | result = Insert(result, Extract(lhs, 4) >> Short(rhs), 4); |
| 4176 | result = Insert(result, Extract(lhs, 5) >> Short(rhs), 5); |
| 4177 | result = Insert(result, Extract(lhs, 6) >> Short(rhs), 6); |
| 4178 | result = Insert(result, Extract(lhs, 7) >> Short(rhs), 7); |
| 4179 | |
| 4180 | return result; |
| 4181 | } |
| 4182 | else |
| 4183 | { |
| 4184 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4185 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 4189 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4190 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | RValue<Int4> Abs(RValue<Int4> x) |
| 4194 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 4195 | auto negative = x >> 31; |
| 4196 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 4200 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4201 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | Type *Short8::getType() |
| 4205 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4206 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4207 | } |
| 4208 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 4209 | UShort8::UShort8(unsigned short c) |
| 4210 | { |
| 4211 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 4212 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 4213 | } |
| 4214 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4215 | 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) |
| 4216 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4217 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 4218 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | UShort8::UShort8(RValue<UShort8> rhs) |
| 4222 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4223 | storeValue(rhs.value); |
| 4224 | } |
| 4225 | |
| 4226 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 4227 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4228 | Value *value = rhs.loadValue(); |
| 4229 | storeValue(value); |
| 4230 | } |
| 4231 | |
| 4232 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 4233 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4234 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 4235 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 4236 | |
| 4237 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4238 | } |
| 4239 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4240 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4241 | { |
| 4242 | storeValue(rhs.value); |
| 4243 | |
| 4244 | return rhs; |
| 4245 | } |
| 4246 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4247 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4248 | { |
| 4249 | Value *value = rhs.loadValue(); |
| 4250 | storeValue(value); |
| 4251 | |
| 4252 | return RValue<UShort8>(value); |
| 4253 | } |
| 4254 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4255 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4256 | { |
| 4257 | Value *value = rhs.loadValue(); |
| 4258 | storeValue(value); |
| 4259 | |
| 4260 | return RValue<UShort8>(value); |
| 4261 | } |
| 4262 | |
| 4263 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4264 | { |
| 4265 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4266 | } |
| 4267 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4268 | RValue<UShort> Extract(RValue<UShort8> val, int i) |
| 4269 | { |
| 4270 | return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i)); |
| 4271 | } |
| 4272 | |
| 4273 | RValue<UShort8> Insert(RValue<UShort8> val, RValue<UShort> element, int i) |
| 4274 | { |
| 4275 | return RValue<UShort8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 4276 | } |
| 4277 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4278 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 4279 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4280 | if(emulateIntrinsics) |
| 4281 | { |
| 4282 | UShort8 result; |
| 4283 | result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0); |
| 4284 | result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1); |
| 4285 | result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2); |
| 4286 | result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3); |
| 4287 | result = Insert(result, Extract(lhs, 4) << UShort(rhs), 4); |
| 4288 | result = Insert(result, Extract(lhs, 5) << UShort(rhs), 5); |
| 4289 | result = Insert(result, Extract(lhs, 6) << UShort(rhs), 6); |
| 4290 | result = Insert(result, Extract(lhs, 7) << UShort(rhs), 7); |
| 4291 | |
| 4292 | return result; |
| 4293 | } |
| 4294 | else |
| 4295 | { |
| 4296 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4297 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 4301 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4302 | if(emulateIntrinsics) |
| 4303 | { |
| 4304 | UShort8 result; |
| 4305 | result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0); |
| 4306 | result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1); |
| 4307 | result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2); |
| 4308 | result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3); |
| 4309 | result = Insert(result, Extract(lhs, 4) >> UShort(rhs), 4); |
| 4310 | result = Insert(result, Extract(lhs, 5) >> UShort(rhs), 5); |
| 4311 | result = Insert(result, Extract(lhs, 6) >> UShort(rhs), 6); |
| 4312 | result = Insert(result, Extract(lhs, 7) >> UShort(rhs), 7); |
| 4313 | |
| 4314 | return result; |
| 4315 | } |
| 4316 | else |
| 4317 | { |
| 4318 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4319 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4323 | { |
| 4324 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4325 | } |
| 4326 | |
| 4327 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4328 | { |
| 4329 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4330 | } |
| 4331 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4332 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4333 | { |
| 4334 | return lhs = lhs + rhs; |
| 4335 | } |
| 4336 | |
| 4337 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 4338 | { |
| 4339 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 4340 | } |
| 4341 | |
| 4342 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 4343 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4344 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 4348 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4349 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 4353 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 4354 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4355 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4356 | // } |
| 4357 | |
| 4358 | Type *UShort8::getType() |
| 4359 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4360 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | Int::Int(Argument<Int> argument) |
| 4364 | { |
| 4365 | storeValue(argument.value); |
| 4366 | } |
| 4367 | |
| 4368 | Int::Int(RValue<Byte> cast) |
| 4369 | { |
| 4370 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 4371 | |
| 4372 | storeValue(integer); |
| 4373 | } |
| 4374 | |
| 4375 | Int::Int(RValue<SByte> cast) |
| 4376 | { |
| 4377 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 4378 | |
| 4379 | storeValue(integer); |
| 4380 | } |
| 4381 | |
| 4382 | Int::Int(RValue<Short> cast) |
| 4383 | { |
| 4384 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 4385 | |
| 4386 | storeValue(integer); |
| 4387 | } |
| 4388 | |
| 4389 | Int::Int(RValue<UShort> cast) |
| 4390 | { |
| 4391 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 4392 | |
| 4393 | storeValue(integer); |
| 4394 | } |
| 4395 | |
| 4396 | Int::Int(RValue<Int2> cast) |
| 4397 | { |
| 4398 | *this = Extract(cast, 0); |
| 4399 | } |
| 4400 | |
| 4401 | Int::Int(RValue<Long> cast) |
| 4402 | { |
| 4403 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 4404 | |
| 4405 | storeValue(integer); |
| 4406 | } |
| 4407 | |
| 4408 | Int::Int(RValue<Float> cast) |
| 4409 | { |
| 4410 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 4411 | |
| 4412 | storeValue(integer); |
| 4413 | } |
| 4414 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4415 | Int::Int(int x) |
| 4416 | { |
| 4417 | storeValue(Nucleus::createConstantInt(x)); |
| 4418 | } |
| 4419 | |
| 4420 | Int::Int(RValue<Int> rhs) |
| 4421 | { |
| 4422 | storeValue(rhs.value); |
| 4423 | } |
| 4424 | |
| 4425 | Int::Int(RValue<UInt> rhs) |
| 4426 | { |
| 4427 | storeValue(rhs.value); |
| 4428 | } |
| 4429 | |
| 4430 | Int::Int(const Int &rhs) |
| 4431 | { |
| 4432 | Value *value = rhs.loadValue(); |
| 4433 | storeValue(value); |
| 4434 | } |
| 4435 | |
| 4436 | Int::Int(const Reference<Int> &rhs) |
| 4437 | { |
| 4438 | Value *value = rhs.loadValue(); |
| 4439 | storeValue(value); |
| 4440 | } |
| 4441 | |
| 4442 | Int::Int(const UInt &rhs) |
| 4443 | { |
| 4444 | Value *value = rhs.loadValue(); |
| 4445 | storeValue(value); |
| 4446 | } |
| 4447 | |
| 4448 | Int::Int(const Reference<UInt> &rhs) |
| 4449 | { |
| 4450 | Value *value = rhs.loadValue(); |
| 4451 | storeValue(value); |
| 4452 | } |
| 4453 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4454 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4455 | { |
| 4456 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4457 | } |
| 4458 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4459 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4460 | { |
| 4461 | storeValue(rhs.value); |
| 4462 | |
| 4463 | return rhs; |
| 4464 | } |
| 4465 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4466 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4467 | { |
| 4468 | storeValue(rhs.value); |
| 4469 | |
| 4470 | return RValue<Int>(rhs); |
| 4471 | } |
| 4472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4473 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4474 | { |
| 4475 | Value *value = rhs.loadValue(); |
| 4476 | storeValue(value); |
| 4477 | |
| 4478 | return RValue<Int>(value); |
| 4479 | } |
| 4480 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4481 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4482 | { |
| 4483 | Value *value = rhs.loadValue(); |
| 4484 | storeValue(value); |
| 4485 | |
| 4486 | return RValue<Int>(value); |
| 4487 | } |
| 4488 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4489 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4490 | { |
| 4491 | Value *value = rhs.loadValue(); |
| 4492 | storeValue(value); |
| 4493 | |
| 4494 | return RValue<Int>(value); |
| 4495 | } |
| 4496 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4497 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4498 | { |
| 4499 | Value *value = rhs.loadValue(); |
| 4500 | storeValue(value); |
| 4501 | |
| 4502 | return RValue<Int>(value); |
| 4503 | } |
| 4504 | |
| 4505 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 4506 | { |
| 4507 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4508 | } |
| 4509 | |
| 4510 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 4511 | { |
| 4512 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4513 | } |
| 4514 | |
| 4515 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 4516 | { |
| 4517 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4518 | } |
| 4519 | |
| 4520 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 4521 | { |
| 4522 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4523 | } |
| 4524 | |
| 4525 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 4526 | { |
| 4527 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4528 | } |
| 4529 | |
| 4530 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 4531 | { |
| 4532 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4533 | } |
| 4534 | |
| 4535 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 4536 | { |
| 4537 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4538 | } |
| 4539 | |
| 4540 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 4541 | { |
| 4542 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4543 | } |
| 4544 | |
| 4545 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 4546 | { |
| 4547 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4548 | } |
| 4549 | |
| 4550 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 4551 | { |
| 4552 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4553 | } |
| 4554 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4555 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4556 | { |
| 4557 | return lhs = lhs + rhs; |
| 4558 | } |
| 4559 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4560 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4561 | { |
| 4562 | return lhs = lhs - rhs; |
| 4563 | } |
| 4564 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4565 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4566 | { |
| 4567 | return lhs = lhs * rhs; |
| 4568 | } |
| 4569 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4570 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4571 | { |
| 4572 | return lhs = lhs / rhs; |
| 4573 | } |
| 4574 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4575 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4576 | { |
| 4577 | return lhs = lhs % rhs; |
| 4578 | } |
| 4579 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4580 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4581 | { |
| 4582 | return lhs = lhs & rhs; |
| 4583 | } |
| 4584 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4585 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4586 | { |
| 4587 | return lhs = lhs | rhs; |
| 4588 | } |
| 4589 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4590 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4591 | { |
| 4592 | return lhs = lhs ^ rhs; |
| 4593 | } |
| 4594 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4595 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4596 | { |
| 4597 | return lhs = lhs << rhs; |
| 4598 | } |
| 4599 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4600 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4601 | { |
| 4602 | return lhs = lhs >> rhs; |
| 4603 | } |
| 4604 | |
| 4605 | RValue<Int> operator+(RValue<Int> val) |
| 4606 | { |
| 4607 | return val; |
| 4608 | } |
| 4609 | |
| 4610 | RValue<Int> operator-(RValue<Int> val) |
| 4611 | { |
| 4612 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4613 | } |
| 4614 | |
| 4615 | RValue<Int> operator~(RValue<Int> val) |
| 4616 | { |
| 4617 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4618 | } |
| 4619 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4620 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4621 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4622 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4623 | val += 1; |
| 4624 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4625 | } |
| 4626 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4627 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4628 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4629 | val += 1; |
| 4630 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4631 | } |
| 4632 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4633 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4634 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4635 | RValue<Int> res = val; |
| 4636 | val -= 1; |
| 4637 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4638 | } |
| 4639 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4640 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4641 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4642 | val -= 1; |
| 4643 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4647 | { |
| 4648 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4649 | } |
| 4650 | |
| 4651 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4652 | { |
| 4653 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4654 | } |
| 4655 | |
| 4656 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4657 | { |
| 4658 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4659 | } |
| 4660 | |
| 4661 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4662 | { |
| 4663 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4664 | } |
| 4665 | |
| 4666 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4667 | { |
| 4668 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4669 | } |
| 4670 | |
| 4671 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4672 | { |
| 4673 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4674 | } |
| 4675 | |
| 4676 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4677 | { |
| 4678 | return IfThenElse(x > y, x, y); |
| 4679 | } |
| 4680 | |
| 4681 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4682 | { |
| 4683 | return IfThenElse(x < y, x, y); |
| 4684 | } |
| 4685 | |
| 4686 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4687 | { |
| 4688 | return Min(Max(x, min), max); |
| 4689 | } |
| 4690 | |
| 4691 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4692 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 4693 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4694 | { |
| 4695 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 4696 | return Int((cast + Float(0x00C00000)) - Float(0x00C00000)); |
| 4697 | } |
| 4698 | else |
| 4699 | { |
| 4700 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 4701 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4702 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4703 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4704 | nearbyint->addArg(cast.value); |
| 4705 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4706 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4707 | return RValue<Int>(V(result)); |
| 4708 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | Type *Int::getType() |
| 4712 | { |
| 4713 | return T(Ice::IceType_i32); |
| 4714 | } |
| 4715 | |
| 4716 | Long::Long(RValue<Int> cast) |
| 4717 | { |
| 4718 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4719 | |
| 4720 | storeValue(integer); |
| 4721 | } |
| 4722 | |
| 4723 | Long::Long(RValue<UInt> cast) |
| 4724 | { |
| 4725 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4726 | |
| 4727 | storeValue(integer); |
| 4728 | } |
| 4729 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4730 | Long::Long(RValue<Long> rhs) |
| 4731 | { |
| 4732 | storeValue(rhs.value); |
| 4733 | } |
| 4734 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4735 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4736 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4737 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4738 | } |
| 4739 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4740 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4741 | { |
| 4742 | storeValue(rhs.value); |
| 4743 | |
| 4744 | return rhs; |
| 4745 | } |
| 4746 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4747 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4748 | { |
| 4749 | Value *value = rhs.loadValue(); |
| 4750 | storeValue(value); |
| 4751 | |
| 4752 | return RValue<Long>(value); |
| 4753 | } |
| 4754 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4755 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4756 | { |
| 4757 | Value *value = rhs.loadValue(); |
| 4758 | storeValue(value); |
| 4759 | |
| 4760 | return RValue<Long>(value); |
| 4761 | } |
| 4762 | |
| 4763 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4764 | { |
| 4765 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4766 | } |
| 4767 | |
| 4768 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4769 | { |
| 4770 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4771 | } |
| 4772 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4773 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4774 | { |
| 4775 | return lhs = lhs + rhs; |
| 4776 | } |
| 4777 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4778 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4779 | { |
| 4780 | return lhs = lhs - rhs; |
| 4781 | } |
| 4782 | |
| 4783 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4784 | { |
| 4785 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4786 | } |
| 4787 | |
| 4788 | Type *Long::getType() |
| 4789 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4790 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4791 | } |
| 4792 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4793 | UInt::UInt(Argument<UInt> argument) |
| 4794 | { |
| 4795 | storeValue(argument.value); |
| 4796 | } |
| 4797 | |
| 4798 | UInt::UInt(RValue<UShort> cast) |
| 4799 | { |
| 4800 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4801 | |
| 4802 | storeValue(integer); |
| 4803 | } |
| 4804 | |
| 4805 | UInt::UInt(RValue<Long> cast) |
| 4806 | { |
| 4807 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4808 | |
| 4809 | storeValue(integer); |
| 4810 | } |
| 4811 | |
| 4812 | UInt::UInt(RValue<Float> cast) |
| 4813 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4814 | // Smallest positive value representable in UInt, but not in Int |
| 4815 | const unsigned int ustart = 0x80000000u; |
| 4816 | const float ustartf = float(ustart); |
| 4817 | |
| 4818 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4819 | storeValue((~(As<Int>(cast) >> 31) & |
| 4820 | // Check if the value can be represented as an Int |
| 4821 | IfThenElse(cast >= ustartf, |
| 4822 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4823 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4824 | // Otherwise, just convert normally |
| 4825 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4826 | } |
| 4827 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4828 | UInt::UInt(int x) |
| 4829 | { |
| 4830 | storeValue(Nucleus::createConstantInt(x)); |
| 4831 | } |
| 4832 | |
| 4833 | UInt::UInt(unsigned int x) |
| 4834 | { |
| 4835 | storeValue(Nucleus::createConstantInt(x)); |
| 4836 | } |
| 4837 | |
| 4838 | UInt::UInt(RValue<UInt> rhs) |
| 4839 | { |
| 4840 | storeValue(rhs.value); |
| 4841 | } |
| 4842 | |
| 4843 | UInt::UInt(RValue<Int> rhs) |
| 4844 | { |
| 4845 | storeValue(rhs.value); |
| 4846 | } |
| 4847 | |
| 4848 | UInt::UInt(const UInt &rhs) |
| 4849 | { |
| 4850 | Value *value = rhs.loadValue(); |
| 4851 | storeValue(value); |
| 4852 | } |
| 4853 | |
| 4854 | UInt::UInt(const Reference<UInt> &rhs) |
| 4855 | { |
| 4856 | Value *value = rhs.loadValue(); |
| 4857 | storeValue(value); |
| 4858 | } |
| 4859 | |
| 4860 | UInt::UInt(const Int &rhs) |
| 4861 | { |
| 4862 | Value *value = rhs.loadValue(); |
| 4863 | storeValue(value); |
| 4864 | } |
| 4865 | |
| 4866 | UInt::UInt(const Reference<Int> &rhs) |
| 4867 | { |
| 4868 | Value *value = rhs.loadValue(); |
| 4869 | storeValue(value); |
| 4870 | } |
| 4871 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4872 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4873 | { |
| 4874 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4875 | } |
| 4876 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4877 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4878 | { |
| 4879 | storeValue(rhs.value); |
| 4880 | |
| 4881 | return rhs; |
| 4882 | } |
| 4883 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4884 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4885 | { |
| 4886 | storeValue(rhs.value); |
| 4887 | |
| 4888 | return RValue<UInt>(rhs); |
| 4889 | } |
| 4890 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4891 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4892 | { |
| 4893 | Value *value = rhs.loadValue(); |
| 4894 | storeValue(value); |
| 4895 | |
| 4896 | return RValue<UInt>(value); |
| 4897 | } |
| 4898 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4899 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4900 | { |
| 4901 | Value *value = rhs.loadValue(); |
| 4902 | storeValue(value); |
| 4903 | |
| 4904 | return RValue<UInt>(value); |
| 4905 | } |
| 4906 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4907 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4908 | { |
| 4909 | Value *value = rhs.loadValue(); |
| 4910 | storeValue(value); |
| 4911 | |
| 4912 | return RValue<UInt>(value); |
| 4913 | } |
| 4914 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4915 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4916 | { |
| 4917 | Value *value = rhs.loadValue(); |
| 4918 | storeValue(value); |
| 4919 | |
| 4920 | return RValue<UInt>(value); |
| 4921 | } |
| 4922 | |
| 4923 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4924 | { |
| 4925 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4926 | } |
| 4927 | |
| 4928 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4929 | { |
| 4930 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4931 | } |
| 4932 | |
| 4933 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4934 | { |
| 4935 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4936 | } |
| 4937 | |
| 4938 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4939 | { |
| 4940 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4941 | } |
| 4942 | |
| 4943 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4944 | { |
| 4945 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4946 | } |
| 4947 | |
| 4948 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4949 | { |
| 4950 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4951 | } |
| 4952 | |
| 4953 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4954 | { |
| 4955 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4956 | } |
| 4957 | |
| 4958 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4959 | { |
| 4960 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4961 | } |
| 4962 | |
| 4963 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4964 | { |
| 4965 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4966 | } |
| 4967 | |
| 4968 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4969 | { |
| 4970 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4971 | } |
| 4972 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4973 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4974 | { |
| 4975 | return lhs = lhs + rhs; |
| 4976 | } |
| 4977 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4978 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4979 | { |
| 4980 | return lhs = lhs - rhs; |
| 4981 | } |
| 4982 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4983 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4984 | { |
| 4985 | return lhs = lhs * rhs; |
| 4986 | } |
| 4987 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4988 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4989 | { |
| 4990 | return lhs = lhs / rhs; |
| 4991 | } |
| 4992 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4993 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4994 | { |
| 4995 | return lhs = lhs % rhs; |
| 4996 | } |
| 4997 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4998 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4999 | { |
| 5000 | return lhs = lhs & rhs; |
| 5001 | } |
| 5002 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5003 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5004 | { |
| 5005 | return lhs = lhs | rhs; |
| 5006 | } |
| 5007 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5008 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5009 | { |
| 5010 | return lhs = lhs ^ rhs; |
| 5011 | } |
| 5012 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5013 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5014 | { |
| 5015 | return lhs = lhs << rhs; |
| 5016 | } |
| 5017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5018 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5019 | { |
| 5020 | return lhs = lhs >> rhs; |
| 5021 | } |
| 5022 | |
| 5023 | RValue<UInt> operator+(RValue<UInt> val) |
| 5024 | { |
| 5025 | return val; |
| 5026 | } |
| 5027 | |
| 5028 | RValue<UInt> operator-(RValue<UInt> val) |
| 5029 | { |
| 5030 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 5031 | } |
| 5032 | |
| 5033 | RValue<UInt> operator~(RValue<UInt> val) |
| 5034 | { |
| 5035 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 5036 | } |
| 5037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5038 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5039 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5040 | RValue<UInt> res = val; |
| 5041 | val += 1; |
| 5042 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5043 | } |
| 5044 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5045 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5046 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5047 | val += 1; |
| 5048 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5049 | } |
| 5050 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5051 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5052 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5053 | RValue<UInt> res = val; |
| 5054 | val -= 1; |
| 5055 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5056 | } |
| 5057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5058 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5059 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5060 | val -= 1; |
| 5061 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 5065 | { |
| 5066 | return IfThenElse(x > y, x, y); |
| 5067 | } |
| 5068 | |
| 5069 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 5070 | { |
| 5071 | return IfThenElse(x < y, x, y); |
| 5072 | } |
| 5073 | |
| 5074 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 5075 | { |
| 5076 | return Min(Max(x, min), max); |
| 5077 | } |
| 5078 | |
| 5079 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5080 | { |
| 5081 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 5082 | } |
| 5083 | |
| 5084 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5085 | { |
| 5086 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 5087 | } |
| 5088 | |
| 5089 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5090 | { |
| 5091 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 5092 | } |
| 5093 | |
| 5094 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5095 | { |
| 5096 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 5097 | } |
| 5098 | |
| 5099 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5100 | { |
| 5101 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 5102 | } |
| 5103 | |
| 5104 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5105 | { |
| 5106 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 5107 | } |
| 5108 | |
| 5109 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 5110 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 5111 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5112 | // } |
| 5113 | |
| 5114 | Type *UInt::getType() |
| 5115 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5116 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | // Int2::Int2(RValue<Int> cast) |
| 5120 | // { |
| 5121 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 5122 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 5123 | // |
| 5124 | // Constant *shuffle[2]; |
| 5125 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 5126 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 5127 | // |
| 5128 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 5129 | // |
| 5130 | // storeValue(replicate); |
| 5131 | // } |
| 5132 | |
| 5133 | Int2::Int2(RValue<Int4> cast) |
| 5134 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5135 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5136 | } |
| 5137 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5138 | Int2::Int2(int x, int y) |
| 5139 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5140 | int64_t constantVector[2] = {x, y}; |
| 5141 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | Int2::Int2(RValue<Int2> rhs) |
| 5145 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5146 | storeValue(rhs.value); |
| 5147 | } |
| 5148 | |
| 5149 | Int2::Int2(const Int2 &rhs) |
| 5150 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5151 | Value *value = rhs.loadValue(); |
| 5152 | storeValue(value); |
| 5153 | } |
| 5154 | |
| 5155 | Int2::Int2(const Reference<Int2> &rhs) |
| 5156 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5157 | Value *value = rhs.loadValue(); |
| 5158 | storeValue(value); |
| 5159 | } |
| 5160 | |
| 5161 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 5162 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5163 | int shuffle[4] = {0, 4, 1, 5}; |
| 5164 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 5165 | |
| 5166 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5167 | } |
| 5168 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5169 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5170 | { |
| 5171 | storeValue(rhs.value); |
| 5172 | |
| 5173 | return rhs; |
| 5174 | } |
| 5175 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5176 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5177 | { |
| 5178 | Value *value = rhs.loadValue(); |
| 5179 | storeValue(value); |
| 5180 | |
| 5181 | return RValue<Int2>(value); |
| 5182 | } |
| 5183 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5184 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5185 | { |
| 5186 | Value *value = rhs.loadValue(); |
| 5187 | storeValue(value); |
| 5188 | |
| 5189 | return RValue<Int2>(value); |
| 5190 | } |
| 5191 | |
| 5192 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5193 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5194 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5198 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5199 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5203 | // { |
| 5204 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5205 | // } |
| 5206 | |
| 5207 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5208 | // { |
| 5209 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5210 | // } |
| 5211 | |
| 5212 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5213 | // { |
| 5214 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5215 | // } |
| 5216 | |
| 5217 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5218 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5219 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5223 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5224 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5228 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5229 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 5233 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5234 | if(emulateIntrinsics) |
| 5235 | { |
| 5236 | Int2 result; |
| 5237 | result = Insert(result, Extract(lhs, 0) << Int(rhs), 0); |
| 5238 | result = Insert(result, Extract(lhs, 1) << Int(rhs), 1); |
| 5239 | |
| 5240 | return result; |
| 5241 | } |
| 5242 | else |
| 5243 | { |
| 5244 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5245 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 5249 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5250 | if(emulateIntrinsics) |
| 5251 | { |
| 5252 | Int2 result; |
| 5253 | result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0); |
| 5254 | result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1); |
| 5255 | |
| 5256 | return result; |
| 5257 | } |
| 5258 | else |
| 5259 | { |
| 5260 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5261 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5262 | } |
| 5263 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5264 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5265 | { |
| 5266 | return lhs = lhs + rhs; |
| 5267 | } |
| 5268 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5269 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5270 | { |
| 5271 | return lhs = lhs - rhs; |
| 5272 | } |
| 5273 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5274 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5275 | // { |
| 5276 | // return lhs = lhs * rhs; |
| 5277 | // } |
| 5278 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5279 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5280 | // { |
| 5281 | // return lhs = lhs / rhs; |
| 5282 | // } |
| 5283 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5284 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5285 | // { |
| 5286 | // return lhs = lhs % rhs; |
| 5287 | // } |
| 5288 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5289 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5290 | { |
| 5291 | return lhs = lhs & rhs; |
| 5292 | } |
| 5293 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5294 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5295 | { |
| 5296 | return lhs = lhs | rhs; |
| 5297 | } |
| 5298 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5299 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5300 | { |
| 5301 | return lhs = lhs ^ rhs; |
| 5302 | } |
| 5303 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5304 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5305 | { |
| 5306 | return lhs = lhs << rhs; |
| 5307 | } |
| 5308 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5309 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5310 | { |
| 5311 | return lhs = lhs >> rhs; |
| 5312 | } |
| 5313 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5314 | // RValue<Int2> operator+(RValue<Int2> val) |
| 5315 | // { |
| 5316 | // return val; |
| 5317 | // } |
| 5318 | |
| 5319 | // RValue<Int2> operator-(RValue<Int2> val) |
| 5320 | // { |
| 5321 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 5322 | // } |
| 5323 | |
| 5324 | RValue<Int2> operator~(RValue<Int2> val) |
| 5325 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 5326 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5327 | } |
| 5328 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 5329 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5330 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5331 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 5332 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5333 | } |
| 5334 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 5335 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5336 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5337 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5338 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 5339 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 5343 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 5344 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 5348 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 5349 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | Type *Int2::getType() |
| 5353 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5354 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5355 | } |
| 5356 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5357 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 5358 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5359 | int64_t constantVector[2] = {x, y}; |
| 5360 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | UInt2::UInt2(RValue<UInt2> rhs) |
| 5364 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5365 | storeValue(rhs.value); |
| 5366 | } |
| 5367 | |
| 5368 | UInt2::UInt2(const UInt2 &rhs) |
| 5369 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5370 | Value *value = rhs.loadValue(); |
| 5371 | storeValue(value); |
| 5372 | } |
| 5373 | |
| 5374 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 5375 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5376 | Value *value = rhs.loadValue(); |
| 5377 | storeValue(value); |
| 5378 | } |
| 5379 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5380 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5381 | { |
| 5382 | storeValue(rhs.value); |
| 5383 | |
| 5384 | return rhs; |
| 5385 | } |
| 5386 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5387 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5388 | { |
| 5389 | Value *value = rhs.loadValue(); |
| 5390 | storeValue(value); |
| 5391 | |
| 5392 | return RValue<UInt2>(value); |
| 5393 | } |
| 5394 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5395 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5396 | { |
| 5397 | Value *value = rhs.loadValue(); |
| 5398 | storeValue(value); |
| 5399 | |
| 5400 | return RValue<UInt2>(value); |
| 5401 | } |
| 5402 | |
| 5403 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5404 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5405 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5406 | } |
| 5407 | |
| 5408 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5409 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5410 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5414 | // { |
| 5415 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5416 | // } |
| 5417 | |
| 5418 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5419 | // { |
| 5420 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5421 | // } |
| 5422 | |
| 5423 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5424 | // { |
| 5425 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5426 | // } |
| 5427 | |
| 5428 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5429 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5430 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5434 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5435 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5436 | } |
| 5437 | |
| 5438 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5439 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5440 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5441 | } |
| 5442 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5443 | RValue<UInt> Extract(RValue<UInt2> val, int i) |
| 5444 | { |
| 5445 | return RValue<UInt>(Nucleus::createExtractElement(val.value, UInt::getType(), i)); |
| 5446 | } |
| 5447 | |
| 5448 | RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i) |
| 5449 | { |
| 5450 | return RValue<UInt2>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 5451 | } |
| 5452 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5453 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 5454 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5455 | if(emulateIntrinsics) |
| 5456 | { |
| 5457 | UInt2 result; |
| 5458 | result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0); |
| 5459 | result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1); |
| 5460 | |
| 5461 | return result; |
| 5462 | } |
| 5463 | else |
| 5464 | { |
| 5465 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5466 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 5470 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5471 | if(emulateIntrinsics) |
| 5472 | { |
| 5473 | UInt2 result; |
| 5474 | result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0); |
| 5475 | result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1); |
| 5476 | |
| 5477 | return result; |
| 5478 | } |
| 5479 | else |
| 5480 | { |
| 5481 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5482 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5483 | } |
| 5484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5485 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5486 | { |
| 5487 | return lhs = lhs + rhs; |
| 5488 | } |
| 5489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5490 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5491 | { |
| 5492 | return lhs = lhs - rhs; |
| 5493 | } |
| 5494 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5495 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5496 | // { |
| 5497 | // return lhs = lhs * rhs; |
| 5498 | // } |
| 5499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5500 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5501 | // { |
| 5502 | // return lhs = lhs / rhs; |
| 5503 | // } |
| 5504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5505 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5506 | // { |
| 5507 | // return lhs = lhs % rhs; |
| 5508 | // } |
| 5509 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5510 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5511 | { |
| 5512 | return lhs = lhs & rhs; |
| 5513 | } |
| 5514 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5515 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5516 | { |
| 5517 | return lhs = lhs | rhs; |
| 5518 | } |
| 5519 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5520 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5521 | { |
| 5522 | return lhs = lhs ^ rhs; |
| 5523 | } |
| 5524 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5525 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5526 | { |
| 5527 | return lhs = lhs << rhs; |
| 5528 | } |
| 5529 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5530 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5531 | { |
| 5532 | return lhs = lhs >> rhs; |
| 5533 | } |
| 5534 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5535 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 5536 | // { |
| 5537 | // return val; |
| 5538 | // } |
| 5539 | |
| 5540 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 5541 | // { |
| 5542 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 5543 | // } |
| 5544 | |
| 5545 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 5546 | { |
| 5547 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 5548 | } |
| 5549 | |
| 5550 | Type *UInt2::getType() |
| 5551 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5552 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5553 | } |
| 5554 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5555 | Int4::Int4() : XYZW(this) |
| 5556 | { |
| 5557 | } |
| 5558 | |
| 5559 | Int4::Int4(RValue<Byte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5560 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5561 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5562 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5563 | |
| 5564 | Value *e; |
| 5565 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 5566 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5567 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 5568 | |
| 5569 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5570 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5571 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 5572 | |
| 5573 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5574 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5575 | } |
| 5576 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5577 | Int4::Int4(RValue<SByte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5578 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5579 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5580 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5581 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5582 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 5583 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5584 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 5585 | |
| 5586 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5587 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5588 | Value *e = Nucleus::createShuffleVector(d, d, swizzle2); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5589 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5590 | *this = As<Int4>(e) >> 24; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5591 | } |
| 5592 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5593 | Int4::Int4(RValue<Float4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5594 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5595 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 5596 | |
| 5597 | storeValue(xyzw); |
| 5598 | } |
| 5599 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5600 | Int4::Int4(RValue<Short4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5601 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5602 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5603 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5604 | |
| 5605 | *this = As<Int4>(c) >> 16; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5606 | } |
| 5607 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5608 | Int4::Int4(RValue<UShort4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5609 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5610 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5611 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5612 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5613 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5614 | } |
| 5615 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5616 | Int4::Int4(int xyzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5617 | { |
| 5618 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5619 | } |
| 5620 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5621 | Int4::Int4(int x, int yzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5622 | { |
| 5623 | constant(x, yzw, yzw, yzw); |
| 5624 | } |
| 5625 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5626 | Int4::Int4(int x, int y, int zw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5627 | { |
| 5628 | constant(x, y, zw, zw); |
| 5629 | } |
| 5630 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5631 | Int4::Int4(int x, int y, int z, int w) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5632 | { |
| 5633 | constant(x, y, z, w); |
| 5634 | } |
| 5635 | |
| 5636 | void Int4::constant(int x, int y, int z, int w) |
| 5637 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5638 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5639 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5640 | } |
| 5641 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5642 | Int4::Int4(RValue<Int4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5643 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5644 | storeValue(rhs.value); |
| 5645 | } |
| 5646 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5647 | Int4::Int4(const Int4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5648 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5649 | Value *value = rhs.loadValue(); |
| 5650 | storeValue(value); |
| 5651 | } |
| 5652 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5653 | Int4::Int4(const Reference<Int4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5654 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5655 | Value *value = rhs.loadValue(); |
| 5656 | storeValue(value); |
| 5657 | } |
| 5658 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5659 | Int4::Int4(RValue<UInt4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5660 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5661 | storeValue(rhs.value); |
| 5662 | } |
| 5663 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5664 | Int4::Int4(const UInt4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5665 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5666 | Value *value = rhs.loadValue(); |
| 5667 | storeValue(value); |
| 5668 | } |
| 5669 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5670 | Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5671 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5672 | Value *value = rhs.loadValue(); |
| 5673 | storeValue(value); |
| 5674 | } |
| 5675 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5676 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5677 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5678 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5679 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5680 | |
| 5681 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5682 | } |
| 5683 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5684 | Int4::Int4(RValue<Int> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5685 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5686 | Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5687 | |
| 5688 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5689 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5690 | |
| 5691 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5692 | } |
| 5693 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5694 | Int4::Int4(const Int &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5695 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5696 | *this = RValue<Int>(rhs.loadValue()); |
| 5697 | } |
| 5698 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5699 | Int4::Int4(const Reference<Int> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5700 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5701 | *this = RValue<Int>(rhs.loadValue()); |
| 5702 | } |
| 5703 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5704 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5705 | { |
| 5706 | storeValue(rhs.value); |
| 5707 | |
| 5708 | return rhs; |
| 5709 | } |
| 5710 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5711 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5712 | { |
| 5713 | Value *value = rhs.loadValue(); |
| 5714 | storeValue(value); |
| 5715 | |
| 5716 | return RValue<Int4>(value); |
| 5717 | } |
| 5718 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5719 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5720 | { |
| 5721 | Value *value = rhs.loadValue(); |
| 5722 | storeValue(value); |
| 5723 | |
| 5724 | return RValue<Int4>(value); |
| 5725 | } |
| 5726 | |
| 5727 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5728 | { |
| 5729 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5730 | } |
| 5731 | |
| 5732 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5733 | { |
| 5734 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5735 | } |
| 5736 | |
| 5737 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5738 | { |
| 5739 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5740 | } |
| 5741 | |
| 5742 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5743 | { |
| 5744 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5745 | } |
| 5746 | |
| 5747 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5748 | { |
| 5749 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5750 | } |
| 5751 | |
| 5752 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5753 | { |
| 5754 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5755 | } |
| 5756 | |
| 5757 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5758 | { |
| 5759 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5760 | } |
| 5761 | |
| 5762 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5763 | { |
| 5764 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5765 | } |
| 5766 | |
| 5767 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5768 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5769 | if(emulateIntrinsics) |
| 5770 | { |
| 5771 | Int4 result; |
| 5772 | result = Insert(result, Extract(lhs, 0) << Int(rhs), 0); |
| 5773 | result = Insert(result, Extract(lhs, 1) << Int(rhs), 1); |
| 5774 | result = Insert(result, Extract(lhs, 2) << Int(rhs), 2); |
| 5775 | result = Insert(result, Extract(lhs, 3) << Int(rhs), 3); |
| 5776 | |
| 5777 | return result; |
| 5778 | } |
| 5779 | else |
| 5780 | { |
| 5781 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5782 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5786 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5787 | if(emulateIntrinsics) |
| 5788 | { |
| 5789 | Int4 result; |
| 5790 | result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0); |
| 5791 | result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1); |
| 5792 | result = Insert(result, Extract(lhs, 2) >> Int(rhs), 2); |
| 5793 | result = Insert(result, Extract(lhs, 3) >> Int(rhs), 3); |
| 5794 | |
| 5795 | return result; |
| 5796 | } |
| 5797 | else |
| 5798 | { |
| 5799 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5800 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5804 | { |
| 5805 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5806 | } |
| 5807 | |
| 5808 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5809 | { |
| 5810 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5811 | } |
| 5812 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5813 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5814 | { |
| 5815 | return lhs = lhs + rhs; |
| 5816 | } |
| 5817 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5818 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5819 | { |
| 5820 | return lhs = lhs - rhs; |
| 5821 | } |
| 5822 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5823 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5824 | { |
| 5825 | return lhs = lhs * rhs; |
| 5826 | } |
| 5827 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5828 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5829 | // { |
| 5830 | // return lhs = lhs / rhs; |
| 5831 | // } |
| 5832 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5833 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5834 | // { |
| 5835 | // return lhs = lhs % rhs; |
| 5836 | // } |
| 5837 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5838 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5839 | { |
| 5840 | return lhs = lhs & rhs; |
| 5841 | } |
| 5842 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5843 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5844 | { |
| 5845 | return lhs = lhs | rhs; |
| 5846 | } |
| 5847 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5848 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5849 | { |
| 5850 | return lhs = lhs ^ rhs; |
| 5851 | } |
| 5852 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5853 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5854 | { |
| 5855 | return lhs = lhs << rhs; |
| 5856 | } |
| 5857 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5858 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5859 | { |
| 5860 | return lhs = lhs >> rhs; |
| 5861 | } |
| 5862 | |
| 5863 | RValue<Int4> operator+(RValue<Int4> val) |
| 5864 | { |
| 5865 | return val; |
| 5866 | } |
| 5867 | |
| 5868 | RValue<Int4> operator-(RValue<Int4> val) |
| 5869 | { |
| 5870 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5871 | } |
| 5872 | |
| 5873 | RValue<Int4> operator~(RValue<Int4> val) |
| 5874 | { |
| 5875 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5876 | } |
| 5877 | |
| 5878 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5879 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5880 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5881 | } |
| 5882 | |
| 5883 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5884 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5885 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5889 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5890 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5894 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5895 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5899 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5900 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5904 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5905 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5909 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5910 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5911 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5912 | ::basicBlock->appendInst(cmp); |
| 5913 | |
| 5914 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5915 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5916 | ::basicBlock->appendInst(select); |
| 5917 | |
| 5918 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5919 | } |
| 5920 | |
| 5921 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5922 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5923 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5924 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5925 | ::basicBlock->appendInst(cmp); |
| 5926 | |
| 5927 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5928 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5929 | ::basicBlock->appendInst(select); |
| 5930 | |
| 5931 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5935 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 5936 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5937 | { |
| 5938 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 5939 | return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000)); |
| 5940 | } |
| 5941 | else |
| 5942 | { |
| 5943 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5944 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5945 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5946 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5947 | nearbyint->addArg(cast.value); |
| 5948 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5949 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5950 | return RValue<Int4>(V(result)); |
| 5951 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5952 | } |
| 5953 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 5954 | RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5955 | { |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5956 | if(emulateIntrinsics) |
| 5957 | { |
| 5958 | Short8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 5959 | result = Insert(result, SaturateSigned(Extract(x, 0)), 0); |
| 5960 | result = Insert(result, SaturateSigned(Extract(x, 1)), 1); |
| 5961 | result = Insert(result, SaturateSigned(Extract(x, 2)), 2); |
| 5962 | result = Insert(result, SaturateSigned(Extract(x, 3)), 3); |
| 5963 | result = Insert(result, SaturateSigned(Extract(y, 0)), 4); |
| 5964 | result = Insert(result, SaturateSigned(Extract(y, 1)), 5); |
| 5965 | result = Insert(result, SaturateSigned(Extract(y, 2)), 6); |
| 5966 | result = Insert(result, SaturateSigned(Extract(y, 3)), 7); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5967 | |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5968 | return result; |
| 5969 | } |
| 5970 | else |
| 5971 | { |
| 5972 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5973 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5974 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5975 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5976 | pack->addArg(x.value); |
| 5977 | pack->addArg(y.value); |
| 5978 | ::basicBlock->appendInst(pack); |
| 5979 | |
| 5980 | return RValue<Short8>(V(result)); |
| 5981 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5982 | } |
| 5983 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 5984 | RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y) |
| 5985 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 5986 | if(emulateIntrinsics || !(CPUID::SSE4_1 || CPUID::ARM)) |
| 5987 | { |
| 5988 | RValue<Int4> sx = As<Int4>(x); |
| 5989 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 5990 | |
| 5991 | RValue<Int4> sy = As<Int4>(y); |
| 5992 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 5993 | |
| 5994 | return As<UShort8>(PackSigned(bx, by) + Short8(0x8000u)); |
| 5995 | } |
| 5996 | else |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 5997 | { |
| 5998 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5999 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6000 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6001 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6002 | pack->addArg(x.value); |
| 6003 | pack->addArg(y.value); |
| 6004 | ::basicBlock->appendInst(pack); |
| 6005 | |
| 6006 | return RValue<UShort8>(V(result)); |
| 6007 | } |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6008 | } |
| 6009 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6010 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 6011 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6012 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 6016 | { |
| 6017 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 6018 | } |
| 6019 | |
| 6020 | RValue<Int> SignMask(RValue<Int4> x) |
| 6021 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6022 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6023 | { |
| 6024 | Int4 xx = (x >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008); |
| 6025 | return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3); |
| 6026 | } |
| 6027 | else |
| 6028 | { |
| 6029 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6030 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6031 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6032 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6033 | movmsk->addArg(x.value); |
| 6034 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6035 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6036 | return RValue<Int>(V(result)); |
| 6037 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 6041 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6042 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | Type *Int4::getType() |
| 6046 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 6047 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6048 | } |
| 6049 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6050 | UInt4::UInt4() : XYZW(this) |
| 6051 | { |
| 6052 | } |
| 6053 | |
| 6054 | UInt4::UInt4(RValue<Float4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6055 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 6056 | // Smallest positive value representable in UInt, but not in Int |
| 6057 | const unsigned int ustart = 0x80000000u; |
| 6058 | const float ustartf = float(ustart); |
| 6059 | |
| 6060 | // Check if the value can be represented as an Int |
| 6061 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 6062 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 6063 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 6064 | // Otherwise, just convert normally |
| 6065 | (~uiValue & Int4(cast)); |
| 6066 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 6067 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6068 | } |
| 6069 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6070 | UInt4::UInt4(int xyzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6071 | { |
| 6072 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6073 | } |
| 6074 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6075 | UInt4::UInt4(int x, int yzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6076 | { |
| 6077 | constant(x, yzw, yzw, yzw); |
| 6078 | } |
| 6079 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6080 | UInt4::UInt4(int x, int y, int zw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6081 | { |
| 6082 | constant(x, y, zw, zw); |
| 6083 | } |
| 6084 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6085 | UInt4::UInt4(int x, int y, int z, int w) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6086 | { |
| 6087 | constant(x, y, z, w); |
| 6088 | } |
| 6089 | |
| 6090 | void UInt4::constant(int x, int y, int z, int w) |
| 6091 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6092 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6093 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6094 | } |
| 6095 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6096 | UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6097 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6098 | storeValue(rhs.value); |
| 6099 | } |
| 6100 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6101 | UInt4::UInt4(const UInt4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6102 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6103 | Value *value = rhs.loadValue(); |
| 6104 | storeValue(value); |
| 6105 | } |
| 6106 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6107 | UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6108 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6109 | Value *value = rhs.loadValue(); |
| 6110 | storeValue(value); |
| 6111 | } |
| 6112 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6113 | UInt4::UInt4(RValue<Int4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6114 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6115 | storeValue(rhs.value); |
| 6116 | } |
| 6117 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6118 | UInt4::UInt4(const Int4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6119 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6120 | Value *value = rhs.loadValue(); |
| 6121 | storeValue(value); |
| 6122 | } |
| 6123 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6124 | UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6125 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6126 | Value *value = rhs.loadValue(); |
| 6127 | storeValue(value); |
| 6128 | } |
| 6129 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6130 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6131 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 6132 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 6133 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 6134 | |
| 6135 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6136 | } |
| 6137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6138 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6139 | { |
| 6140 | storeValue(rhs.value); |
| 6141 | |
| 6142 | return rhs; |
| 6143 | } |
| 6144 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6145 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6146 | { |
| 6147 | Value *value = rhs.loadValue(); |
| 6148 | storeValue(value); |
| 6149 | |
| 6150 | return RValue<UInt4>(value); |
| 6151 | } |
| 6152 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6153 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6154 | { |
| 6155 | Value *value = rhs.loadValue(); |
| 6156 | storeValue(value); |
| 6157 | |
| 6158 | return RValue<UInt4>(value); |
| 6159 | } |
| 6160 | |
| 6161 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6162 | { |
| 6163 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 6164 | } |
| 6165 | |
| 6166 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6167 | { |
| 6168 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 6169 | } |
| 6170 | |
| 6171 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6172 | { |
| 6173 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 6174 | } |
| 6175 | |
| 6176 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6177 | { |
| 6178 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 6179 | } |
| 6180 | |
| 6181 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6182 | { |
| 6183 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 6184 | } |
| 6185 | |
| 6186 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6187 | { |
| 6188 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 6189 | } |
| 6190 | |
| 6191 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6192 | { |
| 6193 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 6194 | } |
| 6195 | |
| 6196 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6197 | { |
| 6198 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 6199 | } |
| 6200 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6201 | RValue<UInt> Extract(RValue<UInt4> x, int i) |
| 6202 | { |
| 6203 | return RValue<UInt>(Nucleus::createExtractElement(x.value, UInt::getType(), i)); |
| 6204 | } |
| 6205 | |
| 6206 | RValue<UInt4> Insert(RValue<UInt4> x, RValue<UInt> element, int i) |
| 6207 | { |
| 6208 | return RValue<UInt4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 6209 | } |
| 6210 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6211 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 6212 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6213 | if(emulateIntrinsics) |
| 6214 | { |
| 6215 | UInt4 result; |
| 6216 | result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0); |
| 6217 | result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1); |
| 6218 | result = Insert(result, Extract(lhs, 2) << UInt(rhs), 2); |
| 6219 | result = Insert(result, Extract(lhs, 3) << UInt(rhs), 3); |
| 6220 | |
| 6221 | return result; |
| 6222 | } |
| 6223 | else |
| 6224 | { |
| 6225 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 6226 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 6230 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6231 | if(emulateIntrinsics) |
| 6232 | { |
| 6233 | UInt4 result; |
| 6234 | result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0); |
| 6235 | result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1); |
| 6236 | result = Insert(result, Extract(lhs, 2) >> UInt(rhs), 2); |
| 6237 | result = Insert(result, Extract(lhs, 3) >> UInt(rhs), 3); |
| 6238 | |
| 6239 | return result; |
| 6240 | } |
| 6241 | else |
| 6242 | { |
| 6243 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 6244 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6248 | { |
| 6249 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 6250 | } |
| 6251 | |
| 6252 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6253 | { |
| 6254 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 6255 | } |
| 6256 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6257 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6258 | { |
| 6259 | return lhs = lhs + rhs; |
| 6260 | } |
| 6261 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6262 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6263 | { |
| 6264 | return lhs = lhs - rhs; |
| 6265 | } |
| 6266 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6267 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6268 | { |
| 6269 | return lhs = lhs * rhs; |
| 6270 | } |
| 6271 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6272 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6273 | // { |
| 6274 | // return lhs = lhs / rhs; |
| 6275 | // } |
| 6276 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6277 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6278 | // { |
| 6279 | // return lhs = lhs % rhs; |
| 6280 | // } |
| 6281 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6282 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6283 | { |
| 6284 | return lhs = lhs & rhs; |
| 6285 | } |
| 6286 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6287 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6288 | { |
| 6289 | return lhs = lhs | rhs; |
| 6290 | } |
| 6291 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6292 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6293 | { |
| 6294 | return lhs = lhs ^ rhs; |
| 6295 | } |
| 6296 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6297 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6298 | { |
| 6299 | return lhs = lhs << rhs; |
| 6300 | } |
| 6301 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6302 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6303 | { |
| 6304 | return lhs = lhs >> rhs; |
| 6305 | } |
| 6306 | |
| 6307 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 6308 | { |
| 6309 | return val; |
| 6310 | } |
| 6311 | |
| 6312 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 6313 | { |
| 6314 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 6315 | } |
| 6316 | |
| 6317 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 6318 | { |
| 6319 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 6320 | } |
| 6321 | |
| 6322 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6323 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6324 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6328 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6329 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6333 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6334 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6338 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6339 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6343 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6344 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6348 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6349 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 6353 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6354 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6355 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 6356 | ::basicBlock->appendInst(cmp); |
| 6357 | |
| 6358 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6359 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6360 | ::basicBlock->appendInst(select); |
| 6361 | |
| 6362 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 6366 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6367 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6368 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 6369 | ::basicBlock->appendInst(cmp); |
| 6370 | |
| 6371 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6372 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6373 | ::basicBlock->appendInst(select); |
| 6374 | |
| 6375 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6376 | } |
| 6377 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6378 | Type *UInt4::getType() |
| 6379 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 6380 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | Float::Float(RValue<Int> cast) |
| 6384 | { |
| 6385 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 6386 | |
| 6387 | storeValue(integer); |
| 6388 | } |
| 6389 | |
Alexis Hetu | cfd9632 | 2017-07-24 14:44:33 -0400 | [diff] [blame] | 6390 | Float::Float(RValue<UInt> cast) |
| 6391 | { |
| 6392 | RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) + |
| 6393 | As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u))); |
| 6394 | |
| 6395 | storeValue(result.value); |
| 6396 | } |
| 6397 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6398 | Float::Float(float x) |
| 6399 | { |
| 6400 | storeValue(Nucleus::createConstantFloat(x)); |
| 6401 | } |
| 6402 | |
| 6403 | Float::Float(RValue<Float> rhs) |
| 6404 | { |
| 6405 | storeValue(rhs.value); |
| 6406 | } |
| 6407 | |
| 6408 | Float::Float(const Float &rhs) |
| 6409 | { |
| 6410 | Value *value = rhs.loadValue(); |
| 6411 | storeValue(value); |
| 6412 | } |
| 6413 | |
| 6414 | Float::Float(const Reference<Float> &rhs) |
| 6415 | { |
| 6416 | Value *value = rhs.loadValue(); |
| 6417 | storeValue(value); |
| 6418 | } |
| 6419 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6420 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6421 | { |
| 6422 | storeValue(rhs.value); |
| 6423 | |
| 6424 | return rhs; |
| 6425 | } |
| 6426 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6427 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6428 | { |
| 6429 | Value *value = rhs.loadValue(); |
| 6430 | storeValue(value); |
| 6431 | |
| 6432 | return RValue<Float>(value); |
| 6433 | } |
| 6434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6435 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6436 | { |
| 6437 | Value *value = rhs.loadValue(); |
| 6438 | storeValue(value); |
| 6439 | |
| 6440 | return RValue<Float>(value); |
| 6441 | } |
| 6442 | |
| 6443 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 6444 | { |
| 6445 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6446 | } |
| 6447 | |
| 6448 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 6449 | { |
| 6450 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6451 | } |
| 6452 | |
| 6453 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 6454 | { |
| 6455 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6456 | } |
| 6457 | |
| 6458 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 6459 | { |
| 6460 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6461 | } |
| 6462 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6463 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6464 | { |
| 6465 | return lhs = lhs + rhs; |
| 6466 | } |
| 6467 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6468 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6469 | { |
| 6470 | return lhs = lhs - rhs; |
| 6471 | } |
| 6472 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6473 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6474 | { |
| 6475 | return lhs = lhs * rhs; |
| 6476 | } |
| 6477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6478 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6479 | { |
| 6480 | return lhs = lhs / rhs; |
| 6481 | } |
| 6482 | |
| 6483 | RValue<Float> operator+(RValue<Float> val) |
| 6484 | { |
| 6485 | return val; |
| 6486 | } |
| 6487 | |
| 6488 | RValue<Float> operator-(RValue<Float> val) |
| 6489 | { |
| 6490 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 6491 | } |
| 6492 | |
| 6493 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 6494 | { |
| 6495 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 6496 | } |
| 6497 | |
| 6498 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 6499 | { |
| 6500 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 6501 | } |
| 6502 | |
| 6503 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 6504 | { |
| 6505 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 6506 | } |
| 6507 | |
| 6508 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 6509 | { |
| 6510 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 6511 | } |
| 6512 | |
| 6513 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 6514 | { |
| 6515 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 6516 | } |
| 6517 | |
| 6518 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 6519 | { |
| 6520 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 6521 | } |
| 6522 | |
| 6523 | RValue<Float> Abs(RValue<Float> x) |
| 6524 | { |
| 6525 | return IfThenElse(x > 0.0f, x, -x); |
| 6526 | } |
| 6527 | |
| 6528 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 6529 | { |
| 6530 | return IfThenElse(x > y, x, y); |
| 6531 | } |
| 6532 | |
| 6533 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 6534 | { |
| 6535 | return IfThenElse(x < y, x, y); |
| 6536 | } |
| 6537 | |
| 6538 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 6539 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6540 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 6544 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6545 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | RValue<Float> Sqrt(RValue<Float> x) |
| 6549 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6550 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 6551 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6552 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6553 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6554 | sqrt->addArg(x.value); |
| 6555 | ::basicBlock->appendInst(sqrt); |
| 6556 | |
| 6557 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | RValue<Float> Round(RValue<Float> x) |
| 6561 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6562 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | RValue<Float> Trunc(RValue<Float> x) |
| 6566 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6567 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | RValue<Float> Frac(RValue<Float> x) |
| 6571 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6572 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6573 | } |
| 6574 | |
| 6575 | RValue<Float> Floor(RValue<Float> x) |
| 6576 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6577 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6578 | } |
| 6579 | |
| 6580 | RValue<Float> Ceil(RValue<Float> x) |
| 6581 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6582 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6583 | } |
| 6584 | |
| 6585 | Type *Float::getType() |
| 6586 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6587 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6588 | } |
| 6589 | |
| 6590 | Float2::Float2(RValue<Float4> cast) |
| 6591 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 6592 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | Type *Float2::getType() |
| 6596 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 6597 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6598 | } |
| 6599 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6600 | Float4::Float4(RValue<Byte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6601 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6602 | Value *a = Int4(cast).loadValue(); |
| 6603 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 6604 | |
| 6605 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6606 | } |
| 6607 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6608 | Float4::Float4(RValue<SByte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6609 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6610 | Value *a = Int4(cast).loadValue(); |
| 6611 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 6612 | |
| 6613 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6614 | } |
| 6615 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6616 | Float4::Float4(RValue<Short4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6617 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6618 | Int4 c(cast); |
| 6619 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 6620 | } |
| 6621 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6622 | Float4::Float4(RValue<UShort4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6623 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6624 | Int4 c(cast); |
| 6625 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 6626 | } |
| 6627 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6628 | Float4::Float4(RValue<Int4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6629 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6630 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 6631 | |
| 6632 | storeValue(xyzw); |
| 6633 | } |
| 6634 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6635 | Float4::Float4(RValue<UInt4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6636 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 6637 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 6638 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6639 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 6640 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6641 | } |
| 6642 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6643 | Float4::Float4() : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6644 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6645 | } |
| 6646 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6647 | Float4::Float4(float xyzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6648 | { |
| 6649 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6650 | } |
| 6651 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6652 | Float4::Float4(float x, float yzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6653 | { |
| 6654 | constant(x, yzw, yzw, yzw); |
| 6655 | } |
| 6656 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6657 | Float4::Float4(float x, float y, float zw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6658 | { |
| 6659 | constant(x, y, zw, zw); |
| 6660 | } |
| 6661 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6662 | Float4::Float4(float x, float y, float z, float w) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6663 | { |
| 6664 | constant(x, y, z, w); |
| 6665 | } |
| 6666 | |
| 6667 | void Float4::constant(float x, float y, float z, float w) |
| 6668 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6669 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6670 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6671 | } |
| 6672 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6673 | Float4::Float4(RValue<Float4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6674 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6675 | storeValue(rhs.value); |
| 6676 | } |
| 6677 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6678 | Float4::Float4(const Float4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6679 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6680 | Value *value = rhs.loadValue(); |
| 6681 | storeValue(value); |
| 6682 | } |
| 6683 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6684 | Float4::Float4(const Reference<Float4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6685 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6686 | Value *value = rhs.loadValue(); |
| 6687 | storeValue(value); |
| 6688 | } |
| 6689 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6690 | Float4::Float4(RValue<Float> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6691 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6692 | Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6693 | |
| 6694 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6695 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6696 | |
| 6697 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6698 | } |
| 6699 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6700 | Float4::Float4(const Float &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6701 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6702 | *this = RValue<Float>(rhs.loadValue()); |
| 6703 | } |
| 6704 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6705 | Float4::Float4(const Reference<Float> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6706 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6707 | *this = RValue<Float>(rhs.loadValue()); |
| 6708 | } |
| 6709 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6710 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6711 | { |
| 6712 | return *this = Float4(x, x, x, x); |
| 6713 | } |
| 6714 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6715 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6716 | { |
| 6717 | storeValue(rhs.value); |
| 6718 | |
| 6719 | return rhs; |
| 6720 | } |
| 6721 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6722 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6723 | { |
| 6724 | Value *value = rhs.loadValue(); |
| 6725 | storeValue(value); |
| 6726 | |
| 6727 | return RValue<Float4>(value); |
| 6728 | } |
| 6729 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6730 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6731 | { |
| 6732 | Value *value = rhs.loadValue(); |
| 6733 | storeValue(value); |
| 6734 | |
| 6735 | return RValue<Float4>(value); |
| 6736 | } |
| 6737 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6738 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6739 | { |
| 6740 | return *this = Float4(rhs); |
| 6741 | } |
| 6742 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6743 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6744 | { |
| 6745 | return *this = Float4(rhs); |
| 6746 | } |
| 6747 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6748 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6749 | { |
| 6750 | return *this = Float4(rhs); |
| 6751 | } |
| 6752 | |
| 6753 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6754 | { |
| 6755 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6756 | } |
| 6757 | |
| 6758 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6759 | { |
| 6760 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6761 | } |
| 6762 | |
| 6763 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6764 | { |
| 6765 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6766 | } |
| 6767 | |
| 6768 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6769 | { |
| 6770 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6771 | } |
| 6772 | |
| 6773 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6774 | { |
| 6775 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6776 | } |
| 6777 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6778 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6779 | { |
| 6780 | return lhs = lhs + rhs; |
| 6781 | } |
| 6782 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6783 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6784 | { |
| 6785 | return lhs = lhs - rhs; |
| 6786 | } |
| 6787 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6788 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6789 | { |
| 6790 | return lhs = lhs * rhs; |
| 6791 | } |
| 6792 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6793 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6794 | { |
| 6795 | return lhs = lhs / rhs; |
| 6796 | } |
| 6797 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6798 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6799 | { |
| 6800 | return lhs = lhs % rhs; |
| 6801 | } |
| 6802 | |
| 6803 | RValue<Float4> operator+(RValue<Float4> val) |
| 6804 | { |
| 6805 | return val; |
| 6806 | } |
| 6807 | |
| 6808 | RValue<Float4> operator-(RValue<Float4> val) |
| 6809 | { |
| 6810 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6811 | } |
| 6812 | |
| 6813 | RValue<Float4> Abs(RValue<Float4> x) |
| 6814 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6815 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6816 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6817 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6818 | |
| 6819 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6823 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6824 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6825 | 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] | 6826 | ::basicBlock->appendInst(cmp); |
| 6827 | |
| 6828 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6829 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6830 | ::basicBlock->appendInst(select); |
| 6831 | |
| 6832 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6833 | } |
| 6834 | |
| 6835 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6836 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6837 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6838 | 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] | 6839 | ::basicBlock->appendInst(cmp); |
| 6840 | |
| 6841 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6842 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6843 | ::basicBlock->appendInst(select); |
| 6844 | |
| 6845 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6846 | } |
| 6847 | |
| 6848 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6849 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6850 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6851 | } |
| 6852 | |
| 6853 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6854 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6855 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6859 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6860 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | 9f737d3 | 2017-07-25 17:26:14 -0400 | [diff] [blame] | 6861 | { |
| 6862 | Float4 result; |
| 6863 | result.x = Sqrt(Float(Float4(x).x)); |
| 6864 | result.y = Sqrt(Float(Float4(x).y)); |
| 6865 | result.z = Sqrt(Float(Float4(x).z)); |
| 6866 | result.w = Sqrt(Float(Float4(x).w)); |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6867 | |
Nicolas Capens | 9f737d3 | 2017-07-25 17:26:14 -0400 | [diff] [blame] | 6868 | return result; |
| 6869 | } |
| 6870 | else |
| 6871 | { |
| 6872 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6873 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6874 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6875 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6876 | sqrt->addArg(x.value); |
| 6877 | ::basicBlock->appendInst(sqrt); |
| 6878 | |
| 6879 | return RValue<Float4>(V(result)); |
| 6880 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6881 | } |
| 6882 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6883 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6884 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6885 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6886 | } |
| 6887 | |
| 6888 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6889 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6890 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6894 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6895 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6899 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6900 | int shuffle[4] = |
| 6901 | { |
| 6902 | ((imm >> 0) & 0x03) + 0, |
| 6903 | ((imm >> 2) & 0x03) + 0, |
| 6904 | ((imm >> 4) & 0x03) + 4, |
| 6905 | ((imm >> 6) & 0x03) + 4, |
| 6906 | }; |
| 6907 | |
| 6908 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6909 | } |
| 6910 | |
| 6911 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6912 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6913 | int shuffle[4] = {0, 4, 1, 5}; |
| 6914 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6918 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6919 | int shuffle[4] = {2, 6, 3, 7}; |
| 6920 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6924 | { |
| 6925 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6926 | Value *result = createMask4(vector, rhs.value, select); |
| 6927 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6928 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6929 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6930 | } |
| 6931 | |
| 6932 | RValue<Int> SignMask(RValue<Float4> x) |
| 6933 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6934 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6935 | { |
| 6936 | Int4 xx = (As<Int4>(x) >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008); |
| 6937 | return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3); |
| 6938 | } |
| 6939 | else |
| 6940 | { |
| 6941 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6942 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6943 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6944 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6945 | movmsk->addArg(x.value); |
| 6946 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6947 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6948 | return RValue<Int>(V(result)); |
| 6949 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6953 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6954 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6958 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6959 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6963 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6964 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6968 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6969 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6973 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6974 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6978 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6979 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6980 | } |
| 6981 | |
Alexis Hetu | 8ef6d10 | 2017-11-09 15:49:09 -0500 | [diff] [blame] | 6982 | RValue<Int4> IsInf(RValue<Float4> x) |
| 6983 | { |
| 6984 | return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000)); |
| 6985 | } |
| 6986 | |
| 6987 | RValue<Int4> IsNan(RValue<Float4> x) |
| 6988 | { |
| 6989 | return ~CmpEQ(x, x); |
| 6990 | } |
| 6991 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6992 | RValue<Float4> Round(RValue<Float4> x) |
| 6993 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6994 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 6995 | { |
| 6996 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 6997 | return (x + Float4(0x00C00000)) - Float4(0x00C00000); |
| 6998 | } |
| 6999 | else if(CPUID::SSE4_1) |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7000 | { |
| 7001 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7002 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7003 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7004 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7005 | round->addArg(x.value); |
| 7006 | round->addArg(::context->getConstantInt32(0)); |
| 7007 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7008 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7009 | return RValue<Float4>(V(result)); |
| 7010 | } |
| 7011 | else |
| 7012 | { |
| 7013 | return Float4(RoundInt(x)); |
| 7014 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7015 | } |
| 7016 | |
| 7017 | RValue<Float4> Trunc(RValue<Float4> x) |
| 7018 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7019 | if(CPUID::SSE4_1) |
| 7020 | { |
| 7021 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7022 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7023 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7024 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7025 | round->addArg(x.value); |
| 7026 | round->addArg(::context->getConstantInt32(3)); |
| 7027 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7028 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7029 | return RValue<Float4>(V(result)); |
| 7030 | } |
| 7031 | else |
| 7032 | { |
| 7033 | return Float4(Int4(x)); |
| 7034 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | RValue<Float4> Frac(RValue<Float4> x) |
| 7038 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7039 | Float4 frc; |
| 7040 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7041 | if(CPUID::SSE4_1) |
| 7042 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7043 | frc = x - Floor(x); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7044 | } |
| 7045 | else |
| 7046 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7047 | frc = x - Float4(Int4(x)); // Signed fractional part. |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7048 | |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7049 | 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] | 7050 | } |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7051 | |
| 7052 | // x - floor(x) can be 1.0 for very small negative x. |
| 7053 | // Clamp against the value just below 1.0. |
| 7054 | return Min(frc, As<Float4>(Int4(0x3F7FFFFF))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | RValue<Float4> Floor(RValue<Float4> x) |
| 7058 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7059 | if(CPUID::SSE4_1) |
| 7060 | { |
| 7061 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7062 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7063 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7064 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7065 | round->addArg(x.value); |
| 7066 | round->addArg(::context->getConstantInt32(1)); |
| 7067 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7068 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7069 | return RValue<Float4>(V(result)); |
| 7070 | } |
| 7071 | else |
| 7072 | { |
| 7073 | return x - Frac(x); |
| 7074 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | RValue<Float4> Ceil(RValue<Float4> x) |
| 7078 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7079 | if(CPUID::SSE4_1) |
| 7080 | { |
| 7081 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7082 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7083 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7084 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7085 | round->addArg(x.value); |
| 7086 | round->addArg(::context->getConstantInt32(2)); |
| 7087 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7088 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7089 | return RValue<Float4>(V(result)); |
| 7090 | } |
| 7091 | else |
| 7092 | { |
| 7093 | return -Floor(-x); |
| 7094 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | Type *Float4::getType() |
| 7098 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 7099 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 7103 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 7104 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 7108 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 7109 | 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] | 7110 | } |
| 7111 | |
| 7112 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 7113 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 7114 | 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] | 7115 | } |
| 7116 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7117 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7118 | { |
| 7119 | return lhs = lhs + offset; |
| 7120 | } |
| 7121 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7122 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7123 | { |
| 7124 | return lhs = lhs + offset; |
| 7125 | } |
| 7126 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7127 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7128 | { |
| 7129 | return lhs = lhs + offset; |
| 7130 | } |
| 7131 | |
| 7132 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 7133 | { |
| 7134 | return lhs + -offset; |
| 7135 | } |
| 7136 | |
| 7137 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 7138 | { |
| 7139 | return lhs + -offset; |
| 7140 | } |
| 7141 | |
| 7142 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 7143 | { |
| 7144 | return lhs + -offset; |
| 7145 | } |
| 7146 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7147 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7148 | { |
| 7149 | return lhs = lhs - offset; |
| 7150 | } |
| 7151 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7152 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7153 | { |
| 7154 | return lhs = lhs - offset; |
| 7155 | } |
| 7156 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7157 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7158 | { |
| 7159 | return lhs = lhs - offset; |
| 7160 | } |
| 7161 | |
| 7162 | void Return() |
| 7163 | { |
| 7164 | Nucleus::createRetVoid(); |
| 7165 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 7166 | Nucleus::createUnreachable(); |
| 7167 | } |
| 7168 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 7169 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7170 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 7171 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 7172 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 7173 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7174 | } |
| 7175 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 7176 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7177 | { |
| 7178 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 7179 | Nucleus::setInsertBlock(bodyBB); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7180 | } |
| 7181 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7182 | RValue<Long> Ticks() |
| 7183 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 7184 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7185 | } |
| 7186 | } |